CoreGraphicsPrivate.h
1 #ifndef COREGRAPHICSPRIVATE_H 2 #define COREGRAPHICSPRIVATE_H 3 #include <CoreGraphics/CoreGraphics.h> 4 #include <IOKit/hidsystem/IOLLEvent.h> 5 #include <CoreFoundation/CoreFoundation.h> 6 7 __BEGIN_DECLS 8 9 // References: 10 // https://github.com/koekeishiya/cglwindow/blob/master/src/cgl_window.c 11 // https://sourceforge.net/p/xnntp/SVN_Xnntp/1/tree/CGSPrivate.h 12 13 typedef int CGSConnectionID; 14 typedef int CGSWindowID; 15 typedef int CGSSurfaceID; 16 typedef unsigned long CGSNotificationType; 17 typedef CFMutableDictionaryRef CGSDictionaryObj; 18 typedef CFTypeRef CGSRegionRef; 19 20 #define CGSDefaultConnection _CGSDefaultConnection() 21 22 enum 23 { 24 kCGSErrorSuccess = 0, 25 }; 26 27 typedef enum { 28 kCGSOrderBelow = -1, 29 kCGSOrderOut, /* hides the window */ 30 kCGSOrderAbove, 31 kCGSOrderIn /* shows the window */ 32 } CGSWindowOrderingMode; 33 34 35 typedef enum { 36 kCGSBackingNonRetianed, 37 kCGSBackingRetained, 38 kCGSBackingBuffered, 39 } CGSBackingType; 40 41 extern void CGSInitialize(void); 42 extern CGError CGSNewConnection(_Nullable CGSDictionaryObj attribs, CGSConnectionID* connId); 43 extern CGError CGSReleaseConnection(CGSConnectionID connId); 44 extern CGSConnectionID _CGSDefaultConnection(void); 45 extern CGSConnectionID CGSMainConnectionID(void); 46 extern CGError CGSSetDenyWindowServerConnections(Boolean deny); 47 extern void CGSShutdownServerConnections(void); 48 49 // CGSRegion 50 extern CGError CGSNewRegionWithRect(const CGRect * rect, CGSRegionRef *newRegion); 51 extern void CGSRegionRelease(CGSRegionRef reg); 52 extern void CGSRegionRetain(CGSRegionRef reg); 53 extern void CGSRegionToRect(CGSRegionRef reg, CGRect* rect); // This is non-standard. We should support non-rectangular regions instead 54 extern bool CGSRegionIsRectangular(CGSRegionRef reg); 55 56 extern CGError CGSNewWindow(CGSConnectionID conn, CFIndex flags, float, float, const CGSRegionRef region, CGSWindowID* windowID); 57 extern CGError CGSReleaseWindow(CGSConnectionID cid, CGSWindowID wid); 58 59 extern CGError CGSSetWindowShape(CGSConnectionID cid, CGSWindowID wid, float x_offset, float y_offset, const CGSRegionRef shape); 60 extern OSStatus CGSOrderWindow(CGSConnectionID cid, CGSWindowID wid, CGSWindowOrderingMode place, CGSWindowID relativeToWindow); 61 extern CGError CGSMoveWindow(CGSConnectionID cid, CGSWindowID wid, const CGPoint *window_pos); 62 extern CGError CGSSetWindowOpacity(CGSConnectionID cid, CGSWindowID wid, bool isOpaque); 63 extern CGError CGSSetWindowAlpha(CGSConnectionID cid, CGSWindowID wid, float alpha); 64 extern CGError CGSSetWindowLevel(CGSConnectionID cid, CGSWindowID wid, CGWindowLevel level); 65 66 // Subwindows (for CGL) 67 extern CGError CGSAddSurface(CGSConnectionID cid, CGSWindowID wid, CGSSurfaceID *sid); 68 extern CGError CGSRemoveSurface(CGSConnectionID cid, CGSWindowID wid, CGSSurfaceID sid); 69 extern CGError CGSSetSurfaceBounds(CGSConnectionID cid, CGSWindowID wid, CGSSurfaceID sid, CGRect rect); 70 extern CGError CGSOrderSurface(CGSConnectionID cid, CGSWindowID wid, CGSSurfaceID sid, int a, int b); 71 //extern CGLError CGLSetSurface(CGLContextObj gl, CGSConnectionID cid, CGSWindowID wid, CGSSurfaceID sid); // in CGL 72 73 //extern CGContextRef CGWindowContextCreate(CGSConnectionID cid, CGSWindowID wid, CFDictionaryRef options); // in CGL 74 75 extern CGError CGSSetWindowTags(CGSConnectionID cid, CGSWindowID wid, const int tags[2], size_t tag_size); 76 extern CGError CGSClearWindowTags(CGSConnectionID cid, CGSWindowID wid, const int tags[2], size_t tag_size); 77 extern CGError CGSAddActivationRegion(CGSConnectionID cid, CGSWindowID wid, CGSRegionRef region); 78 extern CGError CGSClearActivationRegion(CGSConnectionID cid, CGSWindowID wid); 79 extern CGError CGSAddDragRegion(CGSConnectionID cid, CGSWindowID wid, CGSRegionRef region); 80 extern CGError CGSClearDragRegion(CGSConnectionID cid, CGSWindowID wid); 81 extern CGError CGSAddTrackingRect(CGSConnectionID cid, CGSWindowID wid, CGRect rect); 82 extern CGError CGSRemoveAllTrackingAreas(CGSConnectionID cid, CGSWindowID wid); 83 extern CFStringRef CGSCopyManagedDisplayForWindow(const CGSConnectionID cid, CGSWindowID wid); 84 extern CGError CGSGetScreenRectForWindow(CGSConnectionID cid, CGSWindowID wid, CGRect *outRect); 85 86 extern const CFStringRef kCGSWindowTitle; 87 extern CGError CGSSetWindowTitle(CGSConnectionID cid, CGSWindowID wid, CFStringRef title); 88 extern CGError CGSGetWindowProperty(CGSConnectionID cid, CGSWindowID wid, CFStringRef key, CFTypeRef *outValue); 89 extern CGError CGSSetWindowProperty(CGSConnectionID cid, CGSWindowID wid, CFStringRef key, CFTypeRef value); 90 91 typedef uint32_t CGSByteCount; 92 typedef uint16_t CGSEventRecordVersion; 93 typedef unsigned long CGSEventType; 94 typedef uint64_t CGSEventRecordTime; /* nanosecond timer */ 95 typedef unsigned long CGSEventFlag; 96 typedef NXEventData CGSEventRecordData; 97 98 struct _CGSEventRecord 99 { 100 CGSEventRecordVersion major; 101 CGSEventRecordVersion minor; 102 CGSByteCount length; /* Length of complete event record */ 103 CGSEventType type; /* An event type from above */ 104 CGPoint location; /* Base coordinates (global), from upper-left */ 105 CGPoint windowLocation; /* Coordinates relative to window */ 106 CGSEventRecordTime time; /* nanoseconds since startup */ 107 CGSEventFlag flags; /* key state flags */ 108 CGSWindowID window; /* window number of assigned window */ 109 CGSConnectionID connection; /* connection the event came from */ 110 CGSEventRecordData data; /* type-dependent data: 40 bytes */ 111 }; 112 typedef struct _CGSEventRecord CGSEventRecord; 113 typedef CGSEventRecord *CGSEventRecordPtr; 114 115 typedef void(*CGSNotifyProcPtr)(CGSNotificationType type, void* data, unsigned long dataLength, void* client); 116 117 // CGSNotificationType: 118 // 710 + NX event type from IOLLEvent.h 119 #define CGSNotificationSingleEventType(event) (701 + event) 120 #define kCGSNotificationAllEvents 0 121 extern CGError CGSRegisterNotifyProc(CGSNotifyProcPtr proc, CGSNotificationType notificationType, void* client); 122 extern CGError CGSRemoveNotifyProc(CGSNotifyProcPtr proc, CGSNotificationType notificationType); 123 124 // Darling extras, e.g. for CGL 125 void* _CGSNativeDisplay(CGSConnectionID connId); 126 void* _CGSNativeWindowForID(CGSConnectionID connId, CGSWindowID winId); 127 void* _CGSNativeWindowForSurfaceID(CGSConnectionID connId, CGSWindowID winId, CGSSurfaceID surfaceId); 128 129 extern CGEventRef CGEventCreateWithEventRecord(const CGSEventRecordPtr event, uint32_t eventRecordSize); 130 extern CGError CGEventGetEventRecord(CGEventRef event, CGSEventRecordPtr eventRecord, uint32_t eventRecordSize); 131 extern CGError CGEventSetEventRecord(CGEventRef event, CGSEventRecordPtr eventRecord, uint32_t eventRecordSize); 132 extern uint32_t CGEventGetEventRecordSize(CGEventRef event); 133 134 #ifdef __OBJC__ 135 @class CGSConnection; 136 CGSConnection* _CGSConnectionForID(CGSConnectionID connId); 137 CGSConnection* _CGSConnectionFromEventRecord(const CGSEventRecordPtr record); 138 #endif 139 140 __END_DECLS 141 142 #endif