From 692ea66706c23648e1f6422641c006a1c448e10c Mon Sep 17 00:00:00 2001 From: Wang Peng Date: Tue, 10 Aug 2021 15:14:02 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E8=99=9A=E6=8B=9F?= =?UTF-8?q?=E9=94=AE=E7=9B=98=E7=9B=91=E8=A7=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加虚拟键盘服务监视连接, 防止虚拟键盘服务在应用程序后启动, 无法Hook虚拟键盘函数 Log: 防止虚拟键盘在程序后启动虚拟键盘无法显示 Change-Id: I671ab9fdd73fb08ef0ac1e230cff12cfa4d79add --- misc/org.freedesktop.DBus.xml | 82 +++++++++++++++++++++++++++++++++++ xcb/dplatformintegration.cpp | 65 ++++++++++++++++++--------- xcb/dplatformintegration.h | 1 + xcb/xcb.pro | 1 + 4 files changed, 128 insertions(+), 21 deletions(-) create mode 100644 misc/org.freedesktop.DBus.xml 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)