fix(desktop): improve HiDPI and exit integration

This commit is contained in:
Xuc Pan committed 2026-09-25 03:04:51 +08:00
1 parent 2b41541128
commit 9f12a88a08
7 files changed
+114

No files matched your search

+4
View File
@@ -154,6 +154,10 @@ uur display source virtual
uur stop # Stop only uur's helpers and Wine prefix
```
If UU was started from the desktop, choose **Quit** from the launcher's
application actions. When running from a terminal, use `uur stop` or press
Ctrl+C.
Diagnostic input overrides:
```bash
+3
View File
@@ -149,6 +149,9 @@ uur display source virtual
uur stop # 只停止 uur 助手与专用 Wine 前缀
```
从桌面启动 UU 后,可在启动器的应用操作菜单中选择“退出”;从终端运行时可执行
`uur stop` 或按 Ctrl+C。
输入后端排错:
```bash
+1
View File
@@ -55,6 +55,7 @@ session:
webview_failed: "WebView2 installation failed"
quick_launch_ready: "%{count} Linux applications exported to UU Quick Launch"
audio_backend: "Wine audio backend: %{backend}"
wine_dpi: "Wine system DPI set from Xft.dpi: %{dpi}"
setup:
eula_prompt: "The official UU Remote client will be downloaded from NetEase and is governed by their EULA: %{url}\nRe-run with --accept-eula to continue."
+1
View File
@@ -43,6 +43,7 @@ session:
webview_failed: "WebView2 安装失败"
quick_launch_ready: "已向 UU 快速启动导出 %{count} 个 Linux 应用"
audio_backend: "Wine 音频后端:%{backend}"
wine_dpi: "已根据 Xft.dpi 设置 Wine 系统 DPI:%{dpi}"
upstream:
unreachable: "无法访问网易官方发布接口"
+7
View File
@@ -9,6 +9,13 @@ Comment[zh_CN]=在本 Linux 桌面启动完整的 UU 远程会话
Exec=uur run
TryExec=uur
Icon=uur
StartupWMClass=gameviewer.exe
Terminal=false
Categories=Network;RemoteAccess;
Keywords=remote;desktop;uu;网易;远程;
Actions=Quit;
[Desktop Action Quit]
Name=Quit
Name[zh_CN]=退出
Exec=uur stop
+39
View File
@@ -345,6 +345,12 @@ pub fn start() -> Result<()> {
let prefix = data_dir()?.join("wine");
let install_dir = crate::wine::find_client_dir(&prefix)
.context("client not provisioned; run `uur setup` first")?;
if let Some(dpi) = xft_dpi() {
match crate::wine::set_log_pixels(&prefix, dpi) {
Ok(()) => println!("{}", t!("session.wine_dpi", dpi = dpi)),
Err(error) => eprintln!("could not sync Wine DPI from Xft.dpi: {error}"),
}
}
deploy_hooks(&prefix)?;
crate::wine::set_dll_override(&prefix, "wtsapi32", "native")?;
// Re-apply migrations on every launch so an updated uur package repairs
@@ -714,6 +720,25 @@ fn wait_for_runtime_file(path: &Path, stopping: &AtomicBool) -> Result<()> {
anyhow::bail!("native terminal bridge did not become ready")
}
fn xft_dpi() -> Option<u32> {
let resources = run_with_timeout(
Command::new("xrdb").arg("-query"),
std::time::Duration::from_secs(2),
)?;
parse_xft_dpi(&resources)
}
fn parse_xft_dpi(resources: &str) -> Option<u32> {
resources.lines().find_map(|line| {
let (name, value) = line.split_once(':')?;
if name.trim() != "Xft.dpi" {
return None;
}
let dpi = value.trim().parse::<f64>().ok()?;
(dpi.is_finite() && (96.0..=480.0).contains(&dpi)).then(|| dpi.round() as u32)
})
}
fn stop_wineserver(prefix: &Path) {
let _ = Command::new("wineserver")
.env("WINEPREFIX", prefix)
@@ -730,6 +755,20 @@ mod tests {
use super::*;
use std::ffi::OsStr;
#[test]
fn parses_xft_dpi_resources() {
assert_eq!(parse_xft_dpi("Xft.antialias: 1\nXft.dpi: 192\n"), Some(192));
assert_eq!(parse_xft_dpi("Xft.dpi: 168.4\n"), Some(168));
}
#[test]
fn ignores_invalid_xft_dpi_resources() {
assert_eq!(parse_xft_dpi("Xft.dpi: 72\n"), None);
assert_eq!(parse_xft_dpi("Xft.dpi: 500\n"), None);
assert_eq!(parse_xft_dpi("Xft.dpi: automatic\n"), None);
assert_eq!(parse_xft_dpi("Xft.antialias: 192\n"), None);
}
#[test]
fn webview2_installer_uses_builtin_wow64_dlls() {
let command = webview2_install_command(
+59
View File
@@ -239,6 +239,39 @@ pub fn set_dll_override(prefix: &Path, name: &str, mode: &str) -> Result<()> {
Ok(())
}
pub fn set_log_pixels(prefix: &Path, dpi: u32) -> Result<()> {
let status = log_pixels_command(prefix, dpi)
.status()
.context("setting the Wine system DPI")?;
if !status.success() {
anyhow::bail!("Wine rejected the system DPI value {dpi}");
}
Ok(())
}
fn log_pixels_command(prefix: &Path, dpi: u32) -> Command {
let mut command = Command::new("wine");
command
.env("WINEPREFIX", prefix)
.env("WINEDEBUG", wine_debug())
.args([
"reg",
"add",
r"HKCU\Control Panel\Desktop",
"/v",
"LogPixels",
"/t",
"REG_DWORD",
"/d",
&dpi.to_string(),
"/f",
])
.stdin(Stdio::null())
.stdout(Stdio::null())
.stderr(Stdio::null());
command
}
fn wine_debug() -> String {
std::env::var("WINEDEBUG").unwrap_or_else(|_| "-all".to_string())
}
@@ -422,7 +455,9 @@ fn purge_wine_shortcuts() {
#[cfg(test)]
mod tests {
use super::log_pixels_command;
use super::registry_compat_entries;
use std::path::Path;
#[test]
fn bundled_cpp_runtime_is_preferred_for_both_uu_processes() {
@@ -436,4 +471,28 @@ mod tests {
assert!(values.contains(&("msvcp140", "REG_SZ", "native,builtin")));
}
}
#[test]
fn system_dpi_command_writes_winecfg_logpixels_value() {
let command = log_pixels_command(Path::new("/tmp/wine-prefix"), 192);
let args = command
.get_args()
.map(|arg| arg.to_string_lossy().into_owned())
.collect::<Vec<_>>();
assert_eq!(
args,
[
"reg",
"add",
r"HKCU\Control Panel\Desktop",
"/v",
"LogPixels",
"/t",
"REG_DWORD",
"/d",
"192",
"/f",
]
);
}
}