CXWindowsKeyState.h

00001 /*
00002  * synergy -- mouse and keyboard sharing utility
00003  * Copyright (C) 2003 Chris Schoeneman
00004  * 
00005  * This package is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * found in the file COPYING that should have accompanied this file.
00008  * 
00009  * This package is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  */
00014 
00015 #ifndef CXWINDOWSKEYSTATE_H
00016 #define CXWINDOWSKEYSTATE_H
00017 
00018 #include "CKeyState.h"
00019 #include "stdmap.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 #   if HAVE_X11_EXTENSIONS_XTEST_H
00026 #       include <X11/extensions/XTest.h>
00027 #   else
00028 #       error The XTest extension is required to build synergy
00029 #   endif
00030 #   if HAVE_XKB_EXTENSION
00031 #       include <X11/extensions/XKBstr.h>
00032 #   endif
00033 #endif
00034 
00036 
00039 class CXWindowsKeyState : public CKeyState {
00040 public:
00041     typedef std::vector<int> CKeycodeList;
00042     enum {
00043         kGroupPoll       = -1,
00044         kGroupPollAndSet = -2
00045     };
00046 
00047     CXWindowsKeyState(Display*, bool useXKB);
00048     ~CXWindowsKeyState();
00049 
00051 
00052 
00054 
00061     void                setActiveGroup(SInt32 group);
00062 
00064 
00067     void                setAutoRepeat(const XKeyboardState&);
00068 
00070 
00071 
00072 
00074 
00078     KeyModifierMask     mapModifiersFromX(unsigned int state) const;
00079 
00081 
00086     bool                mapModifiersToX(KeyModifierMask, unsigned int&) const;
00087 
00089 
00093     void                mapKeyToKeycodes(KeyID key,
00094                             CKeycodeList& keycodes) const;
00095 
00097 
00098     // IKeyState overrides
00099     virtual bool        fakeCtrlAltDel();
00100     virtual KeyModifierMask
00101                         pollActiveModifiers() const;
00102     virtual SInt32      pollActiveGroup() const;
00103     virtual void        pollPressedKeys(KeyButtonSet& pressedKeys) const;
00104 
00105 protected:
00106     // CKeyState overrides
00107     virtual void        getKeyMap(CKeyMap& keyMap);
00108     virtual void        fakeKey(const Keystroke& keystroke);
00109 
00110 private:
00111     void                updateKeysymMap(CKeyMap&);
00112     void                updateKeysymMapXKB(CKeyMap&);
00113     bool                hasModifiersXKB() const;
00114     int                 getEffectiveGroup(KeyCode, int group) const;
00115     UInt32              getGroupFromState(unsigned int state) const;
00116 
00117     static void         remapKeyModifiers(KeyID, SInt32,
00118                             CKeyMap::KeyItem&, void*);
00119 
00120 private:
00121     struct XKBModifierInfo {
00122     public:
00123         unsigned char   m_level;
00124         UInt32          m_mask;
00125         bool            m_lock;
00126     };
00127 
00128     typedef std::vector<KeyModifierMask> KeyModifierMaskList;
00129     typedef std::map<KeyModifierMask, unsigned int> KeyModifierToXMask;
00130     typedef std::multimap<KeyID, KeyCode> KeyToKeyCodeMap;
00131     typedef std::map<KeyCode, unsigned int> NonXKBModifierMap;
00132     typedef std::map<UInt32, XKBModifierInfo> XKBModifierMap;
00133 
00134     Display*            m_display;
00135 #if HAVE_XKB_EXTENSION
00136     XkbDescPtr          m_xkb;
00137 #endif
00138     SInt32              m_group;
00139     XKBModifierMap      m_lastGoodXKBModifiers;
00140     NonXKBModifierMap   m_lastGoodNonXKBModifiers;
00141 
00142     // X modifier (bit number) to synergy modifier (mask) mapping
00143     KeyModifierMaskList m_modifierFromX;
00144 
00145     // synergy modifier (mask) to X modifier (mask)
00146     KeyModifierToXMask  m_modifierToX;
00147 
00148     // map KeyID to all keycodes that can synthesize that KeyID
00149     KeyToKeyCodeMap     m_keyCodeFromKey;
00150 
00151     // autorepeat state
00152     XKeyboardState      m_keyboardState;
00153 };
00154 
00155 #endif

Generated on Fri Nov 6 00:18:45 2009 for synergy-plus by  doxygen 1.4.7