mouse configuration via mouseon mouseoff

macos-click-through
Keith Simmons 5 years ago
parent ef2d99b508
commit a146c1aaa3

@ -128,6 +128,8 @@ pub enum RedrawEvent {
ModeChange { ModeChange {
mode_index: u64, mode_index: u64,
}, },
MouseOn,
MouseOff,
BusyStart, BusyStart,
BusyStop, BusyStop,
Flush, Flush,
@ -779,6 +781,8 @@ pub fn parse_redraw_event(event_value: Value) -> Result<Vec<RedrawEvent>> {
"mode_info_set" => Some(parse_mode_info_set(event_parameters)?), "mode_info_set" => Some(parse_mode_info_set(event_parameters)?),
"option_set" => Some(parse_option_set(event_parameters)?), "option_set" => Some(parse_option_set(event_parameters)?),
"mode_change" => Some(parse_mode_change(event_parameters)?), "mode_change" => Some(parse_mode_change(event_parameters)?),
"mouse_on" => Some(RedrawEvent::MouseOn),
"mouse_off" => Some(RedrawEvent::MouseOff),
"busy_start" => Some(RedrawEvent::BusyStart), "busy_start" => Some(RedrawEvent::BusyStart),
"busy_stop" => Some(RedrawEvent::BusyStop), "busy_stop" => Some(RedrawEvent::BusyStop),
"flush" => Some(RedrawEvent::Flush), "flush" => Some(RedrawEvent::Flush),

@ -25,10 +25,10 @@ impl Handler for NeovimHandler {
task::spawn_blocking(move || match event_name.as_ref() { task::spawn_blocking(move || match event_name.as_ref() {
"redraw" => { "redraw" => {
handle_redraw_event_group(arguments); handle_redraw_event_group(arguments);
} },
"setting_changed" => { "setting_changed" => {
SETTINGS.handle_changed_notification(arguments); SETTINGS.handle_changed_notification(arguments);
} },
_ => {} _ => {}
}) })
.await .await

@ -3,6 +3,8 @@ use nvim_rs::compat::tokio::Compat;
use nvim_rs::Neovim; use nvim_rs::Neovim;
use tokio::process::ChildStdin; use tokio::process::ChildStdin;
use crate::editor::EDITOR;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum UiCommand { pub enum UiCommand {
Resize { Resize {
@ -38,21 +40,30 @@ impl UiCommand {
UiCommand::MouseButton { UiCommand::MouseButton {
action, action,
position: (grid_x, grid_y), position: (grid_x, grid_y),
} => nvim } => {
.input_mouse("left", &action, "", 0, grid_y as i64, grid_x as i64) if { EDITOR.lock().mouse_enabled } {
.await nvim.input_mouse("left", &action, "", 0, grid_y as i64, grid_x as i64)
.expect("Mouse Input Failed"), .await
.expect("Mouse Input Failed");
}
},
UiCommand::Scroll { UiCommand::Scroll {
direction, direction,
position: (grid_x, grid_y), position: (grid_x, grid_y),
} => nvim } => {
.input_mouse("wheel", &direction, "", 0, grid_y as i64, grid_x as i64) if { EDITOR.lock().mouse_enabled } {
.await nvim.input_mouse("wheel", &direction, "", 0, grid_y as i64, grid_x as i64)
.expect("Mouse Scroll Failed"), .await
UiCommand::Drag(grid_x, grid_y) => nvim .expect("Mouse Scroll Failed");
.input_mouse("left", "drag", "", 0, grid_y as i64, grid_x as i64) }
.await },
.expect("Mouse Drag Failed"), UiCommand::Drag(grid_x, grid_y) => {
if { EDITOR.lock().mouse_enabled } {
nvim.input_mouse("left", "drag", "", 0, grid_y as i64, grid_x as i64)
.await
.expect("Mouse Drag Failed");
}
},
UiCommand::FocusLost => nvim UiCommand::FocusLost => nvim
.command("if exists('#FocusLost') | doautocmd <nomodeline> FocusLost | endif") .command("if exists('#FocusLost') | doautocmd <nomodeline> FocusLost | endif")
.await .await

@ -32,6 +32,7 @@ pub struct DrawCommand {
pub struct Editor { pub struct Editor {
pub grid: CharacterGrid, pub grid: CharacterGrid,
pub title: String, pub title: String,
pub mouse_enabled: bool,
pub font_name: Option<String>, pub font_name: Option<String>,
pub font_size: Option<f32>, pub font_size: Option<f32>,
pub cursor: Cursor, pub cursor: Cursor,
@ -45,6 +46,7 @@ impl Editor {
let mut editor = Editor { let mut editor = Editor {
grid: CharacterGrid::new(window_geometry_or_default()), grid: CharacterGrid::new(window_geometry_or_default()),
title: "Neovide".to_string(), title: "Neovide".to_string(),
mouse_enabled: true,
font_name: None, font_name: None,
font_size: None, font_size: None,
cursor: Cursor::new(), cursor: Cursor::new(),
@ -68,26 +70,32 @@ impl Editor {
RedrawEvent::OptionSet { gui_option } => self.set_option(gui_option), RedrawEvent::OptionSet { gui_option } => self.set_option(gui_option),
RedrawEvent::ModeChange { mode_index } => { RedrawEvent::ModeChange { mode_index } => {
self.cursor.change_mode(mode_index, &self.defined_styles) self.cursor.change_mode(mode_index, &self.defined_styles)
} },
RedrawEvent::MouseOn => {
self.mouse_enabled = true;
},
RedrawEvent::MouseOff => {
self.mouse_enabled = false;
},
RedrawEvent::BusyStart => { RedrawEvent::BusyStart => {
trace!("Cursor off"); trace!("Cursor off");
self.cursor.enabled = false; self.cursor.enabled = false;
} },
RedrawEvent::BusyStop => { RedrawEvent::BusyStop => {
trace!("Cursor on"); trace!("Cursor on");
self.cursor.enabled = true; self.cursor.enabled = true;
} },
RedrawEvent::Flush => { RedrawEvent::Flush => {
trace!("Image flushed"); trace!("Image flushed");
REDRAW_SCHEDULER.queue_next_frame(); REDRAW_SCHEDULER.queue_next_frame();
} },
RedrawEvent::Resize { width, height, .. } => self.grid.resize(width, height), RedrawEvent::Resize { width, height, .. } => self.grid.resize(width, height),
RedrawEvent::DefaultColorsSet { colors } => { RedrawEvent::DefaultColorsSet { colors } => {
self.default_style = Arc::new(Style::new(colors)) self.default_style = Arc::new(Style::new(colors))
} },
RedrawEvent::HighlightAttributesDefine { id, style } => { RedrawEvent::HighlightAttributesDefine { id, style } => {
self.defined_styles.insert(id, Arc::new(style)); self.defined_styles.insert(id, Arc::new(style));
} },
RedrawEvent::GridLine { RedrawEvent::GridLine {
row, row,
column_start, column_start,

Loading…
Cancel
Save