aboutsummaryrefslogtreecommitdiffstats
path: root/src/screen.rs
diff options
context:
space:
mode:
authorDenis Maximov <denismaximov98@gmail.com>2020-12-04 10:59:06 +0200
committerGitHub <noreply@github.com>2020-12-04 09:59:06 +0100
commitb7b3ff74cfa09fce1442bda42332939de4903a7d (patch)
treee84876d04679ebbc913e9d65f6c2a45f0642fdcc /src/screen.rs
parentfix(compatibility): keypad arrow fixes (#80) (diff)
downloadsl0ppij-b7b3ff74cfa09fce1442bda42332939de4903a7d.tar.gz
sl0ppij-b7b3ff74cfa09fce1442bda42332939de4903a7d.tar.xz
sl0ppij-b7b3ff74cfa09fce1442bda42332939de4903a7d.zip
feat(rect): directional move focus #55 (#78)
* feat: directional move focus #55 * wip: refactored match into if let * wip: basic tests * feat: move to most overlapping pane tests * fix: formatting * wip: Moved the definitions to the Rect trait * formatting
Diffstat (limited to 'src/screen.rs')
-rw-r--r--src/screen.rs130
1 files changed, 130 insertions, 0 deletions
diff --git a/src/screen.rs b/src/screen.rs
index 6ad559f3..e00cc0a9 100644
--- a/src/screen.rs
+++ b/src/screen.rs
@@ -4,10 +4,12 @@ use std::os::unix::io::RawFd;
use std::sync::mpsc::{Receiver, Sender, SyncSender};
use crate::boundaries::Boundaries;
+use crate::boundaries::Rect;
use crate::layout::Layout;
use crate::os_input_output::OsApi;
use crate::pty_bus::{PtyInstruction, VteEvent};
use crate::terminal_pane::{PositionAndSize, TerminalPane};
+use crate::utils::logging::debug_log_to_file;
use crate::AppInstruction;
/*
@@ -61,6 +63,10 @@ pub enum ScreenInstruction {
ResizeDown,
ResizeUp,
MoveFocus,
+ MoveFocusLeft,
+ MoveFocusDown,
+ MoveFocusUp,
+ MoveFocusRight,
Quit,
ScrollUp,
ScrollDown,
@@ -1290,6 +1296,130 @@ impl Screen {
}
self.render();
}
+ pub fn move_focus_left(&mut self) {
+ if self.terminals.is_empty() {
+ return;
+ }
+ if self.fullscreen_is_active {
+ return;
+ }
+ let active_terminal = self.get_active_terminal();
+ if let Some(active) = active_terminal {
+ let next_index = self
+ .terminals
+ .iter()
+ .enumerate()
+ .filter(|(_, (_, c))| {
+ c.is_directly_left_of(&active) && c.horizontally_overlaps_with(&active)
+ })
+ .max_by_key(|(_, (_, c))| c.get_horizontal_overlap_with(&active))
+ .map(|(_, (pid, _))| pid);
+ match next_index {
+ Some(p) => {
+ self.active_terminal = Some(*p);
+ }
+ None => {
+ self.active_terminal = Some(active.pid);
+ }
+ }
+ } else {
+ self.active_terminal = Some(active_terminal.unwrap().pid);
+ }
+ self.render();
+ }
+ pub fn move_focus_down(&mut self) {
+ if self.terminals.is_empty() {
+ return;
+ }
+ if self.fullscreen_is_active {
+ return;
+ }
+ let active_terminal = self.get_active_terminal();
+ if let Some(active) = active_terminal {
+ let next_index = self
+ .terminals
+ .iter()
+ .enumerate()
+ .filter(|(_, (_, c))| {
+ c.is_directly_below(&active) && c.vertically_overlaps_with(&active)
+ })
+ .max_by_key(|(_, (_, c))| c.get_vertical_overlap_with(&active))
+ .map(|(_, (pid, _))| pid);
+ match next_index {
+ Some(p) => {
+ self.active_terminal = Some(*p);
+ }
+ None => {
+ self.active_terminal = Some(active.pid);
+ }
+ }
+ } else {
+ self.active_terminal = Some(active_terminal.unwrap().pid);
+ }
+ self.render();
+ }
+ pub fn move_focus_up(&mut self) {
+ if self.terminals.is_empty() {
+ return;
+ }
+ if self.fullscreen_is_active {
+ return;
+ }
+ let active_terminal = self.get_active_terminal();
+ if let Some(active) = active_terminal {
+ let next_index = self
+ .terminals
+ .iter()
+ .enumerate()
+ .filter(|(_, (_, c))| {
+ c.is_directly_above(&active) && c.vertically_overlaps_with(&active)
+ })
+ .max_by_key(|(_, (_, c))| c.get_vertical_overlap_with(&active))
+ .map(|(_, (pid, _))| pid);
+ match next_index {
+ Some(p) => {
+ self.active_terminal = Some(*p);
+ }
+ None => {
+ self.active_terminal = Some(active.pid);
+ }
+ }
+ } else {
+ self.active_terminal = Some(active_terminal.unwrap().pid);
+ }
+ self.render();
+ }
+ pub fn move_focus_right(&mut self) {
+ if self.terminals.is_empty() {
+ return;
+ }
+ if self.fullscreen_is_active {
+ return;
+ }
+ let active_terminal = self.get_active_terminal();
+ if let Some(active) = active_terminal {
+ let next_index = self
+ .terminals
+ .iter()
+ .enumerate()
+ .filter(|(_, (_, c))| {
+ c.is_directly_right_of(&active) && c.horizontally_overlaps_with(&active)
+ })
+ .max_by_key(|(_, (_, c))| c.get_horizontal_overlap_with(&active))
+ .map(|(_, (pid, _))| pid);
+ match next_index {
+ Some(p) => {
+ self.active_terminal = Some(*p);
+ }
+ None => {
+ self.active_terminal = Some(active.pid);
+ }
+ }
+ } else {
+ self.active_terminal = Some(active_terminal.unwrap().pid);
+ }
+ self.render();
+ }
fn horizontal_borders(&self, terminals: &[RawFd]) -> HashSet<usize> {
terminals.iter().fold(HashSet::new(), |mut borders, t| {
let terminal = self.terminals.get(t).unwrap();