hyprland-plugins/borders-plus-plus/borderDeco.cpp

109 lines
4.5 KiB
C++
Raw Normal View History

2023-02-27 16:24:28 +01:00
#include "borderDeco.hpp"
2023-02-27 20:54:53 +01:00
#include <hyprland/src/Compositor.hpp>
#include <hyprland/src/Window.hpp>
2023-02-27 16:24:28 +01:00
2023-02-27 20:54:53 +01:00
#include "globals.hpp"
2023-09-19 12:21:03 +02:00
CBordersPlusPlus::CBordersPlusPlus(CWindow* pWindow) : IHyprWindowDecoration(pWindow) {
2023-02-28 13:06:21 +01:00
m_vLastWindowPos = pWindow->m_vRealPosition.vec();
2023-02-27 16:24:28 +01:00
m_vLastWindowSize = pWindow->m_vRealSize.vec();
}
2023-02-28 13:06:21 +01:00
CBordersPlusPlus::~CBordersPlusPlus() {
damageEntire();
}
2023-02-27 16:24:28 +01:00
2023-02-28 13:06:21 +01:00
SWindowDecorationExtents CBordersPlusPlus::getWindowDecorationExtents() {
return m_seExtents;
}
2023-02-27 16:24:28 +01:00
void CBordersPlusPlus::draw(CMonitor* pMonitor, float a, const Vector2D& offset) {
2023-02-28 13:06:21 +01:00
if (!g_pCompositor->windowValidMapped(m_pWindow))
return;
2023-02-27 16:24:28 +01:00
2023-02-28 13:06:21 +01:00
if (!m_pWindow->m_sSpecialRenderData.decorate)
return;
2023-02-27 16:24:28 +01:00
2023-02-28 13:06:21 +01:00
static auto* const PCOLOR1 = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:borders-plus-plus:col.border_1")->intValue;
static auto* const PCOLOR2 = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:borders-plus-plus:col.border_2")->intValue;
static auto* const PBORDERS = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:borders-plus-plus:add_borders")->intValue;
static auto* const PROUNDING = &HyprlandAPI::getConfigValue(PHANDLE, "decoration:rounding")->intValue;
2023-02-27 16:24:28 +01:00
static auto* const PBORDERSIZE = &HyprlandAPI::getConfigValue(PHANDLE, "general:border_size")->intValue;
2023-02-28 13:06:21 +01:00
if (*PBORDERS < 1)
return;
2023-02-27 16:24:28 +01:00
2023-02-28 13:06:21 +01:00
const auto ROUNDING = !m_pWindow->m_sSpecialRenderData.rounding ?
0 :
(m_pWindow->m_sAdditionalConfigData.rounding.toUnderlying() == -1 ? *PROUNDING : m_pWindow->m_sAdditionalConfigData.rounding.toUnderlying());
2023-02-27 16:24:28 +01:00
// draw the border
2023-02-28 13:06:21 +01:00
wlr_box fullBox = {(int)(m_vLastWindowPos.x - *PBORDERSIZE), (int)(m_vLastWindowPos.y - *PBORDERSIZE), (int)(m_vLastWindowSize.x + 2.0 * *PBORDERSIZE),
(int)(m_vLastWindowSize.y + 2.0 * *PBORDERSIZE)};
2023-02-27 16:24:28 +01:00
fullBox.x -= pMonitor->vecPosition.x;
fullBox.y -= pMonitor->vecPosition.y;
2023-02-27 20:54:53 +01:00
m_seExtents = {{m_vLastWindowPos.x - fullBox.x - pMonitor->vecPosition.x + 2, m_vLastWindowPos.y - fullBox.y - pMonitor->vecPosition.y + 2},
{fullBox.x + fullBox.width + pMonitor->vecPosition.x - m_vLastWindowPos.x - m_vLastWindowSize.x + 2,
fullBox.y + fullBox.height + pMonitor->vecPosition.y - m_vLastWindowPos.y - m_vLastWindowSize.y + 2}};
2023-02-27 16:24:28 +01:00
fullBox.x += offset.x;
fullBox.y += offset.y;
2023-02-28 13:06:21 +01:00
if (fullBox.width < 1 || fullBox.height < 1)
return; // don't draw invisible shadows
2023-02-27 16:24:28 +01:00
g_pHyprOpenGL->scissor((wlr_box*)nullptr);
scaleBox(&fullBox, pMonitor->scale);
2023-03-13 02:32:39 +01:00
g_pHyprOpenGL->renderBorder(&fullBox, CColor(*PCOLOR1), *PROUNDING == 0 ? 0 : *PROUNDING * pMonitor->scale + *PBORDERSIZE * 2, a);
2023-02-27 16:24:28 +01:00
// pass 2
2023-02-28 13:06:21 +01:00
if (*PBORDERS < 2)
return;
2023-02-27 16:24:28 +01:00
2023-02-28 13:06:21 +01:00
fullBox = {(int)(m_vLastWindowPos.x - *PBORDERSIZE * 2), (int)(m_vLastWindowPos.y - *PBORDERSIZE * 2), (int)(m_vLastWindowSize.x + 2.0 * *PBORDERSIZE * 2),
(int)(m_vLastWindowSize.y + 2.0 * *PBORDERSIZE * 2)};
2023-02-27 16:24:28 +01:00
fullBox.x -= pMonitor->vecPosition.x;
fullBox.y -= pMonitor->vecPosition.y;
2023-02-27 20:54:53 +01:00
m_seExtents = {{m_vLastWindowPos.x - fullBox.x - pMonitor->vecPosition.x + 2, m_vLastWindowPos.y - fullBox.y - pMonitor->vecPosition.y + 2},
{fullBox.x + fullBox.width + pMonitor->vecPosition.x - m_vLastWindowPos.x - m_vLastWindowSize.x + 2,
fullBox.y + fullBox.height + pMonitor->vecPosition.y - m_vLastWindowPos.y - m_vLastWindowSize.y + 2}};
2023-02-27 16:24:28 +01:00
fullBox.x += offset.x;
fullBox.y += offset.y;
2023-02-28 13:06:21 +01:00
if (fullBox.width < 1 || fullBox.height < 1)
return; // don't draw invisible shadows
2023-02-27 16:24:28 +01:00
g_pHyprOpenGL->scissor((wlr_box*)nullptr);
scaleBox(&fullBox, pMonitor->scale);
2023-03-13 02:32:39 +01:00
g_pHyprOpenGL->renderBorder(&fullBox, CColor(*PCOLOR2), *PROUNDING == 0 ? 0 : *PROUNDING * pMonitor->scale + *PBORDERSIZE * 4, a);
2023-02-27 16:24:28 +01:00
}
2023-02-28 13:06:21 +01:00
eDecorationType CBordersPlusPlus::getDecorationType() {
return DECORATION_CUSTOM;
}
2023-02-27 16:24:28 +01:00
void CBordersPlusPlus::updateWindow(CWindow* pWindow) {
2023-02-28 13:06:21 +01:00
const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(pWindow->m_iWorkspaceID);
const auto WORKSPACEOFFSET = PWORKSPACE && !pWindow->m_bPinned ? PWORKSPACE->m_vRenderOffset.vec() : Vector2D();
m_vLastWindowPos = pWindow->m_vRealPosition.vec() + WORKSPACEOFFSET;
2023-02-27 16:24:28 +01:00
m_vLastWindowSize = pWindow->m_vRealSize.vec();
damageEntire();
}
void CBordersPlusPlus::damageEntire() {
2023-02-27 20:54:53 +01:00
wlr_box dm = {(int)(m_vLastWindowPos.x - m_seExtents.topLeft.x), (int)(m_vLastWindowPos.y - m_seExtents.topLeft.y),
(int)(m_vLastWindowSize.x + m_seExtents.topLeft.x + m_seExtents.bottomRight.x), (int)m_seExtents.topLeft.y};
2023-02-27 16:24:28 +01:00
g_pHyprRenderer->damageBox(&dm);
}