Skip to content

Commit

Permalink
Merge branch 'display-fd' into 'master'
Browse files Browse the repository at this point in the history
Simplify Display API

See merge request kwinft/wrapland!143
  • Loading branch information
romangg committed Dec 11, 2023
2 parents 048a451 + 7c66a3a commit da46a25
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 40 deletions.
2 changes: 1 addition & 1 deletion autotests/client/connection_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ void TestWaylandConnectionThread::testConnectFdNoSocketName()
m_display = nullptr;

Srv::Display display;
display.start(Srv::Display::StartMode::ConnectClientsOnly);
display.start();
QVERIFY(display.running());

int sv[2];
Expand Down
2 changes: 1 addition & 1 deletion autotests/server/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ void TestServerDisplay::testClientConnection()
void TestServerDisplay::testConnectNoSocket()
{
Wrapland::Server::Display display;
display.start(Wrapland::Server::Display::StartMode::ConnectClientsOnly);
display.start();
QVERIFY(display.running());

// let's try connecting a client
Expand Down
9 changes: 2 additions & 7 deletions server/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,9 @@ std::string Display::socket_name() const
return d_ptr->socket_name;
}

void Display::add_socket_fd(int fd)
void Display::start()
{
d_ptr->add_socket_fd(fd);
}

void Display::start(StartMode mode)
{
d_ptr->start(mode == StartMode::ConnectToSocket);
d_ptr->start();
Q_EMIT started();
}

Expand Down
9 changes: 1 addition & 8 deletions server/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,7 @@ class WRAPLANDSERVER_EXPORT Display : public QObject
uint32_t serial();
uint32_t nextSerial();

enum class StartMode {
ConnectToSocket,
ConnectClientsOnly,
};

void start(StartMode mode = StartMode::ConnectToSocket);
void start();
void terminate();

void startLoop();
Expand All @@ -108,8 +103,6 @@ class WRAPLANDSERVER_EXPORT Display : public QObject
wl_display* native() const;
bool running() const;

void add_socket_fd(int fd);

void createShm();

void dispatch();
Expand Down
27 changes: 7 additions & 20 deletions server/wayland/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,6 @@ wl_display* Display::native() const
return m_display;
}

void Display::add_socket_fd(int fd)
{
if (!m_display) {
m_display = wl_display_create();
}

if (wl_display_add_socket_fd(m_display, fd)) {
qCWarning(WRAPLAND_SERVER, "Failed to add fd %d.", fd);
}
}

bool Display::running() const
{
return m_running;
Expand Down Expand Up @@ -135,22 +124,20 @@ void Display::addSocket()
}
}

void Display::start(bool createSocket)
void Display::start()
{
Q_ASSERT(!m_running);

if (!m_display) {
m_display = wl_display_create();
}

if (createSocket) {
try {
addSocket();
} catch (std::bad_exception&) {
qCWarning(WRAPLAND_SERVER, "Failed to create Wayland socket");
// TODO(romangg): Shall we rethrow?
return;
}
try {
addSocket();
} catch (std::bad_exception&) {
qCWarning(WRAPLAND_SERVER, "Failed to create Wayland socket");
// TODO(romangg): Shall we rethrow?
return;
}

m_loop = wl_display_get_event_loop(m_display);
Expand Down
4 changes: 1 addition & 3 deletions server/wayland/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,12 @@ class Display
explicit Display(Server::Display* handle);
virtual ~Display();

void add_socket_fd(int fd);

void addGlobal(BasicNucleus* nucleus);
void removeGlobal(BasicNucleus* nucleus);

wl_display* native() const;

void start(bool createSocket);
void start();
void terminate();

void startLoop();
Expand Down

0 comments on commit da46a25

Please sign in to comment.