From e878dbc598256ce11b6a1d87537567b9eac4f547 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Sun, 16 Jun 2024 15:15:40 +0200 Subject: [PATCH] app: [macOS] ignore focus changes not meant for the Gio view Extracted from https://github.com/gioui/gio/pull/138 by inkeliz. Signed-off-by: Elias Naur --- app/os_macos.m | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/app/os_macos.m b/app/os_macos.m index 0a3f62629..01b42978b 100644 --- a/app/os_macos.m +++ b/app/os_macos.m @@ -47,13 +47,17 @@ - (void)windowDidChangeScreen:(NSNotification *)notification { } - (void)windowDidBecomeKey:(NSNotification *)notification { NSWindow *window = (NSWindow *)[notification object]; - GioView *view = (GioView *)window.contentView; - gio_onFocus(view.handle, 1); + GioView *view = (GioView *)window.contentView; + if ([window firstResponder] == view) { + gio_onFocus(view.handle, 1); + } } - (void)windowDidResignKey:(NSNotification *)notification { NSWindow *window = (NSWindow *)[notification object]; - GioView *view = (GioView *)window.contentView; - gio_onFocus(view.handle, 0); + GioView *view = (GioView *)window.contentView; + if ([window firstResponder] == view) { + gio_onFocus(view.handle, 0); + } } @end @@ -205,6 +209,14 @@ - (void)applicationDidHide:(NSNotification *)notification { - (void)dealloc { gio_onDestroy(self.handle); } +- (BOOL) becomeFirstResponder { + gio_onFocus(self.handle, 1); + return [super becomeFirstResponder]; + } +- (BOOL) resignFirstResponder { + gio_onFocus(self.handle, 0); + return [super resignFirstResponder]; +} @end // Delegates are weakly referenced from their peers. Nothing