Skip to content

Commit

Permalink
fix: Can't input Chinese when opening the launcher
Browse files Browse the repository at this point in the history
Create an InputEventItem object to forward the input events of the input method.

Issue: linuxdeepin/developer-center#8469
  • Loading branch information
robertkill committed Jul 17, 2024
1 parent 2b072d8 commit 2182128
Show file tree
Hide file tree
Showing 5 changed files with 516 additions and 455 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ set(SOURCE_FILES
desktopintegration.cpp desktopintegration.h
launchercontroller.cpp launchercontroller.h
debughelper.cpp debughelper.h
inputeventitem.h inputeventitem.cpp
)

set(QML_FILES
Expand Down
19 changes: 19 additions & 0 deletions inputeventitem.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later
#include "inputeventitem.h"

InputEventItem::InputEventItem()
{
qApp->installEventFilter(this);
}

bool InputEventItem::eventFilter(QObject *obj, QEvent *event) {
if (event->type() == QEvent::InputMethod && (this->children().contains(obj) || obj == this)) {
QInputMethodEvent *inputMethodEvent = static_cast<QInputMethodEvent *>(event);
qDebug() << "InputEventItem::eventFilter: " << inputMethodEvent->commitString();
if (!inputMethodEvent->commitString().isEmpty())
Q_EMIT inputReceived(inputMethodEvent->commitString());
}
return QObject::eventFilter(obj, event);
}
25 changes: 25 additions & 0 deletions inputeventitem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later
#ifndef INPUTEVENTITEM_H
#define INPUTEVENTITEM_H

#include <QObject>
#include <QQmlEngine>
#include <QQuickItem>

class InputEventItem : public QQuickItem
{
Q_OBJECT
QML_ELEMENT
public:
InputEventItem();

protected:
bool eventFilter(QObject *obj, QEvent *event) override;

signals:
void inputReceived(const QString &input);
};

#endif // INPUTEVENTITEM_H
Loading

0 comments on commit 2182128

Please sign in to comment.