fix: Implement X11 screenshot workaround for Qt6#773
Merged
deepin-bot[bot] merged 1 commit intoDec 11, 2025
Merged
Conversation
- Added a workaround using XGetImage for capturing screenshots in X11 environments with Qt6 to address issues with QScreen::grabWindow under high DPI settings. - Updated ScreenGrabber class to include conditional compilation for X11 support and integrated the new screenshot method. - Modified main application logic to disable high DPI scaling when using the X11 workaround, ensuring consistent behavior across different display setups. This update improves screenshot reliability in multi-screen and high DPI scenarios on X11. bug: https://pms.uniontech.com/bug-view-342909.html
deepin pr auto review我来对这个代码变更进行详细审查:
可以改进的地方:
具体改进建议:
// 验证图像格式
if (ximg->bits_per_pixel != 32 && ximg->bits_per_pixel != 24) {
qCWarning(dsrApp) << "[XGetImage] Unsupported image format:" << ximg->bits_per_pixel;
XDestroyImage(ximg);
XCloseDisplay(dpy);
ok = false;
return QPixmap();
}
// 使用内存拷贝代替逐像素操作
if (ximg->bits_per_pixel == 32 && ximg->byte_order == LSBFirst) {
memcpy(qimg.bits(), ximg->data, ximg->height * ximg->bytes_per_line);
} else {
// 回退到逐像素转换
for (int row = 0; row < ximg->height; ++row) {
for (int col = 0; col < ximg->width; ++col) {
// ... 原有转换逻辑
}
}
}
Display *dpy = XOpenDisplay(NULL);
if (!dpy) {
qCWarning(dsrApp) << "[XGetImage] Failed to open X11 Display";
ok = false;
return QPixmap();
}
// 验证 display 的能力
int major, minor;
if (!XShmQueryVersion(dpy, &major, &minor, NULL)) {
qCWarning(dsrApp) << "[XGetImage] X11 display does not support required features";
XCloseDisplay(dpy);
ok = false;
return QPixmap();
}
// 如果请求的区域远小于整个屏幕,直接抓取指定区域
if (rect.width() * rect.height() < rootAttr.width * rootAttr.height / 4) {
ximg = XGetImage(dpy, root, rect.x(), rect.y(), rect.width(), rect.height(), AllPlanes, ZPixmap);
// 直接返回,无需裁剪
} else {
// 抓取整个屏幕然后裁剪
ximg = XGetImage(dpy, root, 0, 0, rootAttr.width, rootAttr.height, AllPlanes, ZPixmap);
}
总体来说,这是一个合理的解决方案,但可以在性能和安全性方面做一些改进。建议在实施这些改进时,先在测试环境中验证效果。 |
lzwind
approved these changes
Dec 11, 2025
|
[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. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Member
Author
|
/forcemerge |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This update improves screenshot reliability in multi-screen and high DPI scenarios on X11.
bug: https://pms.uniontech.com/bug-view-342909.html