From 2ad2e1d5f5feaf1b7dd65dc162d16547f6b0b20f Mon Sep 17 00:00:00 2001 From: MightyPlaza <123664421+MightyPlaza@users.noreply.github.com> Date: Sat, 30 Dec 2023 14:18:53 +0000 Subject: [PATCH] groupbar: add enabling groupbar and setting priority (#4299) --- src/Compositor.cpp | 1 + src/Window.cpp | 6 ++++ src/Window.hpp | 1 + src/config/ConfigManager.cpp | 6 ++++ .../decorations/CHyprGroupBarDecoration.cpp | 32 ++++++++++++++----- .../decorations/DecorationPositioner.cpp | 2 +- 6 files changed, 39 insertions(+), 9 deletions(-) diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 8a0da27b..26bd56c4 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -2629,6 +2629,7 @@ void CCompositor::moveWindowToWorkspaceSafe(CWindow* pWindow, CWorkspace* pWorks pWindow->moveToWorkspace(pWorkspace->m_iID); pWindow->updateToplevel(); pWindow->updateDynamicRules(); + pWindow->uncacheWindowDecos(); if (!pWindow->m_bIsFloating) { g_pLayoutManager->getCurrentLayout()->onWindowRemovedTiling(pWindow); diff --git a/src/Window.cpp b/src/Window.cpp index debacde0..01b58253 100644 --- a/src/Window.cpp +++ b/src/Window.cpp @@ -222,6 +222,12 @@ void CWindow::removeWindowDeco(IHyprWindowDecoration* deco) { g_pLayoutManager->getCurrentLayout()->recalculateWindow(this); } +void CWindow::uncacheWindowDecos() { + for (auto& wd : m_dWindowDecorations) { + g_pDecorationPositioner->uncacheDecoration(wd.get()); + } +} + bool CWindow::checkInputOnDecos(const eInputType type, const Vector2D& mouseCoords, std::any data) { if (type != INPUT_TYPE_DRAG_END && hasPopupAt(mouseCoords)) return false; diff --git a/src/Window.hpp b/src/Window.hpp index d5de927b..559e4c90 100644 --- a/src/Window.hpp +++ b/src/Window.hpp @@ -348,6 +348,7 @@ class CWindow { void addWindowDeco(std::unique_ptr deco); void updateWindowDecos(); void removeWindowDeco(IHyprWindowDecoration* deco); + void uncacheWindowDecos(); bool checkInputOnDecos(const eInputType, const Vector2D&, std::any = {}); pid_t getPID(); IHyprWindowDecoration* getDecorationByType(eDecorationType); diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 8a3026e1..ee198ded 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -134,9 +134,11 @@ void CConfigManager::setDefaultVars() { configValues["group:insert_after_current"].intValue = 1; configValues["group:focus_removed_window"].intValue = 1; + configValues["group:groupbar:enabled"].intValue = 1; configValues["group:groupbar:font_family"].strValue = "Sans"; configValues["group:groupbar:font_size"].intValue = 8; configValues["group:groupbar:gradients"].intValue = 1; + configValues["group:groupbar:priority"].intValue = 3; configValues["group:groupbar:render_titles"].intValue = 1; configValues["group:groupbar:scrolling"].intValue = 1; configValues["group:groupbar:text_color"].intValue = 0xffffffff; @@ -1730,6 +1732,10 @@ void CConfigManager::loadConfigLoadVars() { ifs.close(); } + for (auto& w : g_pCompositor->m_vWindows) { + w->uncacheWindowDecos(); + } + for (auto& m : g_pCompositor->m_vMonitors) g_pLayoutManager->getCurrentLayout()->recalculateMonitor(m->ID); diff --git a/src/render/decorations/CHyprGroupBarDecoration.cpp b/src/render/decorations/CHyprGroupBarDecoration.cpp index cbd7a73f..33ecff6a 100644 --- a/src/render/decorations/CHyprGroupBarDecoration.cpp +++ b/src/render/decorations/CHyprGroupBarDecoration.cpp @@ -15,8 +15,11 @@ constexpr int BAR_TEXT_PAD = 2; constexpr int BAR_HORIZONTAL_PADDING = 2; CHyprGroupBarDecoration::CHyprGroupBarDecoration(CWindow* pWindow) : IHyprWindowDecoration(pWindow) { - m_pWindow = pWindow; - if (m_tGradientActive.m_iTexID == 0) + static auto* const PGRADIENTS = &g_pConfigManager->getConfigValuePtr("group:groupbar:enabled")->intValue; + static auto* const PENABLED = &g_pConfigManager->getConfigValuePtr("group:groupbar:gradients")->intValue; + m_pWindow = pWindow; + + if (m_tGradientActive.m_iTexID == 0 && *PENABLED && *PGRADIENTS) refreshGroupBarGradients(); } @@ -25,13 +28,19 @@ CHyprGroupBarDecoration::~CHyprGroupBarDecoration() {} SDecorationPositioningInfo CHyprGroupBarDecoration::getPositioningInfo() { static auto* const PRENDERTITLES = &g_pConfigManager->getConfigValuePtr("group:groupbar:render_titles")->intValue; static auto* const PTITLEFONTSIZE = &g_pConfigManager->getConfigValuePtr("group:groupbar:font_size")->intValue; + static auto* const PENABLED = &g_pConfigManager->getConfigValuePtr("group:groupbar:enabled")->intValue; SDecorationPositioningInfo info; - info.policy = DECORATION_POSITION_STICKY; - info.edges = DECORATION_EDGE_TOP; - info.priority = 3; - info.reserved = true; - info.desiredExtents = {{0, BAR_PADDING_OUTER_VERT * 2 + BAR_INDICATOR_HEIGHT + (*PRENDERTITLES ? *PTITLEFONTSIZE : 0) + 2}, {0, 0}}; + info.policy = DECORATION_POSITION_STICKY; + info.edges = DECORATION_EDGE_TOP; + info.priority = g_pConfigManager->getConfigValuePtr("group:groupbar:priority")->intValue; + info.reserved = true; + + if (*PENABLED && m_pWindow->m_sSpecialRenderData.decorate) + info.desiredExtents = {{0, BAR_PADDING_OUTER_VERT * 2 + BAR_INDICATOR_HEIGHT + (*PRENDERTITLES ? *PTITLEFONTSIZE : 0) + 2}, {0, 0}}; + else + info.desiredExtents = {{0, 0}, {0, 0}}; + return info; } @@ -78,11 +87,12 @@ void CHyprGroupBarDecoration::draw(CMonitor* pMonitor, float a, const Vector2D& // get how many bars we will draw int barsToDraw = m_dwGroupMembers.size(); + static auto* const PENABLED = &g_pConfigManager->getConfigValuePtr("group:groupbar:enabled")->intValue; static auto* const PRENDERTITLES = &g_pConfigManager->getConfigValuePtr("group:groupbar:render_titles")->intValue; static auto* const PTITLEFONTSIZE = &g_pConfigManager->getConfigValuePtr("group:groupbar:font_size")->intValue; static auto* const PGRADIENTS = &g_pConfigManager->getConfigValuePtr("group:groupbar:gradients")->intValue; - if (!m_pWindow->m_sSpecialRenderData.decorate) + if (!*PENABLED || !m_pWindow->m_sSpecialRenderData.decorate) return; const auto ASSIGNEDBOX = assignedBoxGlobal(); @@ -280,6 +290,9 @@ void renderGradientTo(CTexture& tex, const CColor& grad) { } void refreshGroupBarGradients() { + static auto* const PGRADIENTS = &g_pConfigManager->getConfigValuePtr("group:groupbar:enabled")->intValue; + static auto* const PENABLED = &g_pConfigManager->getConfigValuePtr("group:groupbar:gradients")->intValue; + static auto* const PGROUPCOLACTIVE = &g_pConfigManager->getConfigValuePtr("group:groupbar:col.active")->data; static auto* const PGROUPCOLINACTIVE = &g_pConfigManager->getConfigValuePtr("group:groupbar:col.inactive")->data; static auto* const PGROUPCOLACTIVELOCKED = &g_pConfigManager->getConfigValuePtr("group:groupbar:col.locked_active")->data; @@ -294,6 +307,9 @@ void refreshGroupBarGradients() { m_tGradientLockedInactive.destroyTexture(); } + if (!*PENABLED || !*PGRADIENTS) + return; + renderGradientTo(m_tGradientActive, ((CGradientValueData*)PGROUPCOLACTIVE->get())->m_vColors[0]); renderGradientTo(m_tGradientInactive, ((CGradientValueData*)PGROUPCOLINACTIVE->get())->m_vColors[0]); renderGradientTo(m_tGradientLockedActive, ((CGradientValueData*)PGROUPCOLACTIVELOCKED->get())->m_vColors[0]); diff --git a/src/render/decorations/DecorationPositioner.cpp b/src/render/decorations/DecorationPositioner.cpp index bdf37e58..e19c361b 100644 --- a/src/render/decorations/DecorationPositioner.cpp +++ b/src/render/decorations/DecorationPositioner.cpp @@ -370,4 +370,4 @@ CBox CDecorationPositioner::getWindowDecorationBox(IHyprWindowDecoration* deco) CBox box = DATA->lastReply.assignedGeometry; box.translate(getEdgeDefinedPoint(DATA->positioningInfo.edges, deco->m_pWindow)); return box; -} \ No newline at end of file +}