Mercurial > minori
annotate dep/animia/src/win/quartz.mm @ 167:31735c8592bc
dep/animia: make x11 window walking actually work
this is HORRIBLY slow, and I'm not *entirely* sure why...
author | paper@DavesDouble.local |
---|---|
date | Sun, 19 Nov 2023 05:32:06 -0500 |
parents | 44c5e6dd9488 |
children | c413e475f496 |
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 |
163
44c5e6dd9488
dep/animia/osx: move GetProcessName to util/osx so we can use it in quartz
Paper <mrpapersonic@gmail.com>
parents:
156
diff
changeset
|
4 #import <Foundation/Foundation.h> |
44c5e6dd9488
dep/animia/osx: move GetProcessName to util/osx so we can use it in quartz
Paper <mrpapersonic@gmail.com>
parents:
156
diff
changeset
|
5 #import <CoreGraphics/CoreGraphics.h> |
44c5e6dd9488
dep/animia/osx: move GetProcessName to util/osx so we can use it in quartz
Paper <mrpapersonic@gmail.com>
parents:
156
diff
changeset
|
6 #import <AppKit/AppKit.h> |
155
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); |
163
44c5e6dd9488
dep/animia/osx: move GetProcessName to util/osx so we can use it in quartz
Paper <mrpapersonic@gmail.com>
parents:
156
diff
changeset
|
51 if (proc.name.empty()) |
44c5e6dd9488
dep/animia/osx: move GetProcessName to util/osx so we can use it in quartz
Paper <mrpapersonic@gmail.com>
parents:
156
diff
changeset
|
52 osx::util::GetProcessName(proc.pid, proc.name); |
155
d2bbb5773616
dep/animia: add quartz backend for windows
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
53 } |
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 Window win; |
d2bbb5773616
dep/animia: add quartz backend for windows
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
56 { |
d2bbb5773616
dep/animia: add quartz backend for windows
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
57 IntegerFromNSNumber([window objectForKey:@"kCGWindowNumber"], win.id); |
d2bbb5773616
dep/animia: add quartz backend for windows
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
58 StringFromNSString([window objectForKey:@"kCGWindowName"], win.class_name); |
d2bbb5773616
dep/animia: add quartz backend for windows
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
59 GetWindowTitle(win.id, win.text); |
d2bbb5773616
dep/animia: add quartz backend for windows
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
60 } |
d2bbb5773616
dep/animia: add quartz backend for windows
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
61 |
d2bbb5773616
dep/animia: add quartz backend for windows
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
62 if (!window_proc(proc, win)) |
d2bbb5773616
dep/animia: add quartz backend for windows
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
63 return false; |
d2bbb5773616
dep/animia: add quartz backend for windows
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
64 } |
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 return true; |
d2bbb5773616
dep/animia: add quartz backend for windows
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
67 } |
d2bbb5773616
dep/animia: add quartz backend for windows
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
68 |
d2bbb5773616
dep/animia: add quartz backend for windows
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
69 } // namespace animia::win::detail |