internal: Window storage rework - part 1 (#5762)

* Window storage rework - part 1

* format

* remove useless include

* fix pch

* format

* fix crash in dwindle

* fix vram leak

* prefer .expired() for bool checks
This commit is contained in:
Vaxry 2024-04-27 12:43:12 +01:00 committed by GitHub
parent 25aec3ac8c
commit bca7804bb6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
72 changed files with 1416 additions and 1346 deletions

View file

@ -167,7 +167,7 @@ bool CHyprOpenGLImpl::passRequiresIntrospection(CMonitor* pMonitor) {
if (m_RenderData.pCurrentMonData->blurFBShouldRender)
return true;
if (pMonitor->solitaryClient)
if (!pMonitor->solitaryClient.expired())
return false;
for (auto& ls : pMonitor->m_aLayerSurfaceLayers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY]) {
@ -224,7 +224,7 @@ bool CHyprOpenGLImpl::passRequiresIntrospection(CMonitor* pMonitor) {
if (!w->m_bIsMapped || w->isHidden())
continue;
if (!g_pHyprRenderer->shouldRenderWindow(w.get()))
if (!g_pHyprRenderer->shouldRenderWindow(w))
continue;
if (w->popupsCount() > 0 && *PBLURPOPUPS)
@ -873,7 +873,7 @@ void CHyprOpenGLImpl::renderTextureInternalWithDamage(const CTexture& tex, CBox*
}
}
if (m_pCurrentWindow && m_pCurrentWindow->m_sAdditionalConfigData.forceRGBX)
if (m_pCurrentWindow.lock() && m_pCurrentWindow.lock()->m_sAdditionalConfigData.forceRGBX)
shader = &m_RenderData.pCurrentMonData->m_shRGBX;
glActiveTexture(GL_TEXTURE0);
@ -940,9 +940,9 @@ void CHyprOpenGLImpl::renderTextureInternalWithDamage(const CTexture& tex, CBox*
glUniform2f(shader->fullSize, FULLSIZE.x, FULLSIZE.y);
glUniform1f(shader->radius, round);
if (allowDim && m_pCurrentWindow && *PDIMINACTIVE) {
if (allowDim && m_pCurrentWindow.lock() && *PDIMINACTIVE) {
glUniform1i(shader->applyTint, 1);
const auto DIM = m_pCurrentWindow->m_fDimPercent.value();
const auto DIM = m_pCurrentWindow.lock()->m_fDimPercent.value();
glUniform3f(shader->tint, 1.f - DIM, 1.f - DIM, 1.f - DIM);
} else {
glUniform1i(shader->applyTint, 0);
@ -1333,14 +1333,14 @@ void CHyprOpenGLImpl::preRender(CMonitor* pMonitor) {
return;
// ignore if solitary present, nothing to blur
if (pMonitor->solitaryClient)
if (!pMonitor->solitaryClient.expired())
return;
// check if we need to update the blur fb
// if there are no windows that would benefit from it,
// we will ignore that the blur FB is dirty.
auto windowShouldBeBlurred = [&](CWindow* pWindow) -> bool {
auto windowShouldBeBlurred = [&](PHLWINDOW pWindow) -> bool {
if (!pWindow)
return false;
@ -1377,7 +1377,7 @@ void CHyprOpenGLImpl::preRender(CMonitor* pMonitor) {
if (w->m_pWorkspace == pMonitor->activeWorkspace && !w->isHidden() && w->m_bIsMapped && (!w->m_bIsFloating || *PBLURXRAY)) {
// check if window is valid
if (!windowShouldBeBlurred(w.get()))
if (!windowShouldBeBlurred(w))
continue;
hasWindows = true;
@ -1453,7 +1453,7 @@ bool CHyprOpenGLImpl::preBlurQueued() {
return !(!m_RenderData.pCurrentMonData->blurFBDirty || !*PBLURNEWOPTIMIZE || !*PBLUR || !m_RenderData.pCurrentMonData->blurFBShouldRender);
}
bool CHyprOpenGLImpl::shouldUseNewBlurOptimizations(SLayerSurface* pLayer, CWindow* pWindow) {
bool CHyprOpenGLImpl::shouldUseNewBlurOptimizations(SLayerSurface* pLayer, PHLWINDOW pWindow) {
static auto PBLURNEWOPTIMIZE = CConfigValue<Hyprlang::INT>("decoration:blur:new_optimizations");
static auto PBLURXRAY = CConfigValue<Hyprlang::INT>("decoration:blur:xray");
@ -1493,7 +1493,7 @@ void CHyprOpenGLImpl::renderTextureWithBlur(const CTexture& tex, CBox* pBox, flo
m_RenderData.renderModif.applyToRegion(texDamage);
if (*PBLURENABLED == 0 || (*PNOBLUROVERSIZED && m_RenderData.primarySurfaceUVTopLeft != Vector2D(-1, -1)) ||
(m_pCurrentWindow && (m_pCurrentWindow->m_sAdditionalConfigData.forceNoBlur || m_pCurrentWindow->m_sAdditionalConfigData.forceRGBX))) {
(m_pCurrentWindow.lock() && (m_pCurrentWindow.lock()->m_sAdditionalConfigData.forceNoBlur || m_pCurrentWindow.lock()->m_sAdditionalConfigData.forceRGBX))) {
renderTexture(tex, pBox, a, round, false, true);
return;
}
@ -1517,7 +1517,7 @@ void CHyprOpenGLImpl::renderTextureWithBlur(const CTexture& tex, CBox* pBox, flo
wlr_region_scale(inverseOpaque.pixman(), inverseOpaque.pixman(), m_RenderData.pMonitor->scale);
// vvv TODO: layered blur fbs?
const bool USENEWOPTIMIZE = shouldUseNewBlurOptimizations(m_pCurrentLayer, m_pCurrentWindow) && !blockBlurOptimization;
const bool USENEWOPTIMIZE = shouldUseNewBlurOptimizations(m_pCurrentLayer, m_pCurrentWindow.lock()) && !blockBlurOptimization;
CFramebuffer* POUTFB = nullptr;
if (!USENEWOPTIMIZE) {
@ -1590,7 +1590,7 @@ void CHyprOpenGLImpl::renderBorder(CBox* box, const CGradientValueData& grad, in
TRACY_GPU_ZONE("RenderBorder");
if (m_RenderData.damage.empty() || (m_pCurrentWindow && m_pCurrentWindow->m_sAdditionalConfigData.forceNoBorder))
if (m_RenderData.damage.empty() || (m_pCurrentWindow.lock() && m_pCurrentWindow.lock()->m_sAdditionalConfigData.forceNoBorder))
return;
CBox newBox = *box;
@ -1681,7 +1681,7 @@ void CHyprOpenGLImpl::renderBorder(CBox* box, const CGradientValueData& grad, in
blend(BLEND);
}
void CHyprOpenGLImpl::makeRawWindowSnapshot(CWindow* pWindow, CFramebuffer* pFramebuffer) {
void CHyprOpenGLImpl::makeRawWindowSnapshot(PHLWINDOW pWindow, CFramebuffer* pFramebuffer) {
// we trust the window is valid.
const auto PMONITOR = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID);
@ -1729,7 +1729,7 @@ void CHyprOpenGLImpl::makeRawWindowSnapshot(CWindow* pWindow, CFramebuffer* pFra
g_pHyprRenderer->endRender();
}
void CHyprOpenGLImpl::makeWindowSnapshot(CWindow* pWindow) {
void CHyprOpenGLImpl::makeWindowSnapshot(PHLWINDOW pWindow) {
// we trust the window is valid.
const auto PMONITOR = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID);
@ -1742,11 +1742,13 @@ void CHyprOpenGLImpl::makeWindowSnapshot(CWindow* pWindow) {
// we need to "damage" the entire monitor
// so that we render the entire window
// this is temporary, doesnt mess with the actual wlr damage
CRegion fakeDamage{0, 0, (int)PMONITOR->vecTransformedSize.x, (int)PMONITOR->vecTransformedSize.y};
CRegion fakeDamage{0, 0, (int)PMONITOR->vecTransformedSize.x, (int)PMONITOR->vecTransformedSize.y};
PHLWINDOWREF ref{pWindow};
g_pHyprRenderer->makeEGLCurrent();
const auto PFRAMEBUFFER = &m_mWindowFramebuffers[pWindow];
const auto PFRAMEBUFFER = &m_mWindowFramebuffers[ref];
PFRAMEBUFFER->alloc(PMONITOR->vecPixelSize.x, PMONITOR->vecPixelSize.y, PMONITOR->drmFormat);
@ -1819,46 +1821,45 @@ void CHyprOpenGLImpl::makeLayerSnapshot(SLayerSurface* pLayer) {
g_pHyprRenderer->m_bRenderingSnapshot = false;
}
void CHyprOpenGLImpl::renderSnapshot(CWindow** pWindow) {
void CHyprOpenGLImpl::renderSnapshot(PHLWINDOW pWindow) {
RASSERT(m_RenderData.pMonitor, "Tried to render snapshot rect without begin()!");
const auto PWINDOW = *pWindow;
static auto PDIMAROUND = CConfigValue<Hyprlang::FLOAT>("decoration:dim_around");
static auto PDIMAROUND = CConfigValue<Hyprlang::FLOAT>("decoration:dim_around");
auto it = m_mWindowFramebuffers.begin();
for (; it != m_mWindowFramebuffers.end(); it++) {
if (it->first == PWINDOW) {
break;
}
}
PHLWINDOWREF ref{pWindow};
if (it == m_mWindowFramebuffers.end() || !it->second.m_cTex.m_iTexID)
if (!m_mWindowFramebuffers.contains(ref))
return;
const auto PMONITOR = g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID);
const auto FBDATA = &m_mWindowFramebuffers.at(ref);
if (!FBDATA->m_cTex.m_iTexID)
return;
const auto PMONITOR = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID);
CBox windowBox;
// some mafs to figure out the correct box
// the originalClosedPos is relative to the monitor's pos
Vector2D scaleXY = Vector2D((PMONITOR->scale * PWINDOW->m_vRealSize.value().x / (PWINDOW->m_vOriginalClosedSize.x * PMONITOR->scale)),
(PMONITOR->scale * PWINDOW->m_vRealSize.value().y / (PWINDOW->m_vOriginalClosedSize.y * PMONITOR->scale)));
Vector2D scaleXY = Vector2D((PMONITOR->scale * pWindow->m_vRealSize.value().x / (pWindow->m_vOriginalClosedSize.x * PMONITOR->scale)),
(PMONITOR->scale * pWindow->m_vRealSize.value().y / (pWindow->m_vOriginalClosedSize.y * PMONITOR->scale)));
windowBox.width = PMONITOR->vecTransformedSize.x * scaleXY.x;
windowBox.height = PMONITOR->vecTransformedSize.y * scaleXY.y;
windowBox.x = ((PWINDOW->m_vRealPosition.value().x - PMONITOR->vecPosition.x) * PMONITOR->scale) - ((PWINDOW->m_vOriginalClosedPos.x * PMONITOR->scale) * scaleXY.x);
windowBox.y = ((PWINDOW->m_vRealPosition.value().y - PMONITOR->vecPosition.y) * PMONITOR->scale) - ((PWINDOW->m_vOriginalClosedPos.y * PMONITOR->scale) * scaleXY.y);
windowBox.x = ((pWindow->m_vRealPosition.value().x - PMONITOR->vecPosition.x) * PMONITOR->scale) - ((pWindow->m_vOriginalClosedPos.x * PMONITOR->scale) * scaleXY.x);
windowBox.y = ((pWindow->m_vRealPosition.value().y - PMONITOR->vecPosition.y) * PMONITOR->scale) - ((pWindow->m_vOriginalClosedPos.y * PMONITOR->scale) * scaleXY.y);
CRegion fakeDamage{0, 0, PMONITOR->vecTransformedSize.x, PMONITOR->vecTransformedSize.y};
if (*PDIMAROUND && (*pWindow)->m_sAdditionalConfigData.dimAround) {
if (*PDIMAROUND && pWindow->m_sAdditionalConfigData.dimAround) {
CBox monbox = {0, 0, g_pHyprOpenGL->m_RenderData.pMonitor->vecPixelSize.x, g_pHyprOpenGL->m_RenderData.pMonitor->vecPixelSize.y};
g_pHyprOpenGL->renderRect(&monbox, CColor(0, 0, 0, *PDIMAROUND * PWINDOW->m_fAlpha.value()));
g_pHyprOpenGL->renderRect(&monbox, CColor(0, 0, 0, *PDIMAROUND * pWindow->m_fAlpha.value()));
g_pHyprRenderer->damageMonitor(PMONITOR);
}
m_bEndFrame = true;
renderTextureInternalWithDamage(it->second.m_cTex, &windowBox, PWINDOW->m_fAlpha.value(), &fakeDamage, 0);
renderTextureInternalWithDamage(FBDATA->m_cTex, &windowBox, pWindow->m_fAlpha.value(), &fakeDamage, 0);
m_bEndFrame = false;
}
@ -1902,7 +1903,7 @@ void CHyprOpenGLImpl::renderSnapshot(SLayerSurface** pLayer) {
void CHyprOpenGLImpl::renderRoundedShadow(CBox* box, int round, int range, const CColor& color, float a) {
RASSERT(m_RenderData.pMonitor, "Tried to render shadow without begin()!");
RASSERT((box->width > 0 && box->height > 0), "Tried to render shadow with width/height < 0!");
RASSERT(m_pCurrentWindow, "Tried to render shadow without a window!");
RASSERT(m_pCurrentWindow.lock(), "Tried to render shadow without a window!");
if (m_RenderData.damage.empty())
return;

View file

@ -7,6 +7,7 @@
#include "../helpers/Region.hpp"
#include <list>
#include <unordered_map>
#include <map>
#include <cairo/cairo.h>
@ -151,12 +152,12 @@ class CHyprOpenGLImpl {
void blend(bool enabled);
void makeWindowSnapshot(CWindow*);
void makeRawWindowSnapshot(CWindow*, CFramebuffer*);
void makeWindowSnapshot(PHLWINDOW);
void makeRawWindowSnapshot(PHLWINDOW, CFramebuffer*);
void makeLayerSnapshot(SLayerSurface*);
void renderSnapshot(CWindow**);
void renderSnapshot(PHLWINDOW);
void renderSnapshot(SLayerSurface**);
bool shouldUseNewBlurOptimizations(SLayerSurface* pLayer, CWindow* pWindow);
bool shouldUseNewBlurOptimizations(SLayerSurface* pLayer, PHLWINDOW pWindow);
void clear(const CColor&);
void clearWithTex();
@ -192,13 +193,13 @@ class CHyprOpenGLImpl {
bool m_bReloadScreenShader = true; // at launch it can be set
CWindow* m_pCurrentWindow = nullptr; // hack to get the current rendered window
SLayerSurface* m_pCurrentLayer = nullptr; // hack to get the current rendered layer
PHLWINDOWREF m_pCurrentWindow; // hack to get the current rendered window
SLayerSurface* m_pCurrentLayer = nullptr; // hack to get the current rendered layer
std::unordered_map<CWindow*, CFramebuffer> m_mWindowFramebuffers;
std::unordered_map<SLayerSurface*, CFramebuffer> m_mLayerFramebuffers;
std::unordered_map<CMonitor*, SMonitorRenderData> m_mMonitorRenderResources;
std::unordered_map<CMonitor*, CFramebuffer> m_mMonitorBGFBs;
std::map<PHLWINDOWREF, CFramebuffer, std::owner_less<PHLWINDOWREF>> m_mWindowFramebuffers;
std::unordered_map<SLayerSurface*, CFramebuffer> m_mLayerFramebuffers;
std::unordered_map<CMonitor*, SMonitorRenderData> m_mMonitorRenderResources;
std::unordered_map<CMonitor*, CFramebuffer> m_mMonitorBGFBs;
struct {
PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC glEGLImageTargetRenderbufferStorageOES = nullptr;

View file

@ -86,7 +86,7 @@ CHyprRenderer::CHyprRenderer() {
static void renderSurface(struct wlr_surface* surface, int x, int y, void* data) {
const auto TEXTURE = wlr_surface_get_texture(surface);
const auto RDATA = (SRenderData*)data;
const auto INTERACTIVERESIZEINPROGRESS = RDATA->pWindow && g_pInputManager->currentlyDraggedWindow == RDATA->pWindow && g_pInputManager->dragMode == MBIND_RESIZE;
const auto INTERACTIVERESIZEINPROGRESS = RDATA->pWindow && g_pInputManager->currentlyDraggedWindow.lock() == RDATA->pWindow && g_pInputManager->dragMode == MBIND_RESIZE;
if (!TEXTURE)
return;
@ -214,7 +214,7 @@ static void renderSurface(struct wlr_surface* surface, int x, int y, void* data)
g_pHyprOpenGL->m_RenderData.useNearestNeighbor = NEARESTNEIGHBORSET;
}
bool CHyprRenderer::shouldRenderWindow(CWindow* pWindow, CMonitor* pMonitor) {
bool CHyprRenderer::shouldRenderWindow(PHLWINDOW pWindow, CMonitor* pMonitor) {
CBox geometry = pWindow->getFullWindowBoundingBox();
if (!wlr_output_layout_intersects(g_pCompositor->m_sWLROutputLayout, pMonitor->output, geometry.pWlr()))
@ -278,9 +278,9 @@ bool CHyprRenderer::shouldRenderWindow(CWindow* pWindow, CMonitor* pMonitor) {
return false;
}
bool CHyprRenderer::shouldRenderWindow(CWindow* pWindow) {
bool CHyprRenderer::shouldRenderWindow(PHLWINDOW pWindow) {
if (!g_pCompositor->windowValidMapped(pWindow))
if (!validMapped(pWindow))
return false;
const auto PWORKSPACE = pWindow->m_pWorkspace;
@ -306,13 +306,13 @@ bool CHyprRenderer::shouldRenderWindow(CWindow* pWindow) {
}
void CHyprRenderer::renderWorkspaceWindowsFullscreen(CMonitor* pMonitor, PHLWORKSPACE pWorkspace, timespec* time) {
CWindow* pWorkspaceWindow = nullptr;
PHLWINDOW pWorkspaceWindow = nullptr;
EMIT_HOOK_EVENT("render", RENDER_PRE_WINDOWS);
// loop over the tiled windows that are fading out
for (auto& w : g_pCompositor->m_vWindows) {
if (!shouldRenderWindow(w.get(), pMonitor))
if (!shouldRenderWindow(w, pMonitor))
continue;
if (w->m_fAlpha.value() == 0.f)
@ -324,12 +324,12 @@ void CHyprRenderer::renderWorkspaceWindowsFullscreen(CMonitor* pMonitor, PHLWORK
if (pWorkspace->m_bIsSpecialWorkspace != w->onSpecialWorkspace())
continue;
renderWindow(w.get(), pMonitor, time, true, RENDER_PASS_ALL);
renderWindow(w, pMonitor, time, true, RENDER_PASS_ALL);
}
// and floating ones too
for (auto& w : g_pCompositor->m_vWindows) {
if (!shouldRenderWindow(w.get(), pMonitor))
if (!shouldRenderWindow(w, pMonitor))
continue;
if (w->m_fAlpha.value() == 0.f)
@ -344,7 +344,7 @@ void CHyprRenderer::renderWorkspaceWindowsFullscreen(CMonitor* pMonitor, PHLWORK
if (pWorkspace->m_bIsSpecialWorkspace && w->m_iMonitorID != pWorkspace->m_iMonitorID)
continue; // special on another are rendered as a part of the base pass
renderWindow(w.get(), pMonitor, time, true, RENDER_PASS_ALL);
renderWindow(w, pMonitor, time, true, RENDER_PASS_ALL);
}
// TODO: this pass sucks
@ -365,13 +365,13 @@ void CHyprRenderer::renderWorkspaceWindowsFullscreen(CMonitor* pMonitor, PHLWORK
if (w->m_iMonitorID == pWorkspace->m_iMonitorID && pWorkspace->m_bIsSpecialWorkspace != w->onSpecialWorkspace())
continue;
if (shouldRenderWindow(w.get(), pMonitor))
renderWindow(w.get(), pMonitor, time, pWorkspace->m_efFullscreenMode != FULLSCREEN_FULL, RENDER_PASS_ALL);
if (shouldRenderWindow(w, pMonitor))
renderWindow(w, pMonitor, time, pWorkspace->m_efFullscreenMode != FULLSCREEN_FULL, RENDER_PASS_ALL);
if (w->m_pWorkspace != pWorkspace)
continue;
pWorkspaceWindow = w.get();
pWorkspaceWindow = w;
}
if (!pWorkspaceWindow) {
@ -391,12 +391,12 @@ void CHyprRenderer::renderWorkspaceWindowsFullscreen(CMonitor* pMonitor, PHLWORK
if (pWorkspace->m_bIsSpecialWorkspace && w->m_iMonitorID != pWorkspace->m_iMonitorID)
continue; // special on another are rendered as a part of the base pass
renderWindow(w.get(), pMonitor, time, true, RENDER_PASS_ALL);
renderWindow(w, pMonitor, time, true, RENDER_PASS_ALL);
}
}
void CHyprRenderer::renderWorkspaceWindows(CMonitor* pMonitor, PHLWORKSPACE pWorkspace, timespec* time) {
CWindow* lastWindow = nullptr;
PHLWINDOW lastWindow;
EMIT_HOOK_EVENT("render", RENDER_PRE_WINDOWS);
@ -408,20 +408,20 @@ void CHyprRenderer::renderWorkspaceWindows(CMonitor* pMonitor, PHLWORKSPACE pWor
if (w->m_bIsFloating)
continue; // floating are in the second pass
if (!shouldRenderWindow(w.get(), pMonitor))
if (!shouldRenderWindow(w, pMonitor))
continue;
if (pWorkspace->m_bIsSpecialWorkspace != w->onSpecialWorkspace())
continue;
// render active window after all others of this pass
if (w.get() == g_pCompositor->m_pLastWindow) {
lastWindow = w.get();
if (w == g_pCompositor->m_pLastWindow.lock()) {
lastWindow = w;
continue;
}
// render the bad boy
renderWindow(w.get(), pMonitor, time, true, RENDER_PASS_MAIN);
renderWindow(w, pMonitor, time, true, RENDER_PASS_MAIN);
}
if (lastWindow)
@ -438,11 +438,11 @@ void CHyprRenderer::renderWorkspaceWindows(CMonitor* pMonitor, PHLWORKSPACE pWor
if (pWorkspace->m_bIsSpecialWorkspace != w->onSpecialWorkspace())
continue;
if (!shouldRenderWindow(w.get(), pMonitor))
if (!shouldRenderWindow(w, pMonitor))
continue;
// render the bad boy
renderWindow(w.get(), pMonitor, time, true, RENDER_PASS_POPUP);
renderWindow(w, pMonitor, time, true, RENDER_PASS_POPUP);
}
// floating on top
@ -453,7 +453,7 @@ void CHyprRenderer::renderWorkspaceWindows(CMonitor* pMonitor, PHLWORKSPACE pWor
if (!w->m_bIsFloating || w->m_bPinned)
continue;
if (!shouldRenderWindow(w.get(), pMonitor))
if (!shouldRenderWindow(w, pMonitor))
continue;
if (pWorkspace->m_bIsSpecialWorkspace != w->onSpecialWorkspace())
@ -463,17 +463,17 @@ void CHyprRenderer::renderWorkspaceWindows(CMonitor* pMonitor, PHLWORKSPACE pWor
continue; // special on another are rendered as a part of the base pass
// render the bad boy
renderWindow(w.get(), pMonitor, time, true, RENDER_PASS_ALL);
renderWindow(w, pMonitor, time, true, RENDER_PASS_ALL);
}
}
void CHyprRenderer::renderWindow(CWindow* pWindow, CMonitor* pMonitor, timespec* time, bool decorate, eRenderPassMode mode, bool ignorePosition, bool ignoreAllGeometry) {
void CHyprRenderer::renderWindow(PHLWINDOW pWindow, CMonitor* pMonitor, timespec* time, bool decorate, eRenderPassMode mode, bool ignorePosition, bool ignoreAllGeometry) {
if (pWindow->isHidden())
return;
if (pWindow->m_bFadingOut) {
if (pMonitor->ID == pWindow->m_iMonitorID) // TODO: fix this
g_pHyprOpenGL->renderSnapshot(&pWindow);
g_pHyprOpenGL->renderSnapshot(pWindow);
return;
}
@ -658,7 +658,7 @@ void CHyprRenderer::renderWindow(CWindow* pWindow, CMonitor* pMonitor, timespec*
EMIT_HOOK_EVENT("render", RENDER_POST_WINDOW);
g_pHyprOpenGL->m_pCurrentWindow = nullptr;
g_pHyprOpenGL->m_pCurrentWindow.reset();
g_pHyprOpenGL->m_RenderData.clipBox = CBox();
}
@ -885,11 +885,11 @@ void CHyprRenderer::renderAllClientsForWorkspace(CMonitor* pMonitor, PHLWORKSPAC
if (!w->m_bPinned || !w->m_bIsFloating)
continue;
if (!shouldRenderWindow(w.get(), pMonitor))
if (!shouldRenderWindow(w, pMonitor))
continue;
// render the bad boy
renderWindow(w.get(), pMonitor, time, true, RENDER_PASS_ALL);
renderWindow(w, pMonitor, time, true, RENDER_PASS_ALL);
}
EMIT_HOOK_EVENT("render", RENDER_POST_WINDOWS);
@ -943,7 +943,7 @@ void CHyprRenderer::renderLockscreen(CMonitor* pMonitor, timespec* now, const CB
}
}
void CHyprRenderer::calculateUVForSurface(CWindow* pWindow, wlr_surface* pSurface, bool main, const Vector2D& projSize, bool fixMisalignedFSV1) {
void CHyprRenderer::calculateUVForSurface(PHLWINDOW pWindow, wlr_surface* pSurface, bool main, const Vector2D& projSize, bool fixMisalignedFSV1) {
if (!pWindow || !pWindow->m_bIsX11) {
Vector2D uvTL;
Vector2D uvBR = Vector2D(1, 1);
@ -1038,7 +1038,7 @@ bool CHyprRenderer::attemptDirectScanout(CMonitor* pMonitor) {
if (!wlr_output_is_direct_scanout_allowed(pMonitor->output))
return false;
const auto PCANDIDATE = pMonitor->solitaryClient;
const auto PCANDIDATE = pMonitor->solitaryClient.lock();
if (!PCANDIDATE)
return false;
@ -1060,12 +1060,12 @@ bool CHyprRenderer::attemptDirectScanout(CMonitor* pMonitor) {
wlr_presentation_surface_scanned_out_on_output(PSURFACE, pMonitor->output);
if (pMonitor->state.commit()) {
if (!m_pLastScanout) {
if (m_pLastScanout.expired()) {
m_pLastScanout = PCANDIDATE;
Debug::log(LOG, "Entered a direct scanout to {:x}: \"{}\"", (uintptr_t)PCANDIDATE, PCANDIDATE->m_szTitle);
Debug::log(LOG, "Entered a direct scanout to {:x}: \"{}\"", (uintptr_t)PCANDIDATE.get(), PCANDIDATE->m_szTitle);
}
} else {
m_pLastScanout = nullptr;
m_pLastScanout.reset();
return false;
}
@ -1171,16 +1171,16 @@ void CHyprRenderer::renderMonitor(CMonitor* pMonitor) {
return;
}
if (pMonitor->solitaryClient)
if (!pMonitor->solitaryClient.expired())
shouldTear = true;
}
if (!*PNODIRECTSCANOUT && !shouldTear) {
if (attemptDirectScanout(pMonitor)) {
return;
} else if (m_pLastScanout) {
} else if (!m_pLastScanout.expired()) {
Debug::log(LOG, "Left a direct scanout.");
m_pLastScanout = nullptr;
m_pLastScanout.reset();
}
}
@ -1285,7 +1285,7 @@ void CHyprRenderer::renderMonitor(CMonitor* pMonitor) {
bool renderCursor = true;
if (!finalDamage.empty()) {
if (!pMonitor->solitaryClient) {
if (pMonitor->solitaryClient.expired()) {
if (pMonitor->isMirror()) {
g_pHyprOpenGL->blend(false);
g_pHyprOpenGL->renderMirrored();
@ -1321,7 +1321,7 @@ void CHyprRenderer::renderMonitor(CMonitor* pMonitor) {
}
}
} else
g_pHyprRenderer->renderWindow(pMonitor->solitaryClient, pMonitor, &now, false, RENDER_PASS_MAIN /* solitary = no popups */);
g_pHyprRenderer->renderWindow(pMonitor->solitaryClient.lock(), pMonitor, &now, false, RENDER_PASS_MAIN /* solitary = no popups */);
} else {
sendFrameEventsToWorkspace(pMonitor, pMonitor->activeWorkspace, &now);
if (pMonitor->activeSpecialWorkspace)
@ -1426,7 +1426,7 @@ void CHyprRenderer::sendFrameEventsToWorkspace(CMonitor* pMonitor, PHLWORKSPACE
if (w->isHidden() || !w->m_bIsMapped || w->m_bFadingOut || !w->m_pWLSurface.wlr())
continue;
if (!shouldRenderWindow(w.get(), pMonitor))
if (!shouldRenderWindow(w, pMonitor))
continue;
wlr_surface_for_each_surface(
@ -1444,7 +1444,7 @@ void CHyprRenderer::sendFrameEventsToWorkspace(CMonitor* pMonitor, PHLWORKSPACE
}
}
void CHyprRenderer::setWindowScanoutMode(CWindow* pWindow) {
void CHyprRenderer::setWindowScanoutMode(PHLWINDOW pWindow) {
if (!g_pCompositor->m_sWLRLinuxDMABuf || g_pSessionLockManager->isSessionLocked())
return;
@ -1764,7 +1764,7 @@ void CHyprRenderer::damageSurface(wlr_surface* pSurface, double x, double y, dou
damageBox.pixman()->extents.x2 - damageBox.pixman()->extents.x1, damageBox.pixman()->extents.y2 - damageBox.pixman()->extents.y1);
}
void CHyprRenderer::damageWindow(CWindow* pWindow, bool forceFull) {
void CHyprRenderer::damageWindow(PHLWINDOW pWindow, bool forceFull) {
if (g_pCompositor->m_bUnsafeState)
return;
@ -2540,7 +2540,7 @@ bool CHyprRenderer::canSkipBackBufferClear(CMonitor* pMonitor) {
}
void CHyprRenderer::recheckSolitaryForMonitor(CMonitor* pMonitor) {
pMonitor->solitaryClient = nullptr; // reset it, if we find one it will be set.
pMonitor->solitaryClient.reset(); // reset it, if we find one it will be set.
if (g_pHyprNotificationOverlay->hasAny())
return;
@ -2572,7 +2572,7 @@ void CHyprRenderer::recheckSolitaryForMonitor(CMonitor* pMonitor) {
}
for (auto& w : g_pCompositor->m_vWindows) {
if (w.get() == PCANDIDATE || (!w->m_bIsMapped && !w->m_bFadingOut) || w->isHidden())
if (w == PCANDIDATE || (!w->m_bIsMapped && !w->m_bFadingOut) || w->isHidden())
continue;
if (w->m_pWorkspace == PCANDIDATE->m_pWorkspace && w->m_bIsFloating && w->m_bCreatedOverFullscreen && w->visibleOnMonitor(pMonitor))

View file

@ -46,19 +46,19 @@ class CHyprRenderer {
void outputMgrApplyTest(wlr_output_configuration_v1*, bool);
void arrangeLayersForMonitor(const int&);
void damageSurface(wlr_surface*, double, double, double scale = 1.0);
void damageWindow(CWindow*, bool forceFull = false);
void damageWindow(PHLWINDOW, bool forceFull = false);
void damageBox(CBox*);
void damageBox(const int& x, const int& y, const int& w, const int& h);
void damageRegion(const CRegion&);
void damageMonitor(CMonitor*);
void damageMirrorsWith(CMonitor*, const CRegion&);
bool applyMonitorRule(CMonitor*, SMonitorRule*, bool force = false);
bool shouldRenderWindow(CWindow*, CMonitor*);
bool shouldRenderWindow(CWindow*);
bool shouldRenderWindow(PHLWINDOW, CMonitor*);
bool shouldRenderWindow(PHLWINDOW);
void ensureCursorRenderingMode();
bool shouldRenderCursor();
void setCursorHidden(bool hide);
void calculateUVForSurface(CWindow*, wlr_surface*, bool main = false, const Vector2D& projSize = {}, bool fixMisalignedFSV1 = false);
void calculateUVForSurface(PHLWINDOW, wlr_surface*, bool main = false, const Vector2D& projSize = {}, bool fixMisalignedFSV1 = false);
std::tuple<float, float, float> getRenderTimes(CMonitor* pMonitor); // avg max min
void renderLockscreen(CMonitor* pMonitor, timespec* now, const CBox& geometry);
void setOccludedForBackLayers(CRegion& region, PHLWORKSPACE pWorkspace);
@ -76,21 +76,21 @@ class CHyprRenderer {
// if RENDER_MODE_NORMAL, provided damage will be written to.
// otherwise, it will be the one used.
bool beginRender(CMonitor* pMonitor, CRegion& damage, eRenderMode mode = RENDER_MODE_NORMAL, wlr_buffer* buffer = nullptr, CFramebuffer* fb = nullptr);
void endRender();
bool beginRender(CMonitor* pMonitor, CRegion& damage, eRenderMode mode = RENDER_MODE_NORMAL, wlr_buffer* buffer = nullptr, CFramebuffer* fb = nullptr);
void endRender();
bool m_bBlockSurfaceFeedback = false;
bool m_bRenderingSnapshot = false;
CWindow* m_pLastScanout = nullptr;
CMonitor* m_pMostHzMonitor = nullptr;
bool m_bDirectScanoutBlocked = false;
bool m_bSoftwareCursorsLocked = false;
bool m_bBlockSurfaceFeedback = false;
bool m_bRenderingSnapshot = false;
PHLWINDOWREF m_pLastScanout;
CMonitor* m_pMostHzMonitor = nullptr;
bool m_bDirectScanoutBlocked = false;
bool m_bSoftwareCursorsLocked = false;
DAMAGETRACKINGMODES
damageTrackingModeFromStr(const std::string&);
bool attemptDirectScanout(CMonitor*);
void setWindowScanoutMode(CWindow*);
void setWindowScanoutMode(PHLWINDOW);
void initiateManualCrash();
bool m_bCrashingInProgress = false;
@ -111,7 +111,7 @@ class CHyprRenderer {
void arrangeLayerArray(CMonitor*, const std::vector<std::unique_ptr<SLayerSurface>>&, bool, CBox*);
void renderWorkspaceWindowsFullscreen(CMonitor*, PHLWORKSPACE, timespec*); // renders workspace windows (fullscreen) (tiled, floating, pinned, but no special)
void renderWorkspaceWindows(CMonitor*, PHLWORKSPACE, timespec*); // renders workspace windows (no fullscreen) (tiled, floating, pinned, but no special)
void renderWindow(CWindow*, CMonitor*, timespec*, bool, eRenderPassMode, bool ignorePosition = false, bool ignoreAllGeometry = false);
void renderWindow(PHLWINDOW, CMonitor*, timespec*, bool, eRenderPassMode, bool ignorePosition = false, bool ignoreAllGeometry = false);
void renderLayer(SLayerSurface*, CMonitor*, timespec*, bool popups = false);
void renderSessionLockSurface(SSessionLockSurface*, CMonitor*, timespec*);
void renderDragIcon(CMonitor*, timespec*);

View file

@ -2,7 +2,7 @@
#include "../../Compositor.hpp"
#include "../../config/ConfigValue.hpp"
CHyprBorderDecoration::CHyprBorderDecoration(CWindow* pWindow) : IHyprWindowDecoration(pWindow) {
CHyprBorderDecoration::CHyprBorderDecoration(PHLWINDOW pWindow) : IHyprWindowDecoration(pWindow) {
m_pWindow = pWindow;
}
@ -11,7 +11,7 @@ CHyprBorderDecoration::~CHyprBorderDecoration() {
}
SDecorationPositioningInfo CHyprBorderDecoration::getPositioningInfo() {
const auto BORDERSIZE = m_pWindow->getRealBorderSize();
const auto BORDERSIZE = m_pWindow.lock()->getRealBorderSize();
m_seExtents = {{BORDERSIZE, BORDERSIZE}, {BORDERSIZE, BORDERSIZE}};
if (doesntWantBorders())
@ -34,14 +34,14 @@ void CHyprBorderDecoration::onPositioningReply(const SDecorationPositioningReply
CBox CHyprBorderDecoration::assignedBoxGlobal() {
CBox box = m_bAssignedGeometry;
box.translate(g_pDecorationPositioner->getEdgeDefinedPoint(DECORATION_EDGE_BOTTOM | DECORATION_EDGE_LEFT | DECORATION_EDGE_RIGHT | DECORATION_EDGE_TOP, m_pWindow));
box.translate(g_pDecorationPositioner->getEdgeDefinedPoint(DECORATION_EDGE_BOTTOM | DECORATION_EDGE_LEFT | DECORATION_EDGE_RIGHT | DECORATION_EDGE_TOP, m_pWindow.lock()));
const auto PWORKSPACE = m_pWindow->m_pWorkspace;
const auto PWORKSPACE = m_pWindow.lock()->m_pWorkspace;
if (!PWORKSPACE)
return box;
const auto WORKSPACEOFFSET = PWORKSPACE && !m_pWindow->m_bPinned ? PWORKSPACE->m_vRenderOffset.value() : Vector2D();
const auto WORKSPACEOFFSET = PWORKSPACE && !m_pWindow.lock()->m_bPinned ? PWORKSPACE->m_vRenderOffset.value() : Vector2D();
return box.translate(WORKSPACEOFFSET);
}
@ -52,28 +52,29 @@ void CHyprBorderDecoration::draw(CMonitor* pMonitor, float a) {
if (m_bAssignedGeometry.width < m_seExtents.topLeft.x + 1 || m_bAssignedGeometry.height < m_seExtents.topLeft.y + 1)
return;
CBox windowBox = assignedBoxGlobal().translate(-pMonitor->vecPosition + m_pWindow->m_vFloatingOffset).expand(-m_pWindow->getRealBorderSize()).scale(pMonitor->scale).round();
CBox windowBox =
assignedBoxGlobal().translate(-pMonitor->vecPosition + m_pWindow.lock()->m_vFloatingOffset).expand(-m_pWindow.lock()->getRealBorderSize()).scale(pMonitor->scale).round();
if (windowBox.width < 1 || windowBox.height < 1)
return;
auto grad = m_pWindow->m_cRealBorderColor;
const bool ANIMATED = m_pWindow->m_fBorderFadeAnimationProgress.isBeingAnimated();
float a1 = a * (ANIMATED ? m_pWindow->m_fBorderFadeAnimationProgress.value() : 1.f);
auto grad = m_pWindow.lock()->m_cRealBorderColor;
const bool ANIMATED = m_pWindow.lock()->m_fBorderFadeAnimationProgress.isBeingAnimated();
float a1 = a * (ANIMATED ? m_pWindow.lock()->m_fBorderFadeAnimationProgress.value() : 1.f);
if (m_pWindow->m_fBorderAngleAnimationProgress.getConfig()->pValues->internalEnabled) {
grad.m_fAngle += m_pWindow->m_fBorderAngleAnimationProgress.value() * M_PI * 2;
if (m_pWindow.lock()->m_fBorderAngleAnimationProgress.getConfig()->pValues->internalEnabled) {
grad.m_fAngle += m_pWindow.lock()->m_fBorderAngleAnimationProgress.value() * M_PI * 2;
grad.m_fAngle = normalizeAngleRad(grad.m_fAngle);
}
int borderSize = m_pWindow->getRealBorderSize();
const auto ROUNDING = m_pWindow->rounding() * pMonitor->scale;
int borderSize = m_pWindow.lock()->getRealBorderSize();
const auto ROUNDING = m_pWindow.lock()->rounding() * pMonitor->scale;
g_pHyprOpenGL->renderBorder(&windowBox, grad, ROUNDING, borderSize, a1);
if (ANIMATED) {
float a2 = a * (1.f - m_pWindow->m_fBorderFadeAnimationProgress.value());
g_pHyprOpenGL->renderBorder(&windowBox, m_pWindow->m_cRealBorderColorPrevious, ROUNDING, borderSize, a2);
float a2 = a * (1.f - m_pWindow.lock()->m_fBorderFadeAnimationProgress.value());
g_pHyprOpenGL->renderBorder(&windowBox, m_pWindow.lock()->m_cRealBorderColorPrevious, ROUNDING, borderSize, a2);
}
}
@ -81,24 +82,24 @@ eDecorationType CHyprBorderDecoration::getDecorationType() {
return DECORATION_BORDER;
}
void CHyprBorderDecoration::updateWindow(CWindow*) {
if (m_pWindow->getRealBorderSize() != m_seExtents.topLeft.x)
void CHyprBorderDecoration::updateWindow(PHLWINDOW) {
if (m_pWindow.lock()->getRealBorderSize() != m_seExtents.topLeft.x)
g_pDecorationPositioner->repositionDeco(this);
}
void CHyprBorderDecoration::damageEntire() {
if (!g_pCompositor->windowValidMapped(m_pWindow))
if (!validMapped(m_pWindow))
return;
auto surfaceBox = m_pWindow->getWindowMainSurfaceBox();
const auto ROUNDING = m_pWindow->rounding();
auto surfaceBox = m_pWindow.lock()->getWindowMainSurfaceBox();
const auto ROUNDING = m_pWindow.lock()->rounding();
const auto ROUNDINGSIZE = ROUNDING - M_SQRT1_2 * ROUNDING + 2;
const auto BORDERSIZE = m_pWindow->getRealBorderSize() + 1;
const auto BORDERSIZE = m_pWindow.lock()->getRealBorderSize() + 1;
const auto PWINDOWWORKSPACE = m_pWindow->m_pWorkspace;
if (PWINDOWWORKSPACE && PWINDOWWORKSPACE->m_vRenderOffset.isBeingAnimated() && !m_pWindow->m_bPinned)
const auto PWINDOWWORKSPACE = m_pWindow.lock()->m_pWorkspace;
if (PWINDOWWORKSPACE && PWINDOWWORKSPACE->m_vRenderOffset.isBeingAnimated() && !m_pWindow.lock()->m_bPinned)
surfaceBox.translate(PWINDOWWORKSPACE->m_vRenderOffset.value());
surfaceBox.translate(m_pWindow->m_vFloatingOffset);
surfaceBox.translate(m_pWindow.lock()->m_vFloatingOffset);
CBox surfaceBoxExpandedBorder = surfaceBox;
surfaceBoxExpandedBorder.expand(BORDERSIZE);
@ -109,7 +110,7 @@ void CHyprBorderDecoration::damageEntire() {
borderRegion.subtract(surfaceBoxShrunkRounding);
for (auto& m : g_pCompositor->m_vMonitors) {
if (!g_pHyprRenderer->shouldRenderWindow(m_pWindow, m.get())) {
if (!g_pHyprRenderer->shouldRenderWindow(m_pWindow.lock(), m.get())) {
const CRegion monitorRegion({m->vecPosition, m->vecSize});
borderRegion.subtract(monitorRegion);
}
@ -133,5 +134,5 @@ std::string CHyprBorderDecoration::getDisplayName() {
}
bool CHyprBorderDecoration::doesntWantBorders() {
return !m_pWindow->m_sSpecialRenderData.border || m_pWindow->m_bX11DoesntWantBorders || m_pWindow->getRealBorderSize() == 0;
return !m_pWindow.lock()->m_sSpecialRenderData.border || m_pWindow.lock()->m_bX11DoesntWantBorders || m_pWindow.lock()->getRealBorderSize() == 0;
}

View file

@ -4,7 +4,7 @@
class CHyprBorderDecoration : public IHyprWindowDecoration {
public:
CHyprBorderDecoration(CWindow*);
CHyprBorderDecoration(PHLWINDOW);
virtual ~CHyprBorderDecoration();
virtual SDecorationPositioningInfo getPositioningInfo();
@ -15,7 +15,7 @@ class CHyprBorderDecoration : public IHyprWindowDecoration {
virtual eDecorationType getDecorationType();
virtual void updateWindow(CWindow*);
virtual void updateWindow(PHLWINDOW);
virtual void damageEntire();
@ -29,7 +29,7 @@ class CHyprBorderDecoration : public IHyprWindowDecoration {
SWindowDecorationExtents m_seExtents;
SWindowDecorationExtents m_seReportedExtents;
CWindow* m_pWindow = nullptr;
PHLWINDOWREF m_pWindow;
Vector2D m_vLastWindowPos;
Vector2D m_vLastWindowSize;

View file

@ -3,7 +3,7 @@
#include "../../Compositor.hpp"
#include "../../config/ConfigValue.hpp"
CHyprDropShadowDecoration::CHyprDropShadowDecoration(CWindow* pWindow) : IHyprWindowDecoration(pWindow) {
CHyprDropShadowDecoration::CHyprDropShadowDecoration(PHLWINDOW pWindow) : IHyprWindowDecoration(pWindow) {
m_pWindow = pWindow;
}
@ -24,7 +24,7 @@ SDecorationPositioningInfo CHyprDropShadowDecoration::getPositioningInfo() {
}
void CHyprDropShadowDecoration::onPositioningReply(const SDecorationPositioningReply& reply) {
updateWindow(m_pWindow);
updateWindow(m_pWindow.lock());
}
uint64_t CHyprDropShadowDecoration::getDecorationFlags() {
@ -41,31 +41,33 @@ void CHyprDropShadowDecoration::damageEntire() {
if (*PSHADOWS != 1)
return; // disabled
CBox shadowBox = {m_pWindow->m_vRealPosition.value().x - m_seExtents.topLeft.x, m_pWindow->m_vRealPosition.value().y - m_seExtents.topLeft.y,
m_pWindow->m_vRealSize.value().x + m_seExtents.topLeft.x + m_seExtents.bottomRight.x,
m_pWindow->m_vRealSize.value().y + m_seExtents.topLeft.y + m_seExtents.bottomRight.y};
const auto PWINDOW = m_pWindow.lock();
const auto PWORKSPACE = m_pWindow->m_pWorkspace;
if (PWORKSPACE && PWORKSPACE->m_vRenderOffset.isBeingAnimated() && !m_pWindow->m_bPinned)
CBox shadowBox = {PWINDOW->m_vRealPosition.value().x - m_seExtents.topLeft.x, PWINDOW->m_vRealPosition.value().y - m_seExtents.topLeft.y,
PWINDOW->m_vRealSize.value().x + m_seExtents.topLeft.x + m_seExtents.bottomRight.x,
PWINDOW->m_vRealSize.value().y + m_seExtents.topLeft.y + m_seExtents.bottomRight.y};
const auto PWORKSPACE = PWINDOW->m_pWorkspace;
if (PWORKSPACE && PWORKSPACE->m_vRenderOffset.isBeingAnimated() && !PWINDOW->m_bPinned)
shadowBox.translate(PWORKSPACE->m_vRenderOffset.value());
shadowBox.translate(m_pWindow->m_vFloatingOffset);
shadowBox.translate(PWINDOW->m_vFloatingOffset);
static auto PSHADOWIGNOREWINDOW = CConfigValue<Hyprlang::INT>("decoration:shadow_ignore_window");
const auto ROUNDING = m_pWindow->rounding();
const auto ROUNDING = PWINDOW->rounding();
const auto ROUNDINGSIZE = ROUNDING - M_SQRT1_2 * ROUNDING + 1;
CRegion shadowRegion(shadowBox);
if (*PSHADOWIGNOREWINDOW) {
CBox surfaceBox = m_pWindow->getWindowMainSurfaceBox();
if (PWORKSPACE && PWORKSPACE->m_vRenderOffset.isBeingAnimated() && !m_pWindow->m_bPinned)
CBox surfaceBox = PWINDOW->getWindowMainSurfaceBox();
if (PWORKSPACE && PWORKSPACE->m_vRenderOffset.isBeingAnimated() && !PWINDOW->m_bPinned)
surfaceBox.translate(PWORKSPACE->m_vRenderOffset.value());
surfaceBox.translate(m_pWindow->m_vFloatingOffset);
surfaceBox.translate(PWINDOW->m_vFloatingOffset);
surfaceBox.expand(-ROUNDINGSIZE);
shadowRegion.subtract(CRegion(surfaceBox));
}
for (auto& m : g_pCompositor->m_vMonitors) {
if (!g_pHyprRenderer->shouldRenderWindow(m_pWindow, m.get())) {
if (!g_pHyprRenderer->shouldRenderWindow(PWINDOW, m.get())) {
const CRegion monitorRegion({m->vecPosition, m->vecSize});
shadowRegion.subtract(monitorRegion);
}
@ -74,9 +76,11 @@ void CHyprDropShadowDecoration::damageEntire() {
g_pHyprRenderer->damageRegion(shadowRegion);
}
void CHyprDropShadowDecoration::updateWindow(CWindow* pWindow) {
m_vLastWindowPos = m_pWindow->m_vRealPosition.value();
m_vLastWindowSize = m_pWindow->m_vRealSize.value();
void CHyprDropShadowDecoration::updateWindow(PHLWINDOW pWindow) {
const auto PWINDOW = m_pWindow.lock();
m_vLastWindowPos = PWINDOW->m_vRealPosition.value();
m_vLastWindowSize = PWINDOW->m_vRealSize.value();
m_bLastWindowBox = {m_vLastWindowPos.x, m_vLastWindowPos.y, m_vLastWindowSize.x, m_vLastWindowSize.y};
m_bLastWindowBoxWithDecos = g_pDecorationPositioner->getBoxWithIncludedDecos(pWindow);
@ -84,19 +88,21 @@ void CHyprDropShadowDecoration::updateWindow(CWindow* pWindow) {
void CHyprDropShadowDecoration::draw(CMonitor* pMonitor, float a) {
if (!g_pCompositor->windowValidMapped(m_pWindow))
const auto PWINDOW = m_pWindow.lock();
if (!validMapped(PWINDOW))
return;
if (m_pWindow->m_cRealShadowColor.value() == CColor(0, 0, 0, 0))
if (PWINDOW->m_cRealShadowColor.value() == CColor(0, 0, 0, 0))
return; // don't draw invisible shadows
if (!m_pWindow->m_sSpecialRenderData.decorate)
if (!PWINDOW->m_sSpecialRenderData.decorate)
return;
if (!m_pWindow->m_sSpecialRenderData.shadow)
if (!PWINDOW->m_sSpecialRenderData.shadow)
return;
if (m_pWindow->m_sAdditionalConfigData.forceNoShadow)
if (PWINDOW->m_sAdditionalConfigData.forceNoShadow)
return;
static auto PSHADOWS = CConfigValue<Hyprlang::INT>("decoration:drop_shadow");
@ -108,10 +114,10 @@ void CHyprDropShadowDecoration::draw(CMonitor* pMonitor, float a) {
if (*PSHADOWS != 1)
return; // disabled
const auto ROUNDINGBASE = m_pWindow->rounding();
const auto ROUNDING = ROUNDINGBASE > 0 ? ROUNDINGBASE + m_pWindow->getRealBorderSize() : 0;
const auto PWORKSPACE = m_pWindow->m_pWorkspace;
const auto WORKSPACEOFFSET = PWORKSPACE && !m_pWindow->m_bPinned ? PWORKSPACE->m_vRenderOffset.value() : Vector2D();
const auto ROUNDINGBASE = PWINDOW->rounding();
const auto ROUNDING = ROUNDINGBASE > 0 ? ROUNDINGBASE + PWINDOW->getRealBorderSize() : 0;
const auto PWORKSPACE = PWINDOW->m_pWorkspace;
const auto WORKSPACEOFFSET = PWORKSPACE && !PWINDOW->m_bPinned ? PWORKSPACE->m_vRenderOffset.value() : Vector2D();
// draw the shadow
CBox fullBox = m_bLastWindowBoxWithDecos;
@ -126,13 +132,13 @@ void CHyprDropShadowDecoration::draw(CMonitor* pMonitor, float a) {
// scale the box in relation to the center of the box
fullBox.scaleFromCenter(SHADOWSCALE).translate(*PSHADOWOFFSET);
updateWindow(m_pWindow);
updateWindow(PWINDOW);
m_vLastWindowPos += WORKSPACEOFFSET;
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}};
fullBox.translate(m_pWindow->m_vFloatingOffset);
fullBox.translate(PWINDOW->m_vFloatingOffset);
if (fullBox.width < 1 || fullBox.height < 1)
return; // don't draw invisible shadows
@ -154,8 +160,8 @@ void CHyprDropShadowDecoration::draw(CMonitor* pMonitor, float a) {
windowBox.translate(-pMonitor->vecPosition + WORKSPACEOFFSET);
withDecos.translate(-pMonitor->vecPosition + WORKSPACEOFFSET);
windowBox.translate(m_pWindow->m_vFloatingOffset);
withDecos.translate(m_pWindow->m_vFloatingOffset);
windowBox.translate(PWINDOW->m_vFloatingOffset);
withDecos.translate(PWINDOW->m_vFloatingOffset);
auto scaledExtentss = withDecos.extentsFrom(windowBox);
scaledExtentss = scaledExtentss * pMonitor->scale;
@ -181,7 +187,7 @@ void CHyprDropShadowDecoration::draw(CMonitor* pMonitor, float a) {
g_pHyprOpenGL->renderRect(&fullBox, CColor(0, 0, 0, 1), 0);
// render white shadow with the alpha of the shadow color (otherwise we clear with alpha later and shit it to 2 bit)
g_pHyprOpenGL->renderRoundedShadow(&fullBox, ROUNDING * pMonitor->scale, *PSHADOWSIZE * pMonitor->scale, CColor(1, 1, 1, m_pWindow->m_cRealShadowColor.value().a), a);
g_pHyprOpenGL->renderRoundedShadow(&fullBox, ROUNDING * pMonitor->scale, *PSHADOWSIZE * pMonitor->scale, CColor(1, 1, 1, PWINDOW->m_cRealShadowColor.value().a), a);
// render black window box ("clip")
g_pHyprOpenGL->renderRect(&windowBox, CColor(0, 0, 0, 1.0), ROUNDING * pMonitor->scale);
@ -189,7 +195,7 @@ void CHyprDropShadowDecoration::draw(CMonitor* pMonitor, float a) {
alphaSwapFB.bind();
// alpha swap just has the shadow color. It will be the "texture" to render.
g_pHyprOpenGL->renderRect(&fullBox, m_pWindow->m_cRealShadowColor.value().stripA(), 0);
g_pHyprOpenGL->renderRect(&fullBox, PWINDOW->m_cRealShadowColor.value().stripA(), 0);
LASTFB->bind();
@ -202,7 +208,7 @@ void CHyprDropShadowDecoration::draw(CMonitor* pMonitor, float a) {
g_pHyprOpenGL->m_RenderData.damage = saveDamage;
} else {
g_pHyprOpenGL->renderRoundedShadow(&fullBox, ROUNDING * pMonitor->scale, *PSHADOWSIZE * pMonitor->scale, m_pWindow->m_cRealShadowColor.value(), a);
g_pHyprOpenGL->renderRoundedShadow(&fullBox, ROUNDING * pMonitor->scale, *PSHADOWSIZE * pMonitor->scale, PWINDOW->m_cRealShadowColor.value(), a);
}
if (m_seExtents != m_seReportedExtents)

View file

@ -4,7 +4,7 @@
class CHyprDropShadowDecoration : public IHyprWindowDecoration {
public:
CHyprDropShadowDecoration(CWindow*);
CHyprDropShadowDecoration(PHLWINDOW);
virtual ~CHyprDropShadowDecoration();
virtual SDecorationPositioningInfo getPositioningInfo();
@ -15,7 +15,7 @@ class CHyprDropShadowDecoration : public IHyprWindowDecoration {
virtual eDecorationType getDecorationType();
virtual void updateWindow(CWindow*);
virtual void updateWindow(PHLWINDOW);
virtual void damageEntire();
@ -29,7 +29,7 @@ class CHyprDropShadowDecoration : public IHyprWindowDecoration {
SWindowDecorationExtents m_seExtents;
SWindowDecorationExtents m_seReportedExtents;
CWindow* m_pWindow = nullptr;
PHLWINDOWREF m_pWindow;
Vector2D m_vLastWindowPos;
Vector2D m_vLastWindowSize;

View file

@ -15,7 +15,7 @@ constexpr int BAR_PADDING_OUTER_VERT = 2;
constexpr int BAR_TEXT_PAD = 2;
constexpr int BAR_HORIZONTAL_PADDING = 2;
CHyprGroupBarDecoration::CHyprGroupBarDecoration(CWindow* pWindow) : IHyprWindowDecoration(pWindow) {
CHyprGroupBarDecoration::CHyprGroupBarDecoration(PHLWINDOW pWindow) : IHyprWindowDecoration(pWindow) {
static auto PGRADIENTS = CConfigValue<Hyprlang::INT>("group:groupbar:enabled");
static auto PENABLED = CConfigValue<Hyprlang::INT>("group:groupbar:gradients");
m_pWindow = pWindow;
@ -39,7 +39,7 @@ SDecorationPositioningInfo CHyprGroupBarDecoration::getPositioningInfo() {
info.priority = *PPRIORITY;
info.reserved = true;
if (*PENABLED && m_pWindow->m_sSpecialRenderData.decorate)
if (*PENABLED && m_pWindow.lock()->m_sSpecialRenderData.decorate)
info.desiredExtents = {{0, BAR_PADDING_OUTER_VERT * 2 + BAR_INDICATOR_HEIGHT + (*PGRADIENTS || *PRENDERTITLES ? *PHEIGHT : 0) + 2}, {0, 0}};
else
info.desiredExtents = {{0, 0}, {0, 0}};
@ -57,33 +57,33 @@ eDecorationType CHyprGroupBarDecoration::getDecorationType() {
//
void CHyprGroupBarDecoration::updateWindow(CWindow* pWindow) {
if (!m_pWindow->m_sGroupData.pNextWindow) {
m_pWindow->removeWindowDeco(this);
void CHyprGroupBarDecoration::updateWindow(PHLWINDOW pWindow) {
if (m_pWindow.lock()->m_sGroupData.pNextWindow.expired()) {
m_pWindow.lock()->removeWindowDeco(this);
return;
}
m_dwGroupMembers.clear();
CWindow* head = pWindow->getGroupHead();
PHLWINDOW head = pWindow->getGroupHead();
m_dwGroupMembers.push_back(head);
CWindow* curr = head->m_sGroupData.pNextWindow;
PHLWINDOW curr = head->m_sGroupData.pNextWindow.lock();
while (curr != head) {
m_dwGroupMembers.push_back(curr);
curr = curr->m_sGroupData.pNextWindow;
curr = curr->m_sGroupData.pNextWindow.lock();
}
damageEntire();
if (m_dwGroupMembers.size() == 0) {
m_pWindow->removeWindowDeco(this);
m_pWindow.lock()->removeWindowDeco(this);
return;
}
}
void CHyprGroupBarDecoration::damageEntire() {
auto box = assignedBoxGlobal();
box.translate(m_pWindow->m_vFloatingOffset);
box.translate(m_pWindow.lock()->m_vFloatingOffset);
g_pHyprRenderer->damageBox(&box);
}
@ -97,7 +97,7 @@ void CHyprGroupBarDecoration::draw(CMonitor* pMonitor, float a) {
static auto PHEIGHT = CConfigValue<Hyprlang::INT>("group:groupbar:height");
static auto PGRADIENTS = CConfigValue<Hyprlang::INT>("group:groupbar:gradients");
if (!*PENABLED || !m_pWindow->m_sSpecialRenderData.decorate)
if (!*PENABLED || !m_pWindow.lock()->m_sSpecialRenderData.decorate)
return;
const auto ASSIGNEDBOX = assignedBoxGlobal();
@ -111,8 +111,8 @@ void CHyprGroupBarDecoration::draw(CMonitor* pMonitor, float a) {
int xoff = 0;
for (int i = 0; i < barsToDraw; ++i) {
CBox rect = {ASSIGNEDBOX.x + xoff - pMonitor->vecPosition.x + m_pWindow->m_vFloatingOffset.x,
ASSIGNEDBOX.y + ASSIGNEDBOX.h - BAR_INDICATOR_HEIGHT - BAR_PADDING_OUTER_VERT - pMonitor->vecPosition.y + m_pWindow->m_vFloatingOffset.y, m_fBarWidth,
CBox rect = {ASSIGNEDBOX.x + xoff - pMonitor->vecPosition.x + m_pWindow.lock()->m_vFloatingOffset.x,
ASSIGNEDBOX.y + ASSIGNEDBOX.h - BAR_INDICATOR_HEIGHT - BAR_PADDING_OUTER_VERT - pMonitor->vecPosition.y + m_pWindow.lock()->m_vFloatingOffset.y, m_fBarWidth,
BAR_INDICATOR_HEIGHT};
if (rect.width <= 0 || rect.height <= 0)
@ -129,32 +129,32 @@ void CHyprGroupBarDecoration::draw(CMonitor* pMonitor, float a) {
auto* const GROUPCOLACTIVELOCKED = (CGradientValueData*)(PGROUPCOLACTIVELOCKED.ptr())->getData();
auto* const GROUPCOLINACTIVELOCKED = (CGradientValueData*)(PGROUPCOLINACTIVELOCKED.ptr())->getData();
const bool GROUPLOCKED = m_pWindow->getGroupHead()->m_sGroupData.locked;
const bool GROUPLOCKED = m_pWindow.lock()->getGroupHead()->m_sGroupData.locked;
const auto* const PCOLACTIVE = GROUPLOCKED ? GROUPCOLACTIVELOCKED : GROUPCOLACTIVE;
const auto* const PCOLINACTIVE = GROUPLOCKED ? GROUPCOLINACTIVELOCKED : GROUPCOLINACTIVE;
CColor color = m_dwGroupMembers[i] == g_pCompositor->m_pLastWindow ? PCOLACTIVE->m_vColors[0] : PCOLINACTIVE->m_vColors[0];
CColor color = m_dwGroupMembers[i].lock() == g_pCompositor->m_pLastWindow.lock() ? PCOLACTIVE->m_vColors[0] : PCOLINACTIVE->m_vColors[0];
color.a *= a;
g_pHyprOpenGL->renderRect(&rect, color);
rect = {ASSIGNEDBOX.x + xoff - pMonitor->vecPosition.x + m_pWindow->m_vFloatingOffset.x,
ASSIGNEDBOX.y - pMonitor->vecPosition.y + m_pWindow->m_vFloatingOffset.y + BAR_PADDING_OUTER_VERT, m_fBarWidth,
rect = {ASSIGNEDBOX.x + xoff - pMonitor->vecPosition.x + m_pWindow.lock()->m_vFloatingOffset.x,
ASSIGNEDBOX.y - pMonitor->vecPosition.y + m_pWindow.lock()->m_vFloatingOffset.y + BAR_PADDING_OUTER_VERT, m_fBarWidth,
ASSIGNEDBOX.h - BAR_INDICATOR_HEIGHT - BAR_PADDING_OUTER_VERT * 2};
rect.scale(pMonitor->scale);
if (*PGRADIENTS) {
const auto& GRADIENTTEX = (m_dwGroupMembers[i] == g_pCompositor->m_pLastWindow ? (GROUPLOCKED ? m_tGradientLockedActive : m_tGradientActive) :
(GROUPLOCKED ? m_tGradientLockedInactive : m_tGradientInactive));
const auto& GRADIENTTEX = (m_dwGroupMembers[i].lock() == g_pCompositor->m_pLastWindow.lock() ? (GROUPLOCKED ? m_tGradientLockedActive : m_tGradientActive) :
(GROUPLOCKED ? m_tGradientLockedInactive : m_tGradientInactive));
if (GRADIENTTEX.m_iTexID != 0)
g_pHyprOpenGL->renderTexture(GRADIENTTEX, &rect, 1.0);
}
if (*PRENDERTITLES) {
CTitleTex* pTitleTex = textureFromTitle(m_dwGroupMembers[i]->m_szTitle);
CTitleTex* pTitleTex = textureFromTitle(m_dwGroupMembers[i].lock()->m_szTitle);
if (!pTitleTex)
pTitleTex = m_sTitleTexs.titleTexs
.emplace_back(std::make_unique<CTitleTex>(m_dwGroupMembers[i],
.emplace_back(std::make_unique<CTitleTex>(m_dwGroupMembers[i].lock(),
Vector2D{m_fBarWidth * pMonitor->scale, (*PTITLEFONTSIZE + 2 * BAR_TEXT_PAD) * pMonitor->scale}))
.get();
@ -184,7 +184,7 @@ void CHyprGroupBarDecoration::invalidateTextures() {
m_sTitleTexs.titleTexs.clear();
}
CTitleTex::CTitleTex(CWindow* pWindow, const Vector2D& bufferSize) {
CTitleTex::CTitleTex(PHLWINDOW pWindow, const Vector2D& bufferSize) {
szContent = pWindow->m_szTitle;
pWindowOwner = pWindow;
const auto CAIROSURFACE = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, bufferSize.x, bufferSize.y);
@ -335,7 +335,7 @@ void refreshGroupBarGradients() {
}
bool CHyprGroupBarDecoration::onBeginWindowDragOnDeco(const Vector2D& pos) {
if (m_pWindow == m_pWindow->m_sGroupData.pNextWindow)
if (m_pWindow.lock() == m_pWindow.lock()->m_sGroupData.pNextWindow.lock())
return false;
const float BARRELATIVEX = pos.x - assignedBoxGlobal().x;
@ -344,7 +344,7 @@ bool CHyprGroupBarDecoration::onBeginWindowDragOnDeco(const Vector2D& pos) {
if (BARRELATIVEX - (m_fBarWidth + BAR_HORIZONTAL_PADDING) * WINDOWINDEX > m_fBarWidth)
return false;
CWindow* pWindow = m_pWindow->getGroupWindowByIndex(WINDOWINDEX);
PHLWINDOW pWindow = m_pWindow.lock()->getGroupWindowByIndex(WINDOWINDEX);
// hack
g_pLayoutManager->getCurrentLayout()->onWindowRemoved(pWindow);
@ -363,33 +363,33 @@ bool CHyprGroupBarDecoration::onBeginWindowDragOnDeco(const Vector2D& pos) {
return true;
}
bool CHyprGroupBarDecoration::onEndWindowDragOnDeco(const Vector2D& pos, CWindow* pDraggedWindow) {
if (!pDraggedWindow->canBeGroupedInto(m_pWindow))
bool CHyprGroupBarDecoration::onEndWindowDragOnDeco(const Vector2D& pos, PHLWINDOW pDraggedWindow) {
if (!pDraggedWindow->canBeGroupedInto(m_pWindow.lock()))
return false;
const float BARRELATIVEX = pos.x - assignedBoxGlobal().x - m_fBarWidth / 2;
const int WINDOWINDEX = BARRELATIVEX < 0 ? -1 : (BARRELATIVEX) / (m_fBarWidth + BAR_HORIZONTAL_PADDING);
CWindow* pWindowInsertAfter = m_pWindow->getGroupWindowByIndex(WINDOWINDEX);
CWindow* pWindowInsertEnd = pWindowInsertAfter->m_sGroupData.pNextWindow;
CWindow* pDraggedHead = pDraggedWindow->m_sGroupData.pNextWindow ? pDraggedWindow->getGroupHead() : pDraggedWindow;
PHLWINDOW pWindowInsertAfter = m_pWindow.lock()->getGroupWindowByIndex(WINDOWINDEX);
PHLWINDOW pWindowInsertEnd = pWindowInsertAfter->m_sGroupData.pNextWindow.lock();
PHLWINDOW pDraggedHead = pDraggedWindow->m_sGroupData.pNextWindow.lock() ? pDraggedWindow->getGroupHead() : pDraggedWindow;
if (pDraggedWindow->m_sGroupData.pNextWindow) {
if (!pDraggedWindow->m_sGroupData.pNextWindow.expired()) {
// stores group data
std::vector<CWindow*> members;
CWindow* curr = pDraggedHead;
const bool WASLOCKED = pDraggedHead->m_sGroupData.locked;
std::vector<PHLWINDOW> members;
PHLWINDOW curr = pDraggedHead;
const bool WASLOCKED = pDraggedHead->m_sGroupData.locked;
do {
members.push_back(curr);
curr = curr->m_sGroupData.pNextWindow;
curr = curr->m_sGroupData.pNextWindow.lock();
} while (curr != members[0]);
// removes all windows
for (CWindow* w : members) {
w->m_sGroupData.pNextWindow = nullptr;
w->m_sGroupData.head = false;
w->m_sGroupData.locked = false;
for (PHLWINDOW w : members) {
w->m_sGroupData.pNextWindow.reset();
w->m_sGroupData.head = false;
w->m_sGroupData.locked = false;
g_pLayoutManager->getCurrentLayout()->onWindowRemoved(w);
}
@ -411,7 +411,7 @@ bool CHyprGroupBarDecoration::onEndWindowDragOnDeco(const Vector2D& pos, CWindow
if (WINDOWINDEX == -1)
std::swap(pDraggedHead->m_sGroupData.head, pWindowInsertEnd->m_sGroupData.head);
m_pWindow->setGroupCurrent(pDraggedWindow);
m_pWindow.lock()->setGroupCurrent(pDraggedWindow);
pDraggedWindow->applyGroupRules();
pDraggedWindow->updateWindowDecos();
g_pLayoutManager->getCurrentLayout()->recalculateWindow(pDraggedWindow);
@ -423,7 +423,7 @@ bool CHyprGroupBarDecoration::onEndWindowDragOnDeco(const Vector2D& pos, CWindow
}
bool CHyprGroupBarDecoration::onMouseButtonOnDeco(const Vector2D& pos, wlr_pointer_button_event* e) {
if (m_pWindow->m_bIsFullscreen && m_pWindow->m_pWorkspace->m_efFullscreenMode == FULLSCREEN_FULL)
if (m_pWindow.lock()->m_bIsFullscreen && m_pWindow.lock()->m_pWorkspace->m_efFullscreenMode == FULLSCREEN_FULL)
return true;
const float BARRELATIVEX = pos.x - assignedBoxGlobal().x;
@ -437,7 +437,7 @@ bool CHyprGroupBarDecoration::onMouseButtonOnDeco(const Vector2D& pos, wlr_point
if (e->state == WL_POINTER_BUTTON_STATE_PRESSED)
pressedCursorPos = pos;
else if (e->state == WL_POINTER_BUTTON_STATE_RELEASED && pressedCursorPos == pos)
g_pXWaylandManager->sendCloseWindow(m_pWindow->getGroupWindowByIndex(WINDOWINDEX));
g_pXWaylandManager->sendCloseWindow(m_pWindow.lock()->getGroupWindowByIndex(WINDOWINDEX));
return true;
}
@ -447,14 +447,14 @@ bool CHyprGroupBarDecoration::onMouseButtonOnDeco(const Vector2D& pos, wlr_point
// click on padding
if (BARRELATIVEX - (m_fBarWidth + BAR_HORIZONTAL_PADDING) * WINDOWINDEX > m_fBarWidth) {
if (!g_pCompositor->isWindowActive(m_pWindow))
g_pCompositor->focusWindow(m_pWindow);
if (!g_pCompositor->isWindowActive(m_pWindow.lock()))
g_pCompositor->focusWindow(m_pWindow.lock());
return true;
}
CWindow* pWindow = m_pWindow->getGroupWindowByIndex(WINDOWINDEX);
PHLWINDOW pWindow = m_pWindow.lock()->getGroupWindowByIndex(WINDOWINDEX);
if (pWindow != m_pWindow)
if (pWindow != m_pWindow.lock())
pWindow->setGroupCurrent(pWindow);
if (!g_pCompositor->isWindowActive(pWindow) && *PFOLLOWMOUSE != 3)
@ -469,13 +469,13 @@ bool CHyprGroupBarDecoration::onMouseButtonOnDeco(const Vector2D& pos, wlr_point
bool CHyprGroupBarDecoration::onScrollOnDeco(const Vector2D& pos, wlr_pointer_axis_event* e) {
static auto PGROUPBARSCROLLING = CConfigValue<Hyprlang::INT>("group:groupbar:scrolling");
if (!*PGROUPBARSCROLLING || !m_pWindow->m_sGroupData.pNextWindow)
if (!*PGROUPBARSCROLLING || m_pWindow.lock()->m_sGroupData.pNextWindow.expired())
return false;
if (e->delta > 0)
m_pWindow->setGroupCurrent(m_pWindow->m_sGroupData.pNextWindow);
m_pWindow.lock()->setGroupCurrent(m_pWindow.lock()->m_sGroupData.pNextWindow.lock());
else
m_pWindow->setGroupCurrent(m_pWindow->getGroupPrevious());
m_pWindow.lock()->setGroupCurrent(m_pWindow.lock()->getGroupPrevious());
return true;
}
@ -485,7 +485,7 @@ bool CHyprGroupBarDecoration::onInputOnDeco(const eInputType type, const Vector2
case INPUT_TYPE_AXIS: return onScrollOnDeco(mouseCoords, std::any_cast<wlr_pointer_axis_event*>(data));
case INPUT_TYPE_BUTTON: return onMouseButtonOnDeco(mouseCoords, std::any_cast<wlr_pointer_button_event*>(data));
case INPUT_TYPE_DRAG_START: return onBeginWindowDragOnDeco(mouseCoords);
case INPUT_TYPE_DRAG_END: return onEndWindowDragOnDeco(mouseCoords, std::any_cast<CWindow*>(data));
case INPUT_TYPE_DRAG_END: return onEndWindowDragOnDeco(mouseCoords, std::any_cast<PHLWINDOW>(data));
default: return false;
}
}
@ -504,11 +504,11 @@ std::string CHyprGroupBarDecoration::getDisplayName() {
CBox CHyprGroupBarDecoration::assignedBoxGlobal() {
CBox box = m_bAssignedBox;
box.translate(g_pDecorationPositioner->getEdgeDefinedPoint(DECORATION_EDGE_TOP, m_pWindow));
box.translate(g_pDecorationPositioner->getEdgeDefinedPoint(DECORATION_EDGE_TOP, m_pWindow.lock()));
const auto PWORKSPACE = m_pWindow->m_pWorkspace;
const auto PWORKSPACE = m_pWindow.lock()->m_pWorkspace;
if (PWORKSPACE && !m_pWindow->m_bPinned)
if (PWORKSPACE && !m_pWindow.lock()->m_bPinned)
box.translate(PWORKSPACE->m_vRenderOffset.value());
return box;

View file

@ -8,19 +8,19 @@
class CTitleTex {
public:
CTitleTex(CWindow* pWindow, const Vector2D& bufferSize);
CTitleTex(PHLWINDOW pWindow, const Vector2D& bufferSize);
~CTitleTex();
CTexture tex;
std::string szContent;
CWindow* pWindowOwner = nullptr;
CTexture tex;
std::string szContent;
PHLWINDOWREF pWindowOwner;
};
void refreshGroupBarGradients();
class CHyprGroupBarDecoration : public IHyprWindowDecoration {
public:
CHyprGroupBarDecoration(CWindow*);
CHyprGroupBarDecoration(PHLWINDOW);
virtual ~CHyprGroupBarDecoration();
virtual SDecorationPositioningInfo getPositioningInfo();
@ -31,7 +31,7 @@ class CHyprGroupBarDecoration : public IHyprWindowDecoration {
virtual eDecorationType getDecorationType();
virtual void updateWindow(CWindow*);
virtual void updateWindow(PHLWINDOW);
virtual void damageEntire();
@ -48,9 +48,9 @@ class CHyprGroupBarDecoration : public IHyprWindowDecoration {
CBox m_bAssignedBox = {0};
CWindow* m_pWindow = nullptr;
PHLWINDOWREF m_pWindow;
std::deque<CWindow*> m_dwGroupMembers;
std::deque<PHLWINDOWREF> m_dwGroupMembers;
float m_fBarWidth;
@ -60,7 +60,7 @@ class CHyprGroupBarDecoration : public IHyprWindowDecoration {
CBox assignedBoxGlobal();
bool onBeginWindowDragOnDeco(const Vector2D&);
bool onEndWindowDragOnDeco(const Vector2D&, CWindow*);
bool onEndWindowDragOnDeco(const Vector2D&, PHLWINDOW);
bool onMouseButtonOnDeco(const Vector2D&, wlr_pointer_button_event*);
bool onScrollOnDeco(const Vector2D&, wlr_pointer_axis_event*);

View file

@ -3,17 +3,17 @@
CDecorationPositioner::CDecorationPositioner() {
static auto P = g_pHookSystem->hookDynamic("closeWindow", [this](void* call, SCallbackInfo& info, std::any data) {
auto* const PWINDOW = std::any_cast<CWindow*>(data);
auto PWINDOW = std::any_cast<PHLWINDOW>(data);
this->onWindowUnmap(PWINDOW);
});
static auto P2 = g_pHookSystem->hookDynamic("openWindow", [this](void* call, SCallbackInfo& info, std::any data) {
auto* const PWINDOW = std::any_cast<CWindow*>(data);
auto PWINDOW = std::any_cast<PHLWINDOW>(data);
this->onWindowMap(PWINDOW);
});
}
Vector2D CDecorationPositioner::getEdgeDefinedPoint(uint32_t edges, CWindow* pWindow) {
Vector2D CDecorationPositioner::getEdgeDefinedPoint(uint32_t edges, PHLWINDOW pWindow) {
const bool TOP = edges & DECORATION_EDGE_TOP;
const bool BOTTOM = edges & DECORATION_EDGE_BOTTOM;
const bool LEFT = edges & DECORATION_EDGE_LEFT;
@ -57,9 +57,9 @@ Vector2D CDecorationPositioner::getEdgeDefinedPoint(uint32_t edges, CWindow* pWi
}
void CDecorationPositioner::uncacheDecoration(IHyprWindowDecoration* deco) {
std::erase_if(m_vWindowPositioningDatas, [&](const auto& data) { return data->pDecoration == deco; });
std::erase_if(m_vWindowPositioningDatas, [&](const auto& data) { return !data->pWindow.lock() || data->pDecoration == deco; });
const auto WIT = std::find_if(m_mWindowDatas.begin(), m_mWindowDatas.end(), [&](const auto& other) { return other.first == deco->m_pWindow; });
const auto WIT = std::find_if(m_mWindowDatas.begin(), m_mWindowDatas.end(), [&](const auto& other) { return other.first.lock() == deco->m_pWindow.lock(); });
if (WIT == m_mWindowDatas.end())
return;
@ -68,10 +68,10 @@ void CDecorationPositioner::uncacheDecoration(IHyprWindowDecoration* deco) {
void CDecorationPositioner::repositionDeco(IHyprWindowDecoration* deco) {
uncacheDecoration(deco);
onWindowUpdate(deco->m_pWindow);
onWindowUpdate(deco->m_pWindow.lock());
}
CDecorationPositioner::SWindowPositioningData* CDecorationPositioner::getDataFor(IHyprWindowDecoration* pDecoration, CWindow* pWindow) {
CDecorationPositioner::SWindowPositioningData* CDecorationPositioner::getDataFor(IHyprWindowDecoration* pDecoration, PHLWINDOW pWindow) {
auto it = std::find_if(m_vWindowPositioningDatas.begin(), m_vWindowPositioningDatas.end(), [&](const auto& el) { return el->pDecoration == pDecoration; });
if (it != m_vWindowPositioningDatas.end())
@ -85,19 +85,19 @@ CDecorationPositioner::SWindowPositioningData* CDecorationPositioner::getDataFor
}
void CDecorationPositioner::sanitizeDatas() {
std::erase_if(m_mWindowDatas, [](const auto& other) { return !g_pCompositor->windowExists(other.first); });
std::erase_if(m_mWindowDatas, [](const auto& other) { return !valid(other.first); });
std::erase_if(m_vWindowPositioningDatas, [](const auto& other) {
if (!g_pCompositor->windowExists(other->pWindow))
if (!validMapped(other->pWindow))
return true;
if (std::find_if(other->pWindow->m_dWindowDecorations.begin(), other->pWindow->m_dWindowDecorations.end(),
[&](const auto& el) { return el.get() == other->pDecoration; }) == other->pWindow->m_dWindowDecorations.end())
if (std::find_if(other->pWindow.lock()->m_dWindowDecorations.begin(), other->pWindow.lock()->m_dWindowDecorations.end(),
[&](const auto& el) { return el.get() == other->pDecoration; }) == other->pWindow.lock()->m_dWindowDecorations.end())
return true;
return false;
});
}
void CDecorationPositioner::forceRecalcFor(CWindow* pWindow) {
const auto WIT = std::find_if(m_mWindowDatas.begin(), m_mWindowDatas.end(), [&](const auto& other) { return other.first == pWindow; });
void CDecorationPositioner::forceRecalcFor(PHLWINDOW pWindow) {
const auto WIT = std::find_if(m_mWindowDatas.begin(), m_mWindowDatas.end(), [&](const auto& other) { return other.first.lock() == pWindow; });
if (WIT == m_mWindowDatas.end())
return;
@ -106,11 +106,11 @@ void CDecorationPositioner::forceRecalcFor(CWindow* pWindow) {
WINDOWDATA->needsRecalc = true;
}
void CDecorationPositioner::onWindowUpdate(CWindow* pWindow) {
if (!g_pCompositor->windowExists(pWindow) || !pWindow->m_bIsMapped)
void CDecorationPositioner::onWindowUpdate(PHLWINDOW pWindow) {
if (!validMapped(pWindow))
return;
const auto WIT = std::find_if(m_mWindowDatas.begin(), m_mWindowDatas.end(), [&](const auto& other) { return other.first == pWindow; });
const auto WIT = std::find_if(m_mWindowDatas.begin(), m_mWindowDatas.end(), [&](const auto& other) { return other.first.lock() == pWindow; });
if (WIT == m_mWindowDatas.end())
return;
@ -125,8 +125,8 @@ void CDecorationPositioner::onWindowUpdate(CWindow* pWindow) {
}
if (WINDOWDATA->lastWindowSize == pWindow->m_vRealSize.value() /* position not changed */
&&
std::all_of(m_vWindowPositioningDatas.begin(), m_vWindowPositioningDatas.end(), [pWindow](const auto& data) { return pWindow != data->pWindow || !data->needsReposition; })
&& std::all_of(m_vWindowPositioningDatas.begin(), m_vWindowPositioningDatas.end(),
[pWindow](const auto& data) { return pWindow != data->pWindow.lock() || !data->needsReposition; })
/* all window datas are either not for this window or don't need a reposition */
&& !WINDOWDATA->needsRecalc /* window doesn't need recalc */
)
@ -269,30 +269,30 @@ void CDecorationPositioner::onWindowUpdate(CWindow* pWindow) {
WINDOWDATA->extents = {{stickyOffsetXL + reservedXL, stickyOffsetYT + reservedYT}, {stickyOffsetXR + reservedXR, stickyOffsetYB + reservedYB}};
}
void CDecorationPositioner::onWindowUnmap(CWindow* pWindow) {
std::erase_if(m_vWindowPositioningDatas, [&](const auto& data) { return data->pWindow == pWindow; });
void CDecorationPositioner::onWindowUnmap(PHLWINDOW pWindow) {
std::erase_if(m_vWindowPositioningDatas, [&](const auto& data) { return data->pWindow.lock() == pWindow; });
m_mWindowDatas.erase(pWindow);
}
void CDecorationPositioner::onWindowMap(CWindow* pWindow) {
void CDecorationPositioner::onWindowMap(PHLWINDOW pWindow) {
m_mWindowDatas[pWindow] = {};
}
SWindowDecorationExtents CDecorationPositioner::getWindowDecorationReserved(CWindow* pWindow) {
SWindowDecorationExtents CDecorationPositioner::getWindowDecorationReserved(PHLWINDOW pWindow) {
try {
const auto E = m_mWindowDatas.at(pWindow);
return E.reserved;
} catch (std::out_of_range& e) { return {}; }
}
SWindowDecorationExtents CDecorationPositioner::getWindowDecorationExtents(CWindow* pWindow, bool inputOnly) {
SWindowDecorationExtents CDecorationPositioner::getWindowDecorationExtents(PHLWINDOW pWindow, bool inputOnly) {
CBox accum = pWindow->getWindowMainSurfaceBox();
for (auto& data : m_vWindowPositioningDatas) {
if (data->pWindow != pWindow)
if (data->pWindow.lock() != pWindow)
continue;
if (!data->pWindow || !data->pDecoration)
if (!data->pWindow.lock() || !data->pDecoration)
continue;
if (!(data->pDecoration->getDecorationFlags() & DECORATION_ALLOWS_MOUSE_INPUT) && inputOnly)
@ -301,7 +301,7 @@ SWindowDecorationExtents CDecorationPositioner::getWindowDecorationExtents(CWind
CBox decoBox;
if (data->positioningInfo.policy == DECORATION_POSITION_ABSOLUTE) {
decoBox = data->pWindow->getWindowMainSurfaceBox();
decoBox = data->pWindow.lock()->getWindowMainSurfaceBox();
decoBox.addExtents(data->positioningInfo.desiredExtents);
} else {
decoBox = data->lastReply.assignedGeometry;
@ -326,11 +326,11 @@ SWindowDecorationExtents CDecorationPositioner::getWindowDecorationExtents(CWind
return accum.extentsFrom(pWindow->getWindowMainSurfaceBox());
}
CBox CDecorationPositioner::getBoxWithIncludedDecos(CWindow* pWindow) {
CBox CDecorationPositioner::getBoxWithIncludedDecos(PHLWINDOW pWindow) {
CBox accum = pWindow->getWindowMainSurfaceBox();
for (auto& data : m_vWindowPositioningDatas) {
if (data->pWindow != pWindow)
if (data->pWindow.lock() != pWindow)
continue;
if (!(data->pDecoration->getDecorationFlags() & DECORATION_PART_OF_MAIN_WINDOW))
@ -339,7 +339,7 @@ CBox CDecorationPositioner::getBoxWithIncludedDecos(CWindow* pWindow) {
CBox decoBox;
if (data->positioningInfo.policy == DECORATION_POSITION_ABSOLUTE) {
decoBox = data->pWindow->getWindowMainSurfaceBox();
decoBox = data->pWindow.lock()->getWindowMainSurfaceBox();
decoBox.addExtents(data->positioningInfo.desiredExtents);
} else {
decoBox = data->lastReply.assignedGeometry;
@ -365,9 +365,9 @@ CBox CDecorationPositioner::getBoxWithIncludedDecos(CWindow* pWindow) {
}
CBox CDecorationPositioner::getWindowDecorationBox(IHyprWindowDecoration* deco) {
const auto DATA = getDataFor(deco, deco->m_pWindow);
const auto DATA = getDataFor(deco, deco->m_pWindow.lock());
CBox box = DATA->lastReply.assignedGeometry;
box.translate(getEdgeDefinedPoint(DATA->positioningInfo.edges, deco->m_pWindow));
box.translate(getEdgeDefinedPoint(DATA->positioningInfo.edges, deco->m_pWindow.lock()));
return box;
}

View file

@ -3,12 +3,15 @@
#include <cstdint>
#include <memory>
#include <vector>
#include <unordered_map>
#include <map>
#include "../../helpers/Box.hpp"
class CWindow;
class IHyprWindowDecoration;
typedef std::shared_ptr<CWindow> PHLWINDOW;
typedef std::weak_ptr<CWindow> PHLWINDOWREF;
enum eDecorationPositioningPolicy {
DECORATION_POSITION_ABSOLUTE = 0, /* Decoration wants absolute positioning */
DECORATION_POSITION_STICKY, /* Decoration is stuck to some edge of a window */
@ -59,21 +62,21 @@ class CDecorationPositioner {
public:
CDecorationPositioner();
Vector2D getEdgeDefinedPoint(uint32_t edges, CWindow* pWindow);
Vector2D getEdgeDefinedPoint(uint32_t edges, PHLWINDOW pWindow);
// called on resize, or insert/removal of a new deco
void onWindowUpdate(CWindow* pWindow);
void onWindowUpdate(PHLWINDOW pWindow);
void uncacheDecoration(IHyprWindowDecoration* deco);
SWindowDecorationExtents getWindowDecorationReserved(CWindow* pWindow);
SWindowDecorationExtents getWindowDecorationExtents(CWindow* pWindow, bool inputOnly = false);
CBox getBoxWithIncludedDecos(CWindow* pWindow);
SWindowDecorationExtents getWindowDecorationReserved(PHLWINDOW pWindow);
SWindowDecorationExtents getWindowDecorationExtents(PHLWINDOW pWindow, bool inputOnly = false);
CBox getBoxWithIncludedDecos(PHLWINDOW pWindow);
void repositionDeco(IHyprWindowDecoration* deco);
CBox getWindowDecorationBox(IHyprWindowDecoration* deco);
void forceRecalcFor(CWindow* pWindow);
void forceRecalcFor(PHLWINDOW pWindow);
private:
struct SWindowPositioningData {
CWindow* pWindow = nullptr;
PHLWINDOWREF pWindow;
IHyprWindowDecoration* pDecoration = nullptr;
SDecorationPositioningInfo positioningInfo;
SDecorationPositioningReply lastReply;
@ -87,13 +90,13 @@ class CDecorationPositioner {
bool needsRecalc = false;
};
std::unordered_map<CWindow*, SWindowData> m_mWindowDatas;
std::vector<std::unique_ptr<SWindowPositioningData>> m_vWindowPositioningDatas;
std::map<PHLWINDOWREF, SWindowData, std::owner_less<PHLWINDOWREF>> m_mWindowDatas;
std::vector<std::unique_ptr<SWindowPositioningData>> m_vWindowPositioningDatas;
SWindowPositioningData* getDataFor(IHyprWindowDecoration* pDecoration, CWindow* pWindow);
void onWindowUnmap(CWindow* pWindow);
void onWindowMap(CWindow* pWindow);
void sanitizeDatas();
SWindowPositioningData* getDataFor(IHyprWindowDecoration* pDecoration, PHLWINDOW pWindow);
void onWindowUnmap(PHLWINDOW pWindow);
void onWindowMap(PHLWINDOW pWindow);
void sanitizeDatas();
};
inline std::unique_ptr<CDecorationPositioner> g_pDecorationPositioner;

View file

@ -2,7 +2,7 @@
class CWindow;
IHyprWindowDecoration::IHyprWindowDecoration(CWindow* pWindow) {
IHyprWindowDecoration::IHyprWindowDecoration(PHLWINDOW pWindow) {
m_pWindow = pWindow;
}

View file

@ -32,7 +32,7 @@ class CDecorationPositioner;
class IHyprWindowDecoration {
public:
IHyprWindowDecoration(CWindow*);
IHyprWindowDecoration(PHLWINDOW);
virtual ~IHyprWindowDecoration() = 0;
virtual SDecorationPositioningInfo getPositioningInfo() = 0;
@ -43,7 +43,7 @@ class IHyprWindowDecoration {
virtual eDecorationType getDecorationType() = 0;
virtual void updateWindow(CWindow*) = 0;
virtual void updateWindow(PHLWINDOW) = 0;
virtual void damageEntire() = 0; // should be ignored by non-absolute decos
@ -56,7 +56,7 @@ class IHyprWindowDecoration {
virtual std::string getDisplayName();
private:
CWindow* m_pWindow = nullptr;
PHLWINDOWREF m_pWindow;
friend class CDecorationPositioner;
};