formatting and clippy fixes

macos-click-through
Keith Simmons 3 years ago
parent 80d5ed983c
commit cbdb28b094

@ -66,12 +66,16 @@ impl Handler for NeovimHandler {
#[cfg(windows)] #[cfg(windows)]
"neovide.register_right_click" => { "neovide.register_right_click" => {
let ui_command_sender = ui_command_sender.lock(); let ui_command_sender = ui_command_sender.lock();
ui_command_sender.send(ParallelCommand::RegisterRightClick.into()).ok(); ui_command_sender
.send(ParallelCommand::RegisterRightClick.into())
.ok();
} }
#[cfg(windows)] #[cfg(windows)]
"neovide.unregister_right_click" => { "neovide.unregister_right_click" => {
let ui_command_sender = ui_command_sender.lock(); let ui_command_sender = ui_command_sender.lock();
ui_command_sender.send(ParallelCommand::UnregisterRightClick.into()).ok(); ui_command_sender
.send(ParallelCommand::UnregisterRightClick.into())
.ok();
} }
_ => {} _ => {}
}); });

@ -22,7 +22,7 @@ use crate::{cmd_line::CmdLineSettings, error_handling::ResultPanicExplanation};
pub use events::*; pub use events::*;
use handler::NeovimHandler; use handler::NeovimHandler;
pub use tx_wrapper::{TxWrapper, WrapTx}; pub use tx_wrapper::{TxWrapper, WrapTx};
pub use ui_commands::{UiCommand, SerialCommand, ParallelCommand, start_ui_command_handler}; pub use ui_commands::{start_ui_command_handler, ParallelCommand, SerialCommand, UiCommand};
#[cfg(windows)] #[cfg(windows)]
fn set_windows_creation_flags(cmd: &mut Command) { fn set_windows_creation_flags(cmd: &mut Command) {

@ -1,21 +1,11 @@
use std::sync::{ use std::sync::Arc;
Arc,
atomic::{
AtomicBool,
Ordering,
},
};
use log::trace;
#[cfg(windows)] #[cfg(windows)]
use log::error; use log::error;
use log::trace;
use nvim_rs::Neovim; use nvim_rs::Neovim;
use tokio::sync::mpsc::{ use tokio::sync::mpsc::{unbounded_channel, UnboundedReceiver};
unbounded_channel,
UnboundedReceiver,
UnboundedSender,
};
use crate::bridge::TxWrapper; use crate::bridge::TxWrapper;
use crate::running_tracker::RUNNING_TRACKER; use crate::running_tracker::RUNNING_TRACKER;
@ -180,7 +170,6 @@ impl ParallelCommand {
} }
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum UiCommand { pub enum UiCommand {
Serial(SerialCommand), Serial(SerialCommand),
@ -199,14 +188,18 @@ impl From<ParallelCommand> for UiCommand {
} }
} }
pub fn start_ui_command_handler(mut ui_command_receiver: UnboundedReceiver<UiCommand>, nvim: Arc<Neovim<TxWrapper>>) { pub fn start_ui_command_handler(
mut ui_command_receiver: UnboundedReceiver<UiCommand>,
nvim: Arc<Neovim<TxWrapper>>,
) {
let (serial_tx, mut serial_rx) = unbounded_channel::<SerialCommand>(); let (serial_tx, mut serial_rx) = unbounded_channel::<SerialCommand>();
let ui_command_nvim = nvim.clone(); let ui_command_nvim = nvim.clone();
tokio::spawn(async move { tokio::spawn(async move {
while RUNNING_TRACKER.is_running() { while RUNNING_TRACKER.is_running() {
match ui_command_receiver.recv().await { match ui_command_receiver.recv().await {
Some(UiCommand::Serial(serial_command)) => Some(UiCommand::Serial(serial_command)) => serial_tx
serial_tx.send(serial_command).expect("Could not send serial ui command"), .send(serial_command)
.expect("Could not send serial ui command"),
Some(UiCommand::Parallel(parallel_command)) => { Some(UiCommand::Parallel(parallel_command)) => {
let ui_command_nvim = ui_command_nvim.clone(); let ui_command_nvim = ui_command_nvim.clone();
tokio::spawn(async move { tokio::spawn(async move {
@ -220,16 +213,15 @@ pub fn start_ui_command_handler(mut ui_command_receiver: UnboundedReceiver<UiCom
} }
}); });
let serial_command_nvim = nvim.clone();
tokio::spawn(async move { tokio::spawn(async move {
while RUNNING_TRACKER.is_running() { while RUNNING_TRACKER.is_running() {
match serial_rx.recv().await { match serial_rx.recv().await {
Some(serial_command) => { Some(serial_command) => {
serial_command.execute(&serial_command_nvim).await; serial_command.execute(&nvim).await;
}, }
None => { None => {
RUNNING_TRACKER.quit("serial ui command channel failed"); RUNNING_TRACKER.quit("serial ui command channel failed");
}, }
} }
} }
}); });

@ -19,9 +19,9 @@ mod editor;
mod error_handling; mod error_handling;
mod redraw_scheduler; mod redraw_scheduler;
mod renderer; mod renderer;
mod running_tracker;
mod settings; mod settings;
mod utils; mod utils;
mod running_tracker;
mod window; mod window;
mod windows_utils; mod windows_utils;
@ -30,7 +30,7 @@ extern crate derive_new;
#[macro_use] #[macro_use]
extern crate lazy_static; extern crate lazy_static;
use std::sync::{atomic::AtomicBool, mpsc::channel, Arc}; use std::sync::mpsc::channel;
use log::trace; use log::trace;
use tokio::sync::mpsc::unbounded_channel; use tokio::sync::mpsc::unbounded_channel;

@ -1,9 +1,6 @@
use std::sync::{ use std::sync::{
Arc, atomic::{AtomicBool, Ordering},
atomic::{ Arc,
AtomicBool,
Ordering,
},
}; };
use log::info; use log::info;
@ -13,13 +10,13 @@ lazy_static! {
} }
pub struct RunningTracker { pub struct RunningTracker {
running: Arc<AtomicBool> running: Arc<AtomicBool>,
} }
impl RunningTracker { impl RunningTracker {
fn new() -> Self { fn new() -> Self {
Self { Self {
running: Arc::new(AtomicBool::new(true)) running: Arc::new(AtomicBool::new(true)),
} }
} }

@ -107,11 +107,15 @@ impl GlutinWindowWrapper {
} }
pub fn handle_focus_lost(&mut self) { pub fn handle_focus_lost(&mut self) {
self.ui_command_sender.send(ParallelCommand::FocusLost.into()).ok(); self.ui_command_sender
.send(ParallelCommand::FocusLost.into())
.ok();
} }
pub fn handle_focus_gained(&mut self) { pub fn handle_focus_gained(&mut self) {
self.ui_command_sender.send(ParallelCommand::FocusGained.into()).ok(); self.ui_command_sender
.send(ParallelCommand::FocusGained.into())
.ok();
REDRAW_SCHEDULER.queue_next_frame(); REDRAW_SCHEDULER.queue_next_frame();
} }
@ -144,9 +148,10 @@ impl GlutinWindowWrapper {
.. ..
} => { } => {
self.ui_command_sender self.ui_command_sender
.send(ParallelCommand::FileDrop( .send(
path.into_os_string().into_string().unwrap(), ParallelCommand::FileDrop(path.into_os_string().into_string().unwrap())
).into()) .into(),
)
.ok(); .ok();
} }
Event::WindowEvent { Event::WindowEvent {
@ -221,10 +226,13 @@ impl GlutinWindowWrapper {
} }
self.saved_grid_size = Some(grid_size); self.saved_grid_size = Some(grid_size);
self.ui_command_sender self.ui_command_sender
.send(ParallelCommand::Resize { .send(
width: grid_size.width, ParallelCommand::Resize {
height: grid_size.height, width: grid_size.width,
}.into()) height: grid_size.height,
}
.into(),
)
.ok(); .ok();
} }

@ -162,12 +162,15 @@ impl MouseManager {
// If dragging and we haven't already sent a position, send a drag command // If dragging and we haven't already sent a position, send a drag command
if self.dragging.is_some() && has_moved { if self.dragging.is_some() && has_moved {
self.command_sender self.command_sender
.send(SerialCommand::Drag { .send(
button: self.dragging.as_ref().unwrap().to_owned(), SerialCommand::Drag {
grid_id: relevant_window_details.id, button: self.dragging.as_ref().unwrap().to_owned(),
position: self.drag_position.into(), grid_id: relevant_window_details.id,
modifier_string: keyboard_manager.format_modifier_string(true), position: self.drag_position.into(),
}.into()) modifier_string: keyboard_manager.format_modifier_string(true),
}
.into(),
)
.ok(); .ok();
} else { } else {
// otherwise, update the window_id_under_mouse to match the one selected // otherwise, update the window_id_under_mouse to match the one selected
@ -203,13 +206,16 @@ impl MouseManager {
}; };
self.command_sender self.command_sender
.send(SerialCommand::MouseButton { .send(
button: button_text.clone(), SerialCommand::MouseButton {
action, button: button_text.clone(),
grid_id: details.id, action,
position: position.into(), grid_id: details.id,
modifier_string: keyboard_manager.format_modifier_string(true), position: position.into(),
}.into()) modifier_string: keyboard_manager.format_modifier_string(true),
}
.into(),
)
.ok(); .ok();
} }
@ -247,7 +253,8 @@ impl MouseManager {
.unwrap_or(0), .unwrap_or(0),
position: self.drag_position.into(), position: self.drag_position.into(),
modifier_string: keyboard_manager.format_modifier_string(true), modifier_string: keyboard_manager.format_modifier_string(true),
}.into(); }
.into();
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();
} }
@ -273,7 +280,8 @@ impl MouseManager {
.unwrap_or(0), .unwrap_or(0),
position: self.drag_position.into(), position: self.drag_position.into(),
modifier_string: keyboard_manager.format_modifier_string(true), modifier_string: keyboard_manager.format_modifier_string(true),
}.into(); }
.into();
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();
} }

Loading…
Cancel
Save