Remove generic parameter T from EventLoopWindowTarget (#3298)

This commit is contained in:
Mads Marquart 2024-01-13 21:36:53 +01:00 committed by GitHub
parent 169cd39f93
commit 22311802b5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
37 changed files with 174 additions and 210 deletions

View file

@ -36,7 +36,7 @@ use crate::{
/// The X11 documentation states: "Keycodes lie in the inclusive range `[8, 255]`".
const KEYCODE_OFFSET: u8 = 8;
pub(super) struct EventProcessor<T: 'static> {
pub(super) struct EventProcessor {
pub(super) dnd: Dnd,
pub(super) ime_receiver: ImeReceiver,
pub(super) ime_event_receiver: ImeEventReceiver,
@ -44,7 +44,7 @@ pub(super) struct EventProcessor<T: 'static> {
pub(super) devices: RefCell<HashMap<DeviceId, Device>>,
pub(super) xi2ext: ExtensionInformation,
pub(super) xkbext: ExtensionInformation,
pub(super) target: Rc<RootELW<T>>,
pub(super) target: Rc<RootELW>,
pub(super) kb_state: KbdState,
// Number of touch events currently in progress
pub(super) num_touch: u32,
@ -61,7 +61,7 @@ pub(super) struct EventProcessor<T: 'static> {
pub(super) is_composing: bool,
}
impl<T: 'static> EventProcessor<T> {
impl EventProcessor {
pub(super) fn init_device(&self, device: xinput::DeviceId) {
let wt = get_xtarget(&self.target);
let mut devices = self.devices.borrow_mut();
@ -136,7 +136,7 @@ impl<T: 'static> EventProcessor<T> {
result != 0
}
pub(super) fn process_event<F>(&mut self, xev: &mut ffi::XEvent, mut callback: F)
pub(super) fn process_event<T: 'static, F>(&mut self, xev: &mut ffi::XEvent, mut callback: F)
where
F: FnMut(Event<T>),
{
@ -1370,7 +1370,11 @@ impl<T: 'static> EventProcessor<T> {
/// Send modifiers for the active window.
///
/// The event won't be send when the `modifiers` match the previosly `sent` modifiers value.
fn send_modifiers<F: FnMut(Event<T>)>(&self, modifiers: ModifiersState, callback: &mut F) {
fn send_modifiers<T: 'static, F: FnMut(Event<T>)>(
&self,
modifiers: ModifiersState,
callback: &mut F,
) {
let window_id = match self.active_window {
Some(window) => mkwid(window),
None => return,
@ -1384,8 +1388,8 @@ impl<T: 'static> EventProcessor<T> {
}
}
fn handle_pressed_keys<F>(
wt: &super::EventLoopWindowTarget<T>,
fn handle_pressed_keys<T: 'static, F>(
wt: &super::EventLoopWindowTarget,
window_id: crate::window::WindowId,
state: ElementState,
kb_state: &mut KbdState,
@ -1415,7 +1419,7 @@ impl<T: 'static> EventProcessor<T> {
}
}
fn process_dpi_change<F>(&self, callback: &mut F)
fn process_dpi_change<T: 'static, F>(&self, callback: &mut F)
where
F: FnMut(Event<T>),
{

View file

@ -27,6 +27,7 @@ use std::{
collections::{HashMap, HashSet},
ffi::CStr,
fmt,
marker::PhantomData,
mem::MaybeUninit,
ops::Deref,
os::{
@ -142,7 +143,7 @@ impl<T> PeekableReceiver<T> {
}
}
pub struct EventLoopWindowTarget<T> {
pub struct EventLoopWindowTarget {
xconn: Arc<XConnection>,
wm_delete_window: xproto::Atom,
net_wm_ping: xproto::Atom,
@ -155,19 +156,18 @@ pub struct EventLoopWindowTarget<T> {
redraw_sender: WakeSender<WindowId>,
activation_sender: WakeSender<ActivationToken>,
device_events: Cell<DeviceEvents>,
_marker: ::std::marker::PhantomData<T>,
}
pub struct EventLoop<T: 'static> {
loop_running: bool,
event_loop: Loop<'static, EventLoopState>,
waker: calloop::ping::Ping,
event_processor: EventProcessor<T>,
event_processor: EventProcessor,
redraw_receiver: PeekableReceiver<WindowId>,
user_receiver: PeekableReceiver<T>,
activation_receiver: PeekableReceiver<ActivationToken>,
user_sender: Sender<T>,
target: Rc<RootELW<T>>,
target: Rc<RootELW>,
/// The current state of the event loop.
state: EventLoopState,
@ -307,7 +307,6 @@ impl<T: 'static> EventLoop<T> {
control_flow: Cell::new(ControlFlow::default()),
exit: Cell::new(None),
windows: Default::default(),
_marker: ::std::marker::PhantomData,
ime_sender,
xconn,
wm_delete_window,
@ -328,7 +327,7 @@ impl<T: 'static> EventLoop<T> {
let target = Rc::new(RootELW {
p: super::EventLoopWindowTarget::X(window_target),
_marker: ::std::marker::PhantomData,
_marker: PhantomData,
});
let event_processor = EventProcessor {
@ -397,13 +396,13 @@ impl<T: 'static> EventLoop<T> {
}
}
pub(crate) fn window_target(&self) -> &RootELW<T> {
pub(crate) fn window_target(&self) -> &RootELW {
&self.target
}
pub fn run_on_demand<F>(&mut self, mut event_handler: F) -> Result<(), EventLoopError>
where
F: FnMut(Event<T>, &RootELW<T>),
F: FnMut(Event<T>, &RootELW),
{
if self.loop_running {
return Err(EventLoopError::AlreadyRunning);
@ -437,7 +436,7 @@ impl<T: 'static> EventLoop<T> {
pub fn pump_events<F>(&mut self, timeout: Option<Duration>, mut callback: F) -> PumpStatus
where
F: FnMut(Event<T>, &RootELW<T>),
F: FnMut(Event<T>, &RootELW),
{
if !self.loop_running {
self.loop_running = true;
@ -470,7 +469,7 @@ impl<T: 'static> EventLoop<T> {
pub fn poll_events_with_timeout<F>(&mut self, mut timeout: Option<Duration>, mut callback: F)
where
F: FnMut(Event<T>, &RootELW<T>),
F: FnMut(Event<T>, &RootELW),
{
let start = Instant::now();
@ -548,7 +547,7 @@ impl<T: 'static> EventLoop<T> {
fn single_iteration<F>(&mut self, callback: &mut F, cause: StartCause)
where
F: FnMut(Event<T>, &RootELW<T>),
F: FnMut(Event<T>, &RootELW),
{
callback(crate::event::Event::NewEvents(cause), &self.target);
@ -622,7 +621,7 @@ impl<T: 'static> EventLoop<T> {
fn drain_events<F>(&mut self, callback: &mut F)
where
F: FnMut(Event<T>, &RootELW<T>),
F: FnMut(Event<T>, &RootELW),
{
let target = &self.target;
let mut xev = MaybeUninit::uninit();
@ -673,7 +672,7 @@ impl<T> AsRawFd for EventLoop<T> {
}
}
pub(crate) fn get_xtarget<T>(target: &RootELW<T>) -> &EventLoopWindowTarget<T> {
pub(crate) fn get_xtarget(target: &RootELW) -> &EventLoopWindowTarget {
match target.p {
super::EventLoopWindowTarget::X(ref target) => target,
#[cfg(wayland_platform)]
@ -681,7 +680,7 @@ pub(crate) fn get_xtarget<T>(target: &RootELW<T>) -> &EventLoopWindowTarget<T> {
}
}
impl<T> EventLoopWindowTarget<T> {
impl EventLoopWindowTarget {
/// Returns the `XConnection` of this events loop.
#[inline]
pub(crate) fn x_connection(&self) -> &Arc<XConnection> {
@ -840,8 +839,8 @@ impl Deref for Window {
}
impl Window {
pub(crate) fn new<T>(
event_loop: &EventLoopWindowTarget<T>,
pub(crate) fn new(
event_loop: &EventLoopWindowTarget,
attribs: WindowAttributes,
pl_attribs: PlatformSpecificWindowBuilderAttributes,
) -> Result<Self, RootOsError> {

View file

@ -152,8 +152,8 @@ macro_rules! leap {
impl UnownedWindow {
#[allow(clippy::unnecessary_cast)]
pub(crate) fn new<T>(
event_loop: &EventLoopWindowTarget<T>,
pub(crate) fn new(
event_loop: &EventLoopWindowTarget,
window_attrs: WindowAttributes,
pl_attribs: PlatformSpecificWindowBuilderAttributes,
) -> Result<UnownedWindow, RootOsError> {