forked from joejulian/gio
app: [macOS] make the app delegate optional
Inspired by the discussion at golang.org/issue/70089, this change makes our particular NSApplicationDelegate implementation optional. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -40,6 +40,7 @@ import (
|
|||||||
#define MOUSE_SCROLL 4
|
#define MOUSE_SCROLL 4
|
||||||
|
|
||||||
__attribute__ ((visibility ("hidden"))) void gio_main(void);
|
__attribute__ ((visibility ("hidden"))) void gio_main(void);
|
||||||
|
__attribute__ ((visibility ("hidden"))) void gio_init(void);
|
||||||
__attribute__ ((visibility ("hidden"))) CFTypeRef gio_createView(int presentWithTrans);
|
__attribute__ ((visibility ("hidden"))) CFTypeRef gio_createView(int presentWithTrans);
|
||||||
__attribute__ ((visibility ("hidden"))) CFTypeRef gio_createWindow(CFTypeRef viewRef, CGFloat width, CGFloat height);
|
__attribute__ ((visibility ("hidden"))) CFTypeRef gio_createWindow(CFTypeRef viewRef, CGFloat width, CGFloat height);
|
||||||
__attribute__ ((visibility ("hidden"))) void gio_viewSetHandle(CFTypeRef viewRef, uintptr_t handle);
|
__attribute__ ((visibility ("hidden"))) void gio_viewSetHandle(CFTypeRef viewRef, uintptr_t handle);
|
||||||
@@ -334,6 +335,8 @@ import "C"
|
|||||||
func init() {
|
func init() {
|
||||||
// Darwin requires that UI operations happen on the main thread only.
|
// Darwin requires that UI operations happen on the main thread only.
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
|
// Register launch finished listener.
|
||||||
|
C.gio_init()
|
||||||
}
|
}
|
||||||
|
|
||||||
// AppKitViewEvent notifies the client of changes to the window AppKit handles.
|
// AppKitViewEvent notifies the client of changes to the window AppKit handles.
|
||||||
|
|||||||
+22
-1
@@ -420,7 +420,6 @@ void gio_viewSetHandle(CFTypeRef viewRef, uintptr_t handle) {
|
|||||||
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
|
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
|
||||||
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
|
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
|
||||||
[NSApp activateIgnoringOtherApps:YES];
|
[NSApp activateIgnoringOtherApps:YES];
|
||||||
gio_onFinishLaunching();
|
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@@ -451,3 +450,25 @@ void gio_main() {
|
|||||||
[NSApp run];
|
[NSApp run];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@interface AppListener : NSObject
|
||||||
|
@end
|
||||||
|
|
||||||
|
static AppListener *appListener;
|
||||||
|
|
||||||
|
@implementation AppListener
|
||||||
|
- (void)launchFinished:(NSNotification *)notification {
|
||||||
|
appListener = nil;
|
||||||
|
gio_onFinishLaunching();
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
|
void gio_init() {
|
||||||
|
@autoreleasepool {
|
||||||
|
appListener = [[AppListener alloc] init];
|
||||||
|
[[NSNotificationCenter defaultCenter] addObserver:appListener
|
||||||
|
selector:@selector(launchFinished:)
|
||||||
|
name:NSApplicationDidFinishLaunchingNotification
|
||||||
|
object:nil];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user