]> git.eshelyaron.com Git - emacs.git/commitdiff
Correctly translate GDK virtual modifiers when using native input
authorPo Lu <luangruo@yahoo.com>
Sat, 8 Jan 2022 12:42:10 +0000 (20:42 +0800)
committerPo Lu <luangruo@yahoo.com>
Sat, 8 Jan 2022 12:44:47 +0000 (20:44 +0800)
* src/gtkutil.c (xg_virtual_mods_to_x): New function.
(xg_widget_key_press_event_cb): Translate modifiers to X first.

src/gtkutil.c

index f2362275147e8cfedb67cae034a3eb957c35b541..aaa2933f86eb66239df6f44228a1a5509a494389 100644 (file)
@@ -6024,6 +6024,27 @@ xg_add_virtual_mods (struct x_display_info *dpyinfo, GdkEventKey *key)
     key->state |= GDK_HYPER_MASK;
 }
 
+static unsigned int
+xg_virtual_mods_to_x (struct x_display_info *dpyinfo, guint virtual)
+{
+  unsigned int modifiers = virtual & ~(GDK_SUPER_MASK
+                                      | GDK_META_MASK
+                                      | GDK_HYPER_MASK
+                                      | GDK_MOD2_MASK
+                                      | GDK_MOD3_MASK
+                                      | GDK_MOD4_MASK
+                                      | GDK_MOD5_MASK);
+
+  if (virtual & GDK_META_MASK)
+    modifiers |= dpyinfo->meta_mod_mask;
+  if (virtual & GDK_SUPER_MASK)
+    modifiers |= dpyinfo->super_mod_mask;
+  if (virtual & GDK_HYPER_MASK)
+    modifiers |= dpyinfo->hyper_mod_mask;
+
+  return modifiers;
+}
+
 static void
 xg_im_context_commit (GtkIMContext *imc, gchar *str,
                      gpointer user_data)
@@ -6093,6 +6114,7 @@ xg_widget_key_press_event_cb (GtkWidget *widget, GdkEvent *event,
   struct frame *f = NULL;
   union buffered_input_event inev;
   guint keysym = event->key.keyval;
+  unsigned int xstate;
   gunichar *cb;
   ptrdiff_t i;
   glong len;
@@ -6117,8 +6139,11 @@ xg_widget_key_press_event_cb (GtkWidget *widget, GdkEvent *event,
   EVENT_INIT (inev.ie);
   XSETFRAME (inev.ie.frame_or_window, f);
 
-  inev.ie.modifiers |= x_x_to_emacs_modifiers (FRAME_DISPLAY_INFO (f),
-                                              event->key.state);
+  xstate = xg_virtual_mods_to_x (FRAME_DISPLAY_INFO (f),
+                                event->key.state);
+
+  inev.ie.modifiers
+    |= x_x_to_emacs_modifiers (FRAME_DISPLAY_INFO (f), xstate);
 
   /* First deal with keysyms which have defined
      translations to characters.  */