[xdg-desktop-portal-gnome/gnome-42] screencast: Wait for windows before restoring session



commit f0f5088d51e972215008562939781a9c47f0c74d
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Thu Aug 4 22:26:09 2022 -0300

    screencast: Wait for windows before restoring session
    
    We need to wait for the full list of windows before attempting
    to restore a previous window stream, otherwise we'll always fail.
    
    Spin the mainloop until the list of windows is ready.
    
    Fixes
    https://gitlab.gnome.org/GNOME/xdg-desktop-portal-gnome/-/issues/49

 src/screencast.c      |  1 +
 src/shellintrospect.c | 15 +++++++++++++--
 src/shellintrospect.h |  2 ++
 3 files changed, 16 insertions(+), 2 deletions(-)
---
diff --git a/src/screencast.c b/src/screencast.c
index a7e96b7..09238b1 100644
--- a/src/screencast.c
+++ b/src/screencast.c
@@ -444,6 +444,7 @@ find_best_window_by_app_id_and_title (const char *app_id,
   best_match_distance = G_MAXLONG;
 
   shell_introspect_ref_listeners (shell_introspect);
+  shell_introspect_wait_for_windows (shell_introspect);
 
   windows = shell_introspect_get_windows (shell_introspect);
   for (size_t i = 0; windows && i < windows->len; i++)
diff --git a/src/shellintrospect.c b/src/shellintrospect.c
index 5bbc076..8922d4e 100644
--- a/src/shellintrospect.c
+++ b/src/shellintrospect.c
@@ -83,8 +83,6 @@ get_windows_cb (GObject *source_object,
   uint64_t id;
   GVariant *params = NULL;
 
-  g_clear_pointer (&shell_introspect->windows, g_ptr_array_unref);
-
   if (!org_gnome_shell_introspect_call_get_windows_finish (shell_introspect->proxy,
                                                            &windows_variant,
                                                            res,
@@ -128,6 +126,8 @@ get_windows_cb (GObject *source_object,
 static void
 sync_state (ShellIntrospect *shell_introspect)
 {
+  g_clear_pointer (&shell_introspect->windows, g_ptr_array_unref);
+
   org_gnome_shell_introspect_call_get_windows (shell_introspect->proxy,
                                                shell_introspect->cancellable,
                                                get_windows_cb,
@@ -320,3 +320,14 @@ shell_introspect_are_animations_enabled (ShellIntrospect *shell_introspect,
   *out_animations_enabled = shell_introspect->animations_enabled;
   return TRUE;
 }
+
+void
+shell_introspect_wait_for_windows (ShellIntrospect *shell_introspect)
+{
+  g_assert (shell_introspect->num_listeners > 0);
+
+  sync_state (shell_introspect);
+
+  while (!shell_introspect->windows)
+    g_main_context_iteration (NULL, TRUE);
+}
diff --git a/src/shellintrospect.h b/src/shellintrospect.h
index a783d55..a8378dc 100644
--- a/src/shellintrospect.h
+++ b/src/shellintrospect.h
@@ -44,3 +44,5 @@ GPtrArray * shell_introspect_get_windows (ShellIntrospect *shell_introspect);
 
 gboolean shell_introspect_are_animations_enabled (ShellIntrospect *introspect,
                                                   gboolean        *enable_animations);
+
+void shell_introspect_wait_for_windows (ShellIntrospect *shell_introspect);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]