xwayland: Properly handle xcb_connect_to_fd() failures
xcb_connect_to_fd() will never return a NULL pointer, even if an error has occurred. Right after creating an xcb connection, xcb_connection_has_error() needs to be called in order to determine if the connection has an error.
This commit is contained in:
parent
bfcf312e37
commit
b8a16d4abf
2 changed files with 11 additions and 8 deletions
|
@ -297,11 +297,14 @@ void Xwayland::handleXwaylandError(QProcess::ProcessError error)
|
|||
}
|
||||
}
|
||||
|
||||
void Xwayland::createX11Connection()
|
||||
bool Xwayland::createX11Connection()
|
||||
{
|
||||
xcb_connection_t *connection = xcb_connect_to_fd(m_xcbConnectionFd, nullptr);
|
||||
if (!connection) {
|
||||
return;
|
||||
|
||||
const int errorCode = xcb_connection_has_error(connection);
|
||||
if (errorCode) {
|
||||
qCDebug(KWIN_XWL, "Failed to establish the XCB connection (error %d)", errorCode);
|
||||
return false;
|
||||
}
|
||||
|
||||
xcb_screen_t *screen = xcb_setup_roots_iterator(xcb_get_setup(connection)).data;
|
||||
|
@ -320,6 +323,8 @@ void Xwayland::createX11Connection()
|
|||
// Note that it's very important to have valid x11RootWindow(), x11ScreenNumber(), and
|
||||
// atoms when the rest of kwin is notified about the new X11 connection.
|
||||
emit m_app->x11ConnectionChanged();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Xwayland::destroyX11Connection()
|
||||
|
@ -347,16 +352,14 @@ void Xwayland::destroyX11Connection()
|
|||
|
||||
void Xwayland::continueStartupWithX()
|
||||
{
|
||||
createX11Connection();
|
||||
xcb_connection_t *xcbConn = m_app->x11Connection();
|
||||
if (!xcbConn) {
|
||||
if (!createX11Connection()) {
|
||||
// about to quit
|
||||
Q_EMIT criticalError(1);
|
||||
return;
|
||||
}
|
||||
|
||||
// create selection owner for WM_S0 - magic X display number expected by XWayland
|
||||
KSelectionOwner owner("WM_S0", xcbConn, m_app->x11RootWindow());
|
||||
KSelectionOwner owner("WM_S0", kwinApp()->x11Connection(), kwinApp()->x11RootWindow());
|
||||
owner.claim(true);
|
||||
|
||||
DataBridge::create(this);
|
||||
|
|
|
@ -87,7 +87,7 @@ private:
|
|||
void installSocketNotifier();
|
||||
void uninstallSocketNotifier();
|
||||
|
||||
void createX11Connection();
|
||||
bool createX11Connection();
|
||||
void destroyX11Connection();
|
||||
void continueStartupWithX();
|
||||
|
||||
|
|
Loading…
Reference in a new issue