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
This commit is contained in:
Dante Pippi 2021-04-20 23:58:38 -03:00
parent f2fa8839d4
commit f5b781c66f
3 changed files with 32 additions and 6 deletions

View file

@ -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;
}
}

View file

@ -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 {

View file

@ -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) => {