annotate dep/animia/src/win/quartz.mm @ 182:c413e475f496

dep/animia: various stylistic changes
author Paper <mrpapersonic@gmail.com>
date Mon, 04 Dec 2023 13:19:54 -0500
parents 44c5e6dd9488
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
182
c413e475f496 dep/animia: various stylistic changes
Paper <mrpapersonic@gmail.com>
parents: 163
diff changeset
1 /* We actually DON'T need Objective-C for most of this file.
c413e475f496 dep/animia: various stylistic changes
Paper <mrpapersonic@gmail.com>
parents: 163
diff changeset
2 * GetWindowTitle() is the only function that really needs it.
c413e475f496 dep/animia: various stylistic changes
Paper <mrpapersonic@gmail.com>
parents: 163
diff changeset
3 * (and even then, we can use the C bindings for it...)
c413e475f496 dep/animia: various stylistic changes
Paper <mrpapersonic@gmail.com>
parents: 163
diff changeset
4 *
c413e475f496 dep/animia: various stylistic changes
Paper <mrpapersonic@gmail.com>
parents: 163
diff changeset
5 * However, being able to use the Foundation classes makes things
c413e475f496 dep/animia: various stylistic changes
Paper <mrpapersonic@gmail.com>
parents: 163
diff changeset
6 * so, so, so much easier, and so I've decided to make this file
c413e475f496 dep/animia: various stylistic changes
Paper <mrpapersonic@gmail.com>
parents: 163
diff changeset
7 * in Objective-C++.
c413e475f496 dep/animia: various stylistic changes
Paper <mrpapersonic@gmail.com>
parents: 163
diff changeset
8 */
155
d2bbb5773616 dep/animia: add quartz backend for windows
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
9 #include "animia/win/quartz.h"
d2bbb5773616 dep/animia: add quartz backend for windows
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
10 #include "animia.h"
d2bbb5773616 dep/animia: add quartz backend for windows
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
11
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
12 #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
13 #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
14 #import <AppKit/AppKit.h>
155
d2bbb5773616 dep/animia: add quartz backend for windows
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
15
d2bbb5773616 dep/animia: add quartz backend for windows
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
16 namespace animia::internal::quartz {
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 template<typename T>
d2bbb5773616 dep/animia: add quartz backend for windows
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
19 static bool IntegerFromNSNumber(NSNumber* num, T& result) {
d2bbb5773616 dep/animia: add quartz backend for windows
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
20 if (!num)
d2bbb5773616 dep/animia: add quartz backend for windows
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
21 return false;
156
cdf79282d647 dep/animia: add VERY early x11 window stuff
Paper <mrpapersonic@gmail.com>
parents: 155
diff changeset
22
155
d2bbb5773616 dep/animia: add quartz backend for windows
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
23 result = [num intValue];
d2bbb5773616 dep/animia: add quartz backend for windows
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
24 return true;
d2bbb5773616 dep/animia: add quartz backend for windows
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
25 }
d2bbb5773616 dep/animia: add quartz backend for windows
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
26
156
cdf79282d647 dep/animia: add VERY early x11 window stuff
Paper <mrpapersonic@gmail.com>
parents: 155
diff changeset
27 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
28 if (!string)
cdf79282d647 dep/animia: add VERY early x11 window stuff
Paper <mrpapersonic@gmail.com>
parents: 155
diff changeset
29 return false;
cdf79282d647 dep/animia: add VERY early x11 window stuff
Paper <mrpapersonic@gmail.com>
parents: 155
diff changeset
30
cdf79282d647 dep/animia: add VERY early x11 window stuff
Paper <mrpapersonic@gmail.com>
parents: 155
diff changeset
31 result = [string UTF8String];
cdf79282d647 dep/animia: add VERY early x11 window stuff
Paper <mrpapersonic@gmail.com>
parents: 155
diff changeset
32 return true;
cdf79282d647 dep/animia: add VERY early x11 window stuff
Paper <mrpapersonic@gmail.com>
parents: 155
diff changeset
33 }
cdf79282d647 dep/animia: add VERY early x11 window stuff
Paper <mrpapersonic@gmail.com>
parents: 155
diff changeset
34
182
c413e475f496 dep/animia: various stylistic changes
Paper <mrpapersonic@gmail.com>
parents: 163
diff changeset
35 /* This is really the only a*/
155
d2bbb5773616 dep/animia: add quartz backend for windows
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
36 static bool GetWindowTitle(unsigned int wid, std::string& result) {
d2bbb5773616 dep/animia: add quartz backend for windows
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
37 NSWindow* window = [NSApp windowWithWindowNumber: wid];
d2bbb5773616 dep/animia: add quartz backend for windows
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
38 if (!window)
d2bbb5773616 dep/animia: add quartz backend for windows
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
39 return false;
d2bbb5773616 dep/animia: add quartz backend for windows
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
40
156
cdf79282d647 dep/animia: add VERY early x11 window stuff
Paper <mrpapersonic@gmail.com>
parents: 155
diff changeset
41 return StringFromNSString([window title], result);
155
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
d2bbb5773616 dep/animia: add quartz backend for windows
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
44 bool QuartzWinTools::EnumerateWindows(window_proc_t window_proc) {
d2bbb5773616 dep/animia: add quartz backend for windows
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
45 if (!window_proc)
d2bbb5773616 dep/animia: add quartz backend for windows
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
46 return false;
d2bbb5773616 dep/animia: add quartz backend for windows
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
47
156
cdf79282d647 dep/animia: add VERY early x11 window stuff
Paper <mrpapersonic@gmail.com>
parents: 155
diff changeset
48 NSMutableArray* windows = reinterpret_cast<NSMutableArray*>(CGWindowListCopyWindowInfo(kCGWindowListOptionAll, kCGNullWindowID));
155
d2bbb5773616 dep/animia: add quartz backend for windows
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
49 if (!windows)
d2bbb5773616 dep/animia: add quartz backend for windows
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
50 return false;
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 for (NSDictionary* window in windows) {
d2bbb5773616 dep/animia: add quartz backend for windows
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
53 if (!window)
d2bbb5773616 dep/animia: add quartz backend for windows
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
54 continue;
d2bbb5773616 dep/animia: add quartz backend for windows
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
55
d2bbb5773616 dep/animia: add quartz backend for windows
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
56 Process proc;
d2bbb5773616 dep/animia: add quartz backend for windows
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
57 {
d2bbb5773616 dep/animia: add quartz backend for windows
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
58 IntegerFromNSNumber([window objectForKey:@"kCGWindowOwnerPID"], proc.pid);
d2bbb5773616 dep/animia: add quartz backend for windows
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
59 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
60 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
61 osx::util::GetProcessName(proc.pid, proc.name);
155
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 Window win;
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 IntegerFromNSNumber([window objectForKey:@"kCGWindowNumber"], win.id);
d2bbb5773616 dep/animia: add quartz backend for windows
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
67 StringFromNSString([window objectForKey:@"kCGWindowName"], win.class_name);
d2bbb5773616 dep/animia: add quartz backend for windows
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
68 GetWindowTitle(win.id, win.text);
d2bbb5773616 dep/animia: add quartz backend for windows
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
69 }
d2bbb5773616 dep/animia: add quartz backend for windows
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
70
d2bbb5773616 dep/animia: add quartz backend for windows
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
71 if (!window_proc(proc, win))
d2bbb5773616 dep/animia: add quartz backend for windows
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
72 return false;
d2bbb5773616 dep/animia: add quartz backend for windows
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
73 }
d2bbb5773616 dep/animia: add quartz backend for windows
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
74
d2bbb5773616 dep/animia: add quartz backend for windows
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
75 return true;
d2bbb5773616 dep/animia: add quartz backend for windows
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
76 }
d2bbb5773616 dep/animia: add quartz backend for windows
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
77
d2bbb5773616 dep/animia: add quartz backend for windows
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
78 } // namespace animia::win::detail