From f6a8ffced07469d2d36f18e1a9b3965072f757d9 Mon Sep 17 00:00:00 2001 From: Tim Biermann Date: Sat, 24 Jul 2021 00:07:47 +0200 Subject: [PATCH] Make waylands app_id and x11s class overrideable (#834) * trying to make app_id and class exchangeable * still fails to hand over the argument * make both app_id and class be set by command line arguments * added missing cfg for class * Changes as requested. Putting the os check in a block however doesn't work for me * getting rid of superfluous to_string() * x11-class argument gets ignored * changed argument name * Update src/cmd_line.rs * changed faulty unwrap * added missing comma * fixed wrong case * fixed class * make cargo fmt happy * exchanged String::from with String::new * make both attributes also overrideable via env::var Co-authored-by: partizan --- src/cmd_line.rs | 34 +++++++++++++++++++++++++++++++- src/window/window_wrapper/mod.rs | 7 ++++++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/cmd_line.rs b/src/cmd_line.rs index 6ac0578..683b63c 100644 --- a/src/cmd_line.rs +++ b/src/cmd_line.rs @@ -17,6 +17,8 @@ pub struct CmdLineSettings { pub multi_grid: bool, pub maximized: bool, pub frameless: bool, + pub wayland_app_id: String, + pub x11_wm_class: String, } impl Default for CmdLineSettings { @@ -34,6 +36,8 @@ impl Default for CmdLineSettings { multi_grid: false, maximized: false, frameless: false, + wayland_app_id: String::new(), + x11_wm_class: String::new(), } } } @@ -76,7 +80,11 @@ pub fn handle_command_line_arguments() -> Result<(), String> { .long("frameless") .help("Removes the window frame. NOTE: Window might not be resizable after this setting is enabled.") ) - .arg(Arg::with_name("wsl").long("wsl").help("Run in WSL")) + .arg( + Arg::with_name("wsl") + .long("wsl") + .help("Run in WSL") + ) .arg( Arg::with_name("remote_tcp") .long("remote-tcp") @@ -101,6 +109,16 @@ pub fn handle_command_line_arguments() -> Result<(), String> { .takes_value(true) .last(true) .help("Specify Arguments to pass down to neovim"), + ) + .arg( + Arg::with_name("wayland_app_id") + .long("wayland-app-id") + .takes_value(true) + ) + .arg( + Arg::with_name("x11_wm_class") + .long("x11-wm-class") + .takes_value(true) ); let matches = clapp.get_matches(); @@ -132,6 +150,20 @@ pub fn handle_command_line_arguments() -> Result<(), String> { wsl: matches.is_present("wsl"), frameless: matches.is_present("frameless") || std::env::var("NEOVIDE_FRAMELESS").is_ok(), geometry: parse_window_geometry(matches.value_of("geometry").map(|i| i.to_owned()))?, + wayland_app_id: match std::env::var("NEOVIDE_APP_ID") { + Ok(val) => val, + Err(_) => matches + .value_of("wayland_app_id") + .unwrap_or("neovide") + .to_string(), + }, + x11_wm_class: match std::env::var("NEOVIDE_WM_CLASS") { + Ok(val) => val, + Err(_) => matches + .value_of("x11_wm_class") + .unwrap_or("neovide") + .to_string(), + }, }); Ok(()) } diff --git a/src/window/window_wrapper/mod.rs b/src/window/window_wrapper/mod.rs index 592ca98..93857cf 100644 --- a/src/window/window_wrapper/mod.rs +++ b/src/window/window_wrapper/mod.rs @@ -222,7 +222,12 @@ pub fn start_loop( .with_decorations(!SETTINGS.get::().frameless); #[cfg(target_os = "linux")] - let winit_window_builder = winit_window_builder.with_app_id("Neovide".to_string()); + let winit_window_builder = winit_window_builder + .with_app_id(SETTINGS.get::().wayland_app_id) + .with_class( + "neovide".to_string(), + SETTINGS.get::().x11_wm_class, + ); let windowed_context = ContextBuilder::new() .with_pixel_format(24, 8)