1
0
mirror of https://github.com/emilk/egui.git synced 2026-06-26 22:53:14 -04:00

Merge branch 'lucas/malmal/suspended-resumed' into lucas/malmal/main

This commit is contained in:
lucasmerlin
2026-02-20 23:58:38 +01:00
3 changed files with 50 additions and 1 deletions

View File

@@ -423,13 +423,32 @@ impl WinitApp for GlowWinitApp<'_> {
// First resume event. Create our root window etc.
self.init_run_state(event_loop)?
};
{
let mut glutin = running.glutin.borrow_mut();
if let Some(viewport) = glutin.viewports.get_mut(&ViewportId::ROOT) {
if let Some(egui_winit) = viewport.egui_winit.as_mut() {
egui_winit.egui_input_mut().events.push(egui::Event::Resumed);
}
}
}
let window_id = running.glutin.borrow().window_from_viewport[&ViewportId::ROOT];
Ok(EventResult::RepaintNow(window_id))
}
fn suspended(&mut self, _: &ActiveEventLoop) -> crate::Result<EventResult> {
if let Some(running) = &mut self.running {
running.glutin.borrow_mut().on_suspend()?;
let mut glutin = running.glutin.borrow_mut();
if let Some(viewport) = glutin.viewports.get_mut(&ViewportId::ROOT) {
if let Some(egui_winit) = viewport.egui_winit.as_mut() {
egui_winit
.egui_input_mut()
.events
.push(egui::Event::Suspended);
}
}
glutin.on_suspend()?;
}
Ok(EventResult::Save)
}

View File

@@ -427,6 +427,15 @@ impl WinitApp for WgpuWinitApp<'_> {
self.init_run_state(egui_ctx, event_loop, storage, window, builder)?
};
{
let mut shared = running.shared.borrow_mut();
if let Some(viewport) = shared.viewports.get_mut(&ViewportId::ROOT) {
if let Some(egui_winit) = viewport.egui_winit.as_mut() {
egui_winit.egui_input_mut().events.push(egui::Event::Resumed);
}
}
}
let viewport = &running.shared.borrow().viewports[&ViewportId::ROOT];
if let Some(window) = &viewport.window {
Ok(EventResult::RepaintNow(window.id()))
@@ -436,6 +445,17 @@ impl WinitApp for WgpuWinitApp<'_> {
}
fn suspended(&mut self, _: &ActiveEventLoop) -> crate::Result<EventResult> {
if let Some(running) = &self.running {
let mut shared = running.shared.borrow_mut();
if let Some(viewport) = shared.viewports.get_mut(&ViewportId::ROOT) {
if let Some(egui_winit) = viewport.egui_winit.as_mut() {
egui_winit
.egui_input_mut()
.events
.push(egui::Event::Suspended);
}
}
}
#[cfg(target_os = "android")]
self.drop_window()?;
Ok(EventResult::Save)

View File

@@ -547,6 +547,16 @@ pub enum Event {
/// The native window gained or lost focused (e.g. the user clicked alt-tab).
WindowFocused(bool),
/// The application was suspended.
///
/// On iOS/Android, this is sent when the app is moved to the background.
Suspended,
/// The application was resumed.
///
/// On iOS/Android, this is sent when the app is brought back to the foreground.
Resumed,
/// An assistive technology (e.g. screen reader) requested an action.
AccessKitActionRequest(accesskit::ActionRequest),