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,
};
use log::info;
use skia_safe::Rect;
use crate::{
@ -85,6 +86,9 @@ pub struct MouseManager {
mouse_hidden: bool,
pub enabled: bool,
// Not exactly a mouse setting but ideally needs to exist for some state
current_window_focused: bool,
}
impl MouseManager {
@ -100,6 +104,7 @@ impl MouseManager {
window_details_under_mouse: None,
mouse_hidden: false,
enabled: true,
current_window_focused: false,
}
}
@ -195,6 +200,7 @@ impl MouseManager {
mouse_button: &MouseButton,
down: bool,
keyboard_manager: &KeyboardManager,
click_through: bool,
) {
// For some reason pointer down is handled differently from pointer up and drag.
// Floating windows: relative coordinates are great.
@ -214,13 +220,15 @@ impl MouseManager {
self.relative_position
};
EVENT_AGGREGATOR.send(UiCommand::Serial(SerialCommand::MouseButton {
button: button_text.clone(),
action,
grid_id: details.id,
position: position.into(),
modifier_string: keyboard_manager.format_modifier_string(true),
}));
if click_through || !self.current_window_focused {
EVENT_AGGREGATOR.send(UiCommand::Serial(SerialCommand::MouseButton {
button: button_text.clone(),
action,
grid_id: details.id,
position: position.into(),
modifier_string: keyboard_manager.format_modifier_string(true),
}));
}
}
if down {
@ -387,13 +395,23 @@ impl MouseManager {
renderer,
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 => {
if let Some(trace) = self.touch_position.remove(&finger_id) {
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 {
self.handle_pointer_motion(
@ -403,8 +421,18 @@ impl MouseManager {
renderer,
windowed_context,
);
self.handle_pointer_transition(&MouseButton::Left, true, keyboard_manager);
self.handle_pointer_transition(&MouseButton::Left, false, keyboard_manager);
self.handle_pointer_transition(
&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>,
) {
match event {
Event::WindowEvent {
event: WindowEvent::Focused(focused),
..
} => self.current_window_focused = *focused,
Event::WindowEvent {
event: WindowEvent::CursorMoved { position, .. },
..
@ -476,11 +508,18 @@ impl MouseManager {
Event::WindowEvent {
event: WindowEvent::MouseInput { button, state, .. },
..
} => self.handle_pointer_transition(
button,
state == &ElementState::Pressed,
keyboard_manager,
),
} => {
let window_settings = SETTINGS.get::<WindowSettings>();
self.handle_pointer_transition(
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::KeyboardInput {

@ -12,6 +12,7 @@ pub struct WindowSettings {
pub hide_mouse_when_typing: bool,
pub touch_deadzone: f32,
pub touch_drag_timeout: f32,
pub click_through: bool
}
impl Default for WindowSettings {
@ -27,6 +28,7 @@ impl Default for WindowSettings {
hide_mouse_when_typing: false,
touch_deadzone: 6.0,
touch_drag_timeout: 0.17,
click_through: false
}
}
}

Loading…
Cancel
Save