The truly free, open-source, local-first, cross-platform CapCut replacement. Scriptable through a JSON-RPC API & MCP.
Rust ffmpegfree-video-editormodel-context-protocolnon-linear-editoroffline-firstopen-source-video-editorself-hostedvideo-editingvideo-editing-automationvideo-editing-softwarevideo-editing-toolsvideo-editorvoice-cloningyoutube-automationyoutube-shorts
fix(settings): Interface scale multiplies the display's scale, not replaces it (#320)
Jareerfa651efea51c
diff --git a/src/crates/concat/src/lib.rs b/src/crates/concat/src/lib.rsindex bbb29375..f66090e7 100644--- a/src/crates/concat/src/lib.rs+++ b/src/crates/concat/src/lib.rs@@ -181,27 +181,14 @@ pub(crate) fn close_window(/// [`run_with_project`], or [`smoke`] when `smoke` is set.fn start(project: Option<std::path::PathBuf>, smoke: bool) -> Result<(), slint::PlatformError> {- // The interface scale is read by Slint's window backend when the window- // is made, so it has to be in the environment before the backend is- // asked to make one - earlier than the studio, which is where the- // preferences are normally read. A remembered scale overrides the- // display's own; nothing remembered leaves an inherited- // SLINT_SCALE_FACTOR alone, so a value set by hand still wins.- // https://github.com/jub0t/Concat/issues/320- if std::env::var_os("SLINT_SCALE_FACTOR").is_none()- && let Ok(dirs) = concat_host::AppDirs::locate()- && let Some(percent) = prefs::Preferences::load(&dirs).ui_scale- && prefs::UI_SCALES.contains(&percent)- {- // SAFETY: the process is single-threaded here - the backend, the- // engine's threads and the window all come after this function - so- // nothing reads the environment concurrently.- unsafe {- std::env::set_var(- "SLINT_SCALE_FACTOR",- prefs::Preferences::scale_factor(percent).to_string(),- );- }+ // The interface scale: a percent of the display's own, applied once+ // the window is up and kept through moves between monitors; see+ // `platform::apply_ui_scale`. https://github.com/jub0t/Concat/issues/320+ if let Ok(dirs) = concat_host::AppDirs::locate() {+ let percent = prefs::Preferences::load(&dirs)+ .ui_scale+ .filter(|percent| prefs::UI_SCALES.contains(percent));+ platform::set_ui_scale(percent);}let (startup_mark, safe) = safe_start();@@ -1525,15 +1512,11 @@ fn start(project: Option<std::path::PathBuf>, smoke: bool) -> Result<(), slint::}});// The interface scale is the one appearance choice a property cannot- // express: the backend takes it as a multiplier, from SLINT_SCALE_FACTOR- // when the window is made and from a scale-factor event at any time- // after. So the choice is written to the environment for the next window- // to open at, and the window that is up is rescaled in place - the- // factor handed to it, then the same physical extent laid out again in- // logical pixels, so the interface grows within the window rather than- // being clipped by it. Nothing is rebuilt; the window keeps its size on- // screen. "System" hands back the scale the platform itself reports,- // which winit knows whatever SLINT_SCALE_FACTOR last told Slint. The row+ // express: it is the window's scale factor. The window that is up is+ // rescaled in place to the display's own scale times the choice - the+ // same physical extent laid out again in logical pixels, so the+ // interface grows within the window rather than being clipped by it.+ // Nothing is rebuilt; the window keeps its size on screen. The row// reads its value off the Theme global, so that is set here too.// https://github.com/jub0t/Concat/issues/320app.on_settings_scale_changed({@@ -1547,39 +1530,8 @@ fn start(project: Option<std::path::PathBuf>, smoke: bool) -> Result<(), slint::studio.prefs.save(&studio.host.dirs);}app.global::<Theme>().set_ui_scale(index);- let window = app.window();- // SAFETY: the window's own thread owns the environment here.- unsafe {- match percent {- Some(percent) => std::env::set_var(- "SLINT_SCALE_FACTOR",- prefs::Preferences::scale_factor(percent).to_string(),- ),- None => std::env::remove_var("SLINT_SCALE_FACTOR"),- }- }- // The platform's own scale, for "System". On a phone the- // window is not winit's and there is no such thing to ask,- // so 1 is the answer, which is what the shell uses anyway.- #[cfg(not(target_os = "android"))]- let system = {- use slint::winit_030::WinitWindowAccessor;- window- .with_winit_window(|winit| winit.scale_factor())- .unwrap_or(1.0)- };- #[cfg(target_os = "android")]- let system = 1.0;- let factor = percent.map_or(system as f32, |percent| {- prefs::Preferences::scale_factor(percent) as f32- });- let physical = window.size();- window.dispatch_event(slint::platform::WindowEvent::ScaleFactorChanged {- scale_factor: factor,- });- window.dispatch_event(slint::platform::WindowEvent::Resized {- size: physical.to_logical(factor),- });+ platform::set_ui_scale(percent);+ platform::apply_ui_scale(app.window());});}});@@ -2089,6 +2041,11 @@ fn start(project: Option<std::path::PathBuf>, smoke: bool) -> Result<(), slint::}});+ // The chosen interface scale, as soon as the window is up.+ slint::Timer::single_shot(std::time::Duration::ZERO, || {+ Shell::with(|_, app| platform::apply_ui_scale(app.window()));+ });+let result = app.run();drop(reader_sweep);log::info!("close: event loop exited (ok={})", result.is_ok());diff --git a/src/crates/concat/src/platform.rs b/src/crates/concat/src/platform.rsindex a2b7754c..8d2344ff 100644--- a/src/crates/concat/src/platform.rs+++ b/src/crates/concat/src/platform.rs@@ -34,6 +34,72 @@ use slint::winit_030::winit::window::{Window as WinitWindow, WindowId};use slint::winit_030::{CustomApplicationHandler, EventResult};use crate::gpu::Gpu;++/// The interface scale the person chose, as a percent of the display's+/// own; 0 follows the display. See [`apply_ui_scale`].+static UI_SCALE: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(0);++/// Remembers the interface scale [`apply_ui_scale`] applies: a percent of+/// the display's own scale, or `None` for the display's.+pub fn set_ui_scale(percent: Option<u32>) {+ UI_SCALE.store(percent.unwrap_or(0), std::sync::atomic::Ordering::Relaxed);+}++/// Scales `window` to the display's own scale times the chosen percent.+///+/// Not through SLINT_SCALE_FACTOR, as it was: Slint takes that as the+/// whole factor, not a multiplier, and ignores the display's scale while+/// it is set, so "100 %" made the interface smaller on a Windows laptop at+/// 150 % and halved it on a Retina Mac, and moving the window to another+/// monitor no longer rescaled it. The display's scale is winit's, which no+/// dispatch here changes; this runs when the window first shows, when the+/// choice changes, and after every move to a monitor of another scale. A+/// SLINT_SCALE_FACTOR set by hand still wins, and then nothing is done.+/// https://github.com/jub0t/Concat/issues/320+#[cfg(not(target_os = "android"))]+pub fn apply_ui_scale(window: &slint::Window) {+ use slint::winit_030::WinitWindowAccessor;+ if std::env::var_os("SLINT_SCALE_FACTOR").is_some() {+ return;+ }+ let Some(native) = window.with_winit_window(|winit| winit.scale_factor()) else {+ return;+ };+ let percent = UI_SCALE.load(std::sync::atomic::Ordering::Relaxed);+ let chosen = if percent == 0 {+ 1.0+ } else {+ crate::prefs::Preferences::scale_factor(percent)+ };+ let factor = (native * chosen) as f32;+ if (window.scale_factor() - factor).abs() < 1e-3 {+ return;+ }+ log::info!("interface scale: the display's {native} times {chosen} is {factor}");+ let physical = window.size();+ window.dispatch_event(slint::platform::WindowEvent::ScaleFactorChanged {+ scale_factor: factor,+ });+ window.dispatch_event(slint::platform::WindowEvent::Resized {+ size: physical.to_logical(factor),+ });+}++/// A phone sets its size the system's way; there is nothing to scale.+#[cfg(target_os = "android")]+pub fn apply_ui_scale(_window: &slint::Window) {}++/// [`apply_ui_scale`] on the open window, once the event in hand is done:+/// Slint applies a display's own scale as it handles the event, and the+/// chosen percent goes on top of that afterwards.+#[cfg(not(target_os = "android"))]+fn reapply_ui_scale() {+ slint::Timer::single_shot(std::time::Duration::ZERO, || {+ crate::host::Shell::with(|_, app| {+ apply_ui_scale(slint::ComponentHandle::window(&app));+ });+ });+}/// The window's raw events, seen before Slint routes them. Two jobs:////// Dropped files. winit reports one path per event, in a burst, and the@@ -199,6 +265,7 @@ impl CustomApplicationHandler for DropHandler {self.wayland = listen_for_wayland_drops(window, &self.arrived);}match event {+ WindowEvent::ScaleFactorChanged { .. } => reapply_ui_scale(),WindowEvent::DroppedFile(path) => self.pending.push(path.clone()),WindowEvent::CursorMoved { position, .. } => {let scale = slint_window