diff --git a/README.md b/README.md index 9b35d1b..a4710b3 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/README.zh-CN.md b/README.zh-CN.md index 0dd35a4..b8de928 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -149,6 +149,9 @@ uur display source virtual uur stop # 只停止 uur 助手与专用 Wine 前缀 ``` +从桌面启动 UU 后,可在启动器的应用操作菜单中选择“退出”;从终端运行时可执行 +`uur stop` 或按 Ctrl+C。 + 输入后端排错: ```bash diff --git a/locales/en.yml b/locales/en.yml index b177143..5e27656 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -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." diff --git a/locales/zh-CN.yml b/locales/zh-CN.yml index c1aadde..0510c8e 100644 --- a/locales/zh-CN.yml +++ b/locales/zh-CN.yml @@ -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: "无法访问网易官方发布接口" diff --git a/packaging/uur.desktop b/packaging/uur.desktop index 70638d1..f813b16 100644 --- a/packaging/uur.desktop +++ b/packaging/uur.desktop @@ -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 diff --git a/src/session.rs b/src/session.rs index fb71f7e..d2cb060 100644 --- a/src/session.rs +++ b/src/session.rs @@ -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 { + 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 { + resources.lines().find_map(|line| { + let (name, value) = line.split_once(':')?; + if name.trim() != "Xft.dpi" { + return None; + } + let dpi = value.trim().parse::().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( diff --git a/src/wine.rs b/src/wine.rs index 8ad4d27..c4a78db 100644 --- a/src/wine.rs +++ b/src/wine.rs @@ -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::>(); + assert_eq!( + args, + [ + "reg", + "add", + r"HKCU\Control Panel\Desktop", + "/v", + "LogPixels", + "/t", + "REG_DWORD", + "/d", + "192", + "/f", + ] + ); + } }