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:
oxalica 2021-08-24 18:36:13 +08:00 committed by GitHub
parent 3bfb580d7a
commit 125ee0b446
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 44 deletions

View file

@ -13,7 +13,7 @@
- **Breaking:** On Wayland, Theme trait and its support types are dropped. - **Breaking:** On Wayland, Theme trait and its support types are dropped.
- On Wayland, bump `smithay-client-toolkit` to 0.15. - On Wayland, bump `smithay-client-toolkit` to 0.15.
- On Wayland, implement `request_user_attention` with `xdg_activation_v1`. - 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) # 0.25.0 (2021-05-15)

View file

@ -1164,21 +1164,24 @@ impl<T: 'static> EventProcessor<T> {
if let Some(prev_list) = prev_list { if let Some(prev_list) = prev_list {
let new_list = wt.xconn.available_monitors(); let new_list = wt.xconn.available_monitors();
for new_monitor in new_list { 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() .iter()
.find(|prev_monitor| prev_monitor.name == new_monitor.name) .find(|prev_monitor| prev_monitor.name == new_monitor.name)
.map(|prev_monitor| { .map(|prev_monitor| prev_monitor.scale_factor);
if new_monitor.scale_factor != prev_monitor.scale_factor { if Some(new_monitor.scale_factor) != maybe_prev_scale_factor {
for (window_id, window) in wt.windows.borrow().iter() { for (window_id, window) in wt.windows.borrow().iter() {
if let Some(window) = window.upgrade() { if let Some(window) = window.upgrade() {
// Check if the window is on this monitor // Check if the window is on this monitor
let monitor = window.current_monitor(); let monitor = window.current_monitor();
if monitor.name == new_monitor.name { if monitor.name == new_monitor.name {
let (width, height) = let (width, height) = window.inner_size_physical();
window.inner_size_physical(); let (new_width, new_height) = window.adjust_for_dpi(
let (new_width, new_height) = window // If there all monitors are closed before, scale
.adjust_for_dpi( // factor would be already changed to 1.0.
prev_monitor.scale_factor, maybe_prev_scale_factor.unwrap_or(1.0),
new_monitor.scale_factor, new_monitor.scale_factor,
width, width,
height, height,
@ -1190,8 +1193,7 @@ impl<T: 'static> EventProcessor<T> {
*window_id, *window_id,
), ),
); );
let old_inner_size = let old_inner_size = PhysicalSize::new(width, height);
PhysicalSize::new(width, height);
let mut new_inner_size = let mut new_inner_size =
PhysicalSize::new(new_width, new_height); PhysicalSize::new(new_width, new_height);
@ -1204,17 +1206,14 @@ impl<T: 'static> EventProcessor<T> {
}); });
if new_inner_size != old_inner_size { if new_inner_size != old_inner_size {
let (new_width, new_height) = let (new_width, new_height) = new_inner_size.into();
new_inner_size.into(); window
window.set_inner_size_physical( .set_inner_size_physical(new_width, new_height);
new_width, new_height,
);
} }
} }
} }
} }
} }
});
} }
} }
} }