diff --git a/apps/vectorcraft/Cargo.toml b/apps/vectorcraft/Cargo.toml index 1c3e7f39e7..cfcc85f487 100644 --- a/apps/vectorcraft/Cargo.toml +++ b/apps/vectorcraft/Cargo.toml @@ -11,7 +11,7 @@ workspace = true [features] default = ["wgpu", "accessibility"] -wgpu = ["eframe/wgpu", "dep:winsafe"] +wgpu = ["eframe/wgpu"] accessibility = ["eframe/accesskit"] [dependencies] @@ -45,7 +45,7 @@ winreg = "0.55" # GPU that shows it: drawing on a GPU without a monitor reset the display driver. Safe wrappers over # Win32 (MIT); the `user` feature is User32.dll only. Only the wgpu renderer chooses an adapter. -winsafe = { version = "0.0.29", default-features = false, features = ["user", "shell"], optional = true } +winsafe = { version = "0.0.29", default-features = false, features = ["user", "shell"] } # Waits for Direct3D 12's adapter list before the window starts (src/gpu.rs, #4150). MIT OR # Apache-2.0, already in the build through eframe. pollster = "1" diff --git a/apps/vectorcraft/src/window_system.rs b/apps/vectorcraft/src/window_system.rs index 97dc432b8a..3426a2a9a1 100644 --- a/apps/vectorcraft/src/window_system.rs +++ b/apps/vectorcraft/src/window_system.rs @@ -17,12 +17,24 @@ pub(super) fn monitor_layout(window: &Window) -> (Vec, Option) { let size = handle.size(); let size = [size.width, size.height]; let pos = handle.position(); - Monitor::new(MonitorKey::new(handle.name().unwrap_or_default(), size), [pos.x, pos.y], size, handle.scale_factor() as f32) + let monitor = Monitor::new(MonitorKey::new(handle.name().unwrap_or_default(), size), [pos.x, pos.y], size, handle.scale_factor() as f32); + #[cfg(windows)] + let monitor = windows_work_area(monitor, pos.x, pos.y); + monitor }) .collect(); (monitors, home) } +#[cfg(windows)] +fn windows_work_area(monitor: Monitor, x: i32, y: i32) -> Monitor { + use winsafe::{HMONITOR, POINT, co}; + let Ok(info) = HMONITOR::MonitorFromPoint(POINT { x, y }, co::MONITOR::DEFAULTTONULL).GetMonitorInfo() else { return monitor }; + let work = info.rcWork; + let (Ok(width), Ok(height)) = (u32::try_from(work.right - work.left), u32::try_from(work.bottom - work.top)) else { return monitor }; + monitor.with_work_px([work.left, work.top], [width, height]) +} + pub(super) struct DesktopWindows { window: Weak, monitors: Mutex)>>,