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
This commit is contained in:
Carlos Garnacho 2018-09-27 21:06:52 +02:00 committed by Carlos Garnacho
parent 2e18f6d793
commit df94a18791
2 changed files with 52 additions and 0 deletions

View File

@ -25,6 +25,7 @@
#include "clutter/clutter-input-method.h" #include "clutter/clutter-input-method.h"
#include "clutter/clutter-input-method-private.h" #include "clutter/clutter-input-method-private.h"
#include "clutter/clutter-input-focus-private.h" #include "clutter/clutter-input-focus-private.h"
#include "clutter/clutter-device-manager-private.h"
typedef struct _ClutterInputMethodPrivate ClutterInputMethodPrivate; 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); 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);
}

View File

@ -85,4 +85,12 @@ void clutter_input_method_notify_key_event (ClutterInputMethod *im,
CLUTTER_AVAILABLE_IN_MUTTER CLUTTER_AVAILABLE_IN_MUTTER
void clutter_input_method_request_toggle_input_panel (ClutterInputMethod *im); 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__ */ #endif /* __CLUTTER_INPUT_METHOD_H__ */