Skip to content

Commit

Permalink
idle-inhibit: fix and cleanup visibility logic
Browse files Browse the repository at this point in the history
fixes #5878
  • Loading branch information
vaxerski committed May 4, 2024
1 parent a3309b5 commit 0b215c5
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/desktop/LayerSurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ PHLLS CLayerSurface::create(wlr_layer_surface_v1* pWLRLS) {

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

pLS->surface.assign(pWLRLS->surface);
pLS->surface.assign(pWLRLS->surface, pLS);

return pLS;
}
Expand Down
35 changes: 23 additions & 12 deletions src/desktop/Popup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ void CPopup::initAllSignals() {
if (!m_pWLR) {
if (!m_pWindowOwner.expired())
hyprListener_newPopup.initCallback(&m_pWindowOwner.lock()->m_uSurface.xdg->events.new_popup, ::onNewPopup, this, "CPopup Head");
else if (m_pLayerOwner)
hyprListener_newPopup.initCallback(&m_pLayerOwner->layerSurface->events.new_popup, ::onNewPopup, this, "CPopup Head");
else if (!m_pLayerOwner.expired())
hyprListener_newPopup.initCallback(&m_pLayerOwner.lock()->layerSurface->events.new_popup, ::onNewPopup, this, "CPopup Head");
else
ASSERT(false);

Expand Down Expand Up @@ -119,8 +119,8 @@ void CPopup::onMap() {
unconstrain();
sendScale();

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

void CPopup::onUnmap() {
Expand All @@ -136,8 +136,8 @@ void CPopup::onUnmap() {

g_pInputManager->simulateMouseMovement();

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

void CPopup::onCommit(bool ignoreSiblings) {
Expand Down Expand Up @@ -178,8 +178,8 @@ void CPopup::onCommit(bool ignoreSiblings) {

m_bRequestedReposition = false;

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

void CPopup::onReposition() {
Expand Down Expand Up @@ -232,8 +232,8 @@ Vector2D CPopup::localToGlobal(const Vector2D& rel) {
Vector2D CPopup::t1ParentCoords() {
if (!m_pWindowOwner.expired())
return m_pWindowOwner.lock()->m_vRealPosition.value();
if (m_pLayerOwner)
return m_pLayerOwner->realPosition.value();
if (!m_pLayerOwner.expired())
return m_pLayerOwner.lock()->realPosition.value();

ASSERT(false);
return {};
Expand Down Expand Up @@ -262,8 +262,19 @@ Vector2D CPopup::size() {
void CPopup::sendScale() {
if (!m_pWindowOwner.expired())
g_pCompositor->setPreferredScaleForSurface(m_sWLSurface.wlr(), m_pWindowOwner.lock()->m_pWLSurface.m_fLastScale);
else if (m_pLayerOwner)
g_pCompositor->setPreferredScaleForSurface(m_sWLSurface.wlr(), m_pLayerOwner->surface.m_fLastScale);
else if (!m_pLayerOwner.expired())
g_pCompositor->setPreferredScaleForSurface(m_sWLSurface.wlr(), m_pLayerOwner.lock()->surface.m_fLastScale);
else
UNREACHABLE();
}

bool CPopup::visible() {
if (!m_pWindowOwner.expired())
return g_pHyprRenderer->shouldRenderWindow(m_pWindowOwner.lock());
if (!m_pLayerOwner.expired())
return true;
if (m_pParent)
return m_pParent->visible();

return false;
}
4 changes: 3 additions & 1 deletion src/desktop/Popup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ class CPopup {

void recheckTree();

bool visible();

CWLSurface m_sWLSurface;

private:
// T1 owners, each popup has to have one of these
PHLWINDOWREF m_pWindowOwner;
PHLLS m_pLayerOwner;
PHLLSREF m_pLayerOwner;

// T2 owners
CPopup* m_pParent = nullptr;
Expand Down
11 changes: 11 additions & 0 deletions src/desktop/Subsurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,14 @@ void CSubsurface::initExistingSubsurfaces(wlr_surface* pSurface) {
Vector2D CSubsurface::size() {
return {m_sWLSurface.wlr()->current.width, m_sWLSurface.wlr()->current.height};
}

bool CSubsurface::visible() {
if (!m_pWindowParent.expired())
return g_pHyprRenderer->shouldRenderWindow(m_pWindowParent.lock());
if (m_pPopupParent)
return m_pPopupParent->visible();
if (m_pParent)
return m_pParent->visible();

return false;
}
2 changes: 2 additions & 0 deletions src/desktop/Subsurface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class CSubsurface {
void onMap();
void onUnmap();

bool visible();

void recheckDamageForSubsurfaces();

private:
Expand Down
12 changes: 12 additions & 0 deletions src/desktop/WLSurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,15 @@ void CWLSurface::onCommit() {
std::shared_ptr<CPointerConstraint> CWLSurface::constraint() {
return m_pConstraint.lock();
}

bool CWLSurface::visible() {
if (!m_pWindowOwner.expired())
return g_pHyprRenderer->shouldRenderWindow(m_pWindowOwner.lock());
if (!m_pLayerOwner.expired())
return true;
if (m_pPopupOwner)
return m_pPopupOwner->visible();
if (m_pSubsurfaceOwner)
return m_pSubsurfaceOwner->visible();
return true; // non-desktop, we don't know much.
}
1 change: 1 addition & 0 deletions src/desktop/WLSurface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class CWLSurface {
Vector2D getViewporterCorrectedSize() const;
CRegion logicalDamage() const;
void onCommit();
bool visible();

// getters for owners.
PHLWINDOW getWindow();
Expand Down
31 changes: 19 additions & 12 deletions src/managers/input/IdleInhibitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,33 @@ void CInputManager::newIdleInhibitor(std::any inhibitor) {
recheckIdleInhibitorStatus();
});

const auto PWINDOW = g_pCompositor->getWindowFromSurface(PINHIBIT->inhibitor->surface);

if (PWINDOW) {
PINHIBIT->pWindow = PWINDOW;
PINHIBIT->windowDestroyListener = PWINDOW->events.destroy.registerListener([PINHIBIT](std::any data) {
Debug::log(WARN, "Inhibitor got its window destroyed before its inhibitor resource.");
PINHIBIT->pWindow.reset();
});
} else
Debug::log(WARN, "Inhibitor is for no window?");
auto WLSurface = CWLSurface::surfaceFromWlr(PINHIBIT->inhibitor->surface);

if (!WLSurface) {
Debug::log(LOG, "Inhibitor has no HL Surface attached to it, likely meaning it's a non-desktop element. Ignoring.");
PINHIBIT->inert = true;
recheckIdleInhibitorStatus();
return;
}

PINHIBIT->surfaceDestroyListener = WLSurface->events.destroy.registerListener(
[this, PINHIBIT](std::any data) { std::erase_if(m_vIdleInhibitors, [PINHIBIT](const auto& other) { return other.get() == PINHIBIT; }); });

recheckIdleInhibitorStatus();
}

void CInputManager::recheckIdleInhibitorStatus() {

for (auto& ii : m_vIdleInhibitors) {
if (ii->pWindow.expired())
if (ii->inert)
continue;

auto WLSurface = CWLSurface::surfaceFromWlr(ii->inhibitor->surface);

if (!WLSurface)
continue;

if (g_pHyprRenderer->shouldRenderWindow(ii->pWindow.lock())) {
if (WLSurface->visible()) {
PROTO::idle->setInhibit(true);
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/managers/input/InputManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ class CInputManager {
// idle inhibitors
struct SIdleInhibitor {
std::shared_ptr<CIdleInhibitor> inhibitor;
PHLWINDOWREF pWindow;
CHyprSignalListener windowDestroyListener;
bool inert = false;
CHyprSignalListener surfaceDestroyListener;
};
std::vector<std::unique_ptr<SIdleInhibitor>> m_vIdleInhibitors;

Expand Down

0 comments on commit 0b215c5

Please sign in to comment.