Atlas - mac_support_cocoa.m
Home / ext / SDL / src / hidapi / testgui Lines: 7 | Size: 2332 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)][FILE BEGIN]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" */ 104[FILE END](C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.