mirror of
https://github.com/emilk/egui.git
synced 2026-08-30 05:10: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:
@@ -802,6 +802,20 @@ impl Frame {
|
||||
self.output.focus = Some(true);
|
||||
}
|
||||
|
||||
/// If the window is unfocused, attract the user's attention (native only).
|
||||
///
|
||||
/// Typically, this means that the window will flash on the taskbar, or bounce, until it is interacted with.
|
||||
///
|
||||
/// When the window comes into focus, or if `None` is passed, the attention request will be automatically reset.
|
||||
///
|
||||
/// See [winit's documentation][user_attention_details] for platform-specific effect details.
|
||||
///
|
||||
/// [user_attention_details]: https://docs.rs/winit/latest/winit/window/enum.UserAttentionType.html
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub fn request_user_attention(&mut self, kind: egui::UserAttentionType) {
|
||||
self.output.attention = Some(kind);
|
||||
}
|
||||
|
||||
/// Maximize or unmaximize window. (native only)
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub fn set_maximized(&mut self, maximized: bool) {
|
||||
@@ -1126,6 +1140,10 @@ pub(crate) mod backend {
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub focus: Option<bool>,
|
||||
|
||||
/// Set to request a user's attention to the native window.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub attention: Option<egui::UserAttentionType>,
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub screenshot_requested: bool,
|
||||
}
|
||||
|
||||
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user