BlueGit

ict rusty-teams

fix(notify): no black toast corners without window transparency

- platform::window_transparency_available: Windows false only with GPUI_DISABLE_DIRECT_COMPOSITION, X11 checks the _NET_WM_CM_S<n> compositor owner (cached), Wayland/other true
- toast, Hide all pill, incoming call and meeting reminder cards use toast_radius(window): 12px when transparent, square otherwise
- tests: popup options request a transparent background, card radius 0 without transparency, compositor detection on Xvfb

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

metis Daniel Däschle · pushed by metis

Authored 2026-10-17 · 6 weeks ago

Hash
ae3630219eab3696d760eca5fef95de60d7c2dc4
Parent
9af36794
7 files changed +105 −9
crates/app-base/src/notify/platform/stub.rs +10 −0
@@ -39,6 +39,16 @@ pub fn make_window_click_through(window: &Window) {
39 39 super::x11_input::make_input_transparent(window);
40 40 }
41 41
42 #[cfg(target_os = "linux")]
43 pub fn window_transparency_available(window: &Window) -> bool {
44 super::x11_input::window_transparency_available(window)
45 }
46
47 #[cfg(not(target_os = "linux"))]
48 pub fn window_transparency_available(_window: &Window) -> bool {
49 true
50 }
51
42 52 #[cfg(not(target_os = "linux"))]
43 53 pub fn make_window_click_through(_window: &Window) {}
44 54
@@ -39,6 +39,16 @@ pub fn make_window_click_through(window: &Window) {
39 super::x11_input::make_input_transparent(window);
39 super::x11_input::make_input_transparent(window);
40}
40}
41
41
42#[cfg(target_os = "linux")]
43pub fn window_transparency_available(window: &Window) -> bool {
44 super::x11_input::window_transparency_available(window)
45}
46
47#[cfg(not(target_os = "linux"))]
48pub fn window_transparency_available(_window: &Window) -> bool {
49 true
50}
51
42#[cfg(not(target_os = "linux"))]
52#[cfg(not(target_os = "linux"))]
43pub fn make_window_click_through(_window: &Window) {}
53pub fn make_window_click_through(_window: &Window) {}
44
54
crates/app-base/src/notify/platform/windows_impl.rs +6 −0
@@ -62,6 +62,12 @@ pub fn native_handle(window: &Window) -> Option<NativeHandle> {
62 62 }
63 63 }
64 64
65 pub fn window_transparency_available(_window: &Window) -> bool {
66 // GPUI then renders into an opaque hwnd swap chain without alpha.
67 !std::env::var("GPUI_DISABLE_DIRECT_COMPOSITION")
68 .is_ok_and(|value| value == "true" || value == "1")
69 }
70
65 71 pub fn prepare_toast_window(handle: NativeHandle) {
66 72 unsafe {
67 73 // GPUI creates popups with style 0, and Windows adds a caption frame to that on its own.
@@ -62,6 +62,12 @@ pub fn native_handle(window: &Window) -> Option<NativeHandle> {
62 }
62 }
63}
63}
64
64
65pub fn window_transparency_available(_window: &Window) -> bool {
66 // GPUI then renders into an opaque hwnd swap chain without alpha.
67 !std::env::var("GPUI_DISABLE_DIRECT_COMPOSITION")
68 .is_ok_and(|value| value == "true" || value == "1")
69}
70
65pub fn prepare_toast_window(handle: NativeHandle) {
71pub fn prepare_toast_window(handle: NativeHandle) {
66 unsafe {
72 unsafe {
67 // GPUI creates popups with style 0, and Windows adds a caption frame to that on its own.
73 // GPUI creates popups with style 0, and Windows adds a caption frame to that on its own.
crates/app-base/src/notify/platform/x11_input.rs +38 −0
@@ -1,3 +1,5 @@
1 use std::sync::OnceLock;
2
1 3 use gpui_kit::Window;
2 4 use raw_window_handle::{HasWindowHandle, RawWindowHandle};
3 5 use x11rb::connection::Connection as _;
@@ -30,6 +32,24 @@ pub fn make_input_transparent(window: &Window) {
30 32 }
31 33 }
32 34
35 pub fn compositor_running(display: Option<&str>) -> Result<bool, Box<dyn std::error::Error>> {
36 let (connection, screen_number) = RustConnection::connect(display)?;
37 let selection = format!("_NET_WM_CM_S{screen_number}");
38 let atom = connection.intern_atom(false, selection.as_bytes())?.reply()?.atom;
39 let owner = connection.get_selection_owner(atom)?.reply()?.owner;
40 Ok(owner != x11rb::NONE)
41 }
42
43 pub fn window_transparency_available(window: &Window) -> bool {
44 static COMPOSITED: OnceLock<bool> = OnceLock::new();
45 match HasWindowHandle::window_handle(window).map(|handle| handle.as_raw()) {
46 Ok(RawWindowHandle::Xcb(_) | RawWindowHandle::Xlib(_)) => {
47 *COMPOSITED.get_or_init(|| compositor_running(None).unwrap_or(false))
48 }
49 _ => true,
50 }
51 }
52
33 53 pub fn window_icon_property(png: &[u8]) -> Option<Vec<u32>> {
34 54 let decoded = image::load_from_memory(png).ok()?;
35 55 let mut property = Vec::new();
@@ -131,6 +151,24 @@ mod tests {
131 151 assert!(after.rectangles.is_empty());
132 152 }
133 153
154 #[test]
155 fn transparency_needs_a_compositor_owning_the_cm_selection() {
156 let Some((_server, display)) = start_server() else {
157 return;
158 };
159 assert!(!compositor_running(Some(&display)).unwrap());
160 let (connection, screen_number) = RustConnection::connect(Some(&display)).unwrap();
161 let root = connection.setup().roots[screen_number].root;
162 let window = connection.generate_id().unwrap();
163 connection
164 .create_window(COPY_DEPTH_FROM_PARENT, window, root, 0, 0, 1, 1, 0, WindowClass::INPUT_OUTPUT, 0, &CreateWindowAux::new())
165 .unwrap();
166 let selection = format!("_NET_WM_CM_S{screen_number}");
167 let atom = connection.intern_atom(false, selection.as_bytes()).unwrap().reply().unwrap().atom;
168 connection.set_selection_owner(window, atom, x11rb::CURRENT_TIME).unwrap().check().unwrap();
169 assert!(compositor_running(Some(&display)).unwrap());
170 }
171
134 172 #[test]
135 173 fn the_window_icon_property_holds_every_size_in_argb() {
136 174 let png = crate::appearance::AppIcon::MicrosoftTeams.png();
@@ -1,3 +1,5 @@
1use std::sync::OnceLock;
2
1use gpui_kit::Window;
3use gpui_kit::Window;
2use raw_window_handle::{HasWindowHandle, RawWindowHandle};
4use raw_window_handle::{HasWindowHandle, RawWindowHandle};
3use x11rb::connection::Connection as _;
5use x11rb::connection::Connection as _;
@@ -30,6 +32,24 @@ pub fn make_input_transparent(window: &Window) {
30 }
32 }
31}
33}
32
34
35pub fn compositor_running(display: Option<&str>) -> Result<bool, Box<dyn std::error::Error>> {
36 let (connection, screen_number) = RustConnection::connect(display)?;
37 let selection = format!("_NET_WM_CM_S{screen_number}");
38 let atom = connection.intern_atom(false, selection.as_bytes())?.reply()?.atom;
39 let owner = connection.get_selection_owner(atom)?.reply()?.owner;
40 Ok(owner != x11rb::NONE)
41}
42
43pub fn window_transparency_available(window: &Window) -> bool {
44 static COMPOSITED: OnceLock<bool> = OnceLock::new();
45 match HasWindowHandle::window_handle(window).map(|handle| handle.as_raw()) {
46 Ok(RawWindowHandle::Xcb(_) | RawWindowHandle::Xlib(_)) => {
47 *COMPOSITED.get_or_init(|| compositor_running(None).unwrap_or(false))
48 }
49 _ => true,
50 }
51}
52
33pub fn window_icon_property(png: &[u8]) -> Option<Vec<u32>> {
53pub fn window_icon_property(png: &[u8]) -> Option<Vec<u32>> {
34 let decoded = image::load_from_memory(png).ok()?;
54 let decoded = image::load_from_memory(png).ok()?;
35 let mut property = Vec::new();
55 let mut property = Vec::new();
@@ -131,6 +151,24 @@ mod tests {
131 assert!(after.rectangles.is_empty());
151 assert!(after.rectangles.is_empty());
132 }
152 }
133
153
154 #[test]
155 fn transparency_needs_a_compositor_owning_the_cm_selection() {
156 let Some((_server, display)) = start_server() else {
157 return;
158 };
159 assert!(!compositor_running(Some(&display)).unwrap());
160 let (connection, screen_number) = RustConnection::connect(Some(&display)).unwrap();
161 let root = connection.setup().roots[screen_number].root;
162 let window = connection.generate_id().unwrap();
163 connection
164 .create_window(COPY_DEPTH_FROM_PARENT, window, root, 0, 0, 1, 1, 0, WindowClass::INPUT_OUTPUT, 0, &CreateWindowAux::new())
165 .unwrap();
166 let selection = format!("_NET_WM_CM_S{screen_number}");
167 let atom = connection.intern_atom(false, selection.as_bytes()).unwrap().reply().unwrap().atom;
168 connection.set_selection_owner(window, atom, x11rb::CURRENT_TIME).unwrap().check().unwrap();
169 assert!(compositor_running(Some(&display)).unwrap());
170 }
171
134 #[test]
172 #[test]
135 fn the_window_icon_property_holds_every_size_in_argb() {
173 fn the_window_icon_property_holds_every_size_in_argb() {
136 let png = crate::appearance::AppIcon::MicrosoftTeams.png();
174 let png = crate::appearance::AppIcon::MicrosoftTeams.png();
crates/app/src/notify/center.rs +23 −1
@@ -1342,9 +1342,31 @@ mod tests {
1342 1342
1343 1343 use std::collections::HashSet;
1344 1344
1345 use super::{preview_lines, unread_conversation_ids};
1345 use gpui_kit::{WindowBackgroundAppearance, WindowKind};
1346
1347 use super::{Slot, WorkArea, popup_options, preview_lines, unread_conversation_ids};
1346 1348 use store::Sidebar;
1347 1349
1350 #[test]
1351 fn toast_windows_ask_for_a_transparent_background() {
1352 let slot = Slot {
1353 x: 0,
1354 y: 0,
1355 width: 360,
1356 height: 120,
1357 };
1358 let area = WorkArea {
1359 left: 0,
1360 top: 0,
1361 right: 1920,
1362 bottom: 1080,
1363 scale: 1.,
1364 };
1365 let options = popup_options(slot, area);
1366 assert_eq!(options.window_background, WindowBackgroundAppearance::Transparent);
1367 assert_eq!(options.kind, WindowKind::PopUp);
1368 }
1369
1348 1370 fn sidebar() -> Sidebar {
1349 1371 Sidebar {
1350 1372 chats: vec![
@@ -1342,9 +1342,31 @@ mod tests {
1342
1342
1343 use std::collections::HashSet;
1343 use std::collections::HashSet;
1344
1344
1345 use super::{preview_lines, unread_conversation_ids};
1345 use gpui_kit::{WindowBackgroundAppearance, WindowKind};
1346
1347 use super::{Slot, WorkArea, popup_options, preview_lines, unread_conversation_ids};
1346 use store::Sidebar;
1348 use store::Sidebar;
1347
1349
1350 #[test]
1351 fn toast_windows_ask_for_a_transparent_background() {
1352 let slot = Slot {
1353 x: 0,
1354 y: 0,
1355 width: 360,
1356 height: 120,
1357 };
1358 let area = WorkArea {
1359 left: 0,
1360 top: 0,
1361 right: 1920,
1362 bottom: 1080,
1363 scale: 1.,
1364 };
1365 let options = popup_options(slot, area);
1366 assert_eq!(options.window_background, WindowBackgroundAppearance::Transparent);
1367 assert_eq!(options.kind, WindowKind::PopUp);
1368 }
1369
1348 fn sidebar() -> Sidebar {
1370 fn sidebar() -> Sidebar {
1349 Sidebar {
1371 Sidebar {
1350 chats: vec![
1372 chats: vec![
crates/app/src/notify/meeting_view.rs +2 −2
@@ -6,7 +6,7 @@ use gpui_kit::*;
6 6
7 7 use super::center::NotificationCenter;
8 8 use super::layout::{AVATAR_GAP, TOAST_PADDING};
9 use super::ring_view::{RING_AVATAR, TOAST_RADIUS, answer_button};
9 use super::ring_view::{RING_AVATAR, answer_button, toast_radius};
10 10 use crate::app_state::AppState;
11 11 use crate::call::ReminderPhase;
12 12 use crate::call::meeting_subtitle;
@@ -98,7 +98,7 @@ impl Render for MeetingToastView {
98 98 div()
99 99 .id(("meeting-toast", toast_id))
100 100 .size_full()
101 .rounded(px(TOAST_RADIUS))
101 .rounded(toast_radius(window))
102 102 .bg(theme::popup())
103 103 .overflow_hidden()
104 104 .child(
@@ -6,7 +6,7 @@ use gpui_kit::*;
6
6
7use super::center::NotificationCenter;
7use super::center::NotificationCenter;
8use super::layout::{AVATAR_GAP, TOAST_PADDING};
8use super::layout::{AVATAR_GAP, TOAST_PADDING};
9use super::ring_view::{RING_AVATAR, TOAST_RADIUS, answer_button};
9use super::ring_view::{RING_AVATAR, answer_button, toast_radius};
10use crate::app_state::AppState;
10use crate::app_state::AppState;
11use crate::call::ReminderPhase;
11use crate::call::ReminderPhase;
12use crate::call::meeting_subtitle;
12use crate::call::meeting_subtitle;
@@ -98,7 +98,7 @@ impl Render for MeetingToastView {
98 div()
98 div()
99 .id(("meeting-toast", toast_id))
99 .id(("meeting-toast", toast_id))
100 .size_full()
100 .size_full()
101 .rounded(px(TOAST_RADIUS))
101 .rounded(toast_radius(window))
102 .bg(theme::popup())
102 .bg(theme::popup())
103 .overflow_hidden()
103 .overflow_hidden()
104 .child(
104 .child(
crates/app/src/notify/ring_view.rs +22 −2
@@ -6,6 +6,7 @@ use gpui_kit::*;
6 6
7 7 use super::center::NotificationCenter;
8 8 use super::layout::{AVATAR_GAP, TOAST_PADDING};
9 use super::platform;
9 10 use crate::app_state::AppState;
10 11 use crate::call::RingEntry;
11 12 use crate::theme;
@@ -16,10 +17,18 @@ use crate::views::widgets::icon;
16 17 pub const RING_AVATAR: f32 = 56.;
17 18 const RING_WIDTH: f32 = 3.;
18 19 const RING_GAP: f32 = 3.;
19 pub(super) const TOAST_RADIUS: f32 = 12.;
20 const TOAST_RADIUS: f32 = 12.;
20 21 const BUTTON_HEIGHT: f32 = 32.;
21 22 pub const ENDS_CURRENT_CALL: &str = "Accept ends current call";
22 23
24 pub(super) fn toast_radius(window: &Window) -> Pixels {
25 px(card_radius(platform::window_transparency_available(window)))
26 }
27
28 fn card_radius(window_transparent: bool) -> f32 {
29 if window_transparent { TOAST_RADIUS } else { 0. }
30 }
31
23 32 pub struct RingView {
24 33 app: Entity<AppState>,
25 34 ring_id: u64,
@@ -126,7 +135,7 @@ impl Render for RingView {
126 135 div()
127 136 .id(("ring", ring_id))
128 137 .size_full()
129 .rounded(px(TOAST_RADIUS))
138 .rounded(toast_radius(window))
130 139 .bg(theme::popup())
131 140 .overflow_hidden()
132 141 .child(
@@ -177,3 +186,14 @@ impl Render for RingView {
177 186 .into_any_element()
178 187 }
179 188 }
189
190 #[cfg(test)]
191 mod tests {
192 use super::{TOAST_RADIUS, card_radius};
193
194 #[test]
195 fn toast_cards_turn_square_without_window_transparency() {
196 assert_eq!(card_radius(true), TOAST_RADIUS);
197 assert_eq!(card_radius(false), 0.);
198 }
199 }
@@ -6,6 +6,7 @@ use gpui_kit::*;
6
6
7use super::center::NotificationCenter;
7use super::center::NotificationCenter;
8use super::layout::{AVATAR_GAP, TOAST_PADDING};
8use super::layout::{AVATAR_GAP, TOAST_PADDING};
9use super::platform;
9use crate::app_state::AppState;
10use crate::app_state::AppState;
10use crate::call::RingEntry;
11use crate::call::RingEntry;
11use crate::theme;
12use crate::theme;
@@ -16,10 +17,18 @@ use crate::views::widgets::icon;
16pub const RING_AVATAR: f32 = 56.;
17pub const RING_AVATAR: f32 = 56.;
17const RING_WIDTH: f32 = 3.;
18const RING_WIDTH: f32 = 3.;
18const RING_GAP: f32 = 3.;
19const RING_GAP: f32 = 3.;
19pub(super) const TOAST_RADIUS: f32 = 12.;
20const TOAST_RADIUS: f32 = 12.;
20const BUTTON_HEIGHT: f32 = 32.;
21const BUTTON_HEIGHT: f32 = 32.;
21pub const ENDS_CURRENT_CALL: &str = "Accept ends current call";
22pub const ENDS_CURRENT_CALL: &str = "Accept ends current call";
22
23
24pub(super) fn toast_radius(window: &Window) -> Pixels {
25 px(card_radius(platform::window_transparency_available(window)))
26}
27
28fn card_radius(window_transparent: bool) -> f32 {
29 if window_transparent { TOAST_RADIUS } else { 0. }
30}
31
23pub struct RingView {
32pub struct RingView {
24 app: Entity<AppState>,
33 app: Entity<AppState>,
25 ring_id: u64,
34 ring_id: u64,
@@ -126,7 +135,7 @@ impl Render for RingView {
126 div()
135 div()
127 .id(("ring", ring_id))
136 .id(("ring", ring_id))
128 .size_full()
137 .size_full()
129 .rounded(px(TOAST_RADIUS))
138 .rounded(toast_radius(window))
130 .bg(theme::popup())
139 .bg(theme::popup())
131 .overflow_hidden()
140 .overflow_hidden()
132 .child(
141 .child(
@@ -177,3 +186,14 @@ impl Render for RingView {
177 .into_any_element()
186 .into_any_element()
178 }
187 }
179}
188}
189
190#[cfg(test)]
191mod tests {
192 use super::{TOAST_RADIUS, card_radius};
193
194 #[test]
195 fn toast_cards_turn_square_without_window_transparency() {
196 assert_eq!(card_radius(true), TOAST_RADIUS);
197 assert_eq!(card_radius(false), 0.);
198 }
199}
crates/app/src/notify/toast.rs +4 −4
@@ -15,6 +15,7 @@ use super::layout::{
15 15 TOAST_PADDING,
16 16 };
17 17 use super::platform;
18 use super::ring_view::toast_radius;
18 19 use super::rules::ChatKind;
19 20 use super::stack::{ReplyState, ToastModel};
20 21 use super::text::{ToastText, describe, mention_ranges};
@@ -25,7 +26,6 @@ use crate::views::composer::submitted_text;
25 26 use crate::views::widgets::symbol;
26 27
27 28 const CLOSE_SIZE: f32 = 24.;
28 const TOAST_RADIUS: f32 = 12.;
29 29
30 30 pub struct ToastView {
31 31 center: Entity<NotificationCenter>,
@@ -543,7 +543,7 @@ impl Render for ToastView {
543 543 .relative()
544 544 .size_full()
545 545 .opacity(model.opacity(Instant::now()))
546 .rounded(px(TOAST_RADIUS))
546 .rounded(toast_radius(window))
547 547 .bg(fill)
548 548 .overflow_hidden()
549 549 .cursor_pointer()
@@ -586,7 +586,7 @@ impl PillView {
586 586 }
587 587
588 588 impl Render for PillView {
589 fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
589 fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
590 590 let (queued, opacity) = {
591 591 let center = self.center.read(cx);
592 592 (center.queued_count(), center.stack_opacity())
@@ -599,7 +599,7 @@ impl Render for PillView {
599 599 .items_center()
600 600 .justify_center()
601 601 .opacity(opacity)
602 .rounded(px(TOAST_RADIUS))
602 .rounded(toast_radius(window))
603 603 .bg(theme::popup())
604 604 .cursor_pointer()
605 605 .hover(|bar| bar.bg(theme::popup_hover()))
@@ -15,6 +15,7 @@ use super::layout::{
15 TOAST_PADDING,
15 TOAST_PADDING,
16};
16};
17use super::platform;
17use super::platform;
18use super::ring_view::toast_radius;
18use super::rules::ChatKind;
19use super::rules::ChatKind;
19use super::stack::{ReplyState, ToastModel};
20use super::stack::{ReplyState, ToastModel};
20use super::text::{ToastText, describe, mention_ranges};
21use super::text::{ToastText, describe, mention_ranges};
@@ -25,7 +26,6 @@ use crate::views::composer::submitted_text;
25use crate::views::widgets::symbol;
26use crate::views::widgets::symbol;
26
27
27const CLOSE_SIZE: f32 = 24.;
28const CLOSE_SIZE: f32 = 24.;
28const TOAST_RADIUS: f32 = 12.;
29
29
30pub struct ToastView {
30pub struct ToastView {
31 center: Entity<NotificationCenter>,
31 center: Entity<NotificationCenter>,
@@ -543,7 +543,7 @@ impl Render for ToastView {
543 .relative()
543 .relative()
544 .size_full()
544 .size_full()
545 .opacity(model.opacity(Instant::now()))
545 .opacity(model.opacity(Instant::now()))
546 .rounded(px(TOAST_RADIUS))
546 .rounded(toast_radius(window))
547 .bg(fill)
547 .bg(fill)
548 .overflow_hidden()
548 .overflow_hidden()
549 .cursor_pointer()
549 .cursor_pointer()
@@ -586,7 +586,7 @@ impl PillView {
586}
586}
587
587
588impl Render for PillView {
588impl Render for PillView {
589 fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
589 fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
590 let (queued, opacity) = {
590 let (queued, opacity) = {
591 let center = self.center.read(cx);
591 let center = self.center.read(cx);
592 (center.queued_count(), center.stack_opacity())
592 (center.queued_count(), center.stack_opacity())
@@ -599,7 +599,7 @@ impl Render for PillView {
599 .items_center()
599 .items_center()
600 .justify_center()
600 .justify_center()
601 .opacity(opacity)
601 .opacity(opacity)
602 .rounded(px(TOAST_RADIUS))
602 .rounded(toast_radius(window))
603 .bg(theme::popup())
603 .bg(theme::popup())
604 .cursor_pointer()
604 .cursor_pointer()
605 .hover(|bar| bar.bg(theme::popup_hover()))
605 .hover(|bar| bar.bg(theme::popup_hover()))