Skip to content

fix: Refactor X11 screenshot handling for Qt6 compatibility#778

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:develop/snipefrom
dengzhongyuan365-dev:20251211Tag
Dec 11, 2025
Merged

fix: Refactor X11 screenshot handling for Qt6 compatibility#778
deepin-bot[bot] merged 1 commit into
linuxdeepin:develop/snipefrom
dengzhongyuan365-dev:20251211Tag

Conversation

@dengzhongyuan365-dev

Copy link
Copy Markdown
Member
  • Introduced a new function to initialize Qt6 XCB environment checks, enhancing the detection of X11 environments.
  • Updated the ScreenGrabber class to utilize the new environment check for enabling XGetImage workaround.
  • Removed deprecated preprocessor directives and streamlined high DPI scaling logic based on the environment.
  • Improved logging for clarity during screenshot operations in X11 environments.

This update ensures better compatibility and reliability for screenshot functionality in Qt6 on X11.

- Introduced a new function to initialize Qt6 XCB environment checks, enhancing the detection of X11 environments.
- Updated the ScreenGrabber class to utilize the new environment check for enabling XGetImage workaround.
- Removed deprecated preprocessor directives and streamlined high DPI scaling logic based on the environment.
- Improved logging for clarity during screenshot operations in X11 environments.

This update ensures better compatibility and reliability for screenshot functionality in Qt6 on X11.
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

我来对这段代码进行审查:

  1. 语法逻辑方面:
  • 代码整体语法正确,逻辑清晰
  • 新增的 initQt6XcbEnv() 函数合理地检测了 Qt6 XCB 环境
  • 条件编译的使用恰当
  1. 代码质量方面:
  • 优点:

    • 移除了编译时的 USE_X11_GETIMAGE 宏,改为运行时检测,更加灵活
    • 将平台检测逻辑集中到 initQt6XcbEnv() 函数中,提高了代码可维护性
    • 日志信息清晰,便于调试
  • 建议改进:

    • initQt6XcbEnv() 函数可以添加更多错误处理,比如检查平台名称是否为空
    • 建议在 Utils::isQt6XcbEnv 变量声明处添加注释说明其用途
  1. 代码性能方面:
  • 性能影响较小,主要改动是运行时检测替代编译时宏定义
  • 建议在 initQt6XcbEnv() 中缓存检测结果,避免重复检测
  1. 代码安全方面:
  • 使用 qEnvironmentVariable() 安全地读取环境变量
  • 字符串比较使用了 toLower() 进行大小写不敏感比较,提高了健壮性

具体改进建议:

  1. initQt6XcbEnv() 中添加空值检查:
static bool initQt6XcbEnv()
{
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
    bool result = false;
    if (QGuiApplication::instance()) {
        const QString platformName = QGuiApplication::platformName();
        if (!platformName.isEmpty()) {
            result = platformName.toLower() == QLatin1String("xcb");
        }
    } else {
        const QString platformEnv = qEnvironmentVariable("QT_QPA_PLATFORM");
        if (!platformEnv.isEmpty()) {
            result = platformEnv.toLower().contains(QLatin1String("xcb"));
        }
    }
    return result;
#endif
    return false;
}
  1. utils.h 中添加变量注释:
// Indicates if the application is running in Qt6 with XCB platform
static bool isQt6XcbEnv;
  1. 考虑添加一个静态变量缓存检测结果:
static bool initQt6XcbEnv()
{
    static bool cached = false;
    static bool result = false;
    
    if (!cached) {
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
        // ... detection logic ...
#endif
        cached = true;
    }
    return result;
}

这些改动可以进一步提高代码的健壮性和可维护性。总体来说,这是一个很好的重构,使代码更加灵活和可维护。

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: dengzhongyuan365-dev, lzwind

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

@dengzhongyuan365-dev

Copy link
Copy Markdown
Member Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Dec 11, 2025

Copy link
Copy Markdown
Contributor

This pr force merged! (status: unstable)

@deepin-bot deepin-bot Bot merged commit 80c7d5f into linuxdeepin:develop/snipe Dec 11, 2025
7 of 9 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