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