From b0630313136195b3134e4e02e8dbf06ac5a4437a Mon Sep 17 00:00:00 2001 From: Xaver Hugl Date: Mon, 21 Feb 2022 19:12:12 +0100 Subject: [PATCH] backends/drm: block input with the placeholder output This is to prevent the user from accidentally changing application state while they don't have an output connected --- src/backends/drm/CMakeLists.txt | 1 + src/backends/drm/drm_backend.cpp | 3 + src/backends/drm/drm_backend.h | 2 + .../drm/placeholderinputeventfilter.cpp | 57 +++++++++++++++++++ .../drm/placeholderinputeventfilter.h | 27 +++++++++ 5 files changed, 90 insertions(+) create mode 100644 src/backends/drm/placeholderinputeventfilter.cpp create mode 100644 src/backends/drm/placeholderinputeventfilter.h diff --git a/src/backends/drm/CMakeLists.txt b/src/backends/drm/CMakeLists.txt index cf6f8e2834..53096f00e5 100644 --- a/src/backends/drm/CMakeLists.txt +++ b/src/backends/drm/CMakeLists.txt @@ -23,6 +23,7 @@ set(DRM_SOURCES drm_buffer_gbm.cpp gbm_surface.cpp gbm_dmabuf.cpp + placeholderinputeventfilter.cpp ) add_library(KWinWaylandDrmBackend MODULE ${DRM_SOURCES}) diff --git a/src/backends/drm/drm_backend.cpp b/src/backends/drm/drm_backend.cpp index 4105d73b09..c55bb8ea55 100644 --- a/src/backends/drm/drm_backend.cpp +++ b/src/backends/drm/drm_backend.cpp @@ -504,6 +504,7 @@ void DrmBackend::enableOutput(DrmAbstractOutput *output, bool enable) qCDebug(KWIN_DRM) << "removing placeholder output"; primaryGpu()->removeVirtualOutput(m_placeHolderOutput); m_placeHolderOutput = nullptr; + m_placeholderFilter.reset(); } } else { if (m_enabledOutputs.count() == 1 && m_outputs.count() > 1) { @@ -523,6 +524,8 @@ void DrmBackend::enableOutput(DrmAbstractOutput *output, bool enable) m_placeHolderOutput = primaryGpu()->createVirtualOutput({}, m_enabledOutputs.constFirst()->pixelSize(), 1, DrmGpu::Placeholder); // placeholder doesn't actually need to render anything m_placeHolderOutput->renderLoop()->inhibit(); + m_placeholderFilter.reset(new PlaceholderInputEventFilter()); + input()->prependInputEventFilter(m_placeholderFilter.data()); } m_enabledOutputs.removeOne(output); Q_EMIT output->gpu()->outputDisabled(output); diff --git a/src/backends/drm/drm_backend.h b/src/backends/drm/drm_backend.h index 9d64b0625e..5a91bf17de 100644 --- a/src/backends/drm/drm_backend.h +++ b/src/backends/drm/drm_backend.h @@ -11,6 +11,7 @@ #include "platform.h" #include "dpmsinputeventfilter.h" +#include "placeholderinputeventfilter.h" #include #include @@ -103,6 +104,7 @@ private: const QStringList m_explicitGpus; QVector m_gpus; QScopedPointer m_dpmsFilter; + QScopedPointer m_placeholderFilter; }; diff --git a/src/backends/drm/placeholderinputeventfilter.cpp b/src/backends/drm/placeholderinputeventfilter.cpp new file mode 100644 index 0000000000..73b4ba632f --- /dev/null +++ b/src/backends/drm/placeholderinputeventfilter.cpp @@ -0,0 +1,57 @@ +/* + KWin - the KDE window manager + This file is part of the KDE project. + + SPDX-FileCopyrightText: 2022 Xaver Hugl + + SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "placeholderinputeventfilter.h" + +namespace KWin +{ + +bool PlaceholderInputEventFilter::pointerEvent(QMouseEvent *event, quint32 nativeButton) +{ + Q_UNUSED(event) + Q_UNUSED(nativeButton) + return true; +} + +bool PlaceholderInputEventFilter::wheelEvent(QWheelEvent *event) +{ + Q_UNUSED(event) + return true; +} + +bool PlaceholderInputEventFilter::keyEvent(QKeyEvent *event) +{ + Q_UNUSED(event) + return true; +} + +bool PlaceholderInputEventFilter::touchDown(qint32 id, const QPointF &pos, quint32 time) +{ + Q_UNUSED(id) + Q_UNUSED(pos) + Q_UNUSED(time) + return true; +} + +bool PlaceholderInputEventFilter::touchMotion(qint32 id, const QPointF &pos, quint32 time) +{ + Q_UNUSED(id) + Q_UNUSED(pos) + Q_UNUSED(time) + return true; +} + +bool PlaceholderInputEventFilter::touchUp(qint32 id, quint32 time) +{ + Q_UNUSED(id) + Q_UNUSED(time) + return true; +} + +} diff --git a/src/backends/drm/placeholderinputeventfilter.h b/src/backends/drm/placeholderinputeventfilter.h new file mode 100644 index 0000000000..d2b5653ad0 --- /dev/null +++ b/src/backends/drm/placeholderinputeventfilter.h @@ -0,0 +1,27 @@ +/* + KWin - the KDE window manager + This file is part of the KDE project. + + SPDX-FileCopyrightText: 2022 Xaver Hugl + + SPDX-License-Identifier: GPL-2.0-or-later +*/ +#pragma once + +#include "input.h" + +namespace KWin +{ + +class PlaceholderInputEventFilter : public InputEventFilter +{ +public: + bool pointerEvent(QMouseEvent *event, quint32 nativeButton) override; + bool wheelEvent(QWheelEvent *event) override; + bool keyEvent(QKeyEvent *event) override; + bool touchDown(qint32 id, const QPointF &pos, quint32 time) override; + bool touchMotion(qint32 id, const QPointF &pos, quint32 time) override; + bool touchUp(qint32 id, quint32 time) override; +}; + +}