feat: Configure click_through as command line argument

macos-click-through
sgoudham 2 years ago
parent ae17af2c55
commit b32b88ca8e
Signed by: hammy
GPG Key ID: 44E818FD5457EEA4

@ -24,6 +24,8 @@ pub struct CmdLineSettings {
pub x11_wm_class: String, pub x11_wm_class: String,
// Disable open multiple files as tabs // Disable open multiple files as tabs
pub no_tabs: bool, pub no_tabs: bool,
// Replicate macOS behaviour where first click is not registered
pub click_through: bool,
} }
impl Default for CmdLineSettings { impl Default for CmdLineSettings {
@ -43,6 +45,7 @@ impl Default for CmdLineSettings {
multi_grid: false, multi_grid: false,
no_idle: false, no_idle: false,
srgb: true, srgb: true,
click_through: false,
// Command-line arguments with environment variable fallback // Command-line arguments with environment variable fallback
neovim_bin: None, neovim_bin: None,
wayland_app_id: String::new(), wayland_app_id: String::new(),
@ -105,6 +108,11 @@ pub fn handle_command_line_arguments(args: Vec<String>) -> Result<(), String> {
.long("wsl") .long("wsl")
.help("Run in WSL") .help("Run in WSL")
) )
.arg(
Arg::new("click_through")
.long("click-through")
.help("On first mouse click, move the cursor to location of mouse click. DISCLAIMER: Providing this flag on non-macOS systems will not change anything")
)
// Command-line flags with environment variable fallback // Command-line flags with environment variable fallback
.arg( .arg(
Arg::new("frame") Arg::new("frame")
@ -186,6 +194,10 @@ pub fn handle_command_line_arguments(args: Vec<String>) -> Result<(), String> {
no_fork: matches.is_present("nofork"), no_fork: matches.is_present("nofork"),
remote_tcp: matches.value_of("remote_tcp").map(|i| i.to_owned()), remote_tcp: matches.value_of("remote_tcp").map(|i| i.to_owned()),
wsl: matches.is_present("wsl"), wsl: matches.is_present("wsl"),
#[cfg(target_os = "macos")]
click_through: matches.is_present("click_through"),
#[cfg(not(target_os = "macos"))]
click_through: true,
// Command-line flags with environment variable fallback // Command-line flags with environment variable fallback
frame: match matches.value_of("frame") { frame: match matches.value_of("frame") {
Some(val) => Frame::from_string(val.to_string()), Some(val) => Frame::from_string(val.to_string()),
@ -197,7 +209,7 @@ pub fn handle_command_line_arguments(args: Vec<String>) -> Result<(), String> {
maximized: matches.is_present("maximized") || std::env::var("NEOVIDE_MAXIMIZED").is_ok(), maximized: matches.is_present("maximized") || std::env::var("NEOVIDE_MAXIMIZED").is_ok(),
multi_grid: matches.is_present("multi_grid") || std::env::var("NEOVIDE_MULTIGRID").is_ok(), multi_grid: matches.is_present("multi_grid") || std::env::var("NEOVIDE_MULTIGRID").is_ok(),
no_idle: matches.is_present("noidle") || std::env::var("NEOVIDE_NO_IDLE").is_ok(), no_idle: matches.is_present("noidle") || std::env::var("NEOVIDE_NO_IDLE").is_ok(),
// Srgb is enabled by default, so set it to false if nosrgb or NOEVIDE_NO_SRGB is set // Srgb is enabled by default, so set it to false if nosrgb or NEOVIDE_NO_SRGB is set
srgb: !(matches.is_present("nosrgb") || std::env::var("NEOVIDE_NO_SRGB").is_ok()), srgb: !(matches.is_present("nosrgb") || std::env::var("NEOVIDE_NO_SRGB").is_ok()),
// Command-line arguments with environment variable fallback // Command-line arguments with environment variable fallback
neovim_bin: matches neovim_bin: matches
@ -345,6 +357,18 @@ mod tests {
assert!(SETTINGS.get::<CmdLineSettings>().log_to_file); assert!(SETTINGS.get::<CmdLineSettings>().log_to_file);
} }
#[test]
fn test_click_through() {
let args: Vec<String> = vec!["neovide", "--click-through"]
.iter()
.map(|s| s.to_string())
.collect();
let _accessing_settings = ACCESSING_SETTINGS.lock().unwrap();
handle_command_line_arguments(args).expect("Could not parse arguments");
assert!(SETTINGS.get::<CmdLineSettings>().click_through)
}
#[test] #[test]
fn test_frameless_flag() { fn test_frameless_flag() {
let args: Vec<String> = vec!["neovide", "--frame=full"] let args: Vec<String> = vec!["neovide", "--frame=full"]

@ -13,7 +13,7 @@ use glutin::{
}, },
PossiblyCurrent, WindowedContext, PossiblyCurrent, WindowedContext,
}; };
use log::info;
use skia_safe::Rect; use skia_safe::Rect;
use crate::{ use crate::{
@ -87,8 +87,8 @@ pub struct MouseManager {
mouse_hidden: bool, mouse_hidden: bool,
pub enabled: bool, pub enabled: bool,
// Not exactly a mouse setting but ideally needs to exist for some state // Not a mouse setting but needs to exist to track the state of WindowFocusedEvents
current_window_focused: bool, window_focused: bool,
} }
impl MouseManager { impl MouseManager {
@ -104,7 +104,7 @@ impl MouseManager {
window_details_under_mouse: None, window_details_under_mouse: None,
mouse_hidden: false, mouse_hidden: false,
enabled: true, enabled: true,
current_window_focused: false, window_focused: false,
} }
} }
@ -220,7 +220,10 @@ impl MouseManager {
self.relative_position self.relative_position
}; };
if click_through || !self.current_window_focused { // Only register command if:
// a) click through is enabled
// b) the current window doesn't have focus
if click_through || !self.window_focused {
EVENT_AGGREGATOR.send(UiCommand::Serial(SerialCommand::MouseButton { EVENT_AGGREGATOR.send(UiCommand::Serial(SerialCommand::MouseButton {
button: button_text.clone(), button: button_text.clone(),
action, action,
@ -450,7 +453,7 @@ impl MouseManager {
Event::WindowEvent { Event::WindowEvent {
event: WindowEvent::Focused(focused), event: WindowEvent::Focused(focused),
.. ..
} => self.current_window_focused = *focused, } => self.window_focused = *focused,
Event::WindowEvent { Event::WindowEvent {
event: WindowEvent::CursorMoved { position, .. }, event: WindowEvent::CursorMoved { position, .. },
.. ..
@ -517,8 +520,9 @@ impl MouseManager {
window_settings.click_through, window_settings.click_through,
); );
// Always reset focused to false to prevent all mouse inputs not working // We want to always reset window_focused to false to ensure that subsequent mouse events
self.current_window_focused = false; // are properly registered after the initial window focus.
self.window_focused = false;
} }
Event::WindowEvent { Event::WindowEvent {
event: event:

@ -28,7 +28,7 @@ impl Default for WindowSettings {
hide_mouse_when_typing: false, hide_mouse_when_typing: false,
touch_deadzone: 6.0, touch_deadzone: 6.0,
touch_drag_timeout: 0.17, touch_drag_timeout: 0.17,
click_through: false click_through: SETTINGS.get::<CmdLineSettings>().click_through,
} }
} }
} }

Loading…
Cancel
Save