From 9ea3dc0dbe61a749c8ccf3f03a8331db47f150a6 Mon Sep 17 00:00:00 2001 From: Tw Date: Wed, 3 Nov 2021 02:49:10 +0800 Subject: [PATCH] feat(ui): add right-click support to plugins --- zellij-client/src/input_handler.rs | 3 +++ zellij-server/src/panes/plugin_pane.rs | 8 ++++++++ zellij-server/src/route.rs | 7 +++++++ zellij-server/src/screen.rs | 10 ++++++++++ zellij-server/src/tab.rs | 9 +++++++++ zellij-tile/src/data.rs | 1 + zellij-utils/src/errors.rs | 1 + zellij-utils/src/input/actions.rs | 1 + 8 files changed, 40 insertions(+) diff --git a/zellij-client/src/input_handler.rs b/zellij-client/src/input_handler.rs index 2b89741e..d07c2caa 100644 --- a/zellij-client/src/input_handler.rs +++ b/zellij-client/src/input_handler.rs @@ -135,6 +135,9 @@ impl InputHandler { MouseButton::Left => { self.dispatch_action(Action::LeftClick(point)); } + MouseButton::Right => { + self.dispatch_action(Action::RightClick(point)); + } _ => {} }, MouseEvent::Release(point) => { diff --git a/zellij-server/src/panes/plugin_pane.rs b/zellij-server/src/panes/plugin_pane.rs index 8659ae15..6b1cb416 100644 --- a/zellij-server/src/panes/plugin_pane.rs +++ b/zellij-server/src/panes/plugin_pane.rs @@ -327,4 +327,12 @@ impl Pane for PluginPane { fn borderless(&self) -> bool { self.borderless } + fn handle_right_click(&mut self, to: &Position) { + self.send_plugin_instructions + .send(PluginInstruction::Update( + Some(self.pid), + Event::Mouse(Mouse::RightClick(to.line.0, to.column.0)), + )) + .unwrap(); + } } diff --git a/zellij-server/src/route.rs b/zellij-server/src/route.rs index bb9e733d..57fea124 100644 --- a/zellij-server/src/route.rs +++ b/zellij-server/src/route.rs @@ -296,6 +296,13 @@ fn route_action( .send_to_screen(ScreenInstruction::LeftClick(point, client_id)) .unwrap(); } + Action::RightClick(point) => { + session + .senders + .send_to_screen(ScreenInstruction::RightClick(point, client_id)) + .unwrap(); + } + Action::MouseRelease(point) => { session .senders diff --git a/zellij-server/src/screen.rs b/zellij-server/src/screen.rs index 72c681c9..4852b305 100644 --- a/zellij-server/src/screen.rs +++ b/zellij-server/src/screen.rs @@ -74,6 +74,7 @@ pub(crate) enum ScreenInstruction { TerminalResize(Size), ChangeMode(ModeInfo, ClientId), LeftClick(Position, ClientId), + RightClick(Position, ClientId), MouseRelease(Position, ClientId), MouseHold(Position, ClientId), Copy(ClientId), @@ -138,6 +139,7 @@ impl From<&ScreenInstruction> for ScreenContext { ScreenInstruction::ScrollUpAt(..) => ScreenContext::ScrollUpAt, ScreenInstruction::ScrollDownAt(..) => ScreenContext::ScrollDownAt, ScreenInstruction::LeftClick(..) => ScreenContext::LeftClick, + ScreenInstruction::RightClick(..) => ScreenContext::RightClick, ScreenInstruction::MouseRelease(..) => ScreenContext::MouseRelease, ScreenInstruction::MouseHold(..) => ScreenContext::MouseHold, ScreenInstruction::Copy(..) => ScreenContext::Copy, @@ -973,6 +975,14 @@ pub(crate) fn screen_thread_main( screen.render(); } + ScreenInstruction::RightClick(point, client_id) => { + screen + .get_active_tab_mut(client_id) + .unwrap() + .handle_right_click(&point); + + screen.render(); + } ScreenInstruction::MouseRelease(point, client_id) => { screen .get_active_tab_mut(client_id) diff --git a/zellij-server/src/tab.rs b/zellij-server/src/tab.rs index d50aba42..5c81b9c6 100644 --- a/zellij-server/src/tab.rs +++ b/zellij-server/src/tab.rs @@ -269,6 +269,7 @@ pub trait Pane { fn set_boundary_color(&mut self, _color: Option) {} fn set_borderless(&mut self, borderless: bool); fn borderless(&self) -> bool; + fn handle_right_click(&mut self, _to: &Position) {} } macro_rules! resize_pty { @@ -2586,6 +2587,14 @@ impl Tab { pane.start_selection(&relative_position); }; } + pub fn handle_right_click(&mut self, position: &Position) { + self.focus_pane_at(position); + + if let Some(pane) = self.get_pane_at(position, false) { + let relative_position = pane.relative_position(position); + pane.handle_right_click(&relative_position); + }; + } fn focus_pane_at(&mut self, point: &Position) { if let Some(clicked_pane) = self.get_pane_id_at(point, true) { self.active_terminal = Some(clicked_pane); diff --git a/zellij-tile/src/data.rs b/zellij-tile/src/data.rs index 9696b356..872a78f9 100644 --- a/zellij-tile/src/data.rs +++ b/zellij-tile/src/data.rs @@ -34,6 +34,7 @@ pub enum Mouse { ScrollUp(usize), // number of lines ScrollDown(usize), // number of lines LeftClick(isize, usize), // line and column + RightClick(isize, usize), // line and column Hold(isize, usize), // line and column Release(Option<(isize, usize)>), // line and column } diff --git a/zellij-utils/src/errors.rs b/zellij-utils/src/errors.rs index be75e4ad..401cdc10 100644 --- a/zellij-utils/src/errors.rs +++ b/zellij-utils/src/errors.rs @@ -258,6 +258,7 @@ pub enum ScreenContext { TerminalResize, ChangeMode, LeftClick, + RightClick, MouseRelease, MouseHold, Copy, diff --git a/zellij-utils/src/input/actions.rs b/zellij-utils/src/input/actions.rs index c1277db1..9dd25958 100644 --- a/zellij-utils/src/input/actions.rs +++ b/zellij-utils/src/input/actions.rs @@ -87,6 +87,7 @@ pub enum Action { /// Detach session and exit Detach, LeftClick(Position), + RightClick(Position), MouseRelease(Position), MouseHold(Position), Copy,