/filesystems/procfs/procfs_windows.cc
http://macfuse.googlecode.com/ · C++ · 67 lines · 46 code · 16 blank · 5 comment · 4 complexity · 97e3b05f5fe59200efa92e6bbc12bc05 MD5 · raw file
- /*
- * 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" */