From 88267eee8550bb8f1a1a5399161cd4ea633a2978 Mon Sep 17 00:00:00 2001 From: Sekhat Temporus Date: Thu, 17 Aug 2023 07:46:14 +0100 Subject: [PATCH] Add opposite support to change group This will allow toggling between horizontal and veritcal layouts for non-tabbed layouts --- README.md | 3 ++- src/Hy3Layout.cpp | 18 ++++++++++++++++++ src/Hy3Layout.hpp | 2 ++ src/dispatchers.cpp | 6 ++---- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 9d4556f..54fa81a 100644 --- a/README.md +++ b/README.md @@ -215,8 +215,9 @@ plugin { - `hy3:makegroup, , [ephemeral | force_ephemeral]` - make a vertical / horizontal split or tab group - `ephemeral` - the group will be removed once it contains only one node. does not affect existing groups. - `force_ephemeral` - same as ephemeral, but converts existing single windows groups. - - `hy3:changegroup, - change the group the node belongs to, to a different layout + - `hy3:changegroup, - change the group the node belongs to, to a different layout - `untab` will untab the group if it was previously tabbed + - `opposite` will toggle between horizontal and vertical layouts if the group is not tabbed. - `hy3:changeephemerality, ` - change the ephemerality of the group the node belongs to - `hy3:movefocus, , [visible]` - move the focus left, up, down, or right - `visible` - only move between visible nodes, not hidden tabs diff --git a/src/Hy3Layout.cpp b/src/Hy3Layout.cpp index 2d01f5d..0b93b4c 100644 --- a/src/Hy3Layout.cpp +++ b/src/Hy3Layout.cpp @@ -765,6 +765,14 @@ void Hy3Layout::untabGroupOnWorkspace(int workspace) { this->untabGroupOn(*node); } +void Hy3Layout::changeGroupToOppositeOnWorkspace(int workspace) { + auto* node = this->getWorkspaceFocusedNode(workspace); + + if (node == nullptr) return; + + this->changeGroupToOppositeOn(*node); +} + void Hy3Layout::changeGroupEphemeralityOnWorkspace(int workspace, bool ephemeral) { auto* node = this->getWorkspaceFocusedNode(workspace); @@ -841,6 +849,16 @@ void Hy3Layout::untabGroupOn(Hy3Node& node) { changeGroupOn(node, group.previous_nontab_layout); } +void Hy3Layout::changeGroupToOppositeOn(Hy3Node& node) { + if (node.parent == nullptr) return; + + auto& group = node.parent->data.as_group; + + if (group.layout == Hy3GroupLayout::Tabbed) return; + group.setLayout(group.layout == Hy3GroupLayout::SplitH ? Hy3GroupLayout::SplitV : Hy3GroupLayout::SplitH); + node.parent->recalcSizePosRecursive(); +} + void Hy3Layout::changeGroupEphemeralityOn(Hy3Node& node, bool ephemeral) { if (node.parent == nullptr) return; diff --git a/src/Hy3Layout.hpp b/src/Hy3Layout.hpp index ef5ed73..e5148cc 100644 --- a/src/Hy3Layout.hpp +++ b/src/Hy3Layout.hpp @@ -92,11 +92,13 @@ public: void makeOppositeGroupOnWorkspace(int workspace, GroupEphemeralityOption); void changeGroupOnWorkspace(int workspace, Hy3GroupLayout); void untabGroupOnWorkspace(int workspace); + void changeGroupToOppositeOnWorkspace(int workspace); void changeGroupEphemeralityOnWorkspace(int workspace, bool ephemeral); void makeGroupOn(Hy3Node*, Hy3GroupLayout, GroupEphemeralityOption); void makeOppositeGroupOn(Hy3Node*, GroupEphemeralityOption); void changeGroupOn(Hy3Node&, Hy3GroupLayout); void untabGroupOn(Hy3Node&); + void changeGroupToOppositeOn(Hy3Node&); void changeGroupEphemeralityOn(Hy3Node&, bool ephemeral); void shiftWindow(int workspace, ShiftDirection, bool once); void shiftFocus(int workspace, ShiftDirection, bool visible); diff --git a/src/dispatchers.cpp b/src/dispatchers.cpp index ca29441..bec72aa 100644 --- a/src/dispatchers.cpp +++ b/src/dispatchers.cpp @@ -57,11 +57,9 @@ void dispatch_changegroup(std::string value) { g_Hy3Layout->changeGroupOnWorkspace(workspace, Hy3GroupLayout::Tabbed); } else if (args[0] == "untab") { g_Hy3Layout->untabGroupOnWorkspace(workspace); + } else if (args[0] == "opposite") { + g_Hy3Layout->changeGroupToOppositeOnWorkspace(workspace); } - // TODO - //else if (args[0] == "opposite") { - // g_Hy3Layout->makeOppositeGroupOnWorkspace(workspace, ephemeral); - //} } void dispatch_changeephemerality(std::string value) {