14dec2e15c9d8cbcc13032348398ffed969e67c1

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

Message

Add support for hyprland movewindow dispatcher

Note that this support is worse than hy3:movwindow and you should
still use that. This fixes the api breakage though.

Diff

  1diff --git a/flake.lock b/flake.lock
  2index af24f17795983eb8e624aaf43596f40dcd429f14..0356e87f1e8683565479254da386290d19b69f1a 100644
  3--- a/flake.lock
  4+++ b/flake.lock
  5@@ -9,11 +9,11 @@
  6         "xdph": "xdph"
  7       },
  8       "locked": {
  9-        "lastModified": 1692123043,
 10-        "narHash": "sha256-6YoTjAZgtJb9OzKrZxtLxjfYiGWSqMmh1Wyh9dvwXn8=",
 11+        "lastModified": 1693851147,
 12+        "narHash": "sha256-kkI7FXwKufOmNIIQQHr868tneIV8ggqupBA0EJ/jAuI=",
 13         "owner": "hyprwm",
 14         "repo": "Hyprland",
 15-        "rev": "4986d74ef201171a930c312a8e3b72a22d9b84ee",
 16+        "rev": "4ddcda93f5887792a953332bf1b487e4b2c3b4ed",
 17         "type": "github"
 18       },
 19       "original": {
 20@@ -49,11 +49,11 @@
 21     },
 22     "nixpkgs": {
 23       "locked": {
 24-        "lastModified": 1691654369,
 25-        "narHash": "sha256-gSILTEx1jRaJjwZxRlnu3ZwMn1FVNk80qlwiCX8kmpo=",
 26+        "lastModified": 1693158576,
 27+        "narHash": "sha256-aRTTXkYvhXosGx535iAFUaoFboUrZSYb1Ooih/auGp0=",
 28         "owner": "NixOS",
 29         "repo": "nixpkgs",
 30-        "rev": "ce5e4a6ef2e59d89a971bc434ca8ca222b9c7f5e",
 31+        "rev": "a999c1cc0c9eb2095729d5aa03e0d8f7ed256780",
 32         "type": "github"
 33       },
 34       "original": {
 35@@ -87,18 +87,18 @@
 36       "flake": false,
 37       "locked": {
 38         "host": "gitlab.freedesktop.org",
 39-        "lastModified": 1691073628,
 40-        "narHash": "sha256-LlxE3o3UzRY7APYVLGNKM30DBMcDifCRIQiMVSbYLIc=",
 41+        "lastModified": 1692976565,
 42+        "narHash": "sha256-eBKkG7tMxg92NskEn8dHRFY245JwjirWRoOZzW6DnUw=",
 43         "owner": "wlroots",
 44         "repo": "wlroots",
 45-        "rev": "c74f89d4f84bfed0284d3908aee5d207698c70c5",
 46+        "rev": "717ded9bb0191ea31bf4368be32e7a15fe1b8294",
 47         "type": "gitlab"
 48       },
 49       "original": {
 50         "host": "gitlab.freedesktop.org",
 51         "owner": "wlroots",
 52         "repo": "wlroots",
 53-        "rev": "c74f89d4f84bfed0284d3908aee5d207698c70c5",
 54+        "rev": "717ded9bb0191ea31bf4368be32e7a15fe1b8294",
 55         "type": "gitlab"
 56       }
 57     },
 58diff --git a/src/Hy3Layout.cpp b/src/Hy3Layout.cpp
 59index 12a67ab80b2f966f09539d946661a62e17dfc1b7..a3af2617c1d93ac193efdd9a09e768d4f71d7a57 100644
 60--- a/src/Hy3Layout.cpp
 61+++ b/src/Hy3Layout.cpp
 62@@ -673,6 +673,20 @@ void Hy3Layout::switchWindows(CWindow* pWindowA, CWindow* pWindowB) {
 63 	// todo
 64 }
 65 
 66+void Hy3Layout::moveWindowTo(CWindow* window, const std::string& direction) {
 67+	auto* node = this->getNodeFromWindow(window);
 68+	if (node == nullptr) return;
 69+
 70+	ShiftDirection shift;
 71+	if (direction == "l") shift = ShiftDirection::Left;
 72+	else if (direction == "r") shift = ShiftDirection::Right;
 73+	else if (direction == "u") shift = ShiftDirection::Up;
 74+	else if (direction == "d") shift = ShiftDirection::Down;
 75+	else return;
 76+
 77+	this->shiftNode(*node, shift, false, false);
 78+}
 79+
 80 void Hy3Layout::alterSplitRatio(CWindow* pWindow, float delta, bool exact) {
 81 	// todo
 82 }
 83@@ -874,26 +888,30 @@ void Hy3Layout::changeGroupEphemeralityOn(Hy3Node& node, bool ephemeral) {
 84 	);
 85 }
 86 
 87-void Hy3Layout::shiftWindow(int workspace, ShiftDirection direction, bool once, bool visible) {
 88-	auto* node = this->getWorkspaceFocusedNode(workspace);
 89-	Debug::log(LOG, "ShiftWindow %p %d", node, direction);
 90-	if (node == nullptr) return;
 91-
 92-	if (once && node->parent != nullptr && node->parent->data.as_group.children.size() == 1) {
 93-		if (node->parent->parent == nullptr) {
 94-			node->parent->data.as_group.setLayout(Hy3GroupLayout::SplitH);
 95-			node->parent->recalcSizePosRecursive();
 96+void Hy3Layout::shiftNode(Hy3Node& node, ShiftDirection direction, bool once, bool visible) {
 97+	if (once && node.parent != nullptr && node.parent->data.as_group.children.size() == 1) {
 98+		if (node.parent->parent == nullptr) {
 99+			node.parent->data.as_group.setLayout(Hy3GroupLayout::SplitH);
100+			node.parent->recalcSizePosRecursive();
101 		} else {
102-			auto* node2 = node->parent;
103-			Hy3Node::swapData(*node, *node2);
104-			node2->layout->nodes.remove(*node);
105+			auto* node2 = node.parent;
106+			Hy3Node::swapData(node, *node2);
107+			node2->layout->nodes.remove(node);
108 			node2->recalcSizePosRecursive();
109 		}
110 	} else {
111-		this->shiftOrGetFocus(*node, direction, true, once, visible);
112+		this->shiftOrGetFocus(node, direction, true, once, visible);
113 	}
114 }
115 
116+void Hy3Layout::shiftWindow(int workspace, ShiftDirection direction, bool once, bool visible) {
117+	auto* node = this->getWorkspaceFocusedNode(workspace);
118+	Debug::log(LOG, "ShiftWindow %p %d", node, direction);
119+	if (node == nullptr) return;
120+
121+	this->shiftNode(*node, direction, once, visible);
122+}
123+
124 void Hy3Layout::shiftFocus(int workspace, ShiftDirection direction, bool visible) {
125 	auto* node = this->getWorkspaceFocusedNode(workspace);
126 	Debug::log(LOG, "ShiftFocus %p %d", node, direction);
127diff --git a/src/Hy3Layout.hpp b/src/Hy3Layout.hpp
128index 83f81c7b600b2d4eba0b71e3d02a05cb60d589e9..f532f739443929fb656501cf02ece88ff77437c7 100644
129--- a/src/Hy3Layout.hpp
130+++ b/src/Hy3Layout.hpp
131@@ -79,6 +79,7 @@ public:
132 	virtual std::any layoutMessage(SLayoutMessageHeader header, std::string content);
133 	virtual SWindowRenderLayoutHints requestRenderHints(CWindow*);
134 	virtual void switchWindows(CWindow*, CWindow*);
135+	virtual void moveWindowTo(CWindow*, const std::string& direction);
136 	virtual void alterSplitRatio(CWindow*, float, bool);
137 	virtual std::string getLayoutName();
138 	virtual CWindow* getNextWindowCandidate(CWindow*);
139@@ -102,6 +103,7 @@ public:
140 	void toggleTabGroupOn(Hy3Node&);
141 	void changeGroupToOppositeOn(Hy3Node&);
142 	void changeGroupEphemeralityOn(Hy3Node&, bool ephemeral);
143+	void shiftNode(Hy3Node&, ShiftDirection, bool once, bool visible);
144 	void shiftWindow(int workspace, ShiftDirection, bool once, bool visible);
145 	void shiftFocus(int workspace, ShiftDirection, bool visible);
146 	void changeFocus(int workspace, FocusShift);