Skip to content
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

macos: reset keyboard state when focus is lost #17453

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading