api: remove ::dummy from Id types

`::dummy` was used for testing purposes and became redundant after
adding e.g. `from_raw` and `into_raw` methods on `Id` types.
This commit is contained in:
daxpedda 2024-09-29 15:49:45 +02:00 committed by GitHub
parent 6e1b9fa24d
commit 32cd1ad9a7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
35 changed files with 219 additions and 352 deletions

View file

@ -111,10 +111,6 @@ pub(crate) static X11_BACKEND: Lazy<Mutex<Result<Arc<XConnection>, XNotSupported
pub struct WindowId(u64);
impl WindowId {
pub const fn dummy() -> Self {
Self(0)
}
pub const fn into_raw(self) -> u64 {
self.0
}
@ -129,18 +125,10 @@ pub enum DeviceId {
#[cfg(x11_platform)]
X(x11::DeviceId),
#[cfg(wayland_platform)]
#[allow(unused)]
Wayland(wayland::DeviceId),
}
impl DeviceId {
pub const fn dummy() -> Self {
#[cfg(wayland_platform)]
return DeviceId::Wayland(wayland::DeviceId::dummy());
#[cfg(all(not(wayland_platform), x11_platform))]
return DeviceId::X(x11::DeviceId::dummy());
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum FingerId {
#[cfg(x11_platform)]
@ -150,6 +138,7 @@ pub enum FingerId {
}
impl FingerId {
#[cfg(test)]
pub const fn dummy() -> Self {
#[cfg(wayland_platform)]
return FingerId::Wayland(wayland::FingerId::dummy());

View file

@ -30,7 +30,7 @@ use sink::EventSink;
use super::state::{WindowCompositorUpdate, WinitState};
use super::window::state::FrameCallbackState;
use super::{logical_to_physical_rounded, DeviceId, WindowId};
use super::{logical_to_physical_rounded, WindowId};
type WaylandDispatcher = calloop::Dispatcher<'static, WaylandSource<WinitState>, WinitState>;

View file

@ -2,9 +2,8 @@
use std::vec::Drain;
use super::{DeviceId, WindowId};
use crate::event::{DeviceEvent, DeviceId as RootDeviceId, Event, WindowEvent};
use crate::platform_impl::platform::DeviceId as PlatformDeviceId;
use super::WindowId;
use crate::event::{DeviceEvent, Event, WindowEvent};
use crate::window::WindowId as RootWindowId;
/// An event loop's sink to deliver events from the Wayland event callbacks
@ -27,11 +26,8 @@ impl EventSink {
/// Add new device event to a queue.
#[inline]
pub fn push_device_event(&mut self, event: DeviceEvent, device_id: DeviceId) {
self.window_events.push(Event::DeviceEvent {
event,
device_id: RootDeviceId(PlatformDeviceId::Wayland(device_id)),
});
pub fn push_device_event(&mut self, event: DeviceEvent) {
self.window_events.push(Event::DeviceEvent { event, device_id: None });
}
/// Add new window event to a queue.

View file

@ -21,16 +21,11 @@ mod window;
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct DeviceId;
impl DeviceId {
pub const fn dummy() -> Self {
DeviceId
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct FingerId(i32);
impl FingerId {
#[cfg(test)]
pub const fn dummy() -> Self {
FingerId(0)
}

View file

@ -17,7 +17,7 @@ use crate::keyboard::ModifiersState;
use crate::platform_impl::common::xkb::Context;
use crate::platform_impl::wayland::event_loop::sink::EventSink;
use crate::platform_impl::wayland::state::WinitState;
use crate::platform_impl::wayland::{self, DeviceId, WindowId};
use crate::platform_impl::wayland::{self, WindowId};
impl Dispatch<WlKeyboard, KeyboardData, WinitState> for WinitState {
fn event(
@ -369,10 +369,9 @@ fn key_input(
None => return,
};
let device_id = crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland(DeviceId));
if let Some(mut key_context) = keyboard_state.xkb_context.key_context() {
let event = key_context.process_key_event(keycode, state, repeat);
let event = WindowEvent::KeyboardInput { device_id, event, is_synthetic: false };
let event = WindowEvent::KeyboardInput { device_id: None, event, is_synthetic: false };
event_sink.push_window_event(event, window_id);
}
}

View file

@ -30,7 +30,7 @@ use crate::dpi::{LogicalPosition, PhysicalPosition};
use crate::event::{ElementState, MouseButton, MouseScrollDelta, TouchPhase, WindowEvent};
use crate::platform_impl::wayland::state::WinitState;
use crate::platform_impl::wayland::{self, DeviceId, WindowId};
use crate::platform_impl::wayland::{self, WindowId};
pub mod relative_pointer;
@ -59,8 +59,6 @@ impl PointerHandler for WinitState {
},
};
let device_id = crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland(DeviceId));
for event in events {
let surface = &event.surface;
@ -124,8 +122,10 @@ impl PointerHandler for WinitState {
},
// Regular events on the main surface.
PointerEventKind::Enter { .. } => {
self.events_sink
.push_window_event(WindowEvent::CursorEntered { device_id }, window_id);
self.events_sink.push_window_event(
WindowEvent::CursorEntered { device_id: None },
window_id,
);
window.pointer_entered(Arc::downgrade(themed_pointer));
@ -133,7 +133,7 @@ impl PointerHandler for WinitState {
pointer.winit_data().inner.lock().unwrap().surface = Some(window_id);
self.events_sink.push_window_event(
WindowEvent::CursorMoved { device_id, position },
WindowEvent::CursorMoved { device_id: None, position },
window_id,
);
},
@ -144,11 +144,11 @@ impl PointerHandler for WinitState {
pointer.winit_data().inner.lock().unwrap().surface = None;
self.events_sink
.push_window_event(WindowEvent::CursorLeft { device_id }, window_id);
.push_window_event(WindowEvent::CursorLeft { device_id: None }, window_id);
},
PointerEventKind::Motion { .. } => {
self.events_sink.push_window_event(
WindowEvent::CursorMoved { device_id, position },
WindowEvent::CursorMoved { device_id: None, position },
window_id,
);
},
@ -164,7 +164,7 @@ impl PointerHandler for WinitState {
ElementState::Released
};
self.events_sink.push_window_event(
WindowEvent::MouseInput { device_id, state, button },
WindowEvent::MouseInput { device_id: None, state, button },
window_id,
);
},
@ -209,7 +209,7 @@ impl PointerHandler for WinitState {
};
self.events_sink.push_window_event(
WindowEvent::MouseWheel { device_id, delta, phase },
WindowEvent::MouseWheel { device_id: None, delta, phase },
window_id,
)
},

View file

@ -66,10 +66,9 @@ impl Dispatch<ZwpRelativePointerV1, GlobalData, WinitState> for RelativePointerS
},
_ => return,
};
state.events_sink.push_device_event(
DeviceEvent::MouseMotion { delta: (dx_unaccel, dy_unaccel) },
super::DeviceId,
);
state
.events_sink
.push_device_event(DeviceEvent::MouseMotion { delta: (dx_unaccel, dy_unaccel) });
}
}

View file

@ -10,7 +10,7 @@ use tracing::warn;
use crate::dpi::LogicalPosition;
use crate::event::{Touch, TouchPhase, WindowEvent};
use crate::platform_impl::wayland::state::WinitState;
use crate::platform_impl::wayland::{self, DeviceId, FingerId};
use crate::platform_impl::wayland::{self, FingerId};
impl TouchHandler for WinitState {
fn down(
@ -44,9 +44,7 @@ impl TouchHandler for WinitState {
self.events_sink.push_window_event(
WindowEvent::Touch(Touch {
device_id: crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland(
DeviceId,
)),
device_id: None,
phase: TouchPhase::Started,
location: location.to_physical(scale_factor),
force: None,
@ -89,9 +87,7 @@ impl TouchHandler for WinitState {
self.events_sink.push_window_event(
WindowEvent::Touch(Touch {
device_id: crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland(
DeviceId,
)),
device_id: None,
phase: TouchPhase::Ended,
location: touch_point.location.to_physical(scale_factor),
force: None,
@ -136,9 +132,7 @@ impl TouchHandler for WinitState {
self.events_sink.push_window_event(
WindowEvent::Touch(Touch {
device_id: crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland(
DeviceId,
)),
device_id: None,
phase: TouchPhase::Moved,
location: touch_point.location.to_physical(scale_factor),
force: None,
@ -170,9 +164,7 @@ impl TouchHandler for WinitState {
self.events_sink.push_window_event(
WindowEvent::Touch(Touch {
device_id: crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland(
DeviceId,
)),
device_id: None,
phase: TouchPhase::Cancelled,
location,
force: None,

View file

@ -878,7 +878,6 @@ impl EventProcessor {
};
let window_id = mkwid(window);
let device_id = mkdid(util::VIRTUAL_CORE_KEYBOARD);
let keycode = xev.keycode as _;
@ -942,7 +941,11 @@ impl EventProcessor {
let event = key_processor.process_key_event(keycode, state, repeat);
let event = Event::WindowEvent {
window_id,
event: WindowEvent::KeyboardInput { device_id, event, is_synthetic: false },
event: WindowEvent::KeyboardInput {
device_id: None,
event,
is_synthetic: false,
},
};
callback(&self.target, event);
}
@ -1012,7 +1015,7 @@ impl EventProcessor {
F: FnMut(&ActiveEventLoop, Event),
{
let window_id = mkwid(event.event as xproto::Window);
let device_id = mkdid(event.deviceid as xinput::DeviceId);
let device_id = Some(mkdid(event.deviceid as xinput::DeviceId));
// Set the timestamp.
self.target.xconn.set_timestamp(event.time as xproto::Timestamp);
@ -1066,7 +1069,7 @@ impl EventProcessor {
// Set the timestamp.
self.target.xconn.set_timestamp(event.time as xproto::Timestamp);
let device_id = mkdid(event.deviceid as xinput::DeviceId);
let device_id = Some(mkdid(event.deviceid as xinput::DeviceId));
let window = event.event as xproto::Window;
let window_id = mkwid(window);
let new_cursor_pos = (event.event_x, event.event_y);
@ -1161,6 +1164,7 @@ impl EventProcessor {
}
if self.window_exists(window) {
let device_id = Some(device_id);
let position = PhysicalPosition::new(event.event_x, event.event_y);
let event =
@ -1190,7 +1194,7 @@ impl EventProcessor {
let event = Event::WindowEvent {
window_id: mkwid(window),
event: WindowEvent::CursorLeft {
device_id: mkdid(event.deviceid as xinput::DeviceId),
device_id: Some(mkdid(event.deviceid as xinput::DeviceId)),
},
};
callback(&self.target, event);
@ -1241,16 +1245,15 @@ impl EventProcessor {
// The deviceid for this event is for a keyboard instead of a pointer,
// so we have to do a little extra work.
let pointer_id = self
let device_id = self
.devices
.borrow()
.get(&DeviceId(xev.deviceid as xinput::DeviceId))
.map(|device| device.attachment)
.unwrap_or(2);
.map(|device| mkdid(device.attachment as _));
let event = Event::WindowEvent {
window_id,
event: WindowEvent::CursorMoved { device_id: mkdid(pointer_id as _), position },
event: WindowEvent::CursorMoved { device_id, position },
};
callback(&self.target, event);
}
@ -1324,10 +1327,7 @@ impl EventProcessor {
if is_first_touch(&mut self.first_touch, &mut self.num_touch, id, phase) {
let event = Event::WindowEvent {
window_id,
event: WindowEvent::CursorMoved {
device_id: mkdid(util::VIRTUAL_CORE_POINTER),
position: location.cast(),
},
event: WindowEvent::CursorMoved { device_id: None, position: location.cast() },
};
callback(&self.target, event);
}
@ -1335,7 +1335,7 @@ impl EventProcessor {
let event = Event::WindowEvent {
window_id,
event: WindowEvent::Touch(Touch {
device_id: mkdid(xev.deviceid as xinput::DeviceId),
device_id: Some(mkdid(xev.deviceid as xinput::DeviceId)),
phase,
location,
force: None, // TODO
@ -1355,7 +1355,7 @@ impl EventProcessor {
if xev.flags & xinput2::XIPointerEmulated == 0 {
let event = Event::DeviceEvent {
device_id: mkdid(xev.deviceid as xinput::DeviceId),
device_id: Some(mkdid(xev.deviceid as xinput::DeviceId)),
event: DeviceEvent::Button { state, button: xev.detail as u32 },
};
callback(&self.target, event);
@ -1369,7 +1369,7 @@ impl EventProcessor {
// Set the timestamp.
self.target.xconn.set_timestamp(xev.time as xproto::Timestamp);
let did = mkdid(xev.deviceid as xinput::DeviceId);
let did = Some(mkdid(xev.deviceid as xinput::DeviceId));
let mask =
unsafe { slice::from_raw_parts(xev.valuators.mask, xev.valuators.mask_len as usize) };
@ -1421,7 +1421,7 @@ impl EventProcessor {
// Set the timestamp.
self.target.xconn.set_timestamp(xev.time as xproto::Timestamp);
let device_id = mkdid(xev.sourceid as xinput::DeviceId);
let device_id = Some(mkdid(xev.sourceid as xinput::DeviceId));
let keycode = xev.detail as u32;
if keycode < KEYCODE_OFFSET as u32 {
return;
@ -1695,8 +1695,6 @@ impl EventProcessor {
) where
F: FnMut(&ActiveEventLoop, Event),
{
let device_id = mkdid(util::VIRTUAL_CORE_KEYBOARD);
// Update modifiers state and emit key events based on which keys are currently pressed.
let xcb = target.xconn.xcb_connection().get_raw_xcb_connection();
@ -1719,7 +1717,7 @@ impl EventProcessor {
let event = key_processor.process_key_event(keycode as u32, state, false);
let event = Event::WindowEvent {
window_id,
event: WindowEvent::KeyboardInput { device_id, event, is_synthetic: true },
event: WindowEvent::KeyboardInput { device_id: None, event, is_synthetic: true },
};
callback(target, event);
}

View file

@ -811,17 +811,11 @@ impl<'a> Deref for DeviceInfo<'a> {
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct DeviceId(xinput::DeviceId);
impl DeviceId {
#[allow(unused)]
pub const fn dummy() -> Self {
DeviceId(0)
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct FingerId(u32);
impl FingerId {
#[cfg(test)]
#[allow(unused)]
pub const fn dummy() -> Self {
FingerId(0)

View file

@ -6,7 +6,6 @@ use x11rb::protocol::xkb;
use super::*;
pub const VIRTUAL_CORE_POINTER: u16 = 2;
pub const VIRTUAL_CORE_KEYBOARD: u16 = 3;
// A base buffer size of 1kB uses a negligible amount of RAM while preventing us from having to
// re-allocate (and make another round-trip) in the *vast* majority of cases.