ce9fc7cda5a670fd4c61f65acd42a1c70484b9f5

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

Message

Disassociate null focused node and group selection

Useful for tabs branch

Diff

  1diff --git a/src/Hy3Layout.cpp b/src/Hy3Layout.cpp
  2index 7951730fa6ae53776cf75d61b85084f5ad3516eb..736a14216c1771c946b365995c5084259f4091bd 100644
  3--- a/src/Hy3Layout.cpp
  4+++ b/src/Hy3Layout.cpp
  5@@ -213,11 +213,13 @@ void Hy3Node::markFocused() {
  6 
  7 	// update focus
  8 	if (this->data.type == Hy3NodeData::Group) {
  9-		this->data.as_group.lastFocusedChild = nullptr;
 10+		this->data.as_group.group_focused = true;
 11+		this->data.as_group.focused_child = nullptr;
 12 	}
 13 
 14 	while (node->parent != nullptr) {
 15-		node->parent->data.as_group.lastFocusedChild = node;
 16+		node->parent->data.as_group.focused_child = node;
 17+		node->parent->data.as_group.group_focused = false;
 18 		node = node->parent;
 19 	}
 20 
 21@@ -258,10 +260,10 @@ Hy3Node* Hy3Node::getFocusedNode() {
 22 	case Hy3NodeData::Window:
 23 		return this;
 24 	case Hy3NodeData::Group:
 25-		if (this->data.as_group.lastFocusedChild == nullptr) {
 26+		if (this->data.as_group.focused_child == nullptr || this->data.as_group.group_focused) {
 27 			return this;
 28 		} else {
 29-			return this->data.as_group.lastFocusedChild->getFocusedNode();
 30+			return this->data.as_group.focused_child->getFocusedNode();
 31 		}
 32 	}
 33 }
 34@@ -309,10 +311,11 @@ Hy3Node* Hy3Node::removeFromParentRecursive() {
 35 		if (group.children.size() > 2) {
 36 			auto iter = std::find(group.children.begin(), group.children.end(), child);
 37 
 38+			group.group_focused = false;
 39 			if (iter == group.children.begin()) {
 40-				group.lastFocusedChild = *std::next(iter);
 41+				group.focused_child = *std::next(iter);
 42 			} else {
 43-				group.lastFocusedChild = *std::prev(iter);
 44+				group.focused_child = *std::prev(iter);
 45 			}
 46 		}
 47 
 48@@ -322,8 +325,9 @@ Hy3Node* Hy3Node::removeFromParentRecursive() {
 49 			return nullptr;
 50 		}
 51 
 52+		group.group_focused = false;
 53 		if (group.children.size() == 1) {
 54-			group.lastFocusedChild = group.children.front();
 55+			group.focused_child = group.children.front();
 56 		}
 57 
 58 		auto child_size_ratio = child->size_ratio;
 59@@ -365,7 +369,8 @@ Hy3Node* Hy3Node::intoGroup(Hy3GroupLayout layout) {
 60 
 61 	this->data = layout;
 62 	this->data.as_group.children.push_back(node);
 63-	this->data.as_group.lastFocusedChild = node;
 64+	this->data.as_group.group_focused = false;
 65+	this->data.as_group.focused_child = node;
 66 	this->recalcSizePosRecursive();
 67 
 68 	return node;
 69@@ -1222,7 +1227,8 @@ Hy3Node* Hy3Layout::shiftOrGetFocus(Hy3Node& node, ShiftDirection direction, boo
 70 				auto* newChild = &this->nodes.back();
 71 				Hy3Node::swapData(*break_parent, *newChild);
 72 				break_parent->data.as_group.children.push_back(newChild);
 73-				break_parent->data.as_group.lastFocusedChild = newChild;
 74+				break_parent->data.as_group.group_focused = false;
 75+				break_parent->data.as_group.focused_child = newChild;
 76 				break_origin = newChild;
 77 			}
 78 
 79@@ -1279,8 +1285,8 @@ Hy3Node* Hy3Layout::shiftOrGetFocus(Hy3Node& node, ShiftDirection direction, boo
 80 						shift_after = true;
 81 					}
 82 				} else {
 83-					if (group_data.lastFocusedChild != nullptr) {
 84-						iter = std::find(group_data.children.begin(), group_data.children.end(), group_data.lastFocusedChild);
 85+					if (group_data.focused_child != nullptr) {
 86+						iter = std::find(group_data.children.begin(), group_data.children.end(), group_data.focused_child);
 87 						shift_after = true;
 88 					} else {
 89 						iter = group_data.children.begin();
 90@@ -1353,7 +1359,7 @@ void Hy3Layout::raiseFocus(int workspace) {
 91 bool Hy3Layout::shouldRenderSelected(CWindow* window) {
 92 	if (window == nullptr) return false;
 93 	auto* root = this->getWorkspaceRootGroup(window->m_iWorkspaceID);
 94-	if (root == nullptr || root->data.as_group.lastFocusedChild == nullptr) return false;
 95+	if (root == nullptr || root->data.as_group.focused_child == nullptr) return false;
 96 	auto* focused = root->getFocusedNode();
 97 	if (focused == nullptr) return false;
 98 
 99diff --git a/src/Hy3Layout.hpp b/src/Hy3Layout.hpp
100index 7b34ae69b6c1710c08461a545d1a13051b9e114a..d3d954a2891c3ce19c4b68161d9461d192d820f3 100644
101--- a/src/Hy3Layout.hpp
102+++ b/src/Hy3Layout.hpp
103@@ -22,7 +22,8 @@ enum class ShiftDirection {
104 struct Hy3GroupData {
105 	Hy3GroupLayout layout = Hy3GroupLayout::SplitH;
106 	std::list<Hy3Node*> children;
107-	Hy3Node* lastFocusedChild = nullptr;
108+	bool group_focused = true;
109+	Hy3Node* focused_child = nullptr;
110 
111 	bool hasChild(Hy3Node* child);
112