diff --git a/apps/desktop-gpui/src/editor_sidebar.rs b/apps/desktop-gpui/src/editor_sidebar.rs index 73afc538eaa..b913e7554b2 100644 --- a/apps/desktop-gpui/src/editor_sidebar.rs +++ b/apps/desktop-gpui/src/editor_sidebar.rs @@ -196,6 +196,7 @@ pub const BACKGROUND_IMAGE_EXTENSIONS: [&str; 6] = ["jpg", "jpeg", "png", "gif", pub const CURRENT_DESKTOP_BACKGROUND_BASENAME: &str = "current-desktop-background"; /// `recording.rs:92-93`. const DESKTOP_BACKGROUND_MAX_DIMENSION: u32 = 2560; +#[cfg(target_os = "macos")] const DESKTOP_BACKGROUND_JPEG_QUALITY: u8 = 82; /// The sidebar's fallback border/shadow objects. The UI's numbers, **not** @@ -1953,30 +1954,33 @@ pub(crate) fn decode_wallpaper_thumbnail(id: &str) -> Option> { /// re-encoding to JPEG at quality 82. The `sips` path matters -- macOS ships /// HEIC wallpapers the `image` crate cannot decode. fn write_desktop_background_snapshot(source: &Path, output: &Path) -> Result<(), String> { - let needs_downscale = image::image_dimensions(source).is_ok_and(|(width, height)| { - width > DESKTOP_BACKGROUND_MAX_DIMENSION || height > DESKTOP_BACKGROUND_MAX_DIMENSION - }); - - let mut command = std::process::Command::new("sips"); - command - .arg("-s") - .arg("format") - .arg("jpeg") - .arg("-s") - .arg("formatOptions") - .arg(DESKTOP_BACKGROUND_JPEG_QUALITY.to_string()); - if needs_downscale { - command - .arg("-Z") - .arg(DESKTOP_BACKGROUND_MAX_DIMENSION.to_string()); - } - if let Ok(output_status) = command.arg(source).arg("--out").arg(output).output() - && output_status.status.success() + #[cfg(target_os = "macos")] { - return Ok(()); + let needs_downscale = image::image_dimensions(source).is_ok_and(|(width, height)| { + width > DESKTOP_BACKGROUND_MAX_DIMENSION || height > DESKTOP_BACKGROUND_MAX_DIMENSION + }); + + let mut command = std::process::Command::new("sips"); + command + .arg("-s") + .arg("format") + .arg("jpeg") + .arg("-s") + .arg("formatOptions") + .arg(DESKTOP_BACKGROUND_JPEG_QUALITY.to_string()); + if needs_downscale { + command + .arg("-Z") + .arg(DESKTOP_BACKGROUND_MAX_DIMENSION.to_string()); + } + if let Ok(output_status) = command.arg(source).arg("--out").arg(output).output() + && output_status.status.success() + { + return Ok(()); + } } - let decoded = cap_gpui_kernels::codec::open_image(source) + let decoded = cap_gpui_kernels::codec::decode_image_file(source) .map_err(|err| format!("failed to decode desktop background: {err}"))?; let decoded = if decoded.width() > DESKTOP_BACKGROUND_MAX_DIMENSION || decoded.height() > DESKTOP_BACKGROUND_MAX_DIMENSION @@ -2426,6 +2430,13 @@ impl EditorWindow { } Err(error) => { tracing::error!("couldn't import your desktop wallpaper: {error}"); + cx.spawn(async move |_, _| { + crate::platform::alert_dialog( + "Couldn't import your desktop wallpaper", + &error, + ); + }) + .detach(); } } cx.notify(); diff --git a/apps/desktop-gpui/src/platform/windows.rs b/apps/desktop-gpui/src/platform/windows.rs index 60ef53662d6..407ed3dc8fd 100644 --- a/apps/desktop-gpui/src/platform/windows.rs +++ b/apps/desktop-gpui/src/platform/windows.rs @@ -660,7 +660,27 @@ pub fn copy_image_bytes_to_clipboard(bytes: &[u8], _cx: &gpui::App) -> Result<() } pub fn desktop_picture_path() -> Option { - None + use std::ffi::OsString; + use std::os::windows::ffi::OsStringExt; + use windows_sys::Win32::UI::WindowsAndMessaging::{ + SPI_GETDESKWALLPAPER, SystemParametersInfoW, + }; + + let mut buffer = vec![0u16; 32_768]; + let success = unsafe { + SystemParametersInfoW( + SPI_GETDESKWALLPAPER, + buffer.len() as u32, + buffer.as_mut_ptr().cast(), + 0, + ) + }; + if success == 0 { + tracing::warn!(error = %std::io::Error::last_os_error(), "failed to read desktop wallpaper path"); + return None; + } + let length = buffer.iter().position(|character| *character == 0)?; + (length > 0).then(|| PathBuf::from(OsString::from_wide(&buffer[..length]))) } pub fn set_activation_policy(_regular: bool) -> bool {