diff options
| author | vaxerski <43317083+vaxerski@users.noreply.github.com> | 2022-03-19 17:48:18 +0100 |
|---|---|---|
| committer | vaxerski <43317083+vaxerski@users.noreply.github.com> | 2022-03-19 17:48:18 +0100 |
| commit | f9a4e9aecd2f38d0f82f24ac2dd4a1f9d4d84045 (patch) | |
| tree | bfc784c918da55993f7635172aa7ce83348fa5f8 /src/managers/KeybindManager.cpp | |
| parent | dba7bbdcf35a123e6106b420d9cc6064528080e0 (diff) | |
basic keybinds
Diffstat (limited to 'src/managers/KeybindManager.cpp')
| -rw-r--r-- | src/managers/KeybindManager.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp new file mode 100644 index 00000000..f61f6ac9 --- /dev/null +++ b/src/managers/KeybindManager.cpp @@ -0,0 +1,62 @@ +#include "KeybindManager.hpp" + +void CKeybindManager::addKeybind(SKeybind kb) { + m_dKeybinds.push_back(kb); +} + +uint32_t CKeybindManager::stringToModMask(std::string mods) { + uint32_t modMask = 0; + if (mods.find("SHIFT") != std::string::npos) + modMask |= WLR_MODIFIER_SHIFT; + if (mods.find("CAPS") != std::string::npos) + modMask |= WLR_MODIFIER_CAPS; + if (mods.find("CTRL") != std::string::npos || mods.find("CONTROL") != std::string::npos) + modMask |= WLR_MODIFIER_CTRL; + if (mods.find("ALT") != std::string::npos) + modMask |= WLR_MODIFIER_ALT; + if (mods.find("MOD2") != std::string::npos) + modMask |= WLR_MODIFIER_MOD2; + if (mods.find("MOD3") != std::string::npos) + modMask |= WLR_MODIFIER_MOD3; + if (mods.find("SUPER") != std::string::npos || mods.find("WIN") != std::string::npos || mods.find("LOGO") != std::string::npos || mods.find("MOD4") != std::string::npos) + modMask |= WLR_MODIFIER_LOGO; + if (mods.find("MOD5") != std::string::npos) + modMask |= WLR_MODIFIER_MOD5; + + return modMask; +} + +void CKeybindManager::handleKeybinds(const uint32_t& modmask, const xkb_keysym_t& key) { + for (auto& k : m_dKeybinds) { + if (modmask != k.modmask) + continue; + + // oMg such performance hit!!11! + // this little maneouver is gonna cost us 4µs + const auto KBKEY = xkb_keysym_from_name(k.key.c_str(), XKB_KEYSYM_CASE_INSENSITIVE); + + if (key != KBKEY) + continue; + + // yes. + if (k.handler == "exec") { spawn(k.arg); } + else if (k.handler == "killactive") { killActive(k.arg); } + } +} + +// Dispatchers + +void CKeybindManager::spawn(std::string args) { + args = "WAYLAND_DISPLAY=" + std::string(g_pCompositor->m_szWLDisplaySocket) + " DISPLAY=" + std::string(g_pXWaylandManager->m_sWLRXWayland->display_name) + " " + args; + Debug::log(LOG, "Executing %s", args.c_str()); + if (fork() == 0) { + execl("/bin/sh", "/bin/sh", "-c", args.c_str(), nullptr); + + _exit(0); + } +} + +void CKeybindManager::killActive(std::string args) { + if (g_pCompositor->m_pLastFocus && g_pCompositor->windowValidMapped(g_pCompositor->m_pLastFocus)) + g_pXWaylandManager->sendCloseWindow(g_pCompositor->m_pLastFocus); +}
\ No newline at end of file |
