Repository navigation
feat: add automatic screen scaling recommendation #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,9 +3,10 @@ | |
| // SPDX-License-Identifier: LGPL-3.0-or-later | ||
| #include "xcbutils.h" | ||
|
|
||
| #include <X11/X.h> | ||
| #include <X11/Xatom.h> | ||
| #include <X11/Xlib.h> | ||
| #include <xcb/randr.h> | ||
| #include <xcb/xcb.h> | ||
|
|
||
| #include <stdio.h> | ||
|
|
@@ -181,6 +182,72 @@ | |
| return ""; | ||
| } | ||
|
|
||
| QList<XcbUtils::MonitorSizeInfo> XcbUtils::getMonitorSizeInfos() | ||
| { | ||
| // 获取XCB版本信息 | ||
| const xcb_setup_t *setup = xcb_get_setup(connection); | ||
| int majorVersion = setup->protocol_major_version; | ||
| int minorVersion = setup->protocol_minor_version; | ||
| qInfo() << QString("randr version %1.%2").arg(majorVersion).arg(minorVersion); | ||
| if (majorVersion < 1 || (majorVersion == 1 && minorVersion < 2)) { | ||
| return {}; | ||
| } | ||
| xcb_screen_iterator_t screen_iter = xcb_setup_roots_iterator(setup); | ||
| xcb_window_t root = screen_iter.data->root; | ||
| xcb_randr_get_screen_resources_cookie_t cookie = xcb_randr_get_screen_resources(connection, root); | ||
| xcb_generic_error_t *error = nullptr; | ||
| xcb_randr_get_screen_resources_reply_t *resources = xcb_randr_get_screen_resources_reply(connection, cookie, &error); | ||
|
Comment on lines
+197
to
+199
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (bug_risk): Missing nullptr check for the get_screen_resources reply can lead to dereferencing a null pointer.
|
||
| if (error) { | ||
| qWarning() << "Error getting screen resources: " << error->error_code; | ||
| free(error); | ||
| return {}; | ||
| } | ||
|
|
||
| xcb_randr_output_t *outputs = xcb_randr_get_screen_resources_outputs(resources); | ||
| int output_count = xcb_randr_get_screen_resources_outputs_length(resources); | ||
| QList<MonitorSizeInfo> monitors; | ||
| for (int i = 0; i < output_count; i++) { | ||
| xcb_randr_output_t output = outputs[i]; | ||
| xcb_randr_get_output_info_cookie_t info_cookie = xcb_randr_get_output_info(connection, output, resources->config_timestamp); | ||
|
|
||
| xcb_randr_get_output_info_reply_t *output_info = xcb_randr_get_output_info_reply(connection, info_cookie, nullptr); | ||
|
|
||
| if (!output_info) | ||
| continue; | ||
|
|
||
| // 检查输出是否连接 | ||
| if (output_info->connection != XCB_RANDR_CONNECTION_CONNECTED) { | ||
| free(output_info); | ||
| continue; | ||
| } | ||
|
|
||
| if (output_info->crtc == XCB_NONE) { | ||
| free(output_info); | ||
| continue; | ||
| } | ||
| xcb_randr_get_crtc_info_cookie_t crtc_cookie = xcb_randr_get_crtc_info(connection, output_info->crtc, resources->config_timestamp); | ||
|
|
||
| xcb_randr_get_crtc_info_reply_t *crtc_info = xcb_randr_get_crtc_info_reply(connection, crtc_cookie, nullptr); | ||
|
|
||
| if (crtc_info) { | ||
| MonitorSizeInfo monitor; | ||
| monitor.width = crtc_info->width; | ||
| monitor.height = crtc_info->height; | ||
| monitor.mmWidth = output_info->mm_width; | ||
| monitor.mmHeight = output_info->mm_height; | ||
|
|
||
| monitors.push_back(monitor); | ||
|
|
||
| free(crtc_info); | ||
| } | ||
|
|
||
| free(output_info); | ||
| } | ||
|
|
||
| free(resources); | ||
| return monitors; | ||
| } | ||
|
|
||
| // 获取 _XSETTINGS_SETTINGS 属性 | ||
| QByteArray XcbUtils::getXcbAtomProperty(xcb_atom_t atom) | ||
| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (bug_risk): The recommendedScaleFactor parameter is effectively unused and the fallback path applies an invalid (<= 0) scale factor.
In
adjustScaleFactor,recommendedScaleFactoris only logged, while forvalue <= 0you still insert that invalidvalueinto the map and pass it tosetScreenScaleFactors(map, false). As a result, when no valid user setting exists, an invalid (<= 0) scale factor is propagated instead of the computed recommendation. Please userecommendedScaleFactorin this branch (or default the DConfig value to it) so the scale factor remains valid and the parameter is meaningful.