PageRenderTime 24ms CodeModel.GetById 15ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/filesystems/procfs/procfs_windows.cc

http://macfuse.googlecode.com/
C++ | 67 lines | 46 code | 16 blank | 5 comment | 4 complexity | 97e3b05f5fe59200efa92e6bbc12bc05 MD5 | raw file
 1/*
 2 * MacFUSE-Based procfs
 3 * Windows
 4 *
 5 */
 6
 7#include <ApplicationServices/ApplicationServices.h>
 8
 9extern "C" {
10
11#include "procfs_windows.h"
12
13off_t
14PROCFS_GetPNGSizeForWindowAtIndex(CGWindowID index)
15{
16    CGRect rect;
17
18    CGError err = CGSGetScreenRectForWindow(_CGSDefaultConnection(), index,
19                                            &rect);
20    if (err) {
21        return (off_t)0;
22    }
23
24    off_t size = ((off_t)rect.size.width  * (off_t)rect.size.height * (off_t)3)
25                  + (off_t)8192;
26
27    return size;
28}
29
30int
31PROCFS_GetPNGForWindowAtIndex(CGWindowID index, CFMutableDataRef *data)
32{
33    *data = (CFMutableDataRef)0;
34
35    CGImageRef image = CGWindowListCreateImage(
36                           CGRectNull, kCGWindowListOptionIncludingWindow,
37                           index, kCGWindowImageBoundsIgnoreFraming);
38
39    if (!image) {
40        return -1;
41    }
42
43    *data = CFDataCreateMutable(kCFAllocatorDefault, 0);
44    if (!*data) {
45        CFRelease(image);
46        return -1;
47    }
48
49    CGImageDestinationRef dest = 
50        CGImageDestinationCreateWithData((CFMutableDataRef)*data, kUTTypePNG,
51                                         1, nil);
52    if (!dest) {
53        CFRelease(*data);
54        CFRelease(image);
55        return -1;
56    }
57
58    CGImageDestinationAddImage(dest, image, nil);
59    CGImageDestinationFinalize(dest);
60
61    CFRelease(dest);
62    CGImageRelease(image);
63
64    return 0;
65}
66
67} /* extern "C" */