1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-29 21:00:03 -04:00

Allow for requesting the user's attention to the window (#2905)

* add method for requesting attention to the main window

* use another enum member for user attention type instead of nested `Option`s

(also, document the enum members now that they don't mirror `winit`)

* update the docstring

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>

* add an example app for testing window attention requests

* Apply suggestions from code review

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>

* remove `chrono` dependency and improve the attention example's readability

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
This commit is contained in:
TicClick
2023-04-19 15:29:17 +02:00
committed by GitHub
parent d1af798a9b
commit e3a021eea6
9 changed files with 206 additions and 3 deletions

View File

@@ -235,6 +235,7 @@ pub fn handle_app_output(
minimized,
maximized,
focus,
attention,
} = app_output;
if let Some(decorated) = decorated {
@@ -289,8 +290,17 @@ pub fn handle_app_output(
window_state.maximized = maximized;
}
if focus == Some(true) {
window.focus_window();
if !window.has_focus() {
if focus == Some(true) {
window.focus_window();
} else if let Some(attention) = attention {
use winit::window::UserAttentionType;
window.request_user_attention(match attention {
egui::UserAttentionType::Reset => None,
egui::UserAttentionType::Critical => Some(UserAttentionType::Critical),
egui::UserAttentionType::Informational => Some(UserAttentionType::Informational),
});
}
}
}
@@ -487,6 +497,9 @@ impl EpiIntegration {
}
self.frame.output.visible = app_output.visible; // this is handled by post_present
self.frame.output.screenshot_requested = app_output.screenshot_requested;
if self.frame.output.attention.is_some() {
self.frame.output.attention = None;
}
handle_app_output(
window,
self.egui_ctx.pixels_per_point(),