2022-03-19 17:48:18 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "../defines.hpp"
|
2024-12-16 15:58:19 +00:00
|
|
|
#include <vector>
|
2024-05-16 10:48:30 +00:00
|
|
|
#include <set>
|
2022-04-21 15:50:52 +02:00
|
|
|
#include <unordered_map>
|
|
|
|
|
#include <functional>
|
2024-07-21 13:09:54 +02:00
|
|
|
#include <xkbcommon/xkbcommon.h>
|
2024-05-05 22:18:10 +01:00
|
|
|
#include "../devices/IPointer.hpp"
|
2024-11-16 07:21:59 +08:00
|
|
|
#include "eventLoop/EventLoopTimer.hpp"
|
2025-04-16 01:37:48 +01:00
|
|
|
#include "../helpers/time/Timer.hpp"
|
2022-03-19 17:48:18 +01:00
|
|
|
|
2022-07-31 15:46:42 +02:00
|
|
|
class CInputManager;
|
2022-11-10 13:50:16 +00:00
|
|
|
class CConfigManager;
|
2023-02-27 12:32:38 +00:00
|
|
|
class CPluginSystem;
|
2024-05-03 22:34:10 +01:00
|
|
|
class IKeyboard;
|
2022-07-31 15:46:42 +02:00
|
|
|
|
2024-12-07 18:51:18 +01:00
|
|
|
enum eMouseBindMode : int8_t;
|
|
|
|
|
|
2022-03-19 17:48:18 +01:00
|
|
|
struct SKeybind {
|
2024-06-11 19:49:54 +02:00
|
|
|
std::string key = "";
|
|
|
|
|
std::set<xkb_keysym_t> sMkKeys = {};
|
|
|
|
|
uint32_t keycode = 0;
|
|
|
|
|
bool catchAll = false;
|
|
|
|
|
uint32_t modmask = 0;
|
|
|
|
|
std::set<xkb_keysym_t> sMkMods = {};
|
|
|
|
|
std::string handler = "";
|
|
|
|
|
std::string arg = "";
|
|
|
|
|
bool locked = false;
|
|
|
|
|
std::string submap = "";
|
|
|
|
|
std::string description = "";
|
|
|
|
|
bool release = false;
|
|
|
|
|
bool repeat = false;
|
2024-11-16 07:21:59 +08:00
|
|
|
bool longPress = false;
|
2024-06-11 19:49:54 +02:00
|
|
|
bool mouse = false;
|
|
|
|
|
bool nonConsuming = false;
|
|
|
|
|
bool transparent = false;
|
|
|
|
|
bool ignoreMods = false;
|
|
|
|
|
bool multiKey = false;
|
|
|
|
|
bool hasDescription = false;
|
2024-07-24 12:10:36 +00:00
|
|
|
bool dontInhibit = false;
|
2025-04-12 10:43:13 -04:00
|
|
|
bool click = false;
|
|
|
|
|
bool drag = false;
|
2022-07-20 23:17:26 +02:00
|
|
|
|
|
|
|
|
// DO NOT INITIALIZE
|
2022-12-16 17:17:31 +00:00
|
|
|
bool shadowed = false;
|
2022-03-19 17:48:18 +01:00
|
|
|
};
|
|
|
|
|
|
2024-12-07 18:51:18 +01:00
|
|
|
enum eFocusWindowMode : uint8_t {
|
2022-07-26 17:30:30 +02:00
|
|
|
MODE_CLASS_REGEX = 0,
|
2024-04-21 17:19:59 +03:00
|
|
|
MODE_INITIAL_CLASS_REGEX,
|
2022-07-26 17:30:30 +02:00
|
|
|
MODE_TITLE_REGEX,
|
2024-04-21 17:19:59 +03:00
|
|
|
MODE_INITIAL_TITLE_REGEX,
|
2025-01-09 14:52:26 -06:00
|
|
|
MODE_TAG_REGEX,
|
2022-07-26 17:30:30 +02:00
|
|
|
MODE_ADDRESS,
|
2024-04-21 17:19:59 +03:00
|
|
|
MODE_PID,
|
|
|
|
|
MODE_ACTIVE_WINDOW
|
2022-07-26 17:30:30 +02:00
|
|
|
};
|
|
|
|
|
|
2024-01-01 18:29:51 +01:00
|
|
|
struct SPressedKeyWithMods {
|
|
|
|
|
std::string keyName = "";
|
|
|
|
|
xkb_keysym_t keysym = 0;
|
|
|
|
|
uint32_t keycode = 0;
|
|
|
|
|
uint32_t modmaskAtPressTime = 0;
|
2024-01-10 18:06:38 +01:00
|
|
|
bool sent = false;
|
2024-03-09 16:08:07 +00:00
|
|
|
std::string submapAtPress = "";
|
2025-04-12 10:43:13 -04:00
|
|
|
Vector2D mousePosAtPress = {};
|
2024-01-01 18:29:51 +01:00
|
|
|
};
|
|
|
|
|
|
2024-03-03 01:17:02 +01:00
|
|
|
struct SParsedKey {
|
|
|
|
|
std::string key = "";
|
|
|
|
|
uint32_t keycode = 0;
|
|
|
|
|
bool catchAll = false;
|
|
|
|
|
};
|
|
|
|
|
|
2024-12-07 18:51:18 +01:00
|
|
|
enum eMultiKeyCase : uint8_t {
|
2024-05-16 10:48:30 +00:00
|
|
|
MK_NO_MATCH = 0,
|
|
|
|
|
MK_PARTIAL_MATCH,
|
|
|
|
|
MK_FULL_MATCH
|
|
|
|
|
};
|
|
|
|
|
|
2022-03-19 17:48:18 +01:00
|
|
|
class CKeybindManager {
|
2022-12-16 17:17:31 +00:00
|
|
|
public:
|
2022-04-21 15:50:52 +02:00
|
|
|
CKeybindManager();
|
2024-05-03 15:42:08 +02:00
|
|
|
~CKeybindManager();
|
2022-04-21 15:50:52 +02:00
|
|
|
|
2024-08-24 11:45:53 -05:00
|
|
|
bool onKeyEvent(std::any, SP<IKeyboard>);
|
|
|
|
|
bool onAxisEvent(const IPointer::SAxisEvent&);
|
|
|
|
|
bool onMouseEvent(const IPointer::SButtonEvent&);
|
|
|
|
|
void resizeWithBorder(const IPointer::SButtonEvent&);
|
|
|
|
|
void onSwitchEvent(const std::string&);
|
|
|
|
|
void onSwitchOnEvent(const std::string&);
|
|
|
|
|
void onSwitchOffEvent(const std::string&);
|
2022-09-25 20:07:48 +02:00
|
|
|
|
2024-08-24 11:45:53 -05:00
|
|
|
void addKeybind(SKeybind);
|
|
|
|
|
void removeKeybind(uint32_t, const SParsedKey&);
|
|
|
|
|
uint32_t stringToModMask(std::string);
|
|
|
|
|
uint32_t keycodeToModifier(xkb_keycode_t);
|
|
|
|
|
void clearKeybinds();
|
|
|
|
|
void shadowKeybinds(const xkb_keysym_t& doesntHave = 0, const uint32_t doesntHaveCode = 0);
|
2024-09-24 11:25:05 +01:00
|
|
|
std::string getCurrentSubmap();
|
2022-03-19 17:48:18 +01:00
|
|
|
|
2024-08-24 11:45:53 -05:00
|
|
|
std::unordered_map<std::string, std::function<SDispatchResult(std::string)>> m_mDispatchers;
|
2022-04-21 15:50:52 +02:00
|
|
|
|
2024-08-24 11:45:53 -05:00
|
|
|
bool m_bGroupsLocked = false;
|
2023-02-21 12:13:35 +00:00
|
|
|
|
2024-11-18 19:56:26 +00:00
|
|
|
std::vector<SP<SKeybind>> m_vKeybinds;
|
2023-01-06 14:32:25 +01:00
|
|
|
|
2024-05-24 20:58:26 +02:00
|
|
|
//since we cant find keycode through keyname in xkb:
|
|
|
|
|
//on sendshortcut call, we once search for keyname (e.g. "g") the correct keycode (e.g. 42)
|
|
|
|
|
//and cache it in this map to make sendshortcut calls faster
|
|
|
|
|
//we also store the keyboard pointer (in the string) to differentiate between different keyboard (layouts)
|
|
|
|
|
std::unordered_map<std::string, xkb_keycode_t> m_mKeyToCodeCache;
|
|
|
|
|
|
2024-08-24 11:45:53 -05:00
|
|
|
static SDispatchResult changeMouseBindMode(const eMouseBindMode mode);
|
2024-07-27 16:46:19 +00:00
|
|
|
|
2022-12-16 17:17:31 +00:00
|
|
|
private:
|
2024-12-16 15:58:19 +00:00
|
|
|
std::vector<SPressedKeyWithMods> m_dPressedKeys;
|
2022-03-19 17:48:18 +01:00
|
|
|
|
2024-12-16 15:58:19 +00:00
|
|
|
inline static std::string m_szCurrentSelectedSubmap = "";
|
2022-06-22 20:23:20 +02:00
|
|
|
|
2024-12-16 15:58:19 +00:00
|
|
|
std::vector<WP<SKeybind>> m_vActiveKeybinds;
|
|
|
|
|
WP<SKeybind> m_pLastLongPressKeybind;
|
|
|
|
|
SP<CEventLoopTimer> m_pLongPressTimer, m_pRepeatKeyTimer;
|
2022-07-25 14:42:49 +02:00
|
|
|
|
2024-12-16 15:58:19 +00:00
|
|
|
uint32_t m_uTimeLastMs = 0;
|
|
|
|
|
uint32_t m_uLastCode = 0;
|
|
|
|
|
uint32_t m_uLastMouseCode = 0;
|
2022-07-26 17:30:30 +02:00
|
|
|
|
2024-12-16 15:58:19 +00:00
|
|
|
std::vector<WP<SKeybind>> m_vPressedSpecialBinds;
|
2022-09-20 10:02:20 +01:00
|
|
|
|
2024-12-16 15:58:19 +00:00
|
|
|
int m_iPassPressed = -1; // used for pass
|
2022-08-27 19:29:28 +02:00
|
|
|
|
2024-12-16 15:58:19 +00:00
|
|
|
CTimer m_tScrollTimer;
|
2022-07-26 23:34:03 +02:00
|
|
|
|
2024-12-16 15:58:19 +00:00
|
|
|
SDispatchResult handleKeybinds(const uint32_t, const SPressedKeyWithMods&, bool);
|
2022-07-20 23:17:26 +02:00
|
|
|
|
2024-12-16 15:58:19 +00:00
|
|
|
std::set<xkb_keysym_t> m_sMkKeys = {};
|
|
|
|
|
std::set<xkb_keysym_t> m_sMkMods = {};
|
|
|
|
|
eMultiKeyCase mkBindMatches(const SP<SKeybind>);
|
|
|
|
|
eMultiKeyCase mkKeysymSetMatches(const std::set<xkb_keysym_t>, const std::set<xkb_keysym_t>);
|
2024-05-16 10:48:30 +00:00
|
|
|
|
2024-12-16 15:58:19 +00:00
|
|
|
bool handleInternalKeybinds(xkb_keysym_t);
|
|
|
|
|
bool handleVT(xkb_keysym_t);
|
2022-03-19 17:48:18 +01:00
|
|
|
|
2024-12-16 15:58:19 +00:00
|
|
|
xkb_state* m_pXKBTranslationState = nullptr;
|
2022-08-21 16:43:18 +02:00
|
|
|
|
2024-12-16 15:58:19 +00:00
|
|
|
void updateXKBTranslationState();
|
|
|
|
|
bool ensureMouseBindState();
|
2022-08-21 16:43:18 +02:00
|
|
|
|
2024-12-16 15:58:19 +00:00
|
|
|
static bool tryMoveFocusToMonitor(PHLMONITOR monitor);
|
|
|
|
|
static void moveWindowOutOfGroup(PHLWINDOW pWindow, const std::string& dir = "");
|
|
|
|
|
static void moveWindowIntoGroup(PHLWINDOW pWindow, PHLWINDOW pWindowInDirection);
|
2025-02-03 04:34:30 +03:00
|
|
|
static void switchToWindow(PHLWINDOW PWINDOWTOCHANGETO, bool preserveFocusHistory = false);
|
2024-12-16 15:58:19 +00:00
|
|
|
static uint64_t spawnRawProc(std::string, PHLWORKSPACE pInitialWorkspace);
|
|
|
|
|
static uint64_t spawnWithRules(std::string, PHLWORKSPACE pInitialWorkspace);
|
2023-04-10 15:40:03 +02:00
|
|
|
|
2022-03-19 17:48:18 +01:00
|
|
|
// -------------- Dispatchers -------------- //
|
2025-01-09 05:16:34 +08:00
|
|
|
static SDispatchResult closeActive(std::string);
|
2024-08-24 11:45:53 -05:00
|
|
|
static SDispatchResult killActive(std::string);
|
2025-01-09 05:16:34 +08:00
|
|
|
static SDispatchResult closeWindow(std::string);
|
|
|
|
|
static SDispatchResult killWindow(std::string);
|
|
|
|
|
static SDispatchResult signalActive(std::string);
|
|
|
|
|
static SDispatchResult signalWindow(std::string);
|
2024-08-24 11:45:53 -05:00
|
|
|
static SDispatchResult spawn(std::string);
|
|
|
|
|
static SDispatchResult spawnRaw(std::string);
|
|
|
|
|
static SDispatchResult toggleActiveFloating(std::string);
|
|
|
|
|
static SDispatchResult toggleActivePseudo(std::string);
|
|
|
|
|
static SDispatchResult setActiveFloating(std::string);
|
|
|
|
|
static SDispatchResult setActiveTiled(std::string);
|
|
|
|
|
static SDispatchResult changeworkspace(std::string);
|
|
|
|
|
static SDispatchResult fullscreenActive(std::string);
|
|
|
|
|
static SDispatchResult fullscreenStateActive(std::string args);
|
|
|
|
|
static SDispatchResult moveActiveToWorkspace(std::string);
|
|
|
|
|
static SDispatchResult moveActiveToWorkspaceSilent(std::string);
|
|
|
|
|
static SDispatchResult moveFocusTo(std::string);
|
|
|
|
|
static SDispatchResult focusUrgentOrLast(std::string);
|
|
|
|
|
static SDispatchResult focusCurrentOrLast(std::string);
|
|
|
|
|
static SDispatchResult centerWindow(std::string);
|
|
|
|
|
static SDispatchResult moveActiveTo(std::string);
|
|
|
|
|
static SDispatchResult swapActive(std::string);
|
|
|
|
|
static SDispatchResult toggleGroup(std::string);
|
|
|
|
|
static SDispatchResult changeGroupActive(std::string);
|
|
|
|
|
static SDispatchResult alterSplitRatio(std::string);
|
|
|
|
|
static SDispatchResult focusMonitor(std::string);
|
|
|
|
|
static SDispatchResult toggleSplit(std::string);
|
|
|
|
|
static SDispatchResult swapSplit(std::string);
|
|
|
|
|
static SDispatchResult moveCursorToCorner(std::string);
|
|
|
|
|
static SDispatchResult moveCursor(std::string);
|
|
|
|
|
static SDispatchResult workspaceOpt(std::string);
|
|
|
|
|
static SDispatchResult renameWorkspace(std::string);
|
|
|
|
|
static SDispatchResult exitHyprland(std::string);
|
|
|
|
|
static SDispatchResult moveCurrentWorkspaceToMonitor(std::string);
|
|
|
|
|
static SDispatchResult moveWorkspaceToMonitor(std::string);
|
|
|
|
|
static SDispatchResult focusWorkspaceOnCurrentMonitor(std::string);
|
|
|
|
|
static SDispatchResult toggleSpecialWorkspace(std::string);
|
|
|
|
|
static SDispatchResult forceRendererReload(std::string);
|
|
|
|
|
static SDispatchResult resizeActive(std::string);
|
|
|
|
|
static SDispatchResult moveActive(std::string);
|
|
|
|
|
static SDispatchResult moveWindow(std::string);
|
|
|
|
|
static SDispatchResult resizeWindow(std::string);
|
|
|
|
|
static SDispatchResult circleNext(std::string);
|
|
|
|
|
static SDispatchResult focusWindow(std::string);
|
|
|
|
|
static SDispatchResult tagWindow(std::string);
|
2025-02-05 10:56:41 +01:00
|
|
|
static SDispatchResult toggleSwallow(std::string);
|
2024-08-24 11:45:53 -05:00
|
|
|
static SDispatchResult setSubmap(std::string);
|
|
|
|
|
static SDispatchResult pass(std::string);
|
|
|
|
|
static SDispatchResult sendshortcut(std::string);
|
2025-03-24 23:59:13 +00:00
|
|
|
static SDispatchResult sendkeystate(std::string);
|
2024-08-24 11:45:53 -05:00
|
|
|
static SDispatchResult layoutmsg(std::string);
|
|
|
|
|
static SDispatchResult dpms(std::string);
|
|
|
|
|
static SDispatchResult swapnext(std::string);
|
|
|
|
|
static SDispatchResult swapActiveWorkspaces(std::string);
|
|
|
|
|
static SDispatchResult pinActive(std::string);
|
|
|
|
|
static SDispatchResult mouse(std::string);
|
|
|
|
|
static SDispatchResult bringActiveToTop(std::string);
|
|
|
|
|
static SDispatchResult alterZOrder(std::string);
|
|
|
|
|
static SDispatchResult lockGroups(std::string);
|
|
|
|
|
static SDispatchResult lockActiveGroup(std::string);
|
|
|
|
|
static SDispatchResult moveIntoGroup(std::string);
|
|
|
|
|
static SDispatchResult moveOutOfGroup(std::string);
|
|
|
|
|
static SDispatchResult moveGroupWindow(std::string);
|
|
|
|
|
static SDispatchResult moveWindowOrGroup(std::string);
|
|
|
|
|
static SDispatchResult setIgnoreGroupLock(std::string);
|
|
|
|
|
static SDispatchResult denyWindowFromGroup(std::string);
|
|
|
|
|
static SDispatchResult global(std::string);
|
|
|
|
|
static SDispatchResult event(std::string);
|
2024-10-28 18:18:58 +00:00
|
|
|
static SDispatchResult setProp(std::string);
|
2022-05-30 17:11:35 +02:00
|
|
|
|
|
|
|
|
friend class CCompositor;
|
2022-07-31 15:46:42 +02:00
|
|
|
friend class CInputManager;
|
2022-11-10 13:50:16 +00:00
|
|
|
friend class CConfigManager;
|
2024-04-06 19:53:32 +05:00
|
|
|
friend class CWorkspace;
|
2024-09-09 20:29:00 +00:00
|
|
|
friend class CPointerManager;
|
2022-03-19 17:48:18 +01:00
|
|
|
};
|
|
|
|
|
|
2025-01-23 21:55:41 +01:00
|
|
|
inline UP<CKeybindManager> g_pKeybindManager;
|