summaryrefslogtreecommitdiff
path: root/src/managers/KeybindManager.hpp
diff options
context:
space:
mode:
authorrszyma <rszyma.dev@gmail.com>2024-01-01 18:29:51 +0100
committerGitHub <noreply@github.com>2024-01-01 18:29:51 +0100
commit37b76cd1caed209e20e0e353671abf6ba4346b42 (patch)
tree7a8c955419bdfc950bc9a6edbac34f1874ee31c1 /src/managers/KeybindManager.hpp
parent0be36cd02d20617010ac3efff198fe7df0d6d07a (diff)
keybinds: fix keys getting stuck + minor refactor & optimizations to keybind handling (#4304)
Diffstat (limited to 'src/managers/KeybindManager.hpp')
-rw-r--r--src/managers/KeybindManager.hpp53
1 files changed, 30 insertions, 23 deletions
diff --git a/src/managers/KeybindManager.hpp b/src/managers/KeybindManager.hpp
index 73997dd6..631b0147 100644
--- a/src/managers/KeybindManager.hpp
+++ b/src/managers/KeybindManager.hpp
@@ -12,7 +12,7 @@ class CPluginSystem;
struct SKeybind {
std::string key = "";
- int keycode = -1;
+ uint32_t keycode = 0;
uint32_t modmask = 0;
std::string handler = "";
std::string arg = "";
@@ -36,6 +36,13 @@ enum eFocusWindowMode {
MODE_PID
};
+struct SPressedKeyWithMods {
+ std::string keyName = "";
+ xkb_keysym_t keysym = 0;
+ uint32_t keycode = 0;
+ uint32_t modmaskAtPressTime = 0;
+};
+
class CKeybindManager {
public:
CKeybindManager();
@@ -51,8 +58,9 @@ class CKeybindManager {
void addKeybind(SKeybind);
void removeKeybind(uint32_t, const std::string&);
uint32_t stringToModMask(std::string);
+ uint32_t keycodeToModifier(xkb_keycode_t);
void clearKeybinds();
- void shadowKeybinds(const xkb_keysym_t& doesntHave = 0, const int& doesntHaveCode = 0);
+ void shadowKeybinds(const xkb_keysym_t& doesntHave = 0, const uint32_t doesntHaveCode = 0);
std::unordered_map<std::string, std::function<void(std::string)>> m_mDispatchers;
@@ -63,38 +71,37 @@ class CKeybindManager {
std::list<SKeybind> m_lKeybinds;
private:
- std::deque<xkb_keysym_t> m_dPressedKeysyms;
- std::deque<int> m_dPressedKeycodes;
+ std::deque<SPressedKeyWithMods> m_dPressedKeys;
- inline static std::string m_szCurrentSelectedSubmap = "";
+ inline static std::string m_szCurrentSelectedSubmap = "";
- SKeybind* m_pActiveKeybind = nullptr;
+ SKeybind* m_pActiveKeybind = nullptr;
- uint32_t m_uTimeLastMs = 0;
- uint32_t m_uLastCode = 0;
- uint32_t m_uLastMouseCode = 0;
+ uint32_t m_uTimeLastMs = 0;
+ uint32_t m_uLastCode = 0;
+ uint32_t m_uLastMouseCode = 0;
- bool m_bIsMouseBindActive = false;
- std::vector<SKeybind*> m_vPressedSpecialBinds;
+ bool m_bIsMouseBindActive = false;
+ std::vector<SKeybind*> m_vPressedSpecialBinds;
- int m_iPassPressed = -1; // used for pass
+ int m_iPassPressed = -1; // used for pass
- CTimer m_tScrollTimer;
+ CTimer m_tScrollTimer;
- bool handleKeybinds(const uint32_t&, const std::string&, const xkb_keysym_t&, const int&, bool, uint32_t);
+ bool handleKeybinds(const uint32_t, const SPressedKeyWithMods&, bool);
- bool handleInternalKeybinds(xkb_keysym_t);
- bool handleVT(xkb_keysym_t);
+ bool handleInternalKeybinds(xkb_keysym_t);
+ bool handleVT(xkb_keysym_t);
- xkb_state* m_pXKBTranslationState = nullptr;
+ xkb_state* m_pXKBTranslationState = nullptr;
- void updateXKBTranslationState();
- bool ensureMouseBindState();
+ void updateXKBTranslationState();
+ bool ensureMouseBindState();
- static bool tryMoveFocusToMonitor(CMonitor* monitor);
- static void moveWindowOutOfGroup(CWindow* pWindow, const std::string& dir = "");
- static void moveWindowIntoGroup(CWindow* pWindow, CWindow* pWindowInDirection);
- static void switchToWindow(CWindow* PWINDOWTOCHANGETO);
+ static bool tryMoveFocusToMonitor(CMonitor* monitor);
+ static void moveWindowOutOfGroup(CWindow* pWindow, const std::string& dir = "");
+ static void moveWindowIntoGroup(CWindow* pWindow, CWindow* pWindowInDirection);
+ static void switchToWindow(CWindow* PWINDOWTOCHANGETO);
// -------------- Dispatchers -------------- //
static void killActive(std::string);