From 43f6c1e04132f27acfe9098d5e9a1a4cbc854fdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Tue, 1 Sep 2015 11:30:30 +0200 Subject: [PATCH] [wayland] Add support for DpmsInterface Our server announces the DpmsManagerInterface and in the DRM backend we announce support for Dpms on the OutputInterface (if the Output supports it) and we connect to changing Dpms requests. --- backends/drm/drm_backend.cpp | 48 ++++++++++++++++++++++++++++++++++++ wayland_server.cpp | 4 +++ 2 files changed, 52 insertions(+) diff --git a/backends/drm/drm_backend.cpp b/backends/drm/drm_backend.cpp index a1b1607cdb..9f24f0ecad 100644 --- a/backends/drm/drm_backend.cpp +++ b/backends/drm/drm_backend.cpp @@ -612,6 +612,40 @@ void DrmOutput::cleanupBlackBuffer() } } +static KWayland::Server::OutputInterface::DpmsMode toWaylandDpmsMode(DrmOutput::DpmsMode mode) +{ + using namespace KWayland::Server; + switch (mode) { + case DrmOutput::DpmsMode::On: + return OutputInterface::DpmsMode::On; + case DrmOutput::DpmsMode::Standby: + return OutputInterface::DpmsMode::Standby; + case DrmOutput::DpmsMode::Suspend: + return OutputInterface::DpmsMode::Suspend; + case DrmOutput::DpmsMode::Off: + return OutputInterface::DpmsMode::Off; + default: + Q_UNREACHABLE(); + } +} + +static DrmOutput::DpmsMode fromWaylandDpmsMode(KWayland::Server::OutputInterface::DpmsMode wlMode) +{ + using namespace KWayland::Server; + switch (wlMode) { + case OutputInterface::DpmsMode::On: + return DrmOutput::DpmsMode::On; + case OutputInterface::DpmsMode::Standby: + return DrmOutput::DpmsMode::Standby; + case OutputInterface::DpmsMode::Suspend: + return DrmOutput::DpmsMode::Suspend; + case OutputInterface::DpmsMode::Off: + return DrmOutput::DpmsMode::Off; + default: + Q_UNREACHABLE(); + } +} + void DrmOutput::init(drmModeConnector *connector) { initEdid(connector); @@ -683,6 +717,17 @@ void DrmOutput::init(drmModeConnector *connector) m_waylandOutput->addMode(QSize(m->hdisplay, m->vdisplay), flags, refreshRate); } + // set dpms + if (!m_dpms.isNull()) { + m_waylandOutput->setDpmsSupported(true); + m_waylandOutput->setDpmsMode(toWaylandDpmsMode(m_dpmsMode)); + connect(m_waylandOutput, &KWayland::Server::OutputInterface::dpmsModeRequested, this, + [this] (KWayland::Server::OutputInterface::DpmsMode mode) { + setDpms(fromWaylandDpmsMode(mode)); + }, Qt::QueuedConnection + ); + } + m_waylandOutput->create(); } @@ -909,6 +954,9 @@ void DrmOutput::setDpms(DrmOutput::DpmsMode mode) return; } m_dpmsMode = mode; + if (m_waylandOutput) { + m_waylandOutput->setDpmsMode(toWaylandDpmsMode(m_dpmsMode)); + } emit dpmsChanged(); if (m_dpmsMode != DpmsMode::On) { connect(input(), &InputRedirection::globalPointerChanged, this, &DrmOutput::reenableDpms); diff --git a/wayland_server.cpp b/wayland_server.cpp index 562edec95a..69493f74de 100644 --- a/wayland_server.cpp +++ b/wayland_server.cpp @@ -34,6 +34,7 @@ along with this program. If not, see . #include #include #include +#include #include #include #include @@ -63,6 +64,7 @@ WaylandServer::WaylandServer(QObject *parent) : QObject(parent) { qRegisterMetaType("KWayland::Server::SurfaceInterface *"); + qRegisterMetaType(); } WaylandServer::~WaylandServer() @@ -186,6 +188,8 @@ void WaylandServer::init(const QByteArray &socketName) ); auto shadowManager = m_display->createShadowManager(m_display); shadowManager->create(); + + m_display->createDpmsManager(m_display)->create(); } void WaylandServer::initWorkspace()