diff options
| author | Dante Pippi <6619666+dantepippi@users.noreply.github.com> | 2021-04-20 23:58:38 -0300 |
|---|---|---|
| committer | Dante Pippi <6619666+dantepippi@users.noreply.github.com> | 2021-04-22 20:59:56 -0300 |
| commit | f5b781c66f0a541e6382d2fef444470a87273c53 (patch) | |
| tree | da2faeaaa079906ccdd29d1f549f74b79550dbe0 /src | |
| parent | chore(version): 0.5.1 (diff) | |
| download | sl0ppij-f5b781c66f0a541e6382d2fef444470a87273c53.tar.gz sl0ppij-f5b781c66f0a541e6382d2fef444470a87273c53.tar.xz sl0ppij-f5b781c66f0a541e6382d2fef444470a87273c53.zip | |
Adding field active_at and using it to sort panes
Using last activity time to determine which pane was previously active
when moving back to a direction.
Changing active_at type to Instant
Diffstat (limited to 'src')
| -rw-r--r-- | src/client/panes/plugin_pane.rs | 15 | ||||
| -rw-r--r-- | src/client/panes/terminal_pane.rs | 11 | ||||
| -rw-r--r-- | src/client/tab.rs | 12 |
3 files changed, 32 insertions, 6 deletions
diff --git a/src/client/panes/plugin_pane.rs b/src/client/panes/plugin_pane.rs index a5b99bb5..21480ac2 100644 --- a/src/client/panes/plugin_pane.rs +++ b/src/client/panes/plugin_pane.rs @@ -1,9 +1,10 @@ use crate::{common::SenderWithContext, pty_bus::VteBytes, tab::Pane, wasm_vm::PluginInstruction}; -use std::{sync::mpsc::channel, unimplemented}; - use crate::panes::{PaneId, PositionAndSize}; +use std::time::Instant; +use std::{sync::mpsc::channel, unimplemented}; + pub struct PluginPane { pub pid: u32, pub should_render: bool, @@ -14,6 +15,7 @@ pub struct PluginPane { pub send_plugin_instructions: SenderWithContext<PluginInstruction>, pub max_height: Option<usize>, pub max_width: Option<usize>, + pub active_at: Instant, } impl PluginPane { @@ -32,6 +34,7 @@ impl PluginPane { send_plugin_instructions, max_height: None, max_width: None, + active_at: Instant::now(), } } } @@ -207,4 +210,12 @@ impl Pane for PluginPane { fn invisible_borders(&self) -> bool { self.invisible_borders } + + fn active_at(&self) -> Instant { + self.active_at + } + + fn set_active_at(&mut self, time: Instant) { + self.active_at = time; + } } diff --git a/src/client/panes/terminal_pane.rs b/src/client/panes/terminal_pane.rs index 51f735d4..ddb10889 100644 --- a/src/client/panes/terminal_pane.rs +++ b/src/client/panes/terminal_pane.rs @@ -2,6 +2,7 @@ use crate::tab::Pane; use ::nix::pty::Winsize; use ::std::os::unix::io::RawFd; use std::fmt::Debug; +use std::time::Instant; use crate::panes::grid::Grid; use crate::panes::terminal_character::{ @@ -45,6 +46,7 @@ pub struct TerminalPane { pub position_and_size_override: Option<PositionAndSize>, pub max_height: Option<usize>, pub max_width: Option<usize>, + pub active_at: Instant, vte_parser: vte::Parser, } @@ -282,6 +284,14 @@ impl Pane for TerminalPane { self.grid.reset_viewport(); self.grid.should_render = true; } + + fn active_at(&self) -> Instant { + self.active_at + } + + fn set_active_at(&mut self, time: Instant) { + self.active_at = time; + } } impl TerminalPane { @@ -296,6 +306,7 @@ impl TerminalPane { max_height: None, max_width: None, vte_parser: vte::Parser::new(), + active_at: Instant::now(), } } pub fn get_x(&self) -> usize { diff --git a/src/client/tab.rs b/src/client/tab.rs index 04d53f79..af48d3fe 100644 --- a/src/client/tab.rs +++ b/src/client/tab.rs @@ -13,6 +13,7 @@ use crate::wasm_vm::PluginInstruction; use crate::{boundaries::Boundaries, panes::PluginPane}; use serde::{Deserialize, Serialize}; use std::os::unix::io::RawFd; +use std::time::Instant; use std::{ cmp::Reverse, collections::{BTreeMap, HashSet}, @@ -122,6 +123,8 @@ pub trait Pane { fn scroll_up(&mut self, count: usize); fn scroll_down(&mut self, count: usize); fn clear_scroll(&mut self); + fn active_at(&self) -> Instant; + fn set_active_at(&mut self, instant: Instant); fn right_boundary_x_coords(&self) -> usize { self.x() + self.columns() @@ -700,6 +703,7 @@ impl Tab { if !self.panes_to_hide.contains(&pane.pid()) { match self.active_terminal.unwrap() == pane.pid() { true => { + pane.set_active_at(Instant::now()); boundaries.add_rect(pane.as_ref(), self.mode_info.mode, Some(colors::GREEN)) } false => boundaries.add_rect(pane.as_ref(), self.mode_info.mode, None), @@ -1837,7 +1841,7 @@ impl Tab { .filter(|(_, (_, c))| { c.is_directly_left_of(active) && c.horizontally_overlaps_with(active) }) - .max_by_key(|(_, (_, c))| c.get_horizontal_overlap_with(active)) + .max_by_key(|(_, (_, c))| c.active_at()) .map(|(_, (pid, _))| pid); match next_index { Some(&p) => { @@ -1867,7 +1871,7 @@ impl Tab { .filter(|(_, (_, c))| { c.is_directly_below(active) && c.vertically_overlaps_with(active) }) - .max_by_key(|(_, (_, c))| c.get_vertical_overlap_with(active)) + .max_by_key(|(_, (_, c))| c.active_at()) .map(|(_, (pid, _))| pid); match next_index { Some(&p) => { @@ -1897,7 +1901,7 @@ impl Tab { .filter(|(_, (_, c))| { c.is_directly_above(active) && c.vertically_overlaps_with(active) }) - .max_by_key(|(_, (_, c))| c.get_vertical_overlap_with(active)) + .max_by_key(|(_, (_, c))| c.active_at()) .map(|(_, (pid, _))| pid); match next_index { Some(&p) => { @@ -1927,7 +1931,7 @@ impl Tab { .filter(|(_, (_, c))| { c.is_directly_right_of(active) && c.horizontally_overlaps_with(active) }) - .max_by_key(|(_, (_, c))| c.get_horizontal_overlap_with(active)) + .max_by_key(|(_, (_, c))| c.active_at()) .map(|(_, (pid, _))| pid); match next_index { Some(&p) => { |
