Commit b9bc1479 authored by Vlad Zahorodnii's avatar Vlad Zahorodnii
Browse files

wayland: Make the dpms protocol use Output directly

It simplifies the dpms protocol implementation by making it use the
Output directly. It also removes unrelated code in WaylandOutput and
OutputInterface that can be used for future cleanups, e.g. removing
WaylandOutput.
parent eeb701bf
Pipeline #222864 passed with stage
in 16 minutes and 16 seconds
......@@ -7,12 +7,10 @@
#include <QtTest>
// KWin
#include "wayland/display.h"
#include "wayland/dpms_interface.h"
#include "wayland/output_interface.h"
#include "wayland/xdgoutput_v1_interface.h"
#include "KWayland/Client/connection_thread.h"
#include "KWayland/Client/dpms.h"
#include "KWayland/Client/event_queue.h"
#include "KWayland/Client/output.h"
#include "KWayland/Client/registry.h"
......
......@@ -7,6 +7,8 @@
#include "dpms_interface_p.h"
#include "output_interface.h"
using namespace KWin;
namespace KWaylandServer
{
static const quint32 s_version = 1;
......@@ -26,11 +28,8 @@ void DpmsManagerInterfacePrivate::org_kde_kwin_dpms_manager_get(Resource *resour
wl_client_post_no_memory(resource->client());
return;
}
auto dpms = new DpmsInterface(o, dpms_resource);
dpms->sendSupported();
dpms->sendMode();
dpms->sendDone();
new DpmsInterface(o, dpms_resource);
}
DpmsManagerInterface::DpmsManagerInterface(Display *display, QObject *parent)
......@@ -44,20 +43,26 @@ DpmsManagerInterface::~DpmsManagerInterface() = default;
DpmsInterface::DpmsInterface(OutputInterface *output, wl_resource *resource)
: QObject()
, QtWaylandServer::org_kde_kwin_dpms(resource)
, output(output)
, m_output(output)
{
connect(output, &OutputInterface::dpmsSupportedChanged, this, [this] {
if (!m_output) {
return;
}
sendSupported();
sendMode();
sendDone();
connect(m_output->handle(), &Output::capabilitiesChanged, this, [this]() {
sendSupported();
sendDone();
});
connect(output, &KWaylandServer::OutputInterface::dpmsModeChanged, this, [this] {
connect(m_output->handle(), &Output::dpmsModeChanged, this, [this]() {
sendMode();
sendDone();
});
}
DpmsInterface::~DpmsInterface() = default;
void DpmsInterface::org_kde_kwin_dpms_release(Resource *resource)
{
wl_resource_destroy(resource->handle);
......@@ -72,34 +77,39 @@ void DpmsInterface::org_kde_kwin_dpms_destroy_resource(Resource *resource)
void DpmsInterface::org_kde_kwin_dpms_set(Resource *resource, uint32_t mode)
{
Q_UNUSED(resource)
KWin::Output::DpmsMode dpmsMode;
if (!m_output) {
return;
}
Output::DpmsMode dpmsMode;
switch (mode) {
case ORG_KDE_KWIN_DPMS_MODE_ON:
dpmsMode = KWin::Output::DpmsMode::On;
dpmsMode = Output::DpmsMode::On;
break;
case ORG_KDE_KWIN_DPMS_MODE_STANDBY:
dpmsMode = KWin::Output::DpmsMode::Standby;
dpmsMode = Output::DpmsMode::Standby;
break;
case ORG_KDE_KWIN_DPMS_MODE_SUSPEND:
dpmsMode = KWin::Output::DpmsMode::Suspend;
dpmsMode = Output::DpmsMode::Suspend;
break;
case ORG_KDE_KWIN_DPMS_MODE_OFF:
dpmsMode = KWin::Output::DpmsMode::Off;
dpmsMode = Output::DpmsMode::Off;
break;
default:
return;
}
Q_EMIT output->dpmsModeRequested(dpmsMode);
m_output->handle()->setDpmsMode(dpmsMode);
}
void DpmsInterface::sendSupported()
{
send_supported(output->isDpmsSupported() ? 1 : 0);
send_supported(m_output->handle()->capabilities() & Output::Capability::Dpms ? 1 : 0);
}
void DpmsInterface::sendMode()
{
const auto mode = output->dpmsMode();
const auto mode = m_output->handle()->dpmsMode();
org_kde_kwin_dpms_mode wlMode;
switch (mode) {
case KWin::Output::DpmsMode::On:
......
......@@ -7,10 +7,13 @@
#include "dpms_interface.h"
#include <QPointer>
#include <qwayland-server-dpms.h>
namespace KWaylandServer
{
class OutputInterface;
class DpmsManagerInterfacePrivate : public QtWaylandServer::org_kde_kwin_dpms_manager
......@@ -29,13 +32,12 @@ class DpmsInterface : public QObject, QtWaylandServer::org_kde_kwin_dpms
Q_OBJECT
public:
explicit DpmsInterface(OutputInterface *output, wl_resource *resource);
~DpmsInterface() override;
void sendSupported();
void sendMode();
void sendDone();
OutputInterface *output;
QPointer<OutputInterface> m_output;
protected:
void org_kde_kwin_dpms_destroy_resource(Resource *resource) override;
......
......@@ -43,11 +43,6 @@ public:
KWin::Output::SubPixel subPixel = KWin::Output::SubPixel::Unknown;
KWin::Output::Transform transform = KWin::Output::Transform::Normal;
OutputInterface::Mode mode;
struct
{
KWin::Output::DpmsMode mode = KWin::Output::DpmsMode::Off;
bool supported = false;
} dpms;
private:
void output_destroy_global() override;
......@@ -351,34 +346,6 @@ void OutputInterface::setTransform(KWin::Output::Transform transform)
Q_EMIT transformChanged(d->transform);
}
void OutputInterface::setDpmsMode(KWin::Output::DpmsMode mode)
{
if (d->dpms.mode == mode) {
return;
}
d->dpms.mode = mode;
Q_EMIT dpmsModeChanged();
}
void OutputInterface::setDpmsSupported(bool supported)
{
if (d->dpms.supported == supported) {
return;
}
d->dpms.supported = supported;
Q_EMIT dpmsSupportedChanged();
}
KWin::Output::DpmsMode OutputInterface::dpmsMode() const
{
return d->dpms.mode;
}
bool OutputInterface::isDpmsSupported() const
{
return d->dpms.supported;
}
QVector<wl_resource *> OutputInterface::clientResources(ClientConnection *client) const
{
const auto outputResources = d->resourceMap().values(client->client());
......@@ -392,14 +359,6 @@ QVector<wl_resource *> OutputInterface::clientResources(ClientConnection *client
return ret;
}
bool OutputInterface::isEnabled() const
{
if (!d->dpms.supported) {
return true;
}
return d->dpms.mode == KWin::Output::DpmsMode::On;
}
void OutputInterface::done()
{
const auto outputResources = d->resourceMap();
......
......@@ -65,8 +65,6 @@ public:
KWin::Output::SubPixel subPixel() const;
KWin::Output::Transform transform() const;
Mode mode() const;
bool isDpmsSupported() const;
KWin::Output::DpmsMode dpmsMode() const;
void setPhysicalSize(const QSize &size);
void setGlobalPosition(const QPoint &pos);
......@@ -78,27 +76,11 @@ public:
void setMode(const Mode &mode);
void setMode(const QSize &size, int refreshRate = 60000);
/**
* Sets whether Dpms is supported for this output.
* Default is @c false.
*/
void setDpmsSupported(bool supported);
/**
* Sets the currently used dpms mode.
* Default is @c DpmsMode::On.
*/
void setDpmsMode(KWin::Output::DpmsMode mode);
/**
* @returns all wl_resources bound for the @p client
*/
QVector<wl_resource *> clientResources(ClientConnection *client) const;
/**
* Returns @c true if the output is on; otherwise returns false.
*/
bool isEnabled() const;
/**
* Submit changes to all clients.
*/
......@@ -124,16 +106,8 @@ Q_SIGNALS:
void subPixelChanged(KWin::Output::SubPixel);
void transformChanged(KWin::Output::Transform);
void modeChanged();
void dpmsModeChanged();
void dpmsSupportedChanged();
void removed();
/**
* Change of dpms @p mode is requested.
* A server is free to ignore this request.
*/
void dpmsModeRequested(KWin::Output::DpmsMode mode);
/**
* Emitted when a client binds to a given output
* @internal
......
......@@ -24,8 +24,6 @@ WaylandOutput::WaylandOutput(Output *output, QObject *parent)
m_waylandOutput->setManufacturer(output->manufacturer());
m_waylandOutput->setModel(output->model());
m_waylandOutput->setPhysicalSize(output->physicalSize());
m_waylandOutput->setDpmsMode(output->dpmsMode());
m_waylandOutput->setDpmsSupported(output->capabilities() & Output::Capability::Dpms);
m_waylandOutput->setGlobalPosition(geometry.topLeft());
m_waylandOutput->setScale(std::ceil(output->scale()));
m_waylandOutput->setMode(output->modeSize(), output->refreshRate());
......@@ -39,12 +37,6 @@ WaylandOutput::WaylandOutput(Output *output, QObject *parent)
m_waylandOutput->done();
m_xdgOutputV1->done();
// The dpms functionality is not part of the wl_output interface, but org_kde_kwin_dpms.
connect(output, &Output::dpmsModeChanged,
this, &WaylandOutput::handleDpmsModeChanged);
connect(m_waylandOutput.get(), &KWaylandServer::OutputInterface::dpmsModeRequested,
this, &WaylandOutput::handleDpmsModeRequested);
// The timer is used to compress output updates so the wayland clients are not spammed.
m_updateTimer.setSingleShot(true);
connect(&m_updateTimer, &QTimer::timeout, this, &WaylandOutput::update);
......@@ -76,14 +68,4 @@ void WaylandOutput::update()
m_xdgOutputV1->done();
}
void WaylandOutput::handleDpmsModeChanged()
{
m_waylandOutput->setDpmsMode(m_platformOutput->dpmsMode());
}
void WaylandOutput::handleDpmsModeRequested(KWin::Output::DpmsMode dpmsMode)
{
m_platformOutput->setDpmsMode(dpmsMode);
}
} // namespace KWin
......@@ -24,9 +24,6 @@ public:
explicit WaylandOutput(Output *output, QObject *parent = nullptr);
private Q_SLOTS:
void handleDpmsModeChanged();
void handleDpmsModeRequested(KWin::Output::DpmsMode dpmsMode);
void update();
void scheduleUpdate();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment