kathenas / rpms / mutter

Forked from rpms/mutter 5 years ago
Clone
Blob Blame History Raw
From ca78984a92c84e8684455c80efb5a86c65061f96 Mon Sep 17 00:00:00 2001
From: Olivier Fourdan <ofourdan@redhat.com>
Date: Fri, 21 Sep 2018 17:49:36 +0200
Subject: [PATCH 09/12] window: Add window id

Generate a unique 64bit window-id which is unrelated to any windowing
backend.

https://gitlab.gnome.org/GNOME/mutter/merge_requests/306
(cherry picked from commit bbcb66ddf4f5eeff379f250b361de0366459b4a3)
---
 src/core/display-private.h |  4 ++++
 src/core/display.c         | 32 ++++++++++++++++++++++++++++++++
 src/core/window-private.h  |  1 +
 src/core/window.c          | 16 ++++++++++++++++
 src/meta/window.h          |  2 ++
 5 files changed, 55 insertions(+)

diff --git a/src/core/display-private.h b/src/core/display-private.h
index 9e4518b..d24ee00 100644
--- a/src/core/display-private.h
+++ b/src/core/display-private.h
@@ -507,4 +507,8 @@ void meta_display_notify_pad_group_switch (MetaDisplay        *display,
                                            guint               n_mode,
                                            guint               n_modes);
 
+MetaWindow *meta_display_get_window_from_id (MetaDisplay *display,
+                                             uint64_t     window_id);
+uint64_t    meta_display_generate_window_id (MetaDisplay *display);
+
 #endif
diff --git a/src/core/display.c b/src/core/display.c
index e7dd453..d09f119 100644
--- a/src/core/display.c
+++ b/src/core/display.c
@@ -3269,3 +3269,35 @@ meta_display_notify_pad_group_switch (MetaDisplay        *display,
 
   g_string_free (message, TRUE);
 }
+
+MetaWindow *
+meta_display_get_window_from_id (MetaDisplay *display,
+                                 uint64_t     window_id)
+{
+  g_autoptr (GSList) windows = NULL;
+  GSList *l;
+
+  windows = meta_display_list_windows (display, META_LIST_DEFAULT);
+  for (l = windows; l; l = l->next)
+    {
+      MetaWindow *window = l->data;
+
+      if (window->id == window_id)
+        return window;
+    }
+
+  return NULL;
+}
+
+uint64_t
+meta_display_generate_window_id (MetaDisplay *display)
+{
+  static uint64_t base_window_id;
+  static uint64_t last_window_id;
+
+  if (!base_window_id)
+    base_window_id = g_random_int () + 1;
+
+  /* We can overflow here, that's fine */
+  return (base_window_id + last_window_id++);
+}
diff --git a/src/core/window-private.h b/src/core/window-private.h
index 8552829..0f652b9 100644
--- a/src/core/window-private.h
+++ b/src/core/window-private.h
@@ -153,6 +153,7 @@ struct _MetaWindow
 
   MetaDisplay *display;
   MetaScreen *screen;
+  uint64_t id;
   guint64 stamp;
   MetaLogicalMonitor *monitor;
   MetaWorkspace *workspace;
diff --git a/src/core/window.c b/src/core/window.c
index a1f4aa4..00b2e4d 100644
--- a/src/core/window.c
+++ b/src/core/window.c
@@ -1142,6 +1142,8 @@ _meta_window_shared_new (MetaDisplay         *display,
       window->has_resize_func = FALSE;
     }
 
+  window->id = meta_display_generate_window_id (display);
+
   META_WINDOW_GET_CLASS (window)->manage (window);
 
   if (!window->override_redirect)
@@ -8466,3 +8468,17 @@ meta_window_is_stackable (MetaWindow *window)
 {
   return META_WINDOW_GET_CLASS (window)->is_stackable (window);
 }
+
+/**
+ * meta_window_get_id:
+ * @window: a #MetaWindow
+ *
+ * Returns the window id associated with window.
+ *
+ * Returns: (transfer none): The window id
+ */
+uint64_t
+meta_window_get_id (MetaWindow *window)
+{
+  return window->id;
+}
diff --git a/src/meta/window.h b/src/meta/window.h
index 09317e6..364d541 100644
--- a/src/meta/window.h
+++ b/src/meta/window.h
@@ -260,4 +260,6 @@ gboolean meta_window_is_client_decorated (MetaWindow *window);
 gboolean meta_window_titlebar_is_onscreen    (MetaWindow *window);
 void     meta_window_shove_titlebar_onscreen (MetaWindow *window);
 
+uint64_t meta_window_get_id (MetaWindow *window);
+
 #endif
-- 
2.19.2