[mutter/wip/carlosg/im-forward-key] clutter: Add clutter_input_method_forward_key() method.



commit 6ec09487ac7d9dcac80679cf5a3629a9e863bee9
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu Sep 27 21:06:52 2018 +0200

    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 | 43 ++++++++++++++++++++++++++++++++++
 clutter/clutter/clutter-input-method.h |  8 +++++++
 2 files changed, 51 insertions(+)
---
diff --git a/clutter/clutter/clutter-input-method.c b/clutter/clutter/clutter-input-method.c
index 11d726d7b..8a43b8a98 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,45 @@ 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;
+
+  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__ */


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