1 |
/* |
2 |
Copyright (c) 2013 - 2017 Christian Schoenebeck |
3 |
|
4 |
This file is part of "gigedit" and released under the terms of the |
5 |
GNU General Public License version 2. |
6 |
*/ |
7 |
|
8 |
#import "MacHelper.h" |
9 |
#import <Cocoa/Cocoa.h> |
10 |
#import <stdio.h> |
11 |
|
12 |
#if __clang__ |
13 |
# define HAS_OBJC_ARC __has_feature(objc_arc) |
14 |
#else |
15 |
# define HAS_OBJC_ARC 0 |
16 |
#endif |
17 |
|
18 |
@interface MacHelper : NSObject { |
19 |
@public |
20 |
void (*m_fn)(void* info); |
21 |
void* m_info; |
22 |
} |
23 |
@end |
24 |
|
25 |
@implementation MacHelper |
26 |
|
27 |
- (id)init { |
28 |
if ((self = [super init])) { |
29 |
m_fn = nil; |
30 |
m_info = nil; |
31 |
} |
32 |
return self; |
33 |
} |
34 |
|
35 |
- (void)runCFunc { |
36 |
(*m_fn)(m_info); |
37 |
} |
38 |
|
39 |
@end |
40 |
|
41 |
#if defined(__cplusplus) |
42 |
extern "C" { |
43 |
#endif // __cplusplus |
44 |
|
45 |
void macHelperRunCFuncOnMainThread(void (*fn)(void* info), void* info) { |
46 |
MacHelper* obj = [[MacHelper alloc] init]; |
47 |
obj->m_fn = fn; |
48 |
obj->m_info = info; |
49 |
printf("perfoming selector on main thread ...\n"); fflush(stdout); |
50 |
[obj performSelectorOnMainThread:@selector(runCFunc) withObject:obj waitUntilDone:NO]; |
51 |
printf("Selector scheduled async. (on main thread).\n"); fflush(stdout); |
52 |
#if !HAS_OBJC_ARC |
53 |
[obj release]; |
54 |
#endif |
55 |
} |
56 |
|
57 |
void macRaiseAppWindow() { |
58 |
[NSApp activateIgnoringOtherApps:YES]; |
59 |
} |
60 |
|
61 |
#if defined(__cplusplus) |
62 |
} |
63 |
#endif // __cplusplus |