1 | /*
|
---|
2 | * synergy -- mouse and keyboard sharing utility
|
---|
3 | * Copyright (C) 2002 Chris Schoeneman
|
---|
4 | * Copyright (C) 2006 Knut St. Osmundsen
|
---|
5 | *
|
---|
6 | * This package is free software; you can redistribute it and/or
|
---|
7 | * modify it under the terms of the GNU General Public License
|
---|
8 | * found in the file COPYING that should have accompanied this file.
|
---|
9 | *
|
---|
10 | * This package is distributed in the hope that it will be useful,
|
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
13 | * GNU General Public License for more details.
|
---|
14 | */
|
---|
15 |
|
---|
16 | #ifndef CPMSCREEN_H
|
---|
17 | #define CPMSCREEN_H
|
---|
18 |
|
---|
19 | #include "CPlatformScreen.h"
|
---|
20 | #include "CPMSynergyHook.h"
|
---|
21 | #include "CCondVar.h"
|
---|
22 | #include "CMutex.h"
|
---|
23 | #include "CString.h"
|
---|
24 | #define INCL_ERRORS
|
---|
25 | #define INCL_BASE
|
---|
26 | #define INCL_PM
|
---|
27 | #include <os2.h>
|
---|
28 |
|
---|
29 |
|
---|
30 | class CEventQueueTimer;
|
---|
31 | class CPMDesks;
|
---|
32 | class CPMKeyState;
|
---|
33 | class CPMScreenSaver;
|
---|
34 | class CThread;
|
---|
35 |
|
---|
36 | //! Implementation of IPlatformScreen for PM
|
---|
37 | class CPMScreen : public CPlatformScreen {
|
---|
38 | public:
|
---|
39 | CPMScreen(bool isPrimary);
|
---|
40 | virtual ~CPMScreen();
|
---|
41 |
|
---|
42 | // IScreen overrides
|
---|
43 | virtual void* getEventTarget() const;
|
---|
44 | virtual bool getClipboard(ClipboardID id, IClipboard*) const;
|
---|
45 | virtual void getShape(SInt32& x, SInt32& y, SInt32& cx, SInt32& cy) const;
|
---|
46 | virtual void getCursorPos(SInt32& x, SInt32& y) const;
|
---|
47 |
|
---|
48 | // IPrimaryScreen overrides
|
---|
49 | virtual void reconfigure(UInt32 activeSides);
|
---|
50 | virtual void warpCursor(SInt32 x, SInt32 y);
|
---|
51 | virtual UInt32 registerHotKey(KeyID key,
|
---|
52 | KeyModifierMask mask);
|
---|
53 | virtual void unregisterHotKey(UInt32 id);
|
---|
54 | virtual void fakeInputBegin();
|
---|
55 | virtual void fakeInputEnd();
|
---|
56 | virtual SInt32 getJumpZoneSize() const;
|
---|
57 | virtual bool isAnyMouseButtonDown() const;
|
---|
58 | virtual void getCursorCenter(SInt32& x, SInt32& y) const;
|
---|
59 |
|
---|
60 | // ISecondaryScreen overrides
|
---|
61 | virtual void fakeMouseButton(ButtonID id, bool press) const;
|
---|
62 | virtual void fakeMouseMove(SInt32 x, SInt32 y) const;
|
---|
63 | virtual void fakeMouseRelativeMove(SInt32 dx, SInt32 dy) const;
|
---|
64 | virtual void fakeMouseWheel(SInt32 xDelta, SInt32 yDelta) const;
|
---|
65 |
|
---|
66 | // IKeyState overrides
|
---|
67 | virtual void updateKeys();
|
---|
68 | virtual void fakeKeyDown(KeyID id, KeyModifierMask mask,
|
---|
69 | KeyButton button);
|
---|
70 | virtual void fakeKeyRepeat(KeyID id, KeyModifierMask mask,
|
---|
71 | SInt32 count, KeyButton button);
|
---|
72 | virtual void fakeKeyUp(KeyButton button);
|
---|
73 | virtual void fakeAllKeysUp();
|
---|
74 |
|
---|
75 | // IPlatformScreen overrides
|
---|
76 | virtual void enable();
|
---|
77 | virtual void disable();
|
---|
78 | virtual void enter();
|
---|
79 | virtual bool leave();
|
---|
80 | virtual bool setClipboard(ClipboardID, const IClipboard*);
|
---|
81 | virtual void checkClipboards();
|
---|
82 | virtual void openScreensaver(bool notify);
|
---|
83 | virtual void closeScreensaver();
|
---|
84 | virtual void screensaver(bool activate);
|
---|
85 | virtual void resetOptions();
|
---|
86 | virtual void setOptions(const COptionsList& options);
|
---|
87 | virtual void setSequenceNumber(UInt32);
|
---|
88 | virtual bool isPrimary() const;
|
---|
89 |
|
---|
90 | protected:
|
---|
91 | // IPlatformScreen overrides
|
---|
92 | virtual void handleSystemEvent(const CEvent&, void*);
|
---|
93 | virtual void updateButtons();
|
---|
94 | virtual IKeyState* getKeyState() const;
|
---|
95 |
|
---|
96 | private:
|
---|
97 | // initialization and shutdown operations
|
---|
98 | HMODULE openHookLibrary(const char* name);
|
---|
99 | void closeHookLibrary(HMODULE hookLibrary) const;
|
---|
100 | HWND createWindow(const char* name);
|
---|
101 | void destroyWindow(HWND) const;
|
---|
102 |
|
---|
103 | // fake message injection
|
---|
104 | void fakeMessage(ULONG msg, MPARAM mp1, MPARAM mp2) const;
|
---|
105 | void fakeMouseMessage(ULONG msg, MPARAM mp1) const;
|
---|
106 |
|
---|
107 | // convenience function to send events
|
---|
108 | void sendEvent(CEvent::Type type, void* = NULL);
|
---|
109 | void sendClipboardEvent(CEvent::Type type, ClipboardID id);
|
---|
110 |
|
---|
111 | // handle message before it gets dispatched. returns true iff
|
---|
112 | // the message should not be dispatched.
|
---|
113 | bool onPreDispatch(HWND, ULONG, MPARAM, MPARAM);
|
---|
114 |
|
---|
115 | // handle message before it gets dispatched. returns true iff
|
---|
116 | // the message should not be dispatched.
|
---|
117 | bool onPreDispatchPrimary(HWND, ULONG, MPARAM, MPARAM);
|
---|
118 |
|
---|
119 | // handle message. returns true iff handled and optionally sets
|
---|
120 | // \c *result (which defaults to 0).
|
---|
121 | bool onEvent(HWND, ULONG, MPARAM, MPARAM, MRESULT*);
|
---|
122 |
|
---|
123 | // message handlers
|
---|
124 | bool onMark(UInt32 mark);
|
---|
125 | bool onKey(USHORT fsFlags, UCHAR ucRepeat, UCHAR ucScanCode, USHORT usch, USHORT usvk);
|
---|
126 | bool onHotKey(MPARAM, MPARAM);
|
---|
127 | bool onMouseButton(ULONG msg, SInt32 ax, SInt32 ay);
|
---|
128 | bool onMouseMove(ULONG msg, SInt32 ax, SInt32 ay);
|
---|
129 | bool onClipboardChange();
|
---|
130 |
|
---|
131 | // warp cursor without discarding queued events
|
---|
132 | void warpCursorNoFlush(SInt32 x, SInt32 y);
|
---|
133 |
|
---|
134 | // discard posted messages
|
---|
135 | void nextMark();
|
---|
136 |
|
---|
137 | // test if event should be ignored
|
---|
138 | bool ignore() const;
|
---|
139 |
|
---|
140 | // update screen size cache
|
---|
141 | void updateScreenShape();
|
---|
142 |
|
---|
143 | // fix timer callback
|
---|
144 | void handleFixes(const CEvent&, void*);
|
---|
145 |
|
---|
146 | // enable/disable special key combinations so we can catch/pass them
|
---|
147 | void enableSpecialKeys(bool) const;
|
---|
148 |
|
---|
149 | // map a button event to a button ID
|
---|
150 | ButtonID mapButtonFromEvent(ULONG msg) const;
|
---|
151 |
|
---|
152 | // map a button event to a press (true) or release (false)
|
---|
153 | bool mapPressFromEvent(ULONG msg) const;
|
---|
154 |
|
---|
155 | // job to update the key state
|
---|
156 | void updateKeysCB(void*);
|
---|
157 |
|
---|
158 | // determine whether the mouse is hidden by the system and force
|
---|
159 | // it to be displayed if user has entered this secondary screen.
|
---|
160 | void forceShowCursor();
|
---|
161 |
|
---|
162 | // forceShowCursor uses MouseKeys to show the cursor. since we
|
---|
163 | // don't actually want MouseKeys behavior we have to make sure
|
---|
164 | // it applies when NumLock is in whatever state it's not in now.
|
---|
165 | // this method does that.
|
---|
166 | void updateForceShowCursor();
|
---|
167 |
|
---|
168 | // our window proc
|
---|
169 | static MRESULT EXPENTRY wndProc(HWND, ULONG, MPARAM, MPARAM);
|
---|
170 |
|
---|
171 | private:
|
---|
172 | struct CHotKeyItem {
|
---|
173 | public:
|
---|
174 | CHotKeyItem(ULONG vk, ULONG modifiers);
|
---|
175 |
|
---|
176 | ULONG getVirtualKey() const;
|
---|
177 |
|
---|
178 | bool operator<(const CHotKeyItem&) const;
|
---|
179 |
|
---|
180 | private:
|
---|
181 | ULONG m_keycode;
|
---|
182 | ULONG m_mask;
|
---|
183 | };
|
---|
184 | typedef std::map<UInt32, CHotKeyItem> HotKeyMap;
|
---|
185 | typedef std::vector<UInt32> HotKeyIDList;
|
---|
186 | typedef std::map<CHotKeyItem, UInt32> HotKeyToIDMap;
|
---|
187 |
|
---|
188 | // true if screen is being used as a primary screen, false otherwise
|
---|
189 | bool m_isPrimary;
|
---|
190 | bool m_isOnScreen;
|
---|
191 |
|
---|
192 | // screen shape stuff
|
---|
193 | SInt32 m_x, m_y;
|
---|
194 | SInt32 m_cx, m_cy;
|
---|
195 | SInt32 m_xCenter, m_yCenter;
|
---|
196 |
|
---|
197 | // true if system appears to have multiple monitors
|
---|
198 | bool m_multimon;
|
---|
199 |
|
---|
200 | // last mouse position
|
---|
201 | SInt32 m_xCursor, m_yCursor;
|
---|
202 |
|
---|
203 | // last clipboard
|
---|
204 | UInt32 m_sequenceNumber;
|
---|
205 |
|
---|
206 | // used to discard queued messages that are no longer needed
|
---|
207 | UInt32 m_mark;
|
---|
208 | UInt32 m_markReceived;
|
---|
209 |
|
---|
210 | // the main loop's thread id, anchor block and message queue.
|
---|
211 | int m_threadID;
|
---|
212 | HAB m_hab;
|
---|
213 | HMQ m_hmq;
|
---|
214 |
|
---|
215 | // screen saver stuff
|
---|
216 | CPMScreenSaver* m_screensaver;
|
---|
217 | bool m_screensaverNotify;
|
---|
218 | bool m_screensaverActive;
|
---|
219 |
|
---|
220 | // clipboard stuff. our window is used mainly as a clipboard
|
---|
221 | // owner and as a link in the clipboard viewer chain.
|
---|
222 | HWND m_window;
|
---|
223 | HWND m_nextClipboardWindow;
|
---|
224 | bool m_ownClipboard;
|
---|
225 |
|
---|
226 | // hook library stuff
|
---|
227 | HMODULE m_hmodHook;
|
---|
228 | InitFunc m_init;
|
---|
229 | CleanupFunc m_cleanup;
|
---|
230 | SetSidesFunc m_setSides;
|
---|
231 | SetZoneFunc m_setZone;
|
---|
232 | SetModeFunc m_setMode;
|
---|
233 | FakeMsgFunc m_fakeMsg;
|
---|
234 |
|
---|
235 | // keyboard stuff
|
---|
236 | CPMKeyState* m_keyState;
|
---|
237 |
|
---|
238 | // hot key stuff
|
---|
239 | HotKeyMap m_hotKeys;
|
---|
240 | HotKeyIDList m_oldHotKeyIDs;
|
---|
241 | HotKeyToIDMap m_hotKeyToIDMap;
|
---|
242 |
|
---|
243 | // map of button state
|
---|
244 | bool m_buttons[1 + kButtonExtra0 + 1];
|
---|
245 |
|
---|
246 | bool m_hasMouse;
|
---|
247 | bool m_showingMouse;
|
---|
248 |
|
---|
249 | static CPMScreen* s_screen;
|
---|
250 | };
|
---|
251 |
|
---|
252 | /*
|
---|
253 | * Local Variables:
|
---|
254 | * mode: c
|
---|
255 | * c-file-style: "k&r"
|
---|
256 | * c-basic-offset: 4
|
---|
257 | * tab-width: 4
|
---|
258 | * indent-tabs-mode: s
|
---|
259 | * End:
|
---|
260 | */
|
---|
261 |
|
---|
262 | #endif
|
---|