From: Po Lu Date: Tue, 4 Jan 2022 11:30:07 +0000 (+0800) Subject: Stop assuming X kbd state works with GDK when forwarding events to xwidgets X-Git-Tag: emacs-29.0.90~3261 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=377bf26ebe292d16b26043c566a7c00c452caf27;p=emacs.git Stop assuming X kbd state works with GDK when forwarding events to xwidgets * src/xwidget.c (xw_translate_x_modifiers): New function. (Fxwidget_perform_lispy_event): Translate X modifiers to GDK modifiers before sending them to the xwidget. --- diff --git a/src/xwidget.c b/src/xwidget.c index 3df208034b8..bfb666e5654 100644 --- a/src/xwidget.c +++ b/src/xwidget.c @@ -222,6 +222,34 @@ xw_forward_event_from_view (GtkWidget *widget, GdkEvent *event, } #endif +#ifdef HAVE_X_WINDOWS +static guint +xw_translate_x_modifiers (struct x_display_info *dpyinfo, + unsigned int modifiers) +{ + guint mods = 0; + + if (modifiers & dpyinfo->meta_mod_mask) + { + /* GDK always assumes Mod1 is alt, but that's no reason for + us to make that mistake as well. */ + if (!dpyinfo->alt_mod_mask) + mods |= GDK_MOD1_MASK; + else + mods |= GDK_META_MASK; + } + + if (modifiers & dpyinfo->alt_mod_mask) + mods |= GDK_MOD1_MASK; + if (modifiers & dpyinfo->super_mod_mask) + mods |= GDK_SUPER_MASK; + if (modifiers & dpyinfo->hyper_mod_mask) + mods |= GDK_HYPER_MASK; + + return mods; +} +#endif + DEFUN ("make-xwidget", Fmake_xwidget, Smake_xwidget, 4, 7, 0, @@ -563,7 +591,13 @@ selected frame is not an X-Windows frame. */) keycode = gdk_unicode_to_keyval (character); xg_event->key.keyval = keycode; +#ifndef HAVE_X_WINDOWS xg_event->key.state = modifiers; +#else + if (f) + xg_event->key.state = xw_translate_x_modifiers (FRAME_DISPLAY_INFO (f), + modifiers); +#endif if (keycode > -1) {