From 0e854287ffb800ff8c9a999779ce1e774b5b3a81 Mon Sep 17 00:00:00 2001 From: outfoxxed Date: Wed, 12 Apr 2023 03:33:45 -0700 Subject: [PATCH] Visual indication for single-window groups & more - Fix being able to create multiple levels of groups around a single window - Destroy single-member groups when they loose focus --- CMakeLists.txt | 1 - src/Hy3Layout.cpp | 73 +++++++++++++++++++++++++++++++++++++++++++++++ src/Hy3Layout.hpp | 2 ++ 3 files changed, 75 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 89ce72b..7a7a9d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,7 +20,6 @@ pkg_check_modules(DEPS REQUIRED pixman-1 libdrm) add_library(hy3 SHARED src/main.cpp src/Hy3Layout.cpp - src/Hy3SpawnLocDecoration.cpp ) target_include_directories(hy3 PRIVATE diff --git a/src/Hy3Layout.cpp b/src/Hy3Layout.cpp index 339496d..c0217fc 100644 --- a/src/Hy3Layout.cpp +++ b/src/Hy3Layout.cpp @@ -103,6 +103,47 @@ void Hy3Node::recalcSizePosRecursive(bool force) { } auto* group = &this->data.as_group; + + if (group->children.size() == 1 && this->parent != nullptr) { + auto& child = group->children.front(); + + double distortOut; + double distortIn; + + const auto* gaps_in = &g_pConfigManager->getConfigValuePtr("general:gaps_in")->intValue; + const auto* gaps_out = &g_pConfigManager->getConfigValuePtr("general:gaps_out")->intValue; + + if (gaps_in > gaps_out) { + distortOut = *gaps_out - 1.0; + } else { + distortOut = *gaps_in - 1.0; + } + + if (distortOut < 0) distortOut = 0.0; + + distortIn = *gaps_in * 2; + + switch (group->layout) { + case Hy3GroupLayout::SplitH: + child->position.x = this->position.x - distortOut; + child->size.x = this->size.x - distortIn; + child->position.y = this->position.y; + child->size.y = this->size.y; + break; + case Hy3GroupLayout::SplitV: + child->position.y = this->position.y - distortOut; + child->size.y = this->size.y - distortIn; + child->position.x = this->position.x; + child->size.x = this->size.x; + case Hy3GroupLayout::Tabbed: + // TODO + break; + } + + child->recalcSizePosRecursive(); + return; + } + int constraint; switch (group->layout) { case Hy3GroupLayout::SplitH: @@ -371,6 +412,28 @@ void Hy3Layout::onWindowRemovedTiling(CWindow* window) { if (parent != nullptr) parent->recalcSizePosRecursive(); } +void Hy3Layout::onWindowFocusChange(CWindow* window) { + Debug::log(LOG, "Switched windows from %p to %p", this->lastActiveWindow, window); + auto* node = this->getNodeFromWindow(this->lastActiveWindow); + + while (node != nullptr + && node->parent != nullptr + && node->parent->parent != nullptr + && node->parent->data.as_group.children.size() == 1) + { + auto parent = node->parent; + std::swap(parent->data, node->data); + this->nodes.remove(*node); + node = parent; + } + + if (node != nullptr) { + node->recalcSizePosRecursive(); + } + + this->lastActiveWindow = window; +} + bool Hy3Layout::isWindowTiled(CWindow* window) { return this->getNodeFromWindow(window) != nullptr; } @@ -402,6 +465,16 @@ std::any Hy3Layout::layoutMessage(SLayoutMessageHeader header, std::string conte layout = Hy3GroupLayout::SplitV; } + if (node->parent != nullptr + && node->parent->data.as_group.children.size() == 1 + && (node->parent->data.as_group.layout == Hy3GroupLayout::SplitH + || node->parent->data.as_group.layout == Hy3GroupLayout::SplitV)) + { + node->parent->data.as_group.layout = layout; + node->parent->recalcSizePosRecursive(); + return ""; + } + Hy3NodeData node_data = Hy3NodeData(Hy3GroupData(layout)); std::swap(node->data, node_data); diff --git a/src/Hy3Layout.hpp b/src/Hy3Layout.hpp index 7d23e80..c6907cb 100644 --- a/src/Hy3Layout.hpp +++ b/src/Hy3Layout.hpp @@ -56,6 +56,7 @@ class Hy3Layout: public IHyprLayout { public: virtual void onWindowCreatedTiling(CWindow*); virtual void onWindowRemovedTiling(CWindow*); + virtual void onWindowFocusChange(CWindow*); virtual bool isWindowTiled(CWindow*); virtual void recalculateMonitor(const int&); virtual void recalculateWindow(CWindow*); @@ -75,6 +76,7 @@ private: // std::list is used over std::vector because it does not invalidate references // when mutated. std::list nodes; + CWindow* lastActiveWindow = nullptr; int getWorkspaceNodeCount(const int&); Hy3Node* getNodeFromWindow(CWindow*);