diff --git a/main_wayland.cpp b/main_wayland.cpp index ef41258272..68bc1315e4 100644 --- a/main_wayland.cpp +++ b/main_wayland.cpp @@ -79,24 +79,44 @@ ApplicationWayland::~ApplicationWayland() void ApplicationWayland::performStartup() { - if (m_startXWayland) { - setOperationMode(KWin::Application::OperationModeXwayland); - int sx[2]; - if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, sx) < 0) { - std::cerr << "FATAL ERROR: failed to open socket to open XCB connection" << std::endl; - exit(1); - return; - } + setOperationMode(m_startXWayland ? OperationModeXwayland : OperationModeWaylandAndX11); - m_xcbConnectionFd = sx[0]; - const int xDisplayPipe = startXServer(WaylandServer::self()->display()->socketName().toUtf8(), sx[1]); - QFutureWatcher *watcher = new QFutureWatcher(this); - QObject::connect(watcher, &QFutureWatcher::finished, this, &ApplicationWayland::continueStartupWithX, Qt::QueuedConnection); - QObject::connect(watcher, &QFutureWatcher::finished, watcher, &QFutureWatcher::deleteLater, Qt::QueuedConnection); - watcher->setFuture(QtConcurrent::run(readDisplay, xDisplayPipe)); - } else { + // try creating the Wayland Backend + createInput(); + Wayland::WaylandBackend *backend = Wayland::WaylandBackend::create(); + connect(backend, &Wayland::WaylandBackend::connectionFailed, this, + [] () { + fputs(i18n("kwin_wayland: could not connect to Wayland Server, ensure WAYLAND_DISPLAY is set.\n").toLocal8Bit().constData(), stderr); + ::exit(1); + } + ); + connect(backend, &Wayland::WaylandBackend::outputsChanged, this, &ApplicationWayland::continueStartupWithScreens); +} + +void ApplicationWayland::continueStartupWithScreens() +{ + disconnect(Wayland::WaylandBackend::self(), &Wayland::WaylandBackend::outputsChanged, this, &ApplicationWayland::continueStartupWithScreens); + createScreens(); + waylandServer()->initOutputs(); + + if (!m_startXWayland) { continueStartupWithX(); + return; } + + int sx[2]; + if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, sx) < 0) { + std::cerr << "FATAL ERROR: failed to open socket to open XCB connection" << std::endl; + exit(1); + return; + } + + m_xcbConnectionFd = sx[0]; + const int xDisplayPipe = startXServer(WaylandServer::self()->display()->socketName().toUtf8(), sx[1]); + QFutureWatcher *watcher = new QFutureWatcher(this); + QObject::connect(watcher, &QFutureWatcher::finished, this, &ApplicationWayland::continueStartupWithX, Qt::QueuedConnection); + QObject::connect(watcher, &QFutureWatcher::finished, watcher, &QFutureWatcher::deleteLater, Qt::QueuedConnection); + watcher->setFuture(QtConcurrent::run(readDisplay, xDisplayPipe)); } void ApplicationWayland::continueStartupWithX() @@ -144,15 +164,6 @@ void ApplicationWayland::continueStartupWithX() ::exit(1); } - // try creating the Wayland Backend - Wayland::WaylandBackend *backend = Wayland::WaylandBackend::create(); - connect(backend, &Wayland::WaylandBackend::connectionFailed, this, - [] () { - fputs(i18n("kwin_wayland: could not connect to Wayland Server, ensure WAYLAND_DISPLAY is set.\n").toLocal8Bit().constData(), stderr); - ::exit(1); - } - ); - createWorkspace(); Xcb::sync(); // Trigger possible errors, there's still a chance to abort diff --git a/main_wayland.h b/main_wayland.h index 16c8b62f06..9a62282fcb 100644 --- a/main_wayland.h +++ b/main_wayland.h @@ -40,6 +40,7 @@ protected: private: void createX11Connection(); + void continueStartupWithScreens(); void continueStartupWithX(); bool m_startXWayland = false;