IMContextSimple: Fix AltGr not working on Win32

The old code assumed that any key press containing Ctrl or Alt cannot be
regular text input. This is not correct on Win32 as AltGr = Ctrl + Alt.
This commit is contained in:
Philip Zander 2022-01-13 13:43:23 +01:00
parent 84386c6466
commit f03bf55688

View File

@ -686,6 +686,7 @@ gtk_im_context_simple_filter_keypress (GtkIMContext *context,
GtkIMContextSimple *context_simple = GTK_IM_CONTEXT_SIMPLE (context);
GtkIMContextSimplePrivate *priv = context_simple->priv;
GdkDisplay *display = gdk_window_get_display (event->window);
GdkKeymap *keymap = gdk_keymap_get_for_display (display);
GSList *tmp_list;
int n_compose = 0;
GdkModifierType hex_mod_mask;
@ -787,11 +788,28 @@ gtk_im_context_simple_filter_keypress (GtkIMContext *context,
!is_hex_start && !is_hex_end && !is_escape && !is_backspace))
{
GdkModifierType no_text_input_mask;
GdkModifierType consumed_modifiers = 0;
no_text_input_mask =
gdk_keymap_get_modifier_mask (gdk_keymap_get_for_display (display),
gdk_keymap_get_modifier_mask (keymap,
GDK_MODIFIER_INTENT_NO_TEXT_INPUT);
#ifdef G_OS_WIN32
/* On Win32, even Ctrl + Alt could be text input because AltGr = Ctrl
* + Alt. For example, Ctrl + Alt + e = on a German keyboard. The
* GdkEvent's state, however, reports *all* modifiers that were
* active at the time the key was pressed, including the ones that
* were consumed to generate the keyval. So we cannot just assume
* that any key event containing Ctrl or Alt is a keybinding. We have
* to first check if those modifiers were actually used to generate
* the keyval. If so, then the keypress is regular input and we
* should not exit here.
*/
gdk_keymap_translate_keyboard_state (keymap, event->hardware_keycode,
event->state, event->group, NULL,
NULL, NULL, &consumed_modifiers);
#endif
if (priv->in_hex_sequence && priv->modifiers_dropped &&
(event->keyval == GDK_KEY_Return ||
event->keyval == GDK_KEY_ISO_Enter ||
@ -800,7 +818,7 @@ gtk_im_context_simple_filter_keypress (GtkIMContext *context,
return FALSE;
}
if (event->state & no_text_input_mask)
if (event->state & no_text_input_mask & ~consumed_modifiers)
{
if (priv->in_hex_sequence || priv->in_compose_sequence)
return TRUE; /* Don't leak random key events during preedit */