From b62bfa54a00e93414e0d9953270698581291ac81 Mon Sep 17 00:00:00 2001 From: Michael Sippel Date: Sat, 16 Jan 2021 18:00:56 +0100 Subject: [PATCH] terminal compositor: move area calculation into impl IndexView --- src/terminal/compositor.rs | 57 +++++++++++++------------------------- src/terminal/terminal.rs | 4 +-- 2 files changed, 21 insertions(+), 40 deletions(-) diff --git a/src/terminal/compositor.rs b/src/terminal/compositor.rs index a4fc0cb..8352e7e 100644 --- a/src/terminal/compositor.rs +++ b/src/terminal/compositor.rs @@ -26,9 +26,6 @@ impl Observer for CompositeLayer { *v = view.clone(); drop(v); - //todo: fixme: why does this cause a deadlock? - //c.update_range(); - if let Some(old_view) = old_view { if let Some(area) = old_view.area() { c.cast.notify_each(area); @@ -53,32 +50,9 @@ impl Observer for CompositeLayer { pub struct TerminalCompositeView { idx_count: usize, layers: HashMap>, Option>)>, - area: Option>>, cast: Arc>> } -impl TerminalCompositeView { - fn update_range(&mut self) { - self.area = Some(Vec::new()); - - for (_, layer) in self.layers.iter() { - if let Some(view) = layer.1.as_ref() { - if let ( - Some(mut new_area), - Some(area) - ) = ( - view.area(), - self.area.as_mut() - ) { - area.append(&mut new_area); - } else { - self.area = None; - } - } - } - } -} - impl ImplIndexView for TerminalCompositeView { type Key = Point2; type Value = Option; @@ -89,16 +63,6 @@ impl ImplIndexView for TerminalCompositeView { for idx in 0 .. self.idx_count { if let Some(l) = self.layers.get(&idx) { if let Some(view) = l.1.as_ref() { - /* - if let Some(range) = view.range() { - if pos.x < range.start.x || - pos.x >= range.end.x || - pos.y < range.start.y || - pos.y >= range.end.y { - continue; - } - } - */ match (atom, view.get(pos)) { (None, next) => atom = next, (Some(last), Some(next)) => atom = Some(next.add_style_back(last.style)), @@ -112,7 +76,25 @@ impl ImplIndexView for TerminalCompositeView { } fn area(&self) -> Option>> { - self.area.clone() + let mut area = Some(Vec::new()); + + for (_, layer) in self.layers.iter() { + if let Some(view) = layer.1.as_ref() { + if let ( + Some(mut new_area), + Some(area) + ) = ( + view.area(), + area.as_mut() + ) { + area.append(&mut new_area); + } else { + area = None; + } + } + } + + area } } @@ -128,7 +110,6 @@ impl TerminalCompositor { TerminalCompositeView { idx_count: 0, layers: HashMap::new(), - area: None,//Some(Vec::new()), cast: port.get_broadcast() } )); diff --git a/src/terminal/terminal.rs b/src/terminal/terminal.rs index b1b4ce8..c50a376 100644 --- a/src/terminal/terminal.rs +++ b/src/terminal/terminal.rs @@ -41,7 +41,7 @@ pub enum TerminalEvent { pub struct Terminal { writer: Arc, - observer: Arc>, + _observer: Arc>, events: ChannelReceiver>, _signal_handle: signal_hook_async_std::Handle @@ -98,7 +98,7 @@ impl Terminal { Terminal { writer, - observer, + _observer: observer, events: event_rx, _signal_handle: handle }