diff --git a/composite.h b/composite.h --- a/composite.h +++ b/composite.h @@ -207,6 +207,7 @@ * Continues the startup after Scene And Workspace are created **/ void startupWithWorkspace(); + void setupX11Support(); /** * Whether the Compositor is currently suspended, 8 bits encoding the reason diff --git a/composite.cpp b/composite.cpp --- a/composite.cpp +++ b/composite.cpp @@ -190,7 +190,7 @@ void Compositor::slotCompositingOptionsInitialized() { - claimCompositorSelection(); + setupX11Support(); // There might still be a deleted around, needs to be cleared before creating the scene (BUG 333275) if (Workspace::self()) { @@ -275,7 +275,7 @@ void Compositor::claimCompositorSelection() { - if (!cm_selection && kwinApp()->x11Connection()) { + if (!cm_selection) { char selection_name[ 100 ]; sprintf(selection_name, "_NET_WM_CM_S%d", Application::x11ScreenNumber()); cm_selection = new CompositorSelectionOwner(selection_name); @@ -291,15 +291,28 @@ } } +void Compositor::setupX11Support() +{ + auto c = kwinApp()->x11Connection(); + if (!c) { + delete cm_selection; + cm_selection = nullptr; + return; + } + claimCompositorSelection(); + xcb_composite_redirect_subwindows(c, kwinApp()->x11RootWindow(), XCB_COMPOSITE_REDIRECT_MANUAL); +} + void Compositor::startupWithWorkspace() { if (!m_starting) { return; } + connect(kwinApp(), &Application::x11ConnectionChanged, this, &Compositor::setupX11Support, Qt::UniqueConnection); Workspace::self()->markXStackingOrderAsDirty(); Q_ASSERT(m_scene); connect(workspace(), &Workspace::destroyed, this, [this] { compositeTimer.stop(); }); - claimCompositorSelection(); + setupX11Support(); m_xrrRefreshRate = KWin::currentRefreshRate(); fpsInterval = options->maxFpsInterval(); if (m_scene->syncsToVBlank()) { // if we do vsync, set the fps to the next multiple of the vblank rate @@ -309,7 +322,6 @@ vBlankInterval = milliToNano(1); // no sync - DO NOT set "0", would cause div-by-zero segfaults. m_timeSinceLastVBlank = fpsInterval - (options->vBlankTime() + 1); // means "start now" - we don't have even a slight idea when the first vsync will occur scheduleRepaint(); - xcb_composite_redirect_subwindows(connection(), rootWindow(), XCB_COMPOSITE_REDIRECT_MANUAL); new EffectsHandlerImpl(this, m_scene); // sets also the 'effects' pointer connect(Workspace::self(), &Workspace::deletedRemoved, m_scene, &Scene::windowDeleted); connect(effects, SIGNAL(screenGeometryChanged(QSize)), SLOT(addRepaintFull())); @@ -377,7 +389,9 @@ c->finishCompositing(); foreach (Deleted * c, Workspace::self()->deletedList()) c->finishCompositing(); - xcb_composite_unredirect_subwindows(connection(), rootWindow(), XCB_COMPOSITE_REDIRECT_MANUAL); + if (auto c = kwinApp()->x11Connection()) { + xcb_composite_unredirect_subwindows(c, kwinApp()->x11RootWindow(), XCB_COMPOSITE_REDIRECT_MANUAL); + } } if (waylandServer()) { foreach (ShellClient *c, waylandServer()->clients()) {