update change group to match requested changes

This commit is contained in:
Sekhat Temporus 2023-08-16 13:28:51 +01:00
parent 2aca365d9b
commit 8b12921939
6 changed files with 48 additions and 55 deletions

View file

@ -215,10 +215,8 @@ plugin {
- `hy3:makegroup, <h | v | opposite | tab>, [ephemeral | force_ephemeral]` - make a vertical / horizontal split or tab group - `hy3:makegroup, <h | v | opposite | tab>, [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. - `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. - `force_ephemeral` - same as ephemeral, but converts existing single windows groups.
- `hy3:changegroup, <h | v | tab | untab>, [ephemeral | force_ephemeral]` - change the group the node belongs to, to a different layout - `hy3:changegroup, <h | v | tab | untab> - change the group the node belongs to, to a different layout
- `untab` will untab the group if it was previously tabbed - `untab` will untab the group if it was previously tabbed
- `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:movefocus, <l | u | d | r | left | down | up | right>, [visible]` - move the focus left, up, down, or right - `hy3:movefocus, <l | u | d | r | left | down | up | right>, [visible]` - move the focus left, up, down, or right
- `visible` - only move between visible nodes, not hidden tabs - `visible` - only move between visible nodes, not hidden tabs
- `hy3:movewindow, <l | u | d | r | left | down | up | right>, [once]` - move a window left, up, down, or right - `hy3:movewindow, <l | u | d | r | left | down | up | right>, [once]` - move a window left, up, down, or right

View file

@ -748,19 +748,21 @@ void Hy3Layout::makeOppositeGroupOnWorkspace(int workspace, GroupEphemeralityOpt
void Hy3Layout::changeGroupOnWorkspace( void Hy3Layout::changeGroupOnWorkspace(
int workspace, int workspace,
Hy3GroupLayout layout, Hy3GroupLayout layout
GroupEphemeralityOption ephemeral
) { ) {
auto* node = this->getWorkspaceFocusedNode(workspace); auto* node = this->getWorkspaceFocusedNode(workspace);
this->changeGroupOn(node, layout, ephemeral);
if (node == nullptr) return;
this->changeGroupOn(*node, layout);
} }
void Hy3Layout::untabGroupOnWorkspace( void Hy3Layout::untabGroupOnWorkspace(int workspace) {
int workspace,
GroupEphemeralityOption ephemeral
) {
auto* node = this->getWorkspaceFocusedNode(workspace); auto* node = this->getWorkspaceFocusedNode(workspace);
this->untabGroupOn(node, ephemeral);
if (node == nullptr) return;
this->untabGroupOn(*node);
} }
void Hy3Layout::makeGroupOn( void Hy3Layout::makeGroupOn(
@ -773,7 +775,8 @@ void Hy3Layout::makeGroupOn(
if (node->parent != nullptr) { if (node->parent != nullptr) {
auto& group = node->parent->data.as_group; auto& group = node->parent->data.as_group;
if (group.children.size() == 1) { if (group.children.size() == 1) {
group.updateLayout(layout, ephemeral); group.setLayout(layout);
group.setEphemeral(ephemeral);
node->parent->recalcSizePosRecursive(); node->parent->recalcSizePosRecursive();
return; return;
} }
@ -798,7 +801,8 @@ void Hy3Layout::makeOppositeGroupOn(
= group.layout == Hy3GroupLayout::SplitH ? Hy3GroupLayout::SplitV : Hy3GroupLayout::SplitH; = group.layout == Hy3GroupLayout::SplitH ? Hy3GroupLayout::SplitV : Hy3GroupLayout::SplitH;
if (group.children.size() == 1) { if (group.children.size() == 1) {
group.updateLayout(layout, ephemeral); group.setLayout(layout);
group.setEphemeral(ephemeral);
node->parent->recalcSizePosRecursive(); node->parent->recalcSizePosRecursive();
return; return;
} }
@ -807,32 +811,28 @@ void Hy3Layout::makeOppositeGroupOn(
} }
void Hy3Layout::changeGroupOn( void Hy3Layout::changeGroupOn(
Hy3Node* node, Hy3Node& node,
Hy3GroupLayout layout, Hy3GroupLayout layout
GroupEphemeralityOption ephemeral
) { ) {
if (node == nullptr) return; if (node.parent == nullptr) {
makeGroupOn(&node, layout, GroupEphemeralityOption::Ephemeral);
if (node->parent == nullptr) {
makeGroupOn(node, layout, ephemeral);
return; return;
} }
auto& group = node->parent->data.as_group; auto& group = node.parent->data.as_group;
group.updateLayout(layout, ephemeral); group.setLayout(layout);
node->parent->recalcSizePosRecursive(); node.parent->recalcSizePosRecursive();
} }
void Hy3Layout::untabGroupOn(Hy3Node* node, GroupEphemeralityOption ephemeral) { void Hy3Layout::untabGroupOn(Hy3Node& node) {
if (node == nullptr) return; if (node.parent == nullptr) return;
if (node->parent == nullptr) return;
auto& group = node->parent->data.as_group;
auto& group = node.parent->data.as_group;
if (group.layout != Hy3GroupLayout::Tabbed) return; if (group.layout != Hy3GroupLayout::Tabbed) return;
changeGroupOn(node, group.previous_nontab_layout, ephemeral); changeGroupOn(node, group.previous_nontab_layout);
} }
void Hy3Layout::shiftWindow(int workspace, ShiftDirection direction, bool once) { void Hy3Layout::shiftWindow(int workspace, ShiftDirection direction, bool once) {
@ -842,7 +842,7 @@ void Hy3Layout::shiftWindow(int workspace, ShiftDirection direction, bool once)
if (once && node->parent != nullptr && node->parent->data.as_group.children.size() == 1) { if (once && node->parent != nullptr && node->parent->data.as_group.children.size() == 1) {
if (node->parent->parent == nullptr) { if (node->parent->parent == nullptr) {
node->parent->data.as_group.layout = Hy3GroupLayout::SplitH; node->parent->data.as_group.setLayout(Hy3GroupLayout::SplitH);
node->parent->recalcSizePosRecursive(); node->parent->recalcSizePosRecursive();
} else { } else {
auto* node2 = node->parent; auto* node2 = node->parent;
@ -1466,7 +1466,7 @@ Hy3Node* Hy3Layout::shiftOrGetFocus(
if (group.layout != Hy3GroupLayout::Tabbed && group.children.size() == 2 if (group.layout != Hy3GroupLayout::Tabbed && group.children.size() == 2
&& std::find(group.children.begin(), group.children.end(), &node) != group.children.end()) && std::find(group.children.begin(), group.children.end(), &node) != group.children.end())
{ {
group.layout = shiftIsVertical(direction) ? Hy3GroupLayout::SplitV : Hy3GroupLayout::SplitH; group.setLayout(shiftIsVertical(direction) ? Hy3GroupLayout::SplitV : Hy3GroupLayout::SplitH);
} else { } else {
// wrap the root group in another group // wrap the root group in another group
this->nodes.push_back({ this->nodes.push_back({

View file

@ -90,12 +90,12 @@ public:
void makeGroupOnWorkspace(int workspace, Hy3GroupLayout, GroupEphemeralityOption); void makeGroupOnWorkspace(int workspace, Hy3GroupLayout, GroupEphemeralityOption);
void makeOppositeGroupOnWorkspace(int workspace, GroupEphemeralityOption); void makeOppositeGroupOnWorkspace(int workspace, GroupEphemeralityOption);
void changeGroupOnWorkspace(int workspace, Hy3GroupLayout, GroupEphemeralityOption); void changeGroupOnWorkspace(int workspace, Hy3GroupLayout);
void untabGroupOnWorkspace(int workspace, GroupEphemeralityOption); void untabGroupOnWorkspace(int workspace);
void makeGroupOn(Hy3Node*, Hy3GroupLayout, GroupEphemeralityOption); void makeGroupOn(Hy3Node*, Hy3GroupLayout, GroupEphemeralityOption);
void makeOppositeGroupOn(Hy3Node*, GroupEphemeralityOption); void makeOppositeGroupOn(Hy3Node*, GroupEphemeralityOption);
void changeGroupOn(Hy3Node*, Hy3GroupLayout, GroupEphemeralityOption); void changeGroupOn(Hy3Node&, Hy3GroupLayout);
void untabGroupOn(Hy3Node*, GroupEphemeralityOption); void untabGroupOn(Hy3Node&);
void shiftWindow(int workspace, ShiftDirection, bool once); void shiftWindow(int workspace, ShiftDirection, bool once);
void shiftFocus(int workspace, ShiftDirection, bool visible); void shiftFocus(int workspace, ShiftDirection, bool visible);
void changeFocus(int workspace, FocusShift); void changeFocus(int workspace, FocusShift);

View file

@ -57,25 +57,26 @@ void Hy3GroupData::collapseExpansions() {
} }
} }
void Hy3GroupData::updateLayout( void Hy3GroupData::setLayout(
Hy3GroupLayout layout, Hy3GroupLayout layout
GroupEphemeralityOption ephemeral
) { ) {
this->layout = layout; this->layout = layout;
if (layout != Hy3GroupLayout::Tabbed) { if (layout != Hy3GroupLayout::Tabbed) {
this->previous_nontab_layout = layout; this->previous_nontab_layout = layout;
} }
}
void Hy3GroupData::setEphemeral(GroupEphemeralityOption ephemeral) {
switch (ephemeral) { switch (ephemeral) {
case GroupEphemeralityOption::ForceEphemeral:
this->ephemeral = true;
break;
case GroupEphemeralityOption::Standard: case GroupEphemeralityOption::Standard:
this->ephemeral = false; this->ephemeral = false;
break; break;
case GroupEphemeralityOption::ForceEphemeral:
this->ephemeral = true;
break;
case GroupEphemeralityOption::Ephemeral: case GroupEphemeralityOption::Ephemeral:
// this->ephemeral stays the same // no change
break; break;
} }
} }

View file

@ -43,7 +43,8 @@ struct Hy3GroupData {
bool hasChild(Hy3Node* child); bool hasChild(Hy3Node* child);
void collapseExpansions(); void collapseExpansions();
void updateLayout(Hy3GroupLayout layout, GroupEphemeralityOption ephemeral); void setLayout(Hy3GroupLayout layout);
void setEphemeral(GroupEphemeralityOption ephemeral);
private: private:
Hy3GroupData(Hy3GroupData&&); Hy3GroupData(Hy3GroupData&&);

View file

@ -49,21 +49,14 @@ void dispatch_changegroup(std::string value) {
auto args = CVarList(value); auto args = CVarList(value);
GroupEphemeralityOption ephemeral = GroupEphemeralityOption::Standard;
if (args[1] == "ephemeral") {
ephemeral = GroupEphemeralityOption::Ephemeral;
} else if (args[1] == "force_ephemeral") {
ephemeral = GroupEphemeralityOption::ForceEphemeral;
}
if (args[0] == "h") { if (args[0] == "h") {
g_Hy3Layout->changeGroupOnWorkspace(workspace, Hy3GroupLayout::SplitH, ephemeral); g_Hy3Layout->changeGroupOnWorkspace(workspace, Hy3GroupLayout::SplitH);
} else if (args[0] == "v") { } else if (args[0] == "v") {
g_Hy3Layout->changeGroupOnWorkspace(workspace, Hy3GroupLayout::SplitV, ephemeral); g_Hy3Layout->changeGroupOnWorkspace(workspace, Hy3GroupLayout::SplitV);
} else if (args[0] == "tab") { } else if (args[0] == "tab") {
g_Hy3Layout->changeGroupOnWorkspace(workspace, Hy3GroupLayout::Tabbed, ephemeral); g_Hy3Layout->changeGroupOnWorkspace(workspace, Hy3GroupLayout::Tabbed);
} else if (args[0] == "untab") { } else if (args[0] == "untab") {
g_Hy3Layout->untabGroupOnWorkspace(workspace, ephemeral); g_Hy3Layout->untabGroupOnWorkspace(workspace);
} }
// TODO // TODO
//else if (args[0] == "opposite") { //else if (args[0] == "opposite") {