backends: move dpms input filter handling to Workspace

This commit is contained in:
Xaver Hugl 2023-09-26 16:36:06 +02:00
parent 66cef35c64
commit 99244efa3b
12 changed files with 49 additions and 88 deletions

View file

@ -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<DpmsInputEventFilter>();
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) {

View file

@ -9,17 +9,13 @@
#pragma once
#include "core/outputbackend.h"
#include "dpmsinputeventfilter.h"
#include <QPointer>
#include <QSize>
#include <QSocketNotifier>
#include <QVector>
// system
#include <sys/types.h>
#include <memory>
#include <sys/types.h>
namespace KWin
{
@ -43,8 +39,6 @@ public:
explicit DrmBackend(Session *session, QObject *parent = nullptr);
~DrmBackend() override;
Session *session() const;
std::unique_ptr<InputBackend> createInputBackend() override;
std::unique_ptr<QPainterBackend> createQPainterBackend() override;
std::unique_ptr<OpenGLBackend> createOpenGLBackend() override;
@ -53,9 +47,7 @@ public:
bool initialize() override;
Outputs outputs() const override;
void createDpmsFilter();
void checkOutputsAreOn();
Session *session() const override;
QVector<CompositingType> supportedCompositors() const override;
@ -76,7 +68,6 @@ public:
const std::vector<std::unique_ptr<DrmGpu>> &gpus() const;
public Q_SLOTS:
void turnOutputsOn();
void sceneInitialized() override;
Q_SIGNALS:
@ -102,7 +93,6 @@ private:
const QStringList m_explicitGpus;
std::vector<std::unique_ptr<DrmGpu>> m_gpus;
std::unique_ptr<DpmsInputEventFilter> m_dpmsFilter;
DrmRenderBackend *m_renderBackend = nullptr;
};

View file

@ -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<OutputChangeSet> &props
m_renderLoop->scheduleRepaint();
Q_EMIT changed();
if (isEnabled() && dpmsMode() == DpmsMode::On) {
m_gpu->platform()->turnOutputsOn();
}
}
void DrmOutput::revertQueuedChanges()

View file

@ -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<DpmsInputEventFilter>();
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);

View file

@ -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<WaylandSeat> m_seat;
WaylandEglBackend *m_eglBackend = nullptr;
QVector<WaylandOutput *> m_outputs;
std::unique_ptr<DpmsInputEventFilter> m_dpmsFilter;
bool m_pointerLockRequested = false;
FileDescriptor m_drmFileDescriptor;
gbm_device *m_gbmDevice = nullptr;

View file

@ -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();

View file

@ -102,6 +102,11 @@ void OutputBackend::setSceneEglGlobalShareContext(::EGLContext context)
m_globalShareContext = context;
}
Session *OutputBackend::session() const
{
return nullptr;
}
} // namespace KWin
#include "moc_outputbackend.cpp"

View file

@ -27,6 +27,7 @@ class OpenGLBackend;
class QPainterBackend;
class OutputConfiguration;
class EglDisplay;
class Session;
class KWIN_EXPORT Outputs : public QVector<Output *>
{
@ -93,6 +94,8 @@ public:
*/
virtual bool applyOutputChanges(const OutputConfiguration &config);
virtual Session *session() const;
public Q_SLOTS:
virtual void sceneInitialized(){};

View file

@ -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<bool>("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"

View file

@ -10,6 +10,7 @@
#include "input.h"
#include <QElapsedTimer>
#include <QObject>
#include <kwin_export.h>
@ -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;

View file

@ -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<Output *> &outputOrder)
for (Output *output : added) {
output->ref();
m_tileManagers[output] = std::make_unique<TileManager>(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<Output *> &outputOrder)
Q_EMIT outputsChanged();
}
void Workspace::createDpmsFilter()
{
if (!m_dpmsFilter) {
m_dpmsFilter = std::make_unique<DpmsInputEventFilter>();
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);

View file

@ -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<Output *> &outputOrder = {});
void createDpmsFilter();
void maybeDestroyDpmsFilter();
struct Constraint
{
@ -722,6 +725,7 @@ private:
std::map<Output *, std::unique_ptr<TileManager>> m_tileManagers;
std::unique_ptr<OutputConfigurationStore> m_outputConfigStore;
std::unique_ptr<LidSwitchTracker> m_lidSwitchTracker;
std::unique_ptr<DpmsInputEventFilter> m_dpmsFilter;
private:
friend bool performTransiencyCheck();