BlueGit

ict rusty-teams

fix(linux): keep ring and meeting cards beside the desktop notification (#104)

metis Joe Mild · pushed by metis

Authored 2026-11-25 · 6 days ago

Hash
795791f80f5d8a425c6fe48d4dff625cc550b2cb
Parent
73aa92a6
2 files changed +123 −4
crates/app/src/notify/center.rs +120 −1
@@ -831,11 +831,59 @@ impl NotificationCenter {
831 831 .map(|toast| (CallToast::Meeting(toast.id), MEETING_HEIGHT));
832 832 rings.chain(meetings).collect()
833 833 }
834 }
835
836 fn call_cards_while_desktop_connected(toasts: &[(CallToast, f32)]) -> Vec<(CallToast, f32)> {
837 toasts
838 .iter()
839 .copied()
840 .filter(|(key, _)| matches!(key, CallToast::Ring(_) | CallToast::Meeting(_)))
841 .collect()
842 }
843
844 impl NotificationCenter {
845 /// Ring and meeting cards stay on screen when a notification service is connected.
846 /// Chat toasts stay desktop notifications.
847 fn sync_ring_cards(&mut self, cx: &mut Context<Self>) {
848 let rings = call_cards_while_desktop_connected(&self.call_toasts(cx));
849 let stale: Vec<CallToast> = self
850 .call_windows
851 .keys()
852 .copied()
853 .filter(|key| !rings.iter().any(|(toast, _)| toast == key))
854 .collect();
855 for key in stale {
856 self.close_call_window(key, cx);
857 }
858 let area = self.work_area(cx);
859 let heights: Vec<f32> = rings.iter().map(|(_, height)| *height).collect();
860 let slots = layout::stack_slots(area, self.settings.corner, &heights, false);
861 for ((key, _), slot) in rings.iter().zip(slots.toasts.iter()) {
862 self.place_call_toast(*key, *slot, area, cx);
863 }
864 }
865
866 fn finish_ring_card(&mut self, ring_id: u64, cx: &mut Context<Self>) {
867 #[cfg(target_os = "linux")]
868 {
869 let still_ringing = self
870 .app
871 .read(cx)
872 .rings
873 .ringing()
874 .any(|entry| entry.ring.ring_id == ring_id);
875 if !still_ringing {
876 self.queue_desktop_close(DesktopKey::Ring(ring_id));
877 }
878 }
879 self.sync_windows(cx);
880 }
834 881
835 882 fn sync_windows(&mut self, cx: &mut Context<Self>) {
836 883 #[cfg(target_os = "linux")]
837 884 if self.desktop.is_some() {
838 885 self.sync_desktop(cx);
886 self.sync_ring_cards(cx);
839 887 return;
840 888 }
841 889 let visible = self.visible_ids();
@@ -915,8 +963,9 @@ impl NotificationCenter {
915 963 if !self.call_opening.insert(key) {
916 964 return;
917 965 }
966 let options = ring_card_options(slot, area);
918 967 open_popup(
919 popup_options(slot, area),
968 options,
920 969 cx,
921 970 move |center, _, cx| match key {
922 971 CallToast::Ring(ring_id) => {
@@ -1565,6 +1614,13 @@ impl NotificationCenter {
1565 1614 self.raise_main_window(cx);
1566 1615 self.app
1567 1616 .update(cx, |state, cx| state.accept_ring(ring_id, mode, cx));
1617 self.finish_ring_card(ring_id, cx);
1618 }
1619
1620 pub fn decline_ring(&mut self, ring_id: u64, cx: &mut Context<Self>) {
1621 self.app
1622 .update(cx, |state, cx| state.decline_ring(ring_id, cx));
1623 self.finish_ring_card(ring_id, cx);
1568 1624 }
1569 1625
1570 1626 fn raise_main_window(&mut self, cx: &mut Context<Self>) {
@@ -1982,6 +2038,18 @@ fn parse_logical_key(key: &str) -> Option<DesktopKey> {
1982 2038 }
1983 2039 }
1984 2040
2041 fn ring_card_options(slot: Slot, area: WorkArea) -> WindowOptions {
2042 // Wayland treats PopUp as a normal toplevel, so Hyprland tiles ring and meeting cards.
2043 #[cfg(target_os = "linux")]
2044 {
2045 let mut options = popup_options(slot, area);
2046 options.kind = WindowKind::Floating;
2047 return options;
2048 }
2049 #[cfg(not(target_os = "linux"))]
2050 popup_options(slot, area)
2051 }
2052
1985 2053 fn popup_options(slot: Slot, area: WorkArea) -> WindowOptions {
1986 2054 let scale = area.scale;
1987 2055 let bounds = Bounds::new(
@@ -2120,6 +2188,57 @@ mod tests {
2120 2188 assert_eq!(options.kind, WindowKind::PopUp);
2121 2189 }
2122 2190
2191 #[cfg(target_os = "linux")]
2192 #[test]
2193 fn linux_ring_card_is_a_floating_window() {
2194 use super::ring_card_options;
2195
2196 let slot = Slot {
2197 x: 10,
2198 y: 20,
2199 width: 360,
2200 height: 140,
2201 };
2202 let area = WorkArea {
2203 left: 0,
2204 top: 0,
2205 right: 1920,
2206 bottom: 1080,
2207 scale: 1.,
2208 };
2209 let options = ring_card_options(slot, area);
2210 assert_eq!(options.kind, WindowKind::Floating);
2211 assert!(!options.focus);
2212 }
2213
2214 #[test]
2215 fn call_cards_while_desktop_connected_keep_rings_and_meetings() {
2216 use super::{CallToast, call_cards_while_desktop_connected};
2217
2218 let toasts = vec![
2219 (CallToast::Ring(7), 140.),
2220 (CallToast::Meeting(3), 96.),
2221 (CallToast::Ring(9), 140.),
2222 ];
2223 let cards = call_cards_while_desktop_connected(&toasts);
2224 assert_eq!(
2225 cards,
2226 vec![
2227 (CallToast::Ring(7), 140.),
2228 (CallToast::Meeting(3), 96.),
2229 (CallToast::Ring(9), 140.)
2230 ]
2231 );
2232 }
2233
2234 #[cfg(target_os = "linux")]
2235 #[test]
2236 fn ring_card_close_token_matches_the_published_ring() {
2237 use super::DesktopKey;
2238
2239 assert_eq!(DesktopKey::Ring(7).replace_token(), "ring:7");
2240 }
2241
2123 2242 fn sidebar() -> Sidebar {
2124 2243 Sidebar {
2125 2244 chats: vec![
@@ -831,11 +831,59 @@ impl NotificationCenter {
831 .map(|toast| (CallToast::Meeting(toast.id), MEETING_HEIGHT));
831 .map(|toast| (CallToast::Meeting(toast.id), MEETING_HEIGHT));
832 rings.chain(meetings).collect()
832 rings.chain(meetings).collect()
833 }
833 }
834}
835
836fn call_cards_while_desktop_connected(toasts: &[(CallToast, f32)]) -> Vec<(CallToast, f32)> {
837 toasts
838 .iter()
839 .copied()
840 .filter(|(key, _)| matches!(key, CallToast::Ring(_) | CallToast::Meeting(_)))
841 .collect()
842}
843
844impl NotificationCenter {
845 /// Ring and meeting cards stay on screen when a notification service is connected.
846 /// Chat toasts stay desktop notifications.
847 fn sync_ring_cards(&mut self, cx: &mut Context<Self>) {
848 let rings = call_cards_while_desktop_connected(&self.call_toasts(cx));
849 let stale: Vec<CallToast> = self
850 .call_windows
851 .keys()
852 .copied()
853 .filter(|key| !rings.iter().any(|(toast, _)| toast == key))
854 .collect();
855 for key in stale {
856 self.close_call_window(key, cx);
857 }
858 let area = self.work_area(cx);
859 let heights: Vec<f32> = rings.iter().map(|(_, height)| *height).collect();
860 let slots = layout::stack_slots(area, self.settings.corner, &heights, false);
861 for ((key, _), slot) in rings.iter().zip(slots.toasts.iter()) {
862 self.place_call_toast(*key, *slot, area, cx);
863 }
864 }
865
866 fn finish_ring_card(&mut self, ring_id: u64, cx: &mut Context<Self>) {
867 #[cfg(target_os = "linux")]
868 {
869 let still_ringing = self
870 .app
871 .read(cx)
872 .rings
873 .ringing()
874 .any(|entry| entry.ring.ring_id == ring_id);
875 if !still_ringing {
876 self.queue_desktop_close(DesktopKey::Ring(ring_id));
877 }
878 }
879 self.sync_windows(cx);
880 }
834
881
835 fn sync_windows(&mut self, cx: &mut Context<Self>) {
882 fn sync_windows(&mut self, cx: &mut Context<Self>) {
836 #[cfg(target_os = "linux")]
883 #[cfg(target_os = "linux")]
837 if self.desktop.is_some() {
884 if self.desktop.is_some() {
838 self.sync_desktop(cx);
885 self.sync_desktop(cx);
886 self.sync_ring_cards(cx);
839 return;
887 return;
840 }
888 }
841 let visible = self.visible_ids();
889 let visible = self.visible_ids();
@@ -915,8 +963,9 @@ impl NotificationCenter {
915 if !self.call_opening.insert(key) {
963 if !self.call_opening.insert(key) {
916 return;
964 return;
917 }
965 }
966 let options = ring_card_options(slot, area);
918 open_popup(
967 open_popup(
919 popup_options(slot, area),
968 options,
920 cx,
969 cx,
921 move |center, _, cx| match key {
970 move |center, _, cx| match key {
922 CallToast::Ring(ring_id) => {
971 CallToast::Ring(ring_id) => {
@@ -1565,6 +1614,13 @@ impl NotificationCenter {
1565 self.raise_main_window(cx);
1614 self.raise_main_window(cx);
1566 self.app
1615 self.app
1567 .update(cx, |state, cx| state.accept_ring(ring_id, mode, cx));
1616 .update(cx, |state, cx| state.accept_ring(ring_id, mode, cx));
1617 self.finish_ring_card(ring_id, cx);
1618 }
1619
1620 pub fn decline_ring(&mut self, ring_id: u64, cx: &mut Context<Self>) {
1621 self.app
1622 .update(cx, |state, cx| state.decline_ring(ring_id, cx));
1623 self.finish_ring_card(ring_id, cx);
1568 }
1624 }
1569
1625
1570 fn raise_main_window(&mut self, cx: &mut Context<Self>) {
1626 fn raise_main_window(&mut self, cx: &mut Context<Self>) {
@@ -1982,6 +2038,18 @@ fn parse_logical_key(key: &str) -> Option<DesktopKey> {
1982 }
2038 }
1983}
2039}
1984
2040
2041fn ring_card_options(slot: Slot, area: WorkArea) -> WindowOptions {
2042 // Wayland treats PopUp as a normal toplevel, so Hyprland tiles ring and meeting cards.
2043 #[cfg(target_os = "linux")]
2044 {
2045 let mut options = popup_options(slot, area);
2046 options.kind = WindowKind::Floating;
2047 return options;
2048 }
2049 #[cfg(not(target_os = "linux"))]
2050 popup_options(slot, area)
2051}
2052
1985fn popup_options(slot: Slot, area: WorkArea) -> WindowOptions {
2053fn popup_options(slot: Slot, area: WorkArea) -> WindowOptions {
1986 let scale = area.scale;
2054 let scale = area.scale;
1987 let bounds = Bounds::new(
2055 let bounds = Bounds::new(
@@ -2120,6 +2188,57 @@ mod tests {
2120 assert_eq!(options.kind, WindowKind::PopUp);
2188 assert_eq!(options.kind, WindowKind::PopUp);
2121 }
2189 }
2122
2190
2191 #[cfg(target_os = "linux")]
2192 #[test]
2193 fn linux_ring_card_is_a_floating_window() {
2194 use super::ring_card_options;
2195
2196 let slot = Slot {
2197 x: 10,
2198 y: 20,
2199 width: 360,
2200 height: 140,
2201 };
2202 let area = WorkArea {
2203 left: 0,
2204 top: 0,
2205 right: 1920,
2206 bottom: 1080,
2207 scale: 1.,
2208 };
2209 let options = ring_card_options(slot, area);
2210 assert_eq!(options.kind, WindowKind::Floating);
2211 assert!(!options.focus);
2212 }
2213
2214 #[test]
2215 fn call_cards_while_desktop_connected_keep_rings_and_meetings() {
2216 use super::{CallToast, call_cards_while_desktop_connected};
2217
2218 let toasts = vec![
2219 (CallToast::Ring(7), 140.),
2220 (CallToast::Meeting(3), 96.),
2221 (CallToast::Ring(9), 140.),
2222 ];
2223 let cards = call_cards_while_desktop_connected(&toasts);
2224 assert_eq!(
2225 cards,
2226 vec![
2227 (CallToast::Ring(7), 140.),
2228 (CallToast::Meeting(3), 96.),
2229 (CallToast::Ring(9), 140.)
2230 ]
2231 );
2232 }
2233
2234 #[cfg(target_os = "linux")]
2235 #[test]
2236 fn ring_card_close_token_matches_the_published_ring() {
2237 use super::DesktopKey;
2238
2239 assert_eq!(DesktopKey::Ring(7).replace_token(), "ring:7");
2240 }
2241
2123 fn sidebar() -> Sidebar {
2242 fn sidebar() -> Sidebar {
2124 Sidebar {
2243 Sidebar {
2125 chats: vec![
2244 chats: vec![
crates/app/src/notify/ring_view.rs +3 −3
@@ -17,7 +17,7 @@ use crate::views::widgets::icon;
17 17 pub const RING_AVATAR: f32 = 56.;
18 18 const RING_WIDTH: f32 = 3.;
19 19 const RING_GAP: f32 = 3.;
20 const TOAST_RADIUS: f32 = 12.;
20 const TOAST_RADIUS: f32 = 10.;
21 21 const BUTTON_HEIGHT: f32 = 32.;
22 22 pub const ENDS_CURRENT_CALL: &str = "Accept ends current call";
23 23
@@ -101,7 +101,7 @@ impl Render for RingView {
101 101 let ends_current = state.call.is_some();
102 102 let avatar = caller_avatar(state, &entry);
103 103 let ring_id = self.ring_id;
104 let decline_app = self.app.clone();
104 let decline_center = self.center.clone();
105 105 let accept_center = self.center.clone();
106 106 let decline = answer_button(
107 107 "ring-decline",
@@ -112,7 +112,7 @@ impl Render for RingView {
112 112 )
113 113 .on_click(move |_, _, cx| {
114 114 cx.stop_propagation();
115 decline_app.update(cx, |state, cx| state.decline_ring(ring_id, cx));
115 decline_center.update(cx, |center, cx| center.decline_ring(ring_id, cx));
116 116 });
117 117 let accept = answer_button(
118 118 "ring-accept",
@@ -17,7 +17,7 @@ use crate::views::widgets::icon;
17pub const RING_AVATAR: f32 = 56.;
17pub const RING_AVATAR: f32 = 56.;
18const RING_WIDTH: f32 = 3.;
18const RING_WIDTH: f32 = 3.;
19const RING_GAP: f32 = 3.;
19const RING_GAP: f32 = 3.;
20const TOAST_RADIUS: f32 = 12.;
20const TOAST_RADIUS: f32 = 10.;
21const BUTTON_HEIGHT: f32 = 32.;
21const BUTTON_HEIGHT: f32 = 32.;
22pub const ENDS_CURRENT_CALL: &str = "Accept ends current call";
22pub const ENDS_CURRENT_CALL: &str = "Accept ends current call";
23
23
@@ -101,7 +101,7 @@ impl Render for RingView {
101 let ends_current = state.call.is_some();
101 let ends_current = state.call.is_some();
102 let avatar = caller_avatar(state, &entry);
102 let avatar = caller_avatar(state, &entry);
103 let ring_id = self.ring_id;
103 let ring_id = self.ring_id;
104 let decline_app = self.app.clone();
104 let decline_center = self.center.clone();
105 let accept_center = self.center.clone();
105 let accept_center = self.center.clone();
106 let decline = answer_button(
106 let decline = answer_button(
107 "ring-decline",
107 "ring-decline",
@@ -112,7 +112,7 @@ impl Render for RingView {
112 )
112 )
113 .on_click(move |_, _, cx| {
113 .on_click(move |_, _, cx| {
114 cx.stop_propagation();
114 cx.stop_propagation();
115 decline_app.update(cx, |state, cx| state.decline_ring(ring_id, cx));
115 decline_center.update(cx, |center, cx| center.decline_ring(ring_id, cx));
116 });
116 });
117 let accept = answer_button(
117 let accept = answer_button(
118 "ring-accept",
118 "ring-accept",