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

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

synergy v1.3.1 sources (zip).

File size: 4.7 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 CXWINDOWSUTIL_H
16#define CXWINDOWSUTIL_H
17
18#include "CString.h"
19#include "BasicTypes.h"
20#include "stdmap.h"
21#include "stdvector.h"
22#if X_DISPLAY_MISSING
23# error X11 is required to build synergy
24#else
25# include <X11/Xlib.h>
26#endif
27
28//! X11 utility functions
29class CXWindowsUtil {
30public:
31 typedef std::vector<KeySym> KeySyms;
32
33 //! Get property
34 /*!
35 Gets property \c property on \c window. \b Appends the data to
36 \c *data if \c data is not NULL, saves the property type in \c *type
37 if \c type is not NULL, and saves the property format in \c *format
38 if \c format is not NULL. If \c deleteProperty is true then the
39 property is deleted after being read.
40 */
41 static bool getWindowProperty(Display*,
42 Window window, Atom property,
43 CString* data, Atom* type,
44 SInt32* format, bool deleteProperty);
45
46 //! Set property
47 /*!
48 Sets property \c property on \c window to \c size bytes of data from
49 \c data.
50 */
51 static bool setWindowProperty(Display*,
52 Window window, Atom property,
53 const void* data, UInt32 size,
54 Atom type, SInt32 format);
55
56 //! Get X server time
57 /*!
58 Returns the current X server time.
59 */
60 static Time getCurrentTime(Display*, Window);
61
62 //! Convert KeySym to KeyID
63 /*!
64 Converts a KeySym to the equivalent KeyID. Returns kKeyNone if the
65 KeySym cannot be mapped.
66 */
67 static UInt32 mapKeySymToKeyID(KeySym);
68
69 //! Convert KeySym to corresponding KeyModifierMask
70 /*!
71 Converts a KeySym to the corresponding KeyModifierMask, or 0 if the
72 KeySym is not a modifier.
73 */
74 static UInt32 getModifierBitForKeySym(KeySym keysym);
75
76 //! Convert Atom to its string
77 /*!
78 Converts \p atom to its string representation.
79 */
80 static CString atomToString(Display*, Atom atom);
81
82 //! Convert several Atoms to a string
83 /*!
84 Converts each atom in \p atoms to its string representation and
85 concatenates the results.
86 */
87 static CString atomsToString(Display* display,
88 const Atom* atom, UInt32 num);
89
90 //! Prepare a property of atoms for use
91 /*!
92 64-bit systems may need to modify a property's data if it's a
93 list of Atoms before using it.
94 */
95 static void convertAtomProperty(CString& data);
96
97 //! Append an Atom to property data
98 /*!
99 Converts \p atom to a 32-bit on-the-wire format and appends it to
100 \p data.
101 */
102 static void appendAtomData(CString& data, Atom atom);
103
104 //! Replace an Atom in property data
105 /*!
106 Converts \p atom to a 32-bit on-the-wire format and replaces the atom
107 at index \p index in \p data.
108 */
109 static void replaceAtomData(CString& data,
110 UInt32 index, Atom atom);
111
112 //! Append an Time to property data
113 /*!
114 Converts \p time to a 32-bit on-the-wire format and appends it to
115 \p data.
116 */
117 static void appendTimeData(CString& data, Time time);
118
119 //! X11 error handler
120 /*!
121 This class sets an X error handler in the c'tor and restores the
122 previous error handler in the d'tor. A lock should only be
123 installed while the display is locked by the thread.
124
125 CErrorLock() ignores errors
126 CErrorLock(bool* flag) sets *flag to true if any error occurs
127 */
128 class CErrorLock {
129 public:
130 //! Error handler type
131 typedef void (*ErrorHandler)(Display*, XErrorEvent*, void* userData);
132
133 /*!
134 Ignore X11 errors.
135 */
136 CErrorLock(Display*);
137
138 /*!
139 Set \c *errorFlag if any error occurs.
140 */
141 CErrorLock(Display*, bool* errorFlag);
142
143 /*!
144 Call \c handler on each error.
145 */
146 CErrorLock(Display*, ErrorHandler handler, void* userData);
147
148 ~CErrorLock();
149
150 private:
151 void install(ErrorHandler, void*);
152 static int internalHandler(Display*, XErrorEvent*);
153 static void ignoreHandler(Display*, XErrorEvent*, void*);
154 static void saveHandler(Display*, XErrorEvent*, void*);
155
156 private:
157 typedef int (*XErrorHandler)(Display*, XErrorEvent*);
158
159 Display* m_display;
160 ErrorHandler m_handler;
161 void* m_userData;
162 XErrorHandler m_oldXHandler;
163 CErrorLock* m_next;
164 static CErrorLock* s_top;
165 };
166
167private:
168 class CPropertyNotifyPredicateInfo {
169 public:
170 Window m_window;
171 Atom m_property;
172 };
173
174 static Bool propertyNotifyPredicate(Display*,
175 XEvent* xevent, XPointer arg);
176
177 static void initKeyMaps();
178
179private:
180 typedef std::map<KeySym, UInt32> CKeySymMap;
181
182 static CKeySymMap s_keySymToUCS4;
183};
184
185#endif
Note: See TracBrowser for help on using the repository browser.