diff --git a/src-tauri/src/lib_commands/app_api/core.rs b/src-tauri/src/lib_commands/app_api/core.rs index 86b45976..0254a01d 100644 --- a/src-tauri/src/lib_commands/app_api/core.rs +++ b/src-tauri/src/lib_commands/app_api/core.rs @@ -11,51 +11,6 @@ pub(crate) fn exit_app(app_handle: tauri::AppHandle) { app_handle.exit(0); } -/// Toggle native window decorations at runtime (Linux custom title bar opt-out). -#[tauri::command] -pub(crate) fn set_window_decorations(enabled: bool, app_handle: tauri::AppHandle) { - if let Some(win) = app_handle.get_webview_window("main") { - let _ = win.set_decorations(enabled); - // Re-enabling native decorations on GTK causes the window manager to - // re-stack the window, which drops focus. Bring it back immediately. - if enabled { - let _ = win.set_focus(); - } - } -} - -/// WebKitGTK: `enable-smooth-scrolling` also drives deferred / kinetic wheel scrolling. -#[cfg(target_os = "linux")] -pub(crate) fn linux_webkit_apply_smooth_scrolling(win: &tauri::WebviewWindow, enabled: bool) -> Result<(), String> { - win.with_webview(move |platform| { - use webkit2gtk::{SettingsExt, WebViewExt}; - if let Some(settings) = platform.inner().settings() { - settings.set_enable_smooth_scrolling(enabled); - } - }) - .map_err(|e| e.to_string()) -} - -/// Called from the frontend settings toggle (Linux); no-op on other platforms. -#[tauri::command] -pub(crate) fn set_linux_webkit_smooth_scrolling(enabled: bool, app_handle: tauri::AppHandle) -> Result<(), String> { - #[cfg(target_os = "linux")] - { - use tauri::Manager; - // Each WebviewWindow has its own WebKitGTK Settings — main-only left the - // mini player on the default (inertial) wheel until the user toggled again. - for label in ["main", "mini"] { - if let Some(win) = app_handle.get_webview_window(label) { - linux_webkit_apply_smooth_scrolling(&win, enabled)?; - } - } - } - #[cfg(not(target_os = "linux"))] - { - let _ = (enabled, app_handle); - } - Ok(()) -} #[tauri::command] pub(crate) fn set_logging_mode(mode: String) -> Result<(), String> { diff --git a/src-tauri/src/lib_commands/app_api/mod.rs b/src-tauri/src/lib_commands/app_api/mod.rs index c23a227e..a7a95881 100644 --- a/src-tauri/src/lib_commands/app_api/mod.rs +++ b/src-tauri/src/lib_commands/app_api/mod.rs @@ -4,6 +4,7 @@ mod cli_bridge; mod core; mod navidrome; mod perf; +mod platform; mod remote; mod integration; mod analysis; @@ -12,6 +13,7 @@ pub(crate) use cli_bridge::*; pub(crate) use core::*; pub(crate) use navidrome::*; pub(crate) use perf::*; +pub(crate) use platform::*; pub(crate) use remote::*; pub(crate) use integration::*; pub(crate) use analysis::*; diff --git a/src-tauri/src/lib_commands/app_api/platform.rs b/src-tauri/src/lib_commands/app_api/platform.rs new file mode 100644 index 00000000..cc48946e --- /dev/null +++ b/src-tauri/src/lib_commands/app_api/platform.rs @@ -0,0 +1,49 @@ +//! Native-window + WebKitGTK platform tweaks exposed as Tauri commands. + +use super::*; + +/// Toggle native window decorations at runtime (Linux custom title bar opt-out). +#[tauri::command] +pub(crate) fn set_window_decorations(enabled: bool, app_handle: tauri::AppHandle) { + if let Some(win) = app_handle.get_webview_window("main") { + let _ = win.set_decorations(enabled); + // Re-enabling native decorations on GTK causes the window manager to + // re-stack the window, which drops focus. Bring it back immediately. + if enabled { + let _ = win.set_focus(); + } + } +} + +/// WebKitGTK: `enable-smooth-scrolling` also drives deferred / kinetic wheel scrolling. +#[cfg(target_os = "linux")] +pub(crate) fn linux_webkit_apply_smooth_scrolling(win: &tauri::WebviewWindow, enabled: bool) -> Result<(), String> { + win.with_webview(move |platform| { + use webkit2gtk::{SettingsExt, WebViewExt}; + if let Some(settings) = platform.inner().settings() { + settings.set_enable_smooth_scrolling(enabled); + } + }) + .map_err(|e| e.to_string()) +} + +/// Called from the frontend settings toggle (Linux); no-op on other platforms. +#[tauri::command] +pub(crate) fn set_linux_webkit_smooth_scrolling(enabled: bool, app_handle: tauri::AppHandle) -> Result<(), String> { + #[cfg(target_os = "linux")] + { + use tauri::Manager; + // Each WebviewWindow has its own WebKitGTK Settings — main-only left the + // mini player on the default (inertial) wheel until the user toggled again. + for label in ["main", "mini"] { + if let Some(win) = app_handle.get_webview_window(label) { + linux_webkit_apply_smooth_scrolling(&win, enabled)?; + } + } + } + #[cfg(not(target_os = "linux"))] + { + let _ = (enabled, app_handle); + } + Ok(()) +}