mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 18:05:35 +00:00
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:
@@ -851,20 +851,6 @@ func gio_onWindowed(view C.CFTypeRef) {
|
|||||||
w.ProcessEvent(ConfigEvent{Config: w.config})
|
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
|
//export gio_onFinishLaunching
|
||||||
func gio_onFinishLaunching() {
|
func gio_onFinishLaunching() {
|
||||||
close(launched)
|
close(launched)
|
||||||
|
|||||||
+15
-6
@@ -191,6 +191,12 @@ static void handleMouse(NSView *view, NSEvent *event, int typ, CGFloat dx, CGFlo
|
|||||||
r = [self convertRect:r toView:nil];
|
r = [self convertRect:r toView:nil];
|
||||||
return [[self window] convertRectToScreen:r];
|
return [[self window] convertRectToScreen:r];
|
||||||
}
|
}
|
||||||
|
- (void)applicationWillUnhide:(NSNotification *)notification {
|
||||||
|
gio_onShow((__bridge CFTypeRef)self);
|
||||||
|
}
|
||||||
|
- (void)applicationDidHide:(NSNotification *)notification {
|
||||||
|
gio_onHide((__bridge CFTypeRef)self);
|
||||||
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
// Delegates are weakly referenced from their peers. Nothing
|
// Delegates are weakly referenced from their peers. Nothing
|
||||||
@@ -374,6 +380,15 @@ CFTypeRef gio_createView(void) {
|
|||||||
GioView* view = [[GioView alloc] initWithFrame:frame];
|
GioView* view = [[GioView alloc] initWithFrame:frame];
|
||||||
view.wantsLayer = YES;
|
view.wantsLayer = YES;
|
||||||
view.layerContentsRedrawPolicy = NSViewLayerContentsRedrawDuringViewResize;
|
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);
|
return CFBridgingRetain(view);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -384,12 +399,6 @@ CFTypeRef gio_createView(void) {
|
|||||||
[NSApp activateIgnoringOtherApps:YES];
|
[NSApp activateIgnoringOtherApps:YES];
|
||||||
gio_onFinishLaunching();
|
gio_onFinishLaunching();
|
||||||
}
|
}
|
||||||
- (void)applicationDidHide:(NSNotification *)aNotification {
|
|
||||||
gio_onAppHide();
|
|
||||||
}
|
|
||||||
- (void)applicationWillUnhide:(NSNotification *)notification {
|
|
||||||
gio_onAppShow();
|
|
||||||
}
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
void gio_main() {
|
void gio_main() {
|
||||||
|
|||||||
Reference in New Issue
Block a user