Skip to content

Commit

Permalink
feat: 覆盖QPlatformInputContext虚函数
Browse files Browse the repository at this point in the history
关联了show() hide() boardRect() visible()函数
关联了keyboardRectangleChanged visibleChanged 信号

Log: 添加虚拟键盘对外接口与QPlatformInputContext接口关联
Change-Id: Ife63b6279de517b0b23e1b07b18644143a629a1f
  • Loading branch information
wangpeng committed Jan 13, 2021
1 parent 5235ff9 commit b7d3c09
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 3 deletions.
23 changes: 23 additions & 0 deletions misc/com.deepin.im.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="com.deepin.im">
<property name="geometry" type="(iiii)" access="read">
<annotation name="org.qtproject.QtDBus.QtTypeName" value="QRect"/>
</property>
<property name="imActive" type="b" access="readwrite"/>
<property name="imSignalLock" type="b" access="readwrite"/>
<signal name="geometryChanged">
<arg name="rect" type="(iiii)" direction="out"/>
<annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QRect"/>
</signal>
<signal name="imActiveChanged">
<arg name="is" type="b" direction="out"/>
</signal>
<signal name="imSignalLockChanged">
<arg name="is" type="b" direction="out"/>
</signal>
<method name="setKeyboardHeight">
<arg name="h" type="i" direction="in"/>
</method>
</interface>
</node>
60 changes: 60 additions & 0 deletions xcb/dplatforminputcontexthook.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright (C) 2020 ~ 2020 Uniontech Software Technology Co.,Ltd.
*
* Author: wangpeng <[email protected]>
*
* Maintainer: wangpeng <[email protected]>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "dplatforminputcontexthook.h"

#include "global.h"
#include <qpa/qplatforminputcontext.h>

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
52 changes: 52 additions & 0 deletions xcb/dplatforminputcontexthook.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (C) 2020 ~ 2020 Uniontech Software Technology Co.,Ltd.
*
* Author: wangpeng <[email protected]>
*
* Maintainer: wangpeng <[email protected]>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef DPLATFORMINPUTCONTEXTHOOK_H
#define DPLATFORMINPUTCONTEXTHOOK_H

#include "global.h"

#include <QRectF>
#include <QtGlobal>

#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
25 changes: 25 additions & 0 deletions xcb/dplatformintegration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "windoweventhook.h"
#include "xcbnativeeventfilter.h"
#include "dplatformnativeinterfacehook.h"
#include "dplatforminputcontexthook.h"
#include "dxcbxsettings.h"
#include "dhighdpi.h"

Expand Down Expand Up @@ -71,8 +72,11 @@
#include <private/qsimpledrag_p.h>
#undef protected
#include <qpa/qplatformnativeinterface.h>
#include <qpa/qplatforminputcontext.h>
#include <private/qpaintengine_raster_p.h>

#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")
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 7 additions & 3 deletions xcb/xcb.pro
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 \
Expand All @@ -56,7 +57,8 @@ HEADERS += \
dhighdpi.h \
dnotitlebarwindowhelper.h \
3rdparty/dsimple.h \
3rdparty/clientwin.h
3rdparty/clientwin.h \
$$PWD/dplatforminputcontexthook.h

INCLUDEPATH += $$PWD/../src

Expand All @@ -69,6 +71,8 @@ isEmpty(INSTALL_PATH) {
target.path = $$INSTALL_PATH
}

DBUS_INTERFACES += ../misc/com.deepin.im.xml

message($$target.path)

INSTALLS += target
Expand Down

0 comments on commit b7d3c09

Please sign in to comment.