summaryrefslogtreecommitdiff
path: root/contrib/SDL-3.2.8/src/hidapi/testgui/mac_support_cocoa.m
diff options
context:
space:
mode:
author3gg <3gg@shellblade.net>2025-12-27 12:03:39 -0800
committer3gg <3gg@shellblade.net>2025-12-27 12:03:39 -0800
commit5a079a2d114f96d4847d1ee305d5b7c16eeec50e (patch)
tree8926ab44f168acf787d8e19608857b3af0f82758 /contrib/SDL-3.2.8/src/hidapi/testgui/mac_support_cocoa.m
Initial commit
Diffstat (limited to 'contrib/SDL-3.2.8/src/hidapi/testgui/mac_support_cocoa.m')
-rw-r--r--contrib/SDL-3.2.8/src/hidapi/testgui/mac_support_cocoa.m103
1 files changed, 103 insertions, 0 deletions
diff --git a/contrib/SDL-3.2.8/src/hidapi/testgui/mac_support_cocoa.m b/contrib/SDL-3.2.8/src/hidapi/testgui/mac_support_cocoa.m
new file mode 100644
index 0000000..1b12163
--- /dev/null
+++ b/contrib/SDL-3.2.8/src/hidapi/testgui/mac_support_cocoa.m
@@ -0,0 +1,103 @@
1/*******************************
2 Mac support for HID Test GUI
3
4 Alan Ott
5 Signal 11 Software
6*******************************/
7
8#include <fx.h>
9#import <Cocoa/Cocoa.h>
10
11#ifndef MAC_OS_X_VERSION_10_12
12#define MAC_OS_X_VERSION_10_12 101200
13#endif
14
15// macOS 10.12 deprecated NSAnyEventMask in favor of NSEventMaskAny
16#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_12
17#define NSEventMaskAny NSAnyEventMask
18#endif
19
20extern FXMainWindow *g_main_window;
21
22
23@interface MyAppDelegate : NSObject<NSApplicationDelegate>
24{
25}
26@end
27
28@implementation MyAppDelegate
29- (void) applicationWillBecomeActive:(NSNotification*)notif
30{
31 printf("WillBecomeActive\n");
32 g_main_window->show();
33
34}
35
36- (void) applicationWillTerminate:(NSNotification*)notif
37{
38 /* Doesn't get called. Not sure why */
39 printf("WillTerminate\n");
40 FXApp::instance()->exit();
41}
42
43- (NSApplicationTerminateReply) applicationShouldTerminate:(NSApplication*)sender
44{
45 /* Doesn't get called. Not sure why */
46 printf("ShouldTerminate\n");
47 return YES;
48}
49
50- (void) applicationWillHide:(NSNotification*)notif
51{
52 printf("WillHide\n");
53 g_main_window->hide();
54}
55
56- (void) handleQuitEvent:(NSAppleEventDescriptor*)event withReplyEvent:(NSAppleEventDescriptor*)replyEvent
57{
58 printf("QuitEvent\n");
59 FXApp::instance()->exit();
60}
61
62@end
63
64extern "C" {
65
66void
67init_apple_message_system()
68{
69 static MyAppDelegate *d = [MyAppDelegate new];
70
71 [[NSApplication sharedApplication] setDelegate:d];
72
73 /* Register for Apple Events. */
74 /* This is from
75 http://stackoverflow.com/questions/1768497/application-exit-event */
76 NSAppleEventManager *aem = [NSAppleEventManager sharedAppleEventManager];
77 [aem setEventHandler:d
78 andSelector:@selector(handleQuitEvent:withReplyEvent:)
79 forEventClass:kCoreEventClass andEventID:kAEQuitApplication];
80}
81
82void
83check_apple_events()
84{
85 NSApplication *app = [NSApplication sharedApplication];
86
87 NSAutoreleasePool *pool = [NSAutoreleasePool new];
88 while (1) {
89 NSEvent* event = [NSApp nextEventMatchingMask:NSEventMaskAny
90 untilDate:nil
91 inMode:NSDefaultRunLoopMode
92 dequeue:YES];
93 if (event == NULL)
94 break;
95 else {
96 //printf("Event happened: Type: %d\n", event->_type);
97 [app sendEvent: event];
98 }
99 }
100 [pool release];
101}
102
103} /* extern "C" */