[mutter/gbsneto/cleanup-x11-from-meta-window: 3/5] window: Delegate meta_window_has_pointer to subclasses



commit 1940de66b055442f35aeca260b348e982b04a1ac
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Sat Dec 22 19:10:59 2018 -0200

    window: Delegate meta_window_has_pointer to subclasses
    
    meta_window_has_pointer() is already aware of X11 or Wayland
    specific implementations, but it makes more sense to have it
    implemented by the subclasses themselves.
    
    Move the Wayland and X11 code paths to their respective subclasses
    through a new vfunc MetaWindowClass.has_pointer().
    
    https://gitlab.gnome.org/GNOME/mutter/merge_requests/372

 src/core/window-private.h         |  1 +
 src/core/window.c                 | 43 +--------------------------------------
 src/wayland/meta-window-wayland.c | 16 +++++++++++++++
 src/x11/window-x11.c              | 24 ++++++++++++++++++++++
 4 files changed, 42 insertions(+), 42 deletions(-)
---
diff --git a/src/core/window-private.h b/src/core/window-private.h
index 481229ea5..f546f5adc 100644
--- a/src/core/window-private.h
+++ b/src/core/window-private.h
@@ -559,6 +559,7 @@ struct _MetaWindowClass
                                    ClutterInputDevice *source);
   gboolean (*is_stackable)        (MetaWindow *window);
   gboolean (*are_updates_frozen)  (MetaWindow *window);
+  gboolean (*has_pointer)         (MetaWindow *window);
 };
 
 /* These differ from window->has_foo_func in that they consider
diff --git a/src/core/window.c b/src/core/window.c
index 0f3c44352..aa5522938 100644
--- a/src/core/window.c
+++ b/src/core/window.c
@@ -8092,51 +8092,10 @@ mouse_mode_focus (MetaWindow  *window,
     }
 }
 
-static gboolean
-window_has_pointer_wayland (MetaWindow *window)
-{
-  ClutterDeviceManager *dm;
-  ClutterInputDevice *dev;
-  ClutterActor *pointer_actor, *window_actor;
-
-  dm = clutter_device_manager_get_default ();
-  dev = clutter_device_manager_get_core_device (dm, CLUTTER_POINTER_DEVICE);
-  pointer_actor = clutter_input_device_get_pointer_actor (dev);
-  window_actor = CLUTTER_ACTOR (meta_window_get_compositor_private (window));
-
-  return pointer_actor && clutter_actor_contains (window_actor, pointer_actor);
-}
-
-static gboolean
-window_has_pointer_x11 (MetaWindow *window)
-{
-  MetaX11Display *x11_display = window->display->x11_display;
-  Window root, child;
-  double root_x, root_y, x, y;
-  XIButtonState buttons;
-  XIModifierState mods;
-  XIGroupState group;
-
-  meta_x11_error_trap_push (x11_display);
-  XIQueryPointer (x11_display->xdisplay,
-                  META_VIRTUAL_CORE_POINTER_ID,
-                  x11_display->xroot,
-                  &root, &child,
-                  &root_x, &root_y, &x, &y,
-                  &buttons, &mods, &group);
-  meta_x11_error_trap_pop (x11_display);
-  free (buttons.mask);
-
-  return meta_x11_display_lookup_x_window (x11_display, child) == window;
-}
-
 gboolean
 meta_window_has_pointer (MetaWindow *window)
 {
-  if (meta_is_wayland_compositor ())
-    return window_has_pointer_wayland (window);
-  else
-    return window_has_pointer_x11 (window);
+  return META_WINDOW_GET_CLASS (window)->has_pointer (window);
 }
 
 static gboolean
diff --git a/src/wayland/meta-window-wayland.c b/src/wayland/meta-window-wayland.c
index 3cd4c7f36..736a764c0 100644
--- a/src/wayland/meta-window-wayland.c
+++ b/src/wayland/meta-window-wayland.c
@@ -609,6 +609,21 @@ meta_window_wayland_are_updates_frozen (MetaWindow *window)
   return !wl_window->has_been_shown;
 }
 
+static gboolean
+meta_window_wayland_has_pointer (MetaWindow *window)
+{
+  ClutterDeviceManager *dm;
+  ClutterInputDevice *dev;
+  ClutterActor *pointer_actor, *window_actor;
+
+  dm = clutter_device_manager_get_default ();
+  dev = clutter_device_manager_get_core_device (dm, CLUTTER_POINTER_DEVICE);
+  pointer_actor = clutter_input_device_get_pointer_actor (dev);
+  window_actor = CLUTTER_ACTOR (meta_window_get_compositor_private (window));
+
+  return pointer_actor && clutter_actor_contains (window_actor, pointer_actor);
+}
+
 static void
 meta_window_wayland_class_init (MetaWindowWaylandClass *klass)
 {
@@ -632,6 +647,7 @@ meta_window_wayland_class_init (MetaWindowWaylandClass *klass)
   window_class->shortcuts_inhibited = meta_window_wayland_shortcuts_inhibited;
   window_class->is_stackable = meta_window_wayland_is_stackable;
   window_class->are_updates_frozen = meta_window_wayland_are_updates_frozen;
+  window_class->has_pointer = meta_window_wayland_has_pointer;
 }
 
 MetaWindow *
diff --git a/src/x11/window-x11.c b/src/x11/window-x11.c
index 9ec28703c..6e67b56b1 100644
--- a/src/x11/window-x11.c
+++ b/src/x11/window-x11.c
@@ -1683,6 +1683,29 @@ meta_window_x11_are_updates_frozen (MetaWindow *window)
   return FALSE;
 }
 
+static gboolean
+meta_window_x11_has_pointer (MetaWindow *window)
+{
+  MetaX11Display *x11_display = window->display->x11_display;
+  Window root, child;
+  double root_x, root_y, x, y;
+  XIButtonState buttons;
+  XIModifierState mods;
+  XIGroupState group;
+
+  meta_x11_error_trap_push (x11_display);
+  XIQueryPointer (x11_display->xdisplay,
+                  META_VIRTUAL_CORE_POINTER_ID,
+                  x11_display->xroot,
+                  &root, &child,
+                  &root_x, &root_y, &x, &y,
+                  &buttons, &mods, &group);
+  meta_x11_error_trap_pop (x11_display);
+  free (buttons.mask);
+
+  return meta_x11_display_lookup_x_window (x11_display, child) == window;
+}
+
 static void
 meta_window_x11_class_init (MetaWindowX11Class *klass)
 {
@@ -1710,6 +1733,7 @@ meta_window_x11_class_init (MetaWindowX11Class *klass)
   window_class->shortcuts_inhibited = meta_window_x11_shortcuts_inhibited;
   window_class->is_stackable = meta_window_x11_is_stackable;
   window_class->are_updates_frozen = meta_window_x11_are_updates_frozen;
+  window_class->has_pointer = meta_window_x11_has_pointer;
 }
 
 void


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