Wayland: Translate wl_tablet.down/up into button events
authorStephen Chandler Paul <thatslyude@gmail.com>
Mon, 22 Jun 2015 16:16:27 +0000 (18:16 +0200)
committerCarlos Garnacho <carlosg@gnome.org>
Wed, 6 Apr 2016 14:12:12 +0000 (16:12 +0200)
These are sent with button=GDK_BUTTON_PRIMARY, axes must be also
included in these events, in addition to motion ones.

gdk/wayland/gdkdevice-wayland.c

index f5653eed43a0e5c8135a18504c06e9ab9f76ba6b..f3f0397d67258cc8fe19656253aef5439bb8eb99 100644 (file)
@@ -3133,6 +3133,66 @@ tablet_tool_handle_proximity_out (void                      *data,
   gdk_device_update_tool (tablet->current_device, NULL);
 }
 
+static void
+tablet_create_button_event_frame (GdkWaylandTabletData *tablet,
+                                  GdkEventType          evtype,
+                                  guint                 button)
+{
+  GdkWaylandSeat *seat = GDK_WAYLAND_SEAT (tablet->seat);
+  GdkWaylandDisplay *wayland_display = GDK_WAYLAND_DISPLAY (seat->display);
+  GdkEvent *event;
+
+  event = gdk_wayland_tablet_get_frame_event (tablet, evtype);
+  event->button.window = g_object_ref (tablet->pointer_info.focus);
+  gdk_event_set_device (event, tablet->master);
+  gdk_event_set_source_device (event, tablet->current_device);
+  gdk_event_set_device_tool (event, tablet->current_tool->tool);
+  event->button.time = tablet->pointer_info.time;
+  event->button.state = device_get_modifiers (tablet->master);
+  event->button.button = button;
+  gdk_event_set_screen (event, wayland_display->screen);
+
+  get_coordinates (tablet->master,
+                   &event->button.x,
+                   &event->button.y,
+                   &event->button.x_root,
+                   &event->button.y_root);
+}
+
+static void
+tablet_tool_handle_down (void                      *data,
+                         struct zwp_tablet_tool_v1 *wp_tablet_tool,
+                         uint32_t                   serial)
+{
+  GdkWaylandTabletToolData *tool = data;
+  GdkWaylandTabletData *tablet = tool->current_tablet;
+  GdkWaylandSeat *seat = GDK_WAYLAND_SEAT (tool->seat);
+  GdkWaylandDisplay *wayland_display = GDK_WAYLAND_DISPLAY (seat->display);
+
+  if (!tablet->pointer_info.focus)
+    return;
+
+  _gdk_wayland_display_update_serial (wayland_display, serial);
+  tablet->pointer_info.press_serial = serial;
+
+  tablet_create_button_event_frame (tablet, GDK_BUTTON_PRESS, GDK_BUTTON_PRIMARY);
+  tablet->pointer_info.button_modifiers |= GDK_BUTTON1_MASK;
+}
+
+static void
+tablet_tool_handle_up (void                      *data,
+                       struct zwp_tablet_tool_v1 *wp_tablet_tool)
+{
+  GdkWaylandTabletToolData *tool = data;
+  GdkWaylandTabletData *tablet = tool->current_tablet;
+
+  if (!tablet->pointer_info.focus)
+    return;
+
+  tablet_create_button_event_frame (tablet, GDK_BUTTON_RELEASE, GDK_BUTTON_PRIMARY);
+  tablet->pointer_info.button_modifiers &= ~GDK_BUTTON1_MASK;
+}
+
 static void
 tablet_tool_handle_motion (void                      *data,
                            struct zwp_tablet_tool_v1 *wp_tablet_tool,
@@ -3307,8 +3367,8 @@ static const struct zwp_tablet_tool_v1_listener tablet_tool_listener = {
   tablet_tool_handle_removed,
   tablet_tool_handle_proximity_in,
   tablet_tool_handle_proximity_out,
-  tablet_handler_placeholder, /* down */
-  tablet_handler_placeholder, /* up */
+  tablet_tool_handle_down,
+  tablet_tool_handle_up,
   tablet_tool_handle_motion,
   tablet_tool_handle_pressure,
   tablet_tool_handle_distance,