use winit::window::Window;
#[cfg(all(unix, not(target_os = "macos")))]
mod wayland;
pub fn raise(window: &Window, token: Option<&str>) {
#[cfg(all(unix, not(target_os = "macos")))]
if crate::active_window_system() == crate::WindowSystem::Wayland {
match token {
Some(token) => wayland::activate_with_token(window, token),
None => request_attention(window),
}
return;
}
let _ = token;
window.focus_window();
}
pub fn apply_creation_token(
attrs: winit::window::WindowAttributes,
event_loop: &winit::event_loop::ActiveEventLoop,
) -> winit::window::WindowAttributes {
#[cfg(all(unix, not(target_os = "macos")))]
{
use winit::platform::startup_notify::{
EventLoopExtStartupNotify, WindowAttributesExtStartupNotify, reset_activation_token_env,
};
if let Some(token) = event_loop.read_token_from_env() {
reset_activation_token_env();
return attrs.with_activation_token(token);
}
}
let _ = event_loop;
attrs
}
pub fn request_activation_token(window: &Window) -> bool {
#[cfg(all(unix, not(target_os = "macos")))]
{
use winit::platform::startup_notify::WindowExtStartupNotify;
window.request_activation_token().is_ok()
}
#[cfg(not(all(unix, not(target_os = "macos"))))]
{
let _ = window;
false
}
}
pub fn set_child_activation_env(cmd: &mut std::process::Command, token: &str) {
#[cfg(all(unix, not(target_os = "macos")))]
{
cmd.env("XDG_ACTIVATION_TOKEN", token);
cmd.env("DESKTOP_STARTUP_ID", token);
}
#[cfg(not(all(unix, not(target_os = "macos"))))]
{
let _ = (cmd, token);
}
}
#[cfg(all(unix, not(target_os = "macos")))]
fn request_attention(window: &Window) {
window.request_user_attention(Some(winit::window::UserAttentionType::Informational));
}