-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Fix lost KEY_UP events with multiple keyboards using shared scancode state #14446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
7402448
dac79ea
6d40439
7f05d56
464f413
65edde5
49fcaac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -51,6 +51,7 @@ typedef struct SDL_Keyboard | |||||||||||||
| SDL_Keymod modstate; | ||||||||||||||
| Uint8 keysource[SDL_SCANCODE_COUNT]; | ||||||||||||||
| bool keystate[SDL_SCANCODE_COUNT]; | ||||||||||||||
| Uint8 keyrefcount[SDL_SCANCODE_COUNT]; // how many devices hold this key // | ||||||||||||||
| SDL_Keymap *keymap; | ||||||||||||||
| Uint32 keycode_options; | ||||||||||||||
| bool autorelease_pending; | ||||||||||||||
|
|
@@ -88,6 +89,12 @@ static void SDLCALL SDL_KeycodeOptionsChanged(void *userdata, const char *name, | |||||||||||||
| // Public functions | ||||||||||||||
| bool SDL_InitKeyboard(void) | ||||||||||||||
| { | ||||||||||||||
| // Init key reference counts to 0 | ||||||||||||||
| SDL_Keyboard *keyboard = &SDL_keyboard; | ||||||||||||||
| for (int i = 0; i < SDL_SCANCODE_COUNT; ++i) { | ||||||||||||||
| keyboard->keyrefcount[i] = 0; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| SDL_AddHintCallback(SDL_HINT_KEYCODE_OPTIONS, | ||||||||||||||
| SDL_KeycodeOptionsChanged, &SDL_keyboard); | ||||||||||||||
|
|
||||||||||||||
|
|
@@ -225,6 +232,7 @@ void SDL_ResetKeyboard(void) | |||||||||||||
| if (keyboard->keystate[scancode]) { | ||||||||||||||
| SDL_SendKeyboardKey(0, SDL_GLOBAL_KEYBOARD_ID, 0, (SDL_Scancode)scancode, false); | ||||||||||||||
| } | ||||||||||||||
| keyboard->keyrefcount[scancode] = 0; // Reset reference count | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
|
|
@@ -522,6 +530,7 @@ static bool SDL_SendKeyboardKeyInternal(Uint64 timestamp, Uint32 flags, SDL_Keyb | |||||||||||||
| SDL_Keycode keycode = SDLK_UNKNOWN; | ||||||||||||||
| Uint32 type; | ||||||||||||||
| bool repeat = false; | ||||||||||||||
| bool last_release = true; | ||||||||||||||
livinamuk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||
| const Uint8 source = flags & KEYBOARD_SOURCE_MASK; | ||||||||||||||
|
|
||||||||||||||
| #ifdef DEBUG_KEYBOARD | ||||||||||||||
|
|
@@ -538,6 +547,9 @@ static bool SDL_SendKeyboardKeyInternal(Uint64 timestamp, Uint32 flags, SDL_Keyb | |||||||||||||
| if (scancode > SDL_SCANCODE_UNKNOWN && scancode < SDL_SCANCODE_COUNT) { | ||||||||||||||
| // Drop events that don't change state | ||||||||||||||
| if (down) { | ||||||||||||||
| if (keyboard->keyrefcount[scancode] < 255) { | ||||||||||||||
| keyboard->keyrefcount[scancode]++; | ||||||||||||||
| } | ||||||||||||||
| if (keyboard->keystate[scancode]) { | ||||||||||||||
| if (!(keyboard->keysource[scancode] & source)) { | ||||||||||||||
| keyboard->keysource[scancode] |= source; | ||||||||||||||
|
|
@@ -547,14 +559,25 @@ static bool SDL_SendKeyboardKeyInternal(Uint64 timestamp, Uint32 flags, SDL_Keyb | |||||||||||||
| } | ||||||||||||||
| keyboard->keysource[scancode] |= source; | ||||||||||||||
| } else { | ||||||||||||||
| if (!keyboard->keystate[scancode]) { | ||||||||||||||
| return false; | ||||||||||||||
livinamuk marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
| if (keyboard->keyrefcount[scancode] > 0) { | ||||||||||||||
| keyboard->keyrefcount[scancode]--; | ||||||||||||||
| } | ||||||||||||||
| if (keyboard->keyrefcount[scancode] == 0) { | ||||||||||||||
| keyboard->keysource[scancode] = 0; | ||||||||||||||
| last_release = true; | ||||||||||||||
| } else { | ||||||||||||||
| last_release = false; | ||||||||||||||
livinamuk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||
| } | ||||||||||||||
| keyboard->keysource[scancode] = 0; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| // Update internal keyboard state | ||||||||||||||
| keyboard->keystate[scancode] = down; | ||||||||||||||
| if (down) { | ||||||||||||||
| keyboard->keystate[scancode] = true; | ||||||||||||||
| } else { | ||||||||||||||
| if (keyboard->keyrefcount[scancode] == 0) { | ||||||||||||||
| keyboard->keystate[scancode] = false; | ||||||||||||||
| } | ||||||||||||||
|
||||||||||||||
| } else { | |
| if (keyboard->keyrefcount[scancode] == 0) { | |
| keyboard->keystate[scancode] = false; | |
| } | |
| } else if (last_release) { | |
| keyboard->keystate[scancode] = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was resolved without accepting the suggestion. Was it incorrect?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Functionaly they're the same, but yours is tighter.
Uh oh!
There was an error while loading. Please reload this page.