From 99244efa3b64029df021ecf1c97cff6b5a8d5265 Mon Sep 17 00:00:00 2001 From: Xaver Hugl Date: Tue, 26 Sep 2023 16:36:06 +0200 Subject: [PATCH] backends: move dpms input filter handling to Workspace --- src/backends/drm/drm_backend.cpp | 38 ------------------------ src/backends/drm/drm_backend.h | 14 ++------- src/backends/drm/drm_output.cpp | 13 -------- src/backends/wayland/wayland_backend.cpp | 16 ---------- src/backends/wayland/wayland_backend.h | 4 --- src/backends/wayland/wayland_output.cpp | 3 -- src/core/outputbackend.cpp | 5 ++++ src/core/outputbackend.h | 3 ++ src/dpmsinputeventfilter.cpp | 11 ++++++- src/dpmsinputeventfilter.h | 4 ++- src/workspace.cpp | 22 ++++++++++++++ src/workspace.h | 4 +++ 12 files changed, 49 insertions(+), 88 deletions(-) diff --git a/src/backends/drm/drm_backend.cpp b/src/backends/drm/drm_backend.cpp index 86ab35b3ac..ebe7e2ad4c 100644 --- a/src/backends/drm/drm_backend.cpp +++ b/src/backends/drm/drm_backend.cpp @@ -71,7 +71,6 @@ DrmBackend::DrmBackend(Session *session, QObject *parent) , m_udevMonitor(m_udev->monitor()) , m_session(session) , m_explicitGpus(splitPathList(qEnvironmentVariable("KWIN_DRM_DEVICES"), ':')) - , m_dpmsFilter() { } @@ -87,42 +86,6 @@ Outputs DrmBackend::outputs() const return m_outputs; } -void DrmBackend::createDpmsFilter() -{ - if (m_dpmsFilter) { - // already another output is off - return; - } - m_dpmsFilter = std::make_unique(); - input()->prependInputEventFilter(m_dpmsFilter.get()); -} - -void DrmBackend::turnOutputsOn() -{ - m_dpmsFilter.reset(); - for (Output *output : std::as_const(m_outputs)) { - if (output->isEnabled()) { - output->setDpmsMode(Output::DpmsMode::On); - } - } -} - -void DrmBackend::checkOutputsAreOn() -{ - if (!m_dpmsFilter) { - // already disabled, all outputs are on - return; - } - for (Output *output : std::as_const(m_outputs)) { - if (output->isEnabled() && output->dpmsMode() != Output::DpmsMode::On) { - // dpms still disabled, need to keep the filter - return; - } - } - // all outputs are on, disable the filter - m_dpmsFilter.reset(); -} - bool DrmBackend::initialize() { connect(m_session, &Session::devicePaused, this, [this](dev_t deviceId) { @@ -135,7 +98,6 @@ bool DrmBackend::initialize() gpu->setActive(true); } }); - connect(m_session, &Session::awoke, this, &DrmBackend::turnOutputsOn); if (!m_explicitGpus.isEmpty()) { for (const QString &fileName : m_explicitGpus) { diff --git a/src/backends/drm/drm_backend.h b/src/backends/drm/drm_backend.h index ec7cb40f4e..ba5f7d287c 100644 --- a/src/backends/drm/drm_backend.h +++ b/src/backends/drm/drm_backend.h @@ -9,17 +9,13 @@ #pragma once #include "core/outputbackend.h" -#include "dpmsinputeventfilter.h" - #include #include #include #include -// system -#include - #include +#include namespace KWin { @@ -43,8 +39,6 @@ public: explicit DrmBackend(Session *session, QObject *parent = nullptr); ~DrmBackend() override; - Session *session() const; - std::unique_ptr createInputBackend() override; std::unique_ptr createQPainterBackend() override; std::unique_ptr createOpenGLBackend() override; @@ -53,9 +47,7 @@ public: bool initialize() override; Outputs outputs() const override; - - void createDpmsFilter(); - void checkOutputsAreOn(); + Session *session() const override; QVector supportedCompositors() const override; @@ -76,7 +68,6 @@ public: const std::vector> &gpus() const; public Q_SLOTS: - void turnOutputsOn(); void sceneInitialized() override; Q_SIGNALS: @@ -102,7 +93,6 @@ private: const QStringList m_explicitGpus; std::vector> m_gpus; - std::unique_ptr m_dpmsFilter; DrmRenderBackend *m_renderBackend = nullptr; }; diff --git a/src/backends/drm/drm_output.cpp b/src/backends/drm/drm_output.cpp index d7b7f8c575..85a3103666 100644 --- a/src/backends/drm/drm_output.cpp +++ b/src/backends/drm/drm_output.cpp @@ -156,11 +156,7 @@ void DrmOutput::setDpmsMode(DpmsMode mode) Q_EMIT aboutToTurnOff(std::chrono::milliseconds(m_turnOffTimer.interval())); m_turnOffTimer.start(); } - if (isEnabled()) { - m_gpu->platform()->createDpmsFilter(); - } } else { - m_gpu->platform()->checkOutputsAreOn(); if (m_turnOffTimer.isActive() || (mode != dpmsMode() && setDrmDpmsMode(mode))) { Q_EMIT wakeUp(); } @@ -187,20 +183,15 @@ bool DrmOutput::setDrmDpmsMode(DpmsMode mode) m_pipeline->applyPendingChanges(); updateDpmsMode(mode); if (active) { - m_gpu->platform()->checkOutputsAreOn(); m_renderLoop->uninhibit(); m_renderLoop->scheduleRepaint(); } else { m_renderLoop->inhibit(); - m_gpu->platform()->createDpmsFilter(); } return true; } else { qCWarning(KWIN_DRM) << "Setting dpms mode failed!"; m_pipeline->revertPendingChanges(); - if (isEnabled() && isActive && !active) { - m_gpu->platform()->checkOutputsAreOn(); - } return false; } } @@ -359,10 +350,6 @@ void DrmOutput::applyQueuedChanges(const std::shared_ptr &props m_renderLoop->scheduleRepaint(); Q_EMIT changed(); - - if (isEnabled() && dpmsMode() == DpmsMode::On) { - m_gpu->platform()->turnOutputsOn(); - } } void DrmOutput::revertQueuedChanges() diff --git a/src/backends/wayland/wayland_backend.cpp b/src/backends/wayland/wayland_backend.cpp index b6dac79694..dedbb21cb8 100644 --- a/src/backends/wayland/wayland_backend.cpp +++ b/src/backends/wayland/wayland_backend.cpp @@ -8,7 +8,6 @@ SPDX-License-Identifier: GPL-2.0-or-later */ #include "wayland_backend.h" -#include "dpmsinputeventfilter.h" #include "input.h" #include "wayland_display.h" #include "wayland_egl_backend.h" @@ -578,21 +577,6 @@ Outputs WaylandBackend::outputs() const return m_outputs; } -void WaylandBackend::createDpmsFilter() -{ - if (m_dpmsFilter) { - // already another output is off - return; - } - m_dpmsFilter = std::make_unique(); - input()->prependInputEventFilter(m_dpmsFilter.get()); -} - -void WaylandBackend::clearDpmsFilter() -{ - m_dpmsFilter.reset(); -} - Output *WaylandBackend::createVirtualOutput(const QString &name, const QSize &size, double scale) { return createOutput(name, size * scale, scale); diff --git a/src/backends/wayland/wayland_backend.h b/src/backends/wayland/wayland_backend.h index bd4496348c..bec23595ac 100644 --- a/src/backends/wayland/wayland_backend.h +++ b/src/backends/wayland/wayland_backend.h @@ -44,7 +44,6 @@ class Touch; namespace KWin { -class DpmsInputEventFilter; class GraphicsBuffer; namespace Wayland @@ -236,8 +235,6 @@ public: { return m_outputs; } - void createDpmsFilter(); - void clearDpmsFilter(); Output *createVirtualOutput(const QString &name, const QSize &size, double scale) override; void removeVirtualOutput(Output *output) override; @@ -269,7 +266,6 @@ private: std::unique_ptr m_seat; WaylandEglBackend *m_eglBackend = nullptr; QVector m_outputs; - std::unique_ptr m_dpmsFilter; bool m_pointerLockRequested = false; FileDescriptor m_drmFileDescriptor; gbm_device *m_gbmDevice = nullptr; diff --git a/src/backends/wayland/wayland_output.cpp b/src/backends/wayland/wayland_output.cpp index ae0bbe7317..be5652d71b 100644 --- a/src/backends/wayland/wayland_output.cpp +++ b/src/backends/wayland/wayland_output.cpp @@ -211,11 +211,8 @@ void WaylandOutput::setDpmsMode(DpmsMode mode) Q_EMIT aboutToTurnOff(std::chrono::milliseconds(m_turnOffTimer.interval())); m_turnOffTimer.start(); } - m_backend->createDpmsFilter(); } else { m_turnOffTimer.stop(); - m_backend->clearDpmsFilter(); - if (mode != dpmsMode()) { updateDpmsMode(mode); Q_EMIT wakeUp(); diff --git a/src/core/outputbackend.cpp b/src/core/outputbackend.cpp index c2aef5ef6f..8fb0e8b667 100644 --- a/src/core/outputbackend.cpp +++ b/src/core/outputbackend.cpp @@ -102,6 +102,11 @@ void OutputBackend::setSceneEglGlobalShareContext(::EGLContext context) m_globalShareContext = context; } +Session *OutputBackend::session() const +{ + return nullptr; +} + } // namespace KWin #include "moc_outputbackend.cpp" diff --git a/src/core/outputbackend.h b/src/core/outputbackend.h index 00f754f5df..6734752497 100644 --- a/src/core/outputbackend.h +++ b/src/core/outputbackend.h @@ -27,6 +27,7 @@ class OpenGLBackend; class QPainterBackend; class OutputConfiguration; class EglDisplay; +class Session; class KWIN_EXPORT Outputs : public QVector { @@ -93,6 +94,8 @@ public: */ virtual bool applyOutputChanges(const OutputConfiguration &config); + virtual Session *session() const; + public Q_SLOTS: virtual void sceneInitialized(){}; diff --git a/src/dpmsinputeventfilter.cpp b/src/dpmsinputeventfilter.cpp index 78f944ea7b..3ff862577c 100644 --- a/src/dpmsinputeventfilter.cpp +++ b/src/dpmsinputeventfilter.cpp @@ -8,6 +8,8 @@ */ #include "dpmsinputeventfilter.h" #include "core/output.h" +#include "core/outputbackend.h" +#include "core/session.h" #include "input_event.h" #include "main.h" #include "wayland/seat.h" @@ -25,9 +27,15 @@ DpmsInputEventFilter::DpmsInputEventFilter() { KSharedConfig::Ptr kwinSettings = kwinApp()->config(); m_enableDoubleTap = kwinSettings->group("Wayland").readEntry("DoubleTapWakeup", true); + if (Session *session = kwinApp()->outputBackend()->session()) { + connect(session, &Session::awoke, this, &DpmsInputEventFilter::notify); + } } -DpmsInputEventFilter::~DpmsInputEventFilter() = default; +DpmsInputEventFilter::~DpmsInputEventFilter() +{ + notify(); +} bool DpmsInputEventFilter::pointerEvent(MouseEvent *event, quint32 nativeButton) { @@ -105,3 +113,4 @@ void DpmsInputEventFilter::notify() } } +#include "moc_dpmsinputeventfilter.cpp" diff --git a/src/dpmsinputeventfilter.h b/src/dpmsinputeventfilter.h index 3d82b530d4..90376f4d25 100644 --- a/src/dpmsinputeventfilter.h +++ b/src/dpmsinputeventfilter.h @@ -10,6 +10,7 @@ #include "input.h" #include +#include #include @@ -18,8 +19,9 @@ namespace KWin class DrmBackend; -class KWIN_EXPORT DpmsInputEventFilter : public InputEventFilter +class KWIN_EXPORT DpmsInputEventFilter : public QObject, public InputEventFilter { + Q_OBJECT public: DpmsInputEventFilter(); ~DpmsInputEventFilter() override; diff --git a/src/workspace.cpp b/src/workspace.cpp index c407379ab8..88fd07ec9c 100644 --- a/src/workspace.cpp +++ b/src/workspace.cpp @@ -45,6 +45,7 @@ #include "tabbox/tabbox.h" #endif #include "decorations/decorationbridge.h" +#include "dpmsinputeventfilter.h" #include "lidswitchtracker.h" #include "main.h" #include "outputconfigurationstore.h" @@ -1289,8 +1290,11 @@ void Workspace::updateOutputs(const QVector &outputOrder) for (Output *output : added) { output->ref(); m_tileManagers[output] = std::make_unique(output); + connect(output, &Output::aboutToTurnOff, this, &Workspace::createDpmsFilter); + connect(output, &Output::dpmsModeChanged, this, &Workspace::maybeDestroyDpmsFilter); Q_EMIT outputAdded(output); } + maybeDestroyDpmsFilter(); const auto removed = oldOutputsSet - outputsSet; for (Output *output : removed) { @@ -1343,6 +1347,24 @@ void Workspace::updateOutputs(const QVector &outputOrder) Q_EMIT outputsChanged(); } +void Workspace::createDpmsFilter() +{ + if (!m_dpmsFilter) { + m_dpmsFilter = std::make_unique(); + input()->prependInputEventFilter(m_dpmsFilter.get()); + } +} + +void Workspace::maybeDestroyDpmsFilter() +{ + const bool allOn = std::all_of(m_outputs.begin(), m_outputs.end(), [](Output *output) { + return output->dpmsMode() == Output::DpmsMode::On; + }); + if (allOn) { + m_dpmsFilter.reset(); + } +} + void Workspace::slotDesktopAdded(VirtualDesktop *desktop) { m_focusChain->addDesktop(desktop); diff --git a/src/workspace.h b/src/workspace.h index 23021834da..84076cfed9 100644 --- a/src/workspace.h +++ b/src/workspace.h @@ -78,6 +78,7 @@ class OutputConfiguration; class TileManager; class OutputConfigurationStore; class LidSwitchTracker; +class DpmsInputEventFilter; class KWIN_EXPORT Workspace : public QObject { @@ -607,6 +608,8 @@ private: void updateOutputConfiguration(); void updateOutputs(const QVector &outputOrder = {}); + void createDpmsFilter(); + void maybeDestroyDpmsFilter(); struct Constraint { @@ -722,6 +725,7 @@ private: std::map> m_tileManagers; std::unique_ptr m_outputConfigStore; std::unique_ptr m_lidSwitchTracker; + std::unique_ptr m_dpmsFilter; private: friend bool performTransiencyCheck();