aboutsummaryrefslogtreecommitdiffstats
path: root/zellij-client/src
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2021-09-30 10:25:48 +0200
committerGitHub <noreply@github.com>2021-09-30 10:25:48 +0200
commitd7e4ec65db028f1ea231d4bee689be394f95cbf5 (patch)
treeaa99bde6c270512dd2c462908095753f6a85876c /zellij-client/src
parentfix(makefile): update `update-default-config` (#751) (diff)
downloadsl0ppij-d7e4ec65db028f1ea231d4bee689be394f95cbf5.tar.gz
sl0ppij-d7e4ec65db028f1ea231d4bee689be394f95cbf5.tar.xz
sl0ppij-d7e4ec65db028f1ea231d4bee689be394f95cbf5.zip
hotfix(stdin): poll for mouse hold in the stdin thread (#752)
* hotfix(stdin): poll for mouse hold in the stdin thread * add missing dont panic * style(fmt): make rustfmt happy
Diffstat (limited to 'zellij-client/src')
-rw-r--r--zellij-client/src/input_handler.rs2
-rw-r--r--zellij-client/src/lib.rs31
-rw-r--r--zellij-client/src/os_input_output.rs19
-rw-r--r--zellij-client/src/unit/input_handler_tests.rs9
4 files changed, 42 insertions, 19 deletions
diff --git a/zellij-client/src/input_handler.rs b/zellij-client/src/input_handler.rs
index e78f59c1..1b2c0f22 100644
--- a/zellij-client/src/input_handler.rs
+++ b/zellij-client/src/input_handler.rs
@@ -157,8 +157,6 @@ impl InputHandler {
}
MouseEvent::Hold(point) => {
self.dispatch_action(Action::MouseHold(point));
- self.os_input
- .start_action_repeater(Action::MouseHold(point));
}
}
}
diff --git a/zellij-client/src/lib.rs b/zellij-client/src/lib.rs
index 92b87e70..06f7e32e 100644
--- a/zellij-client/src/lib.rs
+++ b/zellij-client/src/lib.rs
@@ -20,7 +20,7 @@ use zellij_utils::{
channels::{self, ChannelWithContext, SenderWithContext},
consts::{SESSION_NAME, ZELLIJ_IPC_PIPE},
errors::{ClientContext, ContextType, ErrorInstruction},
- input::{actions::Action, config::Config, options::Options},
+ input::{actions::Action, config::Config, mouse::MouseEvent, options::Options},
ipc::{ClientAttributes, ClientToServerMsg, ExitReason, ServerToClientMsg},
termion,
};
@@ -197,6 +197,35 @@ pub fn start_client(
let stdin_buffer = os_input.read_from_stdin();
for key_result in stdin_buffer.events_and_raw() {
let (key_event, raw_bytes) = key_result.unwrap();
+ if let termion::event::Event::Mouse(me) = key_event {
+ let mouse_event = zellij_utils::input::mouse::MouseEvent::from(me);
+ if let MouseEvent::Hold(_) = mouse_event {
+ // as long as the user is holding the mouse down (no other stdin, eg.
+ // MouseRelease) we need to keep sending this instruction to the app,
+ // because the app itself doesn't have an event loop in the proper
+ // place
+ let mut poller = os_input.stdin_poller();
+ send_input_instructions
+ .send(InputInstruction::KeyEvent(
+ key_event.clone(),
+ raw_bytes.clone(),
+ ))
+ .unwrap();
+ loop {
+ let ready = poller.ready();
+ if ready {
+ break;
+ }
+ send_input_instructions
+ .send(InputInstruction::KeyEvent(
+ key_event.clone(),
+ raw_bytes.clone(),
+ ))
+ .unwrap();
+ }
+ continue;
+ }
+ }
send_input_instructions
.send(InputInstruction::KeyEvent(key_event, raw_bytes))
.unwrap();
diff --git a/zellij-client/src/os_input_output.rs b/zellij-client/src/os_input_output.rs
index b5018c29..c2fdad82 100644
--- a/zellij-client/src/os_input_output.rs
+++ b/zellij-client/src/os_input_output.rs
@@ -1,4 +1,3 @@
-use zellij_utils::input::actions::Action;
use zellij_utils::pane_size::Size;
use zellij_utils::{interprocess, libc, nix, signal_hook, termion, zellij_tile};
@@ -97,7 +96,7 @@ pub trait ClientOsApi: Send + Sync {
fn enable_mouse(&self);
fn disable_mouse(&self);
// Repeatedly send action, until stdin is readable again
- fn start_action_repeater(&mut self, action: Action);
+ fn stdin_poller(&self) -> StdinPoller;
}
impl ClientOsApi for ClientOsInputOutput {
@@ -204,16 +203,8 @@ impl ClientOsApi for ClientOsInputOutput {
}
}
- fn start_action_repeater(&mut self, action: Action) {
- let mut poller = StdinPoller::default();
-
- loop {
- let ready = poller.ready();
- if ready {
- break;
- }
- self.send_to_server(ClientToServerMsg::Action(action.clone()));
- }
+ fn stdin_poller(&self) -> StdinPoller {
+ StdinPoller::default()
}
}
@@ -237,7 +228,7 @@ pub fn get_client_os_input() -> Result<ClientOsInputOutput, nix::Error> {
pub const DEFAULT_STDIN_POLL_TIMEOUT_MS: u64 = 10;
-struct StdinPoller {
+pub struct StdinPoller {
poll: Poll,
events: Events,
timeout: time::Duration,
@@ -245,7 +236,7 @@ struct StdinPoller {
impl StdinPoller {
// use mio poll to check if stdin is readable without blocking
- fn ready(&mut self) -> bool {
+ pub fn ready(&mut self) -> bool {
self.poll
.poll(&mut self.events, Some(self.timeout))
.expect("could not poll stdin for readiness");
diff --git a/zellij-client/src/unit/input_handler_tests.rs b/zellij-client/src/unit/input_handler_tests.rs
index c2cf784b..f4beb53a 100644
--- a/zellij-client/src/unit/input_handler_tests.rs
+++ b/zellij-client/src/unit/input_handler_tests.rs
@@ -8,7 +8,10 @@ use zellij_utils::termion::event::Key;
use zellij_utils::zellij_tile::data::Palette;
use crate::InputInstruction;
-use crate::{os_input_output::ClientOsApi, ClientInstruction, CommandIsExecuting};
+use crate::{
+ os_input_output::{ClientOsApi, StdinPoller},
+ ClientInstruction, CommandIsExecuting,
+};
use std::path::Path;
@@ -133,7 +136,9 @@ impl ClientOsApi for FakeClientOsApi {
}
fn enable_mouse(&self) {}
fn disable_mouse(&self) {}
- fn start_action_repeater(&mut self, _action: Action) {}
+ fn stdin_poller(&self) -> StdinPoller {
+ unimplemented!()
+ }
}
fn extract_actions_sent_to_server(