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 ac397dddcc3f300b89d2dd308b55e478804c0e17..104ec71b8d4160077043315d3cd0df4e7d45f87b 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 4ecc1aa2e2fb95c029adb0e9e10d279e827afad5..935de8b1d8b6afdd6f24275fdae4219420ad5875 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 3cb84102a707af00a6b564468e9f9bfd5d3d79d6..543f680d989befc83a75ace8d115285cb041da8e 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,