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

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

synergy v1.3.1 sources (zip).

File size: 6.3 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 CXWINDOWSSCREEN_H
16#define CXWINDOWSSCREEN_H
17
18#include "CPlatformScreen.h"
19#include "stdset.h"
20#include "stdvector.h"
21#if X_DISPLAY_MISSING
22# error X11 is required to build synergy
23#else
24# include <X11/Xlib.h>
25#endif
26
27class CXWindowsClipboard;
28class CXWindowsKeyState;
29class CXWindowsScreenSaver;
30
31//! Implementation of IPlatformScreen for X11
32class CXWindowsScreen : public CPlatformScreen {
33public:
34 CXWindowsScreen(const char* displayName, bool isPrimary);
35 virtual ~CXWindowsScreen();
36
37 //! @name manipulators
38 //@{
39
40 //@}
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,
46 SInt32& width, SInt32& height) const;
47 virtual void getCursorPos(SInt32& x, SInt32& y) const;
48
49 // IPrimaryScreen overrides
50 virtual void reconfigure(UInt32 activeSides);
51 virtual void warpCursor(SInt32 x, SInt32 y);
52 virtual UInt32 registerHotKey(KeyID key, 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 // IPlatformScreen overrides
67 virtual void enable();
68 virtual void disable();
69 virtual void enter();
70 virtual bool leave();
71 virtual bool setClipboard(ClipboardID, const IClipboard*);
72 virtual void checkClipboards();
73 virtual void openScreensaver(bool notify);
74 virtual void closeScreensaver();
75 virtual void screensaver(bool activate);
76 virtual void resetOptions();
77 virtual void setOptions(const COptionsList& options);
78 virtual void setSequenceNumber(UInt32);
79 virtual bool isPrimary() const;
80
81protected:
82 // IPlatformScreen overrides
83 virtual void handleSystemEvent(const CEvent&, void*);
84 virtual void updateButtons();
85 virtual IKeyState* getKeyState() const;
86
87private:
88 // event sending
89 void sendEvent(CEvent::Type, void* = NULL);
90 void sendClipboardEvent(CEvent::Type, ClipboardID);
91
92 // create the transparent cursor
93 Cursor createBlankCursor() const;
94
95 // determine the clipboard from the X selection. returns
96 // kClipboardEnd if no such clipboard.
97 ClipboardID getClipboardID(Atom selection) const;
98
99 // continue processing a selection request
100 void processClipboardRequest(Window window,
101 Time time, Atom property);
102
103 // terminate a selection request
104 void destroyClipboardRequest(Window window);
105
106 // X I/O error handler
107 void onError();
108 static int ioErrorHandler(Display*);
109
110private:
111 class CKeyEventFilter {
112 public:
113 int m_event;
114 Window m_window;
115 Time m_time;
116 KeyCode m_keycode;
117 };
118
119 Display* openDisplay(const char* displayName);
120 void saveShape();
121 Window openWindow() const;
122 void openIM();
123
124 bool grabMouseAndKeyboard();
125 void onKeyPress(XKeyEvent&);
126 void onKeyRelease(XKeyEvent&, bool isRepeat);
127 bool onHotKey(XKeyEvent&, bool isRepeat);
128 void onMousePress(const XButtonEvent&);
129 void onMouseRelease(const XButtonEvent&);
130 void onMouseMove(const XMotionEvent&);
131
132 void selectEvents(Window) const;
133 void doSelectEvents(Window) const;
134
135 KeyID mapKeyFromX(XKeyEvent*) const;
136 ButtonID mapButtonFromX(const XButtonEvent*) const;
137 unsigned int mapButtonToX(ButtonID id) const;
138
139 void warpCursorNoFlush(SInt32 x, SInt32 y);
140
141 void refreshKeyboard(XEvent*);
142
143 static Bool findKeyEvent(Display*, XEvent* xevent, XPointer arg);
144
145private:
146 struct CHotKeyItem {
147 public:
148 CHotKeyItem(int, unsigned int);
149
150 bool operator<(const CHotKeyItem&) const;
151
152 private:
153 int m_keycode;
154 unsigned int m_mask;
155 };
156 typedef std::set<bool> CFilteredKeycodes;
157 typedef std::vector<std::pair<int, unsigned int> > HotKeyList;
158 typedef std::map<UInt32, HotKeyList> HotKeyMap;
159 typedef std::vector<UInt32> HotKeyIDList;
160 typedef std::map<CHotKeyItem, UInt32> HotKeyToIDMap;
161
162 // true if screen is being used as a primary screen, false otherwise
163 bool m_isPrimary;
164
165 Display* m_display;
166 Window m_root;
167 Window m_window;
168
169 // true if mouse has entered the screen
170 bool m_isOnScreen;
171
172 // screen shape stuff
173 SInt32 m_x, m_y;
174 SInt32 m_w, m_h;
175 SInt32 m_xCenter, m_yCenter;
176
177 // last mouse position
178 SInt32 m_xCursor, m_yCursor;
179
180 // keyboard stuff
181 CXWindowsKeyState* m_keyState;
182
183 // hot key stuff
184 HotKeyMap m_hotKeys;
185 HotKeyIDList m_oldHotKeyIDs;
186 HotKeyToIDMap m_hotKeyToIDMap;
187
188 // input focus stuff
189 Window m_lastFocus;
190 int m_lastFocusRevert;
191
192 // input method stuff
193 XIM m_im;
194 XIC m_ic;
195 KeyCode m_lastKeycode;
196 CFilteredKeycodes m_filtered;
197
198 // clipboards
199 CXWindowsClipboard* m_clipboard[kClipboardEnd];
200 UInt32 m_sequenceNumber;
201
202 // screen saver stuff
203 CXWindowsScreenSaver* m_screensaver;
204 bool m_screensaverNotify;
205
206 // logical to physical button mapping. m_buttons[i] gives the
207 // physical button for logical button i+1.
208 std::vector<unsigned char> m_buttons;
209
210 // true if global auto-repeat was enabled before we turned it off
211 bool m_autoRepeat;
212
213 // stuff to workaround xtest being xinerama unaware. attempting
214 // to fake a mouse motion under xinerama may behave strangely,
215 // especially if screen 0 is not at 0,0 or if faking a motion on
216 // a screen other than screen 0.
217 bool m_xtestIsXineramaUnaware;
218 bool m_xinerama;
219
220 // XKB extension stuff
221 bool m_xkb;
222 int m_xkbEventBase;
223
224 // pointer to (singleton) screen. this is only needed by
225 // ioErrorHandler().
226 static CXWindowsScreen* s_screen;
227};
228
229#endif
Note: See TracBrowser for help on using the repository browser.