fix(#1343): Do not move cursor on first focus for macOS

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

@ -13,6 +13,7 @@ use glutin::{
}, },
PossiblyCurrent, WindowedContext, PossiblyCurrent, WindowedContext,
}; };
use log::info;
use skia_safe::Rect; use skia_safe::Rect;
use crate::{ use crate::{
@ -85,6 +86,9 @@ 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
current_window_focused: bool,
} }
impl MouseManager { impl MouseManager {
@ -100,6 +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,
} }
} }
@ -195,6 +200,7 @@ impl MouseManager {
mouse_button: &MouseButton, mouse_button: &MouseButton,
down: bool, down: bool,
keyboard_manager: &KeyboardManager, keyboard_manager: &KeyboardManager,
click_through: bool,
) { ) {
// For some reason pointer down is handled differently from pointer up and drag. // For some reason pointer down is handled differently from pointer up and drag.
// Floating windows: relative coordinates are great. // Floating windows: relative coordinates are great.
@ -214,13 +220,15 @@ impl MouseManager {
self.relative_position self.relative_position
}; };
EVENT_AGGREGATOR.send(UiCommand::Serial(SerialCommand::MouseButton { if click_through || !self.current_window_focused {
button: button_text.clone(), EVENT_AGGREGATOR.send(UiCommand::Serial(SerialCommand::MouseButton {
action, button: button_text.clone(),
grid_id: details.id, action,
position: position.into(), grid_id: details.id,
modifier_string: keyboard_manager.format_modifier_string(true), position: position.into(),
})); modifier_string: keyboard_manager.format_modifier_string(true),
}));
}
} }
if down { if down {
@ -387,13 +395,23 @@ impl MouseManager {
renderer, renderer,
windowed_context, windowed_context,
); );
self.handle_pointer_transition(&MouseButton::Left, true, keyboard_manager); self.handle_pointer_transition(
&MouseButton::Left,
true,
keyboard_manager,
true,
);
} }
} }
TouchPhase::Ended | TouchPhase::Cancelled => { TouchPhase::Ended | TouchPhase::Cancelled => {
if let Some(trace) = self.touch_position.remove(&finger_id) { if let Some(trace) = self.touch_position.remove(&finger_id) {
if self.dragging.is_some() { if self.dragging.is_some() {
self.handle_pointer_transition(&MouseButton::Left, false, keyboard_manager); self.handle_pointer_transition(
&MouseButton::Left,
false,
keyboard_manager,
true,
);
} }
if !trace.left_deadzone_once { if !trace.left_deadzone_once {
self.handle_pointer_motion( self.handle_pointer_motion(
@ -403,8 +421,18 @@ impl MouseManager {
renderer, renderer,
windowed_context, windowed_context,
); );
self.handle_pointer_transition(&MouseButton::Left, true, keyboard_manager); self.handle_pointer_transition(
self.handle_pointer_transition(&MouseButton::Left, false, keyboard_manager); &MouseButton::Left,
true,
keyboard_manager,
true,
);
self.handle_pointer_transition(
&MouseButton::Left,
false,
keyboard_manager,
true,
);
} }
} }
} }
@ -419,6 +447,10 @@ impl MouseManager {
windowed_context: &WindowedContext<PossiblyCurrent>, windowed_context: &WindowedContext<PossiblyCurrent>,
) { ) {
match event { match event {
Event::WindowEvent {
event: WindowEvent::Focused(focused),
..
} => self.current_window_focused = *focused,
Event::WindowEvent { Event::WindowEvent {
event: WindowEvent::CursorMoved { position, .. }, event: WindowEvent::CursorMoved { position, .. },
.. ..
@ -476,11 +508,18 @@ impl MouseManager {
Event::WindowEvent { Event::WindowEvent {
event: WindowEvent::MouseInput { button, state, .. }, event: WindowEvent::MouseInput { button, state, .. },
.. ..
} => self.handle_pointer_transition( } => {
button, let window_settings = SETTINGS.get::<WindowSettings>();
state == &ElementState::Pressed, self.handle_pointer_transition(
keyboard_manager, button,
), state == &ElementState::Pressed,
keyboard_manager,
window_settings.click_through,
);
// Always reset focused to false to prevent all mouse inputs not working
self.current_window_focused = false;
}
Event::WindowEvent { Event::WindowEvent {
event: event:
WindowEvent::KeyboardInput { WindowEvent::KeyboardInput {

@ -12,6 +12,7 @@ pub struct WindowSettings {
pub hide_mouse_when_typing: bool, pub hide_mouse_when_typing: bool,
pub touch_deadzone: f32, pub touch_deadzone: f32,
pub touch_drag_timeout: f32, pub touch_drag_timeout: f32,
pub click_through: bool
} }
impl Default for WindowSettings { impl Default for WindowSettings {
@ -27,6 +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
} }
} }
} }

Loading…
Cancel
Save