Skip to content

Commit

Permalink
refactor(server): get and set metadata in public output API
Browse files Browse the repository at this point in the history
Instead of providing functions for individual metadata fields, provide getter
and setter for the metadata struct.
  • Loading branch information
romangg committed Mar 18, 2023
1 parent 16517b1 commit d281763
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 91 deletions.
14 changes: 8 additions & 6 deletions autotests/client/output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,8 @@ void TestOutput::init()

QCOMPARE(server.output->mode_size(), QSize(1280, 1024));

server.output->set_name("HDMI-A");
server.output->set_make("Foocorp");
server.output->set_model("Barmodel");
Srv::output_metadata meta{.name = "HDMI-A", .make = "Foocorp", .model = "Barmodel"};
server.output->set_metadata(meta);

server.output->set_mode(mode);
QCOMPARE(server.output->mode_size(), QSize(1024, 768));
Expand Down Expand Up @@ -160,9 +159,12 @@ void TestOutput::testRegistry()
server.output->set_geometry(QRectF(QPoint(100, 50), QSize()));
QCOMPARE(server.output->geometry().topLeft(), QPoint(100, 50));

QCOMPARE(server.output->physical_size(), QSize());
server.output->set_physical_size(QSize(200, 100));
QCOMPARE(server.output->physical_size(), QSize(200, 100));
auto metadata = server.output->get_metadata();
QCOMPARE(metadata.physical_size, QSize());

metadata.physical_size = {200, 100};
server.output->set_metadata(metadata);
QCOMPARE(server.output->get_metadata().physical_size, QSize(200, 100));
server.output->done();

Clt::Registry registry;
Expand Down
19 changes: 9 additions & 10 deletions autotests/client/output_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private Q_SLOTS:
std::string m_make = "Foocorp";
std::string m_model = "Barmodel";
std::string m_description;
QString m_serialNumber;
std::string m_serialNumber = "23498723948723";

Wrapland::Client::ConnectionThread* m_connection;
Wrapland::Client::EventQueue* m_queue;
Expand Down Expand Up @@ -112,17 +112,17 @@ void TestOutputDevice::init()

server.output->set_mode(1);

server.output->set_name(m_name);
server.output->set_make(m_make);
server.output->set_model(m_model);
Srv::output_metadata meta{.name = m_name,
.make = m_make,
.model = m_model,
.serial_number = m_serialNumber,
.physical_size = {200, 100}};
server.output->set_metadata(meta);

server.output->generate_description();
m_description = server.output->description();
m_description = server.output->get_metadata().description;
QCOMPARE(m_description, m_make + " " + m_model + " (" + m_name + ")");

m_serialNumber = "23498723948723";
server.output->set_serial_number(m_serialNumber.toStdString());

server.output->set_enabled(true);
server.output->done();

Expand Down Expand Up @@ -166,7 +166,6 @@ void TestOutputDevice::cleanup()
void TestOutputDevice::testRegistry()
{
server.output->set_geometry(QRectF(QPointF(100, 50), QSizeF(400, 200)));
server.output->set_physical_size(QSize(200, 100));
server.output->done();

Wrapland::Client::Registry registry;
Expand Down Expand Up @@ -212,7 +211,7 @@ void TestOutputDevice::testRegistry()
QCOMPARE(output.make(), QString::fromStdString(m_make));
QCOMPARE(output.model(), QString::fromStdString(m_model));
QCOMPARE(output.description(), QString::fromStdString(m_description));
QCOMPARE(output.serialNumber(), m_serialNumber);
QCOMPARE(output.serialNumber(), QString::fromStdString(m_serialNumber));
}

void TestOutputDevice::testModeChanges()
Expand Down
11 changes: 6 additions & 5 deletions autotests/client/xdg_output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,11 @@ void TestXdgOutput::init()
server_output->set_mode(1);
server_output->set_enabled(true);

server_output->set_name(m_name);
server_output->set_make(m_make);
server_output->set_model(m_model);
Wrapland::Server::output_metadata meta{.name = m_name, .make = m_make, .model = m_model};
server_output->set_metadata(meta);

server_output->generate_description();
m_description = server_output->description();
m_description = server_output->get_metadata().description;

// Not a sensible position for one monitor but works for this test. And a 1.5 scale factor.
server_output->set_geometry(QRectF(QPoint(11, 12), QSize(1280, 720)));
Expand Down Expand Up @@ -192,7 +191,9 @@ void TestXdgOutput::testChanges()
server.globals.outputs.back()->set_geometry(QRectF(QPoint(1000, 2000), QSize(100, 200)));

std::string updated_description = "Updated xdg-output description";
server.globals.outputs.back()->set_description(updated_description);
auto metadata = server.globals.outputs.back()->get_metadata();
metadata.description = updated_description;
server.globals.outputs.back()->set_metadata(metadata);
server.globals.outputs.back()->done();

QVERIFY(xdgOutputChanged.wait());
Expand Down
5 changes: 4 additions & 1 deletion server/drm_lease_v1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,10 @@ drm_lease_connector_v1::drm_lease_connector_v1(std::string const& name,
}

drm_lease_connector_v1::drm_lease_connector_v1(Server::output* output, drm_lease_device_v1* device)
: drm_lease_connector_v1(output->name(), output->description(), output->connector_id(), device)
: drm_lease_connector_v1(output->get_metadata().name,
output->get_metadata().description,
output->connector_id(),
device)
{
d_ptr->output = output;
}
Expand Down
58 changes: 4 additions & 54 deletions server/output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,59 +169,14 @@ output_transform output::transform() const
return d_ptr->pending.transform;
}

std::string output::name() const
output_metadata const& output::get_metadata() const
{
return d_ptr->pending.meta.name;
return d_ptr->pending.meta;
}

std::string output::description() const
void output::set_metadata(output_metadata const& data)
{
return d_ptr->pending.meta.description;
}

std::string output::serial_mumber() const
{
return d_ptr->pending.meta.serial_number;
}

std::string output::make() const
{
return d_ptr->pending.meta.make;
}

std::string output::model() const
{
return d_ptr->pending.meta.model;
}

void output::set_name(std::string const& name)
{
d_ptr->pending.meta.name = name;
}

void output::set_description(std::string const& description)
{
d_ptr->pending.meta.description = description;
}

void output::set_make(std::string const& make)
{
d_ptr->pending.meta.make = make;
}

void output::set_model(std::string const& model)
{
d_ptr->pending.meta.model = model;
}

void output::set_serial_number(std::string const& serial_number)
{
d_ptr->pending.meta.serial_number = serial_number;
}

void output::set_physical_size(QSize const& size)
{
d_ptr->pending.meta.physical_size = size;
d_ptr->pending.meta = data;
}

void output::set_connector_id(int id)
Expand Down Expand Up @@ -259,11 +214,6 @@ void output::set_enabled(bool enabled)
d_ptr->pending.enabled = enabled;
}

QSize output::physical_size() const
{
return d_ptr->pending.meta.physical_size;
}

int output::connector_id() const
{
return d_ptr->connector_id;
Expand Down
14 changes: 2 additions & 12 deletions server/output.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,10 @@ class WRAPLANDSERVER_EXPORT output : public QObject
explicit output(Display* display);
~output() override;

std::string name() const;
std::string description() const;
std::string make() const;
std::string model() const;
std::string serial_mumber() const;
QSize physical_size() const;
output_metadata const& get_metadata() const;
int connector_id() const;

void set_name(std::string const& name);
void set_description(std::string const& description);
void set_make(std::string const& make);
void set_model(std::string const& model);
void set_serial_number(std::string const& serial_number);
void set_physical_size(QSize const& size);
void set_metadata(output_metadata const& data);
void set_connector_id(int id);

/**
Expand Down
4 changes: 3 additions & 1 deletion src/tools/testserver/testserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ void TestServer::init()
globals.outputs.push_back(std::make_unique<Wrapland::Server::output>(m_display.get()));
const QSize size(1280, 1024);
globals.outputs.back()->set_geometry(QRectF(QPoint(0, 0), size));
globals.outputs.back()->set_physical_size(size / 3.8);

output_metadata meta{.physical_size = size / 3.8};
globals.outputs.back()->set_metadata(meta);
globals.outputs.back()->add_mode(output_mode{size});

globals.fake_input = m_display->createFakeInput();
Expand Down
3 changes: 2 additions & 1 deletion tests/renderingservertest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,8 @@ int main(int argc, char** argv)
display.createShm();

auto output = std::make_unique<Wrapland::Server::output>(&display);
output->set_physical_size(QSize(269, 202));
Wrapland::Server::output_metadata meta{.physical_size = {269, 202}};
output->set_metadata(meta);
const QSize windowSize(1024, 768);
output->add_mode(output_mode{windowSize});

Expand Down
3 changes: 2 additions & 1 deletion tests/waylandservertest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ int main(int argc, char** argv)
auto xdg_shell = display.createXdgShell();

auto output = std::make_unique<Wrapland::Server::output>(&display);
output->set_physical_size(QSize(10, 10));
Wrapland::Server::output_metadata meta{.physical_size = {10, 10}};
output->set_metadata(meta);
output->add_mode(Wrapland::Server::output_mode{QSize(1024, 768)});

// starts XWayland by forking and opening a pipe
Expand Down

0 comments on commit d281763

Please sign in to comment.