Skip to content

Commit 7bc05fd

Browse files
committed
Fix continuous RunMode in glium backend on Windows
1 parent c25d4ff commit 7bc05fd

File tree

1 file changed

+35
-24
lines changed

1 file changed

+35
-24
lines changed

egui_glium/src/backend.rs

+35-24
Original file line numberDiff line numberDiff line change
@@ -102,33 +102,44 @@ pub fn run(
102102
let mut clipboard = init_clipboard();
103103

104104
event_loop.run(move |event, _, control_flow| {
105-
*control_flow = glutin::event_loop::ControlFlow::Wait;
106-
107-
match event {
108-
glutin::event::Event::RedrawRequested(_) => {
109-
let egui_start = Instant::now();
110-
raw_input.time = start_time.elapsed().as_nanos() as f64 * 1e-9;
111-
raw_input.seconds_since_midnight = Some(local_time_of_day());
112-
113-
let mut ui = ctx.begin_frame(raw_input.take());
114-
app.ui(&mut ui, &mut runner);
115-
let (output, paint_jobs) = ctx.end_frame();
116-
117-
let frame_time = (Instant::now() - egui_start).as_secs_f64() as f32;
118-
runner.frame_times.add(raw_input.time, frame_time);
119-
120-
runner
121-
.painter
122-
.paint_jobs(&display, paint_jobs, &ctx.texture());
123-
124-
if runner.quit {
125-
*control_flow = glutin::event_loop::ControlFlow::Exit
126-
} else if runner.run_mode() == RunMode::Continuous || output.needs_repaint {
105+
let mut redraw = || {
106+
let egui_start = Instant::now();
107+
raw_input.time = start_time.elapsed().as_nanos() as f64 * 1e-9;
108+
raw_input.seconds_since_midnight = Some(local_time_of_day());
109+
110+
let mut ui = ctx.begin_frame(raw_input.take());
111+
app.ui(&mut ui, &mut runner);
112+
let (output, paint_jobs) = ctx.end_frame();
113+
114+
let frame_time = (Instant::now() - egui_start).as_secs_f64() as f32;
115+
runner.frame_times.add(raw_input.time, frame_time);
116+
117+
runner
118+
.painter
119+
.paint_jobs(&display, paint_jobs, &ctx.texture());
120+
121+
*control_flow = if runner.quit {
122+
glutin::event_loop::ControlFlow::Exit
123+
} else if runner.run_mode() == RunMode::Continuous {
124+
display.gl_window().window().request_redraw();
125+
glutin::event_loop::ControlFlow::Poll
126+
} else {
127+
if output.needs_repaint {
127128
display.gl_window().window().request_redraw();
128129
}
130+
glutin::event_loop::ControlFlow::Wait
131+
};
132+
133+
handle_output(output, &display, clipboard.as_mut());
134+
};
135+
136+
match event {
137+
// Platform-dependent event handlers to workaround a winit bug
138+
// See: https://github.com/rust-windowing/winit/issues/987
139+
// See: https://github.com/rust-windowing/winit/issues/1619
140+
glutin::event::Event::RedrawEventsCleared if cfg!(windows) => redraw(),
141+
glutin::event::Event::RedrawRequested(_) if !cfg!(windows) => redraw(),
129142

130-
handle_output(output, &display, clipboard.as_mut());
131-
}
132143
glutin::event::Event::WindowEvent { event, .. } => {
133144
input_to_egui(event, clipboard.as_mut(), &mut raw_input, control_flow);
134145
display.gl_window().window().request_redraw(); // TODO: maybe only on some events?

0 commit comments

Comments
 (0)