Skip to content

Commit e878dbc

Browse files
committed
app: [macOS] ignore focus changes not meant for the Gio view
Extracted from #138 by inkeliz. Signed-off-by: Elias Naur <mail@eliasnaur.com>
1 parent 1151eac commit e878dbc

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

app/os_macos.m

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,17 @@ - (void)windowDidChangeScreen:(NSNotification *)notification {
4747
}
4848
- (void)windowDidBecomeKey:(NSNotification *)notification {
4949
NSWindow *window = (NSWindow *)[notification object];
50-
GioView *view = (GioView *)window.contentView;
51-
gio_onFocus(view.handle, 1);
50+
GioView *view = (GioView *)window.contentView;
51+
if ([window firstResponder] == view) {
52+
gio_onFocus(view.handle, 1);
53+
}
5254
}
5355
- (void)windowDidResignKey:(NSNotification *)notification {
5456
NSWindow *window = (NSWindow *)[notification object];
55-
GioView *view = (GioView *)window.contentView;
56-
gio_onFocus(view.handle, 0);
57+
GioView *view = (GioView *)window.contentView;
58+
if ([window firstResponder] == view) {
59+
gio_onFocus(view.handle, 0);
60+
}
5761
}
5862
@end
5963

@@ -205,6 +209,14 @@ - (void)applicationDidHide:(NSNotification *)notification {
205209
- (void)dealloc {
206210
gio_onDestroy(self.handle);
207211
}
212+
- (BOOL) becomeFirstResponder {
213+
gio_onFocus(self.handle, 1);
214+
return [super becomeFirstResponder];
215+
}
216+
- (BOOL) resignFirstResponder {
217+
gio_onFocus(self.handle, 0);
218+
return [super resignFirstResponder];
219+
}
208220
@end
209221

210222
// Delegates are weakly referenced from their peers. Nothing

0 commit comments

Comments
 (0)