From 3be4f0556bc47f388c6cd128199001c6b6eea3ad Mon Sep 17 00:00:00 2001 From: outfoxxed Date: Tue, 12 Sep 2023 03:23:24 -0700 Subject: [PATCH] Fix focuswindow not focusing hidden group windows Fixes #28 --- flake.lock | 11 ++++++----- flake.nix | 2 +- src/Hy3Layout.cpp | 8 ++++++-- src/Hy3Layout.hpp | 3 ++- src/Hy3Node.cpp | 17 +++++++++++------ src/Hy3Node.hpp | 3 ++- 6 files changed, 28 insertions(+), 16 deletions(-) diff --git a/flake.lock b/flake.lock index dce26e3..7b31b32 100644 --- a/flake.lock +++ b/flake.lock @@ -9,15 +9,16 @@ "xdph": "xdph" }, "locked": { - "lastModified": 1694074808, - "narHash": "sha256-gFHAGWaGh5ZM144wPSYJ6EXam3xmyS2wLwjLhjd7OKU=", - "owner": "hyprwm", + "lastModified": 1694513107, + "narHash": "sha256-D+e/iynlvTpa+bi2usdQu3Fva9P3SLx6IiaktNVwYkE=", + "owner": "outfoxxed", "repo": "Hyprland", - "rev": "0be6b03ee972fcc4921984f3b68469a2ee121511", + "rev": "87bb9800bb60b4df36232542c79f8308bf6fb17e", "type": "github" }, "original": { - "owner": "hyprwm", + "owner": "outfoxxed", + "ref": "bring-window-to-top", "repo": "Hyprland", "type": "github" } diff --git a/flake.nix b/flake.nix index 3be3c6c..882b0e3 100644 --- a/flake.nix +++ b/flake.nix @@ -1,6 +1,6 @@ { inputs = { - hyprland.url = "github:hyprwm/Hyprland"; + hyprland.url = "github:outfoxxed/Hyprland?ref=bring-window-to-top"; }; outputs = { self, hyprland, ... }: let diff --git a/src/Hy3Layout.cpp b/src/Hy3Layout.cpp index e747037..c3b6012 100644 --- a/src/Hy3Layout.cpp +++ b/src/Hy3Layout.cpp @@ -715,10 +715,14 @@ void Hy3Layout::replaceWindowDataWith(CWindow* from, CWindow* to) { this->applyNodeDataToWindow(node); } -void Hy3Layout::requestFocusForWindow(CWindow* window) { +bool Hy3Layout::isWindowReachable(CWindow* window) { + return this->getNodeFromWindow(window) != nullptr || IHyprLayout::isWindowReachable(window); +} + +void Hy3Layout::bringWindowToTop(CWindow* window) { auto node = this->getNodeFromWindow(window); if (node == nullptr) return; - node->focusWindow(); + node->bringToTop(); } void Hy3Layout::onEnable() { diff --git a/src/Hy3Layout.hpp b/src/Hy3Layout.hpp index f532f73..230210c 100644 --- a/src/Hy3Layout.hpp +++ b/src/Hy3Layout.hpp @@ -84,7 +84,8 @@ public: virtual std::string getLayoutName(); virtual CWindow* getNextWindowCandidate(CWindow*); virtual void replaceWindowDataWith(CWindow* from, CWindow* to); - virtual void requestFocusForWindow(CWindow*); + virtual bool isWindowReachable(CWindow*); + virtual void bringWindowToTop(CWindow*); virtual void onEnable(); virtual void onDisable(); diff --git a/src/Hy3Node.cpp b/src/Hy3Node.cpp index 2a47b8e..52912d2 100644 --- a/src/Hy3Node.cpp +++ b/src/Hy3Node.cpp @@ -153,29 +153,34 @@ void Hy3Node::focus() { } } -bool Hy3Node::focusWindow() { +CWindow* Hy3Node::bringToTop() { switch (this->data.type) { case Hy3NodeType::Window: this->markFocused(); this->data.as_window->setHidden(false); - g_pCompositor->focusWindow(this->data.as_window); - return true; + return this->data.as_window; case Hy3NodeType::Group: if (this->data.as_group.layout == Hy3GroupLayout::Tabbed) { if (this->data.as_group.focused_child != nullptr) { - return this->data.as_group.focused_child->focusWindow(); + return this->data.as_group.focused_child->bringToTop(); } } else { for (auto* node: this->data.as_group.children) { - if (node->focusWindow()) break; + auto* window = node->bringToTop(); + if (window != nullptr) return window; } } - return false; + return nullptr; } } +void Hy3Node::focusWindow() { + auto* window = this->bringToTop(); + if (window != nullptr) g_pCompositor->focusWindow(window); +} + void markGroupFocusedRecursive(Hy3GroupData& group) { group.group_focused = true; for (auto& child: group.children) { diff --git a/src/Hy3Node.hpp b/src/Hy3Node.hpp index 0f81b44..4b17d82 100644 --- a/src/Hy3Node.hpp +++ b/src/Hy3Node.hpp @@ -92,7 +92,8 @@ struct Hy3Node { bool operator==(const Hy3Node&) const; void focus(); - bool focusWindow(); + void focusWindow(); + CWindow* bringToTop(); void markFocused(); void raiseToTop(); Hy3Node* getFocusedNode(bool ignore_group_focus = false, bool stop_at_expanded = false);