diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rs index 4003c90f4..67b8b2ff5 100644 --- a/wezterm-gui/src/termwindow/mod.rs +++ b/wezterm-gui/src/termwindow/mod.rs @@ -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) => { diff --git a/wezterm-gui/src/termwindow/resize.rs b/wezterm-gui/src/termwindow/resize.rs index ee1a6fccb..5b6d220cb 100644 --- a/wezterm-gui/src/termwindow/resize.rs +++ b/wezterm-gui/src/termwindow/resize.rs @@ -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 diff --git a/window/src/lib.rs b/window/src/lib.rs index f195e64b2..3214dee69 100644 --- a/window/src/lib.rs +++ b/window/src/lib.rs @@ -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 diff --git a/window/src/os/macos/window.rs b/window/src/os/macos/window.rs index 9faaaa2b5..6e29f4b4d 100644 --- a/window/src/os/macos/window.rs +++ b/window/src/os/macos/window.rs @@ -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, + + /// 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),