all: chase hyprland

This commit is contained in:
Vaxry 2024-04-27 13:03:46 +01:00
parent 8b0f67a8a6
commit 97e9d252ff
11 changed files with 105 additions and 92 deletions

View file

@ -5,7 +5,7 @@
#include "globals.hpp" #include "globals.hpp"
CBordersPlusPlus::CBordersPlusPlus(CWindow* pWindow) : IHyprWindowDecoration(pWindow), m_pWindow(pWindow) { CBordersPlusPlus::CBordersPlusPlus(PHLWINDOW pWindow) : IHyprWindowDecoration(pWindow), m_pWindow(pWindow) {
m_vLastWindowPos = pWindow->m_vRealPosition.value(); m_vLastWindowPos = pWindow->m_vRealPosition.value();
m_vLastWindowSize = pWindow->m_vRealSize.value(); m_vLastWindowSize = pWindow->m_vRealSize.value();
} }
@ -37,9 +37,8 @@ SDecorationPositioningInfo CBordersPlusPlus::getPositioningInfo() {
info.desiredExtents = {{size, size}, {size, size}}; info.desiredExtents = {{size, size}, {size, size}};
m_fLastThickness = size; m_fLastThickness = size;
} else { } else
info.desiredExtents = {{m_fLastThickness, m_fLastThickness}, {m_fLastThickness, m_fLastThickness}}; info.desiredExtents = {{m_fLastThickness, m_fLastThickness}, {m_fLastThickness, m_fLastThickness}};
}
return info; return info;
} }
@ -61,10 +60,12 @@ std::string CBordersPlusPlus::getDisplayName() {
} }
void CBordersPlusPlus::draw(CMonitor* pMonitor, float a) { void CBordersPlusPlus::draw(CMonitor* pMonitor, float a) {
if (!g_pCompositor->windowValidMapped(m_pWindow)) if (!validMapped(m_pWindow))
return; return;
if (!m_pWindow->m_sSpecialRenderData.decorate) const auto PWINDOW = m_pWindow.lock();
if (!PWINDOW->m_sSpecialRenderData.decorate)
return; return;
static std::vector<Hyprlang::INT* const*> PCOLORS; static std::vector<Hyprlang::INT* const*> PCOLORS;
@ -81,22 +82,17 @@ void CBordersPlusPlus::draw(CMonitor* pMonitor, float a) {
if (**PBORDERS < 1) if (**PBORDERS < 1)
return; return;
const auto PWORKSPACE = m_pWindow->m_pWorkspace; const auto PWORKSPACE = PWINDOW->m_pWorkspace;
const auto WORKSPACEOFFSET = PWORKSPACE && !m_pWindow->m_bPinned ? PWORKSPACE->m_vRenderOffset.value() : Vector2D(); const auto WORKSPACEOFFSET = PWORKSPACE && !PWINDOW->m_bPinned ? PWORKSPACE->m_vRenderOffset.value() : Vector2D();
auto rounding = m_pWindow->rounding() == 0 ? 0 : m_pWindow->rounding() * pMonitor->scale + **PBORDERSIZE; auto rounding = PWINDOW->rounding() == 0 ? 0 : PWINDOW->rounding() * pMonitor->scale + **PBORDERSIZE;
const auto ORIGINALROUND = rounding == 0 ? 0 : m_pWindow->rounding() * pMonitor->scale + **PBORDERSIZE; const auto ORIGINALROUND = rounding == 0 ? 0 : PWINDOW->rounding() * pMonitor->scale + **PBORDERSIZE;
CBox fullBox = {m_vLastWindowPos.x, m_vLastWindowPos.y, m_vLastWindowSize.x, m_vLastWindowSize.y}; CBox fullBox = {m_vLastWindowPos.x, m_vLastWindowPos.y, m_vLastWindowSize.x, m_vLastWindowSize.y};
fullBox.translate(m_pWindow->m_vFloatingOffset - pMonitor->vecPosition + WORKSPACEOFFSET).scale(pMonitor->scale); fullBox.translate(PWINDOW->m_vFloatingOffset - pMonitor->vecPosition + WORKSPACEOFFSET).scale(pMonitor->scale).expand(**PBORDERSIZE * pMonitor->scale);
double fullThickness = 0; double fullThickness = 0;
fullBox.x -= **PBORDERSIZE * pMonitor->scale;
fullBox.y -= **PBORDERSIZE * pMonitor->scale;
fullBox.width += **PBORDERSIZE * 2 * pMonitor->scale;
fullBox.height += **PBORDERSIZE * 2 * pMonitor->scale;
for (size_t i = 0; i < **PBORDERS; ++i) { for (size_t i = 0; i < **PBORDERS; ++i) {
const int PREVBORDERSIZESCALED = i == 0 ? 0 : (**PSIZES[i - 1] == -1 ? **PBORDERSIZE : **(PSIZES[i - 1])) * pMonitor->scale; const int PREVBORDERSIZESCALED = i == 0 ? 0 : (**PSIZES[i - 1] == -1 ? **PBORDERSIZE : **(PSIZES[i - 1])) * pMonitor->scale;
const int THISBORDERSIZE = **(PSIZES[i]) == -1 ? **PBORDERSIZE : (**PSIZES[i]); const int THISBORDERSIZE = **(PSIZES[i]) == -1 ? **PBORDERSIZE : (**PSIZES[i]);
@ -122,6 +118,8 @@ void CBordersPlusPlus::draw(CMonitor* pMonitor, float a) {
m_seExtents = {{fullThickness, fullThickness}, {fullThickness, fullThickness}}; m_seExtents = {{fullThickness, fullThickness}, {fullThickness, fullThickness}};
m_bLastRelativeBox = CBox{0, 0, m_vLastWindowSize.x, m_vLastWindowSize.y}.expand(**PBORDERSIZE).addExtents(m_seExtents);
if (fullThickness != m_fLastThickness) { if (fullThickness != m_fLastThickness) {
m_fLastThickness = fullThickness; m_fLastThickness = fullThickness;
g_pDecorationPositioner->repositionDeco(this); g_pDecorationPositioner->repositionDeco(this);
@ -132,7 +130,7 @@ eDecorationType CBordersPlusPlus::getDecorationType() {
return DECORATION_CUSTOM; return DECORATION_CUSTOM;
} }
void CBordersPlusPlus::updateWindow(CWindow* pWindow) { void CBordersPlusPlus::updateWindow(PHLWINDOW pWindow) {
m_vLastWindowPos = pWindow->m_vRealPosition.value(); m_vLastWindowPos = pWindow->m_vRealPosition.value();
m_vLastWindowSize = pWindow->m_vRealSize.value(); m_vLastWindowSize = pWindow->m_vRealSize.value();
@ -140,7 +138,6 @@ void CBordersPlusPlus::updateWindow(CWindow* pWindow) {
} }
void CBordersPlusPlus::damageEntire() { void CBordersPlusPlus::damageEntire() {
CBox dm = {(int)(m_vLastWindowPos.x - m_seExtents.topLeft.x), (int)(m_vLastWindowPos.y - m_seExtents.topLeft.y), CBox dm = m_bLastRelativeBox.copy().translate(m_vLastWindowPos).expand(2);
(int)(m_vLastWindowSize.x + m_seExtents.topLeft.x + m_seExtents.bottomRight.x), (int)m_seExtents.topLeft.y};
g_pHyprRenderer->damageBox(&dm); g_pHyprRenderer->damageBox(&dm);
} }

View file

@ -6,7 +6,7 @@
class CBordersPlusPlus : public IHyprWindowDecoration { class CBordersPlusPlus : public IHyprWindowDecoration {
public: public:
CBordersPlusPlus(CWindow*); CBordersPlusPlus(PHLWINDOW);
virtual ~CBordersPlusPlus(); virtual ~CBordersPlusPlus();
virtual SDecorationPositioningInfo getPositioningInfo(); virtual SDecorationPositioningInfo getPositioningInfo();
@ -17,7 +17,7 @@ class CBordersPlusPlus : public IHyprWindowDecoration {
virtual eDecorationType getDecorationType(); virtual eDecorationType getDecorationType();
virtual void updateWindow(CWindow*); virtual void updateWindow(PHLWINDOW);
virtual void damageEntire(); virtual void damageEntire();
@ -30,7 +30,9 @@ class CBordersPlusPlus : public IHyprWindowDecoration {
private: private:
SWindowDecorationExtents m_seExtents; SWindowDecorationExtents m_seExtents;
CWindow* m_pWindow = nullptr; PHLWINDOWREF m_pWindow;
CBox m_bLastRelativeBox;
Vector2D m_vLastWindowPos; Vector2D m_vLastWindowPos;
Vector2D m_vLastWindowSize; Vector2D m_vLastWindowSize;

View file

@ -17,7 +17,7 @@ APICALL EXPORT std::string PLUGIN_API_VERSION() {
void onNewWindow(void* self, std::any data) { void onNewWindow(void* self, std::any data) {
// data is guaranteed // data is guaranteed
auto* const PWINDOW = std::any_cast<CWindow*>(data); const auto PWINDOW = std::any_cast<PHLWINDOW>(data);
HyprlandAPI::addWindowDecoration(PHANDLE, PWINDOW, std::make_unique<CBordersPlusPlus>(PWINDOW)); HyprlandAPI::addWindowDecoration(PHANDLE, PWINDOW, std::make_unique<CBordersPlusPlus>(PWINDOW));
} }
@ -50,7 +50,7 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
if (w->isHidden() || !w->m_bIsMapped) if (w->isHidden() || !w->m_bIsMapped)
continue; continue;
HyprlandAPI::addWindowDecoration(PHANDLE, w.get(), std::make_unique<CBordersPlusPlus>(w.get())); HyprlandAPI::addWindowDecoration(PHANDLE, w, std::make_unique<CBordersPlusPlus>(w));
} }
HyprlandAPI::addNotification(PHANDLE, "[borders-plus-plus] Initialized successfully!", CColor{0.2, 1.0, 0.2, 1.0}, 5000); HyprlandAPI::addNotification(PHANDLE, "[borders-plus-plus] Initialized successfully!", CColor{0.2, 1.0, 0.2, 1.0}, 5000);

View file

@ -28,10 +28,10 @@ void hkNotifyMotion(wlr_seat* wlr_seat, uint32_t time_msec, double sx, double sy
static auto* const RESY = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:csgo-vulkan-fix:res_h")->getDataStaticPtr(); static auto* const RESY = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:csgo-vulkan-fix:res_h")->getDataStaticPtr();
static auto* const PCLASS = (Hyprlang::STRING const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:csgo-vulkan-fix:class")->getDataStaticPtr(); static auto* const PCLASS = (Hyprlang::STRING const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:csgo-vulkan-fix:class")->getDataStaticPtr();
if (g_pCompositor->m_pLastWindow && g_pCompositor->m_pLastWindow->m_szInitialClass == *PCLASS && g_pCompositor->m_pLastMonitor) { if (!g_pCompositor->m_pLastWindow.expired() && g_pCompositor->m_pLastWindow.lock()->m_szInitialClass == *PCLASS && g_pCompositor->m_pLastMonitor) {
// fix the coords // fix the coords
sx *= (**RESX / g_pCompositor->m_pLastMonitor->vecSize.x) / g_pCompositor->m_pLastWindow->m_fX11SurfaceScaledBy; sx *= (**RESX / g_pCompositor->m_pLastMonitor->vecSize.x) / g_pCompositor->m_pLastWindow.lock()->m_fX11SurfaceScaledBy;
sy *= (**RESY / g_pCompositor->m_pLastMonitor->vecSize.y) / g_pCompositor->m_pLastWindow->m_fX11SurfaceScaledBy; sy *= (**RESY / g_pCompositor->m_pLastMonitor->vecSize.y) / g_pCompositor->m_pLastWindow.lock()->m_fX11SurfaceScaledBy;
} }
(*(origMotion)g_pMouseMotionHook->m_pOriginal)(wlr_seat, time_msec, sx, sy); (*(origMotion)g_pMouseMotionHook->m_pOriginal)(wlr_seat, time_msec, sx, sy);

View file

@ -6,7 +6,7 @@
#include "globals.hpp" #include "globals.hpp"
CHyprBar::CHyprBar(CWindow* pWindow) : IHyprWindowDecoration(pWindow) { CHyprBar::CHyprBar(PHLWINDOW pWindow) : IHyprWindowDecoration(pWindow) {
m_pWindow = pWindow; m_pWindow = pWindow;
const auto PMONITOR = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID); const auto PMONITOR = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID);
@ -51,9 +51,11 @@ std::string CHyprBar::getDisplayName() {
} }
void CHyprBar::onMouseDown(SCallbackInfo& info, wlr_pointer_button_event* e) { void CHyprBar::onMouseDown(SCallbackInfo& info, wlr_pointer_button_event* e) {
if (m_pWindow != g_pCompositor->m_pLastWindow) if (m_pWindow.lock() != g_pCompositor->m_pLastWindow.lock())
return; return;
const auto PWINDOW = m_pWindow.lock();
const auto COORDS = cursorRelativeToBar(); const auto COORDS = cursorRelativeToBar();
static auto* const PHEIGHT = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_height")->getDataStaticPtr(); static auto* const PHEIGHT = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_height")->getDataStaticPtr();
@ -67,7 +69,7 @@ void CHyprBar::onMouseDown(SCallbackInfo& info, wlr_pointer_button_event* e) {
if (m_bDraggingThis) { if (m_bDraggingThis) {
g_pKeybindManager->m_mDispatchers["mouse"]("0movewindow"); g_pKeybindManager->m_mDispatchers["mouse"]("0movewindow");
Debug::log(LOG, "[hyprbars] Dragging ended on {:x}", (uintptr_t)m_pWindow); Debug::log(LOG, "[hyprbars] Dragging ended on {:x}", (uintptr_t)PWINDOW.get());
} }
m_bDraggingThis = false; m_bDraggingThis = false;
@ -86,7 +88,7 @@ void CHyprBar::onMouseDown(SCallbackInfo& info, wlr_pointer_button_event* e) {
g_pKeybindManager->m_mDispatchers["mouse"]("0movewindow"); g_pKeybindManager->m_mDispatchers["mouse"]("0movewindow");
m_bDraggingThis = false; m_bDraggingThis = false;
Debug::log(LOG, "[hyprbars] Dragging ended on {:x}", (uintptr_t)m_pWindow); Debug::log(LOG, "[hyprbars] Dragging ended on {:x}", (uintptr_t)PWINDOW.get());
} }
m_bDragPending = false; m_bDragPending = false;
@ -94,8 +96,8 @@ void CHyprBar::onMouseDown(SCallbackInfo& info, wlr_pointer_button_event* e) {
return; return;
} }
if (m_pWindow->m_bIsFloating) if (PWINDOW->m_bIsFloating)
g_pCompositor->changeWindowZOrder(m_pWindow, true); g_pCompositor->changeWindowZOrder(PWINDOW, true);
info.cancelled = true; info.cancelled = true;
m_bCancelledDown = true; m_bCancelledDown = true;
@ -126,7 +128,7 @@ void CHyprBar::onMouseMove(Vector2D coords) {
g_pKeybindManager->m_mDispatchers["mouse"]("1movewindow"); g_pKeybindManager->m_mDispatchers["mouse"]("1movewindow");
m_bDraggingThis = true; m_bDraggingThis = true;
Debug::log(LOG, "[hyprbars] Dragging initiated on {:x}", (uintptr_t)m_pWindow); Debug::log(LOG, "[hyprbars] Dragging initiated on {:x}", (uintptr_t)m_pWindow.lock().get());
return; return;
} }
@ -200,7 +202,9 @@ void CHyprBar::renderBarTitle(const Vector2D& bufferSize, const float scale) {
const bool BUTTONSRIGHT = std::string{*PALIGNBUTTONS} != "left"; const bool BUTTONSRIGHT = std::string{*PALIGNBUTTONS} != "left";
const auto BORDERSIZE = m_pWindow->getRealBorderSize(); const auto PWINDOW = m_pWindow.lock();
const auto BORDERSIZE = PWINDOW->getRealBorderSize();
float buttonSizes = **PBARBUTTONPADDING; float buttonSizes = **PBARBUTTONPADDING;
for (auto& b : g_pGlobalState->buttons) { for (auto& b : g_pGlobalState->buttons) {
@ -377,10 +381,12 @@ void CHyprBar::renderBarButtonsText(CBox* barBox, const float scale, const float
} }
void CHyprBar::draw(CMonitor* pMonitor, float a) { void CHyprBar::draw(CMonitor* pMonitor, float a) {
if (!g_pCompositor->windowValidMapped(m_pWindow)) if (!validMapped(m_pWindow))
return; return;
if (!m_pWindow->m_sSpecialRenderData.decorate) const auto PWINDOW = m_pWindow.lock();
if (!PWINDOW->m_sSpecialRenderData.decorate)
return; return;
static auto* const PCOLOR = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_color")->getDataStaticPtr(); static auto* const PCOLOR = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_color")->getDataStaticPtr();
@ -396,10 +402,10 @@ void CHyprBar::draw(CMonitor* pMonitor, float a) {
return; return;
} }
const auto PWORKSPACE = m_pWindow->m_pWorkspace; const auto PWORKSPACE = PWINDOW->m_pWorkspace;
const auto WORKSPACEOFFSET = PWORKSPACE && !m_pWindow->m_bPinned ? PWORKSPACE->m_vRenderOffset.value() : Vector2D(); const auto WORKSPACEOFFSET = PWORKSPACE && !PWINDOW->m_bPinned ? PWORKSPACE->m_vRenderOffset.value() : Vector2D();
const auto ROUNDING = m_pWindow->rounding() + (*PPRECEDENCE ? 0 : m_pWindow->getRealBorderSize()); const auto ROUNDING = PWINDOW->rounding() + (*PPRECEDENCE ? 0 : PWINDOW->getRealBorderSize());
const auto scaledRounding = ROUNDING > 0 ? ROUNDING * pMonitor->scale - 2 /* idk why but otherwise it looks bad due to the gaps */ : 0; const auto scaledRounding = ROUNDING > 0 ? ROUNDING * pMonitor->scale - 2 /* idk why but otherwise it looks bad due to the gaps */ : 0;
@ -415,7 +421,7 @@ void CHyprBar::draw(CMonitor* pMonitor, float a) {
CBox titleBarBox = {DECOBOX.x - pMonitor->vecPosition.x, DECOBOX.y - pMonitor->vecPosition.y, DECOBOX.w, CBox titleBarBox = {DECOBOX.x - pMonitor->vecPosition.x, DECOBOX.y - pMonitor->vecPosition.y, DECOBOX.w,
DECOBOX.h + ROUNDING * 3 /* to fill the bottom cuz we can't disable rounding there */}; DECOBOX.h + ROUNDING * 3 /* to fill the bottom cuz we can't disable rounding there */};
titleBarBox.translate(m_pWindow->m_vFloatingOffset).scale(pMonitor->scale).round(); titleBarBox.translate(PWINDOW->m_vFloatingOffset).scale(pMonitor->scale).round();
if (titleBarBox.w < 1 || titleBarBox.h < 1) if (titleBarBox.w < 1 || titleBarBox.h < 1)
return; return;
@ -424,9 +430,9 @@ void CHyprBar::draw(CMonitor* pMonitor, float a) {
if (ROUNDING) { if (ROUNDING) {
// the +1 is a shit garbage temp fix until renderRect supports an alpha matte // the +1 is a shit garbage temp fix until renderRect supports an alpha matte
CBox windowBox = {m_pWindow->m_vRealPosition.value().x + m_pWindow->m_vFloatingOffset.x - pMonitor->vecPosition.x + 1, CBox windowBox = {PWINDOW->m_vRealPosition.value().x + PWINDOW->m_vFloatingOffset.x - pMonitor->vecPosition.x + 1,
m_pWindow->m_vRealPosition.value().y + m_pWindow->m_vFloatingOffset.y - pMonitor->vecPosition.y + 1, m_pWindow->m_vRealSize.value().x - 2, PWINDOW->m_vRealPosition.value().y + PWINDOW->m_vFloatingOffset.y - pMonitor->vecPosition.y + 1, PWINDOW->m_vRealSize.value().x - 2,
m_pWindow->m_vRealSize.value().y - 2}; PWINDOW->m_vRealSize.value().y - 2};
if (windowBox.w < 1 || windowBox.h < 1) if (windowBox.w < 1 || windowBox.h < 1)
return; return;
@ -452,8 +458,8 @@ void CHyprBar::draw(CMonitor* pMonitor, float a) {
g_pHyprOpenGL->renderRect(&titleBarBox, color, scaledRounding); g_pHyprOpenGL->renderRect(&titleBarBox, color, scaledRounding);
// render title // render title
if (**PENABLETITLE && (m_szLastTitle != m_pWindow->m_szTitle || m_bWindowSizeChanged || m_tTextTex.m_iTexID == 0)) { if (**PENABLETITLE && (m_szLastTitle != PWINDOW->m_szTitle || m_bWindowSizeChanged || m_tTextTex.m_iTexID == 0)) {
m_szLastTitle = m_pWindow->m_szTitle; m_szLastTitle = PWINDOW->m_szTitle;
renderBarTitle(BARBUF, pMonitor->scale); renderBarTitle(BARBUF, pMonitor->scale);
} }
@ -485,7 +491,7 @@ void CHyprBar::draw(CMonitor* pMonitor, float a) {
// dynamic updates change the extents // dynamic updates change the extents
if (m_iLastHeight != **PHEIGHT) { if (m_iLastHeight != **PHEIGHT) {
g_pLayoutManager->getCurrentLayout()->recalculateWindow(m_pWindow); g_pLayoutManager->getCurrentLayout()->recalculateWindow(PWINDOW);
m_iLastHeight = **PHEIGHT; m_iLastHeight = **PHEIGHT;
} }
} }
@ -494,7 +500,7 @@ eDecorationType CHyprBar::getDecorationType() {
return DECORATION_CUSTOM; return DECORATION_CUSTOM;
} }
void CHyprBar::updateWindow(CWindow* pWindow) { void CHyprBar::updateWindow(PHLWINDOW pWindow) {
damageEntire(); damageEntire();
} }
@ -516,15 +522,17 @@ uint64_t CHyprBar::getDecorationFlags() {
} }
CBox CHyprBar::assignedBoxGlobal() { CBox CHyprBar::assignedBoxGlobal() {
CBox box = m_bAssignedBox; const auto PWINDOW = m_pWindow.lock();
box.translate(g_pDecorationPositioner->getEdgeDefinedPoint(DECORATION_EDGE_TOP, m_pWindow));
const auto PWORKSPACE = m_pWindow->m_pWorkspace; CBox box = m_bAssignedBox;
const auto WORKSPACEOFFSET = PWORKSPACE && !m_pWindow->m_bPinned ? PWORKSPACE->m_vRenderOffset.value() : Vector2D(); box.translate(g_pDecorationPositioner->getEdgeDefinedPoint(DECORATION_EDGE_TOP, PWINDOW));
const auto PWORKSPACE = PWINDOW->m_pWorkspace;
const auto WORKSPACEOFFSET = PWORKSPACE && !PWINDOW->m_bPinned ? PWORKSPACE->m_vRenderOffset.value() : Vector2D();
return box.translate(WORKSPACEOFFSET); return box.translate(WORKSPACEOFFSET);
} }
CWindow* CHyprBar::getOwner() { PHLWINDOW CHyprBar::getOwner() {
return m_pWindow; return m_pWindow.lock();
} }

View file

@ -8,7 +8,7 @@
class CHyprBar : public IHyprWindowDecoration { class CHyprBar : public IHyprWindowDecoration {
public: public:
CHyprBar(CWindow*); CHyprBar(PHLWINDOW);
virtual ~CHyprBar(); virtual ~CHyprBar();
virtual SDecorationPositioningInfo getPositioningInfo(); virtual SDecorationPositioningInfo getPositioningInfo();
@ -19,7 +19,7 @@ class CHyprBar : public IHyprWindowDecoration {
virtual eDecorationType getDecorationType(); virtual eDecorationType getDecorationType();
virtual void updateWindow(CWindow*); virtual void updateWindow(PHLWINDOW);
virtual void damageEntire(); virtual void damageEntire();
@ -31,12 +31,12 @@ class CHyprBar : public IHyprWindowDecoration {
virtual std::string getDisplayName(); virtual std::string getDisplayName();
CWindow* getOwner(); PHLWINDOW getOwner();
private: private:
SWindowDecorationExtents m_seExtents; SWindowDecorationExtents m_seExtents;
CWindow* m_pWindow = nullptr; PHLWINDOWREF m_pWindow;
CBox m_bAssignedBox; CBox m_bAssignedBox;

View file

@ -17,7 +17,7 @@ APICALL EXPORT std::string PLUGIN_API_VERSION() {
static void onNewWindow(void* self, std::any data) { static void onNewWindow(void* self, std::any data) {
// data is guaranteed // data is guaranteed
auto* const PWINDOW = std::any_cast<CWindow*>(data); const auto PWINDOW = std::any_cast<PHLWINDOW>(data);
if (!PWINDOW->m_bX11DoesntWantBorders) { if (!PWINDOW->m_bX11DoesntWantBorders) {
std::unique_ptr<CHyprBar> bar = std::make_unique<CHyprBar>(PWINDOW); std::unique_ptr<CHyprBar> bar = std::make_unique<CHyprBar>(PWINDOW);
@ -28,7 +28,7 @@ static void onNewWindow(void* self, std::any data) {
static void onCloseWindow(void* self, std::any data) { static void onCloseWindow(void* self, std::any data) {
// data is guaranteed // data is guaranteed
auto* const PWINDOW = std::any_cast<CWindow*>(data); const auto PWINDOW = std::any_cast<PHLWINDOW>(data);
const auto BARIT = std::find_if(g_pGlobalState->bars.begin(), g_pGlobalState->bars.end(), [PWINDOW](const auto& bar) { return bar->getOwner() == PWINDOW; }); const auto BARIT = std::find_if(g_pGlobalState->bars.begin(), g_pGlobalState->bars.end(), [PWINDOW](const auto& bar) { return bar->getOwner() == PWINDOW; });
@ -110,7 +110,7 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
if (w->isHidden() || !w->m_bIsMapped) if (w->isHidden() || !w->m_bIsMapped)
continue; continue;
onNewWindow(nullptr /* unused */, std::any(w.get())); onNewWindow(nullptr /* unused */, std::any(w));
} }
HyprlandAPI::reloadConfig(); HyprlandAPI::reloadConfig();

View file

@ -19,7 +19,7 @@ APICALL EXPORT std::string PLUGIN_API_VERSION() {
void onNewWindow(void* self, std::any data) { void onNewWindow(void* self, std::any data) {
// data is guaranteed // data is guaranteed
auto* const PWINDOW = std::any_cast<CWindow*>(data); const auto PWINDOW = std::any_cast<PHLWINDOW>(data);
HyprlandAPI::addWindowDecoration(PHANDLE, PWINDOW, std::make_unique<CTrail>(PWINDOW)); HyprlandAPI::addWindowDecoration(PHANDLE, PWINDOW, std::make_unique<CTrail>(PWINDOW));
} }
@ -116,7 +116,7 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprtrails:history_step", Hyprlang::INT{2}); HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprtrails:history_step", Hyprlang::INT{2});
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprtrails:color", Hyprlang::INT{configStringToInt("rgba(ffaa00ff)")}); HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprtrails:color", Hyprlang::INT{configStringToInt("rgba(ffaa00ff)")});
HyprlandAPI::registerCallbackDynamic(PHANDLE, "openWindow", [&](void* self, SCallbackInfo& info, std::any data) { onNewWindow(self, data); }); static auto P = HyprlandAPI::registerCallbackDynamic(PHANDLE, "openWindow", [&](void* self, SCallbackInfo& info, std::any data) { onNewWindow(self, data); });
g_pGlobalState = std::make_unique<SGlobalState>(); g_pGlobalState = std::make_unique<SGlobalState>();
initGlobal(); initGlobal();
@ -126,7 +126,7 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
if (w->isHidden() || !w->m_bIsMapped) if (w->isHidden() || !w->m_bIsMapped)
continue; continue;
HyprlandAPI::addWindowDecoration(PHANDLE, w.get(), std::make_unique<CTrail>(w.get())); HyprlandAPI::addWindowDecoration(PHANDLE, w, std::make_unique<CTrail>(w));
} }
HyprlandAPI::reloadConfig(); HyprlandAPI::reloadConfig();

View file

@ -11,9 +11,11 @@ void CTrail::onTick() {
m_iTimer++; m_iTimer++;
const auto PWINDOW = m_pWindow.lock();
if (m_iTimer > **PHISTORYSTEP) { if (m_iTimer > **PHISTORYSTEP) {
m_dLastGeoms.push_front({box{(float)m_pWindow->m_vRealPosition.value().x, (float)m_pWindow->m_vRealPosition.value().y, (float)m_pWindow->m_vRealSize.value().x, m_dLastGeoms.push_front({box{(float)PWINDOW->m_vRealPosition.value().x, (float)PWINDOW->m_vRealPosition.value().y, (float)PWINDOW->m_vRealSize.value().x,
(float)m_pWindow->m_vRealSize.value().y}, (float)PWINDOW->m_vRealSize.value().y},
std::chrono::system_clock::now()}); std::chrono::system_clock::now()});
while (m_dLastGeoms.size() > **PHISTORYPOINTS) while (m_dLastGeoms.size() > **PHISTORYPOINTS)
m_dLastGeoms.pop_back(); m_dLastGeoms.pop_back();
@ -27,7 +29,7 @@ void CTrail::onTick() {
} }
} }
CTrail::CTrail(CWindow* pWindow) : IHyprWindowDecoration(pWindow), m_pWindow(pWindow) { CTrail::CTrail(PHLWINDOW pWindow) : IHyprWindowDecoration(pWindow), m_pWindow(pWindow) {
m_vLastWindowPos = pWindow->m_vRealPosition.value(); m_vLastWindowPos = pWindow->m_vRealPosition.value();
m_vLastWindowSize = pWindow->m_vRealSize.value(); m_vLastWindowSize = pWindow->m_vRealSize.value();
@ -77,10 +79,12 @@ Vector2D vecForBezierT(const float& t, const std::vector<Vector2D>& verts) {
} }
void CTrail::draw(CMonitor* pMonitor, float a) { void CTrail::draw(CMonitor* pMonitor, float a) {
if (!g_pCompositor->windowValidMapped(m_pWindow)) if (!validMapped(m_pWindow))
return; return;
if (!m_pWindow->m_sSpecialRenderData.decorate) const auto PWINDOW = m_pWindow.lock();
if (!PWINDOW->m_sSpecialRenderData.decorate)
return; return;
static auto* const PBEZIERSTEP = (Hyprlang::FLOAT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprtrails:bezier_step")->getDataStaticPtr(); static auto* const PBEZIERSTEP = (Hyprlang::FLOAT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprtrails:bezier_step")->getDataStaticPtr();
@ -92,8 +96,8 @@ void CTrail::draw(CMonitor* pMonitor, float a) {
if (m_dLastGeoms.size() < 2) if (m_dLastGeoms.size() < 2)
return; return;
box thisbox = box{(float)m_pWindow->m_vRealPosition.value().x, (float)m_pWindow->m_vRealPosition.value().y, (float)m_pWindow->m_vRealSize.value().x, box thisbox =
(float)m_pWindow->m_vRealSize.value().y}; box{(float)PWINDOW->m_vRealPosition.value().x, (float)PWINDOW->m_vRealPosition.value().y, (float)PWINDOW->m_vRealSize.value().x, (float)PWINDOW->m_vRealSize.value().y};
CBox wlrbox = {thisbox.x - pMonitor->vecPosition.x, thisbox.y - pMonitor->vecPosition.y, thisbox.w, thisbox.h}; CBox wlrbox = {thisbox.x - pMonitor->vecPosition.x, thisbox.y - pMonitor->vecPosition.y, thisbox.w, thisbox.h};
wlrbox.scale(pMonitor->scale).round(); wlrbox.scale(pMonitor->scale).round();
@ -107,7 +111,7 @@ void CTrail::draw(CMonitor* pMonitor, float a) {
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
g_pHyprOpenGL->renderRect(&wlrbox, CColor(0, 0, 0, 0), m_pWindow->rounding() * pMonitor->scale); g_pHyprOpenGL->renderRect(&wlrbox, CColor(0, 0, 0, 0), PWINDOW->rounding() * pMonitor->scale);
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glStencilFunc(GL_NOTEQUAL, 1, -1); glStencilFunc(GL_NOTEQUAL, 1, -1);
@ -154,7 +158,7 @@ void CTrail::draw(CMonitor* pMonitor, float a) {
float dists[2] = {0, 0}; float dists[2] = {0, 0};
Vector2D mainVec = {originalCoeff / pMonitor->vecSize.x, originalCoeff / pMonitor->vecSize.y}; Vector2D mainVec = {originalCoeff / pMonitor->vecSize.x, originalCoeff / pMonitor->vecSize.y};
Vector2D windowMiddle = m_pWindow->middle() - pMonitor->vecPosition; Vector2D windowMiddle = PWINDOW->middle() - pMonitor->vecPosition;
points.push_back( points.push_back(
Vector2D{cos(0) * mainVec.x - sin(0) * mainVec.y + windowMiddle.x / pMonitor->vecSize.x, sin(0) * mainVec.x + cos(0) * mainVec.y + windowMiddle.y / pMonitor->vecSize.y}); Vector2D{cos(0) * mainVec.x - sin(0) * mainVec.y + windowMiddle.x / pMonitor->vecSize.x, sin(0) * mainVec.x + cos(0) * mainVec.y + windowMiddle.y / pMonitor->vecSize.y});
@ -237,10 +241,10 @@ void CTrail::draw(CMonitor* pMonitor, float a) {
} }
} }
box thisboxopengl = box{(m_pWindow->m_vRealPosition.value().x - pMonitor->vecPosition.x) / pMonitor->vecSize.x, box thisboxopengl = box{(PWINDOW->m_vRealPosition.value().x - pMonitor->vecPosition.x) / pMonitor->vecSize.x,
(m_pWindow->m_vRealPosition.value().y - pMonitor->vecPosition.y) / pMonitor->vecSize.y, (PWINDOW->m_vRealPosition.value().y - pMonitor->vecPosition.y) / pMonitor->vecSize.y,
(m_pWindow->m_vRealPosition.value().x + m_pWindow->m_vRealSize.value().x) / pMonitor->vecSize.x, (PWINDOW->m_vRealPosition.value().x + PWINDOW->m_vRealSize.value().x) / pMonitor->vecSize.x,
(m_pWindow->m_vRealPosition.value().y + m_pWindow->m_vRealSize.value().y) / pMonitor->vecSize.y}; (PWINDOW->m_vRealPosition.value().y + PWINDOW->m_vRealSize.value().y) / pMonitor->vecSize.y};
glUniform4f(g_pGlobalState->trailShader.gradient, thisboxopengl.x, thisboxopengl.y, thisboxopengl.w, thisboxopengl.h); glUniform4f(g_pGlobalState->trailShader.gradient, thisboxopengl.x, thisboxopengl.y, thisboxopengl.w, thisboxopengl.h);
glUniform4f(g_pGlobalState->trailShader.color, COLOR.r, COLOR.g, COLOR.b, COLOR.a); glUniform4f(g_pGlobalState->trailShader.color, COLOR.r, COLOR.g, COLOR.b, COLOR.a);
@ -315,7 +319,7 @@ eDecorationType CTrail::getDecorationType() {
return DECORATION_CUSTOM; return DECORATION_CUSTOM;
} }
void CTrail::updateWindow(CWindow* pWindow) { void CTrail::updateWindow(PHLWINDOW pWindow) {
const auto PWORKSPACE = pWindow->m_pWorkspace; const auto PWORKSPACE = pWindow->m_pWorkspace;
const auto WORKSPACEOFFSET = PWORKSPACE && !pWindow->m_bPinned ? PWORKSPACE->m_vRenderOffset.value() : Vector2D(); const auto WORKSPACEOFFSET = PWORKSPACE && !pWindow->m_bPinned ? PWORKSPACE->m_vRenderOffset.value() : Vector2D();

View file

@ -30,7 +30,7 @@ struct point2 {
class CTrail : public IHyprWindowDecoration { class CTrail : public IHyprWindowDecoration {
public: public:
CTrail(CWindow*); CTrail(PHLWINDOW);
virtual ~CTrail(); virtual ~CTrail();
virtual SDecorationPositioningInfo getPositioningInfo(); virtual SDecorationPositioningInfo getPositioningInfo();
@ -41,7 +41,7 @@ class CTrail : public IHyprWindowDecoration {
virtual eDecorationType getDecorationType(); virtual eDecorationType getDecorationType();
virtual void updateWindow(CWindow*); virtual void updateWindow(PHLWINDOW);
virtual void damageEntire(); virtual void damageEntire();
@ -55,7 +55,7 @@ class CTrail : public IHyprWindowDecoration {
SWindowDecorationExtents m_seExtents; SWindowDecorationExtents m_seExtents;
CWindow* m_pWindow = nullptr; PHLWINDOWREF m_pWindow;
Vector2D m_vLastWindowPos; Vector2D m_vLastWindowPos;
Vector2D m_vLastWindowSize; Vector2D m_vLastWindowSize;

View file

@ -26,10 +26,10 @@ inline CFunctionHook* commitHook = nullptr;
typedef void (*origCommitSubsurface)(CSubsurface* thisptr); typedef void (*origCommitSubsurface)(CSubsurface* thisptr);
typedef void (*origCommit)(void* owner, void* data); typedef void (*origCommit)(void* owner, void* data);
std::vector<CWindow*> bgWindows; std::vector<PHLWINDOWREF> bgWindows;
// //
void onNewWindow(CWindow* pWindow) { void onNewWindow(PHLWINDOW pWindow) {
static auto* const PCLASS = (Hyprlang::STRING const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprwinwrap:class")->getDataStaticPtr(); static auto* const PCLASS = (Hyprlang::STRING const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprwinwrap:class")->getDataStaticPtr();
if (pWindow->m_szInitialClass != *PCLASS) if (pWindow->m_szInitialClass != *PCLASS)
@ -59,8 +59,8 @@ void onNewWindow(CWindow* pWindow) {
Debug::log(LOG, "[hyprwinwrap] new window moved to bg {}", pWindow); Debug::log(LOG, "[hyprwinwrap] new window moved to bg {}", pWindow);
} }
void onCloseWindow(CWindow* pWindow) { void onCloseWindow(PHLWINDOW pWindow) {
std::erase(bgWindows, pWindow); std::erase_if(bgWindows, [pWindow](const auto& ref) { return ref.expired() || ref.lock() == pWindow; });
Debug::log(LOG, "[hyprwinwrap] closed window {}", pWindow); Debug::log(LOG, "[hyprwinwrap] closed window {}", pWindow);
} }
@ -69,7 +69,9 @@ void onRenderStage(eRenderStage stage) {
if (stage != RENDER_PRE_WINDOWS) if (stage != RENDER_PRE_WINDOWS)
return; return;
for (auto& bgw : bgWindows) { for (auto& bg : bgWindows) {
const auto bgw = bg.lock();
if (bgw->m_iMonitorID != g_pHyprOpenGL->m_RenderData.pMonitor->ID) if (bgw->m_iMonitorID != g_pHyprOpenGL->m_RenderData.pMonitor->ID)
continue; continue;
@ -88,7 +90,7 @@ void onRenderStage(eRenderStage stage) {
void onCommitSubsurface(CSubsurface* thisptr) { void onCommitSubsurface(CSubsurface* thisptr) {
const auto PWINDOW = thisptr->m_sWLSurface.getWindow(); const auto PWINDOW = thisptr->m_sWLSurface.getWindow();
if (!PWINDOW || std::find(bgWindows.begin(), bgWindows.end(), PWINDOW) == bgWindows.end()) { if (!PWINDOW || std::find_if(bgWindows.begin(), bgWindows.end(), [PWINDOW](const auto& ref) { return ref.lock() == PWINDOW; }) == bgWindows.end()) {
((origCommitSubsurface)subsurfaceHook->m_pOriginal)(thisptr); ((origCommitSubsurface)subsurfaceHook->m_pOriginal)(thisptr);
return; return;
} }
@ -104,9 +106,9 @@ void onCommitSubsurface(CSubsurface* thisptr) {
} }
void onCommit(void* owner, void* data) { void onCommit(void* owner, void* data) {
const auto PWINDOW = (CWindow*)owner; const auto PWINDOW = ((CWindow*)owner)->m_pSelf.lock();
if (std::find(bgWindows.begin(), bgWindows.end(), PWINDOW) == bgWindows.end()) { if (std::find_if(bgWindows.begin(), bgWindows.end(), [PWINDOW](const auto& ref) { return ref.lock() == PWINDOW; }) == bgWindows.end()) {
((origCommit)commitHook->m_pOriginal)(owner, data); ((origCommit)commitHook->m_pOriginal)(owner, data);
return; return;
} }
@ -139,8 +141,8 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
} }
// clang-format off // clang-format off
static auto P = HyprlandAPI::registerCallbackDynamic(PHANDLE, "openWindow", [&](void* self, SCallbackInfo& info, std::any data) { onNewWindow(std::any_cast<CWindow*>(data)); }); static auto P = HyprlandAPI::registerCallbackDynamic(PHANDLE, "openWindow", [&](void* self, SCallbackInfo& info, std::any data) { onNewWindow(std::any_cast<PHLWINDOW>(data)); });
static auto P2 = HyprlandAPI::registerCallbackDynamic(PHANDLE, "closeWindow", [&](void* self, SCallbackInfo& info, std::any data) { onCloseWindow(std::any_cast<CWindow*>(data)); }); static auto P2 = HyprlandAPI::registerCallbackDynamic(PHANDLE, "closeWindow", [&](void* self, SCallbackInfo& info, std::any data) { onCloseWindow(std::any_cast<PHLWINDOW>(data)); });
static auto P3 = HyprlandAPI::registerCallbackDynamic(PHANDLE, "render", [&](void* self, SCallbackInfo& info, std::any data) { onRenderStage(std::any_cast<eRenderStage>(data)); }); static auto P3 = HyprlandAPI::registerCallbackDynamic(PHANDLE, "render", [&](void* self, SCallbackInfo& info, std::any data) { onRenderStage(std::any_cast<eRenderStage>(data)); });
static auto P4 = HyprlandAPI::registerCallbackDynamic(PHANDLE, "configReloaded", [&](void* self, SCallbackInfo& info, std::any data) { onConfigReloaded(); }); static auto P4 = HyprlandAPI::registerCallbackDynamic(PHANDLE, "configReloaded", [&](void* self, SCallbackInfo& info, std::any data) { onConfigReloaded(); });
// clang-format on // clang-format on