Skip to content

Commit

Permalink
IBus: connect to ibus-daemon when it restarts in Flatpak
Browse files Browse the repository at this point in the history
IBus clients cannot access the IBus socket path in Flatpak and
need to watch the D-Bus disconnection.

Change-Id: Ida1a5ce4fe112c1c4f8855ec886e74f2cbdcc8a0
Reviewed-by: Lars Knoll <[email protected]>
  • Loading branch information
fujiwarat committed Aug 10, 2018
1 parent 9742ee6 commit e9a8fac
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class QIBusPlatformInputContextPrivate
QIBusProxy *bus;
QIBusProxyPortal *portalBus; // bus and portalBus are alternative.
QIBusInputContextProxy *context;
QDBusServiceWatcher serviceWatcher;

bool usePortal; // return value of shouldConnectIbusPortal
bool valid;
Expand All @@ -107,20 +108,25 @@ class QIBusPlatformInputContextPrivate
QIBusPlatformInputContext::QIBusPlatformInputContext ()
: d(new QIBusPlatformInputContextPrivate())
{
QString socketPath = QIBusPlatformInputContextPrivate::getSocketPath();
QFile file(socketPath);
if (file.open(QFile::ReadOnly)) {
if (!d->usePortal) {
QString socketPath = QIBusPlatformInputContextPrivate::getSocketPath();
QFile file(socketPath);
if (file.open(QFile::ReadOnly)) {
#ifndef QT_NO_FILESYSTEMWATCHER
// If KDE session save is used or restart ibus-daemon,
// the applications could run before ibus-daemon runs.
// We watch the getSocketPath() to get the launching ibus-daemon.
m_socketWatcher.addPath(socketPath);
connect(&m_socketWatcher, SIGNAL(fileChanged(QString)), this, SLOT(socketChanged(QString)));
qCDebug(qtQpaInputMethods) << "socketWatcher.addPath" << socketPath;
// If KDE session save is used or restart ibus-daemon,
// the applications could run before ibus-daemon runs.
// We watch the getSocketPath() to get the launching ibus-daemon.
m_socketWatcher.addPath(socketPath);
connect(&m_socketWatcher, SIGNAL(fileChanged(QString)), this, SLOT(socketChanged(QString)));
#endif
}
m_timer.setSingleShot(true);
connect(&m_timer, SIGNAL(timeout()), this, SLOT(connectToBus()));
}

m_timer.setSingleShot(true);
connect(&m_timer, SIGNAL(timeout()), this, SLOT(connectToBus()));
QObject::connect(&d->serviceWatcher, SIGNAL(serviceRegistered(QString)), this, SLOT(busRegistered(QString)));
QObject::connect(&d->serviceWatcher, SIGNAL(serviceUnregistered(QString)), this, SLOT(busUnregistered(QString)));

connectToContextSignals();

Expand Down Expand Up @@ -534,6 +540,22 @@ void QIBusPlatformInputContext::socketChanged(const QString &str)
m_timer.start(100);
}

void QIBusPlatformInputContext::busRegistered(const QString &str)
{
qCDebug(qtQpaInputMethods) << "busRegistered";
Q_UNUSED (str);
if (d->usePortal) {
connectToBus();
}
}

void QIBusPlatformInputContext::busUnregistered(const QString &str)
{
qCDebug(qtQpaInputMethods) << "busUnregistered";
Q_UNUSED (str);
d->busConnected = false;
}

// When getSocketPath() is modified, the bus is not established yet
// so use m_timer.
void QIBusPlatformInputContext::connectToBus()
Expand All @@ -543,7 +565,7 @@ void QIBusPlatformInputContext::connectToBus()
connectToContextSignals();

#ifndef QT_NO_FILESYSTEMWATCHER
if (m_socketWatcher.files().size() == 0)
if (!d->usePortal && m_socketWatcher.files().size() == 0)
m_socketWatcher.addPath(QIBusPlatformInputContextPrivate::getSocketPath());
#endif
}
Expand Down Expand Up @@ -652,6 +674,11 @@ void QIBusPlatformInputContextPrivate::createBusProxy()

ic = bus->CreateInputContext(QLatin1String("QIBusInputContext"));
}

serviceWatcher.removeWatchedService(ibusService);
serviceWatcher.setConnection(*connection);
serviceWatcher.addWatchedService(ibusService);

if (!ic.isValid()) {
qWarning("QIBusPlatformInputContext: CreateInputContext failed.");
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ public Q_SLOTS:
void showPreeditText();
void filterEventFinished(QDBusPendingCallWatcher *call);
void socketChanged(const QString &str);
void busRegistered(const QString &str);
void busUnregistered(const QString &str);
void connectToBus();
void globalEngineChanged(const QString &engine_name);

Expand Down

0 comments on commit e9a8fac

Please sign in to comment.