Commit ca3cbdf3 authored by Adrien Faveraux's avatar Adrien Faveraux Committed by Vlad Zahorodnii
Browse files

Migrate dpms to new approach

parent 56278245
......@@ -477,7 +477,7 @@ void TestWaylandOutput::testDpms()
using namespace KWayland::Client;
using namespace KWaylandServer;
m_display->createDpmsManager()->create();
m_display->createDpmsManager();
// set Dpms on the Output
QSignalSpy serverDpmsSupportedChangedSpy(m_serverOutput, &OutputInterface::dpmsSupportedChanged);
......@@ -572,7 +572,7 @@ void TestWaylandOutput::testDpmsRequestMode()
using namespace KWaylandServer;
// setup code
m_display->createDpmsManager()->create();
m_display->createDpmsManager();
// set Dpms on the Output
QSignalSpy serverDpmsSupportedChangedSpy(m_serverOutput, &OutputInterface::dpmsSupportedChanged);
......
......@@ -126,7 +126,7 @@ ecm_add_wayland_server_protocol(SERVER_LIB_SRCS
PROTOCOL ${PLASMA_WAYLAND_PROTOCOLS_DIR}/shadow.xml
BASENAME shadow
)
ecm_add_wayland_server_protocol(SERVER_LIB_SRCS
ecm_add_qtwayland_server_protocol(SERVER_LIB_SRCS
PROTOCOL ${PLASMA_WAYLAND_PROTOCOLS_DIR}/dpms.xml
BASENAME dpms
)
......
......@@ -10,71 +10,73 @@
namespace KWaylandServer
{
const quint32 DpmsManagerInterface::Private::s_version = 1;
const quint32 DpmsManagerInterfacePrivate::s_version = 1;
#ifndef K_DOXYGEN
const struct org_kde_kwin_dpms_manager_interface DpmsManagerInterface::Private::s_interface = {
getDpmsCallback
};
#endif
DpmsManagerInterface::Private::Private(DpmsManagerInterface *qptr, Display *d)
: Global::Private(d, &org_kde_kwin_dpms_manager_interface, s_version)
, q(qptr)
{
}
void DpmsManagerInterface::Private::bind(wl_client *client, uint32_t version, uint32_t id)
DpmsManagerInterfacePrivate::DpmsManagerInterfacePrivate(DpmsManagerInterface *_q, Display *display)
: QtWaylandServer::org_kde_kwin_dpms_manager(*display, s_version)
, q(_q)
{
auto c = display->getConnection(client);
wl_resource *dpms = c->createResource(&org_kde_kwin_dpms_manager_interface, qMin(version, s_version), id);
if (!dpms) {
wl_client_post_no_memory(client);
return;
}
wl_resource_set_implementation(dpms, &s_interface, this, nullptr);
}
void DpmsManagerInterface::Private::getDpmsCallback(wl_client *client, wl_resource *resource, uint32_t id, wl_resource *output)
void DpmsManagerInterfacePrivate::org_kde_kwin_dpms_manager_get(Resource *resource, uint32_t id, wl_resource *output)
{
auto p = Private::cast(resource);
auto c = p->display->getConnection(client);
OutputInterface *o = OutputInterface::get(output);
DpmsInterface *dpms = new DpmsInterface(o, resource, p->q);
dpms->create(c, wl_resource_get_version(resource), id);
if (!dpms->resource()) {
wl_resource_post_no_memory(resource);
wl_resource *dpms_resource = wl_resource_create(resource->client(), &org_kde_kwin_dpms_interface, resource->version(), id);
if (!dpms_resource) {
wl_client_post_no_memory(resource->client());
return;
}
auto dpms = new DpmsInterface(o, dpms_resource);
dpms->sendSupported();
dpms->sendMode();
dpms->sendDone();
}
DpmsManagerInterface::DpmsManagerInterface(Display *display, QObject *parent)
: Global(new Private(this, display), parent)
: QObject(parent)
, d(new DpmsManagerInterfacePrivate(this, display))
{
}
DpmsManagerInterface::~DpmsManagerInterface() = default;
DpmsInterface::DpmsInterface(OutputInterface *output, wl_resource *resource)
: QObject()
, QtWaylandServer::org_kde_kwin_dpms(resource)
, output(output)
{
connect(output, &OutputInterface::dpmsSupportedChanged, this,
[this] {
sendSupported();
sendDone();
}
);
connect(output, &OutputInterface::dpmsModeChanged, this,
[this] {
sendMode();
sendDone();
}
);
}
DpmsInterface::~DpmsInterface() = default;
#ifndef K_DOXYGEN
const struct org_kde_kwin_dpms_interface DpmsInterface::Private::s_interface = {
setCallback,
resourceDestroyedCallback
};
#endif
void DpmsInterface::org_kde_kwin_dpms_release(Resource *resource)
{
wl_resource_destroy(resource->handle);
}
DpmsInterface::Private::Private(DpmsInterface *q, DpmsManagerInterface *g, wl_resource *parentResource, OutputInterface *outputInterface)
: Resource::Private(q, g, parentResource, &org_kde_kwin_dpms_interface, &s_interface)
, output(outputInterface)
void DpmsInterface::org_kde_kwin_dpms_destroy_resource(Resource *resource)
{
Q_UNUSED(resource)
delete this;
}
void DpmsInterface::Private::setCallback(wl_client *client, wl_resource *resource, uint32_t mode)
void DpmsInterface::org_kde_kwin_dpms_set(Resource *resource, uint32_t mode)
{
Q_UNUSED(client)
Q_UNUSED(resource)
OutputInterface::DpmsMode dpmsMode;
switch (mode) {
case ORG_KDE_KWIN_DPMS_MODE_ON:
......@@ -92,38 +94,17 @@ void DpmsInterface::Private::setCallback(wl_client *client, wl_resource *resourc
default:
return;
}
emit cast<Private>(resource)->output->dpmsModeRequested(dpmsMode);
emit output->dpmsModeRequested(dpmsMode);
}
DpmsInterface::DpmsInterface(OutputInterface *output, wl_resource *parentResource, DpmsManagerInterface *manager)
: Resource(new Private(this, manager, parentResource, output))
{
connect(output, &OutputInterface::dpmsSupportedChanged, this,
[this] {
sendSupported();
sendDone();
}
);
connect(output, &OutputInterface::dpmsModeChanged, this,
[this] {
sendMode();
sendDone();
}
);
}
DpmsInterface::~DpmsInterface() = default;
void DpmsInterface::sendSupported()
{
Q_D();
org_kde_kwin_dpms_send_supported(d->resource, d->output->isDpmsSupported() ? 1 : 0);
send_supported(output->isDpmsSupported() ? 1 : 0);
}
void DpmsInterface::sendMode()
{
Q_D();
const auto mode = d->output->dpmsMode();
const auto mode = output->dpmsMode();
org_kde_kwin_dpms_mode wlMode;
switch (mode) {
case OutputInterface::DpmsMode::On:
......@@ -141,19 +122,12 @@ void DpmsInterface::sendMode()
default:
Q_UNREACHABLE();
}
org_kde_kwin_dpms_send_mode(d->resource, wlMode);
send_mode(wlMode);
}
void DpmsInterface::sendDone()
{
Q_D();
org_kde_kwin_dpms_send_done(d->resource);
client()->flush();
}
DpmsInterface::Private *DpmsInterface::d_func() const
{
return reinterpret_cast<Private*>(d.data());
send_done();
}
}
......@@ -9,12 +9,12 @@
#include <QObject>
#include <KWaylandServer/kwaylandserver_export.h>
#include "global.h"
namespace KWaylandServer
{
class Display;
class DpmsManagerInterfacePrivate;
/**
* @brief Global for server side Display Power Management Signaling interface.
......@@ -49,16 +49,16 @@ class Display;
* @see OutputInterface
* @since 5.5
**/
class KWAYLANDSERVER_EXPORT DpmsManagerInterface : public Global
class KWAYLANDSERVER_EXPORT DpmsManagerInterface : public QObject
{
Q_OBJECT
public:
virtual ~DpmsManagerInterface();
~DpmsManagerInterface() override;
private:
explicit DpmsManagerInterface(Display *display, QObject *parent = nullptr);
friend class Display;
class Private;
QScopedPointer<DpmsManagerInterfacePrivate> d;
};
}
......
......@@ -7,59 +7,44 @@
#define WAYLAND_SERVER_DPMS_INTERFACE_P_H
#include "dpms_interface.h"
#include "global_p.h"
#include "resource_p.h"
#include <wayland-dpms-server-protocol.h>
#include <qwayland-server-dpms.h>
namespace KWaylandServer
{
class OutputInterface;
class DpmsManagerInterface::Private : public Global::Private
class DpmsManagerInterfacePrivate : public QtWaylandServer::org_kde_kwin_dpms_manager
{
public:
Private(DpmsManagerInterface *q, Display *d);
private:
static void getDpmsCallback(wl_client *client, wl_resource *resource, uint32_t id, wl_resource *output);
static Private *cast(wl_resource *r) {
return reinterpret_cast<Private*>(wl_resource_get_user_data(r));
}
void bind(wl_client *client, uint32_t version, uint32_t id) override;
DpmsManagerInterfacePrivate(DpmsManagerInterface *q, Display *d);
DpmsManagerInterface *q;
static const struct org_kde_kwin_dpms_manager_interface s_interface;
static const quint32 s_version;
protected:
void org_kde_kwin_dpms_manager_get(Resource *resource, uint32_t id, wl_resource *output) override;
};
class DpmsInterface : public Resource
class DpmsInterface : public QObject, QtWaylandServer::org_kde_kwin_dpms
{
Q_OBJECT
public:
explicit DpmsInterface(OutputInterface *output, wl_resource *parentResource, DpmsManagerInterface *manager);
virtual ~DpmsInterface();
explicit DpmsInterface(OutputInterface *output, wl_resource *resource);
~DpmsInterface() override;
void sendSupported();
void sendMode();
void sendDone();
private:
class Private;
Private *d_func() const;
};
class DpmsInterface::Private : public Resource::Private
{
public:
explicit Private(DpmsInterface *q, DpmsManagerInterface *g, wl_resource *parentResource, OutputInterface *output);
OutputInterface *output;
private:
static void setCallback(wl_client *client, wl_resource *resource, uint32_t mode);
static const struct org_kde_kwin_dpms_interface s_interface;
protected:
void org_kde_kwin_dpms_destroy_resource(Resource *resource) override;
void org_kde_kwin_dpms_set(Resource *resource, uint32_t mode) override;
void org_kde_kwin_dpms_release(Resource *resource) override;
};
}
......
Markdown is supported
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