Signed-off-by: Stephen Chandler Paul <thatsly...@gmail.com>
---
 src/compositor.h      |  6 ++++++
 src/input.c           | 39 ++++++++++++++++++++++++++++++++++++++-
 src/libinput-device.c | 23 +++++++++++++++++++++++
 3 files changed, 67 insertions(+), 1 deletion(-)

diff --git a/src/compositor.h b/src/compositor.h
index 46619e3..f1e4353 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -418,12 +418,15 @@ struct weston_tablet {
        struct wl_listener focus_view_listener;
        struct wl_listener focus_resource_listener;
        uint32_t focus_serial;
+       uint32_t grab_serial;
 
        struct weston_tablet_tool *current_tool;
 
        int32_t hotspot_x, hotspot_y;
        wl_fixed_t x, y;
 
+       int button_count;
+
        struct weston_view *sprite;
        struct wl_listener sprite_destroy_listener;
 
@@ -1122,6 +1125,9 @@ void
 notify_tablet_motion(struct weston_tablet *tablet, uint32_t time,
                     wl_fixed_t x, wl_fixed_t y);
 void
+notify_tablet_button(struct weston_tablet *tablet, uint32_t time,
+                    uint32_t button, enum wl_tablet_button_state state);
+void
 notify_tablet_frame(struct weston_tablet *tablet);
 
 void
diff --git a/src/input.c b/src/input.c
index 19e9971..87e4dd9 100644
--- a/src/input.c
+++ b/src/input.c
@@ -481,6 +481,22 @@ default_grab_tablet_motion(struct weston_tablet_grab *grab,
 }
 
 static void
+default_grab_tablet_button(struct weston_tablet_grab *grab,
+                          uint32_t time, uint32_t button,
+                          enum wl_tablet_button_state state)
+{
+       struct weston_tablet *tablet = grab->tablet;
+       struct wl_resource *resource;
+       struct wl_list *resource_list = &tablet->focus_resource_list;
+
+       if (!wl_list_empty(resource_list)) {
+               wl_resource_for_each(resource, resource_list)
+                       wl_tablet_send_button(resource, tablet->grab_serial,
+                                             time, button, state);
+       }
+}
+
+static void
 default_grab_tablet_frame(struct weston_tablet_grab *grab)
 {
        struct wl_resource *resource;
@@ -507,7 +523,7 @@ static struct weston_tablet_grab_interface 
default_tablet_grab_interface = {
        NULL,
        NULL,
        NULL,
-       NULL,
+       default_grab_tablet_button,
        default_grab_tablet_frame,
        default_grab_tablet_cancel,
 };
@@ -1865,6 +1881,27 @@ notify_tablet_frame(struct weston_tablet *tablet)
        grab->interface->frame(grab);
 }
 
+WL_EXPORT void
+notify_tablet_button(struct weston_tablet *tablet, uint32_t time,
+                    uint32_t button, enum wl_tablet_button_state state)
+{
+       struct weston_tablet_grab *grab = tablet->grab;
+       struct weston_compositor *compositor = tablet->seat->compositor;
+
+       if (state == WL_TABLET_BUTTON_STATE_PRESSED) {
+               tablet->button_count++;
+               if (tablet->button_count == 1)
+                       weston_compositor_idle_inhibit(compositor);
+       } else {
+               tablet->button_count--;
+               if (tablet->button_count == 0)
+                       weston_compositor_idle_release(compositor);
+       }
+
+       tablet->grab_serial = wl_display_next_serial(compositor->wl_display);
+       grab->interface->button(grab, time, button, state);
+}
+
 static void
 pointer_cursor_surface_configure(struct weston_surface *es,
                                 int32_t dx, int32_t dy)
diff --git a/src/libinput-device.c b/src/libinput-device.c
index 0501e9b..2e913bd 100644
--- a/src/libinput-device.c
+++ b/src/libinput-device.c
@@ -331,6 +331,25 @@ handle_tablet_proximity_out(struct libinput_device 
*libinput_device,
        notify_tablet_proximity_out(tablet, time);
 }
 
+static void
+handle_tablet_button(struct libinput_device *libinput_device,
+                    struct libinput_event_tablet *button_event)
+{
+       struct evdev_device *device =
+               libinput_device_get_user_data(libinput_device);
+       struct weston_tablet *tablet = device->tablet;
+       uint32_t button, time;
+       enum wl_tablet_button_state state;
+
+       time = libinput_event_tablet_get_time(button_event);
+       button = libinput_event_tablet_get_button(button_event);
+       state = (enum wl_tablet_button_state)
+               libinput_event_tablet_get_button_state(button_event);
+
+       if (button != BTN_TOUCH)
+               notify_tablet_button(tablet, time, button, state);
+}
+
 int
 evdev_device_process_event(struct libinput_event *event)
 {
@@ -389,6 +408,10 @@ evdev_device_process_event(struct libinput_event *event)
                    libinput_device,
                    libinput_event_get_tablet_event(event));
                break;
+       case LIBINPUT_EVENT_TABLET_BUTTON:
+               handle_tablet_button(libinput_device,
+                                    libinput_event_get_tablet_event(event));
+               break;
        default:
                handled = 0;
                weston_log("unknown libinput event %d\n",
-- 
1.8.5.5

_______________________________________________
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/wayland-devel

Reply via email to