diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d5ac771..a36f8f27 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ And please only add new entries to the top of this list, right below the `# Unre - On macOS, set resize increments only for live resizes. - On Wayland, fix rare crash on DPI change - Web: Added support for `Window::theme`. +- On Wayland, fix rounding issues when doing resize. # 0.28.1 diff --git a/src/platform_impl/linux/wayland/event_loop/mod.rs b/src/platform_impl/linux/wayland/event_loop/mod.rs index 5a4c7e2c..84540f6c 100644 --- a/src/platform_impl/linux/wayland/event_loop/mod.rs +++ b/src/platform_impl/linux/wayland/event_loop/mod.rs @@ -19,6 +19,7 @@ use sctk::environment::Environment; use sctk::seat::pointer::{ThemeManager, ThemeSpec}; use sctk::WaylandSource; +use crate::dpi::{LogicalSize, PhysicalSize}; use crate::event::{Event, StartCause, WindowEvent}; use crate::event_loop::{ControlFlow, EventLoopWindowTarget as RootEventLoopWindowTarget}; use crate::platform_impl::platform::sticky_exit_callback; @@ -385,7 +386,7 @@ impl EventLoop { let window_size = window_compositor_update.size.unwrap_or(*size); *size = window_size; - window_size.to_physical(scale_factor) + logical_to_physical_rounded(window_size, scale_factor) }); sticky_exit_callback( @@ -430,7 +431,7 @@ impl EventLoop { } else { *window_size = size; let scale_factor = window_handle.scale_factor(); - let physical_size = size.to_physical(scale_factor); + let physical_size = logical_to_physical_rounded(size, scale_factor); Some(physical_size) }; @@ -599,3 +600,10 @@ impl EventLoop { .map_err(|error| error.into()) } } + +// The default routine does floor, but we need round on Wayland. +fn logical_to_physical_rounded(size: LogicalSize, scale_factor: f64) -> PhysicalSize { + let width = size.width as f64 * scale_factor; + let height = size.height as f64 * scale_factor; + (width.round(), height.round()).into() +}