Move Event::RedrawRequested to WindowEvent (#3049)

This commit is contained in:
daxpedda 2023-08-27 16:15:09 +02:00 committed by GitHub
parent a3cba838ea
commit 67d3fd28f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
46 changed files with 572 additions and 562 deletions

View file

@ -407,7 +407,10 @@ impl<T: 'static> EventLoop<T> {
pending_redraw |= self.redraw_flag.get_and_reset();
if pending_redraw {
pending_redraw = false;
let event = event::Event::RedrawRequested(window::WindowId(WindowId));
let event = event::Event::WindowEvent {
window_id: window::WindowId(WindowId),
event: event::WindowEvent::RedrawRequested,
};
sticky_exit_callback(event, self.window_target(), &mut control_flow, callback);
}
}

View file

@ -57,7 +57,13 @@ enum UserCallbackTransitionResult<'a> {
impl Event<Never> {
fn is_redraw(&self) -> bool {
matches!(self, Event::RedrawRequested(_))
matches!(
self,
Event::WindowEvent {
event: WindowEvent::RedrawRequested,
..
}
)
}
}
@ -755,7 +761,12 @@ pub unsafe fn handle_main_events_cleared() {
let redraw_events: Vec<EventWrapper> = this
.main_events_cleared_transition()
.into_iter()
.map(|window| EventWrapper::StaticEvent(Event::RedrawRequested(RootWindowId(window.id()))))
.map(|window| {
EventWrapper::StaticEvent(Event::WindowEvent {
window_id: RootWindowId(window.id()),
event: WindowEvent::RedrawRequested,
})
})
.collect();
drop(this);

View file

@ -43,9 +43,10 @@ declare_class!(
fn draw_rect(&self, rect: CGRect) {
let window = self.window().unwrap();
unsafe {
app_state::handle_nonuser_event(EventWrapper::StaticEvent(Event::RedrawRequested(
RootWindowId(window.id()),
)));
app_state::handle_nonuser_event(EventWrapper::StaticEvent(Event::WindowEvent {
window_id: RootWindowId(window.id()),
event: WindowEvent::RedrawRequested,
}));
}
let _: () = unsafe { msg_send![super(self), drawRect: rect] };
}

View file

@ -580,7 +580,10 @@ impl<T: 'static> EventLoop<T> {
if request_redraw {
sticky_exit_callback(
Event::RedrawRequested(crate::window::WindowId(window_id)),
Event::WindowEvent {
window_id: crate::window::WindowId(window_id),
event: WindowEvent::RedrawRequested,
},
&self.window_target,
&mut control_flow,
&mut callback,

View file

@ -576,7 +576,10 @@ impl<T: 'static> EventProcessor<T> {
let window = xev.window as xproto::Window;
let window_id = mkwid(window);
callback(Event::RedrawRequested(window_id));
callback(Event::WindowEvent {
window_id,
event: WindowEvent::RedrawRequested,
});
}
}

View file

@ -65,7 +65,7 @@ use self::{
use super::{common::xkb_state::KbdState, OsError};
use crate::{
error::{EventLoopError, OsError as RootOsError},
event::{Event, StartCause},
event::{Event, StartCause, WindowEvent},
event_loop::{ControlFlow, DeviceEvents, EventLoopClosed, EventLoopWindowTarget as RootELW},
platform::pump_events::PumpStatus,
platform_impl::{
@ -671,7 +671,10 @@ impl<T: 'static> EventLoop<T> {
for window_id in windows {
let window_id = crate::window::WindowId(window_id);
sticky_exit_callback(
Event::RedrawRequested(window_id),
Event::WindowEvent {
window_id,
event: WindowEvent::RedrawRequested,
},
&self.target,
&mut control_flow,
callback,
@ -708,7 +711,11 @@ impl<T: 'static> EventLoop<T> {
target,
control_flow,
&mut |event, window_target, control_flow| {
if let Event::RedrawRequested(crate::window::WindowId(wid)) = event {
if let Event::WindowEvent {
window_id: crate::window::WindowId(wid),
event: WindowEvent::RedrawRequested,
} = event
{
wt.redraw_sender.send(wid).unwrap();
} else {
callback(event, window_target, control_flow);

View file

@ -564,8 +564,10 @@ impl AppState {
// Redraw request might come out of order from the OS.
// -> Don't go back into the callback when our callstack originates from there
if !HANDLER.in_callback.swap(true, Ordering::AcqRel) {
HANDLER
.handle_nonuser_event(EventWrapper::StaticEvent(Event::RedrawRequested(window_id)));
HANDLER.handle_nonuser_event(EventWrapper::StaticEvent(Event::WindowEvent {
window_id,
event: WindowEvent::RedrawRequested,
}));
HANDLER.set_in_callback(false);
// `pump_events` will request to stop immediately _after_ dispatching RedrawRequested events
@ -616,8 +618,10 @@ impl AppState {
}
for window_id in HANDLER.should_redraw() {
HANDLER
.handle_nonuser_event(EventWrapper::StaticEvent(Event::RedrawRequested(window_id)));
HANDLER.handle_nonuser_event(EventWrapper::StaticEvent(Event::WindowEvent {
window_id,
event: WindowEvent::RedrawRequested,
}));
}
HANDLER.handle_nonuser_event(EventWrapper::StaticEvent(Event::AboutToWait));

View file

@ -608,7 +608,10 @@ impl<T: 'static> EventLoop<T> {
redraws.pop_front()
} {
event_handler(
event::Event::RedrawRequested(RootWindowId(window_id)),
event::Event::WindowEvent {
window_id: RootWindowId(window_id),
event: event::WindowEvent::RedrawRequested,
},
&self.window_target,
&mut control_flow,
);

View file

@ -567,7 +567,13 @@ impl<T: 'static> Shared<T> {
// Collect all of the redraw events to avoid double-locking the RefCell
let redraw_events: Vec<WindowId> = self.0.redraw_pending.borrow_mut().drain().collect();
for window_id in redraw_events {
self.handle_event(Event::RedrawRequested(window_id), &mut control);
self.handle_event(
Event::WindowEvent {
window_id,
event: WindowEvent::RedrawRequested,
},
&mut control,
);
}
self.handle_event(Event::AboutToWait, &mut control);

View file

@ -1152,7 +1152,10 @@ unsafe fn public_window_callback_inner<T: 'static>(
// redraw the window outside the normal flow of the event loop.
RedrawWindow(window, ptr::null(), 0, RDW_INTERNALPAINT);
} else {
userdata.send_event(Event::RedrawRequested(RootWindowId(WindowId(window))));
userdata.send_event(Event::WindowEvent {
window_id: RootWindowId(WindowId(window)),
event: WindowEvent::RedrawRequested,
});
}
result = ProcResult::DefWindowProc(wparam);
}

View file

@ -198,7 +198,11 @@ impl<T> EventLoopRunner<T> {
}
pub(crate) fn send_event(&self, event: Event<T>) {
if let Event::RedrawRequested(_) = event {
if let Event::WindowEvent {
event: WindowEvent::RedrawRequested,
..
} = event
{
self.call_event_handler(event);
// As a rule, to ensure that `pump_events` can't block an external event loop
// for too long, we always guarantee that `pump_events` will return control to