From b3b4adfe7f495f97f1d20558370692f2b9049232 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Wed, 18 Feb 2015 09:43:04 +0100 Subject: [PATCH] [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 --- src/wayland/tests/CMakeLists.txt | 2 ++ src/wayland/tests/waylandservertest.cpp | 10 +++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/wayland/tests/CMakeLists.txt b/src/wayland/tests/CMakeLists.txt index 5c292bf55c..9dc0ec7e36 100644 --- a/src/wayland/tests/CMakeLists.txt +++ b/src/wayland/tests/CMakeLists.txt @@ -1,5 +1,7 @@ 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 ) diff --git a/src/wayland/tests/waylandservertest.cpp b/src/wayland/tests/waylandservertest.cpp index 4b40fdd99c..29ae90e653 100644 --- a/src/wayland/tests/waylandservertest.cpp +++ b/src/wayland/tests/waylandservertest.cpp @@ -25,6 +25,7 @@ License along with this library. If not, see . #include #include +#include #include #include @@ -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"));