macos: reset keyboard state when focus is lost (#17453)

This commit is contained in:
Eric Warmenhoven 2025-01-21 16:31:24 -05:00 committed by GitHub
parent 66e23fca79
commit f1e3b83d26
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 3 deletions

View File

@ -78,6 +78,11 @@ static UISelectionFeedbackGenerator *feedbackGenerator;
static bool apple_key_state[MAX_KEYS]; static bool apple_key_state[MAX_KEYS];
void apple_input_keyboard_reset(void)
{
memset(apple_key_state, 0, sizeof(apple_key_state));
}
/* Send keyboard inputs directly using RETROK_* codes /* Send keyboard inputs directly using RETROK_* codes
* Used by the iOS custom keyboard implementation */ * Used by the iOS custom keyboard implementation */
void apple_direct_input_keyboard_event(bool down, void apple_direct_input_keyboard_event(bool down,
@ -743,8 +748,7 @@ static void cocoa_input_free(void *data)
if (!apple || !data) if (!apple || !data)
return; return;
for (i = 0; i < MAX_KEYS; i++) memset(apple_key_state, 0, sizeof(apple_key_state));
apple_key_state[i] = 0;
free(apple); free(apple);
} }

View File

@ -166,6 +166,8 @@ enum
RETRO_BEGIN_DECLS RETRO_BEGIN_DECLS
void apple_input_keyboard_reset(void);
void apple_input_keyboard_event(bool down, void apple_input_keyboard_event(bool down,
unsigned code, uint32_t character, uint32_t mod, unsigned device); unsigned code, uint32_t character, uint32_t mod, unsigned device);

View File

@ -824,7 +824,10 @@ static ui_application_t ui_application_cocoa = {
} }
- (void)applicationDidBecomeActive:(NSNotification *)notification { } - (void)applicationDidBecomeActive:(NSNotification *)notification { }
- (void)applicationWillResignActive:(NSNotification *)notification { } - (void)applicationWillResignActive:(NSNotification *)notification
{
apple_input_keyboard_reset();
}
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication { return YES; } - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication { return YES; }
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
{ {