diff options
author | Kirill Chibisov <contact@kchibisov.com> | 2023-07-20 17:40:16 +0400 |
---|---|---|
committer | Kirill Chibisov <contact@kchibisov.com> | 2023-09-04 03:01:12 +0400 |
commit | 8d174429ee1e63e865a9203d7dfc4ce2cd25576d (patch) | |
tree | 5c3d7d80875bd316144a81a4cc638fc89ebb53a2 | |
parent | bfcebbcd38d7bbf2aa4cce2e446fdb781bc0c4f0 (diff) | |
download | alacritty-8d174429ee1e63e865a9203d7dfc4ce2cd25576d.tar.gz alacritty-8d174429ee1e63e865a9203d7dfc4ce2cd25576d.zip |
Support startup notify on Wayland/X11
Activate a window to indicate that we want initial focus when the
system uses startup notifications.
Fixes #6931.
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | alacritty/src/display/window.rs | 16 | ||||
-rw-r--r-- | extra/linux/Alacritty.desktop | 1 |
3 files changed, 18 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 85dd5f0b..776a7358 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - `Back`/`Forward` mouse buttons support in bindings - Copy global IPC options (`-w -1`) for new windows - Bindings to create and navigate tabs on macOS +- Support startup notify protocol to raise initial window on Wayland/X11 ### Changed diff --git a/alacritty/src/display/window.rs b/alacritty/src/display/window.rs index c7ad37c8..aef6e1b5 100644 --- a/alacritty/src/display/window.rs +++ b/alacritty/src/display/window.rs @@ -1,3 +1,8 @@ +#[cfg(not(any(target_os = "macos", windows)))] +use winit::platform::startup_notify::{ + self, EventLoopExtStartupNotify, WindowBuilderExtStartupNotify, +}; + #[cfg(all(not(feature = "x11"), not(any(target_os = "macos", windows))))] use winit::platform::wayland::WindowBuilderExtWayland; @@ -143,6 +148,17 @@ impl Window { .with_position(PhysicalPosition::<i32>::from((position.x, position.y))); } + #[cfg(not(any(target_os = "macos", windows)))] + if let Some(token) = event_loop.read_token_from_env() { + log::debug!("Activating window with token: {token:?}"); + window_builder = window_builder.with_activation_token(token); + + // Remove the token from the env. + unsafe { + startup_notify::reset_activation_token_env(); + } + } + let window = window_builder .with_title(&identity.title) .with_theme(config.window.decorations_theme_variant) diff --git a/extra/linux/Alacritty.desktop b/extra/linux/Alacritty.desktop index 0872a764..a99ef733 100644 --- a/extra/linux/Alacritty.desktop +++ b/extra/linux/Alacritty.desktop @@ -9,6 +9,7 @@ Categories=System;TerminalEmulator; Name=Alacritty GenericName=Terminal Comment=A fast, cross-platform, OpenGL terminal emulator +StartupNotify=true StartupWMClass=Alacritty Actions=New; |