Skip to content

Conversation

@robertkill
Copy link
Contributor

The issue was that tray plugin items could be dragged regardless of their plugin flags. The fix introduces a new readonly property canDragByFlags that checks if the shellSurface's pluginFlags contain the Attribute_CanDrag flag (0x200). The main canDrag property now defaults to this flag-based value instead of always being true. Additionally, when mouse release events (type 3) occur, the canDrag property is restored to the flag-based value rather than being hardcoded to true, ensuring consistent drag behavior based on plugin configuration.

Log: Fixed tray plugin drag behavior to respect plugin flags

Influence:

  1. Test dragging tray plugins that should be draggable (with Attribute_CanDrag flag)
  2. Test dragging tray plugins that should not be draggable (without Attribute_CanDrag flag)
  3. Verify mouse press and release events don't incorrectly modify drag state
  4. Test interaction with plugins that dynamically change their pluginFlags
  5. Verify visual feedback matches drag capability

fix: 修复托盘插件拖动行为基于插件标志

问题在于托盘插件项目无论其插件标志如何都可以被拖动。修复引入了一个新
的只读属性canDragByFlags,用于检查shellSurface的pluginFlags是否包含 Attribute_CanDrag标志(0x200)。主属性canDrag现在默认基于此标志值而不是 始终为true。此外,当鼠标释放事件(type 3)发生时,canDrag属性会恢复到基于
标志的值而不是硬编码为true,确保基于插件配置的拖动行为一致性。

Log: 修复托盘插件拖动行为以尊重插件标志

Influence:

  1. 测试应该可拖动的托盘插件(具有Attribute_CanDrag标志)
  2. 测试不应该可拖动的托盘插件(没有Attribute_CanDrag标志)
  3. 验证鼠标按下和释放事件不会错误地修改拖动状态
  4. 测试与动态更改pluginFlags的插件的交互
  5. 验证视觉反馈与拖动能力匹配

PMS: BUG-347287

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

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

Please try again later or upgrade to continue using Sourcery

The issue was that tray plugin items could be dragged regardless
of their plugin flags. The fix introduces a new readonly property
`canDragByFlags` that checks if the shellSurface's pluginFlags contain
the Attribute_CanDrag flag (0x200). The main `canDrag` property
now defaults to this flag-based value instead of always being true.
Additionally, when mouse release events (type 3) occur, the canDrag
property is restored to the flag-based value rather than being
hardcoded to true, ensuring consistent drag behavior based on plugin
configuration.

Log: Fixed tray plugin drag behavior to respect plugin flags

Influence:
1. Test dragging tray plugins that should be draggable (with
Attribute_CanDrag flag)
2. Test dragging tray plugins that should not be draggable (without
Attribute_CanDrag flag)
3. Verify mouse press and release events don't incorrectly modify drag
state
4. Test interaction with plugins that dynamically change their
pluginFlags
5. Verify visual feedback matches drag capability

fix: 修复托盘插件拖动行为基于插件标志

问题在于托盘插件项目无论其插件标志如何都可以被拖动。修复引入了一个新
的只读属性`canDragByFlags`,用于检查shellSurface的pluginFlags是否包含
Attribute_CanDrag标志(0x200)。主属性`canDrag`现在默认基于此标志值而不是
始终为true。此外,当鼠标释放事件(type 3)发生时,canDrag属性会恢复到基于
标志的值而不是硬编码为true,确保基于插件配置的拖动行为一致性。

Log: 修复托盘插件拖动行为以尊重插件标志

Influence:
1. 测试应该可拖动的托盘插件(具有Attribute_CanDrag标志)
2. 测试不应该可拖动的托盘插件(没有Attribute_CanDrag标志)
3. 验证鼠标按下和释放事件不会错误地修改拖动状态
4. 测试与动态更改pluginFlags的插件的交互
5. 验证视觉反馈与拖动能力匹配

PMS: BUG-347287
@deepin-ci-robot
Copy link

deepin pr auto review

这段代码主要修改了 PluginItem.qml 中关于拖拽功能的逻辑,将原有的简单布尔判断改为基于插件标志位(pluginFlags)的判断。以下是对这段代码的审查意见:

1. 语法逻辑

  • 逻辑正确性:代码逻辑基本正确,通过位运算 (shellSurface.pluginFlags & 0x200) !== 0 判断是否包含 Attribute_CanDrag 标志位。
  • 默认值处理:当 shellSurfacenull 时,canDragByFlags 默认为 true,这是一个合理的默认行为,确保向后兼容。
  • 状态恢复:在 type === 3(鼠标释放)时恢复到基于 canDragByFlags 的判断,这是正确的状态恢复逻辑。

2. 代码质量

  • 可读性:代码注释清晰,解释了 Attribute_CanDrag 的含义和位运算逻辑,但建议将 0x200 定义为常量以提高可读性。
  • 命名规范canDragByFlags 命名清晰,表明这是基于标志位的判断结果。

3. 代码性能

  • 性能影响:位运算和属性绑定对性能影响极小,无需优化。

4. 代码安全

  • 空指针检查shellSurface ? ... : true 的空指针检查是安全的,避免了潜在的运行时错误。
  • 标志位验证:建议验证 shellSurface.pluginFlags 的类型是否为整数,避免非数值类型导致的意外行为。

改进建议

  1. 使用常量代替魔数
    readonly property int Attribute_CanDrag: 0x200
    readonly property bool canDragByFlags: shellSurface ? (shellSurface.pluginFlags & Attribute_CanDrag) !== 0 : true
  2. 类型检查(如果 shellSurface.pluginFlags 可能不是整数):
    readonly property bool canDragByFlags: {
        if (!shellSurface) return true;
        const flags = shellSurface.pluginFlags;
        return typeof flags === "number" && (flags & Attribute_CanDrag) !== 0;
    }
  3. 简化 canDrag 的赋值
    • 如果 canDrag 不需要外部修改,可以直接绑定到 canDragByFlags
      property bool canDrag: canDragByFlags
    • 如果需要动态修改(如 type === 2 时禁用拖拽),当前实现是合理的。

优化后的代码示例

Control {
    property string itemKey
    property alias shellSurface: surfaceLayer.shellSurface
    property alias traySurface: dragLayer.fallbackDragImage
    readonly property int Attribute_CanDrag: 0x200
    readonly property bool canDragByFlags: {
        if (!shellSurface) return true;
        const flags = shellSurface.pluginFlags;
        return typeof flags === "number" && (flags & Attribute_CanDrag) !== 0;
    }
    property bool canDrag: canDragByFlags
    property int radius: 8
    property bool isActive

    function updateSurface() {
        // ...
    }

    // ...
    onTypeChanged: {
        if (type === 2) {
            canDrag = false
        } else if (type === 3) {
            canDrag = canDragByFlags
        }
    }
}

总结

这段代码的修改是合理的,改进了拖拽功能的灵活性。通过使用常量、类型检查和简化属性绑定,可以进一步提高代码的可读性和健壮性。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

@robertkill robertkill merged commit abf68ba into linuxdeepin:master Jan 31, 2026
9 of 11 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