3
3
#import < ApplicationServices/ApplicationServices.h>
4
4
#include " ../window_manager.h"
5
5
6
- std::vector<int32_t > getWindows () {
6
+ std::vector<int64_t > getWindows () {
7
7
CGWindowListOption listOptions = kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements ;
8
8
CFArrayRef windowList = CGWindowListCopyWindowInfo (listOptions, kCGNullWindowID );
9
9
10
- std::vector<int32_t > windowHandles;
10
+ std::vector<int64_t > windowHandles;
11
11
12
12
for (NSDictionary *info in (NSArray *)windowList) {
13
13
NSNumber *ownerPid = info[(id )kCGWindowOwnerPID ];
28
28
return windowHandles;
29
29
}
30
30
31
- MMRect getWindowRect (const int32_t windowHandle) {
31
+ MMRect getWindowRect (const int64_t windowHandle) {
32
32
CGWindowListOption listOptions = kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements ;
33
33
CFArrayRef windowList = CGWindowListCopyWindowInfo (listOptions, kCGNullWindowID );
34
34
@@ -55,3 +55,28 @@ MMRect getWindowRect(const int32_t windowHandle) {
55
55
56
56
return MMRectMake (0 , 0 , 0 , 0 );
57
57
}
58
+
59
+ std::string getWindowTitle (const int64_t windowHandle) {
60
+ CGWindowListOption listOptions = kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements ;
61
+ CFArrayRef windowList = CGWindowListCopyWindowInfo (listOptions, kCGNullWindowID );
62
+
63
+ std::vector<std::string> windowNames;
64
+
65
+ for (NSDictionary *info in (NSArray *)windowList) {
66
+ NSNumber *ownerPid = info[(id )kCGWindowOwnerPID ];
67
+ NSNumber *windowNumber = info[(id )kCGWindowNumber ];
68
+
69
+ auto app = [NSRunningApplication runningApplicationWithProcessIdentifier: [ownerPid intValue ]];
70
+
71
+ if (app && [windowNumber intValue ] == windowHandle) {
72
+ NSString *windowName = info[(id )kCGWindowName ];
73
+ return [windowName UTF8String ];
74
+ }
75
+ }
76
+
77
+ if (windowList) {
78
+ CFRelease (windowList);
79
+ }
80
+
81
+ return " " ;
82
+ }
0 commit comments