From 534aff4a6307cd289746c993aed2c2a70be8f57b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Bernon?= Date: Thu, 20 Jun 2024 23:59:52 +0200 Subject: [PATCH] server: Use a separate variable to determine the message on Alt release. Based on a patch by Huw Davies. --- server/queue.c | 11 +++++------ server/user.h | 1 + server/winstation.c | 1 + 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/server/queue.c b/server/queue.c index 1a98714004c..c17446a1dd9 100644 --- a/server/queue.c +++ b/server/queue.c @@ -2171,17 +2171,16 @@ static int queue_keyboard_message( struct desktop *desktop, user_handle_t win, c if (input->kbd.flags & KEYEVENTF_KEYUP) { /* send WM_SYSKEYUP if Alt still pressed and no other key in between */ - /* we use 0x02 as a flag to track if some other SYSKEYUP was sent already */ - if ((desktop->keystate[VK_MENU] & 0x82) != 0x82) break; + if (!(desktop->keystate[VK_MENU] & 0x80) || !desktop->alt_pressed) break; message_code = WM_SYSKEYUP; - desktop->keystate[VK_MENU] &= ~0x02; + desktop->alt_pressed = 0; } else { /* send WM_SYSKEYDOWN for Alt except with Ctrl */ if (desktop->keystate[VK_CONTROL] & 0x80) break; message_code = WM_SYSKEYDOWN; - desktop->keystate[VK_MENU] |= 0x02; + desktop->alt_pressed = 1; } break; @@ -2191,7 +2190,7 @@ static int queue_keyboard_message( struct desktop *desktop, user_handle_t win, c if (!(input->kbd.flags & KEYEVENTF_KEYUP)) break; if (!(desktop->keystate[VK_MENU] & 0x80)) break; message_code = WM_SYSKEYUP; - desktop->keystate[VK_MENU] &= ~0x02; + desktop->alt_pressed = 0; break; default: @@ -2201,7 +2200,7 @@ static int queue_keyboard_message( struct desktop *desktop, user_handle_t win, c /* fall through */ case VK_F10: message_code = (input->kbd.flags & KEYEVENTF_KEYUP) ? WM_SYSKEYUP : WM_SYSKEYDOWN; - desktop->keystate[VK_MENU] &= ~0x02; + desktop->alt_pressed = 0; break; } diff --git a/server/user.h b/server/user.h index 7355177e13d..99491293a7c 100644 --- a/server/user.h +++ b/server/user.h @@ -81,6 +81,7 @@ struct desktop struct thread_input *foreground_input; /* thread input of foreground thread */ unsigned int users; /* processes and threads using this desktop */ unsigned char keystate[256]; /* asynchronous key state */ + unsigned char alt_pressed; /* last key press was Alt (used to determine msg on release) */ struct key_repeat key_repeat; /* key auto-repeat */ unsigned int clip_flags; /* last cursor clip flags */ user_handle_t cursor_win; /* window that contains the cursor */ diff --git a/server/winstation.c b/server/winstation.c index 300d899638b..63bdc3389de 100644 --- a/server/winstation.c +++ b/server/winstation.c @@ -294,6 +294,7 @@ static struct desktop *create_desktop( const struct unicode_str *name, unsigned list_init( &desktop->threads ); desktop->clip_flags = 0; desktop->cursor_win = 0; + desktop->alt_pressed = 0; memset( desktop->keystate, 0, sizeof(desktop->keystate) ); memset( &desktop->key_repeat, 0, sizeof(desktop->key_repeat) ); list_add_tail( &winstation->desktops, &desktop->entry );