Merge branch 'win32-fix-altgr-gtk4' into 'main'

IMContextSimple/IMContextIME: Fix AltGr not working on Win32 [GTK4]

See merge request GNOME/gtk!4375
This commit is contained in:
Luca Bacci 2022-01-13 23:02:50 +00:00
commit 06e5da456f
3 changed files with 32 additions and 9 deletions

View File

@ -1772,10 +1772,11 @@ gdk_event_translate (MSG *msg,
int i; int i;
GdkModifierType state; GdkModifierType state, consumed_modifiers;
guint keyval; guint keyval;
guint16 keycode; guint16 keycode;
guint8 group; guint8 group;
int level;
gboolean is_modifier; gboolean is_modifier;
double delta_x, delta_y; double delta_x, delta_y;
@ -2003,6 +2004,10 @@ gdk_event_translate (MSG *msg,
{ {
keyval = gdk_unicode_to_keyval (wbuf[0]); keyval = gdk_unicode_to_keyval (wbuf[0]);
} }
/* TODO: What values to use for level and consumed_modifiers? */
level = 0;
consumed_modifiers = 0;
} }
else else
{ {
@ -2011,7 +2016,7 @@ gdk_event_translate (MSG *msg,
state, state,
group, group,
&keyval, &keyval,
NULL, NULL, NULL); NULL, &level, &consumed_modifiers);
} }
if (msg->message == WM_KEYDOWN) if (msg->message == WM_KEYDOWN)
@ -2055,11 +2060,11 @@ gdk_event_translate (MSG *msg,
if (msg->wParam == VK_MENU) if (msg->wParam == VK_MENU)
state &= ~GDK_ALT_MASK; state &= ~GDK_ALT_MASK;
/* FIXME do proper translation */
translated.keyval = keyval; translated.keyval = keyval;
translated.consumed = 0; translated.consumed = consumed_modifiers;
translated.layout = group; translated.layout = group;
translated.level = 0; translated.level = level;
event = gdk_key_event_new ((msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN) event = gdk_key_event_new ((msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN)
? GDK_KEY_PRESS ? GDK_KEY_PRESS
: GDK_KEY_RELEASE, : GDK_KEY_RELEASE,

View File

@ -344,7 +344,7 @@ gtk_im_context_ime_filter_keypress (GtkIMContext *context,
GtkIMContextIME *context_ime; GtkIMContextIME *context_ime;
gboolean retval = FALSE; gboolean retval = FALSE;
guint32 c; guint32 c;
GdkModifierType state; GdkModifierType state, consumed_modifiers, no_text_input_mask;
guint keyval; guint keyval;
g_return_val_if_fail (GTK_IS_IM_CONTEXT_IME (context), FALSE); g_return_val_if_fail (GTK_IS_IM_CONTEXT_IME (context), FALSE);
@ -353,9 +353,12 @@ gtk_im_context_ime_filter_keypress (GtkIMContext *context,
if (gdk_event_get_event_type ((GdkEvent *) event) == GDK_KEY_RELEASE) if (gdk_event_get_event_type ((GdkEvent *) event) == GDK_KEY_RELEASE)
return FALSE; return FALSE;
state = gdk_event_get_modifier_state ((GdkEvent *) event); no_text_input_mask = GDK_ALT_MASK|GDK_CONTROL_MASK;
if (state & GDK_CONTROL_MASK) state = gdk_event_get_modifier_state ((GdkEvent *) event);
consumed_modifiers = gdk_key_event_get_consumed_modifiers (event);
if (state & no_text_input_mask & ~consumed_modifiers)
return FALSE; return FALSE;
context_ime = GTK_IM_CONTEXT_IME (context); context_ime = GTK_IM_CONTEXT_IME (context);

View File

@ -901,9 +901,24 @@ gtk_im_context_simple_filter_keypress (GtkIMContext *context,
!is_hex_start && !is_hex_end && !is_escape && !is_backspace)) !is_hex_start && !is_hex_end && !is_escape && !is_backspace))
{ {
GdkModifierType no_text_input_mask; GdkModifierType no_text_input_mask;
GdkModifierType consumed_modifiers = 0;
no_text_input_mask = GDK_ALT_MASK|GDK_CONTROL_MASK; no_text_input_mask = GDK_ALT_MASK|GDK_CONTROL_MASK;
#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.
*/
consumed_modifiers = gdk_key_event_get_consumed_modifiers (event);
#endif
if (priv->in_hex_sequence && priv->modifiers_dropped && if (priv->in_hex_sequence && priv->modifiers_dropped &&
(keyval == GDK_KEY_Return || (keyval == GDK_KEY_Return ||
keyval == GDK_KEY_ISO_Enter || keyval == GDK_KEY_ISO_Enter ||
@ -912,7 +927,7 @@ gtk_im_context_simple_filter_keypress (GtkIMContext *context,
return FALSE; return FALSE;
} }
if (state & no_text_input_mask) if (state & no_text_input_mask & ~consumed_modifiers)
{ {
if (priv->in_hex_sequence || priv->in_compose_sequence) if (priv->in_hex_sequence || priv->in_compose_sequence)
return TRUE; /* Don't leak random key events during preedit */ return TRUE; /* Don't leak random key events during preedit */