/ CoreGraphics / CGEventObjC.h
CGEventObjC.h
  1  /*
  2   This file is part of Darling.
  3  
  4   Copyright (C) 2020 Lubos Dolezel
  5  
  6   Darling is free software: you can redistribute it and/or modify
  7   it under the terms of the GNU General Public License as published by
  8   the Free Software Foundation, either version 3 of the License, or
  9   (at your option) any later version.
 10  
 11   Darling is distributed in the hope that it will be useful,
 12   but WITHOUT ANY WARRANTY; without even the implied warranty of
 13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 14   GNU General Public License for more details.
 15  
 16   You should have received a copy of the GNU General Public License
 17   along with Darling.  If not, see <http://www.gnu.org/licenses/>.
 18  */
 19  
 20  #ifndef CGEVENT_OBJC_H
 21  #define CGEVENT_OBJC_H
 22  #include <CoreGraphics/CGEvent.h>
 23  #include <CoreFoundation/CFBase.h>
 24  #import <Foundation/NSObject.h>
 25  #import <Foundation/NSDictionary.h>
 26  #import <Foundation/NSData.h>
 27  
 28  @class CGEventSource;
 29  
 30  @interface CGEvent : NSObject <NSCopying, NSCoding> {
 31  	CGEventSource* _source;
 32  	CGEventType _type;
 33  	CGEventTimestamp _timestamp;
 34  	CGEventFlags _flags;
 35  	NSMutableDictionary<NSNumber*, NSNumber*>* _fields;
 36  
 37  	// keyboard events
 38  	CGKeyCode _virtualKey;
 39  	UniChar _unicodeString[5];
 40  
 41  	// mouse button events
 42  	CGPoint _location;
 43  	CGMouseButton _mouseButton;
 44  
 45  	CGSEventRecordPtr _eventRecord;
 46  	uint32_t _eventRecordLength;
 47  }
 48  -(instancetype) initWithSource:(CGEventSource*) source;
 49  -(instancetype) initWithSource:(CGEventSource*) source
 50  						type:(CGEventType) type;
 51  -(instancetype) initWithEventRecord:(const CGSEventRecordPtr) eventRecord
 52  							length:(uint32_t) length;
 53  
 54  -(void) dealloc;
 55  -(id)copy;
 56  -(CFTypeID) _cfTypeID;
 57  
 58  -(void) setEventRecord:(CGSEventRecordPtr) record
 59  				length:(uint32_t) length;
 60  @property(readonly) uint32_t eventRecordLength;
 61  @property(readonly) CGSEventRecordPtr eventRecord;
 62  
 63  @property(readwrite) CGEventType type;
 64  @property(retain) CGEventSource* source;
 65  @property(readwrite) CGEventTimestamp timestamp;
 66  @property(readwrite) CGEventFlags flags;
 67  @property(readonly) NSMutableDictionary<NSNumber*, NSNumber*>* fields;
 68  
 69  @property(readwrite) CGKeyCode virtualKey;
 70  
 71  @property(readwrite) CGPoint location;
 72  @property(readwrite) CGMouseButton mouseButton;
 73  
 74  @property(readonly) UniChar* unicodeString;
 75  
 76  @end
 77  
 78  //////////////////////////////////////////////////////////////////////
 79  
 80  @interface CGEventSource : NSObject {
 81  	CGEventSourceStateID _stateId;
 82  	CGEventSourceKeyboardType _keyboardType;
 83  	int64_t _userData;
 84  	double _pixelsPerLine;
 85  }
 86  -(instancetype) initWithState: (CGEventSourceStateID) stateId;
 87  -(CFTypeID) _cfTypeID;
 88  +(CGEventSource*) hidEventSource;
 89  
 90  @property CGEventSourceKeyboardType keyboardType;
 91  @property CGEventSourceStateID stateID;
 92  @property int64_t userData;
 93  @property double pixelsPerLine;
 94  
 95  @end
 96  
 97  //////////////////////////////////////////////////////////////////////
 98  
 99  @interface CGEventTap : NSObject {
100  	CGEventTapLocation _location;
101  	CGEventTapOptions _options;
102  	CGEventMask _mask;
103  	CGEventTapCallBack _callback;
104  	void* _userInfo;
105  	Boolean _enabled;
106  
107  	mach_port_t _machPort;
108  }
109  
110  -(instancetype) initWithLocation: (CGEventTapLocation) location
111  						options: (CGEventTapOptions) options
112  							mask: (CGEventMask) mask
113  						callback: (CGEventTapCallBack) callback
114  						userInfo: (void*) userInfo;
115  
116  -(void) dealloc;
117  -(CFMachPortRef) createCFMachPort;
118  
119  @property(readonly) mach_port_t machPort;
120  @property(readonly) CGEventTapOptions options;
121  @property(readonly) CGEventMask mask;
122  @property(readonly) CGEventTapCallBack callback;
123  @property(readonly) void* userInfo;
124  @property Boolean enabled;
125  
126  @end
127  
128  #endif
129