2002-08-02 23:57:46 +04: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 23:24:46 +04:00
|
|
|
#ifndef CXWINDOWSSECONDARYSCREEN_H
|
|
|
|
#define CXWINDOWSSECONDARYSCREEN_H
|
|
|
|
|
2002-07-14 02:00:38 +04:00
|
|
|
#include "CSecondaryScreen.h"
|
|
|
|
#include "IScreenEventHandler.h"
|
2003-03-16 20:40:56 +03:00
|
|
|
#include "stdbitset.h"
|
2002-06-01 23:26:11 +04:00
|
|
|
#include "stdmap.h"
|
|
|
|
#include "stdvector.h"
|
2002-07-14 02:00:38 +04:00
|
|
|
#if defined(X_DISPLAY_MISSING)
|
|
|
|
# error X11 is required to build synergy
|
|
|
|
#else
|
|
|
|
# include <X11/Xlib.h>
|
|
|
|
#endif
|
2001-10-08 23:24:46 +04:00
|
|
|
|
2002-07-14 02:00:38 +04:00
|
|
|
class CXWindowsScreen;
|
2002-07-11 01:22:28 +04:00
|
|
|
class IScreenReceiver;
|
|
|
|
|
2002-07-30 18:59:36 +04:00
|
|
|
//! X11 secondary screen implementation
|
2002-07-14 02:00:38 +04:00
|
|
|
class CXWindowsSecondaryScreen :
|
|
|
|
public CSecondaryScreen, public IScreenEventHandler {
|
2002-04-29 18:40:01 +04:00
|
|
|
public:
|
2002-07-11 01:22:28 +04:00
|
|
|
CXWindowsSecondaryScreen(IScreenReceiver*);
|
2001-10-08 23:24:46 +04:00
|
|
|
virtual ~CXWindowsSecondaryScreen();
|
|
|
|
|
2002-07-14 02:00:38 +04:00
|
|
|
// CSecondaryScreen overrides
|
2003-04-27 21:01:14 +04:00
|
|
|
virtual void keyDown(KeyID, KeyModifierMask, KeyButton);
|
|
|
|
virtual void keyRepeat(KeyID, KeyModifierMask,
|
|
|
|
SInt32 count, KeyButton);
|
|
|
|
virtual void keyUp(KeyID, KeyModifierMask, KeyButton);
|
2001-10-26 01:40:29 +04:00
|
|
|
virtual void mouseDown(ButtonID);
|
|
|
|
virtual void mouseUp(ButtonID);
|
2002-07-14 02:00:38 +04:00
|
|
|
virtual void mouseMove(SInt32 x, SInt32 y);
|
2001-10-26 01:40:29 +04:00
|
|
|
virtual void mouseWheel(SInt32 delta);
|
2002-12-23 16:55:21 +03:00
|
|
|
virtual void resetOptions();
|
|
|
|
virtual void setOptions(const COptionsList& options);
|
2002-07-14 02:00:38 +04:00
|
|
|
virtual IScreen* getScreen() const;
|
2001-10-08 23:24:46 +04:00
|
|
|
|
2002-07-14 02:00:38 +04:00
|
|
|
// IScreenEventHandler overrides
|
|
|
|
virtual void onScreensaver(bool activated);
|
2002-07-13 00:41:23 +04:00
|
|
|
virtual bool onPreDispatch(const CEvent* event);
|
|
|
|
virtual bool onEvent(CEvent* event);
|
2003-02-23 00:53:25 +03:00
|
|
|
virtual void onOneShotTimerExpired(UInt32 id);
|
2002-07-15 19:01:36 +04:00
|
|
|
virtual SInt32 getJumpZoneSize() const;
|
2002-07-14 02:00:38 +04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
// CSecondaryScreen overrides
|
2002-07-30 19:17:44 +04:00
|
|
|
virtual void onPreMainLoop();
|
2002-07-14 02:00:38 +04:00
|
|
|
virtual void onPreOpen();
|
|
|
|
virtual void onPostOpen();
|
|
|
|
virtual void onPreEnter();
|
2003-05-03 17:28:21 +04:00
|
|
|
virtual void onPostEnter();
|
2002-07-14 02:00:38 +04:00
|
|
|
virtual void onPreLeave();
|
|
|
|
virtual void createWindow();
|
|
|
|
virtual void destroyWindow();
|
2003-05-03 17:50:06 +04:00
|
|
|
virtual void showWindow(SInt32 x, SInt32 y);
|
2002-07-14 02:00:38 +04:00
|
|
|
virtual void hideWindow();
|
|
|
|
virtual void warpCursor(SInt32 x, SInt32 y);
|
|
|
|
virtual void updateKeys();
|
2003-03-13 01:34:07 +03:00
|
|
|
virtual void releaseKeys();
|
2002-07-14 02:00:38 +04:00
|
|
|
virtual void setToggleState(KeyModifierMask);
|
2002-12-16 01:14:49 +03:00
|
|
|
virtual KeyModifierMask getToggleState() const;
|
2001-11-12 00:15:30 +03:00
|
|
|
|
2002-04-29 18:40:01 +04:00
|
|
|
private:
|
2002-05-03 15:26:44 +04:00
|
|
|
enum EKeyAction { kPress, kRelease, kRepeat };
|
|
|
|
class KeyCodeMask {
|
2002-04-26 21:38:01 +04:00
|
|
|
public:
|
2002-09-14 16:07:02 +04:00
|
|
|
KeyCodeMask();
|
|
|
|
public:
|
|
|
|
KeyCode m_keycode[4];
|
2002-05-03 15:26:44 +04:00
|
|
|
};
|
|
|
|
class Keystroke {
|
|
|
|
public:
|
|
|
|
KeyCode m_keycode;
|
|
|
|
Bool m_press;
|
|
|
|
bool m_repeat;
|
2002-04-26 21:38:01 +04:00
|
|
|
};
|
|
|
|
typedef std::vector<Keystroke> Keystrokes;
|
|
|
|
typedef std::vector<KeyCode> KeyCodes;
|
2002-09-14 16:07:02 +04:00
|
|
|
typedef std::map<KeySym, KeyCodeMask> KeyCodeMap;
|
|
|
|
typedef KeyCodeMap::const_iterator KeyCodeIndex;
|
2002-04-26 21:38:01 +04:00
|
|
|
typedef std::map<KeyCode, unsigned int> ModifierMap;
|
2003-04-27 21:01:14 +04:00
|
|
|
typedef std::map<KeyButton, KeyCode> ServerKeyMap;
|
2002-04-26 21:38:01 +04:00
|
|
|
|
2001-10-08 23:24:46 +04:00
|
|
|
unsigned int mapButton(ButtonID button) const;
|
|
|
|
|
2002-04-26 21:38:01 +04:00
|
|
|
unsigned int mapKey(Keystrokes&, KeyCode&, KeyID,
|
2002-06-11 02:06:45 +04:00
|
|
|
KeyModifierMask, EKeyAction) const;
|
2002-05-03 15:26:44 +04:00
|
|
|
void doKeystrokes(const Keystrokes&, SInt32 count);
|
2002-04-26 21:38:01 +04:00
|
|
|
unsigned int maskToX(KeyModifierMask) const;
|
|
|
|
|
2003-03-16 20:40:56 +03:00
|
|
|
void doUpdateKeys(Display*);
|
2003-03-13 01:34:07 +03:00
|
|
|
void doReleaseKeys(Display*);
|
2002-04-26 21:38:01 +04:00
|
|
|
void updateKeycodeMap(Display* display);
|
|
|
|
void updateModifiers(Display* display);
|
|
|
|
void updateModifierMap(Display* display);
|
2002-09-01 19:30:00 +04:00
|
|
|
unsigned int indexToModifierMask(int index) const;
|
2002-04-30 21:48:11 +04:00
|
|
|
void toggleKey(Display*, KeySym, unsigned int mask);
|
2002-04-26 21:38:01 +04:00
|
|
|
static bool isToggleKeysym(KeySym);
|
|
|
|
|
2002-09-14 16:07:02 +04:00
|
|
|
KeyCodeIndex findKey(KeyID keysym, KeyModifierMask& mask) const;
|
|
|
|
KeyCodeIndex noKey() const;
|
|
|
|
bool adjustForNumLock(KeySym) const;
|
|
|
|
bool adjustForCapsLock(KeySym) const;
|
|
|
|
|
2002-04-29 18:40:01 +04:00
|
|
|
private:
|
2002-09-14 16:07:02 +04:00
|
|
|
enum { kNONE, kSHIFT, kALTGR, kSHIFT_ALTGR };
|
|
|
|
|
2002-07-14 02:00:38 +04:00
|
|
|
CXWindowsScreen* m_screen;
|
2001-10-08 23:24:46 +04:00
|
|
|
Window m_window;
|
2002-04-26 21:38:01 +04:00
|
|
|
|
2002-05-04 22:31:54 +04:00
|
|
|
// note toggle keys that toggles on up/down (false) or on
|
2002-04-30 20:25:29 +04:00
|
|
|
// transition (true)
|
2002-05-04 22:31:54 +04:00
|
|
|
bool m_numLockHalfDuplex;
|
2002-04-30 20:25:29 +04:00
|
|
|
bool m_capsLockHalfDuplex;
|
|
|
|
|
2003-03-16 20:40:56 +03: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 21:38:01 +04:00
|
|
|
|
2002-08-18 21:31:48 +04:00
|
|
|
// logical to physical button mapping. m_buttons[i] gives the
|
|
|
|
// physical button for logical button i+1.
|
2002-12-16 01:39:59 +03:00
|
|
|
std::vector<unsigned char> m_buttons;
|
2002-08-18 21:31:48 +04:00
|
|
|
|
2002-04-26 21:38:01 +04:00
|
|
|
// current active modifiers (X key masks)
|
|
|
|
unsigned int m_mask;
|
|
|
|
|
|
|
|
// maps key IDs to X keycodes and the X modifier key mask needed
|
|
|
|
// to generate the right keysym
|
|
|
|
KeyCodeMap m_keycodeMap;
|
|
|
|
|
|
|
|
// the modifiers that have keys bound to them
|
|
|
|
unsigned int m_modifierMask;
|
|
|
|
|
|
|
|
// set bits indicate modifiers that toggle (e.g. caps-lock)
|
|
|
|
unsigned int m_toggleModifierMask;
|
|
|
|
|
2002-09-01 19:30:00 +04:00
|
|
|
// modifier masks
|
|
|
|
unsigned int m_altMask;
|
|
|
|
unsigned int m_metaMask;
|
2002-09-14 16:07:02 +04:00
|
|
|
unsigned int m_superMask;
|
2002-09-01 19:30:00 +04:00
|
|
|
unsigned int m_modeSwitchMask;
|
2002-04-26 21:38:01 +04:00
|
|
|
unsigned int m_numLockMask;
|
|
|
|
unsigned int m_capsLockMask;
|
2002-04-30 21:48:11 +04:00
|
|
|
unsigned int m_scrollLockMask;
|
2002-04-26 21:38:01 +04:00
|
|
|
|
|
|
|
// map X modifier key indices to the key codes bound to them
|
|
|
|
unsigned int m_keysPerModifier;
|
|
|
|
KeyCodes m_modifierToKeycode;
|
2002-09-14 16:07:02 +04:00
|
|
|
KeyCodes m_modifierToKeycodes;
|
2002-04-26 21:38:01 +04:00
|
|
|
|
|
|
|
// maps keycodes to modifier indices
|
|
|
|
ModifierMap m_keycodeToModifier;
|
2003-04-27 21:01:14 +04:00
|
|
|
|
|
|
|
// map server key buttons to local keycodes
|
|
|
|
ServerKeyMap m_serverKeyMap;
|
2003-05-03 17:28:21 +04:00
|
|
|
|
|
|
|
// the keyboard control state the last time this screen was entered
|
|
|
|
XKeyboardState m_keyControl;
|
2001-10-08 23:24:46 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|