aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKirill Chibisov <contact@kchibisov.com>2025-01-04 09:34:44 +0300
committerKirill Chibisov <contact@kchibisov.com>2025-01-04 12:16:42 +0300
commite79f4b22d809d12b5f09543872443d0fa818fee2 (patch)
treece41efeedf0fdef4e224582f2c383775f6024a39
parent8cb359ad024736bba5456999a67f2a426529dcc7 (diff)
downloadalacritty-e79f4b22d809d12b5f09543872443d0fa818fee2.tar.gz
alacritty-e79f4b22d809d12b5f09543872443d0fa818fee2.zip
Pass activation token in alacritty msg create-window
Fixes #8337.
-rw-r--r--CHANGELOG.md1
-rw-r--r--alacritty/src/cli.rs5
-rw-r--r--alacritty/src/display/window.rs16
-rw-r--r--alacritty/src/main.rs10
-rw-r--r--alacritty/src/window_context.rs12
5 files changed, 31 insertions, 13 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f23f442f..882c7c1c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,6 +14,7 @@ Notable changes to the `alacritty_terminal` crate are documented in its
- Config option `window.level = "AlwaysOnTop"` to force Alacritty to always be the toplevel window
- Escape sequence to move cursor forward tabs ( CSI Ps I )
+- Pass activation token in `alacritty msg create-window` on Wayland/X11
### Changed
diff --git a/alacritty/src/cli.rs b/alacritty/src/cli.rs
index bb0a24f4..5010ffc8 100644
--- a/alacritty/src/cli.rs
+++ b/alacritty/src/cli.rs
@@ -300,6 +300,11 @@ pub struct WindowOptions {
/// The window tabbing identifier to use when building a window.
pub window_tabbing_id: Option<String>,
+ #[clap(skip)]
+ #[cfg(not(any(target_os = "macos", windows)))]
+ /// `ActivationToken` that we pass to winit.
+ pub activation_token: Option<String>,
+
/// Override configuration file options [example: 'cursor.style="Beam"'].
#[clap(short = 'o', long, num_args = 1..)]
option: Vec<String>,
diff --git a/alacritty/src/display/window.rs b/alacritty/src/display/window.rs
index 1c8089bc..fe40fab5 100644
--- a/alacritty/src/display/window.rs
+++ b/alacritty/src/display/window.rs
@@ -2,6 +2,8 @@
use winit::platform::startup_notify::{
self, EventLoopExtStartupNotify, WindowAttributesExtStartupNotify,
};
+#[cfg(not(any(target_os = "macos", windows)))]
+use winit::window::ActivationToken;
#[cfg(all(not(feature = "x11"), not(any(target_os = "macos", windows))))]
use winit::platform::wayland::WindowAttributesExtWayland;
@@ -38,6 +40,7 @@ use winit::window::{
use alacritty_terminal::index::Point;
+use crate::cli::WindowOptions;
use crate::config::window::{Decorations, Identity, WindowConfig};
use crate::config::UiConfig;
use crate::display::SizeInfo;
@@ -124,9 +127,7 @@ impl Window {
event_loop: &ActiveEventLoop,
config: &UiConfig,
identity: &Identity,
- #[rustfmt::skip]
- #[cfg(target_os = "macos")]
- tabbing_id: &Option<String>,
+ _options: &mut WindowOptions,
#[rustfmt::skip]
#[cfg(all(feature = "x11", not(any(target_os = "macos", windows))))]
x11_visual: Option<X11VisualInfo>,
@@ -138,7 +139,7 @@ impl Window {
#[cfg(all(feature = "x11", not(any(target_os = "macos", windows))))]
x11_visual,
#[cfg(target_os = "macos")]
- tabbing_id,
+ &_options.window_tabbing_id.take(),
);
if let Some(position) = config.window.position {
@@ -147,7 +148,12 @@ impl Window {
}
#[cfg(not(any(target_os = "macos", windows)))]
- if let Some(token) = event_loop.read_token_from_env() {
+ if let Some(token) = _options
+ .activation_token
+ .take()
+ .map(ActivationToken::from_raw)
+ .or_else(|| event_loop.read_token_from_env())
+ {
log::debug!("Activating window with token: {token:?}");
window_attributes = window_attributes.with_activation_token(token);
diff --git a/alacritty/src/main.rs b/alacritty/src/main.rs
index 6bbf8dfd..5382e475 100644
--- a/alacritty/src/main.rs
+++ b/alacritty/src/main.rs
@@ -55,6 +55,8 @@ mod gl {
#[cfg(unix)]
use crate::cli::MessageOptions;
+#[cfg(not(any(target_os = "macos", windows)))]
+use crate::cli::SocketMessage;
use crate::cli::{Options, Subcommands};
use crate::config::monitor::ConfigMonitor;
use crate::config::UiConfig;
@@ -89,7 +91,13 @@ fn main() -> Result<(), Box<dyn Error>> {
/// `msg` subcommand entrypoint.
#[cfg(unix)]
-fn msg(options: MessageOptions) -> Result<(), Box<dyn Error>> {
+#[allow(unused_mut)]
+fn msg(mut options: MessageOptions) -> Result<(), Box<dyn Error>> {
+ #[cfg(not(any(target_os = "macos", windows)))]
+ if let SocketMessage::CreateWindow(window_options) = &mut options.message {
+ window_options.activation_token =
+ env::var("XDG_ACTIVATION_TOKEN").or_else(|_| env::var("DESKTOP_STARTUP_ID")).ok();
+ }
ipc::send_message(options.socket, options.message).map_err(|err| err.into())
}
diff --git a/alacritty/src/window_context.rs b/alacritty/src/window_context.rs
index cfc3cd96..e3c39382 100644
--- a/alacritty/src/window_context.rs
+++ b/alacritty/src/window_context.rs
@@ -73,7 +73,7 @@ impl WindowContext {
event_loop: &ActiveEventLoop,
proxy: EventLoopProxy<Event>,
config: Rc<UiConfig>,
- options: WindowOptions,
+ mut options: WindowOptions,
) -> Result<Self, Box<dyn Error>> {
let raw_display_handle = event_loop.display_handle().unwrap().as_raw();
@@ -83,7 +83,7 @@ impl WindowContext {
// Windows has different order of GL platform initialization compared to any other platform;
// it requires the window first.
#[cfg(windows)]
- let window = Window::new(event_loop, &config, &identity)?;
+ let window = Window::new(event_loop, &config, &identity, &mut options)?;
#[cfg(windows)]
let raw_window_handle = Some(window.raw_window_handle());
@@ -102,10 +102,9 @@ impl WindowContext {
event_loop,
&config,
&identity,
+ &mut options,
#[cfg(all(feature = "x11", not(any(target_os = "macos", windows))))]
gl_config.x11_visual(),
- #[cfg(target_os = "macos")]
- &options.window_tabbing_id,
)?;
// Create context.
@@ -123,7 +122,7 @@ impl WindowContext {
event_loop: &ActiveEventLoop,
proxy: EventLoopProxy<Event>,
config: Rc<UiConfig>,
- options: WindowOptions,
+ mut options: WindowOptions,
config_overrides: ParsedOptions,
) -> Result<Self, Box<dyn Error>> {
let gl_display = gl_config.display();
@@ -135,10 +134,9 @@ impl WindowContext {
event_loop,
&config,
&identity,
+ &mut options,
#[cfg(all(feature = "x11", not(any(target_os = "macos", windows))))]
gl_config.x11_visual(),
- #[cfg(target_os = "macos")]
- &options.window_tabbing_id,
)?;
// Create context.