mirror of
https://github.com/debauchee/barrier.git
synced 2026-11-26 05:42:24 +08:00
Checkpoint. Converted X11 to new keyboard state tracking design.
This new design is simpler. For keyboard support, clients need only implement 4 virtual methods on a class derived from CKeyState and one trivial method in the class derived from CPlatformScreen, which is now the superclass of platform screens instead of IPlatformScreen. Keyboard methods have been removed from IPlatformScreen, IPrimaryScreen and ISecondaryScreen. Also, all keyboard state tracking is now in exactly one place (the CKeyState subclass) rather than in CScreen, the platform screen, and the key mapper. Still need to convert Win32.
This commit is contained in:
@@ -12,9 +12,10 @@
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "CXWindowsKeyMapper.h"
|
||||
#include "CXWindowsKeyState.h"
|
||||
#include "CXWindowsUtil.h"
|
||||
#include "CLog.h"
|
||||
#include "CStringUtil.h"
|
||||
#if defined(X_DISPLAY_MISSING)
|
||||
# error X11 is required to build synergy
|
||||
#else
|
||||
@@ -137,73 +138,119 @@ static const KeySym g_mapE000[] =
|
||||
};
|
||||
#endif
|
||||
|
||||
CXWindowsKeyMapper::CXWindowsKeyMapper()
|
||||
CXWindowsKeyState::CXWindowsKeyState(Display* display) :
|
||||
m_display(display)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
CXWindowsKeyMapper::~CXWindowsKeyMapper()
|
||||
CXWindowsKeyState::~CXWindowsKeyState()
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
KeyModifierMask
|
||||
CXWindowsKeyState::mapModifiersFromX(unsigned int state) const
|
||||
{
|
||||
KeyModifierMask mask = 0;
|
||||
if (state & ShiftMask)
|
||||
mask |= KeyModifierShift;
|
||||
if (state & LockMask)
|
||||
mask |= KeyModifierCapsLock;
|
||||
if (state & ControlMask)
|
||||
mask |= KeyModifierControl;
|
||||
if (state & m_altMask)
|
||||
mask |= KeyModifierAlt;
|
||||
if (state & m_metaMask)
|
||||
mask |= KeyModifierMeta;
|
||||
if (state & m_superMask)
|
||||
mask |= KeyModifierSuper;
|
||||
if (state & m_modeSwitchMask)
|
||||
mask |= KeyModifierModeSwitch;
|
||||
if (state & m_numLockMask)
|
||||
mask |= KeyModifierNumLock;
|
||||
if (state & m_scrollLockMask)
|
||||
mask |= KeyModifierScrollLock;
|
||||
return mask;
|
||||
}
|
||||
|
||||
const char*
|
||||
CXWindowsKeyState::getKeyName(KeyButton keycode) const
|
||||
{
|
||||
KeySym keysym = XKeycodeToKeysym(m_display, keycode, 0);
|
||||
char* name = XKeysymToString(keysym);
|
||||
if (name != NULL) {
|
||||
return name;
|
||||
}
|
||||
else {
|
||||
static char buffer[20];
|
||||
return strcpy(buffer,
|
||||
CStringUtil::print("keycode %d", keycode).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
CXWindowsKeyMapper::update(Display* display, IKeyState* keyState)
|
||||
CXWindowsKeyState::doUpdateKeys()
|
||||
{
|
||||
// query which keys are pressed
|
||||
char keys[32];
|
||||
XQueryKeymap(display, keys);
|
||||
XQueryKeymap(m_display, keys);
|
||||
|
||||
// save the auto-repeat mask
|
||||
XGetKeyboardControl(display, &m_keyControl);
|
||||
XGetKeyboardControl(m_display, &m_keyControl);
|
||||
|
||||
// query the pointer to get the keyboard state
|
||||
Window root = DefaultRootWindow(display), window;
|
||||
Window root = DefaultRootWindow(m_display), window;
|
||||
int xRoot, yRoot, xWindow, yWindow;
|
||||
unsigned int state;
|
||||
if (!XQueryPointer(display, root, &root, &window,
|
||||
if (!XQueryPointer(m_display, root, &root, &window,
|
||||
&xRoot, &yRoot, &xWindow, &yWindow, &state)) {
|
||||
state = 0;
|
||||
}
|
||||
|
||||
// update mappings
|
||||
updateKeysymMap(display, keyState);
|
||||
updateKeysymMap();
|
||||
updateModifiers();
|
||||
|
||||
// transfer to our state
|
||||
for (UInt32 i = 0, j = 0; i < 32; j += 8, ++i) {
|
||||
if ((keys[i] & 0x01) != 0)
|
||||
keyState->setKeyDown(j + 0, true);
|
||||
setKeyDown(j + 0, true);
|
||||
if ((keys[i] & 0x02) != 0)
|
||||
keyState->setKeyDown(j + 1, true);
|
||||
setKeyDown(j + 1, true);
|
||||
if ((keys[i] & 0x04) != 0)
|
||||
keyState->setKeyDown(j + 2, true);
|
||||
setKeyDown(j + 2, true);
|
||||
if ((keys[i] & 0x08) != 0)
|
||||
keyState->setKeyDown(j + 3, true);
|
||||
setKeyDown(j + 3, true);
|
||||
if ((keys[i] & 0x10) != 0)
|
||||
keyState->setKeyDown(j + 4, true);
|
||||
setKeyDown(j + 4, true);
|
||||
if ((keys[i] & 0x20) != 0)
|
||||
keyState->setKeyDown(j + 5, true);
|
||||
setKeyDown(j + 5, true);
|
||||
if ((keys[i] & 0x40) != 0)
|
||||
keyState->setKeyDown(j + 6, true);
|
||||
setKeyDown(j + 6, true);
|
||||
if ((keys[i] & 0x80) != 0)
|
||||
keyState->setKeyDown(j + 7, true);
|
||||
setKeyDown(j + 7, true);
|
||||
}
|
||||
|
||||
// set toggle modifier states
|
||||
if ((state & LockMask) != 0)
|
||||
keyState->setToggled(KeyModifierCapsLock);
|
||||
setToggled(KeyModifierCapsLock);
|
||||
if ((state & m_numLockMask) != 0)
|
||||
keyState->setToggled(KeyModifierNumLock);
|
||||
setToggled(KeyModifierNumLock);
|
||||
if ((state & m_scrollLockMask) != 0)
|
||||
keyState->setToggled(KeyModifierScrollLock);
|
||||
setToggled(KeyModifierScrollLock);
|
||||
}
|
||||
|
||||
void
|
||||
CXWindowsKeyState::doFakeKeyEvent(KeyButton keycode, bool press, bool)
|
||||
{
|
||||
XTestFakeKeyEvent(m_display, keycode, press ? True : False, CurrentTime);
|
||||
XFlush(m_display);
|
||||
}
|
||||
|
||||
KeyButton
|
||||
CXWindowsKeyMapper::mapKey(IKeyState::Keystrokes& keys,
|
||||
const IKeyState& keyState, KeyID id,
|
||||
KeyModifierMask desiredMask,
|
||||
bool isAutoRepeat) const
|
||||
CXWindowsKeyState::mapKey(Keystrokes& keys, KeyID id,
|
||||
KeyModifierMask desiredMask, bool isAutoRepeat) const
|
||||
{
|
||||
// the system translates key events into characters depending
|
||||
// on the modifier key state at the time of the event. to
|
||||
@@ -243,7 +290,7 @@ CXWindowsKeyMapper::mapKey(IKeyState::Keystrokes& keys,
|
||||
if (keyIndex != m_keysymMap.end()) {
|
||||
// the keysym is mapped to some keycode. create the keystrokes
|
||||
// for this keysym.
|
||||
return mapToKeystrokes(keys, keyState, keyIndex, isAutoRepeat);
|
||||
return mapToKeystrokes(keys, keyIndex, isAutoRepeat);
|
||||
}
|
||||
|
||||
// we can't find the keysym mapped to any keycode. this doesn't
|
||||
@@ -272,7 +319,7 @@ CXWindowsKeyMapper::mapKey(IKeyState::Keystrokes& keys,
|
||||
}
|
||||
|
||||
// the keysym is mapped to some keycode
|
||||
keycode = mapToKeystrokes(keys, keyState, keyIndex, isAutoRepeat);
|
||||
keycode = mapToKeystrokes(keys, keyIndex, isAutoRepeat);
|
||||
if (keycode == 0) {
|
||||
return 0;
|
||||
}
|
||||
@@ -281,45 +328,20 @@ CXWindowsKeyMapper::mapKey(IKeyState::Keystrokes& keys,
|
||||
return keycode;
|
||||
}
|
||||
|
||||
KeyModifierMask
|
||||
CXWindowsKeyMapper::mapModifier(unsigned int state) const
|
||||
{
|
||||
KeyModifierMask mask = 0;
|
||||
if (state & ShiftMask)
|
||||
mask |= KeyModifierShift;
|
||||
if (state & LockMask)
|
||||
mask |= KeyModifierCapsLock;
|
||||
if (state & ControlMask)
|
||||
mask |= KeyModifierControl;
|
||||
if (state & m_altMask)
|
||||
mask |= KeyModifierAlt;
|
||||
if (state & m_metaMask)
|
||||
mask |= KeyModifierMeta;
|
||||
if (state & m_superMask)
|
||||
mask |= KeyModifierSuper;
|
||||
if (state & m_modeSwitchMask)
|
||||
mask |= KeyModifierModeSwitch;
|
||||
if (state & m_numLockMask)
|
||||
mask |= KeyModifierNumLock;
|
||||
if (state & m_scrollLockMask)
|
||||
mask |= KeyModifierScrollLock;
|
||||
return mask;
|
||||
}
|
||||
|
||||
void
|
||||
CXWindowsKeyMapper::updateKeysymMap(Display* display, IKeyState* keyState)
|
||||
CXWindowsKeyState::updateKeysymMap()
|
||||
{
|
||||
// there are up to 4 keysyms per keycode
|
||||
static const unsigned int maxKeysyms = 4;
|
||||
|
||||
// get the number of keycodes
|
||||
int minKeycode, maxKeycode;
|
||||
XDisplayKeycodes(display, &minKeycode, &maxKeycode);
|
||||
XDisplayKeycodes(m_display, &minKeycode, &maxKeycode);
|
||||
const int numKeycodes = maxKeycode - minKeycode + 1;
|
||||
|
||||
// get the keyboard mapping for all keys
|
||||
int keysymsPerKeycode;
|
||||
KeySym* keysyms = XGetKeyboardMapping(display,
|
||||
KeySym* keysyms = XGetKeyboardMapping(m_display,
|
||||
minKeycode, numKeycodes,
|
||||
&keysymsPerKeycode);
|
||||
|
||||
@@ -364,7 +386,7 @@ CXWindowsKeyMapper::updateKeysymMap(Display* display, IKeyState* keyState)
|
||||
}
|
||||
|
||||
// get modifier map from server
|
||||
XModifierKeymap* modifiers = XGetModifierMapping(display);
|
||||
XModifierKeymap* modifiers = XGetModifierMapping(m_display);
|
||||
unsigned int keysPerModifier = modifiers->max_keypermod;
|
||||
|
||||
// clear state
|
||||
@@ -387,7 +409,7 @@ CXWindowsKeyMapper::updateKeysymMap(Display* display, IKeyState* keyState)
|
||||
for (unsigned int i = 0; i < 8; ++i) {
|
||||
// no keycodes for this modifier yet
|
||||
KeyModifierMask mask = 0;
|
||||
IKeyState::KeyButtons modifierKeys;
|
||||
KeyButtons modifierKeys;
|
||||
|
||||
// add each keycode for modifier
|
||||
for (unsigned int j = 0; j < keysPerModifier; ++j) {
|
||||
@@ -429,9 +451,9 @@ CXWindowsKeyMapper::updateKeysymMap(Display* display, IKeyState* keyState)
|
||||
mapping.m_numLockSensitive = false;
|
||||
}
|
||||
|
||||
// tell keyState about this modifier
|
||||
if (mask != 0 && keyState != NULL) {
|
||||
keyState->addModifier(mask, modifierKeys);
|
||||
// note this modifier
|
||||
if (mask != 0) {
|
||||
addModifier(mask, modifierKeys);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -485,7 +507,7 @@ CXWindowsKeyMapper::updateKeysymMap(Display* display, IKeyState* keyState)
|
||||
}
|
||||
|
||||
KeyModifierMask
|
||||
CXWindowsKeyMapper::mapToModifierMask(unsigned int i, KeySym keysym)
|
||||
CXWindowsKeyState::mapToModifierMask(unsigned int i, KeySym keysym)
|
||||
{
|
||||
// some modifier indices (0,1,2) are dedicated to particular uses,
|
||||
// the rest depend on the keysyms bound.
|
||||
@@ -546,16 +568,16 @@ CXWindowsKeyMapper::mapToModifierMask(unsigned int i, KeySym keysym)
|
||||
}
|
||||
|
||||
void
|
||||
CXWindowsKeyMapper::updateModifiers()
|
||||
CXWindowsKeyState::updateModifiers()
|
||||
{
|
||||
struct CModifierBitInfo {
|
||||
public:
|
||||
KeySym CXWindowsKeyMapper::*m_keysym;
|
||||
KeySym CXWindowsKeyState::*m_keysym;
|
||||
KeySym m_left;
|
||||
KeySym m_right;
|
||||
};
|
||||
static const CModifierBitInfo s_modifierBitTable[] = {
|
||||
{ &CXWindowsKeyMapper::m_modeSwitchKeysym, XK_Mode_switch, NoSymbol },
|
||||
{ &CXWindowsKeyState::m_modeSwitchKeysym, XK_Mode_switch, NoSymbol },
|
||||
};
|
||||
|
||||
// choose the keysym to use for some modifiers. if a modifier has
|
||||
@@ -603,7 +625,7 @@ CXWindowsKeyMapper::updateModifiers()
|
||||
}
|
||||
|
||||
KeySym
|
||||
CXWindowsKeyMapper::keyIDToKeySym(KeyID id, KeyModifierMask mask) const
|
||||
CXWindowsKeyState::keyIDToKeySym(KeyID id, KeyModifierMask mask) const
|
||||
{
|
||||
// convert id to keysym
|
||||
KeySym keysym = NoSymbol;
|
||||
@@ -718,15 +740,13 @@ CXWindowsKeyMapper::keyIDToKeySym(KeyID id, KeyModifierMask mask) const
|
||||
}
|
||||
|
||||
KeyButton
|
||||
CXWindowsKeyMapper::mapToKeystrokes(IKeyState::Keystrokes& keys,
|
||||
const IKeyState& keyState,
|
||||
KeySymIndex keyIndex,
|
||||
bool isAutoRepeat) const
|
||||
CXWindowsKeyState::mapToKeystrokes(Keystrokes& keys,
|
||||
KeySymIndex keyIndex, bool isAutoRepeat) const
|
||||
{
|
||||
// keyIndex must be valid
|
||||
assert(keyIndex != m_keysymMap.end());
|
||||
|
||||
KeyModifierMask currentMask = keyState.getActiveModifiers();
|
||||
KeyModifierMask currentMask = getActiveModifiers();
|
||||
|
||||
// get the keysym we're trying to generate and possible keycodes
|
||||
const KeySym keysym = keyIndex->first;
|
||||
@@ -798,14 +818,14 @@ CXWindowsKeyMapper::mapToKeystrokes(IKeyState::Keystrokes& keys,
|
||||
}
|
||||
|
||||
// adjust the modifiers to match the desired modifiers
|
||||
IKeyState::Keystrokes undo;
|
||||
if (!adjustModifiers(keys, undo, keyState, desiredMask)) {
|
||||
Keystrokes undo;
|
||||
if (!adjustModifiers(keys, undo, desiredMask)) {
|
||||
LOG((CLOG_DEBUG2 "failed to adjust modifiers"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
// add the key event
|
||||
IKeyState::Keystroke keystroke;
|
||||
Keystroke keystroke;
|
||||
keystroke.m_key = keycode;
|
||||
if (!isAutoRepeat) {
|
||||
keystroke.m_press = true;
|
||||
@@ -830,7 +850,7 @@ CXWindowsKeyMapper::mapToKeystrokes(IKeyState::Keystrokes& keys,
|
||||
}
|
||||
|
||||
unsigned int
|
||||
CXWindowsKeyMapper::findBestKeyIndex(KeySymIndex keyIndex,
|
||||
CXWindowsKeyState::findBestKeyIndex(KeySymIndex keyIndex,
|
||||
KeyModifierMask /*currentMask*/) const
|
||||
{
|
||||
// there are up to 4 keycodes per keysym to choose from. the
|
||||
@@ -856,7 +876,7 @@ CXWindowsKeyMapper::findBestKeyIndex(KeySymIndex keyIndex,
|
||||
}
|
||||
|
||||
bool
|
||||
CXWindowsKeyMapper::isShiftInverted(KeySymIndex keyIndex,
|
||||
CXWindowsKeyState::isShiftInverted(KeySymIndex keyIndex,
|
||||
KeyModifierMask currentMask) const
|
||||
{
|
||||
// each keycode has up to 4 keysym associated with it, one each for:
|
||||
@@ -885,12 +905,11 @@ CXWindowsKeyMapper::isShiftInverted(KeySymIndex keyIndex,
|
||||
}
|
||||
|
||||
bool
|
||||
CXWindowsKeyMapper::adjustModifiers(IKeyState::Keystrokes& keys,
|
||||
IKeyState::Keystrokes& undo,
|
||||
const IKeyState& keyState,
|
||||
CXWindowsKeyState::adjustModifiers(Keystrokes& keys,
|
||||
Keystrokes& undo,
|
||||
KeyModifierMask desiredMask) const
|
||||
{
|
||||
KeyModifierMask currentMask = keyState.getActiveModifiers();
|
||||
KeyModifierMask currentMask = getActiveModifiers();
|
||||
|
||||
// get mode switch set correctly. do this before shift because
|
||||
// mode switch may be sensitive to the shift modifier and will
|
||||
@@ -909,8 +928,7 @@ CXWindowsKeyMapper::adjustModifiers(IKeyState::Keystrokes& keys,
|
||||
if (wantShift != haveShift) {
|
||||
// add shift keystrokes
|
||||
LOG((CLOG_DEBUG2 "fix shift for mode switch"));
|
||||
if (!keyState.mapModifier(keys, undo,
|
||||
KeyModifierShift, wantShift)) {
|
||||
if (!mapModifier(keys, undo, KeyModifierShift, wantShift)) {
|
||||
return false;
|
||||
}
|
||||
currentMask ^= KeyModifierShift;
|
||||
@@ -918,8 +936,7 @@ CXWindowsKeyMapper::adjustModifiers(IKeyState::Keystrokes& keys,
|
||||
}
|
||||
|
||||
// add mode switch keystrokes
|
||||
if (!keyState.mapModifier(keys, undo,
|
||||
KeyModifierModeSwitch, wantModeSwitch)) {
|
||||
if (!mapModifier(keys, undo, KeyModifierModeSwitch, wantModeSwitch)) {
|
||||
return false;
|
||||
}
|
||||
currentMask ^= KeyModifierModeSwitch;
|
||||
@@ -931,7 +948,7 @@ CXWindowsKeyMapper::adjustModifiers(IKeyState::Keystrokes& keys,
|
||||
if (wantShift != haveShift) {
|
||||
// add shift keystrokes
|
||||
LOG((CLOG_DEBUG2 "fix shift"));
|
||||
if (!keyState.mapModifier(keys, undo, KeyModifierShift, wantShift)) {
|
||||
if (!mapModifier(keys, undo, KeyModifierShift, wantShift)) {
|
||||
return false;
|
||||
}
|
||||
currentMask ^= KeyModifierShift;
|
||||
@@ -941,13 +958,13 @@ CXWindowsKeyMapper::adjustModifiers(IKeyState::Keystrokes& keys,
|
||||
}
|
||||
|
||||
bool
|
||||
CXWindowsKeyMapper::isNumLockSensitive(KeySym keysym) const
|
||||
CXWindowsKeyState::isNumLockSensitive(KeySym keysym) const
|
||||
{
|
||||
return (IsKeypadKey(keysym) || IsPrivateKeypadKey(keysym));
|
||||
}
|
||||
|
||||
bool
|
||||
CXWindowsKeyMapper::isCapsLockSensitive(KeySym keysym) const
|
||||
CXWindowsKeyState::isCapsLockSensitive(KeySym keysym) const
|
||||
{
|
||||
KeySym lKey, uKey;
|
||||
XConvertCase(keysym, &lKey, &uKey);
|
||||
@@ -956,10 +973,10 @@ CXWindowsKeyMapper::isCapsLockSensitive(KeySym keysym) const
|
||||
|
||||
|
||||
//
|
||||
// CXWindowsKeyMapper::KeyMapping
|
||||
// CXWindowsKeyState::KeyMapping
|
||||
//
|
||||
|
||||
CXWindowsKeyMapper::KeyMapping::KeyMapping()
|
||||
CXWindowsKeyState::KeyMapping::KeyMapping()
|
||||
{
|
||||
m_keycode[0] = 0;
|
||||
m_keycode[1] = 0;
|
||||
@@ -12,62 +12,55 @@
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef CXWINDOWSKEYMAPPER_H
|
||||
#define CXWINDOWSKEYMAPPER_H
|
||||
#ifndef CXWINDOWSKEYSTATE_H
|
||||
#define CXWINDOWSKEYSTATE_H
|
||||
|
||||
#include "IKeyState.h"
|
||||
#include "CKeyState.h"
|
||||
#include "stdmap.h"
|
||||
#if defined(X_DISPLAY_MISSING)
|
||||
# error X11 is required to build synergy
|
||||
#else
|
||||
# include <X11/Xlib.h>
|
||||
# if defined(HAVE_X11_EXTENSIONS_XTEST_H)
|
||||
# include <X11/extensions/XTest.h>
|
||||
# else
|
||||
# error The XTest extension is required to build synergy
|
||||
# endif
|
||||
#endif
|
||||
|
||||
//! X Windows key mapper
|
||||
//! X Windows key state
|
||||
/*!
|
||||
This class maps KeyIDs to keystrokes.
|
||||
A key state for X Windows.
|
||||
*/
|
||||
class CXWindowsKeyMapper {
|
||||
class CXWindowsKeyState : public CKeyState {
|
||||
public:
|
||||
CXWindowsKeyMapper();
|
||||
~CXWindowsKeyMapper();
|
||||
CXWindowsKeyState(Display*);
|
||||
~CXWindowsKeyState();
|
||||
|
||||
//! @name manipulators
|
||||
//@{
|
||||
|
||||
//! Update key mapper
|
||||
/*!
|
||||
Updates the key mapper's internal tables according to the display's
|
||||
current keyboard mapping and updates \c keyState.
|
||||
*/
|
||||
void update(Display*, IKeyState* keyState);
|
||||
|
||||
//@}
|
||||
//! @name accessors
|
||||
//@{
|
||||
|
||||
//! Map key press/repeat to keystrokes
|
||||
/*!
|
||||
Converts a press/repeat of key \c id with the modifiers as given
|
||||
in \c desiredMask into the keystrokes necessary to synthesize
|
||||
that key event. Returns the platform specific code of the key
|
||||
being pressed, or 0 if the key cannot be mapped or \c isAutoRepeat
|
||||
is true and the key does not auto-repeat.
|
||||
*/
|
||||
KeyButton mapKey(IKeyState::Keystrokes&,
|
||||
const IKeyState& keyState, KeyID id,
|
||||
KeyModifierMask desiredMask,
|
||||
bool isAutoRepeat) const;
|
||||
|
||||
//! Convert X modifier mask to synergy mask
|
||||
/*!
|
||||
Returns the synergy modifier mask corresponding to the given X
|
||||
modifier mask.
|
||||
Returns the synergy modifier mask corresponding to the X modifier
|
||||
mask in \p state.
|
||||
*/
|
||||
KeyModifierMask mapModifier(unsigned int state) const;
|
||||
KeyModifierMask mapModifiersFromX(unsigned int state) const;
|
||||
|
||||
//@}
|
||||
|
||||
// IKeyState overrides
|
||||
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,
|
||||
KeyModifierMask desiredMask,
|
||||
bool isAutoRepeat) const;
|
||||
|
||||
private:
|
||||
class KeyMapping {
|
||||
public:
|
||||
@@ -90,9 +83,8 @@ private:
|
||||
typedef std::map<KeySym, KeyMapping> KeySymMap;
|
||||
typedef KeySymMap::const_iterator KeySymIndex;
|
||||
|
||||
// save the current keyboard mapping and note the currently
|
||||
// pressed keys in \c keyState.
|
||||
void updateKeysymMap(Display* display, IKeyState* keyState);
|
||||
// save the current keyboard mapping and note the modifiers
|
||||
void updateKeysymMap();
|
||||
|
||||
// note interesting modifier KeySyms
|
||||
void updateModifiers();
|
||||
@@ -105,8 +97,7 @@ private:
|
||||
KeySym keyIDToKeySym(KeyID id, KeyModifierMask mask) const;
|
||||
|
||||
// map a KeySym into the keystrokes to produce it
|
||||
KeyButton mapToKeystrokes(IKeyState::Keystrokes& keys,
|
||||
const IKeyState& keyState,
|
||||
KeyButton mapToKeystrokes(Keystrokes& keys,
|
||||
KeySymIndex keyIndex,
|
||||
bool isAutoRepeat) const;
|
||||
|
||||
@@ -120,9 +111,8 @@ private:
|
||||
|
||||
// returns the keystrokes to adjust the modifiers into the desired
|
||||
// state the keystrokes to get back to the current state.
|
||||
bool adjustModifiers(IKeyState::Keystrokes& keys,
|
||||
IKeyState::Keystrokes& undo,
|
||||
const IKeyState& keyState,
|
||||
bool adjustModifiers(Keystrokes& keys,
|
||||
Keystrokes& undo,
|
||||
KeyModifierMask desiredMask) const;
|
||||
|
||||
// returns true if keysym is sensitive to the NumLock state
|
||||
@@ -132,6 +122,8 @@ private:
|
||||
bool isCapsLockSensitive(KeySym keysym) const;
|
||||
|
||||
private:
|
||||
Display* m_display;
|
||||
|
||||
// keysym to keycode mapping
|
||||
KeySymMap m_keysymMap;
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "CXWindowsScreen.h"
|
||||
#include "CXWindowsClipboard.h"
|
||||
#include "CXWindowsEventQueueBuffer.h"
|
||||
#include "CXWindowsKeyState.h"
|
||||
#include "CXWindowsScreenSaver.h"
|
||||
#include "CXWindowsUtil.h"
|
||||
#include "CClipboard.h"
|
||||
@@ -131,7 +132,6 @@ CXWindowsScreen::CXWindowsScreen(bool isPrimary) :
|
||||
m_xCenter(0), m_yCenter(0),
|
||||
m_xCursor(0), m_yCursor(0),
|
||||
m_keyState(NULL),
|
||||
m_keyMapper(),
|
||||
m_im(NULL),
|
||||
m_ic(NULL),
|
||||
m_lastKeycode(0),
|
||||
@@ -154,6 +154,7 @@ CXWindowsScreen::CXWindowsScreen(bool isPrimary) :
|
||||
m_window = openWindow();
|
||||
m_screensaver = new CXWindowsScreenSaver(m_display,
|
||||
m_window, getEventTarget());
|
||||
m_keyState = new CXWindowsKeyState(m_display);
|
||||
LOG((CLOG_DEBUG "screen shape: %d,%d %dx%d %s", m_x, m_y, m_w, m_h, m_xinerama ? "(xinerama)" : ""));
|
||||
LOG((CLOG_DEBUG "window is 0x%08x", m_window));
|
||||
}
|
||||
@@ -201,7 +202,9 @@ CXWindowsScreen::~CXWindowsScreen()
|
||||
for (ClipboardID id = 0; id < kClipboardEnd; ++id) {
|
||||
delete m_clipboard[id];
|
||||
}
|
||||
delete m_keyState;
|
||||
delete m_screensaver;
|
||||
m_keyState = NULL;
|
||||
m_screensaver = NULL;
|
||||
if (m_display != NULL) {
|
||||
// FIXME -- is it safe to clean up the IC and IM without a display?
|
||||
@@ -219,12 +222,6 @@ CXWindowsScreen::~CXWindowsScreen()
|
||||
s_screen = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
CXWindowsScreen::setKeyState(IKeyState* keyState)
|
||||
{
|
||||
m_keyState = keyState;
|
||||
}
|
||||
|
||||
void
|
||||
CXWindowsScreen::enable()
|
||||
{
|
||||
@@ -319,7 +316,6 @@ CXWindowsScreen::leave()
|
||||
}
|
||||
|
||||
// raise and show the window
|
||||
// FIXME -- take focus?
|
||||
XMapRaised(m_display, m_window);
|
||||
|
||||
// grab the mouse and keyboard, if primary and possible
|
||||
@@ -328,6 +324,9 @@ CXWindowsScreen::leave()
|
||||
return false;
|
||||
}
|
||||
|
||||
// take focus
|
||||
XSetInputFocus(m_display, m_window, RevertToPointerRoot, CurrentTime);
|
||||
|
||||
// now warp the mouse. we warp after showing the window so we're
|
||||
// guaranteed to get the mouse leave event and to prevent the
|
||||
// keyboard focus from changing under point-to-focus policies.
|
||||
@@ -428,14 +427,6 @@ CXWindowsScreen::setOptions(const COptionsList& options)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
CXWindowsScreen::updateKeys()
|
||||
{
|
||||
// update keyboard and mouse button mappings
|
||||
m_keyMapper.update(m_display, m_keyState);
|
||||
updateButtons();
|
||||
}
|
||||
|
||||
void
|
||||
CXWindowsScreen::setSequenceNumber(UInt32 seqNum)
|
||||
{
|
||||
@@ -547,21 +538,6 @@ CXWindowsScreen::isAnyMouseButtonDown() const
|
||||
return false;
|
||||
}
|
||||
|
||||
KeyModifierMask
|
||||
CXWindowsScreen::getActiveModifiers() const
|
||||
{
|
||||
// query the pointer to get the modifier state
|
||||
Window root, window;
|
||||
int xRoot, yRoot, xWindow, yWindow;
|
||||
unsigned int state;
|
||||
if (XQueryPointer(m_display, m_root, &root, &window,
|
||||
&xRoot, &yRoot, &xWindow, &yWindow, &state)) {
|
||||
return m_keyMapper.mapModifier(state);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
CXWindowsScreen::getCursorCenter(SInt32& x, SInt32& y) const
|
||||
{
|
||||
@@ -569,28 +545,6 @@ CXWindowsScreen::getCursorCenter(SInt32& x, SInt32& y) const
|
||||
y = m_yCenter;
|
||||
}
|
||||
|
||||
const char*
|
||||
CXWindowsScreen::getKeyName(KeyButton keycode) const
|
||||
{
|
||||
KeySym keysym = XKeycodeToKeysym(m_display, keycode, 0);
|
||||
char* name = XKeysymToString(keysym);
|
||||
if (name != NULL) {
|
||||
return name;
|
||||
}
|
||||
else {
|
||||
static char buffer[20];
|
||||
return strcpy(buffer,
|
||||
CStringUtil::print("keycode %d", keycode).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
CXWindowsScreen::fakeKeyEvent(KeyButton keycode, bool press) const
|
||||
{
|
||||
XTestFakeKeyEvent(m_display, keycode, press ? True : False, CurrentTime);
|
||||
XFlush(m_display);
|
||||
}
|
||||
|
||||
bool
|
||||
CXWindowsScreen::fakeCtrlAltDel() const
|
||||
{
|
||||
@@ -645,15 +599,6 @@ CXWindowsScreen::fakeMouseWheel(SInt32 delta) const
|
||||
XFlush(m_display);
|
||||
}
|
||||
|
||||
KeyButton
|
||||
CXWindowsScreen::mapKey(IKeyState::Keystrokes& keys,
|
||||
const IKeyState& keyState, KeyID id,
|
||||
KeyModifierMask desiredMask,
|
||||
bool isAutoRepeat) const
|
||||
{
|
||||
return m_keyMapper.mapKey(keys, keyState, id, desiredMask, isAutoRepeat);
|
||||
}
|
||||
|
||||
Display*
|
||||
CXWindowsScreen::openDisplay() const
|
||||
{
|
||||
@@ -788,6 +733,7 @@ CXWindowsScreen::openIM()
|
||||
// open the input methods
|
||||
XIM im = XOpenIM(m_display, NULL, NULL, NULL);
|
||||
if (im == NULL) {
|
||||
LOG((CLOG_INFO "no support for IM"));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -811,7 +757,7 @@ CXWindowsScreen::openIM()
|
||||
}
|
||||
XFree(styles);
|
||||
if (style == 0) {
|
||||
LOG((CLOG_WARN "no supported IM styles"));
|
||||
LOG((CLOG_INFO "no supported IM styles"));
|
||||
XCloseIM(im);
|
||||
return;
|
||||
}
|
||||
@@ -859,6 +805,12 @@ CXWindowsScreen::sendClipboardEvent(CEvent::Type type, ClipboardID id)
|
||||
sendEvent(type, info);
|
||||
}
|
||||
|
||||
IKeyState*
|
||||
CXWindowsScreen::getKeyState() const
|
||||
{
|
||||
return m_keyState;
|
||||
}
|
||||
|
||||
Bool
|
||||
CXWindowsScreen::findKeyEvent(Display*, XEvent* xevent, XPointer arg)
|
||||
{
|
||||
@@ -1063,7 +1015,7 @@ void
|
||||
CXWindowsScreen::onKeyPress(XKeyEvent& xkey)
|
||||
{
|
||||
LOG((CLOG_DEBUG1 "event: KeyPress code=%d, state=0x%04x", xkey.keycode, xkey.state));
|
||||
const KeyModifierMask mask = m_keyMapper.mapModifier(xkey.state);
|
||||
const KeyModifierMask mask = m_keyState->mapModifiersFromX(xkey.state);
|
||||
KeyID key = mapKeyFromX(&xkey);
|
||||
if (key != kKeyNone) {
|
||||
// check for ctrl+alt+del emulation
|
||||
@@ -1083,19 +1035,15 @@ CXWindowsScreen::onKeyPress(XKeyEvent& xkey)
|
||||
}
|
||||
|
||||
// handle key
|
||||
sendEvent(getKeyDownEvent(), CKeyInfo::alloc(key, mask, keycode, 1));
|
||||
KeyModifierMask keyMask = m_keyState->getMaskForKey(keycode);
|
||||
if (m_keyState->isHalfDuplex(keyMask)) {
|
||||
sendEvent(getKeyUpEvent(),
|
||||
CKeyInfo::alloc(key, mask | keyMask, keycode, 1));
|
||||
}
|
||||
m_keyState->sendKeyEvent(getEventTarget(),
|
||||
true, false, key, mask, 1, keycode);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
CXWindowsScreen::onKeyRelease(XKeyEvent& xkey, bool isRepeat)
|
||||
{
|
||||
const KeyModifierMask mask = m_keyMapper.mapModifier(xkey.state);
|
||||
const KeyModifierMask mask = m_keyState->mapModifiersFromX(xkey.state);
|
||||
KeyID key = mapKeyFromX(&xkey);
|
||||
if (key != kKeyNone) {
|
||||
// check for ctrl+alt+del emulation
|
||||
@@ -1112,12 +1060,8 @@ CXWindowsScreen::onKeyRelease(XKeyEvent& xkey, bool isRepeat)
|
||||
if (!isRepeat) {
|
||||
// no press event follows so it's a plain release
|
||||
LOG((CLOG_DEBUG1 "event: KeyRelease code=%d, state=0x%04x", keycode, xkey.state));
|
||||
KeyModifierMask keyMask = m_keyState->getMaskForKey(keycode);
|
||||
if (m_keyState->isHalfDuplex(keyMask)) {
|
||||
sendEvent(getKeyDownEvent(),
|
||||
CKeyInfo::alloc(key, mask, keycode, 1));
|
||||
}
|
||||
sendEvent(getKeyUpEvent(), CKeyInfo::alloc(key, mask, keycode, 1));
|
||||
m_keyState->sendKeyEvent(getEventTarget(),
|
||||
false, false, key, mask, 1, keycode);
|
||||
}
|
||||
else {
|
||||
// found a press event following so it's a repeat.
|
||||
@@ -1125,8 +1069,8 @@ CXWindowsScreen::onKeyRelease(XKeyEvent& xkey, bool isRepeat)
|
||||
// repeats but we'll just send a repeat of 1.
|
||||
// note that we discard the press event.
|
||||
LOG((CLOG_DEBUG1 "event: repeat code=%d, state=0x%04x", keycode, xkey.state));
|
||||
sendEvent(getKeyRepeatEvent(),
|
||||
CKeyInfo::alloc(key, mask, keycode, 1));
|
||||
m_keyState->sendKeyEvent(getEventTarget(),
|
||||
false, true, key, mask, 1, keycode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,8 +15,7 @@
|
||||
#ifndef CXWINDOWSSCREEN_H
|
||||
#define CXWINDOWSSCREEN_H
|
||||
|
||||
#include "IPlatformScreen.h"
|
||||
#include "CXWindowsKeyMapper.h"
|
||||
#include "CPlatformScreen.h"
|
||||
#include "stdvector.h"
|
||||
#if defined(X_DISPLAY_MISSING)
|
||||
# error X11 is required to build synergy
|
||||
@@ -25,10 +24,11 @@
|
||||
#endif
|
||||
|
||||
class CXWindowsClipboard;
|
||||
class CXWindowsKeyState;
|
||||
class CXWindowsScreenSaver;
|
||||
|
||||
//! Implementation of IPlatformScreen for X11
|
||||
class CXWindowsScreen : public IPlatformScreen {
|
||||
class CXWindowsScreen : public CPlatformScreen {
|
||||
public:
|
||||
CXWindowsScreen(bool isPrimary);
|
||||
virtual ~CXWindowsScreen();
|
||||
@@ -38,23 +38,6 @@ public:
|
||||
|
||||
//@}
|
||||
|
||||
// IPlatformScreen overrides
|
||||
virtual void setKeyState(IKeyState*);
|
||||
virtual void enable();
|
||||
virtual void disable();
|
||||
virtual void enter();
|
||||
virtual bool leave();
|
||||
virtual bool setClipboard(ClipboardID, const IClipboard*);
|
||||
virtual void checkClipboards();
|
||||
virtual void openScreensaver(bool notify);
|
||||
virtual void closeScreensaver();
|
||||
virtual void screensaver(bool activate);
|
||||
virtual void resetOptions();
|
||||
virtual void setOptions(const COptionsList& options);
|
||||
virtual void updateKeys();
|
||||
virtual void setSequenceNumber(UInt32);
|
||||
virtual bool isPrimary() const;
|
||||
|
||||
// IScreen overrides
|
||||
virtual void* getEventTarget() const;
|
||||
virtual bool getClipboard(ClipboardID id, IClipboard*) const;
|
||||
@@ -67,29 +50,40 @@ public:
|
||||
virtual void warpCursor(SInt32 x, SInt32 y);
|
||||
virtual SInt32 getJumpZoneSize() const;
|
||||
virtual bool isAnyMouseButtonDown() const;
|
||||
virtual KeyModifierMask getActiveModifiers() const;
|
||||
virtual void getCursorCenter(SInt32& x, SInt32& y) const;
|
||||
virtual const char* getKeyName(KeyButton) const;
|
||||
|
||||
// ISecondaryScreen overrides
|
||||
virtual void fakeKeyEvent(KeyButton id, bool press) const;
|
||||
virtual bool fakeCtrlAltDel() const;
|
||||
virtual void fakeMouseButton(ButtonID id, bool press) const;
|
||||
virtual void fakeMouseMove(SInt32 x, SInt32 y) const;
|
||||
virtual void fakeMouseWheel(SInt32 delta) const;
|
||||
virtual KeyButton mapKey(IKeyState::Keystrokes&,
|
||||
const IKeyState& keyState, KeyID id,
|
||||
KeyModifierMask desiredMask,
|
||||
bool isAutoRepeat) const;
|
||||
|
||||
// IPlatformScreen overrides
|
||||
virtual void enable();
|
||||
virtual void disable();
|
||||
virtual void enter();
|
||||
virtual bool leave();
|
||||
virtual bool setClipboard(ClipboardID, const IClipboard*);
|
||||
virtual void checkClipboards();
|
||||
virtual void openScreensaver(bool notify);
|
||||
virtual void closeScreensaver();
|
||||
virtual void screensaver(bool activate);
|
||||
virtual void resetOptions();
|
||||
virtual void setOptions(const COptionsList& options);
|
||||
virtual void setSequenceNumber(UInt32);
|
||||
virtual bool isPrimary() const;
|
||||
|
||||
protected:
|
||||
// IPlatformScreen overrides
|
||||
virtual void handleSystemEvent(const CEvent&, void*);
|
||||
virtual void updateButtons();
|
||||
virtual IKeyState* getKeyState() const;
|
||||
|
||||
private:
|
||||
// event sending
|
||||
void sendEvent(CEvent::Type, void* = NULL);
|
||||
void sendClipboardEvent(CEvent::Type, ClipboardID);
|
||||
|
||||
// event handling
|
||||
void handleSystemEvent(const CEvent&, void*);
|
||||
|
||||
// create the transparent cursor
|
||||
Cursor createBlankCursor() const;
|
||||
|
||||
@@ -138,8 +132,6 @@ private:
|
||||
|
||||
void warpCursorNoFlush(SInt32 x, SInt32 y);
|
||||
|
||||
void updateButtons();
|
||||
|
||||
static Bool findKeyEvent(Display*, XEvent* xevent, XPointer arg);
|
||||
|
||||
private:
|
||||
@@ -162,8 +154,7 @@ private:
|
||||
SInt32 m_xCursor, m_yCursor;
|
||||
|
||||
// keyboard stuff
|
||||
IKeyState* m_keyState;
|
||||
CXWindowsKeyMapper m_keyMapper;
|
||||
CXWindowsKeyState* m_keyState;
|
||||
|
||||
// input method stuff
|
||||
XIM m_im;
|
||||
|
||||
@@ -54,7 +54,7 @@ libplatform_a_SOURCES = \
|
||||
CXWindowsClipboardUCS2Converter.cpp \
|
||||
CXWindowsClipboardUTF8Converter.cpp \
|
||||
CXWindowsEventQueueBuffer.cpp \
|
||||
CXWindowsKeyMapper.cpp \
|
||||
CXWindowsKeyState.cpp \
|
||||
CXWindowsScreen.cpp \
|
||||
CXWindowsScreenSaver.cpp \
|
||||
CXWindowsUtil.cpp \
|
||||
@@ -63,7 +63,7 @@ libplatform_a_SOURCES = \
|
||||
CXWindowsClipboardUCS2Converter.h \
|
||||
CXWindowsClipboardUTF8Converter.h \
|
||||
CXWindowsEventQueueBuffer.h \
|
||||
CXWindowsKeyMapper.h \
|
||||
CXWindowsKeyState.h \
|
||||
CXWindowsScreen.h \
|
||||
CXWindowsScreenSaver.h \
|
||||
CXWindowsUtil.h \
|
||||
|
||||
Reference in New Issue
Block a user