Skip to content

Commit 18838a7

Browse files
committed
fix: simulate right-click on tray item long press
1. Add sendRightClickForSurface method to synthesize right-click events via Wayland seat for tray surfaces 2. Expose shellSurface property in PluginSurface for QML access 3. Handle long press in ShellSurfaceItemProxy TapHandler to trigger right-click on tray items 4. Handle long press in PanelTrayItem MouseArea and prevent normal click from firing after long press Log: Simulate right-click mouse events on tray items when long-pressed via touch input fix: 托盘项长按模拟右键点击 1. 新增 sendRightClickForSurface 方法,通过 Wayland seat 向托盘 表面发送右键点击事件 2. 在 PluginSurface 中暴露 shellSurface 属性供 QML 访问 3. 在 ShellSurfaceItemProxy 的 TapHandler 中处理长按,触发 托盘项右键点击 4. 在 PanelTrayItem 的 MouseArea 中处理长按并防止长按结束后 误触发普通点击 Log: 在触控长按托盘项时模拟右键点击鼠标事件 PMS: BUG-364527
1 parent 889ea78 commit 18838a7

5 files changed

Lines changed: 41 additions & 1 deletion

File tree

panels/dock/DockCompositor.qml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ Item {
2323
function notifyXEmbedWindowMoveResult(wid, success) {
2424
pluginManager.notifyXEmbedWindowMoveResult(wid, success)
2525
}
26+
function sendRightClickForSurface(surface) {
27+
pluginManager.sendRightClickForSurface(surface)
28+
}
2629

2730
property ListModel trayPluginSurfaces: ListModel {}
2831
property ListModel quickPluginSurfaces: ListModel {}

panels/dock/pluginmanagerextension.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,3 +1008,20 @@ void PluginManager::onTextInputSurfaceEnabled(QWaylandSurface *surface)
10081008
}
10091009
}
10101010
}
1011+
1012+
void PluginManager::sendRightClickForSurface(QWaylandSurface *surface)
1013+
{
1014+
if (!surface)
1015+
return;
1016+
1017+
QWaylandCompositor *compositor = qobject_cast<QWaylandCompositor *>(extensionContainer());
1018+
if (!compositor)
1019+
return;
1020+
1021+
QWaylandSeat *seat = compositor->defaultSeat();
1022+
if (!seat)
1023+
return;
1024+
1025+
seat->sendMousePressEvent(Qt::RightButton);
1026+
seat->sendMouseReleaseEvent(Qt::RightButton);
1027+
}

panels/dock/pluginmanagerextension_p.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ class PluginManager : public QWaylandCompositorExtensionTemplate<PluginManager>,
7373
// result: true = success, false = error
7474
Q_INVOKABLE void notifyXEmbedWindowMoveResult(uint32_t wid, bool result);
7575

76+
// Called from QML to synthesize a right-click (mouse press + release)
77+
// on the given Wayland surface, e.g. on long press from touch input
78+
Q_INVOKABLE void sendRightClickForSurface(QWaylandSurface *surface);
79+
7680
uint32_t dockPosition() const;
7781
void setDockPosition(uint32_t dockPosition);
7882

@@ -152,6 +156,7 @@ class PluginSurface : public QWaylandShellSurfaceTemplate<PluginSurface>, public
152156
Q_PROPERTY(uint32_t pluginFlags READ pluginFlags CONSTANT)
153157
Q_PROPERTY(uint32_t pluginType READ pluginType CONSTANT)
154158
Q_PROPERTY(uint32_t pluginSizePolicy READ pluginSizePolicy CONSTANT)
159+
Q_PROPERTY(QWaylandSurface *surface READ surface CONSTANT)
155160
Q_PROPERTY(QString displayName READ displayName CONSTANT)
156161
Q_PROPERTY(int height READ height NOTIFY heightChanged)
157162
Q_PROPERTY(int width READ width NOTIFY widthChanged)

panels/dock/tray/ShellSurfaceItemProxy.qml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ Item {
5252
}
5353
TapHandler {
5454
id: tapHandler
55+
onLongPressed: {
56+
DockCompositor.sendRightClickForSurface(root.shellSurface.surface)
57+
}
5558
}
5659

5760
onVisibleChanged: function () {

panels/dock/tray/quickpanel/PanelTrayItem.qml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,18 @@ Control {
116116
MouseArea {
117117
id: mouseHandler
118118
anchors.fill: parent
119-
onClicked: root.clicked()
119+
onPressed: longPressTriggered = false
120+
onPressAndHold: {
121+
longPressTriggered = true
122+
DockCompositor.sendRightClickForSurface(root.shellSurface.surface)
123+
}
124+
onClicked: {
125+
if (!longPressTriggered) {
126+
root.clicked()
127+
}
128+
longPressTriggered = false
129+
}
130+
131+
property bool longPressTriggered: false
120132
}
121133
}

0 commit comments

Comments
 (0)