3be4f0556bc47f388c6cd128199001c6b6eea3ad

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

Message

Fix focuswindow not focusing hidden group windows

Fixes #28

Diff

  1diff --git a/flake.lock b/flake.lock
  2index dce26e35ab820f17bef5154f1d76063e06a6219c..7b31b3204b6d416977bf2275f34db49937c5e764 100644
  3--- a/flake.lock
  4+++ b/flake.lock
  5@@ -9,15 +9,16 @@
  6         "xdph": "xdph"
  7       },
  8       "locked": {
  9-        "lastModified": 1694074808,
 10-        "narHash": "sha256-gFHAGWaGh5ZM144wPSYJ6EXam3xmyS2wLwjLhjd7OKU=",
 11-        "owner": "hyprwm",
 12+        "lastModified": 1694513107,
 13+        "narHash": "sha256-D+e/iynlvTpa+bi2usdQu3Fva9P3SLx6IiaktNVwYkE=",
 14+        "owner": "outfoxxed",
 15         "repo": "Hyprland",
 16-        "rev": "0be6b03ee972fcc4921984f3b68469a2ee121511",
 17+        "rev": "87bb9800bb60b4df36232542c79f8308bf6fb17e",
 18         "type": "github"
 19       },
 20       "original": {
 21-        "owner": "hyprwm",
 22+        "owner": "outfoxxed",
 23+        "ref": "bring-window-to-top",
 24         "repo": "Hyprland",
 25         "type": "github"
 26       }
 27diff --git a/flake.nix b/flake.nix
 28index 3be3c6c176b184756a14ae005150b540ad2937cc..882b0e3d2c10d1887b9ae27f24e34d9ab6e30180 100644
 29--- a/flake.nix
 30+++ b/flake.nix
 31@@ -1,6 +1,6 @@
 32 {
 33   inputs = {
 34-    hyprland.url = "github:hyprwm/Hyprland";
 35+    hyprland.url = "github:outfoxxed/Hyprland?ref=bring-window-to-top";
 36   };
 37 
 38   outputs = { self, hyprland, ... }: let
 39diff --git a/src/Hy3Layout.cpp b/src/Hy3Layout.cpp
 40index e7470375895657fcd917a5bb857dec989e3ec0c3..c3b6012b15ccf86369a578b7d3fd2dbeed871790 100644
 41--- a/src/Hy3Layout.cpp
 42+++ b/src/Hy3Layout.cpp
 43@@ -715,10 +715,14 @@ void Hy3Layout::replaceWindowDataWith(CWindow* from, CWindow* to) {
 44 	this->applyNodeDataToWindow(node);
 45 }
 46 
 47-void Hy3Layout::requestFocusForWindow(CWindow* window) {
 48+bool Hy3Layout::isWindowReachable(CWindow* window) {
 49+	return this->getNodeFromWindow(window) != nullptr || IHyprLayout::isWindowReachable(window);
 50+}
 51+
 52+void Hy3Layout::bringWindowToTop(CWindow* window) {
 53 	auto node = this->getNodeFromWindow(window);
 54 	if (node == nullptr) return;
 55-	node->focusWindow();
 56+	node->bringToTop();
 57 }
 58 
 59 void Hy3Layout::onEnable() {
 60diff --git a/src/Hy3Layout.hpp b/src/Hy3Layout.hpp
 61index f532f739443929fb656501cf02ece88ff77437c7..230210c916533d48417489c975f32a797f2bb46a 100644
 62--- a/src/Hy3Layout.hpp
 63+++ b/src/Hy3Layout.hpp
 64@@ -84,7 +84,8 @@ public:
 65 	virtual std::string getLayoutName();
 66 	virtual CWindow* getNextWindowCandidate(CWindow*);
 67 	virtual void replaceWindowDataWith(CWindow* from, CWindow* to);
 68-	virtual void requestFocusForWindow(CWindow*);
 69+	virtual bool isWindowReachable(CWindow*);
 70+	virtual void bringWindowToTop(CWindow*);
 71 
 72 	virtual void onEnable();
 73 	virtual void onDisable();
 74diff --git a/src/Hy3Node.cpp b/src/Hy3Node.cpp
 75index 2a47b8ea421d2119492437894ae9b875f4845c40..52912d22473b420647eded0a9fda51fce8c0ea44 100644
 76--- a/src/Hy3Node.cpp
 77+++ b/src/Hy3Node.cpp
 78@@ -153,29 +153,34 @@ void Hy3Node::focus() {
 79 	}
 80 }
 81 
 82-bool Hy3Node::focusWindow() {
 83+CWindow* Hy3Node::bringToTop() {
 84 	switch (this->data.type) {
 85 	case Hy3NodeType::Window:
 86 		this->markFocused();
 87 		this->data.as_window->setHidden(false);
 88-		g_pCompositor->focusWindow(this->data.as_window);
 89 
 90-		return true;
 91+		return this->data.as_window;
 92 	case Hy3NodeType::Group:
 93 		if (this->data.as_group.layout == Hy3GroupLayout::Tabbed) {
 94 			if (this->data.as_group.focused_child != nullptr) {
 95-				return this->data.as_group.focused_child->focusWindow();
 96+				return this->data.as_group.focused_child->bringToTop();
 97 			}
 98 		} else {
 99 			for (auto* node: this->data.as_group.children) {
100-				if (node->focusWindow()) break;
101+				auto* window = node->bringToTop();
102+				if (window != nullptr) return window;
103 			}
104 		}
105 
106-		return false;
107+		return nullptr;
108 	}
109 }
110 
111+void Hy3Node::focusWindow() {
112+	auto* window = this->bringToTop();
113+	if (window != nullptr) g_pCompositor->focusWindow(window);
114+}
115+
116 void markGroupFocusedRecursive(Hy3GroupData& group) {
117 	group.group_focused = true;
118 	for (auto& child: group.children) {
119diff --git a/src/Hy3Node.hpp b/src/Hy3Node.hpp
120index 0f81b4464fb3599a4edbfdd648c5c4d38dc7051e..4b17d824100c3a5b4e90890cc0f433984947a79e 100644
121--- a/src/Hy3Node.hpp
122+++ b/src/Hy3Node.hpp
123@@ -92,7 +92,8 @@ struct Hy3Node {
124 	bool operator==(const Hy3Node&) const;
125 
126 	void focus();
127-	bool focusWindow();
128+	void focusWindow();
129+	CWindow* bringToTop();
130 	void markFocused();
131 	void raiseToTop();
132 	Hy3Node* getFocusedNode(bool ignore_group_focus = false, bool stop_at_expanded = false);