Skip to content

Commit

Permalink
Don't damage surfaces coming from not rendered windows
Browse files Browse the repository at this point in the history
  • Loading branch information
vaxerski committed May 31, 2022
1 parent 471654d commit 9700182
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/events/Popups.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ void Events::listener_mapPopupXDG(void* owner, void* data) {

Debug::log(LOG, "New XDG Popup mapped at %d %d", (int)PPOPUP->lx, (int)PPOPUP->ly);

PPOPUP->pSurfaceTree = SubsurfaceTree::createTreeRoot(PPOPUP->popup->base->surface, addPopupGlobalCoords, PPOPUP);
PPOPUP->pSurfaceTree = SubsurfaceTree::createTreeRoot(PPOPUP->popup->base->surface, addPopupGlobalCoords, PPOPUP, PPOPUP->parentWindow);

Debug::log(LOG, "XDG Popup got assigned a surfaceTreeNode %x", PPOPUP->pSurfaceTree);
}
Expand Down
2 changes: 1 addition & 1 deletion src/events/Windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ void Events::listener_mapWindow(void* owner, void* data) {
if (!PWINDOW->m_bNoFocus)
g_pCompositor->focusWindow(PWINDOW);

PWINDOW->m_pSurfaceTree = SubsurfaceTree::createTreeRoot(g_pXWaylandManager->getWindowSurface(PWINDOW), addViewCoords, PWINDOW);
PWINDOW->m_pSurfaceTree = SubsurfaceTree::createTreeRoot(g_pXWaylandManager->getWindowSurface(PWINDOW), addViewCoords, PWINDOW, PWINDOW);

Debug::log(LOG, "Window got assigned a surfaceTreeNode %x", PWINDOW->m_pSurfaceTree);

Expand Down
28 changes: 22 additions & 6 deletions src/helpers/SubsurfaceTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ void addSurfaceGlobalOffset(SSurfaceTreeNode* node, int* lx, int* ly) {
}
}

SSurfaceTreeNode* createTree(wlr_surface* pSurface) {
SSurfaceTreeNode* createTree(wlr_surface* pSurface, CWindow* pWindow) {
SubsurfaceTree::surfaceTreeNodes.push_back(SSurfaceTreeNode());

const auto PNODE = &SubsurfaceTree::surfaceTreeNodes.back();

PNODE->pSurface = pSurface;
PNODE->pWindowOwner = pWindow;

PNODE->hyprListener_newSubsurface.initCallback(&pSurface->events.new_subsurface, &Events::listener_newSubsurfaceNode, PNODE, "SurfaceTreeNode");
PNODE->hyprListener_commit.initCallback(&pSurface->events.commit, &Events::listener_commitSubsurface, PNODE, "SurfaceTreeNode");
Expand All @@ -42,16 +43,21 @@ SSurfaceTreeNode* createTree(wlr_surface* pSurface) {
return PNODE;
}

SSurfaceTreeNode* createSubsurfaceNode(SSurfaceTreeNode* pParent, SSubsurface* pSubsurface, wlr_surface* surface) {
const auto PNODE = createTree(surface);
SSurfaceTreeNode* createSubsurfaceNode(SSurfaceTreeNode* pParent, SSubsurface* pSubsurface, wlr_surface* surface, CWindow* pWindow) {
const auto PNODE = createTree(surface, pWindow);
PNODE->pParent = pParent;
PNODE->pSubsurface = pSubsurface;

Debug::log(LOG, "Creating a subsurface Node! (pWindow: %x)", pWindow);

return PNODE;
}

SSurfaceTreeNode* SubsurfaceTree::createTreeRoot(wlr_surface* pSurface, applyGlobalOffsetFn fn, void* data) {
const auto PNODE = createTree(pSurface);
SSurfaceTreeNode* SubsurfaceTree::createTreeRoot(wlr_surface* pSurface, applyGlobalOffsetFn fn, void* data, CWindow* pWindow) {
const auto PNODE = createTree(pSurface, pWindow);

Debug::log(LOG, "Creating a surfaceTree Root! (pWindow: %x)", pWindow);

PNODE->offsetfn = fn;
PNODE->globalOffsetData = data;

Expand Down Expand Up @@ -120,6 +126,8 @@ void Events::listener_newSubsurfaceNode(void* owner, void* data) {
PNEWSUBSURFACE->hyprListener_unmap.initCallback(&PSUBSURFACE->events.unmap, &Events::listener_unmapSubsurface, PNEWSUBSURFACE, "Subsurface");
PNEWSUBSURFACE->hyprListener_destroy.initCallback(&PSUBSURFACE->events.destroy, &Events::listener_destroySubsurface, PNEWSUBSURFACE, "Subsurface");

PNEWSUBSURFACE->pWindowOwner = pNode->pWindowOwner;

wlr_subsurface* existingWlrSubsurface;
wl_list_for_each(existingWlrSubsurface, &PSUBSURFACE->surface->current.subsurfaces_below, current.link) {
listener_newSubsurfaceNode(pNode, existingWlrSubsurface);
Expand All @@ -134,7 +142,7 @@ void Events::listener_mapSubsurface(void* owner, void* data) {

Debug::log(LOG, "Subsurface %x mapped", subsurface->pSubsurface);

subsurface->pChild = createSubsurfaceNode(subsurface->pParent, subsurface, subsurface->pSubsurface->surface);
subsurface->pChild = createSubsurfaceNode(subsurface->pParent, subsurface, subsurface->pSubsurface->surface, subsurface->pWindowOwner);
}

void Events::listener_unmapSubsurface(void* owner, void* data) {
Expand Down Expand Up @@ -162,6 +170,14 @@ void Events::listener_unmapSubsurface(void* owner, void* data) {
void Events::listener_commitSubsurface(void* owner, void* data) {
SSurfaceTreeNode* pNode = (SSurfaceTreeNode*)owner;

// no damaging if it's not visible
if (!g_pHyprRenderer->shouldRenderWindow(pNode->pWindowOwner)) {
if (g_pConfigManager->getInt("debug:log_damage"))
Debug::log(LOG, "Refusing to commit damage from %x because it's invisible.", pNode->pWindowOwner);
return;
}


int lx = 0, ly = 0;

addSurfaceGlobalOffset(pNode, &lx, &ly);
Expand Down
6 changes: 5 additions & 1 deletion src/helpers/SubsurfaceTree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <list>

struct SSubsurface;
class CWindow;

typedef void (*applyGlobalOffsetFn)(void *, int *, int *);

Expand All @@ -21,6 +22,7 @@ struct SSurfaceTreeNode {

applyGlobalOffsetFn offsetfn;
void *globalOffsetData;
CWindow* pWindowOwner = nullptr;

bool operator==(const SSurfaceTreeNode& rhs) {
return pSurface == rhs.pSurface;
Expand All @@ -37,13 +39,15 @@ struct SSubsurface {
DYNLISTENER(unmap);
DYNLISTENER(destroy);

CWindow* pWindowOwner = nullptr;

bool operator==(const SSubsurface& rhs) {
return pSubsurface == rhs.pSubsurface;
}
};

namespace SubsurfaceTree {
SSurfaceTreeNode* createTreeRoot(wlr_surface*, applyGlobalOffsetFn, void*);
SSurfaceTreeNode* createTreeRoot(wlr_surface*, applyGlobalOffsetFn, void*, CWindow* pWindow = nullptr);
void destroySurfaceTree(SSurfaceTreeNode*);

inline std::list<SSurfaceTreeNode> surfaceTreeNodes;
Expand Down
23 changes: 22 additions & 1 deletion src/render/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void renderSurface(struct wlr_surface* surface, int x, int y, void* data) {
wlr_presentation_surface_sampled_on_output(g_pCompositor->m_sWLRPresentation, surface, RDATA->output);
}

bool shouldRenderWindow(CWindow* pWindow, SMonitor* pMonitor) {
bool CHyprRenderer::shouldRenderWindow(CWindow* pWindow, SMonitor* pMonitor) {
wlr_box geometry = pWindow->getFullWindowBoundingBox();

if (!wlr_output_layout_intersects(g_pCompositor->m_sWLROutputLayout, pMonitor->output, &geometry))
Expand All @@ -52,6 +52,27 @@ bool shouldRenderWindow(CWindow* pWindow, SMonitor* pMonitor) {
return false;
}

bool CHyprRenderer::shouldRenderWindow(CWindow* pWindow) {

if (!g_pCompositor->windowValidMapped(pWindow))
return false;

const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(pWindow->m_iWorkspaceID);

if (g_pCompositor->isWorkspaceVisible(pWindow->m_iWorkspaceID))
return true;

for (auto& m : g_pCompositor->m_lMonitors) {
if (PWORKSPACE && PWORKSPACE->m_iMonitorID == m.ID && (PWORKSPACE->m_vRenderOffset.isBeingAnimated() || PWORKSPACE->m_fAlpha.isBeingAnimated()))
return true;

if (m.specialWorkspaceOpen && pWindow->m_iWorkspaceID == SPECIAL_WORKSPACE_ID)
return true;
}

return false;
}

void CHyprRenderer::renderWorkspaceWithFullscreenWindow(SMonitor* pMonitor, CWorkspace* pWorkspace, timespec* time) {
CWindow* pWorkspaceWindow = nullptr;

Expand Down
2 changes: 2 additions & 0 deletions src/render/Renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class CHyprRenderer {
void damageBox(const int& x, const int& y, const int& w, const int& h);
void damageMonitor(SMonitor*);
void applyMonitorRule(SMonitor*, SMonitorRule*, bool force = false);
bool shouldRenderWindow(CWindow*, SMonitor*);
bool shouldRenderWindow(CWindow*);

DAMAGETRACKINGMODES damageTrackingModeFromStr(const std::string&);

Expand Down

0 comments on commit 9700182

Please sign in to comment.