From b26bedb31c8c770622c1ad0ab28b577dffa0b091 Mon Sep 17 00:00:00 2001 From: Lubos Dolezel Date: Fri, 15 May 2020 10:47:23 +0200 Subject: [PATCH] CGS work progress --- CoreGraphics/CGEvent.m | 462 +++-- CoreGraphics/CGEventObjC.h | 108 +- CoreGraphics/CGEventObjC.m | 391 ++-- CoreGraphics/CGEventTap.m | 89 +- CoreGraphics/CGEventTapInternal.h | 10 + CoreGraphics/CGS.m | 451 +++-- CoreGraphics/CGSConnection.m | 102 +- CoreGraphics/CGSKeyboardLayout.m | 43 + CoreGraphics/CGSScreen.m | 46 + CoreGraphics/CMakeLists.txt | 4 + CoreGraphics/X11.backend/CGSConnectionX11.h | 57 + CoreGraphics/X11.backend/CGSConnectionX11.m | 381 ++++ CoreGraphics/X11.backend/CGSSurfaceX11.h | 28 + CoreGraphics/X11.backend/CGSSurfaceX11.m | 19 + CoreGraphics/X11.backend/CGSWindowX11.h | 28 + CoreGraphics/X11.backend/CGSWindowX11.m | 20 + CoreGraphics/X11.backend/CMakeLists.txt | 55 + CoreGraphics/X11.backend/CarbonKeys.h | 238 +++ CoreGraphics/X11.backend/Info.plist | 26 + CoreGraphics/X11.backend/X11KeySymToUCS.h | 7 + CoreGraphics/X11.backend/X11KeySymToUCS.m | 1664 +++++++++++++++++ CoreGraphics/include/CoreGraphics/CGEvent.h | 120 +- CoreGraphics/include/CoreGraphics/CGS.h | 18 - .../include/CoreGraphics/CGSConnection.h | 42 +- .../include/CoreGraphics/CGSKeyboardLayout.h | 42 + CoreGraphics/include/CoreGraphics/CGSScreen.h | 42 + CoreGraphics/include/CoreGraphics/CGSWindow.h | 44 +- .../CoreGraphics/CoreGraphicsPrivate.h | 157 +- 28 files changed, 4012 insertions(+), 682 deletions(-) create mode 100644 CoreGraphics/CGSKeyboardLayout.m create mode 100644 CoreGraphics/CGSScreen.m create mode 100644 CoreGraphics/X11.backend/CGSConnectionX11.h create mode 100644 CoreGraphics/X11.backend/CGSConnectionX11.m create mode 100644 CoreGraphics/X11.backend/CGSSurfaceX11.h create mode 100644 CoreGraphics/X11.backend/CGSSurfaceX11.m create mode 100644 CoreGraphics/X11.backend/CGSWindowX11.h create mode 100644 CoreGraphics/X11.backend/CGSWindowX11.m create mode 100644 CoreGraphics/X11.backend/CMakeLists.txt create mode 100644 CoreGraphics/X11.backend/CarbonKeys.h create mode 100644 CoreGraphics/X11.backend/Info.plist create mode 100644 CoreGraphics/X11.backend/X11KeySymToUCS.h create mode 100644 CoreGraphics/X11.backend/X11KeySymToUCS.m delete mode 100644 CoreGraphics/include/CoreGraphics/CGS.h create mode 100644 CoreGraphics/include/CoreGraphics/CGSKeyboardLayout.h create mode 100644 CoreGraphics/include/CoreGraphics/CGSScreen.h diff --git a/CoreGraphics/CGEvent.m b/CoreGraphics/CGEvent.m index f032c57f..a09c912c 100644 --- a/CoreGraphics/CGEvent.m +++ b/CoreGraphics/CGEvent.m @@ -17,202 +17,314 @@ along with Darling. If not, see . */ -#import "CGEventObjC.h" #include -#import +#include #include +#import +#import +#import +#import +#import "CGEventObjC.h" -CFTypeID CGEventGetTypeID(void) { - return (CFTypeID)[CGEvent self]; -} - -CGEventRef CGEventCreate(CGEventSourceRef source) { - return (CGEventRef) - [[CGEvent alloc] initWithSource: (CGEventSource *) source]; -} - -CGEventRef CGEventCreateCopy(CGEventRef event) { - return (CGEventRef)[(CGEvent *) event copy]; -} - -CFDataRef CGEventCreateData(CFAllocatorRef allocator, CGEventRef event) { - CGEvent *e = (CGEvent *) event; - NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] init]; - - [e encodeWithCoder: archiver]; - - NSData *data = [[archiver encodedData] retain]; - [archiver release]; - - return data; -} - -CGEventRef CGEventCreateFromData(CFAllocatorRef allocator, CFDataRef data) { - NSKeyedUnarchiver *unarchiver = - [[NSKeyedUnarchiver alloc] initForReadingWithData: data]; - - CGEvent *e = [[CGEvent alloc] initWithCoder: unarchiver]; - - [unarchiver finishDecoding]; - [unarchiver release]; - - return (CGEventRef) e; -} - -CGEventType CGEventGetType(CGEventRef event) { - CGEvent *e = (CGEvent *) event; - return e.type; -} - -void CGEventSetSource(CGEventRef event, CGEventSourceRef source) { - CGEvent *e = (CGEvent *) event; - e.source = (CGEventSource *) source; -} - -CGEventSourceRef CGEventCreateSourceFromEvent(CGEventRef event) { - CGEvent *e = (CGEvent *) event; - return (CGEventSourceRef)[(CGEventSource *) e.source retain]; -} - -void CGEventSetType(CGEventRef event, CGEventType type) { - CGEvent *e = (CGEvent *) event; - e.type = type; -} - -CGEventTimestamp CGEventGetTimestamp(CGEventRef event) { - CGEvent *e = (CGEvent *) event; - return e.timestamp; -} - -void CGEventSetTimestamp(CGEventRef event, CGEventTimestamp timestamp) { - CGEvent *e = (CGEvent *) event; - e.timestamp = timestamp; -} - -int64_t CGEventGetIntegerValueField(CGEventRef event, CGEventField field) { - CGEvent *e = (CGEvent *) event; - NSNumber *value = e.fields[[NSNumber numberWithInt: field]]; - - if (!value) - return 0; - return value.longLongValue; -} - -void CGEventSetIntegerValueField(CGEventRef event, CGEventField field, - int64_t value) +CFTypeID CGEventGetTypeID(void) { - CGEvent *e = (CGEvent *) event; - e.fields[[NSNumber numberWithInt: field]] = - [NSNumber numberWithLongLong: value]; + return (CFTypeID) [CGEvent self]; } -double CGEventGetDoubleValueField(CGEventRef event, CGEventField field) { - CGEvent *e = (CGEvent *) event; - NSNumber *value = e.fields[[NSNumber numberWithInt: field]]; - - if (!value) - return 0; - return value.doubleValue; -} - -void CGEventSetDoubleValueField(CGEventRef event, CGEventField field, - double value) +CGEventRef CGEventCreate(CGEventSourceRef source) { - CGEvent *e = (CGEvent *) event; - e.fields[[NSNumber numberWithInt: field]] = - [NSNumber numberWithDouble: value]; + return (CGEventRef) [[CGEvent alloc] initWithSource: (CGEventSource*) source]; } -CGEventRef CGEventCreateKeyboardEvent(CGEventSourceRef source, - CGKeyCode virtualKey, bool keyDown) +CGEventRef CGEventCreateCopy(CGEventRef event) { - CGEventType type = keyDown ? kCGEventKeyDown : kCGEventKeyUp; - CGEvent *event = [[CGEvent alloc] initWithSource: (CGEventSource *) source - type: type]; - event.virtualKey = virtualKey; - - return (CGEventRef) event; + return (CGEventRef) [(CGEvent*)event copy]; } -CGEventRef CGEventCreateMouseEvent(CGEventSourceRef source, - CGEventType mouseType, - CGPoint mouseCursorPosition, - CGMouseButton mouseButton) +CFDataRef CGEventCreateData(CFAllocatorRef allocator, CGEventRef event) { - CGEvent *event = [[CGEvent alloc] initWithSource: (CGEventSource *) source - type: mouseType]; - event.location = mouseCursorPosition; - event.mouseButton = mouseButton; - return (CGEventRef) event; + CGEvent* e = (CGEvent*) event; + NSData* data = [NSKeyedArchiver archivedDataWithRootObject: e]; + + return (CFDataRef) [data retain]; } -CGEventRef CGEventCreateScrollWheelEvent(CGEventSourceRef source, - CGScrollEventUnit units, - uint32_t wheelCount, int32_t wheel1, - ...) +CGEventRef CGEventCreateFromData(CFAllocatorRef allocator, CFDataRef data) { - CGEvent *event = [[CGEvent alloc] initWithSource: (CGEventSource *) source - type: kCGEventScrollWheel]; - event.scrollEventUnit = units; - event.wheelCount = wheelCount; - event.wheels[0] = wheel1; + NSKeyedUnarchiver* unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData: (NSData*) data]; + + CGEvent* e = [unarchiver decodeObject]; - if (wheelCount > 1) { - va_list vl; - va_start(vl, wheel1); - - event.wheels[1] = va_arg(vl, int32_t); - - if (wheelCount > 2) - event.wheels[2] = va_arg(vl, int32_t); - - va_end(vl); - } - return (CGEventRef) event; + [unarchiver finishDecoding]; + [unarchiver release]; + + return (CGEventRef) e; } -CGPoint CGEventGetLocation(CGEventRef event) { - CGEvent *e = (CGEvent *) event; - return e.location; -} - -void CGEventSetLocation(CGEventRef event, CGPoint location) { - CGEvent *e = (CGEvent *) event; - e.location = location; -} - -void CGEventKeyboardGetUnicodeString(CGEventRef event, - UniCharCount maxStringLength, - UniCharCount *actualStringLength, - UniChar *unicodeString) +CGEventType CGEventGetType(CGEventRef event) { - CGEvent *e = (CGEvent *) event; - UniChar *savedString = e.unicodeString; - - UniCharCount length = 0; - while (length < 5 && savedString[length]) - length++; - - if (maxStringLength == 0) { - *actualStringLength = length; - } - - *actualStringLength = length; - if (maxStringLength < length) - *actualStringLength = maxStringLength; - - memcpy(unicodeString, savedString, *actualStringLength * sizeof(UniChar)); + CGEvent* e = (CGEvent*) event; + return e.type; } -void CGEventKeyboardSetUnicodeString(CGEventRef event, - UniCharCount stringLength, - const UniChar *unicodeString) +void CGEventSetSource(CGEventRef event, CGEventSourceRef source) { - CGEvent *e = (CGEvent *) event; - - // This is the maximum CGEvent can save - if (stringLength > 5) - stringLength = 5; - - memcpy(e.unicodeString, unicodeString, stringLength * sizeof(UniChar)); + CGEvent* e = (CGEvent*) event; + e.source = (CGEventSource*) source; +} + +CGEventSourceRef CGEventCreateSourceFromEvent(CGEventRef event) +{ + CGEvent* e = (CGEvent*) event; + return (CGEventSourceRef) [(CGEventSource*) e.source retain]; +} + +void CGEventSetType(CGEventRef event, CGEventType type) +{ + CGEvent* e = (CGEvent*) event; + e.type = type; +} + +CGEventTimestamp CGEventGetTimestamp(CGEventRef event) +{ + CGEvent* e = (CGEvent*) event; + return e.timestamp; +} + +void CGEventSetTimestamp(CGEventRef event, CGEventTimestamp timestamp) +{ + CGEvent* e = (CGEvent*) event; + e.timestamp = timestamp; +} + +int64_t CGEventGetIntegerValueField(CGEventRef event, CGEventField field) +{ + CGEvent* e = (CGEvent*) event; + NSNumber* value = e.fields[[NSNumber numberWithInt: field]]; + + if (!value) + return 0; + return value.longLongValue; +} + +void CGEventSetIntegerValueField(CGEventRef event, CGEventField field, int64_t value) +{ + CGEvent* e = (CGEvent*) event; + e.fields[[NSNumber numberWithInt: field]] = [NSNumber numberWithLongLong: value]; +} + +double CGEventGetDoubleValueField(CGEventRef event, CGEventField field) +{ + CGEvent* e = (CGEvent*) event; + NSNumber* value = e.fields[[NSNumber numberWithInt: field]]; + + if (!value) + return 0; + + if (field == kCGScrollWheelEventFixedPtDeltaAxis1 || field == kCGScrollWheelEventFixedPtDeltaAxis2 + || field == kCGScrollWheelEventFixedPtDeltaAxis3) + { + int64_t fixedPt = value.longLongValue; + return ((double)fixedPt) / 0x00010000; + } + + return value.doubleValue; +} + +void CGEventSetDoubleValueField(CGEventRef event, CGEventField field, double value) +{ + CGEvent* e = (CGEvent*) event; + + if (field == kCGScrollWheelEventFixedPtDeltaAxis1 || field == kCGScrollWheelEventFixedPtDeltaAxis2 + || field == kCGScrollWheelEventFixedPtDeltaAxis3) + { + int64_t fixedPt = (int64_t) (value * 0x00010000); + e.fields[[NSNumber numberWithInt: field]] = [NSNumber numberWithLongLong: fixedPt]; + } + else + { + e.fields[[NSNumber numberWithInt: field]] = [NSNumber numberWithDouble: value]; + } +} + +CGEventRef CGEventCreateKeyboardEvent(CGEventSourceRef source, CGKeyCode virtualKey, bool keyDown) +{ + CGEventType type = keyDown ? kCGEventKeyDown : kCGEventKeyUp; + CGEvent* event = [[CGEvent alloc] initWithSource: (CGEventSource*) source type: type]; + event.virtualKey = virtualKey; + + return (CGEventRef) event; +} + +CGEventRef CGEventCreateMouseEvent(CGEventSourceRef source, CGEventType mouseType, CGPoint mouseCursorPosition, CGMouseButton mouseButton) +{ + CGEvent* event = [[CGEvent alloc] initWithSource: (CGEventSource*) source type: mouseType]; + event.location = mouseCursorPosition; + event.mouseButton = mouseButton; + return (CGEventRef) event; +} + +CGEventRef CGEventCreateScrollWheelEvent(CGEventSourceRef source, CGScrollEventUnit units, uint32_t wheelCount, int32_t wheel1, ...) +{ + if (!source) + source = (CGEventSourceRef) [CGEventSource hidEventSource]; + + CGEvent* event = [[CGEvent alloc] initWithSource: (CGEventSource*) source type: kCGEventScrollWheel]; + + double pixelsPerLine = CGEventSourceGetPixelsPerLine(source); + + if (units == kCGScrollEventUnitPixel) + { + event.fields[@(kCGScrollWheelEventDeltaAxis1)] = [NSNumber numberWithInt: (int)(wheel1 / pixelsPerLine)]; + event.fields[@(kCGScrollWheelEventFixedPtDeltaAxis1)] = [NSNumber numberWithDouble: wheel1 / pixelsPerLine]; + event.fields[@(kCGScrollWheelEventPointDeltaAxis1)] = [NSNumber numberWithInt: wheel1]; + } + else + { + event.fields[@(kCGScrollWheelEventDeltaAxis1)] = [NSNumber numberWithInt: wheel1]; + event.fields[@(kCGScrollWheelEventFixedPtDeltaAxis1)] = [NSNumber numberWithDouble: wheel1]; + event.fields[@(kCGScrollWheelEventPointDeltaAxis1)] = [NSNumber numberWithInt: (int)(wheel1 * pixelsPerLine)]; + } + + if (wheelCount > 1) + { + va_list vl; + va_start(vl, wheel1); + + int32_t wheelN = va_arg(vl, int32_t); + if (units == kCGScrollEventUnitPixel) + { + event.fields[@(kCGScrollWheelEventDeltaAxis2)] = [NSNumber numberWithInt: (int)(wheelN / pixelsPerLine)]; + event.fields[@(kCGScrollWheelEventFixedPtDeltaAxis2)] = [NSNumber numberWithDouble: wheelN / pixelsPerLine]; + event.fields[@(kCGScrollWheelEventPointDeltaAxis2)] = [NSNumber numberWithInt: wheelN]; + } + else + { + event.fields[@(kCGScrollWheelEventDeltaAxis2)] = [NSNumber numberWithInt: wheelN]; + event.fields[@(kCGScrollWheelEventFixedPtDeltaAxis2)] = [NSNumber numberWithDouble: wheelN]; + event.fields[@(kCGScrollWheelEventPointDeltaAxis2)] = [NSNumber numberWithInt: (int)(wheelN * pixelsPerLine)]; + } + + if (wheelCount > 2) + { + wheelN = va_arg(vl, int32_t); + if (units == kCGScrollEventUnitPixel) + { + event.fields[@(kCGScrollWheelEventDeltaAxis3)] = [NSNumber numberWithInt: (int)(wheelN / pixelsPerLine)]; + event.fields[@(kCGScrollWheelEventFixedPtDeltaAxis3)] = [NSNumber numberWithDouble: wheelN / pixelsPerLine]; + event.fields[@(kCGScrollWheelEventPointDeltaAxis3)] = [NSNumber numberWithInt: wheelN]; + } + else + { + event.fields[@(kCGScrollWheelEventDeltaAxis3)] = [NSNumber numberWithInt: wheelN]; + event.fields[@(kCGScrollWheelEventFixedPtDeltaAxis3)] = [NSNumber numberWithDouble: wheelN]; + event.fields[@(kCGScrollWheelEventPointDeltaAxis3)] = [NSNumber numberWithInt: (int)(wheelN * pixelsPerLine)]; + } + } + + va_end(vl); + } + return (CGEventRef) event; +} + +CGPoint CGEventGetLocation(CGEventRef event) +{ + CGEvent* e = (CGEvent*) event; + return e.location; +} + +// Returns location relative to the LOWER left corner +CGPoint CGEventGetUnflippedLocation(CGEventRef event) +{ + CGEvent* e = (CGEvent*) event; + CGPoint pt = CGEventGetLocation(event); + + CGSConnection* conn = nil; + + if (e.eventRecord) + conn = _CGSConnectionFromEventRecord(e.eventRecord); + + if (!conn) + conn = _CGSConnectionForID(CGSDefaultConnection); + + // Implementaton should cache this for fast access + NSArray* screens = [conn createScreens]; + + if (!screens) + return CGPointMake(-1, -1); + + // And currentModeHeight is also cached to speed this up + pt.y = [screens[0] currentModeHeight] - pt.y; + [screens release]; + + return pt; +} + +void CGEventSetLocation(CGEventRef event, CGPoint location) +{ + CGEvent* e = (CGEvent*) event; + e.location = location; +} + +void CGEventKeyboardGetUnicodeString(CGEventRef event, UniCharCount maxStringLength, UniCharCount *actualStringLength, UniChar *unicodeString) +{ + CGEvent* e = (CGEvent*) event; + UniChar* savedString = e.unicodeString; + + UniCharCount length = 0; + while (length < 5 && savedString[length]) + length++; + + if (maxStringLength == 0) + { + *actualStringLength = length; + } + + *actualStringLength = length; + if (maxStringLength < length) + *actualStringLength = maxStringLength; + + memcpy(unicodeString, savedString, *actualStringLength * sizeof(UniChar)); +} + +void CGEventKeyboardSetUnicodeString(CGEventRef event, UniCharCount stringLength, const UniChar *unicodeString) +{ + CGEvent* e = (CGEvent*) event; + + // This is the maximum CGEvent can save + if (stringLength > 5) + stringLength = 5; + + memcpy(e.unicodeString, unicodeString, stringLength * sizeof(UniChar)); +} + +CGEventRef CGEventCreateWithEventRecord(const CGSEventRecordPtr event, uint32_t eventRecordSize) +{ + CGEvent* e = [[CGEvent alloc] initWithEventRecord: event length: eventRecordSize]; + return (CGEventRef) e; +} + +CGError CGEventGetEventRecord(CGEventRef event, CGSEventRecordPtr eventRecord, uint32_t eventRecordSize) +{ + CGEvent* e = (CGEvent*) event; + + if (eventRecordSize < e.eventRecordLength) + return kCGErrorRangeCheck; + + memcpy(eventRecord, e.eventRecord, e.eventRecordLength); + return kCGErrorSuccess; +} + +CGError CGEventSetEventRecord(CGEventRef event, CGSEventRecordPtr eventRecord, uint32_t eventRecordSize) +{ + CGEvent* e = (CGEvent*) event; + // TODO: should this call reset all other values in the CGEvent? + [e setEventRecord: eventRecord length: eventRecordSize]; + return kCGErrorSuccess; +} + +uint32_t CGEventGetEventRecordSize(CGEventRef event) +{ + CGEvent* e = (CGEvent*) event; + return e.eventRecordLength; } diff --git a/CoreGraphics/CGEventObjC.h b/CoreGraphics/CGEventObjC.h index bbab814d..dfec074d 100644 --- a/CoreGraphics/CGEventObjC.h +++ b/CoreGraphics/CGEventObjC.h @@ -19,72 +19,73 @@ #ifndef CGEVENT_OBJC_H #define CGEVENT_OBJC_H -#include #include -#import -#import +#include #import +#import +#import @class CGEventSource; @interface CGEvent : NSObject { - CGEventSource *_source; - CGEventType _type; - CGEventTimestamp _timestamp; - CGEventFlags _flags; - NSMutableDictionary *_fields; + CGEventSource* _source; + CGEventType _type; + CGEventTimestamp _timestamp; + CGEventFlags _flags; + NSMutableDictionary* _fields; - // keyboard events - CGKeyCode _virtualKey; - UniChar _unicodeString[5]; + // keyboard events + CGKeyCode _virtualKey; + UniChar _unicodeString[5]; - // mouse button events - CGPoint _location; - CGMouseButton _mouseButton; + // mouse button events + CGPoint _location; + CGMouseButton _mouseButton; - // mouse wheel events - CGScrollEventUnit _scrollEventUnit; - uint32_t _wheelCount; - int32_t _wheels[3]; + CGSEventRecordPtr _eventRecord; + uint32_t _eventRecordLength; } -- (instancetype) initWithSource: (CGEventSource *) source; -- (instancetype) initWithSource: (CGEventSource *) source - type: (CGEventType) type; -- (instancetype) initWithData: (NSData *) data; +-(instancetype) initWithSource:(CGEventSource*) source; +-(instancetype) initWithSource:(CGEventSource*) source + type:(CGEventType) type; +-(instancetype) initWithEventRecord:(const CGSEventRecordPtr) eventRecord + length:(uint32_t) length; -- (void) dealloc; -- (id) copy; -- (CFTypeID) _cfTypeID; -- (NSData *) createData; +-(void) dealloc; +-(id)copy; +-(CFTypeID) _cfTypeID; + +-(void) setEventRecord:(CGSEventRecordPtr) record + length:(uint32_t) length; +@property(readonly) uint32_t eventRecordLength; +@property(readonly) CGSEventRecordPtr eventRecord; @property(readwrite) CGEventType type; -@property(retain) CGEventSource *source; +@property(retain) CGEventSource* source; @property(readwrite) CGEventTimestamp timestamp; @property(readwrite) CGEventFlags flags; -@property(readonly) NSMutableDictionary *fields; +@property(readonly) NSMutableDictionary* fields; @property(readwrite) CGKeyCode virtualKey; @property(readwrite) CGPoint location; @property(readwrite) CGMouseButton mouseButton; -@property(readwrite) CGScrollEventUnit scrollEventUnit; -@property(readwrite) uint32_t wheelCount; -@property(readonly) int32_t *wheels; -@property(readonly) UniChar *unicodeString; +@property(readonly) UniChar* unicodeString; @end ////////////////////////////////////////////////////////////////////// @interface CGEventSource : NSObject { - CGEventSourceStateID _stateId; - CGEventSourceKeyboardType _keyboardType; - int64_t _userData; - double _pixelsPerLine; + CGEventSourceStateID _stateId; + CGEventSourceKeyboardType _keyboardType; + int64_t _userData; + double _pixelsPerLine; } -- (instancetype) initWithState: (CGEventSourceStateID) stateId; -- (CFTypeID) _cfTypeID; +-(instancetype) initWithState: (CGEventSourceStateID) stateId; +-(CFTypeID) _cfTypeID; ++(CGEventSource*) hidEventSource; @property CGEventSourceKeyboardType keyboardType; @property CGEventSourceStateID stateID; @@ -96,32 +97,33 @@ ////////////////////////////////////////////////////////////////////// @interface CGEventTap : NSObject { - CGEventTapLocation _location; - CGEventTapOptions _options; - CGEventMask _mask; - CGEventTapCallBack _callback; - void *_userInfo; - Boolean _enabled; + CGEventTapLocation _location; + CGEventTapOptions _options; + CGEventMask _mask; + CGEventTapCallBack _callback; + void* _userInfo; + Boolean _enabled; - mach_port_t _machPort; + mach_port_t _machPort; } -- (instancetype) initWithLocation: (CGEventTapLocation) location - options: (CGEventTapOptions) options - mask: (CGEventMask) mask - callback: (CGEventTapCallBack) callback - userInfo: (void *) userInfo; +-(instancetype) initWithLocation: (CGEventTapLocation) location + options: (CGEventTapOptions) options + mask: (CGEventMask) mask + callback: (CGEventTapCallBack) callback + userInfo: (void*) userInfo; -- (void) dealloc; -- (CFMachPortRef) createCFMachPort; +-(void) dealloc; +-(CFMachPortRef) createCFMachPort; @property(readonly) mach_port_t machPort; @property(readonly) CGEventTapOptions options; @property(readonly) CGEventMask mask; @property(readonly) CGEventTapCallBack callback; -@property(readonly) void *userInfo; +@property(readonly) void* userInfo; @property Boolean enabled; @end #endif + diff --git a/CoreGraphics/CGEventObjC.m b/CoreGraphics/CGEventObjC.m index 53ce5433..0bcfa825 100644 --- a/CoreGraphics/CGEventObjC.m +++ b/CoreGraphics/CGEventObjC.m @@ -17,11 +17,14 @@ along with Darling. If not, see . */ #include "CGEventObjC.h" -#include "CGEventTapInternal.h" +#include #include +#include +#include "CGEventTapInternal.h" #import #import -#include + +#define CGInvalidPoint CGPointMake(CGFLOAT_MAX, CGFLOAT_MAX) @implementation CGEvent @@ -32,97 +35,215 @@ @synthesize fields = _fields; @synthesize virtualKey = _virtualKey; @synthesize mouseButton = _mouseButton; -@synthesize location = _location; -@synthesize scrollEventUnit = _scrollEventUnit; -@synthesize wheelCount = _wheelCount; -- (instancetype) initWithSource: (CGEventSource *) source { - return [self initWithSource: source type: kCGEventNull]; -} - -- (instancetype) initWithSource: (CGEventSource *) source - type: (CGEventType) type; +-(instancetype) initWithSource:(CGEventSource*) source { - _source = [source retain]; - _type = type; - _fields = [[NSMutableDictionary alloc] initWithCapacity: 0]; - _timestamp = clock_gettime_nsec_np(CLOCK_UPTIME_RAW); - return self; + return [self initWithSource: source + type: kCGEventNull]; } -- (instancetype) initWithCoder: (NSCoder *) coder { - NSKeyedUnarchiver *unarchiver = (NSKeyedUnarchiver *) coder; +-(instancetype) initWithSource:(CGEventSource*) source + type:(CGEventType) type; +{ + _source = [source retain]; + _type = type; + _fields = [[NSMutableDictionary alloc] initWithCapacity: 0]; + _timestamp = clock_gettime_nsec_np(CLOCK_UPTIME_RAW); - // TODO - - return self; + _location = CGInvalidPoint; + return self; } -- (void) dealloc { - [_source release]; - [_fields release]; - [super dealloc]; +-(instancetype) initWithCoder:(NSCoder*) coder +{ + NSKeyedUnarchiver* unarchiver = (NSKeyedUnarchiver*) coder; + + // TODO + + return self; } -- (id) copy { - CGEvent *rv = [[CGEvent alloc] initWithSource: _source type: _type]; - rv->_timestamp = self->_timestamp; - rv->_flags = self->_flags; - rv->_fields = [_fields copy]; +-(void) _fillFromEventRecord +{ + _location = _eventRecord->location; + _type = _eventRecord->type; // These types match! + _timestamp = _eventRecord->time; - rv->_virtualKey = _virtualKey; - memcpy(rv->_unicodeString, _unicodeString, sizeof(_unicodeString)); + switch (_eventRecord->type) + { + case NX_LMOUSEDOWN: + case NX_LMOUSEUP: + case NX_RMOUSEDOWN: + case NX_RMOUSEUP: + case NX_OMOUSEDOWN: + case NX_OMOUSEUP: + case NX_LMOUSEDRAGGED: + case NX_RMOUSEDRAGGED: + case NX_OMOUSEDRAGGED: + { + _fields[@(kCGMouseEventButtonNumber)] = [NSNumber numberWithInt: _eventRecord->data.mouse.buttonNumber]; + _fields[@(kCGMouseEventNumber)] = [NSNumber numberWithInt: _eventRecord->data.mouse.eventNum]; + _fields[@(kCGMouseEventPressure)] = [NSNumber numberWithDouble: _eventRecord->data.mouse.pressure / 255.0]; + _fields[@(kCGMouseEventClickState)] = [NSNumber numberWithInt: _eventRecord->data.mouse.click]; + _fields[@(kCGMouseEventSubtype)] = [NSNumber numberWithInt: _eventRecord->data.mouse.subType]; + break; + } + case NX_MOUSEMOVED: + { + _fields[@(kCGMouseEventDeltaX)] = [NSNumber numberWithInt: _eventRecord->data.mouseMove.dx]; + _fields[@(kCGMouseEventDeltaY)] = [NSNumber numberWithInt: _eventRecord->data.mouseMove.dy]; + _fields[@(kCGMouseEventSubtype)] = [NSNumber numberWithInt: _eventRecord->data.mouseMove.subType]; + break; + } + case NX_SCROLLWHEELMOVED: + { + _fields[@(kCGScrollWheelEventDeltaAxis1)] = [NSNumber numberWithInt: _eventRecord->data.scrollWheel.deltaAxis1]; + _fields[@(kCGScrollWheelEventDeltaAxis2)] = [NSNumber numberWithInt: _eventRecord->data.scrollWheel.deltaAxis2]; + _fields[@(kCGScrollWheelEventDeltaAxis3)] = [NSNumber numberWithInt: _eventRecord->data.scrollWheel.deltaAxis3]; - rv->_location = _location; - rv->_mouseButton = _mouseButton; + _fields[@(kCGScrollWheelEventFixedPtDeltaAxis1)] = [NSNumber numberWithInt: _eventRecord->data.scrollWheel.fixedDeltaAxis1]; + _fields[@(kCGScrollWheelEventFixedPtDeltaAxis2)] = [NSNumber numberWithInt: _eventRecord->data.scrollWheel.fixedDeltaAxis2]; + _fields[@(kCGScrollWheelEventFixedPtDeltaAxis3)] = [NSNumber numberWithInt: _eventRecord->data.scrollWheel.fixedDeltaAxis3]; - rv->_scrollEventUnit = _scrollEventUnit; - rv->_wheelCount = _wheelCount; - memcpy(rv->_wheels, _wheels, sizeof(_wheels)); - - return rv; + _fields[@(kCGScrollWheelEventPointDeltaAxis1)] = [NSNumber numberWithInt: _eventRecord->data.scrollWheel.pointDeltaAxis1]; + _fields[@(kCGScrollWheelEventPointDeltaAxis2)] = [NSNumber numberWithInt: _eventRecord->data.scrollWheel.pointDeltaAxis2]; + _fields[@(kCGScrollWheelEventPointDeltaAxis3)] = [NSNumber numberWithInt: _eventRecord->data.scrollWheel.pointDeltaAxis3]; + break; + } + case NX_KEYDOWN: + case NX_KEYUP: + { + break; + } + } } -- (id) copyWithZone: (NSZone *) zone { - return [self copy]; +-(void) _createEventRecord +{ + // TODO } -- (CFTypeID) _cfTypeID { - return CGEventGetTypeID(); +-(uint32_t) eventRecordLength +{ + if (!_eventRecordLength) + [self _createEventRecord]; + return _eventRecordLength; } -- (int32_t *) wheels { - return _wheels; +-(CGSEventRecordPtr) eventRecord +{ + if (!_eventRecord) + [self _createEventRecord]; + return _eventRecord; } -- (UniChar *) unicodeString { - return _unicodeString; +-(instancetype) initWithEventRecord:(const CGSEventRecordPtr) eventRecord + length:(uint32_t) length +{ + _eventRecord = malloc(length); + memcpy(_eventRecord, eventRecord, length); + _eventRecordLength = length; + + _fields = [[NSMutableDictionary alloc] initWithCapacity: 0]; + _source = [[CGEventSource hidEventSource] retain]; + + [self _fillFromEventRecord]; + + return self; } -- (void) encodeWithCoder: (NSCoder *) coder { - NSKeyedArchiver *archiver = (NSKeyedArchiver *) coder; +-(void) setEventRecord:(CGSEventRecordPtr) record + length:(uint32_t) length +{ + CGSEventRecordPtr myCopy = (CGSEventRecordPtr) malloc(length); + memcpy(myCopy, record, length); - CGEventSourceStateID stateId = _source.stateID; - [archiver encodeInt: stateId forKey: @"stateId"]; - - [archiver encodeInt: _type forKey: @"type"]; - [archiver encodeInt64: _timestamp forKey: @"timestamp"]; - [archiver encodeObject: _fields forKey: @"fields"]; - [archiver encodeInt: _virtualKey forKey: @"virtualKey"]; - [archiver encodeBytes: (uint8_t *) _unicodeString - length: sizeof(_unicodeString) - forKey: @"unicodeString"]; - [archiver encodeDouble: _location.x forKey: @"location.x"]; - [archiver encodeDouble: _location.y forKey: @"location.y"]; - [archiver encodeInt: _mouseButton forKey: @"mouseButton"]; - [archiver encodeInt: _scrollEventUnit forKey: @"scrollEventUnit"]; - [archiver encodeInt: _wheelCount forKey: @"wheelCount"]; - - for (uint32_t i = 0; i < _wheelCount; i++) { - [archiver encodeInt: _wheels[i] - forKey: [NSString stringWithFormat: @"wheel-%d", i]]; - } + free(_eventRecord); + _eventRecord = myCopy; + _eventRecordLength = length; } + +-(void) dealloc +{ + free(_eventRecord); + [_source release]; + [_fields release]; + [super dealloc]; +} + +-(id)copy +{ + CGEvent* rv = [[CGEvent alloc] initWithSource: _source type: _type]; + rv->_timestamp = self->_timestamp; + rv->_flags = self->_flags; + rv->_fields = [_fields copy]; + + rv->_virtualKey = _virtualKey; + memcpy(rv->_unicodeString, _unicodeString, sizeof(_unicodeString)); + + rv->_location = _location; + rv->_mouseButton = _mouseButton; + + if (_eventRecord) + { + rv->_eventRecordLength = _eventRecordLength; + rv->_eventRecord = (CGSEventRecordPtr) malloc(_eventRecordLength); + memcpy(rv->_eventRecord, _eventRecord, _eventRecordLength); + } + + return rv; +} + +- (id)copyWithZone:(NSZone *)zone +{ + return [self copy]; +} + +-(CFTypeID) _cfTypeID +{ + return CGEventGetTypeID(); +} + +-(UniChar*) unicodeString +{ + return _unicodeString; +} + +-(void) encodeWithCoder:(NSCoder*) coder +{ + NSKeyedArchiver* archiver = (NSKeyedArchiver*) coder; + + CGEventSourceStateID stateId = _source.stateID; + [archiver encodeInt: stateId forKey:@"stateId"]; + + [archiver encodeInt: _type forKey: @"type"]; + [archiver encodeInt64: _timestamp forKey: @"timestamp"]; + [archiver encodeObject: _fields forKey: @"fields"]; + [archiver encodeInt: _virtualKey forKey: @"virtualKey"]; + [archiver encodeBytes: (uint8_t*) _unicodeString length: sizeof(_unicodeString) forKey: @"unicodeString"]; + [archiver encodeDouble: _location.x forKey: @"location.x"]; + [archiver encodeDouble: _location.y forKey: @"location.y"]; + [archiver encodeInt: _mouseButton forKey: @"mouseButton"]; + + if (_eventRecord) + [archiver encodeBytes: (uint8_t*)_eventRecord length: _eventRecordLength forKey: @"eventRecord"]; +} + +-(CGPoint) location +{ + const CGPoint invalid = CGInvalidPoint; + if (_location.x == invalid.x && _location.y == invalid.y) + { + _location = [_CGSConnectionForID(CGSDefaultConnection) mouseLocation]; + } + return _location; +} + +-(void) setLocation:(CGPoint) location +{ + _location = location; +} + @end //////////////////////////////////////////////////////////////// @@ -133,45 +254,59 @@ @synthesize userData = _userData; @synthesize pixelsPerLine = _pixelsPerLine; -- (instancetype) initWithState: (CGEventSourceStateID) stateId { - _stateId = stateId; - return self; +-(instancetype) initWithState: (CGEventSourceStateID) stateId +{ + _pixelsPerLine = 10; + _stateId = stateId; + return self; } -- (CFTypeID) _cfTypeID { - return CGEventSourceGetTypeID(); +-(CFTypeID) _cfTypeID +{ + return CGEventSourceGetTypeID(); +} + ++(CGEventSource*) hidEventSource +{ + static CGEventSource* instance; + static dispatch_once_t once; + + dispatch_once(&once, ^{ + instance = [[CGEventSource alloc] initWithState: kCGEventSourceStateHIDSystemState]; + }); + return instance; } @end //////////////////////////////////////////////////////////////// -static void cgEventTapCallout(CFMachPortRef mp, void *msg, CFIndex size, - void *info) +static void cgEventTapCallout(CFMachPortRef mp, void* msg, CFIndex size, void* info) { - CGEventTap *tap = (CGEventTap *) info; + CGEventTap* tap = (CGEventTap*) info; - struct TapMachMessage *tapMessage = (struct TapMachMessage *) msg; - CGEventRef event = tapMessage->event; + struct TapMachMessage* tapMessage = (struct TapMachMessage*) msg; + CGEventRef event = tapMessage->event; - CGEventType type = CGEventGetType(tapMessage->event); - if (tap.enabled && (CGEventMaskBit(type) & tap.mask) != 0) { - // Invoke callback - CGEventRef returned = - tap.callback(tapMessage->proxy, type, event, tap.userInfo); + CGEventType type = CGEventGetType(tapMessage->event); + if (tap.enabled && (CGEventMaskBit(type) & tap.mask) != 0) + { + // Invoke callback + CGEventRef returned = tap.callback(tapMessage->proxy, type, event, tap.userInfo); - if (!(tap.options & kCGEventTapOptionListenOnly)) - event = returned; - } + if (!(tap.options & kCGEventTapOptionListenOnly)) + event = returned; + } - // Pass the message on - if (event != NULL) { - CGEventTapPostEvent(tapMessage->proxy, event); + // Pass the message on + if (event != NULL) + { + CGEventTapPostEvent(tapMessage->proxy, event); - if (event != tapMessage->event) - CFRelease(event); - } + if (event != tapMessage->event) + CFRelease(event); + } - CFRelease(tapMessage->event); + CFRelease(tapMessage->event); } @implementation CGEventTap @@ -183,55 +318,53 @@ static void cgEventTapCallout(CFMachPortRef mp, void *msg, CFIndex size, @synthesize userInfo = _userInfo; @synthesize enabled = _enabled; -- (instancetype) initWithLocation: (CGEventTapLocation) location - options: (CGEventTapOptions) options - mask: (CGEventMask) mask - callback: (CGEventTapCallBack) callback - userInfo: (void *) userInfo +-(instancetype) initWithLocation: (CGEventTapLocation) location + options: (CGEventTapOptions) options + mask: (CGEventMask) mask + callback: (CGEventTapCallBack) callback + userInfo: (void*) userInfo { - _location = location; - _options = options; - _mask = mask; - _callback = callback; - _userInfo = userInfo; - _enabled = TRUE; + _location = location; + _options = options; + _mask = mask; + _callback = callback; + _userInfo = userInfo; + _enabled = TRUE; - kern_return_t ret = mach_port_allocate(mach_task_self(), - MACH_PORT_RIGHT_RECEIVE, &_machPort); + kern_return_t ret = mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &_machPort); if (KERN_SUCCESS == ret) { - ret = mach_port_insert_right(mach_task_self(), _machPort, _machPort, - MACH_MSG_TYPE_MAKE_SEND); + ret = mach_port_insert_right(mach_task_self(), _machPort, _machPort, MACH_MSG_TYPE_MAKE_SEND); } if (KERN_SUCCESS != ret) { - if (MACH_PORT_NULL != _machPort) - mach_port_destroy(mach_task_self(), _machPort); - [self release]; + if (MACH_PORT_NULL != _machPort) mach_port_destroy(mach_task_self(), _machPort); + [self release]; return nil; } - return self; + return self; } -- (void) dealloc { - _CGEventTapDestroyed(_location, _machPort); - mach_port_destroy(mach_task_self(), _machPort); - [super dealloc]; +-(void) dealloc +{ + _CGEventTapDestroyed(_location, _machPort); + mach_port_destroy(mach_task_self(), _machPort); + [super dealloc]; } -- (CFMachPortRef) createCFMachPort { - CFMachPortRef mp; - CFMachPortContext ctxt = { - .copyDescription = NULL, - .info = self, - .release = CFRelease, - .retain = CFRetain, - .version = 0, - }; +-(CFMachPortRef) createCFMachPort +{ + CFMachPortRef mp; + CFMachPortContext ctxt = { + .copyDescription = NULL, + .info = self, + .release = CFRelease, + .retain = CFRetain, + .version = 0, + }; - mp = CFMachPortCreateWithPort(NULL, _machPort, cgEventTapCallout, &ctxt, - NULL); + mp = CFMachPortCreateWithPort(NULL, _machPort, cgEventTapCallout, &ctxt, NULL); - return mp; + return mp; } @end diff --git a/CoreGraphics/CGEventTap.m b/CoreGraphics/CGEventTap.m index 31e8a4b9..eeb3bda6 100644 --- a/CoreGraphics/CGEventTap.m +++ b/CoreGraphics/CGEventTap.m @@ -17,54 +17,55 @@ along with Darling. If not, see . */ -#import "CGEventObjC.h" -#include "CGEventTapInternal.h" #include +#import "CGEventObjC.h" +#include -void CGEventPost(CGEventTapLocation tap, CGEventRef _Nullable event) { - // TODO: Create an appropriate CGEventTapProxy and call - // CGEventTapPostEvent() -} - -CFMachPortRef CGEventTapCreate(CGEventTapLocation tap, - CGEventTapPlacement place, - CGEventTapOptions options, - CGEventMask eventsOfInterest, - CGEventTapCallBack callback, void *userInfo) +void CGEventPost(CGEventTapLocation tap, CGEventRef _Nullable event) { - CGEventTap *newTap = [[CGEventTap alloc] initWithLocation: tap - options: options - mask: eventsOfInterest - callback: callback - userInfo: userInfo]; - - mach_port_t port = newTap.machPort; - - // TODO: Save this port to tapping structures - - CFMachPortRef mp = [newTap createCFMachPort]; - [newTap release]; // CFMachPortRef now holds a ref - - return mp; + // TODO: Create an appropriate CGEventTapProxy and call CGEventTapPostEvent() + // TODO: Finally, invoke callbacks registered with CGSRegisterNotifyProc() } -void _CGEventTapDestroyed(CGEventTapLocation location, mach_port_t mp) { - // TODO: Deregister the tap -} - -void CGEventTapEnable(CFMachPortRef tap, bool enable) { - mach_port_t mp = CFMachPortGetPort(tap); - - // TODO: Lookup CGEventTap instance by mp - CGEventTap *tapObj = nil; - tapObj.enabled = enable; -} - -void CGEventTapPostEvent(CGEventTapProxy proxy, CGEventRef event) { -} - -CGError CGGetEventTapList(uint32_t maxNumberOfTaps, - CGEventTapInformation *tapList, - uint32_t *eventTapCount) +CFMachPortRef CGEventTapCreate(CGEventTapLocation tap, CGEventTapPlacement place, + CGEventTapOptions options, CGEventMask eventsOfInterest, CGEventTapCallBack callback, void *userInfo) { + CGEventTap* newTap = [[CGEventTap alloc] initWithLocation: tap + options: options + mask: eventsOfInterest + callback: callback + userInfo: userInfo]; + + mach_port_t port = newTap.machPort; + + // TODO: Save this port to tapping structures + + CFMachPortRef mp = [newTap createCFMachPort]; + [newTap release]; // CFMachPortRef now holds a ref + + return mp; +} + +void _CGEventTapDestroyed(CGEventTapLocation location, mach_port_t mp) +{ + // TODO: Deregister the tap +} + +void CGEventTapEnable(CFMachPortRef tap, bool enable) +{ + mach_port_t mp = CFMachPortGetPort(tap); + + // TODO: Lookup CGEventTap instance by mp + CGEventTap* tapObj = nil; + tapObj.enabled = enable; +} + +void CGEventTapPostEvent(CGEventTapProxy proxy, CGEventRef event) +{ + +} + +CGError CGGetEventTapList(uint32_t maxNumberOfTaps, CGEventTapInformation *tapList, uint32_t *eventTapCount) +{ + } diff --git a/CoreGraphics/CGEventTapInternal.h b/CoreGraphics/CGEventTapInternal.h index 613c008f..640fa1f5 100644 --- a/CoreGraphics/CGEventTapInternal.h +++ b/CoreGraphics/CGEventTapInternal.h @@ -18,6 +18,12 @@ */ #ifndef CGEVENTTAP_INTERNAL_H #define CGEVENTTAP_INTERNAL_H +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif extern void _CGEventTapDestroyed(CGEventTapLocation loc, mach_port_t mp); @@ -27,4 +33,8 @@ struct TapMachMessage { CGEventRef event; }; +#ifdef __cplusplus +} +#endif + #endif diff --git a/CoreGraphics/CGS.m b/CoreGraphics/CGS.m index 89402cf3..813e44eb 100644 --- a/CoreGraphics/CGS.m +++ b/CoreGraphics/CGS.m @@ -16,15 +16,16 @@ You should have received a copy of the GNU General Public License along with Darling. If not, see . */ -#import -#import -#import #include #import #include #include +#import +#import +#import +#include -static NSMutableDictionary *g_connections = nil; +static NSMutableDictionary* g_connections = nil; static Boolean g_denyConnections = FALSE; static CGSConnectionID g_defaultConnection = -1; @@ -33,158 +34,374 @@ static pthread_mutex_t g_defaultConnectionMutex = PTHREAD_MUTEX_INITIALIZER; static _Atomic CGSConnectionID g_nextConnectionID = 1; static Class g_backendClass = nil; -CGError CGSSetDenyWindowServerConnections(Boolean deny) { - // TODO: Instruct our platform abstraction about this - // TODO: Return failure if there's an existing connection - return kCGErrorSuccess; -} +__attribute__((visibility("hidden"))) CFMutableArrayRef g_cgsNotifyProc; +__attribute__((visibility("hidden"))) pthread_mutex_t g_cgsNotifyProcMutex = PTHREAD_MUTEX_INITIALIZER; -void CGSShutdownServerConnections(void) { - // TODO -} - -CGError CGSNewWindow(CGSConnectionID conn, CFIndex flags, float x_offset, - float y_offset, const CGSRegionRef region, - CGSWindowID *windowID) +typedef struct { - CGSConnection *c = _CGSConnectionForID(conn); - if (!c) - return kCGErrorInvalidConnection; + CGSNotifyProcPtr proc; + CGSNotificationType notificationType; + void* private; +} NotifyProcEntry; - CGSWindow *window = [c newWindow: region]; - if (!window) - return kCGErrorIllegalArgument; - - *windowID = window.windowId; - return kCGSErrorSuccess; -} - -CGError CGSReleaseWindow(CGSConnectionID cid, CGSWindowID wid) { - CGSConnection *c = _CGSConnectionForID(cid); - if (!c) - return kCGErrorInvalidConnection; - return [c destroyWindow: wid]; -} - -CGError CGSSetWindowShape(CGSConnectionID cid, CGSWindowID wid, float x_offset, - float y_offset, const CGSRegionRef shape) +CGError CGSSetDenyWindowServerConnections(Boolean deny) { - CGSWindow *window; - CGError err = getWindow(cid, wid, &window); + NSUInteger connectionCount; + @synchronized(g_connections) + { + connectionCount = g_connections.count; + } - if (err != kCGSErrorSuccess) - return err; + if (deny && connectionCount > 0) + { + return kCGErrorFailure; + } - return [window setRegion: shape]; + g_denyConnections = deny; + return kCGSErrorSuccess; } -OSStatus CGSOrderWindow(CGSConnectionID cid, CGSWindowID wid, - CGSWindowOrderingMode place, - CGSWindowID relativeToWindow) +void CGSShutdownServerConnections(void) { - CGSConnection *c = _CGSConnectionForID(cid); - if (!c) - return kCGErrorInvalidConnection; - - CGSWindow *window = [c windowForId: wid]; - if (!window) - return kCGErrorIllegalArgument; - - CGSWindow *relativeTo = [c windowForId: relativeToWindow]; - return [window orderWindow: place relativeTo: relativeTo]; + @synchronized(g_connections) + { + [g_connections removeAllObjects]; + } + g_defaultConnection = -1; } -CGError CGSMoveWindow(CGSConnectionID cid, CGSWindowID wid, - const CGPoint *window_pos) +__attribute__((constructor)) +void CGSInitialize(void) { - CGSWindow *window; - CGError err = getWindow(cid, wid, &window); - - if (err != kCGSErrorSuccess) - return err; - - return [window moveTo: window_pos]; + static dispatch_once_t once; + dispatch_once(&once, ^{ + g_connections = [[NSMutableDictionary alloc] initWithCapacity: 1]; + }); } -extern CGError CGSSetWindowOpacity(CGSConnectionID cid, CGSWindowID wid, - bool isOpaque); -extern CGError CGSSetWindowAlpha(CGSConnectionID cid, CGSWindowID wid, - float alpha); -extern CGError CGSSetWindowLevel(CGSConnectionID cid, CGSWindowID wid, - CGWindowLevel level); - -CGError CGSGetWindowProperty(CGSConnectionID cid, CGSWindowID wid, - CFStringRef key, CFTypeRef *outValue) +static void _CGSLoadBackend(void) { - CGSWindow *window; - CGError err = getWindow(cid, wid, &window); + NSBundle* cgBundle = [NSBundle bundleForClass: [CGSConnection class]]; + NSMutableArray* backends = [NSMutableArray new]; - if (err != kCGSErrorSuccess) - return err; + for (NSString *path in [cgBundle pathsForResourcesOfType: @"backend" inDirectory: @"Backends"]) + { + NSBundle* backendBundle = [NSBundle bundleWithPath: path]; + if ([backendBundle load]) + [backends addObject: backendBundle]; + } - return [window getProperty: key value: outValue]; + // Sort them according to the NSPriority key in their Info.plist files. + [backends sortUsingComparator: ^(NSBundle *b1, NSBundle *b2) { + NSNumber *p1 = [b1 objectForInfoDictionaryKey: @"NSPriority"]; + NSNumber *p2 = [b2 objectForInfoDictionaryKey: @"NSPriority"]; + return [p2 compare: p1]; + }]; + + // Try to instantiate them in that order. + for (NSBundle *backendBundle in backends) + { + Class cls = [backendBundle principalClass]; + if ([cls isAvailable]) + { + g_backendClass = cls; + break; + } + } + [backends release]; } -CGError CGSSetWindowProperty(CGSConnectionID cid, CGSWindowID wid, - CFStringRef key, CFTypeRef value) +CGError CGSNewConnection(CGSDictionaryObj attribs, CGSConnectionID* connId) { - CGSWindow *window; - CGError err = getWindow(cid, wid, &window); + *connId = -1; - if (err != kCGSErrorSuccess) - return err; + if (g_denyConnections) + return kCGErrorCannotComplete; - return [window setProperty: key value: value]; + static dispatch_once_t once; + dispatch_once(&once, ^{ + _CGSLoadBackend(); + }); + + if (!g_backendClass) + return kCGErrorCannotComplete; + + CGSConnectionID newConnID = g_nextConnectionID++; + CGSConnection* conn = [[g_backendClass alloc] initWithConnectionID: newConnID]; + + if (conn != nil) + { + *connId = newConnID; + @synchronized(g_connections) + { + [g_connections setObject: conn forKey: [NSNumber numberWithInt: newConnID]]; + } + [conn release]; + return kCGSErrorSuccess; + } + else + return kCGErrorFailure; } -CGError getSurface(CGSConnectionID cid, CGSWindowID wid, CGSSurfaceID sid, - CGSSurface **surface) +CGSConnection* _CGSConnectionForID(CGSConnectionID connId) { - CGSWindow *window; - - CGError err = getWindow(cid, wid, &window); - if (err != kCGSErrorSuccess) - return err; - - *surface = [window surfaceForId: sid]; - return (*surface) ? kCGSErrorSuccess : kCGErrorIllegalArgument; + @synchronized(g_connections) + { + return [g_connections objectForKey:[NSNumber numberWithInt: connId]]; + } } -CGError CGSAddSurface(CGSConnectionID cid, CGSWindowID wid, CGSSurfaceID *sid) { - CGSWindow *window; +void* _CGSNativeDisplay(CGSConnectionID connId) +{ + return [_CGSConnectionForID(connId) nativeDisplay]; +} - CGError err = getWindow(cid, wid, &window); - if (err != kCGSErrorSuccess) - return err; +void* _CGSNativeWindowForID(CGSConnectionID connId, CGSWindowID winId) +{ + CGSConnection* conn = _CGSConnectionForID(connId); + return [[conn windowForId: winId] nativeWindow]; +} - CGSSurface *surface = [window createSurface]; - if (!surface) - return kCGErrorFailure; +void* _CGSNativeWindowForSurfaceID(CGSConnectionID connId, CGSWindowID winId, CGSSurfaceID surfaceId) +{ + CGSConnection* conn = _CGSConnectionForID(connId); + return [[[conn windowForId: winId] surfaceForId: surfaceId] nativeWindow]; +} - *sid = surface.surfaceId; - return kCGSErrorSuccess; +CGError CGSReleaseConnection(CGSConnectionID connId) +{ + NSNumber* num = [NSNumber numberWithInt:connId]; + + @synchronized(g_connections) + { + if (![g_connections objectForKey: num]) + return kCGErrorInvalidConnection; + [g_connections removeObjectForKey: num]; + } + return kCGSErrorSuccess; +} + +CGSConnectionID _CGSDefaultConnection(void) +{ + return CGSMainConnectionID(); +} + +CGSConnectionID CGSMainConnectionID(void) +{ + if (g_defaultConnection == -1) + { + pthread_mutex_lock(&g_defaultConnectionMutex); + if (g_defaultConnection == -1) + CGSNewConnection(NULL, &g_defaultConnection); + pthread_mutex_unlock(&g_defaultConnectionMutex); + } + return g_defaultConnection; +} + +static CGError getWindow(CGSConnectionID cid, CGSWindowID wid, CGSWindow** out) +{ + CGSConnection* c = _CGSConnectionForID(cid); + if (!c) + return kCGErrorInvalidConnection; + + CGSWindow* window = [c windowForId: wid]; + if (!window) + return kCGErrorIllegalArgument; + + *out = window; + return kCGSErrorSuccess; +} + +CGError CGSNewWindow(CGSConnectionID conn, CFIndex flags, float x_offset, float y_offset, const CGSRegionRef region, CGSWindowID* windowID) +{ + CGSConnection* c = _CGSConnectionForID(conn); + if (!c) + return kCGErrorInvalidConnection; + + CGSWindow* window = [c newWindow: region]; + if (!window) + return kCGErrorIllegalArgument; + + *windowID = window.windowId; + return kCGSErrorSuccess; +} + +CGError CGSReleaseWindow(CGSConnectionID cid, CGSWindowID wid) +{ + CGSConnection* c = _CGSConnectionForID(cid); + if (!c) + return kCGErrorInvalidConnection; + return [c destroyWindow: wid]; +} + +CGError CGSSetWindowShape(CGSConnectionID cid, CGSWindowID wid, float x_offset, float y_offset, const CGSRegionRef shape) +{ + CGSWindow* window; + CGError err = getWindow(cid, wid, &window); + + if (err != kCGSErrorSuccess) + return err; + + return [window setRegion: shape]; +} + +OSStatus CGSOrderWindow(CGSConnectionID cid, CGSWindowID wid, CGSWindowOrderingMode place, CGSWindowID relativeToWindow) +{ + CGSConnection* c = _CGSConnectionForID(cid); + if (!c) + return kCGErrorInvalidConnection; + + CGSWindow* window = [c windowForId: wid]; + if (!window) + return kCGErrorIllegalArgument; + + CGSWindow* relativeTo = [c windowForId: relativeToWindow]; + return [window orderWindow: place relativeTo: relativeTo]; +} + +CGError CGSMoveWindow(CGSConnectionID cid, CGSWindowID wid, const CGPoint *window_pos) +{ + CGSWindow* window; + CGError err = getWindow(cid, wid, &window); + + if (err != kCGSErrorSuccess) + return err; + + return [window moveTo: window_pos]; +} + +extern CGError CGSSetWindowOpacity(CGSConnectionID cid, CGSWindowID wid, bool isOpaque); +extern CGError CGSSetWindowAlpha(CGSConnectionID cid, CGSWindowID wid, float alpha); +extern CGError CGSSetWindowLevel(CGSConnectionID cid, CGSWindowID wid, CGWindowLevel level); + +CGError CGSGetWindowProperty(CGSConnectionID cid, CGSWindowID wid, CFStringRef key, CFTypeRef *outValue) +{ + CGSWindow* window; + CGError err = getWindow(cid, wid, &window); + + if (err != kCGSErrorSuccess) + return err; + + return [window getProperty: key value: outValue]; +} + +CGError CGSSetWindowProperty(CGSConnectionID cid, CGSWindowID wid, CFStringRef key, CFTypeRef value) +{ + CGSWindow* window; + CGError err = getWindow(cid, wid, &window); + + if (err != kCGSErrorSuccess) + return err; + + return [window setProperty: key value: value]; +} + +CGError getSurface(CGSConnectionID cid, CGSWindowID wid, CGSSurfaceID sid, CGSSurface** surface) +{ + CGSWindow* window; + + CGError err = getWindow(cid, wid, &window); + if (err != kCGSErrorSuccess) + return err; + + *surface = [window surfaceForId: sid]; + return (*surface) ? kCGSErrorSuccess : kCGErrorIllegalArgument; +} + +CGError CGSAddSurface(CGSConnectionID cid, CGSWindowID wid, CGSSurfaceID *sid) +{ + CGSWindow* window; + + CGError err = getWindow(cid, wid, &window); + if (err != kCGSErrorSuccess) + return err; + + CGSSurface* surface = [window createSurface]; + if (!surface) + return kCGErrorFailure; + + *sid = surface.surfaceId; + return kCGSErrorSuccess; } CGError CGSRemoveSurface(CGSConnectionID cid, CGSWindowID wid, CGSSurfaceID sid) { - CGSSurface *surface; + CGSSurface* surface; - CGError err = getSurface(cid, wid, sid, &surface); - if (err != kCGSErrorSuccess) - return err; + CGError err = getSurface(cid, wid, sid, &surface); + if (err != kCGSErrorSuccess) + return err; - [surface invalidate]; - return kCGSErrorSuccess; + [surface invalidate]; + return kCGSErrorSuccess; } -CGError CGSSetSurfaceBounds(CGSConnectionID cid, CGSWindowID wid, - CGSSurfaceID sid, CGRect rect) +CGError CGSSetSurfaceBounds(CGSConnectionID cid, CGSWindowID wid, CGSSurfaceID sid, CGRect rect) { - CGSSurface *surface; + CGSSurface* surface; - CGError err = getSurface(cid, wid, sid, &surface); - if (err != kCGSErrorSuccess) - return err; + CGError err = getSurface(cid, wid, sid, &surface); + if (err != kCGSErrorSuccess) + return err; - return [surface setBounds: rect]; + return [surface setBounds: rect]; +} + +CGSConnection* _CGSConnectionFromEventRecord(const CGSEventRecordPtr record) +{ + if (!record) + return nil; + return _CGSConnectionForID(record->connection); +} + +static void simplyFree(CFAllocatorRef allocator, const void* mem) +{ + free((void*) mem); +} + +CGError CGSRegisterNotifyProc(CGSNotifyProcPtr proc, CGSNotificationType notificationType, void* private) +{ + static dispatch_once_t once; + + dispatch_once(&once, ^{ + CFArrayCallBacks cb = { + .release = simplyFree, + .version = 0, + }; + g_cgsNotifyProc = CFArrayCreateMutable(NULL, 0, &cb); + }); + + NotifyProcEntry* e = (NotifyProcEntry*) malloc(sizeof(NotifyProcEntry)); + e->proc = proc; + e->notificationType = notificationType; + e->private = private; + + pthread_mutex_lock(&g_cgsNotifyProcMutex); + CFArrayAppendValue(g_cgsNotifyProc, e); + pthread_mutex_unlock(&g_cgsNotifyProcMutex); + + return kCGSErrorSuccess; +} + +CGError CGSRemoveNotifyProc(CGSNotifyProcPtr proc, CGSNotificationType notificationType) +{ + if (!g_cgsNotifyProc) + return kCGSErrorSuccess; + + pthread_mutex_lock(&g_cgsNotifyProcMutex); + + // This code is not too efficient, but it is called so rarely (if ever), it doesn't matter. + for (CFIndex i = 0; i < CFArrayGetCount(g_cgsNotifyProc); i++) + { + NotifyProcEntry* e = (NotifyProcEntry*) CFArrayGetValueAtIndex(g_cgsNotifyProc, i); + if (e->proc == proc && e->notificationType == notificationType) + { + CFArrayRemoveValueAtIndex(g_cgsNotifyProc, i); + break; + } + } + + pthread_mutex_unlock(&g_cgsNotifyProcMutex); + + return kCGSErrorSuccess; } diff --git a/CoreGraphics/CGSConnection.m b/CoreGraphics/CGSConnection.m index 0b9604db..99826d19 100644 --- a/CoreGraphics/CGSConnection.m +++ b/CoreGraphics/CGSConnection.m @@ -17,61 +17,95 @@ along with Darling. If not, see . */ #import -#import #import +#import #import #import #import @implementation CGSConnection -- (instancetype) initWithConnectionID: (CGSConnectionID) connId { - _nextWindowId = 1; - _connectionId = connId; - _windows = [[NSMutableDictionary alloc] initWithCapacity: 1]; - return self; +-(instancetype) initWithConnectionID:(CGSConnectionID)connId +{ + _nextWindowId = 1; + _connectionId = connId; + _windows = [[NSMutableDictionary alloc] initWithCapacity: 1]; + return self; } -- (CGSWindow *) windowForId: (CGSWindowID) winId { - CGSWindow *rv; - @synchronized(_windows) { - rv = [_windows objectForKey: [NSNumber numberWithInt: winId]]; - } - return rv; +-(CGSWindow*) windowForId:(CGSWindowID)winId +{ + @synchronized(_windows) + { + return [_windows objectForKey: [NSNumber numberWithInt: winId]]; + } } -- (void) _windowInvalidated: (CGSWindowID) winId { - @synchronized(_windows) { - [_windows removeObjectForKey: [NSNumber numberWithInt: winId]]; - } +-(void) _windowInvalidated: (CGSWindowID) winId +{ + @synchronized(_windows) + { + [_windows removeObjectForKey: [NSNumber numberWithInt: winId]]; + } } -- (void) dealloc { - [_windows release]; - [super dealloc]; +-(void) dealloc +{ + [_windows release]; + [super dealloc]; } -+ (BOOL) isAvailable { - NSInvalidAbstractInvocation(); ++(BOOL) isAvailable +{ + NSInvalidAbstractInvocation(); } -- (CGSWindow *) newWindow: (CGSRegionRef) region { - NSInvalidAbstractInvocation(); +-(CGSKeyboardLayout*) createKeyboardLayout +{ + NSInvalidAbstractInvocation(); } -- (void *) nativeDisplay { - NSInvalidAbstractInvocation(); +-(CGPoint) mouseLocation +{ + NSInvalidAbstractInvocation(); } -- (CGError) destroyWindow: (CGSWindowID) winId { - CGSWindow *win = [self windowForId: winId]; - if (win == nil) - return kCGErrorIllegalArgument; - [win invalidate]; +-(NSArray *) modesForScreen:(int)screenIndex +{ + NSInvalidAbstractInvocation(); +} - @synchronized(_windows) { - [_windows removeObjectForKey: [NSNumber numberWithInt: winId]]; - } - return kCGSErrorSuccess; +-(BOOL) setMode:(NSDictionary *)mode forScreen:(int)screenIndex +{ + NSInvalidAbstractInvocation(); +} + +-(NSDictionary*) currentModeForScreen:(int)screenIndex +{ + NSInvalidAbstractInvocation(); +} + +-(CGSWindow*) newWindow:(CGSRegionRef)region +{ + NSInvalidAbstractInvocation(); +} + +-(void*) nativeDisplay +{ + NSInvalidAbstractInvocation(); +} + +-(CGError) destroyWindow:(CGSWindowID)winId +{ + CGSWindow* win = [self windowForId: winId]; + if (win == nil) + return kCGErrorIllegalArgument; + [win invalidate]; + + @synchronized (_windows) + { + [_windows removeObjectForKey: [NSNumber numberWithInt: winId]]; + } + return kCGSErrorSuccess; } @end diff --git a/CoreGraphics/CGSKeyboardLayout.m b/CoreGraphics/CGSKeyboardLayout.m new file mode 100644 index 00000000..4bb9d660 --- /dev/null +++ b/CoreGraphics/CGSKeyboardLayout.m @@ -0,0 +1,43 @@ +/* + This file is part of Darling. + + Copyright (C) 2020 Lubos Dolezel + + Darling is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Darling is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Darling. If not, see . +*/ +#import + +@implementation CGSKeyboardLayout +@synthesize name = _name; +@synthesize fullName = _fullName; +@synthesize layout = _layout; +@synthesize layoutLength = _layoutLength; + +-(void) dealloc +{ + [_name release]; + [_fullName release]; + free(_layout); + [super dealloc]; +} + +-(void) setLayout:(UCKeyboardLayout*) layout length:(uint32_t) length +{ + free(_layout); + _layout = (UCKeyboardLayout*) malloc(length); + memcpy(_layout, layout, length); + _layoutLength = length; +} +@end + diff --git a/CoreGraphics/CGSScreen.m b/CoreGraphics/CGSScreen.m new file mode 100644 index 00000000..682c1023 --- /dev/null +++ b/CoreGraphics/CGSScreen.m @@ -0,0 +1,46 @@ +/* + This file is part of Darling. + + Copyright (C) 2020 Lubos Dolezel + + Darling is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Darling is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Darling. If not, see . +*/ + +#import + +@implementation CGSScreen +@synthesize edid = _edid; +@synthesize modes = _modes; +@synthesize currentMode = _currentMode; + +-(void) dealloc +{ + [_edid release]; + [_modes release]; + [super dealloc]; +} + +-(uint32_t) currentModeHeight +{ + if (!_currentModeHeightCached) + { + if (_currentMode < 0 || _currentMode >= [_modes count]) + return 0; + NSNumber* height = (NSNumber*) _modes[_currentMode][@"Height"]; + _currentModeHeightCached = height.intValue; + } + return _currentModeHeightCached; +} +@end + diff --git a/CoreGraphics/CMakeLists.txt b/CoreGraphics/CMakeLists.txt index 95922f0f..3c90a15a 100644 --- a/CoreGraphics/CMakeLists.txt +++ b/CoreGraphics/CMakeLists.txt @@ -105,7 +105,9 @@ set(CoreGraphics_sources CGSConnection.m CGSWindow.m CGSSurface.m + CGSKeyboardLayout.m CGSRegion.m + CGSScreen.m CGEvent.m CGEventSource.m CGEventTap.m @@ -133,3 +135,5 @@ add_framework(CoreGraphics GL IOKit ) + +add_subdirectory(X11.backend) diff --git a/CoreGraphics/X11.backend/CGSConnectionX11.h b/CoreGraphics/X11.backend/CGSConnectionX11.h new file mode 100644 index 00000000..5437acb5 --- /dev/null +++ b/CoreGraphics/X11.backend/CGSConnectionX11.h @@ -0,0 +1,57 @@ +/* + This file is part of Darling. + + Copyright (C) 2020 Lubos Dolezel + + Darling is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Darling is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Darling. If not, see . +*/ + +#ifndef CGSCONNECTIONX11_H +#define CGSCONNECTIONX11_H +#import +#import +#import +#import + +@interface CGSConnectionX11 : CGSConnection { + Display *_display; + // We use CFRunLoop directly, without going through any Foundation wrapper, + // because Apple's Cocoa has none. Unlike Apple's Cocoa, we need to watch + // over a Unix domain socket, not a Mach port. + CFSocketRef _cfSocket; + CFRunLoopSourceRef _source; + + // NOTE: A CGSScreen refers to a 'crtc' in X11 paralance, and *not* to an X11 screen. + // In other words, it refers to a physical monitor. + NSArray* _screens; + + CGSKeyboardLayout* _keyboardLayout; + int _keyboardLayoutGroup; + + int _xkbEventBase; + int _xrrEventBase; +} + +-(instancetype) initWithConnectionID:(CGSConnectionID)connId; +-(void) dealloc; +-(CGSWindow*) newWindow:(CGSRegionRef)region; + +-(void) processPendingEvents; + ++(BOOL) isAvailable; + +@end + +#endif + diff --git a/CoreGraphics/X11.backend/CGSConnectionX11.m b/CoreGraphics/X11.backend/CGSConnectionX11.m new file mode 100644 index 00000000..7af8bd93 --- /dev/null +++ b/CoreGraphics/X11.backend/CGSConnectionX11.m @@ -0,0 +1,381 @@ +/* + This file is part of Darling. + + Copyright (C) 2020 Lubos Dolezel + + Darling is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Darling is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Darling. If not, see . +*/ +#import "CGSConnectionX11.h" +#import +#include "CarbonKeys.h" +#import "X11KeySymToUCS.h" +#import +#import +#include +#include +#import +#import +#import +#import + +// TODO: Use XInput2: +// https://stackoverflow.com/questions/44095001/getting-double-rawkeypress-events-using-xinput2 +// https://github.com/openbsd/xenocara/blob/master/app/xinput/src/test_xi2.c + +@implementation CGSConnectionX11 + +static int errorHandler(Display* display, XErrorEvent* errorEvent) +{ + NSLog(@"************** X11 ERROR!"); + NSLog(@"Request code: %d:%d", errorEvent->request_code, errorEvent->minor_code); + NSLog(@"Error code: %d", errorEvent->error_code); + return 0; +} + +static void socketCallback(CFSocketRef s, CFSocketCallBackType type, CFDataRef address, + const void *data, void *info) +{ + CGSConnectionX11* self = (CGSConnectionX11*) info; + [self processPendingEvents]; +} + +-(instancetype) initWithConnectionID:(CGSConnectionID)connId +{ + _display = XOpenDisplay(NULL); + if (!_display) + _display = XOpenDisplay(":0"); + + if (!_display) + { + NSLog(@"CGSConnectionX11: XOpenDisplay() failed\n"); + + [self release]; + return nil; + } + self = [super initWithConnectionID: connId]; + + if (NSDebugEnabled) + XSynchronize(_display, True); + + XSetErrorHandler(errorHandler); + + int fd = ConnectionNumber(_display); + + // There's no need to retain/release the display, + // because the display is guaranteed to outlive + // the socket. + CFSocketContext context = { + .version = 0, + .info = self, + .retain = NULL, + .release = NULL, + .copyDescription = NULL + }; + + _cfSocket = CFSocketCreateWithNative(kCFAllocatorDefault, fd, kCFSocketReadCallBack, socketCallback, &context); + _source = CFSocketCreateRunLoopSource(kCFAllocatorDefault, _cfSocket, 0); + CFRunLoopAddSource(CFRunLoopGetMain(), _source, kCFRunLoopCommonModes); + + int errorBase; + if (XRRQueryExtension(_display, &_xrrEventBase, &errorBase)) + { + // Sign up for XRandR events + // TODO: Do we need all these? + XRRSelectInput(_display, DefaultRootWindow(_display), RRScreenChangeNotifyMask | RROutputChangeNotifyMask | RRCrtcChangeNotifyMask); + } + + int major = XkbMajorVersion, minor = XkbMinorVersion; + + if (XkbLibraryVersion(&major, &minor) && XkbQueryExtension(_display, NULL, &_xkbEventBase, &major, &minor, NULL)) + { + XkbSelectEvents(_display, XkbUseCoreKbd, /*XkbMapNotifyMask |*/ XkbStateNotifyMask, 1); + } + + return self; +} + +-(void) dealloc +{ + if (_display) + XCloseDisplay(_display); + + CFRunLoopRemoveSource(CFRunLoopGetMain(), _source, kCFRunLoopCommonModes); + + if (_source != NULL) + CFRelease(_source); + if (_cfSocket != NULL) + CFRelease(_cfSocket); + + [_keyboardLayout release]; + + [super dealloc]; +} + +-(CGSKeyboardLayout*) createKeyboardLayout +{ + @synchronized (self) + { + if (!_keyboardLayout) + [self _doCreateKeyboardLayout]; + return [_keyboardLayout retain]; + } +} + +- (void) _doCreateKeyboardLayout +{ + int major = XkbMajorVersion, minor = XkbMinorVersion; + XkbDescPtr pKBDesc; + unsigned char group = 0; + XkbStateRec state; + + struct MyLayout + { + UCKeyboardLayout layout; + UCKeyModifiersToTableNum modifierVariants; + UInt8 secondTableNum, thirdTableNum; + UCKeyToCharTableIndex tableIndex; + UInt32 secontTableOffset; + UCKeyOutput table1[128]; + UCKeyOutput table2[128]; + }; + + if (!XkbLibraryVersion(&major, &minor)) + return; + if (!XkbQueryExtension(_display, NULL, NULL, &major, &minor, NULL)) + return; + + pKBDesc = XkbGetMap(_display, XkbAllClientInfoMask, XkbUseCoreKbd); + if (!pKBDesc) + return; + + XkbDescPtr desc = XkbGetKeyboard(_display, XkbAllComponentsMask, XkbUseCoreKbd); + if (!desc) + return; + + if (XkbGetState(_display, XkbUseCoreKbd, &state) == Success) + group = state.group; + + struct MyLayout* layout = (struct MyLayout*) malloc(sizeof(struct MyLayout)); + + layout->layout.keyLayoutHeaderFormat = kUCKeyLayoutHeaderFormat; + layout->layout.keyLayoutDataVersion = 0; + layout->layout.keyLayoutFeatureInfoOffset = 0; + layout->layout.keyboardTypeCount = 1; + + memset(layout->layout.keyboardTypeList, 0, sizeof(UCKeyboardTypeHeader)); + + layout->layout.keyboardTypeList[0].keyModifiersToTableNumOffset = offsetof(struct MyLayout, modifierVariants); + layout->layout.keyboardTypeList[0].keyToCharTableIndexOffset = offsetof(struct MyLayout, tableIndex); + + layout->modifierVariants.keyModifiersToTableNumFormat = kUCKeyModifiersToTableNumFormat; + layout->modifierVariants.defaultTableNum = 0; + layout->modifierVariants.modifiersCount = 3; + layout->modifierVariants.tableNum[0] = 0; + layout->modifierVariants.tableNum[1] = 0; // cmd key bit + layout->modifierVariants.tableNum[2] = 1; // shift key bit + + layout->tableIndex.keyToCharTableIndexFormat = kUCKeyToCharTableIndexFormat; + layout->tableIndex.keyToCharTableSize = 128; + layout->tableIndex.keyToCharTableCount = 2; + layout->tableIndex.keyToCharTableOffsets[0] = offsetof(struct MyLayout, table1); + layout->tableIndex.keyToCharTableOffsets[1] = offsetof(struct MyLayout, table2); + + for (int shift = 0; shift <= 1; shift++) + { + UCKeyOutput* outTable = (shift == 0) ? layout->table1 : layout->table2; + for (int i = 0; i < 128; i++) + { + // Reverse the operation we do in -postXEvent: + const int x11KeyCode = carbonToX11[i]; + + if (!x11KeyCode) + { + outTable[i] = 0; + continue; + } + + // NOTE: Not using the group here. It just works with 0 instead... + KeySym sym = XkbKeycodeToKeysym(_display, x11KeyCode, 0, shift); + + if (sym != NoSymbol) + outTable[i] = X11KeySymToUCS(sym); + else + outTable[i] = 0; + } + } + + XkbFreeClientMap(pKBDesc, XkbAllClientInfoMask, true); + NSString *name = @"?", *fullName = @"?"; + + if (fullName != NULL) + { + char *group = XGetAtomName(_display, desc->names->groups[state.group]); + + if (group != NULL) + { + fullName = [NSString stringWithUTF8String: group]; + XFree(group); + } + } + + XkbRF_VarDefsRec vd; + if (name != NULL && XkbRF_GetNamesProp(_display, NULL, &vd)) + { + char* saveptr; + char *tok = strtok_r(vd.layout, ",", &saveptr); + + for (int i = 0; i < state.group; i++) + { + tok = strtok_r(NULL, ",", &saveptr); + if (tok == NULL) + break; + } + + if (tok != NULL) + { + name = [NSString stringWithUTF8String: tok]; + } + } + + CGSKeyboardLayout* cgsLayout = [CGSKeyboardLayout new]; + + [cgsLayout setLayout: &layout->layout length: sizeof(struct MyLayout)]; + cgsLayout.name = name; + cgsLayout.fullName = fullName; + + _keyboardLayout = cgsLayout; + _keyboardLayoutGroup = state.group; +} + +-(CGPoint) mouseLocation +{ + Window child, root = DefaultRootWindow(_display); + + int root_x, root_y; + int win_x, win_y; + unsigned int mask; + + XQueryPointer(_display, root, &root, &child, &root_x, &root_y, &win_x, &win_y, &mask); + return CGPointMake(root_x, root_y); +} + +-(void) processXEvent:(XEvent*) event +{ + switch (event->type) + { + case KeyPress: + case KeyRelease: + break; + case ButtonPress: + break; + case ButtonRelease: + break; + case MotionNotify: + break; + case EnterNotify: + break; + case FocusIn: + break; + case FocusOut: + break; + case KeymapNotify: + break; + case Expose: + break; + case ConfigureNotify: + break; + case ClientMessage: + { + static Atom wmDeleteWindowAtom; + if (!wmDeleteWindowAtom) + wmDeleteWindowAtom = XInternAtom(_display, "WM_DELETE_WINDOW", False); + + if (event->xclient.format == 32 && event->xclient.data.l[0] == wmDeleteWindowAtom) + ; // platformWindowWillClose + break; + } + default: + + if (/*event->type == _xkbEventBase + XkbMapNotify ||*/ event->type == _xkbEventBase + XkbStateNotify) + { + XkbEvent* xkbevt = (XkbEvent*) event; + // Invalidate cached keyboard layout information + if (_keyboardLayout && _keyboardLayoutGroup != xkbevt->state.group) + { + // TODO: Emit kTISNotifySelectedKeyboardInputSourceChanged via NSDistributedNotificationCenter + + @synchronized (self) + { + [_keyboardLayout release]; + _keyboardLayout = nil; + } + _keyboardLayoutGroup = xkbevt->state.group; + } + + break; + } + else if (event->type == _xrrEventBase + RRScreenChangeNotify || event->type == _xrrEventBase + RRNotify) + { + // Invalidate cached information + if (_screens) + { + @synchronized (self) + { + [_screens release]; + _screens = nil; + } + } + } + } +} + +-(void) processPendingEvents +{ + while (XPending(_display) > 0) + { + XEvent event; + + if (XNextEvent(_display, &event) == Success) + [self processXEvent: &event]; + } +} + +-(void) _doGetScreenInformation +{ + +} + +-(NSArray*) createScreens +{ + @synchronized (self) + { + if (!_screens) + [self _doGetScreenInformation]; + return [_screens retain]; + } +} + +-(CGSWindow*) newWindow:(CGSRegionRef)region +{ + +} + ++(BOOL) isAvailable +{ + if (getenv("DISPLAY") != NULL) + return YES; + // TODO: we could be a little smarter here + return NO; +} +@end diff --git a/CoreGraphics/X11.backend/CGSSurfaceX11.h b/CoreGraphics/X11.backend/CGSSurfaceX11.h new file mode 100644 index 00000000..33bcd718 --- /dev/null +++ b/CoreGraphics/X11.backend/CGSSurfaceX11.h @@ -0,0 +1,28 @@ +/* + This file is part of Darling. + + Copyright (C) 2020 Lubos Dolezel + + Darling is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Darling is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Darling. If not, see . +*/ +#ifndef CGSSURFACEX11_H +#define CGSSURFACEX11_H + +#import + +@interface CGSSurfaceX11 : CGSSurface +@end + +#endif + diff --git a/CoreGraphics/X11.backend/CGSSurfaceX11.m b/CoreGraphics/X11.backend/CGSSurfaceX11.m new file mode 100644 index 00000000..94b9de80 --- /dev/null +++ b/CoreGraphics/X11.backend/CGSSurfaceX11.m @@ -0,0 +1,19 @@ +/* + This file is part of Darling. + + Copyright (C) 2020 Lubos Dolezel + + Darling is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Darling is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Darling. If not, see . +*/ +#import "CGSSurfaceX11.h" diff --git a/CoreGraphics/X11.backend/CGSWindowX11.h b/CoreGraphics/X11.backend/CGSWindowX11.h new file mode 100644 index 00000000..00004ddb --- /dev/null +++ b/CoreGraphics/X11.backend/CGSWindowX11.h @@ -0,0 +1,28 @@ +/* + This file is part of Darling. + + Copyright (C) 2020 Lubos Dolezel + + Darling is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Darling is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Darling. If not, see . +*/ +#ifndef CGSWINDOWX11_H +#define CGSWINDOWX11_H + +#import + +@interface CGSWindowX11 : CGSWindow +@end + +#endif + diff --git a/CoreGraphics/X11.backend/CGSWindowX11.m b/CoreGraphics/X11.backend/CGSWindowX11.m new file mode 100644 index 00000000..8d7c9573 --- /dev/null +++ b/CoreGraphics/X11.backend/CGSWindowX11.m @@ -0,0 +1,20 @@ +/* + This file is part of Darling. + + Copyright (C) 2020 Lubos Dolezel + + Darling is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Darling is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Darling. If not, see . +*/ +#import "CGSWindowX11.h" + diff --git a/CoreGraphics/X11.backend/CMakeLists.txt b/CoreGraphics/X11.backend/CMakeLists.txt new file mode 100644 index 00000000..b4992928 --- /dev/null +++ b/CoreGraphics/X11.backend/CMakeLists.txt @@ -0,0 +1,55 @@ +function(add_backend name) + cmake_parse_arguments(BACKEND "" "INFO_PLIST" "SOURCES;DEPENDENCIES;RESOURCES" ${ARGN}) + set(path "/System/Library/Frameworks/CoreGraphics.framework/Versions/C/Resources/Backends/${name}.backend/Contents") + set(DYLIB_INSTALL_NAME "${path}/MacOS/${name}") + + add_darling_library(${name}_cgbackend SHARED ${BACKEND_SOURCES}) + set_target_properties(${name}_cgbackend PROPERTIES OUTPUT_NAME "${name}" SUFFIX "" PREFIX "") + make_fat(${name}_cgbackend) + + if (BACKEND_DEPENDENCIES) + target_link_libraries(${name}_cgbackend PRIVATE ${BACKEND_DEPENDENCIES}) + endif (BACKEND_DEPENDENCIES) + + install(TARGETS ${name}_cgbackend DESTINATION "libexec/darling${path}/MacOS") + install(FILES ${BACKEND_INFO_PLIST} DESTINATION "libexec/darling${path}" RENAME Info.plist) + + if (BACKEND_RESOURCES) + while (BACKEND_RESOURCES) + list(GET BACKEND_RESOURCES 0 res_install_path) + list(GET BACKEND_RESOURCES 1 res_source_path) + get_filename_component(res_install_dir ${res_install_path} DIRECTORY) + get_filename_component(res_install_name ${res_install_path} NAME) + install(FILES ${res_source_path} + DESTINATION libexec/darling${path}/Resources/${res_install_dir} + RENAME ${res_install_name}) + list(REMOVE_AT BACKEND_RESOURCES 0 1) + endwhile (BACKEND_RESOURCES) + endif (BACKEND_RESOURCES) +endfunction(add_backend) + +add_backend(X11 + SOURCES + CGSConnectionX11.m + CGSWindowX11.m + CGSSurfaceX11.m + X11KeySymToUCS.m + INFO_PLIST + Info.plist + DEPENDENCIES + objc + system + CoreFoundation + Foundation + AppKit + Onyx2D + CoreGraphics + OpenGL + QuartzCore + # native libraries + X11 + XRandR + Xcursor + fontconfig + xkbfile +) diff --git a/CoreGraphics/X11.backend/CarbonKeys.h b/CoreGraphics/X11.backend/CarbonKeys.h new file mode 100644 index 00000000..ee01ecf9 --- /dev/null +++ b/CoreGraphics/X11.backend/CarbonKeys.h @@ -0,0 +1,238 @@ +#ifndef _CARBONKEYS_H +#define _CARBONKEYS_H + +#include +#include + +// The contents of this file are hardware specific to a certain degree, +// but this is probably as good as we can do. +// The only hardware-independ codes we can get from X11 are keysyms, +// but those are _after_ the keyboard layout is applied, so definitely +// not something we could easily map to Carbon constants. + +// Missing: +// kVK_ANSI_KeypadEquals +// kVK_Function +// kVK_F16 +// kVK_F17 +// kVK_F18 +// kVK_F19 +// kVK_F20 +// kVK_Help + +static const uint8_t x11ToCarbon[256] = { + [38] = kVK_ANSI_A, + [39] = kVK_ANSI_S, + [40] = kVK_ANSI_D, + [41] = kVK_ANSI_F, + [43] = kVK_ANSI_H, + [42] = kVK_ANSI_G, + [52] = kVK_ANSI_Z, + [53] = kVK_ANSI_X, + [54] = kVK_ANSI_C, + [55] = kVK_ANSI_V, + [56] = kVK_ANSI_B, + [24] = kVK_ANSI_Q, + [25] = kVK_ANSI_W, + [26] = kVK_ANSI_E, + [27] = kVK_ANSI_R, + [29] = kVK_ANSI_Y, + [28] = kVK_ANSI_T, + [10] = kVK_ANSI_1, + [11] = kVK_ANSI_2, + [12] = kVK_ANSI_3, + [13] = kVK_ANSI_4, + [15] = kVK_ANSI_6, + [14] = kVK_ANSI_5, + [21] = kVK_ANSI_Equal, + [18] = kVK_ANSI_9, + [16] = kVK_ANSI_7, + [20] = kVK_ANSI_Minus, + [17] = kVK_ANSI_8, + [19] = kVK_ANSI_0, + [35] = kVK_ANSI_RightBracket, + [32] = kVK_ANSI_O, + [30] = kVK_ANSI_U, + [34] = kVK_ANSI_LeftBracket, + [31] = kVK_ANSI_I, + [33] = kVK_ANSI_P, + [46] = kVK_ANSI_L, + [44] = kVK_ANSI_J, + [48] = kVK_ANSI_Quote, + [45] = kVK_ANSI_K, + [47] = kVK_ANSI_Semicolon, + [51] = kVK_ANSI_Backslash, + [59] = kVK_ANSI_Comma, + [61] = kVK_ANSI_Slash, + [57] = kVK_ANSI_N, + [58] = kVK_ANSI_M, + [60] = kVK_ANSI_Period, + [49] = kVK_ANSI_Grave, + [91] = kVK_ANSI_KeypadDecimal, + [63] = kVK_ANSI_KeypadMultiply, + [86] = kVK_ANSI_KeypadPlus, + [77] = kVK_ANSI_KeypadClear, + [106] = kVK_ANSI_KeypadDivide, + [104] = kVK_ANSI_KeypadEnter, + [82] = kVK_ANSI_KeypadMinus, + [90] = kVK_ANSI_Keypad0, + [87] = kVK_ANSI_Keypad1, + [88] = kVK_ANSI_Keypad2, + [89] = kVK_ANSI_Keypad3, + [83] = kVK_ANSI_Keypad4, + [84] = kVK_ANSI_Keypad5, + [85] = kVK_ANSI_Keypad6, + [79] = kVK_ANSI_Keypad7, + [80] = kVK_ANSI_Keypad8, + [81] = kVK_ANSI_Keypad9, + [36] = kVK_Return, + [23] = kVK_Tab, + [65] = kVK_Space, + [22] = kVK_Delete, + [9] = kVK_Escape, + [64] = kVK_Command, + [50] = kVK_Shift, + [66] = kVK_CapsLock, + [133] = kVK_Option, + [37] = kVK_Control, + [62] = kVK_RightShift, + [134] = kVK_RightOption, + [105] = kVK_RightControl, + [123] = kVK_VolumeUp, + [122] = kVK_VolumeDown, + [121] = kVK_Mute, + [71] = kVK_F5, + [72] = kVK_F6, + [73] = kVK_F7, + [69] = kVK_F3, + [74] = kVK_F8, + [75] = kVK_F9, + [95] = kVK_F11, + [107] = kVK_F13, + [78] = kVK_F14, + [76] = kVK_F10, + [96] = kVK_F12, + [127] = kVK_F15, + [110] = kVK_Home, + [112] = kVK_PageUp, + [119] = kVK_ForwardDelete, + [70] = kVK_F4, + [115] = kVK_End, + [68] = kVK_F2, + [117] = kVK_PageDown, + [67] = kVK_F1, + [113] = kVK_LeftArrow, + [114] = kVK_RightArrow, + [116] = kVK_DownArrow, + [111] = kVK_UpArrow, +}; + +static const uint8_t carbonToX11[256] = { + [kVK_ANSI_A] = 38, + [kVK_ANSI_S] = 39, + [kVK_ANSI_D] = 40, + [kVK_ANSI_F] = 41, + [kVK_ANSI_H] = 43, + [kVK_ANSI_G] = 42, + [kVK_ANSI_Z] = 52, + [kVK_ANSI_X] = 53, + [kVK_ANSI_C] = 54, + [kVK_ANSI_V] = 55, + [kVK_ANSI_B] = 56, + [kVK_ANSI_Q] = 24, + [kVK_ANSI_W] = 25, + [kVK_ANSI_E] = 26, + [kVK_ANSI_R] = 27, + [kVK_ANSI_Y] = 29, + [kVK_ANSI_T] = 28, + [kVK_ANSI_1] = 10, + [kVK_ANSI_2] = 11, + [kVK_ANSI_3] = 12, + [kVK_ANSI_4] = 13, + [kVK_ANSI_6] = 15, + [kVK_ANSI_5] = 14, + [kVK_ANSI_Equal] = 21, + [kVK_ANSI_9] = 18, + [kVK_ANSI_7] = 16, + [kVK_ANSI_Minus] = 20, + [kVK_ANSI_8] = 17, + [kVK_ANSI_0] = 19, + [kVK_ANSI_RightBracket] = 35, + [kVK_ANSI_O] = 32, + [kVK_ANSI_U] = 30, + [kVK_ANSI_LeftBracket] = 34, + [kVK_ANSI_I] = 31, + [kVK_ANSI_P] = 33, + [kVK_ANSI_L] = 46, + [kVK_ANSI_J] = 44, + [kVK_ANSI_Quote] = 48, + [kVK_ANSI_K] = 45, + [kVK_ANSI_Semicolon] = 47, + [kVK_ANSI_Backslash] = 51, + [kVK_ANSI_Comma] = 59, + [kVK_ANSI_Slash] = 61, + [kVK_ANSI_N] = 57, + [kVK_ANSI_M] = 58, + [kVK_ANSI_Period] = 60, + [kVK_ANSI_Grave] = 49, + [kVK_ANSI_KeypadDecimal] = 91, + [kVK_ANSI_KeypadMultiply] = 63, + [kVK_ANSI_KeypadPlus] = 86, + [kVK_ANSI_KeypadClear] = 77, + [kVK_ANSI_KeypadDivide] = 106, + [kVK_ANSI_KeypadEnter] = 104, + [kVK_ANSI_KeypadMinus] = 82, + [kVK_ANSI_Keypad0] = 90, + [kVK_ANSI_Keypad1] = 87, + [kVK_ANSI_Keypad2] = 88, + [kVK_ANSI_Keypad3] = 89, + [kVK_ANSI_Keypad4] = 83, + [kVK_ANSI_Keypad5] = 84, + [kVK_ANSI_Keypad6] = 85, + [kVK_ANSI_Keypad7] = 79, + [kVK_ANSI_Keypad8] = 80, + [kVK_ANSI_Keypad9] = 81, + [kVK_Return] = 36, + [kVK_Tab] = 23, + [kVK_Space] = 65, + [kVK_Delete] = 22, + [kVK_Escape] = 9, + [kVK_Command] = 64, + [kVK_Shift] = 50, + [kVK_CapsLock] = 66, + [kVK_Option] = 133, + [kVK_Control] = 37, + [kVK_RightShift] = 62, + [kVK_RightOption] = 134, + [kVK_RightControl] = 105, + [kVK_VolumeUp] = 123, + [kVK_VolumeDown] = 122, + [kVK_Mute] = 121, + [kVK_F5] = 71, + [kVK_F6] = 72, + [kVK_F7] = 73, + [kVK_F3] = 69, + [kVK_F8] = 74, + [kVK_F9] = 75, + [kVK_F11] = 95, + [kVK_F13] = 107, + [kVK_F14] = 78, + [kVK_F10] = 76, + [kVK_F12] = 96, + [kVK_F15] = 127, + [kVK_Home] = 110, + [kVK_PageUp] = 112, + [kVK_ForwardDelete] = 119, + [kVK_F4] = 70, + [kVK_End] = 115, + [kVK_F2] = 68, + [kVK_PageDown] = 117, + [kVK_F1] = 67, + [kVK_LeftArrow] = 113, + [kVK_RightArrow] = 114, + [kVK_DownArrow] = 116, + [kVK_UpArrow] = 111, +}; + + +#endif diff --git a/CoreGraphics/X11.backend/Info.plist b/CoreGraphics/X11.backend/Info.plist new file mode 100644 index 00000000..0f28392e --- /dev/null +++ b/CoreGraphics/X11.backend/Info.plist @@ -0,0 +1,26 @@ + + + + + CFBundleDevelopmentRegion + English + CFBundleExecutable + X11 + CFBundleIconFile + + CFBundleIdentifier + org.darlinghq.backends.X11 + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + BNDL + CFBundleSignature + OBJC + CFBundleVersion + 1.0 + NSPriority + 200 + NSPrincipalClass + CGSConnectionX11 + + diff --git a/CoreGraphics/X11.backend/X11KeySymToUCS.h b/CoreGraphics/X11.backend/X11KeySymToUCS.h new file mode 100644 index 00000000..169cb39c --- /dev/null +++ b/CoreGraphics/X11.backend/X11KeySymToUCS.h @@ -0,0 +1,7 @@ +#ifndef X11KEYSYMTOUCS_H +#define X11KEYSYMTOUCS_H +#include + +uint32_t X11KeySymToUCS(uint32_t x11KeySym); + +#endif diff --git a/CoreGraphics/X11.backend/X11KeySymToUCS.m b/CoreGraphics/X11.backend/X11KeySymToUCS.m new file mode 100644 index 00000000..de4fce28 --- /dev/null +++ b/CoreGraphics/X11.backend/X11KeySymToUCS.m @@ -0,0 +1,1664 @@ +#include "X11KeySymToUCS.h" +#include + +// Source: https://github.com/substack/node-keysym/blob/master/data/keysyms.txt + +static const uint32_t x11KeySymToUCSData[][2] = { + {0x0020, 0x0020}, + {0x0021, 0x0021}, + {0x0022, 0x0022}, + {0x0023, 0x0023}, + {0x0024, 0x0024}, + {0x0025, 0x0025}, + {0x0026, 0x0026}, + {0x0027, 0x0027}, + {0x0027, 0x0027}, + {0x0028, 0x0028}, + {0x0029, 0x0029}, + {0x002a, 0x002a}, + {0x002b, 0x002b}, + {0x002c, 0x002c}, + {0x002d, 0x002d}, + {0x002e, 0x002e}, + {0x002f, 0x002f}, + {0x0030, 0x0030}, + {0x0031, 0x0031}, + {0x0032, 0x0032}, + {0x0033, 0x0033}, + {0x0034, 0x0034}, + {0x0035, 0x0035}, + {0x0036, 0x0036}, + {0x0037, 0x0037}, + {0x0038, 0x0038}, + {0x0039, 0x0039}, + {0x003a, 0x003a}, + {0x003b, 0x003b}, + {0x003c, 0x003c}, + {0x003d, 0x003d}, + {0x003e, 0x003e}, + {0x003f, 0x003f}, + {0x0040, 0x0040}, + {0x0041, 0x0041}, + {0x0042, 0x0042}, + {0x0043, 0x0043}, + {0x0044, 0x0044}, + {0x0045, 0x0045}, + {0x0046, 0x0046}, + {0x0047, 0x0047}, + {0x0048, 0x0048}, + {0x0049, 0x0049}, + {0x004a, 0x004a}, + {0x004b, 0x004b}, + {0x004c, 0x004c}, + {0x004d, 0x004d}, + {0x004e, 0x004e}, + {0x004f, 0x004f}, + {0x0050, 0x0050}, + {0x0051, 0x0051}, + {0x0052, 0x0052}, + {0x0053, 0x0053}, + {0x0054, 0x0054}, + {0x0055, 0x0055}, + {0x0056, 0x0056}, + {0x0057, 0x0057}, + {0x0058, 0x0058}, + {0x0059, 0x0059}, + {0x005a, 0x005a}, + {0x005b, 0x005b}, + {0x005c, 0x005c}, + {0x005d, 0x005d}, + {0x005e, 0x005e}, + {0x005f, 0x005f}, + {0x0060, 0x0060}, + {0x0060, 0x0060}, + {0x0061, 0x0061}, + {0x0062, 0x0062}, + {0x0063, 0x0063}, + {0x0064, 0x0064}, + {0x0065, 0x0065}, + {0x0066, 0x0066}, + {0x0067, 0x0067}, + {0x0068, 0x0068}, + {0x0069, 0x0069}, + {0x006a, 0x006a}, + {0x006b, 0x006b}, + {0x006c, 0x006c}, + {0x006d, 0x006d}, + {0x006e, 0x006e}, + {0x006f, 0x006f}, + {0x0070, 0x0070}, + {0x0071, 0x0071}, + {0x0072, 0x0072}, + {0x0073, 0x0073}, + {0x0074, 0x0074}, + {0x0075, 0x0075}, + {0x0076, 0x0076}, + {0x0077, 0x0077}, + {0x0078, 0x0078}, + {0x0079, 0x0079}, + {0x007a, 0x007a}, + {0x007b, 0x007b}, + {0x007c, 0x007c}, + {0x007d, 0x007d}, + {0x007e, 0x007e}, + {0x00a0, 0x00a0}, + {0x00a1, 0x00a1}, + {0x00a2, 0x00a2}, + {0x00a3, 0x00a3}, + {0x00a4, 0x00a4}, + {0x00a5, 0x00a5}, + {0x00a6, 0x00a6}, + {0x00a7, 0x00a7}, + {0x00a8, 0x00a8}, + {0x00a9, 0x00a9}, + {0x00aa, 0x00aa}, + {0x00ab, 0x00ab}, + {0x00ac, 0x00ac}, + {0x00ad, 0x00ad}, + {0x00ae, 0x00ae}, + {0x00af, 0x00af}, + {0x00b0, 0x00b0}, + {0x00b1, 0x00b1}, + {0x00b2, 0x00b2}, + {0x00b3, 0x00b3}, + {0x00b4, 0x00b4}, + {0x00b5, 0x00b5}, + {0x00b6, 0x00b6}, + {0x00b7, 0x00b7}, + {0x00b8, 0x00b8}, + {0x00b9, 0x00b9}, + {0x00ba, 0x00ba}, + {0x00bb, 0x00bb}, + {0x00bc, 0x00bc}, + {0x00bd, 0x00bd}, + {0x00be, 0x00be}, + {0x00bf, 0x00bf}, + {0x00c0, 0x00c0}, + {0x00c1, 0x00c1}, + {0x00c2, 0x00c2}, + {0x00c3, 0x00c3}, + {0x00c4, 0x00c4}, + {0x00c5, 0x00c5}, + {0x00c6, 0x00c6}, + {0x00c7, 0x00c7}, + {0x00c8, 0x00c8}, + {0x00c9, 0x00c9}, + {0x00ca, 0x00ca}, + {0x00cb, 0x00cb}, + {0x00cc, 0x00cc}, + {0x00cd, 0x00cd}, + {0x00ce, 0x00ce}, + {0x00cf, 0x00cf}, + {0x00d0, 0x00d0}, + {0x00d0, 0x00d0}, + {0x00d1, 0x00d1}, + {0x00d2, 0x00d2}, + {0x00d3, 0x00d3}, + {0x00d4, 0x00d4}, + {0x00d5, 0x00d5}, + {0x00d6, 0x00d6}, + {0x00d7, 0x00d7}, + {0x00d8, 0x00d8}, + {0x00d9, 0x00d9}, + {0x00da, 0x00da}, + {0x00db, 0x00db}, + {0x00dc, 0x00dc}, + {0x00dd, 0x00dd}, + {0x00de, 0x00de}, + {0x00de, 0x00de}, + {0x00df, 0x00df}, + {0x00e0, 0x00e0}, + {0x00e1, 0x00e1}, + {0x00e2, 0x00e2}, + {0x00e3, 0x00e3}, + {0x00e4, 0x00e4}, + {0x00e5, 0x00e5}, + {0x00e6, 0x00e6}, + {0x00e7, 0x00e7}, + {0x00e8, 0x00e8}, + {0x00e9, 0x00e9}, + {0x00ea, 0x00ea}, + {0x00eb, 0x00eb}, + {0x00ec, 0x00ec}, + {0x00ed, 0x00ed}, + {0x00ee, 0x00ee}, + {0x00ef, 0x00ef}, + {0x00f0, 0x00f0}, + {0x00f1, 0x00f1}, + {0x00f2, 0x00f2}, + {0x00f3, 0x00f3}, + {0x00f4, 0x00f4}, + {0x00f5, 0x00f5}, + {0x00f6, 0x00f6}, + {0x00f7, 0x00f7}, + {0x00f8, 0x00f8}, + {0x00f9, 0x00f9}, + {0x00fa, 0x00fa}, + {0x00fb, 0x00fb}, + {0x00fc, 0x00fc}, + {0x00fd, 0x00fd}, + {0x00fe, 0x00fe}, + {0x00ff, 0x00ff}, + {0x01a1, 0x0104}, + {0x01a2, 0x02d8}, + {0x01a3, 0x0141}, + {0x01a5, 0x013d}, + {0x01a6, 0x015a}, + {0x01a9, 0x0160}, + {0x01aa, 0x015e}, + {0x01ab, 0x0164}, + {0x01ac, 0x0179}, + {0x01ae, 0x017d}, + {0x01af, 0x017b}, + {0x01b1, 0x0105}, + {0x01b2, 0x02db}, + {0x01b3, 0x0142}, + {0x01b5, 0x013e}, + {0x01b6, 0x015b}, + {0x01b7, 0x02c7}, + {0x01b9, 0x0161}, + {0x01ba, 0x015f}, + {0x01bb, 0x0165}, + {0x01bc, 0x017a}, + {0x01bd, 0x02dd}, + {0x01be, 0x017e}, + {0x01bf, 0x017c}, + {0x01c0, 0x0154}, + {0x01c3, 0x0102}, + {0x01c5, 0x0139}, + {0x01c6, 0x0106}, + {0x01c8, 0x010c}, + {0x01ca, 0x0118}, + {0x01cc, 0x011a}, + {0x01cf, 0x010e}, + {0x01d0, 0x0110}, + {0x01d1, 0x0143}, + {0x01d2, 0x0147}, + {0x01d5, 0x0150}, + {0x01d8, 0x0158}, + {0x01d9, 0x016e}, + {0x01db, 0x0170}, + {0x01de, 0x0162}, + {0x01e0, 0x0155}, + {0x01e3, 0x0103}, + {0x01e5, 0x013a}, + {0x01e6, 0x0107}, + {0x01e8, 0x010d}, + {0x01ea, 0x0119}, + {0x01ec, 0x011b}, + {0x01ef, 0x010f}, + {0x01f0, 0x0111}, + {0x01f1, 0x0144}, + {0x01f2, 0x0148}, + {0x01f5, 0x0151}, + {0x01f8, 0x0159}, + {0x01f9, 0x016f}, + {0x01fb, 0x0171}, + {0x01fe, 0x0163}, + {0x01ff, 0x02d9}, + {0x02a1, 0x0126}, + {0x02a6, 0x0124}, + {0x02a9, 0x0130}, + {0x02ab, 0x011e}, + {0x02ac, 0x0134}, + {0x02b1, 0x0127}, + {0x02b6, 0x0125}, + {0x02b9, 0x0131}, + {0x02bb, 0x011f}, + {0x02bc, 0x0135}, + {0x02c5, 0x010a}, + {0x02c6, 0x0108}, + {0x02d5, 0x0120}, + {0x02d8, 0x011c}, + {0x02dd, 0x016c}, + {0x02de, 0x015c}, + {0x02e5, 0x010b}, + {0x02e6, 0x0109}, + {0x02f5, 0x0121}, + {0x02f8, 0x011d}, + {0x02fd, 0x016d}, + {0x02fe, 0x015d}, + {0x03a2, 0x0138}, + {0x03a3, 0x0156}, + {0x03a5, 0x0128}, + {0x03a6, 0x013b}, + {0x03aa, 0x0112}, + {0x03ab, 0x0122}, + {0x03ac, 0x0166}, + {0x03b3, 0x0157}, + {0x03b5, 0x0129}, + {0x03b6, 0x013c}, + {0x03ba, 0x0113}, + {0x03bb, 0x0123}, + {0x03bc, 0x0167}, + {0x03bd, 0x014a}, + {0x03bf, 0x014b}, + {0x03c0, 0x0100}, + {0x03c7, 0x012e}, + {0x03cc, 0x0116}, + {0x03cf, 0x012a}, + {0x03d1, 0x0145}, + {0x03d2, 0x014c}, + {0x03d3, 0x0136}, + {0x03d9, 0x0172}, + {0x03dd, 0x0168}, + {0x03de, 0x016a}, + {0x03e0, 0x0101}, + {0x03e7, 0x012f}, + {0x03ec, 0x0117}, + {0x03ef, 0x012b}, + {0x03f1, 0x0146}, + {0x03f2, 0x014d}, + {0x03f3, 0x0137}, + {0x03f9, 0x0173}, + {0x03fd, 0x0169}, + {0x03fe, 0x016b}, + {0x047e, 0x203e}, + {0x04a1, 0x3002}, + {0x04a2, 0x300c}, + {0x04a3, 0x300d}, + {0x04a4, 0x3001}, + {0x04a5, 0x30fb}, + {0x04a6, 0x30f2}, + {0x04a7, 0x30a1}, + {0x04a8, 0x30a3}, + {0x04a9, 0x30a5}, + {0x04aa, 0x30a7}, + {0x04ab, 0x30a9}, + {0x04ac, 0x30e3}, + {0x04ad, 0x30e5}, + {0x04ae, 0x30e7}, + {0x04af, 0x30c3}, + {0x04b0, 0x30fc}, + {0x04b1, 0x30a2}, + {0x04b2, 0x30a4}, + {0x04b3, 0x30a6}, + {0x04b4, 0x30a8}, + {0x04b5, 0x30aa}, + {0x04b6, 0x30ab}, + {0x04b7, 0x30ad}, + {0x04b8, 0x30af}, + {0x04b9, 0x30b1}, + {0x04ba, 0x30b3}, + {0x04bb, 0x30b5}, + {0x04bc, 0x30b7}, + {0x04bd, 0x30b9}, + {0x04be, 0x30bb}, + {0x04bf, 0x30bd}, + {0x04c0, 0x30bf}, + {0x04c1, 0x30c1}, + {0x04c2, 0x30c4}, + {0x04c3, 0x30c6}, + {0x04c4, 0x30c8}, + {0x04c5, 0x30ca}, + {0x04c6, 0x30cb}, + {0x04c7, 0x30cc}, + {0x04c8, 0x30cd}, + {0x04c9, 0x30ce}, + {0x04ca, 0x30cf}, + {0x04cb, 0x30d2}, + {0x04cc, 0x30d5}, + {0x04cd, 0x30d8}, + {0x04ce, 0x30db}, + {0x04cf, 0x30de}, + {0x04d0, 0x30df}, + {0x04d1, 0x30e0}, + {0x04d2, 0x30e1}, + {0x04d3, 0x30e2}, + {0x04d4, 0x30e4}, + {0x04d5, 0x30e6}, + {0x04d6, 0x30e8}, + {0x04d7, 0x30e9}, + {0x04d8, 0x30ea}, + {0x04d9, 0x30eb}, + {0x04da, 0x30ec}, + {0x04db, 0x30ed}, + {0x04dc, 0x30ef}, + {0x04dd, 0x30f3}, + {0x04de, 0x309b}, + {0x04df, 0x309c}, + {0x05ac, 0x060c}, + {0x05bb, 0x061b}, + {0x05bf, 0x061f}, + {0x05c1, 0x0621}, + {0x05c2, 0x0622}, + {0x05c3, 0x0623}, + {0x05c4, 0x0624}, + {0x05c5, 0x0625}, + {0x05c6, 0x0626}, + {0x05c7, 0x0627}, + {0x05c8, 0x0628}, + {0x05c9, 0x0629}, + {0x05ca, 0x062a}, + {0x05cb, 0x062b}, + {0x05cc, 0x062c}, + {0x05cd, 0x062d}, + {0x05ce, 0x062e}, + {0x05cf, 0x062f}, + {0x05d0, 0x0630}, + {0x05d1, 0x0631}, + {0x05d2, 0x0632}, + {0x05d3, 0x0633}, + {0x05d4, 0x0634}, + {0x05d5, 0x0635}, + {0x05d6, 0x0636}, + {0x05d7, 0x0637}, + {0x05d8, 0x0638}, + {0x05d9, 0x0639}, + {0x05da, 0x063a}, + {0x05e0, 0x0640}, + {0x05e1, 0x0641}, + {0x05e2, 0x0642}, + {0x05e3, 0x0643}, + {0x05e4, 0x0644}, + {0x05e5, 0x0645}, + {0x05e6, 0x0646}, + {0x05e7, 0x0647}, + {0x05e8, 0x0648}, + {0x05e9, 0x0649}, + {0x05ea, 0x064a}, + {0x05eb, 0x064b}, + {0x05ec, 0x064c}, + {0x05ed, 0x064d}, + {0x05ee, 0x064e}, + {0x05ef, 0x064f}, + {0x05f0, 0x0650}, + {0x05f1, 0x0651}, + {0x05f2, 0x0652}, + {0x06a1, 0x0452}, + {0x06a2, 0x0453}, + {0x06a3, 0x0451}, + {0x06a4, 0x0454}, + {0x06a5, 0x0455}, + {0x06a6, 0x0456}, + {0x06a7, 0x0457}, + {0x06a8, 0x0458}, + {0x06a9, 0x0459}, + {0x06aa, 0x045a}, + {0x06ab, 0x045b}, + {0x06ac, 0x045c}, + {0x06ae, 0x045e}, + {0x06af, 0x045f}, + {0x06b0, 0x2116}, + {0x06b1, 0x0402}, + {0x06b2, 0x0403}, + {0x06b3, 0x0401}, + {0x06b4, 0x0404}, + {0x06b5, 0x0405}, + {0x06b6, 0x0406}, + {0x06b7, 0x0407}, + {0x06b8, 0x0408}, + {0x06b9, 0x0409}, + {0x06ba, 0x040a}, + {0x06bb, 0x040b}, + {0x06bc, 0x040c}, + {0x06be, 0x040e}, + {0x06bf, 0x040f}, + {0x06c0, 0x044e}, + {0x06c1, 0x0430}, + {0x06c2, 0x0431}, + {0x06c3, 0x0446}, + {0x06c4, 0x0434}, + {0x06c5, 0x0435}, + {0x06c6, 0x0444}, + {0x06c7, 0x0433}, + {0x06c8, 0x0445}, + {0x06c9, 0x0438}, + {0x06ca, 0x0439}, + {0x06cb, 0x043a}, + {0x06cc, 0x043b}, + {0x06cd, 0x043c}, + {0x06ce, 0x043d}, + {0x06cf, 0x043e}, + {0x06d0, 0x043f}, + {0x06d1, 0x044f}, + {0x06d2, 0x0440}, + {0x06d3, 0x0441}, + {0x06d4, 0x0442}, + {0x06d5, 0x0443}, + {0x06d6, 0x0436}, + {0x06d7, 0x0432}, + {0x06d8, 0x044c}, + {0x06d9, 0x044b}, + {0x06da, 0x0437}, + {0x06db, 0x0448}, + {0x06dc, 0x044d}, + {0x06dd, 0x0449}, + {0x06de, 0x0447}, + {0x06df, 0x044a}, + {0x06e0, 0x042e}, + {0x06e1, 0x0410}, + {0x06e2, 0x0411}, + {0x06e3, 0x0426}, + {0x06e4, 0x0414}, + {0x06e5, 0x0415}, + {0x06e6, 0x0424}, + {0x06e7, 0x0413}, + {0x06e8, 0x0425}, + {0x06e9, 0x0418}, + {0x06ea, 0x0419}, + {0x06eb, 0x041a}, + {0x06ec, 0x041b}, + {0x06ed, 0x041c}, + {0x06ee, 0x041d}, + {0x06ef, 0x041e}, + {0x06f0, 0x041f}, + {0x06f1, 0x042f}, + {0x06f2, 0x0420}, + {0x06f3, 0x0421}, + {0x06f4, 0x0422}, + {0x06f5, 0x0423}, + {0x06f6, 0x0416}, + {0x06f7, 0x0412}, + {0x06f8, 0x042c}, + {0x06f9, 0x042b}, + {0x06fa, 0x0417}, + {0x06fb, 0x0428}, + {0x06fc, 0x042d}, + {0x06fd, 0x0429}, + {0x06fe, 0x0427}, + {0x06ff, 0x042a}, + {0x07a1, 0x0386}, + {0x07a2, 0x0388}, + {0x07a3, 0x0389}, + {0x07a4, 0x038a}, + {0x07a5, 0x03aa}, + {0x07a7, 0x038c}, + {0x07a8, 0x038e}, + {0x07a9, 0x03ab}, + {0x07ab, 0x038f}, + {0x07ae, 0x0385}, + {0x07af, 0x2015}, + {0x07b1, 0x03ac}, + {0x07b2, 0x03ad}, + {0x07b3, 0x03ae}, + {0x07b4, 0x03af}, + {0x07b5, 0x03ca}, + {0x07b6, 0x0390}, + {0x07b7, 0x03cc}, + {0x07b8, 0x03cd}, + {0x07b9, 0x03cb}, + {0x07ba, 0x03b0}, + {0x07bb, 0x03ce}, + {0x07c1, 0x0391}, + {0x07c2, 0x0392}, + {0x07c3, 0x0393}, + {0x07c4, 0x0394}, + {0x07c5, 0x0395}, + {0x07c6, 0x0396}, + {0x07c7, 0x0397}, + {0x07c8, 0x0398}, + {0x07c9, 0x0399}, + {0x07ca, 0x039a}, + {0x07cb, 0x039b}, + {0x07cb, 0x039b}, + {0x07cc, 0x039c}, + {0x07cd, 0x039d}, + {0x07ce, 0x039e}, + {0x07cf, 0x039f}, + {0x07d0, 0x03a0}, + {0x07d1, 0x03a1}, + {0x07d2, 0x03a3}, + {0x07d4, 0x03a4}, + {0x07d5, 0x03a5}, + {0x07d6, 0x03a6}, + {0x07d7, 0x03a7}, + {0x07d8, 0x03a8}, + {0x07d9, 0x03a9}, + {0x07e1, 0x03b1}, + {0x07e2, 0x03b2}, + {0x07e3, 0x03b3}, + {0x07e4, 0x03b4}, + {0x07e5, 0x03b5}, + {0x07e6, 0x03b6}, + {0x07e7, 0x03b7}, + {0x07e8, 0x03b8}, + {0x07e9, 0x03b9}, + {0x07ea, 0x03ba}, + {0x07eb, 0x03bb}, + {0x07ec, 0x03bc}, + {0x07ed, 0x03bd}, + {0x07ee, 0x03be}, + {0x07ef, 0x03bf}, + {0x07f0, 0x03c0}, + {0x07f1, 0x03c1}, + {0x07f2, 0x03c3}, + {0x07f3, 0x03c2}, + {0x07f4, 0x03c4}, + {0x07f5, 0x03c5}, + {0x07f6, 0x03c6}, + {0x07f7, 0x03c7}, + {0x07f8, 0x03c8}, + {0x07f9, 0x03c9}, + {0x08a1, 0x23b7}, + {0x08a2, 0x250c}, + {0x08a3, 0x2500}, + {0x08a4, 0x2320}, + {0x08a5, 0x2321}, + {0x08a6, 0x2502}, + {0x08a7, 0x23a1}, + {0x08a8, 0x23a3}, + {0x08a9, 0x23a4}, + {0x08aa, 0x23a6}, + {0x08ab, 0x239b}, + {0x08ac, 0x239d}, + {0x08ad, 0x239e}, + {0x08ae, 0x23a0}, + {0x08af, 0x23a8}, + {0x08b0, 0x23ac}, + {0x08b1, 0x0000}, + {0x08b2, 0x0000}, + {0x08b3, 0x0000}, + {0x08b4, 0x0000}, + {0x08b5, 0x0000}, + {0x08b6, 0x0000}, + {0x08b7, 0x0000}, + {0x08bc, 0x2264}, + {0x08bd, 0x2260}, + {0x08be, 0x2265}, + {0x08bf, 0x222b}, + {0x08c0, 0x2234}, + {0x08c1, 0x221d}, + {0x08c2, 0x221e}, + {0x08c5, 0x2207}, + {0x08c8, 0x223c}, + {0x08c9, 0x2243}, + {0x08cd, 0x21d4}, + {0x08ce, 0x21d2}, + {0x08cf, 0x2261}, + {0x08d6, 0x221a}, + {0x08da, 0x2282}, + {0x08db, 0x2283}, + {0x08dc, 0x2229}, + {0x08dd, 0x222a}, + {0x08de, 0x2227}, + {0x08df, 0x2228}, + {0x08ef, 0x2202}, + {0x08f6, 0x0192}, + {0x08fb, 0x2190}, + {0x08fc, 0x2191}, + {0x08fd, 0x2192}, + {0x08fe, 0x2193}, + {0x09df, 0x0000}, + {0x09e0, 0x25c6}, + {0x09e1, 0x2592}, + {0x09e2, 0x2409}, + {0x09e3, 0x240c}, + {0x09e4, 0x240d}, + {0x09e5, 0x240a}, + {0x09e8, 0x2424}, + {0x09e9, 0x240b}, + {0x09ea, 0x2518}, + {0x09eb, 0x2510}, + {0x09ec, 0x250c}, + {0x09ed, 0x2514}, + {0x09ee, 0x253c}, + {0x09ef, 0x23ba}, + {0x09f0, 0x23bb}, + {0x09f1, 0x2500}, + {0x09f2, 0x23bc}, + {0x09f3, 0x23bd}, + {0x09f4, 0x251c}, + {0x09f5, 0x2524}, + {0x09f6, 0x2534}, + {0x09f7, 0x252c}, + {0x09f8, 0x2502}, + {0x0aa1, 0x2003}, + {0x0aa2, 0x2002}, + {0x0aa3, 0x2004}, + {0x0aa4, 0x2005}, + {0x0aa5, 0x2007}, + {0x0aa6, 0x2008}, + {0x0aa7, 0x2009}, + {0x0aa8, 0x200a}, + {0x0aa9, 0x2014}, + {0x0aaa, 0x2013}, + {0x0aac, 0x2423}, + {0x0aae, 0x2026}, + {0x0aaf, 0x2025}, + {0x0ab0, 0x2153}, + {0x0ab1, 0x2154}, + {0x0ab2, 0x2155}, + {0x0ab3, 0x2156}, + {0x0ab4, 0x2157}, + {0x0ab5, 0x2158}, + {0x0ab6, 0x2159}, + {0x0ab7, 0x215a}, + {0x0ab8, 0x2105}, + {0x0abb, 0x2012}, + {0x0abc, 0x27e8}, + {0x0abd, 0x002e}, + {0x0abe, 0x27e9}, + {0x0abf, 0x0000}, + {0x0ac3, 0x215b}, + {0x0ac4, 0x215c}, + {0x0ac5, 0x215d}, + {0x0ac6, 0x215e}, + {0x0ac9, 0x2122}, + {0x0aca, 0x2613}, + {0x0acb, 0x0000}, + {0x0acc, 0x25c1}, + {0x0acd, 0x25b7}, + {0x0ace, 0x25cb}, + {0x0acf, 0x25af}, + {0x0ad0, 0x2018}, + {0x0ad1, 0x2019}, + {0x0ad2, 0x201c}, + {0x0ad3, 0x201d}, + {0x0ad4, 0x211e}, + {0x0ad6, 0x2032}, + {0x0ad7, 0x2033}, + {0x0ad9, 0x271d}, + {0x0ada, 0x0000}, + {0x0adb, 0x25ac}, + {0x0adc, 0x25c0}, + {0x0add, 0x25b6}, + {0x0ade, 0x25cf}, + {0x0adf, 0x25ae}, + {0x0ae0, 0x25e6}, + {0x0ae1, 0x25ab}, + {0x0ae2, 0x25ad}, + {0x0ae3, 0x25b3}, + {0x0ae4, 0x25bd}, + {0x0ae5, 0x2606}, + {0x0ae6, 0x2022}, + {0x0ae7, 0x25aa}, + {0x0ae8, 0x25b2}, + {0x0ae9, 0x25bc}, + {0x0aea, 0x261c}, + {0x0aeb, 0x261e}, + {0x0aec, 0x2663}, + {0x0aed, 0x2666}, + {0x0aee, 0x2665}, + {0x0af0, 0x2720}, + {0x0af1, 0x2020}, + {0x0af2, 0x2021}, + {0x0af3, 0x2713}, + {0x0af4, 0x2717}, + {0x0af5, 0x266f}, + {0x0af6, 0x266d}, + {0x0af7, 0x2642}, + {0x0af8, 0x2640}, + {0x0af9, 0x260e}, + {0x0afa, 0x2315}, + {0x0afb, 0x2117}, + {0x0afc, 0x2038}, + {0x0afd, 0x201a}, + {0x0afe, 0x201e}, + {0x0aff, 0x0000}, + {0x0ba3, 0x003c}, + {0x0ba6, 0x003e}, + {0x0ba8, 0x2228}, + {0x0ba9, 0x2227}, + {0x0bc0, 0x00af}, + {0x0bc2, 0x22a5}, + {0x0bc3, 0x2229}, + {0x0bc4, 0x230a}, + {0x0bc6, 0x005f}, + {0x0bca, 0x2218}, + {0x0bcc, 0x2395}, + {0x0bce, 0x22a4}, + {0x0bcf, 0x25cb}, + {0x0bd3, 0x2308}, + {0x0bd6, 0x222a}, + {0x0bd8, 0x2283}, + {0x0bda, 0x2282}, + {0x0bdc, 0x22a2}, + {0x0bfc, 0x22a3}, + {0x0cdf, 0x2017}, + {0x0ce0, 0x05d0}, + {0x0ce1, 0x05d1}, + {0x0ce1, 0x05d1}, + {0x0ce2, 0x05d2}, + {0x0ce2, 0x05d2}, + {0x0ce3, 0x05d3}, + {0x0ce3, 0x05d3}, + {0x0ce4, 0x05d4}, + {0x0ce5, 0x05d5}, + {0x0ce6, 0x05d6}, + {0x0ce6, 0x05d6}, + {0x0ce7, 0x05d7}, + {0x0ce7, 0x05d7}, + {0x0ce8, 0x05d8}, + {0x0ce8, 0x05d8}, + {0x0ce9, 0x05d9}, + {0x0cea, 0x05da}, + {0x0ceb, 0x05db}, + {0x0cec, 0x05dc}, + {0x0ced, 0x05dd}, + {0x0cee, 0x05de}, + {0x0cef, 0x05df}, + {0x0cf0, 0x05e0}, + {0x0cf1, 0x05e1}, + {0x0cf1, 0x05e1}, + {0x0cf2, 0x05e2}, + {0x0cf3, 0x05e3}, + {0x0cf4, 0x05e4}, + {0x0cf5, 0x05e5}, + {0x0cf5, 0x05e5}, + {0x0cf6, 0x05e6}, + {0x0cf6, 0x05e6}, + {0x0cf7, 0x05e7}, + {0x0cf7, 0x05e7}, + {0x0cf8, 0x05e8}, + {0x0cf9, 0x05e9}, + {0x0cfa, 0x05ea}, + {0x0cfa, 0x05ea}, + {0x0da1, 0x0e01}, + {0x0da2, 0x0e02}, + {0x0da3, 0x0e03}, + {0x0da4, 0x0e04}, + {0x0da5, 0x0e05}, + {0x0da6, 0x0e06}, + {0x0da7, 0x0e07}, + {0x0da8, 0x0e08}, + {0x0da9, 0x0e09}, + {0x0daa, 0x0e0a}, + {0x0dab, 0x0e0b}, + {0x0dac, 0x0e0c}, + {0x0dad, 0x0e0d}, + {0x0dae, 0x0e0e}, + {0x0daf, 0x0e0f}, + {0x0db0, 0x0e10}, + {0x0db1, 0x0e11}, + {0x0db2, 0x0e12}, + {0x0db3, 0x0e13}, + {0x0db4, 0x0e14}, + {0x0db5, 0x0e15}, + {0x0db6, 0x0e16}, + {0x0db7, 0x0e17}, + {0x0db8, 0x0e18}, + {0x0db9, 0x0e19}, + {0x0dba, 0x0e1a}, + {0x0dbb, 0x0e1b}, + {0x0dbc, 0x0e1c}, + {0x0dbd, 0x0e1d}, + {0x0dbe, 0x0e1e}, + {0x0dbf, 0x0e1f}, + {0x0dc0, 0x0e20}, + {0x0dc1, 0x0e21}, + {0x0dc2, 0x0e22}, + {0x0dc3, 0x0e23}, + {0x0dc4, 0x0e24}, + {0x0dc5, 0x0e25}, + {0x0dc6, 0x0e26}, + {0x0dc7, 0x0e27}, + {0x0dc8, 0x0e28}, + {0x0dc9, 0x0e29}, + {0x0dca, 0x0e2a}, + {0x0dcb, 0x0e2b}, + {0x0dcc, 0x0e2c}, + {0x0dcd, 0x0e2d}, + {0x0dce, 0x0e2e}, + {0x0dcf, 0x0e2f}, + {0x0dd0, 0x0e30}, + {0x0dd1, 0x0e31}, + {0x0dd2, 0x0e32}, + {0x0dd3, 0x0e33}, + {0x0dd4, 0x0e34}, + {0x0dd5, 0x0e35}, + {0x0dd6, 0x0e36}, + {0x0dd7, 0x0e37}, + {0x0dd8, 0x0e38}, + {0x0dd9, 0x0e39}, + {0x0dda, 0x0e3a}, + {0x0dde, 0x0000}, + {0x0ddf, 0x0e3f}, + {0x0de0, 0x0e40}, + {0x0de1, 0x0e41}, + {0x0de2, 0x0e42}, + {0x0de3, 0x0e43}, + {0x0de4, 0x0e44}, + {0x0de5, 0x0e45}, + {0x0de6, 0x0e46}, + {0x0de7, 0x0e47}, + {0x0de8, 0x0e48}, + {0x0de9, 0x0e49}, + {0x0dea, 0x0e4a}, + {0x0deb, 0x0e4b}, + {0x0dec, 0x0e4c}, + {0x0ded, 0x0e4d}, + {0x0df0, 0x0e50}, + {0x0df1, 0x0e51}, + {0x0df2, 0x0e52}, + {0x0df3, 0x0e53}, + {0x0df4, 0x0e54}, + {0x0df5, 0x0e55}, + {0x0df6, 0x0e56}, + {0x0df7, 0x0e57}, + {0x0df8, 0x0e58}, + {0x0df9, 0x0e59}, + {0x0ea1, 0x3131}, + {0x0ea2, 0x3132}, + {0x0ea3, 0x3133}, + {0x0ea4, 0x3134}, + {0x0ea5, 0x3135}, + {0x0ea6, 0x3136}, + {0x0ea7, 0x3137}, + {0x0ea8, 0x3138}, + {0x0ea9, 0x3139}, + {0x0eaa, 0x313a}, + {0x0eab, 0x313b}, + {0x0eac, 0x313c}, + {0x0ead, 0x313d}, + {0x0eae, 0x313e}, + {0x0eaf, 0x313f}, + {0x0eb0, 0x3140}, + {0x0eb1, 0x3141}, + {0x0eb2, 0x3142}, + {0x0eb3, 0x3143}, + {0x0eb4, 0x3144}, + {0x0eb5, 0x3145}, + {0x0eb6, 0x3146}, + {0x0eb7, 0x3147}, + {0x0eb8, 0x3148}, + {0x0eb9, 0x3149}, + {0x0eba, 0x314a}, + {0x0ebb, 0x314b}, + {0x0ebc, 0x314c}, + {0x0ebd, 0x314d}, + {0x0ebe, 0x314e}, + {0x0ebf, 0x314f}, + {0x0ec0, 0x3150}, + {0x0ec1, 0x3151}, + {0x0ec2, 0x3152}, + {0x0ec3, 0x3153}, + {0x0ec4, 0x3154}, + {0x0ec5, 0x3155}, + {0x0ec6, 0x3156}, + {0x0ec7, 0x3157}, + {0x0ec8, 0x3158}, + {0x0ec9, 0x3159}, + {0x0eca, 0x315a}, + {0x0ecb, 0x315b}, + {0x0ecc, 0x315c}, + {0x0ecd, 0x315d}, + {0x0ece, 0x315e}, + {0x0ecf, 0x315f}, + {0x0ed0, 0x3160}, + {0x0ed1, 0x3161}, + {0x0ed2, 0x3162}, + {0x0ed3, 0x3163}, + {0x0ed4, 0x11a8}, + {0x0ed5, 0x11a9}, + {0x0ed6, 0x11aa}, + {0x0ed7, 0x11ab}, + {0x0ed8, 0x11ac}, + {0x0ed9, 0x11ad}, + {0x0eda, 0x11ae}, + {0x0edb, 0x11af}, + {0x0edc, 0x11b0}, + {0x0edd, 0x11b1}, + {0x0ede, 0x11b2}, + {0x0edf, 0x11b3}, + {0x0ee0, 0x11b4}, + {0x0ee1, 0x11b5}, + {0x0ee2, 0x11b6}, + {0x0ee3, 0x11b7}, + {0x0ee4, 0x11b8}, + {0x0ee5, 0x11b9}, + {0x0ee6, 0x11ba}, + {0x0ee7, 0x11bb}, + {0x0ee8, 0x11bc}, + {0x0ee9, 0x11bd}, + {0x0eea, 0x11be}, + {0x0eeb, 0x11bf}, + {0x0eec, 0x11c0}, + {0x0eed, 0x11c1}, + {0x0eee, 0x11c2}, + {0x0eef, 0x316d}, + {0x0ef0, 0x3171}, + {0x0ef1, 0x3178}, + {0x0ef2, 0x317f}, + {0x0ef3, 0x3181}, + {0x0ef4, 0x3184}, + {0x0ef5, 0x3186}, + {0x0ef6, 0x318d}, + {0x0ef7, 0x318e}, + {0x0ef8, 0x11eb}, + {0x0ef9, 0x11f0}, + {0x0efa, 0x11f9}, + {0x0eff, 0x20a9}, + {0x13bc, 0x0152}, + {0x13bd, 0x0153}, + {0x13be, 0x0178}, + {0x20a0, 0x20a0}, + {0x20a1, 0x20a1}, + {0x20a2, 0x20a2}, + {0x20a3, 0x20a3}, + {0x20a4, 0x20a4}, + {0x20a5, 0x20a5}, + {0x20a6, 0x20a6}, + {0x20a7, 0x20a7}, + {0x20a8, 0x20a8}, + {0x20a9, 0x20a9}, + {0x20aa, 0x20aa}, + {0x20ab, 0x20ab}, + {0x20ac, 0x20ac}, + {0xfd01, 0x0000}, + {0xfd02, 0x0000}, + {0xfd03, 0x0000}, + {0xfd04, 0x0000}, + {0xfd05, 0x0000}, + {0xfd06, 0x0000}, + {0xfd07, 0x0000}, + {0xfd08, 0x0000}, + {0xfd09, 0x0000}, + {0xfd0a, 0x0000}, + {0xfd0b, 0x0000}, + {0xfd0c, 0x0000}, + {0xfd0d, 0x0000}, + {0xfd0e, 0x0000}, + {0xfd0f, 0x0000}, + {0xfd10, 0x0000}, + {0xfd11, 0x0000}, + {0xfd12, 0x0000}, + {0xfd13, 0x0000}, + {0xfd14, 0x0000}, + {0xfd15, 0x0000}, + {0xfd16, 0x0000}, + {0xfd17, 0x0000}, + {0xfd18, 0x0000}, + {0xfd19, 0x0000}, + {0xfd1a, 0x0000}, + {0xfd1b, 0x0000}, + {0xfd1c, 0x0000}, + {0xfd1d, 0x0000}, + {0xfd1e, 0x0000}, + {0xfe01, 0x0000}, + {0xfe02, 0x0000}, + {0xfe03, 0x0000}, + {0xfe04, 0x0000}, + {0xfe05, 0x0000}, + {0xfe06, 0x0000}, + {0xfe07, 0x0000}, + {0xfe08, 0x0000}, + {0xfe09, 0x0000}, + {0xfe0a, 0x0000}, + {0xfe0b, 0x0000}, + {0xfe0c, 0x0000}, + {0xfe0d, 0x0000}, + {0xfe0e, 0x0000}, + {0xfe0f, 0x0000}, + {0xfe20, 0x0000}, + {0xfe21, 0x0000}, + {0xfe22, 0x0000}, + {0xfe23, 0x0000}, + {0xfe24, 0x0000}, + {0xfe25, 0x0000}, + {0xfe26, 0x0000}, + {0xfe27, 0x0000}, + {0xfe28, 0x0000}, + {0xfe29, 0x0000}, + {0xfe2a, 0x0000}, + {0xfe2b, 0x0000}, + {0xfe2c, 0x0000}, + {0xfe2d, 0x0000}, + {0xfe2e, 0x0000}, + {0xfe2f, 0x0000}, + {0xfe30, 0x0000}, + {0xfe31, 0x0000}, + {0xfe32, 0x0000}, + {0xfe33, 0x0000}, + {0xfe34, 0x0000}, + {0xfe50, 0x0300}, + {0xfe51, 0x0301}, + {0xfe52, 0x0302}, + {0xfe53, 0x0303}, + {0xfe54, 0x0304}, + {0xfe55, 0x0306}, + {0xfe56, 0x0307}, + {0xfe57, 0x0308}, + {0xfe58, 0x030a}, + {0xfe59, 0x030b}, + {0xfe5a, 0x030c}, + {0xfe5b, 0x0327}, + {0xfe5c, 0x0328}, + {0xfe5d, 0x0345}, + {0xfe5e, 0x3099}, + {0xfe5f, 0x309a}, + {0xfe70, 0x0000}, + {0xfe71, 0x0000}, + {0xfe72, 0x0000}, + {0xfe73, 0x0000}, + {0xfe74, 0x0000}, + {0xfe75, 0x0000}, + {0xfe76, 0x0000}, + {0xfe77, 0x0000}, + {0xfe78, 0x0000}, + {0xfe79, 0x0000}, + {0xfe7a, 0x0000}, + {0xfed0, 0x0000}, + {0xfed1, 0x0000}, + {0xfed2, 0x0000}, + {0xfed4, 0x0000}, + {0xfed5, 0x0000}, + {0xfee0, 0x0000}, + {0xfee1, 0x0000}, + {0xfee2, 0x0000}, + {0xfee3, 0x0000}, + {0xfee4, 0x0000}, + {0xfee5, 0x0000}, + {0xfee6, 0x0000}, + {0xfee7, 0x0000}, + {0xfee8, 0x0000}, + {0xfee9, 0x0000}, + {0xfeea, 0x0000}, + {0xfeeb, 0x0000}, + {0xfeec, 0x0000}, + {0xfeed, 0x0000}, + {0xfeee, 0x0000}, + {0xfeef, 0x0000}, + {0xfef0, 0x0000}, + {0xfef1, 0x0000}, + {0xfef2, 0x0000}, + {0xfef3, 0x0000}, + {0xfef4, 0x0000}, + {0xfef5, 0x0000}, + {0xfef6, 0x0000}, + {0xfef7, 0x0000}, + {0xfef8, 0x0000}, + {0xfef9, 0x0000}, + {0xfefa, 0x0000}, + {0xfefb, 0x0000}, + {0xfefc, 0x0000}, + {0xfefd, 0x0000}, + {0xff08, 0x0008}, + {0xff09, 0x0009}, + {0xff0a, 0x000a}, + {0xff0b, 0x000b}, + {0xff0d, 0x000d}, + {0xff13, 0x0013}, + {0xff14, 0x0014}, + {0xff15, 0x0015}, + {0xff1b, 0x001b}, + {0xff20, 0x0000}, + {0xff21, 0x0000}, + {0xff22, 0x0000}, + {0xff23, 0x0000}, + {0xff24, 0x0000}, + {0xff25, 0x0000}, + {0xff26, 0x0000}, + {0xff27, 0x0000}, + {0xff28, 0x0000}, + {0xff29, 0x0000}, + {0xff2a, 0x0000}, + {0xff2b, 0x0000}, + {0xff2c, 0x0000}, + {0xff2d, 0x0000}, + {0xff2e, 0x0000}, + {0xff2f, 0x0000}, + {0xff30, 0x0000}, + {0xff31, 0x0000}, + {0xff32, 0x0000}, + {0xff33, 0x0000}, + {0xff34, 0x0000}, + {0xff35, 0x0000}, + {0xff36, 0x0000}, + {0xff37, 0x0000}, + {0xff38, 0x0000}, + {0xff39, 0x0000}, + {0xff3a, 0x0000}, + {0xff3b, 0x0000}, + {0xff3c, 0x0000}, + {0xff3d, 0x0000}, + {0xff3e, 0x0000}, + {0xff3f, 0x0000}, + {0xff50, 0x0000}, + {0xff51, 0x0000}, + {0xff52, 0x0000}, + {0xff53, 0x0000}, + {0xff54, 0x0000}, + {0xff55, 0x0000}, + {0xff56, 0x0000}, + {0xff57, 0x0000}, + {0xff58, 0x0000}, + {0xff60, 0x0000}, + {0xff61, 0x0000}, + {0xff62, 0x0000}, + {0xff63, 0x0000}, + {0xff65, 0x0000}, + {0xff66, 0x0000}, + {0xff67, 0x0000}, + {0xff68, 0x0000}, + {0xff69, 0x0000}, + {0xff6a, 0x0000}, + {0xff6b, 0x0000}, + {0xff7e, 0x0000}, + {0xff7f, 0x0000}, + {0xff80, 0x0020}, + {0xff89, 0x0009}, + {0xff8d, 0x000d}, + {0xff91, 0x0000}, + {0xff92, 0x0000}, + {0xff93, 0x0000}, + {0xff94, 0x0000}, + {0xff95, 0x0000}, + {0xff96, 0x0000}, + {0xff97, 0x0000}, + {0xff98, 0x0000}, + {0xff99, 0x0000}, + {0xff9a, 0x0000}, + {0xff9b, 0x0000}, + {0xff9c, 0x0000}, + {0xff9d, 0x0000}, + {0xff9e, 0x0000}, + {0xff9f, 0x0000}, + {0xffaa, 0x002a}, + {0xffab, 0x002b}, + {0xffac, 0x002c}, + {0xffad, 0x002d}, + {0xffae, 0x002e}, + {0xffaf, 0x002f}, + {0xffb0, 0x0030}, + {0xffb1, 0x0031}, + {0xffb2, 0x0032}, + {0xffb3, 0x0033}, + {0xffb4, 0x0034}, + {0xffb5, 0x0035}, + {0xffb6, 0x0036}, + {0xffb7, 0x0037}, + {0xffb8, 0x0038}, + {0xffb9, 0x0039}, + {0xffbd, 0x003d}, + {0xffbe, 0x0000}, + {0xffbf, 0x0000}, + {0xffc0, 0x0000}, + {0xffc1, 0x0000}, + {0xffc2, 0x0000}, + {0xffc3, 0x0000}, + {0xffc4, 0x0000}, + {0xffc5, 0x0000}, + {0xffc6, 0x0000}, + {0xffc7, 0x0000}, + {0xffc8, 0x0000}, + {0xffc9, 0x0000}, + {0xffca, 0x0000}, + {0xffcb, 0x0000}, + {0xffcc, 0x0000}, + {0xffcd, 0x0000}, + {0xffce, 0x0000}, + {0xffcf, 0x0000}, + {0xffd0, 0x0000}, + {0xffd1, 0x0000}, + {0xffd2, 0x0000}, + {0xffd3, 0x0000}, + {0xffd4, 0x0000}, + {0xffd5, 0x0000}, + {0xffd6, 0x0000}, + {0xffd7, 0x0000}, + {0xffd8, 0x0000}, + {0xffd9, 0x0000}, + {0xffda, 0x0000}, + {0xffdb, 0x0000}, + {0xffdc, 0x0000}, + {0xffdd, 0x0000}, + {0xffde, 0x0000}, + {0xffdf, 0x0000}, + {0xffe0, 0x0000}, + {0xffe1, 0x0000}, + {0xffe2, 0x0000}, + {0xffe3, 0x0000}, + {0xffe4, 0x0000}, + {0xffe5, 0x0000}, + {0xffe6, 0x0000}, + {0xffe7, 0x0000}, + {0xffe8, 0x0000}, + {0xffe9, 0x0000}, + {0xffea, 0x0000}, + {0xffeb, 0x0000}, + {0xffec, 0x0000}, + {0xffed, 0x0000}, + {0xffee, 0x0000}, + {0xffff, 0x0000}, + {0xffffff, 0x0000}, + {0x06ad, 0x0491}, + {0x06bd, 0x0490}, + {0x14a1, 0x0000}, + {0x14a2, 0x0587}, + {0x14a3, 0x0589}, + {0x14a4, 0x0029}, + {0x14a5, 0x0028}, + {0x14a6, 0x00bb}, + {0x14a7, 0x00ab}, + {0x14a8, 0x2014}, + {0x14a9, 0x002e}, + {0x14aa, 0x055d}, + {0x14ab, 0x002c}, + {0x14ac, 0x2013}, + {0x14ad, 0x058a}, + {0x14ae, 0x2026}, + {0x14af, 0x055c}, + {0x14b0, 0x055b}, + {0x14b1, 0x055e}, + {0x14b2, 0x0531}, + {0x14b3, 0x0561}, + {0x14b4, 0x0532}, + {0x14b5, 0x0562}, + {0x14b6, 0x0533}, + {0x14b7, 0x0563}, + {0x14b8, 0x0534}, + {0x14b9, 0x0564}, + {0x14ba, 0x0535}, + {0x14bb, 0x0565}, + {0x14bc, 0x0536}, + {0x14bd, 0x0566}, + {0x14be, 0x0537}, + {0x14bf, 0x0567}, + {0x14c0, 0x0538}, + {0x14c1, 0x0568}, + {0x14c2, 0x0539}, + {0x14c3, 0x0569}, + {0x14c4, 0x053a}, + {0x14c5, 0x056a}, + {0x14c6, 0x053b}, + {0x14c7, 0x056b}, + {0x14c8, 0x053c}, + {0x14c9, 0x056c}, + {0x14ca, 0x053d}, + {0x14cb, 0x056d}, + {0x14cc, 0x053e}, + {0x14cd, 0x056e}, + {0x14ce, 0x053f}, + {0x14cf, 0x056f}, + {0x14d0, 0x0540}, + {0x14d1, 0x0570}, + {0x14d2, 0x0541}, + {0x14d3, 0x0571}, + {0x14d4, 0x0542}, + {0x14d5, 0x0572}, + {0x14d6, 0x0543}, + {0x14d7, 0x0573}, + {0x14d8, 0x0544}, + {0x14d9, 0x0574}, + {0x14da, 0x0545}, + {0x14db, 0x0575}, + {0x14dc, 0x0546}, + {0x14dd, 0x0576}, + {0x14de, 0x0547}, + {0x14df, 0x0577}, + {0x14e0, 0x0548}, + {0x14e1, 0x0578}, + {0x14e2, 0x0549}, + {0x14e3, 0x0579}, + {0x14e4, 0x054a}, + {0x14e5, 0x057a}, + {0x14e6, 0x054b}, + {0x14e7, 0x057b}, + {0x14e8, 0x054c}, + {0x14e9, 0x057c}, + {0x14ea, 0x054d}, + {0x14eb, 0x057d}, + {0x14ec, 0x054e}, + {0x14ed, 0x057e}, + {0x14ee, 0x054f}, + {0x14ef, 0x057f}, + {0x14f0, 0x0550}, + {0x14f1, 0x0580}, + {0x14f2, 0x0551}, + {0x14f3, 0x0581}, + {0x14f4, 0x0552}, + {0x14f5, 0x0582}, + {0x14f6, 0x0553}, + {0x14f7, 0x0583}, + {0x14f8, 0x0554}, + {0x14f9, 0x0584}, + {0x14fa, 0x0555}, + {0x14fb, 0x0585}, + {0x14fc, 0x0556}, + {0x14fd, 0x0586}, + {0x14fe, 0x055a}, + {0x14ff, 0x00a7}, + {0x15d0, 0x10d0}, + {0x15d1, 0x10d1}, + {0x15d2, 0x10d2}, + {0x15d3, 0x10d3}, + {0x15d4, 0x10d4}, + {0x15d5, 0x10d5}, + {0x15d6, 0x10d6}, + {0x15d7, 0x10d7}, + {0x15d8, 0x10d8}, + {0x15d9, 0x10d9}, + {0x15da, 0x10da}, + {0x15db, 0x10db}, + {0x15dc, 0x10dc}, + {0x15dd, 0x10dd}, + {0x15de, 0x10de}, + {0x15df, 0x10df}, + {0x15e0, 0x10e0}, + {0x15e1, 0x10e1}, + {0x15e2, 0x10e2}, + {0x15e3, 0x10e3}, + {0x15e4, 0x10e4}, + {0x15e5, 0x10e5}, + {0x15e6, 0x10e6}, + {0x15e7, 0x10e7}, + {0x15e8, 0x10e8}, + {0x15e9, 0x10e9}, + {0x15ea, 0x10ea}, + {0x15eb, 0x10eb}, + {0x15ec, 0x10ec}, + {0x15ed, 0x10ed}, + {0x15ee, 0x10ee}, + {0x15ef, 0x10ef}, + {0x15f0, 0x10f0}, + {0x15f1, 0x10f1}, + {0x15f2, 0x10f2}, + {0x15f3, 0x10f3}, + {0x15f4, 0x10f4}, + {0x15f5, 0x10f5}, + {0x15f6, 0x10f6}, + {0x12a1, 0x1e02}, + {0x12a2, 0x1e03}, + {0x12a6, 0x1e0a}, + {0x12a8, 0x1e80}, + {0x12aa, 0x1e82}, + {0x12ab, 0x1e0b}, + {0x12ac, 0x1ef2}, + {0x12b0, 0x1e1e}, + {0x12b1, 0x1e1f}, + {0x12b4, 0x1e40}, + {0x12b5, 0x1e41}, + {0x12b7, 0x1e56}, + {0x12b8, 0x1e81}, + {0x12b9, 0x1e57}, + {0x12ba, 0x1e83}, + {0x12bb, 0x1e60}, + {0x12bc, 0x1ef3}, + {0x12bd, 0x1e84}, + {0x12be, 0x1e85}, + {0x12bf, 0x1e61}, + {0x12d0, 0x0174}, + {0x12d7, 0x1e6a}, + {0x12de, 0x0176}, + {0x12f0, 0x0175}, + {0x12f7, 0x1e6b}, + {0x12fe, 0x0177}, + {0x0590, 0x06f0}, + {0x0591, 0x06f1}, + {0x0592, 0x06f2}, + {0x0593, 0x06f3}, + {0x0594, 0x06f4}, + {0x0595, 0x06f5}, + {0x0596, 0x06f6}, + {0x0597, 0x06f7}, + {0x0598, 0x06f8}, + {0x0599, 0x06f9}, + {0x05a5, 0x066a}, + {0x05a6, 0x0670}, + {0x05a7, 0x0679}, + {0x05a8, 0x067e}, + {0x05a9, 0x0686}, + {0x05aa, 0x0688}, + {0x05ab, 0x0691}, + {0x05ae, 0x06d4}, + {0x05b0, 0x0660}, + {0x05b1, 0x0661}, + {0x05b2, 0x0662}, + {0x05b3, 0x0663}, + {0x05b4, 0x0664}, + {0x05b5, 0x0665}, + {0x05b6, 0x0666}, + {0x05b7, 0x0667}, + {0x05b8, 0x0668}, + {0x05b9, 0x0669}, + {0x05f3, 0x0653}, + {0x05f4, 0x0654}, + {0x05f5, 0x0655}, + {0x05f6, 0x0698}, + {0x05f7, 0x06a4}, + {0x05f8, 0x06a9}, + {0x05f9, 0x06af}, + {0x05fa, 0x06ba}, + {0x05fb, 0x06be}, + {0x05fc, 0x06cc}, + {0x05fd, 0x06d2}, + {0x05fe, 0x06c1}, + {0x0680, 0x0492}, + {0x0681, 0x0496}, + {0x0682, 0x049a}, + {0x0683, 0x049c}, + {0x0684, 0x04a2}, + {0x0685, 0x04ae}, + {0x0686, 0x04b0}, + {0x0687, 0x04b2}, + {0x0688, 0x04b6}, + {0x0689, 0x04b8}, + {0x068a, 0x04ba}, + {0x068c, 0x04d8}, + {0x068d, 0x04e2}, + {0x068e, 0x04e8}, + {0x068f, 0x04ee}, + {0x0690, 0x0493}, + {0x0691, 0x0497}, + {0x0692, 0x049b}, + {0x0693, 0x049d}, + {0x0694, 0x04a3}, + {0x0695, 0x04af}, + {0x0696, 0x04b1}, + {0x0697, 0x04b3}, + {0x0698, 0x04b7}, + {0x0699, 0x04b9}, + {0x069a, 0x04bb}, + {0x069c, 0x04d9}, + {0x069d, 0x04e3}, + {0x069e, 0x04e9}, + {0x069f, 0x04ef}, + {0x16a2, 0x0000}, + {0x16a3, 0x1e8a}, + {0x16a5, 0x0000}, + {0x16a6, 0x012c}, + {0x16a7, 0x0000}, + {0x16a8, 0x0000}, + {0x16a9, 0x01b5}, + {0x16aa, 0x01e6}, + {0x16af, 0x019f}, + {0x16b2, 0x0000}, + {0x16b3, 0x1e8b}, + {0x16b4, 0x0000}, + {0x16b5, 0x0000}, + {0x16b6, 0x012d}, + {0x16b7, 0x0000}, + {0x16b8, 0x0000}, + {0x16b9, 0x01b6}, + {0x16ba, 0x01e7}, + {0x16bd, 0x01d2}, + {0x16bf, 0x0275}, + {0x16c6, 0x018f}, + {0x16f6, 0x0259}, + {0x16d1, 0x1e36}, + {0x16d2, 0x0000}, + {0x16d3, 0x0000}, + {0x16e1, 0x1e37}, + {0x16e2, 0x0000}, + {0x16e3, 0x0000}, + {0x1ea0, 0x1ea0}, + {0x1ea1, 0x1ea1}, + {0x1ea2, 0x1ea2}, + {0x1ea3, 0x1ea3}, + {0x1ea4, 0x1ea4}, + {0x1ea5, 0x1ea5}, + {0x1ea6, 0x1ea6}, + {0x1ea7, 0x1ea7}, + {0x1ea8, 0x1ea8}, + {0x1ea9, 0x1ea9}, + {0x1eaa, 0x1eaa}, + {0x1eab, 0x1eab}, + {0x1eac, 0x1eac}, + {0x1ead, 0x1ead}, + {0x1eae, 0x1eae}, + {0x1eaf, 0x1eaf}, + {0x1eb0, 0x1eb0}, + {0x1eb1, 0x1eb1}, + {0x1eb2, 0x1eb2}, + {0x1eb3, 0x1eb3}, + {0x1eb4, 0x1eb4}, + {0x1eb5, 0x1eb5}, + {0x1eb6, 0x1eb6}, + {0x1eb7, 0x1eb7}, + {0x1eb8, 0x1eb8}, + {0x1eb9, 0x1eb9}, + {0x1eba, 0x1eba}, + {0x1ebb, 0x1ebb}, + {0x1ebc, 0x1ebc}, + {0x1ebd, 0x1ebd}, + {0x1ebe, 0x1ebe}, + {0x1ebf, 0x1ebf}, + {0x1ec0, 0x1ec0}, + {0x1ec1, 0x1ec1}, + {0x1ec2, 0x1ec2}, + {0x1ec3, 0x1ec3}, + {0x1ec4, 0x1ec4}, + {0x1ec5, 0x1ec5}, + {0x1ec6, 0x1ec6}, + {0x1ec7, 0x1ec7}, + {0x1ec8, 0x1ec8}, + {0x1ec9, 0x1ec9}, + {0x1eca, 0x1eca}, + {0x1ecb, 0x1ecb}, + {0x1ecc, 0x1ecc}, + {0x1ecd, 0x1ecd}, + {0x1ece, 0x1ece}, + {0x1ecf, 0x1ecf}, + {0x1ed0, 0x1ed0}, + {0x1ed1, 0x1ed1}, + {0x1ed2, 0x1ed2}, + {0x1ed3, 0x1ed3}, + {0x1ed4, 0x1ed4}, + {0x1ed5, 0x1ed5}, + {0x1ed6, 0x1ed6}, + {0x1ed7, 0x1ed7}, + {0x1ed8, 0x1ed8}, + {0x1ed9, 0x1ed9}, + {0x1eda, 0x1eda}, + {0x1edb, 0x1edb}, + {0x1edc, 0x1edc}, + {0x1edd, 0x1edd}, + {0x1ede, 0x1ede}, + {0x1edf, 0x1edf}, + {0x1ee0, 0x1ee0}, + {0x1ee1, 0x1ee1}, + {0x1ee2, 0x1ee2}, + {0x1ee3, 0x1ee3}, + {0x1ee4, 0x1ee4}, + {0x1ee5, 0x1ee5}, + {0x1ee6, 0x1ee6}, + {0x1ee7, 0x1ee7}, + {0x1ee8, 0x1ee8}, + {0x1ee9, 0x1ee9}, + {0x1eea, 0x1eea}, + {0x1eeb, 0x1eeb}, + {0x1eec, 0x1eec}, + {0x1eed, 0x1eed}, + {0x1eee, 0x1eee}, + {0x1eef, 0x1eef}, + {0x1ef0, 0x1ef0}, + {0x1ef1, 0x1ef1}, + {0x1ef4, 0x1ef4}, + {0x1ef5, 0x1ef5}, + {0x1ef6, 0x1ef6}, + {0x1ef7, 0x1ef7}, + {0x1ef8, 0x1ef8}, + {0x1ef9, 0x1ef9}, + {0x1efa, 0x01a0}, + {0x1efb, 0x01a1}, + {0x1efc, 0x01af}, + {0x1efd, 0x01b0}, + {0x1e9f, 0x0303}, + {0x1ef2, 0x0300}, + {0x1ef3, 0x0301}, + {0x1efe, 0x0309}, + {0x1eff, 0x0323}, + {0xfe60, 0x0323}, + {0xfe61, 0x0309}, + {0xfe62, 0x031b}, +}; + +static int comparator(const void* a, const void* b) +{ + const uint32_t* aa = (const uint32_t*) a; + const uint32_t* bb = (const uint32_t*) b; + + if (aa[0] < bb[0]) + return -1; + else if (aa[0] > bb[0]) + return 1; + else + return 0; +} + +uint32_t X11KeySymToUCS(uint32_t x11KeySym) +{ + uint32_t key[2] = { x11KeySym, 0 }; + + const uint32_t* found = (uint32_t*) bsearch(key, + x11KeySymToUCSData, + sizeof(x11KeySymToUCSData) / sizeof(x11KeySymToUCSData[0]), + sizeof(x11KeySymToUCSData[0]), + comparator); + + if (found) + return found[1]; + return 0; +} + diff --git a/CoreGraphics/include/CoreGraphics/CGEvent.h b/CoreGraphics/include/CoreGraphics/CGEvent.h index 84401f4a..7d8c9ca0 100644 --- a/CoreGraphics/include/CoreGraphics/CGEvent.h +++ b/CoreGraphics/include/CoreGraphics/CGEvent.h @@ -20,16 +20,122 @@ #ifndef _CGEVENT_H_ #define _CGEVENT_H_ -#import #include -#import +#include +#include +#include +#include __BEGIN_DECLS -extern void CGEventPost(CGEventTapLocation tapLocation, CGEventRef event); -CGError CGPostMouseEvent(CGPoint mouseCursorPosition, - boolean_t updateMouseCursorPosition, - CGButtonCount buttonCount, boolean_t mouseButtonDown, - ...); +extern CFTypeID CGEventGetTypeID(void); + +extern CGEventRef _Nullable CGEventCreate(CGEventSourceRef _Nullable source); +extern CFDataRef _Nullable CGEventCreateData( + CFAllocatorRef _Nullable allocator, + CGEventRef _Nullable event); + +extern CGEventRef _Nullable CGEventCreateFromData( + CFAllocatorRef _Nullable allocator, CFDataRef _Nullable data); +extern CGEventRef _Nullable CGEventCreateMouseEvent( + CGEventSourceRef _Nullable source, + CGEventType mouseType, CGPoint mouseCursorPosition, + CGMouseButton mouseButton); +extern CGEventRef _Nullable CGEventCreateKeyboardEvent( + CGEventSourceRef _Nullable source, + CGKeyCode virtualKey, bool keyDown); +extern CGEventRef _Nullable CGEventCreateScrollWheelEvent( + CGEventSourceRef _Nullable source, + CGScrollEventUnit units, uint32_t wheelCount, int32_t wheel1, ...); + + + +extern CGEventRef _Nullable CGEventCreateScrollWheelEvent2( + CGEventSourceRef _Nullable source, + CGScrollEventUnit units, uint32_t wheelCount, int32_t wheel1, int32_t wheel2, int32_t wheel3); + + + +extern CGEventRef _Nullable CGEventCreateCopy(CGEventRef _Nullable event); +extern CGEventSourceRef _Nullable CGEventCreateSourceFromEvent( + CGEventRef _Nullable event); + + + +extern void CGEventSetSource(CGEventRef _Nullable event, + CGEventSourceRef _Nullable source); + +extern CGEventType CGEventGetType(CGEventRef _Nullable event); + +extern void CGEventSetType(CGEventRef _Nullable event, CGEventType type); + +extern CGEventTimestamp CGEventGetTimestamp(CGEventRef _Nullable event); + +extern void CGEventSetTimestamp(CGEventRef _Nullable event, + CGEventTimestamp timestamp); + +extern CGPoint CGEventGetLocation(CGEventRef _Nullable event); + +extern CGPoint CGEventGetUnflippedLocation(CGEventRef _Nullable event); + +extern void CGEventSetLocation(CGEventRef _Nullable event, CGPoint location); + + +extern CGEventFlags CGEventGetFlags(CGEventRef _Nullable event); + +extern void CGEventSetFlags(CGEventRef _Nullable event, CGEventFlags flags); + +extern void CGEventKeyboardGetUnicodeString(CGEventRef _Nullable event, + UniCharCount maxStringLength, UniCharCount *_Nullable actualStringLength, + UniChar * _Nullable unicodeString); + +extern void CGEventKeyboardSetUnicodeString(CGEventRef _Nullable event, + UniCharCount stringLength, const UniChar * _Nullable unicodeString); + +extern int64_t CGEventGetIntegerValueField(CGEventRef _Nullable event, + CGEventField field); + +extern void CGEventSetIntegerValueField(CGEventRef _Nullable event, + CGEventField field, int64_t value); + +extern double CGEventGetDoubleValueField(CGEventRef _Nullable event, + CGEventField field); +extern void CGEventSetDoubleValueField(CGEventRef _Nullable event, + CGEventField field, double value); + +extern CFMachPortRef _Nullable CGEventTapCreate(CGEventTapLocation tap, + CGEventTapPlacement place, CGEventTapOptions options, + CGEventMask eventsOfInterest, CGEventTapCallBack callback, + void * _Nullable userInfo); + + +extern CFMachPortRef _Nullable CGEventTapCreateForPSN( + void * processSerialNumber, + CGEventTapPlacement place, CGEventTapOptions options, + CGEventMask eventsOfInterest, CGEventTapCallBack callback, + void *_Nullable userInfo); + +extern CFMachPortRef _Nullable CGEventTapCreateForPid(pid_t pid, + CGEventTapPlacement place, CGEventTapOptions options, + CGEventMask eventsOfInterest, CGEventTapCallBack callback, + void * _Nullable userInfo); +extern void CGEventTapEnable(CFMachPortRef tap, bool enable); + +extern bool CGEventTapIsEnabled(CFMachPortRef tap); +extern void CGEventTapPostEvent(CGEventTapProxy _Nullable proxy, + CGEventRef _Nullable event); + +extern void CGEventPost(CGEventTapLocation tap, CGEventRef _Nullable event); +extern void CGEventPostToPSN(void * _Nullable processSerialNumber, + CGEventRef _Nullable event); + +extern void CGEventPostToPid( pid_t pid, + CGEventRef _Nullable event); + +extern CGError CGGetEventTapList(uint32_t maxNumberOfTaps, + CGEventTapInformation * _Nullable tapList, + uint32_t * _Nullable eventTapCount); + +__END_DECLS #endif diff --git a/CoreGraphics/include/CoreGraphics/CGS.h b/CoreGraphics/include/CoreGraphics/CGS.h deleted file mode 100644 index aa38b040..00000000 --- a/CoreGraphics/include/CoreGraphics/CGS.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef _CGS_H_ -#define _CGS_H_ -#include - -#ifdef __cplusplus -extern "C" { -#endif - -// Private APIs - -CGError CGSSetDenyWindowServerConnections(Boolean deny); -void CGSShutdownServerConnections(void); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/CoreGraphics/include/CoreGraphics/CGSConnection.h b/CoreGraphics/include/CoreGraphics/CGSConnection.h index 399a8602..8c6fdb4f 100644 --- a/CoreGraphics/include/CoreGraphics/CGSConnection.h +++ b/CoreGraphics/include/CoreGraphics/CGSConnection.h @@ -18,30 +18,46 @@ */ #ifndef CGSCONNECTION_H #define CGSCONNECTION_H -#include -#import #import +#import +#include +#include #include @class CGSWindow; +@class CGSScreen; +@class CGSKeyboardLayout; @interface CGSConnection : NSObject { - CGSConnectionID _connectionId; - _Atomic CGSWindowID _nextWindowId; - NSMutableDictionary *_windows; + CGSConnectionID _connectionId; + _Atomic CGSWindowID _nextWindowId; + NSMutableDictionary* _windows; } -- (instancetype) initWithConnectionID: (CGSConnectionID) connId; -- (void) dealloc; -- (CGSWindow *) windowForId: (CGSWindowID) winId; -- (CGSWindow *) newWindow: (CGSRegionRef) region; -- (CGError) destroyWindow: (CGSWindowID) winId; +-(instancetype) initWithConnectionID:(CGSConnectionID)connId; +-(void) dealloc; +-(CGSWindow*) windowForId:(CGSWindowID)winId; +-(CGSWindow*) newWindow:(CGSRegionRef)region; +-(CGError) destroyWindow:(CGSWindowID)winId; -+ (BOOL) isAvailable; +// Mouse location in CG coordinates, i.e. relative to the upper left corner +-(CGPoint) mouseLocation; -- (void) _windowInvalidated: (CGSWindowID) winId; +-(BOOL) setMode:(NSDictionary *)mode forScreen:(int)screenIndex; +// Implementations should cache this information, because it may be accessed frequently +-(NSArray*) createScreens; + +// Implementations should also emit kTISNotifySelectedKeyboardInputSourceChanged via NSDistributedNotificationCenter +// if layout changes. +// Implementations should also cache this and return the same pointer if nothing changed. +-(CGSKeyboardLayout*) createKeyboardLayout; + ++(BOOL) isAvailable; + +-(void) _windowInvalidated: (CGSWindowID) winId; // For CGL -- (void *) nativeDisplay; +-(void*) nativeDisplay; @end #endif + diff --git a/CoreGraphics/include/CoreGraphics/CGSKeyboardLayout.h b/CoreGraphics/include/CoreGraphics/CGSKeyboardLayout.h new file mode 100644 index 00000000..7e4d1e50 --- /dev/null +++ b/CoreGraphics/include/CoreGraphics/CGSKeyboardLayout.h @@ -0,0 +1,42 @@ +/* + This file is part of Darling. + + Copyright (C) 2020 Lubos Dolezel + + Darling is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Darling is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Darling. If not, see . +*/ + +#ifndef CGSKEYBOARDLAYOUT_H +#define CGSKEYBOARDLAYOUT_H +#import +#include +#include + +@interface CGSKeyboardLayout : NSObject { + UCKeyboardLayout* _layout; + uint32_t _layoutLength; + NSString* _name; + NSString* _fullName; +} + +@property(readwrite, strong) NSString* name; +@property(readwrite, strong) NSString* fullName; +@property(readonly) UCKeyboardLayout* layout; +@property(readonly) uint32_t layoutLength; + +-(void) setLayout:(UCKeyboardLayout*) layout length:(uint32_t) length; + +@end + +#endif diff --git a/CoreGraphics/include/CoreGraphics/CGSScreen.h b/CoreGraphics/include/CoreGraphics/CGSScreen.h new file mode 100644 index 00000000..20d5f9b2 --- /dev/null +++ b/CoreGraphics/include/CoreGraphics/CGSScreen.h @@ -0,0 +1,42 @@ +/* + This file is part of Darling. + + Copyright (C) 2020 Lubos Dolezel + + Darling is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Darling is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Darling. If not, see . +*/ +#ifndef CGSSCREEN_H +#define CGSSCREEN_H +#import +#import +#import + +@interface CGSScreen : NSObject { + NSData* _edid; + NSArray* _modes; + CFIndex _currentMode; + + uint32_t _currentModeHeightCached; +} + +@property(readwrite, strong) NSData* edid; +@property(readwrite, strong) NSArray* modes; +@property(readwrite, assign) CFIndex currentMode; + +@property(readonly) uint32_t currentModeHeight; + +@end + +#endif + diff --git a/CoreGraphics/include/CoreGraphics/CGSWindow.h b/CoreGraphics/include/CoreGraphics/CGSWindow.h index 74b8eff2..be23cb8e 100644 --- a/CoreGraphics/include/CoreGraphics/CGSWindow.h +++ b/CoreGraphics/include/CoreGraphics/CGSWindow.h @@ -18,42 +18,42 @@ */ #ifndef CGSWINDOW_H #define CGSWINDOW_H -#include #import +#import +#include #include @class CGSSurface; @class CGSConnection; @interface CGSWindow : NSObject { - CGSConnection *_connection; - CGSWindowID _windowId; - _Atomic CGSSurfaceID _nextSurfaceId; - NSMutableDictionary *_surfaces; + CGSConnection* _connection; + CGSWindowID _windowId; + _Atomic CGSSurfaceID _nextSurfaceId; + NSMutableDictionary* _surfaces; } -- (instancetype) initWithRegion: (CGSRegionRef) region - connection: (CGSConnection *) connection - windowID: (CGSWindowID) windowID; -- (void) dealloc; -- (CGSSurface *) surfaceForId: (CGSSurfaceID) surfaceId; +-(instancetype) initWithRegion:(CGSRegionRef) region + connection:(CGSConnection*) connection + windowID:(CGSWindowID) windowID; +-(void) dealloc; +-(CGSSurface*) surfaceForId:(CGSSurfaceID) surfaceId; -- (CGError) orderWindow: (CGSWindowOrderingMode) place - relativeTo: (CGSWindow *) window; -- (CGError) moveTo: (const CGPoint *) point; -- (CGError) setRegion: (CGSRegionRef) region; -- (CGError) getRect: (CGRect *) outRect; -- (CGError) setProperty: (CFStringRef) key value: (CFTypeRef) value; -- (CGError) getProperty: (CFStringRef) key value: (CFTypeRef *) value; -- (void) invalidate; +-(CGError) orderWindow:(CGSWindowOrderingMode) place relativeTo:(CGSWindow*) window; +-(CGError) moveTo:(const CGPoint*) point; +-(CGError) setRegion:(CGSRegionRef) region; +-(CGError) getRect:(CGRect*) outRect; +-(CGError) setProperty:(CFStringRef) key value:(CFTypeRef) value; +-(CGError) getProperty:(CFStringRef) key value:(CFTypeRef*) value; +-(void) invalidate; // Used, for example, by CGWindowContextCreate() -- (void *) nativeWindow; -- (CGSSurface *) createSurface; +-(void*) nativeWindow; +-(CGSSurface*) createSurface; -@property(readonly) CGSWindowID windowId; +@property (readonly) CGSWindowID windowId; -- (void) _surfaceInvalidated: (CGSSurfaceID) surfaceId; +-(void) _surfaceInvalidated:(CGSSurfaceID) surfaceId; @end diff --git a/CoreGraphics/include/CoreGraphics/CoreGraphicsPrivate.h b/CoreGraphics/include/CoreGraphics/CoreGraphicsPrivate.h index 1728e517..8e23218f 100644 --- a/CoreGraphics/include/CoreGraphics/CoreGraphicsPrivate.h +++ b/CoreGraphics/include/CoreGraphics/CoreGraphicsPrivate.h @@ -1,7 +1,8 @@ #ifndef COREGRAPHICSPRIVATE_H #define COREGRAPHICSPRIVATE_H -#include #include +#include +#include __BEGIN_DECLS @@ -12,31 +13,33 @@ __BEGIN_DECLS typedef int CGSConnectionID; typedef int CGSWindowID; typedef int CGSSurfaceID; +typedef unsigned long CGSNotificationType; typedef CFMutableDictionaryRef CGSDictionaryObj; typedef CFTypeRef CGSRegionRef; #define CGSDefaultConnection _CGSDefaultConnection() -enum { - kCGSErrorSuccess = 0, +enum +{ + kCGSErrorSuccess = 0, }; typedef enum { - kCGSOrderBelow = -1, - kCGSOrderOut, /* hides the window */ - kCGSOrderAbove, - kCGSOrderIn /* shows the window */ + kCGSOrderBelow = -1, + kCGSOrderOut, /* hides the window */ + kCGSOrderAbove, + kCGSOrderIn /* shows the window */ } CGSWindowOrderingMode; + typedef enum { - kCGSBackingNonRetianed, - kCGSBackingRetained, - kCGSBackingBuffered, + kCGSBackingNonRetianed, + kCGSBackingRetained, + kCGSBackingBuffered, } CGSBackingType; extern void CGSInitialize(void); -extern CGError CGSNewConnection(_Nullable CGSDictionaryObj attribs, - CGSConnectionID *connId); +extern CGError CGSNewConnection(_Nullable CGSDictionaryObj attribs, CGSConnectionID* connId); extern CGError CGSReleaseConnection(CGSConnectionID connId); extern CGSConnectionID _CGSDefaultConnection(void); extern CGSConnectionID CGSMainConnectionID(void); @@ -44,81 +47,95 @@ extern CGError CGSSetDenyWindowServerConnections(Boolean deny); extern void CGSShutdownServerConnections(void); // CGSRegion -extern CGError CGSNewRegionWithRect(const CGRect *rect, - CGSRegionRef *newRegion); +extern CGError CGSNewRegionWithRect(const CGRect * rect, CGSRegionRef *newRegion); extern void CGSRegionRelease(CGSRegionRef reg); extern void CGSRegionRetain(CGSRegionRef reg); -extern void -CGSRegionToRect(CGSRegionRef reg, - CGRect *rect); // This is non-standard. We should support - // non-rectangular regions instead +extern void CGSRegionToRect(CGSRegionRef reg, CGRect* rect); // This is non-standard. We should support non-rectangular regions instead extern bool CGSRegionIsRectangular(CGSRegionRef reg); -extern CGError CGSNewWindow(CGSConnectionID conn, CFIndex flags, float, float, - const CGSRegionRef region, CGSWindowID *windowID); +extern CGError CGSNewWindow(CGSConnectionID conn, CFIndex flags, float, float, const CGSRegionRef region, CGSWindowID* windowID); extern CGError CGSReleaseWindow(CGSConnectionID cid, CGSWindowID wid); -extern CGError CGSSetWindowShape(CGSConnectionID cid, CGSWindowID wid, - float x_offset, float y_offset, - const CGSRegionRef shape); -extern OSStatus CGSOrderWindow(CGSConnectionID cid, CGSWindowID wid, - CGSWindowOrderingMode place, - CGSWindowID relativeToWindow); -extern CGError CGSMoveWindow(CGSConnectionID cid, CGSWindowID wid, - const CGPoint *window_pos); -extern CGError CGSSetWindowOpacity(CGSConnectionID cid, CGSWindowID wid, - bool isOpaque); -extern CGError CGSSetWindowAlpha(CGSConnectionID cid, CGSWindowID wid, - float alpha); -extern CGError CGSSetWindowLevel(CGSConnectionID cid, CGSWindowID wid, - CGWindowLevel level); +extern CGError CGSSetWindowShape(CGSConnectionID cid, CGSWindowID wid, float x_offset, float y_offset, const CGSRegionRef shape); +extern OSStatus CGSOrderWindow(CGSConnectionID cid, CGSWindowID wid, CGSWindowOrderingMode place, CGSWindowID relativeToWindow); +extern CGError CGSMoveWindow(CGSConnectionID cid, CGSWindowID wid, const CGPoint *window_pos); +extern CGError CGSSetWindowOpacity(CGSConnectionID cid, CGSWindowID wid, bool isOpaque); +extern CGError CGSSetWindowAlpha(CGSConnectionID cid, CGSWindowID wid, float alpha); +extern CGError CGSSetWindowLevel(CGSConnectionID cid, CGSWindowID wid, CGWindowLevel level); // Subwindows (for CGL) -extern CGError CGSAddSurface(CGSConnectionID cid, CGSWindowID wid, - CGSSurfaceID *sid); -extern CGError CGSRemoveSurface(CGSConnectionID cid, CGSWindowID wid, - CGSSurfaceID sid); -extern CGError CGSSetSurfaceBounds(CGSConnectionID cid, CGSWindowID wid, - CGSSurfaceID sid, CGRect rect); -extern CGError CGSOrderSurface(CGSConnectionID cid, CGSWindowID wid, - CGSSurfaceID sid, int a, int b); -// extern CGLError CGLSetSurface(CGLContextObj gl, CGSConnectionID cid, -// CGSWindowID wid, CGSSurfaceID sid); // in CGL +extern CGError CGSAddSurface(CGSConnectionID cid, CGSWindowID wid, CGSSurfaceID *sid); +extern CGError CGSRemoveSurface(CGSConnectionID cid, CGSWindowID wid, CGSSurfaceID sid); +extern CGError CGSSetSurfaceBounds(CGSConnectionID cid, CGSWindowID wid, CGSSurfaceID sid, CGRect rect); +extern CGError CGSOrderSurface(CGSConnectionID cid, CGSWindowID wid, CGSSurfaceID sid, int a, int b); +//extern CGLError CGLSetSurface(CGLContextObj gl, CGSConnectionID cid, CGSWindowID wid, CGSSurfaceID sid); // in CGL -// extern CGContextRef CGWindowContextCreate(CGSConnectionID cid, CGSWindowID -// wid, CFDictionaryRef options); // in CGL +//extern CGContextRef CGWindowContextCreate(CGSConnectionID cid, CGSWindowID wid, CFDictionaryRef options); // in CGL -extern CGError CGSSetWindowTags(CGSConnectionID cid, CGSWindowID wid, - const int tags[2], size_t tag_size); -extern CGError CGSClearWindowTags(CGSConnectionID cid, CGSWindowID wid, - const int tags[2], size_t tag_size); -extern CGError CGSAddActivationRegion(CGSConnectionID cid, CGSWindowID wid, - CGSRegionRef region); +extern CGError CGSSetWindowTags(CGSConnectionID cid, CGSWindowID wid, const int tags[2], size_t tag_size); +extern CGError CGSClearWindowTags(CGSConnectionID cid, CGSWindowID wid, const int tags[2], size_t tag_size); +extern CGError CGSAddActivationRegion(CGSConnectionID cid, CGSWindowID wid, CGSRegionRef region); extern CGError CGSClearActivationRegion(CGSConnectionID cid, CGSWindowID wid); -extern CGError CGSAddDragRegion(CGSConnectionID cid, CGSWindowID wid, - CGSRegionRef region); +extern CGError CGSAddDragRegion(CGSConnectionID cid, CGSWindowID wid, CGSRegionRef region); extern CGError CGSClearDragRegion(CGSConnectionID cid, CGSWindowID wid); -extern CGError CGSAddTrackingRect(CGSConnectionID cid, CGSWindowID wid, - CGRect rect); +extern CGError CGSAddTrackingRect(CGSConnectionID cid, CGSWindowID wid, CGRect rect); extern CGError CGSRemoveAllTrackingAreas(CGSConnectionID cid, CGSWindowID wid); -extern CFStringRef CGSCopyManagedDisplayForWindow(const CGSConnectionID cid, - CGSWindowID wid); -extern CGError CGSGetScreenRectForWindow(CGSConnectionID cid, CGSWindowID wid, - CGRect *outRect); +extern CFStringRef CGSCopyManagedDisplayForWindow(const CGSConnectionID cid, CGSWindowID wid); +extern CGError CGSGetScreenRectForWindow(CGSConnectionID cid, CGSWindowID wid, CGRect *outRect); extern const CFStringRef kCGSWindowTitle; -extern CGError CGSSetWindowTitle(CGSConnectionID cid, CGSWindowID wid, - CFStringRef title); -extern CGError CGSGetWindowProperty(CGSConnectionID cid, CGSWindowID wid, - CFStringRef key, CFTypeRef *outValue); -extern CGError CGSSetWindowProperty(CGSConnectionID cid, CGSWindowID wid, - CFStringRef key, CFTypeRef value); +extern CGError CGSSetWindowTitle(CGSConnectionID cid, CGSWindowID wid, CFStringRef title); +extern CGError CGSGetWindowProperty(CGSConnectionID cid, CGSWindowID wid, CFStringRef key, CFTypeRef *outValue); +extern CGError CGSSetWindowProperty(CGSConnectionID cid, CGSWindowID wid, CFStringRef key, CFTypeRef value); + +typedef uint32_t CGSByteCount; +typedef uint16_t CGSEventRecordVersion; +typedef unsigned long CGSEventType; +typedef uint64_t CGSEventRecordTime; /* nanosecond timer */ +typedef unsigned long CGSEventFlag; +typedef NXEventData CGSEventRecordData; + +struct _CGSEventRecord +{ + CGSEventRecordVersion major; + CGSEventRecordVersion minor; + CGSByteCount length; /* Length of complete event record */ + CGSEventType type; /* An event type from above */ + CGPoint location; /* Base coordinates (global), from upper-left */ + CGPoint windowLocation; /* Coordinates relative to window */ + CGSEventRecordTime time; /* nanoseconds since startup */ + CGSEventFlag flags; /* key state flags */ + CGSWindowID window; /* window number of assigned window */ + CGSConnectionID connection; /* connection the event came from */ + CGSEventRecordData data; /* type-dependent data: 40 bytes */ +}; +typedef struct _CGSEventRecord CGSEventRecord; +typedef CGSEventRecord *CGSEventRecordPtr; + +typedef void(*CGSNotifyProcPtr)(CGSNotificationType type, void* data, unsigned long dataLength, void* client); + +// CGSNotificationType: +// 710 + NX event type from IOLLEvent.h +#define CGSNotificationSingleEventType(event) (701 + event) +#define kCGSNotificationAllEvents 0 +extern CGError CGSRegisterNotifyProc(CGSNotifyProcPtr proc, CGSNotificationType notificationType, void* client); +extern CGError CGSRemoveNotifyProc(CGSNotifyProcPtr proc, CGSNotificationType notificationType); // Darling extras, e.g. for CGL -void *_CGSNativeDisplay(CGSConnectionID connId); -void *_CGSNativeWindowForID(CGSConnectionID connId, CGSWindowID winId); -void *_CGSNativeWindowForSurfaceID(CGSConnectionID connId, CGSWindowID winId, - CGSSurfaceID surfaceId); +void* _CGSNativeDisplay(CGSConnectionID connId); +void* _CGSNativeWindowForID(CGSConnectionID connId, CGSWindowID winId); +void* _CGSNativeWindowForSurfaceID(CGSConnectionID connId, CGSWindowID winId, CGSSurfaceID surfaceId); + +extern CGEventRef CGEventCreateWithEventRecord(const CGSEventRecordPtr event, uint32_t eventRecordSize); +extern CGError CGEventGetEventRecord(CGEventRef event, CGSEventRecordPtr eventRecord, uint32_t eventRecordSize); +extern CGError CGEventSetEventRecord(CGEventRef event, CGSEventRecordPtr eventRecord, uint32_t eventRecordSize); +extern uint32_t CGEventGetEventRecordSize(CGEventRef event); + +#ifdef __OBJC__ +@class CGSConnection; +CGSConnection* _CGSConnectionForID(CGSConnectionID connId); +CGSConnection* _CGSConnectionFromEventRecord(const CGSEventRecordPtr record); +#endif __END_DECLS