From a3a92c7b8cf52706cdc29fbaf9e36ddebcc2adcf Mon Sep 17 00:00:00 2001 From: Xaver Hugl Date: Tue, 12 Nov 2024 15:08:11 +0000 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. (cherry picked from commit 8676141067d018aea3ff94d2e831b278e864e44e) Co-authored-by: Xaver Hugl --- 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 c60c9b5a17..273eda0513 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 6fb095697b..a6f12e1213 100644 --- a/src/core/output.h +++ b/src/core/output.h @@ -145,6 +145,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: