Skip to content

Instantly share code, notes, and snippets.

@sdsykes
Last active December 29, 2022 13:01
Show Gist options
  • Save sdsykes/5c2c0c2a41396aead3b7 to your computer and use it in GitHub Desktop.
Save sdsykes/5c2c0c2a41396aead3b7 to your computer and use it in GitHub Desktop.
Windows on a space (using private CGS)
/// header
id CGSCopyManagedDisplaySpaces(int conn);
int _CGSDefaultConnection();
id CGSCopyWindowsWithOptionsAndTags(int conn, unsigned owner, NSArray *spids, unsigned options, unsigned long long *setTags, unsigned long long *clearTags);
// code
int spaceNumber = 0; // the space you want to get the windows for. numbering starts at 0.
int conn = _CGSDefaultConnection();
NSArray *info = CGSCopyManagedDisplaySpaces(conn);
NSLog(@"space info: %@", info);
unsigned long long setTags = 0, clearTags = 0x4000000000;
int displayNumber = 0;
NSNumber *spaceID = info[displayNumber][@"Spaces"][spaceNumber][@"id64"];
NSArray *windows = CGSCopyWindowsWithOptionsAndTags(conn, 0, @[spaceID], 2, &setTags, &clearTags);
NSLog(@"windows on space %d are %@", spaceNumber, windows);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment