feat: enable mouse move event when mouse is pressed on macos#12
feat: enable mouse move event when mouse is pressed on macos#12HuakunShen wants to merge 2 commits intorustdesk-org:masterfrom
Conversation
|
This PR works good.
I'm not sure about it. |
|
@fufesou I removed the |
There was a problem hiding this comment.
Pull Request Overview
This PR addresses the absence of mouse move events during mouse drag actions on macOS by mapping Mac’s native left/right drag events to MouseMove events, thereby aligning behavior across platforms. Key changes include:
- Adding handling for CGEventType::LeftMouseDragged and CGEventType::RightMouseDragged in the macOS event conversion.
- Adjusting the type conversion in the USB HID code conversion tests.
- Introducing an example to demonstrate drag event handling.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/macos/common.rs | Adds handling for mouse drag events via MouseMove mapping. |
| src/codes_conv.rs | Updates type assertion from u32 to u16 in code conversion tests. |
| examples/dragging.rs | Provides an example demonstrating the handling of dragging events. |
Comments suppressed due to low confidence (2)
examples/dragging.rs:1
- [nitpick] Consider adding a brief comment at the top of the example to explain its purpose and how it demonstrates the drag event handling.
use std::sync::atomic::AtomicBool;
src/codes_conv.rs:158
- Ensure that converting 'code2' to u16 does not lead to unexpected truncation; confirm that all USB HID code values are within the u16 range.
assert_eq!(code, code2 as u16)
| CGEventType::LeftMouseDragged => { | ||
| let point = cg_event.location(); | ||
| Some(EventType::MouseMove { | ||
| x: point.x, | ||
| y: point.y, | ||
| }) | ||
| } | ||
| CGEventType::RightMouseDragged => { | ||
| let point = cg_event.location(); | ||
| Some(EventType::MouseMove { | ||
| x: point.x, | ||
| y: point.y, | ||
| }) | ||
| } |
There was a problem hiding this comment.
The logic for handling left and right mouse drag events is duplicated. Consider extracting the common event handling into a helper function to improve maintainability.
| CGEventType::LeftMouseDragged => { | |
| let point = cg_event.location(); | |
| Some(EventType::MouseMove { | |
| x: point.x, | |
| y: point.y, | |
| }) | |
| } | |
| CGEventType::RightMouseDragged => { | |
| let point = cg_event.location(); | |
| Some(EventType::MouseMove { | |
| x: point.x, | |
| y: point.y, | |
| }) | |
| } | |
| CGEventType::LeftMouseDragged => handle_mouse_drag(cg_event), | |
| CGEventType::RightMouseDragged => handle_mouse_drag(cg_event), |
|
This PR handles mouse events, but RustDesk uses mouse events from Flutter. |
It's for other people using this library. |
On MacOS, when mouse is pressed, no move event is emitted.
This prevents me from detecting drag event.
On both windows and linux, move event is emitted when mouse is pressed.
I think it's a better idea to add
MouseDragevent toEventType, because Mac's native API already have thisCGEventType::LeftMouseDragged.But this requires also updating windows and linux API to stay consistent.
I may work on that later. This PR makes
rdevbehave the same way on all platforms.