diff options
| author | vaxerski <43317083+vaxerski@users.noreply.github.com> | 2022-05-28 20:46:20 +0200 |
|---|---|---|
| committer | vaxerski <43317083+vaxerski@users.noreply.github.com> | 2022-05-28 20:46:20 +0200 |
| commit | bdf1c1619529792e95cd6cf2aa1d68e51db76252 (patch) | |
| tree | c1fc311647342d21ba49707651ce70e654aa7b81 /src/render/decorations | |
| parent | b1b24cb21a36713aa7c8c0d39464504c97423139 (diff) | |
Added IHyprWindowDecoration and Group Bars
Diffstat (limited to 'src/render/decorations')
| -rw-r--r-- | src/render/decorations/CHyprGroupBarDecoration.cpp | 99 | ||||
| -rw-r--r-- | src/render/decorations/CHyprGroupBarDecoration.hpp | 30 | ||||
| -rw-r--r-- | src/render/decorations/IHyprWindowDecoration.cpp | 7 | ||||
| -rw-r--r-- | src/render/decorations/IHyprWindowDecoration.hpp | 31 |
4 files changed, 167 insertions, 0 deletions
diff --git a/src/render/decorations/CHyprGroupBarDecoration.cpp b/src/render/decorations/CHyprGroupBarDecoration.cpp new file mode 100644 index 00000000..eca14973 --- /dev/null +++ b/src/render/decorations/CHyprGroupBarDecoration.cpp @@ -0,0 +1,99 @@ +#include "CHyprGroupBarDecoration.hpp" +#include "../../Compositor.hpp" + +CHyprGroupBarDecoration::CHyprGroupBarDecoration(CWindow* pWindow) { + m_pWindow = pWindow; + updateWindow(pWindow); +} + +CHyprGroupBarDecoration::~CHyprGroupBarDecoration() { + +} + +SWindowDecorationExtents CHyprGroupBarDecoration::getWindowDecorationExtents() { + return m_seExtents; +} + +eDecorationType CHyprGroupBarDecoration::getDecorationType() { + return DECORATION_GROUPBAR; +} + +void CHyprGroupBarDecoration::updateWindow(CWindow* pWindow) { + damageEntire(); + + const auto PMONITOR = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID); + + if (pWindow->m_vRealPosition.vec() != m_vLastWindowPos || pWindow->m_vRealSize.vec() != m_vLastWindowSize) { + // we draw 3px above the window's border with 3px + const auto BORDERSIZE = g_pConfigManager->getInt("general:border_size"); + + m_seExtents.topLeft = Vector2D(0, BORDERSIZE + 3 + 3); + m_seExtents.bottomRight = Vector2D(); + + m_vLastWindowPos = pWindow->m_vRealPosition.vec(); + m_vLastWindowSize = pWindow->m_vRealSize.vec(); + } + + // let's check if the window group is different. + + if (g_pLayoutManager->getCurrentLayout()->getLayoutName() != "dwindle") { + // ???? + for (auto it = pWindow->m_dWindowDecorations.begin(); it != pWindow->m_dWindowDecorations.end(); it++) { + if ((*it) == this) { + pWindow->m_dWindowDecorations.erase(it); + delete this; + return; + } + } + } + + // get the group info + SLayoutMessageHeader header; + header.pWindow = g_pCompositor->m_pLastWindow; + + m_dwGroupMembers = std::any_cast<std::deque<CWindow*>>(g_pLayoutManager->getCurrentLayout()->layoutMessage(header, "groupinfo")); + + damageEntire(); + + if (m_dwGroupMembers.size() == 0) { + // remove + for (auto it = pWindow->m_dWindowDecorations.begin(); it != pWindow->m_dWindowDecorations.end(); it++) { + if ((*it) == this) { + pWindow->m_dWindowDecorations.erase(it); + delete this; + return; + } + } + } +} + +void CHyprGroupBarDecoration::damageEntire() { + wlr_box dm = {m_vLastWindowPos.x - m_seExtents.topLeft.x, m_vLastWindowPos.y - m_seExtents.topLeft.y, m_vLastWindowSize.x + m_seExtents.topLeft.x + m_seExtents.bottomRight.x, m_seExtents.topLeft.y}; + g_pHyprRenderer->damageBox(&dm); +} + +void CHyprGroupBarDecoration::draw(SMonitor* pMonitor) { + // get how many bars we will draw + int barsToDraw = m_dwGroupMembers.size(); + + if (barsToDraw < 1 || m_pWindow->m_bHidden || !g_pCompositor->windowValidMapped(m_pWindow)) + return; + + const int PAD = 2; //2px + + const int BARW = (m_vLastWindowSize.x - PAD * (barsToDraw - 1)) / barsToDraw; + + int xoff = 0; + + for (int i = 0; i < barsToDraw; ++i) { + wlr_box rect = {m_vLastWindowPos.x + xoff - pMonitor->vecPosition.x, m_vLastWindowPos.y - m_seExtents.topLeft.y - pMonitor->vecPosition.y, BARW, 3}; + + if (rect.width <= 0 || rect.height <= 0) + break; + + CColor color = m_dwGroupMembers[i] == g_pCompositor->m_pLastWindow ? CColor(g_pConfigManager->getInt("dwindle:col.group_border_active")) : CColor(g_pConfigManager->getInt("dwindle:col.group_border")); + g_pHyprOpenGL->renderRect(&rect, color); + + xoff += PAD + BARW; + } +}
\ No newline at end of file diff --git a/src/render/decorations/CHyprGroupBarDecoration.hpp b/src/render/decorations/CHyprGroupBarDecoration.hpp new file mode 100644 index 00000000..74a597a6 --- /dev/null +++ b/src/render/decorations/CHyprGroupBarDecoration.hpp @@ -0,0 +1,30 @@ +#pragma once + +#include "IHyprWindowDecoration.hpp" +#include <deque> + +class CHyprGroupBarDecoration : public IHyprWindowDecoration { +public: + CHyprGroupBarDecoration(CWindow*); + virtual ~CHyprGroupBarDecoration(); + + virtual SWindowDecorationExtents getWindowDecorationExtents(); + + virtual void draw(SMonitor*); + + virtual eDecorationType getDecorationType(); + + virtual void updateWindow(CWindow*); + + virtual void damageEntire(); + +private: + SWindowDecorationExtents m_seExtents; + + CWindow* m_pWindow = nullptr; + + Vector2D m_vLastWindowPos; + Vector2D m_vLastWindowSize; + + std::deque<CWindow*> m_dwGroupMembers; +};
\ No newline at end of file diff --git a/src/render/decorations/IHyprWindowDecoration.cpp b/src/render/decorations/IHyprWindowDecoration.cpp new file mode 100644 index 00000000..ada71985 --- /dev/null +++ b/src/render/decorations/IHyprWindowDecoration.cpp @@ -0,0 +1,7 @@ +#include "IHyprWindowDecoration.hpp" + +#include "../../Window.hpp" + +IHyprWindowDecoration::~IHyprWindowDecoration() { + +}
\ No newline at end of file diff --git a/src/render/decorations/IHyprWindowDecoration.hpp b/src/render/decorations/IHyprWindowDecoration.hpp new file mode 100644 index 00000000..0815273d --- /dev/null +++ b/src/render/decorations/IHyprWindowDecoration.hpp @@ -0,0 +1,31 @@ +#pragma once + +#include "../../defines.hpp" + +enum eDecorationType { + DECORATION_NONE = -1, + DECORATION_GROUPBAR +}; + +struct SWindowDecorationExtents { + Vector2D topLeft; + Vector2D bottomRight; +}; + +class CWindow; +struct SMonitor; + +class IHyprWindowDecoration { +public: + virtual ~IHyprWindowDecoration() = 0; + + virtual SWindowDecorationExtents getWindowDecorationExtents() = 0; + + virtual void draw(SMonitor*) = 0; + + virtual eDecorationType getDecorationType() = 0; + + virtual void updateWindow(CWindow*) = 0; + + virtual void damageEntire() = 0; +};
\ No newline at end of file |
