annotate dep/animia/src/win/quartz.mm @ 157:18c8eb5d1edc

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