source: vendor/synergy/1.3.1/lib/platform/COSXScreen.h@ 2749

Last change on this file since 2749 was 2749, checked in by bird, 19 years ago

synergy v1.3.1 sources (zip).

File size: 7.3 KB
Line 
1/*
2 * synergy -- mouse and keyboard sharing utility
3 * Copyright (C) 2004 Chris Schoeneman
4 *
5 * This package is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * found in the file COPYING that should have accompanied this file.
8 *
9 * This package is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14
15#ifndef COSXSCREEN_H
16#define COSXSCREEN_H
17
18#include "CPlatformScreen.h"
19#include "stdmap.h"
20#include "stdvector.h"
21#include <Carbon/Carbon.h>
22
23#include <mach/mach_port.h>
24#include <mach/mach_interface.h>
25#include <mach/mach_init.h>
26#include <IOKit/pwr_mgt/IOPMLib.h>
27#include <IOKit/IOMessage.h>
28
29template <class T>
30class CCondVar;
31class CEventQueueTimer;
32class CMutex;
33class CThread;
34class COSXKeyState;
35class COSXScreenSaver;
36
37//! Implementation of IPlatformScreen for OS X
38class COSXScreen : public CPlatformScreen {
39public:
40 COSXScreen(bool isPrimary);
41 virtual ~COSXScreen();
42
43 // IScreen overrides
44 virtual void* getEventTarget() const;
45 virtual bool getClipboard(ClipboardID id, IClipboard*) const;
46 virtual void getShape(SInt32& x, SInt32& y,
47 SInt32& width, SInt32& height) const;
48 virtual void getCursorPos(SInt32& x, SInt32& y) const;
49
50 // IPrimaryScreen overrides
51 virtual void reconfigure(UInt32 activeSides);
52 virtual void warpCursor(SInt32 x, SInt32 y);
53 virtual UInt32 registerHotKey(KeyID key, KeyModifierMask mask);
54 virtual void unregisterHotKey(UInt32 id);
55 virtual void fakeInputBegin();
56 virtual void fakeInputEnd();
57 virtual SInt32 getJumpZoneSize() const;
58 virtual bool isAnyMouseButtonDown() const;
59 virtual void getCursorCenter(SInt32& x, SInt32& y) const;
60
61 // ISecondaryScreen overrides
62 virtual void fakeMouseButton(ButtonID id, bool press) const;
63 virtual void fakeMouseMove(SInt32 x, SInt32 y) const;
64 virtual void fakeMouseRelativeMove(SInt32 dx, SInt32 dy) const;
65 virtual void fakeMouseWheel(SInt32 xDelta, SInt32 yDelta) const;
66
67 // IPlatformScreen overrides
68 virtual void enable();
69 virtual void disable();
70 virtual void enter();
71 virtual bool leave();
72 virtual bool setClipboard(ClipboardID, const IClipboard*);
73 virtual void checkClipboards();
74 virtual void openScreensaver(bool notify);
75 virtual void closeScreensaver();
76 virtual void screensaver(bool activate);
77 virtual void resetOptions();
78 virtual void setOptions(const COptionsList& options);
79 virtual void setSequenceNumber(UInt32);
80 virtual bool isPrimary() const;
81
82protected:
83 // IPlatformScreen overrides
84 virtual void handleSystemEvent(const CEvent&, void*);
85 virtual void updateButtons();
86 virtual IKeyState* getKeyState() const;
87
88private:
89 void updateScreenShape();
90 void postMouseEvent(CGPoint&) const;
91
92 // convenience function to send events
93 void sendEvent(CEvent::Type type, void* = NULL) const;
94 void sendClipboardEvent(CEvent::Type type, ClipboardID id) const;
95
96 // message handlers
97 bool onMouseMove(SInt32 x, SInt32 y);
98 // mouse button handler. pressed is true if this is a mousedown
99 // event, false if it is a mouseup event. macButton is the index
100 // of the button pressed using the mac button mapping.
101 bool onMouseButton(bool pressed, UInt16 macButton);
102 bool onMouseWheel(SInt32 xDelta, SInt32 yDelta) const;
103
104 bool onDisplayChange();
105
106 bool onKey(EventRef event);
107 bool onHotKey(EventRef event) const;
108
109 // map mac mouse button to synergy buttons
110 ButtonID mapMacButtonToSynergy(UInt16) const;
111
112 // map mac scroll wheel value to a synergy scroll wheel value
113 SInt32 mapScrollWheelToSynergy(SInt32) const;
114
115 // map synergy scroll wheel value to a mac scroll wheel value
116 SInt32 mapScrollWheelFromSynergy(SInt32) const;
117
118 // get the current scroll wheel speed
119 double getScrollSpeed() const;
120
121 // get the current scroll wheel speed
122 double getScrollSpeedFactor() const;
123
124 // enable/disable drag handling for buttons 3 and up
125 void enableDragTimer(bool enable);
126
127 // drag timer handler
128 void handleDrag(const CEvent&, void*);
129
130 // clipboard check timer handler
131 void handleClipboardCheck(const CEvent&, void*);
132
133 // Resolution switch callback
134 static pascal void displayManagerCallback(void* inUserData,
135 SInt16 inMessage, void* inNotifyData);
136
137 // fast user switch callback
138 static pascal OSStatus
139 userSwitchCallback(EventHandlerCallRef nextHandler,
140 EventRef theEvent, void* inUserData);
141
142 // sleep / wakeup support
143 void watchSystemPowerThread(void*);
144 static void testCanceled(CFRunLoopTimerRef timer, void*info);
145 static void powerChangeCallback(void* refcon, io_service_t service,
146 natural_t messageType, void* messageArgument);
147 void handlePowerChangeRequest(natural_t messageType,
148 void* messageArgument);
149
150 static CEvent::Type getConfirmSleepEvent();
151 void handleConfirmSleep(const CEvent& event, void*);
152
153 // global hotkey operating mode
154 static bool isGlobalHotKeyOperatingModeAvailable();
155 static void setGlobalHotKeysEnabled(bool enabled);
156 static bool getGlobalHotKeysEnabled();
157
158private:
159 struct CHotKeyItem {
160 public:
161 CHotKeyItem(UInt32, UInt32);
162 CHotKeyItem(EventHotKeyRef, UInt32, UInt32);
163
164 EventHotKeyRef getRef() const;
165
166 bool operator<(const CHotKeyItem&) const;
167
168 private:
169 EventHotKeyRef m_ref;
170 UInt32 m_keycode;
171 UInt32 m_mask;
172 };
173 typedef std::map<UInt32, CHotKeyItem> HotKeyMap;
174 typedef std::vector<UInt32> HotKeyIDList;
175 typedef std::map<KeyModifierMask, UInt32> ModifierHotKeyMap;
176 typedef std::map<CHotKeyItem, UInt32> HotKeyToIDMap;
177
178 // true if screen is being used as a primary screen, false otherwise
179 bool m_isPrimary;
180
181 // true if mouse has entered the screen
182 bool m_isOnScreen;
183
184 // the display
185 CGDirectDisplayID m_displayID;
186
187 // screen shape stuff
188 SInt32 m_x, m_y;
189 SInt32 m_w, m_h;
190 SInt32 m_xCenter, m_yCenter;
191
192 // mouse state
193 mutable SInt32 m_xCursor, m_yCursor;
194 mutable bool m_cursorPosValid;
195 mutable boolean_t m_buttons[5];
196 bool m_cursorHidden;
197 SInt32 m_dragNumButtonsDown;
198 Point m_dragLastPoint;
199 CEventQueueTimer* m_dragTimer;
200
201 // keyboard stuff
202 COSXKeyState* m_keyState;
203
204 // clipboards
205 UInt32 m_sequenceNumber;
206
207 // screen saver stuff
208 COSXScreenSaver* m_screensaver;
209 bool m_screensaverNotify;
210
211 // clipboard stuff
212 bool m_ownClipboard;
213 CEventQueueTimer* m_clipboardTimer;
214
215 // window object that gets user input events when the server
216 // has focus.
217 WindowRef m_hiddenWindow;
218 // window object that gets user input events when the server
219 // does not have focus.
220 WindowRef m_userInputWindow;
221
222 // display manager stuff (to get screen resolution switches).
223 DMExtendedNotificationUPP m_displayManagerNotificationUPP;
224 ProcessSerialNumber m_PSN;
225
226 // fast user switching
227 EventHandlerRef m_switchEventHandlerRef;
228
229 // sleep / wakeup
230 CMutex* m_pmMutex;
231 CThread* m_pmWatchThread;
232 CCondVar<bool>* m_pmThreadReady;
233 CFRunLoopRef m_pmRunloop;
234 io_connect_t m_pmRootPort;
235
236 // hot key stuff
237 HotKeyMap m_hotKeys;
238 HotKeyIDList m_oldHotKeyIDs;
239 ModifierHotKeyMap m_modifierHotKeys;
240 UInt32 m_activeModifierHotKey;
241 KeyModifierMask m_activeModifierHotKeyMask;
242 HotKeyToIDMap m_hotKeyToIDMap;
243
244 // global hotkey operating mode
245 static bool s_testedForGHOM;
246 static bool s_hasGHOM;
247
248 // events
249 static CEvent::Type s_confirmSleepEvent;
250};
251
252#endif
Note: See TracBrowser for help on using the repository browser.