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

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

synergy v1.3.1 sources (zip).

File size: 4.1 KB
Line 
1/*
2 * synergy -- mouse and keyboard sharing utility
3 * Copyright (C) 2003 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 CXWINDOWSKEYSTATE_H
16#define CXWINDOWSKEYSTATE_H
17
18#include "CKeyState.h"
19#include "stdmap.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# if HAVE_X11_EXTENSIONS_XTEST_H
26# include <X11/extensions/XTest.h>
27# else
28# error The XTest extension is required to build synergy
29# endif
30# if HAVE_XKB_EXTENSION
31# include <X11/extensions/XKBstr.h>
32# endif
33#endif
34
35//! X Windows key state
36/*!
37A key state for X Windows.
38*/
39class CXWindowsKeyState : public CKeyState {
40public:
41 typedef std::vector<int> CKeycodeList;
42 enum {
43 kGroupPoll = -1,
44 kGroupPollAndSet = -2
45 };
46
47 CXWindowsKeyState(Display*, bool useXKB);
48 ~CXWindowsKeyState();
49
50 //! @name modifiers
51 //@{
52
53 //! Set active group
54 /*!
55 Sets the active group to \p group. This is the group returned by
56 \c pollActiveGroup(). If \p group is \c kGroupPoll then
57 \c pollActiveGroup() will really poll, but that's a slow operation
58 on X11. If \p group is \c kGroupPollAndSet then this will poll the
59 active group now and use it for future calls to \c pollActiveGroup().
60 */
61 void setActiveGroup(SInt32 group);
62
63 //! Set the auto-repeat state
64 /*!
65 Sets the auto-repeat state.
66 */
67 void setAutoRepeat(const XKeyboardState&);
68
69 //@}
70 //! @name accessors
71 //@{
72
73 //! Convert X modifier mask to synergy mask
74 /*!
75 Returns the synergy modifier mask corresponding to the X modifier
76 mask in \p state.
77 */
78 KeyModifierMask mapModifiersFromX(unsigned int state) const;
79
80 //! Convert synergy modifier mask to X mask
81 /*!
82 Converts the synergy modifier mask to the corresponding X modifier
83 mask. Returns \c true if successful and \c false if any modifier
84 could not be converted.
85 */
86 bool mapModifiersToX(KeyModifierMask, unsigned int&) const;
87
88 //! Convert synergy key to all corresponding X keycodes
89 /*!
90 Converts the synergy key \p key to all of the keycodes that map to
91 that key.
92 */
93 void mapKeyToKeycodes(KeyID key,
94 CKeycodeList& keycodes) const;
95
96 //@}
97
98 // IKeyState overrides
99 virtual bool fakeCtrlAltDel();
100 virtual KeyModifierMask
101 pollActiveModifiers() const;
102 virtual SInt32 pollActiveGroup() const;
103 virtual void pollPressedKeys(KeyButtonSet& pressedKeys) const;
104
105protected:
106 // CKeyState overrides
107 virtual void getKeyMap(CKeyMap& keyMap);
108 virtual void fakeKey(const Keystroke& keystroke);
109
110private:
111 void updateKeysymMap(CKeyMap&);
112 void updateKeysymMapXKB(CKeyMap&);
113 bool hasModifiersXKB() const;
114 int getEffectiveGroup(KeyCode, int group) const;
115 UInt32 getGroupFromState(unsigned int state) const;
116
117 static void remapKeyModifiers(KeyID, SInt32,
118 CKeyMap::KeyItem&, void*);
119
120private:
121 struct XKBModifierInfo {
122 public:
123 unsigned char m_level;
124 UInt32 m_mask;
125 bool m_lock;
126 };
127
128 typedef std::vector<KeyModifierMask> KeyModifierMaskList;
129 typedef std::map<KeyModifierMask, unsigned int> KeyModifierToXMask;
130 typedef std::multimap<KeyID, KeyCode> KeyToKeyCodeMap;
131 typedef std::map<KeyCode, unsigned int> NonXKBModifierMap;
132 typedef std::map<UInt32, XKBModifierInfo> XKBModifierMap;
133
134 Display* m_display;
135#if HAVE_XKB_EXTENSION
136 XkbDescPtr m_xkb;
137#endif
138 SInt32 m_group;
139 XKBModifierMap m_lastGoodXKBModifiers;
140 NonXKBModifierMap m_lastGoodNonXKBModifiers;
141
142 // X modifier (bit number) to synergy modifier (mask) mapping
143 KeyModifierMaskList m_modifierFromX;
144
145 // synergy modifier (mask) to X modifier (mask)
146 KeyModifierToXMask m_modifierToX;
147
148 // map KeyID to all keycodes that can synthesize that KeyID
149 KeyToKeyCodeMap m_keyCodeFromKey;
150
151 // autorepeat state
152 XKeyboardState m_keyboardState;
153};
154
155#endif
Note: See TracBrowser for help on using the repository browser.