mirror of
https://github.com/brl/mutter.git
synced 2025-02-16 13:24:09 +00:00
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)
This commit is contained in:
parent
15513adcc3
commit
ce78db31b7
@ -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;
|
||||
@ -289,6 +290,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)
|
||||
{
|
||||
@ -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;
|
||||
}
|
||||
|
@ -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 */
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user