add modifiers to nvim_input_mouse scroll events

macos-click-through
Keith Simmons 3 years ago committed by Keith Simmons
parent a1fc0bf9c7
commit abd3d52ae3

@ -30,6 +30,7 @@ pub enum UiCommand {
direction: String, direction: String,
grid_id: u64, grid_id: u64,
position: (u32, u32), position: (u32, u32),
modifier_string: String,
}, },
Drag { Drag {
grid_id: u64, grid_id: u64,
@ -79,11 +80,12 @@ impl UiCommand {
direction, direction,
grid_id, grid_id,
position: (grid_x, grid_y), position: (grid_x, grid_y),
modifier_string,
} => { } => {
nvim.input_mouse( nvim.input_mouse(
"wheel", "wheel",
&direction, &direction,
"", &modifier_string,
grid_id as i64, grid_id as i64,
grid_y as i64, grid_y as i64,
grid_x as i64, grid_x as i64,

@ -129,13 +129,19 @@ impl KeyboardManager {
let special = special || self.ctrl || use_alt(self.alt) || self.logo; let special = special || self.ctrl || use_alt(self.alt) || self.logo;
let open = or_empty(special, "<"); let open = or_empty(special, "<");
let modifiers = self.format_modifier_string(use_shift);
let close = or_empty(special, ">");
open.to_owned() + &modifiers + text + close
}
pub fn format_modifier_string(&self, use_shift: bool) -> String {
let shift = or_empty(self.shift && use_shift, "S-"); let shift = or_empty(self.shift && use_shift, "S-");
let ctrl = or_empty(self.ctrl, "C-"); let ctrl = or_empty(self.ctrl, "C-");
let alt = or_empty(use_alt(self.alt), "M-"); let alt = or_empty(use_alt(self.alt), "M-");
let logo = or_empty(self.logo, "D-"); let logo = or_empty(self.logo, "D-");
let close = or_empty(special, ">");
format!("{}{}{}{}{}{}{}", open, shift, ctrl, alt, logo, text, close) shift.to_owned() + ctrl + alt + logo
} }
} }

@ -120,8 +120,8 @@ impl GlutinWindowWrapper {
pub fn handle_event(&mut self, event: Event<()>, running: &Arc<AtomicBool>) { pub fn handle_event(&mut self, event: Event<()>, running: &Arc<AtomicBool>) {
self.keyboard_manager.handle_event(&event); self.keyboard_manager.handle_event(&event);
self.mouse_manager self.mouse_manager.handle_event(
.handle_event(&event, &self.renderer, &self.windowed_context); &event, &self.keyboard_manager, &self.renderer, &self.windowed_context);
match event { match event {
Event::LoopDestroyed => { Event::LoopDestroyed => {
self.handle_quit(running); self.handle_quit(running);

@ -11,6 +11,7 @@ use skia_safe::Rect;
use crate::bridge::UiCommand; use crate::bridge::UiCommand;
use crate::channel_utils::LoggingTx; use crate::channel_utils::LoggingTx;
use crate::renderer::{Renderer, WindowDrawDetails}; use crate::renderer::{Renderer, WindowDrawDetails};
use super::keyboard_manager::KeyboardManager;
fn clamp_position( fn clamp_position(
position: PhysicalPosition<f32>, position: PhysicalPosition<f32>,
@ -210,7 +211,7 @@ impl MouseManager {
} }
} }
fn handle_line_scroll(&mut self, x: f32, y: f32) { fn handle_line_scroll(&mut self, x: f32, y: f32, keyboard_manager: &KeyboardManager) {
if !self.enabled { if !self.enabled {
return; return;
} }
@ -234,6 +235,7 @@ impl MouseManager {
.map(|details| details.id) .map(|details| details.id)
.unwrap_or(0), .unwrap_or(0),
position: self.drag_position.into(), position: self.drag_position.into(),
modifier_string: keyboard_manager.format_modifier_string(true),
}; };
for _ in 0..(new_y - previous_y).abs() { for _ in 0..(new_y - previous_y).abs() {
self.command_sender.send(scroll_command.clone()).ok(); self.command_sender.send(scroll_command.clone()).ok();
@ -259,6 +261,7 @@ impl MouseManager {
.map(|details| details.id) .map(|details| details.id)
.unwrap_or(0), .unwrap_or(0),
position: self.drag_position.into(), position: self.drag_position.into(),
modifier_string: keyboard_manager.format_modifier_string(true),
}; };
for _ in 0..(new_x - previous_x).abs() { for _ in 0..(new_x - previous_x).abs() {
self.command_sender.send(scroll_command.clone()).ok(); self.command_sender.send(scroll_command.clone()).ok();
@ -270,13 +273,18 @@ impl MouseManager {
&mut self, &mut self,
(font_width, font_height): (u64, u64), (font_width, font_height): (u64, u64),
(pixel_x, pixel_y): (f32, f32), (pixel_x, pixel_y): (f32, f32),
keyboard_manager: &KeyboardManager,
) { ) {
self.handle_line_scroll(pixel_x / font_width as f32, pixel_y / font_height as f32); self.handle_line_scroll(
pixel_x / font_width as f32,
pixel_y / font_height as f32,
keyboard_manager);
} }
pub fn handle_event( pub fn handle_event(
&mut self, &mut self,
event: &Event<()>, event: &Event<()>,
keyboard_manager: &KeyboardManager,
renderer: &Renderer, renderer: &Renderer,
windowed_context: &WindowedContext<PossiblyCurrent>, windowed_context: &WindowedContext<PossiblyCurrent>,
) { ) {
@ -297,7 +305,7 @@ impl MouseManager {
.. ..
}, },
.. ..
} => self.handle_line_scroll(*x, *y), } => self.handle_line_scroll(*x, *y, keyboard_manager),
Event::WindowEvent { Event::WindowEvent {
event: event:
WindowEvent::MouseWheel { WindowEvent::MouseWheel {
@ -308,6 +316,7 @@ impl MouseManager {
} => self.handle_pixel_scroll( } => self.handle_pixel_scroll(
renderer.grid_renderer.font_dimensions.into(), renderer.grid_renderer.font_dimensions.into(),
(delta.x as f32, delta.y as f32), (delta.x as f32, delta.y as f32),
keyboard_manager,
), ),
Event::WindowEvent { Event::WindowEvent {
event: WindowEvent::MouseInput { button, state, .. }, event: WindowEvent::MouseInput { button, state, .. },

Loading…
Cancel
Save