From 09d7f597d4c9070c986a46ca264fdc801ad15d93 Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Sat, 8 Feb 2020 08:44:39 +0300 Subject: [PATCH] anvil.shell: refresh toplevels on commit This updates the toplevel state in the WindowMap as soon as it's committed. It will be used to update the toplevel location on top-left resize, but this is a better approach in general than the current update-every-drawn-frame. I think we should update the WindowMap state as soon as possible, and only when necessary. --- anvil/src/shell.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/anvil/src/shell.rs b/anvil/src/shell.rs index 92c34de..2f2d7d7 100644 --- a/anvil/src/shell.rs +++ b/anvil/src/shell.rs @@ -197,11 +197,19 @@ pub fn init_shell( Arc>>, Rc>, ) { + // TODO: this is awkward... + let almost_window_map = Rc::new(RefCell::new(None::>>)); + let almost_window_map_compositor = almost_window_map.clone(); + // Create the compositor let (compositor_token, _, _) = compositor_init( display, move |request, surface, ctoken| match request { - SurfaceEvent::Commit => surface_commit(&surface, ctoken, &buffer_utils), + SurfaceEvent::Commit => { + let window_map = almost_window_map_compositor.borrow(); + let window_map = window_map.as_ref().unwrap(); + surface_commit(&surface, ctoken, &buffer_utils, &*window_map) + } SurfaceEvent::Frame { callback } => callback .implement_closure(|_, _| unreachable!(), None::, ()) .done(0), @@ -211,6 +219,7 @@ pub fn init_shell( // Init a window map, to track the location of our windows let window_map = Rc::new(RefCell::new(WindowMap::new(compositor_token))); + *almost_window_map.borrow_mut() = Some(window_map.clone()); // init the xdg_shell let xdg_window_map = window_map.clone(); @@ -509,12 +518,13 @@ fn surface_commit( surface: &wl_surface::WlSurface, token: CompositorToken, buffer_utils: &BufferUtils, + window_map: &RefCell, ) { let geometry = token .with_role_data(surface, |role: &mut XdgSurfaceRole| role.window_geometry) .unwrap_or(None); - token.with_surface_data(surface, |attributes| { + let refresh = token.with_surface_data(surface, |attributes| { attributes.user_data.insert_if_missing(SurfaceData::default); let data = attributes.user_data.get_mut::().unwrap(); @@ -543,5 +553,12 @@ fn surface_commit( } None => {} } + + window_map.borrow().find(surface) }); + + if let Some(toplevel) = refresh { + let mut window_map = window_map.borrow_mut(); + window_map.refresh_toplevel(&toplevel); + } }