Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 32 additions & 21 deletions apps/desktop-gpui/src/editor_sidebar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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**
Expand Down Expand Up @@ -1953,30 +1954,33 @@ pub(crate) fn decode_wallpaper_thumbnail(id: &str) -> Option<Arc<RenderImage>> {
/// 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
Expand Down Expand Up @@ -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();
Expand Down
22 changes: 21 additions & 1 deletion apps/desktop-gpui/src/platform/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,27 @@ pub fn copy_image_bytes_to_clipboard(bytes: &[u8], _cx: &gpui::App) -> Result<()
}

pub fn desktop_picture_path() -> Option<PathBuf> {
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 {
Expand Down
Loading