From 3bf93f5457cbeb8a4e85d5c0c919f22c212aaeab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Mon, 10 Jun 2024 10:28:00 +0200 Subject: [PATCH] Fix visual defects when switching workspaces properly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/TabGroup.cpp | 37 +++++++++++++++++++++++-------------- src/TabGroup.hpp | 3 +-- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/TabGroup.cpp b/src/TabGroup.cpp index 4c4a9d5..24b9e6a 100644 --- a/src/TabGroup.cpp +++ b/src/TabGroup.cpp @@ -409,14 +409,6 @@ Hy3TabGroup::Hy3TabGroup(Hy3Node& node) { this->size.warp(); } -void Hy3TabGroup::damage() { - auto pos = this->node->position; - auto size = this->node->size; - auto box = CBox {pos.x, pos.y, size.x, size.y}; - - g_pHyprRenderer->damageBox(&box); -} - void Hy3TabGroup::updateWithGroup(Hy3Node& node, bool warp) { this->node = &node; @@ -453,6 +445,11 @@ void Hy3TabGroup::updateWithGroup(Hy3Node& node, bool warp) { } } +void damageBox(const Vector2D* position, const Vector2D* size) { + auto box = CBox {position->x, position->y, size->x, size->y}; + g_pHyprRenderer->damageBox(&box); +} + void Hy3TabGroup::tick() { static const auto enter_from_top = ConfigValue("plugin:hy3:tabs:from_top"); static const auto padding = ConfigValue("plugin:hy3:tabs:padding"); @@ -466,8 +463,22 @@ void Hy3TabGroup::tick() { if (this->bar.fade_opacity.goal() != 1.0) this->bar.fade_opacity = 1.0; } - if (this->workspace->m_vRenderOffset.isBeingAnimated()) { - this->damage(); + auto workspaceOffset = this->workspace->m_vRenderOffset.value(); + if (this->last_workspace_offset != workspaceOffset) { + // First we damage the area where the bar was during the previous + // tick, cleaning up after ourselves + auto pos = this->last_pos + this->last_workspace_offset; + auto size = this->last_size; + damageBox(&pos, &size); + + // Then we damage the current position of the bar, to avoid seeing + // glitches with animations disabled + pos = this->pos.value() + workspaceOffset; + size = this->size.value(); + damageBox(&pos, &size); + + this->bar.damaged = true; + this->last_workspace_offset = workspaceOffset; } } @@ -475,8 +486,7 @@ void Hy3TabGroup::tick() { auto size = this->size.value(); if (this->last_pos != pos || this->last_size != size) { - CBox damage_box = {this->last_pos.x, this->last_pos.y, this->last_size.x, this->last_size.y}; - g_pHyprRenderer->damageBox(&damage_box); + damageBox(&this->last_pos, &this->last_size); this->bar.damaged = true; this->last_pos = pos; @@ -490,8 +500,7 @@ void Hy3TabGroup::tick() { pos.y -= *padding; } - CBox damage_box = {pos.x, pos.y, size.x, size.y}; - g_pHyprRenderer->damageBox(&damage_box); + damageBox(&pos, &size); this->bar.damaged = true; this->bar.dirty = false; diff --git a/src/TabGroup.hpp b/src/TabGroup.hpp index 910b304..26eda2e 100644 --- a/src/TabGroup.hpp +++ b/src/TabGroup.hpp @@ -103,6 +103,7 @@ public: private: std::vector stencil_windows; + Vector2D last_workspace_offset; Vector2D last_pos; Vector2D last_size; Hy3Node* node; @@ -114,6 +115,4 @@ private: // UB if node is not a group. void updateStencilWindows(Hy3Node&); - - void damage(); };