A DPI Adaptive Method for Qt Applications on Domestic Operating Systems
By establishing a multi-source detection mechanism in the Linux desktop environment to obtain the system scaling factor and coordinate the scaling of rendered interface elements, the problem of inconsistent display in cross-platform applications is solved, and adaptive rendering of the interface is achieved when there are multiple monitors and system configuration changes, thus improving the user experience.
Patent Information
- Application Number
- CN202611506544.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-27
- Publication Date
- 2026-11-17
AI Technical Summary
In a Linux desktop environment, applications struggle to accurately obtain scaling settings, leading to inconsistent display of interface elements. This is especially problematic in multi-monitor scenarios and when system configurations change, as the inability to adjust the size of interface elements in real time affects the display consistency and user experience of cross-platform applications.
The system scaling factor is obtained through a multi-source detection mechanism, a mapping relationship between logical pixels and physical pixels is established, an independent screen scaling factor is maintained for each display screen, and system font scaling change events are listened to. The interface elements are scaled and rendered in a coordinated manner, including reading the system distribution identification file, environment variables and desktop component information, and obtaining the scaling factor using the desktop bus interface, system-level configuration interface and native display protocol interface.
It enables adaptive rendering of the interface in diverse Linux desktop environments and multi-monitor scenarios, ensuring collaborative scaling of different types of resources and improving the visual adaptability and user experience of cross-platform applications.
Smart Images

Figure CN123114401A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of information technology, and in particular to a DPI adaptive method for Qt applications on domestic operating systems. Background Technology
[0002] As the desktop application ecosystem evolves towards cross-platform compatibility, maintaining consistent display across different operating systems has become a core requirement for user experience. This is particularly true in Linux desktop environments, where the variety of distributions, display protocols, and desktop environments presents complex technical challenges for application interface adaptation.
[0003] Current interface adaptation solutions typically rely on a single configuration read path to obtain system scaling parameters, which works well on highly standardized platforms. However, the open nature of the Linux ecosystem leads to significant differences in the storage location and access methods of scaling factors across different distributions. For example, in Ubuntu, scaling parameters may be exposed through the desktop bus interface, while in Fedora, specific configuration files need to be read. Some lightweight desktop environments do not provide a unified configuration interface at all. This heterogeneity makes it difficult for applications to accurately obtain scaling settings through fixed query methods, which can lead to UI elements being displayed too large or too small in certain environments.
[0004] The dynamic adaptation requirements arising from multi-monitor usage scenarios are even more complex. In modern office environments, users often work with multiple monitors, which typically have different resolutions and scaling ratios. For example, a user's laptop screen might be set to 150% scaling for a clear display, while an external 4K monitor might be set to 200% scaling to accommodate the high resolution. When an application window is dragged from the laptop screen to the external monitor, the text, icons, buttons, and other interface elements within the window need to be resized according to the new screen's scaling parameters. However, due to the lack of a real-time tracking mechanism for the scaling state of each screen, the application cannot perceive the change in the screen on which the window is located, and therefore cannot trigger the corresponding size adjustment. This results in interface elements appearing too small on a high-resolution screen or too large on a low-resolution screen.
[0005] Furthermore, users may adjust font size or overall scaling during system operation, and these configuration changes require real-time responses from the application. However, the lack of an effective communication mechanism between the application process and the system configuration service prevents timely notification of configuration change events. Simultaneously, different resource types in the interface, such as text, vector icons, and bitmaps, need to be scaled according to their respective characteristics. Without a unified coordination mechanism, inconsistencies may arise where text is enlarged while icons remain at their original size. Therefore, accurately obtaining scaling parameters for each screen in diverse Linux desktop environments and adjusting the size of interface elements in real-time during window cross-screen movement and system configuration changes to ensure coordinated scaling of different resource types has become a key issue for cross-platform application interface adaptation. Summary of the Invention
[0006] This invention provides a DPI adaptive method for Qt applications on domestic operating systems, mainly including: The system obtains the currently running operating system type, display protocol, and desktop environment information; based on the operating system type, display protocol, and desktop environment information, it obtains the system scaling factor through a multi-source detection mechanism, wherein the multi-source detection mechanism queries multiple detection sources according to a preset priority order; it establishes a mapping relationship from logical pixels to physical pixels based on the system scaling factor and maintains an independent screen scaling factor for each display screen; it listens for system font scaling change events and performs collaborative scaling rendering of fonts, icons, and layouts in the application interface based on the system scaling factor and the screen scaling factor. Further, obtaining the currently running operating system type, display protocol, and desktop environment information includes: reading a system distribution identifier file and determining the operating system type based on field information in the system distribution identifier file; reading system environment variables and determining the display protocol based on display server configuration parameters in the system environment variables; and reading the current user's session process information and determining the desktop environment information based on desktop component identifiers in the session process information. Furthermore, the step of reading the system distribution identifier file and determining the operating system type based on the field information in the system distribution identifier file includes: obtaining a preset system distribution identifier file path; opening the corresponding text file according to the system distribution identifier file path; reading the key-value pair data in the text file line by line and extracting the numeric string corresponding to a specific key name; and matching the numeric string according to a preset operating system type mapping table to obtain the successfully matched operating system type. Furthermore, the step of obtaining the system scaling factor through a multi-source detection mechanism based on the operating system type, the display protocol, and the desktop environment information includes: determining the corresponding desktop bus interface based on the desktop environment information; reading first configuration data through the desktop bus interface; determining whether a compliant first scaling factor exists in the first configuration data; if the first scaling factor exists, determining the first scaling factor as the system scaling factor; if the first configuration data does not contain a compliant first scaling factor, determining the corresponding system-level configuration interface based on the operating system type; reading second configuration data through the system-level configuration interface; determining whether a compliant second scaling factor exists in the second configuration data; if the second scaling factor exists, determining the second scaling factor as the system scaling factor; if the second configuration data does not contain a compliant second scaling factor, determining the corresponding native display protocol interface based on the display protocol; reading third configuration data through the native display protocol interface; determining whether a compliant third scaling factor exists in the third configuration data; if the third scaling factor exists, determining the third scaling factor as the system scaling factor; if the third configuration data does not contain a compliant third scaling factor, obtaining a pre-set baseline scaling factor and determining the baseline scaling factor as the system scaling factor.Furthermore, the step of establishing a mapping relationship from logical pixels to physical pixels based on the system scaling factor, and maintaining an independent screen scaling factor for each display screen, includes: obtaining the physical pixel size of each user interface element in the application interface, calculating the logical pixel size of each user interface element based on the physical pixel size and the system scaling factor, wherein the logical pixel size is independent of the pixel density of the display device; obtaining the identification information of all display screens connected to the current device, obtaining the screen scaling factor corresponding to each display screen, and establishing a mapping table between the identification information and the screen scaling factor; obtaining the initial identification information of the initial display screen where the current application window is located, querying the initial screen scaling factor corresponding to the initial identification information according to the mapping table, and calculating the initial rendering physical pixel size based on the logical pixel size and the initial screen scaling factor; obtaining the current application window movement event, obtaining the target identification information of the target display screen based on the movement event, querying the target screen scaling factor corresponding to the target identification information according to the mapping table, and calculating the target rendering physical pixel size based on the logical pixel size and the target screen scaling factor. Furthermore, the step of listening to system font scaling change events and performing collaborative scaling rendering of the font, icons, and layout in the application interface according to the system scaling factor and the screen scaling factor includes: registering a listener for font configuration change signals set in the system settings through an inter-process communication mechanism; acquiring the font scaling change event captured by the listener; and recalculating the pixel size of the application font according to the system scaling factor in response to the font scaling change event. Furthermore, the step of listening to system font scaling change events and performing collaborative scaling rendering of the font, icons, and layout in the application interface according to the system scaling factor also includes: acquiring vector image resources in the application interface and scaling the vector image resources proportionally according to the system scaling factor to obtain a target vector image resource; acquiring multi-magnification bitmap image resources in the application interface and matching a target bitmap image resource from the multi-magnification bitmap image resources according to the system scaling factor; generating a redraw instruction based on the recalculated pixel size of the application font, the target vector image resource, and the target bitmap image resource; and redrawing the application interface according to the redraw instruction to obtain the target application interface.
[0007] The technical solutions provided by the embodiments of the present invention may include the following beneficial effects: This invention discloses a cross-platform application interface adaptive scaling rendering method. Addressing the difficulties in obtaining scaling factors and multi-screen adaptation issues caused by different distributions, display protocols, and desktop environments within the Linux ecosystem, this method establishes a complete perception chain from operating system identification to display protocol detection to desktop environment determination. It constructs a multi-source detection mechanism encompassing the desktop bus interface, system-level configuration interface, and native display protocol interface, querying scaling factors level by level according to priority to ensure accurate acquisition of system scaling parameters in heterogeneous environments. Based on this, a mapping relationship from logical pixels to physical pixels is established, maintaining an independent scaling factor mapping table for each display screen to achieve dynamic size recalculation when application windows move across screens. Simultaneously, an inter-process communication mechanism listens for font configuration change signals, coordinating system scaling factors and screen scaling factors to perform collaborative scaling processing on text, vector icons, and bitmap resources, ultimately generating a unified redraw instruction to complete interface rendering. This invention solves the display consistency problem of Linux desktop applications in diverse system environments and multi-monitor scenarios, improving the visual adaptation capability and user experience of cross-platform applications. Attached Figure Description
[0008] Figure 1 This is a flowchart of a DPI adaptive method for Qt applications on a domestic operating system according to the present invention. Detailed Implementation
[0009] The technical solutions of the embodiments of the present invention will be clearly and thoroughly described below with reference to the accompanying drawings. The described embodiments are merely some embodiments of the present invention.
[0010] like Figure 1 This embodiment of a DPI adaptive method for Qt applications on a domestic operating system may specifically include: S1. Obtain the currently running operating system type, display protocol, and desktop environment information; S2. Based on the operating system type, the display protocol, and the desktop environment information, obtain the system scaling factor through a multi-source detection mechanism, wherein the multi-source detection mechanism queries multiple detection sources in a preset priority order.
[0011] S3. Establish a mapping relationship between logical pixels and physical pixels based on the system scaling factor, and maintain an independent screen scaling factor for each display screen.
[0012] S4. Listen for system font scaling change events, and perform coordinated scaling rendering of fonts, icons, and layout in the application interface according to the system scaling factor and the screen scaling factor.
[0013] Step S1, which involves obtaining the currently running operating system type, display protocol, and desktop environment information, includes: Step S11: Read the system distribution identification file and determine the operating system type based on the field information in the system distribution identification file.
[0014] Step S111: Obtain the preset system release identifier file path, and open the corresponding text file according to the system release identifier file path.
[0015] During the Qt application startup initialization phase, the absolute path of the pre-defined system distribution identifier file is first read from the configuration management module. This path typically points to the ` / etc / os-release` file in a Linux system. The text file is opened using the standard file input / output interface, and a file read handle is established. Simultaneously, the file access permissions are set to read-only mode to ensure no accidental modification to system configuration files is made. If opening the file fails, an error log is logged, and an alternative identification path is enabled, such as attempting to read distribution information files from alternative locations like ` / etc / lsb-release` or ` / usr / lib / os-release`.
[0016] Step S112: Read the key-value pair data in the text file line by line and extract the numerical string corresponding to the specific key name.
[0017] Step S1121: Split the text file content into independent data lines according to line delimiters, and preprocess each line of data to remove whitespace characters, tabs, and comment symbols at the beginning and end of the line. In the distribution identification files of domestic operating systems, comment lines usually start with a hash symbol, and these invalid data lines need to be filtered out before parsing to avoid interfering with the subsequent key-value pair extraction process.
[0018] Step S1122: Each row of preprocessed data is split using the equals sign separator. The left side of the split result is identified as the key name, and the right side is identified as the corresponding numerical content. For any quotation marks, double quotation marks, or other enclosing symbols that may be present in the numerical content, a string cleaning operation is performed to extract the clean numerical string.
[0019] For example, when parsing a key-value pair like NAME="UOS", the double quotes need to be removed to get the key name NAME and the numeric string UOS.
[0020] Step S1123: Based on a predefined list of key fields, filter out key-value pairs that are meaningful for identifying the operating system type. This list of key fields includes field names such as NAME, ID, ID_LIKE, VERSION_ID, and PRETTY_NAME. These fields carry core system identity information in different domestic operating system distributions. The filtered key names and numeric strings are then used to construct a hash mapping structure for easy subsequent fast querying and matching operations.
[0021] Step S1124: To address the issue of missing or formatted fields in some domestic operating system distributions, a field completion mechanism is established. When the NAME field is detected to be empty but the PRETTTY_NAME field is valid, the value of PRETTTY_NAME is extracted and used as a replacement value for the NAME field. When the ID field is missing, the operating system version code is extracted from the VERSION or VERSION_ID field and compared with known domestic OS version repositories to infer possible ID values, ensuring sufficient identification information is available even when the configuration file is incomplete.
[0022] Step S113: Match the numerical string according to the preset operating system type mapping table to obtain the successfully matched operating system type.
[0023] Step S1131: Load a pre-built operating system type mapping table from local storage or embedded resources. This mapping table is organized with a multi-level index structure. The first-level index is the codename of the main domestic operating system distribution, such as UOS, Kylin, and OpenKylin. The second-level index is the specific version number or version range. The third-level index is the desktop environment type identifier, such as DDE, UKUI, and GNOME. Each entry in the mapping table corresponds to a standardized operating system type enumeration value, which is used for branch selection in the subsequent DPI detection module.
[0024] Step S1132 involves performing an exact match between the ID field numeric string extracted in step S112 and the first-level index of the mapping table. First, the numeric string is converted to lowercase and its prefixes and suffixes are trimmed to remove any possible version number suffixes and special characters; for example, converting uniontechos-desktop to the simplified form of uos. Then, the mapping table is searched for a first-level index entry that is completely identical to the processed string. If a match is found, the operating system type corresponding to that index entry is directly obtained; otherwise, a fuzzy matching process is initiated.
[0025] Step S1133: In the event of a failure to achieve an exact match, a fuzzy matching mechanism based on string similarity calculation is activated. The longest common subsequence algorithm is used to calculate the similarity score between the numerical string and each first-level index keyword in the mapping table. The similarity score is calculated by dividing the length of the common subsequence by the average length of the two strings. A similarity threshold of 0.7 is set. When the similarity score of an index keyword exceeds this threshold, it is considered a candidate match and its similarity score is recorded. Finally, the candidate with the highest similarity score is selected as the fuzzy matching result.
[0026] Step S1134: For the operating system type candidates obtained through fuzzy matching, further version number verification is performed using the VERSION_ID field. The major and minor version numbers are extracted from the VERSION_ID numeric string and compared with the version range defined in the second-level index of the mapping table to confirm whether the current system version is within the version range supported by the operating system type.
[0027] For example, when the system ID is identified as kylin and the VERSION_ID is V10, it is necessary to verify whether V10 belongs to the valid version range of the Kylin operating system. Verification by version number can eliminate interference from operating systems with the same name but different series.
[0028] Step S1135: After completing the initial identification of the operating system type, read the DESKTOP_SESSION or XDG_CURRENT_DESKTOP field from the system environment variables to extract the currently running desktop environment identifier. Match the desktop environment identifier with the third-level index of the mapping table to attach a desktop environment attribute label to the identified operating system type.
[0029] For example, when the operating system type is identified as Tongxin UOS and the desktop environment is identified as deepin, the final output operating system type result is a UOS-DDE combination type. This combination type will guide the subsequent DPI detection module to prioritize using the DDE-specific D-Bus interface to obtain the scaling factor.
[0030] Step S1136 establishes a redundant multi-path matching mechanism. When the ID field fails to match, it attempts to match keywords from the ID_LIKE field and then the NAME field in turn. The ID_LIKE field typically contains information about the upstream distribution on which the current distribution is based. For example, the ID_LIKE field value of some domestic operating systems is Debian or Ubuntu. By parsing this field, the package management system and infrastructure characteristics of the operating system can be inferred. The NAME field may contain the complete commercial name of the operating system. By extracting the core keywords from the name, such as extracting UnionTech from UnionTech OS Desktop, and then matching it with the mapping table, it can serve as a final identification method to ensure successful identification of the operating system type under various configuration file format variations.
[0031] Step S1137: For new domestic operating systems or customized distributions not included in the mapping table, enable dynamic learning mode. Report unmatched ID, NAME, and other field values, along with the complete system distribution identifier file content, to the local log system. Simultaneously, generate a default general Linux operating system type identifier as a temporary return result to prevent application startup from being interrupted due to identification failure. Developers can update the mapping table configuration and redeploy the application based on the unknown system information collected from the logs, achieving gradual adaptation and coverage of new domestic operating systems.
[0032] In one embodiment, the process of reading the text file line by line and extracting key-value pair data in step S112 is adapted to the actual configuration file format of the UnionTech UOS operating system. The / etc / os-release file of UnionTech UOS contains key-value pair lines such as NAME equals UnionTech OS Desktop, ID equals uos, and VERSION_ID equals 20. First, the file content is split into independent data lines according to the newline character. For the line NAME equals UnionTech OS Desktop, it is split by the equals sign to obtain the key name NAME and the quoted value UnionTech OS Desktop. The double quotes are removed using a string processing function to obtain the pure value UnionTech OS Desktop. The same processing is performed on the lines ID equals uos and VERSION_ID equals 20, ultimately constructing a hash mapping structure containing three key-value pairs, where the key name NAME corresponds to the value UnionTech OS Desktop, the key name ID corresponds to the value uos, and the key name VERSION_ID corresponds to the value 20. These extracted numerical strings provide the necessary data foundation for subsequent operating system type matching.
[0033] In one embodiment, during operating system type matching based on the mapping table in step S113, differentiated identification is performed for multiple version branches of the Kylin operating system. The Kylin operating system has two main series: a server version and a desktop version, with ID fields of kylin-server and kylin-desktop, respectively. Corresponding index entries are created in the first-level index of the mapping table. When the ID field value of kylin-desktop is extracted from the system distribution identifier file, lowercase conversion and hyphen preservation are first performed. Then, the kylin-desktop index entry is searched in the mapping table and successfully matched, indicating that the operating system type is Kylin Desktop. Next, the VERSION_ID field value of V10 is read and compared with the version range of Kylin Desktop in the second-level index of the mapping table. It is confirmed that V10 is within the valid range of V10 to V11, completing the version number verification. Finally, the system environment variable XDG_CURRENT_DESKTOP is read as UKUI. After matching it with the third-level index of the mapping table, the UKUI desktop environment label is attached to the operating system type. Finally, the combined recognition result of Galaxy Kylin Desktop Edition-UKUI is output. This result will guide the DPI detection module to prioritize calling the org.ukui.desktop.interface D-Bus interface of the UKUI desktop environment.
[0034] In one embodiment, the field completion mechanism in step S1124 plays a crucial role in addressing the issue of incomplete fields in the configuration files of some customized domestic operating system distributions. For example, a government-specific operating system deeply customized based on Tongxin UOS has an empty string value for the NAME field in its / etc / os-release file, but the PRETTY_NAME field contains complete system name information: "Government Operating System Based on UOS". When the empty NAME field is detected during line-by-line file parsing, the field completion process is triggered. The value "Government Operating System Based on UOS" is extracted from the PRETTY_NAME field and stored as a replacement value for the NAME field in the hash mapping structure. Further analysis of this string reveals the UOS keyword, and combined with the ID_LIKE field value of "debian", it is inferred that the system is based on Tongxin UOS and has undergone secondary development. In the subsequent mapping table matching process, the extracted UOS keyword is used to perform a fuzzy match with the Tongxin UOS index item in the mapping table, successfully identifying the operating system type as a Tongxin UOS derivative, ensuring that even with incomplete configuration files, the application can still obtain the correct DPI detection path guidance.
[0035] In one embodiment, the fuzzy matching mechanism in step S1133 is applied to the scenario of identifying the Open Kylin operating system. The ID field value of the Open Kylin operating system is openkylin, but in some earlier versions or community-customized versions, this field may be written as open-kylin or openKylin, etc. When the ID field value is extracted as open-kylin, an exact match is first attempted, but no corresponding index item is found in the mapping table, and then the fuzzy matching process is initiated. The longest common subsequence between open-kylin and the index keyword openkylin in the mapping table is calculated. The common subsequence of the two strings is openkylin, with a length of nine, open-kylin has a length of ten, and openkylin has a length of nine, with an average length of nine and five. The similarity score is nine divided by nine and five, which is approximately 0.947, exceeding the set threshold of 0.7. openkylin is used as a candidate matching item, and its similarity score is recorded. Since this candidate item is the only one with the highest similarity score, it is directly determined as the fuzzy matching result, and the operating system type is successfully identified as Open Kylin. This fuzzy matching based on string similarity can effectively address the subtle differences in ID field formats between different versions or customized environments of domestic operating system distributions, thus improving the robustness of recognition.
[0036] It should be noted that the mechanism in step S1135, which uses the desktop environment identifier to attach attribute tags to the operating system type, plays a decisive role in the subsequent interface selection of the DPI detection module. The Tongxin UOS operating system comes with a default DDE desktop environment, which provides the com.deepin.daemon.Display D-Bus interface for obtaining display scaling factors. The UKUI desktop environment of the Galaxy Kylin operating system exposes scaling configurations through the org.ukui.desktop.interface interface. When the operating system type is identified as Tongxin UOS and a DDE tag is attached, the DPI detection module will first call the DDE-specific interface. If this interface call fails, it will then attempt to read the gsettings configuration and query the X11 RandR interface, forming a layered and degraded detection strategy. This method of identifying the operating system type in combination with the desktop environment ensures that, given the diverse ecosystem of domestic operating systems, Qt applications can choose the most suitable DPI information acquisition path, avoiding scaling factor reading failures due to interface incompatibility.
[0037] In one embodiment, the multi-path matching redundancy mechanism in step S1136 is applied to the scenario of identifying the ZTE NewStart operating system. In some versions of the ZTE NewStart operating system, the ID field is not explicitly marked, but the ID_LIKE field value is "debian" and the NAME field value is "NewStart CGSL". When the ID field match fails, the system reads the ID_LIKE field and identifies the keyword "debian", initially determining that the operating system is built on the Debian architecture and has the basic characteristics of using the apt package manager and systemd service management. Further parsing the NAME field, the core keyword "NewStart" is extracted from "NewStart CGSL", and an index entry related to "NewStart" is searched in the first-level index of the mapping table. If the mapping table has included the ZTE NewStart operating system and uses "newstart" as the index keyword, then the operating system type is successfully identified as ZTE NewStart through keyword matching in the NAME field. This multi-path redundancy matching mechanism, through tiered queries of the ID, ID_LIKE, and NAME fields, significantly improves the identification coverage of various domestic operating system distributions and reduces the probability of identification failure due to missing or formatted single fields.
[0038] Specifically, the entire operating system type identification process is completed in the early initialization phase of Qt application startup. The identification result is stored as a global configuration variable for subsequent modules such as DPI detection, font rendering, and icon loading. By accurately identifying mainstream domestic operating systems and their desktop environment combinations, such as UnionTech UOS, Galaxy Kylin, and Open Kylin, the application can select the optimal DPI information acquisition interface for the display architecture characteristics of different systems. This solves the display anomalies such as blurred interfaces and misaligned elements caused by the incompatibility of DPI acquisition mechanisms in traditional Qt applications on domestic operating systems, ensuring the consistency and visual clarity of the user interface of Qt applications in the domestic operating system ecosystem.
[0039] Step S12: Read the system environment variables and determine the display protocol based on the display server configuration parameters in the system environment variables.
[0040] Step S121: Obtain the current process's environment variable set. Retrieve all set environment variable key-value pairs through the process environment variable reading interface and store the environment variable data in a string mapping table. Focus on extracting environment variables related to the display server, including the DISPLAY, WAYLAND_DISPLAY, XDG_SESSION_TYPE, and SESSION_MANAGER variables. The DISPLAY variable indicates the connection identifier of the X11 display server. Its typical format is a colon followed by a number, such as :0 or :1, representing the display number of the local X11 server. If this variable exists and is not empty, it is preliminarily determined that an X11 display service exists in the system. The WAYLAND_DISPLAY variable indicates the socket name of the Wayland display server. Its typical format is wayland-0 or wayland-1, representing the connection identifier of the Wayland compositor. If this variable exists and is not empty, it is preliminarily determined that a Wayland display service exists in the system.
[0041] Step S122: Establish priority rules for display protocol determination. Since some domestic operating systems support mixed operation of X11 and Wayland, i.e., providing an X11 compatibility layer through XWayland in a Wayland session, it is necessary to determine the actual display protocol type used by the application. First, check the value of the XDG_SESSION_TYPE variable. This variable is set by the desktop session manager and explicitly indicates the display protocol type of the current session. If the value of XDG_SESSION_TYPE is "wayland", then the display protocol is determined to be Wayland; if the value is "x11", then the display protocol is determined to be X11. If the XDG_SESSION_TYPE variable is not set or its value is empty, the secondary judgment logic is entered, and the existence of the WAYLAND_DISPLAY and DISPLAY variables is checked. If only the WAYLAND_DISPLAY variable exists, it is determined to be a pure Wayland environment. If only the DISPLAY variable exists, it is determined to be a pure X11 environment. If both exist, it is determined to be the XWayland compatible mode in the Wayland session. At this time, the display protocol type is marked as the Wayland main protocol and the X11 compatibility status is recorded.
[0042] Step S123 involves supplementary testing for the customized display services of domestic operating systems. Some domestic desktop environments, such as Tongxin UOS's DDE desktop, have proprietary extensions in their display server configurations, requiring the reading of additional environment variables to obtain complete display protocol information. The existence of the `DDE_SESSION_PROCESS_ID` variable is checked; this variable represents the identifier of the DDE session process. If it exists, it indicates that the system is currently running in a DDE desktop environment. The `DBUS_SESSION_BUS_ADDRESS` variable is then read to obtain the D-Bus session bus address. The `Protocol` property of the `com.deepin.daemon.Display` service is queried through the D-Bus interface. This property directly returns the string representing the display protocol type currently used by the DDE desktop. For Galaxy Kylin's UKUI desktop, the existence of the `UKUI_SESSION_ID` variable is checked. If it exists, the display protocol information is obtained by reading the `DisplayProtocol` property of the `org.ukui.session D-Bus` service. The display protocol type obtained from the desktop environment-specific interface is used as the highest priority criterion, overriding the results inferred from general environment variables.
[0043] Step S13: Read the current user's session process information and determine the desktop environment information based on the desktop component identifier in the session process information.
[0044] Step S131: Enumerate all running processes in the current user space. Obtain the process list by reading the process directories under the proc filesystem. The proc filesystem is a virtual filesystem interface provided by the Linux kernel. Each numbered subdirectory under the / proc path corresponds to a running process, and the directory name is the process identifier. Traverse all numbered directories under the / proc path and read the status file of each process directory to obtain basic process information, including the process name (Name), process user identifier (Uid), and parent process identifier (PPid). Filter out processes owned by the current user, i.e., processes whose Uid field matches the currently logged-in user's user identifier, excluding system daemons and processes from other users, thus narrowing down the range of processes to be checked.
[0045] Step S132: Identify the characteristic processes of the desktop environment from the process list. Different domestic desktop environments have their own unique core process names. By matching these characteristic process names, the type of the currently running desktop environment can be accurately determined. Establish a desktop environment characteristic process mapping table. This table defines the set of key process names corresponding to each desktop environment. The characteristic processes of the Tongxin UOS DDE desktop environment include the dde-desktop process, dde-dock process, dde-launcher process, and startdde process. The characteristic processes of the Galaxy Kylin UKUI desktop environment include the ukui-panel process, ukui-session process, and peony-qt-desktop process. The characteristic processes of the GNOME-based customized domestic desktop environment include the gnome-shell process and the gnome-session process. Iterate through the filtered process list and match the Name field of each process with the feature process names in the mapping table. If a process name is found to be exactly the same as any name in the feature process set of DDE desktop, then mark the desktop environment type as DDE type. If a feature process of UKUI desktop is matched, then mark it as UKUI type. If a GNOME-related process is matched, then mark it as GNOME type.
[0046] Step S133 further verifies the desktop environment type through process command-line parameters and environment variables. Relying solely on process name matching may lead to misjudgments; for example, a user might manually start a desktop component process but actually be running a different desktop environment. Cross-verification using detailed process information is necessary. The complete command-line parameters of the process are obtained by reading the cmdline file in the process directory. The cmdline file separates each parameter with an empty string. After parsing, the executable file path and input parameters at process startup can be obtained. The executable file path of the DDE desktop characteristic process is checked to see if it is located in a standard DDE installation path such as / usr / bin or / usr / lib / deepin-daemon. If the path does not match, the reliability of the process as a desktop environment determination is reduced. The environment variables of the process are obtained by reading the environ file in the process directory. The environ file separates each environment variable key-value pair with an empty string. The DESKTOP_SESSION, XDG_CURRENT_DESKTOP, and XDG_SESSION_DESKTOP variables are extracted from it. The `DESKTOP_SESSION` variable is set by the session manager, and its value is usually an identifier for the desktop environment, such as Deepin, UKUI, or GNOME. The `XDG_CURRENT_DESKTOP` variable identifies the name of the current desktop environment, supporting multiple desktop environment names separated by colons. The `XDG_SESSION_DESKTOP` variable records the desktop environment selected when the session starts. The desktop identifier extracted from the process environment variable is compared with the desktop type obtained by matching the process name. If they match, the desktop environment determination result is confirmed. If there is a conflict, the identifier in the environment variable takes precedence, because the environment variable is uniformly set by the desktop session manager and is more reliable.
[0047] Step S134 handles special cases of desktop environment identification. Some domestic operating systems allow users to select different desktop environments during login, or install multiple desktop environments simultaneously on a single system, resulting in the possible presence of component processes for multiple desktop environments in the process list. A parent-child relationship tree for desktop environment processes is established, tracing the parent process of each process through the PPID field to identify process groups started by the same session manager. The session manager process is typically a systemd user instance or a dedicated session startup process such as startdde or ukui-session. All component processes corresponding to the currently active desktop environment should form a process tree structure with the session manager as the root node. The number of characteristic processes for each desktop environment type is counted, and the desktop environment type with the most characteristic processes and the most complete process tree structure is selected as the final determination result. If the desktop environment type cannot be clearly determined through process information, the desktop session configuration file in the user's home directory is read. This file path is usually ~ / .dmrc or ~ / .config / session, and the value of the Session field is extracted as the final basis for desktop environment determination.
[0048] In one embodiment, when locating the system distribution identifier file in step S111, adaptations are made for the specific characteristics of the Tongxin UOS operating system. In addition to the standard / etc / os-release file, Tongxin UOS provides an additional / etc / uos-release file. This file contains UOS-specific version information fields, such as the EditionName field indicating the UOS version type, including different distributions like Professional, Personal, and Server versions; the MinorVersion field indicating the minor version number; and the Processor field indicating the processor architecture type, such as domestic processor architectures like amd64, arm64, and mips64el. The / etc / uos-release file is read first. If the file exists, the EditionName and MinorVersion fields are extracted and appended to the operating system type data structure, providing a more granular basis for determining the system environment for subsequent DPI adaptation logic. If the / etc / uos-release file does not exist, the process reverts to reading the standard / etc / os-release file, inferring the UOS version information from the ID and VERSION_ID fields. This hierarchical reading mechanism ensures that the system identifier can be accurately obtained on all versions of UOS, avoiding recognition failures due to version differences.
[0049] In one embodiment, when establishing the priority rules for display protocol determination in step S122, the process takes into account the phased characteristics of Wayland support in the Kylin V10 operating system. Early versions of Kylin V10 used the X11 display protocol by default, while later versions gradually introduced Wayland support but kept X11 as an alternative. The specific version number of Kylin is determined by the VERSION_ID field. If the version number is lower than V10 SP1, even if the WAYLAND_DISPLAY variable is detected, it will not be used as the basis for display protocol determination because early versions of Wayland implementation have compatibility issues, and the actual running applications still use the X11 protocol through XWayland. If the version number is V10 SP1 or higher, the priority determination logic between Wayland and X11 is executed normally. For the detected X11 protocol environment, the specific value of the DISPLAY variable is further read. If the value points to a local socket, such as 0, it is confirmed as a local X11 server. If the value contains a network address, such as hostname:0, it is marked as a remote X11 connection. Because the DPI acquisition mechanism of remote X11 connection is different from that of local X11, different query strategies need to be adopted in the subsequent DPI detection phase.
[0050] In one embodiment, when identifying the characteristic processes of the desktop environment from the process list in step S132, compatibility processing is performed to address the changes in process names between different versions of the Deepin operating system's DDE desktop. Early versions of the DDE desktop used dde-desktop as the desktop component process name, while newer versions renamed this process to dde-desktop-background. Some components, such as the file manager, were renamed from dde-file-manager to dde-file-manager-daemon. A version compatibility mapping relationship for process names is established. An aliasing mechanism is created in the characteristic process mapping table for different version names of the same desktop component, treating both dde-desktop and dde-desktop-background as valid characteristic processes of the DDE desktop environment, and including both dde-file-manager and dde-file-manager-daemon in the matching scope. When traversing the process list, each process name is checked to see if it matches the main name or any alias of the characteristic process. If a match is successful, it is counted in the characteristic process count of the corresponding desktop environment. This version compatibility mechanism ensures that the DDE desktop environment can be accurately identified on different versions of the Deepin system, avoiding misjudgment of the desktop environment due to changes in process names.
[0051] In one embodiment, when further verifying the desktop environment type in step S133 using process command-line parameters and environment variables, special processing is performed for the UKUI desktop of the OpenKylin operating system. Although the UKUI desktop of OpenKylin and the UKUI desktop of GalaxyKylin share the same code base, they differ in configuration paths and environment variable settings. The XDG_CONFIG_DIRS variable is extracted from the process environment variables. This variable defines the list of search paths for system-level configuration files. The UKUI desktop of OpenKylin sets the configuration path to / usr / share / openkylin / ukui, while GalaxyKylin uses the / usr / share / ukui path. By checking whether the XDG_CONFIG_DIRS variable contains the string "openkylin" and combining it with the value of the DESKTOP_SESSION variable, the specific distribution source of the two UKUI desktops can be distinguished. If XDG_CONFIG_DIRS contains an OpenKylin path and DESKTOP_SESSION is ukui, then the desktop environment type is refined to OpenKylin UKUI. If XDG_CONFIG_DIRS does not contain an OpenKylin path, then it is marked as GalaxyKylin UKUI. This refined desktop environment classification provides an accurate basis for subsequent DPI information queries based on the differences in D-Bus interfaces across different distributions.
[0052] It should be noted that the operating system environment identification process, consisting of steps S111 to S134, outputs operating system type enumeration values, operating system version numbers, display protocol types, and desktop environment types. This information, as a whole system environment context data structure, is passed to the subsequent DPI multi-source detection module. The operating system type in the system environment context data structure determines the vendor-specific configuration interface to be queried during DPI detection; the display protocol type determines whether the underlying DPI value is obtained through the X11 RandR extension or the Wayland output interface; and the desktop environment type determines the query target and interface method name of the D-Bus service. By completing a comprehensive system environment identification at the initial stage of the DPI adaptation process, the repeated execution of environment determination logic in subsequent adaptation steps is avoided, improving the overall efficiency of the adaptation process. Simultaneously, it ensures that all adaptation decisions are based on consistent environment information, avoiding adaptation strategy conflicts caused by information asynchrony.
[0053] Specifically, when the Qt application starts, step S111 is executed first to read the system distribution identification file. Assuming the ` / etc / os-release` file contains the ID field as `uos`, the `VERSION_ID` field as `20`, and the `NAME` field as `UnionTech OS 20`, then according to the matching rules in step S113, the operating system type is determined to be UnionTech UOS, and the version number is 20. Next, step S121 is executed to obtain environment variables. The `XDG_SESSION_TYPE` variable is read as `wayland`, the `WAYLAND_DISPLAY` variable as `wayland-0`, and the `DISPLAY` variable as `1`. According to the priority rules in step S122, since `XDG_SESSION_TYPE` explicitly indicates `wayland`, the display protocol is determined to be of type Wayland, and the existence of an XWayland compatibility layer is recorded. Then, step S131 is executed to enumerate the process list. The process list contains the processes dde-desktop, dde-dock, and startdde. Based on the matching rules of the feature process mapping table in step S132, the desktop environment type is determined to be DDE. Step S133 is then executed to read the environment variables of the startdde process. It is confirmed that the DESKTOP_SESSION variable and the XDG_CURRENT_DESKTOP variable both have the value "deepin," matching the process names. The verification is successful. The final output system environment context data structure contains the operating system type as Tongxin UOS, version number 20, display protocol as Wayland and supports XWayland, and desktop environment as DDE. This data structure guides subsequent steps to prioritize querying the DDE's D-Bus interface to obtain DPI information and using Wayland protocol-related scaling factor query methods.
[0054] Preferably, in step S112, when parsing the key fields of the system distribution identifier file, special characters in the field values are normalized. Some domestic operating systems include additional information such as version codes or release dates in the PRETTY_NAME field. This information may contain special characters such as spaces, parentheses, and Chinese characters, which can affect subsequent string matching operations. Normalization operations such as removing leading and trailing whitespace characters, converting to lowercase, and removing non-alphanumeric characters are performed on the extracted field values. The normalized string is then used for operating system type matching, ensuring that the system type can be correctly identified even with slight differences in field format. Simultaneously, the original field values are retained for log recording, facilitating problem tracking and debugging.
[0055] Preferably, in step S123, when performing supplementary testing for the customized display service features of the domestic operating system, the validity of the D-Bus interface query results is verified. Since the D-Bus service may fail to query due to permission restrictions, service not starting, or version incompatibility, a query timeout and exception handling mechanism need to be set. The timeout for the D-Bus method call is set to 500 milliseconds. If no result is received within the timeout period, the query source is abandoned, and the process reverts to the general environment variable judgment logic. The format of the Protocol attribute value returned by D-Bus is validated to confirm that the return value is the expected x11 or wayland string. If the return value is empty or contains illegal characters, it is considered an invalid result and this judgment criterion is not adopted. By validating the results of each query source, the failure of the entire display protocol judgment process due to an abnormality of a single data source is avoided, improving the robustness of the system environment identification.
[0056] Preferably, in step S134, when handling special cases of desktop environment identification, permission checks and path expansion are performed on the reading of the desktop session configuration file in the user's home directory. The user's home directory path is usually obtained through the HOME environment variable, but in some restricted environments, the HOME variable may not be set or may point to a non-standard path. First, the value of the HOME variable is read from the environment variables. If the variable does not exist, the home directory path corresponding to the current user identifier is obtained by reading the passwd database. The existence and readability checks are performed on the complete path of the concatenated configuration file. If the file does not exist or there is no read permission, this step is skipped to avoid program exceptions caused by file access failures. When parsing the successfully read configuration file content, a fault-tolerant configuration file parsing method is used, ignoring lines with non-standard formats and only extracting valid configuration items that conform to the key-value pair format, ensuring that valid Session field values can be obtained even if the configuration file is partially corrupted.
[0057] In summary, through the multi-layered system environment identification process from steps S11 to S13, comprehensive and accurate acquisition of information on the type of domestic operating system, display protocol, and desktop environment was achieved. This process, addressing the diversity and customization of domestic operating systems in terms of system identification, display service architecture, and desktop environment implementation, established a multi-data source cross-verification mechanism and version compatibility adaptation strategy. This ensures accurate identification of the system environment on various domestic operating systems and their different versions, including UnionTech UOS, Galaxy Kylin, Open Kylin, and Deepin. This provides a reliable environmental judgment basis for subsequent DPI multi-source detection, avoiding incorrect DPI adaptation strategy selection due to inaccurate system environment information, and fundamentally guaranteeing the interface display quality of Qt applications on domestic operating systems.
[0058] Step S2, which involves obtaining the system scaling factor through a multi-source detection mechanism based on the operating system type, the display protocol, and the desktop environment information, includes: Step S21: Determine the corresponding desktop bus interface based on the desktop environment information, read the first configuration data through the desktop bus interface, determine whether there is a compliant first scaling factor in the first configuration data, and if there is a first scaling factor, determine the first scaling factor as the system scaling factor.
[0059] Step S211: Parse the desktop environment type identifier in the desktop environment information, and determine the corresponding bus service name and object path according to the preset desktop environment mapping table. The desktop environment mapping table stores the bus service name (com.deepin.daemon.Display) and object path ( / com / deepin / daemon / Display) for the Tongxin UOS Deepin desktop environment, the bus service name (org.ukui.SettingsDaemon.plugins.xsettings) and object path ( / org / ukui / SettingsDaemon / plugins / xsettings) for the Galaxy Kylin UKUI desktop environment, and the bus service name (org.gnome.Mutter.DisplayConfig) and object path ( / org / gnome / Mutter / DisplayConfig) for the customized GNOME desktop environment. By matching the read desktop environment type identifier with the identifier in the mapping table, the corresponding bus service name and object path are obtained, establishing an access address for subsequent bus interface calls.
[0060] Step S212: Based on the bus service name and object path, establish an inter-process communication connection with the desktop environment background service process via the D-Bus session bus. First, obtain the connection handle of the D-Bus session bus, call the bus connection method, and pass the bus service name as the target service parameter to establish a message channel to that service. After the connection is established, construct a method call message, specifying the object path, interface name, and method name. The interface name is obtained from the mapping table. For the Deepin desktop environment, the interface name is com.deepin.daemon.Display, and the method name is GetScaleFactor. For the UKUI desktop environment, the interface name is org.ukui.SettingsDaemon.plugins.xsettings, and the method name is GetScaling. Send the constructed method call message to the target service process via the bus connection and wait to receive the returned response message.
[0061] Step S213: Receive the response message and extract the configuration data payload. Parse the configuration data payload according to the data format specification corresponding to the desktop environment type. The configuration data returned by the Deepin desktop environment is a double-precision floating-point number; the floating-point value is directly extracted from the parameter segment of the response message as the original scaling factor value. The configuration data returned by the UKUI desktop environment is an integer percentage value; the extracted integer value needs to be divided by 100 to convert it to a decimal scaling factor. The configuration data returned by the customized GNOME desktop environment is a structure array containing configurations for multiple displays; the array needs to be traversed to find the configuration item for the currently active display, and the scaling factor value is extracted from the scale field of the configuration item. Through differentiated parsing processing for different desktop environments, a unified format of original scaling factor values is obtained.
[0062] Step S214: Perform compliance verification on the original scaling factor value to determine whether the value is within a preset valid range and meets the precision requirements. The valid range is set between 0.5 and 4.0. If the original scaling factor value is less than 0.5 or greater than 4.0, it is determined to be non-compliant. The precision requirement is that the scaling factor value must be an integer multiple of 0.25. This is determined by calculating whether the result of multiplying the original scaling factor value by 4 is an integer. If it is not an integer, it is determined to be non-compliant. For original scaling factor values determined to be compliant, they are used as the first scaling factor and directly assigned to the system scaling factor variable to complete the determination of the scaling factor. For cases determined to be non-compliant, exception information is recorded and a flag is set to indicate that the first priority acquisition failed, triggering the subsequent second priority acquisition process.
[0063] Step S22: If there is no compliant first scaling factor in the first configuration data, determine the corresponding system-level configuration interface according to the operating system type, read the second configuration data through the system-level configuration interface, determine whether there is a compliant second scaling factor in the second configuration data, and if there is a second scaling factor, determine the second scaling factor as the system scaling factor.
[0064] Step S221: Determine the system-level configuration storage mechanism based on the operating system type. For systems based on dconf, select the GSettings interface; for systems based on traditional configuration files, select the direct file reading method. The operating system distribution is identified by checking the ID field in the / etc / os-release file. If the ID is uos or deepin, the configuration mode of the GSettings interface with the path com.deepin.xsettings is used to read the configuration item with the key name scale-factor. If the ID is kylin, the configuration mode of the GSettings interface with the path org.ukui.font-rendering is used to read the configuration item with the key name dpi and divide it by 96 to obtain the scaling factor. If it cannot be obtained through GSettings, the scaling factor value is obtained by reading the config / monitors.xml file in the user's home directory and parsing the scale tag content in the XML structure.
[0065] Step S222: The system-level configuration interface's read method is invoked to obtain configuration values, which are then converted to standard double-precision floating-point format. For the scale-factor configuration item obtained through GSettings, which is itself a floating-point number, it can be read directly. For the scaling factor calculated from the dpi configuration item, the integer dpi value is read first, and then a floating-point division operation by 96 is performed to obtain the scaling factor. For the scale tag content parsed from the XML file, the string within the tag is extracted first, and then a string-to-floating-point conversion function is called to complete the type conversion. Through unified conversion processing, it is ensured that configuration values from different sources are ultimately presented with the same data type.
[0066] Step S223: Perform compliance verification on the converted configuration value. The verification rules are the same as those in step S214, determining whether the value is within the range of 0.5 to 4.0 and is an integer multiple of 0.25. If the verification passes, the value is determined as the second scaling factor and assigned to the system scaling factor variable. If the verification fails, a flag is set to indicate that the second priority acquisition failed, and preparation is made to execute the third priority native display protocol interface acquisition process.
[0067] Step S23: If there is no compliant second scaling factor in the second configuration data, determine the corresponding native display protocol interface according to the display protocol, read the third configuration data through the native display protocol interface, determine whether there is a compliant third scaling factor in the third configuration data, and if there is a third scaling factor, determine the third scaling factor as the system scaling factor.
[0068] For the X11 display protocol, the XRRGetScreenResources function of the XRandR extension interface is called to obtain screen resource information. The output device list is traversed, and the physical size and pixel resolution of each output device are read. The scaling factor is calculated using the ratio of pixel density to the standard 96 DPI. For the Wayland display protocol, the scale event of the wl_output interface is listened to, and the integer scaling factor provided by the compositor is directly obtained from the event parameters. The obtained scaling factor value is validated for compliance. If the validation passes, it is determined as the third scaling factor and assigned to the system scaling factor variable; otherwise, step S24 is executed.
[0069] Step S24: If there is no compliant third scaling factor in the third configuration data, obtain the preset baseline scaling factor and determine the baseline scaling factor as the system scaling factor.
[0070] The baseline scaling factor is preset to 1.0, indicating no scaling. This value serves as the final fallback value after all priority probes fail, ensuring that the system scaling factor variable always holds a valid value and preventing subsequent rendering processes from encountering errors due to a lack of scaling factor. Log information is also recorded to indicate that all probe sources failed to obtain the scaling factor, facilitating subsequent troubleshooting.
[0071] In one embodiment, the desktop environment type identifier in step S211 is obtained by reading the value of the environment variable XDG_CURRENT_DESKTOP. This environment variable is set by the desktop session manager when the user logs in; a value of DEEPIN corresponds to the Deepin desktop environment, a value of UKUI corresponds to the Kylin desktop environment, and a value of GNOME corresponds to the customized GNOME desktop environment. By directly reading this environment variable, complex desktop environment detection logic is avoided, improving the accuracy and response speed of type recognition.
[0072] For example, when the environment variable value is DEEPIN, the bus service name com.deepin.daemon.Display and the object path / com / deepin / daemon / Display are looked up from the mapping table. These two parameters will be used as the target address for the D-Bus method call, ensuring that the message can be accurately routed to the display configuration service process of the Deepin desktop environment.
[0073] In one possible implementation, the D-Bus connection establishment in step S212 employs an asynchronous call mechanism to avoid blocking due to the target service process being unresponsive. The `dbus_bus_get_private` function is called to obtain an independent session bus connection, which is not shared with other bus users to prevent message confusion. When sending the method call message, a timeout of 500 milliseconds is set. If no response message is received within the timeout period, the priority acquisition is considered a failure, the wait is immediately canceled, and the next priority process is executed. This mechanism ensures that the application startup process is not suspended for an extended period when the desktop environment service is abnormal, guaranteeing the overall robustness of the DPI adaptation process.
[0074] It should be noted that the percentage value conversion for the UKUI desktop environment in step S213 typically returns integer values in the range of 100, 125, 150, 175, and 200, corresponding to scaling factors of 1.0, 1.25, 1.5, 1.75, and 2.0, respectively. By dividing by 100, the percentage concept presented in the user interface is mapped to the multiplier concept used by the rendering layer, achieving a unification between user perception and technical implementation.
[0075] For example, when the integer value 150 is received from the UKUI service, it is calculated by dividing by 100 to get 1.5. This value indicates that the rendering size of the interface element is 1.5 times the base size, which satisfies the display requirements of high-resolution screens while maintaining the clarity of the interface elements.
[0076] Specifically, the precision requirement check in step S214 is achieved by multiplying the scaling factor by 4 and then taking the modulo 1. If the result is 0, it means that the scaling factor is an integer multiple of 0.25, which meets the scaling precision requirements of the Qt rendering engine. This is because a precision step of 0.25 ensures a smooth transition between text and graphic edges when Qt performs sub-pixel rendering. If the result is not 0, it means that the scaling factor precision is too high, which may lead to pixel alignment problems during rendering, causing blurry or jagged interface elements.
[0077] For example, when the original scaling factor is 1.3, 1.3 multiplied by 4 equals 5.2, and the result modulo 1 is 0.2, which is not 0, therefore it is judged as non-compliant. However, a scaling factor of 1.25 multiplied by 4 equals 5, and the result modulo 1 is 0, which is judged as compliant. Through this precision check, abnormal scaling values that may cause rendering quality problems are filtered out, ensuring that subsequent UI elements can be accurately aligned on pixel boundaries.
[0078] In one embodiment, in step S221, when the configuration cannot be obtained through GSettings, the config / monitors.xml file needs to be read to handle exceptions such as file non-existence or corrupted format. First, check if the file exists; if it does not, skip this acquisition method and proceed directly to step S23. If the file exists, use an XML parsing library to load the file content, capturing format errors during parsing. If an exception occurs, record a warning message and skip this acquisition method. This exception handling mechanism ensures that when the system configuration file is abnormal, the entire DPI adaptation process will not be interrupted, but rather smoothly degraded to the next priority acquisition method, demonstrating the fault tolerance capability of the multi-source detection mechanism.
[0079] Preferably, in step S222, when parsing the scale tag content from the XML file, it is necessary to locate the configuration node corresponding to the currently connected monitor. The monitors.xml file contains multiple monitor configuration blocks, each corresponding to a monitor. The target configuration block is determined by matching the connector tag content in the configuration block with the connector name of the currently active monitor. The connector name is obtained by querying the display driver interface, such as HDMI-1, eDP-1, etc. After locating the target configuration block, the scale tag content is extracted. This precise matching mechanism avoids reading the scaling configuration of the wrong monitor in a multi-monitor environment, ensuring that the obtained scaling factor is consistent with the actual monitor used.
[0080] In one embodiment, step S23, which calculates the scaling factor for the X11 display protocol, considers the possibility that the display may report incorrect physical dimensions. Some displays report physical dimensions of 0 or obviously unreasonable values via EDID data. In such cases, directly calculating the scaling factor using pixel density would yield an incorrect scaling factor. Therefore, before calculation, the physical dimensions are checked to ensure they are within a reasonable range. If the physical width or height is less than 50 mm or greater than 2000 mm, it is considered an abnormal value. The pixel density calculation method is abandoned, and instead, the Xft.dpi configuration item in the X resource database is read, and the value of this configuration item is divided by 96 to obtain the scaling factor. This compensation mechanism improves the success rate of scaling factor acquisition when hardware information is unreliable, thus enhancing the applicability of the method.
[0081] Understandably, setting the baseline scaling factor to 1.0 in step S24 means that if all automatic detection methods fail, the application will render the interface without scaling. While this may result in overly small interface elements on high-DPI displays, it ensures normal application startup and basic functionality. Users can adjust the scaling factor manually after the application is running. This design follows the graceful degradation principle in software engineering, ensuring that the system still provides a minimum level of service in extreme cases, rather than refusing to start due to the inability to obtain configuration, thus reflecting a balance between practicality and user experience.
[0082] Step S3, which involves establishing a mapping relationship between logical pixels and physical pixels based on the system scaling factor and maintaining an independent screen scaling factor for each display screen, includes: Step S31: Obtain the physical pixel size of each user interface element in the application interface, and calculate the logical pixel size of each user interface element based on the physical pixel size and the system scaling factor, wherein the logical pixel size is independent of the pixel density of the display device.
[0083] Step S311: Iterate through all user interface elements within the application window, including button controls, text labels, icon resources, input boxes, list views, and other components. Read the current width and height values of each element through the Qt framework's geometry information interface. These values, expressed in pixels, represent the actual physical space occupied by the element on the screen. The physical pixel size reflects the absolute rendered size of the element on a specific display device and is directly affected by the monitor's pixel density.
[0084] Step S312: Divide the physical pixel size of each user interface element obtained in step S311 by the system scaling factor to obtain the corresponding logical pixel size. A logical pixel is a hardware-independent abstract unit of measurement; its value only reflects the relative position and proportion of the element in the interface layout and does not change with the physical resolution or pixel density of the display. The calculation formula is: logical pixel width equals physical pixel width divided by the system scaling factor, and logical pixel height equals physical pixel height divided by the system scaling factor.
[0085] For example, when the system scaling factor is 1.5, a button control with a physical size of 300 pixels by 200 pixels has a logical pixel size of 200 pixels by 133.33 pixels.
[0086] Step S313: The logical pixel size calculated in step S312 is stored in memory as the base size for each user interface element. All subsequent rendering operations are performed based on this logical size. By introducing a logical pixel layer, the interface layout definition is decoupled from the physical display device, allowing the same interface description to maintain a consistent visual proportion on screens with different pixel densities.
[0087] Step S32: Obtain the identification information of all display screens connected to the current device; for each display screen, obtain the screen scaling factor corresponding to the display screen; and establish a mapping table between the identification information and the screen scaling factor.
[0088] Step S321: Enumerate all currently connected physical display screens through the Qt platform abstraction layer interface to obtain the unique identification information of each screen. Under the X11 display protocol, the screen identification information is obtained through the screen output name of the RandR extension interface, such as the output port name in string form like HDMI-1, DP-2, eDP-1, etc. Under the Wayland display protocol, the global identifier of the wl_output object is used as the screen identifier. For the mixed display protocol scenarios common in domestic operating systems, priority is given to reading the unified screen identifier interface provided by the desktop environment. For example, in the DDE environment of Tongxin UOS, the ListOutputs method of the com.deepin.daemon.Display service is called through D-Bus to obtain the path identifier of all screens. This identifier remains stable at the system level and is not affected by the switching of the underlying display protocol.
[0089] Step S322: For each screen identifier obtained in step S321, query the scaling factor value of the current application on that screen. First, attempt to read via a desktop-specific interface. For example, in a DDE environment, obtain the independent scaling ratio of each monitor through the ScaleFactor property of the D-Bus attribute com.deepin.daemon.Display.Monitor. This value is typically a discrete value such as 1.0, 1.25, 1.5, 1.75, 2.0, etc. If the desktop environment interface is unavailable, fall back to reading the system-level configuration. Query the scaling-factor key value under the org.gnome.desktop.interface architecture via gsettings, or read the scaling configuration items corresponding to each screen in the dconf database. In an X11 environment, further obtain the physical size and current resolution of each output through the RandR interface, calculate the pixel density, and then deduce the equivalent scaling factor. In a Wayland environment, listen to the scale event of the wl_output object to obtain the integer scaling factor announced by the compositor.
[0090] Step S323: Create a hash mapping table structure in memory that maps screen identifiers to screen scaling factors, using the screen identifier string or identifier as the key and the corresponding scaling factor value as the value. This mapping table is initialized and built when the application starts and is dynamically updated during runtime.
[0091] For example, when the system connects a new external monitor or the user adjusts the scaling of a screen in the system settings, the system updates the values of the corresponding key-value pairs in the mapping table in real time by listening for display configuration change signals of the desktop environment.
[0092] Step S324 involves adding version markers and timestamps to the mapping table to record the time and trigger source of each mapping relationship change. When a mapping table update is detected, a version number increment event is generated, notifying the application's internal rendering manager to refresh the screen ownership determination and scaling status of all current windows. By maintaining the version history of the mapping table, the change trajectory of the screen scaling factor can be traced during the debugging phase, helping to locate the root cause of cross-screen display anomalies.
[0093] Step S33: Obtain the initial identification information of the initial display screen where the current application window is located, query the initial screen scaling factor corresponding to the initial identification information according to the mapping table, and calculate the initial rendering physical pixel size according to the logical pixel size and the initial screen scaling factor.
[0094] Step S331: When the application window is created or displayed, obtain the current display screen object of the window through Qt's screen query interface, and extract the identification information corresponding to the screen object. Specifically, call the screen method of the window object to return the screen pointer, and then read the corresponding identifier in the identification system established in step S321 from the screen object. For example, read the screen output name string in the X11 environment, and read the global identifier wl_output in the Wayland environment.
[0095] In step S332, using the initial identifier information obtained in step S331 as the key, a query operation is performed in the mapping table established in step S323 to return the current scaling factor value of the screen, which is recorded as the initial screen scaling factor. If the query result is empty or the mapping table has not yet been initialized, the default scaling factor of 1.0 is used as a temporary value, and the window is redrawn after the mapping table is updated.
[0096] Step S333: Multiply the logical pixel size of each user interface element stored in step S313 by the initial screen scaling factor obtained in step S332 to calculate the rendered physical pixel size of each element on the initial display screen. The calculation formula is: rendered physical pixel width equals logical pixel width multiplied by the initial screen scaling factor, and rendered physical pixel height equals logical pixel height multiplied by the initial screen scaling factor. The calculation result is rounded to the nearest integer to ensure pixel alignment.
[0097] Step S334: Apply the initial rendering physical pixel size calculated in step S333 to the Qt rendering pipeline, update the geometric properties of each user interface element, trigger the first drawing operation of the window, and make the interface content display correctly according to the initial screen scaling factor.
[0098] Step S34: Obtain the current application window movement event, obtain the target identification information of the target display screen according to the movement event, query the target screen scaling factor corresponding to the target identification information according to the mapping table, and calculate the target rendering physical pixel size according to the logical pixel size and the target screen scaling factor.
[0099] Step S341: Register a screen change event listener for the window during application runtime. This listener responds to screen switching signals generated by the Qt framework. When the user moves the window from one display screen to another by dragging or maximizing, or when the window's geometric center point crosses the screen boundary, the Qt platform plugin triggers a screen change event. The event parameters contain a reference to the target screen object. After capturing this event, the listener extracts the target screen object's identification information in the screen identification system, which is recorded as the target identification information.
[0100] Step S342: Using the target identifier information obtained in step S341 as the key, query the corresponding screen scaling factor in the mapping table maintained in step S323, and return the current scaling factor value of the target screen, denoted as the target screen scaling factor. During the query process, the version flag of the mapping table is read synchronously to confirm the timeliness of the current mapping table data, avoiding rendering errors caused by using outdated scaling factor values.
[0101] Step S343: Compare the target screen scaling factor obtained in step S342 with the screen scaling factor currently used by the window to determine if there is a numerical difference between the two. If the scaling factors are the same, there is no need to recalculate the rendering size, and the subsequent steps are skipped. If the scaling factors are different, the size recalculation process continues.
[0102] Step S344: When step S343 determines that the scaling factor has changed, the logical pixel size of each user interface element stored in step S313 is reread. The logical pixel size is then multiplied by the target screen scaling factor obtained in step S342 to calculate the target rendering physical pixel size of each element on the target display screen. The calculation formula is the same as in step S333, but the scaling factor used is replaced with the target screen scaling factor.
[0103] Step S345 updates the target rendering physical pixel size calculated in step S344 to the geometric attributes of each user interface element, triggering an incremental redraw operation for the window. Incremental redraw only processes element areas where the size has changed, avoiding the performance overhead of a full window refresh. During the redraw process, the pixel size settings of the font rendering engine are adjusted synchronously to ensure the text rendering size is consistent with the target screen scaling factor. For SVG format vector icons, the bitmap is directly re-rasterized according to the target screen scaling factor. For PNG format bitmap icons, the closest scaling version is selected from the preloaded multi-scaling resource set based on the target screen scaling factor. For example, when the target scaling factor is 1.5, a 2x resource is preferentially selected and rendered at a reduced scale; if a 2x resource is not available, it falls back to a 1x resource and renders at a larger scale.
[0104] Step S346: After completing the redrawing operation in step S345, update the current screen identifier and current screen scaling factor state variables recorded inside the window to keep them synchronized with the target screen, so as to provide correct reference data for the processing of the next screen switching event.
[0105] In one embodiment, when obtaining screen identification information in step S321, for the Tongxin UOS operating system environment, the service object at com / deepin / daemon / Display is first connected via the D-Bus session bus. Its ListOutputs method is called to return a list of all currently displayed output object paths. Each object path is formatted as / com / deepin / daemon / Display / Output followed by a numerical number. This number remains stable during system operation and is unaffected by hot-plugging of the display. The object path list is traversed, and the Name attribute interface of each output object is called to obtain the user-friendly name of the display, for example, eDP-1 for a built-in laptop screen and HDMI-A-0 for an external HDMI display. The object path serves as a unique internal identifier, and the user-friendly name serves as an auxiliary identifier, together forming a binary structure for the screen identification information. When the user adjusts the display arrangement order or primary / secondary screen role in the system settings, the object path remains unchanged; only the arrangement attribute changes, ensuring the stability of the identification.
[0106] In one embodiment, when querying the screen scaling factor in step S322, for the Kylin OS environment, the desktop environment type is first detected. If it is a UKUI desktop, the system connects to the org.ukui.SettingsDaemon.XRANDR service via the D-Bus system bus to read the ScaleFactor attribute value corresponding to each monitor. This attribute value is stored as a percentage in the UKUI environment; for example, 125 represents 1.25 times scaling, which needs to be divided by 100 to convert it to a floating-point scaling factor. If the UKUI service is unavailable, the system falls back to reading the scaling-factor key value under the org.ukui.SettingsDaemon.plugins.xsettings architecture in gsettings. This key value is an integer, representing a scaling factor of 256 times, which needs to be divided by 256 to restore the actual scaling factor. For example, when the key value is 384, the actual scaling factor is 1.5. After obtaining the scaling factor, the value is validated to ensure it is within a reasonable range of 0.5 to 3.0. Abnormal values outside the range are treated as 1.0 and a warning log is recorded.
[0107] In one embodiment, when establishing the mapping table in step S323, an unordered mapping container from the standard template library is used to implement a hash table structure, with the hash value of the screen identifier string as the internal index key and the floating-point number of the screen scaling factor as the storage value. During mapping table initialization, an independent key-value pair entry is assigned to each connected screen, and a read-write mutex is set to protect concurrent access. After the application's main thread completes the mapping table construction, an independent display configuration listening thread is created. This thread subscribes to the desktop environment's display configuration change D-Bus signal, such as the MonitorsChanged signal from com.deepin.daemon.Display in a DDE environment. When the listening thread receives the signal, it re-executes the screen information query process in steps S321 and S322 to obtain the latest screen identifier and scaling factor data, updates the corresponding key-value pair values in the mapping table through the mutex protection mechanism, and increments the version number counter of the mapping table. The rendering manager in the main thread periodically checks for version number changes; when an increment in the version number is detected, it triggers a process of re-determining the screen ownership and recalculating the size of all windows.
[0108] It's important to note that the mapping table versioning mechanism maintained in step S324 resolves the data consistency issue between asynchronous configuration updates and synchronous rendering. In traditional solutions, when a user adjusts the screen scaling in system settings, the configuration change signal might arrive while the application window is rendering. Directly modifying the mapping table data can cause the rendering pipeline to read inconsistent scaling factors, resulting in screen flickering or element misalignment. By introducing a version number mechanism, configuration update operations first modify the mapping table data and increment the version number. The rendering manager checks the version number before each draw, triggering a complete size recalculation and redraw process only when the version number changes, thus avoiding data races during rendering. The version number uses a 64-bit unsigned integer type, incrementing from 0, and will not overflow during the application's lifecycle. The timestamp information is obtained using a monotonically increasing system clock with millisecond precision, recording the absolute moment of each mapping table change. This facilitates the correlation and display of the timing relationship between configuration events and interface rendering behavior in the log file.
[0109] In one embodiment, when listening for window movement events in step S341, in addition to responding to the Qt framework's screenChanged signal, an active geometric position detection mechanism is added to address situations where signal triggering is not timely under certain domestic operating system environments. In the window's moveEvent and resizeEvent callback functions, the current global coordinates and size information of the window are actively obtained, and the coordinates of the center point of the window's geometric rectangle are calculated. All screen objects obtained in step S321 are traversed, and the global geometric region of each screen is read to determine which screen's region the window's center point falls within. The screen object containing the window's center point is taken as the current target screen, and its identification information is extracted. If the window's center point is located at a special position on the screen boundary and is simultaneously contained by two screen regions, the screen with the larger window geometric area is selected as the target screen. Through this dual mechanism of active detection and signal response, changes in the screen where the window is located are accurately identified under various display environments.
[0110] In one embodiment, when calculating the target rendering physical pixel size in step S344, for text label controls contained within the window, in addition to adjusting the width and height geometric properties of the controls, the font pixel size used for text rendering also needs to be updated synchronously. First, the system-level font scaling setting is read. In domestic operating systems, this is typically obtained through the `text-scaling-factor` key value under the `org.gnome.desktop.interface` architecture of `gsettings`. This key value is a floating-point number, with a default value of 1.0. The logical pixel font size is then multiplied sequentially by the target screen scaling factor and the system font scaling factor to obtain the final rendered font pixel size.
[0111] For example, if the logical font size of a text label is 12 pixels, the target screen scaling factor is 1.5, and the system font scaling factor is 1.2, then the rendered font pixel size is 12 x 1.5 x 1.2 = 21.6 pixels, which is rounded to the nearest integer 22 pixels. Set the calculated result to the pixel size property of the Qt font object to ensure clear text rendering and consistency with the system's global font scaling.
[0112] In one embodiment, when processing icon resources in step S345, for the PNG bitmap icons used in the application, three icon files of different scales—1x, 1.5x, and 2x—are preloaded during the application initialization phase and stored in different resource paths. When the target screen scaling factor is 1.5, the 1.5x version icon file is first searched in the resource path; if the file exists, it is loaded and used directly. If the 1.5x version does not exist, the 2x version is searched, loaded, and then scaled down to 1.5x for rendering. The scaling algorithm uses bilinear interpolation to ensure image quality. If the 2x version also does not exist, it finally reverts to the 1x version and scales up to 1.5x for rendering. At this point, the image may appear slightly blurry, but it is still better than the display effect without any scaling. By preloading multiple scaling resources and establishing scaling selection logic, the performance overhead of real-time vector rendering is avoided while ensuring icon clarity, making it particularly suitable for complex interface scenarios containing a large number of icon elements.
[0113] Specifically, step S346, updating the window state variables, involves synchronizing screen association information maintained within the window object. The window object stores two key state variables: the current screen identifier string and the current screen scaling factor floating-point number. After the interface redraw is completed in step S345, the target identifier information obtained in step S341 is written to the current screen identifier variable, and the target screen scaling factor queried in step S342 is written to the current scaling factor variable. These two state variables are used in the scaling factor comparison in step S343 during the next screen switching event, serving as the basis for determining whether the rendering size needs to be recalculated. Simultaneously, the state variable update operation also triggers a window attribute change event, notifying other modules within the application. For example, the theme manager can adjust the blur radius of the window shadow effect according to the new screen scaling factor, and the toolbar manager can adjust the spacing of the toolbar buttons according to the scaling factor, achieving collaborative adaptation of elements at different levels of the interface.
[0114] In one possible implementation, regarding the fallback mechanism for querying the screen scaling factor in step S322, when all desktop environment-specific interfaces and system-level configuration interfaces fail to return a valid scaling factor, a calculation method based on physical size and resolution is adopted. The physical width and height reported by the monitor are obtained via the X11's RandR extension interface or Wayland's wl_output interface, in millimeters. Simultaneously, the horizontal and vertical pixel counts at the current resolution are obtained. The horizontal pixel density is calculated using the formula: horizontal pixel count divided by the physical width and then multiplied by 25.4, in pixels per inch. The vertical pixel density is calculated using the formula: vertical pixel count divided by the physical height and then multiplied by 25.4. The arithmetic mean of the horizontal and vertical pixel densities is taken as the monitor's overall pixel density. The overall pixel density is divided by the baseline pixel density of 96 to obtain the calculated scaling factor.
[0115] For example, a monitor with a resolution of 2560 x 1440 and physical dimensions of 597 mm x 336 mm has a horizontal pixel density of approximately 108.9 (2560 divided by 597 x 25.4) and a vertical pixel density of approximately 108.9 (1440 divided by 336 x 25.4). The combined pixel density is 108.9. The calculated scaling factor is approximately 1.13 (108.9 divided by 96), rounded to the nearest standard scaling factor of 1.25. This calculation method serves as a fallback solution, ensuring a reasonable scaling factor value is obtained under any display environment and preventing display anomalies due to missing configuration settings.
[0116] Preferably, during incremental redraw in step S345, a dirty region marking mechanism is used to optimize rendering performance. During the calculation of the target rendering physical pixel size, the old and new size values of each user interface element are compared, and elements whose size has changed are marked as dirty regions. The dirty region information includes the element's boundary rectangle coordinates and the change type, which is divided into three types: size enlargement, size reduction, and position offset. During the redraw phase, only elements marked as dirty regions and their parent containers are drawn; other unchanged elements retain their original rendering cache. For elements with enlarged sizes, their clipping region is expanded and the complete content is redrawn. For elements with reduced sizes, the pixel content of redundant areas is cleared and the reduced area is redrawn. For elements with position offsets, the pixel content of the old position is cleared first, and then the element is drawn at the new position. By precisely controlling the redraw range, the wasted GPU fill rate and screen flickering caused by full window refresh are avoided. In complex interfaces containing hundreds of controls, incremental redraw can reduce drawing time by approximately 70% compared to global redraw, significantly improving the smoothness of cross-screen movement.
[0117] To avoid performance fluctuations caused by numerous consecutive redraws triggered when users frequently drag windows across multiple screens, this method adds the following optimizations before incremental redraws: Debouncing strategy: When a DPI change signal or window shifting event is detected, a redraw is not triggered immediately. Instead, a timer with a very short delay (e.g., 50ms) is started. If the same event is received again during the delay period, the timer is reset, and a redraw is performed only once after the delay ends, effectively merging high-frequency redraw requests.
[0118] Scaling factor change threshold: When the difference between the newly calculated scaling factor and the currently effective value is less than 0.05, it is considered as no effective change and no redraw is triggered to avoid invalid refresh due to floating-point precision issues.
[0119] Cache reuse: The calculated mapping results from logical pixels to physical pixels are cached based on the screen ID and scaling factor. When the scaling factor of the same screen does not change, the cached mapping results are directly reused without recalculation.
[0120] It should be noted that the rounding operation used in steps S333 and S344 when calculating the rendering physical pixel size is crucial for ensuring pixel alignment of interface elements. Without rounding, the rendering size may contain decimal parts, such as 133.33 pixels, which can lead to subpixel rendering during rasterization, causing blurred edges or color mixing. By rounding, the size is unified to an integer pixel value, ensuring that the boundary of each element is precisely aligned with the physical pixel grid of the display, presenting a sharp and clear visual effect. In some special scenarios, such as when the total width of the layout container is an odd number of pixels and needs to be evenly distributed among an even number of child elements, the even distribution calculation will produce a rounding error of 0.5 pixels. In this case, an error accumulation and distribution algorithm is used to distribute the rounding error sequentially among the child elements, ensuring that the sum of the widths of all child elements is strictly equal to the total width of the container, avoiding gaps or overlaps of 1 pixel.
[0121] In one embodiment, the application runs on the Tongxin UOS operating system. The system connects to two displays: the primary display is the built-in laptop screen with a resolution of 1920 x 1080 and physical dimensions of 344 mm x 193 mm, with a scaling factor of 1.0; the secondary display is an external 4K monitor with a resolution of 3840 x 2160 and physical dimensions of 620 mm x 340 mm, with a scaling factor of 2.0. When the application starts, the window is displayed on the primary display by default. Step S321 calls the ListOutputs method of the DDE display service via D-Bus to obtain the paths of two screen objects: / com / deepin / daemon / Display / Output0 and / com / deepin / daemon / Display / Output1. Step S322 queries the ScaleFactor property of Output0, finding it to be 1.0, and the ScaleFactor property of Output1, finding it to be 2.0. Step S323 establishes a mapping table, mapping Output0 to 1.0 and Output1 to 2.0. The application window contains a toolbar with an icon button whose logical pixel size is defined as 48 pixels by 48 pixels at design time. The window is initially displayed on the main display Output0. Step S331 identifies the current screen as Output0. Step S332 retrieves the initial screen scaling factor as 1.0 from the mapping table. Step S333 calculates the initial rendering physical pixel size as 48 x 1.0, which equals 48 pixels by 48 pixels. The button is displayed normally on the main display with a size of 48 pixels by 48 pixels. When the user drags the window to the secondary display Output1, the listener in step S341 captures the screen change event, identifies the target screen as Output1, retrieves the target screen scaling factor as 2.0 from the mapping table, and determines that the scaling factor has changed from 1.0 to 2.0, requiring recalculation. Step S344 multiplies the logical pixel size of 48 pixels by 48 pixels by the target scaling factor of 2.0, resulting in a target rendering physical pixel size of 96 pixels by 96 pixels. Step S345 triggers the button redraw operation, and the button is displayed on the secondary display at a size of 96 pixels by 96 pixels, which is twice the size of the primary display and consistent with the 2x scaling setting of the secondary display. The user sees the same visual size of the button on both displays, achieving cross-screen display consistency.
[0122] For example, in the UKUI desktop environment of the Kylin OS, the user adjusts the scaling ratio of the main display from 100% to 125% in the display panel of the system settings. The system triggers a display configuration change D-Bus signal. After receiving the signal, the display configuration listening thread in step S323 re-executes the screen information query process. In step S322, the ScaleFactor attribute of the main display is read through D-Bus, and the new value 125 is obtained. This value is divided by 100 to convert it into a scaling factor of 1.25. The listening thread updates the scaling factor value corresponding to the main display identifier in the mapping table, changing it from the original 1.0 to 1.25, and increments the mapping table version number from 3 to 4. The rendering manager in the application's main thread detects the version number change in the next event loop cycle, reads the screen ownership information of all current windows, and finds that a certain window is being displayed on the main display. The rendering manager triggers a screen ownership reassessment process for the window. Step S341 confirms the window is still on the primary display. Step S342 retrieves the new scaling factor of 1.25 from the updated mapping table. Step S343 determines the scaling factor has changed from 1.0 to 1.25. Step S344 recalculates the rendering size of all elements within the window. The window contains a text label with a logical font size of 14 pixels. The original rendered font size was 14 x 1.0 = 14 pixels. After recalculation, the rendered font size becomes 14 x 1.25 = 17.5 pixels, rounded to 18 pixels. Step S345 updates the pixel size attribute of the font object to 18 pixels, redraws the text label, and the text size seen by the user is correspondingly enlarged, synchronized with the system's global 125% scaling setting, taking effect without requiring an application restart.
[0123] In one possible implementation, regarding step S321, which involves obtaining the screen identifier within the Wayland display protocol environment, the application obtains all wl_output objects provided by the current compositor through Qt's Wayland platform plugin. Each wl_output object represents a physical display output, and a unique global name, a 32-bit unsigned integer, is assigned by the compositor upon object creation. The application records the global name of each wl_output object as the internal identifier of the screen. Simultaneously, it listens for the geometry and mode events of the wl_output objects, extracting the monitor's manufacturer and model names from the geometry event and the current resolution and refresh rate information from the mode event. The manufacturer name, model name, and global name are combined to form a human-readable screen identifier string, such as Dell-P2415Q-output-5. When the compositor removes a wl_output object, it triggers the global object's remove event. Upon receiving this event, the application removes the entry for the corresponding identifier from the mapping table and notifies the rendering manager to check the screen ownership of all windows. If a window was originally located on the removed monitor, it is migrated to the remaining monitor with the highest resolution, and the rendering size is recalculated.
[0124] Specifically, in step S345, when processing the scaling rendering of SVG vector icons, the view frame attribute of the SVG file is first parsed to obtain the design baseline size of the icon. This design baseline size is used as the logical pixel size and multiplied by the target screen scaling factor to obtain the target rendering size. Qt's SVG rendering engine is then invoked to rasterize the SVG content into a bitmap of the specified size. Anti-aliasing is enabled during rasterization to ensure smooth curves and diagonal edges. The anti-aliasing sampling rate parameter is adjusted to address the rendering characteristics of domestic GPU drivers at high DPI.
[0125] For example, under the Jingjia Micro GPU driver, the default 4x multisampling anti-aliasing may become overly smoothed at 2x scaling, leading to loss of detail. In this case, reducing the sampling rate to 2x ensures smooth edges while preserving the sharp features of the icon. Under the Zhaoxin GPU driver, high-DPI rasterization has color space conversion errors. The SVG's color configuration needs to be converted from sRGB to linear RGB before rasterization, and then converted back to sRGB after rasterization to avoid grayish colors. Through targeted driver adaptation parameter adjustments, it is ensured that SVG icons can present accurate visual effects on various domestic hardware platforms.
[0126] Preferably, in step S312, when calculating the logical pixel size, a hybrid measurement strategy is adopted for special elements with fixed physical size requirements. Some interface elements, such as touch buttons, require, from an ergonomic perspective, a physical size of at least 7 mm by 7 mm to ensure accurate finger clicking. For such elements, their physical size on the current screen is first calculated using the formula: physical pixel size divided by pixel density and then multiplied by 25.4. If the calculated physical size is less than 7 mm, the minimum required physical pixel size is calculated in reverse using the formula: 7 divided by 25.4 and then multiplied by pixel density. This minimum physical pixel size is used as the lower limit constraint for the element. In steps S333 and S344, when calculating the rendering physical pixel size, the calculation result is compared with the lower limit constraint, and the larger of the two values is taken as the final rendering size.
[0127] For example, a touch button has a logical pixel size of 40 pixels by 40 pixels. On a main display with a pixel density of 96 pixels per inch, its physical size is 40 divided by 96 multiplied by 25.4, approximately 10.6 millimeters, meeting the 7mm requirement. When the window moves to a high-DPI display with a pixel density of 192 pixels per inch, without a lower limit constraint, the calculated rendered physical pixel size is 40 multiplied by 2.0, equaling 80 pixels, and the physical size is 80 divided by 192 multiplied by 25.4, approximately 10.6 millimeters, still meeting the requirement. However, if the window moves to the output of a low-DPI projector with a pixel density of 48 pixels per inch, the calculated rendered physical pixel size is 40 multiplied by 0.5, equaling 20 pixels, and the physical size is 20 divided by 48 multiplied by 25.4, approximately 10.6 millimeters, still meeting the requirement. By using a hybrid measurement strategy, the physical availability of key interactive elements is ensured while maintaining the consistency of logical pixel ratios, improving the user experience across devices.
[0128] In one embodiment, after updating the window state variable in step S346, a synchronous adjustment of the window decoration elements is also triggered. Window decorations include the title bar, border, and shadow effects; the size and style parameters of these elements are stored in a separate theme configuration object. When the window's current screen scaling factor variable is updated to a new value, the theme manager receives an attribute change notification and rereads the decoration parameter baseline values in the theme configuration. The baseline value for the title bar height is 32 pixels, the baseline value for the border width is 1 pixel, and the baseline value for the shadow blur radius is 10 pixels. Each baseline value is multiplied by the new screen scaling factor to obtain the adjusted decoration parameters.
[0129] For example, when the scaling factor changes from 1.0 to 1.5, the title bar height is adjusted to 32 x 1.5 = 48 pixels, the border width is adjusted to 1 x 1.5 = 1.5 pixels (rounded to 2 pixels), and the shadow blur radius is adjusted to 10 x 1.5 = 15 pixels. The adjusted parameters are then used to redraw the window decorations, ensuring that the visual thickness of the title bar, border, and shadow is consistent with the scaling ratio of the window content, avoiding the visual incongruity of enlarged window content without changed decorative elements. Especially in the desktop environment of domestic operating systems, window decoration styles typically follow unified design specifications; the synchronized scaling of decorative elements ensures consistency between the application and the overall system visual style.
[0130] It should be noted that in step S322, when querying the screen scaling factor, for desktop environments that support fractional scaling, the scaling factor may be a non-standard value, such as 1.33 or 1.67. In this case, the scaling factor stored in the mapping table retains two decimal places of precision to avoid the accumulation of floating-point rounding errors. In the multiplication calculations of steps S333 and S344, double-precision floating-point operations are used to ensure the precision of intermediate results, and rounding is only performed when the result is converted to the rendering physical pixel size.
[0131] For example, if an element has a logical pixel width of 100 pixels and a screen scaling factor of 1.33, the intermediate calculation result is 100 multiplied by 1.33, which equals 133.0 pixels, rounded down to 133 pixels. If the logical pixel width is 101 pixels, the intermediate calculation result is 101 multiplied by 1.33, which equals 134.33 pixels, rounded down to 134 pixels. By uniformly rounding down at the end of the calculation chain, the accumulation of errors caused by multiple roundings is avoided, ensuring the stability of the interface layout under fractional scaling.
[0132] In one possible implementation, regarding the window movement event listener in step S341, in a multi-monitor mixed DPI scenario, the window may simultaneously span two screens, requiring the determination of the window's primary screen. The application calculates the intersection area between the window's geometric rectangle and the geometric regions of each screen, selecting the screen with the largest intersection area as the primary screen.
[0133] For example, a window measuring 800 pixels by 600 pixels has its top-left corner offset 200 pixels to the right of the main display's right edge. This results in the left 600 pixels of the window being within the main display's area, and the right 200 pixels being within the secondary display's area. The intersection area between the window and the main display is 600 x 600 = 360,000 square pixels, and the intersection area between the window and the secondary display is 200 x 600 = 120,000 square pixels. The application determines that the window belongs to the main display and renders it using the main display's scaling factor. When the user continues to drag the window, causing its right side to exceed 400 pixels into the secondary display's area, the intersection area reverses, the window's ownership switches to the secondary display, triggering a screen change event and recalculating the rendering size. This area comparison-based ownership determination mechanism avoids interface jitter caused by frequent scaling factor switching near screen boundaries, improving the smoothness of cross-screen dragging.
[0134] Specifically, in step S344, when recalculating the rendering size, a top-down recursive calculation strategy is adopted for complex interfaces containing nested layouts. First, the rendering physical pixel size of the top-level container is calculated, and then the sizes of its child containers and child controls are calculated sequentially. When calculating each child element, in addition to applying the target screen scaling factor, the layout strategy of the parent container must also be considered.
[0135] For example, a vertically laid-out container has a logical pixel height of 400 pixels and contains four child controls with logical pixel heights of 80, 100, 120, and 100 pixels respectively. On a screen with a scaling factor of 1.5, the container's rendered physical pixel height is 400 x 1.5 = 600 pixels, and the rendered heights of the child controls are 120, 150, 180, and 150 pixels respectively, totaling 600 pixels, consistent with the container's height. However, if a child control has a fixed height constraint, such as the second child control being fixed at 160 pixels, then when allocating layout space, the fixed height portion is first deducted, and the remaining 600 minus 160 = 440 pixels is proportionally distributed among the other three child controls, ensuring the integrity and consistency of the layout. By recursively calculating and processing various layout constraints, the structural stability of complex interfaces during cross-screen scaling is guaranteed.
[0136] For example, in the GNOME desktop environment of the open Kylin operating system, the user connects an ultrawide monitor with a resolution of 3840 x 1080, physical dimensions of 886 mm x 249 mm, and a pixel density of approximately 110 pixels per inch. The system automatically calculates a scaling factor based on the pixel density: 110 divided by 96, approximately 1.15. However, GNOME only supports standard scaling factors such as 1.0, 1.25, and 1.5. The system adjusts the scaling factor to the closest value, 1.25. Step S322 reads the scaling-factor key value of org.gnome.desktop.interface through gsettings to obtain a scaling factor of 1.25. The application window is displayed on the ultrawide screen, and step S333 uses a scaling factor of 1.25 when calculating the rendering size of each element. The window contains a toolbar with eight horizontally arranged toolbar buttons, each with a logical pixel width of 40 pixels and a button spacing of 8 pixels. At a scaling factor of 1.25, each button is rendered with a width of 40 x 1.25 = 50 pixels, the button spacing is 8 x 1.25 = 10 pixels, and the total toolbar width is 8 x 50 + 7 x 10 = 470 pixels. Due to the ample horizontal resolution of the ultrawide screen, the toolbar occupies a reasonable proportion on the screen, each button is clearly distinguishable, and the spacing is appropriate, conforming to the user's visual and operational habits. By accurately applying the system-adjusted standard scaling factor, the interface is ensured to display correctly on non-standard resolution monitors.
[0137] Through the above technical solution, this invention achieves accurate adaptive rendering of Qt applications in a multi-monitor mixed DPI environment of a domestic operating system, solving problems such as cross-screen blurring, layout misalignment, and lack of dynamic response in traditional solutions, significantly improving the clarity and consistency of the user interface, and providing reliable technical support for cross-platform application development under the domestic operating system ecosystem.
[0138] The process described in S4, which involves listening to system font scaling change events and performing coordinated scaling rendering of fonts, icons, and layouts in the application interface based on the system scaling factor and the screen scaling factor, includes: Step S41: Register a listener for the system-set font configuration change signal through the inter-process communication mechanism.
[0139] Step S411: Identify the inter-process communication protocol type used by the desktop environment based on the currently running domestic operating system. Read the operating system identification file, extract the distribution name and version number, and match this information with the pre-stored desktop environment mapping table to determine the desktop environment type used by the current system. Tongxin UOS system corresponds to the Deepin desktop environment, Galaxy Kylin system corresponds to the UKUI desktop environment, and ZTE NewStart system corresponds to the customized GNOME environment. Different desktop environments use different configuration management mechanisms: the Deepin desktop environment exposes configuration interfaces through the D-Bus message bus, the UKUI desktop environment configures system management display parameters through GSettings, and the customized GNOME environment supports both D-Bus and DConf configuration backends. After identifying the desktop environment type, select the corresponding inter-process communication protocol and establish a communication channel with the system configuration service.
[0140] Step S412: For desktop environments using the D-Bus message bus, connect to the system-level D-Bus session bus and subscribe to the font configuration service's property change signal. Create a D-Bus connection object, specifying the connection target as the system session bus, and query the object path of the font configuration service by the bus name. The font configuration service in the Deepin desktop environment is registered under the bus name com.deepin.daemon.Appearance, with the object path / com / deepin / daemon / Appearance and the interface name com.deepin.daemon.Appearance. Subscribe to the PropertiesChanged signal to this interface, specifying to listen for changes to the FontSize property in the signal filtering rules. When a system user adjusts the font scaling ratio through the control center, the font configuration service broadcasts the PropertiesChanged signal on the D-Bus bus, with the signal payload containing the changed property name and new value. By subscribing to this signal, applications can receive notifications instantly when the font configuration changes, without polling the system configuration file.
[0141] Step S413: For desktop environments using the GSettings configuration system, create a configuration mode object and listen for changes in configuration key values related to font scaling. Initialize the GSettings client library and load the org.ukui.desktop.interface configuration mode, which defines the interface display parameters of the UKUI desktop environment. Locate the scaling-factor configuration key in the configuration mode; this key stores the current system's font scaling factor, with a value range of 0.75 to 3.0. Call the signal connection method of the configuration mode object to bind the changed signal to a custom callback function. When the value of the scaling-factor key changes, the GSettings background daemon will trigger the changed signal, passing the changed key name and new value as parameters to the callback function. This mechanism allows applications to passively receive real-time updates to the system configuration without actively querying, reducing processor resource consumption caused by polling.
[0142] Step S414: For desktop environments that support multiple configuration backends simultaneously, establish a multi-channel listening mechanism and set priority arbitration rules. Create D-Bus and GSettings listeners respectively and register them to the event loop. Set the priority of the D-Bus listener to be higher than that of the GSettings listener. When both listeners simultaneously capture font configuration change events, the value provided by the D-Bus listener will be used first. This design takes into account the possibility of incomplete configuration migration during the upgrade process of some domestic operating systems. As the native configuration channel of the desktop environment, the D-Bus interface usually has higher data accuracy than the compatibility configuration system. At the same time, maintain an event deduplication cache, recording the most recently processed font scaling value and timestamp. When a duplicate event with the same value is received within 100 milliseconds, the subsequent event is discarded to avoid unnecessary interface redraw operations.
[0143] In one embodiment, the listener registration process in the deep desktop environment is as follows: First, the D-Bus introspection mechanism is used to query whether the com.deepin.daemon.Appearance service is available. An introspection request is sent to the system session bus to obtain a list of all interfaces and methods exposed by the service. After confirming the existence of the Appearance interface, the Properties property set of the interface is read, and the FontSize property is verified to be in the property list. A signal matching rule is constructed, with the rule string containing the filter conditions of signal type PropertiesChanged, interface name com.deepin.daemon.Appearance, and object path / com / deepin / daemon / Appearance. The add matching method of the D-Bus connection object is called to register the matching rule to the bus daemon and associate it with the signal handling function. In the signal handling function, the payload data of the PropertiesChanged signal is parsed. The payload data is a dictionary structure, where the key is the changed property name and the value is the new value of the property. When the FontSize key is detected, its corresponding floating-point value is extracted, which represents the user-defined font size in points. This value is compared with the system's baseline font size to calculate the relative scaling factor. The baseline font size is usually 11 points. If the user sets it to 16.5 points, the scaling factor is 1.5.
[0144] In one embodiment, the listener registration process in the UKUI desktop environment is as follows: When loading the GSettings configuration mode, it first checks whether the mode file exists in the system configuration directory, typically / usr / share / glib-2.0 / schemas / . It then iterates through all XML configuration files in this directory, searching for the file containing the org.ukui.desktop.interface mode definition. The XML file content is parsed to extract the default value and value range constraints of the scaling-factor key. The default value is 1.0, the minimum value is 0.75, the maximum value is 3.0, and the step value is 0.25. A GSettings object is created and bound to the mode, and the object's connection method is called to register a listener for the changed signal. In the listener callback function, it first verifies whether the key name triggering the signal is scaling-factor, then calls the get method to read the current value of the key, returning a double-precision floating-point number. The obtained scaling factor is compared with the previous scaling factor maintained internally by the application. If the difference is greater than 0.01, a valid change is considered to have occurred, triggering the subsequent font recalculation process. This threshold judgment mechanism can filter out minor fluctuations caused by floating-point precision errors, avoiding frequent invalid updates.
[0145] Step S42: Obtain the font scaling change event captured by the listener.
[0146] When the listener receives a font configuration change signal, it extracts font scaling-related parameters from the signal payload. The parameter type varies depending on the desktop environment's configuration format. For the D-Bus signal, it reads the floating-point value corresponding to the FontSize key from the dictionary-structured payload, or the scaling factor from the ScaleFactor key. For the GSettings signal, it directly obtains the current value of the scaling-factor key. The extracted values are stored in an event object, which contains an event type identifier indicating a font scaling change, an event source identifier indicating a system configuration service, and the specific scaling value. This event object is then placed in the application's event queue, awaiting processing by the main thread's event loop.
[0147] Step S43: In response to the font scaling change event, recalculate the pixel size of the applied font based on the system scaling factor.
[0148] Step S431: Extract the system scaling factor value from the font scaling change event and determine the screen scaling factor of the screen where the current application window is located. The system scaling factor reflects the global font magnification factor specified by the user in the system settings, and this value applies to all applications. The screen scaling factor reflects the ratio of the physical DPI of a specific display to the standard DPI, which is defined as 96. Query the screen information interface provided by the window manager to obtain the physical width, physical height, pixel width, and pixel height of the screen where the current window is located. Calculate the actual DPI of the screen based on the physical and pixel dimensions using the formula: pixel width divided by physical width multiplied by 25.4, yielding the horizontal DPI. The calculation method for the vertical DPI is the same. Take the average of the horizontal and vertical DPI as the overall DPI of the screen, and divide this value by 96 to obtain the screen scaling factor.
[0149] Step S432: Iterate through all UI elements in the application that use fonts and obtain the currently set font object for each element. The font object contains attributes such as font family name, font style, font weight, and font size. The unit for font size may be points or pixels, which needs to be distinguished according to the unit attribute of the font object. Points are a device-independent typographic unit, 1 point equals 1 / 72 inch, while pixels are a device-dependent display unit, whose physical size depends on the screen DPI. If the font size unit is points, it needs to be converted to pixels for accurate rendering on the screen.
[0150] Step S433: For font objects whose font size unit is points, convert the point value to a base pixel value. The conversion formula is: base pixel value equals point value × 96 ÷ 72. This formula is based on the assumption that the standard DPI is 96, and one point corresponds to 1.333 pixels at the standard DPI.
[0151] For example, when the font size is 12 points, the baseline pixel value is 12 multiplied by 96 and divided by 72, resulting in 16 pixels. This baseline pixel value represents the pixel height that the font should occupy on a standard DPI display.
[0152] Step S434: Calculate the final rendered pixel value based on the system scaling factor and the screen scaling factor. The calculation formula is: the final rendered pixel value equals the base pixel value multiplied by the system scaling factor, and then multiplied by the screen scaling factor. The system scaling factor reflects the user's subjective magnification needs, while the screen scaling factor reflects the objective physical characteristics of the display device. The product of the two constitutes the complete scaling factor.
[0153] For example, if the base pixel value is 16, the system scaling factor is 1.5, and the screen scaling factor is 1.25, then the final rendered pixel value is 16 multiplied by 1.5 multiplied by 1.25, resulting in 30. This value indicates that the font should occupy 30 physical pixels in height on the actual screen to ensure that the font remains clearly readable on high-DPI screens.
[0154] Step S435: Set the calculated final rendered pixel value to the new pixel size of the font object and update the font object's unit attribute to pixels. Call the font object's set method, passing in the new pixel size and unit identifier. The font rendering engine will regenerate the glyph cache based on the new parameters. The glyph cache contains bitmap data for each character in the font at a specific size. Updating the cache will cause the new glyphs to be used for rendering in the next drawing.
[0155] Step S436: For the vector icon resources in the interface, recalculate the rendering size of the icons based on the system scaling factor and the screen scaling factor. Vector icons are usually stored in SVG format, and their size is defined in logical units rather than fixed pixels. Read the original logical width and logical height of the icon, multiply the logical size by the system scaling factor and the screen scaling factor to obtain the rendering pixel size of the icon.
[0156] For example, if the icon's logical size is 24 x 24, the system scaling factor is 1.5, and the screen scaling factor is 1.25, then the rendered pixel size will be 24 x 1.5 x 1.25, with a width and height of 45 pixels each. A vector graphics rendering library is called to re-rasterize the icon according to the new pixel size, generating a high-resolution bitmap cache.
[0157] Step S437: For bitmap icon resources in the interface, select an appropriate icon scaling version based on the system scaling factor and screen scaling factor. Bitmap icons are usually prepared in multiple resolution versions, labeled as 1x, 1.5x, 2x, and 3x. Calculate the required total scaling factor using the formula: total scaling factor equals system scaling factor multiplied by screen scaling factor. Compare the total scaling factor with preset scaling levels and select the scaling version that is closest to and not less than the total scaling factor.
[0158] For example, if the total scaling factor is 1.875, then select the icon version with a 2x scaling factor. Load the icon file with the selected scaling factor, replace the icon display content in the interface elements, and ensure that the icons still maintain clear edges after scaling, avoiding blurring or jagged edges.
[0159] Step S438: For the layout containers and control margins in the interface, recalculate the layout parameters based on the system scaling factor and screen scaling factor. Layout parameters include the spacing between controls, the inner margins of containers, and the minimum size constraints of controls. Read the original spacing values of the layout objects, which are typically defined in logical pixels. Multiply the original spacing values by the system scaling factor and screen scaling factor to obtain the physical pixel spacing that should be used during actual rendering.
[0160] For example, if the original spacing is 8 logical pixels, the system scaling factor is 1.5, and the screen scaling factor is 1.25, then the actual spacing is 8 multiplied by 1.5 multiplied by 1.25, resulting in 15 physical pixels. Calling the layout object's set method updates all spacing parameters, and the layout engine recalculates the position and size of child controls based on the new parameters, triggering a UI re-layout process.
[0161] Step S439: An update request is sent to the application's main window object, triggering a complete redraw of the window content. The redraw process traverses the window's control tree, calling the drawing method of each control in turn. Each drawing method uses the updated font object, icon resources, and layout parameters for rendering. The rendering result is output to the window's drawing buffer, and the contents of the drawing buffer are ultimately passed to the display server, which composites them into the screen's framebuffer. The interface seen by the user on the screen is the final effect after scaling adjustments; all text, icons, and layout elements are enlarged or reduced by a uniform scaling factor, maintaining visual consistency.
[0162] In one embodiment, the application runs on the Tongxin UOS system, with a system-configured font size of 14 points. The user adjusts the font size to 21 points via the control center. The Deepin Desktop environment's font configuration service broadcasts a PropertiesChanged signal on the D-Bus, changing the value of the FontSize attribute in the signal payload from 14 to 21. The application's D-Bus listener captures this signal, extracts the new font size value of 21 points, and calculates the system scaling factor as 21 divided by 14, resulting in 1.5. The application's current window is located on a monitor with physical dimensions of 508 mm x 285.75 mm and a resolution of 3840 x 2160. Based on the physical dimensions and resolution, the horizontal DPI is calculated as 3840 divided by 508 and then multiplied by 25.4, resulting in approximately 192. The vertical DPI calculation yields the same result. The overall screen DPI is 192, and the screen scaling factor is 192 divided by 96, resulting in 2.0. A label control in the application has a font size of 12 points. The base pixel value is 12 x 96 x 72, resulting in 16 pixels. The final rendered pixel value is 16 x 1.5 x 2.0, resulting in 48 pixels. The font object's pixel size is updated to 48, and the font rendering engine regenerates the glyph cache for this size. A button in the application uses an icon with a logical size of 24 x 24. The rendered pixel size is 24 x 1.5 x 2.0, resulting in 72 x 72. The vector icon is rasterized to a size of 72 pixels, and the resulting high-resolution bitmap is set as the button's icon content. A vertical layout container in the application has an original spacing of 8 logical pixels. The actual spacing is 8 x 1.5 x 2.0, resulting in 24 physical pixels. The layout engine rearranges the controls within the container according to the new spacing, and the vertical distance between the controls becomes 24 pixels. The main window triggers a complete redraw, and all controls are rendered using the scaled parameters. In the interface that the user sees on the screen, the text size, icon size, and control spacing are all enlarged by a total scaling factor of 3, and the interface elements are clearly displayed on the high-resolution screen with harmonious proportions.
[0163] In one embodiment, the application runs on a Kylin OS, and the user adjusts the font scaling from 1.0 to 1.25 through system settings. The GSettings configuration system's scaling-factor key changes its value from 1.0 to 1.25, triggering a changed signal. The application's GSettings listener captures this signal, reads the new scaling factor of 1.25, and uses it as the system scaling factor. The application's current window is located on a standard monitor with physical dimensions of 345.44 mm x 194.31 mm and a resolution of 1920 x 1080. The horizontal DPI is calculated as 1920 divided by 345.44 multiplied by 25.4, resulting in approximately 141; the vertical DPI calculation yields the same result. The overall screen DPI is 141, and the screen scaling factor is 141 divided by 96, resulting in approximately 1.47. A text edit box in the application has its font set to 10 points, and the base pixel value is 10 multiplied by 96 divided by 72, resulting in approximately 13.33 pixels. The final rendered pixel value is 13.33 multiplied by 1.25 multiplied by 1.47, resulting in approximately 24.48 pixels, rounded to 24 pixels. The font object's pixel size is updated to 24, and the text in the text editing box is rendered according to the new size. A bitmap icon used in a toolbar within the application is pre-prepared in 1x and 2x scaling versions. The total scaling factor is calculated as 1.25 multiplied by 1.47, resulting in approximately 1.84. The 2x scaling version of the icon is selected, the 2x scaling icon file is loaded, and the toolbar button's display content is replaced. The original spacing of a horizontal layout container in the application is 12 logical pixels; the actual spacing is 12 multiplied by 1.25 multiplied by 1.47, resulting in approximately 22.05 pixels, rounded to 22 pixels. The layout engine rearranges the buttons within the container according to the new spacing, and the horizontal distance between the buttons becomes 22 pixels. The main window triggers a complete redraw, and all interface elements are rendered using scaled parameters. The size of text and icons in the interface seen by the user on the screen is appropriately increased, and the interface elements remain clear and readable on a normal DPI screen without appearing too crowded.
[0164] It's important to note that intermediate results need to be rounded during font pixel size calculations to avoid blurry character edges caused by non-integer pixel values. After the final rendered pixel value calculation is complete, if the result is a floating-point number, it is rounded to the nearest integer. The rounding rule is: round up if the decimal part is greater than or equal to 0.5, and round down if it is less than 0.5. This rounding strategy ensures that the character is aligned to the pixel grid during rasterization while maintaining scaling accuracy, avoiding color edge distortion caused by subpixel rendering.
[0165] It's important to note that when an application window moves between multiple monitors, the changes in the screen it's on need to be detected in real-time. The rendering sizes of fonts and icons are then recalculated based on the new screen's scaling factor. The system listens for screen change events and repeats steps S431 to S439 within the event handler, replacing the original parameters with the new screen's DPI parameters to ensure that interface elements maintain correct display even after cross-screen movement. This dynamic adaptation mechanism solves the interface consistency problem in multi-monitor DPI scenarios. When users drag an application window from a low-DPI screen to a high-DPI screen, they immediately see a clear magnification of interface elements without blurring or pixelation.
[0166] Specifically, when generating the glyph cache, the font rendering engine locates the installed font files based on the font's pixel size and font family name. It then parses the vector outline data from the font files and rasterizes the vector outlines according to the specified pixel size, generating a bitmap representation for each character. The rasterization process employs an anti-aliasing algorithm, using grayscale values or sub-pixel color values to smooth transitions at glyph edges, improving the visual quality of the glyphs. The generated bitmap data is stored in the glyph cache, indexed by character encoding and font size. Subsequent rendering of the same character directly reads the bitmap data from the cache, avoiding redundant rasterization calculations and improving rendering performance.
[0167] Specifically, the rasterization process for vector icons is handled by a vector graphics rendering library. The library parses the path data, fill color, stroke width, and other drawing instructions from the SVG file, constructs a scene graph of the vector graphics in memory, calculates the coordinate transformation matrix of the scene graph based on the specified rendering pixel size, and converts the vector path into rasterized pixel data. The rasterization process also employs anti-aliasing techniques, using multisampling or oversampling methods at the graphic edges to reduce jagged edges and moiré patterns, ensuring smooth edges on the icon at any scaling factor. The bitmap data generated by rasterization is cached in an icon cache, indexed by the icon path and rendering size, to avoid repeated rasterization operations on the same icon.
[0168] Specifically, when recalculating control positions and sizes, the layout engine iterates through the list of child controls in the layout container, reads the sizing strategy, minimum size, maximum size, and preferred size of each child control, and calculates the actual width and height of each child control based on the available space in the container and the size constraints of the child controls. For horizontal layout containers, child controls are arranged from left to right, with specified horizontal spacing inserted between them. The vertical position of the child controls is determined by the alignment method, which can be top alignment, bottom alignment, or center alignment. For vertical layout containers, child controls are arranged from top to bottom, with specified vertical spacing inserted between them. The horizontal position of the child controls is determined by the alignment method. After the layout calculation is complete, the set geometry method for each child control is called, passing in the calculated position and size parameters. The child control updates its internal drawing area according to the new geometry parameters, preparing for subsequent redrawing operations.
[0169] Through the above steps, the application can automatically adjust the rendering parameters of fonts, icons, and layout after receiving system font scaling change events, achieving coordinated scaling of interface elements. This ensures that the user interface maintains a clear, harmonious, and consistent visual effect under different DPI screens and different scaling settings, solving the DPI adaptation problem of Qt applications on domestic operating systems and improving user experience and cross-platform compatibility of the software.
[0170] The method described in S4, which involves listening to system font scaling change events and performing coordinated scaling rendering of fonts, icons, and layouts in the application interface based on the system scaling factor and the screen scaling factor, further includes: Step S44: Obtain the vector image resource in the application interface, and scale the vector image resource proportionally according to the system scaling factor to obtain the target vector image resource.
[0171] Step S441: Traverse the control tree structure of the application interface to identify all image resources using vector image format. In the Qt application, recursively traverse all child controls using the `children` method of `QWidget`, checking the `icon`, `pixmap`, or `stylesheet` properties of each control to extract the referenced image resource paths. For each image resource, read the file header identifier to determine its format type. When the file header contains an XML declaration tag in SVG format, mark the resource as a vector image resource. Simultaneously, record the reference location of the resource in the interface, including the object pointer of the associated control, the attribute name, and the coordinate information in the layout. During the traversal, build a list of vector image resources, where each entry contains the resource's file path, original logical size, and a list of controls referencing the resource.
[0172] Step S442: Parse the scalable vector graphics data structure of the vector image resource. Read the XML content of the SVG file, locate the `viewBox` attribute of the root node, which defines the logical coordinate system and bounding box of the vector graphics. Extract the width and height values from the `viewBox` as the base logical dimensions of the vector image. Parse the path elements, shape elements, and text elements in the SVG document, and identify the size attributes that use absolute units. When elements are found to use absolute units such as pixels or centimeters, convert them to percentage units relative to the `viewBox` to ensure that the vector image maintains proportional consistency at any scaling factor. For SVG resources containing embedded bitmaps, extract the bitmap data referenced by the `image` element and mark them as hybrid resources requiring special processing.
[0173] Step S443: Calculate the target rendering size of the vector image. Multiply the base logical size of the vector image by the system scaling factor to obtain the physical pixel size that the resource should display in the current screen environment.
[0174] In one embodiment, if the base logical width is 48, the base logical height is 48, and the system scaling factor is 1.5, then the target rendering width is 72 physical pixels and the target rendering height is 72 physical pixels. For applications displayed on high-resolution screens, when the system scaling factor is 2.0, the same vector image will be rendered to a size of 96 by 96 physical pixels, ensuring that the image has the same visual size in different DPI environments.
[0175] Step S444: The vector graphics rendering engine is invoked to perform real-time rasterization processing on the vector image resources. The parsed SVG data is loaded using Qt's QSvgRenderer class, and a QImage object matching the target rendering size is created as the rendering target. The pixel format of the rendering target is set to ARGB32, ensuring support for alpha channels and anti-aliasing. The render method of QSvgRenderer is called, passing in the rendering target and target size parameters, to perform rasterization conversion of the vector path. Subpixel rendering is enabled during rasterization, multisampling is performed on the edges of the vector path, and the color value and transparency of each pixel are calculated.
[0176] In one embodiment, for icons containing curved paths, the Bézier curve equation is discretized into multiple straight lines, each no longer than 0.5 physical pixels, to ensure the smoothness of the curve on high-DPI screens. After rendering, the generated bitmap data is cached in memory, and a mapping relationship from the vector resource path to the rendered bitmap is established.
[0177] Step S445: For the DPI differences of different screens, generate multiple sets of rendering results for the same vector image. Iterate through all display devices in the application's runtime environment and obtain the screen scaling factor for each display. For each screen scaling factor, repeat steps S443 and S444 to generate the rendering bitmap at that scaling factor. In a multi-display mixed DPI scenario, when the main screen scaling factor is 1.0 and the secondary screen scaling factor is 2.0, the same vector icon will be rendered as two sets of bitmap resources: 48x48 and 96x96. The rendering results at different scaling factors are stored in a hierarchical cache structure, with the outer index being the screen device identifier and the inner index being the vector resource path. When the application window moves between different screens, the corresponding scaling rendering bitmap is directly retrieved from the cache based on the target screen's device identifier, avoiding repeated rasterization calculations.
[0178] Step S45: Obtain multi-magnification bitmap image resources from the application interface, and match the target bitmap image resource from the multi-magnification bitmap image resources according to the system scaling factor.
[0179] Step S451: Scan the application resource directory to identify a set of bitmap image files that conform to the multi-magnification naming convention. Examine the filenames of all PNG, JPG, and other bitmap format files in the resource directory, identifying filename patterns containing magnification identifiers. When filenames end with suffixes such as @1x, @2x, or @3x, they are categorized as multi-magnification bitmap resources. Extract the base name from the filename after removing the magnification identifier, using it as the identifier key for that bitmap resource group. For multiple files with the same base name, create an ordered list based on the numerical value of the magnification identifier.
[0180] In one embodiment, when three files—icon_button.png, icon_button@2x.png, and icon_button@3x.png—exist in the resource directory, they are grouped into the same resource group with the base name "icon_button" and the scaling factor lists as 1.0, 2.0, and 3.0. Simultaneously, the complete path and file size of each scaling factor file are recorded to create a multi-scaling bitmap resource index table.
[0181] Step S452: Calculate the optimal matching magnification corresponding to the current system scaling factor. Compare the system scaling factor with all available magnifications in the resource group, and select the magnification with the closest value and not less than the system scaling factor as the target magnification. When the system scaling factor is 1.5 and the available magnifications in the resource group are 1.0 and 2.0, select 2.0 as the target magnification to ensure image sharpness is prioritized. When the system scaling factor is 2.5 and the maximum available magnification in the resource group is 3.0, select 3.0 to avoid blurring caused by using low-magnification resources. If the system scaling factor is greater than all available magnifications, select the highest magnification resource, and then perform upscaling processing using an interpolation algorithm. If the system scaling factor is less than the lowest available magnification, select the lowest magnification resource, and then perform downsampling processing.
[0182] Step S453: Extract the corresponding bitmap file from the multi-magnification bitmap resource group based on the matched target magnification. In the multi-magnification bitmap resource index table, use the base name and target magnification as the lookup key to obtain the complete path of the corresponding bitmap file. Load the bitmap file using Qt's QPixmap class, reading the raw pixel data of the bitmap into memory. Check whether the actual pixel size of the bitmap matches the expectation; the expected pixel size should be equal to the base logical size multiplied by the target magnification.
[0183] In one embodiment, with a base logical size of 32x32 and a target scaling factor of 2.0, the actual pixel size of the loaded bitmap should be 64x64. If the actual size does not match the expectation, a resource exception log is recorded, and the bitmap is marked as requiring size correction.
[0184] Step S454: Set the device pixel ratio for the target bitmap resource. Call the `setDevicePixelRatio` method of `QPixmap`, passing in the target scaling factor as a parameter, to mark the ratio between the logical size and physical size of the bitmap. After setting the device pixel ratio, the Qt rendering engine will automatically divide the physical pixel size by the device pixel ratio when drawing the bitmap to obtain the logical size it occupies in the interface layout.
[0185] In one embodiment, a 64x64 physical pixel bitmap, with a device pixel ratio set to 2.0, will be displayed as a 32x32 logical pixel size in the interface, consistent with the baseline logical size. This approach ensures that the bitmap is rendered at high resolution on high-DPI screens while maintaining the correct logical size in layout calculations, avoiding abnormal control sizes.
[0186] Step S455: For cases where there is a difference between the target magnification and the system scaling factor, interpolation adjustments are made to the bitmap resources. The ratio of the target magnification to the system scaling factor is calculated. When the ratio is not equal to 1.0, the bitmap needs to be scaled. When the ratio is greater than 1.0, bicubic interpolation is used to downsample the bitmap, reducing the high-magnification bitmap to the size corresponding to the system scaling factor. When the ratio is less than 1.0, Lanzos interpolation is used to upsample the bitmap, enlarging the low-magnification bitmap to the size corresponding to the system scaling factor.
[0187] In one embodiment, with a system scaling factor of 1.8, a target scaling factor of 2.0, and a ratio of 1.11, a 64x64 pixel bitmap is downsampled to generate an adjusted 58x58 pixel bitmap, ensuring that the actual display size of the image on the screen precisely matches the system scaling factor. The adjusted bitmap replaces the originally loaded bitmap, and the device pixel ratio is updated to the system scaling factor, completing the precise adaptation of the bitmap resource.
[0188] Step S46: Generate a redraw instruction based on the recalculated pixel size of the applied font, the target vector image resource, and the target bitmap image resource.
[0189] Step S461: Collect all UI elements that need updating and their latest rendering parameters. Traverse the application's UI control tree, checking each control for text content, icon resources, or child controls that need to be rearranged. For controls containing text, record their text content string and the recalculated font pixel size. For controls containing icons, associate the memory address of the target vector image resource or target bitmap image resource they reference. For container controls, record the new layout position and size of their child controls. Organize this information into a UI element update list, where each entry contains a control object pointer, element type, old rendering parameters, and new rendering parameters.
[0190] Step S462: Construct a rendering operation sequence based on the UI element update list. Sort the update list according to the hierarchy and drawing order of controls in the interface, ensuring that the redraw operation of parent controls is executed before that of child controls. For each control that needs to be updated, generate corresponding rendering operation instructions based on its element type. For text elements, generate font update instructions and text redraw instructions, with instruction parameters including the new font pixel size, font family, and text content. For icon elements, generate image replacement instructions, with instruction parameters including the memory address of the target image resource and the coordinates of the rendering area. For layout elements, generate geometric transformation instructions, with instruction parameters including the new position coordinates and new size of the control. Organize all generated rendering operation instructions into an instruction queue according to the execution order, with the first instruction executed at the head of the queue and the last instruction executed at the tail.
[0191] Step S463: Insert batch optimization markers into the rendering operation sequence. Analyze consecutive similar-type instructions in the instruction queue to identify instruction groups that can be merged for execution. When multiple consecutive controls perform the same type of image replacement operation, and their image resources come from the same cache page, insert a batch start marker before this group of instructions and a batch end marker after the last instruction. When the rendering engine executes a batch marker, it loads all image resources within the marker range into the graphics processor's video memory at once, reducing the number of data transfers between the CPU and GPU.
[0192] In one embodiment, when the interface contains 20 icon controls that need to have their images replaced, and the target bitmap resources of these icons are all located on the same cache page, the 20 independent image transfer operations are merged into one batch transfer by batch processing, which significantly reduces the latency of the rendering process.
[0193] Step S464: Add local refresh region information to the rendering operation sequence. For each rendering operation in the instruction queue, calculate the bounding box of the screen area affected by the operation. The bounding box is determined by the position coordinates, width, and height of the control, and is represented as the coordinates of the top-left and bottom-right corners of a rectangular area. Traverse the bounding boxes of all rendering operations, calculate the union of adjacent or overlapping bounding boxes, and merge multiple small areas into a larger refresh region. Independent areas with an interval distance less than a preset threshold are also merged to avoid generating too many fragmented refresh regions.
[0194] In one embodiment, the bounding boxes of the two controls have top-left corner coordinates of 100, 150 and 120, 170 respectively, and bottom-right corner coordinates of 150, 200 and 170, 220 respectively. When the horizontal distance between them is 20 pixels, if the preset threshold is 30 pixels, the two bounding boxes are merged into a unified refresh area. The merged area has top-left corner coordinates of 100, 150 and bottom-right corner coordinates of 170, 220. The coordinate range of each refresh area is recorded in the rendering operation sequence to guide the rendering engine to redraw only the changed areas, keeping the pixel content of the unchanged areas unchanged.
[0195] Step S465 generates a redraw instruction data structure containing the rendering operation sequence and refresh area information. A redraw instruction object is created, containing an operation instruction queue, a refresh area list, a target window handle, and a timestamp attribute. The operation instruction queue stores all rendering operations and their parameters generated in step S462, and the refresh area list stores all screen areas that need to be redrawn calculated in step S464. The target window handle points to the top-level window object of the current application and is used to locate the rendering target. The timestamp records the generation time of the redraw instruction and is used for frame synchronization control of the rendering engine. The redraw instruction object is serialized into a compact binary format to reduce the memory footprint of the instructions, facilitating subsequent transmission and parsing.
[0196] Step S44: Redraw the application interface according to the redraw instructions to obtain the target application interface. Submit the redraw instructions to the rendering engine's instruction processing queue, and the rendering engine executes the rendering operations one by one according to the order of the instruction queue. For font update instructions, call Qt's font rendering interface to update the font attributes of the control, triggering the recalculation of the text layout. For image replacement instructions, copy the pixel data of the target image resource to the drawing buffer of the control, and update the display content of the control. For geometric transformation instructions, modify the layout parameters of the control in the parent container, triggering the adjustment of the control's position and size. After all rendering operations are completed, for each refresh area, call the window system's drawing interface to copy the pixel data of that area from the application's back buffer to the screen's foreground buffer, completing the visual update of the interface. In a multi-monitor environment, if the application window spans multiple screens, perform independent redraw processing on the window area of each screen, using the corresponding screen's scaling parameters and rendering resources to ensure that the interface presents a clear and consistent display effect on screens with different DPIs.
[0197] In one possible implementation, for a Qt application running on the UnionTech UOS system, when the system scaling factor is adjusted from 1.0 to 1.5, the application interface includes three types of image resources: title bar icons, toolbar buttons, and content areas. The title bar icons use SVG vector format with an original logical size of 24x24. Step S443 calculates the target rendering size to be 36x36 physical pixels, and QSvgRenderer is used to generate a 36x36 bitmap. Subpixel anti-aliasing is applied in step S444 to ensure smooth icon edges. The toolbar buttons use multi-scale PNG resources, with resource groups containing @1x and @2x scaling. Step S452 selects the @2x resource, loads a 64x64 physical pixel bitmap, and then performs bicubic interpolation downsampling in step S455 to 48x48 pixels, precisely adapting to the 1.5x scaling. The text font in the content area is recalculated from 12 points to 18 pixels to maintain the same proportion as the icon size change. The rendering operation sequence generated in step S462 includes 3 image replacement instructions and 15 text redraw instructions. Step S464 calculates three refresh rectangles for the title bar area, toolbar area, and content area. After redrawing in step S44, the application interface is clearly displayed in a 1.5x DPI environment, and the font and icon sizes are consistent. Users can see the interface adjustment effect without restarting the application.
[0198] It should be noted that in the multi-monitor environment of the Galaxy Kylin operating system, the main screen has a resolution of 1920 x 1080 with a scaling factor of 1.0, and the secondary screen has a resolution of 3840 x 2160 with a scaling factor of 2.0. When an application window is dragged from the main screen to the secondary screen, the vector image cache generated in step S445 for both screens comes into play. The vector icon uses a 48 x 48 pixel cached bitmap on the main screen. After moving to the secondary screen, the rendering engine directly extracts a 96 x 96 pixel cached bitmap without re-performing rasterization calculations, and the interface remains smooth during window movement. At the same time, the multi-scale bitmap resources identified in step S451 automatically switch to the @2x version on the secondary screen. The device pixel ratio set in step S454 ensures that the logical size of the bitmap in the layout remains unchanged, with only the physical rendering resolution increasing, avoiding the problem of abrupt control size changes caused by cross-screen transitions in traditional solutions. The partial refresh mechanism in step S464 only redraws images and text elements when the window spans multiple screens, while the layout framework remains unchanged, reducing unnecessary rendering overhead. This differentiated screen adaptation capability ensures the display quality of the application in mixed DPI environments.
[0199] Specifically, for application scenarios involving complex icon combinations, such as toolbars in graphics editing software, step S441, during the traversal of the control tree, identifies dozens of mixed use cases of vector icon resources and multi-scale bitmap resources. Some tool buttons use SVG icons to support lossless scaling, while some status indicators use PNG sequence frames to provide animation effects. During SVG parsing in step S442, some icons containing embedded bitmap textures are detected and marked as mixed resources. Subsequently, in the rasterization process of step S444, vector paths and embedded bitmaps are processed separately. The vector portion is rendered according to the system scaling factor, while the embedded bitmap portion is interpolated according to the ratio of its original resolution to the scaling factor. In the multi-scale bitmap resources identified in step S451, the animation sequence frames need to ensure that the scaling factor selection is consistent across all frames. In step S452, when matching the target scaling factor, all frame files in the same animation resource group are uniformly assigned the same scaling factor to avoid size jumps during playback. The batch processing optimization in step S463 targets consecutively arranged icon buttons in the toolbar, merging the image data of 20 icons into a single GPU texture upload operation. Combined with the overall toolbar refresh area calculated in step S464, efficient rendering is achieved when the interface is scaled. The entire redrawing process is completed within 16 milliseconds, meeting the requirement of smooth display at 60 frames per second. This collaborative processing mechanism for complex interfaces significantly improves the user experience of Qt applications under the domestic operating system environment.
[0200] In practical implementation, it will be integrated with domestically developed operating systems and hardware: Deeply integrated desktop environment: By listening to the ScaleFactorChanged signal of DDE / UKUI through D-Bus, it achieves second-level response to DPI changes without restarting the application.
[0201] GPU rendering pipeline optimization: In Qt's OpenGL or Vulkan backend, this method encapsulates the 'logical pixel → physical pixel' mapping calculation into a unified transformation matrix in the vertex shader. This matrix is dynamically updated by the current screen scaling factor, and the vertex coordinates of all UI elements are transformed from logical pixels to physical pixels on the GPU side, eliminating the need for calculations on the CPU side by traversing controls one by one. Simultaneously, the mapping calculation results are directly written to the GPU vertex buffer object (VBO), achieving upload once, reuse multiple times, effectively reducing the overhead of CPU-side scaling calculations and data copying.
[0202] Adapted for domestic GPU drivers: The anti-aliasing parameters have been fine-tuned to suit the rendering characteristics of domestic GPUs such as Jingjia Micro and Zhaoxin, avoiding blurry lines at high DPI.
[0203] The above are merely preferred embodiments of the present invention and do not limit the scope of the patent. Any equivalent structural or procedural transformations made based on the description and drawings of the present invention, or direct or indirect applications in other related technical fields, are similarly included within the scope of patent protection of the present invention.
Claims
1. A DPI adaptive method for Qt applications on domestic operating systems, characterized in that, include: Obtain the currently running operating system type, display protocol, and desktop environment information; Based on the operating system type, the display protocol, and the desktop environment information, a system scaling factor is obtained through a multi-source detection mechanism. This mechanism queries multiple detection sources according to a preset priority order. A mapping relationship between logical pixels and physical pixels is established based on the system scaling factor, and an independent screen scaling factor is maintained for each display screen. System font scaling change events are monitored, and the fonts, icons, and layout in the application interface are collaboratively scaled and rendered based on the system scaling factor and the screen scaling factor.
2. The method as described in claim 1, characterized in that, The step of obtaining the currently running operating system type, display protocol, and desktop environment information includes: reading the system distribution identification file and determining the operating system type based on the field information in the system distribution identification file; reading system environment variables and determining the display protocol based on the display server configuration parameters in the system environment variables; and reading the current user's session process information and determining the desktop environment information based on the desktop component identifier in the session process information.
3. The method as described in claim 2, characterized in that, The step of reading the system distribution identifier file and determining the operating system type based on the field information in the system distribution identifier file includes: obtaining a preset system distribution identifier file path; opening the corresponding text file according to the system distribution identifier file path; reading the key-value pair data in the text file line by line and extracting the numeric string corresponding to a specific key name; matching the numeric string according to a preset operating system type mapping table to obtain the successfully matched operating system type.
4. The method as described in claim 1, characterized in that, The step of obtaining the system scaling factor through a multi-source detection mechanism based on the operating system type, the display protocol, and the desktop environment information includes: determining the corresponding desktop bus interface based on the desktop environment information; reading first configuration data through the desktop bus interface; determining whether a compliant first scaling factor exists in the first configuration data; if the first scaling factor exists, determining the first scaling factor as the system scaling factor; if the first configuration data does not contain a compliant first scaling factor, determining the corresponding system-level configuration interface based on the operating system type; reading second configuration data through the system-level configuration interface; determining whether a compliant second scaling factor exists in the second configuration data; if the second scaling factor exists, determining the second scaling factor as the system scaling factor; if the second configuration data does not contain a compliant second scaling factor, determining the corresponding native display protocol interface based on the display protocol; reading third configuration data through the native display protocol interface; determining whether a compliant third scaling factor exists in the third configuration data; if the third scaling factor exists, determining the third scaling factor as the system scaling factor; if the third configuration data does not contain a compliant third scaling factor, obtaining a pre-set baseline scaling factor and determining the baseline scaling factor as the system scaling factor.
5. The method as described in claim 1, characterized in that, The step of establishing a mapping relationship from logical pixels to physical pixels based on the system scaling factor and maintaining an independent screen scaling factor for each display screen includes: obtaining the physical pixel size of each user interface element in the application interface, calculating the logical pixel size of each user interface element based on the physical pixel size and the system scaling factor, wherein the logical pixel size is independent of the pixel density of the display device; obtaining the identification information of all display screens connected to the current device, obtaining the screen scaling factor corresponding to each display screen, and establishing a mapping table between the identification information and the screen scaling factor; obtaining the initial identification information of the initial display screen where the current application window is located, querying the initial screen scaling factor corresponding to the initial identification information according to the mapping table, and calculating the initial rendering physical pixel size based on the logical pixel size and the initial screen scaling factor; obtaining the current application window movement event, obtaining the target identification information of the target display screen based on the movement event, querying the target screen scaling factor corresponding to the target identification information according to the mapping table, and calculating the target rendering physical pixel size based on the logical pixel size and the target screen scaling factor.
6. The method as described in claim 1, characterized in that, The process of listening for system font scaling change events and performing collaborative scaling rendering of fonts, icons, and layouts in the application interface based on the system scaling factor and the screen scaling factor includes: registering a listener for system-set font configuration change signals through an inter-process communication mechanism; acquiring font scaling change events captured by the listener; and recalculating the pixel size of the application font based on the system scaling factor in response to the font scaling change events.
7. The method as described in claim 1, characterized in that, The method of listening to system font scaling change events and performing collaborative scaling rendering of fonts, icons, and layouts in the application interface according to the system scaling factor and the screen scaling factor also includes: acquiring vector image resources in the application interface, scaling the vector image resources proportionally according to the system scaling factor to obtain target vector image resources; acquiring multi-magnification bitmap image resources in the application interface, matching target bitmap image resources from the multi-magnification bitmap image resources according to the system scaling factor; generating redraw instructions based on the recalculated pixel size of the application font, the target vector image resources, and the target bitmap image resources, and redrawing the application interface according to the redraw instructions to obtain the target application interface.
