From kde-commits Fri Sep 01 16:06:14 2017 From: =?utf-8?q?Martin_Fl=C3=B6ser?= Date: Fri, 01 Sep 2017 16:06:14 +0000 To: kde-commits Subject: [kwin] /: Do not hard runtime depend on X11 in composite startup Message-Id: X-MARC-Message: https://marc.info/?l=kde-commits&m=150428198618254 Git commit 2892fad5b6c5d3eccd946a6aa24d0f77b40f0058 by Martin Fl=C3=B6ser. Committed on 01/09/2017 at 16:05. Pushed by graesslin into branch 'master'. Do not hard runtime depend on X11 in composite startup Summary: The compositor needs to claim the X11 compositor selection and redirect the X11 windows. This of course only makes sense when having X11 support. This change refactors the code so that if X11 support is missing the code is not executed, but as soon as X11 support comes available the selection gets claimed. Also if the connection goes away the selection is deleted, though it might be that this does not work as KSelectionOwner might call into xcb and cause a crash. This needs to be tested once we start supporting XWayland going away. Reviewers: #kwin, #plasma Subscribers: plasma-devel, kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D7504 M +19 -5 composite.cpp M +1 -0 composite.h https://commits.kde.org/kwin/2892fad5b6c5d3eccd946a6aa24d0f77b40f0058 diff --git a/composite.cpp b/composite.cpp index 705c6d5bf..9c5d9e441 100644 --- a/composite.cpp +++ b/composite.cpp @@ -190,7 +190,7 @@ extern bool is_multihead; = void Compositor::slotCompositingOptionsInitialized() { - claimCompositorSelection(); + setupX11Support(); = // There might still be a deleted around, needs to be cleared before c= reating the scene (BUG 333275) if (Workspace::self()) { @@ -290,7 +290,7 @@ void Compositor::slotCompositingOptionsInitialized() = void Compositor::claimCompositorSelection() { - if (!cm_selection && kwinApp()->x11Connection()) { + if (!cm_selection) { char selection_name[ 100 ]; sprintf(selection_name, "_NET_WM_CM_S%d", Application::x11ScreenNu= mber()); cm_selection =3D new CompositorSelectionOwner(selection_name); @@ -306,15 +306,28 @@ void Compositor::claimCompositorSelection() } } = +void Compositor::setupX11Support() +{ + auto c =3D kwinApp()->x11Connection(); + if (!c) { + delete cm_selection; + cm_selection =3D nullptr; + return; + } + claimCompositorSelection(); + xcb_composite_redirect_subwindows(c, kwinApp()->x11RootWindow(), XCB_C= OMPOSITE_REDIRECT_MANUAL); +} + void Compositor::startupWithWorkspace() { if (!m_starting) { return; } + connect(kwinApp(), &Application::x11ConnectionChanged, this, &Composit= or::setupX11Support, Qt::UniqueConnection); Workspace::self()->markXStackingOrderAsDirty(); Q_ASSERT(m_scene); connect(workspace(), &Workspace::destroyed, this, [this] { compositeTi= mer.stop(); }); - claimCompositorSelection(); + setupX11Support(); m_xrrRefreshRate =3D KWin::currentRefreshRate(); fpsInterval =3D options->maxFpsInterval(); if (m_scene->syncsToVBlank()) { // if we do vsync, set the fps to the= next multiple of the vblank rate @@ -324,7 +337,6 @@ void Compositor::startupWithWorkspace() vBlankInterval =3D milliToNano(1); // no sync - DO NOT set "0", wo= uld cause div-by-zero segfaults. m_timeSinceLastVBlank =3D 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_COMP= OSITE_REDIRECT_MANUAL); new EffectsHandlerImpl(this, m_scene); // sets also the 'effects' po= inter connect(Workspace::self(), &Workspace::deletedRemoved, m_scene, &Scene= ::windowDeleted); connect(effects, SIGNAL(screenGeometryChanged(QSize)), SLOT(addRepaint= Full())); @@ -392,7 +404,9 @@ void Compositor::finish() c->finishCompositing(); foreach (Deleted * c, Workspace::self()->deletedList()) c->finishCompositing(); - xcb_composite_unredirect_subwindows(connection(), rootWindow(), XC= B_COMPOSITE_REDIRECT_MANUAL); + if (auto c =3D kwinApp()->x11Connection()) { + xcb_composite_unredirect_subwindows(c, kwinApp()->x11RootWindo= w(), XCB_COMPOSITE_REDIRECT_MANUAL); + } } if (waylandServer()) { foreach (ShellClient *c, waylandServer()->clients()) { diff --git a/composite.h b/composite.h index ccff306a9..9f6590cfc 100644 --- a/composite.h +++ b/composite.h @@ -207,6 +207,7 @@ private: * Continues the startup after Scene And Workspace are created **/ void startupWithWorkspace(); + void setupX11Support(); = /** * Whether the Compositor is currently suspended, 8 bits encoding the = reason