-
Notifications
You must be signed in to change notification settings - Fork 11
/
procfs_windows.cc
67 lines (51 loc) · 1.4 KB
/
procfs_windows.cc
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
* MacFUSE-Based procfs
* Windows
*
*/
#include <ApplicationServices/ApplicationServices.h>
extern "C" {
#include "procfs_windows.h"
off_t
PROCFS_GetPNGSizeForWindowAtIndex(CGWindowID index)
{
CGRect rect;
CGError err = CGSGetScreenRectForWindow(_CGSDefaultConnection(), index,
&rect);
if (err) {
return (off_t)0;
}
off_t size = ((off_t)rect.size.width * (off_t)rect.size.height * (off_t)3)
+ (off_t)8192;
return size;
}
int
PROCFS_GetPNGForWindowAtIndex(CGWindowID index, CFMutableDataRef *data)
{
*data = (CFMutableDataRef)0;
CGImageRef image = CGWindowListCreateImage(
CGRectNull, kCGWindowListOptionIncludingWindow,
index, kCGWindowImageBoundsIgnoreFraming);
if (!image) {
return -1;
}
*data = CFDataCreateMutable(kCFAllocatorDefault, 0);
if (!*data) {
CFRelease(image);
return -1;
}
CGImageDestinationRef dest =
CGImageDestinationCreateWithData((CFMutableDataRef)*data, kUTTypePNG,
1, nil);
if (!dest) {
CFRelease(*data);
CFRelease(image);
return -1;
}
CGImageDestinationAddImage(dest, image, nil);
CGImageDestinationFinalize(dest);
CFRelease(dest);
CGImageRelease(image);
return 0;
}
} /* extern "C" */