mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-23 22:01:31 +11:00
Emit ScaleFactorChanged event on monitor reconnect (#1963)
When disconnect the only monitor, scale factor is reset to 1.0. We need to set it back when the monitor is reconnected. We previously assume current window must be on an existing monitor, but that's not true in case of reconnecting the only one monitor.
This commit is contained in:
parent
3bfb580d7a
commit
125ee0b446
|
@ -13,7 +13,7 @@
|
|||
- **Breaking:** On Wayland, Theme trait and its support types are dropped.
|
||||
- On Wayland, bump `smithay-client-toolkit` to 0.15.
|
||||
- On Wayland, implement `request_user_attention` with `xdg_activation_v1`.
|
||||
|
||||
- On X11, emit missing `WindowEvent::ScaleFactorChanged` when the only monitor gets reconnected.
|
||||
|
||||
# 0.25.0 (2021-05-15)
|
||||
|
||||
|
|
|
@ -1164,21 +1164,24 @@ impl<T: 'static> EventProcessor<T> {
|
|||
if let Some(prev_list) = prev_list {
|
||||
let new_list = wt.xconn.available_monitors();
|
||||
for new_monitor in new_list {
|
||||
prev_list
|
||||
// Previous list may be empty, in case of disconnecting and
|
||||
// reconnecting the only one monitor. We still need to emit events in
|
||||
// this case.
|
||||
let maybe_prev_scale_factor = prev_list
|
||||
.iter()
|
||||
.find(|prev_monitor| prev_monitor.name == new_monitor.name)
|
||||
.map(|prev_monitor| {
|
||||
if new_monitor.scale_factor != prev_monitor.scale_factor {
|
||||
.map(|prev_monitor| prev_monitor.scale_factor);
|
||||
if Some(new_monitor.scale_factor) != maybe_prev_scale_factor {
|
||||
for (window_id, window) in wt.windows.borrow().iter() {
|
||||
if let Some(window) = window.upgrade() {
|
||||
// Check if the window is on this monitor
|
||||
let monitor = window.current_monitor();
|
||||
if monitor.name == new_monitor.name {
|
||||
let (width, height) =
|
||||
window.inner_size_physical();
|
||||
let (new_width, new_height) = window
|
||||
.adjust_for_dpi(
|
||||
prev_monitor.scale_factor,
|
||||
let (width, height) = window.inner_size_physical();
|
||||
let (new_width, new_height) = window.adjust_for_dpi(
|
||||
// If there all monitors are closed before, scale
|
||||
// factor would be already changed to 1.0.
|
||||
maybe_prev_scale_factor.unwrap_or(1.0),
|
||||
new_monitor.scale_factor,
|
||||
width,
|
||||
height,
|
||||
|
@ -1190,8 +1193,7 @@ impl<T: 'static> EventProcessor<T> {
|
|||
*window_id,
|
||||
),
|
||||
);
|
||||
let old_inner_size =
|
||||
PhysicalSize::new(width, height);
|
||||
let old_inner_size = PhysicalSize::new(width, height);
|
||||
let mut new_inner_size =
|
||||
PhysicalSize::new(new_width, new_height);
|
||||
|
||||
|
@ -1204,17 +1206,14 @@ impl<T: 'static> EventProcessor<T> {
|
|||
});
|
||||
|
||||
if new_inner_size != old_inner_size {
|
||||
let (new_width, new_height) =
|
||||
new_inner_size.into();
|
||||
window.set_inner_size_physical(
|
||||
new_width, new_height,
|
||||
);
|
||||
let (new_width, new_height) = new_inner_size.into();
|
||||
window
|
||||
.set_inner_size_physical(new_width, new_height);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue