Let the fun begin: start a WaylandServer in kwin_wayland
The WaylandServer is at the moment only used to support starting an Xwayland. It does not support Wayland clients yet, so don't get excited. For Xwayland it's using the trick of creating the Display before the QApplication is created with manual event dispatching.
This commit is contained in:
parent
f651007ebe
commit
47bdce074e
4 changed files with 190 additions and 11 deletions
|
@ -416,6 +416,7 @@ if(HAVE_WAYLAND)
|
|||
${kwin_KDEINIT_SRCS}
|
||||
screens_wayland.cpp
|
||||
wayland_backend.cpp
|
||||
wayland_server.cpp
|
||||
)
|
||||
if(KWIN_HAVE_EGL AND Wayland_Egl_FOUND)
|
||||
set(kwin_KDEINIT_SRCS ${kwin_KDEINIT_SRCS} egl_wayland_backend.cpp)
|
||||
|
@ -503,6 +504,7 @@ set(kwin_WAYLAND_LIBS
|
|||
XCB::XTEST
|
||||
XKB::XKB
|
||||
KF5::WaylandClient
|
||||
KF5::WaylandServer
|
||||
)
|
||||
|
||||
set(kwin_WAYLAND_EGL_LIBS
|
||||
|
|
|
@ -21,8 +21,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#include <config-kwin.h>
|
||||
// kwin
|
||||
#include "wayland_backend.h"
|
||||
#include "wayland_server.h"
|
||||
#include "xcbutils.h"
|
||||
|
||||
// KWayland
|
||||
#include <KWayland/Server/display.h>
|
||||
// KDE
|
||||
#include <KLocalizedString>
|
||||
// Qt
|
||||
|
@ -109,7 +112,7 @@ void ApplicationWayland::performStartup()
|
|||
* Starts the X-Server with binary name @p process on @p display.
|
||||
* The new process is started by forking into it.
|
||||
**/
|
||||
static void startXServer(const QByteArray &process, const QByteArray &display, bool rootless = false)
|
||||
static int startXServer(const QByteArray &process, const QByteArray &display, bool rootless = false, const QByteArray &waylandSocket = QByteArray())
|
||||
{
|
||||
int pipeFds[2];
|
||||
if (pipe(pipeFds) != 0) {
|
||||
|
@ -140,6 +143,7 @@ static void startXServer(const QByteArray &process, const QByteArray &display, b
|
|||
*index++ = const_cast<char*>(display.data());
|
||||
}
|
||||
*index++ = nullptr;
|
||||
qputenv("WAYLAND_DISPLAY", waylandSocket.isEmpty() ? QByteArrayLiteral("wayland-0") : waylandSocket);
|
||||
execvp(process.constData(), args);
|
||||
close(pipeFds[1]);
|
||||
exit(20);
|
||||
|
@ -147,14 +151,14 @@ static void startXServer(const QByteArray &process, const QByteArray &display, b
|
|||
// parent process - this is KWin
|
||||
// reads from pipe, closes write side
|
||||
close(pipeFds[1]);
|
||||
return pipeFds[0];
|
||||
}
|
||||
|
||||
static void readDisplay(int pipe)
|
||||
{
|
||||
QFile readPipe;
|
||||
if (!readPipe.open(pipeFds[0], QIODevice::ReadOnly)) {
|
||||
std::cerr << "FATAL ERROR failed to open pipe to start X Server "
|
||||
<< process.constData()
|
||||
<< " with arguments "
|
||||
<< display.constData()
|
||||
<< std::endl;
|
||||
if (!readPipe.open(pipe, QIODevice::ReadOnly)) {
|
||||
std::cerr << "FATAL ERROR failed to open pipe to start X Server" << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
QByteArray displayNumber = readPipe.readLine();
|
||||
|
@ -166,7 +170,7 @@ static void startXServer(const QByteArray &process, const QByteArray &display, b
|
|||
setenv("DISPLAY", displayNumber.constData(), true);
|
||||
|
||||
// close our pipe
|
||||
close(pipeFds[0]);
|
||||
close(pipe);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
@ -181,6 +185,7 @@ KWIN_EXPORT int kdemain(int argc, char * argv[])
|
|||
bool rootlessXwayland = false;
|
||||
QByteArray xDisplay;
|
||||
QByteArray xServer;
|
||||
QByteArray waylandSocket;
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
QByteArray arg = QByteArray::fromRawData(argv[i], qstrlen(argv[i]));
|
||||
if (arg == "-x" || arg == "--x-server") {
|
||||
|
@ -206,16 +211,42 @@ KWIN_EXPORT int kdemain(int argc, char * argv[])
|
|||
xDisplay = QByteArray::fromRawData(argv[i], qstrlen(argv[i]));
|
||||
}
|
||||
}
|
||||
if (arg == "--socket" || arg == "-s") {
|
||||
if (++i < argc) {
|
||||
waylandSocket = QByteArray::fromRawData(argv[i], qstrlen(argv[i]));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (arg.startsWith("--socket=")) {
|
||||
waylandSocket = arg.mid(9);
|
||||
}
|
||||
}
|
||||
|
||||
KWin::WaylandServer *server = KWin::WaylandServer::create(nullptr);
|
||||
server->init(waylandSocket);
|
||||
|
||||
int xDisplayPipe = -1;
|
||||
if (startXephyr) {
|
||||
KWin::startXServer(QByteArrayLiteral("Xephyr"), xDisplay);
|
||||
xDisplayPipe = KWin::startXServer(QByteArrayLiteral("Xephyr"), xDisplay);
|
||||
}
|
||||
if (startXvfb) {
|
||||
KWin::startXServer(QByteArrayLiteral("Xvfb"), xDisplay);
|
||||
xDisplayPipe = KWin::startXServer(QByteArrayLiteral("Xvfb"), xDisplay);
|
||||
}
|
||||
if (startXwayland) {
|
||||
KWin::startXServer(QByteArrayLiteral("Xwayland"), xDisplay, rootlessXwayland);
|
||||
xDisplayPipe = KWin::startXServer(QByteArrayLiteral("Xwayland"), xDisplay, rootlessXwayland, waylandSocket);
|
||||
fd_set rfds;
|
||||
struct timeval tv;
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 0;
|
||||
do {
|
||||
server->display()->dispatchEvents(1000);
|
||||
FD_ZERO(&rfds);
|
||||
FD_SET(xDisplayPipe, &rfds);
|
||||
} while (select(xDisplayPipe + 1, &rfds, NULL, NULL, &tv) == 0);
|
||||
}
|
||||
|
||||
if (xDisplayPipe != -1) {
|
||||
KWin::readDisplay(xDisplayPipe);
|
||||
}
|
||||
|
||||
KWin::Application::setupMalloc();
|
||||
|
@ -242,6 +273,9 @@ KWIN_EXPORT int kdemain(int argc, char * argv[])
|
|||
KWin::ApplicationWayland a(argc, argv);
|
||||
a.setupTranslator();
|
||||
|
||||
server->setParent(&a);
|
||||
server->display()->startLoop();
|
||||
|
||||
KWin::Application::createAboutData();
|
||||
|
||||
QCommandLineOption startXServerOption(QStringList({QStringLiteral("x"), QStringLiteral("x-server")}),
|
||||
|
@ -252,12 +286,16 @@ KWIN_EXPORT int kdemain(int argc, char * argv[])
|
|||
QCommandLineOption x11DisplayOption(QStringLiteral("display"),
|
||||
i18n("The X11 Display to connect to. If not set next free number will be picked."),
|
||||
QStringLiteral("display"));
|
||||
QCommandLineOption waylandSocketOption(QStringList{QStringLiteral("s"), QStringLiteral("socket")},
|
||||
i18n("Name of the Wayland socket to listen on. If not set \"wayland-0\" is used."),
|
||||
QStringLiteral("socket"));
|
||||
|
||||
QCommandLineParser parser;
|
||||
a.setupCommandLine(&parser);
|
||||
parser.addOption(startXServerOption);
|
||||
parser.addOption(xwaylandOption);
|
||||
parser.addOption(x11DisplayOption);
|
||||
parser.addOption(waylandSocketOption);
|
||||
#if HAVE_INPUT
|
||||
QCommandLineOption libinputOption(QStringLiteral("libinput"),
|
||||
i18n("Enable libinput support for input events processing. Note: never use in a nested session."));
|
||||
|
|
61
wayland_server.cpp
Normal file
61
wayland_server.cpp
Normal file
|
@ -0,0 +1,61 @@
|
|||
/********************************************************************
|
||||
KWin - the KDE window manager
|
||||
This file is part of the KDE project.
|
||||
|
||||
Copyright (C) 2015 Martin Gräßlin <mgraesslin@kde.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*********************************************************************/
|
||||
#include "wayland_server.h"
|
||||
|
||||
#include <KWayland/Server/compositor_interface.h>
|
||||
#include <KWayland/Server/display.h>
|
||||
#include <KWayland/Server/output_interface.h>
|
||||
#include <KWayland/Server/shell_interface.h>
|
||||
|
||||
using namespace KWayland::Server;
|
||||
|
||||
namespace KWin
|
||||
{
|
||||
|
||||
KWIN_SINGLETON_FACTORY(WaylandServer)
|
||||
|
||||
WaylandServer::WaylandServer(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
WaylandServer::~WaylandServer() = default;
|
||||
|
||||
void WaylandServer::init(const QByteArray &socketName)
|
||||
{
|
||||
m_display = new KWayland::Server::Display(this);
|
||||
if (!socketName.isNull() && !socketName.isEmpty()) {
|
||||
m_display->setSocketName(QString::fromUtf8(socketName));
|
||||
}
|
||||
m_display->start();
|
||||
m_compositor = m_display->createCompositor(m_display);
|
||||
m_compositor->create();
|
||||
m_shell = m_display->createShell(m_display);
|
||||
m_shell->create();
|
||||
m_display->createShm();
|
||||
|
||||
// we need a dummy output
|
||||
OutputInterface *output = m_display->createOutput(m_display);
|
||||
output->setPhysicalSize(QSize(10, 10));
|
||||
output->addMode(QSize(1024, 768));
|
||||
output->create();
|
||||
}
|
||||
|
||||
}
|
78
wayland_server.h
Normal file
78
wayland_server.h
Normal file
|
@ -0,0 +1,78 @@
|
|||
/********************************************************************
|
||||
KWin - the KDE window manager
|
||||
This file is part of the KDE project.
|
||||
|
||||
Copyright (C) 2015 Martin Gräßlin <mgraesslin@kde.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*********************************************************************/
|
||||
#ifndef KWIN_WAYLAND_SERVER_H
|
||||
#define KWIN_WAYLAND_SERVER_H
|
||||
|
||||
#include <kwinglobals.h>
|
||||
|
||||
#include <QObject>
|
||||
|
||||
namespace KWayland
|
||||
{
|
||||
namespace Server
|
||||
{
|
||||
class CompositorInterface;
|
||||
class Display;
|
||||
class ShellInterface;
|
||||
class SeatInterface;
|
||||
class OutputInterface;
|
||||
}
|
||||
}
|
||||
|
||||
namespace KWin
|
||||
{
|
||||
|
||||
class KWIN_EXPORT WaylandServer : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
virtual ~WaylandServer();
|
||||
void init(const QByteArray &socketName = QByteArray());
|
||||
|
||||
KWayland::Server::Display *display() {
|
||||
return m_display;
|
||||
}
|
||||
KWayland::Server::CompositorInterface *compositor() {
|
||||
return m_compositor;
|
||||
}
|
||||
KWayland::Server::SeatInterface *seat() {
|
||||
return m_seat;
|
||||
}
|
||||
KWayland::Server::ShellInterface *shell() {
|
||||
return m_shell;
|
||||
}
|
||||
|
||||
private:
|
||||
KWayland::Server::Display *m_display = nullptr;
|
||||
KWayland::Server::CompositorInterface *m_compositor = nullptr;
|
||||
KWayland::Server::SeatInterface *m_seat = nullptr;
|
||||
KWayland::Server::ShellInterface *m_shell = nullptr;
|
||||
KWIN_SINGLETON(WaylandServer)
|
||||
};
|
||||
|
||||
inline
|
||||
WaylandServer *waylandServer() {
|
||||
return WaylandServer::self();
|
||||
}
|
||||
|
||||
} // namespace KWin
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in a new issue