00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef CXWINDOWSSCREEN_H
00016 #define CXWINDOWSSCREEN_H
00017
00018 #include "CPlatformScreen.h"
00019 #include "stdset.h"
00020 #include "stdvector.h"
00021 #if X_DISPLAY_MISSING
00022 # error X11 is required to build synergy
00023 #else
00024 # include <X11/Xlib.h>
00025 #endif
00026
00027 class CXWindowsClipboard;
00028 class CXWindowsKeyState;
00029 class CXWindowsScreenSaver;
00030
00032 class CXWindowsScreen : public CPlatformScreen {
00033 public:
00034 CXWindowsScreen(const char* displayName, bool isPrimary, int mouseScrollDelta=0);
00035 virtual ~CXWindowsScreen();
00036
00038
00039
00041
00042
00043 virtual void* getEventTarget() const;
00044 virtual bool getClipboard(ClipboardID id, IClipboard*) const;
00045 virtual void getShape(SInt32& x, SInt32& y,
00046 SInt32& width, SInt32& height) const;
00047 virtual void getCursorPos(SInt32& x, SInt32& y) const;
00048
00049
00050 virtual void reconfigure(UInt32 activeSides);
00051 virtual void warpCursor(SInt32 x, SInt32 y);
00052 virtual UInt32 registerHotKey(KeyID key, KeyModifierMask mask);
00053 virtual void unregisterHotKey(UInt32 id);
00054 virtual void fakeInputBegin();
00055 virtual void fakeInputEnd();
00056 virtual SInt32 getJumpZoneSize() const;
00057 virtual bool isAnyMouseButtonDown() const;
00058 virtual void getCursorCenter(SInt32& x, SInt32& y) const;
00059
00060
00061 virtual void fakeMouseButton(ButtonID id, bool press) const;
00062 virtual void fakeMouseMove(SInt32 x, SInt32 y) const;
00063 virtual void fakeMouseRelativeMove(SInt32 dx, SInt32 dy) const;
00064 virtual void fakeMouseWheel(SInt32 xDelta, SInt32 yDelta) const;
00065
00066
00067 virtual void enable();
00068 virtual void disable();
00069 virtual void enter();
00070 virtual bool leave();
00071 virtual bool setClipboard(ClipboardID, const IClipboard*);
00072 virtual void checkClipboards();
00073 virtual void openScreensaver(bool notify);
00074 virtual void closeScreensaver();
00075 virtual void screensaver(bool activate);
00076 virtual void resetOptions();
00077 virtual void setOptions(const COptionsList& options);
00078 virtual void setSequenceNumber(UInt32);
00079 virtual bool isPrimary() const;
00080
00081 protected:
00082
00083 virtual void handleSystemEvent(const CEvent&, void*);
00084 virtual void updateButtons();
00085 virtual IKeyState* getKeyState() const;
00086
00087 private:
00088
00089 void sendEvent(CEvent::Type, void* = NULL);
00090 void sendClipboardEvent(CEvent::Type, ClipboardID);
00091
00092
00093 Cursor createBlankCursor() const;
00094
00095
00096
00097 ClipboardID getClipboardID(Atom selection) const;
00098
00099
00100 void processClipboardRequest(Window window,
00101 Time time, Atom property);
00102
00103
00104 void destroyClipboardRequest(Window window);
00105
00106
00107 void onError();
00108 static int ioErrorHandler(Display*);
00109
00110 private:
00111 class CKeyEventFilter {
00112 public:
00113 int m_event;
00114 Window m_window;
00115 Time m_time;
00116 KeyCode m_keycode;
00117 };
00118
00119 Display* openDisplay(const char* displayName);
00120 void saveShape();
00121 Window openWindow() const;
00122 void openIM();
00123
00124 bool grabMouseAndKeyboard();
00125 void onKeyPress(XKeyEvent&);
00126 void onKeyRelease(XKeyEvent&, bool isRepeat);
00127 bool onHotKey(XKeyEvent&, bool isRepeat);
00128 void onMousePress(const XButtonEvent&);
00129 void onMouseRelease(const XButtonEvent&);
00130 void onMouseMove(const XMotionEvent&);
00131
00132 void selectEvents(Window) const;
00133 void doSelectEvents(Window) const;
00134
00135 KeyID mapKeyFromX(XKeyEvent*) const;
00136 ButtonID mapButtonFromX(const XButtonEvent*) const;
00137 unsigned int mapButtonToX(ButtonID id) const;
00138
00139 void warpCursorNoFlush(SInt32 x, SInt32 y);
00140
00141 void refreshKeyboard(XEvent*);
00142
00143 static Bool findKeyEvent(Display*, XEvent* xevent, XPointer arg);
00144
00145 private:
00146 struct CHotKeyItem {
00147 public:
00148 CHotKeyItem(int, unsigned int);
00149
00150 bool operator<(const CHotKeyItem&) const;
00151
00152 private:
00153 int m_keycode;
00154 unsigned int m_mask;
00155 };
00156 typedef std::set<bool> CFilteredKeycodes;
00157 typedef std::vector<std::pair<int, unsigned int> > HotKeyList;
00158 typedef std::map<UInt32, HotKeyList> HotKeyMap;
00159 typedef std::vector<UInt32> HotKeyIDList;
00160 typedef std::map<CHotKeyItem, UInt32> HotKeyToIDMap;
00161
00162
00163 bool m_isPrimary;
00164 int m_mouseScrollDelta;
00165
00166 Display* m_display;
00167 Window m_root;
00168 Window m_window;
00169
00170
00171 bool m_isOnScreen;
00172
00173
00174 SInt32 m_x, m_y;
00175 SInt32 m_w, m_h;
00176 SInt32 m_xCenter, m_yCenter;
00177
00178
00179 SInt32 m_xCursor, m_yCursor;
00180
00181
00182 CXWindowsKeyState* m_keyState;
00183
00184
00185 HotKeyMap m_hotKeys;
00186 HotKeyIDList m_oldHotKeyIDs;
00187 HotKeyToIDMap m_hotKeyToIDMap;
00188
00189
00190 Window m_lastFocus;
00191 int m_lastFocusRevert;
00192
00193
00194 XIM m_im;
00195 XIC m_ic;
00196 KeyCode m_lastKeycode;
00197 CFilteredKeycodes m_filtered;
00198
00199
00200 CXWindowsClipboard* m_clipboard[kClipboardEnd];
00201 UInt32 m_sequenceNumber;
00202
00203
00204 CXWindowsScreenSaver* m_screensaver;
00205 bool m_screensaverNotify;
00206
00207
00208
00209 std::vector<unsigned char> m_buttons;
00210
00211
00212 bool m_autoRepeat;
00213
00214
00215
00216
00217
00218 bool m_xtestIsXineramaUnaware;
00219 bool m_xinerama;
00220
00221
00222
00223 bool m_preserveFocus;
00224
00225
00226 bool m_xkb;
00227 int m_xkbEventBase;
00228
00229
00230
00231 static CXWindowsScreen* s_screen;
00232 };
00233
00234 #endif