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