Skip to content

Conversation

@dengzhongyuan365-dev
Copy link

  • Introduced a new method to force the X11 window position to (0,0) in Qt6 XCB environments, ensuring proper window management.
  • Updated screen size calculations to use logical coordinates for virtual desktop dimensions, improving multi-screen support.
  • Adjusted background rectangle handling based on the environment, ensuring correct scaling and positioning in high DPI scenarios.

This update improves the application's behavior in X11 environments, particularly for Qt6, enhancing user experience and reliability during screen capture operations.

bug: https://pms.uniontech.com/bug-view-344149.html

- Introduced a new method to force the X11 window position to (0,0) in Qt6 XCB environments, ensuring proper window management.
- Updated screen size calculations to use logical coordinates for virtual desktop dimensions, improving multi-screen support.
- Adjusted background rectangle handling based on the environment, ensuring correct scaling and positioning in high DPI scenarios.

This update improves the application's behavior in X11 environments, particularly for Qt6, enhancing user experience and reliability during screen capture operations.

bug: https://pms.uniontech.com/bug-view-344149.html
@deepin-ci-robot
Copy link

deepin pr auto review

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

  1. 代码逻辑分析:

主要改动集中在以下几个方面:

  • 移除了Qt6 XCB环境下禁用High DPI缩放的代码
  • 优化了多屏幕尺寸计算逻辑
  • 增加了Qt6 XCB环境下的窗口位置和大小处理
  • 改进了截图功能的坐标转换逻辑
  1. 主要改进建议:

A. 代码结构方面:

// 建议将Qt6 XCB相关的特殊处理封装成独立函数
// 例如:
void handleQt6XcbScaling() {
    if (Utils::isQt6XcbEnv) {
        // Qt6 XCB 特殊处理
    }
}

B. 性能优化:

// 在forceX11WindowPosition()中,可以缓存Display指针
static Display* cachedDisplay = nullptr;
if (!cachedDisplay) {
    cachedDisplay = XOpenDisplay(nullptr);
}

C. 错误处理:

// 在getX11RootWindowSize()中增加更详细的错误处理
if (!dpy) {
    qCCritical(dsrApp) << "[getX11RootWindowSize] Failed to open X11 Display:" << XDisplayName(nullptr);
    return QSize();
}

D. 安全性:

// 在X11相关操作中增加资源清理
class X11DisplayGuard {
    Display* dpy;
public:
    X11DisplayGuard() : dpy(XOpenDisplay(nullptr)) {}
    ~X11DisplayGuard() { if(dpy) XCloseDisplay(dpy); }
    operator Display*() const { return dpy; }
};
  1. 具体问题:

A. 坐标转换逻辑:

// 建议统一坐标转换逻辑,避免多处重复代码
class CoordinateConverter {
public:
    static QRect logicalToPhysical(const QRect& logical, qreal dpr) {
        return QRect(
            logical.x() * dpr,
            logical.y() * dpr,
            logical.width() * dpr,
            logical.height() * dpr
        );
    }
};

B. 多屏幕处理:

// 建议优化屏幕信息计算
void calculateScreenGeometry() {
    QRect virtualDesktop;
    for (auto screen : QGuiApplication::screens()) {
        virtualDesktop = virtualDesktop.united(screen->geometry());
    }
    // 使用virtualDesktop进行后续计算
}
  1. 代码质量改进:

A. 添加更多注释:

/**
 * @brief 强制设置X11窗口位置到(0,0)
 * 
 * 此函数用于在Qt6+XCB环境下确保窗口正确定位,
 * 因为Qt的窗口管理可能在高DPI环境下出现偏差。
 */
void MainWindow::forceX11WindowPosition()

B. 增加调试信息:

qCDebug(dsrApp) << "[GeomTrace] Screen info:"
    << "totalSize=" << m_screenSize
    << "pixelRatio=" << m_pixelRatio
    << "isQt6Xcb=" << Utils::isQt6XcbEnv;
  1. 性能优化建议:

A. 缓存计算结果:

// 缓存屏幕信息,避免重复计算
class ScreenInfoCache {
private:
    static QSize cachedSize;
    static bool isValid;
public:
    static QSize getVirtualDesktopSize() {
        if (!isValid) {
            // 计算并缓存
            cachedSize = calculateSize();
            isValid = true;
        }
        return cachedSize;
    }
};
  1. 安全性改进:

A. 资源管理:

// 使用RAII管理X11资源
class XImageGuard {
    XImage* img;
public:
    XImageGuard(XImage* i) : img(i) {}
    ~XImageGuard() { if(img) XDestroyImage(img); }
    operator XImage*() const { return img; }
};
  1. 测试建议:

A. 添加单元测试:

void TestScreenGrabber::testCoordinateConversion() {
    QRect logical(100, 100, 200, 200);
    qreal dpr = 2.0;
    QRect physical = CoordinateConverter::logicalToPhysical(logical, dpr);
    QCOMPARE(physical, QRect(200, 200, 400, 400));
}

这些改进建议主要关注代码的可维护性、性能和安全性。建议在实施时优先考虑对核心功能的稳定性影响,逐步进行优化。

@deepin-ci-robot
Copy link

[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
Author

/forcemerge

@deepin-bot deepin-bot bot merged commit 813dc29 into linuxdeepin:develop/snipe Dec 18, 2025
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