From 3d959e0f40c9ce0d80daa04eaa19f0ddd7329ed7 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Wed, 27 Feb 2019 00:09:59 -0800 Subject: [PATCH] batch resize events in x11 backend Similar to the previous commit for glium, this diff avoids resize and render for every resize event coming in from xwindows. Instead we buffer up the most recent window size, scheduling a later call to assess and apply that data. This improves resize performance. --- src/xwindows/xwin.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/xwindows/xwin.rs b/src/xwindows/xwin.rs index f5ebc26a6..dd8aa3aa7 100644 --- a/src/xwindows/xwin.rs +++ b/src/xwindows/xwin.rs @@ -50,6 +50,7 @@ pub struct X11TerminalWindow { cell_height: usize, cell_width: usize, tabs: Tabs, + have_pending_resize: Option<(u16, u16)>, } impl TerminalWindow for X11TerminalWindow { @@ -120,6 +121,13 @@ impl TerminalWindow for X11TerminalWindow { // XCB_CONFIG_WINDOW_WIDTH and XCB_CONFIG_WINDOW_HEIGHT set. Ok(false) } + + fn check_for_resize(&mut self) -> Result<(), Error> { + if let Some((width, height)) = self.have_pending_resize.take() { + self.resize_surfaces(width, height, false)?; + } + Ok(()) + } } impl X11TerminalWindow { @@ -172,6 +180,7 @@ impl X11TerminalWindow { cell_height, cell_width, tabs: Tabs::new(tab), + have_pending_resize: None, }) } @@ -206,7 +215,11 @@ impl X11TerminalWindow { } xcb::CONFIGURE_NOTIFY => { let cfg: &xcb::ConfigureNotifyEvent = unsafe { xcb::cast_event(event) }; - self.resize_surfaces(cfg.width(), cfg.height(), false)?; + let schedule = self.have_pending_resize.is_none(); + self.have_pending_resize = Some((cfg.width(), cfg.height())); + if schedule { + self.host.with_window(|win| win.check_for_resize()); + } } xcb::KEY_PRESS => { let key_press: &xcb::KeyPressEvent = unsafe { xcb::cast_event(event) };