-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.m
51 lines (41 loc) · 1.27 KB
/
main.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
@import Cocoa;
static NSArray* windows;
static NSUInteger count;
#if __cplusplus
extern "C" {
#endif
__attribute__((visibility("default")))
int enumWindows()
{
CGWindowListOption listOptions = kCGWindowListOptionAll;
listOptions |= kCGWindowListOptionOnScreenOnly;
listOptions |= kCGWindowListExcludeDesktopElements;
// Ask the window server for the list of windows.
windows = (NSArray*)CGWindowListCopyWindowInfo(listOptions, kCGNullWindowID);
count = [windows count];
return count;
}
__attribute__((visibility("default")))
const char* getTitle(i) {
if(windows == NULL) {
count = enumWindows();
}
//for (NSUInteger i = 0; i < count; i++) {
//}
NSDictionary* nswindowsdescription = [windows objectAtIndex:i];
//NSNumber* windowid = (NSNumber*)[nswindowsdescription objectForKey:@"kCGWindowNumber"];
NSString* windowName = (NSString*)[nswindowsdescription objectForKey:@"kCGWindowOwnerName"];
NSNumber* windowLayer = (NSNumber*)[nswindowsdescription objectForKey:@"kCGWindowLayer"];
NSString* res = [NSString stringWithFormat:@"%@: %s", windowLayer, [windowName UTF8String]];
return (char *)[res UTF8String];
}
#if __cplusplus
}
#endif
int main(int argc, char *argv[])
{
int count = enumWindows();
for(int i = 0; i < count; i++) {
printf("%s\n", getTitle(i));
}
}