From 8f62f6d4b0dbf18f1857e13831638a7d3615aeee Mon Sep 17 00:00:00 2001 From: Darksome Date: Mon, 20 Jun 2022 22:47:28 +0300 Subject: [PATCH 01/13] Add workspace switching with mouse wheel --- src/events/Devices.cpp | 5 ++--- src/managers/input/InputManager.cpp | 18 ++++++++++++++++++ src/managers/input/InputManager.hpp | 1 + 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/events/Devices.cpp b/src/events/Devices.cpp index 7a47df77..09f7d2ab 100644 --- a/src/events/Devices.cpp +++ b/src/events/Devices.cpp @@ -49,9 +49,8 @@ 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/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index 003535f7..fefc4047 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -230,6 +230,24 @@ void CInputManager::onMouseButton(wlr_pointer_button_event* e) { } +void CInputManager::onMouseWheel(wlr_pointer_axis_event* e) { + const auto PKEYBOARD = wlr_seat_get_keyboard(g_pCompositor->m_sSeat.seat); + + if (wlr_keyboard_get_modifiers(PKEYBOARD) == (uint32_t)g_pConfigManager->getInt("general:main_mod_internal") && + e->source == WLR_AXIS_SOURCE_WHEEL && e->orientation == WLR_AXIS_ORIENTATION_VERTICAL) { + + if (e->delta > 0) { + g_pKeybindManager->m_mDispatchers["workspace"]("-1"); + } else { + g_pKeybindManager->m_mDispatchers["workspace"]("+1"); + } + + return; + } + + 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 18d9857e..7a3601bc 100644 --- a/src/managers/input/InputManager.hpp +++ b/src/managers/input/InputManager.hpp @@ -11,6 +11,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*); From 776ca3baf269059e8c13ba8b625645215e71f78c Mon Sep 17 00:00:00 2001 From: Darksome Date: Fri, 24 Jun 2022 18:57:14 +0300 Subject: [PATCH 02/13] Change workspace wheel scrolling direction --- src/managers/input/InputManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index fefc4047..826354f1 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -236,7 +236,7 @@ void CInputManager::onMouseWheel(wlr_pointer_axis_event* e) { if (wlr_keyboard_get_modifiers(PKEYBOARD) == (uint32_t)g_pConfigManager->getInt("general:main_mod_internal") && e->source == WLR_AXIS_SOURCE_WHEEL && e->orientation == WLR_AXIS_ORIENTATION_VERTICAL) { - if (e->delta > 0) { + if (e->delta < 0) { g_pKeybindManager->m_mDispatchers["workspace"]("-1"); } else { g_pKeybindManager->m_mDispatchers["workspace"]("+1"); From fc4b10d13c14c4eb08febb0637f27177cb6a1940 Mon Sep 17 00:00:00 2001 From: xDarksome Date: Sun, 26 Jun 2022 19:28:30 +0300 Subject: [PATCH 03/13] Remove empty line --- src/events/Devices.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/events/Devices.cpp b/src/events/Devices.cpp index c2e6b39a..d8b1ff89 100644 --- a/src/events/Devices.cpp +++ b/src/events/Devices.cpp @@ -50,7 +50,6 @@ void Events::listener_mouseButton(wl_listener* listener, void* data) { void Events::listener_mouseAxis(wl_listener* listener, void* data) { g_pInputManager->onMouseWheel((wlr_pointer_axis_event*)data); - } void Events::listener_requestMouse(wl_listener* listener, void* data) { @@ -167,4 +166,4 @@ void Events::listener_destroyMouse(void* owner, void* data) { const auto PMOUSE = (SMouse*)owner; g_pInputManager->destroyMouse(PMOUSE->mouse); -} \ No newline at end of file +} From cb8a6f881b11e9a269fd5f7aa64eafe2beda0b0d Mon Sep 17 00:00:00 2001 From: Darksome Date: Sat, 2 Jul 2022 19:55:35 +0300 Subject: [PATCH 04/13] Disallow scrolling into empty workspaces --- src/managers/input/InputManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index 94d4b8c8..92a06a4c 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -360,7 +360,7 @@ void CInputManager::onMouseWheel(wlr_pointer_axis_event* e) { if (e->delta < 0) { g_pKeybindManager->m_mDispatchers["workspace"]("-1"); } else { - g_pKeybindManager->m_mDispatchers["workspace"]("+1"); + g_pKeybindManager->m_mDispatchers["workspace"]("m+1"); } return; From 1eceae811f54a87c3c7de1d10202842db78c3f69 Mon Sep 17 00:00:00 2001 From: Darksome Date: Fri, 15 Jul 2022 21:54:05 +0300 Subject: [PATCH 05/13] Try mouse wheel configuration --- example/hyprland.conf | 3 +++ src/config/defaultConfig.hpp | 3 +++ src/managers/KeybindManager.cpp | 17 +++++++++-------- src/managers/KeybindManager.hpp | 2 +- src/managers/input/InputManager.cpp | 25 +++++++++++++------------ 5 files changed, 29 insertions(+), 21 deletions(-) diff --git a/example/hyprland.conf b/example/hyprland.conf index a42f0550..a776559a 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,+1 +bind=SUPER,mouse_up,workspace,-1 \ No newline at end of file diff --git a/src/config/defaultConfig.hpp b/src/config/defaultConfig.hpp index 1577e36a..15dbbe16 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,+1 +bind=SUPER,mouse_up,workspace,-1 )#"; \ No newline at end of file diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 60e4cdd6..4e00818e 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -82,10 +82,10 @@ uint32_t CKeybindManager::stringToModMask(std::string mods) { return modMask; } -bool CKeybindManager::handleKeybinds(const uint32_t& modmask, const xkb_keysym_t& key, const int& keycode) { +bool CKeybindManager::handleKeybinds(const uint32_t& modmask, const std::string& key, const xkb_keysym_t& keysym, const int& keycode) { bool found = false; - if (handleInternalKeybinds(key)) + if (handleInternalKeybinds(keysym)) return true; if (g_pCompositor->m_sSeat.exclusiveClient) @@ -95,13 +95,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) 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! @@ -110,7 +111,7 @@ 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; } @@ -121,7 +122,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)", modmask, key); DISPATCHER->second(k.arg); } diff --git a/src/managers/KeybindManager.hpp b/src/managers/KeybindManager.hpp index 08a1cba3..049568a6 100644 --- a/src/managers/KeybindManager.hpp +++ b/src/managers/KeybindManager.hpp @@ -20,7 +20,7 @@ class CKeybindManager { public: CKeybindManager(); - bool handleKeybinds(const uint32_t&, const xkb_keysym_t&, const int&); + bool handleKeybinds(const uint32_t&, const std::string&, const xkb_keysym_t&, const int&); void addKeybind(SKeybind); void removeKeybind(uint32_t, const std::string&); uint32_t stringToModMask(std::string); diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index 5f1b1a3a..55890abc 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -376,21 +376,20 @@ void CInputManager::processMouseDownKill(wlr_pointer_button_event* e) { } void CInputManager::onMouseWheel(wlr_pointer_axis_event* e) { - const auto PKEYBOARD = wlr_seat_get_keyboard(g_pCompositor->m_sSeat.seat); + const auto MODS = accumulateModsFromAllKBs(); - if (wlr_keyboard_get_modifiers(PKEYBOARD) == (uint32_t)g_pConfigManager->getInt("general:main_mod_internal") && - e->source == WLR_AXIS_SOURCE_WHEEL && e->orientation == WLR_AXIS_ORIENTATION_VERTICAL) { - + bool found = false; + if (e->source == WLR_AXIS_SOURCE_WHEEL && e->orientation == WLR_AXIS_ORIENTATION_VERTICAL) { if (e->delta < 0) { - g_pKeybindManager->m_mDispatchers["workspace"]("-1"); + found = g_pKeybindManager->handleKeybinds(MODS, "mouse_down", 0, 0); } else { - g_pKeybindManager->m_mDispatchers["workspace"]("m+1"); + found = g_pKeybindManager->handleKeybinds(MODS, "mouse_up", 0, 0); } - - return; } - wlr_seat_pointer_notify_axis(g_pCompositor->m_sSeat.seat, e->time_msec, e->orientation, e->delta, e->delta_discrete, e->source); + if (!found) { + 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() { @@ -631,10 +630,12 @@ void CInputManager::onKeyboardKey(wlr_keyboard_key_event* e, SKeyboard* pKeyboar bool found = false; if (e->state == WL_KEYBOARD_KEY_STATE_PRESSED) { - for (int i = 0; i < syms; ++i) - found = g_pKeybindManager->handleKeybinds(MODS, keysyms[i], 0) || found; + static const std::string empty = ""; - found = g_pKeybindManager->handleKeybinds(MODS, 0, KEYCODE) || found; + for (int i = 0; i < syms; ++i) + found = g_pKeybindManager->handleKeybinds(MODS, empty, keysyms[i], 0) || found; + + found = g_pKeybindManager->handleKeybinds(MODS, empty, 0, KEYCODE) || found; } else if (e->state == WL_KEYBOARD_KEY_STATE_RELEASED) { // hee hee } From 16fecac2d1efa5f92c22bfc5ad0654febdec1017 Mon Sep 17 00:00:00 2001 From: xDarksome Date: Fri, 15 Jul 2022 18:55:08 +0000 Subject: [PATCH 06/13] [gha] bump flake inputs --- flake.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/flake.lock b/flake.lock index ca1c9328..81081ac0 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1657447684, - "narHash": "sha256-FCP9AuU1q6PE3vOeM5SFf58f/UKPBAsoSGDUGamNBbo=", + "lastModified": 1657802959, + "narHash": "sha256-9+JWARSdlL8KiH3ymnKDXltE1vM+/WEJ78F5B1kjXys=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "5f43d8b088d3771274bcfb69d3c7435b1121ac88", + "rev": "4a01ca36d6bfc133bc617e661916a81327c9bbc8", "type": "github" }, "original": { @@ -26,11 +26,11 @@ "flake": false, "locked": { "host": "gitlab.freedesktop.org", - "lastModified": 1656865312, - "narHash": "sha256-xtQ0zwJZwN8sciruveM10CzKz6TWxBY8SyXa8E4jly4=", + "lastModified": 1654618691, + "narHash": "sha256-8y3u8CoigjoZOVbA2wCWBHlDNEakv0AVxU46/cOC00s=", "owner": "wlroots", "repo": "wlroots", - "rev": "5dc1d4671dd2ca3c1f0f09587c463fdbb542f0a4", + "rev": "b89ed9015c3fbe8d339e9d65cf70fdca6e5645bc", "type": "gitlab" }, "original": { From 43b7da0bb1bde522c890eba513c8b4b546c3a328 Mon Sep 17 00:00:00 2001 From: Darksome Date: Sat, 16 Jul 2022 12:30:07 +0300 Subject: [PATCH 07/13] Rollback flake.lock --- flake.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/flake.lock b/flake.lock index 81081ac0..ca1c9328 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1657802959, - "narHash": "sha256-9+JWARSdlL8KiH3ymnKDXltE1vM+/WEJ78F5B1kjXys=", + "lastModified": 1657447684, + "narHash": "sha256-FCP9AuU1q6PE3vOeM5SFf58f/UKPBAsoSGDUGamNBbo=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "4a01ca36d6bfc133bc617e661916a81327c9bbc8", + "rev": "5f43d8b088d3771274bcfb69d3c7435b1121ac88", "type": "github" }, "original": { @@ -26,11 +26,11 @@ "flake": false, "locked": { "host": "gitlab.freedesktop.org", - "lastModified": 1654618691, - "narHash": "sha256-8y3u8CoigjoZOVbA2wCWBHlDNEakv0AVxU46/cOC00s=", + "lastModified": 1656865312, + "narHash": "sha256-xtQ0zwJZwN8sciruveM10CzKz6TWxBY8SyXa8E4jly4=", "owner": "wlroots", "repo": "wlroots", - "rev": "b89ed9015c3fbe8d339e9d65cf70fdca6e5645bc", + "rev": "5dc1d4671dd2ca3c1f0f09587c463fdbb542f0a4", "type": "gitlab" }, "original": { From fdbc54d97b745e7e11e3c114bc9763f68e8dfbfd Mon Sep 17 00:00:00 2001 From: Darksome Date: Sat, 16 Jul 2022 12:44:12 +0300 Subject: [PATCH 08/13] Restore events/Devices.cpp formatting --- src/events/Devices.cpp | 258 +++++++++++++++++++---------------------- 1 file changed, 122 insertions(+), 136 deletions(-) diff --git a/src/events/Devices.cpp b/src/events/Devices.cpp index 349ffe61..5660772c 100644 --- a/src/events/Devices.cpp +++ b/src/events/Devices.cpp @@ -15,179 +15,165 @@ // // // ---------------------------------------------------- // -void Events::listener_keyboardDestroy(void *owner, void *data) { - SKeyboard *PKEYBOARD = (SKeyboard *)owner; - g_pInputManager->destroyKeyboard(PKEYBOARD); +void Events::listener_keyboardDestroy(void* owner, void* data) { + SKeyboard* PKEYBOARD = (SKeyboard*)owner; + g_pInputManager->destroyKeyboard(PKEYBOARD); - Debug::log(LOG, "Destroyed keyboard %x", PKEYBOARD); + Debug::log(LOG, "Destroyed keyboard %x", PKEYBOARD); } -void Events::listener_keyboardKey(void *owner, void *data) { - SKeyboard *PKEYBOARD = (SKeyboard *)owner; - g_pInputManager->onKeyboardKey((wlr_keyboard_key_event *)data, PKEYBOARD); +void Events::listener_keyboardKey(void* owner, void* data) { + SKeyboard* PKEYBOARD = (SKeyboard*)owner; + g_pInputManager->onKeyboardKey((wlr_keyboard_key_event*)data, PKEYBOARD); } -void Events::listener_keyboardMod(void *owner, void *data) { - SKeyboard *PKEYBOARD = (SKeyboard *)owner; - g_pInputManager->onKeyboardMod(data, PKEYBOARD); +void Events::listener_keyboardMod(void* owner, void* data) { + SKeyboard* PKEYBOARD = (SKeyboard*)owner; + g_pInputManager->onKeyboardMod(data, PKEYBOARD); } -void Events::listener_mouseFrame(wl_listener *listener, void *data) { - wlr_seat_pointer_notify_frame(g_pCompositor->m_sSeat.seat); +void Events::listener_mouseFrame(wl_listener* listener, void* data) { + wlr_seat_pointer_notify_frame(g_pCompositor->m_sSeat.seat); } -void Events::listener_mouseMove(wl_listener *listener, void *data) { - g_pInputManager->onMouseMoved((wlr_pointer_motion_event *)data); +void Events::listener_mouseMove(wl_listener* listener, void* data) { + g_pInputManager->onMouseMoved((wlr_pointer_motion_event*)data); } -void Events::listener_mouseMoveAbsolute(wl_listener *listener, void *data) { - g_pInputManager->onMouseWarp((wlr_pointer_motion_absolute_event *)data); +void Events::listener_mouseMoveAbsolute(wl_listener* listener, void* data) { + g_pInputManager->onMouseWarp((wlr_pointer_motion_absolute_event*)data); } -void Events::listener_mouseButton(wl_listener *listener, void *data) { - g_pInputManager->onMouseButton((wlr_pointer_button_event *)data); +void Events::listener_mouseButton(wl_listener* listener, void* data) { + g_pInputManager->onMouseButton((wlr_pointer_button_event*)data); } -void Events::listener_mouseAxis(wl_listener *listener, void *data) { - g_pInputManager->onMouseWheel((wlr_pointer_axis_event *)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); } -void Events::listener_requestMouse(wl_listener *listener, void *data) { - const auto EVENT = (wlr_seat_pointer_request_set_cursor_event *)data; +void Events::listener_requestMouse(wl_listener* listener, void* data) { + const auto EVENT = (wlr_seat_pointer_request_set_cursor_event*)data; - g_pInputManager->processMouseRequest(EVENT); + g_pInputManager->processMouseRequest(EVENT); } -void Events::listener_newInput(wl_listener *listener, void *data) { - const auto DEVICE = (wlr_input_device *)data; +void Events::listener_newInput(wl_listener* listener, void* data) { + const auto DEVICE = (wlr_input_device*)data; - switch (DEVICE->type) { - case WLR_INPUT_DEVICE_KEYBOARD: - Debug::log(LOG, "Attached a keyboard with name %s", DEVICE->name); - g_pInputManager->newKeyboard(DEVICE); - break; - case WLR_INPUT_DEVICE_POINTER: - Debug::log(LOG, "Attached a mouse with name %s", DEVICE->name); - g_pInputManager->newMouse(DEVICE); - break; - case WLR_INPUT_DEVICE_TOUCH: - Debug::log(LOG, "Attached a touch device with name %s", DEVICE->name); - Debug::log(WARN, "!!!! Hyprland does not directly support touchscreens, " - "bugs may occur !!!!"); - wlr_cursor_attach_input_device(g_pCompositor->m_sWLRCursor, DEVICE); - break; - case WLR_INPUT_DEVICE_TABLET_TOOL: - Debug::log(LOG, "Attached a tablet tool with name %s", DEVICE->name); - g_pInputManager->newTabletTool(DEVICE); - break; - case WLR_INPUT_DEVICE_TABLET_PAD: - Debug::log(LOG, "Attached a tablet pad with name %s", DEVICE->name); - g_pInputManager->newTabletPad(DEVICE); - break; - default: - Debug::log(WARN, "Unrecognized input device plugged in: %s", DEVICE->name); - break; - } - - g_pInputManager->updateCapabilities(DEVICE); -} - -void Events::listener_newConstraint(wl_listener *listener, void *data) { - const auto PCONSTRAINT = (wlr_pointer_constraint_v1 *)data; - - Debug::log(LOG, "New mouse constraint at %x", PCONSTRAINT); - - g_pInputManager->m_lConstraints.emplace_back(); - const auto CONSTRAINT = &g_pInputManager->m_lConstraints.back(); - - CONSTRAINT->pMouse = g_pCompositor->m_sSeat.mouse; - CONSTRAINT->constraint = PCONSTRAINT; - - CONSTRAINT->hyprListener_destroyConstraint.initCallback( - &PCONSTRAINT->events.destroy, &Events::listener_destroyConstraint, - CONSTRAINT, "Constraint"); - CONSTRAINT->hyprListener_setConstraintRegion.initCallback( - &PCONSTRAINT->events.set_region, &Events::listener_setConstraintRegion, - CONSTRAINT, "Constraint"); - - if (g_pCompositor->m_pLastFocus == PCONSTRAINT->surface) { - g_pInputManager->constrainMouse(CONSTRAINT->pMouse, PCONSTRAINT); - } -} - -void Events::listener_destroyConstraint(void *owner, void *data) { - const auto PCONSTRAINT = (SConstraint *)owner; - - if (PCONSTRAINT->pMouse->currentConstraint == PCONSTRAINT->constraint) { - PCONSTRAINT->pMouse->hyprListener_commitConstraint.removeCallback(); - - const auto PWINDOW = - g_pCompositor->getConstraintWindow(g_pCompositor->m_sSeat.mouse); - - if (PWINDOW) { - if (PWINDOW->m_bIsX11) { - wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, - PCONSTRAINT->constraint->current.cursor_hint.x + - PWINDOW->m_uSurface.xwayland->x, - PWINDOW->m_uSurface.xwayland->y + - PCONSTRAINT->constraint->current.cursor_hint.y); - - wlr_seat_pointer_warp(PCONSTRAINT->constraint->seat, - PCONSTRAINT->constraint->current.cursor_hint.x, - PCONSTRAINT->constraint->current.cursor_hint.y); - } else { - wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, - PCONSTRAINT->constraint->current.cursor_hint.x + - PWINDOW->m_vRealPosition.vec().x, - PCONSTRAINT->constraint->current.cursor_hint.y + - PWINDOW->m_vRealPosition.vec().y); - - wlr_seat_pointer_warp(PCONSTRAINT->constraint->seat, - PCONSTRAINT->constraint->current.cursor_hint.x, - PCONSTRAINT->constraint->current.cursor_hint.y); - } + switch(DEVICE->type) { + case WLR_INPUT_DEVICE_KEYBOARD: + Debug::log(LOG, "Attached a keyboard with name %s", DEVICE->name); + g_pInputManager->newKeyboard(DEVICE); + break; + case WLR_INPUT_DEVICE_POINTER: + Debug::log(LOG, "Attached a mouse with name %s", DEVICE->name); + g_pInputManager->newMouse(DEVICE); + break; + case WLR_INPUT_DEVICE_TOUCH: + Debug::log(LOG, "Attached a touch device with name %s", DEVICE->name); + Debug::log(WARN, "!!!! Hyprland does not directly support touchscreens, bugs may occur !!!!"); + wlr_cursor_attach_input_device(g_pCompositor->m_sWLRCursor, DEVICE); + break; + case WLR_INPUT_DEVICE_TABLET_TOOL: + Debug::log(LOG, "Attached a tablet tool with name %s", DEVICE->name); + g_pInputManager->newTabletTool(DEVICE); + break; + case WLR_INPUT_DEVICE_TABLET_PAD: + Debug::log(LOG, "Attached a tablet pad with name %s", DEVICE->name); + g_pInputManager->newTabletPad(DEVICE); + break; + default: + Debug::log(WARN, "Unrecognized input device plugged in: %s", DEVICE->name); + break; } - PCONSTRAINT->pMouse->currentConstraint = nullptr; - } - - Debug::log(LOG, "Unconstrained mouse from %x", PCONSTRAINT->constraint); - - g_pInputManager->m_lConstraints.remove(*PCONSTRAINT); + g_pInputManager->updateCapabilities(DEVICE); } -void Events::listener_setConstraintRegion(void *owner, void *data) { - // no +void Events::listener_newConstraint(wl_listener* listener, void* data) { + const auto PCONSTRAINT = (wlr_pointer_constraint_v1*)data; + + Debug::log(LOG, "New mouse constraint at %x", PCONSTRAINT); + + g_pInputManager->m_lConstraints.emplace_back(); + const auto CONSTRAINT = &g_pInputManager->m_lConstraints.back(); + + CONSTRAINT->pMouse = g_pCompositor->m_sSeat.mouse; + CONSTRAINT->constraint = PCONSTRAINT; + + CONSTRAINT->hyprListener_destroyConstraint.initCallback(&PCONSTRAINT->events.destroy, &Events::listener_destroyConstraint, CONSTRAINT, "Constraint"); + CONSTRAINT->hyprListener_setConstraintRegion.initCallback(&PCONSTRAINT->events.set_region, &Events::listener_setConstraintRegion, CONSTRAINT, "Constraint"); + + if (g_pCompositor->m_pLastFocus == PCONSTRAINT->surface) { + g_pInputManager->constrainMouse(CONSTRAINT->pMouse, PCONSTRAINT); + } } -void Events::listener_newVirtPtr(wl_listener *listener, void *data) { - const auto EV = (wlr_virtual_pointer_v1_new_pointer_event *)data; - const auto POINTER = EV->new_pointer; - const auto DEVICE = &POINTER->pointer.base; +void Events::listener_destroyConstraint(void* owner, void* data) { + const auto PCONSTRAINT = (SConstraint*)owner; - g_pInputManager->newMouse(DEVICE, true); + if (PCONSTRAINT->pMouse->currentConstraint == PCONSTRAINT->constraint) { + PCONSTRAINT->pMouse->hyprListener_commitConstraint.removeCallback(); + + const auto PWINDOW = g_pCompositor->getConstraintWindow(g_pCompositor->m_sSeat.mouse); + + if (PWINDOW) { + if (PWINDOW->m_bIsX11) { + wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, + PCONSTRAINT->constraint->current.cursor_hint.x + PWINDOW->m_uSurface.xwayland->x, PWINDOW->m_uSurface.xwayland->y + PCONSTRAINT->constraint->current.cursor_hint.y); + + wlr_seat_pointer_warp(PCONSTRAINT->constraint->seat, PCONSTRAINT->constraint->current.cursor_hint.x, PCONSTRAINT->constraint->current.cursor_hint.y); + } else { + wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, + PCONSTRAINT->constraint->current.cursor_hint.x + PWINDOW->m_vRealPosition.vec().x, PCONSTRAINT->constraint->current.cursor_hint.y + PWINDOW->m_vRealPosition.vec().y); + + wlr_seat_pointer_warp(PCONSTRAINT->constraint->seat, PCONSTRAINT->constraint->current.cursor_hint.x, PCONSTRAINT->constraint->current.cursor_hint.y); + } + } + + PCONSTRAINT->pMouse->currentConstraint = nullptr; + } + + Debug::log(LOG, "Unconstrained mouse from %x", PCONSTRAINT->constraint); + + g_pInputManager->m_lConstraints.remove(*PCONSTRAINT); } -void Events::listener_destroyMouse(void *owner, void *data) { - const auto PMOUSE = (SMouse *)owner; - - g_pInputManager->destroyMouse(PMOUSE->mouse); +void Events::listener_setConstraintRegion(void* owner, void* data) { + // no } -void Events::listener_swipeBegin(wl_listener *listener, void *data) { - const auto EVENT = (wlr_pointer_swipe_begin_event *)data; +void Events::listener_newVirtPtr(wl_listener* listener, void* data) { + const auto EV = (wlr_virtual_pointer_v1_new_pointer_event*)data; + const auto POINTER = EV->new_pointer; + const auto DEVICE = &POINTER->pointer.base; - g_pInputManager->onSwipeBegin(EVENT); + g_pInputManager->newMouse(DEVICE, true); } -void Events::listener_swipeUpdate(wl_listener *listener, void *data) { - const auto EVENT = (wlr_pointer_swipe_update_event *)data; +void Events::listener_destroyMouse(void* owner, void* data) { + const auto PMOUSE = (SMouse*)owner; - g_pInputManager->onSwipeUpdate(EVENT); + g_pInputManager->destroyMouse(PMOUSE->mouse); } -void Events::listener_swipeEnd(wl_listener *listener, void *data) { - const auto EVENT = (wlr_pointer_swipe_end_event *)data; +void Events::listener_swipeBegin(wl_listener* listener, void* data) { + const auto EVENT = (wlr_pointer_swipe_begin_event*)data; - g_pInputManager->onSwipeEnd(EVENT); + g_pInputManager->onSwipeBegin(EVENT); +} + +void Events::listener_swipeUpdate(wl_listener* listener, void* data) { + const auto EVENT = (wlr_pointer_swipe_update_event*)data; + + g_pInputManager->onSwipeUpdate(EVENT); +} + +void Events::listener_swipeEnd(wl_listener* listener, void* data) { + const auto EVENT = (wlr_pointer_swipe_end_event*)data; + + g_pInputManager->onSwipeEnd(EVENT); } From 2ae088d63102cf7c0281157c1845d27e3502048e Mon Sep 17 00:00:00 2001 From: Darksome Date: Sat, 16 Jul 2022 12:47:37 +0300 Subject: [PATCH 09/13] Use correct wlroots commit --- subprojects/wlroots | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subprojects/wlroots b/subprojects/wlroots index b89ed901..5dc1d467 160000 --- a/subprojects/wlroots +++ b/subprojects/wlroots @@ -1 +1 @@ -Subproject commit b89ed9015c3fbe8d339e9d65cf70fdca6e5645bc +Subproject commit 5dc1d4671dd2ca3c1f0f09587c463fdbb542f0a4 From ce9efb7ae38acb84d72035e6b4a772a6fe5e9319 Mon Sep 17 00:00:00 2001 From: Darksome Date: Sat, 16 Jul 2022 15:28:17 +0300 Subject: [PATCH 10/13] Impl changeworkspace(e+{n}) --- example/hyprland.conf | 4 ++-- src/config/defaultConfig.hpp | 4 ++-- src/events/Devices.cpp | 4 +--- src/helpers/MiscFunctions.cpp | 6 ++++-- src/managers/input/InputManager.cpp | 6 ++---- 5 files changed, 11 insertions(+), 13 deletions(-) diff --git a/example/hyprland.conf b/example/hyprland.conf index a776559a..7c5918e7 100644 --- a/example/hyprland.conf +++ b/example/hyprland.conf @@ -103,5 +103,5 @@ bind=ALT,8,movetoworkspace,8 bind=ALT,9,movetoworkspace,9 bind=ALT,0,movetoworkspace,10 -bind=SUPER,mouse_down,workspace,+1 -bind=SUPER,mouse_up,workspace,-1 \ No newline at end of file +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 15dbbe16..1897d93d 100644 --- a/src/config/defaultConfig.hpp +++ b/src/config/defaultConfig.hpp @@ -112,6 +112,6 @@ bind=ALT,8,movetoworkspace,8 bind=ALT,9,movetoworkspace,9 bind=ALT,0,movetoworkspace,10 -bind=SUPER,mouse_down,workspace,+1 -bind=SUPER,mouse_up,workspace,-1 +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 5660772c..4b8762ba 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 126600f3..cf415847 100644 --- a/src/helpers/MiscFunctions.cpp +++ b/src/helpers/MiscFunctions.cpp @@ -193,7 +193,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; @@ -234,7 +236,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/input/InputManager.cpp b/src/managers/input/InputManager.cpp index 55890abc..c7fcfb7a 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -630,12 +630,10 @@ void CInputManager::onKeyboardKey(wlr_keyboard_key_event* e, SKeyboard* pKeyboar bool found = false; if (e->state == WL_KEYBOARD_KEY_STATE_PRESSED) { - static const std::string empty = ""; - for (int i = 0; i < syms; ++i) - found = g_pKeybindManager->handleKeybinds(MODS, empty, keysyms[i], 0) || found; + found = g_pKeybindManager->handleKeybinds(MODS, "", keysyms[i], 0) || found; - found = g_pKeybindManager->handleKeybinds(MODS, empty, 0, KEYCODE) || found; + found = g_pKeybindManager->handleKeybinds(MODS, "", 0, KEYCODE) || found; } else if (e->state == WL_KEYBOARD_KEY_STATE_RELEASED) { // hee hee } From 08319dd1f5185e1938df86a0a0a61f06b30026f4 Mon Sep 17 00:00:00 2001 From: Darksome Date: Sat, 16 Jul 2022 15:34:13 +0300 Subject: [PATCH 11/13] Fix handleKeybinds debug log --- src/managers/KeybindManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 4e00818e..3aecc3b6 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -122,7 +122,7 @@ bool CKeybindManager::handleKeybinds(const uint32_t& modmask, const std::string& 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, %s)", modmask, key); + Debug::log(LOG, "Keybind triggered, calling dispatcher (%d, %s, %d)", modmask, key, keysym); DISPATCHER->second(k.arg); } From ce508f1cdc5b504c16792eddb8b0a04b5dbba4d7 Mon Sep 17 00:00:00 2001 From: Darksome Date: Thu, 21 Jul 2022 19:48:34 +0300 Subject: [PATCH 12/13] Fix merge --- src/managers/KeybindManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index cf820611..7fb4f2bd 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -169,7 +169,7 @@ bool CKeybindManager::handleKeybinds(const uint32_t& modmask, const std::string& if (pressed && k.release) { // suppress down event - m_kHeldBack = key; + m_kHeldBack = keysym; return true; } From d5ccca4fdbdf53eec011210f4bbbdb20049aa12e Mon Sep 17 00:00:00 2001 From: Darksome Date: Thu, 21 Jul 2022 20:31:38 +0300 Subject: [PATCH 13/13] Consider scroll as a 'pressed' key --- src/managers/KeybindManager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 7fb4f2bd..3f723565 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -119,9 +119,9 @@ bool CKeybindManager::onAxisEvent(wlr_pointer_axis_event* e) { 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, false, 0); + found = g_pKeybindManager->handleKeybinds(MODS, "mouse_down", 0, 0, true, 0); } else { - found = g_pKeybindManager->handleKeybinds(MODS, "mouse_up", 0, 0, false, 0); + found = g_pKeybindManager->handleKeybinds(MODS, "mouse_up", 0, 0, true, 0); } }