IBus: Use WAYLAND_DISPLAY on Wayland sessions to make up socket names

A recent change in IBus made it prefer the WAYLAND_DISPLAY envvar in
order to compose its socket path for Wayland sessions. This is because
DISPLAY is unreliable in those environment: It might not be there, there
might be several displays pointing to the same Xwayland server (as it's
the case in GNOME 3.36), or there might even be multiple Xwayland servers
(eg. to enforce inter-app isolation with X11 apps).

Fixes: QTBUG-82910
Pick-To: 5.15
Change-Id: I4883b5d06863ba284883dd95281bed2ce7203e29
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
Takao Fujiwara 2020-05-11 21:14:01 +09:00
parent 5ffa5808f8
commit 54aa63be9b

View File

@ -712,19 +712,35 @@ void QIBusPlatformInputContextPrivate::createBusProxy()
QString QIBusPlatformInputContextPrivate::getSocketPath()
{
QByteArray display(qgetenv("DISPLAY"));
QByteArray host = "unix";
QByteArray display;
QByteArray displayNumber = "0";
bool isWayland = false;
if (qEnvironmentVariableIsSet("IBUS_ADDRESS_FILE")) {
QByteArray path = qgetenv("IBUS_ADDRESS_FILE");
return QString::fromLocal8Bit(path);
} else if (qEnvironmentVariableIsSet("WAYLAND_DISPLAY")) {
display = qgetenv("WAYLAND_DISPLAY");
isWayland = true;
} else {
display = qgetenv("DISPLAY");
}
QByteArray host = "unix";
if (isWayland) {
displayNumber = display;
} else {
int pos = display.indexOf(':');
if (pos > 0)
host = display.left(pos);
++pos;
int pos2 = display.indexOf('.', pos);
if (pos2 > 0)
displayNumber = display.mid(pos, pos2 - pos);
else
displayNumber = display.mid(pos);
}
int pos = display.indexOf(':');
if (pos > 0)
host = display.left(pos);
++pos;
int pos2 = display.indexOf('.', pos);
if (pos2 > 0)
displayNumber = display.mid(pos, pos2 - pos);
else
displayNumber = display.mid(pos);
if (debug)
qDebug() << "host=" << host << "displayNumber" << displayNumber;