From cf781031e3df53027b78924a59ec664b04d60942 Mon Sep 17 00:00:00 2001 From: Keith Simmons Date: Sat, 18 Sep 2021 00:39:18 -0700 Subject: [PATCH] pass button to mouse input event --- src/bridge/ui_commands.rs | 4 +- src/window/window_wrapper/mouse_manager.rs | 56 +++++++++++++--------- 2 files changed, 36 insertions(+), 24 deletions(-) diff --git a/src/bridge/ui_commands.rs b/src/bridge/ui_commands.rs index 60ab634..8f0a159 100644 --- a/src/bridge/ui_commands.rs +++ b/src/bridge/ui_commands.rs @@ -21,6 +21,7 @@ pub enum UiCommand { }, Keyboard(String), MouseButton { + button: String, action: String, grid_id: u64, position: (u32, u32), @@ -58,12 +59,13 @@ impl UiCommand { nvim.input(&input_command).await.expect("Input failed"); } UiCommand::MouseButton { + button, action, grid_id, position: (grid_x, grid_y), } => { nvim.input_mouse( - "left", + &button, &action, "", grid_id as i64, diff --git a/src/window/window_wrapper/mouse_manager.rs b/src/window/window_wrapper/mouse_manager.rs index a916d4c..47feb27 100644 --- a/src/window/window_wrapper/mouse_manager.rs +++ b/src/window/window_wrapper/mouse_manager.rs @@ -165,32 +165,42 @@ impl MouseManager { } } - fn handle_pointer_transition(&mut self, down: bool) { + fn handle_pointer_transition(&mut self, mouse_button: &MouseButton, down: bool) { // For some reason pointer down is handled differently from pointer up and drag. // Floating windows: relative coordinates are great. // Non floating windows: rather than global coordinates, relative are needed if self.enabled { - if let Some(details) = &self.window_details_under_mouse { - let action = if down { - "press".to_owned() - } else { - "release".to_owned() - }; - - let position = if !down && self.has_moved { - self.drag_position - } else { - self.relative_position - }; + let button_text = match mouse_button { + MouseButton::Left => Some("left"), + MouseButton::Right => Some("right"), + MouseButton::Middle => Some("middle"), + _ => None, + }; - self.command_sender - .send(UiCommand::MouseButton { - action, - grid_id: details.id, - position: position.into(), - }) - .ok(); - } + if let Some(button_text) = button_text { + if let Some(details) = &self.window_details_under_mouse { + let action = if down { + "press".to_owned() + } else { + "release".to_owned() + }; + + let position = if !down && self.has_moved { + self.drag_position + } else { + self.relative_position + }; + + self.command_sender + .send(UiCommand::MouseButton { + button: button_text.to_string(), + action, + grid_id: details.id, + position: position.into(), + }) + .ok(); + } + } } self.dragging = down; @@ -302,12 +312,12 @@ impl MouseManager { Event::WindowEvent { event: WindowEvent::MouseInput { - button: MouseButton::Left, + button, state, .. }, .. - } => self.handle_pointer_transition(state == &ElementState::Pressed), + } => self.handle_pointer_transition(button, state == &ElementState::Pressed), _ => {} } }