[libwnck/wip/muktupavels/issue-146: 1/2] screen: fallback to WM_CLASS when window group is not provided




commit ce65a6ffe785e30002245f92f8c20ee778c7db57
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Sun Oct 9 22:35:54 2022 +0300

    screen: fallback to WM_CLASS when window group is not provided
    
    If application/window does not provide window group use WM_CLASS
    to consider if window belongs to the same application.
    
    https://gitlab.gnome.org/GNOME/libwnck/-/issues/146

 libwnck/screen.c              | 16 ++++++++++------
 libwnck/wnck-handle-private.h |  3 +++
 libwnck/wnck-handle.c         | 32 ++++++++++++++++++++++++++++++++
 3 files changed, 45 insertions(+), 6 deletions(-)
---
diff --git a/libwnck/screen.c b/libwnck/screen.c
index 35d33c22..42f0c764 100644
--- a/libwnck/screen.c
+++ b/libwnck/screen.c
@@ -1387,9 +1387,9 @@ update_client_list (WnckScreen *screen)
       if (window == NULL)
         {
           Window leader;
+          const char *res_class;
           WnckApplication *app;
-         const char *res_class;
-         WnckClassGroup *class_group;
+          WnckClassGroup *class_group;
 
           window = _wnck_window_create (mapping[i],
                                         screen,
@@ -1397,11 +1397,17 @@ update_client_list (WnckScreen *screen)
 
           created = g_list_prepend (created, window);
 
-         /* Application */
-
           leader = wnck_window_get_group_leader (window);
+          res_class = wnck_window_get_class_group_name (window);
+
+          /* Application */
 
           app = wnck_handle_get_application (screen->priv->handle, leader);
+
+          if (app == NULL)
+            app = _wnck_handle_get_application_from_res_class (screen->priv->handle,
+                                                               res_class);
+
           if (app == NULL)
             {
               app = _wnck_application_create (leader, screen);
@@ -1412,8 +1418,6 @@ update_client_list (WnckScreen *screen)
 
          /* Class group */
 
-         res_class = wnck_window_get_class_group_name (window);
-
          class_group = wnck_handle_get_class_group (screen->priv->handle, res_class);
          if (class_group == NULL)
            {
diff --git a/libwnck/wnck-handle-private.h b/libwnck/wnck-handle-private.h
index c4217cef..770836c8 100644
--- a/libwnck/wnck-handle-private.h
+++ b/libwnck/wnck-handle-private.h
@@ -44,6 +44,9 @@ void             _wnck_handle_insert_application         (WnckHandle      *self,
 void             _wnck_handle_remove_application         (WnckHandle      *self,
                                                           gpointer         xwindow);
 
+WnckApplication *_wnck_handle_get_application_from_res_class (WnckHandle  *self,
+                                                              const char  *res_class);
+
 void             _wnck_handle_insert_window              (WnckHandle      *self,
                                                           gpointer         xwindow,
                                                           WnckWindow      *window);
diff --git a/libwnck/wnck-handle.c b/libwnck/wnck-handle.c
index e12ff882..28ac8549 100644
--- a/libwnck/wnck-handle.c
+++ b/libwnck/wnck-handle.c
@@ -563,6 +563,38 @@ _wnck_handle_remove_application (WnckHandle *self,
   g_hash_table_remove (self->app_hash, xwindow);
 }
 
+WnckApplication *
+_wnck_handle_get_application_from_res_class (WnckHandle *self,
+                                             const char *res_class)
+{
+  WnckApplication *app;
+  GHashTableIter iter;
+  gpointer value;
+
+  if (res_class == NULL || *res_class == '\0')
+    return NULL;
+
+  app = NULL;
+
+  g_hash_table_iter_init (&iter, self->app_hash);
+  while (g_hash_table_iter_next (&iter, NULL, &value))
+    {
+      GList *windows;
+      const char *window_res_class;
+
+      app = WNCK_APPLICATION (value);
+
+      windows = wnck_application_get_windows (app);
+      window_res_class = wnck_window_get_class_group_name (windows->data);
+
+      if (g_strcmp0 (res_class, window_res_class) == 0)
+        break;
+
+      app = NULL;
+    }
+
+  return app;
+}
 
 /**
  * wnck_handle_get_application:


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