diff --git a/misc/org.freedesktop.DBus.xml b/misc/org.freedesktop.DBus.xml new file mode 100644 index 00000000..fd14f638 --- /dev/null +++ b/misc/org.freedesktop.DBus.xml @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/xcb/dplatformintegration.cpp b/xcb/dplatformintegration.cpp index 54bb9ece..adc831d4 100644 --- a/xcb/dplatformintegration.cpp +++ b/xcb/dplatformintegration.cpp @@ -73,6 +73,7 @@ #include #include "im_interface.h" +#include "dbus_interface.h" // https://www.freedesktop.org/wiki/Specifications/XSettingsRegistry/ #define XSETTINGS_CURSOR_BLINK QByteArrayLiteral("Net/CursorBlink") @@ -1029,27 +1030,6 @@ void DPlatformIntegration::initialize() QSurfaceFormat::setDefaultFormat(format); } - // 适配虚拟键盘 - if (DPlatformInputContextHook::instance()->isValid()) { - VtableHook::overrideVfptrFun(inputContext(), - &QPlatformInputContext::showInputPanel, - &DPlatformInputContextHook::showInputPanel); - VtableHook::overrideVfptrFun(inputContext(), - &QPlatformInputContext::hideInputPanel, - &DPlatformInputContextHook::hideInputPanel); - VtableHook::overrideVfptrFun(inputContext(), - &QPlatformInputContext::isInputPanelVisible, - &DPlatformInputContextHook::isInputPanelVisible); - VtableHook::overrideVfptrFun(inputContext(), - &QPlatformInputContext::keyboardRect, - &DPlatformInputContextHook::keyboardRect); - - QObject::connect(DPlatformInputContextHook::instance(), &ComDeepinImInterface::geometryChanged, - inputContext(), &QPlatformInputContext::emitKeyboardRectChanged); - QObject::connect(DPlatformInputContextHook::instance(), &ComDeepinImInterface::imActiveChanged, - inputContext(), &QPlatformInputContext::emitInputPanelVisibleChanged); - } - #ifdef Q_OS_LINUX m_eventFilter = new XcbNativeEventFilter(defaultConnection()); qApp->installNativeEventFilter(m_eventFilter); @@ -1121,6 +1101,26 @@ void DPlatformIntegration::initialize() m_pDesktopInputSelectionControl->setApplicationEventMonitor(m_pApplicationEventMonitor.data()); } }); + + // 适配虚拟键盘 + if (DPlatformInputContextHook::instance()->isValid()) { + inputContextHookFunc(); + } else { + // 虚拟键盘服务未启动时,开始监听DBUS + // 待虚拟键盘启动后 Hook QPlatformInputContext函数 + // 该连接将一直存在防止使用中虚拟键盘服务重启 + OrgFreedesktopDBusInterface *interface = new OrgFreedesktopDBusInterface("org.freedesktop.DBus", "/org/freedesktop/DBus", QDBusConnection::sessionBus(), qApp); + QObject::connect(interface, &OrgFreedesktopDBusInterface::NameOwnerChanged, qApp, [ = ](const QString &in0, const QString &in1, const QString &in2){ + Q_UNUSED(in1) + Q_UNUSED(in2) + + if (in0 == "com.deepin.im") { + inputContextHookFunc(); + QObject::disconnect(interface, &OrgFreedesktopDBusInterface::NameOwnerChanged, nullptr, nullptr); + interface->deleteLater(); + } + }); + } } } @@ -1195,4 +1195,27 @@ bool DPlatformIntegration::isWindowBlockedHandle(QWindow *window, QWindow **bloc return VtableHook::callOriginalFun(qApp->d_func(), &QGuiApplicationPrivate::isWindowBlocked, window, blockingWindow); } +void DPlatformIntegration::inputContextHookFunc() +{ +// if (!VtableHook::hasVtable(inputContext())) { + VtableHook::overrideVfptrFun(inputContext(), + &QPlatformInputContext::showInputPanel, + &DPlatformInputContextHook::showInputPanel); + VtableHook::overrideVfptrFun(inputContext(), + &QPlatformInputContext::hideInputPanel, + &DPlatformInputContextHook::hideInputPanel); + VtableHook::overrideVfptrFun(inputContext(), + &QPlatformInputContext::isInputPanelVisible, + &DPlatformInputContextHook::isInputPanelVisible); + VtableHook::overrideVfptrFun(inputContext(), + &QPlatformInputContext::keyboardRect, + &DPlatformInputContextHook::keyboardRect); + + QObject::connect(DPlatformInputContextHook::instance(), &ComDeepinImInterface::geometryChanged, + inputContext(), &QPlatformInputContext::emitKeyboardRectChanged); + QObject::connect(DPlatformInputContextHook::instance(), &ComDeepinImInterface::imActiveChanged, + inputContext(), &QPlatformInputContext::emitInputPanelVisibleChanged); +// } +} + DPP_END_NAMESPACE diff --git a/xcb/dplatformintegration.h b/xcb/dplatformintegration.h index b3de34ca..67d5aeaa 100644 --- a/xcb/dplatformintegration.h +++ b/xcb/dplatformintegration.h @@ -103,6 +103,7 @@ class DPlatformIntegration : public DPlatformIntegrationParent private: // handle the DFrameWindow modal blocked state bool isWindowBlockedHandle(QWindow *window, QWindow **blockingWindow); + void inputContextHookFunc(); DPlatformBackingStoreHelper *m_storeHelper; DPlatformOpenGLContextHelper *m_contextHelper; diff --git a/xcb/xcb.pro b/xcb/xcb.pro index 5c3c17dc..47eb001f 100644 --- a/xcb/xcb.pro +++ b/xcb/xcb.pro @@ -71,6 +71,7 @@ isEmpty(INSTALL_PATH) { } DBUS_INTERFACES += ../misc/com.deepin.im.xml +DBUS_INTERFACES += ../misc/org.freedesktop.DBus.xml message($$target.path)