[xdg-desktop-portal-gnome/gnome-42] shellintrospection: Handle multiple calls to sync_state()



commit 2a02b94a02ad602a6f52d3d036efb0e9f977614c
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Thu Aug 4 22:37:40 2022 -0300

    shellintrospection: Handle multiple calls to sync_state()
    
    Internally, whenever multiple callers call into sync_state(),
    ShellIntrospection would perform as many separate operations
    as the number of calls. This is not optimal.
    
    Cancel ongoing calls to GetWindows() before calling it again.

 src/shellintrospect.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
---
diff --git a/src/shellintrospect.c b/src/shellintrospect.c
index 8922d4e..8a81086 100644
--- a/src/shellintrospect.c
+++ b/src/shellintrospect.c
@@ -83,12 +83,15 @@ get_windows_cb (GObject *source_object,
   uint64_t id;
   GVariant *params = NULL;
 
+  g_clear_object (&shell_introspect->cancellable);
+
   if (!org_gnome_shell_introspect_call_get_windows_finish (shell_introspect->proxy,
                                                            &windows_variant,
                                                            res,
                                                            &error))
     {
-      g_warning ("Failed to get window list: %s", error->message);
+      if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+        g_warning ("Failed to get window list: %s", error->message);
       return;
     }
 
@@ -128,6 +131,10 @@ sync_state (ShellIntrospect *shell_introspect)
 {
   g_clear_pointer (&shell_introspect->windows, g_ptr_array_unref);
 
+  g_cancellable_cancel (shell_introspect->cancellable);
+  g_clear_object (&shell_introspect->cancellable);
+  shell_introspect->cancellable = g_cancellable_new ();
+
   org_gnome_shell_introspect_call_get_windows (shell_introspect->proxy,
                                                shell_introspect->cancellable,
                                                get_windows_cb,


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