Skip to content

fix: fall back to Qt default drag for wayland quick panel#1625

Merged
18202781743 merged 1 commit into
linuxdeepin:masterfrom
18202781743:drag
Jun 9, 2026
Merged

fix: fall back to Qt default drag for wayland quick panel#1625
18202781743 merged 1 commit into
linuxdeepin:masterfrom
18202781743:drag

Conversation

@18202781743

Copy link
Copy Markdown
Contributor

In Wayland environment, the custom DQuickDrag overlay window causes
issues with the quick panel drag functionality. This change forces
DQuickDrag to be inactive on non-X11 platforms, falling back to Qt's
native drag which uses the automatic image source. Additionally, the
Drag properties (imageSource and hotSpot) are only set when not on XCB,
as Qt's automatic drag handles these correctly on Wayland.

Log: Disable custom drag overlay on Wayland for quick panel items

Influence:

  1. Test quick panel item drag on X11 session to ensure custom overlay
    still works
  2. Test quick panel item drag on Wayland session to verify Qt default
    drag works
  3. Check that the drag image and hotspot are positioned correctly on
    both platforms
  4. Verify no visual glitches or crashes during drag operations

fix: wayland下快捷面板拖拽回退到qt默认拖拽

在wayland环境下,自定义DQuickDrag覆盖窗口会导致快捷面板拖拽功能出现问
题。此修改强制在非X11平台上禁用DQuickDrag,回退到使用自动图片源的Qt原生
拖拽。同时,Drag属性(imageSource和hotSpot)仅在不使用XCB时设置,因为Qt
的自动拖拽在wayland上能正确处理这些属性。

Log: 在wayland上禁用快捷面板项目的自定义拖拽覆盖

Influence:

  1. 在X11会话中测试快捷面板项目拖拽,确保自定义覆盖仍正常工作
  2. 在wayland会话中测试快捷面板项目拖拽,验证Qt默认拖拽功能正常
  3. 检查两个平台下拖拽图片和热点位置是否正确
  4. 验证拖拽操作过程中无视觉异常或崩溃

PMS: BUG-346735

In Wayland environment, the custom DQuickDrag overlay window causes
issues with the quick panel drag functionality. This change forces
DQuickDrag to be inactive on non-X11 platforms, falling back to Qt's
native drag which uses the automatic image source. Additionally, the
Drag properties (imageSource and hotSpot) are only set when not on XCB,
as Qt's automatic drag handles these correctly on Wayland.

Log: Disable custom drag overlay on Wayland for quick panel items

Influence:
1. Test quick panel item drag on X11 session to ensure custom overlay
still works
2. Test quick panel item drag on Wayland session to verify Qt default
drag works
3. Check that the drag image and hotspot are positioned correctly on
both platforms
4. Verify no visual glitches or crashes during drag operations

fix: wayland下快捷面板拖拽回退到qt默认拖拽

在wayland环境下,自定义DQuickDrag覆盖窗口会导致快捷面板拖拽功能出现问
题。此修改强制在非X11平台上禁用DQuickDrag,回退到使用自动图片源的Qt原生
拖拽。同时,Drag属性(imageSource和hotSpot)仅在不使用XCB时设置,因为Qt
的自动拖拽在wayland上能正确处理这些属性。

Log: 在wayland上禁用快捷面板项目的自定义拖拽覆盖

Influence:
1. 在X11会话中测试快捷面板项目拖拽,确保自定义覆盖仍正常工作
2. 在wayland会话中测试快捷面板项目拖拽,验证Qt默认拖拽功能正常
3. 检查两个平台下拖拽图片和热点位置是否正确
4. 验证拖拽操作过程中无视觉异常或崩溃

PMS: BUG-346735

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @18202781743, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

我来对这段代码进行审查,并提出改进意见:

语法逻辑

  1. 代码使用了条件判断来区分平台(Qt.platform.pluginName !== "xcb"),这是一个好的做法,因为它确保了特定平台的兼容性。
  2. 使用了Qt.binding()来创建绑定关系,这是QML中处理动态更新的正确方式。
  3. Drag.active的判断增加了平台检查,这是一个合理的改进。

代码质量

  1. 代码结构清晰,逻辑分块明确。
  2. 命名规范合理,变量和属性名具有描述性。
  3. 使用了平台相关的条件判断,提高了代码的可移植性。

代码性能

  1. 使用Qt.binding()可能会带来一定的性能开销,因为需要建立绑定关系并持续监控变化。
  2. 对于频繁更新的属性(如draggingImage),可以考虑使用更高效的更新机制。
  3. 建议将平台判断的结果缓存起来,而不是每次都进行判断。

代码安全

  1. 没有看到明显的安全问题。
  2. 对于平台相关的代码,建议添加更多的错误处理和兼容性检查。

改进建议

  1. 性能优化
// 缓存平台判断结果
property bool isXcbPlatform: Qt.platform.pluginName === "xcb"

// 使用缓存的平台判断
if (!isXcbPlatform) {
    dragItem.Drag.imageSource = Qt.binding(function () {
        return root.draggingImage
    })
    dragItem.Drag.hotSpot.x = Qt.binding(function () {
        return dragItem.width / 2
    })
    dragItem.Drag.hotSpot.y = Qt.binding(function () {
        return dragItem.height / 2
    })
}

// 使用缓存的平台判断
dragItem.DQuickDrag.active = Qt.binding(function () {
    return dragItem.Drag.active && isXcbPlatform
})
  1. 可读性改进
// 添加注释说明平台相关代码的目的
// XCB平台特定的拖拽行为配置
if (!isXcbPlatform) {
    // 配置拖拽图像和热点位置
    dragItem.Drag.imageSource = Qt.binding(function () {
        return root.draggingImage
    })
    dragItem.Drag.hotSpot.x = Qt.binding(function () {
        return dragItem.width / 2
    })
    dragItem.Drag.hotSpot.y = Qt.binding(function () {
        return dragItem.height / 2
    })
}

// 仅在XCB平台启用拖拽
dragItem.DQuickDrag.active = Qt.binding(function () {
    return dragItem.Drag.active && isXcbPlatform
})
  1. 错误处理
// 添加错误处理
property bool isXcbPlatform: Qt.platform.pluginName === "xcb"

// 安全地访问root.draggingImage
function getDraggingImage() {
    try {
        return root ? root.draggingImage : null
    } catch (e) {
        console.error("Error accessing draggingImage:", e)
        return null
    }
}

if (!isXcbPlatform) {
    dragItem.Drag.imageSource = Qt.binding(function () {
        return getDraggingImage()
    })
    // ... 其他代码
}
  1. 代码组织
// 将平台相关代码封装到单独的函数中
function setupDragForPlatform() {
    if (isXcbPlatform) {
        setupXcbDrag()
    } else {
        setupNonXcbDrag()
    }
}

function setupXcbDrag() {
    dragItem.DQuickDrag.active = Qt.binding(function () {
        return dragItem.Drag.active
    })
}

function setupNonXcbDrag() {
    dragItem.Drag.imageSource = Qt.binding(function () {
        return root.draggingImage
    })
    dragItem.Drag.hotSpot.x = Qt.binding(function () {
        return dragItem.width / 2
    })
    dragItem.Drag.hotSpot.y = Qt.binding(function () {
        return dragItem.height / 2
    })
    dragItem.DQuickDrag.active = Qt.binding(function () {
        return dragItem.Drag.active
    })
}

// 在组件加载时调用
Component.onCompleted: setupDragForPlatform()

这些改进可以提高代码的性能、可读性和可维护性,同时保持原有的功能不变。

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, BLumia

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@18202781743 18202781743 merged commit 6e1bd64 into linuxdeepin:master Jun 9, 2026
10 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants