Fix focuswindow not focusing hidden group windows

Fixes #28
This commit is contained in:
outfoxxed 2023-09-12 03:23:24 -07:00
parent 2680b1933b
commit 3be4f0556b
No known key found for this signature in database
GPG key ID: 4C88A185FB89301E
6 changed files with 28 additions and 16 deletions

11
flake.lock generated
View file

@ -9,15 +9,16 @@
"xdph": "xdph" "xdph": "xdph"
}, },
"locked": { "locked": {
"lastModified": 1694074808, "lastModified": 1694513107,
"narHash": "sha256-gFHAGWaGh5ZM144wPSYJ6EXam3xmyS2wLwjLhjd7OKU=", "narHash": "sha256-D+e/iynlvTpa+bi2usdQu3Fva9P3SLx6IiaktNVwYkE=",
"owner": "hyprwm", "owner": "outfoxxed",
"repo": "Hyprland", "repo": "Hyprland",
"rev": "0be6b03ee972fcc4921984f3b68469a2ee121511", "rev": "87bb9800bb60b4df36232542c79f8308bf6fb17e",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "hyprwm", "owner": "outfoxxed",
"ref": "bring-window-to-top",
"repo": "Hyprland", "repo": "Hyprland",
"type": "github" "type": "github"
} }

View file

@ -1,6 +1,6 @@
{ {
inputs = { inputs = {
hyprland.url = "github:hyprwm/Hyprland"; hyprland.url = "github:outfoxxed/Hyprland?ref=bring-window-to-top";
}; };
outputs = { self, hyprland, ... }: let outputs = { self, hyprland, ... }: let

View file

@ -715,10 +715,14 @@ void Hy3Layout::replaceWindowDataWith(CWindow* from, CWindow* to) {
this->applyNodeDataToWindow(node); 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); auto node = this->getNodeFromWindow(window);
if (node == nullptr) return; if (node == nullptr) return;
node->focusWindow(); node->bringToTop();
} }
void Hy3Layout::onEnable() { void Hy3Layout::onEnable() {

View file

@ -84,7 +84,8 @@ public:
virtual std::string getLayoutName(); virtual std::string getLayoutName();
virtual CWindow* getNextWindowCandidate(CWindow*); virtual CWindow* getNextWindowCandidate(CWindow*);
virtual void replaceWindowDataWith(CWindow* from, CWindow* to); virtual void replaceWindowDataWith(CWindow* from, CWindow* to);
virtual void requestFocusForWindow(CWindow*); virtual bool isWindowReachable(CWindow*);
virtual void bringWindowToTop(CWindow*);
virtual void onEnable(); virtual void onEnable();
virtual void onDisable(); virtual void onDisable();

View file

@ -153,29 +153,34 @@ void Hy3Node::focus() {
} }
} }
bool Hy3Node::focusWindow() { CWindow* Hy3Node::bringToTop() {
switch (this->data.type) { switch (this->data.type) {
case Hy3NodeType::Window: case Hy3NodeType::Window:
this->markFocused(); this->markFocused();
this->data.as_window->setHidden(false); this->data.as_window->setHidden(false);
g_pCompositor->focusWindow(this->data.as_window);
return true; return this->data.as_window;
case Hy3NodeType::Group: case Hy3NodeType::Group:
if (this->data.as_group.layout == Hy3GroupLayout::Tabbed) { if (this->data.as_group.layout == Hy3GroupLayout::Tabbed) {
if (this->data.as_group.focused_child != nullptr) { 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 { } else {
for (auto* node: this->data.as_group.children) { 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) { void markGroupFocusedRecursive(Hy3GroupData& group) {
group.group_focused = true; group.group_focused = true;
for (auto& child: group.children) { for (auto& child: group.children) {

View file

@ -92,7 +92,8 @@ struct Hy3Node {
bool operator==(const Hy3Node&) const; bool operator==(const Hy3Node&) const;
void focus(); void focus();
bool focusWindow(); void focusWindow();
CWindow* bringToTop();
void markFocused(); void markFocused();
void raiseToTop(); void raiseToTop();
Hy3Node* getFocusedNode(bool ignore_group_focus = false, bool stop_at_expanded = false); Hy3Node* getFocusedNode(bool ignore_group_focus = false, bool stop_at_expanded = false);