88267eee8550bb8f1a1a5399161cd4ea633a2978

Author
Sekhat Temporus <sekhat@temporus.me>
Committer
Sekhat Temporus <sekhat@temporus.me>
Date

Message

Add opposite support to change group

This will allow toggling between horizontal and veritcal layouts for
non-tabbed layouts

Diff

 1diff --git a/README.md b/README.md
 2index 9d4556fc280b5bb6463173066ba81562800e4832..54fa81a481eb31d90b40b053a4299d2dfdd23202 100644
 3--- a/README.md
 4+++ b/README.md
 5@@ -215,8 +215,9 @@ plugin {
 6  - `hy3:makegroup, <h | v | opposite | tab>, [ephemeral | force_ephemeral]` - make a vertical / horizontal split or tab group
 7    - `ephemeral` - the group will be removed once it contains only one node. does not affect existing groups.
 8    - `force_ephemeral` - same as ephemeral, but converts existing single windows groups.
 9- - `hy3:changegroup, <h | v | tab | untab> - change the group the node belongs to, to a different layout
10+ - `hy3:changegroup, <h | v | tab | untab | opposite> - change the group the node belongs to, to a different layout
11    - `untab` will untab the group if it was previously tabbed
12+   - `opposite` will toggle between horizontal and vertical layouts if the group is not tabbed.
13  - `hy3:changeephemerality, <true | false>` - change the ephemerality of the group the node belongs to
14  - `hy3:movefocus, <l | u | d | r | left | down | up | right>, [visible]` - move the focus left, up, down, or right
15    - `visible` - only move between visible nodes, not hidden tabs
16diff --git a/src/Hy3Layout.cpp b/src/Hy3Layout.cpp
17index 2d01f5d285f7af79213b3a894bd4c1e93102a2b7..0b93b4cfb2bb3f84456403658e7bafda888d953f 100644
18--- a/src/Hy3Layout.cpp
19+++ b/src/Hy3Layout.cpp
20@@ -765,6 +765,14 @@ void Hy3Layout::untabGroupOnWorkspace(int workspace) {
21 	this->untabGroupOn(*node);
22 }
23 
24+void Hy3Layout::changeGroupToOppositeOnWorkspace(int workspace) {
25+	auto* node = this->getWorkspaceFocusedNode(workspace);
26+
27+	if (node == nullptr) return;
28+
29+	this->changeGroupToOppositeOn(*node);
30+}
31+
32 void Hy3Layout::changeGroupEphemeralityOnWorkspace(int workspace, bool ephemeral) {
33 	auto* node = this->getWorkspaceFocusedNode(workspace);
34 
35@@ -841,6 +849,16 @@ void Hy3Layout::untabGroupOn(Hy3Node& node) {
36 	changeGroupOn(node, group.previous_nontab_layout);
37 }
38 
39+void Hy3Layout::changeGroupToOppositeOn(Hy3Node& node) {
40+	if (node.parent == nullptr) return;
41+
42+	auto& group = node.parent->data.as_group;
43+
44+	if (group.layout == Hy3GroupLayout::Tabbed) return;
45+	group.setLayout(group.layout == Hy3GroupLayout::SplitH ? Hy3GroupLayout::SplitV : Hy3GroupLayout::SplitH);
46+	node.parent->recalcSizePosRecursive();
47+}
48+
49 void Hy3Layout::changeGroupEphemeralityOn(Hy3Node& node, bool ephemeral) {
50 	if (node.parent == nullptr) return;
51 
52diff --git a/src/Hy3Layout.hpp b/src/Hy3Layout.hpp
53index ef5ed73a531fc7524788d6a4cf7736744f07510c..e5148cc4ab1e53dcc416d2994bbe143aee5400b6 100644
54--- a/src/Hy3Layout.hpp
55+++ b/src/Hy3Layout.hpp
56@@ -92,11 +92,13 @@ public:
57 	void makeOppositeGroupOnWorkspace(int workspace, GroupEphemeralityOption);
58 	void changeGroupOnWorkspace(int workspace, Hy3GroupLayout);
59 	void untabGroupOnWorkspace(int workspace);
60+	void changeGroupToOppositeOnWorkspace(int workspace);
61 	void changeGroupEphemeralityOnWorkspace(int workspace, bool ephemeral);
62 	void makeGroupOn(Hy3Node*, Hy3GroupLayout, GroupEphemeralityOption);
63 	void makeOppositeGroupOn(Hy3Node*, GroupEphemeralityOption);
64 	void changeGroupOn(Hy3Node&, Hy3GroupLayout);
65 	void untabGroupOn(Hy3Node&);
66+	void changeGroupToOppositeOn(Hy3Node&);
67 	void changeGroupEphemeralityOn(Hy3Node&, bool ephemeral);
68 	void shiftWindow(int workspace, ShiftDirection, bool once);
69 	void shiftFocus(int workspace, ShiftDirection, bool visible);
70diff --git a/src/dispatchers.cpp b/src/dispatchers.cpp
71index ca29441e25e46be80d312436c41d1ce47ade2f06..bec72aa63a25549d7ed88a6495b07909e8502a69 100644
72--- a/src/dispatchers.cpp
73+++ b/src/dispatchers.cpp
74@@ -57,11 +57,9 @@ void dispatch_changegroup(std::string value) {
75 		g_Hy3Layout->changeGroupOnWorkspace(workspace, Hy3GroupLayout::Tabbed);
76 	} else if (args[0] == "untab") {
77 		g_Hy3Layout->untabGroupOnWorkspace(workspace);
78+	} else if (args[0] == "opposite") {
79+		g_Hy3Layout->changeGroupToOppositeOnWorkspace(workspace);
80 	}
81-	// TODO
82-	//else if (args[0] == "opposite") {
83-	//	g_Hy3Layout->makeOppositeGroupOnWorkspace(workspace, ephemeral);
84-	//}
85 }
86 
87 void dispatch_changeephemerality(std::string value) {