/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. #include <ApplicationServices/ApplicationServices.h>
  7. extern "C" {
  8. #include "procfs_windows.h"
  9. off_t
  10. PROCFS_GetPNGSizeForWindowAtIndex(CGWindowID index)
  11. {
  12. CGRect rect;
  13. CGError err = CGSGetScreenRectForWindow(_CGSDefaultConnection(), index,
  14. &rect);
  15. if (err) {
  16. return (off_t)0;
  17. }
  18. off_t size = ((off_t)rect.size.width * (off_t)rect.size.height * (off_t)3)
  19. + (off_t)8192;
  20. return size;
  21. }
  22. int
  23. PROCFS_GetPNGForWindowAtIndex(CGWindowID index, CFMutableDataRef *data)
  24. {
  25. *data = (CFMutableDataRef)0;
  26. CGImageRef image = CGWindowListCreateImage(
  27. CGRectNull, kCGWindowListOptionIncludingWindow,
  28. index, kCGWindowImageBoundsIgnoreFraming);
  29. if (!image) {
  30. return -1;
  31. }
  32. *data = CFDataCreateMutable(kCFAllocatorDefault, 0);
  33. if (!*data) {
  34. CFRelease(image);
  35. return -1;
  36. }
  37. CGImageDestinationRef dest =
  38. CGImageDestinationCreateWithData((CFMutableDataRef)*data, kUTTypePNG,
  39. 1, nil);
  40. if (!dest) {
  41. CFRelease(*data);
  42. CFRelease(image);
  43. return -1;
  44. }
  45. CGImageDestinationAddImage(dest, image, nil);
  46. CGImageDestinationFinalize(dest);
  47. CFRelease(dest);
  48. CGImageRelease(image);
  49. return 0;
  50. }
  51. } /* extern "C" */