mirror of
https://github.com/rust-windowing/winit.git
synced 2026-06-27 15:13:13 -04:00
On Wayland, add support for fractional scaling
This adds support for the fractional scaling on Wayland via the wp-fractional-scale protocol. Co-authored-by: Julian Orth <ju.orth@gmail.com>
This commit is contained in:
@@ -374,10 +374,11 @@ impl<T: 'static> EventLoop<T> {
|
||||
});
|
||||
|
||||
for (window_id, window_compositor_update) in window_compositor_updates.iter_mut() {
|
||||
if let Some(scale_factor) = window_compositor_update.scale_factor.map(|f| f as f64)
|
||||
{
|
||||
if let Some(scale_factor) = window_compositor_update.scale_factor {
|
||||
let mut physical_size = self.with_state(|state| {
|
||||
let window_handle = state.window_map.get(window_id).unwrap();
|
||||
*window_handle.scale_factor.lock().unwrap() = scale_factor;
|
||||
|
||||
let mut size = window_handle.size.lock().unwrap();
|
||||
|
||||
// Update the new logical size if it was changed.
|
||||
@@ -409,6 +410,15 @@ impl<T: 'static> EventLoop<T> {
|
||||
if let Some(size) = window_compositor_update.size.take() {
|
||||
let physical_size = self.with_state(|state| {
|
||||
let window_handle = state.window_map.get_mut(window_id).unwrap();
|
||||
|
||||
if let Some(fs_state) = window_handle.fractional_scaling_state.as_ref() {
|
||||
// If we have a viewport then we support fractional scaling. As per the
|
||||
// protocol, we have to set the viewport size of the size prior scaling.
|
||||
fs_state
|
||||
.viewport
|
||||
.set_destination(size.width as _, size.height as _);
|
||||
}
|
||||
|
||||
let mut window_size = window_handle.size.lock().unwrap();
|
||||
|
||||
// Always issue resize event on scale factor change.
|
||||
@@ -419,9 +429,8 @@ impl<T: 'static> EventLoop<T> {
|
||||
None
|
||||
} else {
|
||||
*window_size = size;
|
||||
let scale_factor =
|
||||
sctk::get_surface_scale_factor(window_handle.window.surface());
|
||||
let physical_size = size.to_physical(scale_factor as f64);
|
||||
let scale_factor = window_handle.scale_factor();
|
||||
let physical_size = size.to_physical(scale_factor);
|
||||
Some(physical_size)
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user