formatting fixes

macos-click-through
Keith Simmons 3 years ago
parent f5b65a6770
commit 407a7e24a9

@ -94,7 +94,10 @@ impl Corner {
self.start_position = self.current_position; self.start_position = self.current_position;
self.previous_destination = destination; self.previous_destination = destination;
self.length_multiplier = if settings.distance_length_adjust { self.length_multiplier = if settings.distance_length_adjust {
(destination - self.current_position).length().log10().max(0.0) (destination - self.current_position)
.length()
.log10()
.max(0.0)
} else { } else {
1.0 1.0
} }
@ -109,7 +112,8 @@ impl Corner {
let relative_scaled_position: Point = ( let relative_scaled_position: Point = (
self.relative_position.x * font_dimensions.x, self.relative_position.x * font_dimensions.x,
self.relative_position.y * font_dimensions.y, self.relative_position.y * font_dimensions.y,
).into(); )
.into();
let corner_destination = destination + relative_scaled_position; let corner_destination = destination + relative_scaled_position;

@ -101,7 +101,8 @@ impl KeyboardManager {
pub fn handle_event(&mut self, event: &Event<()>) { pub fn handle_event(&mut self, event: &Event<()>) {
match event { match event {
Event::WindowEvent { Event::WindowEvent {
event: WindowEvent::KeyboardInput { event:
WindowEvent::KeyboardInput {
event: key_event, .. event: key_event, ..
}, },
.. ..
@ -115,7 +116,7 @@ impl KeyboardManager {
.expect("Could not send keyboard ui command"); .expect("Could not send keyboard ui command");
} }
} }
}, }
Event::WindowEvent { Event::WindowEvent {
event: WindowEvent::ModifiersChanged(modifiers), event: WindowEvent::ModifiersChanged(modifiers),
.. ..
@ -124,8 +125,8 @@ impl KeyboardManager {
self.ctrl = modifiers.control_key(); self.ctrl = modifiers.control_key();
self.alt = modifiers.alt_key(); self.alt = modifiers.alt_key();
self.logo = modifiers.super_key(); self.logo = modifiers.super_key();
}, }
_ => { } _ => {}
} }
} }
} }

@ -1,37 +1,44 @@
use glutin::{ use glutin::{
self, self,
WindowedContext, dpi::{LogicalPosition, PhysicalPosition},
dpi::{ event::{ElementState, Event, MouseButton, MouseScrollDelta, WindowEvent},
LogicalPosition, PossiblyCurrent, WindowedContext,
PhysicalPosition,
},
event::{
ElementState,
Event,
MouseButton,
MouseScrollDelta,
WindowEvent,
},
PossiblyCurrent
}; };
use skia_safe::Rect; use skia_safe::Rect;
use crate::channel_utils::LoggingTx;
use crate::bridge::UiCommand; use crate::bridge::UiCommand;
use crate::channel_utils::LoggingTx;
use crate::renderer::{Renderer, WindowDrawDetails}; use crate::renderer::{Renderer, WindowDrawDetails};
use crate::settings::SETTINGS; use crate::settings::SETTINGS;
use crate::window::WindowSettings; use crate::window::WindowSettings;
fn clamp_position(position: LogicalPosition<f32>, region: Rect, font_width: u64, font_height: u64) -> LogicalPosition<f32> { fn clamp_position(
position: LogicalPosition<f32>,
region: Rect,
font_width: u64,
font_height: u64,
) -> LogicalPosition<f32> {
LogicalPosition::new( LogicalPosition::new(
position.x.min(region.right - font_width as f32).max(region.left), position
position.y.min(region.bottom - font_height as f32).max(region.top)) .x
.min(region.right - font_width as f32)
.max(region.left),
position
.y
.min(region.bottom - font_height as f32)
.max(region.top),
)
} }
fn to_grid_coords(position: LogicalPosition<f32>, font_width: u64, font_height: u64) -> LogicalPosition<u32> { fn to_grid_coords(
position: LogicalPosition<f32>,
font_width: u64,
font_height: u64,
) -> LogicalPosition<u32> {
LogicalPosition::new( LogicalPosition::new(
(position.x as u64 / font_width) as u32, (position.x as u64 / font_width) as u32,
(position.y as u64 / font_height) as u32) (position.y as u64 / font_height) as u32,
)
} }
pub struct MouseManager { pub struct MouseManager {
@ -59,7 +66,13 @@ impl MouseManager {
} }
} }
fn handle_pointer_motion(&mut self, x: i32, y: i32, renderer: &Renderer, windowed_context: &WindowedContext<PossiblyCurrent>) { fn handle_pointer_motion(
&mut self,
x: i32,
y: i32,
renderer: &Renderer,
windowed_context: &WindowedContext<PossiblyCurrent>,
) {
let size = windowed_context.window().inner_size(); let size = windowed_context.window().inner_size();
if x < 0 || x as u32 >= size.width || y < 0 || y as u32 >= size.height { if x < 0 || x as u32 >= size.width || y < 0 || y as u32 >= size.height {
return; return;
@ -71,29 +84,48 @@ impl MouseManager {
// If dragging, the relevant window (the one which we send all commands to) is the one // If dragging, the relevant window (the one which we send all commands to) is the one
// which the mouse drag started on. Otherwise its the top rendered window // which the mouse drag started on. Otherwise its the top rendered window
let relevant_window_details = if self.dragging { let relevant_window_details = if self.dragging {
renderer.window_regions.iter() renderer.window_regions.iter().find(|details| {
.find(|details| details.id == self.window_details_under_mouse.as_ref().expect("If dragging, there should be a window details recorded").id) details.id
== self
.window_details_under_mouse
.as_ref()
.expect("If dragging, there should be a window details recorded")
.id
})
} else { } else {
// the rendered window regions are sorted by draw order, so the earlier windows in the // the rendered window regions are sorted by draw order, so the earlier windows in the
// list are drawn under the later ones // list are drawn under the later ones
renderer.window_regions.iter().filter(|details| { renderer
logical_position.x >= details.region.left && .window_regions
logical_position.x < details.region.right && .iter()
logical_position.y >= details.region.top && .filter(|details| {
logical_position.y < details.region.bottom logical_position.x >= details.region.left
}).last() && logical_position.x < details.region.right
&& logical_position.y >= details.region.top
&& logical_position.y < details.region.bottom
})
.last()
}; };
let global_bounds = relevant_window_details.map(|details| details.region).unwrap_or(Rect::from_wh(size.width as f32, size.height as f32)); let global_bounds = relevant_window_details
let clamped_position = clamp_position(logical_position, global_bounds, renderer.font_width, renderer.font_height); .map(|details| details.region)
.unwrap_or(Rect::from_wh(size.width as f32, size.height as f32));
let clamped_position = clamp_position(
logical_position,
global_bounds,
renderer.font_width,
renderer.font_height,
);
self.position = to_grid_coords(clamped_position, renderer.font_width, renderer.font_height); self.position = to_grid_coords(clamped_position, renderer.font_width, renderer.font_height);
if let Some(relevant_window_details) = relevant_window_details { if let Some(relevant_window_details) = relevant_window_details {
let relative_position = LogicalPosition::new( let relative_position = LogicalPosition::new(
clamped_position.x - relevant_window_details.region.left, clamped_position.x - relevant_window_details.region.left,
clamped_position.y - relevant_window_details.region.top); clamped_position.y - relevant_window_details.region.top,
self.relative_position = to_grid_coords(relative_position, renderer.font_width, renderer.font_height); );
self.relative_position =
to_grid_coords(relative_position, renderer.font_width, renderer.font_height);
let previous_position = self.drag_position; let previous_position = self.drag_position;
// Until https://github.com/neovim/neovim/pull/12667 is merged, we have to special // Until https://github.com/neovim/neovim/pull/12667 is merged, we have to special
@ -178,7 +210,11 @@ impl MouseManager {
self.command_sender self.command_sender
.send(UiCommand::Scroll { .send(UiCommand::Scroll {
direction: input_type.to_string(), direction: input_type.to_string(),
grid_id: self.window_details_under_mouse.as_ref().map(|details| details.id).unwrap_or(0), grid_id: self
.window_details_under_mouse
.as_ref()
.map(|details| details.id)
.unwrap_or(0),
position: self.drag_position.into(), position: self.drag_position.into(),
}) })
.ok(); .ok();
@ -194,21 +230,33 @@ impl MouseManager {
self.command_sender self.command_sender
.send(UiCommand::Scroll { .send(UiCommand::Scroll {
direction: input_type.to_string(), direction: input_type.to_string(),
grid_id: self.window_details_under_mouse.as_ref().map(|details| details.id).unwrap_or(0), grid_id: self
.window_details_under_mouse
.as_ref()
.map(|details| details.id)
.unwrap_or(0),
position: self.drag_position.into(), position: self.drag_position.into(),
}) })
.ok(); .ok();
} }
} }
pub fn handle_event(&mut self, event: &Event<()>, renderer: &Renderer, windowed_context: &WindowedContext<PossiblyCurrent>) { pub fn handle_event(
&mut self,
event: &Event<()>,
renderer: &Renderer,
windowed_context: &WindowedContext<PossiblyCurrent>,
) {
match event { match event {
Event::WindowEvent { Event::WindowEvent {
event: WindowEvent::CursorMoved { position, .. }, event: WindowEvent::CursorMoved { position, .. },
.. ..
} => self.handle_pointer_motion( } => self.handle_pointer_motion(
position.x as i32, position.y as i32, position.x as i32,
renderer, windowed_context), position.y as i32,
renderer,
windowed_context,
),
Event::WindowEvent { Event::WindowEvent {
event: event:
WindowEvent::MouseWheel { WindowEvent::MouseWheel {

Loading…
Cancel
Save