app: [macOS] use NSNotificationCenter to receive app events

Notifications don't require a list of windows nor an app delegate.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2023-12-11 15:00:58 -06:00
parent 9bca5bfdcf
commit d7528a8338
2 changed files with 15 additions and 20 deletions
-14
View File
@@ -851,20 +851,6 @@ func gio_onWindowed(view C.CFTypeRef) {
w.ProcessEvent(ConfigEvent{Config: w.config})
}
//export gio_onAppHide
func gio_onAppHide() {
for _, w := range viewMap {
w.setStage(StagePaused)
}
}
//export gio_onAppShow
func gio_onAppShow() {
for _, w := range viewMap {
w.setStage(StageRunning)
}
}
//export gio_onFinishLaunching
func gio_onFinishLaunching() {
close(launched)
+15 -6
View File
@@ -191,6 +191,12 @@ static void handleMouse(NSView *view, NSEvent *event, int typ, CGFloat dx, CGFlo
r = [self convertRect:r toView:nil];
return [[self window] convertRectToScreen:r];
}
- (void)applicationWillUnhide:(NSNotification *)notification {
gio_onShow((__bridge CFTypeRef)self);
}
- (void)applicationDidHide:(NSNotification *)notification {
gio_onHide((__bridge CFTypeRef)self);
}
@end
// Delegates are weakly referenced from their peers. Nothing
@@ -374,6 +380,15 @@ CFTypeRef gio_createView(void) {
GioView* view = [[GioView alloc] initWithFrame:frame];
view.wantsLayer = YES;
view.layerContentsRedrawPolicy = NSViewLayerContentsRedrawDuringViewResize;
[[NSNotificationCenter defaultCenter] addObserver:view
selector:@selector(applicationWillUnhide:)
name:NSApplicationWillUnhideNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:view
selector:@selector(applicationDidHide:)
name:NSApplicationDidHideNotification
object:nil];
return CFBridgingRetain(view);
}
}
@@ -384,12 +399,6 @@ CFTypeRef gio_createView(void) {
[NSApp activateIgnoringOtherApps:YES];
gio_onFinishLaunching();
}
- (void)applicationDidHide:(NSNotification *)aNotification {
gio_onAppHide();
}
- (void)applicationWillUnhide:(NSNotification *)notification {
gio_onAppShow();
}
@end
void gio_main() {