Skip to content
This repository was archived by the owner on May 8, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions qt5/platforminputcontext/fcitxwatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,8 @@ QString socketFile() {
}

FcitxWatcher::FcitxWatcher(QDBusConnection sessionBus, QObject *parent)
: QObject(parent), m_fsWatcher(new QFileSystemWatcher(this)),
m_serviceWatcher(new QDBusServiceWatcher(this)), m_connection(nullptr),
m_sessionBus(sessionBus), m_socketFile(socketFile()),
: QObject(parent), m_connection(nullptr), m_sessionBus(sessionBus),
m_socketFile(socketFile()),
m_serviceName(QString("org.fcitx.Fcitx-%1").arg(displayNumber())),
m_availability(false) {}

Expand Down Expand Up @@ -118,6 +117,7 @@ void FcitxWatcher::watch() {
return;
}

m_serviceWatcher = new QDBusServiceWatcher(this);
connect(m_serviceWatcher,
SIGNAL(serviceOwnerChanged(QString, QString, QString)), this,
SLOT(imChanged(QString, QString, QString)));
Expand Down Expand Up @@ -145,6 +145,8 @@ void FcitxWatcher::unwatch() {
disconnect(m_serviceWatcher,
SIGNAL(serviceOwnerChanged(QString, QString, QString)), this,
SLOT(imChanged(QString, QString, QString)));
delete m_serviceWatcher;
m_serviceWatcher = nullptr;
unwatchSocketFile();
cleanUpConnection();
m_mainPresent = false;
Expand Down Expand Up @@ -243,6 +245,7 @@ void FcitxWatcher::watchSocketFile() {
QDir rt(QDir::root());
rt.mkpath(info.path());
}
m_fsWatcher = new QFileSystemWatcher(this);
m_fsWatcher->addPath(info.path());
if (info.exists()) {
m_fsWatcher->addPath(info.filePath());
Expand All @@ -255,14 +258,8 @@ void FcitxWatcher::watchSocketFile() {
}

void FcitxWatcher::unwatchSocketFile() {
if (!m_fsWatcher->files().isEmpty()) {
m_fsWatcher->removePaths(m_fsWatcher->files());
}
if (!m_fsWatcher->directories().isEmpty()) {
m_fsWatcher->removePaths(m_fsWatcher->directories());
}
m_fsWatcher->disconnect(SIGNAL(fileChanged(QString)));
m_fsWatcher->disconnect(SIGNAL(directoryChanged(QString)));
delete m_fsWatcher;
m_fsWatcher = nullptr;
}

void FcitxWatcher::imChanged(const QString &service, const QString &,
Expand Down
4 changes: 2 additions & 2 deletions qt5/platforminputcontext/fcitxwatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ private Q_SLOTS:
void setAvailability(bool availability);
void updateAvailability();

QFileSystemWatcher *m_fsWatcher;
QDBusServiceWatcher *m_serviceWatcher;
QFileSystemWatcher *m_fsWatcher = nullptr;
QDBusServiceWatcher *m_serviceWatcher = nullptr;
QDBusConnection *m_connection;
QDBusConnection m_sessionBus;
QString m_socketFile;
Expand Down
4 changes: 3 additions & 1 deletion qt5/platforminputcontext/qfcitxplatforminputcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <QPalette>
#include <QTextCharFormat>
#include <QWindow>
#include <qnamespace.h>
#include <qpa/qplatformcursor.h>
#include <qpa/qplatformscreen.h>
#include <qpa/qwindowsysteminterface.h>
Expand Down Expand Up @@ -99,7 +100,8 @@ QFcitxPlatformInputContext::QFcitxPlatformInputContext()
? xkb_compose_state_new(m_xkbComposeTable.data(),
XKB_COMPOSE_STATE_NO_FLAGS)
: 0) {
m_watcher->watch();
QMetaObject::invokeMethod(
this, [this]() { m_watcher->watch(); }, Qt::QueuedConnection);
}

QFcitxPlatformInputContext::~QFcitxPlatformInputContext() {
Expand Down