Skip to content

Commit ff8f1fc

Browse files
committed
fix(dock): fix pasting text in Wayland plugin windows
To fix pasting text in Wayland plugin windows, this commit ensures that nested Wayland clients can correctly receive host clipboard contents. Wayland compositor (dde-shell) does not automatically synchronize the host system's clipboard to its nested clients. This caused plugin popup windows to be unable to paste text that was copied from outside applications. This fix enables retained selection in QWaylandCompositor and explicitly listens to QClipboard::changed from the host environment to forward the QMimeData to the compositor via overrideSelection(). Log: fix pasting text in Wayland plugin windows Pms: BUG-329435
1 parent b63e013 commit ff8f1fc

2 files changed

Lines changed: 29 additions & 10 deletions

File tree

panels/dock/pluginmanagerextension.cpp

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2023 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: GPL-3.0-or-later
44

@@ -26,6 +26,11 @@
2626
#include <QtWaylandCompositor/QWaylandQtTextInputMethod>
2727
#include <QtWaylandCompositor/QWaylandQuickItem>
2828

29+
#include <QGuiApplication>
30+
#include <QInputMethod>
31+
#include <QClipboard>
32+
#include <QMimeData>
33+
2934
#include <QJsonObject>
3035
#include <QJsonParseError>
3136

@@ -39,9 +44,6 @@
3944
#include <private/qwlqttouch_p.h>
4045
#endif
4146

42-
#include <QtGui/qguiapplication.h>
43-
#include <QtGui/qinputmethod.h>
44-
4547
DGUI_USE_NAMESPACE
4648

4749
struct WlQtTextInputMethodHelper : public QtWaylandServer::qt_text_input_method_v1 {
@@ -75,11 +77,9 @@ struct WlQtTextInputMethodHelper : public QtWaylandServer::qt_text_input_method_
7577
d->cursorRectangle = QRect();
7678
d->preferredLanguage.clear();
7779
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());
8383

8484
d->focusDestroyListener.listenForDestruction(surface->resource());
8585
if (d->inputPanelVisible && d->enabledSurfaces.values().contains(surface))
@@ -516,6 +516,21 @@ void PluginManager::initialize()
516516

517517
// 设置 text input 焦点代理
518518
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+
}
519534
}
520535

521536
void PluginManager::updateDockOverflowState(int state)
@@ -836,6 +851,10 @@ void PluginManager::setupTextInputProxy(QWaylandCompositor *compositor)
836851
(QWaylandSurface *newFocus, QWaylandSurface *oldFocus) {
837852
Q_UNUSED(oldFocus);
838853

854+
if (newFocus) {
855+
newFocus->updateSelection();
856+
}
857+
839858
// 由于 Deepin Qt6 构建中 QWaylandTextInput/V3 的公开类符号没有导出,
840859
// 无法使用 findIn() 和公开的 setFocus()。
841860
// 改用 Private API:遍历 seat 的 extension 列表,

panels/dock/pluginmanagerextension_p.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2023 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: GPL-3.0-or-later
44

0 commit comments

Comments
 (0)