├── .gitignore ├── CGSAccessibility.h ├── CGSCIFilter.h ├── CGSConnection.h ├── CGSCursor.h ├── CGSDebug.h ├── CGSDevice.h ├── CGSDisplays.h ├── CGSEvent.h ├── CGSHotKeys.h ├── CGSInternal.h ├── CGSMisc.h ├── CGSRegion.h ├── CGSSession.h ├── CGSSpace.h ├── CGSSurface.h ├── CGSTile.h ├── CGSTransitions.h ├── CGSWindow.h ├── CGSWorkspace.h └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | .DS_Store 3 | */build/* 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | xcuserdata 13 | profile 14 | *.moved-aside 15 | DerivedData 16 | .idea/ 17 | *.hmap 18 | *.xccheckout 19 | 20 | #CocoaPods 21 | Pods 22 | 23 | -------------------------------------------------------------------------------- /CGSAccessibility.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2008 Alacatia Labs 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 3. This notice may not be removed or altered from any source distribution. 19 | * 20 | * Joe Ranieri joe@alacatia.com 21 | * 22 | */ 23 | 24 | // 25 | // Updated by Robert Widmann. 26 | // Copyright © 2015-2016 CodaFi. All rights reserved. 27 | // Released under the MIT license. 28 | // 29 | 30 | #ifndef CGS_ACCESSIBILITY_INTERNAL_H 31 | #define CGS_ACCESSIBILITY_INTERNAL_H 32 | 33 | #include "CGSConnection.h" 34 | 35 | 36 | #pragma mark - Display Zoom 37 | 38 | 39 | /// Gets whether the display is zoomed. 40 | CG_EXTERN CGError CGSIsZoomed(CGSConnectionID cid, bool *outIsZoomed); 41 | 42 | 43 | #pragma mark - Invert Colors 44 | 45 | 46 | /// Gets the preference value for inverted colors on the current display. 47 | CG_EXTERN bool CGDisplayUsesInvertedPolarity(void); 48 | 49 | /// Sets the preference value for the state of the inverted colors on the current display. This 50 | /// preference value is monitored by the system, and updating it causes a fairly immediate change 51 | /// in the screen's colors. 52 | /// 53 | /// Internally, this sets and synchronizes `DisplayUseInvertedPolarity` in the 54 | /// "com.apple.CoreGraphics" preferences bundle. 55 | CG_EXTERN void CGDisplaySetInvertedPolarity(bool invertedPolarity); 56 | 57 | 58 | #pragma mark - Use Grayscale 59 | 60 | 61 | /// Gets whether the screen forces all drawing as grayscale. 62 | CG_EXTERN bool CGDisplayUsesForceToGray(void); 63 | 64 | /// Sets whether the screen forces all drawing as grayscale. 65 | CG_EXTERN void CGDisplayForceToGray(bool forceToGray); 66 | 67 | 68 | #pragma mark - Increase Contrast 69 | 70 | 71 | /// Sets the display's contrast. There doesn't seem to be a get version of this function. 72 | CG_EXTERN CGError CGSSetDisplayContrast(CGFloat contrast); 73 | 74 | #endif /* CGS_ACCESSIBILITY_INTERNAL_H */ 75 | -------------------------------------------------------------------------------- /CGSCIFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2008 Alacatia Labs 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 3. This notice may not be removed or altered from any source distribution. 19 | * 20 | * Joe Ranieri joe@alacatia.com 21 | * 22 | */ 23 | 24 | // 25 | // Updated by Robert Widmann. 26 | // Copyright © 2015-2016 CodaFi. All rights reserved. 27 | // Released under the MIT license. 28 | // 29 | 30 | #ifndef CGS_CIFILTER_INTERNAL_H 31 | #define CGS_CIFILTER_INTERNAL_H 32 | 33 | #include "CGSConnection.h" 34 | 35 | typedef enum { 36 | kCGWindowFilterUnderlay = 1, 37 | kCGWindowFilterDock = 0x3001, 38 | } CGSCIFilterID; 39 | 40 | /// Creates a new filter from a filter name. 41 | /// 42 | /// Any valid CIFilter names are valid names for this function. 43 | CG_EXTERN CGError CGSNewCIFilterByName(CGSConnectionID cid, CFStringRef filterName, CGSCIFilterID *outFilter); 44 | 45 | /// Inserts the given filter into the window. 46 | /// 47 | /// The values for the `flags` field is currently unknown. 48 | CG_EXTERN CGError CGSAddWindowFilter(CGSConnectionID cid, CGWindowID wid, CGSCIFilterID filter, int flags); 49 | 50 | /// Removes the given filter from the window. 51 | CG_EXTERN CGError CGSRemoveWindowFilter(CGSConnectionID cid, CGWindowID wid, CGSCIFilterID filter); 52 | 53 | /// Invokes `-[CIFilter setValue:forKey:]` on each entry in the dictionary for the window's filter. 54 | /// 55 | /// The Window Server only checks for the existence of 56 | /// 57 | /// inputPhase 58 | /// inputPhase0 59 | /// inputPhase1 60 | CG_EXTERN CGError CGSSetCIFilterValuesFromDictionary(CGSConnectionID cid, CGSCIFilterID filter, CFDictionaryRef filterValues); 61 | 62 | /// Releases a window's CIFilter. 63 | CG_EXTERN CGError CGSReleaseCIFilter(CGSConnectionID cid, CGSCIFilterID filter); 64 | 65 | #endif /* CGS_CIFILTER_INTERNAL_H */ 66 | -------------------------------------------------------------------------------- /CGSConnection.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2008 Alacatia Labs 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 3. This notice may not be removed or altered from any source distribution. 19 | * 20 | * Joe Ranieri joe@alacatia.com 21 | * 22 | */ 23 | 24 | // 25 | // Updated by Robert Widmann. 26 | // Copyright © 2015-2016 CodaFi. All rights reserved. 27 | // Released under the MIT license. 28 | // 29 | 30 | #ifndef CGS_CONNECTION_INTERNAL_H 31 | #define CGS_CONNECTION_INTERNAL_H 32 | 33 | /// The type of connections to the Window Server. 34 | /// 35 | /// Every application is given a singular connection ID through which it can receieve and manipulate 36 | /// values, state, notifications, events, etc. in the Window Server. It 37 | typedef int CGSConnectionID; 38 | 39 | typedef void *CGSNotificationData; 40 | typedef void *CGSNotificationArg; 41 | typedef int CGSTransitionID; 42 | 43 | 44 | #pragma mark - Connection Lifecycle 45 | 46 | 47 | /// Gets the default connection for this process. 48 | CG_EXTERN CGSConnectionID CGSMainConnectionID(void); 49 | 50 | /// Creates a new connection to the Window Server. 51 | CG_EXTERN CGError CGSNewConnection(int unused, CGSConnectionID *outConnection); 52 | 53 | /// Releases a CGSConnection and all CGSWindows owned by it. 54 | CG_EXTERN CGError CGSReleaseConnection(CGSConnectionID cid); 55 | 56 | /// Gets the default connection for the current thread. 57 | CG_EXTERN CGSConnectionID CGSDefaultConnectionForThread(void); 58 | 59 | /// Gets the pid of the process that owns this connection to the Window Server. 60 | CG_EXTERN CGError CGSConnectionGetPID(CGSConnectionID cid, pid_t *outPID); 61 | 62 | /// Gets the connection for the given process serial number. 63 | CG_EXTERN CGError CGSGetConnectionIDForPSN(CGSConnectionID cid, const ProcessSerialNumber *psn, CGSConnectionID *outOwnerCID); 64 | 65 | /// Returns whether the menu bar exists for the given connection ID. 66 | /// 67 | /// For the majority of applications, this function should return true. But at system updates, 68 | /// initialization, and shutdown, the menu bar will be either initially gone then created or 69 | /// hidden and then destroyed. 70 | CG_EXTERN bool CGSMenuBarExists(CGSConnectionID cid); 71 | 72 | /// Closes ALL connections to the Window Server by the current application. 73 | /// 74 | /// The application is effectively turned into a Console-based application after the invocation of 75 | /// this method. 76 | CG_EXTERN CGError CGSShutdownServerConnections(void); 77 | 78 | 79 | #pragma mark - Connection Properties 80 | 81 | 82 | /// Retrieves the value associated with the given key for the given connection. 83 | /// 84 | /// This method is structured so processes can send values through the Window Server to other 85 | /// processes - assuming they know each others connection IDs. The recommended use case for this 86 | /// function appears to be keeping state around for application-level sub-connections. 87 | CG_EXTERN CGError CGSCopyConnectionProperty(CGSConnectionID cid, CGSConnectionID targetCID, CFStringRef key, CFTypeRef *outValue); 88 | 89 | /// Associates a value for the given key on the given connection. 90 | CG_EXTERN CGError CGSSetConnectionProperty(CGSConnectionID cid, CGSConnectionID targetCID, CFStringRef key, CFTypeRef value); 91 | 92 | 93 | #pragma mark - Connection Updates 94 | 95 | 96 | /// Disables updates on a connection 97 | /// 98 | /// Calls to disable updates nest much like `-beginUpdates`/`-endUpdates`. the Window Server will 99 | /// forcibly reenable updates after 1 second if you fail to invoke `CGSReenableUpdate`. 100 | CG_EXTERN CGError CGSDisableUpdate(CGSConnectionID cid); 101 | 102 | /// Re-enables updates on a connection. 103 | /// 104 | /// Calls to enable updates nest much like `-beginUpdates`/`-endUpdates`. 105 | CG_EXTERN CGError CGSReenableUpdate(CGSConnectionID cid); 106 | 107 | 108 | #pragma mark - Connection Notifications 109 | 110 | 111 | typedef void (*CGSNewConnectionNotificationProc)(CGSConnectionID cid); 112 | 113 | /// Registers a function that gets invoked when the application's connection ID is created by the 114 | /// Window Server. 115 | CG_EXTERN CGError CGSRegisterForNewConnectionNotification(CGSNewConnectionNotificationProc proc); 116 | 117 | /// Removes a function that was registered to receive notifications for the creation of the 118 | /// application's connection to the Window Server. 119 | CG_EXTERN CGError CGSRemoveNewConnectionNotification(CGSNewConnectionNotificationProc proc); 120 | 121 | typedef void (*CGSConnectionDeathNotificationProc)(CGSConnectionID cid); 122 | 123 | /// Registers a function that gets invoked when the application's connection ID is destroyed - 124 | /// ideally by the Window Server. 125 | /// 126 | /// Connection death is supposed to be a fatal event that is only triggered when the application 127 | /// terminates or when you have explicitly destroyed a sub-connection to the Window Server. 128 | CG_EXTERN CGError CGSRegisterForConnectionDeathNotification(CGSConnectionDeathNotificationProc proc); 129 | 130 | /// Removes a function that was registered to receive notifications for the destruction of the 131 | /// application's connection to the Window Server. 132 | CG_EXTERN CGError CGSRemoveConnectionDeathNotification(CGSConnectionDeathNotificationProc proc); 133 | 134 | 135 | #pragma mark - Miscellaneous Security Holes 136 | 137 | /// Sets a "Universal Owner" for the connection ID. Currently, that owner is Dock.app, which needs 138 | /// control over the window to provide system features like hiding and showing windows, moving them 139 | /// around, etc. 140 | /// 141 | /// Because the Universal Owner owns every window under this connection, it can manipulate them 142 | /// all as it sees fit. If you can beat the dock, you have total control over the process' 143 | /// connection. 144 | CG_EXTERN CGError CGSSetUniversalOwner(CGSConnectionID cid); 145 | 146 | /// Assuming you have the connection ID of the current universal owner, or are said universal owner, 147 | /// allows you to specify another connection that has total control over the application's windows. 148 | CG_EXTERN CGError CGSSetOtherUniversalConnection(CGSConnectionID cid, CGSConnectionID otherConnection); 149 | 150 | /// Sets the given connection ID as the login window connection ID. Windows for the application are 151 | /// then brought to the fore when the computer logs off or goes to sleep. 152 | /// 153 | /// Why this is still here, I have no idea. Window Server only accepts one process calling this 154 | /// ever. If you attempt to invoke this after loginwindow does you will be yelled at and nothing 155 | /// will happen. If you can manage to beat loginwindow, however, you know what they say: 156 | /// 157 | /// When you teach a man to phish... 158 | CG_EXTERN CGError CGSSetLoginwindowConnection(CGSConnectionID cid) AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER; 159 | 160 | //! The data sent with kCGSNotificationAppUnresponsive and kCGSNotificationAppResponsive. 161 | typedef struct { 162 | #if __BIG_ENDIAN__ 163 | uint16_t majorVersion; 164 | uint16_t minorVersion; 165 | #else 166 | uint16_t minorVersion; 167 | uint16_t majorVersion; 168 | #endif 169 | 170 | //! The length of the entire notification. 171 | uint32_t length; 172 | 173 | CGSConnectionID cid; 174 | pid_t pid; 175 | ProcessSerialNumber psn; 176 | } CGSProcessNotificationData; 177 | 178 | //! The data sent with kCGSNotificationDebugOptionsChanged. 179 | typedef struct { 180 | int newOptions; 181 | int unknown[2]; // these two seem to be zero 182 | } CGSDebugNotificationData; 183 | 184 | //! The data sent with kCGSNotificationTransitionEnded 185 | typedef struct { 186 | CGSTransitionID transition; 187 | } CGSTransitionNotificationData; 188 | 189 | #endif /* CGS_CONNECTION_INTERNAL_H */ 190 | -------------------------------------------------------------------------------- /CGSCursor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2008 Alacatia Labs 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 3. This notice may not be removed or altered from any source distribution. 19 | * 20 | * Joe Ranieri joe@alacatia.com 21 | * 22 | */ 23 | 24 | // 25 | // Updated by Robert Widmann. 26 | // Copyright © 2015-2016 CodaFi. All rights reserved. 27 | // Released under the MIT license. 28 | // 29 | 30 | #ifndef CGS_CURSOR_INTERNAL_H 31 | #define CGS_CURSOR_INTERNAL_H 32 | 33 | #include "CGSConnection.h" 34 | 35 | typedef enum : NSInteger { 36 | CGSCursorArrow = 0, 37 | CGSCursorIBeam = 1, 38 | CGSCursorIBeamXOR = 2, 39 | CGSCursorAlias = 3, 40 | CGSCursorCopy = 4, 41 | CGSCursorMove = 5, 42 | CGSCursorArrowContext = 6, 43 | CGSCursorWait = 7, 44 | CGSCursorEmpty = 8, 45 | } CGSCursorID; 46 | 47 | 48 | /// Registers a cursor with the given properties. 49 | /// 50 | /// - Parameter cid: The connection ID to register with. 51 | /// - Parameter cursorName: The system-wide name the cursor will be registered under. 52 | /// - Parameter setGlobally: Whether the cursor registration can appear system-wide. 53 | /// - Parameter instantly: Whether the registration of cursor images should occur immediately. Passing false 54 | /// may speed up the call. 55 | /// - Parameter frameCount: The number of images in the cursor image array. 56 | /// - Parameter imageArray: An array of CGImageRefs that are used to display the cursor. Multiple images in 57 | /// conjunction with a non-zero `frameDuration` cause animation. 58 | /// - Parameter cursorSize: The size of the cursor's images. Recommended size is 16x16 points 59 | /// - Parameter hotspot: The location touch events will emanate from. 60 | /// - Parameter seed: The seed for the cursor's registration. 61 | /// - Parameter bounds: The total size of the cursor. 62 | /// - Parameter frameDuration: How long each image will be displayed for. 63 | /// - Parameter repeatCount: Number of times the cursor should repeat cycling its image frames. 64 | CG_EXTERN CGError CGSRegisterCursorWithImages(CGSConnectionID cid, 65 | const char *cursorName, 66 | bool setGlobally, bool instantly, 67 | NSUInteger frameCount, CFArrayRef imageArray, 68 | CGSize cursorSize, CGPoint hotspot, 69 | int *seed, 70 | CGRect bounds, CGFloat frameDuration, 71 | NSInteger repeatCount); 72 | 73 | 74 | #pragma mark - Cursor Registration 75 | 76 | 77 | /// Copies the size of data associated with the cursor registered under the given name. 78 | CG_EXTERN CGError CGSGetRegisteredCursorDataSize(CGSConnectionID cid, const char *cursorName, size_t *outDataSize); 79 | 80 | /// Re-assigns the given cursor name to the cursor represented by the given seed value. 81 | CG_EXTERN CGError CGSSetRegisteredCursor(CGSConnectionID cid, const char *cursorName, int *cursorSeed); 82 | 83 | /// Copies the properties out of the cursor registered under the given name. 84 | CG_EXTERN CGError CGSCopyRegisteredCursorImages(CGSConnectionID cid, const char *cursorName, CGSize *imageSize, CGPoint *hotSpot, NSUInteger *frameCount, CGFloat *frameDuration, CFArrayRef *imageArray); 85 | 86 | /// Re-assigns one of the system-defined cursors to the cursor represented by the given seed value. 87 | CG_EXTERN void CGSSetSystemDefinedCursorWithSeed(CGSConnectionID connection, CGSCursorID systemCursor, int *cursorSeed); 88 | 89 | 90 | #pragma mark - Cursor Display 91 | 92 | 93 | /// Shows the cursor. 94 | CG_EXTERN CGError CGSShowCursor(CGSConnectionID cid); 95 | 96 | /// Hides the cursor. 97 | CG_EXTERN CGError CGSHideCursor(CGSConnectionID cid); 98 | 99 | /// Hides the cursor until the cursor is moved. 100 | CG_EXTERN CGError CGSObscureCursor(CGSConnectionID cid); 101 | 102 | /// Acts as if a mouse moved event occured and that reveals the cursor if it was hidden. 103 | CG_EXTERN CGError CGSRevealCursor(CGSConnectionID cid); 104 | 105 | /// Shows or hides the spinning beachball of death. 106 | /// 107 | /// If you call this, I hate you. 108 | CG_EXTERN CGError CGSForceWaitCursorActive(CGSConnectionID cid, bool showWaitCursor); 109 | 110 | /// Unconditionally sets the location of the cursor on the screen to the given coordinates. 111 | CG_EXTERN CGError CGSWarpCursorPosition(CGSConnectionID cid, CGFloat x, CGFloat y); 112 | 113 | 114 | #pragma mark - Cursor Properties 115 | 116 | 117 | /// Gets the current cursor's seed value. 118 | /// 119 | /// Every time the cursor is updated, the seed changes. 120 | CG_EXTERN int CGSCurrentCursorSeed(void); 121 | 122 | /// Gets the current location of the cursor relative to the screen's coordinates. 123 | CG_EXTERN CGError CGSGetCurrentCursorLocation(CGSConnectionID cid, CGPoint *outPos); 124 | 125 | /// Gets the name (ideally in reverse DNS form) of a system cursor. 126 | CG_EXTERN char *CGSCursorNameForSystemCursor(CGSCursorID cursor); 127 | 128 | /// Gets the scale of the current currsor. 129 | CG_EXTERN CGError CGSGetCursorScale(CGSConnectionID cid, CGFloat *outScale); 130 | 131 | /// Sets the scale of the current cursor. 132 | /// 133 | /// The largest the Universal Access prefpane allows you to go is 4.0. 134 | CG_EXTERN CGError CGSSetCursorScale(CGSConnectionID cid, CGFloat scale); 135 | 136 | 137 | #pragma mark - Cursor Data 138 | 139 | 140 | /// Gets the size of the data for the connection's cursor. 141 | CG_EXTERN CGError CGSGetCursorDataSize(CGSConnectionID cid, size_t *outDataSize); 142 | 143 | /// Gets the data for the connection's cursor. 144 | CG_EXTERN CGError CGSGetCursorData(CGSConnectionID cid, void *outData); 145 | 146 | /// Gets the size of the data for the current cursor. 147 | CG_EXTERN CGError CGSGetGlobalCursorDataSize(CGSConnectionID cid, size_t *outDataSize); 148 | 149 | /// Gets the data for the current cursor. 150 | CG_EXTERN CGError CGSGetGlobalCursorData(CGSConnectionID cid, void *outData, int *outDataSize, int *outRowBytes, CGRect *outRect, CGPoint *outHotSpot, int *outDepth, int *outComponents, int *outBitsPerComponent); 151 | 152 | /// Gets the size of data for a system-defined cursor. 153 | CG_EXTERN CGError CGSGetSystemDefinedCursorDataSize(CGSConnectionID cid, CGSCursorID cursor, size_t *outDataSize); 154 | 155 | /// Gets the data for a system-defined cursor. 156 | CG_EXTERN CGError CGSGetSystemDefinedCursorData(CGSConnectionID cid, CGSCursorID cursor, void *outData, int *outRowBytes, CGRect *outRect, CGPoint *outHotSpot, int *outDepth, int *outComponents, int *outBitsPerComponent); 157 | 158 | #endif /* CGS_CURSOR_INTERNAL_H */ 159 | -------------------------------------------------------------------------------- /CGSDebug.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Routines for debugging the Window Server and application drawing. 3 | * 4 | * Copyright (C) 2007-2008 Alacatia Labs 5 | * 6 | * This software is provided 'as-is', without any express or implied 7 | * warranty. In no event will the authors be held liable for any damages 8 | * arising from the use of this software. 9 | * 10 | * Permission is granted to anyone to use this software for any purpose, 11 | * including commercial applications, and to alter it and redistribute it 12 | * freely, subject to the following restrictions: 13 | * 14 | * 1. The origin of this software must not be misrepresented; you must not 15 | * claim that you wrote the original software. If you use this software 16 | * in a product, an acknowledgment in the product documentation would be 17 | * appreciated but is not required. 18 | * 2. Altered source versions must be plainly marked as such, and must not be 19 | * misrepresented as being the original software. 20 | * 3. This notice may not be removed or altered from any source distribution. 21 | * 22 | * Joe Ranieri joe@alacatia.com 23 | * 24 | */ 25 | 26 | // 27 | // Updated by Robert Widmann. 28 | // Copyright © 2015-2016 CodaFi. All rights reserved. 29 | // Released under the MIT license. 30 | // 31 | 32 | #ifndef CGS_DEBUG_INTERNAL_H 33 | #define CGS_DEBUG_INTERNAL_H 34 | 35 | #include "CGSConnection.h" 36 | 37 | /// The set of options that the Window Server 38 | typedef enum { 39 | /// Clears all flags. 40 | kCGSDebugOptionNone = 0, 41 | 42 | /// All screen updates are flashed in yellow. Regions under a DisableUpdate are flashed in orange. Regions that are hardware accellerated are painted green. 43 | kCGSDebugOptionFlashScreenUpdates = 0x4, 44 | 45 | /// Colors windows green if they are accellerated, otherwise red. Doesn't cause things to refresh properly - leaves excess rects cluttering the screen. 46 | kCGSDebugOptionColorByAccelleration = 0x20, 47 | 48 | /// Disables shadows on all windows. 49 | kCGSDebugOptionNoShadows = 0x4000, 50 | 51 | /// Setting this disables the pause after a flash when using FlashScreenUpdates or FlashIdenticalUpdates. 52 | kCGSDebugOptionNoDelayAfterFlash = 0x20000, 53 | 54 | /// Flushes the contents to the screen after every drawing operation. 55 | kCGSDebugOptionAutoflushDrawing = 0x40000, 56 | 57 | /// Highlights mouse tracking areas. Doesn't cause things to refresh correctly - leaves excess rectangles cluttering the screen. 58 | kCGSDebugOptionShowMouseTrackingAreas = 0x100000, 59 | 60 | /// Flashes identical updates in red. 61 | kCGSDebugOptionFlashIdenticalUpdates = 0x4000000, 62 | 63 | /// Dumps a list of windows to /tmp/WindowServer.winfo.out. This is what Quartz Debug uses to get the window list. 64 | kCGSDebugOptionDumpWindowListToFile = 0x80000001, 65 | 66 | /// Dumps a list of connections to /tmp/WindowServer.cinfo.out. 67 | kCGSDebugOptionDumpConnectionListToFile = 0x80000002, 68 | 69 | /// Dumps a very verbose debug log of the WindowServer to /tmp/CGLog_WinServer_. 70 | kCGSDebugOptionVerboseLogging = 0x80000006, 71 | 72 | /// Dumps a very verbose debug log of all processes to /tmp/CGLog__. 73 | kCGSDebugOptionVerboseLoggingAllApps = 0x80000007, 74 | 75 | /// Dumps a list of hotkeys to /tmp/WindowServer.keyinfo.out. 76 | kCGSDebugOptionDumpHotKeyListToFile = 0x8000000E, 77 | 78 | /// Dumps information about OpenGL extensions, etc to /tmp/WindowServer.glinfo.out. 79 | kCGSDebugOptionDumpOpenGLInfoToFile = 0x80000013, 80 | 81 | /// Dumps a list of shadows to /tmp/WindowServer.shinfo.out. 82 | kCGSDebugOptionDumpShadowListToFile = 0x80000014, 83 | 84 | /// Leopard: Dumps information about caches to `/tmp/WindowServer.scinfo.out`. 85 | kCGSDebugOptionDumpCacheInformationToFile = 0x80000015, 86 | 87 | /// Leopard: Purges some sort of cache - most likely the same caches dummped with `kCGSDebugOptionDumpCacheInformationToFile`. 88 | kCGSDebugOptionPurgeCaches = 0x80000016, 89 | 90 | /// Leopard: Dumps a list of windows to `/tmp/WindowServer.winfo.plist`. This is what Quartz Debug on 10.5 uses to get the window list. 91 | kCGSDebugOptionDumpWindowListToPlist = 0x80000017, 92 | 93 | /// Leopard: DOCUMENTATION PENDING 94 | kCGSDebugOptionEnableSurfacePurging = 0x8000001B, 95 | 96 | // Leopard: 0x8000001C - invalid 97 | 98 | /// Leopard: DOCUMENTATION PENDING 99 | kCGSDebugOptionDisableSurfacePurging = 0x8000001D, 100 | 101 | /// Leopard: Dumps information about an application's resource usage to `/tmp/CGResources__`. 102 | kCGSDebugOptionDumpResourceUsageToFiles = 0x80000020, 103 | 104 | // Leopard: 0x80000022 - something about QuartzGL? 105 | 106 | // Leopard: Returns the magic mirror to its normal mode. The magic mirror is what the Dock uses to draw the screen reflection. For more information, see `CGSSetMagicMirror`. 107 | kCGSDebugOptionSetMagicMirrorModeNormal = 0x80000023, 108 | 109 | /// Leopard: Disables the magic mirror. It still appears but draws black instead of a reflection. 110 | kCGSDebugOptionSetMagicMirrorModeDisabled = 0x80000024, 111 | } CGSDebugOption; 112 | 113 | 114 | /// Gets and sets the debug options. 115 | /// 116 | /// These options are global and are not reset when your application dies! 117 | CG_EXTERN CGError CGSGetDebugOptions(int *outCurrentOptions); 118 | CG_EXTERN CGError CGSSetDebugOptions(int options); 119 | 120 | /// Queries the server about its performance. This is how Quartz Debug gets the FPS meter, but not 121 | /// the CPU meter (for that it uses host_processor_info). Quartz Debug subtracts 25 so that it is at 122 | /// zero with the minimum FPS. 123 | CG_EXTERN CGError CGSGetPerformanceData(CGSConnectionID cid, CGFloat *outFPS, CGFloat *unk, CGFloat *unk2, CGFloat *unk3); 124 | 125 | #endif /* CGS_DEBUG_INTERNAL_H */ 126 | -------------------------------------------------------------------------------- /CGSDevice.h: -------------------------------------------------------------------------------- 1 | // 2 | // CGSDevice.h 3 | // CGSInternal 4 | // 5 | // Created by Robert Widmann on 9/14/13. 6 | // Copyright (c) 2016 CodaFi. All rights reserved. 7 | // Released under the MIT license. 8 | // 9 | 10 | 11 | #ifndef CGS_DEVICE_INTERNAL_H 12 | #define CGS_DEVICE_INTERNAL_H 13 | 14 | #include "CGSConnection.h" 15 | 16 | /// Actuates the Taptic Engine underneath the user's fingers. 17 | /// 18 | /// Valid patterns are in the range 0x1-0x6 and 0xf-0x10 inclusive. 19 | /// 20 | /// Currently, deviceID and strength must be 0 as non-zero configurations are not 21 | /// yet supported 22 | CG_EXTERN CGError CGSActuateDeviceWithPattern(CGSConnectionID cid, int deviceID, int pattern, int strength) AVAILABLE_MAC_OS_X_VERSION_10_11_AND_LATER; 23 | 24 | /// Overrides the current pressure configuration with the given configuration. 25 | CG_EXTERN CGError CGSSetPressureConfigurationOverride(CGSConnectionID cid, int deviceID, void *config) AVAILABLE_MAC_OS_X_VERSION_10_10_3_AND_LATER; 26 | 27 | #endif /* CGSDevice_h */ 28 | -------------------------------------------------------------------------------- /CGSDisplays.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2008 Alacatia Labs 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 3. This notice may not be removed or altered from any source distribution. 19 | * 20 | * Joe Ranieri joe@alacatia.com 21 | * Ryan Govostes ryan@alacatia.com 22 | * 23 | */ 24 | 25 | // 26 | // Updated by Robert Widmann. 27 | // Copyright © 2015-2016 CodaFi. All rights reserved. 28 | // Released under the MIT license. 29 | // 30 | 31 | #ifndef CGS_DISPLAYS_INTERNAL_H 32 | #define CGS_DISPLAYS_INTERNAL_H 33 | 34 | #include "CGSRegion.h" 35 | 36 | typedef enum { 37 | CGSDisplayQueryMirrorStatus = 9, 38 | } CGSDisplayQuery; 39 | 40 | typedef struct { 41 | uint32_t mode; 42 | uint32_t flags; 43 | uint32_t width; 44 | uint32_t height; 45 | uint32_t depth; 46 | uint32_t dc2[42]; 47 | uint16_t dc3; 48 | uint16_t freq; 49 | uint8_t dc4[16]; 50 | CGFloat scale; 51 | } CGSDisplayModeDescription; 52 | 53 | typedef int CGSDisplayMode; 54 | 55 | 56 | /// Gets the main display. 57 | CG_EXTERN CGDirectDisplayID CGSMainDisplayID(void); 58 | 59 | 60 | #pragma mark - Display Properties 61 | 62 | 63 | /// Gets the number of displays known to the system. 64 | CG_EXTERN uint32_t CGSGetNumberOfDisplays(void); 65 | 66 | /// Gets the depth of a display. 67 | CG_EXTERN CGError CGSGetDisplayDepth(CGDirectDisplayID display, int *outDepth); 68 | 69 | /// Gets the displays at a point. Note that multiple displays can have the same point - think mirroring. 70 | CG_EXTERN CGError CGSGetDisplaysWithPoint(const CGPoint *point, int maxDisplayCount, CGDirectDisplayID *outDisplays, int *outDisplayCount); 71 | 72 | /// Gets the displays which contain a rect. Note that multiple displays can have the same bounds - think mirroring. 73 | CG_EXTERN CGError CGSGetDisplaysWithRect(const CGRect *point, int maxDisplayCount, CGDirectDisplayID *outDisplays, int *outDisplayCount); 74 | 75 | /// Gets the bounds for the display. Note that multiple displays can have the same bounds - think mirroring. 76 | CG_EXTERN CGError CGSGetDisplayRegion(CGDirectDisplayID display, CGSRegionRef *outRegion); 77 | CG_EXTERN CGError CGSGetDisplayBounds(CGDirectDisplayID display, CGRect *outRect); 78 | 79 | /// Gets the number of bytes per row. 80 | CG_EXTERN CGError CGSGetDisplayRowBytes(CGDirectDisplayID display, int *outRowBytes); 81 | 82 | /// Returns an array of dictionaries describing the spaces each screen contains. 83 | CG_EXTERN CFArrayRef CGSCopyManagedDisplaySpaces(CGSConnectionID cid); 84 | 85 | /// Gets the current display mode for the display. 86 | CG_EXTERN CGError CGSGetCurrentDisplayMode(CGDirectDisplayID display, int *modeNum); 87 | 88 | /// Gets the number of possible display modes for the display. 89 | CG_EXTERN CGError CGSGetNumberOfDisplayModes(CGDirectDisplayID display, int *nModes); 90 | 91 | /// Gets a description of the mode of the display. 92 | CG_EXTERN CGError CGSGetDisplayModeDescriptionOfLength(CGDirectDisplayID display, int idx, CGSDisplayModeDescription *desc, int length); 93 | 94 | /// Sets a display's configuration mode. 95 | CG_EXTERN CGError CGSConfigureDisplayMode(CGDisplayConfigRef config, CGDirectDisplayID display, int modeNum); 96 | 97 | /// Gets a list of on line displays */ 98 | CG_EXTERN CGDisplayErr CGSGetOnlineDisplayList(CGDisplayCount maxDisplays, CGDirectDisplayID *displays, CGDisplayCount *outDisplayCount); 99 | 100 | /// Gets a list of active displays */ 101 | CG_EXTERN CGDisplayErr CGSGetActiveDisplayList(CGDisplayCount maxDisplays, CGDirectDisplayID *displays, CGDisplayCount *outDisplayCount); 102 | 103 | 104 | #pragma mark - Display Configuration 105 | 106 | 107 | /// Begins a new display configuration transacation. 108 | CG_EXTERN CGDisplayErr CGSBeginDisplayConfiguration(CGDisplayConfigRef *config); 109 | 110 | /// Sets the origin of a display relative to the main display. The main display is at (0, 0) and contains the menubar. 111 | CG_EXTERN CGDisplayErr CGSConfigureDisplayOrigin(CGDisplayConfigRef config, CGDirectDisplayID display, int32_t x, int32_t y); 112 | 113 | /// Applies the configuration changes made in this transaction. 114 | CG_EXTERN CGDisplayErr CGSCompleteDisplayConfiguration(CGDisplayConfigRef config); 115 | 116 | /// Drops the configuration changes made in this transaction. 117 | CG_EXTERN CGDisplayErr CGSCancelDisplayConfiguration(CGDisplayConfigRef config); 118 | 119 | 120 | #pragma mark - Querying for Display Status 121 | 122 | 123 | /// Queries the Window Server about the status of the query. 124 | CG_EXTERN CGError CGSDisplayStatusQuery(CGDirectDisplayID display, CGSDisplayQuery query); 125 | 126 | #endif /* CGS_DISPLAYS_INTERNAL_H */ 127 | -------------------------------------------------------------------------------- /CGSEvent.h: -------------------------------------------------------------------------------- 1 | // 2 | // CGSEvent.h 3 | // CGSInternal 4 | // 5 | // Created by Robert Widmann on 9/14/13. 6 | // Copyright (c) 2015-2016 CodaFi. All rights reserved. 7 | // Released under the MIT license. 8 | // 9 | 10 | #ifndef CGS_EVENT_INTERNAL_H 11 | #define CGS_EVENT_INTERNAL_H 12 | 13 | #include "CGSWindow.h" 14 | 15 | typedef unsigned long CGSByteCount; 16 | typedef unsigned short CGSEventRecordVersion; 17 | typedef unsigned long long CGSEventRecordTime; /* nanosecond timer */ 18 | typedef unsigned long CGSEventFlag; 19 | typedef unsigned long CGSError; 20 | 21 | typedef enum : unsigned int { 22 | kCGSDisplayWillReconfigure = 100, 23 | kCGSDisplayDidReconfigure = 101, 24 | kCGSDisplayWillSleep = 102, 25 | kCGSDisplayDidWake = 103, 26 | kCGSDisplayIsCaptured = 106, 27 | kCGSDisplayIsReleased = 107, 28 | kCGSDisplayAllDisplaysReleased = 108, 29 | kCGSDisplayHardwareChanged = 111, 30 | kCGSDisplayDidReconfigure2 = 115, 31 | kCGSDisplayFullScreenAppRunning = 116, 32 | kCGSDisplayFullScreenAppDone = 117, 33 | kCGSDisplayReconfigureHappened = 118, 34 | kCGSDisplayColorProfileChanged = 119, 35 | kCGSDisplayZoomStateChanged = 120, 36 | kCGSDisplayAcceleratorChanged = 121, 37 | kCGSDebugOptionsChangedNotification = 200, 38 | kCGSDebugPrintResourcesNotification = 203, 39 | kCGSDebugPrintResourcesMemoryNotification = 205, 40 | kCGSDebugPrintResourcesContextNotification = 206, 41 | kCGSDebugPrintResourcesImageNotification = 208, 42 | kCGSServerConnDirtyScreenNotification = 300, 43 | kCGSServerLoginNotification = 301, 44 | kCGSServerShutdownNotification = 302, 45 | kCGSServerUserPreferencesLoadedNotification = 303, 46 | kCGSServerUpdateDisplayNotification = 304, 47 | kCGSServerCAContextDidCommitNotification = 305, 48 | kCGSServerUpdateDisplayCompletedNotification = 306, 49 | 50 | kCPXForegroundProcessSwitched = 400, 51 | kCPXSpecialKeyPressed = 401, 52 | kCPXForegroundProcessSwitchRequestedButRedundant = 402, 53 | 54 | kCGSSpecialKeyEventNotification = 700, 55 | 56 | kCGSEventNotificationNullEvent = 710, 57 | kCGSEventNotificationLeftMouseDown = 711, 58 | kCGSEventNotificationLeftMouseUp = 712, 59 | kCGSEventNotificationRightMouseDown = 713, 60 | kCGSEventNotificationRightMouseUp = 714, 61 | kCGSEventNotificationMouseMoved = 715, 62 | kCGSEventNotificationLeftMouseDragged = 716, 63 | kCGSEventNotificationRightMouseDragged = 717, 64 | kCGSEventNotificationMouseEntered = 718, 65 | kCGSEventNotificationMouseExited = 719, 66 | 67 | kCGSEventNotificationKeyDown = 720, 68 | kCGSEventNotificationKeyUp = 721, 69 | kCGSEventNotificationFlagsChanged = 722, 70 | kCGSEventNotificationKitDefined = 723, 71 | kCGSEventNotificationSystemDefined = 724, 72 | kCGSEventNotificationApplicationDefined = 725, 73 | kCGSEventNotificationTimer = 726, 74 | kCGSEventNotificationCursorUpdate = 727, 75 | kCGSEventNotificationSuspend = 729, 76 | kCGSEventNotificationResume = 730, 77 | kCGSEventNotificationNotification = 731, 78 | kCGSEventNotificationScrollWheel = 732, 79 | kCGSEventNotificationTabletPointer = 733, 80 | kCGSEventNotificationTabletProximity = 734, 81 | kCGSEventNotificationOtherMouseDown = 735, 82 | kCGSEventNotificationOtherMouseUp = 736, 83 | kCGSEventNotificationOtherMouseDragged = 737, 84 | kCGSEventNotificationZoom = 738, 85 | kCGSEventNotificationAppIsUnresponsive = 750, 86 | kCGSEventNotificationAppIsNoLongerUnresponsive = 751, 87 | 88 | kCGSEventSecureTextInputIsActive = 752, 89 | kCGSEventSecureTextInputIsOff = 753, 90 | 91 | kCGSEventNotificationSymbolicHotKeyChanged = 760, 92 | kCGSEventNotificationSymbolicHotKeyDisabled = 761, 93 | kCGSEventNotificationSymbolicHotKeyEnabled = 762, 94 | kCGSEventNotificationHotKeysGloballyDisabled = 763, 95 | kCGSEventNotificationHotKeysGloballyEnabled = 764, 96 | kCGSEventNotificationHotKeysExceptUniversalAccessGloballyDisabled = 765, 97 | kCGSEventNotificationHotKeysExceptUniversalAccessGloballyEnabled = 766, 98 | 99 | kCGSWindowIsObscured = 800, 100 | kCGSWindowIsUnobscured = 801, 101 | kCGSWindowIsOrderedIn = 802, 102 | kCGSWindowIsOrderedOut = 803, 103 | kCGSWindowIsTerminated = 804, 104 | kCGSWindowIsChangingScreens = 805, 105 | kCGSWindowDidMove = 806, 106 | kCGSWindowDidResize = 807, 107 | kCGSWindowDidChangeOrder = 808, 108 | kCGSWindowGeometryDidChange = 809, 109 | kCGSWindowMonitorDataPending = 810, 110 | kCGSWindowDidCreate = 811, 111 | kCGSWindowRightsGrantOffered = 812, 112 | kCGSWindowRightsGrantCompleted = 813, 113 | kCGSWindowRecordForTermination = 814, 114 | kCGSWindowIsVisible = 815, 115 | kCGSWindowIsInvisible = 816, 116 | 117 | kCGSLikelyUnbalancedDisableUpdateNotification = 902, 118 | 119 | kCGSConnectionWindowsBecameVisible = 904, 120 | kCGSConnectionWindowsBecameOccluded = 905, 121 | kCGSConnectionWindowModificationsStarted = 906, 122 | kCGSConnectionWindowModificationsStopped = 907, 123 | 124 | kCGSWindowBecameVisible = 912, 125 | kCGSWindowBecameOccluded = 913, 126 | 127 | kCGSServerWindowDidCreate = 1000, 128 | kCGSServerWindowWillTerminate = 1001, 129 | kCGSServerWindowOrderDidChange = 1002, 130 | kCGSServerWindowDidTerminate = 1003, 131 | 132 | kCGSWindowWasMovedByDockEvent = 1205, 133 | kCGSWindowWasResizedByDockEvent = 1207, 134 | kCGSWindowDidBecomeManagedByDockEvent = 1208, 135 | 136 | kCGSServerMenuBarCreated = 1300, 137 | kCGSServerHidBackstopMenuBar = 1301, 138 | kCGSServerShowBackstopMenuBar = 1302, 139 | kCGSServerMenuBarDrawingStyleChanged = 1303, 140 | kCGSServerPersistentAppsRegistered = 1304, 141 | kCGSServerPersistentCheckinComplete = 1305, 142 | 143 | kCGSPackagesWorkspacesDisabled = 1306, 144 | kCGSPackagesWorkspacesEnabled = 1307, 145 | kCGSPackagesStatusBarSpaceChanged = 1308, 146 | 147 | kCGSWorkspaceWillChange = 1400, 148 | kCGSWorkspaceDidChange = 1401, 149 | kCGSWorkspaceWindowIsViewable = 1402, 150 | kCGSWorkspaceWindowIsNotViewable = 1403, 151 | kCGSWorkspaceWindowDidMove = 1404, 152 | kCGSWorkspacePrefsDidChange = 1405, 153 | kCGSWorkspacesWindowDragDidStart = 1411, 154 | kCGSWorkspacesWindowDragDidEnd = 1412, 155 | kCGSWorkspacesWindowDragWillEnd = 1413, 156 | kCGSWorkspacesShowSpaceForProcess = 1414, 157 | kCGSWorkspacesWindowDidOrderInOnNonCurrentManagedSpacesOnly = 1415, 158 | kCGSWorkspacesWindowDidOrderOutOnNonCurrentManagedSpaces = 1416, 159 | 160 | kCGSessionConsoleConnect = 1500, 161 | kCGSessionConsoleDisconnect = 1501, 162 | kCGSessionRemoteConnect = 1502, 163 | kCGSessionRemoteDisconnect = 1503, 164 | kCGSessionLoggedOn = 1504, 165 | kCGSessionLoggedOff = 1505, 166 | kCGSessionConsoleWillDisconnect = 1506, 167 | kCGXWillCreateSession = 1550, 168 | kCGXDidCreateSession = 1551, 169 | kCGXWillDestroySession = 1552, 170 | kCGXDidDestroySession = 1553, 171 | kCGXWorkspaceConnected = 1554, 172 | kCGXSessionReleased = 1555, 173 | 174 | kCGSTransitionDidFinish = 1700, 175 | 176 | kCGXServerDisplayHardwareWillReset = 1800, 177 | kCGXServerDesktopShapeChanged = 1801, 178 | kCGXServerDisplayConfigurationChanged = 1802, 179 | kCGXServerDisplayAcceleratorOffline = 1803, 180 | kCGXServerDisplayAcceleratorDeactivate = 1804, 181 | } CGSEventType; 182 | 183 | 184 | #pragma mark - System-Level Event Notification Registration 185 | 186 | 187 | typedef void (*CGSNotifyProcPtr)(CGSEventType type, void *data, unsigned int dataLength, void *userData); 188 | 189 | /// Registers a function to receive notifications for system-wide events. 190 | CG_EXTERN CGError CGSRegisterNotifyProc(CGSNotifyProcPtr proc, CGSEventType type, void *userData); 191 | 192 | /// Unregisters a function that was registered to receive notifications for system-wide events. 193 | CG_EXTERN CGError CGSRemoveNotifyProc(CGSNotifyProcPtr proc, CGSEventType type, void *userData); 194 | 195 | 196 | #pragma mark - Application-Level Event Notification Registration 197 | 198 | 199 | typedef void (*CGConnectionNotifyProc)(CGSEventType type, CGSNotificationData notificationData, size_t dataLength, CGSNotificationArg userParameter, CGSConnectionID); 200 | 201 | /// Registers a function to receive notifications for connection-level events. 202 | CG_EXTERN CGError CGSRegisterConnectionNotifyProc(CGSConnectionID cid, CGConnectionNotifyProc function, CGSEventType event, void *userData); 203 | 204 | /// Unregisters a function that was registered to receive notifications for connection-level events. 205 | CG_EXTERN CGError CGSRemoveConnectionNotifyProc(CGSConnectionID cid, CGConnectionNotifyProc function, CGSEventType event, void *userData); 206 | 207 | 208 | typedef struct _CGSEventRecord { 209 | CGSEventRecordVersion major; /*0x0*/ 210 | CGSEventRecordVersion minor; /*0x2*/ 211 | CGSByteCount length; /*0x4*/ /* Length of complete event record */ 212 | CGSEventType type; /*0x8*/ /* An event type from above */ 213 | CGPoint location; /*0x10*/ /* Base coordinates (global), from upper-left */ 214 | CGPoint windowLocation; /*0x20*/ /* Coordinates relative to window */ 215 | CGSEventRecordTime time; /*0x30*/ /* nanoseconds since startup */ 216 | CGSEventFlag flags; /* key state flags */ 217 | CGWindowID window; /* window number of assigned window */ 218 | CGSConnectionID connection; /* connection the event came from */ 219 | struct __CGEventSourceData { 220 | int source; 221 | unsigned int sourceUID; 222 | unsigned int sourceGID; 223 | unsigned int flags; 224 | unsigned long long userData; 225 | unsigned int sourceState; 226 | unsigned short localEventSuppressionInterval; 227 | unsigned char suppressionIntervalFlags; 228 | unsigned char remoteMouseDragFlags; 229 | unsigned long long serviceID; 230 | } eventSource; 231 | struct _CGEventProcess { 232 | int pid; 233 | unsigned int psnHi; 234 | unsigned int psnLo; 235 | unsigned int targetID; 236 | unsigned int flags; 237 | } eventProcess; 238 | NXEventData eventData; 239 | SInt32 _padding[4]; 240 | void *ioEventData; 241 | unsigned short _field16; 242 | unsigned short _field17; 243 | struct _CGSEventAppendix { 244 | unsigned short windowHeight; 245 | unsigned short mainDisplayHeight; 246 | unsigned short *unicodePayload; 247 | unsigned int eventOwner; 248 | unsigned char passedThrough; 249 | } *appendix; 250 | unsigned int _field18; 251 | bool passedThrough; 252 | CFDataRef data; 253 | } CGSEventRecord; 254 | 255 | /// Gets the event record for a given `CGEventRef`. 256 | /// 257 | /// For Carbon events, use `GetEventPlatformEventRecord`. 258 | CG_EXTERN CGError CGEventGetEventRecord(CGEventRef event, CGSEventRecord *outRecord, size_t recSize); 259 | 260 | /// Gets the main event port for the connection ID. 261 | CG_EXTERN OSErr CGSGetEventPort(CGSConnectionID identifier, mach_port_t *port); 262 | 263 | /// Getter and setter for the background event mask. 264 | CG_EXTERN void CGSGetBackgroundEventMask(CGSConnectionID cid, int *outMask); 265 | CG_EXTERN CGError CGSSetBackgroundEventMask(CGSConnectionID cid, int mask); 266 | 267 | 268 | /// Returns `True` if the application has been deemed unresponsive for a certain amount of time. 269 | CG_EXTERN bool CGSEventIsAppUnresponsive(CGSConnectionID cid, const ProcessSerialNumber *psn); 270 | 271 | /// Sets the amount of time it takes for an application to be considered unresponsive. 272 | CG_EXTERN CGError CGSEventSetAppIsUnresponsiveNotificationTimeout(CGSConnectionID cid, double theTime); 273 | 274 | #pragma mark input 275 | 276 | // Gets and sets the status of secure input. When secure input is enabled, keyloggers, etc are harder to do. 277 | CG_EXTERN bool CGSIsSecureEventInputSet(void); 278 | CG_EXTERN CGError CGSSetSecureEventInput(CGSConnectionID cid, bool useSecureInput); 279 | 280 | #endif /* CGS_EVENT_INTERNAL_H */ 281 | -------------------------------------------------------------------------------- /CGSHotKeys.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2008 Alacatia Labs 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 3. This notice may not be removed or altered from any source distribution. 19 | * 20 | * Joe Ranieri joe@alacatia.com 21 | * 22 | */ 23 | 24 | // 25 | // Updated by Robert Widmann. 26 | // Copyright © 2015-2016 CodaFi. All rights reserved. 27 | // Released under the MIT license. 28 | // 29 | 30 | #ifndef CGS_HOTKEYS_INTERNAL_H 31 | #define CGS_HOTKEYS_INTERNAL_H 32 | 33 | #include "CGSConnection.h" 34 | 35 | /// The system defines a limited number of "symbolic" hot keys that are remembered system-wide. The 36 | /// original intent is to have a common registry for the action of function keys and numerous 37 | /// other event-generating system gestures. 38 | typedef enum { 39 | // full keyboard access hotkeys 40 | kCGSHotKeyToggleFullKeyboardAccess = 12, 41 | kCGSHotKeyFocusMenubar = 7, 42 | kCGSHotKeyFocusDock = 8, 43 | kCGSHotKeyFocusNextGlobalWindow = 9, 44 | kCGSHotKeyFocusToolbar = 10, 45 | kCGSHotKeyFocusFloatingWindow = 11, 46 | kCGSHotKeyFocusApplicationWindow = 27, 47 | kCGSHotKeyFocusNextControl = 13, 48 | kCGSHotKeyFocusDrawer = 51, 49 | kCGSHotKeyFocusStatusItems = 57, 50 | 51 | // screenshot hotkeys 52 | kCGSHotKeyScreenshot = 28, 53 | kCGSHotKeyScreenshotToClipboard = 29, 54 | kCGSHotKeyScreenshotRegion = 30, 55 | kCGSHotKeyScreenshotRegionToClipboard = 31, 56 | 57 | // universal access 58 | kCGSHotKeyToggleZoom = 15, 59 | kCGSHotKeyZoomOut = 19, 60 | kCGSHotKeyZoomIn = 17, 61 | kCGSHotKeyZoomToggleSmoothing = 23, 62 | kCGSHotKeyIncreaseContrast = 25, 63 | kCGSHotKeyDecreaseContrast = 26, 64 | kCGSHotKeyInvertScreen = 21, 65 | kCGSHotKeyToggleVoiceOver = 59, 66 | 67 | // Dock 68 | kCGSHotKeyToggleDockAutohide = 52, 69 | kCGSHotKeyExposeAllWindows = 32, 70 | kCGSHotKeyExposeAllWindowsSlow = 34, 71 | kCGSHotKeyExposeApplicationWindows = 33, 72 | kCGSHotKeyExposeApplicationWindowsSlow = 35, 73 | kCGSHotKeyExposeDesktop = 36, 74 | kCGSHotKeyExposeDesktopsSlow = 37, 75 | kCGSHotKeyDashboard = 62, 76 | kCGSHotKeyDashboardSlow = 63, 77 | 78 | // spaces (Leopard and later) 79 | kCGSHotKeySpaces = 75, 80 | kCGSHotKeySpacesSlow = 76, 81 | // 77 - fn F7 (disabled) 82 | // 78 - ⇧fn F7 (disabled) 83 | kCGSHotKeySpaceLeft = 79, 84 | kCGSHotKeySpaceLeftSlow = 80, 85 | kCGSHotKeySpaceRight = 81, 86 | kCGSHotKeySpaceRightSlow = 82, 87 | kCGSHotKeySpaceDown = 83, 88 | kCGSHotKeySpaceDownSlow = 84, 89 | kCGSHotKeySpaceUp = 85, 90 | kCGSHotKeySpaceUpSlow = 86, 91 | 92 | // input 93 | kCGSHotKeyToggleCharacterPallette = 50, 94 | kCGSHotKeySelectPreviousInputSource = 60, 95 | kCGSHotKeySelectNextInputSource = 61, 96 | 97 | // Spotlight 98 | kCGSHotKeySpotlightSearchField = 64, 99 | kCGSHotKeySpotlightWindow = 65, 100 | 101 | kCGSHotKeyToggleFrontRow = 73, 102 | kCGSHotKeyLookUpWordInDictionary = 70, 103 | kCGSHotKeyHelp = 98, 104 | 105 | // displays - not verified 106 | kCGSHotKeyDecreaseDisplayBrightness = 53, 107 | kCGSHotKeyIncreaseDisplayBrightness = 54, 108 | } CGSSymbolicHotKey; 109 | 110 | /// The possible operating modes of a hot key. 111 | typedef enum { 112 | /// All hot keys are enabled app-wide. 113 | kCGSGlobalHotKeyEnable = 0, 114 | /// All hot keys are disabled app-wide. 115 | kCGSGlobalHotKeyDisable = 1, 116 | /// Hot keys are disabled app-wide, but exceptions are made for Accessibility. 117 | kCGSGlobalHotKeyDisableAllButUniversalAccess = 2, 118 | } CGSGlobalHotKeyOperatingMode; 119 | 120 | /// Options representing device-independent bits found in event modifier flags: 121 | typedef enum : unsigned int { 122 | /// Set if Caps Lock key is pressed. 123 | kCGSAlphaShiftKeyMask = 1 << 16, 124 | /// Set if Shift key is pressed. 125 | kCGSShiftKeyMask = 1 << 17, 126 | /// Set if Control key is pressed. 127 | kCGSControlKeyMask = 1 << 18, 128 | /// Set if Option or Alternate key is pressed. 129 | kCGSAlternateKeyMask = 1 << 19, 130 | /// Set if Command key is pressed. 131 | kCGSCommandKeyMask = 1 << 20, 132 | /// Set if any key in the numeric keypad is pressed. 133 | kCGSNumericPadKeyMask = 1 << 21, 134 | /// Set if the Help key is pressed. 135 | kCGSHelpKeyMask = 1 << 22, 136 | /// Set if any function key is pressed. 137 | kCGSFunctionKeyMask = 1 << 23, 138 | /// Used to retrieve only the device-independent modifier flags, allowing applications to mask 139 | /// off the device-dependent modifier flags, including event coalescing information. 140 | kCGSDeviceIndependentModifierFlagsMask = 0xffff0000U 141 | } CGSModifierFlags; 142 | 143 | 144 | #pragma mark - Symbolic Hot Keys 145 | 146 | 147 | /// Gets the current global hot key operating mode for the application. 148 | CG_EXTERN CGError CGSGetGlobalHotKeyOperatingMode(CGSConnectionID cid, CGSGlobalHotKeyOperatingMode *outMode); 149 | 150 | /// Sets the current operating mode for the application. 151 | /// 152 | /// This function can be used to enable and disable all hot key events on the given connection. 153 | CG_EXTERN CGError CGSSetGlobalHotKeyOperatingMode(CGSConnectionID cid, CGSGlobalHotKeyOperatingMode mode); 154 | 155 | 156 | #pragma mark - Symbol Hot Key Properties 157 | 158 | 159 | /// Returns whether the symbolic hot key represented by the given UID is enabled. 160 | CG_EXTERN bool CGSIsSymbolicHotKeyEnabled(CGSSymbolicHotKey hotKey); 161 | 162 | /// Sets whether the symbolic hot key represented by the given UID is enabled. 163 | CG_EXTERN CGError CGSSetSymbolicHotKeyEnabled(CGSSymbolicHotKey hotKey, bool isEnabled); 164 | 165 | /// Returns the values the symbolic hot key represented by the given UID is configured with. 166 | CG_EXTERN CGError CGSGetSymbolicHotKeyValue(CGSSymbolicHotKey hotKey, unichar *outKeyEquivalent, unichar *outVirtualKeyCode, CGSModifierFlags *outModifiers); 167 | 168 | 169 | #pragma mark - Custom Hot Keys 170 | 171 | 172 | /// Sets the value of the configuration options for the hot key represented by the given UID, 173 | /// creating a hot key if needed. 174 | /// 175 | /// If the given UID is unique and not in use, a hot key will be instantiated for you under it. 176 | CG_EXTERN void CGSSetHotKey(CGSConnectionID cid, int uid, unichar options, unichar key, CGSModifierFlags modifierFlags); 177 | 178 | /// Functions like `CGSSetHotKey` but with an exclusion value. 179 | /// 180 | /// The exact function of the exclusion value is unknown. Working theory: It is supposed to be 181 | /// passed the UID of another existing hot key that it supresses. Why can only one can be passed, tho? 182 | CG_EXTERN void CGSSetHotKeyWithExclusion(CGSConnectionID cid, int uid, unichar options, unichar key, CGSModifierFlags modifierFlags, int exclusion); 183 | 184 | /// Returns the value of the configured options for the hot key represented by the given UID. 185 | CG_EXTERN bool CGSGetHotKey(CGSConnectionID cid, int uid, unichar *options, unichar *key, CGSModifierFlags *modifierFlags); 186 | 187 | /// Removes a previously created hot key. 188 | CG_EXTERN void CGSRemoveHotKey(CGSConnectionID cid, int uid); 189 | 190 | 191 | #pragma mark - Custom Hot Key Properties 192 | 193 | 194 | /// Returns whether the hot key represented by the given UID is enabled. 195 | CG_EXTERN BOOL CGSIsHotKeyEnabled(CGSConnectionID cid, int uid); 196 | 197 | /// Sets whether the hot key represented by the given UID is enabled. 198 | CG_EXTERN void CGSSetHotKeyEnabled(CGSConnectionID cid, int uid, bool enabled); 199 | 200 | #endif /* CGS_HOTKEYS_INTERNAL_H */ 201 | -------------------------------------------------------------------------------- /CGSInternal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2008 Alacatia Labs 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 3. This notice may not be removed or altered from any source distribution. 19 | * 20 | * Joe Ranieri joe@alacatia.com 21 | * 22 | */ 23 | 24 | // 25 | // Updated by Robert Widmann. 26 | // Copyright © 2015-2016 CodaFi. All rights reserved. 27 | // Released under the MIT license. 28 | // 29 | 30 | #ifndef CGS_INTERNAL_API_H 31 | #define CGS_INTERNAL_API_H 32 | 33 | #include 34 | #include 35 | 36 | // WARNING: CGSInternal contains PRIVATE FUNCTIONS and should NOT BE USED in shipping applications! 37 | 38 | #include "CGSAccessibility.h" 39 | #include "CGSCIFilter.h" 40 | #include "CGSConnection.h" 41 | #include "CGSCursor.h" 42 | #include "CGSDebug.h" 43 | #include "CGSDevice.h" 44 | #include "CGSDisplays.h" 45 | #include "CGSEvent.h" 46 | #include "CGSHotKeys.h" 47 | #include "CGSMisc.h" 48 | #include "CGSRegion.h" 49 | #include "CGSSession.h" 50 | #include "CGSSpace.h" 51 | #include "CGSSurface.h" 52 | #include "CGSTile.h" 53 | #include "CGSTransitions.h" 54 | #include "CGSWindow.h" 55 | #include "CGSWorkspace.h" 56 | 57 | #endif /* CGS_INTERNAL_API_H */ 58 | -------------------------------------------------------------------------------- /CGSMisc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2008 Alacatia Labs 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 3. This notice may not be removed or altered from any source distribution. 19 | * 20 | * Joe Ranieri joe@alacatia.com 21 | * 22 | */ 23 | 24 | // 25 | // Updated by Robert Widmann. 26 | // Copyright © 2015-2016 CodaFi. All rights reserved. 27 | // Released under the MIT license. 28 | // 29 | 30 | #ifndef CGS_MISC_INTERNAL_H 31 | #define CGS_MISC_INTERNAL_H 32 | 33 | #include "CGSConnection.h" 34 | 35 | /// Is someone watching this screen? Applies to Apple's remote desktop only? 36 | CG_EXTERN bool CGSIsScreenWatcherPresent(void); 37 | 38 | #pragma mark - Error Logging 39 | 40 | /// Logs an error and returns `err`. 41 | CG_EXTERN CGError CGSGlobalError(CGError err, const char *msg); 42 | 43 | /// Logs an error and returns `err`. 44 | CG_EXTERN CGError CGSGlobalErrorv(CGError err, const char *msg, ...); 45 | 46 | /// Gets the error message for an error code. 47 | CG_EXTERN char *CGSErrorString(CGError error); 48 | 49 | #endif /* CGS_MISC_INTERNAL_H */ 50 | -------------------------------------------------------------------------------- /CGSRegion.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2008 Alacatia Labs 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 3. This notice may not be removed or altered from any source distribution. 19 | * 20 | * Joe Ranieri joe@alacatia.com 21 | * 22 | */ 23 | 24 | // 25 | // Updated by Robert Widmann. 26 | // Copyright © 2015-2016 CodaFi. All rights reserved. 27 | // Released under the MIT license. 28 | // 29 | 30 | #ifndef CGS_REGION_INTERNAL_H 31 | #define CGS_REGION_INTERNAL_H 32 | 33 | typedef CFTypeRef CGSRegionRef; 34 | typedef CFTypeRef CGSRegionEnumeratorRef; 35 | 36 | 37 | #pragma mark - Region Lifecycle 38 | 39 | 40 | /// Creates a region from a `CGRect`. 41 | CG_EXTERN CGError CGSNewRegionWithRect(const CGRect *rect, CGSRegionRef *outRegion); 42 | 43 | /// Creates a region from a list of `CGRect`s. 44 | CG_EXTERN CGError CGSNewRegionWithRectList(const CGRect *rects, int rectCount, CGSRegionRef *outRegion); 45 | 46 | /// Creates a new region from a QuickDraw region. 47 | CG_EXTERN CGError CGSNewRegionWithQDRgn(RgnHandle region, CGSRegionRef *outRegion); 48 | 49 | /// Creates an empty region. 50 | CG_EXTERN CGError CGSNewEmptyRegion(CGSRegionRef *outRegion); 51 | 52 | /// Releases a region. 53 | CG_EXTERN CGError CGSReleaseRegion(CGSRegionRef region); 54 | 55 | 56 | #pragma mark - Creating Complex Regions 57 | 58 | 59 | /// Created a new region by changing the origin an existing one. 60 | CG_EXTERN CGError CGSOffsetRegion(CGSRegionRef region, CGFloat offsetLeft, CGFloat offsetTop, CGSRegionRef *outRegion); 61 | 62 | /// Creates a new region by copying an existing one. 63 | CG_EXTERN CGError CGSCopyRegion(CGSRegionRef region, CGSRegionRef *outRegion); 64 | 65 | /// Creates a new region by combining two regions together. 66 | CG_EXTERN CGError CGSUnionRegion(CGSRegionRef region1, CGSRegionRef region2, CGSRegionRef *outRegion); 67 | 68 | /// Creates a new region by combining a region and a rect. 69 | CG_EXTERN CGError CGSUnionRegionWithRect(CGSRegionRef region, CGRect *rect, CGSRegionRef *outRegion); 70 | 71 | /// Creates a region by XORing two regions together. 72 | CG_EXTERN CGError CGSXorRegion(CGSRegionRef region1, CGSRegionRef region2, CGSRegionRef *outRegion); 73 | 74 | /// Creates a `CGRect` from a region. 75 | CG_EXTERN CGError CGSGetRegionBounds(CGSRegionRef region, CGRect *outRect); 76 | 77 | /// Creates a rect from the difference of two regions. 78 | CG_EXTERN CGError CGSDiffRegion(CGSRegionRef region1, CGSRegionRef region2, CGSRegionRef *outRegion); 79 | 80 | 81 | #pragma mark - Comparing Regions 82 | 83 | 84 | /// Determines if two regions are equal. 85 | CG_EXTERN bool CGSRegionsEqual(CGSRegionRef region1, CGSRegionRef region2); 86 | 87 | /// Determines if a region is inside of a region. 88 | CG_EXTERN bool CGSRegionInRegion(CGSRegionRef region1, CGSRegionRef region2); 89 | 90 | /// Determines if a region intersects a region. 91 | CG_EXTERN bool CGSRegionIntersectsRegion(CGSRegionRef region1, CGSRegionRef region2); 92 | 93 | /// Determines if a rect intersects a region. 94 | CG_EXTERN bool CGSRegionIntersectsRect(CGSRegionRef obj, const CGRect *rect); 95 | 96 | 97 | #pragma mark - Checking for Membership 98 | 99 | 100 | /// Determines if a point in a region. 101 | CG_EXTERN bool CGSPointInRegion(CGSRegionRef region, const CGPoint *point); 102 | 103 | /// Determines if a rect is in a region. 104 | CG_EXTERN bool CGSRectInRegion(CGSRegionRef region, const CGRect *rect); 105 | 106 | 107 | #pragma mark - Checking Region Characteristics 108 | 109 | 110 | /// Determines if the region is empty. 111 | CG_EXTERN bool CGSRegionIsEmpty(CGSRegionRef region); 112 | 113 | /// Determines if the region is rectangular. 114 | CG_EXTERN bool CGSRegionIsRectangular(CGSRegionRef region); 115 | 116 | 117 | #pragma mark - Region Enumerators 118 | 119 | 120 | /// Gets the enumerator for a region. 121 | CG_EXTERN CGSRegionEnumeratorRef CGSRegionEnumerator(CGSRegionRef region); 122 | 123 | /// Releases a region enumerator. 124 | CG_EXTERN void CGSReleaseRegionEnumerator(CGSRegionEnumeratorRef enumerator); 125 | 126 | /// Gets the next rect of a region. 127 | CG_EXTERN CGRect *CGSNextRect(CGSRegionEnumeratorRef enumerator); 128 | 129 | 130 | /// DOCUMENTATION PENDING */ 131 | CG_EXTERN CGError CGSFetchDirtyScreenRegion(CGSConnectionID cid, CGSRegionRef *outDirtyRegion); 132 | 133 | #endif /* CGS_REGION_INTERNAL_H */ 134 | -------------------------------------------------------------------------------- /CGSSession.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2008 Alacatia Labs 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 3. This notice may not be removed or altered from any source distribution. 19 | * 20 | * Joe Ranieri joe@alacatia.com 21 | * 22 | */ 23 | 24 | // 25 | // Updated by Robert Widmann. 26 | // Copyright © 2015-2016 CodaFi. All rights reserved. 27 | // Released under the MIT license. 28 | // 29 | 30 | #ifndef CGS_SESSION_INTERNAL_H 31 | #define CGS_SESSION_INTERNAL_H 32 | 33 | #include "CGSInternal.h" 34 | 35 | typedef int CGSSessionID; 36 | 37 | /// Creates a new "blank" login session. 38 | /// 39 | /// Switches to the LoginWindow. This does NOT check to see if fast user switching is enabled! 40 | CG_EXTERN CGError CGSCreateLoginSession(CGSSessionID *outSession); 41 | 42 | /// Releases a session. 43 | CG_EXTERN CGError CGSReleaseSession(CGSSessionID session); 44 | 45 | /// Gets information about the current login session. 46 | /// 47 | /// As of OS X 10.6, the following keys appear in this dictionary: 48 | /// 49 | /// kCGSSessionGroupIDKey : CFNumberRef 50 | /// kCGSSessionOnConsoleKey : CFBooleanRef 51 | /// kCGSSessionIDKey : CFNumberRef 52 | /// kCGSSessionUserNameKey : CFStringRef 53 | /// kCGSessionLongUserNameKey : CFStringRef 54 | /// kCGSessionLoginDoneKey : CFBooleanRef 55 | /// kCGSSessionUserIDKey : CFNumberRef 56 | /// kCGSSessionSecureInputPID : CFNumberRef 57 | CG_EXTERN CFDictionaryRef CGSCopyCurrentSessionDictionary(void); 58 | 59 | /// Gets a list of session dictionaries. 60 | /// 61 | /// Each session dictionary is in the format returned by `CGSCopyCurrentSessionDictionary`. 62 | CG_EXTERN CFArrayRef CGSCopySessionList(void); 63 | 64 | #endif /* CGS_SESSION_INTERNAL_H */ 65 | -------------------------------------------------------------------------------- /CGSSpace.h: -------------------------------------------------------------------------------- 1 | // 2 | // CGSSpace.h 3 | // CGSInternal 4 | // 5 | // Created by Robert Widmann on 9/14/13. 6 | // Copyright © 2015-2016 CodaFi. All rights reserved. 7 | // Released under the MIT license. 8 | // 9 | 10 | #ifndef CGS_SPACE_INTERNAL_H 11 | #define CGS_SPACE_INTERNAL_H 12 | 13 | #include "CGSConnection.h" 14 | #include "CGSRegion.h" 15 | 16 | typedef size_t CGSSpaceID; 17 | 18 | /// Representations of the possible types of spaces the system can create. 19 | typedef enum { 20 | /// User-created desktop spaces. 21 | CGSSpaceTypeUser = 0, 22 | /// Fullscreen spaces. 23 | CGSSpaceTypeFullscreen = 1, 24 | /// System spaces e.g. Dashboard. 25 | CGSSpaceTypeSystem = 2, 26 | } CGSSpaceType; 27 | 28 | /// Flags that can be applied to queries for spaces. 29 | typedef enum { 30 | CGSSpaceIncludesCurrent = 1 << 0, 31 | CGSSpaceIncludesOthers = 1 << 1, 32 | CGSSpaceIncludesUser = 1 << 2, 33 | 34 | CGSSpaceVisible = 1 << 16, 35 | 36 | kCGSCurrentSpaceMask = CGSSpaceIncludesUser | CGSSpaceIncludesCurrent, 37 | kCGSOtherSpacesMask = CGSSpaceIncludesOthers | CGSSpaceIncludesCurrent, 38 | kCGSAllSpacesMask = CGSSpaceIncludesUser | CGSSpaceIncludesOthers | CGSSpaceIncludesCurrent, 39 | KCGSAllVisibleSpacesMask = CGSSpaceVisible | kCGSAllSpacesMask, 40 | } CGSSpaceMask; 41 | 42 | typedef enum { 43 | /// Each display manages a single contiguous space. 44 | kCGSPackagesSpaceManagementModeNone = 0, 45 | /// Each display manages a separate stack of spaces. 46 | kCGSPackagesSpaceManagementModePerDesktop = 1, 47 | } CGSSpaceManagementMode; 48 | 49 | #pragma mark - Space Lifecycle 50 | 51 | 52 | /// Creates a new space with the given options dictionary. 53 | /// 54 | /// Valid keys are: 55 | /// 56 | /// "type": CFNumberRef 57 | /// "uuid": CFStringRef 58 | CG_EXTERN CGSSpaceID CGSSpaceCreate(CGSConnectionID cid, void *null, CFDictionaryRef options); 59 | 60 | /// Removes and destroys the space corresponding to the given space ID. 61 | CG_EXTERN void CGSSpaceDestroy(CGSConnectionID cid, CGSSpaceID sid); 62 | 63 | 64 | #pragma mark - Configuring Spaces 65 | 66 | 67 | /// Get and set the human-readable name of a space. 68 | CG_EXTERN CFStringRef CGSSpaceCopyName(CGSConnectionID cid, CGSSpaceID sid); 69 | CG_EXTERN CGError CGSSpaceSetName(CGSConnectionID cid, CGSSpaceID sid, CFStringRef name); 70 | 71 | /// Get and set the affine transform of a space. 72 | CG_EXTERN CGAffineTransform CGSSpaceGetTransform(CGSConnectionID cid, CGSSpaceID space); 73 | CG_EXTERN void CGSSpaceSetTransform(CGSConnectionID cid, CGSSpaceID space, CGAffineTransform transform); 74 | 75 | /// Gets and sets the region the space occupies. You are responsible for releasing the region object. 76 | CG_EXTERN void CGSSpaceSetShape(CGSConnectionID cid, CGSSpaceID space, CGSRegionRef shape); 77 | CG_EXTERN CGSRegionRef CGSSpaceCopyShape(CGSConnectionID cid, CGSSpaceID space); 78 | 79 | 80 | 81 | #pragma mark - Space Properties 82 | 83 | 84 | /// Copies and returns a region the space occupies. You are responsible for releasing the region object. 85 | CG_EXTERN CGSRegionRef CGSSpaceCopyManagedShape(CGSConnectionID cid, CGSSpaceID sid); 86 | 87 | /// Gets the type of a space. 88 | CG_EXTERN CGSSpaceType CGSSpaceGetType(CGSConnectionID cid, CGSSpaceID sid); 89 | 90 | /// Gets the current space management mode. 91 | /// 92 | /// This method reflects whether the “Displays have separate Spaces” option is 93 | /// enabled in Mission Control system preference. You might use the return value 94 | /// to determine how to present your app when in fullscreen mode. 95 | CG_EXTERN CGSSpaceManagementMode CGSGetSpaceManagementMode(CGSConnectionID cid) AVAILABLE_MAC_OS_X_VERSION_10_9_AND_LATER; 96 | 97 | /// Sets the current space management mode. 98 | CG_EXTERN CGError CGSSetSpaceManagementMode(CGSConnectionID cid, CGSSpaceManagementMode mode) AVAILABLE_MAC_OS_X_VERSION_10_9_AND_LATER; 99 | 100 | #pragma mark - Global Space Properties 101 | 102 | 103 | /// Gets the ID of the space currently visible to the user. 104 | CG_EXTERN CGSSpaceID CGSGetActiveSpace(CGSConnectionID cid); 105 | 106 | /// Returns an array of PIDs of applications that have ownership of a given space. 107 | CG_EXTERN CFArrayRef CGSSpaceCopyOwners(CGSConnectionID cid, CGSSpaceID sid); 108 | 109 | /// Returns an array of all space IDs. 110 | CG_EXTERN CFArrayRef CGSCopySpaces(CGSConnectionID cid, CGSSpaceMask mask); 111 | 112 | /// Given an array of window numbers, returns the IDs of the spaces those windows lie on. 113 | CG_EXTERN CFArrayRef CGSCopySpacesForWindows(CGSConnectionID cid, CGSSpaceMask mask, CFArrayRef windowIDs); 114 | 115 | 116 | #pragma mark - Space-Local State 117 | 118 | 119 | /// Connection-local data in a given space. 120 | CG_EXTERN CFDictionaryRef CGSSpaceCopyValues(CGSConnectionID cid, CGSSpaceID space); 121 | CG_EXTERN CGError CGSSpaceSetValues(CGSConnectionID cid, CGSSpaceID sid, CFDictionaryRef values); 122 | CG_EXTERN CGError CGSSpaceRemoveValuesForKeys(CGSConnectionID cid, CGSSpaceID sid, CFArrayRef values); 123 | 124 | 125 | #pragma mark - Displaying Spaces 126 | 127 | 128 | /// Given an array of space IDs, each space is shown to the user. 129 | CG_EXTERN void CGSShowSpaces(CGSConnectionID cid, CFArrayRef spaces); 130 | 131 | /// Given an array of space IDs, each space is hidden from the user. 132 | CG_EXTERN void CGSHideSpaces(CGSConnectionID cid, CFArrayRef spaces); 133 | 134 | /// Given an array of window numbers and an array of space IDs, adds each window to each space. 135 | CG_EXTERN void CGSAddWindowsToSpaces(CGSConnectionID cid, CFArrayRef windows, CFArrayRef spaces); 136 | 137 | /// Given an array of window numbers and an array of space IDs, removes each window from each space. 138 | CG_EXTERN void CGSRemoveWindowsFromSpaces(CGSConnectionID cid, CFArrayRef windows, CFArrayRef spaces); 139 | 140 | CG_EXTERN CFStringRef kCGSPackagesMainDisplayIdentifier; 141 | 142 | /// Changes the active space for a given display. 143 | CG_EXTERN void CGSManagedDisplaySetCurrentSpace(CGSConnectionID cid, CFStringRef display, CGSSpaceID space); 144 | 145 | #endif /// CGS_SPACE_INTERNAL_H */ 146 | 147 | -------------------------------------------------------------------------------- /CGSSurface.h: -------------------------------------------------------------------------------- 1 | // 2 | // CGSSurface.h 3 | // CGSInternal 4 | // 5 | // Created by Robert Widmann on 9/14/13. 6 | // Copyright © 2015-2016 CodaFi. All rights reserved. 7 | // Released under the MIT license. 8 | // 9 | 10 | #ifndef CGS_SURFACE_INTERNAL_H 11 | #define CGS_SURFACE_INTERNAL_H 12 | 13 | #include "CGSWindow.h" 14 | 15 | typedef int CGSSurfaceID; 16 | 17 | 18 | #pragma mark - Surface Lifecycle 19 | 20 | 21 | /// Adds a drawable surface to a window. 22 | CG_EXTERN CGError CGSAddSurface(CGSConnectionID cid, CGWindowID wid, CGSSurfaceID *outSID); 23 | 24 | /// Removes a drawable surface from a window. 25 | CG_EXTERN CGError CGSRemoveSurface(CGSConnectionID cid, CGWindowID wid, CGSSurfaceID sid); 26 | 27 | /// Binds a CAContext to a surface. 28 | /// 29 | /// Pass ctx the result of invoking -[CAContext contextId]. 30 | CG_EXTERN CGError CGSBindSurface(CGSConnectionID cid, CGWindowID wid, CGSSurfaceID sid, int x, int y, unsigned int ctx); 31 | 32 | #pragma mark - Surface Properties 33 | 34 | 35 | /// Sets the bounds of a surface. 36 | CG_EXTERN CGError CGSSetSurfaceBounds(CGSConnectionID cid, CGWindowID wid, CGSSurfaceID sid, CGRect bounds); 37 | 38 | /// Gets the smallest rectangle a surface's frame fits in. 39 | CG_EXTERN CGError CGSGetSurfaceBounds(CGSConnectionID cid, CGWindowID wid, CGSSurfaceID sid, CGFloat *bounds); 40 | 41 | /// Sets the opacity of the surface 42 | CG_EXTERN CGError CGSSetSurfaceOpacity(CGSConnectionID cid, CGWindowID wid, CGSSurfaceID sid, bool isOpaque); 43 | 44 | /// Sets a surface's color space. 45 | CG_EXTERN CGError CGSSetSurfaceColorSpace(CGSConnectionID cid, CGWindowID wid, CGSSurfaceID surface, CGColorSpaceRef colorSpace); 46 | 47 | /// Tunes a number of properties the Window Server uses when rendering a layer-backed surface. 48 | CG_EXTERN CGError CGSSetSurfaceLayerBackingOptions(CGSConnectionID cid, CGWindowID wid, CGSSurfaceID surface, CGFloat flattenDelay, CGFloat decelerationDelay, CGFloat discardDelay); 49 | 50 | /// Sets the order of a surface relative to another surface. 51 | CG_EXTERN CGError CGSOrderSurface(CGSConnectionID cid, CGWindowID wid, CGSSurfaceID surface, CGSSurfaceID otherSurface, int place); 52 | 53 | /// Currently does nothing. 54 | CG_EXTERN CGError CGSSetSurfaceBackgroundBlur(CGSConnectionID cid, CGWindowID wid, CGSSurfaceID sid, CGFloat blur) AVAILABLE_MAC_OS_X_VERSION_10_11_AND_LATER; 55 | 56 | /// Sets the drawing resolution of the surface. 57 | CG_EXTERN CGError CGSSetSurfaceResolution(CGSConnectionID cid, CGWindowID wid, CGSSurfaceID sid, CGFloat scale) AVAILABLE_MAC_OS_X_VERSION_10_11_AND_LATER; 58 | 59 | 60 | #pragma mark - Window Surface Properties 61 | 62 | 63 | /// Gets the count of all drawable surfaces on a window. 64 | CG_EXTERN CGError CGSGetSurfaceCount(CGSConnectionID cid, CGWindowID wid, int *outCount); 65 | 66 | /// Gets a list of surfaces owned by a window. 67 | CG_EXTERN CGError CGSGetSurfaceList(CGSConnectionID cid, CGWindowID wid, int countIds, CGSSurfaceID *ids, int *outCount); 68 | 69 | 70 | #pragma mark - Drawing Surfaces 71 | 72 | 73 | /// Flushes a surface to its window. 74 | CG_EXTERN CGError CGSFlushSurface(CGSConnectionID cid, CGWindowID wid, CGSSurfaceID surface, int param); 75 | 76 | #endif /* CGS_SURFACE_INTERNAL_H */ 77 | -------------------------------------------------------------------------------- /CGSTile.h: -------------------------------------------------------------------------------- 1 | // 2 | // CGSTile.h 3 | // NUIKit 4 | // 5 | // Created by Robert Widmann on 10/9/15. 6 | // Copyright © 2015-2016 CodaFi. All rights reserved. 7 | // Released under the MIT license. 8 | // 9 | 10 | #ifndef CGS_TILE_INTERNAL_H 11 | #define CGS_TILE_INTERNAL_H 12 | 13 | #include "CGSSurface.h" 14 | 15 | typedef size_t CGSTileID; 16 | 17 | 18 | #pragma mark - Proposed Tile Properties 19 | 20 | 21 | /// Returns true if the space ID and connection admit the creation of a new tile. 22 | CG_EXTERN bool CGSSpaceCanCreateTile(CGSConnectionID cid, CGSSpaceID sid) AVAILABLE_MAC_OS_X_VERSION_10_11_AND_LATER; 23 | 24 | /// Returns the recommended size for a tile that could be added to the given space. 25 | CG_EXTERN CGError CGSSpaceGetSizeForProposedTile(CGSConnectionID cid, CGSSpaceID sid, CGSize *outSize) AVAILABLE_MAC_OS_X_VERSION_10_11_AND_LATER; 26 | 27 | 28 | #pragma mark - Tile Creation 29 | 30 | 31 | /// Creates a new tile ID in the given space. 32 | CG_EXTERN CGError CGSSpaceCreateTile(CGSConnectionID cid, CGSSpaceID sid, CGSTileID *outTID) AVAILABLE_MAC_OS_X_VERSION_10_11_AND_LATER; 33 | 34 | 35 | #pragma mark - Tile Spaces 36 | 37 | 38 | /// Returns an array of CFNumberRefs of CGSSpaceIDs. 39 | CG_EXTERN CFArrayRef CGSSpaceCopyTileSpaces(CGSConnectionID cid, CGSSpaceID sid) AVAILABLE_MAC_OS_X_VERSION_10_11_AND_LATER; 40 | 41 | 42 | #pragma mark - Tile Properties 43 | 44 | 45 | /// Returns the size of the inter-tile spacing between tiles in the given space ID. 46 | CG_EXTERN CGFloat CGSSpaceGetInterTileSpacing(CGSConnectionID cid, CGSSpaceID sid) AVAILABLE_MAC_OS_X_VERSION_10_11_AND_LATER; 47 | /// Sets the size of the inter-tile spacing for the given space ID. 48 | CG_EXTERN CGError CGSSpaceSetInterTileSpacing(CGSConnectionID cid, CGSSpaceID sid, CGFloat spacing) AVAILABLE_MAC_OS_X_VERSION_10_11_AND_LATER; 49 | 50 | /// Gets the space ID for the given tile space. 51 | CG_EXTERN CGSSpaceID CGSTileSpaceResizeRecordGetSpaceID(CGSSpaceID sid) AVAILABLE_MAC_OS_X_VERSION_10_11_AND_LATER; 52 | /// Gets the space ID for the parent of the given tile space. 53 | CG_EXTERN CGSSpaceID CGSTileSpaceResizeRecordGetParentSpaceID(CGSSpaceID sid) AVAILABLE_MAC_OS_X_VERSION_10_11_AND_LATER; 54 | 55 | /// Returns whether the current tile space is being resized. 56 | CG_EXTERN bool CGSTileSpaceResizeRecordIsLiveResizing(CGSSpaceID sid) AVAILABLE_MAC_OS_X_VERSION_10_11_AND_LATER; 57 | 58 | /// 59 | CG_EXTERN CGSTileID CGSTileOwnerChangeRecordGetTileID(CGSConnectionID ownerID) AVAILABLE_MAC_OS_X_VERSION_10_11_AND_LATER; 60 | /// 61 | CG_EXTERN CGSSpaceID CGSTileOwnerChangeRecordGetManagedSpaceID(CGSConnectionID ownerID) AVAILABLE_MAC_OS_X_VERSION_10_11_AND_LATER; 62 | 63 | /// 64 | CG_EXTERN CGSTileID CGSTileEvictionRecordGetTileID(CGSConnectionID ownerID) AVAILABLE_MAC_OS_X_VERSION_10_11_AND_LATER; 65 | /// 66 | CG_EXTERN CGSSpaceID CGSTileEvictionRecordGetManagedSpaceID(CGSConnectionID ownerID) AVAILABLE_MAC_OS_X_VERSION_10_11_AND_LATER; 67 | 68 | /// 69 | CG_EXTERN CGSSpaceID CGSTileOwnerChangeRecordGetNewOwner(CGSConnectionID ownerID) AVAILABLE_MAC_OS_X_VERSION_10_11_AND_LATER; 70 | /// 71 | CG_EXTERN CGSSpaceID CGSTileOwnerChangeRecordGetOldOwner(CGSConnectionID ownerID) AVAILABLE_MAC_OS_X_VERSION_10_11_AND_LATER; 72 | 73 | #endif /* CGS_TILE_INTERNAL_H */ 74 | -------------------------------------------------------------------------------- /CGSTransitions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2008 Alacatia Labs 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 3. This notice may not be removed or altered from any source distribution. 19 | * 20 | * Joe Ranieri joe@alacatia.com 21 | * 22 | */ 23 | 24 | // 25 | // Updated by Robert Widmann. 26 | // Copyright © 2015-2016 CodaFi. All rights reserved. 27 | // Released under the MIT license. 28 | // 29 | 30 | #ifndef CGS_TRANSITIONS_INTERNAL_H 31 | #define CGS_TRANSITIONS_INTERNAL_H 32 | 33 | #include "CGSConnection.h" 34 | 35 | typedef enum { 36 | /// No animation is performed during the transition. 37 | kCGSTransitionNone, 38 | /// The window's content fades as it becomes visible or hidden. 39 | kCGSTransitionFade, 40 | /// The window's content zooms in or out as it becomes visible or hidden. 41 | kCGSTransitionZoom, 42 | /// The window's content is revealed gradually in the direction specified by the transition subtype. 43 | kCGSTransitionReveal, 44 | /// The window's content slides in or out along the direction specified by the transition subtype. 45 | kCGSTransitionSlide, 46 | /// 47 | kCGSTransitionWarpFade, 48 | kCGSTransitionSwap, 49 | /// The window's content is aligned to the faces of a cube and rotated in or out along the 50 | /// direction specified by the transition subtype. 51 | kCGSTransitionCube, 52 | /// 53 | kCGSTransitionWarpSwitch, 54 | /// The window's content is flipped along its midpoint like a page being turned over along the 55 | /// direction specified by the transition subtype. 56 | kCGSTransitionFlip 57 | } CGSTransitionType; 58 | 59 | typedef enum { 60 | /// Directions bits for the transition. Some directions don't apply to some transitions. 61 | kCGSTransitionDirectionLeft = 1 << 0, 62 | kCGSTransitionDirectionRight = 1 << 1, 63 | kCGSTransitionDirectionDown = 1 << 2, 64 | kCGSTransitionDirectionUp = 1 << 3, 65 | kCGSTransitionDirectionCenter = 1 << 4, 66 | 67 | /// Reverses a transition. Doesn't apply for all transitions. 68 | kCGSTransitionFlagReversed = 1 << 5, 69 | 70 | /// Ignore the background color and only transition the window. 71 | kCGSTransitionFlagTransparent = 1 << 7, 72 | } CGSTransitionFlags; 73 | 74 | typedef struct CGSTransitionSpec { 75 | int version; // always set to zero 76 | CGSTransitionType type; 77 | CGSTransitionFlags options; 78 | CGWindowID wid; /* 0 means a full screen transition. */ 79 | CGFloat *backColor; /* NULL means black. */ 80 | } *CGSTransitionSpecRef; 81 | 82 | /// Creates a new transition from a `CGSTransitionSpec`. 83 | CG_EXTERN CGError CGSNewTransition(CGSConnectionID cid, const CGSTransitionSpecRef spec, CGSTransitionID *outTransition); 84 | 85 | /// Invokes a transition asynchronously. Note that `duration` is in seconds. 86 | CG_EXTERN CGError CGSInvokeTransition(CGSConnectionID cid, CGSTransitionID transition, CGFloat duration); 87 | 88 | /// Releases a transition. 89 | CG_EXTERN CGError CGSReleaseTransition(CGSConnectionID cid, CGSTransitionID transition); 90 | 91 | #endif /* CGS_TRANSITIONS_INTERNAL_H */ 92 | -------------------------------------------------------------------------------- /CGSWindow.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2008 Alacatia Labs 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 3. This notice may not be removed or altered from any source distribution. 19 | * 20 | * Joe Ranieri joe@alacatia.com 21 | * 22 | */ 23 | 24 | // 25 | // Updated by Robert Widmann. 26 | // Copyright © 2015-2016 CodaFi. All rights reserved. 27 | // Released under the MIT license. 28 | // 29 | 30 | #ifndef CGS_WINDOW_INTERNAL_H 31 | #define CGS_WINDOW_INTERNAL_H 32 | 33 | #include "CGSConnection.h" 34 | #include "CGSRegion.h" 35 | 36 | typedef CFTypeRef CGSAnimationRef; 37 | typedef CFTypeRef CGSWindowBackdropRef; 38 | typedef struct CGSWarpPoint CGSWarpPoint; 39 | 40 | #define kCGSRealMaximumTagSize (sizeof(void *) * 8) 41 | 42 | typedef enum { 43 | kCGSSharingNone, 44 | kCGSSharingReadOnly, 45 | kCGSSharingReadWrite 46 | } CGSSharingState; 47 | 48 | typedef enum { 49 | kCGSOrderBelow = -1, 50 | kCGSOrderOut, /* hides the window */ 51 | kCGSOrderAbove, 52 | kCGSOrderIn /* shows the window */ 53 | } CGSWindowOrderingMode; 54 | 55 | typedef enum { 56 | kCGSBackingNonRetianed, 57 | kCGSBackingRetained, 58 | kCGSBackingBuffered, 59 | } CGSBackingType; 60 | 61 | typedef enum { 62 | CGSWindowSaveWeightingDontReuse, 63 | CGSWindowSaveWeightingTopLeft, 64 | CGSWindowSaveWeightingTopRight, 65 | CGSWindowSaveWeightingBottomLeft, 66 | CGSWindowSaveWeightingBottomRight, 67 | CGSWindowSaveWeightingClip, 68 | } CGSWindowSaveWeighting; 69 | typedef enum : int { 70 | // Lo bits 71 | 72 | /// The window appears in the default style of OS X windows. "Document" is most likely a 73 | /// historical name. 74 | kCGSDocumentWindowTagBit = 1 << 0, 75 | /// The window appears floating over other windows. This mask is often combined with other 76 | /// non-activating bits to enable floating panels. 77 | kCGSFloatingWindowTagBit = 1 << 1, 78 | 79 | /// Disables the window's badging when it is minimized into its Dock Tile. 80 | kCGSDoNotShowBadgeInDockTagBit = 1 << 2, 81 | 82 | /// The window will be displayed without a shadow, and will ignore any given shadow parameters. 83 | kCGSDisableShadowTagBit = 1 << 3, 84 | 85 | /// Causes the Window Server to resample the window at a higher rate. While this may lead to an 86 | /// improvement in the look of the window, it can lead to performance issues. 87 | kCGSHighQualityResamplingTagBit = 1 << 4, 88 | 89 | /// The window may set the cursor when the application is not active. Useful for windows that 90 | /// present controls like editable text fields. 91 | kCGSSetsCursorInBackgroundTagBit = 1 << 5, 92 | 93 | /// The window continues to operate while a modal run loop has been pushed. 94 | kCGSWorksWhenModalTagBit = 1 << 6, 95 | 96 | /// The window is anchored to another window. 97 | kCGSAttachedWindowTagBit = 1 << 7, 98 | 99 | /// When dragging, the window will ignore any alpha and appear 100% opaque. 100 | kCGSIgnoreAlphaForDraggingTagBit = 1 << 8, 101 | 102 | /// The window appears transparent to events. Mouse events will pass through it to the next 103 | /// eligible responder. This bit or kCGSOpaqueForEventsTagBit must be exclusively set. 104 | kCGSIgnoreForEventsTagBit = 1 << 9, 105 | /// The window appears opaque to events. Mouse events will be intercepted by the window when 106 | /// necessary. This bit or kCGSIgnoreForEventsTagBit must be exclusively set. 107 | kCGSOpaqueForEventsTagBit = 1 << 10, 108 | 109 | /// The window appears on all workspaces regardless of where it was created. This bit is used 110 | /// for QuickLook panels. 111 | kCGSOnAllWorkspacesTagBit = 1 << 11, 112 | 113 | /// 114 | kCGSPointerEventsAvoidCPSTagBit = 1 << 12, 115 | 116 | /// 117 | kCGSKitVisibleTagBit = 1 << 13, 118 | 119 | /// On application deactivation the window disappears from the window list. 120 | kCGSHideOnDeactivateTagBit = 1 << 14, 121 | 122 | /// When the window appears it will not bring the application to the forefront. 123 | kCGSAvoidsActivationTagBit = 1 << 15, 124 | /// When the window is selected it will not bring the application to the forefront. 125 | kCGSPreventsActivationTagBit = 1 << 16, 126 | 127 | /// 128 | kCGSIgnoresOptionTagBit = 1 << 17, 129 | 130 | /// The window ignores the window cycling mechanism. 131 | kCGSIgnoresCycleTagBit = 1 << 18, 132 | 133 | /// 134 | kCGSDefersOrderingTagBit = 1 << 19, 135 | 136 | /// 137 | kCGSDefersActivationTagBit = 1 << 20, 138 | 139 | /// WindowServer will ignore all requests to order this window front. 140 | kCGSIgnoreAsFrontWindowTagBit = 1 << 21, 141 | 142 | /// The WindowServer will control the movement of the window on the screen using its given 143 | /// dragging rects. This enables windows to be movable even when the application stalls. 144 | kCGSEnableServerSideDragTagBit = 1 << 22, 145 | 146 | /// 147 | kCGSMouseDownEventsGrabbedTagBit = 1 << 23, 148 | 149 | /// The window ignores all requests to hide. 150 | kCGSDontHideTagBit = 1 << 24, 151 | 152 | /// 153 | kCGSDontDimWindowDisplayTagBit = 1 << 25, 154 | 155 | /// The window converts all pointers, no matter if they are mice or tablet pens, to its pointer 156 | /// type when they enter the window. 157 | kCGSInstantMouserWindowTagBit = 1 << 26, 158 | 159 | /// The window appears only on active spaces, and will follow when the user changes said active 160 | /// space. 161 | kCGSWindowOwnerFollowsForegroundTagBit = 1 << 27, 162 | 163 | /// 164 | kCGSActivationWindowLevelTagBit = 1 << 28, 165 | 166 | /// The window brings its owning application to the forefront when it is selected. 167 | kCGSBringOwningApplicationForwardTagBit = 1 << 29, 168 | 169 | /// The window is allowed to appear when over login screen. 170 | kCGSPermittedBeforeLoginTagBit = 1 << 30, 171 | 172 | /// The window is modal. 173 | kCGSModalWindowTagBit = 1 << 31, 174 | 175 | // Hi bits 176 | 177 | /// The window draws itself like the dock -the "Magic Mirror". 178 | kCGSWindowIsMagicMirrorTagBit = 1 << 1, 179 | 180 | /// 181 | kCGSFollowsUserTagBit = 1 << 2, 182 | 183 | /// 184 | kCGSWindowDoesNotCastMirrorReflectionTagBit = 1 << 3, 185 | 186 | /// 187 | kCGSMeshedWindowTagBit = 1 << 4, 188 | 189 | /// Bit is set when CoreDrag has dragged something to the window. 190 | kCGSCoreDragIsDraggingWindowTagBit = 1 << 5, 191 | 192 | /// 193 | kCGSAvoidsCaptureTagBit = 1 << 6, 194 | 195 | /// The window is ignored for expose and does not change its appearance in any way when it is 196 | /// activated. 197 | kCGSIgnoreForExposeTagBit = 1 << 7, 198 | 199 | /// The window is hidden. 200 | kCGSHiddenTagBit = 1 << 8, 201 | 202 | /// The window is explicitly included in the window cycling mechanism. 203 | kCGSIncludeInCycleTagBit = 1 << 9, 204 | 205 | /// The window captures gesture events even when the application is not in the foreground. 206 | kCGSWantGesturesInBackgroundTagBit = 1 << 10, 207 | 208 | /// The window is fullscreen. 209 | kCGSFullScreenTagBit = 1 << 11, 210 | 211 | /// 212 | kCGSWindowIsMagicZoomTagBit = 1 << 12, 213 | 214 | /// 215 | kCGSSuperStickyTagBit = 1 << 13, 216 | 217 | /// The window is attached to the menu bar. This is used for NSMenus presented by menu bar 218 | /// apps. 219 | kCGSAttachesToMenuBarTagBit = 1 << 14, 220 | 221 | /// The window appears on the menu bar. This is used for all menu bar items. 222 | kCGSMergesWithMenuBarTagBit = 1 << 15, 223 | 224 | /// 225 | kCGSNeverStickyTagBit = 1 << 16, 226 | 227 | /// The window appears at the level of the desktop picture. 228 | kCGSDesktopPictureTagBit = 1 << 17, 229 | 230 | /// When the window is redrawn it moves forward. Useful for debugging, annoying in practice. 231 | kCGSOrdersForwardWhenSurfaceFlushedTagBit = 1 << 18, 232 | 233 | /// 234 | kCGSDragsMovementGroupParentTagBit = 1 << 19, 235 | kCGSNeverFlattenSurfacesDuringSwipesTagBit = 1 << 20, 236 | kCGSFullScreenCapableTagBit = 1 << 21, 237 | kCGSFullScreenTileCapableTagBit = 1 << 22, 238 | } CGSWindowTagBit; 239 | 240 | struct CGSWarpPoint { 241 | CGPoint localPoint; 242 | CGPoint globalPoint; 243 | }; 244 | 245 | 246 | #pragma mark - Creating Windows 247 | 248 | 249 | /// Creates a new CGSWindow. 250 | /// 251 | /// The real window top/left is the sum of the region's top/left and the top/left parameters. 252 | CG_EXTERN CGError CGSNewWindow(CGSConnectionID cid, CGSBackingType backingType, CGFloat left, CGFloat top, CGSRegionRef region, CGWindowID *outWID); 253 | 254 | /// Creates a new CGSWindow. 255 | /// 256 | /// The real window top/left is the sum of the region's top/left and the top/left parameters. 257 | CG_EXTERN CGError CGSNewWindowWithOpaqueShape(CGSConnectionID cid, CGSBackingType backingType, CGFloat left, CGFloat top, CGSRegionRef region, CGSRegionRef opaqueShape, int unknown, CGSWindowTagBit *tags, int tagSize, CGWindowID *outWID); 258 | 259 | /// Releases a CGSWindow. 260 | CG_EXTERN CGError CGSReleaseWindow(CGSConnectionID cid, CGWindowID wid); 261 | 262 | 263 | #pragma mark - Configuring Windows 264 | 265 | 266 | /// Gets the value associated with the specified window property as a CoreFoundation object. 267 | CG_EXTERN CGError CGSGetWindowProperty(CGSConnectionID cid, CGWindowID wid, CFStringRef key, CFTypeRef *outValue); 268 | CG_EXTERN CGError CGSSetWindowProperty(CGSConnectionID cid, CGWindowID wid, CFStringRef key, CFTypeRef value); 269 | 270 | /// Sets the window's title. 271 | /// 272 | /// A window's title and what is displayed on its titlebar are often distinct strings. The value 273 | /// passed to this method is used to identify the window in spaces. 274 | /// 275 | /// Internally this calls `CGSSetWindowProperty(cid, wid, kCGSWindowTitle, title)`. 276 | CG_EXTERN CGError CGSSetWindowTitle(CGSConnectionID cid, CGWindowID wid, CFStringRef title); 277 | 278 | 279 | /// Returns the window’s alpha value. 280 | CG_EXTERN CGError CGSGetWindowAlpha(CGSConnectionID cid, CGWindowID wid, CGFloat *outAlpha); 281 | 282 | /// Sets the window's alpha value. 283 | CG_EXTERN CGError CGSSetWindowAlpha(CGSConnectionID cid, CGWindowID wid, CGFloat alpha); 284 | 285 | /// Sets the shape of the window and describes how to redraw if the bounding 286 | /// boxes don't match. 287 | CG_EXTERN CGError CGSSetWindowShapeWithWeighting(CGSConnectionID cid, CGWindowID wid, CGFloat offsetX, CGFloat offsetY, CGSRegionRef shape, CGSWindowSaveWeighting weight); 288 | 289 | /// Sets the shape of the window. 290 | CG_EXTERN CGError CGSSetWindowShape(CGSConnectionID cid, CGWindowID wid, CGFloat offsetX, CGFloat offsetY, CGSRegionRef shape); 291 | 292 | /// Gets and sets a Boolean value indicating whether the window is opaque. 293 | CG_EXTERN CGError CGSGetWindowOpacity(CGSConnectionID cid, CGWindowID wid, bool *outIsOpaque); 294 | CG_EXTERN CGError CGSSetWindowOpacity(CGSConnectionID cid, CGWindowID wid, bool isOpaque); 295 | 296 | /// Gets and sets the window's color space. 297 | CG_EXTERN CGError CGSCopyWindowColorSpace(CGSConnectionID cid, CGWindowID wid, CGColorSpaceRef *outColorSpace); 298 | CG_EXTERN CGError CGSSetWindowColorSpace(CGSConnectionID cid, CGWindowID wid, CGColorSpaceRef colorSpace); 299 | 300 | /// Gets and sets the window's clip shape. 301 | CG_EXTERN CGError CGSCopyWindowClipShape(CGSConnectionID cid, CGWindowID wid, CGSRegionRef *outRegion); 302 | CG_EXTERN CGError CGSSetWindowClipShape(CGWindowID wid, CGSRegionRef shape); 303 | 304 | /// Gets and sets the window's transform. 305 | /// 306 | /// Severe restrictions are placed on transformation: 307 | /// - Transformation Matrices may only include a singular transform. 308 | /// - Transformations involving scale may not scale upwards past the window's frame. 309 | /// - Transformations involving rotation must be followed by translation or the window will fall offscreen. 310 | CG_EXTERN CGError CGSGetWindowTransform(CGSConnectionID cid, CGWindowID wid, const CGAffineTransform *outTransform); 311 | CG_EXTERN CGError CGSSetWindowTransform(CGSConnectionID cid, CGWindowID wid, CGAffineTransform transform); 312 | 313 | /// Gets and sets the window's transform in place. 314 | /// 315 | /// Severe restrictions are placed on transformation: 316 | /// - Transformation Matrices may only include a singular transform. 317 | /// - Transformations involving scale may not scale upwards past the window's frame. 318 | /// - Transformations involving rotation must be followed by translation or the window will fall offscreen. 319 | CG_EXTERN CGError CGSGetWindowTransformAtPlacement(CGSConnectionID cid, CGWindowID wid, const CGAffineTransform *outTransform); 320 | CG_EXTERN CGError CGSSetWindowTransformAtPlacement(CGSConnectionID cid, CGWindowID wid, CGAffineTransform transform); 321 | 322 | /// Gets and sets the `CGConnectionID` that owns this window. Only the owner can change most properties of the window. 323 | CG_EXTERN CGError CGSGetWindowOwner(CGSConnectionID cid, CGWindowID wid, CGSConnectionID *outOwner); 324 | CG_EXTERN CGError CGSSetWindowOwner(CGSConnectionID cid, CGWindowID wid, CGSConnectionID owner); 325 | 326 | /// Sets the background color of the window. 327 | CG_EXTERN CGError CGSSetWindowAutofillColor(CGSConnectionID cid, CGWindowID wid, CGFloat red, CGFloat green, CGFloat blue); 328 | 329 | /// Sets the warp for the window. The mesh maps a local (window) point to a point on screen. 330 | CG_EXTERN CGError CGSSetWindowWarp(CGSConnectionID cid, CGWindowID wid, int warpWidth, int warpHeight, const CGSWarpPoint *warp); 331 | 332 | /// Gets or sets whether the Window Server should auto-fill the window's background. 333 | CG_EXTERN CGError CGSGetWindowAutofill(CGSConnectionID cid, CGWindowID wid, bool *outShouldAutoFill); 334 | CG_EXTERN CGError CGSSetWindowAutofill(CGSConnectionID cid, CGWindowID wid, bool shouldAutoFill); 335 | 336 | /// Gets and sets the window level for a window. 337 | CG_EXTERN CGError CGSGetWindowLevel(CGSConnectionID cid, CGWindowID wid, CGWindowLevel *outLevel); 338 | CG_EXTERN CGError CGSSetWindowLevel(CGSConnectionID cid, CGWindowID wid, CGWindowLevel level); 339 | 340 | /// Gets and sets the sharing state. This determines the level of access other applications have over this window. 341 | CG_EXTERN CGError CGSGetWindowSharingState(CGSConnectionID cid, CGWindowID wid, CGSSharingState *outState); 342 | CG_EXTERN CGError CGSSetWindowSharingState(CGSConnectionID cid, CGWindowID wid, CGSSharingState state); 343 | 344 | /// Sets whether this window is ignored in the global window cycle (Control-F4 by default). There is no Get version? */ 345 | CG_EXTERN CGError CGSSetIgnoresCycle(CGSConnectionID cid, CGWindowID wid, bool ignoresCycle); 346 | 347 | 348 | #pragma mark - Managing Window Key State 349 | 350 | 351 | /// Forces a window to acquire key window status. 352 | CG_EXTERN CGError CGSSetMouseFocusWindow(CGSConnectionID cid, CGWindowID wid); 353 | 354 | /// Forces a window to draw with its key appearance. 355 | CG_EXTERN CGError CGSSetWindowHasKeyAppearance(CGSConnectionID cid, CGWindowID wid, bool hasKeyAppearance); 356 | 357 | /// Forces a window to be active. 358 | CG_EXTERN CGError CGSSetWindowActive(CGSConnectionID cid, CGWindowID wid, bool isActive); 359 | 360 | 361 | #pragma mark - Handling Events 362 | 363 | /// DEPRECATED: Sets the shape over which the window can capture events in its frame rectangle. 364 | CG_EXTERN CGError CGSSetWindowEventShape(CGSConnectionID cid, CGSBackingType backingType, CGSRegionRef *shape); 365 | 366 | /// Gets and sets the window's event mask. 367 | CG_EXTERN CGError CGSGetWindowEventMask(CGSConnectionID cid, CGWindowID wid, CGEventMask *mask); 368 | CG_EXTERN CGError CGSSetWindowEventMask(CGSConnectionID cid, CGWindowID wid, CGEventMask mask); 369 | 370 | /// Sets whether a window can recieve mouse events. If no, events will pass to the next window that can receive the event. 371 | CG_EXTERN CGError CGSSetMouseEventEnableFlags(CGSConnectionID cid, CGWindowID wid, bool shouldEnable); 372 | 373 | 374 | 375 | /// Gets the screen rect for a window. 376 | CG_EXTERN CGError CGSGetScreenRectForWindow(CGSConnectionID cid, CGWindowID wid, CGRect *outRect); 377 | 378 | 379 | #pragma mark - Drawing Windows 380 | 381 | /// Creates a graphics context for the window. 382 | /// 383 | /// Acceptable keys options: 384 | /// 385 | /// - CGWindowContextShouldUseCA : CFBooleanRef 386 | CG_EXTERN CGContextRef CGWindowContextCreate(CGSConnectionID cid, CGWindowID wid, CFDictionaryRef options); 387 | 388 | /// Flushes a window's buffer to the screen. 389 | CG_EXTERN CGError CGSFlushWindow(CGSConnectionID cid, CGWindowID wid, CGSRegionRef flushRegion); 390 | 391 | 392 | #pragma mark - Window Order 393 | 394 | 395 | /// Sets the order of a window. 396 | CG_EXTERN CGError CGSOrderWindow(CGSConnectionID cid, CGWindowID wid, CGSWindowOrderingMode mode, CGWindowID relativeToWID); 397 | 398 | CG_EXTERN CGError CGSOrderFrontConditionally(CGSConnectionID cid, CGWindowID wid, bool force); 399 | 400 | 401 | #pragma mark - Sizing Windows 402 | 403 | 404 | /// Sets the origin (top-left) of a window. 405 | CG_EXTERN CGError CGSMoveWindow(CGSConnectionID cid, CGWindowID wid, const CGPoint *origin); 406 | 407 | /// Sets the origin (top-left) of a window relative to another window's origin. 408 | CG_EXTERN CGError CGSSetWindowOriginRelativeToWindow(CGSConnectionID cid, CGWindowID wid, CGWindowID relativeToWID, CGFloat offsetX, CGFloat offsetY); 409 | 410 | /// Sets the frame and position of a window. Updates are grouped for the sake of animation. 411 | CG_EXTERN CGError CGSMoveWindowWithGroup(CGSConnectionID cid, CGWindowID wid, CGRect *newFrame); 412 | 413 | /// Gets the mouse's current location inside the bounds rectangle of the window. 414 | CG_EXTERN CGError CGSGetWindowMouseLocation(CGSConnectionID cid, CGWindowID wid, CGPoint *outPos); 415 | 416 | 417 | #pragma mark - Window Shadows 418 | 419 | 420 | /// Sets the shadow information for a window. 421 | /// 422 | /// Calls through to `CGSSetWindowShadowAndRimParameters` passing 1 for `flags`. 423 | CG_EXTERN CGError CGSSetWindowShadowParameters(CGSConnectionID cid, CGWindowID wid, CGFloat standardDeviation, CGFloat density, int offsetX, int offsetY); 424 | 425 | /// Gets and sets the shadow information for a window. 426 | /// 427 | /// Values for `flags` are unknown. Calls `CGSSetWindowShadowAndRimParametersWithStretch`. 428 | CG_EXTERN CGError CGSSetWindowShadowAndRimParameters(CGSConnectionID cid, CGWindowID wid, CGFloat standardDeviation, CGFloat density, int offsetX, int offsetY, int flags); 429 | CG_EXTERN CGError CGSGetWindowShadowAndRimParameters(CGSConnectionID cid, CGWindowID wid, CGFloat *outStandardDeviation, CGFloat *outDensity, int *outOffsetX, int *outOffsetY, int *outFlags); 430 | 431 | /// Sets the shadow information for a window. 432 | CG_EXTERN CGError CGSSetWindowShadowAndRimParametersWithStretch(CGSConnectionID cid, CGWindowID wid, CGFloat standardDeviation, CGFloat density, int offsetX, int offsetY, int stretch_x, int stretch_y, unsigned int flags); 433 | 434 | /// Invalidates a window's shadow. 435 | CG_EXTERN CGError CGSInvalidateWindowShadow(CGSConnectionID cid, CGWindowID wid); 436 | 437 | /// Sets a window's shadow properties. 438 | /// 439 | /// Acceptable keys: 440 | /// 441 | /// - com.apple.WindowShadowDensity - (0.0 - 1.0) Opacity of the window's shadow. 442 | /// - com.apple.WindowShadowRadius - The radius of the shadow around the window's corners. 443 | /// - com.apple.WindowShadowVerticalOffset - Vertical offset of the shadow. 444 | /// - com.apple.WindowShadowRimDensity - (0.0 - 1.0) Opacity of the black rim around the window. 445 | /// - com.apple.WindowShadowRimStyleHard - Sets a hard black rim around the window. 446 | CG_EXTERN CGError CGSWindowSetShadowProperties(CGWindowID wid, CFDictionaryRef properties); 447 | 448 | 449 | #pragma mark - Window Lists 450 | 451 | 452 | /// Gets the number of windows the `targetCID` owns. 453 | CG_EXTERN CGError CGSGetWindowCount(CGSConnectionID cid, CGSConnectionID targetCID, int *outCount); 454 | 455 | /// Gets a list of windows owned by `targetCID`. 456 | CG_EXTERN CGError CGSGetWindowList(CGSConnectionID cid, CGSConnectionID targetCID, int count, CGWindowID *list, int *outCount); 457 | 458 | /// Gets the number of windows owned by `targetCID` that are on screen. 459 | CG_EXTERN CGError CGSGetOnScreenWindowCount(CGSConnectionID cid, CGSConnectionID targetCID, int *outCount); 460 | 461 | /// Gets a list of windows oned by `targetCID` that are on screen. 462 | CG_EXTERN CGError CGSGetOnScreenWindowList(CGSConnectionID cid, CGSConnectionID targetCID, int count, CGWindowID *list, int *outCount); 463 | 464 | /// Sets the alpha of a group of windows over a period of time. Note that `duration` is in seconds. 465 | CG_EXTERN CGError CGSSetWindowListAlpha(CGSConnectionID cid, const CGWindowID *widList, int widCount, CGFloat alpha, CGFloat duration); 466 | 467 | 468 | #pragma mark - Window Activation Regions 469 | 470 | 471 | /// Sets the shape over which the window can capture events in its frame rectangle. 472 | CG_EXTERN CGError CGSAddActivationRegion(CGSConnectionID cid, CGWindowID wid, CGSRegionRef region); 473 | 474 | /// Sets the shape over which the window can recieve mouse drag events. 475 | CG_EXTERN CGError CGSAddDragRegion(CGSConnectionID cid, CGWindowID wid, CGSRegionRef region); 476 | 477 | /// Removes any shapes over which the window can be dragged. 478 | CG_EXTERN CGError CGSClearDragRegion(CGSConnectionID cid, CGWindowID wid); 479 | 480 | CG_EXTERN CGError CGSDragWindowRelativeToMouse(CGSConnectionID cid, CGWindowID wid, CGPoint point); 481 | 482 | 483 | #pragma mark - Window Animations 484 | 485 | 486 | /// Creates a Dock-style genie animation that goes from `wid` to `destinationWID`. 487 | CG_EXTERN CGError CGSCreateGenieWindowAnimation(CGSConnectionID cid, CGWindowID wid, CGWindowID destinationWID, CGSAnimationRef *outAnimation); 488 | 489 | /// Creates a sheet animation that's used when the parent window is brushed metal. Oddly enough, seems to be the only one used, even if the parent window isn't metal. 490 | CG_EXTERN CGError CGSCreateMetalSheetWindowAnimationWithParent(CGSConnectionID cid, CGWindowID wid, CGWindowID parentWID, CGSAnimationRef *outAnimation); 491 | 492 | /// Sets the progress of an animation. 493 | CG_EXTERN CGError CGSSetWindowAnimationProgress(CGSAnimationRef animation, CGFloat progress); 494 | 495 | /// DOCUMENTATION PENDING */ 496 | CG_EXTERN CGError CGSWindowAnimationChangeLevel(CGSAnimationRef animation, CGWindowLevel level); 497 | 498 | /// DOCUMENTATION PENDING */ 499 | CG_EXTERN CGError CGSWindowAnimationSetParent(CGSAnimationRef animation, CGWindowID parent) AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER; 500 | 501 | /// Releases a window animation. 502 | CG_EXTERN CGError CGSReleaseWindowAnimation(CGSAnimationRef animation); 503 | 504 | 505 | #pragma mark - Window Accelleration 506 | 507 | 508 | /// Gets the state of accelleration for the window. 509 | CG_EXTERN CGError CGSWindowIsAccelerated(CGSConnectionID cid, CGWindowID wid, bool *outIsAccelerated); 510 | 511 | /// Gets and sets if this window can be accellerated. I don't know if playing with this is safe. 512 | CG_EXTERN CGError CGSWindowCanAccelerate(CGSConnectionID cid, CGWindowID wid, bool *outCanAccelerate); 513 | CG_EXTERN CGError CGSWindowSetCanAccelerate(CGSConnectionID cid, CGWindowID wid, bool canAccelerate); 514 | 515 | 516 | #pragma mark - Status Bar Windows 517 | 518 | 519 | /// Registers or unregisters a window as a global status item (see `NSStatusItem`, `NSMenuExtra`). 520 | /// Once a window is registered, the Window Server takes care of placing it in the apropriate location. 521 | CG_EXTERN CGError CGSSystemStatusBarRegisterWindow(CGSConnectionID cid, CGWindowID wid, int priority); 522 | CG_EXTERN CGError CGSUnregisterWindowWithSystemStatusBar(CGSConnectionID cid, CGWindowID wid); 523 | 524 | /// Rearranges items in the system status bar. You should call this after registering or unregistering a status item or changing the window's width. 525 | CG_EXTERN CGError CGSAdjustSystemStatusBarWindows(CGSConnectionID cid); 526 | 527 | 528 | #pragma mark - Window Tags 529 | 530 | 531 | /// Get the given tags for a window. Pass kCGSRealMaximumTagSize to maxTagSize. 532 | /// 533 | /// Tags are represented server-side as 64-bit integers, but CoreGraphics maintains compatibility 534 | /// with 32-bit clients by requiring 2 32-bit options tags to be specified. The first entry in the 535 | /// options array populates the lower 32 bits, the last populates the upper 32 bits. 536 | CG_EXTERN CGError CGSGetWindowTags(CGSConnectionID cid, CGWindowID wid, const CGSWindowTagBit tags[2], size_t maxTagSize); 537 | 538 | /// Set the given tags for a window. Pass kCGSRealMaximumTagSize to maxTagSize. 539 | /// 540 | /// Tags are represented server-side as 64-bit integers, but CoreGraphics maintains compatibility 541 | /// with 32-bit clients by requiring 2 32-bit options tags to be specified. The first entry in the 542 | /// options array populates the lower 32 bits, the last populates the upper 32 bits. 543 | CG_EXTERN CGError CGSSetWindowTags(CGSConnectionID cid, CGWindowID wid, const CGSWindowTagBit tags[2], size_t maxTagSize); 544 | 545 | /// Clear the given tags for a window. Pass kCGSRealMaximumTagSize to maxTagSize. 546 | /// 547 | /// Tags are represented server-side as 64-bit integers, but CoreGraphics maintains compatibility 548 | /// with 32-bit clients by requiring 2 32-bit options tags to be specified. The first entry in the 549 | /// options array populates the lower 32 bits, the last populates the upper 32 bits. 550 | CG_EXTERN CGError CGSClearWindowTags(CGSConnectionID cid, CGWindowID wid, const CGSWindowTagBit tags[2], size_t maxTagSize); 551 | 552 | 553 | #pragma mark - Window Backdrop 554 | 555 | 556 | /// Creates a new window backdrop with a given material and frame. 557 | /// 558 | /// the Window Server will apply the backdrop's material effect to the window using the 559 | /// application's default connection. 560 | CG_EXTERN CGSWindowBackdropRef CGSWindowBackdropCreateWithLevel(CGWindowID wid, CFStringRef materialName, CGWindowLevel level, CGRect frame) AVAILABLE_MAC_OS_X_VERSION_10_10_AND_LATER; 561 | 562 | /// Releases a window backdrop object. 563 | CG_EXTERN void CGSWindowBackdropRelease(CGSWindowBackdropRef backdrop) AVAILABLE_MAC_OS_X_VERSION_10_10_AND_LATER; 564 | 565 | /// Activates the backdrop's effect. OS X currently only makes the key window's backdrop active. 566 | CG_EXTERN void CGSWindowBackdropActivate(CGSWindowBackdropRef backdrop) AVAILABLE_MAC_OS_X_VERSION_10_10_AND_LATER; 567 | CG_EXTERN void CGSWindowBackdropDeactivate(CGSWindowBackdropRef backdrop) AVAILABLE_MAC_OS_X_VERSION_10_10_AND_LATER; 568 | 569 | /// Sets the saturation of the backdrop. For certain material types this can imitate the "vibrancy" effect in AppKit. 570 | CG_EXTERN void CGSWindowBackdropSetSaturation(CGSWindowBackdropRef backdrop, CGFloat saturation) AVAILABLE_MAC_OS_X_VERSION_10_10_AND_LATER; 571 | 572 | /// Sets the bleed for the window's backdrop effect. Vibrant NSWindows use ~0.2. 573 | CG_EXTERN void CGSWindowSetBackdropBackgroundBleed(CGWindowID wid, CGFloat bleedAmount) AVAILABLE_MAC_OS_X_VERSION_10_10_AND_LATER; 574 | 575 | #endif /* CGS_WINDOW_INTERNAL_H */ 576 | -------------------------------------------------------------------------------- /CGSWorkspace.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2008 Alacatia Labs 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 3. This notice may not be removed or altered from any source distribution. 19 | * 20 | * Joe Ranieri joe@alacatia.com 21 | * 22 | */ 23 | 24 | // 25 | // Updated by Robert Widmann. 26 | // Copyright © 2015-2016 CodaFi. All rights reserved. 27 | // Released under the MIT license. 28 | // 29 | 30 | #ifndef CGS_WORKSPACE_INTERNAL_H 31 | #define CGS_WORKSPACE_INTERNAL_H 32 | 33 | #include "CGSConnection.h" 34 | #include "CGSWindow.h" 35 | #include "CGSTransitions.h" 36 | 37 | typedef unsigned int CGSWorkspaceID; 38 | 39 | /// The space ID given when we're switching spaces. 40 | static const CGSWorkspaceID kCGSTransitioningWorkspaceID = 65538; 41 | 42 | /// Gets and sets the current workspace. 43 | CG_EXTERN CGError CGSGetWorkspace(CGSConnectionID cid, CGSWorkspaceID *outWorkspace); 44 | CG_EXTERN CGError CGSSetWorkspace(CGSConnectionID cid, CGSWorkspaceID workspace); 45 | 46 | /// Transitions to a workspace asynchronously. Note that `duration` is in seconds. 47 | CG_EXTERN CGError CGSSetWorkspaceWithTransition(CGSConnectionID cid, CGSWorkspaceID workspace, CGSTransitionType transition, CGSTransitionFlags options, CGFloat duration); 48 | 49 | /// Gets and sets the workspace for a window. 50 | CG_EXTERN CGError CGSGetWindowWorkspace(CGSConnectionID cid, CGWindowID wid, CGSWorkspaceID *outWorkspace); 51 | CG_EXTERN CGError CGSSetWindowWorkspace(CGSConnectionID cid, CGWindowID wid, CGSWorkspaceID workspace); 52 | 53 | /// Gets the number of windows in the workspace. 54 | CG_EXTERN CGError CGSGetWorkspaceWindowCount(CGSConnectionID cid, int workspaceNumber, int *outCount); 55 | CG_EXTERN CGError CGSGetWorkspaceWindowList(CGSConnectionID cid, int workspaceNumber, int count, CGWindowID *list, int *outCount); 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | CGSInternal 2 | =========== 3 | 4 | A collection of private CoreGraphics routines. 5 | 6 | --------------------------------------------------------------------------------