Skip to content

Commit

Permalink
Rename PointerType to PointerKind
Browse files Browse the repository at this point in the history
  • Loading branch information
daxpedda committed Aug 18, 2024
1 parent 69b619f commit d7e7e31
Show file tree
Hide file tree
Showing 14 changed files with 105 additions and 93 deletions.
12 changes: 6 additions & 6 deletions src/changelog/unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ changelog entry.
- Implement `Clone`, `Copy`, `Debug`, `Deserialize`, `Eq`, `Hash`, `Ord`, `PartialEq`, `PartialOrd`
and `Serialize` on many types.
- Add `MonitorHandle::current_video_mode()`.
- Add `PointerType`, `PointerSource`, `ButtonSource`, `FingerId` and `position` to all pointer
- Add `PointerKind`, `PointerSource`, `ButtonSource`, `FingerId` and `position` to all pointer
events as part of the pointer event overhaul.

### Changed
Expand Down Expand Up @@ -110,14 +110,14 @@ changelog entry.
- 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
- New `PointerKind` 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
- New `PointerSource` added to `PointerMoved`, similar to `PointerKind` but holding additional
data.
- New `ButtonSource` added to `PointerButton`, similar to `PointerType` but holding pointer type
- New `ButtonSource` added to `PointerButton`, similar to `PointerKind` but holding pointer type
specific buttons. Use `ButtonSource::mouse_button()` to easily normalize any pointer button
type to a generic mouse button.
- New `FingerId` added to `PointerType::Touch` and `PointerSource::Touch` able to uniquely
- New `FingerId` added to `PointerKind::Touch` and `PointerSource::Touch` able to uniquely
identify a finger in a multi-touch interaction. Replaces the old `Touch::id`.
- On Web and Windows, add `FingerIdExt*::is_primary()`, exposing a way to determine
the primary finger in a multi-touch interaction.
Expand Down Expand Up @@ -148,7 +148,7 @@ changelog entry.
- Remove `MonitorHandle::size()` and `refresh_rate_millihertz()` in favor of
`MonitorHandle::current_video_mode()`.
- On Android, remove all `MonitorHandle` support instead of emitting false data.
- Remove `WindowEvent::Touch` and `Touch` in favor of the new `PointerType`, `PointerSource` and
- Remove `WindowEvent::Touch` and `Touch` in favor of the new `PointerKind`, `PointerSource` and
`ButtonSource` as part of the new pointer event overhaul.
- Remove `Force::altitude_angle`.

Expand Down
14 changes: 7 additions & 7 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ pub enum WindowEvent {
/// [`transform`]: https://developer.mozilla.org/en-US/docs/Web/CSS/transform
position: PhysicalPosition<f64>,

ty: PointerType,
kind: PointerKind,
},

/// The cursor has left the window.
Expand All @@ -278,7 +278,7 @@ pub enum WindowEvent {
/// [`transform`]: https://developer.mozilla.org/en-US/docs/Web/CSS/transform
position: Option<PhysicalPosition<f64>>,

ty: PointerType,
kind: PointerKind,
},

/// A mouse wheel movement or touchpad scroll occurred.
Expand Down Expand Up @@ -456,7 +456,7 @@ pub enum WindowEvent {
/// **Wayland/X11:** Can only identify [`Touch`](Self::Touch), any other pointer is identified as
/// [`Mouse`](Self::Mouse).
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum PointerType {
pub enum PointerKind {
Mouse,
/// See [`PointerSource::Touch`] for more details.
///
Expand Down Expand Up @@ -519,7 +519,7 @@ pub enum PointerSource {
Unknown,
}

impl From<PointerSource> for PointerType {
impl From<PointerSource> for PointerKind {
fn from(source: PointerSource) -> Self {
match source {
PointerSource::Mouse => Self::Mouse,
Expand Down Expand Up @@ -1141,7 +1141,7 @@ mod tests {
use crate::event::Event::*;
use crate::event::Ime::Enabled;
use crate::event::WindowEvent::*;
use crate::event::{PointerSource, PointerType};
use crate::event::{PointerKind, PointerSource};
use crate::window::WindowId;

// Mainline events.
Expand Down Expand Up @@ -1173,12 +1173,12 @@ mod tests {
with_window_event(PointerEntered {
device_id: did,
position: (0, 0).into(),
ty: PointerType::Mouse,
kind: PointerKind::Mouse,
});
with_window_event(PointerLeft {
device_id: did,
position: Some((0, 0).into()),
ty: PointerType::Mouse,
kind: PointerKind::Mouse,
});
with_window_event(MouseWheel {
device_id: did,
Expand Down
4 changes: 2 additions & 2 deletions src/platform_impl/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ impl EventLoop {
let event = event::WindowEvent::PointerEntered {
device_id,
position,
ty: event::PointerType::Touch(finger_id),
kind: event::PointerKind::Touch(finger_id),
};
app.window_event(&self.window_target, window_id, event);
let event = event::WindowEvent::PointerButton {
Expand Down Expand Up @@ -391,7 +391,7 @@ impl EventLoop {
let event = event::WindowEvent::PointerLeft {
device_id,
position: Some(position),
ty: event::PointerType::Touch(finger_id),
kind: event::PointerKind::Touch(finger_id),
};
app.window_event(&self.window_target, window_id, event);
},
Expand Down
8 changes: 4 additions & 4 deletions src/platform_impl/apple/appkit/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ use super::window::WinitWindow;
use super::DEVICE_ID;
use crate::dpi::{LogicalPosition, LogicalSize};
use crate::event::{
DeviceEvent, ElementState, Ime, Modifiers, MouseButton, MouseScrollDelta, PointerSource,
PointerType, TouchPhase, WindowEvent,
DeviceEvent, ElementState, Ime, Modifiers, MouseButton, MouseScrollDelta, PointerKind,
PointerSource, TouchPhase, WindowEvent,
};
use crate::keyboard::{Key, KeyCode, KeyLocation, ModifiersState, NamedKey};
use crate::platform::macos::OptionAsAlt;
Expand Down Expand Up @@ -651,7 +651,7 @@ declare_class!(
self.queue_event(WindowEvent::PointerEntered {
device_id: DEVICE_ID,
position: view_point.to_physical(self.scale_factor()),
ty: PointerType::Mouse,
kind: PointerKind::Mouse,
});
}

Expand All @@ -664,7 +664,7 @@ declare_class!(
self.queue_event(WindowEvent::PointerLeft {
device_id: DEVICE_ID,
position: Some(position),
ty: PointerType::Mouse,
kind: PointerKind::Mouse,
});
}

Expand Down
14 changes: 7 additions & 7 deletions src/platform_impl/apple/uikit/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use super::window::WinitUIWindow;
use super::{FingerId, DEVICE_ID};
use crate::dpi::PhysicalPosition;
use crate::event::{
ButtonSource, ElementState, Event, FingerId as RootFingerId, Force, PointerSource, PointerType,
ButtonSource, ElementState, Event, FingerId as RootFingerId, Force, PointerKind, PointerSource,
TouchPhase, WindowEvent,
};
use crate::window::{WindowAttributes, WindowId as RootWindowId};
Expand Down Expand Up @@ -495,10 +495,10 @@ impl WinitView {
event: WindowEvent::PointerEntered {
device_id: DEVICE_ID,
position,
ty: if let UITouchType::Pencil = touch_type {
PointerType::Unknown
kind: if let UITouchType::Pencil = touch_type {
PointerKind::Unknown
} else {
PointerType::Touch(finger_id)
PointerKind::Touch(finger_id)
},
},
}));
Expand Down Expand Up @@ -553,10 +553,10 @@ impl WinitView {
event: WindowEvent::PointerLeft {
device_id: DEVICE_ID,
position: Some(position),
ty: if let UITouchType::Pencil = touch_type {
PointerType::Unknown
kind: if let UITouchType::Pencil = touch_type {
PointerKind::Unknown
} else {
PointerType::Touch(finger_id)
PointerKind::Touch(finger_id)
},
},
}));
Expand Down
10 changes: 7 additions & 3 deletions src/platform_impl/linux/wayland/seat/pointer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use sctk::seat::pointer::{
use sctk::seat::SeatState;

use crate::dpi::{LogicalPosition, PhysicalPosition};
use crate::event::{ElementState, MouseButton, MouseScrollDelta, PointerSource, PointerType, TouchPhase, WindowEvent};
use crate::event::{ElementState, MouseButton, MouseScrollDelta, PointerSource, PointerKind, TouchPhase, WindowEvent};

use crate::platform_impl::wayland::state::WinitState;
use crate::platform_impl::wayland::{self, DeviceId, WindowId};
Expand Down Expand Up @@ -125,7 +125,11 @@ impl PointerHandler for WinitState {
// Regular events on the main surface.
PointerEventKind::Enter { .. } => {
self.events_sink.push_window_event(
WindowEvent::PointerEntered { device_id, position, ty: PointerType::Mouse },
WindowEvent::PointerEntered {
device_id,
position,
kind: PointerKind::Mouse,
},
window_id,
);

Expand All @@ -144,7 +148,7 @@ impl PointerHandler for WinitState {
WindowEvent::PointerLeft {
device_id,
position: Some(position),
ty: PointerType::Mouse,
kind: PointerKind::Mouse,
},
window_id,
);
Expand Down
12 changes: 8 additions & 4 deletions src/platform_impl/linux/wayland/seat/touch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use sctk::seat::touch::{TouchData, TouchHandler};
use tracing::warn;

use crate::dpi::LogicalPosition;
use crate::event::{ButtonSource, ElementState, PointerSource, PointerType, WindowEvent};
use crate::event::{ButtonSource, ElementState, PointerKind, PointerSource, WindowEvent};
use crate::platform_impl::wayland::state::WinitState;
use crate::platform_impl::wayland::{self, DeviceId, FingerId};

Expand Down Expand Up @@ -48,7 +48,11 @@ impl TouchHandler for WinitState {
crate::event::FingerId(crate::platform_impl::FingerId::Wayland(FingerId(id)));

self.events_sink.push_window_event(
WindowEvent::PointerEntered { device_id, position, ty: PointerType::Touch(finger_id) },
WindowEvent::PointerEntered {
device_id,
position,
kind: PointerKind::Touch(finger_id),
},
window_id,
);
self.events_sink.push_window_event(
Expand Down Expand Up @@ -109,7 +113,7 @@ impl TouchHandler for WinitState {
WindowEvent::PointerLeft {
device_id,
position: Some(position),
ty: PointerType::Touch(finger_id),
kind: PointerKind::Touch(finger_id),
},
window_id,
);
Expand Down Expand Up @@ -187,7 +191,7 @@ impl TouchHandler for WinitState {
DeviceId,
)),
position: Some(position),
ty: PointerType::Touch(crate::event::FingerId(
kind: PointerKind::Touch(crate::event::FingerId(
crate::platform_impl::FingerId::Wayland(FingerId(id)),
)),
},
Expand Down
14 changes: 9 additions & 5 deletions src/platform_impl/linux/x11/event_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use xkbcommon_dl::xkb_mod_mask_t;
use crate::dpi::{PhysicalPosition, PhysicalSize};
use crate::event::{
ButtonSource, DeviceEvent, ElementState, Event, Ime, InnerSizeWriter, MouseButton,
MouseScrollDelta, PointerSource, PointerType, RawKeyEvent, TouchPhase, WindowEvent,
MouseScrollDelta, PointerKind, PointerSource, RawKeyEvent, TouchPhase, WindowEvent,
};
use crate::keyboard::ModifiersState;
use crate::platform_impl::common::xkb::{self, XkbState};
Expand Down Expand Up @@ -1185,7 +1185,11 @@ impl EventProcessor {

let event = Event::WindowEvent {
window_id,
event: WindowEvent::PointerEntered { device_id, position, ty: PointerType::Mouse },
event: WindowEvent::PointerEntered {
device_id,
position,
kind: PointerKind::Mouse,
},
};
callback(&self.target, event);
}
Expand All @@ -1208,7 +1212,7 @@ impl EventProcessor {
event: WindowEvent::PointerLeft {
device_id: mkdid(event.deviceid as xinput::DeviceId),
position: Some(PhysicalPosition::new(event.event_x, event.event_y)),
ty: PointerType::Mouse,
kind: PointerKind::Mouse,
},
};
callback(&self.target, event);
Expand Down Expand Up @@ -1365,7 +1369,7 @@ impl EventProcessor {
event: WindowEvent::PointerEntered {
device_id,
position,
ty: PointerType::Touch(finger_id),
kind: PointerKind::Touch(finger_id),
},
};
callback(&self.target, event);
Expand Down Expand Up @@ -1407,7 +1411,7 @@ impl EventProcessor {
event: WindowEvent::PointerLeft {
device_id: mkdid(xev.deviceid as xinput::DeviceId),
position: Some(position),
ty: PointerType::Touch(finger_id),
kind: PointerKind::Touch(finger_id),
},
};
callback(&self.target, event);
Expand Down
4 changes: 2 additions & 2 deletions src/platform_impl/orbital/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,13 +488,13 @@ impl EventLoop {
event::WindowEvent::PointerEntered {
device_id: event::DeviceId(DeviceId),
position: dpi::PhysicalPosition::default(),
ty: event::PointerType::Mouse,
kind: event::PointerKind::Mouse,
}
} else {
event::WindowEvent::PointerLeft {
device_id: event::DeviceId(DeviceId),
position: None,
ty: event::PointerType::Mouse,
kind: event::PointerKind::Mouse,
}
};

Expand Down
8 changes: 4 additions & 4 deletions src/platform_impl/web/event_loop/window_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ impl ActiveEventLoop {
let has_focus = has_focus.clone();
let modifiers = self.modifiers.clone();

move |active_modifiers, device_id, position, ty| {
move |active_modifiers, device_id, position, kind| {
let focus = (has_focus.get() && modifiers.get() != active_modifiers).then(|| {
modifiers.set(active_modifiers);
Event::WindowEvent {
Expand All @@ -224,7 +224,7 @@ impl ActiveEventLoop {
event: WindowEvent::PointerLeft {
device_id: RootDeviceId(device_id),
position: Some(position),
ty,
kind,
},
})))
}
Expand All @@ -235,7 +235,7 @@ impl ActiveEventLoop {
let has_focus = has_focus.clone();
let modifiers = self.modifiers.clone();

move |active_modifiers, device_id, position, ty| {
move |active_modifiers, device_id, position, kind| {
let focus = (has_focus.get() && modifiers.get() != active_modifiers).then(|| {
modifiers.set(active_modifiers);
Event::WindowEvent {
Expand All @@ -249,7 +249,7 @@ impl ActiveEventLoop {
event: WindowEvent::PointerEntered {
device_id: RootDeviceId(device_id),
position,
ty,
kind,
},
})))
}
Expand Down
6 changes: 3 additions & 3 deletions src/platform_impl/web/web_sys/canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use super::{event, fullscreen, ResizeScaleHandle};
use crate::dpi::{LogicalPosition, PhysicalPosition, PhysicalSize};
use crate::error::OsError as RootOE;
use crate::event::{
ButtonSource, ElementState, InnerSizeWriter, MouseScrollDelta, PointerSource, PointerType,
ButtonSource, ElementState, InnerSizeWriter, MouseScrollDelta, PointerKind, PointerSource,
};
use crate::keyboard::{Key, KeyLocation, ModifiersState, PhysicalKey};
use crate::platform_impl::{Fullscreen, OsError};
Expand Down Expand Up @@ -332,14 +332,14 @@ impl Canvas {

pub fn on_pointer_leave<F>(&self, handler: F)
where
F: 'static + FnMut(ModifiersState, DeviceId, PhysicalPosition<f64>, PointerType),
F: 'static + FnMut(ModifiersState, DeviceId, PhysicalPosition<f64>, PointerKind),
{
self.handlers.borrow_mut().pointer_handler.on_pointer_leave(&self.common, handler)
}

pub fn on_pointer_enter<F>(&self, handler: F)
where
F: 'static + FnMut(ModifiersState, DeviceId, PhysicalPosition<f64>, PointerType),
F: 'static + FnMut(ModifiersState, DeviceId, PhysicalPosition<f64>, PointerKind),
{
self.handlers.borrow_mut().pointer_handler.on_pointer_enter(&self.common, handler)
}
Expand Down
Loading

0 comments on commit d7e7e31

Please sign in to comment.