From 8676141067d018aea3ff94d2e831b278e864e44e Mon Sep 17 00:00:00 2001 From: Xaver Hugl Date: Mon, 11 Nov 2024 20:04:16 +0100 Subject: [PATCH] workspace: fix the dpms input event filter sometimes being wrongly deleted Before, it could break in the following scenario: - drm backend emits aboutToTurnOff - workspace creates the dpms filter - workspace gets some event that triggers it to update outputs - maybeDestroyDpmsFilter sees that the output is on and deletes the dpms filter - the drm backend actually turns the screen off In that case, the dpms input event filter is gone and the output off. Unless the dpms mode gets changed again by some other process, the output would now stay off forever. --- src/backends/drm/drm_output.cpp | 5 +++-- src/core/output.h | 1 + src/wayland/dpms.cpp | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/backends/drm/drm_output.cpp b/src/backends/drm/drm_output.cpp index b4334e490b..0c93a30f5d 100644 --- a/src/backends/drm/drm_output.cpp +++ b/src/backends/drm/drm_output.cpp @@ -143,6 +143,7 @@ void DrmOutput::setDpmsMode(DpmsMode mode) { if (mode == DpmsMode::Off) { if (!m_turnOffTimer.isActive()) { + updateDpmsMode(DpmsMode::AboutToTurnOff); Q_EMIT aboutToTurnOff(std::chrono::milliseconds(m_turnOffTimer.interval())); m_turnOffTimer.start(); } @@ -159,8 +160,8 @@ bool DrmOutput::setDrmDpmsMode(DpmsMode mode) if (!isEnabled()) { return false; } - bool active = mode == DpmsMode::On; - bool isActive = dpmsMode() == DpmsMode::On; + bool active = mode == DpmsMode::On || mode == DpmsMode::AboutToTurnOff; + bool isActive = dpmsMode() == DpmsMode::On || dpmsMode() == DpmsMode::AboutToTurnOff; if (active == isActive) { updateDpmsMode(mode); return true; diff --git a/src/core/output.h b/src/core/output.h index 3026fcb306..ee31df0708 100644 --- a/src/core/output.h +++ b/src/core/output.h @@ -148,6 +148,7 @@ public: Standby, Suspend, Off, + AboutToTurnOff, }; Q_ENUM(DpmsMode) diff --git a/src/wayland/dpms.cpp b/src/wayland/dpms.cpp index 206462a051..031e8b3c1f 100644 --- a/src/wayland/dpms.cpp +++ b/src/wayland/dpms.cpp @@ -148,6 +148,7 @@ void DpmsInterface::sendMode() org_kde_kwin_dpms_mode wlMode; switch (mode) { case Output::DpmsMode::On: + case Output::DpmsMode::AboutToTurnOff: wlMode = ORG_KDE_KWIN_DPMS_MODE_ON; break; case Output::DpmsMode::Standby: