2003-09-03 02:05:47 +04:00
|
|
|
/*
|
|
|
|
* synergy -- mouse and keyboard sharing utility
|
|
|
|
* Copyright (C) 2003 Chris Schoeneman
|
|
|
|
*
|
|
|
|
* This package is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* found in the file COPYING that should have accompanied this file.
|
|
|
|
*
|
|
|
|
* This package is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
2004-03-21 23:01:41 +03:00
|
|
|
#ifndef CXWINDOWSKEYSTATE_H
|
|
|
|
#define CXWINDOWSKEYSTATE_H
|
2003-09-03 02:05:47 +04:00
|
|
|
|
2004-03-21 23:01:41 +03:00
|
|
|
#include "CKeyState.h"
|
2003-09-03 02:05:47 +04:00
|
|
|
#include "stdmap.h"
|
|
|
|
#if defined(X_DISPLAY_MISSING)
|
|
|
|
# error X11 is required to build synergy
|
|
|
|
#else
|
|
|
|
# include <X11/Xlib.h>
|
2004-03-21 23:01:41 +03:00
|
|
|
# if defined(HAVE_X11_EXTENSIONS_XTEST_H)
|
|
|
|
# include <X11/extensions/XTest.h>
|
|
|
|
# else
|
|
|
|
# error The XTest extension is required to build synergy
|
|
|
|
# endif
|
2003-09-03 02:05:47 +04:00
|
|
|
#endif
|
|
|
|
|
2004-03-21 23:01:41 +03:00
|
|
|
//! X Windows key state
|
2003-09-03 02:05:47 +04:00
|
|
|
/*!
|
2004-03-21 23:01:41 +03:00
|
|
|
A key state for X Windows.
|
2003-09-03 02:05:47 +04:00
|
|
|
*/
|
2004-03-21 23:01:41 +03:00
|
|
|
class CXWindowsKeyState : public CKeyState {
|
2003-09-03 02:05:47 +04:00
|
|
|
public:
|
2004-03-21 23:01:41 +03:00
|
|
|
CXWindowsKeyState(Display*);
|
|
|
|
~CXWindowsKeyState();
|
2003-09-03 02:05:47 +04:00
|
|
|
|
2004-03-21 23:01:41 +03:00
|
|
|
//! @name accessors
|
2003-09-03 02:05:47 +04:00
|
|
|
//@{
|
|
|
|
|
2004-03-21 23:01:41 +03:00
|
|
|
//! Convert X modifier mask to synergy mask
|
2003-09-03 02:05:47 +04:00
|
|
|
/*!
|
2004-03-21 23:01:41 +03:00
|
|
|
Returns the synergy modifier mask corresponding to the X modifier
|
|
|
|
mask in \p state.
|
2003-09-03 02:05:47 +04:00
|
|
|
*/
|
2004-03-21 23:01:41 +03:00
|
|
|
KeyModifierMask mapModifiersFromX(unsigned int state) const;
|
2003-09-03 02:05:47 +04:00
|
|
|
|
|
|
|
//@}
|
|
|
|
|
2004-03-21 23:01:41 +03:00
|
|
|
// IKeyState overrides
|
2004-03-26 23:59:26 +03:00
|
|
|
virtual bool fakeCtrlAltDel();
|
2004-03-21 23:01:41 +03:00
|
|
|
virtual const char* getKeyName(KeyButton) const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// IKeyState overrides
|
|
|
|
virtual void doUpdateKeys();
|
|
|
|
virtual void doFakeKeyEvent(KeyButton button,
|
|
|
|
bool press, bool isAutoRepeat);
|
|
|
|
virtual KeyButton mapKey(Keystrokes& keys, KeyID id,
|
2003-09-03 02:05:47 +04:00
|
|
|
KeyModifierMask desiredMask,
|
|
|
|
bool isAutoRepeat) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
class KeyMapping {
|
|
|
|
public:
|
|
|
|
KeyMapping();
|
|
|
|
|
|
|
|
public:
|
|
|
|
// KeyCode to generate keysym and whether keycode[i] is
|
|
|
|
// sensitive to shift and mode switch.
|
|
|
|
KeyCode m_keycode[4];
|
|
|
|
bool m_shiftSensitive[4];
|
|
|
|
bool m_modeSwitchSensitive[4];
|
|
|
|
|
|
|
|
// the modifier mask of keysym or 0 if not a modifier
|
|
|
|
KeyModifierMask m_modifierMask;
|
|
|
|
|
|
|
|
// whether keysym is sensitive to caps and num lock
|
|
|
|
bool m_numLockSensitive;
|
|
|
|
bool m_capsLockSensitive;
|
|
|
|
};
|
|
|
|
typedef std::map<KeySym, KeyMapping> KeySymMap;
|
|
|
|
typedef KeySymMap::const_iterator KeySymIndex;
|
|
|
|
|
2004-03-21 23:01:41 +03:00
|
|
|
// save the current keyboard mapping and note the modifiers
|
|
|
|
void updateKeysymMap();
|
2003-09-03 02:05:47 +04:00
|
|
|
|
|
|
|
// note interesting modifier KeySyms
|
|
|
|
void updateModifiers();
|
|
|
|
|
|
|
|
// map a modifier index and its KeySym to a modifier mask. also
|
|
|
|
// save the modifier mask in one of m_*Mask.
|
|
|
|
KeyModifierMask mapToModifierMask(unsigned int, KeySym);
|
|
|
|
|
|
|
|
// convert a KeyID to a KeySym
|
|
|
|
KeySym keyIDToKeySym(KeyID id, KeyModifierMask mask) const;
|
|
|
|
|
|
|
|
// map a KeySym into the keystrokes to produce it
|
2004-03-21 23:01:41 +03:00
|
|
|
KeyButton mapToKeystrokes(Keystrokes& keys,
|
2003-09-03 02:05:47 +04:00
|
|
|
KeySymIndex keyIndex,
|
|
|
|
bool isAutoRepeat) const;
|
|
|
|
|
|
|
|
// choose the best set of modifiers to generate the KeySym
|
|
|
|
unsigned int findBestKeyIndex(KeySymIndex keyIndex,
|
|
|
|
KeyModifierMask currentMask) const;
|
|
|
|
|
|
|
|
// returns true if the sense of shift is inverted for KeySym
|
|
|
|
bool isShiftInverted(KeySymIndex keyIndex,
|
|
|
|
KeyModifierMask currentMask) const;
|
|
|
|
|
|
|
|
// returns the keystrokes to adjust the modifiers into the desired
|
|
|
|
// state the keystrokes to get back to the current state.
|
2004-03-21 23:01:41 +03:00
|
|
|
bool adjustModifiers(Keystrokes& keys,
|
|
|
|
Keystrokes& undo,
|
2003-09-03 02:05:47 +04:00
|
|
|
KeyModifierMask desiredMask) const;
|
|
|
|
|
|
|
|
// returns true if keysym is sensitive to the NumLock state
|
|
|
|
bool isNumLockSensitive(KeySym keysym) const;
|
|
|
|
|
|
|
|
// returns true if keysym is sensitive to the CapsLock state
|
|
|
|
bool isCapsLockSensitive(KeySym keysym) const;
|
|
|
|
|
|
|
|
private:
|
2004-03-21 23:01:41 +03:00
|
|
|
Display* m_display;
|
|
|
|
|
2003-09-03 02:05:47 +04:00
|
|
|
// keysym to keycode mapping
|
|
|
|
KeySymMap m_keysymMap;
|
|
|
|
|
|
|
|
// the keyboard control state the last time this screen was entered
|
|
|
|
XKeyboardState m_keyControl;
|
|
|
|
|
|
|
|
// modifier keysyms
|
|
|
|
KeySym m_modeSwitchKeysym;
|
|
|
|
|
|
|
|
// modifier masks
|
|
|
|
unsigned int m_altMask;
|
|
|
|
unsigned int m_metaMask;
|
|
|
|
unsigned int m_superMask;
|
|
|
|
unsigned int m_modeSwitchMask;
|
|
|
|
unsigned int m_numLockMask;
|
|
|
|
unsigned int m_scrollLockMask;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|