2002-08-02 19:57:46 +00:00
|
|
|
/*
|
|
|
|
* synergy -- mouse and keyboard sharing utility
|
|
|
|
* Copyright (C) 2002 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.
|
|
|
|
*/
|
|
|
|
|
2001-10-08 19:24:46 +00:00
|
|
|
#ifndef CXWINDOWSSECONDARYSCREEN_H
|
|
|
|
#define CXWINDOWSSECONDARYSCREEN_H
|
|
|
|
|
2002-07-13 22:00:38 +00:00
|
|
|
#include "CSecondaryScreen.h"
|
|
|
|
#include "IScreenEventHandler.h"
|
2003-03-16 17:40:56 +00:00
|
|
|
#include "stdbitset.h"
|
2002-06-01 19:26:11 +00:00
|
|
|
#include "stdmap.h"
|
|
|
|
#include "stdvector.h"
|
2002-07-13 22:00:38 +00:00
|
|
|
#if defined(X_DISPLAY_MISSING)
|
|
|
|
# error X11 is required to build synergy
|
|
|
|
#else
|
|
|
|
# include <X11/Xlib.h>
|
|
|
|
#endif
|
2001-10-08 19:24:46 +00:00
|
|
|
|
2002-07-13 22:00:38 +00:00
|
|
|
class CXWindowsScreen;
|
2002-07-10 21:22:28 +00:00
|
|
|
class IScreenReceiver;
|
|
|
|
|
2002-07-30 14:59:36 +00:00
|
|
|
//! X11 secondary screen implementation
|
2002-07-13 22:00:38 +00:00
|
|
|
class CXWindowsSecondaryScreen :
|
|
|
|
public CSecondaryScreen, public IScreenEventHandler {
|
2002-04-29 14:40:01 +00:00
|
|
|
public:
|
2002-07-10 21:22:28 +00:00
|
|
|
CXWindowsSecondaryScreen(IScreenReceiver*);
|
2001-10-08 19:24:46 +00:00
|
|
|
virtual ~CXWindowsSecondaryScreen();
|
|
|
|
|
2002-07-13 22:00:38 +00:00
|
|
|
// CSecondaryScreen overrides
|
2003-04-27 17:01:14 +00:00
|
|
|
virtual void keyDown(KeyID, KeyModifierMask, KeyButton);
|
|
|
|
virtual void keyRepeat(KeyID, KeyModifierMask,
|
|
|
|
SInt32 count, KeyButton);
|
|
|
|
virtual void keyUp(KeyID, KeyModifierMask, KeyButton);
|
2001-10-25 21:40:29 +00:00
|
|
|
virtual void mouseDown(ButtonID);
|
|
|
|
virtual void mouseUp(ButtonID);
|
2002-07-13 22:00:38 +00:00
|
|
|
virtual void mouseMove(SInt32 x, SInt32 y);
|
2001-10-25 21:40:29 +00:00
|
|
|
virtual void mouseWheel(SInt32 delta);
|
2002-12-23 13:55:21 +00:00
|
|
|
virtual void resetOptions();
|
|
|
|
virtual void setOptions(const COptionsList& options);
|
2002-07-13 22:00:38 +00:00
|
|
|
virtual IScreen* getScreen() const;
|
2001-10-08 19:24:46 +00:00
|
|
|
|
2002-07-13 22:00:38 +00:00
|
|
|
// IScreenEventHandler overrides
|
|
|
|
virtual void onScreensaver(bool activated);
|
2002-07-12 20:41:23 +00:00
|
|
|
virtual bool onPreDispatch(const CEvent* event);
|
|
|
|
virtual bool onEvent(CEvent* event);
|
2003-02-22 21:53:25 +00:00
|
|
|
virtual void onOneShotTimerExpired(UInt32 id);
|
2002-07-15 15:01:36 +00:00
|
|
|
virtual SInt32 getJumpZoneSize() const;
|
2002-07-13 22:00:38 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
// CSecondaryScreen overrides
|
2002-07-30 15:17:44 +00:00
|
|
|
virtual void onPreMainLoop();
|
2002-07-13 22:00:38 +00:00
|
|
|
virtual void onPreOpen();
|
|
|
|
virtual void onPostOpen();
|
2003-05-03 13:57:52 +00:00
|
|
|
virtual void onPreClose();
|
2002-07-13 22:00:38 +00:00
|
|
|
virtual void onPreEnter();
|
2003-05-03 13:28:21 +00:00
|
|
|
virtual void onPostEnter();
|
2002-07-13 22:00:38 +00:00
|
|
|
virtual void onPreLeave();
|
|
|
|
virtual void createWindow();
|
|
|
|
virtual void destroyWindow();
|
2003-05-03 13:50:06 +00:00
|
|
|
virtual void showWindow(SInt32 x, SInt32 y);
|
2002-07-13 22:00:38 +00:00
|
|
|
virtual void hideWindow();
|
|
|
|
virtual void warpCursor(SInt32 x, SInt32 y);
|
|
|
|
virtual void updateKeys();
|
2003-03-12 22:34:07 +00:00
|
|
|
virtual void releaseKeys();
|
2002-07-13 22:00:38 +00:00
|
|
|
virtual void setToggleState(KeyModifierMask);
|
2002-12-15 22:14:49 +00:00
|
|
|
virtual KeyModifierMask getToggleState() const;
|
2001-11-11 21:15:30 +00:00
|
|
|
|
2002-04-29 14:40:01 +00:00
|
|
|
private:
|
2002-05-03 11:26:44 +00:00
|
|
|
enum EKeyAction { kPress, kRelease, kRepeat };
|
2003-07-01 19:35:28 +00:00
|
|
|
typedef unsigned int ModifierIndex;
|
|
|
|
typedef unsigned int ModifierMask;
|
2002-05-03 11:26:44 +00:00
|
|
|
class Keystroke {
|
|
|
|
public:
|
|
|
|
KeyCode m_keycode;
|
|
|
|
Bool m_press;
|
|
|
|
bool m_repeat;
|
2002-04-26 17:38:01 +00:00
|
|
|
};
|
2003-07-01 19:35:28 +00:00
|
|
|
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
|
|
|
|
ModifierMask m_modifierMask;
|
|
|
|
|
|
|
|
// whether keysym is sensitive to caps and num lock
|
|
|
|
bool m_numLockSensitive;
|
|
|
|
bool m_capsLockSensitive;
|
|
|
|
};
|
|
|
|
|
2002-04-26 17:38:01 +00:00
|
|
|
typedef std::vector<KeyCode> KeyCodes;
|
2003-07-01 19:35:28 +00:00
|
|
|
typedef std::map<KeyCode, ModifierIndex> KeyCodeToModifierMap;
|
|
|
|
typedef std::map<KeySym, KeyMapping> KeySymMap;
|
|
|
|
typedef KeySymMap::const_iterator KeySymIndex;
|
|
|
|
typedef std::vector<Keystroke> Keystrokes;
|
|
|
|
typedef std::vector<KeySym> KeySyms;
|
|
|
|
typedef std::map<KeySym, KeySyms> KeySymsMap;
|
2003-04-27 17:01:14 +00:00
|
|
|
typedef std::map<KeyButton, KeyCode> ServerKeyMap;
|
2002-04-26 17:38:01 +00:00
|
|
|
|
2001-10-08 19:24:46 +00:00
|
|
|
unsigned int mapButton(ButtonID button) const;
|
|
|
|
|
2003-07-01 19:35:28 +00:00
|
|
|
ModifierMask mapKey(Keystrokes&, KeyCode&, KeyID,
|
2002-06-10 22:06:45 +00:00
|
|
|
KeyModifierMask, EKeyAction) const;
|
2003-07-01 19:35:28 +00:00
|
|
|
ModifierMask mapKeyRelease(Keystrokes&, KeyCode) const;
|
|
|
|
bool mapToKeystrokes(Keystrokes& keys,
|
|
|
|
KeyCode& keycode,
|
|
|
|
ModifierMask& finalMask,
|
|
|
|
KeySymIndex keyIndex,
|
|
|
|
ModifierMask currentMask,
|
|
|
|
EKeyAction action) const;
|
|
|
|
bool adjustModifiers(Keystrokes& keys,
|
|
|
|
Keystrokes& undo,
|
|
|
|
ModifierMask& inOutMask,
|
|
|
|
ModifierMask desiredMask) const;
|
|
|
|
bool adjustModifier(Keystrokes& keys,
|
|
|
|
Keystrokes& undo,
|
|
|
|
KeySym keysym,
|
|
|
|
bool desireActive) const;
|
2002-05-03 11:26:44 +00:00
|
|
|
void doKeystrokes(const Keystrokes&, SInt32 count);
|
2003-07-01 19:35:28 +00:00
|
|
|
ModifierMask maskToX(KeyModifierMask) const;
|
|
|
|
|
|
|
|
unsigned int findBestKeyIndex(KeySymIndex keyIndex,
|
|
|
|
ModifierMask currentMask) const;
|
|
|
|
bool isShiftInverted(KeySymIndex keyIndex,
|
|
|
|
ModifierMask currentMask) const;
|
|
|
|
ModifierMask getModifierMask(KeySym) const;
|
2002-04-26 17:38:01 +00:00
|
|
|
|
2003-03-16 17:40:56 +00:00
|
|
|
void doUpdateKeys(Display*);
|
2003-03-12 22:34:07 +00:00
|
|
|
void doReleaseKeys(Display*);
|
2003-07-01 19:35:28 +00:00
|
|
|
void updateKeysymMap(Display* display);
|
2002-04-26 17:38:01 +00:00
|
|
|
void updateModifiers(Display* display);
|
2003-07-01 19:35:28 +00:00
|
|
|
ModifierIndex keySymToModifierIndex(KeySym) const;
|
|
|
|
void toggleKey(Display*, KeySym, ModifierMask mask);
|
2002-04-26 17:38:01 +00:00
|
|
|
static bool isToggleKeysym(KeySym);
|
|
|
|
|
2003-07-01 19:35:28 +00:00
|
|
|
KeySym keyIDToKeySym(KeyID id, ModifierMask mask) const;
|
2002-09-14 12:07:02 +00:00
|
|
|
bool adjustForNumLock(KeySym) const;
|
|
|
|
bool adjustForCapsLock(KeySym) const;
|
|
|
|
|
2003-07-01 19:35:28 +00:00
|
|
|
bool decomposeKeySym(KeySym keysym,
|
|
|
|
KeySyms& decomposed) const;
|
|
|
|
static const KeySymsMap& getDecomposedKeySymTable();
|
2002-09-14 12:07:02 +00:00
|
|
|
|
2003-07-01 19:35:28 +00:00
|
|
|
private:
|
2002-07-13 22:00:38 +00:00
|
|
|
CXWindowsScreen* m_screen;
|
2001-10-08 19:24:46 +00:00
|
|
|
Window m_window;
|
2002-04-26 17:38:01 +00:00
|
|
|
|
2002-05-04 18:31:54 +00:00
|
|
|
// note toggle keys that toggles on up/down (false) or on
|
2002-04-30 16:25:29 +00:00
|
|
|
// transition (true)
|
2002-05-04 18:31:54 +00:00
|
|
|
bool m_numLockHalfDuplex;
|
2002-04-30 16:25:29 +00:00
|
|
|
bool m_capsLockHalfDuplex;
|
|
|
|
|
2003-03-16 17:40:56 +00:00
|
|
|
// set entries indicate keys that are pressed (by us or by the user).
|
|
|
|
// indexed by keycode.
|
|
|
|
std::bitset<256> m_keys;
|
|
|
|
|
|
|
|
// set entries indicate keys that are synthetically pressed by us.
|
|
|
|
// this is normally the same as m_keys.
|
|
|
|
std::bitset<256> m_fakeKeys;
|
2002-04-26 17:38:01 +00:00
|
|
|
|
2002-08-18 17:31:48 +00:00
|
|
|
// logical to physical button mapping. m_buttons[i] gives the
|
|
|
|
// physical button for logical button i+1.
|
2002-12-15 22:39:59 +00:00
|
|
|
std::vector<unsigned char> m_buttons;
|
2002-08-18 17:31:48 +00:00
|
|
|
|
2002-04-26 17:38:01 +00:00
|
|
|
// current active modifiers (X key masks)
|
2003-07-01 19:35:28 +00:00
|
|
|
ModifierMask m_mask;
|
2002-04-26 17:38:01 +00:00
|
|
|
|
|
|
|
// the modifiers that have keys bound to them
|
2003-07-01 19:35:28 +00:00
|
|
|
ModifierMask m_modifierMask;
|
2002-04-26 17:38:01 +00:00
|
|
|
|
|
|
|
// set bits indicate modifiers that toggle (e.g. caps-lock)
|
2003-07-01 19:35:28 +00:00
|
|
|
ModifierMask m_toggleModifierMask;
|
|
|
|
|
|
|
|
// keysym to keycode mapping
|
|
|
|
KeySymMap m_keysymMap;
|
|
|
|
|
|
|
|
// modifier index to keycodes
|
|
|
|
KeyCodes m_modifierKeycodes[8];
|
|
|
|
|
|
|
|
// keycode to modifier index
|
|
|
|
KeyCodeToModifierMap m_keycodeToModifier;
|
|
|
|
|
|
|
|
// modifier keysyms
|
|
|
|
KeySym m_shiftKeysym;
|
|
|
|
KeySym m_ctrlKeysym;
|
|
|
|
KeySym m_altKeysym;
|
|
|
|
KeySym m_metaKeysym;
|
|
|
|
KeySym m_superKeysym;
|
|
|
|
KeySym m_modeSwitchKeysym;
|
|
|
|
KeySym m_numLockKeysym;
|
|
|
|
KeySym m_capsLockKeysym;
|
|
|
|
KeySym m_scrollLockKeysym;
|
2002-04-26 17:38:01 +00:00
|
|
|
|
2002-09-01 15:30:00 +00:00
|
|
|
// modifier masks
|
2003-07-01 19:35:28 +00:00
|
|
|
ModifierMask m_shiftMask;
|
|
|
|
ModifierMask m_ctrlMask;
|
|
|
|
ModifierMask m_altMask;
|
|
|
|
ModifierMask m_metaMask;
|
|
|
|
ModifierMask m_superMask;
|
|
|
|
ModifierMask m_modeSwitchMask;
|
|
|
|
ModifierMask m_numLockMask;
|
|
|
|
ModifierMask m_capsLockMask;
|
|
|
|
ModifierMask m_scrollLockMask;
|
2002-04-26 17:38:01 +00:00
|
|
|
|
2003-04-27 17:01:14 +00:00
|
|
|
// map server key buttons to local keycodes
|
|
|
|
ServerKeyMap m_serverKeyMap;
|
2003-05-03 13:28:21 +00:00
|
|
|
|
|
|
|
// the keyboard control state the last time this screen was entered
|
|
|
|
XKeyboardState m_keyControl;
|
2003-05-17 13:44:24 +00:00
|
|
|
|
|
|
|
// stuff to workaround xtest being xinerama unaware. attempting
|
2003-05-17 14:03:32 +00:00
|
|
|
// to fake a mouse motion under xinerama may behave strangely,
|
|
|
|
// especially if screen 0 is not at 0,0 or if faking a motion on
|
|
|
|
// a screen other than screen 0.
|
2003-05-17 13:44:24 +00:00
|
|
|
bool m_xtestIsXineramaUnaware;
|
|
|
|
bool m_xinerama;
|
2003-07-01 19:35:28 +00:00
|
|
|
|
|
|
|
// a table of keysym decompositions
|
|
|
|
static KeySymsMap s_decomposedKeySyms;
|
2001-10-08 19:24:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|