[mutter/wip/tablet-protocol-v2: 45/48] wayland: Implement zwp_tablet_pad.mode



commit bfc8ceb9ca6ad04b196c8ac36c3527181134e0fa
Author: Carlos Garnacho <carlosg gnome org>
Date:   Fri May 13 16:32:22 2016 +0200

    wayland: Implement zwp_tablet_pad.mode
    
    The current mode for a given pad is global in the compositor,
    this event must be emitted 1) whenever the current mode changes
    while the surface is focused and 2) after wp_tablet_pad.enter in
    order to notify of the current mode.

 src/wayland/meta-wayland-tablet-pad.c |   50 +++++++++++++++++++++++++++++++++
 src/wayland/meta-wayland-tablet-pad.h |    1 +
 2 files changed, 51 insertions(+), 0 deletions(-)
---
diff --git a/src/wayland/meta-wayland-tablet-pad.c b/src/wayland/meta-wayland-tablet-pad.c
index 8c938e9..3d6bca2 100644
--- a/src/wayland/meta-wayland-tablet-pad.c
+++ b/src/wayland/meta-wayland-tablet-pad.c
@@ -342,6 +342,50 @@ handle_pad_strip_event (MetaWaylandTabletPad *pad,
   return meta_wayland_tablet_pad_strip_handle_event (strip, event);
 }
 
+static void
+meta_wayland_tablet_pad_update_action (MetaWaylandTabletPad *pad,
+                                       const ClutterEvent   *event)
+{
+  if (event->type == CLUTTER_PAD_BUTTON_PRESS &&
+      event->pad_button.button == pad->mode_switch_button)
+    {
+      /* Switch current mode */
+      pad->current_mode = (pad->current_mode + 1) % pad->n_modes;
+    }
+}
+
+static void
+broadcast_pad_mode (MetaWaylandTabletPad *pad,
+                    uint32_t              time)
+{
+  struct wl_list *l = &pad->focus_resource_list;
+  struct wl_resource *resource;
+  struct wl_display *display = pad->tablet_seat->seat->wl_display;
+
+  pad->mode_switch_serial = wl_display_next_serial (display);
+
+  wl_resource_for_each (resource, l)
+    {
+      zwp_tablet_pad_v2_send_mode (resource, time,
+                                   pad->mode_switch_serial,
+                                   pad->current_mode);
+    }
+}
+
+static gboolean
+meta_wayland_tablet_pad_handle_event_action (MetaWaylandTabletPad *pad,
+                                             const ClutterEvent   *event)
+{
+  if (event->pad_button.button == pad->mode_switch_button)
+    {
+      if (event->type == CLUTTER_PAD_BUTTON_PRESS)
+        broadcast_pad_mode (pad, clutter_event_get_time (event));
+      return TRUE;
+    }
+
+  return FALSE;
+}
+
 gboolean
 meta_wayland_tablet_pad_handle_event (MetaWaylandTabletPad *pad,
                                       const ClutterEvent   *event)
@@ -350,6 +394,8 @@ meta_wayland_tablet_pad_handle_event (MetaWaylandTabletPad *pad,
     {
     case CLUTTER_PAD_BUTTON_PRESS:
     case CLUTTER_PAD_BUTTON_RELEASE:
+      if (meta_wayland_tablet_pad_handle_event_action (pad, event))
+        return TRUE;
       return handle_pad_button_event (pad, event);
     case CLUTTER_PAD_RING:
       return handle_pad_ring_event (pad, event);
@@ -464,6 +510,8 @@ meta_wayland_tablet_pad_set_focus (MetaWaylandTabletPad *pad,
                                             tablet_resource,
                                             pad->focus_surface->resource);
             }
+
+          broadcast_pad_mode (pad, clutter_get_current_event_time ());
         }
     }
 
@@ -479,6 +527,8 @@ meta_wayland_tablet_pad_update (MetaWaylandTabletPad *pad,
     {
     case CLUTTER_PAD_BUTTON_PRESS:
     case CLUTTER_PAD_BUTTON_RELEASE:
+      meta_wayland_tablet_pad_update_action (pad, event);
+      break;
     case CLUTTER_PAD_RING:
     case CLUTTER_PAD_STRIP:
     default:
diff --git a/src/wayland/meta-wayland-tablet-pad.h b/src/wayland/meta-wayland-tablet-pad.h
index e322664..269c6b8 100644
--- a/src/wayland/meta-wayland-tablet-pad.h
+++ b/src/wayland/meta-wayland-tablet-pad.h
@@ -44,6 +44,7 @@ struct _MetaWaylandTabletPad
   uint32_t n_modes;
   uint32_t current_mode;
   uint32_t mode_switch_button;
+  uint32_t mode_switch_serial;
 
   GList *strips;
   GList *rings;


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