Skip to content

Commit c96a86a

Browse files
committed
(#17) Updated windowhandle types, added implementation for getWindowTitle
1 parent 36ba190 commit c96a86a

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

src/macos/window_manager.mm

+28-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
#import <ApplicationServices/ApplicationServices.h>
44
#include "../window_manager.h"
55

6-
std::vector<int32_t> getWindows() {
6+
std::vector<int64_t> getWindows() {
77
CGWindowListOption listOptions = kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements;
88
CFArrayRef windowList = CGWindowListCopyWindowInfo(listOptions, kCGNullWindowID);
99

10-
std::vector<int32_t> windowHandles;
10+
std::vector<int64_t> windowHandles;
1111

1212
for (NSDictionary *info in (NSArray *)windowList) {
1313
NSNumber *ownerPid = info[(id)kCGWindowOwnerPID];
@@ -28,7 +28,7 @@
2828
return windowHandles;
2929
}
3030

31-
MMRect getWindowRect(const int32_t windowHandle) {
31+
MMRect getWindowRect(const int64_t windowHandle) {
3232
CGWindowListOption listOptions = kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements;
3333
CFArrayRef windowList = CGWindowListCopyWindowInfo(listOptions, kCGNullWindowID);
3434

@@ -55,3 +55,28 @@ MMRect getWindowRect(const int32_t windowHandle) {
5555

5656
return MMRectMake(0, 0, 0, 0);
5757
}
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

Comments
 (0)