Skip to content

Commit

Permalink
On Wayland, fix rounding issue in resizes
Browse files Browse the repository at this point in the history
  • Loading branch information
kchibisov committed Mar 2, 2023
1 parent 644c47a commit 41e524f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 10 additions & 2 deletions src/platform_impl/linux/wayland/event_loop/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -385,7 +386,7 @@ impl<T: 'static> EventLoop<T> {
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(
Expand Down Expand Up @@ -430,7 +431,7 @@ impl<T: 'static> EventLoop<T> {
} 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)
};

Expand Down Expand Up @@ -599,3 +600,10 @@ impl<T: 'static> EventLoop<T> {
.map_err(|error| error.into())
}
}

// The default routine does floor, but we need round on Wayland.
fn logical_to_physical_rounded(size: LogicalSize<u32>, scale_factor: f64) -> PhysicalSize<u32> {
let width = size.width as f64 * scale_factor;
let height = size.height as f64 * scale_factor;
(width.round(), height.round()).into()
}

0 comments on commit 41e524f

Please sign in to comment.