1
- diff -uNr a/src/video/cocoa/SDL_cocoaevents.m b /src/video/cocoa/SDL_cocoaevents.m
1
+ diff -uNr a/src/video/cocoa/SDL_cocoaevents.m e /src/video/cocoa/SDL_cocoaevents.m
2
2
--- a/src/video/cocoa/SDL_cocoaevents.m 2020-03-11 02:36:18.000000000 +0100
3
- +++ b/src/video/cocoa/SDL_cocoaevents.m 2020-07-19 14:50:50.000000000 +0200
4
- @@ -233,47 +233,12 @@
3
+ +++ e/src/video/cocoa/SDL_cocoaevents.m 2020-07-28 21:40:49.000000000 +0200
4
+ @@ -34,6 +34,18 @@
5
+ #define kIOPMAssertPreventUserIdleDisplaySleep kIOPMAssertionTypePreventUserIdleDisplaySleep
6
+ #endif
7
+
8
+ + static void _openUrl(NSString *url) {
9
+ + [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:url]];
10
+ + }
11
+ +
12
+ + static void _openFile(NSString *file, NSString *app) {
13
+ + NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:file];
14
+ + if (path) {
15
+ + if (!app) app = @"TextEdit";
16
+ + [[NSWorkspace sharedWorkspace] openFile:path withApplication:app];
17
+ + }
18
+ + }
19
+ +
20
+ @interface SDLApplication : NSApplication
21
+
22
+ - (void)terminate:(id)sender;
23
+ @@ -45,6 +57,23 @@
24
+
25
+ @implementation SDLApplication
26
+
27
+ + /* KOReader specific actions */
28
+ + - (IBAction) openWeb: (NSMenuItem*) sender {
29
+ + _openUrl(@"https://koreader.rocks");
30
+ + }
31
+ +
32
+ + - (IBAction) openWiki: (NSMenuItem*) sender {
33
+ + _openUrl(@"https://github.com/koreader/koreader/wiki");
34
+ + }
35
+ +
36
+ + - (IBAction) openForum: (NSMenuItem*) sender {
37
+ + _openUrl(@"https://www.mobileread.com/forums/forumdisplay.php?f=276");
38
+ + }
39
+ +
40
+ + - (IBAction) openLicense: (NSMenuItem*) sender {
41
+ + _openFile(@"COPYING", nil);
42
+ + }
43
+ +
44
+ // Override terminate to handle Quit and System Shutdown smoothly.
45
+ - (void)terminate:(id)sender
46
+ {
47
+ @@ -233,20 +262,7 @@
5
48
6
49
- (void)applicationDidFinishLaunching:(NSNotification *)notification
7
50
{
@@ -19,132 +62,20 @@ diff -uNr a/src/video/cocoa/SDL_cocoaevents.m b/src/video/cocoa/SDL_cocoaevents.
19
62
- SDL_Delay(300); /* !!! FIXME: this isn't right. */
20
63
- [NSApp activateIgnoringOtherApps:YES];
21
64
- }
22
- -
23
- - /* If we call this before NSApp activation, macOS might print a complaint
24
- - * about ApplePersistenceIgnoreState. */
25
- [SDLApplication registerUserDefaults];
26
- }
27
- @end
28
-
29
- static SDLAppDelegate *appDelegate = nil;
65
+ + [NSApp activateIgnoringOtherApps:YES];
30
66
31
- - static NSString *
32
- - GetApplicationName(void)
33
- - {
34
- - NSString *appName;
35
- -
36
- - /* Determine the application name */
37
- - appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"];
38
- - if (!appName) {
39
- - appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"];
40
- - }
41
- -
42
- - if (![appName length]) {
43
- - appName = [[NSProcessInfo processInfo] processName];
44
- - }
45
- -
46
- - return appName;
47
- - }
48
- -
49
- static bool
50
- LoadMainMenuNibIfAvailable(void)
51
- {
52
- @@ -296,11 +261,9 @@
53
- static void
54
- CreateApplicationMenus(void)
55
- {
56
- - NSString *appName;
57
- + NSString *appName = @"KOReader";
58
- NSString *title;
59
- NSMenu *appleMenu;
60
- - NSMenu *serviceMenu;
61
- - NSMenu *windowMenu;
62
- NSMenuItem *menuItem;
63
- NSMenu *mainMenu;
64
-
65
- @@ -317,27 +280,18 @@
66
- mainMenu = nil;
67
-
68
- /* Create the application menu */
69
- - appName = GetApplicationName();
70
- appleMenu = [[NSMenu alloc] initWithTitle:@""];
71
-
72
- - /* Add menu items */
73
- - title = [@"About " stringByAppendingString:appName];
74
- - [appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""];
75
- -
76
- - [appleMenu addItem:[NSMenuItem separatorItem]];
77
- -
78
- - [appleMenu addItemWithTitle:@"Preferences…" action:nil keyEquivalent:@","];
79
- -
80
- - [appleMenu addItem:[NSMenuItem separatorItem]];
81
- -
82
- - serviceMenu = [[NSMenu alloc] initWithTitle:@""];
83
- - menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Services" action:nil keyEquivalent:@""];
84
- - [menuItem setSubmenu:serviceMenu];
85
- -
86
- - [NSApp setServicesMenu:serviceMenu];
87
- - [serviceMenu release];
88
- -
89
- - [appleMenu addItem:[NSMenuItem separatorItem]];
90
- + /* Add the fullscreen toggle menu option, if supported */
91
- + if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6) {
92
- + /* Cocoa should update the title to Enter or Exit Full Screen automatically.
93
- + * But if not, then just fallback to Toggle Full Screen.
94
- + */
95
- + menuItem = [[NSMenuItem alloc] initWithTitle:@"Toggle Full Screen" action:@selector(toggleFullScreen:) keyEquivalent:@"f"];
96
- + [menuItem setKeyEquivalentModifierMask:NSEventModifierFlagControl | NSEventModifierFlagCommand];
97
- + [appleMenu addItem:menuItem];
98
- + [menuItem release];
99
- + }
100
-
101
- title = [@"Hide " stringByAppendingString:appName];
102
- [appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h"];
103
- @@ -361,38 +315,6 @@
104
- /* Tell the application object that this is now the application menu */
105
- [NSApp setAppleMenu:appleMenu];
106
- [appleMenu release];
107
- -
108
- -
109
- - /* Create the window menu */
110
- - windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];
111
- -
112
- - /* Add menu items */
113
- - [windowMenu addItemWithTitle:@"Close" action:@selector(performClose:) keyEquivalent:@"w"];
114
- -
115
- - [windowMenu addItemWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"];
116
- -
117
- - [windowMenu addItemWithTitle:@"Zoom" action:@selector(performZoom:) keyEquivalent:@""];
118
- -
119
- - /* Add the fullscreen toggle menu option, if supported */
120
- - if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6) {
121
- - /* Cocoa should update the title to Enter or Exit Full Screen automatically.
122
- - * But if not, then just fallback to Toggle Full Screen.
123
- - */
124
- - menuItem = [[NSMenuItem alloc] initWithTitle:@"Toggle Full Screen" action:@selector(toggleFullScreen:) keyEquivalent:@"f"];
125
- - [menuItem setKeyEquivalentModifierMask:NSEventModifierFlagControl | NSEventModifierFlagCommand];
126
- - [windowMenu addItem:menuItem];
127
- - [menuItem release];
128
- - }
129
- -
130
- - /* Put menu into the menubar */
131
- - menuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""];
132
- - [menuItem setSubmenu:windowMenu];
133
- - [[NSApp mainMenu] addItem:menuItem];
134
- - [menuItem release];
135
- -
136
- - /* Tell the application object that this is now the window menu */
137
- - [NSApp setWindowsMenu:windowMenu];
138
- - [windowMenu release];
139
- }
140
-
141
- void
142
- @@ -498,7 +420,7 @@
143
- * seen by OS X power users. there's an additional optional human-readable
144
- * (localized) reason parameter which we don't set.
145
- */
146
- - NSString *name = [GetApplicationName() stringByAppendingString:@" using SDL_DisableScreenSaver"];
147
- + NSString *name = [@"luajit" stringByAppendingString:@" using SDL_DisableScreenSaver"];
148
- IOPMAssertionCreateWithDescription(kIOPMAssertPreventUserIdleDisplaySleep,
149
- (CFStringRef) name,
150
- NULL, NULL, NULL, 0, NULL,
67
+ /* If we call this before NSApp activation, macOS might print a complaint
68
+ * about ApplePersistenceIgnoreState. */
69
+ @@ -424,12 +440,6 @@
70
+ }
71
+ }
72
+ [NSApp finishLaunching];
73
+ - if ([NSApp delegate]) {
74
+ - /* The SDL app delegate calls this in didFinishLaunching if it's
75
+ - * attached to the NSApp, otherwise we need to call it manually.
76
+ - */
77
+ - [SDLApplication registerUserDefaults];
78
+ - }
79
+ }
80
+ if (NSApp && !appDelegate) {
81
+ appDelegate = [[SDLAppDelegate alloc] init];
0 commit comments