~nobuto/ubuntu/natty/synergy/merge-from-experimental

« back to all changes in this revision

Viewing changes to lib/platform/CXWindowsUtil.h

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Lutz
  • Date: 2003-10-31 19:36:30 UTC
  • Revision ID: james.westby@ubuntu.com-20031031193630-knbv79x5az7qh49y
Tags: upstream-1.0.14
ImportĀ upstreamĀ versionĀ 1.0.14

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
#if defined(X_DISPLAY_MISSING)
 
22
#       error X11 is required to build synergy
 
23
#else
 
24
#       include <X11/Xlib.h>
 
25
#endif
 
26
 
 
27
//! X11 utility functions
 
28
class CXWindowsUtil {
 
29
public:
 
30
        //! Get property
 
31
        /*!
 
32
        Gets property \c property on \c window.  \b Appends the data to
 
33
        \c *data if \c data is not NULL, saves the property type in \c *type
 
34
        if \c type is not NULL, and saves the property format in \c *format
 
35
        if \c format is not NULL.  If \c deleteProperty is true then the
 
36
        property is deleted after being read.
 
37
        */
 
38
        static bool                     getWindowProperty(Display*,
 
39
                                                        Window window, Atom property,
 
40
                                                        CString* data, Atom* type,
 
41
                                                        SInt32* format, bool deleteProperty);
 
42
 
 
43
        //! Set property
 
44
        /*!
 
45
        Sets property \c property on \c window to \c size bytes of data from
 
46
        \c data.
 
47
        */
 
48
        static bool                     setWindowProperty(Display*,
 
49
                                                        Window window, Atom property,
 
50
                                                        const void* data, UInt32 size,
 
51
                                                        Atom type, SInt32 format);
 
52
 
 
53
        //! Get X server time
 
54
        /*!
 
55
        Returns the current X server time.
 
56
        */
 
57
        static Time                     getCurrentTime(Display*, Window);
 
58
 
 
59
        //! Convert KeySym to UCS-4
 
60
        /*!
 
61
        Converts a KeySym to the equivalent UCS-4 character.  Returns
 
62
        0x0000ffff if the KeySym cannot be mapped.
 
63
        */
 
64
        static UInt32           mapKeySymToUCS4(KeySym);
 
65
 
 
66
        //! Convert UCS-4 to KeySym
 
67
        /*!
 
68
        Converts a UCS-4 character to the equivalent KeySym.  Returns
 
69
        NoSymbol (0) if the character cannot be mapped.
 
70
        */
 
71
        static KeySym           mapUCS4ToKeySym(UInt32);
 
72
 
 
73
        //! X11 error handler
 
74
        /*!
 
75
        This class sets an X error handler in the c'tor and restores the
 
76
        previous error handler in the d'tor.  A lock should only be
 
77
        installed while the display is locked by the thread.
 
78
        
 
79
        CErrorLock() ignores errors
 
80
        CErrorLock(bool* flag) sets *flag to true if any error occurs
 
81
        */
 
82
        class CErrorLock {
 
83
        public:
 
84
                //! Error handler type
 
85
                typedef void (*ErrorHandler)(Display*, XErrorEvent*, void* userData);
 
86
 
 
87
                /*!
 
88
                Ignore X11 errors.
 
89
                */
 
90
                CErrorLock(Display*);
 
91
 
 
92
                /*!
 
93
                Set \c *errorFlag if any error occurs.
 
94
                */
 
95
                CErrorLock(Display*, bool* errorFlag);
 
96
 
 
97
                /*!
 
98
                Call \c handler on each error.
 
99
                */
 
100
                CErrorLock(Display*, ErrorHandler handler, void* userData);
 
101
 
 
102
                ~CErrorLock();
 
103
 
 
104
        private:
 
105
                void                    install(ErrorHandler, void*);
 
106
                static int              internalHandler(Display*, XErrorEvent*);
 
107
                static void             ignoreHandler(Display*, XErrorEvent*, void*);
 
108
                static void             saveHandler(Display*, XErrorEvent*, void*);
 
109
 
 
110
        private:
 
111
                typedef int (*XErrorHandler)(Display*, XErrorEvent*);
 
112
 
 
113
                Display*                m_display;
 
114
                ErrorHandler    m_handler;
 
115
                void*                   m_userData;
 
116
                XErrorHandler   m_oldXHandler;
 
117
                CErrorLock*             m_next;
 
118
                static CErrorLock*      s_top;
 
119
        };
 
120
 
 
121
private:
 
122
        class CPropertyNotifyPredicateInfo {
 
123
        public:
 
124
                Window                  m_window;
 
125
                Atom                    m_property;
 
126
        };
 
127
 
 
128
        static Bool                     propertyNotifyPredicate(Display*,
 
129
                                                        XEvent* xevent, XPointer arg);
 
130
 
 
131
        static void                     initKeyMaps();
 
132
 
 
133
private:
 
134
        typedef std::map<KeySym, UInt32> CKeySymMap;
 
135
        typedef std::map<UInt32, KeySym> CUCS4Map;
 
136
 
 
137
        static CKeySymMap       s_keySymToUCS4;
 
138
        static CUCS4Map         s_UCS4ToKeySym;
 
139
};
 
140
 
 
141
#endif