diff --git a/CHANGELOG.md b/CHANGELOG.md index 655cedf..4387074 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Upcoming +- Added `hy3:warpcursor` dispatcher to warp cursor to current node. - Added cursor warping options for `hy3:movefocus`. ## hl0.37.1 and before diff --git a/README.md b/README.md index 4b73234..2fc3f3b 100644 --- a/README.md +++ b/README.md @@ -321,6 +321,7 @@ plugin { - `visible` - only move between visible nodes, not hidden tabs - `warp` - warp the mouse to the selected window, even if `general:no_cursor_warps` is true. - `nowarp` - does not warp the mouse to the selected window, even if `general:no_cursor_warps` is false. + - `hy3:warpcursor` - warp the cursor to the center of the focused node - `hy3:movewindow, , [once], [visible]` - move a window left, up, down, or right - `once` - only move directly to the neighboring group, without moving into any of its subgroups - `visible` - only move between visible nodes, not hidden tabs diff --git a/src/Hy3Layout.cpp b/src/Hy3Layout.cpp index bc5dc5d..fc17e5d 100644 --- a/src/Hy3Layout.cpp +++ b/src/Hy3Layout.cpp @@ -925,6 +925,22 @@ void Hy3Layout::shiftFocus( } } +void Hy3Layout::warpCursor() { + auto current_window = g_pCompositor->m_pLastWindow.lock(); + + if (current_window != nullptr) { + if (current_window != nullptr) { + g_pCompositor->warpCursorTo(current_window->middle(), true); + } + } else { + auto* node = this->getWorkspaceFocusedNode(g_pCompositor->m_pLastMonitor->activeWorkspace); + + if (node != nullptr) { + g_pCompositor->warpCursorTo(node->position + node->size / 2); + } + } +} + void changeNodeWorkspaceRecursive(Hy3Node& node, const PHLWORKSPACE& workspace) { node.workspace = workspace; diff --git a/src/Hy3Layout.hpp b/src/Hy3Layout.hpp index d6b118b..e73938a 100644 --- a/src/Hy3Layout.hpp +++ b/src/Hy3Layout.hpp @@ -113,6 +113,7 @@ public: void shiftNode(Hy3Node&, ShiftDirection, bool once, bool visible); void shiftWindow(const PHLWORKSPACE& workspace, ShiftDirection, bool once, bool visible); void shiftFocus(const PHLWORKSPACE& workspace, ShiftDirection, bool visible, bool warp); + void warpCursor(); void moveNodeToWorkspace(const PHLWORKSPACE& origin, std::string wsname, bool follow); void changeFocus(const PHLWORKSPACE& workspace, FocusShift); void focusTab( diff --git a/src/dispatchers.cpp b/src/dispatchers.cpp index aae34e8..8ea2693 100644 --- a/src/dispatchers.cpp +++ b/src/dispatchers.cpp @@ -129,6 +129,10 @@ void dispatch_movefocus(std::string value) { g_Hy3Layout->shiftFocus(workspace, shift.value(), visible, warp_cursor); } +void dispatch_warpcursor(std::string value) { + g_Hy3Layout->warpCursor(); +} + void dispatch_move_to_workspace(std::string value) { auto origin_workspace = workspace_for_action(true); if (!valid(origin_workspace)) return; @@ -259,6 +263,7 @@ void registerDispatchers() { HyprlandAPI::addDispatcher(PHANDLE, "hy3:changegroup", dispatch_changegroup); HyprlandAPI::addDispatcher(PHANDLE, "hy3:setephemeral", dispatch_setephemeral); HyprlandAPI::addDispatcher(PHANDLE, "hy3:movefocus", dispatch_movefocus); + HyprlandAPI::addDispatcher(PHANDLE, "hy3:warpcursor", dispatch_warpcursor); HyprlandAPI::addDispatcher(PHANDLE, "hy3:movewindow", dispatch_movewindow); HyprlandAPI::addDispatcher(PHANDLE, "hy3:movetoworkspace", dispatch_move_to_workspace); HyprlandAPI::addDispatcher(PHANDLE, "hy3:changefocus", dispatch_changefocus);