From dbcb5885adb1f0b23c29838ef8dd837212322409 Mon Sep 17 00:00:00 2001 From: Josh Leeb-du Toit Date: Sun, 22 Jul 2018 10:38:53 +1000 Subject: Add binding action for hiding the window --- src/event.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/event.rs') diff --git a/src/event.rs b/src/event.rs index c10f8a72..7e8a955c 100644 --- a/src/event.rs +++ b/src/event.rs @@ -40,6 +40,7 @@ pub struct ActionContext<'a, N: 'a> { pub received_count: &'a mut usize, pub suppress_chars: &'a mut bool, pub last_modifiers: &'a mut ModifiersState, + pub window_changes: &'a mut WindowChanges, } impl<'a, N: Notify + 'a> input::ActionContext for ActionContext<'a, N> { @@ -133,6 +134,33 @@ impl<'a, N: Notify + 'a> input::ActionContext for ActionContext<'a, N> { fn last_modifiers(&mut self) -> &mut ModifiersState { &mut self.last_modifiers } + + #[inline] + fn hide_window(&mut self) { + self.window_changes.hide = true; + } +} + +/// The ActionContext can't really have direct access to the Window +/// with the current design. Event handlers that want to change the +/// window must set these flags instead. The processor will trigger +/// the actual changes. +pub struct WindowChanges { + pub hide: bool, +} + +impl WindowChanges { + fn clear(&mut self) { + self.hide = false; + } +} + +impl Default for WindowChanges { + fn default() -> WindowChanges { + WindowChanges { + hide: false, + } + } } pub enum ClickState { @@ -199,6 +227,7 @@ pub struct Processor { suppress_chars: bool, last_modifiers: ModifiersState, pending_events: Vec, + window_changes: WindowChanges, } /// Notify that the terminal was resized @@ -242,6 +271,7 @@ impl Processor { suppress_chars: false, last_modifiers: Default::default(), pending_events: Vec::with_capacity(4), + window_changes: Default::default(), } } @@ -401,6 +431,7 @@ impl Processor { received_count: &mut self.received_count, suppress_chars: &mut self.suppress_chars, last_modifiers: &mut self.last_modifiers, + window_changes: &mut self.window_changes, }; processor = input::Processor { @@ -448,6 +479,11 @@ impl Processor { } } + if self.window_changes.hide { + window.hide(); + } + + self.window_changes.clear(); self.wait_for_event = !terminal.dirty; terminal -- cgit v1.2.3-54-g00ecf