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

112 lines
4.1 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-10-10 21:13:15 +02:00
CBordersPlusPlus::CBordersPlusPlus(CWindow* pWindow) : IHyprWindowDecoration(pWindow), m_pWindow(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
SWindowDecorationExtents CBordersPlusPlus::getWindowDecorationReservedArea() {
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
static std::vector<int64_t*> PCOLORS;
static std::vector<int64_t*> PSIZES;
for (size_t i = 0; i < 9; ++i) {
PCOLORS.push_back(&HyprlandAPI::getConfigValue(PHANDLE, "plugin:borders-plus-plus:col.border_" + std::to_string(i + 1))->intValue);
PSIZES.push_back(&HyprlandAPI::getConfigValue(PHANDLE, "plugin:borders-plus-plus:border_size_" + std::to_string(i + 1))->intValue);
}
static auto* const PBORDERS = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:borders-plus-plus:add_borders")->intValue;
static auto* const PNATURALROUND = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:borders-plus-plus:natural_rounding")->intValue;
static auto* const PROUNDING = &HyprlandAPI::getConfigValue(PHANDLE, "decoration:rounding")->intValue;
static auto* const PBORDERSIZE = &HyprlandAPI::getConfigValue(PHANDLE, "general:border_size")->intValue;
2023-02-27 16:24:28 +01:00
2023-02-28 13:06:21 +01:00
if (*PBORDERS < 1)
return;
2023-02-27 16:24:28 +01:00
auto rounding = m_pWindow->rounding() * pMonitor->scale + *PBORDERSIZE;
const auto ORIGINALROUND = m_pWindow->rounding() * pMonitor->scale + *PBORDERSIZE;
wlr_box fullBox = {(int)m_vLastWindowPos.x, (int)m_vLastWindowPos.y, (int)m_vLastWindowSize.x, (int)m_vLastWindowSize.y};
2023-02-27 16:24:28 +01:00
fullBox.x -= pMonitor->vecPosition.x;
fullBox.y -= pMonitor->vecPosition.y;
fullBox.x += offset.x;
fullBox.y += offset.y;
double fullThickness = 0;
2023-02-27 16:24:28 +01:00
fullBox.x -= *PBORDERSIZE;
fullBox.y -= *PBORDERSIZE;
fullBox.width += *PBORDERSIZE * 2;
fullBox.height += *PBORDERSIZE * 2;
2023-02-27 16:24:28 +01:00
for (size_t i = 0; i < *PBORDERS; ++i) {
const int PREVBORDERSIZE = i == 0 ? 0 : (*PSIZES[i - 1] == -1 ? *PBORDERSIZE : *PSIZES[i - 1]);
const int THISBORDERSIZE = *PSIZES[i] == -1 ? *PBORDERSIZE : *PSIZES[i];
2023-02-27 16:24:28 +01:00
if (i != 0) {
rounding += PREVBORDERSIZE;
fullBox.x -= PREVBORDERSIZE;
fullBox.y -= PREVBORDERSIZE;
fullBox.width += PREVBORDERSIZE * 2;
fullBox.height += PREVBORDERSIZE * 2;
}
2023-02-27 16:24:28 +01:00
if (fullBox.width < 1 || fullBox.height < 1)
break;
2023-02-27 16:24:28 +01:00
g_pHyprOpenGL->scissor((wlr_box*)nullptr);
wlr_box saveBox = fullBox;
2023-02-27 16:24:28 +01:00
scaleBox(&fullBox, pMonitor->scale);
2023-02-27 16:24:28 +01:00
g_pHyprOpenGL->renderBorder(&fullBox, CColor{(uint64_t)*PCOLORS[i]}, *PNATURALROUND ? ORIGINALROUND : rounding, THISBORDERSIZE, a, *PNATURALROUND ? ORIGINALROUND : -1);
2023-02-27 16:24:28 +01:00
fullBox = saveBox;
2023-02-27 16:24:28 +01:00
fullThickness += THISBORDERSIZE;
}
2023-02-27 16:24:28 +01:00
m_seExtents = {{fullThickness, fullThickness}, {fullThickness, fullThickness}};
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);
}