fixed mouse dpi mapping

macos-click-through
Keith Simmons 5 years ago
parent 0ab52f1ac6
commit 8c19cdd275

10
Cargo.lock generated

@ -458,9 +458,9 @@ dependencies = [
[[package]]
name = "curl-sys"
version = "0.4.25"
version = "0.4.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c38ca47d60b86d0cc9d42caa90a0885669c2abc9791f871c81f58cdf39e979b"
checksum = "0853fe2a575bb381b1f173610372c7722d9fa9bc4056512ed99fe6a644c388c6"
dependencies = [
"cc",
"libc",
@ -1630,7 +1630,7 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
name = "sdl2"
version = "0.33.0"
source = "git+https://github.com/Rust-SDL2/rust-sdl2#4ff7e9ce79c42360bf02f716818cdb3bfd057370"
source = "git+https://github.com/Rust-SDL2/rust-sdl2#c3f0088ea49f6c1b29b9e110313cd7b2a9833dc9"
dependencies = [
"bitflags",
"lazy_static",
@ -1641,7 +1641,7 @@ dependencies = [
[[package]]
name = "sdl2-sys"
version = "0.33.0"
source = "git+https://github.com/Rust-SDL2/rust-sdl2#4ff7e9ce79c42360bf02f716818cdb3bfd057370"
source = "git+https://github.com/Rust-SDL2/rust-sdl2#c3f0088ea49f6c1b29b9e110313cd7b2a9833dc9"
dependencies = [
"cfg-if",
"cmake",
@ -1784,7 +1784,7 @@ dependencies = [
[[package]]
name = "skulpin"
version = "0.5.2"
source = "git+https://github.com/Kethku/skulpin?branch=sdl2#af8b8f50f5f02c727dcb9d9c5bc958de3b708513"
source = "git+https://github.com/Kethku/skulpin?branch=sdl2#b4451490e457cd7ad504819a99d978a8d0f38ff4"
dependencies = [
"ash",
"cocoa",

@ -4,31 +4,31 @@ use tokio::process::ChildStdin;
#[derive(Debug, Clone)]
pub enum UiCommand {
Resize { width: i64, height: i64 },
Resize { width: u32, height: u32 },
Keyboard(String),
MouseButton { action: String, position: (i64, i64) },
Scroll { direction: String, position: (i64, i64) },
Drag(i64, i64)
MouseButton { action: String, position: (u32, u32) },
Scroll { direction: String, position: (u32, u32) },
Drag(u32, u32)
}
impl UiCommand {
pub async fn execute(self, nvim: &Neovim<Compat<ChildStdin>>) {
match self {
UiCommand::Resize { width, height } =>
nvim.ui_try_resize(width.max(10), height.max(3)).await
nvim.ui_try_resize(width.max(10) as i64, height.max(3) as i64).await
.expect("Resize failed"),
UiCommand::Keyboard(input_command) => {
nvim.input(&input_command).await
.expect("Input failed");
},
UiCommand::MouseButton { action, position: (grid_x, grid_y) } =>
nvim.input_mouse("left", &action, "", 0, grid_y, grid_x).await
nvim.input_mouse("left", &action, "", 0, grid_y as i64, grid_x as i64).await
.expect("Mouse Input Failed"),
UiCommand::Scroll { direction, position: (grid_x, grid_y) } =>
nvim.input_mouse("wheel", &direction, "", 0, grid_y, grid_x).await
nvim.input_mouse("wheel", &direction, "", 0, grid_y as i64, grid_x as i64).await
.expect("Mouse Scroll Failed"),
UiCommand::Drag(grid_x, grid_y) =>
nvim.input_mouse("left", "drag", "", 0, grid_y, grid_x).await
nvim.input_mouse("left", "drag", "", 0, grid_y as i64, grid_x as i64).await
.expect("Mouse Drag Failed")
}
}

@ -30,10 +30,10 @@ fn windows_fix_dpi() {
fn handle_new_grid_size(new_size: LogicalSize, renderer: &Renderer) {
if new_size.width > 0 && new_size.height > 0 {
let new_width = ((new_size.width + 1) as f32 / renderer.font_width) as i64;
let new_height = ((new_size.height + 1) as f32 / renderer.font_height) as i64;
let new_width = ((new_size.width + 1) as f32 / renderer.font_width) as u32;
let new_height = ((new_size.height + 1) as f32 / renderer.font_height) as u32;
// Add 1 here to make sure resizing doesn't change the grid size on startup
BRIDGE.queue_command(UiCommand::Resize { width: new_width as i64, height: new_height as i64 });
BRIDGE.queue_command(UiCommand::Resize { width: new_width, height: new_height });
}
}
@ -83,7 +83,10 @@ pub fn ui_loop() {
info!("renderer created");
let mut mouse_down = false;
let mut mouse_pos = (0, 0);
let mut mouse_position = LogicalSize {
width: 0,
height: 0
};
let mut title = "Neovide".to_string();
let mut previous_size = LogicalSize::new(&window).unwrap();
@ -136,20 +139,23 @@ pub fn ui_loop() {
}
},
Event::MouseMotion { x, y, .. } => {
let grid_x = (x as f32 / renderer.font_width) as i64;
let grid_y = (y as f32 / renderer.font_height) as i64;
let (old_x, old_y) = mouse_pos;
mouse_pos = (grid_x, grid_y);
if mouse_down && (old_x != grid_x || old_y != grid_y) {
BRIDGE.queue_command(UiCommand::Drag(grid_x, grid_y));
let previous_position = mouse_position;
mouse_position = LogicalSize::from_physical_size_tuple((
(x as f32 / renderer.font_width) as u32,
(y as f32 / renderer.font_height) as u32
),
&window
).expect("Could not calculate logical mouse position");
if mouse_down && previous_position != mouse_position {
BRIDGE.queue_command(UiCommand::Drag(mouse_position.width, mouse_position.height));
}
},
Event::MouseButtonDown { .. } => {
BRIDGE.queue_command(UiCommand::MouseButton { action: String::from("press"), position: mouse_pos });
BRIDGE.queue_command(UiCommand::MouseButton { action: String::from("press"), position: (mouse_position.width, mouse_position.height) });
mouse_down = true;
},
Event::MouseButtonUp { .. } => {
BRIDGE.queue_command(UiCommand::MouseButton { action: String::from("release"), position: mouse_pos });
BRIDGE.queue_command(UiCommand::MouseButton { action: String::from("release"), position: (mouse_position.width, mouse_position.height) });
mouse_down = false;
},
Event::MouseWheel { x, y, .. } => {
@ -162,7 +168,7 @@ pub fn ui_loop() {
};
if let Some(input_type) = vertical_input_type {
BRIDGE.queue_command(UiCommand::Scroll { direction: input_type.to_string(), position: mouse_pos });
BRIDGE.queue_command(UiCommand::Scroll { direction: input_type.to_string(), position: (mouse_position.width, mouse_position.height) });
}
let horizontal_input_type = if x > 0 {
@ -174,7 +180,7 @@ pub fn ui_loop() {
};
if let Some(input_type) = horizontal_input_type {
BRIDGE.queue_command(UiCommand::Scroll { direction: input_type.to_string(), position: mouse_pos });
BRIDGE.queue_command(UiCommand::Scroll { direction: input_type.to_string(), position: (mouse_position.width, mouse_position.height) });
}
},
_ => {}

Loading…
Cancel
Save