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