From b79e74f13fb3e94e24596fc056809bc997dc4b86 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Thu, 27 Sep 2018 21:06:52 +0200 Subject: [PATCH] clutter: Add clutter_input_method_forward_key() method. This allows input methods to inject key events with specific keyval/keycode, those events will be flagged with CLUTTER_EVENT_FLAG_INPUT_METHOD so they won't be processed by the IM again. https://gitlab.gnome.org/GNOME/gnome-shell/issues/531 --- clutter/clutter/clutter-input-method.c | 44 ++++++++++++++++++++++++++ clutter/clutter/clutter-input-method.h | 8 +++++ 2 files changed, 52 insertions(+) diff --git a/clutter/clutter/clutter-input-method.c b/clutter/clutter/clutter-input-method.c index 11d726d7b..cb5364b21 100644 --- a/clutter/clutter/clutter-input-method.c +++ b/clutter/clutter/clutter-input-method.c @@ -25,6 +25,7 @@ #include "clutter/clutter-input-method.h" #include "clutter/clutter-input-method-private.h" #include "clutter/clutter-input-focus-private.h" +#include "clutter/clutter-device-manager-private.h" typedef struct _ClutterInputMethodPrivate ClutterInputMethodPrivate; @@ -442,3 +443,46 @@ clutter_input_method_filter_key_event (ClutterInputMethod *im, return im_class->filter_key_event (im, (const ClutterEvent *) key); } + +void +clutter_input_method_forward_key (ClutterInputMethod *im, + uint32_t keyval, + uint32_t keycode, + uint32_t state, + uint64_t time_, + gboolean press) +{ + ClutterInputMethodPrivate *priv; + ClutterDeviceManager *device_manager; + ClutterInputDevice *keyboard; + ClutterStage *stage; + ClutterEvent *event; + + g_return_if_fail (CLUTTER_IS_INPUT_METHOD (im)); + + priv = clutter_input_method_get_instance_private (im); + if (!priv->focus) + return; + + device_manager = clutter_device_manager_get_default (); + keyboard = clutter_device_manager_get_core_device (device_manager, + CLUTTER_KEYBOARD_DEVICE); + stage = _clutter_input_device_get_stage (keyboard); + if (stage == NULL) + return; + + event = clutter_event_new (press ? CLUTTER_KEY_PRESS : CLUTTER_KEY_RELEASE); + event->key.time = time_; + event->key.flags = CLUTTER_EVENT_FLAG_INPUT_METHOD; + event->key.modifier_state = state; + event->key.keyval = keyval; + event->key.hardware_keycode = keycode; + event->key.unicode_value = clutter_keysym_to_unicode (keyval); + + clutter_event_set_device (event, keyboard); + clutter_event_set_source_device (event, keyboard); + clutter_event_set_stage (event, stage); + + clutter_event_put (event); + clutter_event_free (event); +} diff --git a/clutter/clutter/clutter-input-method.h b/clutter/clutter/clutter-input-method.h index d37522d14..3aa549e24 100644 --- a/clutter/clutter/clutter-input-method.h +++ b/clutter/clutter/clutter-input-method.h @@ -85,4 +85,12 @@ void clutter_input_method_notify_key_event (ClutterInputMethod *im, CLUTTER_AVAILABLE_IN_MUTTER void clutter_input_method_request_toggle_input_panel (ClutterInputMethod *im); +CLUTTER_AVAILABLE_IN_MUTTER +void clutter_input_method_forward_key (ClutterInputMethod *im, + uint32_t keyval, + uint32_t keycode, + uint32_t state, + uint64_t time_, + gboolean press); + #endif /* __CLUTTER_INPUT_METHOD_H__ */