deskflow/src/lib/synergy/KeyState.h

239 lines
6.9 KiB
C
Raw Normal View History

2012-06-10 16:50:54 +00:00
/*
* synergy -- mouse and keyboard sharing utility
2016-09-07 14:24:00 +00:00
* Copyright (C) 2012-2016 Symless Ltd.
* Copyright (C) 2004 Chris Schoeneman
*
2012-06-10 16:50:54 +00:00
* 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 LICENSE that should have accompanied this file.
*
2012-06-10 16:50:54 +00:00
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
2012-06-10 16:50:54 +00:00
#include "synergy/IKeyState.h"
#include "synergy/KeyMap.h"
2012-06-10 16:50:54 +00:00
//! Core key state
/*!
This class provides key state services. Subclasses must implement a few
platform specific methods.
*/
2014-11-11 13:51:47 +00:00
class KeyState : public IKeyState {
2012-06-10 16:50:54 +00:00
public:
KeyState(
IEventQueue *events, std::vector<String> layouts, bool isLangSyncEnabled);
KeyState(
IEventQueue *events, synergy::KeyMap &keyMap, std::vector<String> layouts,
bool isLangSyncEnabled);
virtual ~KeyState();
//! @name manipulators
//@{
//! Handle key event
/*!
Sets the state of \p button to down or up and updates the current
modifier state to \p newState. This method should be called by
primary screens only in response to local events. For auto-repeat
set \p down to \c true. Overrides must forward to the superclass.
*/
virtual void onKey(KeyButton button, bool down, KeyModifierMask newState);
//! Post a key event
/*!
Posts a key event. This may adjust the event or post additional
events in some circumstances. If this is overridden it must forward
to the superclass.
*/
virtual void sendKeyEvent(
void *target, bool press, bool isAutoRepeat, KeyID key,
KeyModifierMask mask, SInt32 count, KeyButton button);
//@}
//! @name accessors
//@{
//@}
void updateKeyMap(synergy::KeyMap *existing);
// IKeyState overrides
void updateKeyMap() override { this->updateKeyMap(nullptr); }
void updateKeyState() override;
void setHalfDuplexMask(KeyModifierMask) override;
void fakeKeyDown(
KeyID id, KeyModifierMask mask, KeyButton button,
const String &lang) override;
bool fakeKeyRepeat(
KeyID id, KeyModifierMask mask, SInt32 count, KeyButton button,
const String &lang) override;
bool fakeKeyUp(KeyButton button) override;
void fakeAllKeysUp() override;
bool fakeMediaKey(KeyID id) override;
bool isKeyDown(KeyButton) const override;
KeyModifierMask getActiveModifiers() const override;
// Left abstract
virtual bool fakeCtrlAltDel() = 0;
virtual KeyModifierMask pollActiveModifiers() const = 0;
virtual SInt32 pollActiveGroup() const = 0;
virtual void pollPressedKeys(KeyButtonSet &pressedKeys) const = 0;
SInt32 getKeyState(KeyButton keyButton) { return m_keys[keyButton]; }
2012-06-10 16:50:54 +00:00
protected:
typedef synergy::KeyMap::Keystroke Keystroke;
//! @name protected manipulators
//@{
//! Get the keyboard map
/*!
Fills \p keyMap with the current keyboard map.
*/
virtual void getKeyMap(synergy::KeyMap &keyMap) = 0;
//! Fake a key event
/*!
Synthesize an event for \p keystroke.
*/
virtual void fakeKey(const Keystroke &keystroke) = 0;
//! Get the active modifiers
/*!
Returns the modifiers that are currently active according to our
shadowed state. The state may be modified.
*/
virtual KeyModifierMask &getActiveModifiersRValue();
//@}
//! @name protected accessors
//@{
//! Compute a group number
/*!
Returns the number of the group \p offset groups after group \p group.
*/
SInt32 getEffectiveGroup(SInt32 group, SInt32 offset) const;
//! Check if key is ignored
/*!
Returns \c true if and only if the key should always be ignored.
The default returns \c true only for the toggle keys.
*/
virtual bool isIgnoredKey(KeyID key, KeyModifierMask mask) const;
//! Get button for a KeyID
/*!
Return the button mapped to key \p id in group \p group if any,
otherwise returns 0.
*/
KeyButton getButton(KeyID id, SInt32 group) const;
//@}
2012-06-10 16:50:54 +00:00
private:
typedef synergy::KeyMap::Keystrokes Keystrokes;
typedef synergy::KeyMap::ModifierToKeys ModifierToKeys;
2012-06-10 16:50:54 +00:00
public:
struct AddActiveModifierContext {
public:
AddActiveModifierContext(
SInt32 group, KeyModifierMask mask, ModifierToKeys &activeModifiers);
public:
SInt32 m_activeGroup;
KeyModifierMask m_mask;
ModifierToKeys &m_activeModifiers;
private:
// not implemented
AddActiveModifierContext(const AddActiveModifierContext &);
AddActiveModifierContext &operator=(const AddActiveModifierContext &);
};
private:
class ButtonToKeyLess {
public:
bool operator()(
const synergy::KeyMap::ButtonToKeyMap::value_type &a,
const synergy::KeyMap::ButtonToKeyMap::value_type b) const {
return (a.first < b.first);
}
};
// not implemented
KeyState(const KeyState &);
KeyState &operator=(const KeyState &);
// called by all ctors.
void init();
// adds alias key sequences. these are sequences that are equivalent
// to other sequences.
void addAliasEntries();
// adds non-keypad key sequences for keypad KeyIDs
void addKeypadEntries();
// adds key sequences for combination KeyIDs (those built using
// dead keys)
void addCombinationEntries();
// synthesize key events. synthesize auto-repeat events count times.
void fakeKeys(const Keystrokes &, UInt32 count);
// update key state to match changes to modifiers
void updateModifierKeyState(
KeyButton button, const ModifierToKeys &oldModifiers,
const ModifierToKeys &newModifiers);
// active modifiers collection callback
static void addActiveModifierCB(
KeyID id, SInt32 group, synergy::KeyMap::KeyItem &keyItem,
void *vcontext);
2012-06-10 16:50:54 +00:00
private:
// must be declared before m_keyMap. used when this class owns the key map.
synergy::KeyMap *m_keyMapPtr;
2012-06-10 16:50:54 +00:00
// the keyboard map
synergy::KeyMap &m_keyMap;
2012-06-10 16:50:54 +00:00
// current modifier state
KeyModifierMask m_mask;
2012-06-10 16:50:54 +00:00
// the active modifiers and the buttons activating them
ModifierToKeys m_activeModifiers;
2012-06-10 16:50:54 +00:00
// current keyboard state (> 0 if pressed, 0 otherwise). this is
// initialized to the keyboard state according to the system then
// it tracks synthesized events.
SInt32 m_keys[kNumButtons];
2012-06-10 16:50:54 +00:00
// synthetic keyboard state (> 0 if pressed, 0 otherwise). this
// tracks the synthesized keyboard state. if m_keys[n] > 0 but
// m_syntheticKeys[n] == 0 then the key was pressed locally and
// not synthesized yet.
SInt32 m_syntheticKeys[kNumButtons];
2012-06-10 16:50:54 +00:00
// client data for each pressed key
UInt32 m_keyClientData[kNumButtons];
2012-06-10 16:50:54 +00:00
// server keyboard state. an entry is 0 if not the key isn't pressed
// otherwise it's the local KeyButton synthesized for the server key.
KeyButton m_serverKeys[kNumButtons];
IEventQueue *m_events;
Synergy 907 client tray language switcher reverts to en (#7038) * SYNERGY-907 Client tray language switcher reverts to EN *Fix checkbox spelling * SYNERGY-907 Client tray language switcher reverts to EN *Update changelog * SYNERGY-907 Client tray language switcher reverts to EN *Temporary disable language sync logic * SYNERGY-907 client tray language switcher reverts to en *Update changelog * Synergy 907 client tray language switcher reverts to en *Fix sonar * Synergy 907 client tray language switcher reverts to en *Fix sonar * Synergy 907 client tray language switcher reverts to en *Fix chnagelog * SYNERGY-907 Client tray language switcher reverts to EN *Add prototype of keyboard layout names transfer(Windows part) * SYNERGY-907 Client tray language switcher reverts to EN *Add keyboard layout determination(Mac part) * SYNERGY-907 Client tray language switcher reverts to EN *Add language check on client side * SYNERGY-907 Client tray language switcher reverts to EN *Fix Windows build * SYNERGY-907-Client-tray-language-switcher-reverts-to-EN *Add logs * SYNERGY-907-Client-tray-language-switcher-reverts-to-EN *Add protocol update * SYNERGY-907-Client-tray-language-switcher-reverts-to-EN *Add server side of language sync * SYNERGY-907-Client-tray-language-switcher-reverts-to-EN *Remove unused variables * SYNERGY-907-Client-tray-language-switcher-reverts-to-EN *AFix mac language determination * SYNERGY-907-Client-tray-language-switcher-reverts-to-EN *Clean up logs * SYNERGY-907 Client tray language switcher reverts to EN *Replace logs with messagebox on Windows * SYNERGY-907-Client-tray-language-switcher-reverts-to-EN *Add mac messagebox, revert protocol changes * SYNERGY-907-Client-tray-language-switcher-reverts-to-EN *Fix minor language bugs * SYNERGY-907-Client-tray-language-switcher-reverts-to-EN *Update chagelog * SYNERGY-907-Client-tray-language-switcher-reverts-to-EN *Minor fixes * SYNERGY-907-Client-tray-language-switcher-reverts-to-EN *Fix Linux build * SYNERGY-907-Client-tray-language-switcher-reverts-to-EN *Fix sonar code smells * SYNERGY-907-Client-tray-language-switcher-reverts-to-EN *Fix Linux build * SYNERGY-907-Client-tray-language-switcher-reverts-to-EN *Add Linux language determination * SYNERGY-907-Client-tray-language-switcher-reverts-to-EN *Fix sonar codesmells * SYNERGY-907-Client-tray-language-switcher-reverts-to-EN *Fix sonar codesmells * SYNERGY-907-Client-tray-language-switcher-reverts-to-EN *Replace custom xml parser with tinyxml2 * SYNERGY-907 Client tray language switcher reverts to EN *Fix PR comments * SYNERGY-907 Client tray language switcher reverts to EN *Update changelog * SYNERGY-907 Client tray language switcher reverts to EN *Fix unix build * SYNERGY-907 Client tray language switcher reverts to EN *Fix unix build * SYNERGY-907 Client tray language switcher reverts to EN *Fix sonar code smells * SYNERGY-907 Client tray language switcher reverts to EN *Update changelog * SYNERGY-907 Client tray language switcher reverts to EN *Replace tinuxml with pugixml * SYNERGY-907 Client tray language switcher reverts to EN *Add pugixml as a git submodule * SYNERGY-907 Client tray language switcher reverts to EN *Add missed files * SYNERGY-907 Client tray language switcher reverts to EN *Fix sonar code smells * SYNERGY-907 Client tray language switcher reverts to EN *Fix comments from PR * SYNERGY-907 Client tray language switcher reverts to EN *Fix sonar code smell * SYNERGY-907 Client tray language switcher reverts to EN *add tests for x11 files parser * SYNERGY-907 Client tray language switcher reverts to EN *Fix include for unix build * SYNERGY-907 Client tray language switcher reverts to EN *Add test coverage for new logic * SYNERGY-907 Client tray language switcher reverts to EN *Add test coverage for new logic * SYNERGY-907 Client tray language switcher reverts to EN *Add code coverage *Fix code smells * SYNERGY-907 Client tray language switcher reverts to EN *Return missed file * SYNERGY-907 Client tray language switcher reverts to EN *Improve code coverage of x11Layouts parser * SYNERGY-907 Client tray language switcher reverts to EN *Add client args code coverage * SYNERGY-907 Client tray language switcher reverts to EN *Return runtime language sync * SYNERGY-907 Client tray language switcher reverts to EN *Return windows current keyboard layout determination * SYNERGY-907 Client tray language switcher reverts to EN *Return Linux language determination * SYNERGY-907 Client tray language switcher reverts to EN *Remove debug code * SYNERGY-907 Client tray language switcher reverts to EN *Move back Carbon current language determination * SYNERGY-907 Client tray language switcher reverts to EN *Fix language change for existed languages on iOS and Linux * SYNERGY-907 Client tray language switcher reverts to EN *Return protocol missed parameter * SYNERGY-907 Client tray language switcher reverts to EN *Fix macOS language change * SYNERGY-907 Client tray language switcher reverts to EN *Fix language sync (when it is disabled) * SYNERGY-907 Client tray language switcher reverts to EN *Add correct language choosing *Fix code coverage tests * SYNERGY-907 Client tray language switcher reverts to EN *Fix windows build and tests * SYNERGY-907 Client tray language switcher reverts to EN *Fix macOS build and tests * SYNERGY-907 Client tray language switcher reverts to EN *Fix language change for first letter in keystroke * SYNERGY-907 Client tray language switcher reverts to EN *Fix macOS build * SYNERGY-907 Client tray language switcher reverts to EN *Partially fix Sonar codesmells * SYNERGY-907 Client tray language switcher reverts to EN *Partially fix Sonar codesmells * SYNERGY-907 Client tray language switcher reverts to EN *Fix build * SYNERGY-907 Client tray language switcher reverts to EN *Added logging for language change process *Fixed language change process for Windows * SYNERGY-907 Client tray language switcher reverts to EN *Fix double layout change in key repeat event * SYNERGY-907 Client tray language switcher reverts to EN *Fix determination of current language on windows *Removed legacy code of restoring language when leaving screen *Fix double group change on Linux * SYNERGY-907 Client tray language switcher reverts to EN *Temp fix for language change on Linux * SYNERGY-907 Client tray language switcher reverts to EN *Add XSync to normalize Linux language polling and setting *Remove setxkbmap using * SYNERGY-907 Client tray language switcher reverts to EN *Add keyboard layout changing on Linux with DBus * SYNERGY-907 Client tray language switcher reverts to EN *Add comments to new language change function *Logical fix * SYNERGY-907 Client tray language switcher reverts to EN *Remove input attaching * SYNERGY-907 Client tray language switcher reverts to EN *Fix language change on macOS * SYNERGY-907 Fix review issues * SYNERGY-907 Fix review comment for Windows * SYNERGY-907 Removed debug trace Co-authored-by: Andrii Batyiev <andrii-external@symless.com> Co-authored-by: user <user@users-Mac-mini.local> Co-authored-by: Serhii Hadzhilov <serhii-external@symless.com>
2021-10-04 15:51:12 +00:00
bool m_isLangSyncEnabled;
2012-06-10 16:50:54 +00:00
};