[mutter] MetaWaylandPointerConstraint: Use own 'appears-focused' signal handler



commit 6396974eae9f9ad99575a181d9c4b84a8ce53200
Author: Jonas Ådahl <jadahl gmail com>
Date:   Wed Feb 24 19:55:58 2016 +0800

    MetaWaylandPointerConstraint: Use own 'appears-focused' signal handler
    
    Instead of having MetaWindowWayland having hooks into pointer
    constraints subsystem, have the pointer constraints subsystem listen
    for the signal itself and enable/disable itself.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=762661

 src/wayland/meta-wayland-pointer-constraints.c |   63 +++++++++++++++++++++++-
 src/wayland/meta-wayland-pointer-constraints.h |    5 --
 src/wayland/meta-window-wayland.c              |    7 ---
 3 files changed, 61 insertions(+), 14 deletions(-)
---
diff --git a/src/wayland/meta-wayland-pointer-constraints.c b/src/wayland/meta-wayland-pointer-constraints.c
index 2c288ea..dc81b80 100644
--- a/src/wayland/meta-wayland-pointer-constraints.c
+++ b/src/wayland/meta-wayland-pointer-constraints.c
@@ -68,6 +68,8 @@ struct _MetaWaylandPointerConstraint
 typedef struct _MetaWaylandSurfacePointerConstraintsData
 {
   GList *pointer_constraints;
+  MetaWindow *window;
+  gulong appears_changed_handler_id;
 } MetaWaylandSurfacePointerConstraintsData;
 
 typedef struct
@@ -93,6 +95,13 @@ static const MetaWaylandPointerGrabInterface confined_pointer_grab_interface;
 static void
 meta_wayland_pointer_constraint_destroy (MetaWaylandPointerConstraint *constraint);
 
+static void
+meta_wayland_pointer_constraint_maybe_enable_for_window (MetaWindow *window);
+
+static void
+meta_wayland_pointer_constraint_maybe_remove_for_seat (MetaWaylandSeat *seat,
+                                                       MetaWindow      *focus_window);
+
 static MetaWaylandSurfacePointerConstraintsData *
 get_surface_constraints_data (MetaWaylandSurface *surface)
 {
@@ -101,8 +110,58 @@ get_surface_constraints_data (MetaWaylandSurface *surface)
 }
 
 static void
+appears_focused_changed (MetaWindow *window,
+                         GParamSpec *pspec,
+                         gpointer    user_data)
+{
+  MetaWaylandCompositor *wayland_compositor;
+
+  wayland_compositor = meta_wayland_compositor_get_default ();
+  meta_wayland_pointer_constraint_maybe_remove_for_seat (wayland_compositor->seat,
+                                                         window);
+
+  if (window->unmanaging)
+    return;
+
+  meta_wayland_pointer_constraint_maybe_enable_for_window (window);
+}
+
+static MetaWaylandSurfacePointerConstraintsData *
+surface_constraint_data_new (MetaWaylandSurface *surface)
+{
+  MetaWaylandSurfacePointerConstraintsData *data;
+
+  data = g_new0 (MetaWaylandSurfacePointerConstraintsData, 1);
+
+  if (surface->window)
+    {
+      data->window = surface->window;
+      g_object_add_weak_pointer (G_OBJECT (data->window),
+                                 (gpointer *) &data->window);
+      data->appears_changed_handler_id =
+        g_signal_connect (data->window, "notify::appears-focused",
+                          G_CALLBACK (appears_focused_changed), NULL);
+    }
+  else
+    {
+      /* TODO: Support constraints on non-toplevel windows, such as subsurfaces.
+       */
+      g_warn_if_reached ();
+    }
+
+  return data;
+}
+static void
 surface_constraint_data_free (MetaWaylandSurfacePointerConstraintsData *data)
 {
+  if (data->window)
+    {
+      g_signal_handler_disconnect (data->window,
+                                   data->appears_changed_handler_id);
+      g_object_remove_weak_pointer (G_OBJECT (data->window),
+                                    (gpointer *) &data->window);
+    }
+
   g_list_free_full (data->pointer_constraints,
                     (GDestroyNotify) meta_wayland_pointer_constraint_destroy);
   g_free (data);
@@ -116,7 +175,7 @@ ensure_surface_constraints_data (MetaWaylandSurface *surface)
   data = get_surface_constraints_data (surface);
   if (!data)
     {
-      data = g_new0 (MetaWaylandSurfacePointerConstraintsData, 1);
+      data = surface_constraint_data_new (surface);
       g_object_set_qdata_full (G_OBJECT (surface),
                                quark_surface_pointer_constraints_data,
                                data,
@@ -365,7 +424,7 @@ meta_wayland_pointer_constraint_maybe_remove_for_seat (MetaWaylandSeat *seat,
     }
 }
 
-void
+static void
 meta_wayland_pointer_constraint_maybe_enable_for_window (MetaWindow *window)
 {
   MetaWaylandSurface *surface = window->surface;
diff --git a/src/wayland/meta-wayland-pointer-constraints.h b/src/wayland/meta-wayland-pointer-constraints.h
index 2a66091..0a28948 100644
--- a/src/wayland/meta-wayland-pointer-constraints.h
+++ b/src/wayland/meta-wayland-pointer-constraints.h
@@ -44,9 +44,4 @@ cairo_region_t * meta_wayland_pointer_constraint_calculate_effective_region (Met
 
 MetaWaylandSurface * meta_wayland_pointer_constraint_get_surface (MetaWaylandPointerConstraint *constraint);
 
-void meta_wayland_pointer_constraint_maybe_remove_for_seat (MetaWaylandSeat *seat,
-                                                            MetaWindow      *focus_window);
-
-void meta_wayland_pointer_constraint_maybe_enable_for_window (MetaWindow *window);
-
 #endif /* META_WAYLAND_POINTER_CONSTRAINTS_H */
diff --git a/src/wayland/meta-window-wayland.c b/src/wayland/meta-window-wayland.c
index 46865ed..f38e4b9 100644
--- a/src/wayland/meta-window-wayland.c
+++ b/src/wayland/meta-window-wayland.c
@@ -403,11 +403,6 @@ appears_focused_changed (GObject    *object,
                          gpointer    user_data)
 {
   MetaWindow *window = META_WINDOW (object);
-  MetaWaylandCompositor *wayland_compositor;
-
-  wayland_compositor = meta_wayland_compositor_get_default ();
-  meta_wayland_pointer_constraint_maybe_remove_for_seat (wayland_compositor->seat,
-                                                         window);
 
   /* When we're unmanaging, we remove focus from the window,
    * causing this to fire. Don't do anything in that case. */
@@ -415,8 +410,6 @@ appears_focused_changed (GObject    *object,
     return;
 
   surface_state_changed (window);
-
-  meta_wayland_pointer_constraint_maybe_enable_for_window (window);
 }
 
 static void


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