diff --git a/example/hyprland.conf b/example/hyprland.conf index a42f0550..7c5918e7 100644 --- a/example/hyprland.conf +++ b/example/hyprland.conf @@ -102,3 +102,6 @@ bind=ALT,7,movetoworkspace,7 bind=ALT,8,movetoworkspace,8 bind=ALT,9,movetoworkspace,9 bind=ALT,0,movetoworkspace,10 + +bind=SUPER,mouse_down,workspace,e+1 +bind=SUPER,mouse_up,workspace,e-1 \ No newline at end of file diff --git a/src/config/defaultConfig.hpp b/src/config/defaultConfig.hpp index 1577e36a..1897d93d 100644 --- a/src/config/defaultConfig.hpp +++ b/src/config/defaultConfig.hpp @@ -111,4 +111,7 @@ bind=ALT,7,movetoworkspace,7 bind=ALT,8,movetoworkspace,8 bind=ALT,9,movetoworkspace,9 bind=ALT,0,movetoworkspace,10 + +bind=SUPER,mouse_down,workspace,e+1 +bind=SUPER,mouse_up,workspace,e-1 )#"; \ No newline at end of file diff --git a/src/events/Devices.cpp b/src/events/Devices.cpp index 53ac70dc..948e7aba 100644 --- a/src/events/Devices.cpp +++ b/src/events/Devices.cpp @@ -49,9 +49,7 @@ void Events::listener_mouseButton(wl_listener* listener, void* data) { } void Events::listener_mouseAxis(wl_listener* listener, void* data) { - const auto E = (wlr_pointer_axis_event*)data; - - wlr_seat_pointer_notify_axis(g_pCompositor->m_sSeat.seat, E->time_msec, E->orientation, E->delta, E->delta_discrete, E->source); + g_pInputManager->onMouseWheel((wlr_pointer_axis_event*)data); } void Events::listener_requestMouse(wl_listener* listener, void* data) { diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp index 8f8ee0f9..3fc6d20e 100644 --- a/src/helpers/MiscFunctions.cpp +++ b/src/helpers/MiscFunctions.cpp @@ -217,7 +217,9 @@ int getWorkspaceIDFromString(const std::string& in, std::string& outName) { } outName = WORKSPACENAME; } else { - if (in[0] == 'm') { + if (in[0] == 'm' || in[0] == 'e') { + bool onAllMonitors = in[0] == 'e'; + if (!g_pCompositor->m_pLastMonitor) { Debug::log(ERR, "Relative monitor workspace on monitor null!"); result = INT_MAX; @@ -258,7 +260,7 @@ int getWorkspaceIDFromString(const std::string& in, std::string& outName) { } if (const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(searchID); PWORKSPACE && PWORKSPACE->m_iID != SPECIAL_WORKSPACE_ID) { - if (PWORKSPACE->m_iMonitorID == g_pCompositor->m_pLastMonitor->ID) { + if (onAllMonitors || PWORKSPACE->m_iMonitorID == g_pCompositor->m_pLastMonitor->ID) { currentID = PWORKSPACE->m_iID; if (remains < 0) diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 74cecc45..3f723565 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -95,17 +95,17 @@ bool CKeybindManager::onKeyEvent(wlr_keyboard_key_event* e, SKeyboard* pKeyboard m_dPressedKeycodes.push_back(KEYCODE); m_dPressedKeysyms.push_back(keysym); - found = g_pKeybindManager->handleKeybinds(MODS, keysym, 0, true, e->time_msec) || found; + found = g_pKeybindManager->handleKeybinds(MODS, "", keysym, 0, true, e->time_msec) || found; - found = g_pKeybindManager->handleKeybinds(MODS, 0, KEYCODE, true, e->time_msec) || found; + found = g_pKeybindManager->handleKeybinds(MODS, "", 0, KEYCODE, true, e->time_msec) || found; } else if (e->state == WL_KEYBOARD_KEY_STATE_RELEASED) { m_dPressedKeycodes.erase(std::remove(m_dPressedKeycodes.begin(), m_dPressedKeycodes.end(), KEYCODE)); m_dPressedKeysyms.erase(std::remove(m_dPressedKeysyms.begin(), m_dPressedKeysyms.end(), keysym)); - found = g_pKeybindManager->handleKeybinds(MODS, keysym, 0, false, e->time_msec) || found; + found = g_pKeybindManager->handleKeybinds(MODS, "", keysym, 0, false, e->time_msec) || found; - found = g_pKeybindManager->handleKeybinds(MODS, 0, KEYCODE, false, e->time_msec) || found; + found = g_pKeybindManager->handleKeybinds(MODS, "", 0, KEYCODE, false, e->time_msec) || found; shadowKeybinds(); } @@ -113,10 +113,25 @@ bool CKeybindManager::onKeyEvent(wlr_keyboard_key_event* e, SKeyboard* pKeyboard return !found; } -bool CKeybindManager::handleKeybinds(const uint32_t& modmask, const xkb_keysym_t& key, const int& keycode, bool pressed, uint32_t time) { +bool CKeybindManager::onAxisEvent(wlr_pointer_axis_event* e) { + const auto MODS = g_pInputManager->accumulateModsFromAllKBs(); + + bool found = false; + if (e->source == WLR_AXIS_SOURCE_WHEEL && e->orientation == WLR_AXIS_ORIENTATION_VERTICAL) { + if (e->delta < 0) { + found = g_pKeybindManager->handleKeybinds(MODS, "mouse_down", 0, 0, true, 0); + } else { + found = g_pKeybindManager->handleKeybinds(MODS, "mouse_up", 0, 0, true, 0); + } + } + + return !found; +} + +bool CKeybindManager::handleKeybinds(const uint32_t& modmask, const std::string& key, const xkb_keysym_t& keysym, const int& keycode, bool pressed, uint32_t time) { bool found = false; - if (handleInternalKeybinds(key)) + if (handleInternalKeybinds(keysym)) return true; if (g_pCompositor->m_sSeat.exclusiveClient) @@ -132,12 +147,14 @@ bool CKeybindManager::handleKeybinds(const uint32_t& modmask, const xkb_keysym_t if (modmask != k.modmask || (g_pCompositor->m_sSeat.exclusiveClient && !k.locked) || k.submap != m_szCurrentSelectedSubmap || (!pressed && !k.release) || k.shadowed) continue; - if (k.keycode != -1) { + if (!key.empty()) { + if (key != k.key) + continue; + } else if (k.keycode != -1) { if (keycode != k.keycode) continue; - } else { - if (key == 0) + if (keysym == 0) continue; // this is a keycode check run // oMg such performance hit!!11! @@ -146,13 +163,13 @@ bool CKeybindManager::handleKeybinds(const uint32_t& modmask, const xkb_keysym_t const auto KBKEYUPPER = xkb_keysym_to_upper(KBKEY); // small TODO: fix 0-9 keys and other modified ones with shift - if (key != KBKEY && key != KBKEYUPPER) + if (keysym != KBKEY && keysym != KBKEYUPPER) continue; } if (pressed && k.release) { // suppress down event - m_kHeldBack = key; + m_kHeldBack = keysym; return true; } @@ -163,7 +180,7 @@ bool CKeybindManager::handleKeybinds(const uint32_t& modmask, const xkb_keysym_t Debug::log(ERR, "Inavlid handler in a keybind! (handler %s does not exist)", k.handler.c_str()); } else { // call the dispatcher - Debug::log(LOG, "Keybind triggered, calling dispatcher (%d, %d)", modmask, key); + Debug::log(LOG, "Keybind triggered, calling dispatcher (%d, %s, %d)", modmask, key, keysym); DISPATCHER->second(k.arg); } diff --git a/src/managers/KeybindManager.hpp b/src/managers/KeybindManager.hpp index 62568fc0..4fa314a9 100644 --- a/src/managers/KeybindManager.hpp +++ b/src/managers/KeybindManager.hpp @@ -25,6 +25,7 @@ public: CKeybindManager(); bool onKeyEvent(wlr_keyboard_key_event*, SKeyboard*); + bool onAxisEvent(wlr_pointer_axis_event*); void addKeybind(SKeybind); void removeKeybind(uint32_t, const std::string&); @@ -42,7 +43,7 @@ private: xkb_keysym_t m_kHeldBack = 0; - bool handleKeybinds(const uint32_t&, const xkb_keysym_t&, const int&, bool, uint32_t); + bool handleKeybinds(const uint32_t&, const std::string&, const xkb_keysym_t&, const int&, bool, uint32_t); void shadowKeybinds(); diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index c922421c..e1f2e98f 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -381,6 +381,16 @@ void CInputManager::processMouseDownKill(wlr_pointer_button_event* e) { m_ecbClickBehavior = CLICKMODE_DEFAULT; } +void CInputManager::onMouseWheel(wlr_pointer_axis_event* e) { + bool passEvent = g_pKeybindManager->onAxisEvent(e); + + wlr_idle_notify_activity(g_pCompositor->m_sWLRIdle, g_pCompositor->m_sSeat.seat); + + if (passEvent) { + wlr_seat_pointer_notify_axis(g_pCompositor->m_sSeat.seat, e->time_msec, e->orientation, e->delta, e->delta_discrete, e->source); + } +} + Vector2D CInputManager::getMouseCoordsInternal() { return Vector2D(g_pCompositor->m_sWLRCursor->x, g_pCompositor->m_sWLRCursor->y); } diff --git a/src/managers/input/InputManager.hpp b/src/managers/input/InputManager.hpp index 107d891f..da821dfc 100644 --- a/src/managers/input/InputManager.hpp +++ b/src/managers/input/InputManager.hpp @@ -17,6 +17,7 @@ public: void onMouseMoved(wlr_pointer_motion_event*); void onMouseWarp(wlr_pointer_motion_absolute_event*); void onMouseButton(wlr_pointer_button_event*); + void onMouseWheel(wlr_pointer_axis_event*); void onKeyboardKey(wlr_keyboard_key_event*, SKeyboard*); void onKeyboardMod(void*, SKeyboard*);