Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Issues : Unexpected Monitor Behavior When Resizing egui Program with wgpu on Windows. #5064

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions crates/eframe/src/native/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ impl<T: WinitApp> WinitAppWrapper<T> {
event_result: Result<EventResult>,
) {
let mut exit = false;
let mut repaint_window_id: Option<WindowId> = None;

log::trace!("event_result: {event_result:?}");

Expand All @@ -92,18 +93,23 @@ impl<T: WinitApp> WinitAppWrapper<T> {

if cfg!(target_os = "windows") {
// Fix flickering on Windows, see https://github.com/emilk/egui/pull/2280
self.winit_app.run_ui_and_paint(event_loop, window_id)
let event_result = self.winit_app.run_ui_and_paint(event_loop, window_id);
if let Ok(result) = event_result {
if result == EventResult::Wait {
event_loop.set_control_flow(ControlFlow::Wait);
} else {
repaint_window_id = Some(window_id);
}
}
event_result
} else {
// Fix for https://github.com/emilk/egui/issues/2425
self.windows_next_repaint_times
.insert(window_id, Instant::now());
repaint_window_id = Some(window_id);
Ok(event_result)
}
}
EventResult::RepaintNext(window_id) => {
log::trace!("RepaintNext of {window_id:?}",);
self.windows_next_repaint_times
.insert(window_id, Instant::now());
repaint_window_id = Some(window_id);
Ok(event_result)
}
EventResult::RepaintAt(window_id, repaint_time) => {
Expand Down Expand Up @@ -143,12 +149,17 @@ impl<T: WinitApp> WinitAppWrapper<T> {
}
}

self.check_redraw_requests(event_loop);
}

fn check_redraw_requests(&mut self, event_loop: &ActiveEventLoop) {
let now = Instant::now();
if let Some(window_id) = repaint_window_id {
self.windows_next_repaint_times.insert(window_id, now);
self.windows_next_repaint_times
.insert(window_id, now + std::time::Duration::from_millis(1));
}

self.check_redraw_requests(event_loop, now);
}

fn check_redraw_requests(&mut self, event_loop: &ActiveEventLoop, now: Instant) {
self.windows_next_repaint_times
.retain(|window_id, repaint_time| {
if now < *repaint_time {
Expand Down Expand Up @@ -260,7 +271,7 @@ impl<T: WinitApp> ApplicationHandler<UserEvent> for WinitAppWrapper<T> {
log::trace!("Woke up to check next_repaint_time");
}

self.check_redraw_requests(event_loop);
self.check_redraw_requests(event_loop, Instant::now());
}

fn window_event(
Expand Down
Loading