Hyprland/src/managers/KeybindManager.hpp

189 lines
7.8 KiB
C++
Raw Normal View History

2022-03-19 17:48:18 +01:00
#pragma once
#include "../defines.hpp"
#include <deque>
#include "../Compositor.hpp"
2022-04-21 15:50:52 +02:00
#include <unordered_map>
#include <functional>
2022-03-19 17:48:18 +01:00
2022-07-31 15:46:42 +02:00
class CInputManager;
2022-11-10 14:50:16 +01:00
class CConfigManager;
class CPluginSystem;
2022-07-31 15:46:42 +02:00
2022-03-19 17:48:18 +01:00
struct SKeybind {
std::string key = "";
uint32_t keycode = 0;
bool catchAll = false;
uint32_t modmask = 0;
std::string handler = "";
std::string arg = "";
bool locked = false;
std::string submap = "";
bool release = false;
bool repeat = false;
bool mouse = false;
bool nonConsuming = false;
bool transparent = false;
2023-10-17 21:09:54 +02:00
bool ignoreMods = false;
2022-07-20 23:17:26 +02:00
// DO NOT INITIALIZE
bool shadowed = false;
2022-03-19 17:48:18 +01:00
};
enum eFocusWindowMode {
2022-07-26 17:30:30 +02:00
MODE_CLASS_REGEX = 0,
MODE_INITIAL_CLASS_REGEX,
2022-07-26 17:30:30 +02:00
MODE_TITLE_REGEX,
MODE_INITIAL_TITLE_REGEX,
2022-07-26 17:30:30 +02:00
MODE_ADDRESS,
MODE_PID,
MODE_ACTIVE_WINDOW
2022-07-26 17:30:30 +02:00
};
struct SPressedKeyWithMods {
std::string keyName = "";
xkb_keysym_t keysym = 0;
uint32_t keycode = 0;
uint32_t modmaskAtPressTime = 0;
bool sent = false;
std::string submapAtPress = "";
};
struct SParsedKey {
std::string key = "";
uint32_t keycode = 0;
bool catchAll = false;
};
2022-03-19 17:48:18 +01:00
class CKeybindManager {
public:
2022-04-21 15:50:52 +02:00
CKeybindManager();
bool onKeyEvent(wlr_keyboard_key_event*, SKeyboard*);
bool onAxisEvent(wlr_pointer_axis_event*);
bool onMouseEvent(wlr_pointer_button_event*);
2023-02-18 23:35:31 +01:00
void resizeWithBorder(wlr_pointer_button_event*);
void onSwitchEvent(const std::string&);
void onSwitchOnEvent(const std::string&);
void onSwitchOffEvent(const std::string&);
2022-09-25 20:07:48 +02: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);
2022-03-19 17:48:18 +01:00
2022-04-21 15:50:52 +02:00
std::unordered_map<std::string, std::function<void(std::string)>> m_mDispatchers;
wl_event_source* m_pActiveKeybindEventSource = nullptr;
2022-07-25 14:42:49 +02:00
2023-02-21 13:13:35 +01:00
bool m_bGroupsLocked = false;
2023-01-06 14:32:25 +01:00
std::list<SKeybind> m_lKeybinds;
std::list<SShortcutInhibitor> m_lShortcutInhibitors;
2023-01-06 14:32:25 +01:00
private:
std::deque<SPressedKeyWithMods> m_dPressedKeys;
2022-03-19 17:48:18 +01:00
inline static std::string m_szCurrentSelectedSubmap = "";
2022-06-22 20:23:20 +02:00
SKeybind* m_pActiveKeybind = nullptr;
2022-07-25 14:42:49 +02:00
uint32_t m_uTimeLastMs = 0;
uint32_t m_uLastCode = 0;
uint32_t m_uLastMouseCode = 0;
2022-07-26 17:30:30 +02:00
bool m_bIsMouseBindActive = false;
std::vector<SKeybind*> m_vPressedSpecialBinds;
2022-09-20 11:02:20 +02:00
int m_iPassPressed = -1; // used for pass
CTimer m_tScrollTimer;
2022-07-26 23:34:03 +02:00
bool handleKeybinds(const uint32_t, const SPressedKeyWithMods&, bool);
2022-07-20 23:17:26 +02:00
bool handleInternalKeybinds(xkb_keysym_t);
bool handleVT(xkb_keysym_t);
2022-03-19 17:48:18 +01:00
xkb_state* m_pXKBTranslationState = nullptr;
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);
2022-03-19 17:48:18 +01:00
// -------------- Dispatchers -------------- //
2023-02-19 14:59:39 +01:00
static void killActive(std::string);
static void kill(std::string);
static void spawn(std::string);
static uint64_t spawnRaw(std::string);
static void toggleActiveFloating(std::string);
static void toggleActivePseudo(std::string);
static void setActiveFloating(std::string);
static void setActiveTiled(std::string);
2023-02-19 14:59:39 +01:00
static void changeworkspace(std::string);
static void fullscreenActive(std::string);
static void fakeFullscreenActive(std::string);
static void moveActiveToWorkspace(std::string);
static void moveActiveToWorkspaceSilent(std::string);
static void moveFocusTo(std::string);
static void focusUrgentOrLast(std::string);
static void focusCurrentOrLast(std::string);
static void centerWindow(std::string);
static void moveActiveTo(std::string);
2023-04-10 21:07:49 +02:00
static void swapActive(std::string);
2023-02-19 14:59:39 +01:00
static void toggleGroup(std::string);
static void changeGroupActive(std::string);
static void alterSplitRatio(std::string);
static void focusMonitor(std::string);
static void toggleSplit(std::string);
static void swapSplit(std::string);
2023-02-19 14:59:39 +01:00
static void moveCursorToCorner(std::string);
static void moveCursor(std::string);
2023-02-19 14:59:39 +01:00
static void workspaceOpt(std::string);
static void renameWorkspace(std::string);
static void exitHyprland(std::string);
static void moveCurrentWorkspaceToMonitor(std::string);
static void moveWorkspaceToMonitor(std::string);
static void focusWorkspaceOnCurrentMonitor(std::string);
2023-02-19 14:59:39 +01:00
static void toggleSpecialWorkspace(std::string);
static void forceRendererReload(std::string);
static void resizeActive(std::string);
static void moveActive(std::string);
static void moveWindow(std::string);
static void resizeWindow(std::string);
static void circleNext(std::string);
static void focusWindow(std::string);
static void setSubmap(std::string);
static void pass(std::string);
static void layoutmsg(std::string);
static void toggleOpaque(std::string);
static void dpms(std::string);
static void swapnext(std::string);
static void swapActiveWorkspaces(std::string);
static void pinActive(std::string);
static void mouse(std::string);
static void bringActiveToTop(std::string);
static void alterZOrder(std::string);
2023-02-21 13:13:35 +01:00
static void lockGroups(std::string);
static void lockActiveGroup(std::string);
2023-02-26 14:52:11 +01:00
static void moveIntoGroup(std::string);
2023-02-26 14:55:35 +01:00
static void moveOutOfGroup(std::string);
2023-07-13 17:55:20 +02:00
static void moveGroupWindow(std::string);
static void moveWindowOrGroup(std::string);
static void setIgnoreGroupLock(std::string);
static void denyWindowFromGroup(std::string);
static void global(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 14:50:16 +01:00
friend class CConfigManager;
friend class CWorkspace;
2022-03-19 17:48:18 +01:00
};
inline std::unique_ptr<CKeybindManager> g_pKeybindManager;