[gtk+/wip/wayland-tablet: 1259/1271] wayland: Refactor master pointer data into a separate struct



commit ebca39461fd07d74b4a83231ef67c4f3cfbd779b
Author: Carlos Garnacho <carlosg gnome org>
Date:   Fri Jun 19 17:25:54 2015 +0200

    wayland: Refactor master pointer data into a separate struct
    
    This will enable multiple "pointers" to have separate data here.
    Will come out useful when adding support for tablets, as they
    will have a separate cursor for all purposes.

 gdk/wayland/gdkdevice-wayland.c |  379 ++++++++++++++++++++++-----------------
 1 files changed, 212 insertions(+), 167 deletions(-)
---
diff --git a/gdk/wayland/gdkdevice-wayland.c b/gdk/wayland/gdkdevice-wayland.c
index bdbfdeb..0c20238 100644
--- a/gdk/wayland/gdkdevice-wayland.c
+++ b/gdk/wayland/gdkdevice-wayland.c
@@ -37,6 +37,7 @@
 #include <sys/mman.h>
 
 typedef struct _GdkWaylandTouchData GdkWaylandTouchData;
+typedef struct _GdkWaylandPointerData GdkWaylandPointerData;
 
 struct _GdkWaylandTouchData
 {
@@ -48,6 +49,31 @@ struct _GdkWaylandTouchData
   guint initial_touch : 1;
 };
 
+struct _GdkWaylandPointerData {
+  GdkDevice *device;
+  GdkWindow *focus;
+
+  double surface_x, surface_y;
+
+  GdkModifierType button_modifiers;
+
+  uint32_t time;
+  uint32_t enter_serial;
+  uint32_t press_serial;
+
+  GdkWindow *grab_window;
+  uint32_t grab_time;
+
+  struct wl_surface *pointer_surface;
+  GdkCursor *cursor;
+  guint cursor_timeout_id;
+  guint cursor_image_index;
+  guint cursor_image_delay;
+
+  guint current_output_scale;
+  GSList *pointer_surface_outputs;
+};
+
 struct _GdkWaylandDeviceData
 {
   guint32 id;
@@ -71,18 +97,11 @@ struct _GdkWaylandDeviceData
 
   GHashTable *touches;
 
+  GdkWaylandPointerData pointer_info;
+
   GdkModifierType key_modifiers;
-  GdkModifierType button_modifiers;
-  GdkWindow *pointer_focus;
   GdkWindow *keyboard_focus;
-  GdkAtom pending_selection;
-  struct wl_data_device *data_device;
-  double surface_x, surface_y;
-  uint32_t time;
-  uint32_t enter_serial;
-  uint32_t button_press_serial;
-  GdkWindow *pointer_grab_window;
-  uint32_t pointer_grab_time;
+
   gboolean have_server_repeat;
   uint32_t server_repeat_rate;
   uint32_t server_repeat_delay;
@@ -91,16 +110,10 @@ struct _GdkWaylandDeviceData
   guint32 repeat_count;
   GSettings *keyboard_settings;
 
-  guint cursor_timeout_id;
-  guint cursor_image_index;
-  guint cursor_image_delay;
-
+  GdkAtom pending_selection;
+  struct wl_data_device *data_device;
   GdkDragContext *drop_context;
 
-  struct wl_surface *pointer_surface;
-  guint current_output_scale;
-  GSList *pointer_surface_outputs;
-
   /* Source/dest for non-local dnd */
   GdkWindow *foreign_dnd_window;
 
@@ -113,6 +126,7 @@ struct _GdkWaylandDevice
 {
   GdkDevice parent_instance;
   GdkWaylandDeviceData *device;
+  GdkWaylandPointerData *pointer;
 };
 
 struct _GdkWaylandDeviceClass
@@ -180,33 +194,37 @@ gdk_wayland_device_get_state (GdkDevice       *device,
 }
 
 static void
-gdk_wayland_device_stop_window_cursor_animation (GdkWaylandDeviceData *wd)
+gdk_wayland_pointer_stop_cursor_animation (GdkWaylandPointerData *pointer)
 {
-  if (wd->cursor_timeout_id > 0)
+  if (pointer->cursor_timeout_id > 0)
     {
-      g_source_remove (wd->cursor_timeout_id);
-      wd->cursor_timeout_id = 0;
+      g_source_remove (pointer->cursor_timeout_id);
+      pointer->cursor_timeout_id = 0;
     }
-  wd->cursor_image_index = 0;
-  wd->cursor_image_delay = 0;
+
+  pointer->cursor_image_index = 0;
+  pointer->cursor_image_delay = 0;
 }
 
 static gboolean
-gdk_wayland_device_update_window_cursor (GdkWaylandDeviceData *wd)
+gdk_wayland_device_update_window_cursor (GdkDevice *device)
 {
+  GdkWaylandDeviceData *wd = GDK_WAYLAND_DEVICE (device)->device;
+  GdkWaylandPointerData *pointer = GDK_WAYLAND_DEVICE (device)->pointer;
   struct wl_buffer *buffer;
   int x, y, w, h, scale;
   guint next_image_index, next_image_delay;
   gboolean retval = G_SOURCE_REMOVE;
 
-  if (wd->cursor)
+  if (pointer->cursor)
     {
-      buffer = _gdk_wayland_cursor_get_buffer (wd->cursor, wd->cursor_image_index,
+      buffer = _gdk_wayland_cursor_get_buffer (pointer->cursor,
+                                               pointer->cursor_image_index,
                                                &x, &y, &w, &h, &scale);
     }
   else
     {
-      wd->cursor_timeout_id = 0;
+      pointer->cursor_timeout_id = 0;
       return retval;
     }
 
@@ -214,45 +232,45 @@ gdk_wayland_device_update_window_cursor (GdkWaylandDeviceData *wd)
     return retval;
 
   wl_pointer_set_cursor (wd->wl_pointer,
-                         wd->enter_serial,
-                         wd->pointer_surface,
+                         pointer->enter_serial,
+                         pointer->pointer_surface,
                          x, y);
   if (buffer)
     {
-      wl_surface_attach (wd->pointer_surface, buffer, 0, 0);
-      wl_surface_set_buffer_scale (wd->pointer_surface, scale);
-      wl_surface_damage (wd->pointer_surface,  0, 0, w, h);
-      wl_surface_commit (wd->pointer_surface);
+      wl_surface_attach (pointer->pointer_surface, buffer, 0, 0);
+      wl_surface_set_buffer_scale (pointer->pointer_surface, scale);
+      wl_surface_damage (pointer->pointer_surface,  0, 0, w, h);
+      wl_surface_commit (pointer->pointer_surface);
     }
 
   next_image_index =
-    _gdk_wayland_cursor_get_next_image_index (wd->cursor,
-                                              wd->cursor_image_index,
+    _gdk_wayland_cursor_get_next_image_index (pointer->cursor,
+                                              pointer->cursor_image_index,
                                               &next_image_delay);
 
-  if (next_image_index != wd->cursor_image_index)
+  if (next_image_index != pointer->cursor_image_index)
     {
-      if (next_image_delay != wd->cursor_image_delay)
+      if (next_image_delay != pointer->cursor_image_delay)
         {
           guint id;
 
-          gdk_wayland_device_stop_window_cursor_animation (wd);
+          gdk_wayland_pointer_stop_cursor_animation (pointer);
 
           /* Queue timeout for next frame */
           id = g_timeout_add (next_image_delay,
                               (GSourceFunc)gdk_wayland_device_update_window_cursor,
-                              wd);
+                              device);
           g_source_set_name_by_id (id, "[gtk+] gdk_wayland_device_update_window_cursor");
-          wd->cursor_timeout_id = id;
+          pointer->cursor_timeout_id = id;
         }
       else
         retval = G_SOURCE_CONTINUE;
 
-      wd->cursor_image_index = next_image_index;
-      wd->cursor_image_delay = next_image_delay;
+      pointer->cursor_image_index = next_image_index;
+      pointer->cursor_image_delay = next_image_delay;
     }
   else
-    gdk_wayland_device_stop_window_cursor_animation (wd);
+    gdk_wayland_pointer_stop_cursor_animation (pointer);
 
   return retval;
 }
@@ -263,32 +281,33 @@ gdk_wayland_device_set_window_cursor (GdkDevice *device,
                                       GdkCursor *cursor)
 {
   GdkWaylandDeviceData *wd = GDK_WAYLAND_DEVICE (device)->device;
+  GdkWaylandPointerData *pointer = GDK_WAYLAND_DEVICE (device)->pointer;
 
   /* Setting the cursor to NULL means that we should use
    * the default cursor
    */
   if (!cursor)
     {
-      guint scale = wd->current_output_scale;
+      guint scale = pointer->current_output_scale;
       cursor =
         _gdk_wayland_display_get_cursor_for_type_with_scale (wd->display,
                                                              GDK_LEFT_PTR,
                                                              scale);
     }
   else
-    _gdk_wayland_cursor_set_scale (cursor, wd->current_output_scale);
+    _gdk_wayland_cursor_set_scale (cursor, pointer->current_output_scale);
 
-  if (cursor == wd->cursor)
+  if (cursor == pointer->cursor)
     return;
 
-  gdk_wayland_device_stop_window_cursor_animation (wd);
+  gdk_wayland_pointer_stop_cursor_animation (pointer);
 
-  if (wd->cursor)
-    g_object_unref (wd->cursor);
+  if (pointer->cursor)
+    g_object_unref (pointer->cursor);
 
-  wd->cursor = g_object_ref (cursor);
+  pointer->cursor = g_object_ref (cursor);
 
-  gdk_wayland_device_update_window_cursor (wd);
+  gdk_wayland_device_update_window_cursor (device);
 }
 
 static void
@@ -300,30 +319,31 @@ gdk_wayland_device_warp (GdkDevice *device,
 }
 
 static void
-get_coordinates (GdkWaylandDeviceData *data,
-                 double               *x,
-                 double               *y,
-                 double               *x_root,
-                 double               *y_root)
+get_coordinates (GdkDevice *device,
+                 double    *x,
+                 double    *y,
+                 double    *x_root,
+                 double    *y_root)
 {
+  GdkWaylandPointerData *pointer = GDK_WAYLAND_DEVICE (device)->pointer;
   int root_x, root_y;
 
   if (x)
-    *x = data->surface_x;
+    *x = pointer->surface_x;
   if (y)
-    *y = data->surface_y;
+    *y = pointer->surface_y;
 
-  if (data->pointer_focus)
+  if (pointer->focus)
     {
-      gdk_window_get_root_coords (data->pointer_focus,
-                                  data->surface_x,
-                                  data->surface_y,
+      gdk_window_get_root_coords (pointer->focus,
+                                  pointer->surface_x,
+                                  pointer->surface_y,
                                   &root_x, &root_y);
     }
   else
     {
-      root_x = data->surface_x;
-      root_y = data->surface_y;
+      root_x = pointer->surface_x;
+      root_y = pointer->surface_y;
     }
 
   if (x_root)
@@ -332,6 +352,21 @@ get_coordinates (GdkWaylandDeviceData *data,
     *y_root = root_y;
 }
 
+static GdkModifierType
+device_get_modifiers (GdkDevice *device)
+{
+  GdkWaylandDeviceData *wd = GDK_WAYLAND_DEVICE (device)->device;
+  GdkWaylandPointerData *pointer = GDK_WAYLAND_DEVICE (device)->pointer;
+  GdkModifierType mask;
+
+  mask = wd->key_modifiers;
+
+  if (pointer)
+    mask |= pointer->button_modifiers;
+
+  return mask;
+}
+
 static void
 gdk_wayland_device_query_state (GdkDevice        *device,
                                 GdkWindow        *window,
@@ -344,19 +379,21 @@ gdk_wayland_device_query_state (GdkDevice        *device,
                                 GdkModifierType  *mask)
 {
   GdkWaylandDeviceData *wd;
+  GdkWaylandPointerData *pointer;
   GdkScreen *default_screen;
 
   wd = GDK_WAYLAND_DEVICE (device)->device;
+  pointer = GDK_WAYLAND_DEVICE (device)->pointer;
   default_screen = gdk_display_get_default_screen (wd->display);
 
   if (root_window)
     *root_window = gdk_screen_get_root_window (default_screen);
   if (child_window)
-    *child_window = wd->pointer_focus;
+    *child_window = pointer->focus;
   if (mask)
-    *mask = wd->button_modifiers | wd->key_modifiers;
+    *mask = device_get_modifiers (device);
 
-  get_coordinates (wd, win_x, win_y, root_x, root_y);
+  get_coordinates (device, win_x, win_y, root_x, root_y);
 }
 
 static void
@@ -448,6 +485,7 @@ gdk_wayland_device_grab (GdkDevice    *device,
                          guint32       time_)
 {
   GdkWaylandDeviceData *wayland_device = GDK_WAYLAND_DEVICE (device)->device;
+  GdkWaylandPointerData *pointer = GDK_WAYLAND_DEVICE (device)->pointer;
   GdkWindow *prev_focus = gdk_wayland_device_get_focus (device);
 
   if (prev_focus != window)
@@ -461,17 +499,17 @@ gdk_wayland_device_grab (GdkDevice    *device,
   else
     {
       /* Device is a pointer */
-      if (wayland_device->pointer_grab_window != NULL &&
-          time_ != 0 && wayland_device->pointer_grab_time > time_)
+      if (pointer->grab_window != NULL &&
+          time_ != 0 && pointer->grab_time > time_)
         {
           return GDK_GRAB_ALREADY_GRABBED;
         }
 
       if (time_ == 0)
-        time_ = wayland_device->time;
+        time_ = pointer->time;
 
-      wayland_device->pointer_grab_window = window;
-      wayland_device->pointer_grab_time = time_;
+      pointer->grab_window = window;
+      pointer->grab_time = time_;
 
       /* FIXME: This probably breaks if you end up with multiple grabs
        * on the same window - but we need to know the input device for
@@ -488,7 +526,7 @@ gdk_wayland_device_grab (GdkDevice    *device,
       if (cursor)
         wayland_device->cursor = g_object_ref (cursor);
 
-      gdk_wayland_device_update_window_cursor (wayland_device);
+      gdk_wayland_device_update_window_cursor (device);
     }
 
   return GDK_GRAB_SUCCESS;
@@ -498,7 +536,7 @@ static void
 gdk_wayland_device_ungrab (GdkDevice *device,
                            guint32    time_)
 {
-  GdkWaylandDeviceData *wayland_device = GDK_WAYLAND_DEVICE (device)->device;
+  GdkWaylandPointerData *pointer = GDK_WAYLAND_DEVICE (device)->pointer;
   GdkDisplay *display;
   GdkDeviceGrabInfo *grab;
   GdkWindow *focus, *prev_focus = NULL;
@@ -525,10 +563,10 @@ gdk_wayland_device_ungrab (GdkDevice *device,
   else
     {
       /* Device is a pointer */
-      gdk_wayland_device_update_window_cursor (wayland_device);
+      gdk_wayland_device_update_window_cursor (device);
 
-      if (wayland_device->pointer_grab_window)
-        _gdk_wayland_window_set_device_grabbed (wayland_device->pointer_grab_window,
+      if (pointer->grab_window)
+        _gdk_wayland_window_set_device_grabbed (pointer->grab_window,
                                                 NULL,
                                                 NULL,
                                                 0);
@@ -542,17 +580,18 @@ gdk_wayland_device_window_at_position (GdkDevice       *device,
                                        GdkModifierType *mask,
                                        gboolean         get_toplevel)
 {
-  GdkWaylandDeviceData *wd;
+  GdkWaylandPointerData *pointer;
+
+  pointer = GDK_WAYLAND_DEVICE(device)->pointer;
 
-  wd = GDK_WAYLAND_DEVICE(device)->device;
   if (win_x)
-    *win_x = wd->surface_x;
+    *win_x = pointer->surface_x;
   if (win_y)
-    *win_y = wd->surface_y;
+    *win_y = pointer->surface_y;
   if (mask)
-    *mask = wd->button_modifiers | wd->key_modifiers;
+    *mask = device_get_modifiers (device);
 
-  return wd->pointer_focus;
+  return pointer->focus;
 }
 
 static void
@@ -704,9 +743,9 @@ data_device_enter (void                  *data,
                        data_device, serial, surface, wl_fixed_to_double (x), wl_fixed_to_double (y), offer));
 
   /* Update pointer state, so device state queries work during DnD */
-  device->pointer_focus = g_object_ref (dest_window);
-  device->surface_x = wl_fixed_to_double (x);
-  device->surface_y = wl_fixed_to_double (y);
+  device->pointer_info.focus = g_object_ref (dest_window);
+  device->pointer_info.surface_x = wl_fixed_to_double (x);
+  device->pointer_info.surface_y = wl_fixed_to_double (y);
 
   gdk_wayland_drop_context_update_targets (device->drop_context);
 
@@ -743,7 +782,8 @@ data_device_leave (void                  *data,
   if (!gdk_drag_context_get_dest_window (device->drop_context))
     return;
 
-  device->pointer_focus = NULL;
+  g_object_unref (device->pointer_info.focus);
+  device->pointer_info.focus = NULL;
 
   _gdk_wayland_drag_context_set_coords (device->drop_context, -1, -1);
   _gdk_wayland_drag_context_emit_event (device->drop_context, GDK_DRAG_LEAVE,
@@ -767,8 +807,8 @@ data_device_motion (void                  *data,
     return;
 
   /* Update pointer state, so device state queries work during DnD */
-  device->surface_x = wl_fixed_to_double (x);
-  device->surface_y = wl_fixed_to_double (y);
+  device->pointer_info.surface_x = wl_fixed_to_double (x);
+  device->pointer_info.surface_y = wl_fixed_to_double (y);
 
   gdk_wayland_drop_context_update_targets (device->drop_context);
   _gdk_wayland_drag_context_set_coords (device->drop_context,
@@ -853,15 +893,15 @@ pointer_handle_enter (void              *data,
 
   _gdk_wayland_display_update_serial (wayland_display, serial);
 
-  device->pointer_focus = wl_surface_get_user_data(surface);
-  g_object_ref(device->pointer_focus);
+  device->pointer_info.focus = wl_surface_get_user_data(surface);
+  g_object_ref(device->pointer_info.focus);
 
-  device->surface_x = wl_fixed_to_double (sx);
-  device->surface_y = wl_fixed_to_double (sy);
-  device->enter_serial = serial;
+  device->pointer_info.surface_x = wl_fixed_to_double (sx);
+  device->pointer_info.surface_y = wl_fixed_to_double (sy);
+  device->pointer_info.enter_serial = serial;
 
   event = gdk_event_new (GDK_ENTER_NOTIFY);
-  event->crossing.window = g_object_ref (device->pointer_focus);
+  event->crossing.window = g_object_ref (device->pointer_info.focus);
   gdk_event_set_device (event, device->master_pointer);
   gdk_event_set_source_device (event, device->pointer);
   event->crossing.subwindow = NULL;
@@ -871,9 +911,9 @@ pointer_handle_enter (void              *data,
   event->crossing.focus = TRUE;
   event->crossing.state = 0;
 
-  gdk_wayland_device_update_window_cursor (device);
+  gdk_wayland_device_update_window_cursor (device->master_pointer);
 
-  get_coordinates (device,
+  get_coordinates (device->master_pointer,
                    &event->crossing.x,
                    &event->crossing.y,
                    &event->crossing.x_root,
@@ -883,7 +923,7 @@ pointer_handle_enter (void              *data,
 
   GDK_NOTE (EVENTS,
             g_message ("enter, device %p surface %p",
-                       device, device->pointer_focus));
+                       device, device->pointer_info.focus));
 }
 
 static void
@@ -902,13 +942,13 @@ pointer_handle_leave (void              *data,
   if (!GDK_IS_WINDOW (wl_surface_get_user_data (surface)))
     return;
 
-  if (!device->pointer_focus)
+  if (!device->pointer_info.focus)
     return;
 
   _gdk_wayland_display_update_serial (wayland_display, serial);
 
   event = gdk_event_new (GDK_LEAVE_NOTIFY);
-  event->crossing.window = g_object_ref (device->pointer_focus);
+  event->crossing.window = g_object_ref (device->pointer_info.focus);
   gdk_event_set_device (event, device->master_pointer);
   gdk_event_set_source_device (event, device->pointer);
   event->crossing.subwindow = NULL;
@@ -918,9 +958,9 @@ pointer_handle_leave (void              *data,
   event->crossing.focus = TRUE;
   event->crossing.state = 0;
 
-  gdk_wayland_device_update_window_cursor (device);
+  gdk_wayland_device_update_window_cursor (device->master_pointer);
 
-  get_coordinates (device,
+  get_coordinates (device->master_pointer,
                    &event->crossing.x,
                    &event->crossing.y,
                    &event->crossing.x_root,
@@ -930,13 +970,12 @@ pointer_handle_leave (void              *data,
 
   GDK_NOTE (EVENTS,
             g_message ("leave, device %p surface %p",
-                       device, device->pointer_focus));
+                       device, device->pointer_info.focus));
 
-  g_object_unref (device->pointer_focus);
+  g_object_unref (device->pointer_info.focus);
+  device->pointer_info.focus = NULL;
   if (device->cursor)
-    gdk_wayland_device_stop_window_cursor_animation (device);
-
-  device->pointer_focus = NULL;
+    gdk_wayland_pointer_stop_cursor_animation (&device->pointer_info);
 }
 
 static void
@@ -950,26 +989,26 @@ pointer_handle_motion (void              *data,
   GdkWaylandDisplay *display = GDK_WAYLAND_DISPLAY (device->display);
   GdkEvent *event;
 
-  if (!device->pointer_focus)
+  if (!device->pointer_info.focus)
     return;
 
   event = gdk_event_new (GDK_NOTHING);
 
-  device->time = time;
-  device->surface_x = wl_fixed_to_double (sx);
-  device->surface_y = wl_fixed_to_double (sy);
+  device->pointer_info.time = time;
+  device->pointer_info.surface_x = wl_fixed_to_double (sx);
+  device->pointer_info.surface_y = wl_fixed_to_double (sy);
 
   event->motion.type = GDK_MOTION_NOTIFY;
-  event->motion.window = g_object_ref (device->pointer_focus);
+  event->motion.window = g_object_ref (device->pointer_info.focus);
   gdk_event_set_device (event, device->master_pointer);
   gdk_event_set_source_device (event, device->pointer);
   event->motion.time = time;
   event->motion.axes = NULL;
-  event->motion.state = device->button_modifiers | device->key_modifiers;
+  event->motion.state = device_get_modifiers (device->master_pointer);
   event->motion.is_hint = 0;
   gdk_event_set_screen (event, display->screen);
 
-  get_coordinates (device,
+  get_coordinates (device->master_pointer,
                    &event->motion.x,
                    &event->motion.y,
                    &event->motion.x_root,
@@ -997,7 +1036,7 @@ pointer_handle_button (void              *data,
   uint32_t modifier;
   int gdk_button;
 
-  if (!device->pointer_focus)
+  if (!device->pointer_info.focus)
     return;
 
   _gdk_wayland_display_update_serial (display, serial);
@@ -1015,21 +1054,21 @@ pointer_handle_button (void              *data,
       break;
     }
 
-  device->time = time;
+  device->pointer_info.time = time;
   if (state)
-    device->button_press_serial = serial;
+    device->pointer_info.press_serial = serial;
 
   event = gdk_event_new (state ? GDK_BUTTON_PRESS : GDK_BUTTON_RELEASE);
-  event->button.window = g_object_ref (device->pointer_focus);
+  event->button.window = g_object_ref (device->pointer_info.focus);
   gdk_event_set_device (event, device->master_pointer);
   gdk_event_set_source_device (event, device->pointer);
   event->button.time = time;
   event->button.axes = NULL;
-  event->button.state = device->button_modifiers | device->key_modifiers;
+  event->button.state = device_get_modifiers (device->master_pointer);
   event->button.button = gdk_button;
   gdk_event_set_screen (event, display->screen);
 
-  get_coordinates (device,
+  get_coordinates (device->master_pointer,
                    &event->button.x,
                    &event->button.y,
                    &event->button.x_root,
@@ -1037,9 +1076,9 @@ pointer_handle_button (void              *data,
 
   modifier = 1 << (8 + gdk_button - 1);
   if (state)
-    device->button_modifiers |= modifier;
+    device->pointer_info.button_modifiers |= modifier;
   else
-    device->button_modifiers &= ~modifier;
+    device->pointer_info.button_modifiers &= ~modifier;
 
   GDK_NOTE (EVENTS,
            g_message ("button %d %s, device %p state %d",
@@ -1063,7 +1102,7 @@ pointer_handle_axis (void              *data,
   GdkEvent *event;
   gdouble delta_x, delta_y;
 
-  if (!device->pointer_focus)
+  if (!device->pointer_info.focus)
     return;
 
   /* get the delta and convert it into the expected range */
@@ -1081,19 +1120,19 @@ pointer_handle_axis (void              *data,
       g_return_if_reached ();
     }
 
-  device->time = time;
+  device->pointer_info.time = time;
   event = gdk_event_new (GDK_SCROLL);
-  event->scroll.window = g_object_ref (device->pointer_focus);
+  event->scroll.window = g_object_ref (device->pointer_info.focus);
   gdk_event_set_device (event, device->master_pointer);
   gdk_event_set_source_device (event, device->pointer);
   event->scroll.time = time;
   event->scroll.direction = GDK_SCROLL_SMOOTH;
   event->scroll.delta_x = delta_x;
   event->scroll.delta_y = delta_y;
-  event->scroll.state = device->button_modifiers | device->key_modifiers;
+  event->scroll.state = device_get_modifiers (device->master_pointer);
   gdk_event_set_screen (event, display->screen);
 
-  get_coordinates (device,
+  get_coordinates (device->master_pointer,
                    &event->scroll.x,
                    &event->scroll.y,
                    &event->scroll.x_root,
@@ -1365,7 +1404,7 @@ deliver_key_event (GdkWaylandDeviceData *device,
 
   sym = xkb_state_key_get_one_sym (xkb_state, key);
 
-  device->time = time_;
+  device->pointer_info.time = time_;
   device->key_modifiers = gdk_keymap_get_modifier_state (keymap);
 
   event = gdk_event_new (state ? GDK_KEY_PRESS : GDK_KEY_RELEASE);
@@ -1373,7 +1412,7 @@ deliver_key_event (GdkWaylandDeviceData *device,
   gdk_event_set_device (event, device->master_keyboard);
   gdk_event_set_source_device (event, device->keyboard);
   event->key.time = time_;
-  event->key.state = device->button_modifiers | device->key_modifiers;
+  event->key.state = device_get_modifiers (device->master_pointer);
   event->key.group = 0;
   event->key.hardware_keycode = key;
   event->key.keyval = sym;
@@ -1429,7 +1468,7 @@ keyboard_repeat (gpointer data)
 {
   GdkWaylandDeviceData *device = data;
 
-  return deliver_key_event (device, device->time, device->repeat_key, 1);
+  return deliver_key_event (device, device->pointer_info.time, device->repeat_key, 1);
 }
 
 static void
@@ -1536,9 +1575,12 @@ _create_touch_event (GdkWaylandDeviceData *device,
   gdk_event_set_device (event, device->master_pointer);
   gdk_event_set_source_device (event, device->touch);
   event->touch.time = time;
-  event->touch.state = device->button_modifiers | device->key_modifiers;
   gdk_event_set_screen (event, display->screen);
   event->touch.sequence = GDK_SLOT_TO_EVENT_SEQUENCE (touch->id);
+  event->touch.state = device->key_modifiers;
+
+  if (evtype != GDK_TOUCH_BEGIN)
+    event->touch.state |= GDK_BUTTON1_MASK;
 
   if (touch->initial_touch)
     {
@@ -1676,24 +1718,24 @@ emit_gesture_swipe_event (GdkWaylandDeviceData    *device,
   GdkWaylandDisplay *display = GDK_WAYLAND_DISPLAY (device->display);
   GdkEvent *event;
 
-  if (!device->pointer_focus)
+  if (!device->pointer_info.focus)
     return;
 
-  device->time = _time;
+  device->pointer_info.time = _time;
 
   event = gdk_event_new (GDK_TOUCHPAD_SWIPE);
   event->touchpad_swipe.phase = phase;
-  event->touchpad_swipe.window = g_object_ref (device->pointer_focus);
+  event->touchpad_swipe.window = g_object_ref (device->pointer_info.focus);
   gdk_event_set_device (event, device->master_pointer);
   gdk_event_set_source_device (event, device->pointer);
   event->touchpad_swipe.time = _time;
-  event->touchpad_swipe.state = device->button_modifiers | device->key_modifiers;
+  event->touchpad_swipe.state = device_get_modifiers (device->master_pointer);
   gdk_event_set_screen (event, display->screen);
   event->touchpad_swipe.dx = dx;
   event->touchpad_swipe.dy = dy;
   event->touchpad_swipe.n_fingers = n_fingers;
 
-  get_coordinates (device,
+  get_coordinates (device->master_pointer,
                    &event->touchpad_swipe.x,
                    &event->touchpad_swipe.y,
                    &event->touchpad_swipe.x_root,
@@ -1778,18 +1820,18 @@ emit_gesture_pinch_event (GdkWaylandDeviceData    *device,
   GdkWaylandDisplay *display = GDK_WAYLAND_DISPLAY (device->display);
   GdkEvent *event;
 
-  if (!device->pointer_focus)
+  if (!device->pointer_info.focus)
     return;
 
-  device->time = _time;
+  device->pointer_info.time = _time;
 
   event = gdk_event_new (GDK_TOUCHPAD_PINCH);
   event->touchpad_pinch.phase = phase;
-  event->touchpad_pinch.window = g_object_ref (device->pointer_focus);
+  event->touchpad_pinch.window = g_object_ref (device->pointer_info.focus);
   gdk_event_set_device (event, device->master_pointer);
   gdk_event_set_source_device (event, device->pointer);
   event->touchpad_pinch.time = _time;
-  event->touchpad_pinch.state = device->button_modifiers | device->key_modifiers;
+  event->touchpad_pinch.state = device_get_modifiers (device->master_pointer);
   gdk_event_set_screen (event, display->screen);
   event->touchpad_pinch.dx = dx;
   event->touchpad_pinch.dy = dy;
@@ -1797,7 +1839,7 @@ emit_gesture_pinch_event (GdkWaylandDeviceData    *device,
   event->touchpad_pinch.angle_delta = angle_delta * G_PI / 180;
   event->touchpad_pinch.n_fingers = n_fingers;
 
-  get_coordinates (device,
+  get_coordinates (device->master_pointer,
                    &event->touchpad_pinch.x,
                    &event->touchpad_pinch.y,
                    &event->touchpad_pinch.x_root,
@@ -2090,6 +2132,7 @@ init_devices (GdkWaylandDeviceData *device)
                                          "device-manager", device_manager,
                                          NULL);
   GDK_WAYLAND_DEVICE (device->master_pointer)->device = device;
+  GDK_WAYLAND_DEVICE (device->master_pointer)->pointer = &device->pointer_info;
 
   device_manager->devices =
     g_list_prepend (device_manager->devices, device->master_pointer);
@@ -2117,9 +2160,11 @@ init_devices (GdkWaylandDeviceData *device)
 }
 
 static void
-pointer_surface_update_scale (GdkWaylandDeviceData *device)
+pointer_surface_update_scale (GdkDevice *device)
 {
-  GdkWaylandDisplay *wayland_display = GDK_WAYLAND_DISPLAY (device->display);
+  GdkWaylandDeviceData *wd = GDK_WAYLAND_DEVICE (device)->device;
+  GdkWaylandPointerData *pointer = GDK_WAYLAND_DEVICE (device)->pointer;
+  GdkWaylandDisplay *wayland_display = GDK_WAYLAND_DISPLAY (wd->display);
   guint32 scale;
   GSList *l;
 
@@ -2130,7 +2175,7 @@ pointer_surface_update_scale (GdkWaylandDeviceData *device)
     }
 
   scale = 1;
-  for (l = device->pointer_surface_outputs; l != NULL; l = l->next)
+  for (l = pointer->pointer_surface_outputs; l != NULL; l = l->next)
     {
       guint32 output_scale =
         _gdk_wayland_screen_get_output_scale (wayland_display->screen,
@@ -2138,10 +2183,10 @@ pointer_surface_update_scale (GdkWaylandDeviceData *device)
       scale = MAX (scale, output_scale);
     }
 
-  device->current_output_scale = scale;
+  pointer->current_output_scale = scale;
 
-  if (device->cursor)
-    _gdk_wayland_cursor_set_scale (device->cursor, scale);
+  if (pointer->cursor)
+    _gdk_wayland_cursor_set_scale (pointer->cursor, scale);
 
   gdk_wayland_device_update_window_cursor (device);
 }
@@ -2158,10 +2203,10 @@ pointer_surface_enter (void              *data,
             g_message ("pointer surface of device %p entered output %p",
                        device, output));
 
-  device->pointer_surface_outputs =
-    g_slist_append (device->pointer_surface_outputs, output);
+  device->pointer_info.pointer_surface_outputs =
+    g_slist_append (device->pointer_info.pointer_surface_outputs, output);
 
-  pointer_surface_update_scale (device);
+  pointer_surface_update_scale (device->master_pointer);
 }
 
 static void
@@ -2175,10 +2220,10 @@ pointer_surface_leave (void              *data,
             g_message ("pointer surface of device %p left output %p",
                        device, output));
 
-  device->pointer_surface_outputs =
-    g_slist_remove (device->pointer_surface_outputs, output);
+  device->pointer_info.pointer_surface_outputs =
+    g_slist_remove (device->pointer_info.pointer_surface_outputs, output);
 
-  pointer_surface_update_scale (device);
+  pointer_surface_update_scale (device->master_pointer);
 }
 
 static const struct wl_surface_listener pointer_surface_listener = {
@@ -2239,10 +2284,10 @@ _gdk_wayland_device_manager_add_seat (GdkDeviceManager *device_manager,
   wl_data_device_add_listener (device->data_device,
                                &data_device_listener, device);
 
-  device->current_output_scale = 1;
-  device->pointer_surface =
+  device->pointer_info.current_output_scale = 1;
+  device->pointer_info.pointer_surface =
     wl_compositor_create_surface (display_wayland->compositor);
-  wl_surface_add_listener (device->pointer_surface,
+  wl_surface_add_listener (device->pointer_info.pointer_surface,
                            &pointer_surface_listener,
                            device);
 
@@ -2265,7 +2310,7 @@ _gdk_wayland_device_manager_remove_seat (GdkDeviceManager *manager,
         {
           seat_handle_capabilities (device, device->wl_seat, 0);
           g_object_unref (device->keymap);
-          wl_surface_destroy (device->pointer_surface);
+          wl_surface_destroy (device->pointer_info.pointer_surface);
           /* FIXME: destroy data_device */
           g_clear_object (&device->keyboard_settings);
           g_hash_table_destroy (device->touches);
@@ -2375,7 +2420,7 @@ _gdk_wayland_device_get_implicit_grab_serial (GdkWaylandDevice *device,
   if (touch)
     return touch->touch_down_serial;
   else
-    return device->device->button_press_serial;
+    return device->pointer->press_serial;
 }
 
 uint32_t
@@ -2391,8 +2436,8 @@ _gdk_wayland_device_get_last_implicit_grab_serial (GdkWaylandDevice  *device,
   if (sequence)
     *sequence = NULL;
 
-  if (device->device->button_press_serial > serial)
-    serial = device->device->button_press_serial;
+  if (device->pointer->press_serial > serial)
+    serial = device->pointer->press_serial;
 
   while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &touch))
     {
@@ -2449,22 +2494,22 @@ gdk_wayland_device_set_selection (GdkDevice             *gdk_device,
 void
 gdk_wayland_device_unset_grab (GdkDevice *gdk_device)
 {
-  GdkWaylandDeviceData *device;
+  GdkWaylandPointerData *pointer;
   GdkEventSequence *sequence;
   GdkModifierType state;
   GdkEvent *event;
   guint button;
   gdouble x, y;
 
-  device = GDK_WAYLAND_DEVICE (gdk_device)->device;
+  pointer = GDK_WAYLAND_DEVICE (gdk_device)->pointer;
   _gdk_wayland_device_get_last_implicit_grab_serial (GDK_WAYLAND_DEVICE (gdk_device), &sequence);
-  gdk_window_get_device_position_double (device->pointer_grab_window,
+  gdk_window_get_device_position_double (pointer->grab_window,
                                          gdk_device, &x, &y, &state);
 
   if (sequence)
     {
       event = gdk_event_new (GDK_TOUCH_END);
-      event->touch.window = g_object_ref (device->pointer_grab_window);
+      event->touch.window = g_object_ref (pointer->grab_window);
       event->touch.send_event = TRUE;
       event->touch.sequence = sequence;
       event->touch.time = GDK_CURRENT_TIME;
@@ -2483,7 +2528,7 @@ gdk_wayland_device_unset_grab (GdkDevice *gdk_device)
         return;
 
       event = gdk_event_new (GDK_BUTTON_RELEASE);
-      event->button.window = g_object_ref (device->pointer_grab_window);
+      event->button.window = g_object_ref (pointer->grab_window);
       event->button.send_event = TRUE;
       event->button.button = button;
       event->button.time = GDK_CURRENT_TIME;
@@ -2493,7 +2538,7 @@ gdk_wayland_device_unset_grab (GdkDevice *gdk_device)
   else
     return;
 
-  device->button_modifiers = 0;
+  pointer->button_modifiers = 0;
   gdk_event_set_device (event, gdk_device);
   gdk_event_set_source_device (event, gdk_device);
 


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