From b7d3c0914b8850d93878925984f83a7e1dcf5631 Mon Sep 17 00:00:00 2001 From: wangpeng Date: Thu, 7 Jan 2021 19:06:27 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=A6=86=E7=9B=96QPlatformInputContext?= =?UTF-8?q?=E8=99=9A=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联了show() hide() boardRect() visible()函数 关联了keyboardRectangleChanged visibleChanged 信号 Log: 添加虚拟键盘对外接口与QPlatformInputContext接口关联 Change-Id: Ife63b6279de517b0b23e1b07b18644143a629a1f --- misc/com.deepin.im.xml | 23 ++++++++++++ xcb/dplatforminputcontexthook.cpp | 60 +++++++++++++++++++++++++++++++ xcb/dplatforminputcontexthook.h | 52 +++++++++++++++++++++++++++ xcb/dplatformintegration.cpp | 25 +++++++++++++ xcb/xcb.pro | 10 ++++-- 5 files changed, 167 insertions(+), 3 deletions(-) create mode 100644 misc/com.deepin.im.xml create mode 100644 xcb/dplatforminputcontexthook.cpp create mode 100644 xcb/dplatforminputcontexthook.h diff --git a/misc/com.deepin.im.xml b/misc/com.deepin.im.xml new file mode 100644 index 00000000..2ea75999 --- /dev/null +++ b/misc/com.deepin.im.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/xcb/dplatforminputcontexthook.cpp b/xcb/dplatforminputcontexthook.cpp new file mode 100644 index 00000000..67b60201 --- /dev/null +++ b/xcb/dplatforminputcontexthook.cpp @@ -0,0 +1,60 @@ +/* +* Copyright (C) 2020 ~ 2020 Uniontech Software Technology Co.,Ltd. +* +* Author: wangpeng +* +* Maintainer: wangpeng +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*/ +#include "dplatforminputcontexthook.h" + +#include "global.h" +#include + +DPP_BEGIN_NAMESPACE + +void DPlatformInputContextHook::showInputPanel(QPlatformInputContext *inputContext) +{ + Q_UNUSED(inputContext) + instance()->setImActive(true); +} + +void DPlatformInputContextHook::hideInputPanel(QPlatformInputContext *inputContext) +{ + Q_UNUSED(inputContext) + instance()->setImActive(false); +} + +bool DPlatformInputContextHook::isInputPanelVisible(QPlatformInputContext *inputContext) +{ + Q_UNUSED(inputContext) + return instance()->imActive(); +} + +QRectF DPlatformInputContextHook::keyboardRect(QPlatformInputContext *inputContext) +{ + Q_UNUSED(inputContext) + return instance()->geometry(); +} + +Q_GLOBAL_STATIC_WITH_ARGS(ComDeepinImInterface, __imInterface, + (QString("com.deepin.im"), QString("/com/deepin/im"), QDBusConnection::sessionBus())) + +ComDeepinImInterface* DPlatformInputContextHook::instance() +{ + return __imInterface; +} + +DPP_END_NAMESPACE diff --git a/xcb/dplatforminputcontexthook.h b/xcb/dplatforminputcontexthook.h new file mode 100644 index 00000000..b47b6bae --- /dev/null +++ b/xcb/dplatforminputcontexthook.h @@ -0,0 +1,52 @@ +/* +* Copyright (C) 2020 ~ 2020 Uniontech Software Technology Co.,Ltd. +* +* Author: wangpeng +* +* Maintainer: wangpeng +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*/ +#ifndef DPLATFORMINPUTCONTEXTHOOK_H +#define DPLATFORMINPUTCONTEXTHOOK_H + +#include "global.h" + +#include +#include + +#include "im_interface.h" + + +QT_BEGIN_NAMESPACE +class QPlatformInputContext; +QT_END_NAMESPACE + +DPP_BEGIN_NAMESPACE + +class DPlatformInputContextHook +{ + +public: + static void showInputPanel(QPlatformInputContext *inputContext); + static void hideInputPanel(QPlatformInputContext *inputContext); + static bool isInputPanelVisible(QPlatformInputContext *inputContext); + static QRectF keyboardRect(QPlatformInputContext *inputContext); + + static ComDeepinImInterface* instance(); +}; + +DPP_END_NAMESPACE + +#endif // DPLATFORMINPUTCONTEXTHOOK_H diff --git a/xcb/dplatformintegration.cpp b/xcb/dplatformintegration.cpp index ede4332b..faa2c9bd 100644 --- a/xcb/dplatformintegration.cpp +++ b/xcb/dplatformintegration.cpp @@ -43,6 +43,7 @@ #include "windoweventhook.h" #include "xcbnativeeventfilter.h" #include "dplatformnativeinterfacehook.h" +#include "dplatforminputcontexthook.h" #include "dxcbxsettings.h" #include "dhighdpi.h" @@ -71,8 +72,11 @@ #include #undef protected #include +#include #include +#include "im_interface.h" + // https://www.freedesktop.org/wiki/Specifications/XSettingsRegistry/ #define XSETTINGS_CURSOR_BLINK QByteArrayLiteral("Net/CursorBlink") #define XSETTINGS_CURSOR_BLINK_TIME QByteArrayLiteral("Net/CursorBlinkTime") @@ -1006,6 +1010,27 @@ void DPlatformIntegration::initialize() QXcbIntegration::initialize(); + // 适配虚拟键盘 + 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); diff --git a/xcb/xcb.pro b/xcb/xcb.pro index fd64e502..b732b725 100644 --- a/xcb/xcb.pro +++ b/xcb/xcb.pro @@ -8,7 +8,7 @@ PLUGIN_CLASS_NAME = DXcbIntegrationPlugin DESTDIR = $$_PRO_FILE_PWD_/../bin/plugins/platforms -QT += opengl x11extras +QT += opengl x11extras dbus QT += core-private #xcb_qpa_lib-private greaterThan(QT_MAJOR_VERSION, 4) { QT += widgets widgets-private @@ -45,7 +45,8 @@ SOURCES += \ dhighdpi.cpp \ dnotitlebarwindowhelper.cpp \ 3rdparty/dsimple.c \ - 3rdparty/clientwin.c + 3rdparty/clientwin.c \ + $$PWD/dplatforminputcontexthook.cpp HEADERS += \ $$PWD/dplatformintegration.h \ @@ -56,7 +57,8 @@ HEADERS += \ dhighdpi.h \ dnotitlebarwindowhelper.h \ 3rdparty/dsimple.h \ - 3rdparty/clientwin.h + 3rdparty/clientwin.h \ + $$PWD/dplatforminputcontexthook.h INCLUDEPATH += $$PWD/../src @@ -69,6 +71,8 @@ isEmpty(INSTALL_PATH) { target.path = $$INSTALL_PATH } +DBUS_INTERFACES += ../misc/com.deepin.im.xml + message($$target.path) INSTALLS += target