From fdcd00212597cf49fe3aed53c9eac70ecbd62fb3 Mon Sep 17 00:00:00 2001 From: MightyPlaza <123664421+MightyPlaza@users.noreply.github.com> Date: Fri, 15 Sep 2023 15:15:34 +0100 Subject: [PATCH] add groupbar "max_size" modified: src/config/ConfigManager.cpp modified: src/render/decorations/CHyprGroupBarDecoration.cpp Signed-off-by: MightyPlaza <123664421+MightyPlaza@users.noreply.github.com> --- src/config/ConfigManager.cpp | 1 + .../decorations/CHyprGroupBarDecoration.cpp | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index f7b42611..5c2ab595 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -130,6 +130,7 @@ void CConfigManager::setDefaultVars() { configValues["group:groupbar:enabled"].intValue = 1; configValues["group:groupbar:font"].strValue = "Sans"; configValues["group:groupbar:height"].intValue = 20; + configValues["group:groupbar:max_width"].intValue = 0; configValues["group:groupbar:mode"].intValue = 1; configValues["group:groupbar:internal_bar"].intValue = 1; configValues["group:groupbar:render_titles"].intValue = 1; diff --git a/src/render/decorations/CHyprGroupBarDecoration.cpp b/src/render/decorations/CHyprGroupBarDecoration.cpp index 12489a90..4cb78b57 100644 --- a/src/render/decorations/CHyprGroupBarDecoration.cpp +++ b/src/render/decorations/CHyprGroupBarDecoration.cpp @@ -89,6 +89,8 @@ void CHyprGroupBarDecoration::draw(CMonitor* pMonitor, float a, const Vector2D& static auto* const PGROUPCOLINACTIVELOCKED = &g_pConfigManager->getConfigValuePtr("group:groupbar:col.locked_inactive")->data; static auto* const PGROUPCOLBACKGROUND = &g_pConfigManager->getConfigValuePtr("group:groupbar:col.background")->data; + static auto* const PMAXWIDTH = &g_pConfigManager->getConfigValuePtr("group:groupbar:max_width")->intValue; + const bool GROUPLOCKED = m_pWindow->getGroupHead()->m_sGroupData.locked; const auto* const PCOLACTIVE = GROUPLOCKED ? PGROUPCOLACTIVELOCKED : PGROUPCOLACTIVE; const auto* const PCOLINACTIVE = GROUPLOCKED ? PGROUPCOLINACTIVELOCKED : PGROUPCOLINACTIVE; @@ -99,6 +101,10 @@ void CHyprGroupBarDecoration::draw(CMonitor* pMonitor, float a, const Vector2D& m_fBarWidth = (m_vLastWindowSize.x - 2 * ROUNDING - BAR_HORIZONTAL_PADDING * (barsToDraw + 1)) / barsToDraw; + if (*PMAXWIDTH >= 1) { + m_fBarWidth = std::min(m_fBarWidth, (float)*PMAXWIDTH); + } + float currentOffset = BAR_HORIZONTAL_PADDING; if (m_fBarWidth <= 0) @@ -392,9 +398,10 @@ bool CHyprGroupBarDecoration::allowsInput() { } void CHyprGroupBarDecoration::dragWindowToDecoration(CWindow* m_pDraggedWindow, const Vector2D& pos) { + const int SIZE = m_dwGroupMembers.size(); const int ROUNDING = m_pWindow->getRealRounding(); const float BARRELATIVEX = pos.x - (m_vLastWindowPos.x + ROUNDING) - (m_fBarWidth / 2 + BAR_HORIZONTAL_PADDING); - const int WINDOWINDEX = BARRELATIVEX < 0 ? -1 : (BARRELATIVEX) / (m_fBarWidth + BAR_HORIZONTAL_PADDING); + const int WINDOWINDEX = std::min(BARRELATIVEX < 0 ? -1 : (int)((BARRELATIVEX) / (m_fBarWidth + BAR_HORIZONTAL_PADDING)), SIZE - 1); CWindow* pWindowInsertAfter = m_pWindow->getGroupWindowByIndex(WINDOWINDEX); @@ -405,11 +412,12 @@ void CHyprGroupBarDecoration::dragWindowToDecoration(CWindow* m_pDraggedWindow, } void CHyprGroupBarDecoration::clickDecoration(const Vector2D& pos) { + const int SIZE = m_dwGroupMembers.size(); const int ROUNDING = m_pWindow->getRealRounding(); const float BARRELATIVEX = pos.x - (m_vLastWindowPos.x + ROUNDING); const int WINDOWINDEX = (BARRELATIVEX) / (m_fBarWidth + BAR_HORIZONTAL_PADDING); - if (BARRELATIVEX - (m_fBarWidth + BAR_HORIZONTAL_PADDING) * WINDOWINDEX < BAR_HORIZONTAL_PADDING) { + if (BARRELATIVEX - (m_fBarWidth + BAR_HORIZONTAL_PADDING) * WINDOWINDEX < BAR_HORIZONTAL_PADDING || WINDOWINDEX > SIZE - 1) { if (!g_pCompositor->isWindowActive(m_pWindow)) g_pCompositor->focusWindow(m_pWindow); return; @@ -425,11 +433,12 @@ void CHyprGroupBarDecoration::clickDecoration(const Vector2D& pos) { } void CHyprGroupBarDecoration::dragFromDecoration(const Vector2D& pos) { + const int SIZE = m_dwGroupMembers.size(); const int ROUNDING = m_pWindow->getRealRounding(); const float BARRELATIVEX = pos.x - (m_vLastWindowPos.x + ROUNDING); const int WINDOWINDEX = (BARRELATIVEX) / (m_fBarWidth + BAR_HORIZONTAL_PADDING); - if (BARRELATIVEX - (m_fBarWidth + BAR_HORIZONTAL_PADDING) * WINDOWINDEX < BAR_HORIZONTAL_PADDING) + if (BARRELATIVEX - (m_fBarWidth + BAR_HORIZONTAL_PADDING) * WINDOWINDEX < BAR_HORIZONTAL_PADDING || WINDOWINDEX > SIZE - 1) return; CWindow* pWindow = m_pWindow->getGroupWindowByIndex(WINDOWINDEX);