mirror of
https://github.com/wez/wezterm.git
synced 2024-11-23 06:54:45 +03:00
gui: avoid glitchy live resize
Pass down whether we are in a live resize to the gui layer, so that we don't incorrectly assume that the scale has changed, and fight with the window manager. Built this on my mac: will need to fixup for windows and linux. refs: https://github.com/wez/wezterm/issues/1491
This commit is contained in:
parent
462a256e83
commit
0224f65fed
@ -799,8 +799,9 @@ impl TermWindow {
|
||||
WindowEvent::Resized {
|
||||
dimensions,
|
||||
window_state,
|
||||
live_resizing,
|
||||
} => {
|
||||
self.resize(dimensions, window_state, window);
|
||||
self.resize(dimensions, window_state, window, live_resizing);
|
||||
Ok(true)
|
||||
}
|
||||
WindowEvent::RawKeyEvent(event) => {
|
||||
|
@ -13,9 +13,16 @@ pub struct RowsAndCols {
|
||||
}
|
||||
|
||||
impl super::TermWindow {
|
||||
pub fn resize(&mut self, dimensions: Dimensions, window_state: WindowState, window: &Window) {
|
||||
pub fn resize(
|
||||
&mut self,
|
||||
dimensions: Dimensions,
|
||||
window_state: WindowState,
|
||||
window: &Window,
|
||||
live_resizing: bool,
|
||||
) {
|
||||
log::trace!(
|
||||
"resize event, current cells: {:?}, current dims: {:?}, new dims: {:?} window_state:{:?}",
|
||||
"resize event, live={} current cells: {:?}, current dims: {:?}, new dims: {:?} window_state:{:?}",
|
||||
live_resizing,
|
||||
self.current_cell_dimensions(),
|
||||
self.dimensions,
|
||||
dimensions,
|
||||
@ -33,7 +40,11 @@ impl super::TermWindow {
|
||||
return;
|
||||
}
|
||||
self.window_state = window_state;
|
||||
self.scaling_changed(dimensions, self.fonts.get_font_scale(), window);
|
||||
if live_resizing {
|
||||
self.apply_dimensions(&dimensions, None, window);
|
||||
} else {
|
||||
self.scaling_changed(dimensions, self.fonts.get_font_scale(), window);
|
||||
}
|
||||
self.emit_window_event("window-resized", None);
|
||||
}
|
||||
|
||||
@ -242,10 +253,11 @@ impl super::TermWindow {
|
||||
// Wayland is weird!
|
||||
if saved_dims != dims {
|
||||
log::trace!(
|
||||
"scale changed so resize from {:?} to {:?} {:?}",
|
||||
"scale changed so resize from {:?} to {:?} {:?} (event called with {:?})",
|
||||
saved_dims,
|
||||
dims,
|
||||
cell_dims
|
||||
cell_dims,
|
||||
dimensions
|
||||
);
|
||||
// Stash this size pre-emptively. Without this, on Windows,
|
||||
// when the font scaling is changed we can end up not seeing
|
||||
|
@ -145,6 +145,7 @@ pub enum WindowEvent {
|
||||
Resized {
|
||||
dimensions: Dimensions,
|
||||
window_state: WindowState,
|
||||
live_resizing: bool,
|
||||
},
|
||||
|
||||
/// Called when the window has been invalidated and needs to
|
||||
|
@ -423,6 +423,7 @@ impl Window {
|
||||
config: config.clone(),
|
||||
ime_state: ImeDisposition::None,
|
||||
ime_last_event: None,
|
||||
live_resizing: false,
|
||||
}));
|
||||
|
||||
let window: id = msg_send![get_window_class(), alloc];
|
||||
@ -522,6 +523,7 @@ impl Window {
|
||||
as usize,
|
||||
},
|
||||
window_state: WindowState::default(),
|
||||
live_resizing: false,
|
||||
});
|
||||
|
||||
Ok(window_handle)
|
||||
@ -919,6 +921,7 @@ impl WindowInner {
|
||||
cartesian.x as f64 - delta_x,
|
||||
cartesian.y as f64 - delta_y - content_frame.size.height,
|
||||
);
|
||||
log::info!("set_window_position {:?}", coords);
|
||||
NSWindow::setFrameOrigin_(*self.window, point);
|
||||
}
|
||||
}
|
||||
@ -1059,6 +1062,9 @@ struct Inner {
|
||||
/// where the IME mysteriously swallows repeats but only
|
||||
/// for certain keys.
|
||||
ime_last_event: Option<KeyEvent>,
|
||||
|
||||
/// Whether we're in live resize
|
||||
live_resizing: bool,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
@ -2085,6 +2091,20 @@ impl WindowView {
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" fn will_start_live_resize(this: &mut Object, _sel: Sel, _notification: id) {
|
||||
if let Some(this) = Self::get_this(this) {
|
||||
let mut inner = this.inner.borrow_mut();
|
||||
inner.live_resizing = true;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" fn did_end_live_resize(this: &mut Object, _sel: Sel, _notification: id) {
|
||||
if let Some(this) = Self::get_this(this) {
|
||||
let mut inner = this.inner.borrow_mut();
|
||||
inner.live_resizing = false;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" fn did_resize(this: &mut Object, _sel: Sel, _notification: id) {
|
||||
if let Some(this) = Self::get_this(this) {
|
||||
let inner = this.inner.borrow_mut();
|
||||
@ -2114,6 +2134,8 @@ impl WindowView {
|
||||
style_mask.contains(NSWindowStyleMask::NSFullScreenWindowMask)
|
||||
});
|
||||
|
||||
let live_resizing = inner.live_resizing;
|
||||
|
||||
inner.events.dispatch(WindowEvent::Resized {
|
||||
dimensions: Dimensions {
|
||||
pixel_width: width as usize,
|
||||
@ -2126,6 +2148,7 @@ impl WindowView {
|
||||
} else {
|
||||
WindowState::default()
|
||||
},
|
||||
live_resizing,
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -2228,6 +2251,14 @@ impl WindowView {
|
||||
Self::allow_automatic_tabbing as extern "C" fn(&Object, Sel) -> BOOL,
|
||||
);
|
||||
|
||||
cls.add_method(
|
||||
sel!(windowWillStartLiveResize:),
|
||||
Self::will_start_live_resize as extern "C" fn(&mut Object, Sel, id),
|
||||
);
|
||||
cls.add_method(
|
||||
sel!(windowDidEndLiveResize:),
|
||||
Self::did_end_live_resize as extern "C" fn(&mut Object, Sel, id),
|
||||
);
|
||||
cls.add_method(
|
||||
sel!(windowDidResize:),
|
||||
Self::did_resize as extern "C" fn(&mut Object, Sel, id),
|
||||
|
Loading…
Reference in New Issue
Block a user