00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef CMSWINDOWSSCREEN_H
00016 #define CMSWINDOWSSCREEN_H
00017
00018 #include "CPlatformScreen.h"
00019 #include "CSynergyHook.h"
00020 #include "CCondVar.h"
00021 #include "CMutex.h"
00022 #include "CString.h"
00023 #define WIN32_LEAN_AND_MEAN
00024 #include <windows.h>
00025
00026 class CEventQueueTimer;
00027 class CMSWindowsDesks;
00028 class CMSWindowsKeyState;
00029 class CMSWindowsScreenSaver;
00030 class CThread;
00031
00033 class CMSWindowsScreen : public CPlatformScreen {
00034 public:
00035 CMSWindowsScreen(bool isPrimary);
00036 virtual ~CMSWindowsScreen();
00037
00039
00040
00042
00046 static void init(HINSTANCE);
00047
00049
00050
00051
00053
00056 static HINSTANCE getInstance();
00057
00059
00060
00061 virtual void* getEventTarget() const;
00062 virtual bool getClipboard(ClipboardID id, IClipboard*) const;
00063 virtual void getShape(SInt32& x, SInt32& y,
00064 SInt32& width, SInt32& height) const;
00065 virtual void getCursorPos(SInt32& x, SInt32& y) const;
00066
00067
00068 virtual void reconfigure(UInt32 activeSides);
00069 virtual void warpCursor(SInt32 x, SInt32 y);
00070 virtual UInt32 registerHotKey(KeyID key,
00071 KeyModifierMask mask);
00072 virtual void unregisterHotKey(UInt32 id);
00073 virtual void fakeInputBegin();
00074 virtual void fakeInputEnd();
00075 virtual SInt32 getJumpZoneSize() const;
00076 virtual bool isAnyMouseButtonDown() const;
00077 virtual void getCursorCenter(SInt32& x, SInt32& y) const;
00078
00079
00080 virtual void fakeMouseButton(ButtonID id, bool press) const;
00081 virtual void fakeMouseMove(SInt32 x, SInt32 y) const;
00082 virtual void fakeMouseRelativeMove(SInt32 dx, SInt32 dy) const;
00083 virtual void fakeMouseWheel(SInt32 xDelta, SInt32 yDelta) const;
00084
00085
00086 virtual void updateKeys();
00087 virtual void fakeKeyDown(KeyID id, KeyModifierMask mask,
00088 KeyButton button);
00089 virtual void fakeKeyRepeat(KeyID id, KeyModifierMask mask,
00090 SInt32 count, KeyButton button);
00091 virtual void fakeKeyUp(KeyButton button);
00092 virtual void fakeAllKeysUp();
00093
00094
00095 virtual void enable();
00096 virtual void disable();
00097 virtual void enter();
00098 virtual bool leave();
00099 virtual bool setClipboard(ClipboardID, const IClipboard*);
00100 virtual void checkClipboards();
00101 virtual void openScreensaver(bool notify);
00102 virtual void closeScreensaver();
00103 virtual void screensaver(bool activate);
00104 virtual void resetOptions();
00105 virtual void setOptions(const COptionsList& options);
00106 virtual void setSequenceNumber(UInt32);
00107 virtual bool isPrimary() const;
00108
00109 protected:
00110
00111 virtual void handleSystemEvent(const CEvent&, void*);
00112 virtual void updateButtons();
00113 virtual IKeyState* getKeyState() const;
00114
00115 private:
00116
00117 HINSTANCE openHookLibrary(const char* name);
00118 void closeHookLibrary(HINSTANCE hookLibrary) const;
00119 HCURSOR createBlankCursor() const;
00120 void destroyCursor(HCURSOR cursor) const;
00121 ATOM createWindowClass() const;
00122 ATOM createDeskWindowClass(bool isPrimary) const;
00123 void destroyClass(ATOM windowClass) const;
00124 HWND createWindow(ATOM windowClass, const char* name) const;
00125 void destroyWindow(HWND) const;
00126
00127
00128 void sendEvent(CEvent::Type type, void* = NULL);
00129 void sendClipboardEvent(CEvent::Type type, ClipboardID id);
00130
00131
00132
00133 bool onPreDispatch(HWND, UINT, WPARAM, LPARAM);
00134
00135
00136
00137 bool onPreDispatchPrimary(HWND, UINT, WPARAM, LPARAM);
00138
00139
00140
00141 bool onEvent(HWND, UINT, WPARAM, LPARAM, LRESULT* result);
00142
00143
00144 bool onMark(UInt32 mark);
00145 bool onKey(WPARAM, LPARAM);
00146 bool onHotKey(WPARAM, LPARAM);
00147 bool onMouseButton(WPARAM, LPARAM);
00148 bool onMouseMove(SInt32 x, SInt32 y);
00149 bool onMouseWheel(SInt32 xDelta, SInt32 yDelta);
00150 bool onScreensaver(bool activated);
00151 bool onDisplayChange();
00152 bool onClipboardChange();
00153
00154
00155 void warpCursorNoFlush(SInt32 x, SInt32 y);
00156
00157
00158 void nextMark();
00159
00160
00161 bool ignore() const;
00162
00163
00164 void updateScreenShape();
00165
00166
00167 void handleFixes(const CEvent&, void*);
00168
00169
00170 void fixClipboardViewer();
00171
00172
00173 void enableSpecialKeys(bool) const;
00174
00175
00176 ButtonID mapButtonFromEvent(WPARAM msg, LPARAM button) const;
00177
00178
00179 bool mapPressFromEvent(WPARAM msg, LPARAM button) const;
00180
00181
00182 void updateKeysCB(void*);
00183
00184
00185
00186 void forceShowCursor();
00187
00188
00189
00190
00191
00192 void updateForceShowCursor();
00193
00194
00195 static LRESULT CALLBACK wndProc(HWND, UINT, WPARAM, LPARAM);
00196
00197 private:
00198 struct CHotKeyItem {
00199 public:
00200 CHotKeyItem(UINT vk, UINT modifiers);
00201
00202 UINT getVirtualKey() const;
00203
00204 bool operator<(const CHotKeyItem&) const;
00205
00206 private:
00207 UINT m_keycode;
00208 UINT m_mask;
00209 };
00210 typedef std::map<UInt32, CHotKeyItem> HotKeyMap;
00211 typedef std::vector<UInt32> HotKeyIDList;
00212 typedef std::map<CHotKeyItem, UInt32> HotKeyToIDMap;
00213
00214 static HINSTANCE s_instance;
00215
00216
00217 bool m_isPrimary;
00218
00219
00220 bool m_is95Family;
00221
00222
00223 bool m_isOnScreen;
00224
00225
00226 ATOM m_class;
00227
00228
00229 SInt32 m_x, m_y;
00230 SInt32 m_w, m_h;
00231 SInt32 m_xCenter, m_yCenter;
00232
00233
00234 bool m_multimon;
00235
00236
00237 SInt32 m_xCursor, m_yCursor;
00238
00239
00240 UInt32 m_sequenceNumber;
00241
00242
00243 UInt32 m_mark;
00244 UInt32 m_markReceived;
00245
00246
00247 DWORD m_threadID;
00248
00249
00250 CEventQueueTimer* m_fixTimer;
00251
00252
00253 HKL m_keyLayout;
00254
00255
00256 CMSWindowsScreenSaver* m_screensaver;
00257 bool m_screensaverNotify;
00258 bool m_screensaverActive;
00259
00260
00261
00262 HWND m_window;
00263 HWND m_nextClipboardWindow;
00264 bool m_ownClipboard;
00265
00266
00267 CMSWindowsDesks* m_desks;
00268
00269
00270 HINSTANCE m_hookLibrary;
00271 InitFunc m_init;
00272 CleanupFunc m_cleanup;
00273 SetSidesFunc m_setSides;
00274 SetZoneFunc m_setZone;
00275 SetModeFunc m_setMode;
00276
00277
00278 CMSWindowsKeyState* m_keyState;
00279
00280
00281 HotKeyMap m_hotKeys;
00282 HotKeyIDList m_oldHotKeyIDs;
00283 HotKeyToIDMap m_hotKeyToIDMap;
00284
00285
00286 bool m_buttons[1 + kButtonExtra0 + 1];
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299 bool m_hasMouse;
00300 bool m_showingMouse;
00301 bool m_gotOldMouseKeys;
00302 MOUSEKEYS m_mouseKeys;
00303 MOUSEKEYS m_oldMouseKeys;
00304
00305 static CMSWindowsScreen* s_screen;
00306 };
00307
00308 #endif