From f62079375a04ec99f76d866f5712a64dd839e9fa Mon Sep 17 00:00:00 2001 From: Christian Meissl Date: Sat, 15 Jan 2022 19:35:26 +0100 Subject: [PATCH 1/3] disable clippy non-send-fields-in-send-ty --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8f2657c..748987e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -64,12 +64,12 @@ jobs: uses: actions-rs/clippy-check@v1 with: token: ${{ secrets.GITHUB_TOKEN }} - args: --features "test_all_features" -- -D warnings + args: --features "test_all_features" -- -D warnings -A clippy::non-send-fields-in-send-ty - name: Clippy Anvil uses: actions-rs/clippy-check@v1 with: token: ${{ secrets.GITHUB_TOKEN }} - args: --manifest-path "./anvil/Cargo.toml" --features "test_all_features" -- -D warnings + args: --manifest-path "./anvil/Cargo.toml" --features "test_all_features" -- -D warnings -A clippy::non-send-fields-in-send-ty check-minimal: env: From 8f73a1e4f8fe9de8541e4154375034380cb687d3 Mon Sep 17 00:00:00 2001 From: Victor Brekenfeld Date: Wed, 12 Jan 2022 23:47:22 +0100 Subject: [PATCH 2/3] desktop: Fix damage for removed popups --- src/desktop/space/mod.rs | 17 +++++ src/desktop/space/popup.rs | 129 +++++++++++++++++++++++++++++++++++++ src/desktop/window.rs | 12 ---- 3 files changed, 146 insertions(+), 12 deletions(-) create mode 100644 src/desktop/space/popup.rs diff --git a/src/desktop/space/mod.rs b/src/desktop/space/mod.rs index 47116b4..11bd6e8 100644 --- a/src/desktop/space/mod.rs +++ b/src/desktop/space/mod.rs @@ -24,6 +24,7 @@ use wayland_server::protocol::wl_surface::WlSurface; mod element; mod layer; mod output; +mod popup; mod window; pub use self::element::*; @@ -486,6 +487,16 @@ impl Space { let output_geo = Rectangle::from_loc_and_size(state.location, output_size); let layer_map = layer_map_for_output(output); + let window_popups = self + .windows + .iter() + .flat_map(|w| w.popup_elements::(self.id)) + .collect::>(); + let layer_popups = layer_map + .layers() + .flat_map(|l| l.popup_elements::(self.id)) + .collect::>(); + // This will hold all the damage we need for this rendering step let mut damage = Vec::>::new(); // First add damage for windows gone @@ -497,7 +508,9 @@ impl Space { .windows .iter() .map(|w| w as &SpaceElem) + .chain(window_popups.iter().map(|p| p as &SpaceElem)) .chain(layer_map.layers().map(|l| l as &SpaceElem)) + .chain(layer_popups.iter().map(|p| p as &SpaceElem)) .chain(custom_elements.iter().map(|c| c as &SpaceElem)) .any(|e| ToplevelId::from(e) == *id) { @@ -517,7 +530,9 @@ impl Space { .windows .iter() .map(|w| w as &SpaceElem) + .chain(window_popups.iter().map(|p| p as &SpaceElem)) .chain(layer_map.layers().map(|l| l as &SpaceElem)) + .chain(layer_popups.iter().map(|p| p as &SpaceElem)) .chain(custom_elements.iter().map(|c| c as &SpaceElem)) { let geo = element.geometry(self.id); @@ -647,7 +662,9 @@ impl Space { .windows .iter() .map(|w| w as &SpaceElem) + .chain(window_popups.iter().map(|p| p as &SpaceElem)) .chain(layer_map.layers().map(|l| l as &SpaceElem)) + .chain(layer_popups.iter().map(|p| p as &SpaceElem)) .chain(custom_elements.iter().map(|c| c as &SpaceElem)) .map(|elem| { let geo = elem.geometry(self.id); diff --git a/src/desktop/space/popup.rs b/src/desktop/space/popup.rs new file mode 100644 index 0000000..dbef156 --- /dev/null +++ b/src/desktop/space/popup.rs @@ -0,0 +1,129 @@ +use crate::{ + backend::renderer::{Frame, ImportAll, Renderer, Texture}, + desktop::{ + layer::LayerSurface, + popup::{PopupKind, PopupManager}, + space::{window_loc, Space, SpaceElement}, + utils::{bbox_from_surface_tree, damage_from_surface_tree}, + window::Window, + }, + utils::{Logical, Point, Rectangle}, + wayland::output::Output, +}; +use std::any::TypeId; + +#[derive(Debug)] +pub struct RenderPopup { + location: Point, + popup: PopupKind, +} + +impl Window { + pub(super) fn popup_elements(&self, space_id: usize) -> impl Iterator + where + R: Renderer + ImportAll + 'static, + R::TextureId: 'static, + R::Error: 'static, + R::Frame: 'static, + { + let loc = window_loc(self, &space_id) + self.geometry().loc; + self.toplevel() + .get_surface() + .map(move |surface| { + PopupManager::popups_for_surface(surface) + .ok() + .into_iter() + .flatten() + .map(move |(popup, location)| { + let offset = loc + location - popup.geometry().loc; + RenderPopup { + location: offset, + popup, + } + }) + }) + .into_iter() + .flatten() + } +} + +impl LayerSurface { + pub(super) fn popup_elements(&self, space_id: usize) -> impl Iterator + where + R: Renderer + ImportAll + 'static, + R::TextureId: 'static, + R::Error: 'static, + R::Frame: 'static, + { + type SpaceElem = + dyn SpaceElement::Frame, ::Error, ::TextureId>; + + let loc = (self as &SpaceElem).geometry(space_id).loc; + self.get_surface() + .map(move |surface| { + PopupManager::popups_for_surface(surface) + .ok() + .into_iter() + .flatten() + .map(move |(popup, location)| { + let offset = loc + location - popup.geometry().loc; + RenderPopup { + location: offset, + popup, + } + }) + }) + .into_iter() + .flatten() + } +} + +impl SpaceElement for RenderPopup +where + R: Renderer + ImportAll, + F: Frame, + E: std::error::Error, + T: Texture + 'static, +{ + fn id(&self) -> usize { + self.popup + .get_surface() + .map(|s| s.as_ref().id() as usize) + .unwrap_or(0) + } + + fn type_of(&self) -> TypeId { + TypeId::of::() + } + + fn geometry(&self, _space_id: usize) -> Rectangle { + if let Some(surface) = self.popup.get_surface() { + bbox_from_surface_tree(surface, self.location) + } else { + Rectangle::from_loc_and_size((0, 0), (0, 0)) + } + } + + fn accumulated_damage(&self, for_values: Option<(&Space, &Output)>) -> Vec> { + if let Some(surface) = self.popup.get_surface() { + damage_from_surface_tree(surface, (0, 0), for_values) + } else { + Vec::new() + } + } + + #[allow(clippy::too_many_arguments)] + fn draw( + &self, + _space_id: usize, + _renderer: &mut R, + _frame: &mut F, + _scale: f64, + _location: Point, + _damage: &[Rectangle], + _log: &slog::Logger, + ) -> Result<(), R::Error> { + // popups are special, we track them, but they render with their parents + Ok(()) + } +} diff --git a/src/desktop/window.rs b/src/desktop/window.rs index a45d65d..1c57b1a 100644 --- a/src/desktop/window.rs +++ b/src/desktop/window.rs @@ -258,18 +258,6 @@ impl Window { .into_iter() .flat_map(|rect| rect.intersection(self.bbox())), ); - for (popup, location) in PopupManager::popups_for_surface(surface) - .ok() - .into_iter() - .flatten() - { - if let Some(surface) = popup.get_surface() { - let offset = self.geometry().loc + location - popup.geometry().loc; - let bbox = bbox_from_surface_tree(surface, offset); - let popup_damage = damage_from_surface_tree(surface, offset, for_values); - damage.extend(popup_damage.into_iter().flat_map(|rect| rect.intersection(bbox))); - } - } } damage } From 34667b791afeff63bd36407e7db9e4716b87a62f Mon Sep 17 00:00:00 2001 From: Victor Brekenfeld Date: Fri, 14 Jan 2022 20:38:25 +0100 Subject: [PATCH 3/3] utils: correctly increment ids on first call --- src/utils/ids.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utils/ids.rs b/src/utils/ids.rs index ce4178d..b7b1e33 100644 --- a/src/utils/ids.rs +++ b/src/utils/ids.rs @@ -20,6 +20,7 @@ macro_rules! id_gen { while ids.iter().any(|k| *k == id) { id += 1; } + id += 1; Some(id) }, );