[mutter] wayland: Move checks for grabbing into a central location



commit 6408e59c7c54106572763e83713aa26235f4867f
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Thu May 22 10:57:02 2014 -0400

    wayland: Move checks for grabbing into a central location
    
    This means that we won't have as much work to do to introduce similar
    checks for touch.

 src/wayland/meta-wayland-pointer.c |   10 ++++++++++
 src/wayland/meta-wayland-pointer.h |    4 ++++
 src/wayland/meta-wayland-seat.c    |    8 ++++++++
 src/wayland/meta-wayland-seat.h    |    4 ++++
 src/wayland/meta-wayland-surface.c |   16 ++++------------
 5 files changed, 30 insertions(+), 12 deletions(-)
---
diff --git a/src/wayland/meta-wayland-pointer.c b/src/wayland/meta-wayland-pointer.c
index 31ae17b..ff6f6e3 100644
--- a/src/wayland/meta-wayland-pointer.c
+++ b/src/wayland/meta-wayland-pointer.c
@@ -805,3 +805,13 @@ meta_wayland_pointer_create_new_resource (MetaWaylandPointer *pointer,
   if (pointer->focus_surface && wl_resource_get_client (pointer->focus_surface->resource) == client)
     meta_wayland_pointer_set_focus (pointer, pointer->focus_surface);
 }
+
+gboolean
+meta_wayland_pointer_can_grab_surface (MetaWaylandPointer *pointer,
+                                       MetaWaylandSurface *surface,
+                                       uint32_t            serial)
+{
+  return (pointer->button_count == 0 &&
+          pointer->grab_serial == serial &&
+          pointer->focus_surface == surface);
+}
diff --git a/src/wayland/meta-wayland-pointer.h b/src/wayland/meta-wayland-pointer.h
index ec957a1..6bd01a8 100644
--- a/src/wayland/meta-wayland-pointer.h
+++ b/src/wayland/meta-wayland-pointer.h
@@ -110,4 +110,8 @@ void meta_wayland_pointer_create_new_resource (MetaWaylandPointer *pointer,
                                                struct wl_resource *seat_resource,
                                                uint32_t id);
 
+gboolean meta_wayland_pointer_can_grab_surface (MetaWaylandPointer *pointer,
+                                                MetaWaylandSurface *surface,
+                                                uint32_t            serial);
+
 #endif /* META_WAYLAND_POINTER_H */
diff --git a/src/wayland/meta-wayland-seat.c b/src/wayland/meta-wayland-seat.c
index 3d35bea..2dedf7e 100644
--- a/src/wayland/meta-wayland-seat.c
+++ b/src/wayland/meta-wayland-seat.c
@@ -182,3 +182,11 @@ meta_wayland_seat_update_cursor_surface (MetaWaylandSeat *seat)
 {
   meta_wayland_pointer_update_cursor_surface (&seat->pointer);
 }
+
+gboolean
+meta_wayland_seat_can_grab_surface (MetaWaylandSeat    *seat,
+                                    MetaWaylandSurface *surface,
+                                    uint32_t            serial)
+{
+  return meta_wayland_pointer_can_grab_surface (&seat->pointer, surface, serial);
+}
diff --git a/src/wayland/meta-wayland-seat.h b/src/wayland/meta-wayland-seat.h
index d0d0c5d..d220174 100644
--- a/src/wayland/meta-wayland-seat.h
+++ b/src/wayland/meta-wayland-seat.h
@@ -70,4 +70,8 @@ gboolean meta_wayland_seat_handle_event (MetaWaylandSeat *seat,
 void meta_wayland_seat_repick (MetaWaylandSeat *seat);
 void meta_wayland_seat_update_cursor_surface (MetaWaylandSeat *seat);
 
+gboolean meta_wayland_seat_can_grab_surface (MetaWaylandSeat    *seat,
+                                             MetaWaylandSurface *surface,
+                                             uint32_t            serial);
+
 #endif /* META_WAYLAND_SEAT_H */
diff --git a/src/wayland/meta-wayland-surface.c b/src/wayland/meta-wayland-surface.c
index ff56f92..e9e09e4 100644
--- a/src/wayland/meta-wayland-surface.c
+++ b/src/wayland/meta-wayland-surface.c
@@ -802,9 +802,7 @@ xdg_surface_move (struct wl_client *client,
   MetaWaylandSeat *seat = wl_resource_get_user_data (seat_resource);
   MetaWaylandSurface *surface = wl_resource_get_user_data (resource);
 
-  if (seat->pointer.button_count == 0 ||
-      seat->pointer.grab_serial != serial ||
-      seat->pointer.focus_surface != surface)
+  if (!meta_wayland_seat_can_grab_surface (seat, surface, serial))
     return;
 
   begin_grab_op_on_surface (surface, seat, META_GRAB_OP_MOVING);
@@ -847,9 +845,7 @@ xdg_surface_resize (struct wl_client *client,
   MetaWaylandSeat *seat = wl_resource_get_user_data (seat_resource);
   MetaWaylandSurface *surface = wl_resource_get_user_data (resource);
 
-  if (seat->pointer.button_count == 0 ||
-      seat->pointer.grab_serial != serial ||
-      seat->pointer.focus_surface != surface)
+  if (!meta_wayland_seat_can_grab_surface (seat, surface, serial))
     return;
 
   begin_grab_op_on_surface (surface, seat, grab_op_for_xdg_surface_resize_edge (edges));
@@ -1105,9 +1101,7 @@ wl_shell_surface_move (struct wl_client *client,
   MetaWaylandSeat *seat = wl_resource_get_user_data (seat_resource);
   MetaWaylandSurface *surface = wl_resource_get_user_data (resource);
 
-  if (seat->pointer.button_count == 0 ||
-      seat->pointer.grab_serial != serial ||
-      seat->pointer.focus_surface != surface)
+  if (!meta_wayland_seat_can_grab_surface (seat, surface, serial))
     return;
 
   begin_grab_op_on_surface (surface, seat, META_GRAB_OP_MOVING);
@@ -1150,9 +1144,7 @@ wl_shell_surface_resize (struct wl_client *client,
   MetaWaylandSeat *seat = wl_resource_get_user_data (seat_resource);
   MetaWaylandSurface *surface = wl_resource_get_user_data (resource);
 
-  if (seat->pointer.button_count == 0 ||
-      seat->pointer.grab_serial != serial ||
-      seat->pointer.focus_surface != surface)
+  if (!meta_wayland_seat_can_grab_surface (seat, surface, serial))
     return;
 
   begin_grab_op_on_surface (surface, seat, grab_op_for_wl_shell_surface_resize_edge (edges));


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