From 0d9185053c0042f05470190ececf8606edb1c55c Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Tue, 20 Apr 2021 10:34:15 +0300 Subject: [PATCH] platforms/drm: Ignore udev events while session is inactive While the session is inactive, the drm master permissions are revoked. Therefore, we cannot perform things such as modesetting, etc. It also makes no sense to create or destroy DrmOutput objects. CCBUG: 435941 --- src/plugins/platforms/drm/drm_backend.cpp | 58 ++++++++++++----------- src/plugins/platforms/drm/drm_backend.h | 1 + 2 files changed, 32 insertions(+), 27 deletions(-) diff --git a/src/plugins/platforms/drm/drm_backend.cpp b/src/plugins/platforms/drm/drm_backend.cpp index 5622cbdf53..cf6ff9661b 100644 --- a/src/plugins/platforms/drm/drm_backend.cpp +++ b/src/plugins/platforms/drm/drm_backend.cpp @@ -158,8 +158,6 @@ void DrmBackend::reactivate() // only relevant in atomic mode o->m_modesetRequested = true; o->m_crtc->blank(o); - o->showCursor(); - o->moveCursor(); } } @@ -169,6 +167,11 @@ void DrmBackend::reactivate() if (Compositor *compositor = Compositor::self()) { compositor->addRepaintFull(); } + + // While the session had been inactive, an output could have been added or + // removed, we need to re-scan outputs. + updateOutputs(); + updateCursor(); } void DrmBackend::deactivate() @@ -247,27 +250,7 @@ bool DrmBackend::initialize() const int fd = m_udevMonitor->fd(); if (fd != -1) { QSocketNotifier *notifier = new QSocketNotifier(fd, QSocketNotifier::Read, this); - connect(notifier, &QSocketNotifier::activated, this, - [this] { - while (auto device = m_udevMonitor->getDevice()) { - bool drm = false; - for (auto gpu : m_gpus) { - if (gpu->drmId() == device->sysNum()) { - drm = true; - break; - } - } - if (!drm) { - return; - } - if (device->hasProperty("HOTPLUG", "1")) { - qCDebug(KWIN_DRM) << "Received hot plug event for monitored drm device"; - updateOutputs(); - updateCursor(); - } - } - } - ); + connect(notifier, &QSocketNotifier::activated, this, &DrmBackend::handleUdevEvent); m_udevMonitor->enable(); } } @@ -275,12 +258,33 @@ bool DrmBackend::initialize() return true; } +void DrmBackend::handleUdevEvent() +{ + while (auto device = m_udevMonitor->getDevice()) { + if (!session()->isActive()) { + continue; + } + + bool drm = false; + for (auto gpu : m_gpus) { + if (gpu->drmId() == device->sysNum()) { + drm = true; + break; + } + } + if (!drm) { + continue; + } + if (device->hasProperty("HOTPLUG", "1")) { + qCDebug(KWIN_DRM) << "Received hot plug event for monitored drm device"; + updateOutputs(); + updateCursor(); + } + } +} + void DrmBackend::addOutput(DrmOutput *o) { - if (!m_active) { - o->renderLoop()->inhibit(); - } - m_outputs.append(o); m_enabledOutputs.append(o); emit o->gpu()->outputEnabled(o); diff --git a/src/plugins/platforms/drm/drm_backend.h b/src/plugins/platforms/drm/drm_backend.h index d25fb1f9d9..cef842a872 100644 --- a/src/plugins/platforms/drm/drm_backend.h +++ b/src/plugins/platforms/drm/drm_backend.h @@ -103,6 +103,7 @@ private: QString generateOutputConfigurationUuid() const; DrmOutput *findOutput(quint32 connector); void updateOutputsEnabled(); + void handleUdevEvent(); QScopedPointer m_udev; QScopedPointer m_udevMonitor; Session *m_session = nullptr;