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>
33template <
class T>
class CondVar;
58 void getShape(int32_t &
x, int32_t &
y, int32_t &width, int32_t &height)
const override;
82 void enter()
override;
84 void leave()
override;
105 bool updateScreenShape();
106 bool updateScreenShape(
const CGDirectDisplayID,
const CGDisplayChangeSummaryFlags);
107 void postMouseEvent(CGPoint &)
const;
118 bool onMouseButton(
bool pressed, uint16_t macButton);
119 bool onMouseWheel(int32_t xDelta, int32_t yDelta)
const;
121 void constructMouseButtonEventMap();
123 bool onKey(CGEventRef event);
125 void onMediaKey(CGEventRef event);
127 bool onHotKey(EventRef event)
const;
134 ButtonID mapDeskflowButtonToMac(uint16_t)
const;
137 ButtonID mapMacButtonToDeskflow(uint16_t)
const;
140 int32_t mapScrollWheelToDeskflow(int32_t)
const;
143 double getScrollSpeed()
const;
146 static void displayReconfigurationCallback(CGDirectDisplayID, CGDisplayChangeSummaryFlags,
void *);
149 static pascal OSStatus userSwitchCallback(EventHandlerCallRef nextHandler, EventRef theEvent,
void *inUserData);
152 void watchSystemPowerThread(
const void *);
153 static void testCanceled(CFRunLoopTimerRef timer,
void *info);
154 static void powerChangeCallback(
void *refcon, io_service_t service, natural_t messageType,
void *messageArgument);
155 void handlePowerChangeRequest(natural_t messageType,
void *messageArgument);
157 void handleConfirmSleep(
const Event &event);
160 static bool isGlobalHotKeyOperatingModeAvailable();
161 static void setGlobalHotKeysEnabled(
bool enabled);
162 static bool getGlobalHotKeysEnabled();
165 static CGEventRef handleCGInputEvent(CGEventTapProxy proxy, CGEventType
type, CGEventRef event,
void *refcon);
167 handleCGInputEventSecondary(CGEventTapProxy proxy, CGEventType
type, CGEventRef event,
void *refcon);
170 static char *CFStringRefToUTF8String(CFStringRef aString);
176 HotKeyItem(uint32_t, uint32_t);
177 HotKeyItem(EventHotKeyRef, uint32_t, uint32_t);
179 EventHotKeyRef getRef()
const;
181 bool operator<(
const HotKeyItem &)
const;
184 EventHotKeyRef m_ref;
189 enum EMouseButtonState
197 class MouseButtonState
200 void set(uint32_t button, EMouseButtonState state);
203 void overwrite(uint32_t buttons);
205 bool test(uint32_t button)
const;
206 int8_t getFirstButtonDown()
const;
209 std::bitset<NumButtonIDs> m_buttons;
212 using HotKeyMap = std::map<uint32_t, HotKeyItem>;
213 using HotKeyIDList = std::vector<uint32_t>;
214 using ModifierHotKeyMap = std::map<KeyModifierMask, uint32_t>;
215 using HotKeyToIDMap = std::map<HotKeyItem, uint32_t>;
224 CGDirectDisplayID m_displayID;
226 uint32_t m_activeSides = 0;
230 int32_t m_xCenter, m_yCenter;
233 mutable int32_t m_xCursor, m_yCursor;
234 mutable bool m_cursorPosValid;
242 mutable MouseButtonState m_buttonState;
243 using MouseButtonEventMapType = std::map<uint16_t, CGEventType>;
244 std::vector<MouseButtonEventMapType> MouseButtonEventMap;
249 OSXKeyState *m_keyState;
252 OSXClipboard m_pasteboard;
253 uint32_t m_sequenceNumber;
256 OSXScreenSaver *m_screensaver;
257 bool m_screensaverNotify;
261 EventQueueTimer *m_clipboardTimer;
265 WindowRef m_hiddenWindow;
268 WindowRef m_userInputWindow;
271 EventHandlerRef m_switchEventHandlerRef;
275 Thread *m_pmWatchThread;
276 CondVar<bool> *m_pmThreadReady;
277 CFRunLoopRef m_pmRunloop;
278 io_connect_t m_pmRootPort;
282 HotKeyIDList m_oldHotKeyIDs;
283 ModifierHotKeyMap m_modifierHotKeys;
284 uint32_t m_activeModifierHotKey;
286 HotKeyToIDMap m_hotKeyToIDMap;
289 static bool s_testedForGHOM;
290 static bool s_hasGHOM;
293 CFMachPortRef m_eventTapPort;
294 CFRunLoopSourceRef m_eventTapRLSR;
297 double m_lastClickTime;
299 int32_t m_lastSingleClickXCursor;
300 int32_t m_lastSingleClickYCursor;
302 IEventQueue *m_events;
304 std::unique_ptr<Thread> m_getDropTargetThread;
305 std::string m_dropTarget;
307 Mutex *m_carbonLoopMutex;
308 CondVar<bool> *m_carbonLoopReady;
310 OSXPowerManager m_powerManager;
312 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:28
int _CGSDefaultConnection()
std::vector< uint32_t > OptionsList
Definition OptionTypes.h:26
int y
Definition ServerConfig.cpp:25
int x
Definition ServerConfig.cpp:24
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:550
std::string getSecureInputApp() const override
Determine the name of the app causing a secure input state.
Definition OSXScreen.mm:1771
void unregisterHotKey(uint32_t id) override
Unregister a system hotkey.
Definition OSXScreen.mm:357
uint32_t registerHotKey(KeyID key, KeyModifierMask mask) override
Register a system hotkey.
Definition OSXScreen.mm:304
bool canLeave() override
Leave screen.
Definition OSXScreen.mm:751
void handleSystemEvent(const Event &e) override
Handle system event.
Definition OSXScreen.mm:844
void enter() override
Enter screen.
Definition OSXScreen.mm:727
OSXScreen(IEventQueue *events, bool isPrimary, bool enableLangSync=false)
Definition OSXScreen.mm:77
virtual ~OSXScreen()
Definition OSXScreen.mm:177
uint32_t activeSides() override
activeSides
Definition OSXScreen.mm:254
void getCursorCenter(int32_t &x, int32_t &y) const override
Get cursor center position.
Definition OSXScreen.mm:298
void fakeInputEnd() override
Done synthesizing input on primary screen.
Definition OSXScreen.mm:278
void enable() override
Enable screen.
Definition OSXScreen.mm:655
void * getEventTarget() const override
Get event target.
Definition OSXScreen.mm:216
void reconfigure(uint32_t activeSides) override
Update configuration.
Definition OSXScreen.mm:247
void disable() override
Disable screen.
Definition OSXScreen.mm:698
void fakeMouseRelativeMove(int32_t dx, int32_t dy) const override
Fake mouse move.
Definition OSXScreen.mm:564
void screensaver(bool activate) override
Activate/deactivate screen saver.
Definition OSXScreen.mm:802
void setSequenceNumber(uint32_t) override
Set clipboard sequence number.
Definition OSXScreen.mm:821
bool isAnyMouseButtonDown(uint32_t &buttonID) const override
Test if mouse is pressed.
Definition OSXScreen.mm:288
void warpCursor(int32_t x, int32_t y) override
Warp cursor.
Definition OSXScreen.mm:259
void fakeMouseButton(ButtonID id, bool press) override
Fake mouse press/release.
Definition OSXScreen.mm:482
void leave() override
Leave screen.
Definition OSXScreen.mm:756
void openScreensaver(bool notify) override
Open screen saver.
Definition OSXScreen.mm:787
void getCursorPos(int32_t &x, int32_t &y) const override
Get cursor position.
Definition OSXScreen.mm:235
void getShape(int32_t &x, int32_t &y, int32_t &width, int32_t &height) const override
Get screen shape.
Definition OSXScreen.mm:227
void checkClipboards() override
Check clipboard owner.
Definition OSXScreen.mm:777
int32_t getJumpZoneSize() const override
Get jump zone size.
Definition OSXScreen.mm:283
bool setClipboard(ClipboardID, const IClipboard *) override
Set clipboard.
Definition OSXScreen.mm:768
bool isPrimary() const override
Test if is primary screen.
Definition OSXScreen.mm:826
IEventQueue * getEvents() const
Definition OSXScreen.h:50
void fakeMouseWheel(ScrollDelta delta) const override
Synthesize a mouse wheel event of amount This Implmentation for this method should call applyScrollMo...
Definition OSXScreen.mm:588
void closeScreensaver() override
Close screen saver.
Definition OSXScreen.mm:795
bool getClipboard(ClipboardID id, IClipboard *) const override
Get clipboard.
Definition OSXScreen.mm:221
void setOptions(const OptionsList &options) override
Notify of options changes.
Definition OSXScreen.mm:816
void waitForCarbonLoop() const
Definition OSXScreen.mm:1749
IKeyState * getKeyState() const override
Get the key state.
Definition OSXScreen.mm:1257
void fakeInputBegin() override
Prepare to synthesize input on primary screen.
Definition OSXScreen.mm:273
void resetOptions() override
Notify of options changes.
Definition OSXScreen.mm:811
void updateButtons() override
Update mouse buttons.
Definition OSXScreen.mm:1250
Thread handle.
Definition Thread.h:33
EventTypes
Definition EventTypes.h:13