basic keybinds
This commit is contained in:
parent
dba7bbdcf3
commit
f9a4e9aecd
7 changed files with 139 additions and 3 deletions
|
|
@ -136,14 +136,16 @@ void CInputManager::onKeyboardKey(wlr_event_keyboard_key* e, SKeyboard* pKeyboar
|
|||
wlr_idle_notify_activity(g_pCompositor->m_sWLRIdle, g_pCompositor->m_sWLRSeat);
|
||||
|
||||
if (e->state == WL_KEYBOARD_KEY_STATE_PRESSED) {
|
||||
// TODO: keybinds
|
||||
|
||||
for (int i = 0; i < syms; ++i)
|
||||
g_pKeybindManager->handleKeybinds(MODS, keysyms[i]);
|
||||
} else if (e->state == WL_KEYBOARD_KEY_STATE_RELEASED) {
|
||||
|
||||
// hee hee
|
||||
}
|
||||
|
||||
wlr_seat_set_keyboard(g_pCompositor->m_sWLRSeat, pKeyboard->keyboard);
|
||||
wlr_seat_keyboard_notify_key(g_pCompositor->m_sWLRSeat, e->time_msec, e->keycode, e->state);
|
||||
|
||||
g_pCompositor->focusWindow(g_pCompositor->vectorToWindowIdeal(g_pInputManager->getMouseCoordsInternal()));
|
||||
}
|
||||
|
||||
void CInputManager::onKeyboardMod(void* data, SKeyboard* pKeyboard) {
|
||||
|
|
|
|||
62
src/managers/KeybindManager.cpp
Normal file
62
src/managers/KeybindManager.cpp
Normal file
|
|
@ -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);
|
||||
}
|
||||
30
src/managers/KeybindManager.hpp
Normal file
30
src/managers/KeybindManager.hpp
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
#pragma once
|
||||
|
||||
#include "../defines.hpp"
|
||||
#include <deque>
|
||||
#include "../Compositor.hpp"
|
||||
|
||||
struct SKeybind {
|
||||
std::string key = 0;
|
||||
uint32_t modmask = 0;
|
||||
std::string handler = "";
|
||||
std::string arg = "";
|
||||
};
|
||||
|
||||
class CKeybindManager {
|
||||
public:
|
||||
void handleKeybinds(const uint32_t&, const xkb_keysym_t&);
|
||||
void addKeybind(SKeybind);
|
||||
uint32_t stringToModMask(std::string);
|
||||
|
||||
private:
|
||||
std::deque<SKeybind> m_dKeybinds;
|
||||
|
||||
|
||||
// -------------- Dispatchers -------------- //
|
||||
void killActive(std::string);
|
||||
void spawn(std::string);
|
||||
|
||||
};
|
||||
|
||||
inline std::unique_ptr<CKeybindManager> g_pKeybindManager;
|
||||
Loading…
Add table
Add a link
Reference in a new issue