Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit db9e4021 authored by Martin Flöser's avatar Martin Flöser

[tests] Install eventDispatcher before creating the QGuiApplication

This change demonstrates how one can install a custom event dispatcher
before creating the QGuiApplication and how to process Wayland events
using the event dispatcher to e.g. start an Xwayland server prior to
creating the application.

It also allows to use

--platform wayland

on the test application. The wayland QPA plugin will connect to the
KWayland server started prior to creating the application.
Please note that such a setup will freeze unless QtWayland has commit
1e32e71 [1].

[1] https://qt.gitorious.org/qt/qtwayland/commit/1e32e71403a6a9cb117343464fbc34564598e831
parent f947dd7c
include(ECMMarkAsTest)
# find_package(Qt5Core ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENT Private _check_private)
include_directories(${Qt5Core_PRIVATE_INCLUDE_DIRS})
set(testServer_SRCS
waylandservertest.cpp
)
......
......@@ -25,6 +25,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
#include <QGuiApplication>
#include <QFile>
#include <QtCore/private/qeventdispatcher_glib_p.h>
#include <unistd.h>
#include <iostream>
......@@ -80,9 +81,14 @@ int main(int argc, char **argv)
{
using namespace KWayland::Server;
// set our own event dispatcher to be able to dispatch events before the event loop is started
QAbstractEventDispatcher *eventDispatcher = new QEventDispatcherGlib();
QCoreApplication::setEventDispatcher(eventDispatcher);
// first create the Server and setup with minimum to get an XWayland connected
Display display;
display.start();
display.createShm();
CompositorInterface *compositor = display.createCompositor(&display);
compositor->create();
ShellInterface *shell = display.createShell();
......@@ -91,7 +97,6 @@ int main(int argc, char **argv)
output->setPhysicalSize(QSize(10, 10));
output->addMode(QSize(1024, 768));
output->create();
display.createShm();
// starts XWayland by forking and opening a pipe
const int pipe = startXServer();
......@@ -104,7 +109,7 @@ int main(int argc, char **argv)
tv.tv_sec = 0;
tv.tv_usec = 0;
do {
display.dispatchEvents(1000);
eventDispatcher->processEvents(QEventLoop::WaitForMoreEvents);
FD_ZERO(&rfds);
FD_SET(pipe, &rfds);
} while (select(pipe + 1, &rfds, NULL, NULL, &tv) == 0);
......@@ -113,7 +118,6 @@ int main(int argc, char **argv)
readDisplayFromPipe(pipe);
QGuiApplication app(argc, argv);
display.startLoop();
SeatInterface *seat = display.createSeat();
seat->setName(QStringLiteral("testSeat0"));
......
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