From f597f71e9bc2959c580d6c10441249a2a2f61282 Mon Sep 17 00:00:00 2001 From: podulator Date: Thu, 26 Nov 2026 10:15:31 +0100 Subject: [PATCH 1/2] X11: port the fix for repeated suggested scale factors (#358) to next handle_host_suggest_scale_factor() converted the current physical size back to logical pixels with a scale of 1.0 instead of the scale in use, so a second suggested scale compounded on the first. #358 fixed this on master after next branched; this is the same change on next. --- src/platform/x11/sizing.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/platform/x11/sizing.rs b/src/platform/x11/sizing.rs index 9df1b3d1..da4f0833 100644 --- a/src/platform/x11/sizing.rs +++ b/src/platform/x11/sizing.rs @@ -111,6 +111,7 @@ impl SizingState { pub fn handle_host_suggest_scale_factor( &self, scale: f64, handler: &Handler, shared: &WindowShared, ) -> Result { + let previous_scale = shared.sizing_state.scale_factor(); shared.sizing_state.host_suggested_scale_factor.set(Some(scale)); // If the scaling factor is already provided by the system, do nothing @@ -118,7 +119,7 @@ impl SizingState { return Ok(false); }; - let current_logical_size = shared.sizing_state.size().to_logical::(1.0); + let current_logical_size = shared.sizing_state.size().to_logical::(previous_scale); let new_physical_size = current_logical_size.to_physical(scale); shared.sizing_state.resize_from_host(new_physical_size, handler, shared)?; From fd173224775361ddabd401f726de8187bd011f6e Mon Sep 17 00:00:00 2001 From: podulator Date: Thu, 26 Nov 2026 10:23:47 +0100 Subject: [PATCH 2/2] X11: a host's suggested scale factor takes precedence over Xft.dpi for embedded windows A window with a parent is a host's child (a plug-in's editor, say), and the host knows the scale its own UI is drawn at, which Xft.dpi, one value for the whole X display, may not match (a Wayland-native host, per-monitor scaling). CLAP's set_scale() is documented to override any OS info. Windows without a parent keep the current order: Xft.dpi first, then the suggestion. The window's first size now uses the same rule as scale_factor(), so they agree from the start. --- host/src/window.rs | 4 +++- src/platform/x11/sizing.rs | 35 +++++++++++++++++++++++------------ src/window.rs | 4 +++- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/host/src/window.rs b/host/src/window.rs index ce784ea9..73113b46 100644 --- a/host/src/window.rs +++ b/host/src/window.rs @@ -70,7 +70,9 @@ pub trait HostedWindow { /// /// On Win32, this value is used if running on early versions of Windows 10 (or earlier). /// - /// On X11, this value is used if no `Xft.dpi`setting is set. + /// On X11, for a window embedded in a parent (e.g. a plug-in's editor), this value takes + /// precedence over the `Xft.dpi` setting. For other windows, it is used if no `Xft.dpi` + /// setting is set. /// /// On macOS, this function is always a no-op, and always returns `false`. fn suggest_fallback_scale_factor(&self, scale_factor: f64) -> Result>; diff --git a/src/platform/x11/sizing.rs b/src/platform/x11/sizing.rs index da4f0833..953c90b5 100644 --- a/src/platform/x11/sizing.rs +++ b/src/platform/x11/sizing.rs @@ -107,15 +107,17 @@ impl SizingState { } /// Returns whether the suggested scale factor is now the one in use (`false` if the system - /// provides its own, which takes precedence). + /// provides its own, which takes precedence for a window that has no parent). pub fn handle_host_suggest_scale_factor( &self, scale: f64, handler: &Handler, shared: &WindowShared, ) -> Result { let previous_scale = shared.sizing_state.scale_factor(); shared.sizing_state.host_suggested_scale_factor.set(Some(scale)); - // If the scaling factor is already provided by the system, do nothing - if shared.sizing_state.system_scale_factor.get().is_some() { + // If the scaling factor is already provided by the system, do nothing, unless the window + // is embedded: then the host's scale takes precedence + if !shared.sizing_state.parented && shared.sizing_state.system_scale_factor.get().is_some() + { return Ok(false); }; @@ -133,12 +135,18 @@ pub struct SizingStateShared { system_scale_factor: Cell>, host_suggested_scale_factor: Cell>, + /// Whether the window is embedded in a parent (e.g. a plug-in's editor). Then the host's + /// suggested scale takes precedence over the system's: the host knows the scale its own UI is + /// drawn at, which `Xft.dpi` (one value for the whole X display) may not match. + parented: bool, } impl SizingStateShared { pub fn load(connection: &X11Connection, settings: &WindowSettings) -> Result { let scaling = connection.resources.xft_dpi.map(|dpi| dpi as f64 / 96.0); - let initial_scale_factor = scaling.unwrap_or(1.0); + let parented = settings.parent.is_some(); + let initial_scale_factor = + Self::pick_scale_factor(parented, scaling, settings.fallback_scale_factor); let sizing_strategy = SizingStrategy::from_settings(settings); let window_size = settings.size.to_physical(initial_scale_factor); @@ -148,19 +156,22 @@ impl SizingStateShared { window_size: window_size.into(), system_scale_factor: scaling.into(), host_suggested_scale_factor: settings.fallback_scale_factor.into(), + parented, }) } pub fn scale_factor(&self) -> f64 { - if let Some(factor) = self.system_scale_factor.get() { - return factor; - }; - - if let Some(factor) = self.host_suggested_scale_factor.get() { - return factor; - } + Self::pick_scale_factor( + self.parented, + self.system_scale_factor.get(), + self.host_suggested_scale_factor.get(), + ) + } - 1.0 + /// The system's scale factor first, then the host's suggestion; the other way round for an + /// embedded window. 1.0 if neither is known. + fn pick_scale_factor(parented: bool, system: Option, host: Option) -> f64 { + if parented { host.or(system) } else { system.or(host) }.unwrap_or(1.0) } pub fn size(&self) -> PhysicalSize { diff --git a/src/window.rs b/src/window.rs index 2737e42d..40bb96f1 100644 --- a/src/window.rs +++ b/src/window.rs @@ -112,7 +112,9 @@ impl Window { /// /// On Win32, this value is used if running on early versions of Windows 10 (or earlier). /// - /// On X11, this value is used if no `Xft.dpi`setting is set. + /// On X11, for a window embedded in a parent (e.g. a plug-in's editor), this value takes + /// precedence over the `Xft.dpi` setting. For other windows, it is used if no `Xft.dpi` + /// setting is set. /// /// On macOS, this function is always a no-op, and always returns `false`. #[inline]