source: trunk/synergy/lib/platform/CMSWindowsScreen.h

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

synergy v1.3.1 sources (zip).

File size: 8.9 KB
Line 
1/*
2 * synergy -- mouse and keyboard sharing utility
3 * Copyright (C) 2002 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 CMSWINDOWSSCREEN_H
16#define CMSWINDOWSSCREEN_H
17
18#include "CPlatformScreen.h"
19#include "CSynergyHook.h"
20#include "CCondVar.h"
21#include "CMutex.h"
22#include "CString.h"
23#define WIN32_LEAN_AND_MEAN
24#include <windows.h>
25
26class CEventQueueTimer;
27class CMSWindowsDesks;
28class CMSWindowsKeyState;
29class CMSWindowsScreenSaver;
30class CThread;
31
32//! Implementation of IPlatformScreen for Microsoft Windows
33class CMSWindowsScreen : public CPlatformScreen {
34public:
35 CMSWindowsScreen(bool isPrimary);
36 virtual ~CMSWindowsScreen();
37
38 //! @name manipulators
39 //@{
40
41 //! Initialize
42 /*!
43 Saves the application's HINSTANCE. This \b must be called by
44 WinMain with the HINSTANCE it was passed.
45 */
46 static void init(HINSTANCE);
47
48 //@}
49 //! @name accessors
50 //@{
51
52 //! Get instance
53 /*!
54 Returns the application instance handle passed to init().
55 */
56 static HINSTANCE getInstance();
57
58 //@}
59
60 // IScreen overrides
61 virtual void* getEventTarget() const;
62 virtual bool getClipboard(ClipboardID id, IClipboard*) const;
63 virtual void getShape(SInt32& x, SInt32& y,
64 SInt32& width, SInt32& height) const;
65 virtual void getCursorPos(SInt32& x, SInt32& y) const;
66
67 // IPrimaryScreen overrides
68 virtual void reconfigure(UInt32 activeSides);
69 virtual void warpCursor(SInt32 x, SInt32 y);
70 virtual UInt32 registerHotKey(KeyID key,
71 KeyModifierMask mask);
72 virtual void unregisterHotKey(UInt32 id);
73 virtual void fakeInputBegin();
74 virtual void fakeInputEnd();
75 virtual SInt32 getJumpZoneSize() const;
76 virtual bool isAnyMouseButtonDown() const;
77 virtual void getCursorCenter(SInt32& x, SInt32& y) const;
78
79 // ISecondaryScreen overrides
80 virtual void fakeMouseButton(ButtonID id, bool press) const;
81 virtual void fakeMouseMove(SInt32 x, SInt32 y) const;
82 virtual void fakeMouseRelativeMove(SInt32 dx, SInt32 dy) const;
83 virtual void fakeMouseWheel(SInt32 xDelta, SInt32 yDelta) const;
84
85 // IKeyState overrides
86 virtual void updateKeys();
87 virtual void fakeKeyDown(KeyID id, KeyModifierMask mask,
88 KeyButton button);
89 virtual void fakeKeyRepeat(KeyID id, KeyModifierMask mask,
90 SInt32 count, KeyButton button);
91 virtual void fakeKeyUp(KeyButton button);
92 virtual void fakeAllKeysUp();
93
94 // IPlatformScreen overrides
95 virtual void enable();
96 virtual void disable();
97 virtual void enter();
98 virtual bool leave();
99 virtual bool setClipboard(ClipboardID, const IClipboard*);
100 virtual void checkClipboards();
101 virtual void openScreensaver(bool notify);
102 virtual void closeScreensaver();
103 virtual void screensaver(bool activate);
104 virtual void resetOptions();
105 virtual void setOptions(const COptionsList& options);
106 virtual void setSequenceNumber(UInt32);
107 virtual bool isPrimary() const;
108
109protected:
110 // IPlatformScreen overrides
111 virtual void handleSystemEvent(const CEvent&, void*);
112 virtual void updateButtons();
113 virtual IKeyState* getKeyState() const;
114
115private:
116 // initialization and shutdown operations
117 HINSTANCE openHookLibrary(const char* name);
118 void closeHookLibrary(HINSTANCE hookLibrary) const;
119 HCURSOR createBlankCursor() const;
120 void destroyCursor(HCURSOR cursor) const;
121 ATOM createWindowClass() const;
122 ATOM createDeskWindowClass(bool isPrimary) const;
123 void destroyClass(ATOM windowClass) const;
124 HWND createWindow(ATOM windowClass, const char* name) const;
125 void destroyWindow(HWND) const;
126
127 // convenience function to send events
128 void sendEvent(CEvent::Type type, void* = NULL);
129 void sendClipboardEvent(CEvent::Type type, ClipboardID id);
130
131 // handle message before it gets dispatched. returns true iff
132 // the message should not be dispatched.
133 bool onPreDispatch(HWND, UINT, WPARAM, LPARAM);
134
135 // handle message before it gets dispatched. returns true iff
136 // the message should not be dispatched.
137 bool onPreDispatchPrimary(HWND, UINT, WPARAM, LPARAM);
138
139 // handle message. returns true iff handled and optionally sets
140 // \c *result (which defaults to 0).
141 bool onEvent(HWND, UINT, WPARAM, LPARAM, LRESULT* result);
142
143 // message handlers
144 bool onMark(UInt32 mark);
145 bool onKey(WPARAM, LPARAM);
146 bool onHotKey(WPARAM, LPARAM);
147 bool onMouseButton(WPARAM, LPARAM);
148 bool onMouseMove(SInt32 x, SInt32 y);
149 bool onMouseWheel(SInt32 xDelta, SInt32 yDelta);
150 bool onScreensaver(bool activated);
151 bool onDisplayChange();
152 bool onClipboardChange();
153
154 // warp cursor without discarding queued events
155 void warpCursorNoFlush(SInt32 x, SInt32 y);
156
157 // discard posted messages
158 void nextMark();
159
160 // test if event should be ignored
161 bool ignore() const;
162
163 // update screen size cache
164 void updateScreenShape();
165
166 // fix timer callback
167 void handleFixes(const CEvent&, void*);
168
169 // fix the clipboard viewer chain
170 void fixClipboardViewer();
171
172 // enable/disable special key combinations so we can catch/pass them
173 void enableSpecialKeys(bool) const;
174
175 // map a button event to a button ID
176 ButtonID mapButtonFromEvent(WPARAM msg, LPARAM button) const;
177
178 // map a button event to a press (true) or release (false)
179 bool mapPressFromEvent(WPARAM msg, LPARAM button) const;
180
181 // job to update the key state
182 void updateKeysCB(void*);
183
184 // determine whether the mouse is hidden by the system and force
185 // it to be displayed if user has entered this secondary screen.
186 void forceShowCursor();
187
188 // forceShowCursor uses MouseKeys to show the cursor. since we
189 // don't actually want MouseKeys behavior we have to make sure
190 // it applies when NumLock is in whatever state it's not in now.
191 // this method does that.
192 void updateForceShowCursor();
193
194 // our window proc
195 static LRESULT CALLBACK wndProc(HWND, UINT, WPARAM, LPARAM);
196
197private:
198 struct CHotKeyItem {
199 public:
200 CHotKeyItem(UINT vk, UINT modifiers);
201
202 UINT getVirtualKey() const;
203
204 bool operator<(const CHotKeyItem&) const;
205
206 private:
207 UINT m_keycode;
208 UINT m_mask;
209 };
210 typedef std::map<UInt32, CHotKeyItem> HotKeyMap;
211 typedef std::vector<UInt32> HotKeyIDList;
212 typedef std::map<CHotKeyItem, UInt32> HotKeyToIDMap;
213
214 static HINSTANCE s_instance;
215
216 // true if screen is being used as a primary screen, false otherwise
217 bool m_isPrimary;
218
219 // true if windows 95/98/me
220 bool m_is95Family;
221
222 // true if mouse has entered the screen
223 bool m_isOnScreen;
224
225 // our resources
226 ATOM m_class;
227
228 // screen shape stuff
229 SInt32 m_x, m_y;
230 SInt32 m_w, m_h;
231 SInt32 m_xCenter, m_yCenter;
232
233 // true if system appears to have multiple monitors
234 bool m_multimon;
235
236 // last mouse position
237 SInt32 m_xCursor, m_yCursor;
238
239 // last clipboard
240 UInt32 m_sequenceNumber;
241
242 // used to discard queued messages that are no longer needed
243 UInt32 m_mark;
244 UInt32 m_markReceived;
245
246 // the main loop's thread id
247 DWORD m_threadID;
248
249 // timer for periodically checking stuff that requires polling
250 CEventQueueTimer* m_fixTimer;
251
252 // the keyboard layout to use when off primary screen
253 HKL m_keyLayout;
254
255 // screen saver stuff
256 CMSWindowsScreenSaver* m_screensaver;
257 bool m_screensaverNotify;
258 bool m_screensaverActive;
259
260 // clipboard stuff. our window is used mainly as a clipboard
261 // owner and as a link in the clipboard viewer chain.
262 HWND m_window;
263 HWND m_nextClipboardWindow;
264 bool m_ownClipboard;
265
266 // one desk per desktop and a cond var to communicate with it
267 CMSWindowsDesks* m_desks;
268
269 // hook library stuff
270 HINSTANCE m_hookLibrary;
271 InitFunc m_init;
272 CleanupFunc m_cleanup;
273 SetSidesFunc m_setSides;
274 SetZoneFunc m_setZone;
275 SetModeFunc m_setMode;
276
277 // keyboard stuff
278 CMSWindowsKeyState* m_keyState;
279
280 // hot key stuff
281 HotKeyMap m_hotKeys;
282 HotKeyIDList m_oldHotKeyIDs;
283 HotKeyToIDMap m_hotKeyToIDMap;
284
285 // map of button state
286 bool m_buttons[1 + kButtonExtra0 + 1];
287
288 // the system shows the mouse cursor when an internal display count
289 // is >= 0. this count is maintained per application but there's
290 // apparently a system wide count added to the application's count.
291 // this system count is 0 if there's a mouse attached to the system
292 // and -1 otherwise. the MouseKeys accessibility feature can modify
293 // this system count by making the system appear to have a mouse.
294 //
295 // m_hasMouse is true iff there's a mouse attached to the system or
296 // MouseKeys is simulating one. we track this so we can force the
297 // cursor to be displayed when the user has entered this screen.
298 // m_showingMouse is true when we're doing that.
299 bool m_hasMouse;
300 bool m_showingMouse;
301 bool m_gotOldMouseKeys;
302 MOUSEKEYS m_mouseKeys;
303 MOUSEKEYS m_oldMouseKeys;
304
305 static CMSWindowsScreen* s_screen;
306};
307
308#endif
Note: See TracBrowser for help on using the repository browser.