move output device to the news approach

This commit is contained in:
Adrien Faveraux 2021-03-11 11:12:25 +01:00
parent d853b08659
commit 54d3d7e68f
6 changed files with 198 additions and 390 deletions

View file

@ -85,9 +85,9 @@ ecm_add_wayland_server_protocol(SERVER_LIB_SRCS
BASENAME output-management
)
ecm_add_wayland_server_protocol(SERVER_LIB_SRCS
ecm_add_qtwayland_server_protocol_kde(SERVER_LIB_SRCS
PROTOCOL ${PLASMA_WAYLAND_PROTOCOLS_DIR}/outputdevice.xml
BASENAME org_kde_kwin_outputdevice
BASENAME org-kde-kwin-outputdevice
)
ecm_add_qtwayland_server_protocol_kde(SERVER_LIB_SRCS

View file

@ -30,9 +30,6 @@ private Q_SLOTS:
void testRegistry();
void testModeChanges();
#if KWAYLANDSERVER_ENABLE_DEPRECATED_SINCE(5, 50)
void testScaleChange_legacy();
#endif
void testScaleChange();
void testColorCurvesChange();
@ -76,6 +73,7 @@ TestWaylandOutputDevice::TestWaylandOutputDevice(QObject *parent)
void TestWaylandOutputDevice::init()
{
using namespace KWaylandServer;
qRegisterMetaType<OutputDevice::Enablement>();
delete m_display;
m_display = new Display(this);
m_display->addSocketName(s_socketName);
@ -128,8 +126,6 @@ void TestWaylandOutputDevice::init()
}
m_serverOutputDevice->setColorCurves(m_initColorCurves);
m_serverOutputDevice->create();
// setup connection
m_connection = new KWayland::Client::ConnectionThread;
QSignalSpy connectedSpy(m_connection, &KWayland::Client::ConnectionThread::connected);
@ -187,7 +183,7 @@ void TestWaylandOutputDevice::testRegistry()
KWayland::Client::OutputDevice output;
QVERIFY(!output.isValid());
QCOMPARE(output.uuid(), QByteArray());
QCOMPARE(output.uuid(), QString());
QCOMPARE(output.geometry(), QRect());
QCOMPARE(output.globalPosition(), QPoint());
QCOMPARE(output.manufacturer(), QString());
@ -195,9 +191,6 @@ void TestWaylandOutputDevice::testRegistry()
QCOMPARE(output.physicalSize(), QSize());
QCOMPARE(output.pixelSize(), QSize());
QCOMPARE(output.refreshRate(), 0);
#if KWAYLANDSERVER_ENABLE_DEPRECATED_SINCE(5, 50)
QCOMPARE(output.scale(), 1);
#endif
QCOMPARE(output.scaleF(), 1.0);
QCOMPARE(output.colorCurves().red, QVector<quint16>());
QCOMPARE(output.colorCurves().green, QVector<quint16>());
@ -224,9 +217,6 @@ void TestWaylandOutputDevice::testRegistry()
QCOMPARE(output.physicalSize(), QSize(200, 100));
QCOMPARE(output.pixelSize(), QSize(1024, 768));
QCOMPARE(output.refreshRate(), 60000);
#if KWAYLANDSERVER_ENABLE_DEPRECATED_SINCE(5, 50)
QCOMPARE(output.scale(), 1);
#endif
QCOMPARE(output.scaleF(), 1.0);
QCOMPARE(output.colorCurves().red, m_initColorCurves.red);
QCOMPARE(output.colorCurves().green, m_initColorCurves.green);
@ -238,7 +228,7 @@ void TestWaylandOutputDevice::testRegistry()
QCOMPARE(output.edid(), m_edid);
QCOMPARE(output.enabled(), OutputDevice::Enablement::Enabled);
QCOMPARE(output.uuid(), QByteArray("1337"));
QCOMPARE(output.uuid(), QStringLiteral("1337"));
QCOMPARE(output.serialNumber(), m_serialNumber);
QCOMPARE(output.eisaId(), m_eidaId);
}
@ -340,46 +330,6 @@ void TestWaylandOutputDevice::testModeChanges()
QCOMPARE(output.pixelSize(), QSize(1280, 1024));
}
#if KWAYLANDSERVER_ENABLE_DEPRECATED_SINCE(5, 50)
void TestWaylandOutputDevice::testScaleChange_legacy()
{
KWayland::Client::Registry registry;
QSignalSpy interfacesAnnouncedSpy(&registry, &KWayland::Client::Registry::interfacesAnnounced);
QVERIFY(interfacesAnnouncedSpy.isValid());
QSignalSpy announced(&registry, &KWayland::Client::Registry::outputDeviceAnnounced);
registry.setEventQueue(m_queue);
registry.create(m_connection->display());
QVERIFY(registry.isValid());
registry.setup();
wl_display_flush(m_connection->display());
QVERIFY(interfacesAnnouncedSpy.wait());
KWayland::Client::OutputDevice output;
QSignalSpy outputChanged(&output, &KWayland::Client::OutputDevice::done);
QVERIFY(outputChanged.isValid());
output.setup(registry.bindOutputDevice(announced.first().first().value<quint32>(), announced.first().last().value<quint32>()));
wl_display_flush(m_connection->display());
QVERIFY(outputChanged.wait());
QCOMPARE(output.scale(), 1);
QCOMPARE(output.scaleF(), 1.0);
// change the scale
outputChanged.clear();
m_serverOutputDevice->setScale(2);
QVERIFY(outputChanged.wait());
QCOMPARE(output.scale(), 2);
QCOMPARE(output.scaleF(), 2.0); //check we're forward compatible
// change once more
outputChanged.clear();
m_serverOutputDevice->setScale(4);
QVERIFY(outputChanged.wait());
QCOMPARE(output.scale(), 4);
QCOMPARE(output.scaleF(), 4.0);
}
#endif
void TestWaylandOutputDevice::testScaleChange()
{
KWayland::Client::Registry registry;
@ -405,18 +355,12 @@ void TestWaylandOutputDevice::testScaleChange()
outputChanged.clear();
m_serverOutputDevice->setScaleF(2.2);
QVERIFY(outputChanged.wait());
#if KWAYLANDSERVER_ENABLE_DEPRECATED_SINCE(5, 50)
QCOMPARE(output.scale(), 2); //check backwards compatibility works
#endif
QCOMPARE(wl_fixed_from_double(output.scaleF()), wl_fixed_from_double(2.2));
// change once more
outputChanged.clear();
m_serverOutputDevice->setScaleF(4.9);
QVERIFY(outputChanged.wait());
#if KWAYLANDSERVER_ENABLE_DEPRECATED_SINCE(5, 50)
QCOMPARE(output.scale(), 5);
#endif
QCOMPARE(wl_fixed_from_double(output.scaleF()), wl_fixed_from_double(4.9));
}
@ -652,7 +596,7 @@ void TestWaylandOutputDevice::testId()
wl_display_flush(m_connection->display());
QVERIFY(outputChanged.wait());
QCOMPARE(output.uuid(), QByteArray("1337"));
QCOMPARE(output.uuid(), QStringLiteral("1337"));
QSignalSpy idChanged(&output, &KWayland::Client::OutputDevice::uuidChanged);
QVERIFY(idChanged.isValid());
@ -661,13 +605,13 @@ void TestWaylandOutputDevice::testId()
QVERIFY(idChanged.wait());
QCOMPARE(idChanged.first().first().toByteArray(), QByteArray("42"));
idChanged.clear();
QCOMPARE(output.uuid(), QByteArray("42"));
QCOMPARE(output.uuid(), QStringLiteral("42"));
m_serverOutputDevice->setUuid("4711");
QVERIFY(idChanged.wait());
QCOMPARE(idChanged.first().first().toByteArray(), QByteArray("4711"));
idChanged.clear();
QCOMPARE(output.uuid(), QByteArray("4711"));
QCOMPARE(output.uuid(), QStringLiteral("4711"));
}
void TestWaylandOutputDevice::testDone()

View file

@ -126,7 +126,6 @@ void TestWaylandOutputManagement::init()
outputDeviceInterface->setCurrentMode(1);
outputDeviceInterface->setGlobalPosition(QPoint(0, 1920));
outputDeviceInterface->create();
m_serverOutputs << outputDeviceInterface;
m_outputManagementInterface = new OutputManagementInterface(m_display, this);
@ -249,9 +248,6 @@ void TestWaylandOutputManagement::createOutputDevices()
QCOMPARE(output->physicalSize(), QSize());
QCOMPARE(output->pixelSize(), QSize());
QCOMPARE(output->refreshRate(), 0);
#if KWAYLANDSERVER_ENABLE_DEPRECATED_SINCE(5, 50)
QCOMPARE(output->scale(), 1);
#endif
QCOMPARE(output->scaleF(), 1.0);
QCOMPARE(output->colorCurves().red, QVector<quint16>());
QCOMPARE(output->colorCurves().green, QVector<quint16>());
@ -260,7 +256,7 @@ void TestWaylandOutputManagement::createOutputDevices()
QCOMPARE(output->transform(), KWayland::Client::OutputDevice::Transform::Normal);
QCOMPARE(output->enabled(), OutputDevice::Enablement::Enabled);
QCOMPARE(output->edid(), QByteArray());
QCOMPARE(output->uuid(), QByteArray());
QCOMPARE(output->uuid(), QString());
QSignalSpy outputChanged(output, &KWayland::Client::OutputDevice::changed);
QVERIFY(outputChanged.isValid());
@ -407,7 +403,7 @@ void TestWaylandOutputManagement::testMultipleSettings()
QVERIFY(configAppliedSpy.isValid());
QVERIFY(configAppliedSpy.wait(200));
QCOMPARE(configAppliedSpy.count(), 1);
QCOMPARE(outputChangedSpy.count(), 6);
QCOMPARE(outputChangedSpy.count(), 5);
config->setMode(output, m_modes.at(1).id);
config->setTransform(output, OutputDevice::Transform::Normal);
@ -425,7 +421,7 @@ void TestWaylandOutputManagement::testMultipleSettings()
QVERIFY(configAppliedSpy.wait(200));
QCOMPARE(configAppliedSpy.count(), 2);
QCOMPARE(outputChangedSpy.count(), 12);
QCOMPARE(outputChangedSpy.count(), 10);
}
@ -433,11 +429,9 @@ void TestWaylandOutputManagement::testConfigFailed()
{
createConfig();
auto config = m_outputConfiguration;
auto s_o = m_serverOutputs.first();
KWayland::Client::OutputDevice *output = m_clientOutputs.first();
QVERIFY(config->isValid());
QVERIFY(s_o->isValid());
QVERIFY(output->isValid());
QSignalSpy serverApplySpy(m_outputManagementInterface, &OutputManagementInterface::configurationChangeRequested);
@ -507,23 +501,7 @@ void TestWaylandOutputManagement::testScale()
QVERIFY(configAppliedSpy.isValid());
QVERIFY(configAppliedSpy.wait(200));
#if KWAYLANDSERVER_ENABLE_DEPRECATED_SINCE(5, 50)
QCOMPARE(output->scale(), 2); //test backwards compatibility
#endif
QCOMPARE(wl_fixed_from_double(output->scaleF()), wl_fixed_from_double(2.3));
#if KWAYLANDSERVER_ENABLE_DEPRECATED_SINCE(5, 50)
config->setScale(output, 3);
config->apply();
QVERIFY(configAppliedSpy.isValid());
QVERIFY(configAppliedSpy.wait(200));
//will be setApplied using the connect above
QCOMPARE(output->scale(), 3);
QCOMPARE(output->scaleF(), 3.0); //test forward compatibility
#endif
}

View file

@ -13,7 +13,7 @@
#include <wayland-server.h>
#include "wayland-output-management-server-protocol.h"
#include "wayland-org_kde_kwin_outputdevice-server-protocol.h"
#include "wayland-org-kde-kwin-outputdevice-server-protocol.h"
#include <QDebug>
#include <QSize>

View file

@ -5,27 +5,25 @@
*/
#include "outputdevice_interface.h"
#include "display_p.h"
#include "global_p.h"
#include "display.h"
#include "logging.h"
#include "utils.h"
#include <wayland-server.h>
#include "wayland-org_kde_kwin_outputdevice-server-protocol.h"
#include "qwayland-server-org-kde-kwin-outputdevice.h"
#include <QDebug>
#include <QString>
#include <QPointer>
namespace KWaylandServer
{
class OutputDeviceInterface::Private : public Global::Private
static const quint32 s_version = 2;
class OutputDeviceInterfacePrivate : public QtWaylandServer::org_kde_kwin_outputdevice
{
public:
struct ResourceData {
wl_resource *resource;
uint32_t version;
};
Private(OutputDeviceInterface *q, Display *d);
~Private();
OutputDeviceInterfacePrivate(OutputDeviceInterface *q, Display *display);
~OutputDeviceInterfacePrivate() override;
void updateGeometry();
void updateUuid();
@ -36,16 +34,18 @@ public:
void updateEisaId();
void updateSerialNumber();
void sendGeometry(wl_resource *resource);
void sendMode(wl_resource *resource, const Mode &mode);
void sendDone(const ResourceData &data);
void sendUuid(const ResourceData &data);
void sendEdid(const ResourceData &data);
void sendEnabled(const ResourceData &data);
void sendScale(const ResourceData &data);
void sendColorCurves(const ResourceData &data);
void sendEisaId(const ResourceData &data);
void sendSerialNumber(const ResourceData &data);
void sendGeometry(Resource *resource);
void sendMode(Resource *resource, const OutputDeviceInterface::Mode &mode);
void sendDone(Resource *resource);
void sendUuid(Resource *resource);
void sendEdid(Resource *resource);
void sendEnabled(Resource *resource);
void sendScale(Resource *resource);
void sendColorCurves(Resource *resource);
void sendEisaId(Resource *resource);
void sendSerialNumber(Resource *resource);
static OutputDeviceInterface *get(wl_resource *native);
QSize physicalSize;
QPoint globalPosition;
@ -54,119 +54,78 @@ public:
qreal scale = 1.0;
QString serialNumber;
QString eisaId;
SubPixel subPixel = SubPixel::Unknown;
Transform transform = Transform::Normal;
ColorCurves colorCurves;
QList<Mode> modes;
Mode currentMode;
QList<ResourceData> resources;
OutputDeviceInterface::SubPixel subPixel = OutputDeviceInterface::SubPixel::Unknown;
OutputDeviceInterface::Transform transform = OutputDeviceInterface::Transform::Normal;
OutputDeviceInterface::ColorCurves colorCurves;
QList<OutputDeviceInterface::Mode> modes;
OutputDeviceInterface::Mode currentMode;
QByteArray edid;
Enablement enabled = Enablement::Enabled;
QByteArray uuid;
static OutputDeviceInterface *get(wl_resource *native);
OutputDeviceInterface::Enablement enabled = OutputDeviceInterface::Enablement::Enabled;
QString uuid;
QPointer<Display> display;
OutputDeviceInterface *q;
private:
static Private *cast(wl_resource *native);
static void unbind(wl_resource *resource);
void bind(wl_client *client, uint32_t version, uint32_t id) override;
int32_t toTransform() const;
int32_t toSubPixel() const;
static const quint32 s_version;
OutputDeviceInterface *q;
static QVector<Private*> s_privates;
protected:
void org_kde_kwin_outputdevice_bind_resource(Resource *resource) override;
};
const quint32 OutputDeviceInterface::Private::s_version = 2;
QVector<OutputDeviceInterface::Private*> OutputDeviceInterface::Private::s_privates;
OutputDeviceInterface::Private::Private(OutputDeviceInterface *q, Display *d)
: Global::Private(d, &org_kde_kwin_outputdevice_interface, s_version)
OutputDeviceInterfacePrivate::OutputDeviceInterfacePrivate(OutputDeviceInterface *q, Display *display)
: QtWaylandServer::org_kde_kwin_outputdevice(*display, s_version)
, display(display)
, q(q)
{
DisplayPrivate *displayPrivate = DisplayPrivate::get(display);
displayPrivate->outputdevices.append(q);
s_privates << this;
}
OutputDeviceInterface::Private::~Private()
OutputDeviceInterfacePrivate::~OutputDeviceInterfacePrivate()
{
if (display) {
DisplayPrivate *displayPrivate = DisplayPrivate::get(display);
displayPrivate->outputdevices.removeOne(q);
}
s_privates.removeAll(this);
}
OutputDeviceInterface *OutputDeviceInterface::Private::get(wl_resource *native)
{
if (Private *p = cast(native)) {
return p->q;
}
return nullptr;
}
OutputDeviceInterface::Private *OutputDeviceInterface::Private::cast(wl_resource *native)
{
for (auto it = s_privates.constBegin(); it != s_privates.constEnd(); ++it) {
const auto &resources = (*it)->resources;
auto rit = std::find_if(resources.begin(), resources.end(), [native] (const ResourceData &data) { return data.resource == native; });
if (rit != resources.end()) {
return (*it);
}
}
return nullptr;
}
OutputDeviceInterface::OutputDeviceInterface(Display *display, QObject *parent)
: Global(new Private(this, display), parent)
: QObject(parent)
, d(new OutputDeviceInterfacePrivate(this, display))
{
Q_D();
connect(this, &OutputDeviceInterface::currentModeChanged, this,
[d] {
[this] {
Q_ASSERT(d->currentMode.id >= 0);
for (auto it = d->resources.constBegin(); it != d->resources.constEnd(); ++it) {
d->sendMode((*it).resource, d->currentMode);
d->sendDone(*it);
const auto clientResources = d->resourceMap();
for (auto resource : clientResources) {
d->sendMode(resource, d->currentMode);
d->sendDone(resource);
}
wl_display_flush_clients(*(d->display));
}
);
connect(this, &OutputDeviceInterface::subPixelChanged, this, [d] { d->updateGeometry(); });
connect(this, &OutputDeviceInterface::transformChanged, this, [d] { d->updateGeometry(); });
connect(this, &OutputDeviceInterface::globalPositionChanged, this, [d] { d->updateGeometry(); });
connect(this, &OutputDeviceInterface::modelChanged, this, [d] { d->updateGeometry(); });
connect(this, &OutputDeviceInterface::manufacturerChanged, this, [d] { d->updateGeometry(); });
connect(this, &OutputDeviceInterface::scaleFChanged, this, [d] { d->updateScale(); });
connect(this, &OutputDeviceInterface::colorCurvesChanged, this, [d] { d->updateColorCurves(); });
connect(this, &OutputDeviceInterface::subPixelChanged, this, [this] { d->updateGeometry(); });
connect(this, &OutputDeviceInterface::transformChanged, this, [this] { d->updateGeometry(); });
connect(this, &OutputDeviceInterface::globalPositionChanged, this, [this] { d->updateGeometry(); });
connect(this, &OutputDeviceInterface::modelChanged, this, [this] { d->updateGeometry(); });
connect(this, &OutputDeviceInterface::manufacturerChanged, this, [this] { d->updateGeometry(); });
connect(this, &OutputDeviceInterface::scaleFChanged, this, [this] { d->updateScale(); });
connect(this, &OutputDeviceInterface::colorCurvesChanged, this, [this] { d->updateColorCurves(); });
}
OutputDeviceInterface::~OutputDeviceInterface() = default;
QSize OutputDeviceInterface::pixelSize() const
{
Q_D();
if (d->currentMode.id == -1) {
return QSize();
}
return d->currentMode.size;
}
OutputDeviceInterface *OutputDeviceInterface::get(wl_resource* native)
{
return Private::get(native);
}
int OutputDeviceInterface::refreshRate() const
{
Q_D();
if (d->currentMode.id == -1) {
return 60000;
}
@ -175,10 +134,8 @@ int OutputDeviceInterface::refreshRate() const
void OutputDeviceInterface::addMode(Mode &mode)
{
Q_ASSERT(!isValid());
Q_ASSERT(mode.id >= 0);
Q_ASSERT(mode.size.isValid());
Q_D();
auto currentModeIt = std::find_if(d->modes.begin(), d->modes.end(),
[](const Mode &mode) {
@ -213,7 +170,7 @@ void OutputDeviceInterface::addMode(Mode &mode)
mode.id == mode_it.id;
}
);
auto emitChanges = [this, d, mode] {
auto emitChanges = [this, mode] {
emit modesChanged();
if (mode.flags.testFlag(ModeFlag::Current)) {
d->currentMode = mode;
@ -248,7 +205,6 @@ void OutputDeviceInterface::addMode(Mode &mode)
void OutputDeviceInterface::setCurrentMode(const int modeId)
{
Q_D();
auto currentModeIt = std::find_if(d->modes.begin(), d->modes.end(),
[](const Mode &mode) {
return mode.flags.testFlag(ModeFlag::Current);
@ -276,7 +232,6 @@ void OutputDeviceInterface::setCurrentMode(const int modeId)
bool OutputDeviceInterface::setCurrentMode(const QSize &size, int refreshRate)
{
Q_D();
auto mode = std::find_if(d->modes.constBegin(), d->modes.constEnd(),
[size, refreshRate](const Mode &mode) {
return mode.size == size && mode.refreshRate == refreshRate;
@ -289,73 +244,60 @@ bool OutputDeviceInterface::setCurrentMode(const QSize &size, int refreshRate)
return true;
}
int32_t OutputDeviceInterface::Private::toTransform() const
int32_t OutputDeviceInterfacePrivate::toTransform() const
{
switch (transform) {
case Transform::Normal:
case OutputDeviceInterface::Transform::Normal:
return WL_OUTPUT_TRANSFORM_NORMAL;
case Transform::Rotated90:
case OutputDeviceInterface::Transform::Rotated90:
return WL_OUTPUT_TRANSFORM_90;
case Transform::Rotated180:
case OutputDeviceInterface::Transform::Rotated180:
return WL_OUTPUT_TRANSFORM_180;
case Transform::Rotated270:
case OutputDeviceInterface::Transform::Rotated270:
return WL_OUTPUT_TRANSFORM_270;
case Transform::Flipped:
case OutputDeviceInterface::Transform::Flipped:
return WL_OUTPUT_TRANSFORM_FLIPPED;
case Transform::Flipped90:
case OutputDeviceInterface::Transform::Flipped90:
return WL_OUTPUT_TRANSFORM_FLIPPED_90;
case Transform::Flipped180:
case OutputDeviceInterface::Transform::Flipped180:
return WL_OUTPUT_TRANSFORM_FLIPPED_180;
case Transform::Flipped270:
case OutputDeviceInterface::Transform::Flipped270:
return WL_OUTPUT_TRANSFORM_FLIPPED_270;
}
abort();
}
int32_t OutputDeviceInterface::Private::toSubPixel() const
int32_t OutputDeviceInterfacePrivate::toSubPixel() const
{
switch (subPixel) {
case SubPixel::Unknown:
case OutputDeviceInterface::SubPixel::Unknown:
return WL_OUTPUT_SUBPIXEL_UNKNOWN;
case SubPixel::None:
case OutputDeviceInterface::SubPixel::None:
return WL_OUTPUT_SUBPIXEL_NONE;
case SubPixel::HorizontalRGB:
case OutputDeviceInterface::SubPixel::HorizontalRGB:
return WL_OUTPUT_SUBPIXEL_HORIZONTAL_RGB;
case SubPixel::HorizontalBGR:
case OutputDeviceInterface::SubPixel::HorizontalBGR:
return WL_OUTPUT_SUBPIXEL_HORIZONTAL_BGR;
case SubPixel::VerticalRGB:
case OutputDeviceInterface::SubPixel::VerticalRGB:
return WL_OUTPUT_SUBPIXEL_VERTICAL_RGB;
case SubPixel::VerticalBGR:
case OutputDeviceInterface::SubPixel::VerticalBGR:
return WL_OUTPUT_SUBPIXEL_VERTICAL_BGR;
}
abort();
}
void OutputDeviceInterface::Private::bind(wl_client *client, uint32_t version, uint32_t id)
void OutputDeviceInterfacePrivate::org_kde_kwin_outputdevice_bind_resource(Resource *resource)
{
auto c = display->getConnection(client);
wl_resource *resource = c->createResource(&org_kde_kwin_outputdevice_interface, qMin(version, s_version), id);
if (!resource) {
wl_client_post_no_memory(client);
return;
}
wl_resource_set_user_data(resource, this);
wl_resource_set_destructor(resource, unbind);
ResourceData r;
r.resource = resource;
r.version = version;
resources << r;
sendGeometry(resource);
sendScale(r);
sendColorCurves(r);
sendEisaId(r);
sendSerialNumber(r);
sendScale(resource);
sendColorCurves(resource);
sendEisaId(resource);
sendSerialNumber(resource);
auto currentModeIt = modes.constEnd();
for (auto it = modes.constBegin(); it != modes.constEnd(); ++it) {
const Mode &mode = *it;
if (mode.flags.testFlag(ModeFlag::Current)) {
const OutputDeviceInterface::Mode &mode = *it;
if (mode.flags.testFlag(OutputDeviceInterface::ModeFlag::Current)) {
// needs to be sent as last mode
currentModeIt = it;
continue;
@ -367,134 +309,120 @@ void OutputDeviceInterface::Private::bind(wl_client *client, uint32_t version, u
sendMode(resource, *currentModeIt);
}
sendUuid(r);
sendEdid(r);
sendEnabled(r);
sendDone(r);
c->flush();
sendUuid(resource);
sendEdid(resource);
sendEnabled(resource);
sendDone(resource);
}
void OutputDeviceInterface::Private::unbind(wl_resource *resource)
{
Private *o = cast(resource);
if (!o) {
return;
}
auto it = std::find_if(o->resources.begin(), o->resources.end(), [resource](const ResourceData &r) { return r.resource == resource; });
if (it != o->resources.end()) {
o->resources.erase(it);
}
}
void OutputDeviceInterface::Private::sendMode(wl_resource *resource, const Mode &mode)
void OutputDeviceInterfacePrivate::sendMode(Resource *resource, const OutputDeviceInterface::Mode &mode)
{
int32_t flags = 0;
if (mode.flags.testFlag(ModeFlag::Current)) {
if (mode.flags.testFlag(OutputDeviceInterface::ModeFlag::Current)) {
flags |= WL_OUTPUT_MODE_CURRENT;
}
if (mode.flags.testFlag(ModeFlag::Preferred)) {
if (mode.flags.testFlag(OutputDeviceInterface::ModeFlag::Preferred)) {
flags |= WL_OUTPUT_MODE_PREFERRED;
}
org_kde_kwin_outputdevice_send_mode(resource,
flags,
mode.size.width(),
mode.size.height(),
mode.refreshRate,
mode.id);
send_mode(resource->handle,
flags,
mode.size.width(),
mode.size.height(),
mode.refreshRate,
mode.id);
}
void OutputDeviceInterface::Private::sendGeometry(wl_resource *resource)
void OutputDeviceInterfacePrivate::sendGeometry(Resource *resource)
{
org_kde_kwin_outputdevice_send_geometry(resource,
globalPosition.x(),
globalPosition.y(),
physicalSize.width(),
physicalSize.height(),
toSubPixel(),
qPrintable(manufacturer),
qPrintable(model),
toTransform());
send_geometry(resource->handle,
globalPosition.x(),
globalPosition.y(),
physicalSize.width(),
physicalSize.height(),
toSubPixel(),
manufacturer,
model,
toTransform());
}
void OutputDeviceInterface::Private::sendScale(const ResourceData &data)
void OutputDeviceInterfacePrivate::sendScale(Resource *resource)
{
if (wl_resource_get_version(data.resource) < ORG_KDE_KWIN_OUTPUTDEVICE_SCALEF_SINCE_VERSION) {
org_kde_kwin_outputdevice_send_scale(data.resource, qRound(scale));
if (resource->version() < ORG_KDE_KWIN_OUTPUTDEVICE_SCALEF_SINCE_VERSION) {
send_scale(resource->handle, qRound(scale));
} else {
org_kde_kwin_outputdevice_send_scalef(data.resource, wl_fixed_from_double(scale));
send_scalef(resource->handle, wl_fixed_from_double(scale));
}
}
void OutputDeviceInterface::Private::sendColorCurves(const ResourceData &data)
void OutputDeviceInterfacePrivate::sendColorCurves(Resource *resource)
{
if (data.version < ORG_KDE_KWIN_OUTPUTDEVICE_COLORCURVES_SINCE_VERSION) {
if (resource->version() < ORG_KDE_KWIN_OUTPUTDEVICE_COLORCURVES_SINCE_VERSION) {
return;
}
wl_array wlRed, wlGreen, wlBlue;
QByteArray red = QByteArray::fromRawData(
reinterpret_cast<const char *>(colorCurves.red.constData()),
sizeof(quint16) * colorCurves.red.size()
);
auto fillArray = [](const QVector<quint16> &origin, wl_array *dest) {
wl_array_init(dest);
const size_t memLength = sizeof(uint16_t) * origin.size();
void *s = wl_array_add(dest, memLength);
memcpy(s, origin.data(), memLength);
};
fillArray(colorCurves.red, &wlRed);
fillArray(colorCurves.green, &wlGreen);
fillArray(colorCurves.blue, &wlBlue);
QByteArray green = QByteArray::fromRawData(
reinterpret_cast<const char *>(colorCurves.green.constData()),
sizeof(quint16) * colorCurves.green.size()
);
org_kde_kwin_outputdevice_send_colorcurves(data.resource, &wlRed, &wlGreen, &wlBlue);
QByteArray blue = QByteArray::fromRawData(
reinterpret_cast<const char *>(colorCurves.blue.constData()),
sizeof(quint16) * colorCurves.blue.size()
);
wl_array_release(&wlRed);
wl_array_release(&wlGreen);
wl_array_release(&wlBlue);
send_colorcurves(resource->handle, red, green, blue);
}
void KWaylandServer::OutputDeviceInterface::Private::sendSerialNumber(const ResourceData &data)
void KWaylandServer::OutputDeviceInterfacePrivate::sendSerialNumber(Resource *resource)
{
if (wl_resource_get_version(data.resource) >= ORG_KDE_KWIN_OUTPUTDEVICE_SERIAL_NUMBER_SINCE_VERSION) {
org_kde_kwin_outputdevice_send_serial_number(data.resource,
qPrintable(serialNumber));
if (resource->version() >= ORG_KDE_KWIN_OUTPUTDEVICE_SERIAL_NUMBER_SINCE_VERSION) {
send_serial_number(resource->handle, serialNumber);
}
}
void KWaylandServer::OutputDeviceInterface::Private::sendEisaId(const ResourceData &data)
void KWaylandServer::OutputDeviceInterfacePrivate::sendEisaId(Resource *resource)
{
if (wl_resource_get_version(data.resource) >= ORG_KDE_KWIN_OUTPUTDEVICE_EISA_ID_SINCE_VERSION) {
org_kde_kwin_outputdevice_send_eisa_id(data.resource,
qPrintable(eisaId));
if (resource->version() >= ORG_KDE_KWIN_OUTPUTDEVICE_EISA_ID_SINCE_VERSION) {
send_eisa_id(resource->handle, eisaId);
}
}
void OutputDeviceInterface::Private::sendDone(const ResourceData &data)
void OutputDeviceInterfacePrivate::sendDone(Resource *resource)
{
org_kde_kwin_outputdevice_send_done(data.resource);
send_done(resource->handle);
}
void OutputDeviceInterface::Private::updateGeometry()
void OutputDeviceInterfacePrivate::updateGeometry()
{
for (auto it = resources.constBegin(); it != resources.constEnd(); ++it) {
sendGeometry((*it).resource);
sendDone(*it);
const auto clientResources = resourceMap();
for (auto resource : clientResources) {
sendGeometry(resource);
sendDone(resource);
}
}
void OutputDeviceInterface::Private::updateScale()
void OutputDeviceInterfacePrivate::updateScale()
{
for (auto it = resources.constBegin(); it != resources.constEnd(); ++it) {
sendScale(*it);
sendDone(*it);
const auto clientResources = resourceMap();
for (auto resource : clientResources) {
sendScale(resource);
sendDone(resource);
}
}
void OutputDeviceInterface::Private::updateColorCurves()
void OutputDeviceInterfacePrivate::updateColorCurves()
{
for (auto it = resources.constBegin(); it != resources.constEnd(); ++it) {
sendColorCurves(*it);
sendDone(*it);
const auto clientResources = resourceMap();
for (auto resource : clientResources) {
sendColorCurves(resource);
sendDone(resource);
}
}
@ -509,7 +437,6 @@ bool OutputDeviceInterface::ColorCurves::operator!=(const ColorCurves &cc) const
#define SETTER(setterName, type, argumentName) \
void OutputDeviceInterface::setterName(type arg) \
{ \
Q_D(); \
if (d->argumentName == arg) { \
return; \
} \
@ -528,104 +455,73 @@ SETTER(setTransform, Transform, transform)
#undef SETTER
void OutputDeviceInterface::setScale(int scale)
{
Q_D();
if (d->scale == scale) {
return;
}
d->scale = scale;
emit scaleChanged(d->scale);
emit scaleFChanged(d->scale);
}
void OutputDeviceInterface::setScaleF(qreal scale)
{
Q_D();
if (qFuzzyCompare(d->scale, scale)) {
return;
}
d->scale = scale;
emit scaleChanged(qRound(d->scale));
emit scaleFChanged(d->scale);
}
QSize OutputDeviceInterface::physicalSize() const
{
Q_D();
return d->physicalSize;
}
QPoint OutputDeviceInterface::globalPosition() const
{
Q_D();
return d->globalPosition;
}
QString OutputDeviceInterface::manufacturer() const
{
Q_D();
return d->manufacturer;
}
QString OutputDeviceInterface::model() const
{
Q_D();
return d->model;
}
QString OutputDeviceInterface::serialNumber() const
{
Q_D();
return d->serialNumber;
}
QString OutputDeviceInterface::eisaId() const
{
Q_D();
return d->eisaId;
}
int OutputDeviceInterface::scale() const
{
Q_D();
return qRound(d->scale);
}
qreal OutputDeviceInterface::scaleF() const
{
Q_D();
return d->scale;
}
OutputDeviceInterface::SubPixel OutputDeviceInterface::subPixel() const
{
Q_D();
return d->subPixel;
}
OutputDeviceInterface::Transform OutputDeviceInterface::transform() const
{
Q_D();
return d->transform;
}
OutputDeviceInterface::ColorCurves OutputDeviceInterface::colorCurves() const
{
Q_D();
return d->colorCurves;
}
QList< OutputDeviceInterface::Mode > OutputDeviceInterface::modes() const
{
Q_D();
return d->modes;
}
int OutputDeviceInterface::currentModeId() const
{
Q_D();
for (const Mode &m: d->modes) {
if (m.flags.testFlag(OutputDeviceInterface::ModeFlag::Current)) {
return m.id;
@ -634,15 +530,8 @@ int OutputDeviceInterface::currentModeId() const
return -1;
}
OutputDeviceInterface::Private *OutputDeviceInterface::d_func() const
{
return reinterpret_cast<Private*>(d.data());
}
void OutputDeviceInterface::setColorCurves(const ColorCurves &colorCurves)
{
Q_D();
if (d->colorCurves == colorCurves) {
return;
}
@ -652,7 +541,6 @@ void OutputDeviceInterface::setColorCurves(const ColorCurves &colorCurves)
void OutputDeviceInterface::setEdid(const QByteArray &edid)
{
Q_D();
d->edid = edid;
d->updateEdid();
emit edidChanged();
@ -660,13 +548,11 @@ void OutputDeviceInterface::setEdid(const QByteArray &edid)
QByteArray OutputDeviceInterface::edid() const
{
Q_D();
return d->edid;
}
void OutputDeviceInterface::setEnabled(OutputDeviceInterface::Enablement enabled)
{
Q_D();
if (d->enabled != enabled) {
d->enabled = enabled;
d->updateEnabled();
@ -676,13 +562,11 @@ void OutputDeviceInterface::setEnabled(OutputDeviceInterface::Enablement enabled
OutputDeviceInterface::Enablement OutputDeviceInterface::enabled() const
{
Q_D();
return d->enabled;
}
void OutputDeviceInterface::setUuid(const QByteArray &uuid)
void OutputDeviceInterface::setUuid(const QString &uuid)
{
Q_D();
if (d->uuid != uuid) {
d->uuid = uuid;
d->updateUuid();
@ -690,59 +574,73 @@ void OutputDeviceInterface::setUuid(const QByteArray &uuid)
}
}
QByteArray OutputDeviceInterface::uuid() const
QString OutputDeviceInterface::uuid() const
{
Q_D();
return d->uuid;
}
void KWaylandServer::OutputDeviceInterface::Private::sendEdid(const ResourceData &data)
void OutputDeviceInterfacePrivate::sendEdid(Resource *resource)
{
org_kde_kwin_outputdevice_send_edid(data.resource,
edid.toBase64().constData());
send_edid(resource->handle, QString::fromStdString(edid.toBase64().toStdString()));
}
void KWaylandServer::OutputDeviceInterface::Private::sendEnabled(const ResourceData &data)
void OutputDeviceInterfacePrivate::sendEnabled(Resource *resource)
{
int _enabled = 0;
int32_t _enabled = 0;
if (enabled == OutputDeviceInterface::Enablement::Enabled) {
_enabled = 1;
}
org_kde_kwin_outputdevice_send_enabled(data.resource, _enabled);
send_enabled(resource->handle, _enabled);
}
void OutputDeviceInterface::Private::sendUuid(const ResourceData &data)
void OutputDeviceInterfacePrivate::sendUuid(Resource *resource)
{
org_kde_kwin_outputdevice_send_uuid(data.resource, uuid.constData());
send_uuid(resource->handle, uuid);
}
void KWaylandServer::OutputDeviceInterface::Private::updateEnabled()
void OutputDeviceInterfacePrivate::updateEnabled()
{
for (auto it = resources.constBegin(); it != resources.constEnd(); ++it) {
sendEnabled(*it);
const auto clientResources = resourceMap();
for (auto resource : clientResources) {
sendEnabled(resource);
}
}
void KWaylandServer::OutputDeviceInterface::Private::updateEdid()
void OutputDeviceInterfacePrivate::updateEdid()
{
for (auto it = resources.constBegin(); it != resources.constEnd(); ++it) {
sendEdid(*it);
const auto clientResources = resourceMap();
for (auto resource : clientResources) {
sendEdid(resource);
}
}
void KWaylandServer::OutputDeviceInterface::Private::updateUuid()
void OutputDeviceInterfacePrivate::updateUuid()
{
for (auto it = resources.constBegin(); it != resources.constEnd(); ++it) {
sendUuid(*it);
const auto clientResources = resourceMap();
for (auto resource : clientResources) {
sendUuid(resource);
}
}
void KWaylandServer::OutputDeviceInterface::Private::updateEisaId()
void OutputDeviceInterfacePrivate::updateEisaId()
{
for (auto it = resources.constBegin(); it != resources.constEnd(); ++it) {
sendEisaId(*it);
const auto clientResources = resourceMap();
for (auto resource : clientResources) {
sendEisaId(resource);
}
}
OutputDeviceInterface *OutputDeviceInterfacePrivate::get(wl_resource *native)
{
if (auto devicePrivate = resource_cast<OutputDeviceInterfacePrivate *>(native)) {
return devicePrivate->q;
}
return nullptr;
}
OutputDeviceInterface *OutputDeviceInterface::get(wl_resource *native)
{
return OutputDeviceInterfacePrivate::get(native);
}
}

View file

@ -19,6 +19,7 @@ namespace KWaylandServer
{
class Display;
class OutputDeviceInterfacePrivate;
/** @class OutputDeviceInterface
*
@ -28,7 +29,7 @@ class Display;
* @see OutputManagementInterface
* @since 5.5
*/
class KWAYLANDSERVER_EXPORT OutputDeviceInterface : public Global
class KWAYLANDSERVER_EXPORT OutputDeviceInterface : public QObject
{
Q_OBJECT
Q_PROPERTY(QSize physicalSize READ physicalSize WRITE setPhysicalSize NOTIFY physicalSizeChanged)
@ -42,7 +43,7 @@ class KWAYLANDSERVER_EXPORT OutputDeviceInterface : public Global
Q_PROPERTY(qreal scale READ scaleF WRITE setScaleF NOTIFY scaleFChanged)
Q_PROPERTY(QByteArray edid READ edid WRITE setEdid NOTIFY edidChanged)
Q_PROPERTY(OutputDeviceInterface::Enablement enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
Q_PROPERTY(QByteArray uuid READ uuid WRITE setUuid NOTIFY uuidChanged)
Q_PROPERTY(QString uuid READ uuid WRITE setUuid NOTIFY uuidChanged)
public:
enum class SubPixel {
Unknown,
@ -84,7 +85,7 @@ public:
};
explicit OutputDeviceInterface(Display *display, QObject *parent = nullptr);
virtual ~OutputDeviceInterface();
~OutputDeviceInterface() override;
QSize physicalSize() const;
QPoint globalPosition() const;
@ -94,11 +95,7 @@ public:
QString eisaId() const;
QSize pixelSize() const;
int refreshRate() const;
#if KWAYLANDSERVER_ENABLE_DEPRECATED_SINCE(5, 50)
/// @deprecated Since 5.50, use scaleF()
KWAYLANDSERVER_DEPRECATED_VERSION(5, 50, "Use OutputDeviceInterface::scaleF()")
int scale() const;
#endif
/// @since 5.50
qreal scaleF() const;
SubPixel subPixel() const;
@ -109,7 +106,7 @@ public:
QByteArray edid() const;
OutputDeviceInterface::Enablement enabled() const;
QByteArray uuid() const;
QString uuid() const;
void setPhysicalSize(const QSize &size);
void setGlobalPosition(const QPoint &pos);
@ -117,11 +114,7 @@ public:
void setModel(const QString &model);
void setSerialNumber(const QString &serialNumber);
void setEisaId(const QString &eisaId);
#if KWAYLANDSERVER_ENABLE_DEPRECATED_SINCE(5, 50)
/// @deprecated Since 5.50, use setScale(qreal)
KWAYLANDSERVER_DEPRECATED_VERSION(5, 50, "Use OutputDeviceInterface::setScale(qreal)")
void setScale(int scale);
#endif
/// @since 5.50
void setScaleF(qreal scale);
void setSubPixel(SubPixel subPixel);
@ -144,7 +137,7 @@ public:
void setEdid(const QByteArray &edid);
void setEnabled(OutputDeviceInterface::Enablement enabled);
void setUuid(const QByteArray &uuid);
void setUuid(const QString &uuid);
static OutputDeviceInterface *get(wl_resource *native);
static QList<OutputDeviceInterface *>list();
@ -158,11 +151,7 @@ Q_SIGNALS:
void eisaIdChanged(const QString &);
void pixelSizeChanged(const QSize&);
void refreshRateChanged(int);
#if KWAYLANDSERVER_ENABLE_DEPRECATED_SINCE(5, 50)
/// @deprecated Since 5.50, use scaleFChanged(qreal)
KWAYLANDSERVER_DEPRECATED_VERSION(5, 50, "Use OutputDeviceInterface::scaleFChanged(qreal)")
void scaleChanged(int);
#endif
/// @since 5.50
void scaleFChanged(qreal);
void subPixelChanged(SubPixel);
@ -176,8 +165,7 @@ Q_SIGNALS:
void uuidChanged();
private:
class Private;
Private *d_func() const;
QScopedPointer<OutputDeviceInterfacePrivate> d;
};
}