Skip to content

Commit

Permalink
macos: reset keyboard state when focus is lost (#17453)
Browse files Browse the repository at this point in the history
  • Loading branch information
warmenhoven authored Jan 21, 2025
1 parent 66e23fc commit f1e3b83
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
8 changes: 6 additions & 2 deletions input/drivers/cocoa_input.m
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@

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
* Used by the iOS custom keyboard implementation */
void apple_direct_input_keyboard_event(bool down,
Expand Down Expand Up @@ -743,8 +748,7 @@ static void cocoa_input_free(void *data)
if (!apple || !data)
return;

for (i = 0; i < MAX_KEYS; i++)
apple_key_state[i] = 0;
memset(apple_key_state, 0, sizeof(apple_key_state));

free(apple);
}
Expand Down
2 changes: 2 additions & 0 deletions input/drivers_keyboard/keyboard_event_apple.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ enum

RETRO_BEGIN_DECLS

void apple_input_keyboard_reset(void);

void apple_input_keyboard_event(bool down,
unsigned code, uint32_t character, uint32_t mod, unsigned device);

Expand Down
5 changes: 4 additions & 1 deletion ui/drivers/ui_cocoa.m
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,10 @@ - (void) rarch_main
}

- (void)applicationDidBecomeActive:(NSNotification *)notification { }
- (void)applicationWillResignActive:(NSNotification *)notification { }
- (void)applicationWillResignActive:(NSNotification *)notification
{
apple_input_keyboard_reset();
}
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication { return YES; }
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
{
Expand Down

0 comments on commit f1e3b83

Please sign in to comment.