Skip to main content

egui_pop_platform/
window.rs

1//! The main window brought to the front, as the platform services do
2//! when a second launch, a tray click or a notification asks for the
3//! application. In an application it is the bus's `pop.window.activate` of
4//! the main window ([`raise_app`]): the registry holds it as the active
5//! window and its `pop.window.raise` listener brings it forward.
6//!
7//! <div class="warning">Experimental: may change in any release
8//! (docs/stability.md).</div>
9
10use egui::Context;
11use egui_pop_api::AppHandle;
12use egui_pop_api::bus::{Reason, WindowKind, WindowRequest};
13use egui_pop_api::windows::WindowId;
14
15/// Who asks the main window to the front: the platform services.
16pub const OWNER: &str = "egui_pop.platform";
17
18/// Asks the application's main window to the front: its
19/// `pop.window.activate` with the reason `command`, owned by [`OWNER`]. The
20/// window is shown, restored when minimized and asked for the focus. On
21/// Wayland a window cannot take the focus by itself (the compositor needs
22/// an activation token, which egui does not pass on): the window asks
23/// for attention instead, and the desktop says so.
24pub fn raise_app(app: &AppHandle) {
25    app.request_window_activate(WindowRequest::new(
26        WindowId::MAIN,
27        WindowKind::Main,
28        OWNER,
29        Reason::Command,
30    ));
31}
32
33/// The same for a program without an egui-pop application (the platform
34/// readers used standalone): the main window shown, restored and asked
35/// for the focus, attention asked on Wayland. An application uses
36/// [`raise_app`], so the bus knows the active window.
37pub fn raise(ctx: &Context) {
38    egui_pop_api::bus::raise_main_window(ctx);
39}
40
41/// Whether the session is a Wayland one.
42pub fn wayland() -> bool {
43    cfg!(all(unix, not(target_os = "macos")))
44        && (std::env::var_os("WAYLAND_DISPLAY").is_some()
45            || std::env::var("XDG_SESSION_TYPE").is_ok_and(|t| t == "wayland"))
46}