egui_glium: prevent cursor icon flickering at frame boundary on Windows (#217) (#218)

* egui_glium: prevent cursor icon flickering at frame boundary (Windows)

* fix compiler warning

* cargo fmt
This commit is contained in:
Norbert Nemec 2021-03-13 12:27:05 +01:00 committed by GitHub
parent 269bcdfce3
commit ee1fcf1ead
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 12 deletions

View file

@ -173,6 +173,7 @@ pub fn run(mut app: Box<dyn epi::App>) -> ! {
let mut previous_frame_time = None;
let mut painter = Painter::new(&display);
let mut clipboard = init_clipboard();
let mut previous_cursor_icon = None;
#[cfg(feature = "persistence")]
let mut last_auto_save = Instant::now();
@ -208,7 +209,15 @@ pub fn run(mut app: Box<dyn epi::App>) -> ! {
ctx.clear_animations();
let (egui_output, _shapes) = ctx.end_frame();
handle_output(egui_output, &display, clipboard.as_mut());
let new_cursor_icon = egui_output.cursor_icon;
handle_output(egui_output, clipboard.as_mut());
display
.gl_window()
.window()
.set_cursor_icon(translate_cursor(new_cursor_icon));
previous_cursor_icon = Some(new_cursor_icon);
// TODO: handle app_output
// eprintln!("Warmed up in {} ms", warm_up_start.elapsed().as_millis())
}
@ -276,7 +285,18 @@ pub fn run(mut app: Box<dyn epi::App>) -> ! {
}
screen_reader.speak(&egui_output.events_description());
handle_output(egui_output, &display, clipboard.as_mut());
let new_cursor_icon = egui_output.cursor_icon;
handle_output(egui_output, clipboard.as_mut());
if Some(new_cursor_icon) != previous_cursor_icon {
// call only when changed to prevent flickering near frame boundary
// when Windows OS tries to control cursor icon for window resizing
display
.gl_window()
.window()
.set_cursor_icon(translate_cursor(new_cursor_icon));
previous_cursor_icon = Some(new_cursor_icon);
}
#[cfg(feature = "persistence")]
if let Some(storage) = &mut storage {

View file

@ -277,11 +277,7 @@ pub fn translate_cursor(cursor_icon: egui::CursorIcon) -> glutin::window::Cursor
}
}
pub fn handle_output(
output: egui::Output,
display: &glium::backend::glutin::Display,
clipboard: Option<&mut ClipboardContext>,
) {
pub fn handle_output(output: egui::Output, clipboard: Option<&mut ClipboardContext>) {
if let Some(open) = output.open_url {
if let Err(err) = webbrowser::open(&open.url) {
eprintln!("Failed to open url: {}", err);
@ -295,11 +291,6 @@ pub fn handle_output(
}
}
}
display
.gl_window()
.window()
.set_cursor_icon(translate_cursor(output.cursor_icon));
}
pub fn init_clipboard() -> Option<ClipboardContext> {