Files
RedBear-OS/local/recipes/kde/kwin/source/tests/waylandservertest.cpp
T
vasilito 7aeb3bb475 build: capture build script auto-stash changes from 0.2.5 kernel/relibc/base build
The build-redbear.sh script auto-stashes working tree changes
in nested relibc and base source trees before running the
build. These changes were captured by the failed kernel
build attempt that hit the json-target-spec / kernel rust
toolchain mismatch (fixed in 0.2.5 by creating the local
0.2.5 branch).

Captured changes:
- local/recipes/kde/* : KDE Frameworks 6 source CMakeLists
  whitespace changes from the autostash (preserved)
- local/recipes/qt/qtbase/* : qtypes.h whitespace from the
  autostash (preserved)
- local/sources/kernel/Cargo.lock : dependency lock from
  the kernel relibc rebuild attempt
- local/sources/kernel/src/lib.rs : touched (mtime) by the
  build script's touch + make prefix command

This is a bookkeeping commit — the actual code changes
for the threading plan are on the 4 submodule branches
(kernel, relibc, base, libredox) and will be pushed
separately.

0.2.5 branch was created from 0.2.4 (HEAD cd3950072e) to
continue Phase 0 of the multi-threading plan work in a
clean branch.
2026-07-02 13:41:03 +03:00

114 lines
3.3 KiB
C++

/*
SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org>
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#include "wayland/compositor.h"
#include "wayland/display.h"
#include "wayland/output.h"
#include "wayland/seat.h"
#include "wayland/xdgshell.h"
#include "fakeoutput.h"
#include <QFile>
#include <QGuiApplication>
#include <private/qeventdispatcher_glib_p.h>
#include <iostream>
#include <sys/select.h>
#include <unistd.h>
static int startXServer()
{
const QByteArray process = QByteArrayLiteral("Xwayland");
int pipeFds[2];
if (pipe(pipeFds) != 0) {
std::cerr << "FATAL ERROR failed to create pipe to start X Server " << process.constData() << std::endl;
exit(1);
}
pid_t pid = fork();
if (pid == 0) {
// child process - should be turned into Xwayland
// writes to pipe, closes read side
close(pipeFds[0]);
char fdbuf[16];
sprintf(fdbuf, "%d", pipeFds[1]);
execlp(process.constData(), process.constData(), "-displayfd", fdbuf, (char *)nullptr);
close(pipeFds[1]);
exit(20);
}
// parent process - this is the wayland server
// reads from pipe, closes write side
close(pipeFds[1]);
return pipeFds[0];
}
static void readDisplayFromPipe(int pipe)
{
QFile readPipe;
if (!readPipe.open(pipe, QIODevice::ReadOnly)) {
std::cerr << "FATAL ERROR failed to open pipe to start X Server XWayland" << std::endl;
exit(1);
}
QByteArray displayNumber = readPipe.readLine();
displayNumber.prepend(QByteArray(":"));
displayNumber.remove(displayNumber.size() - 1, 1);
std::cout << "X-Server started on display " << displayNumber.constData() << std::endl;
setenv("DISPLAY", displayNumber.constData(), true);
// close our pipe
close(pipe);
}
int main(int argc, char **argv)
{
using namespace KWin;
// 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
KWin::Display display;
display.start();
display.createShm();
new CompositorInterface(&display, &display);
new XdgShellInterface(&display, &display);
auto fakeOutput = std::make_unique<FakeBackendOutput>();
fakeOutput->setMode(QSize(1024, 768), 60000);
fakeOutput->setPhysicalSize(QSize(10, 10));
auto outputHandle = std::make_unique<LogicalOutput>(fakeOutput.get());
auto outputInterface = std::make_unique<OutputInterface>(&display, outputHandle.get());
// starts XWayland by forking and opening a pipe
const int pipe = startXServer();
if (pipe == -1) {
exit(1);
}
fd_set rfds;
struct timeval tv;
tv.tv_sec = 0;
tv.tv_usec = 0;
do {
eventDispatcher->processEvents(QEventLoop::WaitForMoreEvents);
FD_ZERO(&rfds);
FD_SET(pipe, &rfds);
} while (select(pipe + 1, &rfds, nullptr, nullptr, &tv) == 0);
// now Xwayland is ready and we can read the pipe to get the display
readDisplayFromPipe(pipe);
QGuiApplication app(argc, argv);
new SeatInterface(&display, QStringLiteral("testSeat0"));
return app.exec();
}