-
Notifications
You must be signed in to change notification settings - Fork 0
/
WindowGrabber.m
47 lines (35 loc) · 1.64 KB
/
WindowGrabber.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
//
// WindowGrabber.m
// AXRecord
//
// Created by Sylvain Malacria on 11/03/16.
// Copyright © 2016 Sylvain Malacria. All rights reserved.
//
#import "WindowGrabber.h"
#import "VnrWindowInfo.h"
@implementation WindowGrabber
+(NSArray*)getWindowList
{
NSMutableArray *windows = (NSMutableArray *)CFBridgingRelease(CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements, kCGNullWindowID));
NSMutableArray *vnrWindows = [NSMutableArray new];
for (NSDictionary *window in windows) {
NSString *owner = [window objectForKey:@"kCGWindowOwnerName"];
NSString *name = [window objectForKey:@"kCGWindowName"];
int layer = [[window objectForKey:@"kCGWindowLayer"] intValue];
//if(layer==0){
BOOL onScreen = [[window objectForKey:@"kCGWindowIsOnscreen"] boolValue];
NSDictionary* bounds = [window objectForKey:@"kCGWindowBounds"];
int x = [[bounds objectForKey:@"X"] intValue];
int y = [[bounds objectForKey:@"Y"] intValue];
int w = [[bounds objectForKey:@"Width"] intValue];
int h = [[bounds objectForKey:@"Height"] intValue];
pid_t ownerPID = [[window objectForKey:@"kCGWindowOwnerPID"] intValue];
CGWindowID windowID = [[window objectForKey:@"kCGWindowNumber"] intValue];
VnrWindowInfo* winfo = [[VnrWindowInfo alloc] initWithFrame:CGRectMake(x,y,w,h) title:name owner:owner ownerPID:ownerPID windowID:windowID layer:layer];
[winfo setIsOnScreen:onScreen];
[vnrWindows addObject:winfo];
//}
}
return [vnrWindows copy];
}
@end