From e877b06fdde60a9fc391628c83258e4ee3b42297 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Wed, 27 Jan 2021 23:25:51 +0100 Subject: [PATCH] screen-cast/monitor-stream: Don't fall apart when monitor changes If the monitor configuration changed, even though the streamed monitor didn't change, we'd still fail to continue streaming, as we failed to update the stage watchers, meaning we wouldn't be notified about when the stage views were painted. Fix this by reattaching the stage watches, i.e. update the painted signalling listeners to listen to the right views, when monitor changes happens. Part-of: --- .../meta-screen-cast-monitor-stream-src.c | 63 +++++++++++++++---- 1 file changed, 50 insertions(+), 13 deletions(-) diff --git a/src/backends/meta-screen-cast-monitor-stream-src.c b/src/backends/meta-screen-cast-monitor-stream-src.c index e22718266..2fa7ebdef 100644 --- a/src/backends/meta-screen-cast-monitor-stream-src.c +++ b/src/backends/meta-screen-cast-monitor-stream-src.c @@ -323,18 +323,59 @@ add_view_watches (MetaScreenCastMonitorStreamSrc *monitor_src, } } +static void +reattach_watches (MetaScreenCastMonitorStreamSrc *monitor_src) +{ + MetaScreenCastStreamSrc *src = META_SCREEN_CAST_STREAM_SRC (monitor_src); + MetaScreenCastStream *stream; + ClutterStage *stage; + GList *l; + + stream = meta_screen_cast_stream_src_get_stream (src); + stage = get_stage (monitor_src); + + for (l = monitor_src->watches; l; l = l->next) + meta_stage_remove_watch (META_STAGE (stage), l->data); + g_clear_pointer (&monitor_src->watches, g_list_free); + + switch (meta_screen_cast_stream_get_cursor_mode (stream)) + { + case META_SCREEN_CAST_CURSOR_MODE_METADATA: + case META_SCREEN_CAST_CURSOR_MODE_HIDDEN: + add_view_watches (monitor_src, + META_STAGE_WATCH_BEFORE_PAINT, + before_stage_painted); + add_view_watches (monitor_src, + META_STAGE_WATCH_AFTER_ACTOR_PAINT, + stage_painted); + break; + case META_SCREEN_CAST_CURSOR_MODE_EMBEDDED: + add_view_watches (monitor_src, + META_STAGE_WATCH_AFTER_PAINT, + stage_painted); + break; + } +} + +static void +on_monitors_changed (MetaMonitorManager *monitor_manager, + MetaScreenCastMonitorStreamSrc *monitor_src) +{ + reattach_watches (monitor_src); +} + static void meta_screen_cast_monitor_stream_src_enable (MetaScreenCastStreamSrc *src) { MetaScreenCastMonitorStreamSrc *monitor_src = META_SCREEN_CAST_MONITOR_STREAM_SRC (src); MetaBackend *backend = get_backend (monitor_src); + MetaMonitorManager *monitor_manager = + meta_backend_get_monitor_manager (backend); MetaCursorTracker *cursor_tracker = meta_backend_get_cursor_tracker (backend); - ClutterStage *stage; MetaScreenCastStream *stream; stream = meta_screen_cast_stream_src_get_stream (src); - stage = get_stage (monitor_src); switch (meta_screen_cast_stream_get_cursor_mode (stream)) { @@ -348,25 +389,21 @@ meta_screen_cast_monitor_stream_src_enable (MetaScreenCastStreamSrc *src) G_CALLBACK (cursor_changed), monitor_src); meta_cursor_tracker_track_position (cursor_tracker); - G_GNUC_FALLTHROUGH; + break; case META_SCREEN_CAST_CURSOR_MODE_HIDDEN: - add_view_watches (monitor_src, - META_STAGE_WATCH_BEFORE_PAINT, - before_stage_painted); - add_view_watches (monitor_src, - META_STAGE_WATCH_AFTER_ACTOR_PAINT, - stage_painted); break; case META_SCREEN_CAST_CURSOR_MODE_EMBEDDED: inhibit_hw_cursor (monitor_src); meta_cursor_tracker_track_position (cursor_tracker); - add_view_watches (monitor_src, - META_STAGE_WATCH_AFTER_PAINT, - stage_painted); break; } - clutter_actor_queue_redraw (CLUTTER_ACTOR (stage)); + reattach_watches (monitor_src); + g_signal_connect_object (monitor_manager, "monitors-changed-internal", + G_CALLBACK (on_monitors_changed), + monitor_src, 0); + + clutter_actor_queue_redraw (CLUTTER_ACTOR (get_stage (monitor_src))); } static void