format files

macos-click-through
keith 4 years ago
parent edd082d7af
commit aeda4ad2df

@ -263,7 +263,7 @@ pub enum RedrawEvent {
fn unpack_color(packed_color: u64) -> Color4f { fn unpack_color(packed_color: u64) -> Color4f {
let packed_color = packed_color as u32; let packed_color = packed_color as u32;
let r = ((packed_color & 0xff0000) >> 16) as f32; let r = ((packed_color & 0x00ff_0000) >> 16) as f32;
let g = ((packed_color & 0xff00) >> 8) as f32; let g = ((packed_color & 0xff00) >> 8) as f32;
let b = (packed_color & 0xff) as f32; let b = (packed_color & 0xff) as f32;
Color4f { Color4f {

@ -1,5 +1,5 @@
use async_trait::async_trait; use async_trait::async_trait;
use log::{trace, error}; use log::{error, trace};
use nvim_rs::{compat::tokio::Compat, Handler, Neovim}; use nvim_rs::{compat::tokio::Compat, Handler, Neovim};
use rmpv::Value; use rmpv::Value;
use tokio::process::ChildStdin; use tokio::process::ChildStdin;
@ -10,8 +10,7 @@ use crate::settings::SETTINGS;
#[cfg(windows)] #[cfg(windows)]
use crate::settings::windows_registry::{ use crate::settings::windows_registry::{
unregister_rightclick, register_rightclick_directory, register_rightclick_file, unregister_rightclick,
register_rightclick_directory, register_rightclick_file
}; };
#[derive(Clone)] #[derive(Clone)]
@ -36,11 +35,16 @@ impl Handler for NeovimHandler {
SETTINGS.handle_changed_notification(arguments); SETTINGS.handle_changed_notification(arguments);
} }
"neovide.register_right_click" => { "neovide.register_right_click" => {
if cfg!(windows) && if cfg!(windows) {
!(unregister_rightclick() && if unregister_rightclick() {
register_rightclick_directory() && error!("Setup of Windows Registry failed during unregister. Try running as Admin?");
register_rightclick_file()) { }
error!("Setup of Windows Registry failed, probably no Admin"); if !register_rightclick_directory() {
error!("Setup of Windows Registry failed during directory registration. Try running as Admin?");
}
if !register_rightclick_file() {
error!("Setup of Windows Registry failed during file registration. Try running as Admin?");
}
} }
} }
"neovide.unregister_right_click" => { "neovide.unregister_right_click" => {

@ -32,7 +32,7 @@ lazy_static! {
#[cfg(windows)] #[cfg(windows)]
fn set_windows_creation_flags(cmd: &mut Command) { fn set_windows_creation_flags(cmd: &mut Command) {
cmd.creation_flags(0x08000000); // CREATE_NO_WINDOW cmd.creation_flags(0x0800_0000); // CREATE_NO_WINDOW
} }
#[cfg(windows)] #[cfg(windows)]
@ -41,10 +41,7 @@ fn platform_build_nvim_cmd(bin: &str) -> Option<Command> {
return None; return None;
} }
if env::args() if env::args().any(|arg| arg == "--wsl") {
.collect::<Vec<String>>()
.contains(&String::from("--wsl"))
{
let mut cmd = Command::new("wsl"); let mut cmd = Command::new("wsl");
cmd.arg(bin); cmd.arg(bin);
Some(cmd) Some(cmd)
@ -109,13 +106,19 @@ async fn drain(receiver: &mut UnboundedReceiver<UiCommand>) -> Option<Vec<UiComm
} }
fn build_neovide_command(channel: u64, num_args: u64, command: &str, event: &str) -> String { fn build_neovide_command(channel: u64, num_args: u64, command: &str, event: &str) -> String {
let nargs: String = if num_args > 1 { "+".to_string() } else { num_args.to_string() }; let nargs: String = if num_args > 1 {
"+".to_string()
} else {
num_args.to_string()
};
if num_args == 0 { if num_args == 0 {
return format!("command! -nargs={} -complete=expression {} call rpcnotify({}, 'neovide.{}')", return format!(
"command! -nargs={} -complete=expression {} call rpcnotify({}, 'neovide.{}')",
nargs, command, channel, event nargs, command, channel, event
); );
} else { } else {
return format!("command! -nargs={} -complete=expression {} call rpcnotify({}, 'neovide.{}', <args>)", return format!(
"command! -nargs={} -complete=expression {} call rpcnotify({}, 'neovide.{}', <args>)",
nargs, command, channel, event nargs, command, channel, event
); );
}; };
@ -169,16 +172,22 @@ async fn start_process(mut receiver: UnboundedReceiver<UiCommand>) {
nvim.set_client_info( nvim.set_client_info(
"neovide", "neovide",
vec![(Value::from("major"), Value::from(0u64)), vec![
(Value::from("minor"), Value::from(6u64))], (Value::from("major"), Value::from(0u64)),
(Value::from("minor"), Value::from(6u64)),
],
"ui", "ui",
vec![], vec![],
vec![] vec![],
).await.ok(); )
.await
.ok();
// parsing the client list to get the channel id for neovide // parsing the client list to get the channel id for neovide
let neovide_channel: u64 = let neovide_channel: u64 = nvim
nvim.list_chans().await.ok() .list_chans()
.await
.ok()
.and_then(|chans| { .and_then(|chans| {
for chan in chans.iter() { for chan in chans.iter() {
let mut found = false; let mut found = false;
@ -203,16 +212,32 @@ async fn start_process(mut receiver: UnboundedReceiver<UiCommand>) {
} }
} }
None None
}).unwrap_or(0); })
info!("Neovide registered to nvim with channel id {}", neovide_channel); .unwrap_or(0);
info!(
"Neovide registered to nvim with channel id {}",
neovide_channel
);
#[cfg(windows)] #[cfg(windows)]
nvim.command(&build_neovide_command(neovide_channel, 0, "NeovideRegisterRightClick", "register_right_click")) nvim.command(&build_neovide_command(
.await.ok(); neovide_channel,
0,
"NeovideRegisterRightClick",
"register_right_click",
))
.await
.ok();
#[cfg(windows)] #[cfg(windows)]
nvim.command(&build_neovide_command(neovide_channel, 0, "NeovideUnregisterRightClick", "unregister_right_click")) nvim.command(&build_neovide_command(
.await.ok(); neovide_channel,
0,
"NeovideUnregisterRightClick",
"unregister_right_click",
))
.await
.ok();
nvim.ui_attach(width as i64, height as i64, &options) nvim.ui_attach(width as i64, height as i64, &options)
.await .await

@ -366,8 +366,8 @@ struct RngState {
impl RngState { impl RngState {
fn new() -> RngState { fn new() -> RngState {
RngState { RngState {
state: 0x853C49E6748FEA9Bu64, state: 0x853C_49E6_748F_EA9Bu64,
inc: (0xDA3E39CB94B95BDBu64 << 1) | 1, inc: (0xDA3E_39CB_94B9_5BDBu64 << 1) | 1,
} }
} }
fn next(&mut self) -> u32 { fn next(&mut self) -> u32 {

@ -1,30 +1,29 @@
use std::ffi::{CString}; use std::ffi::CString;
use std::ptr::{null, null_mut}; use std::ptr::{null, null_mut};
#[cfg(windows)] #[cfg(windows)]
use winapi::{ use winapi::{
shared::minwindef::{HKEY, MAX_PATH, DWORD}, shared::minwindef::{DWORD, HKEY, MAX_PATH},
um::{ um::{
winnt::{ libloaderapi::GetModuleFileNameA,
REG_SZ, REG_OPTION_NON_VOLATILE, KEY_WRITE winnt::{KEY_WRITE, REG_OPTION_NON_VOLATILE, REG_SZ},
winreg::{RegCloseKey, RegCreateKeyExA, RegDeleteTreeA, RegSetValueExA, HKEY_CLASSES_ROOT},
}, },
winreg::{
RegCreateKeyExA, RegSetValueExA, RegCloseKey, RegDeleteTreeA,
HKEY_CLASSES_ROOT
},
libloaderapi::{
GetModuleFileNameA
},
}
}; };
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
fn get_binary_path() -> String { fn get_binary_path() -> String {
let mut buffer = vec![0u8; MAX_PATH]; let mut buffer = vec![0u8; MAX_PATH];
unsafe { unsafe {
GetModuleFileNameA(null_mut(), buffer.as_mut_ptr() as *mut i8, MAX_PATH as DWORD); GetModuleFileNameA(
null_mut(),
buffer.as_mut_ptr() as *mut i8,
MAX_PATH as DWORD,
);
CString::from_vec_unchecked(buffer) CString::from_vec_unchecked(buffer)
.into_string().unwrap_or_else(|_| "".to_string()) .into_string()
.trim_end_matches(char::from(0)).to_string() .unwrap_or_else(|_| "".to_string())
.trim_end_matches(char::from(0))
.to_string()
} }
} }
@ -44,41 +43,83 @@ pub fn register_rightclick_directory() -> bool {
let neovide_path = get_binary_path(); let neovide_path = get_binary_path();
let mut registry_key: HKEY = null_mut(); let mut registry_key: HKEY = null_mut();
let str_registry_path = CString::new("Directory\\Background\\shell\\Neovide").unwrap(); let str_registry_path = CString::new("Directory\\Background\\shell\\Neovide").unwrap();
let str_registry_command_path = CString::new("Directory\\Background\\shell\\Neovide\\command").unwrap(); let str_registry_command_path =
CString::new("Directory\\Background\\shell\\Neovide\\command").unwrap();
let str_icon = CString::new("Icon").unwrap(); let str_icon = CString::new("Icon").unwrap();
let str_command = CString::new(format!("{} \"%V\"", neovide_path).as_bytes()).unwrap(); let str_command = CString::new(format!("{} \"%V\"", neovide_path).as_bytes()).unwrap();
let str_description = CString::new("Open with Neovide").unwrap(); let str_description = CString::new("Open with Neovide").unwrap();
let str_neovide_path = CString::new(neovide_path.as_bytes()).unwrap(); let str_neovide_path = CString::new(neovide_path.as_bytes()).unwrap();
unsafe { unsafe {
if RegCreateKeyExA( if RegCreateKeyExA(
HKEY_CLASSES_ROOT, str_registry_path.as_ptr(), HKEY_CLASSES_ROOT,
0, null_mut(), str_registry_path.as_ptr(),
REG_OPTION_NON_VOLATILE, KEY_WRITE, 0,
null_mut(), &mut registry_key, null_mut()) != 0 { null_mut(),
REG_OPTION_NON_VOLATILE,
KEY_WRITE,
null_mut(),
&mut registry_key,
null_mut(),
) != 0
{
RegCloseKey(registry_key); RegCloseKey(registry_key);
return false; return false;
} }
let registry_values = [ let registry_values = [
(null(), REG_SZ, str_description.as_ptr() as *const u8, str_description.to_bytes().len() + 1), (
(str_icon.as_ptr(), REG_SZ, str_neovide_path.as_ptr() as *const u8, str_neovide_path.to_bytes().len() + 1), null(),
REG_SZ,
str_description.as_ptr() as *const u8,
str_description.to_bytes().len() + 1,
),
(
str_icon.as_ptr(),
REG_SZ,
str_neovide_path.as_ptr() as *const u8,
str_neovide_path.to_bytes().len() + 1,
),
]; ];
for &(key, keytype, value_ptr, size_in_bytes) in &registry_values { for &(key, keytype, value_ptr, size_in_bytes) in &registry_values {
RegSetValueExA(registry_key, key, 0, keytype, value_ptr, size_in_bytes as u32); RegSetValueExA(
registry_key,
key,
0,
keytype,
value_ptr,
size_in_bytes as u32,
);
} }
RegCloseKey(registry_key); RegCloseKey(registry_key);
if RegCreateKeyExA( if RegCreateKeyExA(
HKEY_CLASSES_ROOT, str_registry_command_path.as_ptr(), HKEY_CLASSES_ROOT,
0, null_mut(), str_registry_command_path.as_ptr(),
REG_OPTION_NON_VOLATILE, KEY_WRITE, 0,
null_mut(), &mut registry_key, null_mut()) != 0 { null_mut(),
REG_OPTION_NON_VOLATILE,
KEY_WRITE,
null_mut(),
&mut registry_key,
null_mut(),
) != 0
{
return false; return false;
} }
let registry_values = [ let registry_values = [(
(null(), REG_SZ, str_command.as_ptr() as *const u8, str_command.to_bytes().len() + 1), null(),
]; REG_SZ,
str_command.as_ptr() as *const u8,
str_command.to_bytes().len() + 1,
)];
for &(key, keytype, value_ptr, size_in_bytes) in &registry_values { for &(key, keytype, value_ptr, size_in_bytes) in &registry_values {
RegSetValueExA(registry_key, key, 0, keytype, value_ptr, size_in_bytes as u32); RegSetValueExA(
registry_key,
key,
0,
keytype,
value_ptr,
size_in_bytes as u32,
);
} }
RegCloseKey(registry_key); RegCloseKey(registry_key);
} }
@ -97,34 +138,75 @@ pub fn register_rightclick_file() -> bool {
let str_neovide_path = CString::new(neovide_path.as_bytes()).unwrap(); let str_neovide_path = CString::new(neovide_path.as_bytes()).unwrap();
unsafe { unsafe {
if RegCreateKeyExA( if RegCreateKeyExA(
HKEY_CLASSES_ROOT, str_registry_path.as_ptr(), HKEY_CLASSES_ROOT,
0, null_mut(), str_registry_path.as_ptr(),
REG_OPTION_NON_VOLATILE, KEY_WRITE, 0,
null_mut(), &mut registry_key, null_mut()) != 0 { null_mut(),
REG_OPTION_NON_VOLATILE,
KEY_WRITE,
null_mut(),
&mut registry_key,
null_mut(),
) != 0
{
RegCloseKey(registry_key); RegCloseKey(registry_key);
return false; return false;
} }
let registry_values = [ let registry_values = [
(null(), REG_SZ, str_description.as_ptr() as *const u8, str_description.to_bytes().len() + 1), (
(str_icon.as_ptr(), REG_SZ, str_neovide_path.as_ptr() as *const u8, str_neovide_path.to_bytes().len() + 1), null(),
REG_SZ,
str_description.as_ptr() as *const u8,
str_description.to_bytes().len() + 1,
),
(
str_icon.as_ptr(),
REG_SZ,
str_neovide_path.as_ptr() as *const u8,
str_neovide_path.to_bytes().len() + 1,
),
]; ];
for &(key, keytype, value_ptr, size_in_bytes) in &registry_values { for &(key, keytype, value_ptr, size_in_bytes) in &registry_values {
RegSetValueExA(registry_key, key, 0, keytype, value_ptr, size_in_bytes as u32); RegSetValueExA(
registry_key,
key,
0,
keytype,
value_ptr,
size_in_bytes as u32,
);
} }
RegCloseKey(registry_key); RegCloseKey(registry_key);
if RegCreateKeyExA( if RegCreateKeyExA(
HKEY_CLASSES_ROOT, str_registry_command_path.as_ptr(), HKEY_CLASSES_ROOT,
0, null_mut(), str_registry_command_path.as_ptr(),
REG_OPTION_NON_VOLATILE, KEY_WRITE, 0,
null_mut(), &mut registry_key, null_mut()) != 0 { null_mut(),
REG_OPTION_NON_VOLATILE,
KEY_WRITE,
null_mut(),
&mut registry_key,
null_mut(),
) != 0
{
return false; return false;
} }
let registry_values = [ let registry_values = [(
(null(), REG_SZ, str_command.as_ptr() as *const u8, str_command.to_bytes().len() + 1), null(),
]; REG_SZ,
str_command.as_ptr() as *const u8,
str_command.to_bytes().len() + 1,
)];
for &(key, keytype, value_ptr, size_in_bytes) in &registry_values { for &(key, keytype, value_ptr, size_in_bytes) in &registry_values {
RegSetValueExA(registry_key, key, 0, keytype, value_ptr, size_in_bytes as u32); RegSetValueExA(
registry_key,
key,
0,
keytype,
value_ptr,
size_in_bytes as u32,
);
} }
RegCloseKey(registry_key); RegCloseKey(registry_key);
} }

Loading…
Cancel
Save