[mutter/wip/dnd-actions: 143/144] wayland: Add MetaWaylandKeyboardGrab and keyboard grab API
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter/wip/dnd-actions: 143/144] wayland: Add MetaWaylandKeyboardGrab and keyboard grab API
- Date: Mon, 28 Sep 2015 14:32:07 +0000 (UTC)
commit ce78db31b7bd594ace216b7499ec3bcdfb5716a8
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 c4836cb..e0b5386 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");
@@ -672,3 +714,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 ea9db32..7750ba4 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;
};
@@ -100,4 +117,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 ba5b66e..bea5e20 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 _MetaWaylandDragDestFuncs MetaWaylandDragDestFuncs;
typedef struct _MetaWaylandDataOffer MetaWaylandDataOffer;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]