Merge branch 'fix-keyboard-shortcuts-win32' into 'main'

Win32 key events cleanup

See merge request GNOME/gtk!4349
This commit is contained in:
Luca Bacci 2022-01-17 13:34:17 +00:00
commit 93bc97b7ec
4 changed files with 307 additions and 278 deletions

View File

@ -1740,16 +1740,12 @@ gdk_event_translate (MSG *msg,
POINT point;
MINMAXINFO *mmi;
HWND hwnd;
BYTE key_state[256];
HIMC himc;
WINDOWPOS *windowpos;
gboolean ignore_leave;
GdkEvent *event;
wchar_t wbuf[100];
int ccount;
GdkDisplay *display;
GdkSurface *window = NULL;
GdkWin32Surface *impl;
@ -1767,21 +1763,12 @@ gdk_event_translate (MSG *msg,
int button;
char buf[256];
gboolean return_val = FALSE;
int i;
GdkModifierType state, consumed_modifiers;
guint keyval;
guint16 keycode;
guint8 group;
int level;
gboolean is_modifier;
double delta_x, delta_y;
GdkScrollDirection direction;
GdkTranslatedKey translated;
display = gdk_display_get_default ();
win32_display = GDK_WIN32_DISPLAY (display);
@ -1840,18 +1827,21 @@ gdk_event_translate (MSG *msg,
switch (msg->message)
{
case WM_INPUTLANGCHANGE:
{
GdkWin32Keymap *win32_keymap;
GdkTranslatedKey translated;
win32_keymap = GDK_WIN32_KEYMAP (_gdk_win32_display_get_keymap (_gdk_display));
_gdk_input_locale = (HKL) msg->lParam;
_gdk_win32_keymap_set_active_layout (GDK_WIN32_KEYMAP (_gdk_win32_display_get_keymap (_gdk_display)), _gdk_input_locale);
GetLocaleInfo (MAKELCID (LOWORD (_gdk_input_locale), SORT_DEFAULT),
LOCALE_IDEFAULTANSICODEPAGE,
buf, sizeof (buf));
_gdk_input_codepage = atoi (buf);
_gdk_win32_keymap_set_active_layout (win32_keymap, _gdk_input_locale);
_gdk_keymap_serial++;
GDK_NOTE (EVENTS,
g_print (" cs:%lu hkl:%p%s cp:%d",
g_print (" cs:%lu hkl:%p%s",
(gulong) msg->wParam,
(gpointer) msg->lParam, _gdk_input_locale_is_ime ? " (IME)" : "",
_gdk_input_codepage));
(gpointer) msg->lParam,
_gdk_input_locale_is_ime ? " (IME)" : ""));
gdk_display_setting_changed (display, "gtk-im-module");
/* Generate a dummy key event to "nudge" IMContext */
@ -1869,6 +1859,7 @@ gdk_event_translate (MSG *msg,
&translated,
&translated);
_gdk_win32_append_event (event);
}
break;
case WM_SYSKEYUP:
@ -1905,10 +1896,21 @@ gdk_event_translate (MSG *msg,
decode_key_lparam (msg->lParam)));
keyup_or_down:
{
GdkWin32Keymap *win32_keymap;
GdkModifierType state;
guint keyval;
guint16 keycode;
guint8 group;
gboolean is_modifier;
GdkTranslatedKey translated;
GdkTranslatedKey no_lock;
BYTE key_state[256];
wchar_t wbuf[100];
int ccount = 0;
/* Ignore key messages intended for the IME */
if (msg->wParam == VK_PROCESSKEY ||
in_ime_composition)
if (msg->wParam == VK_PROCESSKEY || in_ime_composition)
break;
/* Ignore autorepeats on modifiers */
@ -1922,6 +1924,7 @@ gdk_event_translate (MSG *msg,
if (GDK_SURFACE_DESTROYED (window))
break;
win32_keymap = GDK_WIN32_KEYMAP (_gdk_win32_display_get_keymap (display));
impl = GDK_WIN32_SURFACE (window);
API_CALL (GetKeyboardState, (key_state));
@ -1972,13 +1975,12 @@ gdk_event_translate (MSG *msg,
}
}
else if (msg->wParam == VK_SHIFT &&
LOBYTE (HIWORD (msg->lParam)) == _gdk_win32_keymap_get_rshift_scancode (GDK_WIN32_KEYMAP (_gdk_win32_display_get_keymap (_gdk_display))))
LOBYTE (HIWORD (msg->lParam)) == _gdk_win32_keymap_get_rshift_scancode (win32_keymap))
keycode = VK_RSHIFT;
is_modifier = (msg->wParam == VK_CONTROL ||
msg->wParam == VK_SHIFT ||
msg->wParam == VK_MENU);
/* g_print ("ctrl:%02x lctrl:%02x rctrl:%02x alt:%02x lalt:%02x ralt:%02x\n", key_state[VK_CONTROL], key_state[VK_LCONTROL], key_state[VK_RCONTROL], key_state[VK_MENU], key_state[VK_LMENU], key_state[VK_RMENU]); */
state = build_key_event_state (key_state);
group = get_active_group ();
@ -2005,18 +2007,33 @@ gdk_event_translate (MSG *msg,
keyval = gdk_unicode_to_keyval (wbuf[0]);
}
/* TODO: What values to use for level and consumed_modifiers? */
level = 0;
consumed_modifiers = 0;
translated.keyval = keyval;
translated.consumed = 0;
translated.layout = 0;
translated.level = 0;
no_lock = translated;
}
else
{
gdk_keymap_translate_keyboard_state (_gdk_win32_display_get_keymap (display),
keycode,
state,
group,
&keyval,
NULL, &level, &consumed_modifiers);
int level = 0;
int effective_group = 0;
GdkModifierType consumed = 0;
gdk_keymap_translate_keyboard_state ((GdkKeymap*) win32_keymap, keycode, state, group,
&keyval, &effective_group, &level, &consumed);
translated.keyval = keyval;
translated.consumed = consumed;
translated.layout = effective_group;
translated.level = level;
gdk_keymap_translate_keyboard_state ((GdkKeymap*) win32_keymap, keycode,
state & ~GDK_LOCK_MASK, group, &keyval,
&effective_group, &level, &consumed);
no_lock.keyval = keyval;
no_lock.consumed = consumed;
no_lock.layout = effective_group;
no_lock.level = level;
}
if (msg->message == WM_KEYDOWN)
@ -2060,11 +2077,6 @@ gdk_event_translate (MSG *msg,
if (msg->wParam == VK_MENU)
state &= ~GDK_ALT_MASK;
translated.keyval = keyval;
translated.consumed = consumed_modifiers;
translated.layout = group;
translated.level = level;
event = gdk_key_event_new ((msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN)
? GDK_KEY_PRESS
: GDK_KEY_RELEASE,
@ -2075,11 +2087,12 @@ gdk_event_translate (MSG *msg,
state,
is_modifier,
&translated,
&translated);
&no_lock);
_gdk_win32_append_event (event);
return_val = TRUE;
}
break;
case WM_SYSCHAR:
@ -2100,6 +2113,11 @@ gdk_event_translate (MSG *msg,
break;
case WM_IME_COMPOSITION:
{
BYTE key_state[256];
wchar_t wbuf[100];
int ccount = 0;
/* On Win2k WM_IME_CHAR doesn't work correctly for non-Unicode
* applications. Thus, handle WM_IME_COMPOSITION with
* GCS_RESULTSTR instead, fetch the Unicode chars from the IME
@ -2136,6 +2154,8 @@ gdk_event_translate (MSG *msg,
for (i = 0; i < ccount; i++)
{
GdkTranslatedKey translated;
/* Build a key press event */
translated.keyval = gdk_unicode_to_keyval (wbuf[i]);
translated.consumed = 0;
@ -2166,7 +2186,9 @@ gdk_event_translate (MSG *msg,
_gdk_win32_append_event (event);
}
return_val = TRUE;
}
break;
case WM_LBUTTONDOWN:
@ -2963,6 +2985,9 @@ gdk_event_translate (MSG *msg,
break;
case WM_WINDOWPOSCHANGING:
#ifdef G_ENABLE_DEBUG
{
char buf[256];
GDK_NOTE (EVENTS, (windowpos = (WINDOWPOS *) msg->lParam,
g_print (" %s %s %dx%d@%+d%+d now below %p",
_gdk_win32_surface_pos_bits_to_string (windowpos->flags),
@ -2974,6 +2999,8 @@ gdk_event_translate (MSG *msg,
buf))))),
windowpos->cx, windowpos->cy, windowpos->x, windowpos->y,
GetNextWindow (msg->hwnd, GW_HWNDPREV))));
}
#endif
if (GDK_SURFACE_IS_MAPPED (window))
{
@ -2999,6 +3026,10 @@ gdk_event_translate (MSG *msg,
case WM_WINDOWPOSCHANGED:
windowpos = (WINDOWPOS *) msg->lParam;
#ifdef G_ENABLE_DEBUG
{
char buf[256];
GDK_NOTE (EVENTS, g_print (" %s %s %dx%d@%+d%+d",
_gdk_win32_surface_pos_bits_to_string (windowpos->flags),
(windowpos->hwndInsertAfter == HWND_BOTTOM ? "BOTTOM" :
@ -3008,6 +3039,8 @@ gdk_event_translate (MSG *msg,
(sprintf (buf, "%p", windowpos->hwndInsertAfter),
buf))))),
windowpos->cx, windowpos->cy, windowpos->x, windowpos->y));
}
#endif
/* Break grabs on unmap or minimize */
if (windowpos->flags & SWP_HIDEWINDOW ||

View File

@ -38,7 +38,6 @@ int _gdk_input_ignore_core;
HKL _gdk_input_locale;
gboolean _gdk_input_locale_is_ime = FALSE;
UINT _gdk_input_codepage;
GdkWin32ModalOpKind _modal_operation_in_progress = GDK_WIN32_MODAL_OP_NONE;
HWND _modal_move_resize_window = NULL;

View File

@ -52,7 +52,9 @@ static gboolean gdk_synchronize = FALSE;
void
_gdk_win32_surfaceing_init (void)
{
char buf[10];
GdkWin32Keymap *win32_keymap;
win32_keymap = GDK_WIN32_KEYMAP (_gdk_win32_display_get_keymap (_gdk_display));
if (gdk_synchronize)
GdiSetBatchLimit (1);
@ -60,13 +62,9 @@ _gdk_win32_surfaceing_init (void)
_gdk_app_hmodule = GetModuleHandle (NULL);
_gdk_display_hdc = CreateDC ("DISPLAY", NULL, NULL, NULL);
_gdk_input_locale = GetKeyboardLayout (0);
_gdk_win32_keymap_set_active_layout (GDK_WIN32_KEYMAP (_gdk_win32_display_get_keymap (_gdk_display)), _gdk_input_locale);
GetLocaleInfo (MAKELCID (LOWORD (_gdk_input_locale), SORT_DEFAULT),
LOCALE_IDEFAULTANSICODEPAGE,
buf, sizeof (buf));
_gdk_input_codepage = atoi (buf);
GDK_NOTE (EVENTS, g_print ("input_locale:%p, codepage:%d\n",
_gdk_input_locale, _gdk_input_codepage));
_gdk_win32_keymap_set_active_layout (win32_keymap, _gdk_input_locale);
GDK_NOTE (EVENTS, g_print ("input_locale: %p\n", _gdk_input_locale));
_gdk_win32_clipdrop_init ();
}

View File

@ -269,7 +269,6 @@ extern int _gdk_input_ignore_core;
*/
extern HKL _gdk_input_locale;
extern gboolean _gdk_input_locale_is_ime;
extern UINT _gdk_input_codepage;
extern guint _gdk_keymap_serial;