summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTakao Fujiwara <takao.fujiwara1@gmail.com>2018-08-09 16:37:21 +0900
committerTakao Fujiwara <takao.fujiwara1@gmail.com>2018-08-10 10:56:03 +0000
commite9a8facc96ce6d3b8df4832032ca4df9fac6e9d7 (patch)
tree313a49b2ea1286f683fc71c38997f386f71c09a5 /src
parent9742ee681b6c877f518013a3af1ce1aa0a328d2c (diff)
IBus: connect to ibus-daemon when it restarts in Flatpak
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 <lars.knoll@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/platforminputcontexts/ibus/qibusplatforminputcontext.cpp49
-rw-r--r--src/plugins/platforminputcontexts/ibus/qibusplatforminputcontext.h2
2 files changed, 40 insertions, 11 deletions
diff --git a/src/plugins/platforminputcontexts/ibus/qibusplatforminputcontext.cpp b/src/plugins/platforminputcontexts/ibus/qibusplatforminputcontext.cpp
index 19f0afbf50..0e587965ca 100644
--- a/src/plugins/platforminputcontexts/ibus/qibusplatforminputcontext.cpp
+++ b/src/plugins/platforminputcontexts/ibus/qibusplatforminputcontext.cpp
@@ -93,6 +93,7 @@ public:
QIBusProxy *bus;
QIBusProxyPortal *portalBus; // bus and portalBus are alternative.
QIBusInputContextProxy *context;
+ QDBusServiceWatcher serviceWatcher;
bool usePortal; // return value of shouldConnectIbusPortal
bool valid;
@@ -107,20 +108,25 @@ public:
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();
@@ -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()
@@ -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
}
@@ -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;
diff --git a/src/plugins/platforminputcontexts/ibus/qibusplatforminputcontext.h b/src/plugins/platforminputcontexts/ibus/qibusplatforminputcontext.h
index 9b92b2e1f9..f37552b937 100644
--- a/src/plugins/platforminputcontexts/ibus/qibusplatforminputcontext.h
+++ b/src/plugins/platforminputcontexts/ibus/qibusplatforminputcontext.h
@@ -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);