From 9c3482083bf8e15aefb7bab38c0c4649d64c27c5 Mon Sep 17 00:00:00 2001 From: Mike Qin Date: Thu, 30 Jan 2025 19:47:16 -0500 Subject: [PATCH] Map window after set_app_id() under X11 (#23046) GPUI applications can set the window class by the `app_id` window option. However, GPUI will map the window first and then change the window class after the window is displayed. This doesn't work on some X11 window managers. FVWM, for example, does not track window class after a window is mapped. Because in practice, a window shouldn't change its application group on the fly. This PR fixed this by adding a `map_window()` function `PlatformWindow`. On X11, it will `set_app_id()` first and then map the window. Release Notes: - N/A --- crates/gpui/src/platform.rs | 3 +++ crates/gpui/src/platform/linux/x11/window.rs | 9 ++++++++- crates/gpui/src/window.rs | 2 ++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/crates/gpui/src/platform.rs b/crates/gpui/src/platform.rs index ac397dddcc..104ec71b8d 100644 --- a/crates/gpui/src/platform.rs +++ b/crates/gpui/src/platform.rs @@ -432,6 +432,9 @@ pub(crate) trait PlatformWindow: HasWindowHandle + HasDisplayHandle { Decorations::Server } fn set_app_id(&mut self, _app_id: &str) {} + fn map_window(&mut self) -> anyhow::Result<()> { + Ok(()) + } fn window_controls(&self) -> WindowControls { WindowControls::default() } diff --git a/crates/gpui/src/platform/linux/x11/window.rs b/crates/gpui/src/platform/linux/x11/window.rs index 4ecc1aa2e2..935de8b1d8 100644 --- a/crates/gpui/src/platform/linux/x11/window.rs +++ b/crates/gpui/src/platform/linux/x11/window.rs @@ -590,7 +590,6 @@ impl X11WindowState { BladeRenderer::new(gpu_context, &raw_window, config)? }; - check_reply(|| "X11 MapWindow failed.", xcb.map_window(x_window))?; let display = Rc::new(X11Display::new(xcb, scale_factor, x_screen_index)?); Ok(Self { @@ -1278,6 +1277,14 @@ impl PlatformWindow for X11Window { .unwrap(); } + fn map_window(&mut self) -> anyhow::Result<()> { + check_reply( + || "X11 MapWindow failed.", + self.0.xcb.map_window(self.0.x_window), + )?; + Ok(()) + } + fn set_edited(&mut self, _edited: bool) { log::info!("ignoring macOS specific set_edited"); } diff --git a/crates/gpui/src/window.rs b/crates/gpui/src/window.rs index 3cb84102a7..543f680d98 100644 --- a/crates/gpui/src/window.rs +++ b/crates/gpui/src/window.rs @@ -878,6 +878,8 @@ impl Window { platform_window.set_app_id(&app_id); } + platform_window.map_window().unwrap(); + Ok(Window { handle, invalidator,