584a1b1e357412a1a4ac40dbc6c4e5adaa7ec59b

Author
outfoxxed <outfoxxed@outfoxxed.me>
Committer
outfoxxed <outfoxxed@outfoxxed.me>
Date

Message

feat: add `hy3:warpcursor`

Diff

 1diff --git a/CHANGELOG.md b/CHANGELOG.md
 2index 655cedfcfc65df44d039d78fd5b1c43c6afbc634..4387074ebc2c0d8c4ff21e8f3186c7a765c4b6ee 100644
 3--- a/CHANGELOG.md
 4+++ b/CHANGELOG.md
 5@@ -2,6 +2,7 @@
 6 
 7 ## Upcoming
 8 
 9+- Added `hy3:warpcursor` dispatcher to warp cursor to current node.
10 - Added cursor warping options for `hy3:movefocus`.
11 
12 ## hl0.37.1 and before
13diff --git a/README.md b/README.md
14index 4b732346cea41cc78b4495319dff2d8868f15aa6..2fc3f3b46bfcb8609b928a12c427a31c345a0d1a 100644
15--- a/README.md
16+++ b/README.md
17@@ -321,6 +321,7 @@ plugin {
18    - `visible` - only move between visible nodes, not hidden tabs
19    - `warp` - warp the mouse to the selected window, even if `general:no_cursor_warps` is true.
20    - `nowarp` - does not warp the mouse to the selected window, even if `general:no_cursor_warps` is false.
21+ - `hy3:warpcursor` - warp the cursor to the center of the focused node
22  - `hy3:movewindow, <l | u | d | r | left | down | up | right>, [once], [visible]` - move a window left, up, down, or right
23    - `once` - only move directly to the neighboring group, without moving into any of its subgroups
24    - `visible` - only move between visible nodes, not hidden tabs
25diff --git a/src/Hy3Layout.cpp b/src/Hy3Layout.cpp
26index bc5dc5dbfc64b55818bd1bdcd92f18fdef51b513..fc17e5da08abe2323635d70833d4848255659ee4 100644
27--- a/src/Hy3Layout.cpp
28+++ b/src/Hy3Layout.cpp
29@@ -925,6 +925,22 @@ void Hy3Layout::shiftFocus(
30 	}
31 }
32 
33+void Hy3Layout::warpCursor() {
34+	auto current_window = g_pCompositor->m_pLastWindow.lock();
35+
36+	if (current_window != nullptr) {
37+		if (current_window != nullptr) {
38+			g_pCompositor->warpCursorTo(current_window->middle(), true);
39+		}
40+	} else {
41+		auto* node = this->getWorkspaceFocusedNode(g_pCompositor->m_pLastMonitor->activeWorkspace);
42+
43+		if (node != nullptr) {
44+			g_pCompositor->warpCursorTo(node->position + node->size / 2);
45+		}
46+	}
47+}
48+
49 void changeNodeWorkspaceRecursive(Hy3Node& node, const PHLWORKSPACE& workspace) {
50 	node.workspace = workspace;
51 
52diff --git a/src/Hy3Layout.hpp b/src/Hy3Layout.hpp
53index d6b118b06dddb4b9e78e10a2b44aebf24565f110..e73938afbbe581c982d2edf51cab1d1866f3ad08 100644
54--- a/src/Hy3Layout.hpp
55+++ b/src/Hy3Layout.hpp
56@@ -113,6 +113,7 @@ public:
57 	void shiftNode(Hy3Node&, ShiftDirection, bool once, bool visible);
58 	void shiftWindow(const PHLWORKSPACE& workspace, ShiftDirection, bool once, bool visible);
59 	void shiftFocus(const PHLWORKSPACE& workspace, ShiftDirection, bool visible, bool warp);
60+	void warpCursor();
61 	void moveNodeToWorkspace(const PHLWORKSPACE& origin, std::string wsname, bool follow);
62 	void changeFocus(const PHLWORKSPACE& workspace, FocusShift);
63 	void focusTab(
64diff --git a/src/dispatchers.cpp b/src/dispatchers.cpp
65index aae34e8523723b010bdaad2d10fb0941383419b0..8ea26932c94aa2c1234c30eabd0168b8e67d0e2d 100644
66--- a/src/dispatchers.cpp
67+++ b/src/dispatchers.cpp
68@@ -129,6 +129,10 @@ void dispatch_movefocus(std::string value) {
69 	g_Hy3Layout->shiftFocus(workspace, shift.value(), visible, warp_cursor);
70 }
71 
72+void dispatch_warpcursor(std::string value) {
73+	g_Hy3Layout->warpCursor();
74+}
75+
76 void dispatch_move_to_workspace(std::string value) {
77 	auto origin_workspace = workspace_for_action(true);
78 	if (!valid(origin_workspace)) return;
79@@ -259,6 +263,7 @@ void registerDispatchers() {
80 	HyprlandAPI::addDispatcher(PHANDLE, "hy3:changegroup", dispatch_changegroup);
81 	HyprlandAPI::addDispatcher(PHANDLE, "hy3:setephemeral", dispatch_setephemeral);
82 	HyprlandAPI::addDispatcher(PHANDLE, "hy3:movefocus", dispatch_movefocus);
83+	HyprlandAPI::addDispatcher(PHANDLE, "hy3:warpcursor", dispatch_warpcursor);
84 	HyprlandAPI::addDispatcher(PHANDLE, "hy3:movewindow", dispatch_movewindow);
85 	HyprlandAPI::addDispatcher(PHANDLE, "hy3:movetoworkspace", dispatch_move_to_workspace);
86 	HyprlandAPI::addDispatcher(PHANDLE, "hy3:changefocus", dispatch_changefocus);