[mutter/wip/dnd-actions: 1/3] wayland: Add MetaWaylandKeyboardGrab and keyboard grab API



commit aa8f744cd5bfcc7a5dd6bc284d84c5b5fa7e70c4
Author: Carlos Garnacho <carlosg gnome org>
Date:   Tue Apr 7 15:54:41 2015 +0200

    wayland: Add MetaWaylandKeyboardGrab and keyboard grab API
    
    This will be useful during DnD, where mutter is expected to consume
    keyboard events for either allowing changes in the selected DnD action,
    or misc a11y features like keyboard-driven DnD.
    
    Currently, the vtable contains 2 functions, key() will be used on every
    key event we get from Clutter, modifiers() will notify of changes in the
    keyboard modifiers (mouse buttons will never be set in the modifier mask)

 src/wayland/meta-wayland-keyboard.c |   61 +++++++++++++++++++++++++++++++++-
 src/wayland/meta-wayland-keyboard.h |   22 ++++++++++++
 src/wayland/meta-wayland-types.h    |    2 +
 3 files changed, 83 insertions(+), 2 deletions(-)
---
diff --git a/src/wayland/meta-wayland-keyboard.c b/src/wayland/meta-wayland-keyboard.c
index e4d4f22..af1eba0 100644
--- a/src/wayland/meta-wayland-keyboard.c
+++ b/src/wayland/meta-wayland-keyboard.c
@@ -63,6 +63,7 @@
 
 static void meta_wayland_keyboard_update_xkb_state (MetaWaylandKeyboard *keyboard);
 static void notify_modifiers (MetaWaylandKeyboard *keyboard);
+static guint evdev_code (const ClutterKeyEvent *event);
 
 static void
 unbind_resource (struct wl_resource *resource)
@@ -264,7 +265,7 @@ notify_key (MetaWaylandKeyboard *keyboard,
 }
 
 static void
-notify_modifiers (MetaWaylandKeyboard *keyboard)
+apply_modifiers (MetaWaylandKeyboard *keyboard)
 {
   struct xkb_state *state;
   struct wl_resource *resource;
@@ -290,6 +291,16 @@ notify_modifiers (MetaWaylandKeyboard *keyboard)
 }
 
 static void
+notify_modifiers (MetaWaylandKeyboard *keyboard)
+{
+  struct xkb_state *state;
+
+  state = keyboard->xkb_info.state;
+  keyboard->grab->interface->modifiers (keyboard->grab,
+                                        xkb_state_serialize_mods (state, XKB_STATE_MODS_EFFECTIVE));
+}
+
+static void
 meta_wayland_keyboard_update_xkb_state (MetaWaylandKeyboard *keyboard)
 {
   MetaWaylandXkbInfo *xkb_info = &keyboard->xkb_info;
@@ -368,6 +379,33 @@ settings_changed (GSettings           *settings,
   notify_key_repeat (keyboard);
 }
 
+static gboolean
+default_grab_key (MetaWaylandKeyboardGrab *grab,
+                  const ClutterEvent      *event)
+{
+  MetaWaylandKeyboard *keyboard = grab->keyboard;
+  gboolean is_press = event->type == CLUTTER_KEY_PRESS;
+
+  /* Synthetic key events are for autorepeat. Ignore those, as
+   * autorepeat in Wayland is done on the client side. */
+  if (event->key.flags & CLUTTER_EVENT_FLAG_SYNTHETIC)
+    return FALSE;
+
+  return notify_key (keyboard, event->key.time, evdev_code (&event->key), is_press);
+}
+
+static void
+default_grab_modifiers (MetaWaylandKeyboardGrab *grab,
+                        ClutterModifierType      modifiers)
+{
+  apply_modifiers (grab->keyboard);
+}
+
+static const MetaWaylandKeyboardGrabInterface default_keyboard_grab_interface = {
+  default_grab_key,
+  default_grab_modifiers
+};
+
 void
 meta_wayland_keyboard_init (MetaWaylandKeyboard *keyboard,
                             struct wl_display   *display)
@@ -385,6 +423,10 @@ meta_wayland_keyboard_init (MetaWaylandKeyboard *keyboard,
 
   keyboard->xkb_info.keymap_fd = -1;
 
+  keyboard->default_grab.interface = &default_keyboard_grab_interface;
+  keyboard->default_grab.keyboard = keyboard;
+  keyboard->grab = &keyboard->default_grab;
+
   keyboard->settings = g_settings_new ("org.gnome.desktop.peripherals.keyboard");
   g_signal_connect (keyboard->settings, "changed",
                     G_CALLBACK (settings_changed), keyboard);
@@ -461,7 +503,7 @@ meta_wayland_keyboard_handle_event (MetaWaylandKeyboard *keyboard,
                is_press ? "press" : "release",
                event->hardware_keycode);
 
-  handled = notify_key (keyboard, event->time, evdev_code (event), is_press);
+  handled = keyboard->grab->interface->key (keyboard->grab, (const ClutterEvent *) event);
 
   if (handled)
     meta_verbose ("Sent event to wayland client\n");
@@ -644,3 +686,18 @@ meta_wayland_keyboard_create_new_resource (MetaWaylandKeyboard *keyboard,
       wl_list_insert (&keyboard->resource_list, wl_resource_get_link (cr));
     }
 }
+
+void
+meta_wayland_keyboard_start_grab (MetaWaylandKeyboard     *keyboard,
+                                  MetaWaylandKeyboardGrab *grab)
+{
+  meta_wayland_keyboard_set_focus (keyboard, NULL);
+  keyboard->grab = grab;
+  grab->keyboard = keyboard;
+}
+
+void
+meta_wayland_keyboard_end_grab (MetaWaylandKeyboard *keyboard)
+{
+  keyboard->grab = &keyboard->default_grab;
+}
diff --git a/src/wayland/meta-wayland-keyboard.h b/src/wayland/meta-wayland-keyboard.h
index b4a8c52..9eeedac 100644
--- a/src/wayland/meta-wayland-keyboard.h
+++ b/src/wayland/meta-wayland-keyboard.h
@@ -49,6 +49,20 @@
 #include <wayland-server.h>
 #include <xkbcommon/xkbcommon.h>
 
+struct _MetaWaylandKeyboardGrabInterface
+{
+  gboolean (* key)      (MetaWaylandKeyboardGrab *grab,
+                         const ClutterEvent      *event);
+  void     (*modifiers) (MetaWaylandKeyboardGrab *grab,
+                         ClutterModifierType      modifiers);
+};
+
+struct _MetaWaylandKeyboardGrab
+{
+  const MetaWaylandKeyboardGrabInterface *interface;
+  MetaWaylandKeyboard *keyboard;
+};
+
 typedef struct
 {
   struct xkb_keymap *keymap;
@@ -72,6 +86,9 @@ struct _MetaWaylandKeyboard
   MetaWaylandXkbInfo xkb_info;
   enum xkb_state_component mods_changed;
 
+  MetaWaylandKeyboardGrab *grab;
+  MetaWaylandKeyboardGrab default_grab;
+
   GSettings *settings;
 };
 
@@ -96,4 +113,9 @@ void meta_wayland_keyboard_create_new_resource (MetaWaylandKeyboard *keyboard,
                                                 struct wl_resource  *seat_resource,
                                                 uint32_t id);
 
+void meta_wayland_keyboard_start_grab (MetaWaylandKeyboard     *keyboard,
+                                       MetaWaylandKeyboardGrab *grab);
+void meta_wayland_keyboard_end_grab   (MetaWaylandKeyboard     *keyboard);
+
+
 #endif /* META_WAYLAND_KEYBOARD_H */
diff --git a/src/wayland/meta-wayland-types.h b/src/wayland/meta-wayland-types.h
index 9713f1e..5165a76 100644
--- a/src/wayland/meta-wayland-types.h
+++ b/src/wayland/meta-wayland-types.h
@@ -29,6 +29,8 @@ typedef struct _MetaWaylandPointerGrabInterface MetaWaylandPointerGrabInterface;
 typedef struct _MetaWaylandPopupGrab MetaWaylandPopupGrab;
 typedef struct _MetaWaylandPopup MetaWaylandPopup;
 typedef struct _MetaWaylandKeyboard MetaWaylandKeyboard;
+typedef struct _MetaWaylandKeyboardGrab MetaWaylandKeyboardGrab;
+typedef struct _MetaWaylandKeyboardGrabInterface MetaWaylandKeyboardGrabInterface;
 typedef struct _MetaWaylandTouch MetaWaylandTouch;
 typedef struct _MetaWaylandDataSource MetaWaylandDataSource;
 typedef struct _MetaWaylandDataDevice MetaWaylandDataDevice;


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