fix: set default cursor when cursor is null#324
Conversation
|
qquickwindow中,当鼠标移动到底层窗口上时,会unsetCursor, 此时传递一个空的QCursor 给平台光标设置,xcbcursor会给 libxcb 设置 XCB_CURSOR_NONE,此时该窗口会复用其父窗口的光标,而父窗口可能是kwin的装饰器窗口或者root窗口,目前kwin就算设置了光标实时更改,Qt的窗口的默认光标也还是一个错误的光标。还没有找到具体原因,此笔提交将设置给平台光标的null手动设置为Qt的默认光标,防止给libxcb设置XCB_CURSOR_NONE,从而fallback到父窗口光标,达到修复的目的。 若之后找到根因,可回退该提交 |
When the cursor parameter is null in overrideChangeCursor, the original function call would pass null to QPlatformCursor::changeCursor. This could cause the platform cursor to fall back to the parent window's cursor, which might be incorrect or unintended. By creating a default Qt::ArrowCursor and using it when cursor is null, we ensure a consistent cursor appearance and prevent unexpected cursor behavior. Log: Fixed cursor display issue when setting null cursor fix: 当光标为null时设置默认光标 当overrideChangeCursor函数中的cursor参数为null时,原始函数调用会将 null传递给QPlatformCursor::changeCursor。这可能导致平台光标回退到父 窗口的光标,而父窗口的光标可能是错误或不正确的。通过创建一个默认的 Qt::ArrowCursor并在cursor为null时使用它,我们确保了光标外观的一致性,并 防止了意外的光标行为。 Log: 修复设置null光标时的显示问题 PMS: BUG-345829 PMS: BUG-344197
deepin pr auto review这段代码修改的目的是在 以下是对这段代码的详细审查意见: 1. 语法与逻辑
2. 代码质量
3. 代码性能
4. 代码安全
改进建议方案一:确保指针有效性(推荐,假设底层不持有指针)如果确定底层函数只是同步读取,当前的代码是可以的,但为了更安全和明确,可以使用 // 使用 static 变量确保 defaultCursor 的生命周期贯穿整个程序运行期
// 这样即使底层函数异步访问该指针也是安全的
static QCursor defaultCursor;
// 如果 cursor 为空,则使用 defaultCursor 的地址,否则使用传入的 cursor
QCursor *effectiveCursor = cursor ? cursor : &defaultCursor;
VtableHook::callOriginalFun(cursorHandle, &QPlatformCursor::changeCursor, effectiveCursor, widget);优点:
方案二:明确指定默认光标类型如果不想依赖 static QCursor defaultCursor(Qt::ArrowCursor);
QCursor *effectiveCursor = cursor ? cursor : &defaultCursor;
VtableHook::callOriginalFun(cursorHandle, &QPlatformCursor::changeCursor, effectiveCursor, widget);总结原代码的修复方向是正确的(防止空指针),但存在因局部变量生命周期导致的潜在悬空指针风险。强烈建议采用方案一,利用 |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 18202781743, mhduiy The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
When the cursor parameter is null in overrideChangeCursor, the original function call would pass null to QPlatformCursor::changeCursor. This could cause the platform cursor to fall back to the parent window's cursor, which might be incorrect or unintended. By creating a default Qt::ArrowCursor and using it when cursor is null, we ensure a consistent cursor appearance and prevent unexpected cursor behavior.
Log: Fixed cursor display issue when setting null cursor
fix: 当光标为null时设置默认光标
当overrideChangeCursor函数中的cursor参数为null时,原始函数调用会将
null传递给QPlatformCursor::changeCursor。这可能导致平台光标回退到父 窗口的光标,而父窗口的光标可能是错误或不正确的。通过创建一个默认的
Qt::ArrowCursor并在cursor为null时使用它,我们确保了光标外观的一致性,并
防止了意外的光标行为。
Log: 修复设置null光标时的显示问题
PMS: BUG-345829
PMS: BUG-344197