Mercurial > minori
comparison dep/animia/src/win/quartz.mm @ 155:d2bbb5773616
dep/animia: add quartz backend for windows
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Wed, 15 Nov 2023 15:24:39 -0500 |
parents | |
children | cdf79282d647 |
comparison
equal
deleted
inserted
replaced
154:d43d68408d3c | 155:d2bbb5773616 |
---|---|
1 #include "animia/win/quartz.h" | |
2 #include "animia.h" | |
3 | |
4 #include <Foundation/Foundation.h> | |
5 #include <CoreGraphics/CoreGraphics.h> | |
6 #include <AppKit/AppKit.h> | |
7 | |
8 namespace animia::internal::quartz { | |
9 | |
10 template<typename T> | |
11 static bool IntegerFromNSNumber(NSNumber* num, T& result) { | |
12 if (!num) | |
13 return false; | |
14 result = [num intValue]; | |
15 return true; | |
16 } | |
17 | |
18 static bool GetWindowTitle(unsigned int wid, std::string& result) { | |
19 NSWindow* window = [NSApp windowWithWindowNumber: wid]; | |
20 if (!window) | |
21 return false; | |
22 | |
23 NSString* title = [window title]; | |
24 if (!title) | |
25 return false; | |
26 | |
27 result = [title UTF8String]; | |
28 | |
29 return true; | |
30 } | |
31 | |
32 static bool StringFromNSString(NSString* string, std::string& result) { | |
33 if (!string) | |
34 return false; | |
35 result = [string UTF8String]; | |
36 return true; | |
37 } | |
38 | |
39 bool QuartzWinTools::EnumerateWindows(window_proc_t window_proc) { | |
40 if (!window_proc) | |
41 return false; | |
42 | |
43 NSMutableArray* windows = (NSMutableArray*)CGWindowListCopyWindowInfo(kCGWindowListOptionAll, kCGNullWindowID); | |
44 if (!windows) | |
45 return false; | |
46 | |
47 for (NSDictionary* window in windows) { | |
48 if (!window) | |
49 continue; | |
50 | |
51 Process proc; | |
52 { | |
53 IntegerFromNSNumber([window objectForKey:@"kCGWindowOwnerPID"], proc.pid); | |
54 StringFromNSString([window objectForKey:@"kCGWindowOwnerName"], proc.name); | |
55 } | |
56 | |
57 Window win; | |
58 { | |
59 IntegerFromNSNumber([window objectForKey:@"kCGWindowNumber"], win.id); | |
60 StringFromNSString([window objectForKey:@"kCGWindowName"], win.class_name); | |
61 GetWindowTitle(win.id, win.text); | |
62 } | |
63 | |
64 if (!window_proc(proc, win)) | |
65 return false; | |
66 } | |
67 | |
68 return true; | |
69 } | |
70 | |
71 } // namespace animia::win::detail |