mirror of
https://github.com/hyprwm/Hypr.git
synced 2024-11-26 06:45:58 +01:00
Better mod parsing
This commit is contained in:
parent
efcb0f1a9e
commit
b897a1b64e
7 changed files with 21 additions and 47 deletions
|
@ -50,25 +50,16 @@ uint32_t KeybindManager::getKeyCodeFromName(std::string name) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
unsigned int KeybindManager::modToMask(MODS mod) {
|
||||
switch(mod) {
|
||||
case MOD_NONE:
|
||||
return 0;
|
||||
case MOD_SUPER:
|
||||
return XCB_MOD_MASK_4;
|
||||
case MOD_SHIFT:
|
||||
return XCB_MOD_MASK_SHIFT;
|
||||
case MOD_SHIFTSUPER:
|
||||
return XCB_MOD_MASK_4 | XCB_MOD_MASK_SHIFT;
|
||||
case MOD_SHIFTCTRL:
|
||||
return XCB_MOD_MASK_SHIFT | XCB_MOD_MASK_CONTROL;
|
||||
case MOD_CTRL:
|
||||
return XCB_MOD_MASK_CONTROL;
|
||||
case MOD_CTRLSUPER:
|
||||
return XCB_MOD_MASK_CONTROL | XCB_MOD_MASK_4;
|
||||
}
|
||||
unsigned int KeybindManager::modToMask(std::string mod) {
|
||||
|
||||
return 0;
|
||||
unsigned int sum = 0;
|
||||
|
||||
if (CONTAINS(mod, "SUPER") || CONTAINS(mod, "MOD4")) sum |= XCB_MOD_MASK_4;
|
||||
if (CONTAINS(mod, "SHIFT")) sum |= XCB_MOD_MASK_SHIFT;
|
||||
if (CONTAINS(mod, "CTRL")) sum |= XCB_MOD_MASK_CONTROL;
|
||||
if (CONTAINS(mod, "ALT") || CONTAINS(mod, "MOD1")) sum |= XCB_MOD_MASK_1;
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
xcb_keysym_t KeybindManager::getKeysymFromKeycode(xcb_keycode_t keycode) {
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
namespace KeybindManager {
|
||||
inline std::vector<Keybind> keybinds;
|
||||
|
||||
unsigned int modToMask(MODS);
|
||||
unsigned int modToMask(std::string);
|
||||
|
||||
Keybind* findKeybindByKey(int mod, xcb_keysym_t keysym);
|
||||
xcb_keysym_t getKeysymFromKeycode(xcb_keycode_t keycode);
|
||||
|
|
|
@ -97,15 +97,6 @@ void handleBind(const std::string& command, const std::string& value) {
|
|||
|
||||
const auto COMMAND = valueCopy;
|
||||
|
||||
MODS mod = MOD_NONE;
|
||||
|
||||
if (MOD == "SUPER") mod = MOD_SUPER;
|
||||
else if (MOD == "SHIFT") mod = MOD_SHIFT;
|
||||
else if (MOD == "SUPERSHIFT" || MOD == "SHIFTSUPER") mod = MOD_SHIFTSUPER;
|
||||
else if (MOD == "SUPERCTRL" || MOD == "CTRLSUPER") mod = MOD_CTRLSUPER;
|
||||
else if (MOD == "CTRL") mod = MOD_CTRL;
|
||||
else if (MOD == "CTRLSHIFT" || MOD == "SHIFTCTRL") mod = MOD_SHIFTCTRL;
|
||||
|
||||
Dispatcher dispatcher = nullptr;
|
||||
if (HANDLER == "exec") dispatcher = KeybindManager::call;
|
||||
if (HANDLER == "killactive") dispatcher = KeybindManager::killactive;
|
||||
|
@ -117,7 +108,7 @@ void handleBind(const std::string& command, const std::string& value) {
|
|||
if (HANDLER == "togglefloating") dispatcher = KeybindManager::toggleActiveWindowFloating;
|
||||
|
||||
if (dispatcher)
|
||||
KeybindManager::keybinds.push_back(Keybind(mod, KEY, COMMAND, dispatcher));
|
||||
KeybindManager::keybinds.push_back(Keybind(KeybindManager::modToMask(MOD), KEY, COMMAND, dispatcher));
|
||||
}
|
||||
|
||||
void handleRawExec(const std::string& command, const std::string& args) {
|
||||
|
@ -359,7 +350,7 @@ void ConfigManager::applyKeybindsToX() {
|
|||
|
||||
for (auto& keybind : KeybindManager::keybinds) {
|
||||
xcb_grab_key(g_pWindowManager->DisplayConnection, 1, g_pWindowManager->Screen->root,
|
||||
KeybindManager::modToMask(keybind.getMod()), KeybindManager::getKeycodeFromKeysym(keybind.getKeysym()),
|
||||
keybind.getMod(), KeybindManager::getKeycodeFromKeysym(keybind.getKeysym()),
|
||||
XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);
|
||||
}
|
||||
|
||||
|
@ -369,12 +360,12 @@ void ConfigManager::applyKeybindsToX() {
|
|||
xcb_grab_button(g_pWindowManager->DisplayConnection, 0,
|
||||
g_pWindowManager->Screen->root, XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE,
|
||||
XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC, g_pWindowManager->Screen->root, XCB_NONE,
|
||||
1, KeybindManager::modToMask(MOD_SUPER));
|
||||
1, KeybindManager::modToMask("SUPER"));
|
||||
|
||||
xcb_grab_button(g_pWindowManager->DisplayConnection, 0,
|
||||
g_pWindowManager->Screen->root, XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE,
|
||||
XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC, g_pWindowManager->Screen->root, XCB_NONE,
|
||||
3, KeybindManager::modToMask(MOD_SUPER));
|
||||
3, KeybindManager::modToMask("SUPER"));
|
||||
|
||||
xcb_flush(g_pWindowManager->DisplayConnection);
|
||||
}
|
||||
|
|
|
@ -78,3 +78,5 @@
|
|||
#define RED(c) ((double)(((c) >> 16) & 0xff) / 255.0)
|
||||
#define GREEN(c) ((double)(((c) >> 8) & 0xff) / 255.0)
|
||||
#define BLUE(c) ((double)(((c)) & 0xff) / 255.0)
|
||||
|
||||
#define CONTAINS(s, f) s.find(f) != std::string::npos
|
|
@ -394,7 +394,7 @@ void Events::eventKeyPress(xcb_generic_event_t* event) {
|
|||
const auto KEYSYM = KeybindManager::getKeysymFromKeycode(E->detail);
|
||||
|
||||
for (auto& keybind : KeybindManager::keybinds) {
|
||||
if (keybind.getKeysym() != 0 && keybind.getKeysym() == KEYSYM && KeybindManager::modToMask(keybind.getMod()) == E->state) {
|
||||
if (keybind.getKeysym() != 0 && keybind.getKeysym() == KEYSYM && keybind.getMod() == E->state) {
|
||||
keybind.getDispatcher()(keybind.getCommand());
|
||||
return;
|
||||
// TODO: fix duplicating keybinds
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "Keybind.hpp"
|
||||
|
||||
Keybind::Keybind(MODS mod, xcb_keysym_t keysym, std::string comm, Dispatcher disp) {
|
||||
Keybind::Keybind(unsigned int mod, xcb_keysym_t keysym, std::string comm, Dispatcher disp) {
|
||||
this->m_iMod = mod;
|
||||
this->m_Keysym = keysym;
|
||||
this->m_szCommand = comm;
|
||||
|
|
|
@ -3,22 +3,12 @@
|
|||
|
||||
typedef void (*Dispatcher)(std::string);
|
||||
|
||||
enum MODS {
|
||||
MOD_NONE = 0,
|
||||
MOD_SUPER,
|
||||
MOD_SHIFT,
|
||||
MOD_SHIFTSUPER,
|
||||
MOD_SHIFTCTRL,
|
||||
MOD_CTRL,
|
||||
MOD_CTRLSUPER
|
||||
};
|
||||
|
||||
class Keybind {
|
||||
public:
|
||||
Keybind(MODS, xcb_keysym_t, std::string, Dispatcher);
|
||||
Keybind(unsigned int, xcb_keysym_t, std::string, Dispatcher);
|
||||
~Keybind();
|
||||
|
||||
EXPOSED_MEMBER(Mod, MODS, i);
|
||||
EXPOSED_MEMBER(Mod, unsigned int, i);
|
||||
EXPOSED_MEMBER(Keysym, xcb_keysym_t,);
|
||||
EXPOSED_MEMBER(Command, std::string, sz);
|
||||
EXPOSED_MEMBER(Dispatcher, Dispatcher, p);
|
||||
|
|
Loading…
Reference in a new issue