Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save own2pwn/b101a059c566b3d70375f6e8e662559f to your computer and use it in GitHub Desktop.

Select an option

Save own2pwn/b101a059c566b3d70375f6e8e662559f to your computer and use it in GitHub Desktop.

Revisions

  1. @mmmulani mmmulani created this gist Apr 11, 2016.
    38 changes: 38 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    #import <Foundation/Foundation.h>

    typedef uint64_t CGSSpace;
    typedef uint64_t CGSManagedDisplay;
    typedef int CGSConnection;

    typedef enum _CGSSpaceSelector {
    kCGSSpaceCurrent = 5,
    kCGSSpaceOther = 6,
    kCGSSpaceAll = 7
    } CGSSpaceSelector;

    extern CGSManagedDisplay kCGSPackagesMainDisplayIdentifier;

    extern CFArrayRef CGSCopySpaces(const CGSConnection cid, CGSSpaceSelector type);
    extern void CGSManagedDisplaySetCurrentSpace(const CGSConnection cid, CGSManagedDisplay display, CGSSpace space, CGSSpace space2);
    extern int CGSManagedDisplayGetCurrentSpace(const CGSConnection cid, CGSManagedDisplay display);
    extern void CGSShowSpaces(const CGSConnection cid, CFArrayRef spaces);
    extern void CGSHideSpaces(const CGSConnection cid, CFArrayRef spaces);

    extern CGSConnection _CGSDefaultConnection(void);

    extern id CGSWillSwitchSpaces(const CGSConnection cid, CFArrayRef spaces);

    int main(int argc, char *argv[]) {
    @autoreleasepool {
    NSLog(@"Current space: %d", CGSManagedDisplayGetCurrentSpace(_CGSDefaultConnection(), kCGSPackagesMainDisplayIdentifier));
    NSArray *spaces = @[ ];
    id result = CGSWillSwitchSpaces(_CGSDefaultConnection(), (__bridge CFArrayRef)spaces);
    NSLog(@"Will change spaces result: %@", result);
    CGSManagedDisplaySetCurrentSpace(_CGSDefaultConnection(), kCGSPackagesMainDisplayIdentifier, 3, 3);
    spaces = @[ @1, @3 ];
    CGSShowSpaces(_CGSDefaultConnection(), (__bridge CFArrayRef)spaces);
    spaces = @[ @1 ];
    CGSHideSpaces(_CGSDefaultConnection(), (__bridge CFArrayRef)spaces);
    NSLog(@"Current space: %d", CGSManagedDisplayGetCurrentSpace(_CGSDefaultConnection(), kCGSPackagesMainDisplayIdentifier));
    }
    }