|
1 | | -// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
| 1 | +// SPDX-FileCopyrightText: 2023 - 2026 UnionTech Software Technology Co., Ltd. |
2 | 2 | // |
3 | 3 | // SPDX-License-Identifier: GPL-3.0-or-later |
4 | 4 |
|
|
26 | 26 | #include <QtWaylandCompositor/QWaylandQtTextInputMethod> |
27 | 27 | #include <QtWaylandCompositor/QWaylandQuickItem> |
28 | 28 |
|
| 29 | +#include <QGuiApplication> |
| 30 | +#include <QInputMethod> |
| 31 | +#include <QClipboard> |
| 32 | +#include <QMimeData> |
| 33 | + |
29 | 34 | #include <QJsonObject> |
30 | 35 | #include <QJsonParseError> |
31 | 36 |
|
|
39 | 44 | #include <private/qwlqttouch_p.h> |
40 | 45 | #endif |
41 | 46 |
|
42 | | -#include <QtGui/qguiapplication.h> |
43 | | -#include <QtGui/qinputmethod.h> |
44 | | - |
45 | 47 | DGUI_USE_NAMESPACE |
46 | 48 |
|
47 | 49 | struct WlQtTextInputMethodHelper : public QtWaylandServer::qt_text_input_method_v1 { |
@@ -75,11 +77,9 @@ struct WlQtTextInputMethodHelper : public QtWaylandServer::qt_text_input_method_ |
75 | 77 | d->cursorRectangle = QRect(); |
76 | 78 | d->preferredLanguage.clear(); |
77 | 79 | d->hints = Qt::InputMethodHints(); |
78 | | - auto *helper = static_cast<WlQtTextInputMethodHelper*>(base); |
79 | | - helper->send_enter(d->resource->handle, d->focusedSurface->resource()); |
80 | | - |
81 | | - helper->send_input_direction_changed(d->resource->handle, int(qApp->inputMethod()->inputDirection())); |
82 | | - helper->send_locale_changed(d->resource->handle, qApp->inputMethod()->locale().bcp47Name()); |
| 80 | + base->send_enter(d->resource->handle, d->focusedSurface->resource()); |
| 81 | + base->send_input_direction_changed(d->resource->handle, int(qApp->inputMethod()->inputDirection())); |
| 82 | + base->send_locale_changed(d->resource->handle, qApp->inputMethod()->locale().bcp47Name()); |
83 | 83 |
|
84 | 84 | d->focusDestroyListener.listenForDestruction(surface->resource()); |
85 | 85 | if (d->inputPanelVisible && d->enabledSurfaces.values().contains(surface)) |
@@ -516,6 +516,21 @@ void PluginManager::initialize() |
516 | 516 |
|
517 | 517 | // 设置 text input 焦点代理 |
518 | 518 | setupTextInputProxy(compositor); |
| 519 | + |
| 520 | + // 启用剪贴板保留并在宿主系统剪贴板更新时同步给插件 Wayland 客户端,实现粘贴功能 |
| 521 | + compositor->setRetainedSelectionEnabled(true); |
| 522 | + if (auto *clipboard = QGuiApplication::clipboard()) { |
| 523 | + QObject::connect(clipboard, &QClipboard::changed, this, [compositor](QClipboard::Mode mode) { |
| 524 | + if (mode == QClipboard::Clipboard) { |
| 525 | + if (const QMimeData *mimeData = QGuiApplication::clipboard()->mimeData(mode)) { |
| 526 | + compositor->overrideSelection(mimeData); |
| 527 | + } |
| 528 | + } |
| 529 | + }); |
| 530 | + if (const QMimeData *mimeData = clipboard->mimeData(QClipboard::Clipboard)) { |
| 531 | + compositor->overrideSelection(mimeData); |
| 532 | + } |
| 533 | + } |
519 | 534 | } |
520 | 535 |
|
521 | 536 | void PluginManager::updateDockOverflowState(int state) |
@@ -836,6 +851,10 @@ void PluginManager::setupTextInputProxy(QWaylandCompositor *compositor) |
836 | 851 | (QWaylandSurface *newFocus, QWaylandSurface *oldFocus) { |
837 | 852 | Q_UNUSED(oldFocus); |
838 | 853 |
|
| 854 | + if (newFocus) { |
| 855 | + newFocus->updateSelection(); |
| 856 | + } |
| 857 | + |
839 | 858 | // 由于 Deepin Qt6 构建中 QWaylandTextInput/V3 的公开类符号没有导出, |
840 | 859 | // 无法使用 findIn() 和公开的 setFocus()。 |
841 | 860 | // 改用 Private API:遍历 seat 的 extension 列表, |
|
0 commit comments