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>
@@ -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")]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
true50
}51
42
#[cfg(not(target_os = "linux"))]52
#[cfg(not(target_os = "linux"))]43
pub fn make_window_click_through(_window: &Window) {}53
pub fn make_window_click_through(_window: &Window) {}44
54
@@ -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
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
pub fn prepare_toast_window(handle: NativeHandle) {71
pub 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.@@ -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 @@1
use std::sync::OnceLock;2
1
use gpui_kit::Window;3
use gpui_kit::Window;2
use raw_window_handle::{HasWindowHandle, RawWindowHandle};4
use raw_window_handle::{HasWindowHandle, RawWindowHandle};3
use x11rb::connection::Connection as _;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
pub fn window_icon_property(png: &[u8]) -> Option<Vec<u32>> {53
pub 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
connection164
.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();@@ -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![@@ -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
7
use super::center::NotificationCenter;7
use super::center::NotificationCenter;8
use super::layout::{AVATAR_GAP, TOAST_PADDING};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
use crate::app_state::AppState;10
use crate::app_state::AppState;11
use crate::call::ReminderPhase;11
use crate::call::ReminderPhase;12
use crate::call::meeting_subtitle;12
use 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(@@ -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
7
use super::center::NotificationCenter;7
use super::center::NotificationCenter;8
use super::layout::{AVATAR_GAP, TOAST_PADDING};8
use super::layout::{AVATAR_GAP, TOAST_PADDING};9
use super::platform;9
use crate::app_state::AppState;10
use crate::app_state::AppState;10
use crate::call::RingEntry;11
use crate::call::RingEntry;11
use crate::theme;12
use crate::theme;@@ -16,10 +17,18 @@ use crate::views::widgets::icon;16
pub const RING_AVATAR: f32 = 56.;17
pub const RING_AVATAR: f32 = 56.;17
const RING_WIDTH: f32 = 3.;18
const RING_WIDTH: f32 = 3.;18
const RING_GAP: f32 = 3.;19
const RING_GAP: f32 = 3.;19
pub(super) const TOAST_RADIUS: f32 = 12.;20
const TOAST_RADIUS: f32 = 12.;20
const BUTTON_HEIGHT: f32 = 32.;21
const BUTTON_HEIGHT: f32 = 32.;21
pub const ENDS_CURRENT_CALL: &str = "Accept ends current call";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
pub struct RingView {32
pub 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)]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
}@@ -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
};17
use super::platform;17
use super::platform;18
use super::ring_view::toast_radius;18
use super::rules::ChatKind;19
use super::rules::ChatKind;19
use super::stack::{ReplyState, ToastModel};20
use super::stack::{ReplyState, ToastModel};20
use super::text::{ToastText, describe, mention_ranges};21
use super::text::{ToastText, describe, mention_ranges};@@ -25,7 +26,6 @@ use crate::views::composer::submitted_text;25
use crate::views::widgets::symbol;26
use crate::views::widgets::symbol;26
27
27
const CLOSE_SIZE: f32 = 24.;28
const CLOSE_SIZE: f32 = 24.;28
const TOAST_RADIUS: f32 = 12.;29
29
30
pub struct ToastView {30
pub 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
588
impl Render for PillView {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
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()))