15#include <Carbon/Carbon.h>
16#include <IOKit/IOMessage.h>
17#include <mach/mach_init.h>
18#include <mach/mach_interface.h>
19#include <mach/mach_port.h>
34template <
class T>
class CondVar;
59 void getShape(int32_t &
x, int32_t &
y, int32_t &width, int32_t &height)
const override;
83 void enter()
override;
85 void leave()
override;
106 bool updateScreenShape();
107 bool updateScreenShape(
const CGDirectDisplayID,
const CGDisplayChangeSummaryFlags);
108 void postMouseEvent(CGPoint &)
const;
119 bool onMouseButton(
bool pressed, uint16_t macButton);
120 bool onMouseWheel(int32_t xDelta, int32_t yDelta)
const;
122 void constructMouseButtonEventMap();
124 bool onKey(CGEventRef event);
126 void onMediaKey(CGEventRef event);
128 bool onHotKey(EventRef event)
const;
135 ButtonID mapDeskflowButtonToMac(uint16_t)
const;
138 ButtonID mapMacButtonToDeskflow(uint16_t)
const;
141 int32_t mapScrollWheelToDeskflow(int32_t)
const;
144 double getScrollSpeed()
const;
147 static void displayReconfigurationCallback(CGDirectDisplayID, CGDisplayChangeSummaryFlags,
void *);
150 static pascal OSStatus userSwitchCallback(EventHandlerCallRef nextHandler, EventRef theEvent,
void *inUserData);
153 void watchSystemPowerThread(
const void *);
154 static void testCanceled(CFRunLoopTimerRef timer,
void *info);
155 static void powerChangeCallback(
void *refcon, io_service_t service, natural_t messageType,
void *messageArgument);
156 void handlePowerChangeRequest(natural_t messageType,
void *messageArgument);
158 void handleConfirmSleep(
const Event &event);
161 static bool isGlobalHotKeyOperatingModeAvailable();
162 static void setGlobalHotKeysEnabled(
bool enabled);
163 static bool getGlobalHotKeysEnabled();
166 static CGEventRef handleCGInputEvent(CGEventTapProxy proxy, CGEventType
type, CGEventRef event,
void *refcon);
168 handleCGInputEventSecondary(CGEventTapProxy proxy, CGEventType
type, CGEventRef event,
void *refcon);
171 static char *CFStringRefToUTF8String(CFStringRef aString);
177 HotKeyItem(uint32_t, uint32_t);
178 HotKeyItem(EventHotKeyRef, uint32_t, uint32_t);
180 EventHotKeyRef getRef()
const;
182 bool operator<(
const HotKeyItem &)
const;
185 EventHotKeyRef m_ref;
190 enum EMouseButtonState
198 class MouseButtonState
201 void set(uint32_t button, EMouseButtonState state);
204 void overwrite(uint32_t buttons);
206 bool test(uint32_t button)
const;
207 int8_t getFirstButtonDown()
const;
210 std::bitset<NumButtonIDs> m_buttons;
213 using HotKeyMap = std::map<uint32_t, HotKeyItem>;
214 using HotKeyIDList = std::vector<uint32_t>;
215 using ModifierHotKeyMap = std::map<KeyModifierMask, uint32_t>;
216 using HotKeyToIDMap = std::map<HotKeyItem, uint32_t>;
225 CGDirectDisplayID m_displayID;
227 uint32_t m_activeSides = 0;
231 int32_t m_xCenter, m_yCenter;
234 mutable int32_t m_xCursor, m_yCursor;
235 mutable bool m_cursorPosValid;
243 mutable MouseButtonState m_buttonState;
244 using MouseButtonEventMapType = std::map<uint16_t, CGEventType>;
245 std::vector<MouseButtonEventMapType> MouseButtonEventMap;
250 OSXKeyState *m_keyState;
253 OSXClipboard m_pasteboard;
254 uint32_t m_sequenceNumber;
257 OSXScreenSaver *m_screensaver;
258 bool m_screensaverNotify;
262 EventQueueTimer *m_clipboardTimer;
266 WindowRef m_hiddenWindow;
269 WindowRef m_userInputWindow;
272 EventHandlerRef m_switchEventHandlerRef;
276 Thread *m_pmWatchThread;
277 CondVar<bool> *m_pmThreadReady;
278 CFRunLoopRef m_pmRunloop;
279 io_connect_t m_pmRootPort;
283 HotKeyIDList m_oldHotKeyIDs;
284 ModifierHotKeyMap m_modifierHotKeys;
285 uint32_t m_activeModifierHotKey;
287 HotKeyToIDMap m_hotKeyToIDMap;
290 static bool s_testedForGHOM;
291 static bool s_hasGHOM;
294 CFMachPortRef m_eventTapPort;
295 CFRunLoopSourceRef m_eventTapRLSR;
296 std::thread m_eventTapThread;
297 CFRunLoopRef m_eventTapRunLoop =
nullptr;
300 double m_lastClickTime;
302 int32_t m_lastSingleClickXCursor;
303 int32_t m_lastSingleClickYCursor;
305 IEventQueue *m_events;
307 std::unique_ptr<Thread> m_getDropTargetThread;
308 std::string m_dropTarget;
310 Mutex *m_carbonLoopMutex;
311 CondVar<bool> *m_carbonLoopReady;
313 OSXPowerManager m_powerManager;
315 class OSXScreenImpl *m_impl;
static int type
Definition ArchNetworkWinsock.cpp:45
static int(PASCAL FAR *bind_winsock)(SOCKET s
uint8_t ClipboardID
Clipboard ID.
Definition ClipboardTypes.h:16
Coordinate ScrollDelta
Definition Coordinate.h:21
int key
Definition KeySequence.cpp:15
uint32_t KeyID
Key ID.
Definition KeyTypes.h:21
uint32_t KeyModifierMask
Modifier key mask.
Definition KeyTypes.h:44
uint8_t ButtonID
Mouse button ID.
Definition MouseTypes.h:16
CGError CGSSetConnectionProperty(CGSConnectionID cid, CGSConnectionID targetCID, CFStringRef key, CFTypeRef value)
int CGSConnectionID
Definition OSXScreen.h:29
int _CGSDefaultConnection()
std::vector< uint32_t > OptionsList
Definition OptionTypes.h:26
int y
Definition ServerConfig.cpp:24
int x
Definition ServerConfig.cpp:23
Condition variable.
Definition CondVar.h:121
Definition EventQueueTimer.h:12
Event.
Definition Event.h:29
Clipboard interface.
Definition IClipboard.h:19
Event queue interface.
Definition IEventQueue.h:29
Key state interface.
Definition IKeyState.h:23
Mutual exclusion.
Definition Mutex.h:22
OS X key state.
Definition OSXKeyState.h:25
OSX screen saver implementation.
Definition OSXScreenSaver.h:18
void fakeMouseMove(int32_t x, int32_t y) override
Fake mouse move.
Definition OSXScreen.mm:551
std::string getSecureInputApp() const override
Determine the name of the app causing a secure input state.
Definition OSXScreen.mm:1791
void unregisterHotKey(uint32_t id) override
Unregister a system hotkey.
Definition OSXScreen.mm:358
uint32_t registerHotKey(KeyID key, KeyModifierMask mask) override
Register a system hotkey.
Definition OSXScreen.mm:305
bool canLeave() override
Leave screen.
Definition OSXScreen.mm:771
void handleSystemEvent(const Event &e) override
Handle system event.
Definition OSXScreen.mm:864
void enter() override
Enter screen.
Definition OSXScreen.mm:747
OSXScreen(IEventQueue *events, bool isPrimary, bool enableLangSync=false)
Definition OSXScreen.mm:78
virtual ~OSXScreen()
Definition OSXScreen.mm:178
uint32_t activeSides() override
activeSides
Definition OSXScreen.mm:255
void getCursorCenter(int32_t &x, int32_t &y) const override
Get cursor center position.
Definition OSXScreen.mm:299
void fakeInputEnd() override
Done synthesizing input on primary screen.
Definition OSXScreen.mm:279
void enable() override
Enable screen.
Definition OSXScreen.mm:656
void * getEventTarget() const override
Get event target.
Definition OSXScreen.mm:217
void reconfigure(uint32_t activeSides) override
Update configuration.
Definition OSXScreen.mm:248
void disable() override
Disable screen.
Definition OSXScreen.mm:712
void fakeMouseRelativeMove(int32_t dx, int32_t dy) const override
Fake mouse move.
Definition OSXScreen.mm:565
void screensaver(bool activate) override
Activate/deactivate screen saver.
Definition OSXScreen.mm:822
void setSequenceNumber(uint32_t) override
Set clipboard sequence number.
Definition OSXScreen.mm:841
bool isAnyMouseButtonDown(uint32_t &buttonID) const override
Test if mouse is pressed.
Definition OSXScreen.mm:289
void warpCursor(int32_t x, int32_t y) override
Warp cursor.
Definition OSXScreen.mm:260
void fakeMouseButton(ButtonID id, bool press) override
Fake mouse press/release.
Definition OSXScreen.mm:483
void leave() override
Leave screen.
Definition OSXScreen.mm:776
void openScreensaver(bool notify) override
Open screen saver.
Definition OSXScreen.mm:807
void getCursorPos(int32_t &x, int32_t &y) const override
Get cursor position.
Definition OSXScreen.mm:236
void getShape(int32_t &x, int32_t &y, int32_t &width, int32_t &height) const override
Get screen shape.
Definition OSXScreen.mm:228
void checkClipboards() override
Check clipboard owner.
Definition OSXScreen.mm:797
int32_t getJumpZoneSize() const override
Get jump zone size.
Definition OSXScreen.mm:284
bool setClipboard(ClipboardID, const IClipboard *) override
Set clipboard.
Definition OSXScreen.mm:788
bool isPrimary() const override
Test if is primary screen.
Definition OSXScreen.mm:846
IEventQueue * getEvents() const
Definition OSXScreen.h:51
void fakeMouseWheel(ScrollDelta delta) const override
Synthesize a mouse wheel event of amount This Implmentation for this method should call applyScrollMo...
Definition OSXScreen.mm:589
void closeScreensaver() override
Close screen saver.
Definition OSXScreen.mm:815
bool getClipboard(ClipboardID id, IClipboard *) const override
Get clipboard.
Definition OSXScreen.mm:222
void setOptions(const OptionsList &options) override
Notify of options changes.
Definition OSXScreen.mm:836
void waitForCarbonLoop() const
Definition OSXScreen.mm:1769
IKeyState * getKeyState() const override
Get the key state.
Definition OSXScreen.mm:1277
void fakeInputBegin() override
Prepare to synthesize input on primary screen.
Definition OSXScreen.mm:274
void resetOptions() override
Notify of options changes.
Definition OSXScreen.mm:831
void updateButtons() override
Update mouse buttons.
Definition OSXScreen.mm:1270
Thread handle.
Definition Thread.h:33
EventTypes
Definition EventTypes.h:13