Implement changes to RedrawRequested event (#1062)
* Implement changes to `RedrawRequested` event Implements the changes described in #1041 for the X11 platform and for platform-independent public-facing code. * Fix `request_redraw` example * Fix examples in lib docs * Only issue `RedrawRequested` on final `Expose` event
This commit is contained in:
parent
c10c820311
commit
0c151f9fb3
7 changed files with 67 additions and 37 deletions
|
|
@ -526,7 +526,7 @@ impl<T: 'static> EventLoop<T> {
|
|||
// send Events cleared
|
||||
{
|
||||
sticky_exit_callback(
|
||||
crate::event::Event::EventsCleared,
|
||||
crate::event::Event::MainEventsCleared,
|
||||
&self.window_target,
|
||||
&mut control_flow,
|
||||
&mut callback,
|
||||
|
|
@ -704,7 +704,8 @@ impl<T> EventLoop<T> {
|
|||
);
|
||||
}
|
||||
if window.refresh {
|
||||
sink.send_window_event(crate::event::WindowEvent::RedrawRequested, window.wid);
|
||||
unimplemented!()
|
||||
//sink.send_window_event(crate::event::WindowEvent::RedrawRequested, window.wid);
|
||||
}
|
||||
if window.closed {
|
||||
sink.send_window_event(crate::event::WindowEvent::CloseRequested, window.wid);
|
||||
|
|
|
|||
|
|
@ -534,13 +534,14 @@ impl<T: 'static> EventProcessor<T> {
|
|||
ffi::Expose => {
|
||||
let xev: &ffi::XExposeEvent = xev.as_ref();
|
||||
|
||||
let window = xev.window;
|
||||
let window_id = mkwid(window);
|
||||
// Multiple Expose events may be received for subareas of a window.
|
||||
// We issue `RedrawRequested` only for the last event of such a series.
|
||||
if xev.count == 0 {
|
||||
let window = xev.window;
|
||||
let window_id = mkwid(window);
|
||||
|
||||
callback(Event::WindowEvent {
|
||||
window_id,
|
||||
event: WindowEvent::RedrawRequested,
|
||||
});
|
||||
callback(Event::RedrawRequested(window_id));
|
||||
}
|
||||
}
|
||||
|
||||
ffi::KeyPress | ffi::KeyRelease => {
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ use self::{
|
|||
};
|
||||
use crate::{
|
||||
error::OsError as RootOsError,
|
||||
event::{Event, StartCause, WindowEvent},
|
||||
event::{Event, StartCause},
|
||||
event_loop::{ControlFlow, EventLoopClosed, EventLoopWindowTarget as RootELW},
|
||||
platform_impl::{platform::sticky_exit_callback, PlatformSpecificWindowBuilderAttributes},
|
||||
window::WindowAttributes,
|
||||
|
|
@ -151,6 +151,8 @@ impl<T: 'static> EventLoop<T> {
|
|||
|
||||
xconn.update_cached_wm_info(root);
|
||||
|
||||
let pending_redraws: Arc<Mutex<HashSet<WindowId>>> = Default::default();
|
||||
|
||||
let mut mod_keymap = ModifierKeymap::new();
|
||||
mod_keymap.reset_from_x_connection(&xconn);
|
||||
|
||||
|
|
@ -164,7 +166,7 @@ impl<T: 'static> EventLoop<T> {
|
|||
xconn,
|
||||
wm_delete_window,
|
||||
net_wm_ping,
|
||||
pending_redraws: Default::default(),
|
||||
pending_redraws: pending_redraws.clone(),
|
||||
}),
|
||||
_marker: ::std::marker::PhantomData,
|
||||
});
|
||||
|
|
@ -227,7 +229,9 @@ impl<T: 'static> EventLoop<T> {
|
|||
if evt.readiness.is_readable() {
|
||||
let mut processor = processor.borrow_mut();
|
||||
let mut pending_events = pending_events.borrow_mut();
|
||||
drain_events(&mut processor, &mut pending_events);
|
||||
let mut pending_redraws = pending_redraws.lock().unwrap();
|
||||
|
||||
drain_events(&mut processor, &mut pending_events, &mut pending_redraws);
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
@ -293,6 +297,15 @@ impl<T: 'static> EventLoop<T> {
|
|||
);
|
||||
}
|
||||
}
|
||||
// send MainEventsCleared
|
||||
{
|
||||
sticky_exit_callback(
|
||||
crate::event::Event::MainEventsCleared,
|
||||
&self.target,
|
||||
&mut control_flow,
|
||||
&mut callback,
|
||||
);
|
||||
}
|
||||
// Empty the redraw requests
|
||||
{
|
||||
// Release the lock to prevent deadlock
|
||||
|
|
@ -300,20 +313,17 @@ impl<T: 'static> EventLoop<T> {
|
|||
|
||||
for wid in windows {
|
||||
sticky_exit_callback(
|
||||
Event::WindowEvent {
|
||||
window_id: crate::window::WindowId(super::WindowId::X(wid)),
|
||||
event: WindowEvent::RedrawRequested,
|
||||
},
|
||||
Event::RedrawRequested(crate::window::WindowId(super::WindowId::X(wid))),
|
||||
&self.target,
|
||||
&mut control_flow,
|
||||
&mut callback,
|
||||
);
|
||||
}
|
||||
}
|
||||
// send Events cleared
|
||||
// send RedrawEventsCleared
|
||||
{
|
||||
sticky_exit_callback(
|
||||
crate::event::Event::EventsCleared,
|
||||
crate::event::Event::RedrawEventsCleared,
|
||||
&self.target,
|
||||
&mut control_flow,
|
||||
&mut callback,
|
||||
|
|
@ -392,8 +402,10 @@ impl<T: 'static> EventLoop<T> {
|
|||
fn drain_events(&self) {
|
||||
let mut processor = self.event_processor.borrow_mut();
|
||||
let mut pending_events = self.pending_events.borrow_mut();
|
||||
let wt = get_xtarget(&self.target);
|
||||
let mut pending_redraws = wt.pending_redraws.lock().unwrap();
|
||||
|
||||
drain_events(&mut processor, &mut pending_events);
|
||||
drain_events(&mut processor, &mut pending_events, &mut pending_redraws);
|
||||
}
|
||||
|
||||
fn events_waiting(&self) -> bool {
|
||||
|
|
@ -404,9 +416,14 @@ impl<T: 'static> EventLoop<T> {
|
|||
fn drain_events<T: 'static>(
|
||||
processor: &mut EventProcessor<T>,
|
||||
pending_events: &mut VecDeque<Event<T>>,
|
||||
pending_redraws: &mut HashSet<WindowId>,
|
||||
) {
|
||||
let mut callback = |event| {
|
||||
pending_events.push_back(event);
|
||||
if let Event::RedrawRequested(crate::window::WindowId(super::WindowId::X(wid))) = event {
|
||||
pending_redraws.insert(wid);
|
||||
} else {
|
||||
pending_events.push_back(event);
|
||||
}
|
||||
};
|
||||
|
||||
// process all pending events
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue