Skip to content

Commit b2a61a6

Browse files
daxpeddakchibisov
andcommitted
api: overhaul pointer API
- Rename `CursorMoved` to `PointerMoved`. - Rename `CursorEntered` to `PointerEntered`. - Rename `CursorLeft` to `PointerLeft`. - Rename `MouseInput` to `PointerButton`. - Add `position` to every `PointerEvent`. - Remove `Touch`, which is folded into the `Pointer*` events. - New `PointerType` added to `PointerEntered` and `PointerLeft`, signifying which pointer type is the source of this event. - New `PointerSource` added to `PointerMoved`, similar to `PointerType` but holding additional data. - New `ButtonSource` added to `PointerButton`, similar to `PointerType` but holding pointer type specific buttons. Use `ButtonSource::mouse_button()` to easily normalize any pointer button type to a generic mouse button. - In the same spirit rename `DeviceEvent::MouseMotion` to `PointerMotion`. - Remove `Force::Calibrated::altitude_angle`. Fixes rust-windowing#3833. Fixes rust-windowing#883. Fixes rust-windowing#336. Co-authored-by: Kirill Chibisov <contact@kchibisov.com>
1 parent 32cd1ad commit b2a61a6

File tree

25 files changed

+1232
-865
lines changed

25 files changed

+1232
-865
lines changed

examples/child_window.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ fn main() -> Result<(), impl std::error::Error> {
4444
self.windows.clear();
4545
event_loop.exit();
4646
},
47-
WindowEvent::CursorEntered { device_id: _ } => {
47+
WindowEvent::PointerEntered { device_id: _, .. } => {
4848
// On x11, println when the cursor entered in a window even if the child window
4949
// is created by some key inputs.
5050
// the child windows are always placed at (0, 0) with size (200, 200) in the

examples/window.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -446,20 +446,23 @@ impl ApplicationHandler for Application {
446446
}
447447
}
448448
},
449-
WindowEvent::MouseInput { button, state, .. } => {
449+
WindowEvent::PointerButton { button, state, .. } => {
450+
info!("Pointer button {button:?} {state:?}");
450451
let mods = window.modifiers;
451-
if let Some(action) =
452-
state.is_pressed().then(|| Self::process_mouse_binding(button, &mods)).flatten()
452+
if let Some(action) = state
453+
.is_pressed()
454+
.then(|| Self::process_mouse_binding(button.mouse_button(), &mods))
455+
.flatten()
453456
{
454457
self.handle_action_with_window(event_loop, window_id, action);
455458
}
456459
},
457-
WindowEvent::CursorLeft { .. } => {
458-
info!("Cursor left Window={window_id:?}");
460+
WindowEvent::PointerLeft { .. } => {
461+
info!("Pointer left Window={window_id:?}");
459462
window.cursor_left();
460463
},
461-
WindowEvent::CursorMoved { position, .. } => {
462-
info!("Moved cursor to {position:?}");
464+
WindowEvent::PointerMoved { position, .. } => {
465+
info!("Moved pointer to {position:?}");
463466
window.cursor_moved(position);
464467
},
465468
WindowEvent::ActivationTokenDone { token: _token, .. } => {
@@ -510,11 +513,10 @@ impl ApplicationHandler for Application {
510513
WindowEvent::TouchpadPressure { .. }
511514
| WindowEvent::HoveredFileCancelled
512515
| WindowEvent::KeyboardInput { .. }
513-
| WindowEvent::CursorEntered { .. }
516+
| WindowEvent::PointerEntered { .. }
514517
| WindowEvent::DroppedFile(_)
515518
| WindowEvent::HoveredFile(_)
516519
| WindowEvent::Destroyed
517-
| WindowEvent::Touch(_)
518520
| WindowEvent::Moved(_) => (),
519521
}
520522
}

src/changelog/unreleased.md

+28-4
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,15 @@ changelog entry.
5656

5757
Keep in mind that handles do not auto-upgrade after permissions are granted and have to be
5858
re-created to make full use of this feature.
59-
- Add `Touch::finger_id` with a new type `FingerId`.
60-
- On Web and Windows, add `FingerIdExt*::is_primary()`, exposing a way to determine
61-
the primary finger in a multi-touch interaction.
6259
- Implement `Clone`, `Copy`, `Debug`, `Deserialize`, `Eq`, `Hash`, `Ord`, `PartialEq`, `PartialOrd`
6360
and `Serialize` on many types.
6461
- Add `MonitorHandle::current_video_mode()`.
6562
- Add basic iOS IME support. The soft keyboard can now be shown using `Window::set_ime_allowed`.
6663
- On macOS, add `WindowExtMacOS::set_borderless_game` and `WindowAttributesExtMacOS::with_borderless_game`
6764
to fully disable the menu bar and dock in Borderless Fullscreen as commonly done in games.
6865
- Add `WindowId::into_raw()` and `from_raw()`.
66+
- Add `PointerKind`, `PointerSource`, `ButtonSource`, `FingerId` and `position` to all pointer
67+
events as part of the pointer event overhaul.
6968

7069
### Changed
7170

@@ -127,6 +126,29 @@ changelog entry.
127126
To migrate, you can probably just replace all instances of `inner_size` with `surface_size` in your codebase.
128127
- Every event carrying a `DeviceId` now uses `Option<DeviceId>` instead. A `None` value signifies that the
129128
device can't be uniquely identified.
129+
- Pointer `WindowEvent`s were overhauled. The new events can handle any type of pointer, serving as
130+
a single pointer input source. Now your application can handle any pointer type without having to
131+
explicitly handle e.g. `Touch`:
132+
- Rename `CursorMoved` to `PointerMoved`.
133+
- Rename `CursorEntered` to `PointerEntered`.
134+
- Rename `CursorLeft` to `PointerLeft`.
135+
- Rename `MouseInput` to `PointerButton`.
136+
- Add `position` to every `PointerEvent`.
137+
- `PointerMoved` is **not sent** after `PointerEntered` anymore.
138+
- Remove `Touch`, which is folded into the `Pointer*` events.
139+
- New `PointerKind` added to `PointerEntered` and `PointerLeft`, signifying which pointer type is
140+
the source of this event.
141+
- New `PointerSource` added to `PointerMoved`, similar to `PointerKind` but holding additional
142+
data.
143+
- New `ButtonSource` added to `PointerButton`, similar to `PointerKind` but holding pointer type
144+
specific buttons. Use `ButtonSource::mouse_button()` to easily normalize any pointer button
145+
type to a generic mouse button.
146+
- New `FingerId` added to `PointerKind::Touch` and `PointerSource::Touch` able to uniquely
147+
identify a finger in a multi-touch interaction. Replaces the old `Touch::id`.
148+
- On Web and Windows, add `FingerIdExt*::is_primary()`, exposing a way to determine
149+
the primary finger in a multi-touch interaction.
150+
- In the same spirit rename `DeviceEvent::MouseMotion` to `PointerMotion`.
151+
- Remove `Force::Calibrated::altitude_angle`.
130152

131153
### Removed
132154

@@ -149,13 +171,15 @@ changelog entry.
149171
v0.5 support. v0.6 remains in place and is enabled by default.
150172
- Remove `DeviceEvent::Added` and `DeviceEvent::Removed`.
151173
- Remove `DeviceEvent::Motion` and `WindowEvent::AxisMotion`.
152-
- Remove `Touch::id` in favor of `Touch::finger_id`.
153174
- Remove `MonitorHandle::size()` and `refresh_rate_millihertz()` in favor of
154175
`MonitorHandle::current_video_mode()`.
155176
- On Android, remove all `MonitorHandle` support instead of emitting false data.
156177
- Remove `impl From<u64> for WindowId` and `impl From<WindowId> for u64`. Replaced with
157178
`WindowId::into_raw()` and `from_raw()`.
158179
- Remove `dummy()` from `WindowId` and `DeviceId`.
180+
- Remove `WindowEvent::Touch` and `Touch` in favor of the new `PointerKind`, `PointerSource` and
181+
`ButtonSource` as part of the new pointer event overhaul.
182+
- Remove `Force::altitude_angle`.
159183

160184
### Fixed
161185

0 commit comments

Comments
 (0)