Skip to content

Commit 0b215c5

Browse files
committed
idle-inhibit: fix and cleanup visibility logic
fixes #5878
1 parent a3309b5 commit 0b215c5

9 files changed

+74
-28
lines changed

src/desktop/LayerSurface.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ PHLLS CLayerSurface::create(wlr_layer_surface_v1* pWLRLS) {
9090

9191
pLS->alpha.setValueAndWarp(0.f);
9292

93-
pLS->surface.assign(pWLRLS->surface);
93+
pLS->surface.assign(pWLRLS->surface, pLS);
9494

9595
return pLS;
9696
}

src/desktop/Popup.cpp

+23-12
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ void CPopup::initAllSignals() {
7171
if (!m_pWLR) {
7272
if (!m_pWindowOwner.expired())
7373
hyprListener_newPopup.initCallback(&m_pWindowOwner.lock()->m_uSurface.xdg->events.new_popup, ::onNewPopup, this, "CPopup Head");
74-
else if (m_pLayerOwner)
75-
hyprListener_newPopup.initCallback(&m_pLayerOwner->layerSurface->events.new_popup, ::onNewPopup, this, "CPopup Head");
74+
else if (!m_pLayerOwner.expired())
75+
hyprListener_newPopup.initCallback(&m_pLayerOwner.lock()->layerSurface->events.new_popup, ::onNewPopup, this, "CPopup Head");
7676
else
7777
ASSERT(false);
7878

@@ -119,8 +119,8 @@ void CPopup::onMap() {
119119
unconstrain();
120120
sendScale();
121121

122-
if (m_pLayerOwner && m_pLayerOwner->layer < ZWLR_LAYER_SHELL_V1_LAYER_TOP)
123-
g_pHyprOpenGL->markBlurDirtyForMonitor(g_pCompositor->getMonitorFromID(m_pLayerOwner->layer));
122+
if (!m_pLayerOwner.expired() && m_pLayerOwner.lock()->layer < ZWLR_LAYER_SHELL_V1_LAYER_TOP)
123+
g_pHyprOpenGL->markBlurDirtyForMonitor(g_pCompositor->getMonitorFromID(m_pLayerOwner.lock()->layer));
124124
}
125125

126126
void CPopup::onUnmap() {
@@ -136,8 +136,8 @@ void CPopup::onUnmap() {
136136

137137
g_pInputManager->simulateMouseMovement();
138138

139-
if (m_pLayerOwner && m_pLayerOwner->layer < ZWLR_LAYER_SHELL_V1_LAYER_TOP)
140-
g_pHyprOpenGL->markBlurDirtyForMonitor(g_pCompositor->getMonitorFromID(m_pLayerOwner->layer));
139+
if (!m_pLayerOwner.expired() && m_pLayerOwner.lock()->layer < ZWLR_LAYER_SHELL_V1_LAYER_TOP)
140+
g_pHyprOpenGL->markBlurDirtyForMonitor(g_pCompositor->getMonitorFromID(m_pLayerOwner.lock()->layer));
141141
}
142142

143143
void CPopup::onCommit(bool ignoreSiblings) {
@@ -178,8 +178,8 @@ void CPopup::onCommit(bool ignoreSiblings) {
178178

179179
m_bRequestedReposition = false;
180180

181-
if (m_pLayerOwner && m_pLayerOwner->layer < ZWLR_LAYER_SHELL_V1_LAYER_TOP)
182-
g_pHyprOpenGL->markBlurDirtyForMonitor(g_pCompositor->getMonitorFromID(m_pLayerOwner->layer));
181+
if (!m_pLayerOwner.expired() && m_pLayerOwner.lock()->layer < ZWLR_LAYER_SHELL_V1_LAYER_TOP)
182+
g_pHyprOpenGL->markBlurDirtyForMonitor(g_pCompositor->getMonitorFromID(m_pLayerOwner.lock()->layer));
183183
}
184184

185185
void CPopup::onReposition() {
@@ -232,8 +232,8 @@ Vector2D CPopup::localToGlobal(const Vector2D& rel) {
232232
Vector2D CPopup::t1ParentCoords() {
233233
if (!m_pWindowOwner.expired())
234234
return m_pWindowOwner.lock()->m_vRealPosition.value();
235-
if (m_pLayerOwner)
236-
return m_pLayerOwner->realPosition.value();
235+
if (!m_pLayerOwner.expired())
236+
return m_pLayerOwner.lock()->realPosition.value();
237237

238238
ASSERT(false);
239239
return {};
@@ -262,8 +262,19 @@ Vector2D CPopup::size() {
262262
void CPopup::sendScale() {
263263
if (!m_pWindowOwner.expired())
264264
g_pCompositor->setPreferredScaleForSurface(m_sWLSurface.wlr(), m_pWindowOwner.lock()->m_pWLSurface.m_fLastScale);
265-
else if (m_pLayerOwner)
266-
g_pCompositor->setPreferredScaleForSurface(m_sWLSurface.wlr(), m_pLayerOwner->surface.m_fLastScale);
265+
else if (!m_pLayerOwner.expired())
266+
g_pCompositor->setPreferredScaleForSurface(m_sWLSurface.wlr(), m_pLayerOwner.lock()->surface.m_fLastScale);
267267
else
268268
UNREACHABLE();
269269
}
270+
271+
bool CPopup::visible() {
272+
if (!m_pWindowOwner.expired())
273+
return g_pHyprRenderer->shouldRenderWindow(m_pWindowOwner.lock());
274+
if (!m_pLayerOwner.expired())
275+
return true;
276+
if (m_pParent)
277+
return m_pParent->visible();
278+
279+
return false;
280+
}

src/desktop/Popup.hpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@ class CPopup {
2929

3030
void recheckTree();
3131

32+
bool visible();
33+
3234
CWLSurface m_sWLSurface;
3335

3436
private:
3537
// T1 owners, each popup has to have one of these
3638
PHLWINDOWREF m_pWindowOwner;
37-
PHLLS m_pLayerOwner;
39+
PHLLSREF m_pLayerOwner;
3840

3941
// T2 owners
4042
CPopup* m_pParent = nullptr;

src/desktop/Subsurface.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,14 @@ void CSubsurface::initExistingSubsurfaces(wlr_surface* pSurface) {
227227
Vector2D CSubsurface::size() {
228228
return {m_sWLSurface.wlr()->current.width, m_sWLSurface.wlr()->current.height};
229229
}
230+
231+
bool CSubsurface::visible() {
232+
if (!m_pWindowParent.expired())
233+
return g_pHyprRenderer->shouldRenderWindow(m_pWindowParent.lock());
234+
if (m_pPopupParent)
235+
return m_pPopupParent->visible();
236+
if (m_pParent)
237+
return m_pParent->visible();
238+
239+
return false;
240+
}

src/desktop/Subsurface.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ class CSubsurface {
2929
void onMap();
3030
void onUnmap();
3131

32+
bool visible();
33+
3234
void recheckDamageForSubsurfaces();
3335

3436
private:

src/desktop/WLSurface.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,15 @@ void CWLSurface::onCommit() {
197197
std::shared_ptr<CPointerConstraint> CWLSurface::constraint() {
198198
return m_pConstraint.lock();
199199
}
200+
201+
bool CWLSurface::visible() {
202+
if (!m_pWindowOwner.expired())
203+
return g_pHyprRenderer->shouldRenderWindow(m_pWindowOwner.lock());
204+
if (!m_pLayerOwner.expired())
205+
return true;
206+
if (m_pPopupOwner)
207+
return m_pPopupOwner->visible();
208+
if (m_pSubsurfaceOwner)
209+
return m_pSubsurfaceOwner->visible();
210+
return true; // non-desktop, we don't know much.
211+
}

src/desktop/WLSurface.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class CWLSurface {
3333
Vector2D getViewporterCorrectedSize() const;
3434
CRegion logicalDamage() const;
3535
void onCommit();
36+
bool visible();
3637

3738
// getters for owners.
3839
PHLWINDOW getWindow();

src/managers/input/IdleInhibitor.cpp

+19-12
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,33 @@ void CInputManager::newIdleInhibitor(std::any inhibitor) {
1414
recheckIdleInhibitorStatus();
1515
});
1616

17-
const auto PWINDOW = g_pCompositor->getWindowFromSurface(PINHIBIT->inhibitor->surface);
18-
19-
if (PWINDOW) {
20-
PINHIBIT->pWindow = PWINDOW;
21-
PINHIBIT->windowDestroyListener = PWINDOW->events.destroy.registerListener([PINHIBIT](std::any data) {
22-
Debug::log(WARN, "Inhibitor got its window destroyed before its inhibitor resource.");
23-
PINHIBIT->pWindow.reset();
24-
});
25-
} else
26-
Debug::log(WARN, "Inhibitor is for no window?");
17+
auto WLSurface = CWLSurface::surfaceFromWlr(PINHIBIT->inhibitor->surface);
18+
19+
if (!WLSurface) {
20+
Debug::log(LOG, "Inhibitor has no HL Surface attached to it, likely meaning it's a non-desktop element. Ignoring.");
21+
PINHIBIT->inert = true;
22+
recheckIdleInhibitorStatus();
23+
return;
24+
}
25+
26+
PINHIBIT->surfaceDestroyListener = WLSurface->events.destroy.registerListener(
27+
[this, PINHIBIT](std::any data) { std::erase_if(m_vIdleInhibitors, [PINHIBIT](const auto& other) { return other.get() == PINHIBIT; }); });
28+
2729
recheckIdleInhibitorStatus();
2830
}
2931

3032
void CInputManager::recheckIdleInhibitorStatus() {
3133

3234
for (auto& ii : m_vIdleInhibitors) {
33-
if (ii->pWindow.expired())
35+
if (ii->inert)
36+
continue;
37+
38+
auto WLSurface = CWLSurface::surfaceFromWlr(ii->inhibitor->surface);
39+
40+
if (!WLSurface)
3441
continue;
3542

36-
if (g_pHyprRenderer->shouldRenderWindow(ii->pWindow.lock())) {
43+
if (WLSurface->visible()) {
3744
PROTO::idle->setInhibit(true);
3845
return;
3946
}

src/managers/input/InputManager.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,8 @@ class CInputManager {
242242
// idle inhibitors
243243
struct SIdleInhibitor {
244244
std::shared_ptr<CIdleInhibitor> inhibitor;
245-
PHLWINDOWREF pWindow;
246-
CHyprSignalListener windowDestroyListener;
245+
bool inert = false;
246+
CHyprSignalListener surfaceDestroyListener;
247247
};
248248
std::vector<std::unique_ptr<SIdleInhibitor>> m_vIdleInhibitors;
249249

0 commit comments

Comments
 (0)