BlueGit

ict rusty-teams

merge: call health and view layouts

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

metis Daniel Däschle · pushed by metis

Authored 2026-10-13 · 7 weeks ago

Hash
be286804d3eb9158767027506ab0e5513fc47d65
22 files changed +2352 −289
ROADMAP.md +3 −2
@@ -2,7 +2,7 @@
2 2
3 3 Feature parity with the Microsoft Teams desktop client.
4 4
5 **Parity: 89 %** (81 done, 14 partial, 4 missing of 99). Partial counts half.
5 **Parity: 89 %** (81 done, 15 partial, 4 missing of 100). Partial counts half.
6 6
7 7 ## By area
8 8
@@ -138,7 +138,7 @@ Feature parity with the Microsoft Teams desktop client.
138 138 | Full-text search over cached messages | Done | |
139 139 | Jump to a message from search | Done | |
140 140 | Esc closes the open conversation or editor | Done | Back to the channel keeps the feed position |
141 | Keyboard shortcuts like Teams | Done | Ctrl+1 Activity, 2 Chats, 3 Channels, 4 Saved; Alt+Up/Down previous and next chat or channel in the visible list, also while typing; calls Ctrl+Shift+A accept, D decline, H hang up, O camera, E share screen, M mute; Ctrl+. lists all shortcuts. Ctrl+5..9 not used |
141 | Keyboard shortcuts like Teams | Done | Ctrl+1 Activity, 2 Chats, 3 Channels, 4 Saved; Alt+Up/Down previous and next chat or channel in the visible list, also while typing; calls Ctrl+Shift+A accept, D decline, H hang up, O camera, E share menu, K raise hand, Y lobby, M mute, F11 full screen, Alt+Shift+A / V start an audio / video call in the open chat; Ctrl+. lists all shortcuts. Ctrl+5..9 not used |
142 142
143 143 ## Presence and people
144 144
@@ -176,6 +176,7 @@ Feature parity with the Microsoft Teams desktop client.
176 176 | Hold, resume, transfer | Partial | 1:1 "..." > Hold renegotiates every line inactive, "On hold" view with Resume, "You're on hold" when the other side holds, Transfer... person picker with Transfer now (blind) and Consult first (second call, first held, Transfer now). Needs a second person; redirect and park not built |
177 177 | Breakout rooms (participant) | Partial | Move message from the participant update or the replacement invite: notice "Moving you to <room>", leave and join the room, "Return to main meeting" in the header, a closed room goes back to the main meeting. Parsing unit tested; needs an organizer who moves people |
178 178 | Call health and encryption | Partial | Header shows signal bars and a shield; click opens "Call health" with loss, round trip, jitter, bitrate, "Secured by Teams encryption", DTLS-SRTP cipher and media path (direct or via Microsoft media server). Unstable network banner with "Turn off incoming video", overloaded computer banner with "Turn off effects". Thresholds unit tested; not yet seen on a bad live network |
179 | View and layout | Partial | "View" button between share and "...": Gallery (up to 3x3 of 16:9 tiles, "+N" tile with a pin list; visible tiles only swap after 2 s of speech, one swap per 5 s), Speaker (stage plus filmstrip of up to 6), Focus on content (only while someone shares), Hide people without video with a count chip, Hide me / Show me, Chat bubbles, Full screen (F11, controls hide after 3 s). Choice, Hide people without video and Chat bubbles are remembered. Checked with the demo gallery scene only; not yet in a large live meeting |
179 180 | Whiteboard | Partial | Stage shows "<name> is sharing a whiteboard" with Open in browser, "..." > Whiteboard opens the meeting's board. State parsing unit tested; the share callback link is registered on join but not yet seen live |
180 181 | Call history | Done | Calls tab (Ctrl+5) from the Teams call log: avatar, name, Missed call in red, Outgoing / Incoming / Meeting with duration, time like the chat list. Click calls back or opens the meeting chat; right-click Call back and Open chat. Refreshes on tab open and after a call ends. Read live (counts and shapes); no realtime update |
181 182 | Join by link or meeting ID | Done | "Join with ID" dialog, "Paste a meeting link", Join chip next to Teams meeting links in the composer and messages. IDs and /meet/ links resolve through a roster-only conversation like Teams web; verified live with a self-created scheduled meeting (same meeting chat found) |
@@ -2,7 +2,7 @@
2
2
3Feature parity with the Microsoft Teams desktop client.
3Feature parity with the Microsoft Teams desktop client.
4
4
5**Parity: 89 %** (81 done, 14 partial, 4 missing of 99). Partial counts half.
5**Parity: 89 %** (81 done, 15 partial, 4 missing of 100). Partial counts half.
6
6
7## By area
7## By area
8
8
@@ -138,7 +138,7 @@ Feature parity with the Microsoft Teams desktop client.
138| Full-text search over cached messages | Done | |
138| Full-text search over cached messages | Done | |
139| Jump to a message from search | Done | |
139| Jump to a message from search | Done | |
140| Esc closes the open conversation or editor | Done | Back to the channel keeps the feed position |
140| Esc closes the open conversation or editor | Done | Back to the channel keeps the feed position |
141| Keyboard shortcuts like Teams | Done | Ctrl+1 Activity, 2 Chats, 3 Channels, 4 Saved; Alt+Up/Down previous and next chat or channel in the visible list, also while typing; calls Ctrl+Shift+A accept, D decline, H hang up, O camera, E share screen, M mute; Ctrl+. lists all shortcuts. Ctrl+5..9 not used |
141| Keyboard shortcuts like Teams | Done | Ctrl+1 Activity, 2 Chats, 3 Channels, 4 Saved; Alt+Up/Down previous and next chat or channel in the visible list, also while typing; calls Ctrl+Shift+A accept, D decline, H hang up, O camera, E share menu, K raise hand, Y lobby, M mute, F11 full screen, Alt+Shift+A / V start an audio / video call in the open chat; Ctrl+. lists all shortcuts. Ctrl+5..9 not used |
142
142
143## Presence and people
143## Presence and people
144
144
@@ -176,6 +176,7 @@ Feature parity with the Microsoft Teams desktop client.
176| Hold, resume, transfer | Partial | 1:1 "..." > Hold renegotiates every line inactive, "On hold" view with Resume, "You're on hold" when the other side holds, Transfer... person picker with Transfer now (blind) and Consult first (second call, first held, Transfer now). Needs a second person; redirect and park not built |
176| Hold, resume, transfer | Partial | 1:1 "..." > Hold renegotiates every line inactive, "On hold" view with Resume, "You're on hold" when the other side holds, Transfer... person picker with Transfer now (blind) and Consult first (second call, first held, Transfer now). Needs a second person; redirect and park not built |
177| Breakout rooms (participant) | Partial | Move message from the participant update or the replacement invite: notice "Moving you to <room>", leave and join the room, "Return to main meeting" in the header, a closed room goes back to the main meeting. Parsing unit tested; needs an organizer who moves people |
177| Breakout rooms (participant) | Partial | Move message from the participant update or the replacement invite: notice "Moving you to <room>", leave and join the room, "Return to main meeting" in the header, a closed room goes back to the main meeting. Parsing unit tested; needs an organizer who moves people |
178| Call health and encryption | Partial | Header shows signal bars and a shield; click opens "Call health" with loss, round trip, jitter, bitrate, "Secured by Teams encryption", DTLS-SRTP cipher and media path (direct or via Microsoft media server). Unstable network banner with "Turn off incoming video", overloaded computer banner with "Turn off effects". Thresholds unit tested; not yet seen on a bad live network |
178| Call health and encryption | Partial | Header shows signal bars and a shield; click opens "Call health" with loss, round trip, jitter, bitrate, "Secured by Teams encryption", DTLS-SRTP cipher and media path (direct or via Microsoft media server). Unstable network banner with "Turn off incoming video", overloaded computer banner with "Turn off effects". Thresholds unit tested; not yet seen on a bad live network |
179| View and layout | Partial | "View" button between share and "...": Gallery (up to 3x3 of 16:9 tiles, "+N" tile with a pin list; visible tiles only swap after 2 s of speech, one swap per 5 s), Speaker (stage plus filmstrip of up to 6), Focus on content (only while someone shares), Hide people without video with a count chip, Hide me / Show me, Chat bubbles, Full screen (F11, controls hide after 3 s). Choice, Hide people without video and Chat bubbles are remembered. Checked with the demo gallery scene only; not yet in a large live meeting |
179| Whiteboard | Partial | Stage shows "<name> is sharing a whiteboard" with Open in browser, "..." > Whiteboard opens the meeting's board. State parsing unit tested; the share callback link is registered on join but not yet seen live |
180| Whiteboard | Partial | Stage shows "<name> is sharing a whiteboard" with Open in browser, "..." > Whiteboard opens the meeting's board. State parsing unit tested; the share callback link is registered on join but not yet seen live |
180| Call history | Done | Calls tab (Ctrl+5) from the Teams call log: avatar, name, Missed call in red, Outgoing / Incoming / Meeting with duration, time like the chat list. Click calls back or opens the meeting chat; right-click Call back and Open chat. Refreshes on tab open and after a call ends. Read live (counts and shapes); no realtime update |
181| Call history | Done | Calls tab (Ctrl+5) from the Teams call log: avatar, name, Missed call in red, Outgoing / Incoming / Meeting with duration, time like the chat list. Click calls back or opens the meeting chat; right-click Call back and Open chat. Refreshes on tab open and after a call ends. Read live (counts and shapes); no realtime update |
181| Join by link or meeting ID | Done | "Join with ID" dialog, "Paste a meeting link", Join chip next to Teams meeting links in the composer and messages. IDs and /meet/ links resolve through a roster-only conversation like Teams web; verified live with a self-created scheduled meeting (same meeting chat found) |
182| Join by link or meeting ID | Done | "Join with ID" dialog, "Paste a meeting link", Join chip next to Teams meeting links in the composer and messages. IDs and /meet/ links resolve through a roster-only conversation like Teams web; verified live with a self-created scheduled meeting (same meeting chat found) |
crates/app/src/app_state.rs +3 −0
@@ -124,6 +124,7 @@ pub struct AppState {
124 124 pub call_launcher: Option<Arc<CallLauncher>>,
125 125 pub call_count: u64,
126 126 pub call_share_sound: bool,
127 pub call_view: crate::call::ViewSettings,
127 128 pub call_background: crate::call::BackgroundPick,
128 129 pub call_camera: calling::DeviceChoice,
129 130 pub meet_now_pending: bool,
@@ -221,6 +222,7 @@ impl AppState {
221 222 call_launcher: None,
222 223 call_count: 0,
223 224 call_share_sound: false,
225 call_view: crate::call::ViewSettings::default(),
224 226 call_background: crate::call::BackgroundPick::None,
225 227 call_camera: calling::DeviceChoice::SystemDefault,
226 228 meet_now_pending: false,
@@ -239,6 +241,7 @@ impl AppState {
239 241 state.local_previews = load_local_previews(&state.store);
240 242 state.collapsed = state.load_collapsed();
241 243 state.call_share_sound = crate::call::load_share_sound(&state.store);
244 state.call_view = crate::call::ViewSettings::load(&state.store);
242 245 state.call_background = crate::call::load_background(&state.store);
243 246 state.call_camera = crate::call::load_camera(&state.store);
244 247 state.call_backgrounds.customs = crate::call::load_custom_backgrounds(&state.store);
@@ -124,6 +124,7 @@ pub struct AppState {
124 pub call_launcher: Option<Arc<CallLauncher>>,
124 pub call_launcher: Option<Arc<CallLauncher>>,
125 pub call_count: u64,
125 pub call_count: u64,
126 pub call_share_sound: bool,
126 pub call_share_sound: bool,
127 pub call_view: crate::call::ViewSettings,
127 pub call_background: crate::call::BackgroundPick,
128 pub call_background: crate::call::BackgroundPick,
128 pub call_camera: calling::DeviceChoice,
129 pub call_camera: calling::DeviceChoice,
129 pub meet_now_pending: bool,
130 pub meet_now_pending: bool,
@@ -221,6 +222,7 @@ impl AppState {
221 call_launcher: None,
222 call_launcher: None,
222 call_count: 0,
223 call_count: 0,
223 call_share_sound: false,
224 call_share_sound: false,
225 call_view: crate::call::ViewSettings::default(),
224 call_background: crate::call::BackgroundPick::None,
226 call_background: crate::call::BackgroundPick::None,
225 call_camera: calling::DeviceChoice::SystemDefault,
227 call_camera: calling::DeviceChoice::SystemDefault,
226 meet_now_pending: false,
228 meet_now_pending: false,
@@ -239,6 +241,7 @@ impl AppState {
239 state.local_previews = load_local_previews(&state.store);
241 state.local_previews = load_local_previews(&state.store);
240 state.collapsed = state.load_collapsed();
242 state.collapsed = state.load_collapsed();
241 state.call_share_sound = crate::call::load_share_sound(&state.store);
243 state.call_share_sound = crate::call::load_share_sound(&state.store);
244 state.call_view = crate::call::ViewSettings::load(&state.store);
242 state.call_background = crate::call::load_background(&state.store);
245 state.call_background = crate::call::load_background(&state.store);
243 state.call_camera = crate::call::load_camera(&state.store);
246 state.call_camera = crate::call::load_camera(&state.store);
244 state.call_backgrounds.customs = crate::call::load_custom_backgrounds(&state.store);
247 state.call_backgrounds.customs = crate::call::load_custom_backgrounds(&state.store);
crates/app/src/call/actions.rs +7 −17
@@ -218,6 +218,8 @@ impl AppState {
218 218 if let Some(call) = self.call.as_mut() {
219 219 call.model.background = self.call_background.clone();
220 220 call.model.camera = self.call_camera.clone();
221 call.model.view = self.call_view;
222 call.model.refresh_layout(Instant::now());
221 223 }
222 224 if self.call_camera != DeviceChoice::SystemDefault {
223 225 self.send_call_command(CallCommand::SelectCamera(self.call_camera.clone()));
@@ -260,6 +262,7 @@ impl AppState {
260 262 if ticks.is_multiple_of(SHARE_SOURCES_EVERY_TICKS) {
261 263 state.refresh_share_sources();
262 264 }
265 state.tick_call_layout(cx);
263 266 CallMedia::changed(&state.call_media, cx);
264 267 }
265 268 running
@@ -411,22 +414,6 @@ impl AppState {
411 414 self.send_call_command(CallCommand::StartShare(source));
412 415 }
413 416
414 pub fn toggle_call_share(&mut self, cx: &mut Context<Self>) {
415 let Some(call) = self.call.as_ref() else {
416 return;
417 };
418 if call.model.local_share.is_some() {
419 self.stop_call_share(cx);
420 return;
421 }
422 if !call.model.can_share() {
423 return;
424 }
425 if let Some(source) = call.model.screens().first().map(|source| (*source).clone()) {
426 self.start_call_share(source, cx);
427 }
428 }
429
430 417 pub fn stop_call_share(&mut self, _cx: &mut Context<Self>) {
431 418 self.send_call_command(CallCommand::StopShare);
432 419 }
@@ -857,7 +844,7 @@ impl AppState {
857 844 )
858 845 } else {
859 846 let script = DemoCall::Meeting {
860 guests: demo_guests(DEMO_SMALL_MEETING),
847 guests: demo_guests(scene.guests().unwrap_or(DEMO_SMALL_MEETING)),
861 848 lobby: false,
862 849 organizer: true,
863 850 };
@@ -877,6 +864,9 @@ impl AppState {
877 864 meeting_data: None,
878 865 });
879 866 }
867 if scene == DemoScene::Gallery {
868 self.queue_demo_bubbles(conversation_id, cx);
869 }
880 870 }
881 871
882 872 fn signal_ring(&mut self, ring_id: u64, signal: RingSignal, cx: &mut Context<Self>) {
@@ -218,6 +218,8 @@ impl AppState {
218 if let Some(call) = self.call.as_mut() {
218 if let Some(call) = self.call.as_mut() {
219 call.model.background = self.call_background.clone();
219 call.model.background = self.call_background.clone();
220 call.model.camera = self.call_camera.clone();
220 call.model.camera = self.call_camera.clone();
221 call.model.view = self.call_view;
222 call.model.refresh_layout(Instant::now());
221 }
223 }
222 if self.call_camera != DeviceChoice::SystemDefault {
224 if self.call_camera != DeviceChoice::SystemDefault {
223 self.send_call_command(CallCommand::SelectCamera(self.call_camera.clone()));
225 self.send_call_command(CallCommand::SelectCamera(self.call_camera.clone()));
@@ -260,6 +262,7 @@ impl AppState {
260 if ticks.is_multiple_of(SHARE_SOURCES_EVERY_TICKS) {
262 if ticks.is_multiple_of(SHARE_SOURCES_EVERY_TICKS) {
261 state.refresh_share_sources();
263 state.refresh_share_sources();
262 }
264 }
265 state.tick_call_layout(cx);
263 CallMedia::changed(&state.call_media, cx);
266 CallMedia::changed(&state.call_media, cx);
264 }
267 }
265 running
268 running
@@ -411,22 +414,6 @@ impl AppState {
411 self.send_call_command(CallCommand::StartShare(source));
414 self.send_call_command(CallCommand::StartShare(source));
412 }
415 }
413
416
414 pub fn toggle_call_share(&mut self, cx: &mut Context<Self>) {
415 let Some(call) = self.call.as_ref() else {
416 return;
417 };
418 if call.model.local_share.is_some() {
419 self.stop_call_share(cx);
420 return;
421 }
422 if !call.model.can_share() {
423 return;
424 }
425 if let Some(source) = call.model.screens().first().map(|source| (*source).clone()) {
426 self.start_call_share(source, cx);
427 }
428 }
429
430 pub fn stop_call_share(&mut self, _cx: &mut Context<Self>) {
417 pub fn stop_call_share(&mut self, _cx: &mut Context<Self>) {
431 self.send_call_command(CallCommand::StopShare);
418 self.send_call_command(CallCommand::StopShare);
432 }
419 }
@@ -857,7 +844,7 @@ impl AppState {
857 )
844 )
858 } else {
845 } else {
859 let script = DemoCall::Meeting {
846 let script = DemoCall::Meeting {
860 guests: demo_guests(DEMO_SMALL_MEETING),
847 guests: demo_guests(scene.guests().unwrap_or(DEMO_SMALL_MEETING)),
861 lobby: false,
848 lobby: false,
862 organizer: true,
849 organizer: true,
863 };
850 };
@@ -877,6 +864,9 @@ impl AppState {
877 meeting_data: None,
864 meeting_data: None,
878 });
865 });
879 }
866 }
867 if scene == DemoScene::Gallery {
868 self.queue_demo_bubbles(conversation_id, cx);
869 }
880 }
870 }
881
871
882 fn signal_ring(&mut self, ring_id: u64, signal: RingSignal, cx: &mut Context<Self>) {
872 fn signal_ring(&mut self, ring_id: u64, signal: RingSignal, cx: &mut Context<Self>) {
crates/app/src/call/bubbles.rs added +75 −0
@@ -0,0 +1,75 @@
1 use std::time::{Duration, Instant};
2
3 pub const BUBBLE_SHOWN: Duration = Duration::from_secs(5);
4 pub const BUBBLE_MAX: usize = 3;
5
6 #[derive(Debug, Clone, PartialEq, Eq)]
7 pub struct ChatBubble {
8 pub id: String,
9 pub sender_id: Option<String>,
10 pub name: String,
11 pub text: String,
12 pub at: Instant,
13 }
14
15 pub fn push_bubble(bubbles: &mut Vec<ChatBubble>, bubble: ChatBubble) {
16 if bubbles.iter().any(|shown| shown.id == bubble.id) {
17 return;
18 }
19 bubbles.push(bubble);
20 let surplus = bubbles.len().saturating_sub(BUBBLE_MAX);
21 bubbles.drain(..surplus);
22 }
23
24 pub fn shown_bubbles(bubbles: &[ChatBubble], now: Instant) -> Vec<&ChatBubble> {
25 bubbles
26 .iter()
27 .filter(|bubble| now.saturating_duration_since(bubble.at) < BUBBLE_SHOWN)
28 .collect()
29 }
30
31 #[cfg(test)]
32 mod tests {
33 use super::*;
34
35 fn bubble(id: &str, at: Instant) -> ChatBubble {
36 ChatBubble {
37 id: id.to_owned(),
38 sender_id: None,
39 name: "Ana".to_owned(),
40 text: "hello".to_owned(),
41 at,
42 }
43 }
44
45 #[test]
46 fn only_the_newest_three_stay() {
47 let now = Instant::now();
48 let mut bubbles = Vec::new();
49 for id in ["a", "b", "c", "d"] {
50 push_bubble(&mut bubbles, bubble(id, now));
51 }
52 let ids: Vec<&str> = bubbles.iter().map(|shown| shown.id.as_str()).collect();
53 assert_eq!(ids, ["b", "c", "d"]);
54 }
55
56 #[test]
57 fn a_message_never_shows_twice() {
58 let now = Instant::now();
59 let mut bubbles = Vec::new();
60 push_bubble(&mut bubbles, bubble("a", now));
61 push_bubble(&mut bubbles, bubble("a", now));
62 assert_eq!(bubbles.len(), 1);
63 }
64
65 #[test]
66 fn bubbles_vanish_after_five_seconds() {
67 let now = Instant::now();
68 let bubbles = vec![bubble("a", now)];
69 assert_eq!(
70 shown_bubbles(&bubbles, now + Duration::from_secs(4)).len(),
71 1
72 );
73 assert!(shown_bubbles(&bubbles, now + BUBBLE_SHOWN).is_empty());
74 }
75 }
@@ -0,0 +1,75 @@
1use std::time::{Duration, Instant};
2
3pub const BUBBLE_SHOWN: Duration = Duration::from_secs(5);
4pub const BUBBLE_MAX: usize = 3;
5
6#[derive(Debug, Clone, PartialEq, Eq)]
7pub struct ChatBubble {
8 pub id: String,
9 pub sender_id: Option<String>,
10 pub name: String,
11 pub text: String,
12 pub at: Instant,
13}
14
15pub fn push_bubble(bubbles: &mut Vec<ChatBubble>, bubble: ChatBubble) {
16 if bubbles.iter().any(|shown| shown.id == bubble.id) {
17 return;
18 }
19 bubbles.push(bubble);
20 let surplus = bubbles.len().saturating_sub(BUBBLE_MAX);
21 bubbles.drain(..surplus);
22}
23
24pub fn shown_bubbles(bubbles: &[ChatBubble], now: Instant) -> Vec<&ChatBubble> {
25 bubbles
26 .iter()
27 .filter(|bubble| now.saturating_duration_since(bubble.at) < BUBBLE_SHOWN)
28 .collect()
29}
30
31#[cfg(test)]
32mod tests {
33 use super::*;
34
35 fn bubble(id: &str, at: Instant) -> ChatBubble {
36 ChatBubble {
37 id: id.to_owned(),
38 sender_id: None,
39 name: "Ana".to_owned(),
40 text: "hello".to_owned(),
41 at,
42 }
43 }
44
45 #[test]
46 fn only_the_newest_three_stay() {
47 let now = Instant::now();
48 let mut bubbles = Vec::new();
49 for id in ["a", "b", "c", "d"] {
50 push_bubble(&mut bubbles, bubble(id, now));
51 }
52 let ids: Vec<&str> = bubbles.iter().map(|shown| shown.id.as_str()).collect();
53 assert_eq!(ids, ["b", "c", "d"]);
54 }
55
56 #[test]
57 fn a_message_never_shows_twice() {
58 let now = Instant::now();
59 let mut bubbles = Vec::new();
60 push_bubble(&mut bubbles, bubble("a", now));
61 push_bubble(&mut bubbles, bubble("a", now));
62 assert_eq!(bubbles.len(), 1);
63 }
64
65 #[test]
66 fn bubbles_vanish_after_five_seconds() {
67 let now = Instant::now();
68 let bubbles = vec![bubble("a", now)];
69 assert_eq!(
70 shown_bubbles(&bubbles, now + Duration::from_secs(4)).len(),
71 1
72 );
73 assert!(shown_bubbles(&bubbles, now + BUBBLE_SHOWN).is_empty());
74 }
75}
crates/app/src/call/demo.rs +44 −14
@@ -29,6 +29,8 @@ const SPEAKING_LEVEL: f32 = 0.3;
29 29 const SPEAKER_TICKS: u32 = 10;
30 30 const VIDEO_PERIOD: Duration = Duration::from_millis(125);
31 31 const DEMO_CAMERAS: usize = 4;
32 const GALLERY_CAMERAS: usize = 7;
33 const GALLERY_SPEAKER_TICKS: u32 = 15;
32 34 const SCREEN_EVERY_TICKS: u32 = 4;
33 35 const SHARE_START: Duration = Duration::from_secs(10);
34 36 const SHARE_END: Duration = Duration::from_secs(45);
@@ -60,7 +62,7 @@ const SELF_PHASE: u32 = 211;
60 62 pub const DEMO_OWN_MRI: &str = "8:orgid:demo-me";
61 63 pub const DEMO_RING_ID: u64 = 9001;
62 64 const DEMO_CALLER: (&str, &str) = ("8:orgid:demo-mara", "Mara Lindqvist");
63 const DEMO_GUESTS: [&str; 11] = [
65 const DEMO_GUESTS: [&str; 12] = [
64 66 "Mara Lindqvist",
65 67 "Jonas Ortega",
66 68 "Priya Nair",
@@ -72,6 +74,7 @@ const DEMO_GUESTS: [&str; 11] = [
72 74 "Yuki Tanaka",
73 75 "Carlos Mendez",
74 76 "Sofia Rossi",
77 "Emil Nowak",
75 78 ];
76 79
77 80 pub type Person = (String, String);
@@ -88,6 +91,7 @@ pub enum DemoScene {
88 91 Breakout,
89 92 Whiteboard,
90 93 Network,
94 Gallery,
91 95 }
92 96
93 97 impl DemoScene {
@@ -101,6 +105,7 @@ impl DemoScene {
101 105 "breakout" => DemoScene::Breakout,
102 106 "whiteboard" => DemoScene::Whiteboard,
103 107 "network" => DemoScene::Network,
108 "gallery" => DemoScene::Gallery,
104 109 _ => return None,
105 110 })
106 111 }
@@ -108,8 +113,27 @@ impl DemoScene {
108 113 pub fn is_one_to_one(self) -> bool {
109 114 matches!(self, DemoScene::Call | DemoScene::Hold | DemoScene::Held | DemoScene::Network)
110 115 }
116
117 pub fn guests(self) -> Option<usize> {
118 (self == DemoScene::Gallery).then_some(DEMO_GALLERY_GUESTS)
119 }
120
121 fn cameras(self) -> usize {
122 match self {
123 DemoScene::Gallery => GALLERY_CAMERAS,
124 _ => DEMO_CAMERAS,
125 }
126 }
127
128 fn speaker_ticks(self) -> u32 {
129 match self {
130 DemoScene::Gallery => GALLERY_SPEAKER_TICKS,
131 _ => SPEAKER_TICKS,
132 }
133 }
111 134 }
112 135
136 pub const DEMO_GALLERY_GUESTS: usize = 12;
113 137 const BREAKOUT_AT_TICKS: u32 = 20;
114 138 const WHITEBOARD_AT_TICKS: u32 = 5;
115 139 const DEMO_BOARD_URL: &str = "https://app.whiteboard.microsoft.com/me/whiteboards/demo";
@@ -218,7 +242,7 @@ pub fn start_demo_scene_call(script: DemoCall, scene: DemoScene) -> CallHandle {
218 242 handle
219 243 }
220 244
221 fn roster_of(people: &[Person]) -> Vec<RosterEntry> {
245 fn roster_of(people: &[Person], cameras: usize) -> Vec<RosterEntry> {
222 246 people
223 247 .iter()
224 248 .enumerate()
@@ -227,7 +251,7 @@ fn roster_of(people: &[Person]) -> Vec<RosterEntry> {
227 251 display_name: name.clone(),
228 252 muted: index % 3 == 1,
229 253 in_lobby: false,
230 has_video: index < DEMO_CAMERAS,
254 has_video: index < cameras,
231 255 sharing: false,
232 256 hand: None,
233 257 spotlight: None,
@@ -271,7 +295,7 @@ async fn run_demo_call(mut control: CallControl, script: DemoCall, scene: DemoSc
271 295 }
272 296 control.send(CallUpdate::Lobby(false));
273 297 }
274 let mut roster = roster_of(&people);
298 let mut roster = roster_of(&people, scene.cameras());
275 299 if matches!(script, DemoCall::People(_)) {
276 300 control.send(CallUpdate::ReplacementLink(
277 301 DEMO_REPLACEMENT_LINK.to_owned(),
@@ -303,7 +327,8 @@ async fn run_demo_call(mut control: CallControl, script: DemoCall, scene: DemoSc
303 327 let video = !matches!(script, DemoCall::Test);
304 328 let sharer = matches!(script, DemoCall::Meeting { .. })
305 329 .then(|| people.get(1).map(|person| person.0.clone()))
306 .flatten();
330 .flatten()
331 .filter(|_| scene != DemoScene::Gallery);
307 332 start_scene(&control, scene);
308 333 speak_until_hangup(control, people, roster, video, sharer, scene).await;
309 334 }
@@ -335,6 +360,7 @@ fn publish_demo_video(
335 360 sharing: bool,
336 361 sharer: Option<&str>,
337 362 camera: Option<bool>,
363 cameras: usize,
338 364 ) {
339 365 if let Some(blur) = camera {
340 366 control.video.publish(
@@ -342,7 +368,7 @@ fn publish_demo_video(
342 368 self_view((tick + SELF_PHASE) as usize, blur),
343 369 );
344 370 }
345 for (index, (mri, _)) in people.iter().take(DEMO_CAMERAS).enumerate() {
371 for (index, (mri, _)) in people.iter().take(cameras).enumerate() {
346 372 let frame = pattern_frame(PatternKind::Camera, tick + index as u32 * GUEST_PHASE);
347 373 control
348 374 .video
@@ -366,7 +392,11 @@ fn start_scene(control: &CallControl, scene: DemoScene) {
366 392 DemoScene::Hold => control.send(CallUpdate::Hold(HoldState::Local)),
367 393 DemoScene::Held => control.send(CallUpdate::Hold(HoldState::Remote)),
368 394 DemoScene::Network => control.send(CallUpdate::Health(poor_network_health())),
369 DemoScene::Call | DemoScene::Breakout | DemoScene::Whiteboard | DemoScene::Plain => {}
395 DemoScene::Call
396 | DemoScene::Breakout
397 | DemoScene::Whiteboard
398 | DemoScene::Gallery
399 | DemoScene::Plain => {}
370 400 }
371 401 }
372 402
@@ -453,7 +483,7 @@ async fn speak_until_hangup(
453 483 sharing = share_now;
454 484 control.send(CallUpdate::ScreenShare(sharer.clone().filter(|_| sharing)));
455 485 }
456 publish_demo_video(&control, if incoming_video { people.as_slice() } else { &[] }, video_ticks, sharing, sharer.as_deref(), camera_on.then_some(blur));
486 publish_demo_video(&control, if incoming_video { people.as_slice() } else { &[] }, video_ticks, sharing, sharer.as_deref(), camera_on.then_some(blur), scene.cameras());
457 487 video_ticks += 1;
458 488 }
459 489 _ = tick.tick() => {
@@ -463,8 +493,8 @@ async fn speak_until_hangup(
463 493 local: if LOCAL_SPEAKS.contains(&phase) && !muted { SPEAKING_LEVEL } else { 0.0 },
464 494 remote: if remote_speaks { SPEAKING_LEVEL } else { 0.0 },
465 495 });
466 if people.len() > 1 && ticks.is_multiple_of(SPEAKER_TICKS) {
467 let speaker = &people[(ticks / SPEAKER_TICKS) as usize % people.len()];
496 if people.len() > 1 && ticks.is_multiple_of(scene.speaker_ticks()) {
497 let speaker = &people[(ticks / scene.speaker_ticks()) as usize % people.len()];
468 498 control.send(CallUpdate::Speakers(vec![speaker.0.clone()]));
469 499 }
470 500 if ticks % REACTION_EVERY_TICKS == REACTION_EVERY_TICKS / 2
@@ -683,17 +713,17 @@ mod tests {
683 713
684 714 #[test]
685 715 fn demo_guests_have_distinct_mris_and_names() {
686 let guests = demo_guests(11);
687 assert_eq!(guests.len(), 11);
716 let guests = demo_guests(12);
717 assert_eq!(guests.len(), 12);
688 718 let mut mris: Vec<&String> = guests.iter().map(|guest| &guest.0).collect();
689 719 mris.sort();
690 720 mris.dedup();
691 assert_eq!(mris.len(), 11);
721 assert_eq!(mris.len(), 12);
692 722 }
693 723
694 724 #[test]
695 725 fn demo_hands_queue_in_order_and_lowering_drops_the_own_entry() {
696 let mut roster = roster_of(&demo_guests(3));
726 let mut roster = roster_of(&demo_guests(3), DEMO_CAMERAS);
697 727 set_demo_hand(&mut roster, "8:orgid:demo-guest-1", true);
698 728 set_demo_hand(&mut roster, DEMO_OWN_MRI, true);
699 729 let ranks: Vec<u64> = roster
@@ -29,6 +29,8 @@ const SPEAKING_LEVEL: f32 = 0.3;
29const SPEAKER_TICKS: u32 = 10;
29const SPEAKER_TICKS: u32 = 10;
30const VIDEO_PERIOD: Duration = Duration::from_millis(125);
30const VIDEO_PERIOD: Duration = Duration::from_millis(125);
31const DEMO_CAMERAS: usize = 4;
31const DEMO_CAMERAS: usize = 4;
32const GALLERY_CAMERAS: usize = 7;
33const GALLERY_SPEAKER_TICKS: u32 = 15;
32const SCREEN_EVERY_TICKS: u32 = 4;
34const SCREEN_EVERY_TICKS: u32 = 4;
33const SHARE_START: Duration = Duration::from_secs(10);
35const SHARE_START: Duration = Duration::from_secs(10);
34const SHARE_END: Duration = Duration::from_secs(45);
36const SHARE_END: Duration = Duration::from_secs(45);
@@ -60,7 +62,7 @@ const SELF_PHASE: u32 = 211;
60pub const DEMO_OWN_MRI: &str = "8:orgid:demo-me";
62pub const DEMO_OWN_MRI: &str = "8:orgid:demo-me";
61pub const DEMO_RING_ID: u64 = 9001;
63pub const DEMO_RING_ID: u64 = 9001;
62const DEMO_CALLER: (&str, &str) = ("8:orgid:demo-mara", "Mara Lindqvist");
64const DEMO_CALLER: (&str, &str) = ("8:orgid:demo-mara", "Mara Lindqvist");
63const DEMO_GUESTS: [&str; 11] = [
65const DEMO_GUESTS: [&str; 12] = [
64 "Mara Lindqvist",
66 "Mara Lindqvist",
65 "Jonas Ortega",
67 "Jonas Ortega",
66 "Priya Nair",
68 "Priya Nair",
@@ -72,6 +74,7 @@ const DEMO_GUESTS: [&str; 11] = [
72 "Yuki Tanaka",
74 "Yuki Tanaka",
73 "Carlos Mendez",
75 "Carlos Mendez",
74 "Sofia Rossi",
76 "Sofia Rossi",
77 "Emil Nowak",
75];
78];
76
79
77pub type Person = (String, String);
80pub type Person = (String, String);
@@ -88,6 +91,7 @@ pub enum DemoScene {
88 Breakout,
91 Breakout,
89 Whiteboard,
92 Whiteboard,
90 Network,
93 Network,
94 Gallery,
91}
95}
92
96
93impl DemoScene {
97impl DemoScene {
@@ -101,6 +105,7 @@ impl DemoScene {
101 "breakout" => DemoScene::Breakout,
105 "breakout" => DemoScene::Breakout,
102 "whiteboard" => DemoScene::Whiteboard,
106 "whiteboard" => DemoScene::Whiteboard,
103 "network" => DemoScene::Network,
107 "network" => DemoScene::Network,
108 "gallery" => DemoScene::Gallery,
104 _ => return None,
109 _ => return None,
105 })
110 })
106 }
111 }
@@ -108,8 +113,27 @@ impl DemoScene {
108 pub fn is_one_to_one(self) -> bool {
113 pub fn is_one_to_one(self) -> bool {
109 matches!(self, DemoScene::Call | DemoScene::Hold | DemoScene::Held | DemoScene::Network)
114 matches!(self, DemoScene::Call | DemoScene::Hold | DemoScene::Held | DemoScene::Network)
110 }
115 }
116
117 pub fn guests(self) -> Option<usize> {
118 (self == DemoScene::Gallery).then_some(DEMO_GALLERY_GUESTS)
119 }
120
121 fn cameras(self) -> usize {
122 match self {
123 DemoScene::Gallery => GALLERY_CAMERAS,
124 _ => DEMO_CAMERAS,
125 }
126 }
127
128 fn speaker_ticks(self) -> u32 {
129 match self {
130 DemoScene::Gallery => GALLERY_SPEAKER_TICKS,
131 _ => SPEAKER_TICKS,
132 }
133 }
111}
134}
112
135
136pub const DEMO_GALLERY_GUESTS: usize = 12;
113const BREAKOUT_AT_TICKS: u32 = 20;
137const BREAKOUT_AT_TICKS: u32 = 20;
114const WHITEBOARD_AT_TICKS: u32 = 5;
138const WHITEBOARD_AT_TICKS: u32 = 5;
115const DEMO_BOARD_URL: &str = "https://app.whiteboard.microsoft.com/me/whiteboards/demo";
139const DEMO_BOARD_URL: &str = "https://app.whiteboard.microsoft.com/me/whiteboards/demo";
@@ -218,7 +242,7 @@ pub fn start_demo_scene_call(script: DemoCall, scene: DemoScene) -> CallHandle {
218 handle
242 handle
219}
243}
220
244
221fn roster_of(people: &[Person]) -> Vec<RosterEntry> {
245fn roster_of(people: &[Person], cameras: usize) -> Vec<RosterEntry> {
222 people
246 people
223 .iter()
247 .iter()
224 .enumerate()
248 .enumerate()
@@ -227,7 +251,7 @@ fn roster_of(people: &[Person]) -> Vec<RosterEntry> {
227 display_name: name.clone(),
251 display_name: name.clone(),
228 muted: index % 3 == 1,
252 muted: index % 3 == 1,
229 in_lobby: false,
253 in_lobby: false,
230 has_video: index < DEMO_CAMERAS,
254 has_video: index < cameras,
231 sharing: false,
255 sharing: false,
232 hand: None,
256 hand: None,
233 spotlight: None,
257 spotlight: None,
@@ -271,7 +295,7 @@ async fn run_demo_call(mut control: CallControl, script: DemoCall, scene: DemoSc
271 }
295 }
272 control.send(CallUpdate::Lobby(false));
296 control.send(CallUpdate::Lobby(false));
273 }
297 }
274 let mut roster = roster_of(&people);
298 let mut roster = roster_of(&people, scene.cameras());
275 if matches!(script, DemoCall::People(_)) {
299 if matches!(script, DemoCall::People(_)) {
276 control.send(CallUpdate::ReplacementLink(
300 control.send(CallUpdate::ReplacementLink(
277 DEMO_REPLACEMENT_LINK.to_owned(),
301 DEMO_REPLACEMENT_LINK.to_owned(),
@@ -303,7 +327,8 @@ async fn run_demo_call(mut control: CallControl, script: DemoCall, scene: DemoSc
303 let video = !matches!(script, DemoCall::Test);
327 let video = !matches!(script, DemoCall::Test);
304 let sharer = matches!(script, DemoCall::Meeting { .. })
328 let sharer = matches!(script, DemoCall::Meeting { .. })
305 .then(|| people.get(1).map(|person| person.0.clone()))
329 .then(|| people.get(1).map(|person| person.0.clone()))
306 .flatten();
330 .flatten()
331 .filter(|_| scene != DemoScene::Gallery);
307 start_scene(&control, scene);
332 start_scene(&control, scene);
308 speak_until_hangup(control, people, roster, video, sharer, scene).await;
333 speak_until_hangup(control, people, roster, video, sharer, scene).await;
309}
334}
@@ -335,6 +360,7 @@ fn publish_demo_video(
335 sharing: bool,
360 sharing: bool,
336 sharer: Option<&str>,
361 sharer: Option<&str>,
337 camera: Option<bool>,
362 camera: Option<bool>,
363 cameras: usize,
338) {
364) {
339 if let Some(blur) = camera {
365 if let Some(blur) = camera {
340 control.video.publish(
366 control.video.publish(
@@ -342,7 +368,7 @@ fn publish_demo_video(
342 self_view((tick + SELF_PHASE) as usize, blur),
368 self_view((tick + SELF_PHASE) as usize, blur),
343 );
369 );
344 }
370 }
345 for (index, (mri, _)) in people.iter().take(DEMO_CAMERAS).enumerate() {
371 for (index, (mri, _)) in people.iter().take(cameras).enumerate() {
346 let frame = pattern_frame(PatternKind::Camera, tick + index as u32 * GUEST_PHASE);
372 let frame = pattern_frame(PatternKind::Camera, tick + index as u32 * GUEST_PHASE);
347 control
373 control
348 .video
374 .video
@@ -366,7 +392,11 @@ fn start_scene(control: &CallControl, scene: DemoScene) {
366 DemoScene::Hold => control.send(CallUpdate::Hold(HoldState::Local)),
392 DemoScene::Hold => control.send(CallUpdate::Hold(HoldState::Local)),
367 DemoScene::Held => control.send(CallUpdate::Hold(HoldState::Remote)),
393 DemoScene::Held => control.send(CallUpdate::Hold(HoldState::Remote)),
368 DemoScene::Network => control.send(CallUpdate::Health(poor_network_health())),
394 DemoScene::Network => control.send(CallUpdate::Health(poor_network_health())),
369 DemoScene::Call | DemoScene::Breakout | DemoScene::Whiteboard | DemoScene::Plain => {}
395 DemoScene::Call
396 | DemoScene::Breakout
397 | DemoScene::Whiteboard
398 | DemoScene::Gallery
399 | DemoScene::Plain => {}
370 }
400 }
371}
401}
372
402
@@ -453,7 +483,7 @@ async fn speak_until_hangup(
453 sharing = share_now;
483 sharing = share_now;
454 control.send(CallUpdate::ScreenShare(sharer.clone().filter(|_| sharing)));
484 control.send(CallUpdate::ScreenShare(sharer.clone().filter(|_| sharing)));
455 }
485 }
456 publish_demo_video(&control, if incoming_video { people.as_slice() } else { &[] }, video_ticks, sharing, sharer.as_deref(), camera_on.then_some(blur));
486 publish_demo_video(&control, if incoming_video { people.as_slice() } else { &[] }, video_ticks, sharing, sharer.as_deref(), camera_on.then_some(blur), scene.cameras());
457 video_ticks += 1;
487 video_ticks += 1;
458 }
488 }
459 _ = tick.tick() => {
489 _ = tick.tick() => {
@@ -463,8 +493,8 @@ async fn speak_until_hangup(
463 local: if LOCAL_SPEAKS.contains(&phase) && !muted { SPEAKING_LEVEL } else { 0.0 },
493 local: if LOCAL_SPEAKS.contains(&phase) && !muted { SPEAKING_LEVEL } else { 0.0 },
464 remote: if remote_speaks { SPEAKING_LEVEL } else { 0.0 },
494 remote: if remote_speaks { SPEAKING_LEVEL } else { 0.0 },
465 });
495 });
466 if people.len() > 1 && ticks.is_multiple_of(SPEAKER_TICKS) {
496 if people.len() > 1 && ticks.is_multiple_of(scene.speaker_ticks()) {
467 let speaker = &people[(ticks / SPEAKER_TICKS) as usize % people.len()];
497 let speaker = &people[(ticks / scene.speaker_ticks()) as usize % people.len()];
468 control.send(CallUpdate::Speakers(vec![speaker.0.clone()]));
498 control.send(CallUpdate::Speakers(vec![speaker.0.clone()]));
469 }
499 }
470 if ticks % REACTION_EVERY_TICKS == REACTION_EVERY_TICKS / 2
500 if ticks % REACTION_EVERY_TICKS == REACTION_EVERY_TICKS / 2
@@ -683,17 +713,17 @@ mod tests {
683
713
684 #[test]
714 #[test]
685 fn demo_guests_have_distinct_mris_and_names() {
715 fn demo_guests_have_distinct_mris_and_names() {
686 let guests = demo_guests(11);
716 let guests = demo_guests(12);
687 assert_eq!(guests.len(), 11);
717 assert_eq!(guests.len(), 12);
688 let mut mris: Vec<&String> = guests.iter().map(|guest| &guest.0).collect();
718 let mut mris: Vec<&String> = guests.iter().map(|guest| &guest.0).collect();
689 mris.sort();
719 mris.sort();
690 mris.dedup();
720 mris.dedup();
691 assert_eq!(mris.len(), 11);
721 assert_eq!(mris.len(), 12);
692 }
722 }
693
723
694 #[test]
724 #[test]
695 fn demo_hands_queue_in_order_and_lowering_drops_the_own_entry() {
725 fn demo_hands_queue_in_order_and_lowering_drops_the_own_entry() {
696 let mut roster = roster_of(&demo_guests(3));
726 let mut roster = roster_of(&demo_guests(3), DEMO_CAMERAS);
697 set_demo_hand(&mut roster, "8:orgid:demo-guest-1", true);
727 set_demo_hand(&mut roster, "8:orgid:demo-guest-1", true);
698 set_demo_hand(&mut roster, DEMO_OWN_MRI, true);
728 set_demo_hand(&mut roster, DEMO_OWN_MRI, true);
699 let ranks: Vec<u64> = roster
729 let ranks: Vec<u64> = roster
crates/app/src/call/fullscreen.rs added +71 −0
@@ -0,0 +1,71 @@
1 use std::time::{Duration, Instant};
2
3 pub const CHROME_IDLE: Duration = Duration::from_secs(3);
4 pub const HINT_SHOWN: Duration = Duration::from_secs(2);
5
6 #[derive(Debug, Clone, Copy)]
7 pub struct FullscreenState {
8 pub entered: Instant,
9 pub active_at: Instant,
10 pub hovered: bool,
11 pub timer_running: bool,
12 }
13
14 impl FullscreenState {
15 pub fn new(now: Instant) -> Self {
16 FullscreenState {
17 entered: now,
18 active_at: now,
19 hovered: false,
20 timer_running: false,
21 }
22 }
23
24 pub fn chrome_visible(&self, now: Instant) -> bool {
25 self.hovered || now.saturating_duration_since(self.active_at) < CHROME_IDLE
26 }
27
28 pub fn hint_visible(&self, now: Instant) -> bool {
29 now.saturating_duration_since(self.entered) < HINT_SHOWN
30 }
31
32 pub fn next_change(&self, now: Instant) -> Option<Duration> {
33 if self.hovered {
34 return None;
35 }
36 let hide_at = self.active_at + CHROME_IDLE;
37 (hide_at > now).then(|| hide_at - now)
38 }
39 }
40
41 #[cfg(test)]
42 mod tests {
43 use super::*;
44
45 #[test]
46 fn controls_hide_after_three_idle_seconds_and_return_on_movement() {
47 let start = Instant::now();
48 let mut state = FullscreenState::new(start);
49 assert!(state.chrome_visible(start + Duration::from_millis(2900)));
50 assert!(!state.chrome_visible(start + CHROME_IDLE));
51 state.active_at = start + Duration::from_secs(10);
52 assert!(state.chrome_visible(start + Duration::from_secs(11)));
53 }
54
55 #[test]
56 fn controls_stay_while_the_pointer_is_over_them() {
57 let start = Instant::now();
58 let mut state = FullscreenState::new(start);
59 state.hovered = true;
60 assert!(state.chrome_visible(start + Duration::from_secs(60)));
61 assert_eq!(state.next_change(start), None);
62 }
63
64 #[test]
65 fn the_exit_hint_shows_for_two_seconds() {
66 let start = Instant::now();
67 let state = FullscreenState::new(start);
68 assert!(state.hint_visible(start + Duration::from_millis(1900)));
69 assert!(!state.hint_visible(start + HINT_SHOWN));
70 }
71 }
@@ -0,0 +1,71 @@
1use std::time::{Duration, Instant};
2
3pub const CHROME_IDLE: Duration = Duration::from_secs(3);
4pub const HINT_SHOWN: Duration = Duration::from_secs(2);
5
6#[derive(Debug, Clone, Copy)]
7pub struct FullscreenState {
8 pub entered: Instant,
9 pub active_at: Instant,
10 pub hovered: bool,
11 pub timer_running: bool,
12}
13
14impl FullscreenState {
15 pub fn new(now: Instant) -> Self {
16 FullscreenState {
17 entered: now,
18 active_at: now,
19 hovered: false,
20 timer_running: false,
21 }
22 }
23
24 pub fn chrome_visible(&self, now: Instant) -> bool {
25 self.hovered || now.saturating_duration_since(self.active_at) < CHROME_IDLE
26 }
27
28 pub fn hint_visible(&self, now: Instant) -> bool {
29 now.saturating_duration_since(self.entered) < HINT_SHOWN
30 }
31
32 pub fn next_change(&self, now: Instant) -> Option<Duration> {
33 if self.hovered {
34 return None;
35 }
36 let hide_at = self.active_at + CHROME_IDLE;
37 (hide_at > now).then(|| hide_at - now)
38 }
39}
40
41#[cfg(test)]
42mod tests {
43 use super::*;
44
45 #[test]
46 fn controls_hide_after_three_idle_seconds_and_return_on_movement() {
47 let start = Instant::now();
48 let mut state = FullscreenState::new(start);
49 assert!(state.chrome_visible(start + Duration::from_millis(2900)));
50 assert!(!state.chrome_visible(start + CHROME_IDLE));
51 state.active_at = start + Duration::from_secs(10);
52 assert!(state.chrome_visible(start + Duration::from_secs(11)));
53 }
54
55 #[test]
56 fn controls_stay_while_the_pointer_is_over_them() {
57 let start = Instant::now();
58 let mut state = FullscreenState::new(start);
59 state.hovered = true;
60 assert!(state.chrome_visible(start + Duration::from_secs(60)));
61 assert_eq!(state.next_change(start), None);
62 }
63
64 #[test]
65 fn the_exit_hint_shows_for_two_seconds() {
66 let start = Instant::now();
67 let state = FullscreenState::new(start);
68 assert!(state.hint_visible(start + Duration::from_millis(1900)));
69 assert!(!state.hint_visible(start + HINT_SHOWN));
70 }
71}
crates/app/src/call/mod.rs +10 −2
@@ -1,11 +1,13 @@
1 1 mod actions;
2 2 mod agenda;
3 3 mod background;
4 mod bubbles;
4 5 mod calendar;
5 6 mod demo;
6 7 mod demo_scene;
7 8 mod features;
8 9 mod health;
10 mod fullscreen;
9 11 mod history;
10 12 mod join;
11 13 mod launcher;
@@ -17,7 +19,10 @@ mod overlay_layout;
17 19 mod pictures;
18 20 mod preview;
19 21 mod ring;
22 mod stage_layout;
20 23 mod target;
24 mod view_actions;
25 mod view_settings;
21 26
22 27 pub use actions::{load_camera, load_share_sound};
23 28 pub use agenda::{AgendaRow, fetch_window, join_available};
@@ -25,6 +30,7 @@ pub use background::{
25 30 BackgroundLibrary, BackgroundPick, default_cache_directory, demo_library, load_background,
26 31 load_custom_backgrounds,
27 32 };
33 pub use bubbles::{BUBBLE_SHOWN, shown_bubbles};
28 34 pub use demo::DemoScene;
29 35 pub use features::TransferCandidate;
30 36 pub use health::{HealthBanner, level_text, media_text, network_rows, transport_text};
@@ -36,10 +42,12 @@ pub use list::{
36 42 };
37 43 pub use media::CallMedia;
38 44 pub use model::{
39 ActiveCall, CAPTION_SHOWN, CHAT_OPEN_TILES, CallKind, CallModel, Focus, GridLayout, MAX_TILES,
40 REACTION_SHOWN, Tile, TileSize, TileState, grid_layout, tile_size,
45 ActiveCall, CAPTION_SHOWN, CallKind, CallModel, Focus, REACTION_SHOWN, Tile, TileSize,
46 TileState,
41 47 };
42 48 pub use overlay::CallWindows;
43 49 pub use preview::{CameraPreview, preview_backgrounds};
44 50 pub use ring::{MissedCall, RingEntry, Rings};
51 pub use stage_layout::{GALLERY_MAX, filmstrip, gallery_grid, split_overflow};
45 52 pub use target::plan_for_chat;
53 pub use view_settings::{CallLayout, ViewSettings};
@@ -1,11 +1,13 @@
1mod actions;
1mod actions;
2mod agenda;
2mod agenda;
3mod background;
3mod background;
4mod bubbles;
4mod calendar;
5mod calendar;
5mod demo;
6mod demo;
6mod demo_scene;
7mod demo_scene;
7mod features;
8mod features;
8mod health;
9mod health;
10mod fullscreen;
9mod history;
11mod history;
10mod join;
12mod join;
11mod launcher;
13mod launcher;
@@ -17,7 +19,10 @@ mod overlay_layout;
17mod pictures;
19mod pictures;
18mod preview;
20mod preview;
19mod ring;
21mod ring;
22mod stage_layout;
20mod target;
23mod target;
24mod view_actions;
25mod view_settings;
21
26
22pub use actions::{load_camera, load_share_sound};
27pub use actions::{load_camera, load_share_sound};
23pub use agenda::{AgendaRow, fetch_window, join_available};
28pub use agenda::{AgendaRow, fetch_window, join_available};
@@ -25,6 +30,7 @@ pub use background::{
25 BackgroundLibrary, BackgroundPick, default_cache_directory, demo_library, load_background,
30 BackgroundLibrary, BackgroundPick, default_cache_directory, demo_library, load_background,
26 load_custom_backgrounds,
31 load_custom_backgrounds,
27};
32};
33pub use bubbles::{BUBBLE_SHOWN, shown_bubbles};
28pub use demo::DemoScene;
34pub use demo::DemoScene;
29pub use features::TransferCandidate;
35pub use features::TransferCandidate;
30pub use health::{HealthBanner, level_text, media_text, network_rows, transport_text};
36pub use health::{HealthBanner, level_text, media_text, network_rows, transport_text};
@@ -36,10 +42,12 @@ pub use list::{
36};
42};
37pub use media::CallMedia;
43pub use media::CallMedia;
38pub use model::{
44pub use model::{
39 ActiveCall, CAPTION_SHOWN, CHAT_OPEN_TILES, CallKind, CallModel, Focus, GridLayout, MAX_TILES,
45 ActiveCall, CAPTION_SHOWN, CallKind, CallModel, Focus, REACTION_SHOWN, Tile, TileSize,
40 REACTION_SHOWN, Tile, TileSize, TileState, grid_layout, tile_size,
46 TileState,
41};
47};
42pub use overlay::CallWindows;
48pub use overlay::CallWindows;
43pub use preview::{CameraPreview, preview_backgrounds};
49pub use preview::{CameraPreview, preview_backgrounds};
44pub use ring::{MissedCall, RingEntry, Rings};
50pub use ring::{MissedCall, RingEntry, Rings};
51pub use stage_layout::{GALLERY_MAX, filmstrip, gallery_grid, split_overflow};
45pub use target::plan_for_chat;
52pub use target::plan_for_chat;
53pub use view_settings::{CallLayout, ViewSettings};
crates/app/src/call/model.rs +254 −92
@@ -1,3 +1,5 @@
1 use std::cell::Cell;
2 use std::rc::Rc;
1 3 use std::sync::Arc;
2 4 use std::time::{Duration, Instant};
3 5
@@ -10,18 +12,21 @@ use tokio::sync::mpsc::UnboundedSender;
10 12
11 13 use super::background::BackgroundPick;
12 14 use super::health::{HealthBanner, HealthState};
15 use super::bubbles::ChatBubble;
16 use super::fullscreen::FullscreenState;
13 17 use super::pictures::CallPictures;
18 use super::stage_layout::{FILMSTRIP_MAX, GALLERY_MAX, VisibleRotation, split_overflow};
19 use super::view_settings::{CallLayout, ViewSettings};
14 20
15 21 pub const TEST_CALL_TITLE: &str = "Test call";
16 22 pub const ECHO_NAME: &str = "Teams echo";
17 23 pub const ECHO_MRI: &str = calling::signaling::ECHO_BOT_MRI;
18 pub const MAX_TILES: usize = 9;
19 24 const ORGID_PREFIX: &str = "8:orgid:";
20 const WIDE_TILES: usize = 2;
21 const MEDIUM_TILES: usize = 4;
25 const AVATAR_SHARE: f32 = 0.42;
26 const MIN_AVATAR: f32 = 32.;
27 const MAX_AVATAR: f32 = 96.;
22 28 pub const REACTION_SHOWN: Duration = Duration::from_secs(3);
23 29 const OWN_ECHO_WINDOW: Duration = Duration::from_secs(2);
24 pub const CHAT_OPEN_TILES: usize = 6;
25 30 pub const CAPTION_SHOWN: Duration = Duration::from_secs(4);
26 31 const CAPTION_LINES: usize = 2;
27 32
@@ -34,6 +39,11 @@ pub struct ActiveCall {
34 39 pub video: Arc<VideoHub>,
35 40 pub pictures: CallPictures,
36 41 pub stage_fullscreen: bool,
42 pub fullscreen: Option<FullscreenState>,
43 pub stage_size: Rc<Cell<(f32, f32)>>,
44 pub bubbles: Vec<ChatBubble>,
45 pub share_menu_open: bool,
46 pub lobby_list_open: bool,
37 47 pub chat_open: bool,
38 48 pub meeting_target: Option<MeetingTarget>,
39 49 pub pending_move: Option<PendingMove>,
@@ -91,6 +101,11 @@ impl ActiveCall {
91 101 video,
92 102 pictures: CallPictures::default(),
93 103 stage_fullscreen: false,
104 fullscreen: None,
105 stage_size: Rc::default(),
106 bubbles: Vec::new(),
107 share_menu_open: false,
108 lobby_list_open: false,
94 109 chat_open: false,
95 110 meeting_target: None,
96 111 pending_move: None,
@@ -186,27 +201,6 @@ pub struct CaptionLine {
186 201 pub at: Instant,
187 202 }
188 203
189 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
190 pub struct GridLayout {
191 pub shown_others: usize,
192 pub hidden: usize,
193 }
194
195 pub fn grid_layout(others: usize, max_tiles: usize) -> GridLayout {
196 let total = others + 1;
197 if total <= max_tiles {
198 return GridLayout {
199 shown_others: others,
200 hidden: 0,
201 };
202 }
203 let shown_others = max_tiles - 2;
204 GridLayout {
205 shown_others,
206 hidden: others - shown_others,
207 }
208 }
209
210 204 #[derive(Debug, Clone, Copy, PartialEq)]
211 205 pub struct TileSize {
212 206 pub width: f32,
@@ -214,24 +208,13 @@ pub struct TileSize {
214 208 pub avatar: f32,
215 209 }
216 210
217 pub fn tile_size(cells: usize) -> TileSize {
218 if cells <= WIDE_TILES {
219 TileSize {
220 width: 260.,
221 height: 210.,
222 avatar: 96.,
223 }
224 } else if cells <= MEDIUM_TILES {
211 impl TileSize {
212 pub fn sixteen_by_nine(width: f32) -> TileSize {
213 let height = width * 9. / 16.;
225 214 TileSize {
226 width: 220.,
227 height: 180.,
228 avatar: 72.,
229 }
230 } else {
231 TileSize {
232 width: 190.,
233 height: 150.,
234 avatar: 56.,
215 width,
216 height,
217 avatar: (height * AVATAR_SHARE).clamp(MIN_AVATAR, MAX_AVATAR),
235 218 }
236 219 }
237 220 }
@@ -289,6 +272,8 @@ pub struct CallModel {
289 272 pub reactions: Vec<ReactionChip>,
290 273 reaction_serial: u64,
291 274 pub meeting_chat: Option<String>,
275 pub view: ViewSettings,
276 rotation: VisibleRotation,
292 277 local_detector: SpeakingDetector,
293 278 remote_detector: SpeakingDetector,
294 279 }
@@ -339,6 +324,8 @@ impl CallModel {
339 324 reactions: Vec::new(),
340 325 reaction_serial: 0,
341 326 meeting_chat: None,
327 view: ViewSettings::default(),
328 rotation: VisibleRotation::default(),
342 329 local_detector: SpeakingDetector::default(),
343 330 remote_detector: SpeakingDetector::default(),
344 331 }
@@ -420,8 +407,14 @@ impl CallModel {
420 407 CallUpdate::ListenOnly(listen_only) => self.listen_only = listen_only,
421 408 CallUpdate::Stats { .. } => {}
422 409 CallUpdate::Progress(progress) => self.progress = Some(progress),
423 CallUpdate::Roster(entries) => self.apply_roster(&entries),
424 CallUpdate::Speakers(mris) => self.speaking_mris = mris,
410 CallUpdate::Roster(entries) => {
411 self.apply_roster(&entries);
412 self.refresh_layout(Instant::now());
413 }
414 CallUpdate::Speakers(mris) => {
415 self.speaking_mris = mris;
416 self.refresh_layout(Instant::now());
417 }
425 418 CallUpdate::Lobby(lobby) => self.lobby = lobby,
426 419 CallUpdate::OwnIdentity { mri } => self.own_mri = Some(mri),
427 420 CallUpdate::ScreenShare(sharer) => self.screen_sharer = sharer,
@@ -579,6 +572,7 @@ impl CallModel {
579 572 } else {
580 573 Some(mri.to_owned())
581 574 };
575 self.refresh_layout(Instant::now());
582 576 }
583 577
584 578 pub fn is_spotlighted(&self, mri: &str) -> bool {
@@ -742,6 +736,128 @@ impl CallModel {
742 736 tiles
743 737 }
744 738
739 pub fn has_content(&self) -> bool {
740 self.screen_sharer.is_some() || self.whiteboard.is_some()
741 }
742
743 pub fn effective_layout(&self) -> CallLayout {
744 match self.view.layout {
745 CallLayout::Content if self.has_content() => CallLayout::Content,
746 CallLayout::Content => match self.view.layout_before_content {
747 CallLayout::Content => CallLayout::Gallery,
748 before => before,
749 },
750 layout => layout,
751 }
752 }
753
754 fn is_prioritized(&self, tile: &Tile) -> bool {
755 self.is_pinned(&tile.mri) || tile.spotlight.is_some() || tile.hand.is_some()
756 }
757
758 pub fn hidden_for_no_video(&self, tile: &Tile) -> bool {
759 self.view.hide_no_video
760 && matches!(self.kind, CallKind::Group | CallKind::Meeting)
761 && tile.state == TileState::Present
762 && !tile.has_video
763 && !self.is_pinned(&tile.mri)
764 && !self.tile_speaking(tile)
765 }
766
767 pub fn hidden_without_video(&self) -> usize {
768 self.visible_tiles()
769 .into_iter()
770 .filter(|tile| self.hidden_for_no_video(tile))
771 .count()
772 }
773
774 fn layout_members(&self) -> Vec<&Tile> {
775 let mut tiles: Vec<&Tile> = self
776 .visible_tiles()
777 .into_iter()
778 .filter(|tile| !self.hidden_for_no_video(tile))
779 .collect();
780 tiles.sort_by_key(|tile| !self.is_prioritized(tile));
781 tiles
782 }
783
784 pub fn layout_tiles(&self) -> Vec<&Tile> {
785 let members = self.layout_members();
786 let mut ordered: Vec<&Tile> = self
787 .rotation
788 .order()
789 .iter()
790 .filter_map(|mri| members.iter().find(|tile| &tile.mri == mri).copied())
791 .collect();
792 ordered.extend(
793 members
794 .into_iter()
795 .filter(|tile| !self.rotation.order().contains(&tile.mri)),
796 );
797 ordered
798 }
799
800 pub fn own_cells(&self) -> usize {
801 usize::from(!self.view.hide_me)
802 }
803
804 fn rotation_capacity(&self, others: usize) -> usize {
805 let cells = match self.effective_layout() {
806 _ if self.has_content() => return others,
807 CallLayout::Speaker => FILMSTRIP_MAX,
808 CallLayout::Gallery | CallLayout::Content => GALLERY_MAX,
809 };
810 split_overflow(others, self.own_cells(), cells).shown
811 }
812
813 pub fn refresh_layout(&mut self, now: Instant) -> bool {
814 let members: Vec<String> = self
815 .layout_members()
816 .iter()
817 .map(|tile| tile.mri.clone())
818 .collect();
819 let priority: Vec<String> = self
820 .layout_members()
821 .iter()
822 .filter(|tile| self.is_prioritized(tile))
823 .map(|tile| tile.mri.clone())
824 .collect();
825 let capacity = self.rotation_capacity(members.len());
826 let speaking = self.speaking_mris.clone();
827 self.rotation
828 .update(now, &members, &priority, &speaking, capacity)
829 }
830
831 pub fn speaker_focus(&self) -> Option<Focus> {
832 if let Some(focus) = self.focus() {
833 return Some(focus);
834 }
835 let tiles = self.layout_tiles();
836 let spoken = self
837 .speaking_mris
838 .iter()
839 .find(|mri| tiles.iter().any(|tile| &tile.mri == *mri))
840 .map(String::as_str)
841 .or_else(|| {
842 self.rotation
843 .last_speaker()
844 .filter(|mri| tiles.iter().any(|tile| tile.mri == *mri))
845 })
846 .or_else(|| tiles.first().map(|tile| tile.mri.as_str()));
847 let own_mri = self.own_mri.clone().filter(|_| self.own_cells() > 0);
848 let (mri, own) = match (spoken, own_mri) {
849 (Some(mri), _) => (mri.to_owned(), false),
850 (None, Some(own_mri)) => (own_mri, true),
851 (None, None) => return None,
852 };
853 Some(Focus {
854 mri,
855 own,
856 spotlight: false,
857 pinned: false,
858 })
859 }
860
745 861 pub fn sharing_label(&self) -> Option<String> {
746 862 let sharer = self.screen_sharer.as_ref()?;
747 863 let name = self
@@ -1227,61 +1343,107 @@ mod tests {
1227 1343 assert!(lone.tile_speaking(&lone.tiles[0].clone()));
1228 1344 }
1229 1345
1346 fn crowd(count: usize) -> CallModel {
1347 let mut model = meeting_with_me();
1348 model.apply(CallUpdate::Roster(
1349 (0..count)
1350 .map(|index| {
1351 entry(
1352 &format!("8:orgid:p{index}"),
1353 &format!("P{index}"),
1354 false,
1355 false,
1356 )
1357 })
1358 .collect(),
1359 ));
1360 model
1361 }
1362
1363 fn shown_mris(model: &CallModel) -> Vec<String> {
1364 model
1365 .layout_tiles()
1366 .iter()
1367 .map(|tile| tile.mri.clone())
1368 .collect()
1369 }
1370
1230 1371 #[test]
1231 fn more_than_nine_cells_collapse_into_a_plus_n_tile() {
1232 assert_eq!(
1233 grid_layout(0, MAX_TILES),
1234 GridLayout {
1235 shown_others: 0,
1236 hidden: 0
1237 }
1238 );
1239 assert_eq!(
1240 grid_layout(8, MAX_TILES),
1241 GridLayout {
1242 shown_others: 8,
1243 hidden: 0
1244 }
1245 );
1246 assert_eq!(
1247 grid_layout(9, MAX_TILES),
1248 GridLayout {
1249 shown_others: 7,
1250 hidden: 2
1251 }
1252 );
1253 assert_eq!(
1254 grid_layout(30, MAX_TILES),
1255 GridLayout {
1256 shown_others: 7,
1257 hidden: 23
1258 }
1259 );
1372 fn hiding_people_without_video_keeps_speakers_and_the_pinned_person() {
1373 let mut model = meeting_with_me();
1374 model.apply(CallUpdate::Roster(vec![
1375 entry("8:orgid:a", "Ana", false, false),
1376 RosterEntry {
1377 has_video: true,
1378 ..entry("8:orgid:b", "Bo", false, false)
1379 },
1380 entry("8:orgid:c", "Cy", false, false),
1381 ]));
1382 model.view.hide_no_video = true;
1383 assert_eq!(model.hidden_without_video(), 2);
1384 assert_eq!(shown_mris(&model), vec!["8:orgid:b"]);
1385 model.apply(CallUpdate::Speakers(vec!["8:orgid:a".into()]));
1386 assert_eq!(model.hidden_without_video(), 1);
1387 assert!(shown_mris(&model).contains(&"8:orgid:a".to_owned()));
1388 model.toggle_pin("8:orgid:c");
1389 assert_eq!(model.hidden_without_video(), 0);
1260 1390 }
1261 1391
1262 1392 #[test]
1263 fn an_open_chat_panel_leaves_room_for_fewer_tiles() {
1264 assert_eq!(
1265 grid_layout(5, CHAT_OPEN_TILES),
1266 GridLayout {
1267 shown_others: 5,
1268 hidden: 0
1269 }
1270 );
1271 assert_eq!(
1272 grid_layout(6, CHAT_OPEN_TILES),
1273 GridLayout {
1274 shown_others: 4,
1275 hidden: 2
1276 }
1277 );
1393 fn people_without_video_stay_in_one_to_one_calls() {
1394 let mut model = CallModel::people("Bea", &[("8:orgid:b".into(), "Bea".into())]);
1395 model.view.hide_no_video = true;
1396 model.apply(CallUpdate::Roster(vec![entry(
1397 "8:orgid:b",
1398 "Bea",
1399 false,
1400 false,
1401 )]));
1402 assert_eq!(model.hidden_without_video(), 0);
1403 }
1404
1405 #[test]
1406 fn focus_on_content_falls_back_to_the_previous_layout_when_the_share_ends() {
1407 let mut model = meeting_with_me();
1408 model.view.choose(CallLayout::Speaker);
1409 model.view.choose(CallLayout::Content);
1410 assert_eq!(model.effective_layout(), CallLayout::Speaker);
1411 model.apply(CallUpdate::ScreenShare(Some("8:orgid:a".into())));
1412 assert_eq!(model.effective_layout(), CallLayout::Content);
1413 model.apply(CallUpdate::ScreenShare(None));
1414 assert_eq!(model.effective_layout(), CallLayout::Speaker);
1415 }
1416
1417 #[test]
1418 fn the_speaker_stage_follows_the_active_speaker_and_keeps_the_last_one() {
1419 let mut model = crowd(3);
1420 model.apply(CallUpdate::Speakers(vec!["8:orgid:p1".into()]));
1421 assert_eq!(model.speaker_focus().unwrap().mri, "8:orgid:p1");
1422 model.apply(CallUpdate::Speakers(Vec::new()));
1423 assert_eq!(model.speaker_focus().unwrap().mri, "8:orgid:p1");
1424 model.toggle_pin("8:orgid:p2");
1425 let focus = model.speaker_focus().unwrap();
1426 assert_eq!((focus.mri.as_str(), focus.pinned), ("8:orgid:p2", true));
1427 }
1428
1429 #[test]
1430 fn a_pinned_person_outside_the_grid_moves_into_it() {
1431 let mut model = crowd(12);
1432 let grid = split_overflow(12, 1, GALLERY_MAX).shown;
1433 assert_eq!(grid, 7);
1434 assert!(!shown_mris(&model)[..grid].contains(&"8:orgid:p11".to_owned()));
1435 model.toggle_pin("8:orgid:p11");
1436 assert!(shown_mris(&model)[..grid].contains(&"8:orgid:p11".to_owned()));
1437 assert_eq!(model.layout_tiles().len(), 12);
1278 1438 }
1279 1439
1280 1440 #[test]
1281 fn crowded_calls_get_smaller_tiles() {
1282 assert_eq!(tile_size(2).avatar, 96.);
1283 assert_eq!(tile_size(4).avatar, 72.);
1284 assert_eq!(tile_size(9).avatar, 56.);
1441 fn hiding_me_frees_a_grid_cell() {
1442 let mut model = crowd(12);
1443 assert_eq!(model.own_cells(), 1);
1444 model.view.hide_me = true;
1445 assert_eq!(model.own_cells(), 0);
1446 assert_eq!(split_overflow(12, model.own_cells(), GALLERY_MAX).shown, 8);
1285 1447 }
1286 1448
1287 1449 #[test]
@@ -1,3 +1,5 @@
1use std::cell::Cell;
2use std::rc::Rc;
1use std::sync::Arc;
3use std::sync::Arc;
2use std::time::{Duration, Instant};
4use std::time::{Duration, Instant};
3
5
@@ -10,18 +12,21 @@ use tokio::sync::mpsc::UnboundedSender;
10
12
11use super::background::BackgroundPick;
13use super::background::BackgroundPick;
12use super::health::{HealthBanner, HealthState};
14use super::health::{HealthBanner, HealthState};
15use super::bubbles::ChatBubble;
16use super::fullscreen::FullscreenState;
13use super::pictures::CallPictures;
17use super::pictures::CallPictures;
18use super::stage_layout::{FILMSTRIP_MAX, GALLERY_MAX, VisibleRotation, split_overflow};
19use super::view_settings::{CallLayout, ViewSettings};
14
20
15pub const TEST_CALL_TITLE: &str = "Test call";
21pub const TEST_CALL_TITLE: &str = "Test call";
16pub const ECHO_NAME: &str = "Teams echo";
22pub const ECHO_NAME: &str = "Teams echo";
17pub const ECHO_MRI: &str = calling::signaling::ECHO_BOT_MRI;
23pub const ECHO_MRI: &str = calling::signaling::ECHO_BOT_MRI;
18pub const MAX_TILES: usize = 9;
19const ORGID_PREFIX: &str = "8:orgid:";
24const ORGID_PREFIX: &str = "8:orgid:";
20const WIDE_TILES: usize = 2;
25const AVATAR_SHARE: f32 = 0.42;
21const MEDIUM_TILES: usize = 4;
26const MIN_AVATAR: f32 = 32.;
27const MAX_AVATAR: f32 = 96.;
22pub const REACTION_SHOWN: Duration = Duration::from_secs(3);
28pub const REACTION_SHOWN: Duration = Duration::from_secs(3);
23const OWN_ECHO_WINDOW: Duration = Duration::from_secs(2);
29const OWN_ECHO_WINDOW: Duration = Duration::from_secs(2);
24pub const CHAT_OPEN_TILES: usize = 6;
25pub const CAPTION_SHOWN: Duration = Duration::from_secs(4);
30pub const CAPTION_SHOWN: Duration = Duration::from_secs(4);
26const CAPTION_LINES: usize = 2;
31const CAPTION_LINES: usize = 2;
27
32
@@ -34,6 +39,11 @@ pub struct ActiveCall {
34 pub video: Arc<VideoHub>,
39 pub video: Arc<VideoHub>,
35 pub pictures: CallPictures,
40 pub pictures: CallPictures,
36 pub stage_fullscreen: bool,
41 pub stage_fullscreen: bool,
42 pub fullscreen: Option<FullscreenState>,
43 pub stage_size: Rc<Cell<(f32, f32)>>,
44 pub bubbles: Vec<ChatBubble>,
45 pub share_menu_open: bool,
46 pub lobby_list_open: bool,
37 pub chat_open: bool,
47 pub chat_open: bool,
38 pub meeting_target: Option<MeetingTarget>,
48 pub meeting_target: Option<MeetingTarget>,
39 pub pending_move: Option<PendingMove>,
49 pub pending_move: Option<PendingMove>,
@@ -91,6 +101,11 @@ impl ActiveCall {
91 video,
101 video,
92 pictures: CallPictures::default(),
102 pictures: CallPictures::default(),
93 stage_fullscreen: false,
103 stage_fullscreen: false,
104 fullscreen: None,
105 stage_size: Rc::default(),
106 bubbles: Vec::new(),
107 share_menu_open: false,
108 lobby_list_open: false,
94 chat_open: false,
109 chat_open: false,
95 meeting_target: None,
110 meeting_target: None,
96 pending_move: None,
111 pending_move: None,
@@ -186,27 +201,6 @@ pub struct CaptionLine {
186 pub at: Instant,
201 pub at: Instant,
187}
202}
188
203
189#[derive(Debug, Clone, Copy, PartialEq, Eq)]
190pub struct GridLayout {
191 pub shown_others: usize,
192 pub hidden: usize,
193}
194
195pub fn grid_layout(others: usize, max_tiles: usize) -> GridLayout {
196 let total = others + 1;
197 if total <= max_tiles {
198 return GridLayout {
199 shown_others: others,
200 hidden: 0,
201 };
202 }
203 let shown_others = max_tiles - 2;
204 GridLayout {
205 shown_others,
206 hidden: others - shown_others,
207 }
208}
209
210#[derive(Debug, Clone, Copy, PartialEq)]
204#[derive(Debug, Clone, Copy, PartialEq)]
211pub struct TileSize {
205pub struct TileSize {
212 pub width: f32,
206 pub width: f32,
@@ -214,24 +208,13 @@ pub struct TileSize {
214 pub avatar: f32,
208 pub avatar: f32,
215}
209}
216
210
217pub fn tile_size(cells: usize) -> TileSize {
211impl TileSize {
218 if cells <= WIDE_TILES {
212 pub fn sixteen_by_nine(width: f32) -> TileSize {
219 TileSize {
213 let height = width * 9. / 16.;
220 width: 260.,
221 height: 210.,
222 avatar: 96.,
223 }
224 } else if cells <= MEDIUM_TILES {
225 TileSize {
214 TileSize {
226 width: 220.,
215 width,
227 height: 180.,
216 height,
228 avatar: 72.,
217 avatar: (height * AVATAR_SHARE).clamp(MIN_AVATAR, MAX_AVATAR),
229 }
230 } else {
231 TileSize {
232 width: 190.,
233 height: 150.,
234 avatar: 56.,
235 }
218 }
236 }
219 }
237}
220}
@@ -289,6 +272,8 @@ pub struct CallModel {
289 pub reactions: Vec<ReactionChip>,
272 pub reactions: Vec<ReactionChip>,
290 reaction_serial: u64,
273 reaction_serial: u64,
291 pub meeting_chat: Option<String>,
274 pub meeting_chat: Option<String>,
275 pub view: ViewSettings,
276 rotation: VisibleRotation,
292 local_detector: SpeakingDetector,
277 local_detector: SpeakingDetector,
293 remote_detector: SpeakingDetector,
278 remote_detector: SpeakingDetector,
294}
279}
@@ -339,6 +324,8 @@ impl CallModel {
339 reactions: Vec::new(),
324 reactions: Vec::new(),
340 reaction_serial: 0,
325 reaction_serial: 0,
341 meeting_chat: None,
326 meeting_chat: None,
327 view: ViewSettings::default(),
328 rotation: VisibleRotation::default(),
342 local_detector: SpeakingDetector::default(),
329 local_detector: SpeakingDetector::default(),
343 remote_detector: SpeakingDetector::default(),
330 remote_detector: SpeakingDetector::default(),
344 }
331 }
@@ -420,8 +407,14 @@ impl CallModel {
420 CallUpdate::ListenOnly(listen_only) => self.listen_only = listen_only,
407 CallUpdate::ListenOnly(listen_only) => self.listen_only = listen_only,
421 CallUpdate::Stats { .. } => {}
408 CallUpdate::Stats { .. } => {}
422 CallUpdate::Progress(progress) => self.progress = Some(progress),
409 CallUpdate::Progress(progress) => self.progress = Some(progress),
423 CallUpdate::Roster(entries) => self.apply_roster(&entries),
410 CallUpdate::Roster(entries) => {
424 CallUpdate::Speakers(mris) => self.speaking_mris = mris,
411 self.apply_roster(&entries);
412 self.refresh_layout(Instant::now());
413 }
414 CallUpdate::Speakers(mris) => {
415 self.speaking_mris = mris;
416 self.refresh_layout(Instant::now());
417 }
425 CallUpdate::Lobby(lobby) => self.lobby = lobby,
418 CallUpdate::Lobby(lobby) => self.lobby = lobby,
426 CallUpdate::OwnIdentity { mri } => self.own_mri = Some(mri),
419 CallUpdate::OwnIdentity { mri } => self.own_mri = Some(mri),
427 CallUpdate::ScreenShare(sharer) => self.screen_sharer = sharer,
420 CallUpdate::ScreenShare(sharer) => self.screen_sharer = sharer,
@@ -579,6 +572,7 @@ impl CallModel {
579 } else {
572 } else {
580 Some(mri.to_owned())
573 Some(mri.to_owned())
581 };
574 };
575 self.refresh_layout(Instant::now());
582 }
576 }
583
577
584 pub fn is_spotlighted(&self, mri: &str) -> bool {
578 pub fn is_spotlighted(&self, mri: &str) -> bool {
@@ -742,6 +736,128 @@ impl CallModel {
742 tiles
736 tiles
743 }
737 }
744
738
739 pub fn has_content(&self) -> bool {
740 self.screen_sharer.is_some() || self.whiteboard.is_some()
741 }
742
743 pub fn effective_layout(&self) -> CallLayout {
744 match self.view.layout {
745 CallLayout::Content if self.has_content() => CallLayout::Content,
746 CallLayout::Content => match self.view.layout_before_content {
747 CallLayout::Content => CallLayout::Gallery,
748 before => before,
749 },
750 layout => layout,
751 }
752 }
753
754 fn is_prioritized(&self, tile: &Tile) -> bool {
755 self.is_pinned(&tile.mri) || tile.spotlight.is_some() || tile.hand.is_some()
756 }
757
758 pub fn hidden_for_no_video(&self, tile: &Tile) -> bool {
759 self.view.hide_no_video
760 && matches!(self.kind, CallKind::Group | CallKind::Meeting)
761 && tile.state == TileState::Present
762 && !tile.has_video
763 && !self.is_pinned(&tile.mri)
764 && !self.tile_speaking(tile)
765 }
766
767 pub fn hidden_without_video(&self) -> usize {
768 self.visible_tiles()
769 .into_iter()
770 .filter(|tile| self.hidden_for_no_video(tile))
771 .count()
772 }
773
774 fn layout_members(&self) -> Vec<&Tile> {
775 let mut tiles: Vec<&Tile> = self
776 .visible_tiles()
777 .into_iter()
778 .filter(|tile| !self.hidden_for_no_video(tile))
779 .collect();
780 tiles.sort_by_key(|tile| !self.is_prioritized(tile));
781 tiles
782 }
783
784 pub fn layout_tiles(&self) -> Vec<&Tile> {
785 let members = self.layout_members();
786 let mut ordered: Vec<&Tile> = self
787 .rotation
788 .order()
789 .iter()
790 .filter_map(|mri| members.iter().find(|tile| &tile.mri == mri).copied())
791 .collect();
792 ordered.extend(
793 members
794 .into_iter()
795 .filter(|tile| !self.rotation.order().contains(&tile.mri)),
796 );
797 ordered
798 }
799
800 pub fn own_cells(&self) -> usize {
801 usize::from(!self.view.hide_me)
802 }
803
804 fn rotation_capacity(&self, others: usize) -> usize {
805 let cells = match self.effective_layout() {
806 _ if self.has_content() => return others,
807 CallLayout::Speaker => FILMSTRIP_MAX,
808 CallLayout::Gallery | CallLayout::Content => GALLERY_MAX,
809 };
810 split_overflow(others, self.own_cells(), cells).shown
811 }
812
813 pub fn refresh_layout(&mut self, now: Instant) -> bool {
814 let members: Vec<String> = self
815 .layout_members()
816 .iter()
817 .map(|tile| tile.mri.clone())
818 .collect();
819 let priority: Vec<String> = self
820 .layout_members()
821 .iter()
822 .filter(|tile| self.is_prioritized(tile))
823 .map(|tile| tile.mri.clone())
824 .collect();
825 let capacity = self.rotation_capacity(members.len());
826 let speaking = self.speaking_mris.clone();
827 self.rotation
828 .update(now, &members, &priority, &speaking, capacity)
829 }
830
831 pub fn speaker_focus(&self) -> Option<Focus> {
832 if let Some(focus) = self.focus() {
833 return Some(focus);
834 }
835 let tiles = self.layout_tiles();
836 let spoken = self
837 .speaking_mris
838 .iter()
839 .find(|mri| tiles.iter().any(|tile| &tile.mri == *mri))
840 .map(String::as_str)
841 .or_else(|| {
842 self.rotation
843 .last_speaker()
844 .filter(|mri| tiles.iter().any(|tile| tile.mri == *mri))
845 })
846 .or_else(|| tiles.first().map(|tile| tile.mri.as_str()));
847 let own_mri = self.own_mri.clone().filter(|_| self.own_cells() > 0);
848 let (mri, own) = match (spoken, own_mri) {
849 (Some(mri), _) => (mri.to_owned(), false),
850 (None, Some(own_mri)) => (own_mri, true),
851 (None, None) => return None,
852 };
853 Some(Focus {
854 mri,
855 own,
856 spotlight: false,
857 pinned: false,
858 })
859 }
860
745 pub fn sharing_label(&self) -> Option<String> {
861 pub fn sharing_label(&self) -> Option<String> {
746 let sharer = self.screen_sharer.as_ref()?;
862 let sharer = self.screen_sharer.as_ref()?;
747 let name = self
863 let name = self
@@ -1227,61 +1343,107 @@ mod tests {
1227 assert!(lone.tile_speaking(&lone.tiles[0].clone()));
1343 assert!(lone.tile_speaking(&lone.tiles[0].clone()));
1228 }
1344 }
1229
1345
1346 fn crowd(count: usize) -> CallModel {
1347 let mut model = meeting_with_me();
1348 model.apply(CallUpdate::Roster(
1349 (0..count)
1350 .map(|index| {
1351 entry(
1352 &format!("8:orgid:p{index}"),
1353 &format!("P{index}"),
1354 false,
1355 false,
1356 )
1357 })
1358 .collect(),
1359 ));
1360 model
1361 }
1362
1363 fn shown_mris(model: &CallModel) -> Vec<String> {
1364 model
1365 .layout_tiles()
1366 .iter()
1367 .map(|tile| tile.mri.clone())
1368 .collect()
1369 }
1370
1230 #[test]
1371 #[test]
1231 fn more_than_nine_cells_collapse_into_a_plus_n_tile() {
1372 fn hiding_people_without_video_keeps_speakers_and_the_pinned_person() {
1232 assert_eq!(
1373 let mut model = meeting_with_me();
1233 grid_layout(0, MAX_TILES),
1374 model.apply(CallUpdate::Roster(vec![
1234 GridLayout {
1375 entry("8:orgid:a", "Ana", false, false),
1235 shown_others: 0,
1376 RosterEntry {
1236 hidden: 0
1377 has_video: true,
1237 }
1378 ..entry("8:orgid:b", "Bo", false, false)
1238 );
1379 },
1239 assert_eq!(
1380 entry("8:orgid:c", "Cy", false, false),
1240 grid_layout(8, MAX_TILES),
1381 ]));
1241 GridLayout {
1382 model.view.hide_no_video = true;
1242 shown_others: 8,
1383 assert_eq!(model.hidden_without_video(), 2);
1243 hidden: 0
1384 assert_eq!(shown_mris(&model), vec!["8:orgid:b"]);
1244 }
1385 model.apply(CallUpdate::Speakers(vec!["8:orgid:a".into()]));
1245 );
1386 assert_eq!(model.hidden_without_video(), 1);
1246 assert_eq!(
1387 assert!(shown_mris(&model).contains(&"8:orgid:a".to_owned()));
1247 grid_layout(9, MAX_TILES),
1388 model.toggle_pin("8:orgid:c");
1248 GridLayout {
1389 assert_eq!(model.hidden_without_video(), 0);
1249 shown_others: 7,
1250 hidden: 2
1251 }
1252 );
1253 assert_eq!(
1254 grid_layout(30, MAX_TILES),
1255 GridLayout {
1256 shown_others: 7,
1257 hidden: 23
1258 }
1259 );
1260 }
1390 }
1261
1391
1262 #[test]
1392 #[test]
1263 fn an_open_chat_panel_leaves_room_for_fewer_tiles() {
1393 fn people_without_video_stay_in_one_to_one_calls() {
1264 assert_eq!(
1394 let mut model = CallModel::people("Bea", &[("8:orgid:b".into(), "Bea".into())]);
1265 grid_layout(5, CHAT_OPEN_TILES),
1395 model.view.hide_no_video = true;
1266 GridLayout {
1396 model.apply(CallUpdate::Roster(vec![entry(
1267 shown_others: 5,
1397 "8:orgid:b",
1268 hidden: 0
1398 "Bea",
1269 }
1399 false,
1270 );
1400 false,
1271 assert_eq!(
1401 )]));
1272 grid_layout(6, CHAT_OPEN_TILES),
1402 assert_eq!(model.hidden_without_video(), 0);
1273 GridLayout {
1403 }
1274 shown_others: 4,
1404
1275 hidden: 2
1405 #[test]
1276 }
1406 fn focus_on_content_falls_back_to_the_previous_layout_when_the_share_ends() {
1277 );
1407 let mut model = meeting_with_me();
1408 model.view.choose(CallLayout::Speaker);
1409 model.view.choose(CallLayout::Content);
1410 assert_eq!(model.effective_layout(), CallLayout::Speaker);
1411 model.apply(CallUpdate::ScreenShare(Some("8:orgid:a".into())));
1412 assert_eq!(model.effective_layout(), CallLayout::Content);
1413 model.apply(CallUpdate::ScreenShare(None));
1414 assert_eq!(model.effective_layout(), CallLayout::Speaker);
1415 }
1416
1417 #[test]
1418 fn the_speaker_stage_follows_the_active_speaker_and_keeps_the_last_one() {
1419 let mut model = crowd(3);
1420 model.apply(CallUpdate::Speakers(vec!["8:orgid:p1".into()]));
1421 assert_eq!(model.speaker_focus().unwrap().mri, "8:orgid:p1");
1422 model.apply(CallUpdate::Speakers(Vec::new()));
1423 assert_eq!(model.speaker_focus().unwrap().mri, "8:orgid:p1");
1424 model.toggle_pin("8:orgid:p2");
1425 let focus = model.speaker_focus().unwrap();
1426 assert_eq!((focus.mri.as_str(), focus.pinned), ("8:orgid:p2", true));
1427 }
1428
1429 #[test]
1430 fn a_pinned_person_outside_the_grid_moves_into_it() {
1431 let mut model = crowd(12);
1432 let grid = split_overflow(12, 1, GALLERY_MAX).shown;
1433 assert_eq!(grid, 7);
1434 assert!(!shown_mris(&model)[..grid].contains(&"8:orgid:p11".to_owned()));
1435 model.toggle_pin("8:orgid:p11");
1436 assert!(shown_mris(&model)[..grid].contains(&"8:orgid:p11".to_owned()));
1437 assert_eq!(model.layout_tiles().len(), 12);
1278 }
1438 }
1279
1439
1280 #[test]
1440 #[test]
1281 fn crowded_calls_get_smaller_tiles() {
1441 fn hiding_me_frees_a_grid_cell() {
1282 assert_eq!(tile_size(2).avatar, 96.);
1442 let mut model = crowd(12);
1283 assert_eq!(tile_size(4).avatar, 72.);
1443 assert_eq!(model.own_cells(), 1);
1284 assert_eq!(tile_size(9).avatar, 56.);
1444 model.view.hide_me = true;
1445 assert_eq!(model.own_cells(), 0);
1446 assert_eq!(split_overflow(12, model.own_cells(), GALLERY_MAX).shown, 8);
1285 }
1447 }
1286
1448
1287 #[test]
1449 #[test]
crates/app/src/call/stage_layout.rs added +471 −0
@@ -0,0 +1,471 @@
1 use std::collections::HashMap;
2 use std::time::{Duration, Instant};
3
4 pub const GALLERY_MAX: usize = 9;
5 pub const FILMSTRIP_MAX: usize = 6;
6 pub const FILMSTRIP_MIN_WIDTH: f32 = 160.;
7 pub const SWAP_AFTER_SPEAKING: Duration = Duration::from_secs(2);
8 pub const SWAP_INTERVAL: Duration = Duration::from_secs(5);
9 const TILE_ASPECT: f32 = 16. / 9.;
10
11 #[derive(Debug, Clone, Copy, PartialEq)]
12 pub struct GalleryGrid {
13 pub columns: usize,
14 pub tile_width: f32,
15 pub tile_height: f32,
16 }
17
18 pub fn gallery_grid(cells: usize, stage_width: f32, stage_height: f32, gap: f32) -> GalleryGrid {
19 let cells = cells.max(1);
20 let mut best = GalleryGrid {
21 columns: 1,
22 tile_width: 0.,
23 tile_height: 0.,
24 };
25 for columns in 1..=cells {
26 let rows = cells.div_ceil(columns);
27 let cell_width = (stage_width - gap * (columns - 1) as f32) / columns as f32;
28 let cell_height = (stage_height - gap * (rows - 1) as f32) / rows as f32;
29 let tile_width = cell_width.min(cell_height * TILE_ASPECT).max(0.);
30 if tile_width > best.tile_width {
31 best = GalleryGrid {
32 columns,
33 tile_width,
34 tile_height: tile_width / TILE_ASPECT,
35 };
36 }
37 }
38 best
39 }
40
41 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
42 pub struct Overflow {
43 pub shown: usize,
44 pub hidden: usize,
45 }
46
47 pub fn split_overflow(others: usize, own_cells: usize, capacity: usize) -> Overflow {
48 if others + own_cells <= capacity {
49 return Overflow {
50 shown: others,
51 hidden: 0,
52 };
53 }
54 let shown = capacity.saturating_sub(own_cells + 1);
55 Overflow {
56 shown,
57 hidden: others - shown,
58 }
59 }
60
61 #[derive(Debug, Clone, Copy, PartialEq)]
62 pub struct Filmstrip {
63 pub tile_width: f32,
64 pub tile_height: f32,
65 pub overflow: Overflow,
66 }
67
68 pub fn filmstrip(
69 others: usize,
70 own_cells: usize,
71 stage_width: f32,
72 gap: f32,
73 max_tile_width: f32,
74 ) -> Filmstrip {
75 let fitting = ((stage_width + gap) / (FILMSTRIP_MIN_WIDTH + gap)) as usize;
76 let capacity = FILMSTRIP_MAX.min(fitting.max(1));
77 let overflow = split_overflow(others, own_cells, capacity);
78 let cells = (overflow.shown + own_cells + usize::from(overflow.hidden > 0)).max(1);
79 let tile_width = ((stage_width - gap * (cells - 1) as f32) / cells as f32)
80 .clamp(FILMSTRIP_MIN_WIDTH, max_tile_width);
81 Filmstrip {
82 tile_width,
83 tile_height: tile_width / TILE_ASPECT,
84 overflow,
85 }
86 }
87
88 #[derive(Debug, Clone, Default)]
89 pub struct VisibleRotation {
90 order: Vec<String>,
91 speaking_since: HashMap<String, Instant>,
92 last_spoke: HashMap<String, Instant>,
93 last_swap: Option<Instant>,
94 }
95
96 impl VisibleRotation {
97 pub fn order(&self) -> &[String] {
98 &self.order
99 }
100
101 pub fn last_speaker(&self) -> Option<&str> {
102 self.order
103 .iter()
104 .filter_map(|mri| Some((mri, self.last_spoke.get(mri)?)))
105 .max_by_key(|(_, spoke)| **spoke)
106 .map(|(mri, _)| mri.as_str())
107 }
108
109 pub fn update(
110 &mut self,
111 now: Instant,
112 members: &[String],
113 priority: &[String],
114 speaking: &[String],
115 capacity: usize,
116 ) -> bool {
117 let before = self.order.clone();
118 self.track_speakers(now, speaking);
119 self.order.retain(|mri| members.contains(mri));
120 let mut arrivals: Vec<(usize, &String)> = members
121 .iter()
122 .enumerate()
123 .filter(|(_, mri)| !self.order.contains(mri))
124 .collect();
125 arrivals.sort_by_key(|(index, mri)| {
126 (
127 !priority.contains(mri),
128 std::cmp::Reverse(self.last_spoke.get(*mri).copied()),
129 *index,
130 )
131 });
132 self.order
133 .extend(arrivals.into_iter().map(|(_, mri)| mri.clone()));
134 if capacity > 0 && capacity < self.order.len() {
135 self.pull_in_priority(priority, capacity);
136 self.pull_in_speaker(now, priority, capacity);
137 }
138 self.order != before
139 }
140
141 fn track_speakers(&mut self, now: Instant, speaking: &[String]) {
142 self.speaking_since.retain(|mri, _| speaking.contains(mri));
143 for mri in speaking {
144 self.speaking_since.entry(mri.clone()).or_insert(now);
145 self.last_spoke.insert(mri.clone(), now);
146 }
147 }
148
149 fn pull_in_priority(&mut self, priority: &[String], capacity: usize) {
150 for mri in priority {
151 if let Some(index) = self.order.iter().position(|other| other == mri)
152 && index >= capacity
153 {
154 self.swap_in(index, priority, capacity);
155 }
156 }
157 }
158
159 fn pull_in_speaker(&mut self, now: Instant, priority: &[String], capacity: usize) {
160 let rested = self
161 .last_swap
162 .is_none_or(|swapped| now.saturating_duration_since(swapped) >= SWAP_INTERVAL);
163 if !rested {
164 return;
165 }
166 let candidate = self.order[capacity..]
167 .iter()
168 .enumerate()
169 .filter_map(|(offset, mri)| Some((capacity + offset, *self.speaking_since.get(mri)?)))
170 .filter(|(_, since)| now.saturating_duration_since(*since) >= SWAP_AFTER_SPEAKING)
171 .min_by_key(|(_, since)| *since);
172 if let Some((index, _)) = candidate
173 && self.swap_in(index, priority, capacity)
174 {
175 self.last_swap = Some(now);
176 }
177 }
178
179 fn swap_in(&mut self, index: usize, priority: &[String], capacity: usize) -> bool {
180 let victim = self.order[..capacity]
181 .iter()
182 .enumerate()
183 .filter(|(_, mri)| !priority.contains(mri))
184 .min_by_key(|(position, mri)| {
185 (
186 self.last_spoke.get(*mri).copied(),
187 std::cmp::Reverse(*position),
188 )
189 })
190 .map(|(position, _)| position);
191 let Some(victim) = victim else {
192 return false;
193 };
194 self.order.swap(victim, index);
195 true
196 }
197 }
198
199 #[cfg(test)]
200 mod tests {
201 use super::*;
202
203 fn names(count: usize) -> Vec<String> {
204 (0..count).map(|index| format!("p{index}")).collect()
205 }
206
207 fn visible(rotation: &VisibleRotation, capacity: usize) -> Vec<String> {
208 rotation.order()[..capacity].to_vec()
209 }
210
211 fn speak(mris: &[&str]) -> Vec<String> {
212 mris.iter().map(|mri| (*mri).to_owned()).collect()
213 }
214
215 #[test]
216 fn a_single_tile_takes_the_whole_stage() {
217 let grid = gallery_grid(1, 1600., 900., 20.);
218 assert_eq!(grid.columns, 1);
219 assert!((grid.tile_width - 1600.).abs() < 0.01);
220 }
221
222 #[test]
223 fn two_tiles_sit_side_by_side_on_a_wide_stage() {
224 let grid = gallery_grid(2, 1600., 900., 20.);
225 assert_eq!(grid.columns, 2);
226 assert_eq!(grid.tile_width, 790.);
227 }
228
229 #[test]
230 fn nine_tiles_make_three_by_three_and_fit_the_stage() {
231 let grid = gallery_grid(9, 1600., 900., 20.);
232 assert_eq!(grid.columns, 3);
233 assert!(grid.tile_width * 3. + 40. <= 1600.);
234 assert!(grid.tile_height * 3. + 40. <= 900.);
235 }
236
237 #[test]
238 fn a_tall_stage_prefers_fewer_columns() {
239 let grid = gallery_grid(4, 500., 1200., 20.);
240 assert_eq!(grid.columns, 1);
241 }
242
243 #[test]
244 fn tiles_stay_sixteen_by_nine() {
245 let grid = gallery_grid(7, 1234., 777., 20.);
246 assert!((grid.tile_width / grid.tile_height - 16. / 9.).abs() < 0.001);
247 }
248
249 #[test]
250 fn nine_people_fit_and_ten_end_in_a_plus_tile() {
251 assert_eq!(
252 split_overflow(8, 1, GALLERY_MAX),
253 Overflow {
254 shown: 8,
255 hidden: 0
256 }
257 );
258 assert_eq!(
259 split_overflow(9, 1, GALLERY_MAX),
260 Overflow {
261 shown: 7,
262 hidden: 2
263 }
264 );
265 assert_eq!(
266 split_overflow(12, 0, GALLERY_MAX),
267 Overflow {
268 shown: 8,
269 hidden: 4
270 }
271 );
272 }
273
274 #[test]
275 fn the_filmstrip_holds_six_tiles_then_a_plus_tile() {
276 let strip = filmstrip(5, 1, 1600., 12., 240.);
277 assert_eq!(strip.overflow.hidden, 0);
278 let strip = filmstrip(6, 1, 1600., 12., 240.);
279 assert_eq!(
280 strip.overflow,
281 Overflow {
282 shown: 4,
283 hidden: 2
284 }
285 );
286 assert_eq!(strip.tile_width, 240.);
287 }
288
289 #[test]
290 fn a_narrow_filmstrip_keeps_tiles_at_the_minimum_and_adds_the_plus_tile() {
291 let strip = filmstrip(5, 1, 504., 12., 240.);
292 assert_eq!(strip.tile_width, FILMSTRIP_MIN_WIDTH);
293 assert_eq!(strip.tile_height, 90.);
294 assert_eq!(
295 strip.overflow,
296 Overflow {
297 shown: 1,
298 hidden: 4
299 }
300 );
301 }
302
303 #[test]
304 fn new_members_start_in_priority_order_and_stay_put() {
305 let mut rotation = VisibleRotation::default();
306 let now = Instant::now();
307 let members = names(5);
308 rotation.update(now, &members, &speak(&["p3"]), &[], 4);
309 assert_eq!(rotation.order()[0], "p3");
310 let before = visible(&rotation, 4);
311 rotation.update(now, &members, &speak(&["p3"]), &[], 4);
312 assert_eq!(visible(&rotation, 4), before);
313 }
314
315 #[test]
316 fn an_outside_speaker_swaps_in_only_after_two_seconds_of_speech() {
317 let mut rotation = VisibleRotation::default();
318 let start = Instant::now();
319 let members = names(6);
320 rotation.update(start, &members, &[], &[], 4);
321 let outside = "p5";
322 rotation.update(start, &members, &[], &speak(&[outside]), 4);
323 rotation.update(
324 start + Duration::from_millis(1900),
325 &members,
326 &[],
327 &speak(&[outside]),
328 4,
329 );
330 assert!(!visible(&rotation, 4).contains(&outside.to_owned()));
331 rotation.update(
332 start + SWAP_AFTER_SPEAKING,
333 &members,
334 &[],
335 &speak(&[outside]),
336 4,
337 );
338 assert!(visible(&rotation, 4).contains(&outside.to_owned()));
339 }
340
341 #[test]
342 fn interrupted_speech_restarts_the_two_second_clock() {
343 let mut rotation = VisibleRotation::default();
344 let start = Instant::now();
345 let members = names(6);
346 rotation.update(start, &members, &[], &[], 4);
347 rotation.update(start, &members, &[], &speak(&["p5"]), 4);
348 rotation.update(start + Duration::from_millis(1500), &members, &[], &[], 4);
349 rotation.update(
350 start + Duration::from_millis(2500),
351 &members,
352 &[],
353 &speak(&["p5"]),
354 4,
355 );
356 rotation.update(
357 start + Duration::from_millis(3500),
358 &members,
359 &[],
360 &speak(&["p5"]),
361 4,
362 );
363 assert!(!visible(&rotation, 4).contains(&"p5".to_owned()));
364 }
365
366 #[test]
367 fn the_least_recently_speaking_visible_tile_is_replaced_and_the_others_keep_their_slots() {
368 let mut rotation = VisibleRotation::default();
369 let start = Instant::now();
370 let members = names(6);
371 rotation.update(start, &members, &[], &[], 4);
372 rotation.update(start, &members, &[], &speak(&["p0", "p1", "p3"]), 4);
373 let before = visible(&rotation, 4);
374 rotation.update(start, &members, &[], &speak(&["p5", "p0", "p1", "p3"]), 4);
375 rotation.update(
376 start + SWAP_AFTER_SPEAKING,
377 &members,
378 &[],
379 &speak(&["p5", "p0", "p1", "p3"]),
380 4,
381 );
382 let after = visible(&rotation, 4);
383 let slot = before.iter().position(|mri| mri == "p2").unwrap();
384 assert_eq!(after[slot], "p5");
385 for (index, mri) in before
386 .iter()
387 .enumerate()
388 .filter(|(index, _)| *index != slot)
389 {
390 assert_eq!(&after[index], mri);
391 }
392 }
393
394 #[test]
395 fn at_most_one_speaker_swaps_in_per_five_seconds() {
396 let mut rotation = VisibleRotation::default();
397 let start = Instant::now();
398 let members = names(7);
399 rotation.update(start, &members, &[], &[], 4);
400 let talking = speak(&["p5", "p6"]);
401 rotation.update(start, &members, &[], &talking, 4);
402 rotation.update(start + SWAP_AFTER_SPEAKING, &members, &[], &talking, 4);
403 let swapped = visible(&rotation, 4)
404 .iter()
405 .filter(|mri| *mri == "p5" || *mri == "p6")
406 .count();
407 assert_eq!(swapped, 1);
408 rotation.update(
409 start + SWAP_AFTER_SPEAKING + Duration::from_secs(4),
410 &members,
411 &[],
412 &talking,
413 4,
414 );
415 let still = visible(&rotation, 4)
416 .iter()
417 .filter(|mri| *mri == "p5" || *mri == "p6")
418 .count();
419 assert_eq!(still, 1);
420 rotation.update(
421 start + SWAP_AFTER_SPEAKING + SWAP_INTERVAL,
422 &members,
423 &[],
424 &talking,
425 4,
426 );
427 let both = visible(&rotation, 4)
428 .iter()
429 .filter(|mri| *mri == "p5" || *mri == "p6")
430 .count();
431 assert_eq!(both, 2);
432 }
433
434 #[test]
435 fn a_pinned_person_outside_the_grid_swaps_in_at_once_and_is_never_replaced() {
436 let mut rotation = VisibleRotation::default();
437 let start = Instant::now();
438 let members = names(6);
439 rotation.update(start, &members, &[], &[], 4);
440 let pinned = speak(&["p5"]);
441 rotation.update(start, &members, &pinned, &[], 4);
442 assert!(visible(&rotation, 4).contains(&"p5".to_owned()));
443 let talking = speak(&["p4"]);
444 rotation.update(
445 start + Duration::from_secs(1),
446 &members,
447 &pinned,
448 &talking,
449 4,
450 );
451 rotation.update(
452 start + Duration::from_secs(4),
453 &members,
454 &pinned,
455 &talking,
456 4,
457 );
458 assert!(visible(&rotation, 4).contains(&"p5".to_owned()));
459 }
460
461 #[test]
462 fn people_who_leave_drop_out_and_the_next_one_moves_up() {
463 let mut rotation = VisibleRotation::default();
464 let now = Instant::now();
465 let members = names(5);
466 rotation.update(now, &members, &[], &[], 3);
467 let remaining: Vec<String> = members.into_iter().filter(|mri| mri != "p1").collect();
468 rotation.update(now, &remaining, &[], &[], 3);
469 assert_eq!(visible(&rotation, 3), vec!["p0", "p2", "p3"]);
470 }
471 }
@@ -0,0 +1,471 @@
1use std::collections::HashMap;
2use std::time::{Duration, Instant};
3
4pub const GALLERY_MAX: usize = 9;
5pub const FILMSTRIP_MAX: usize = 6;
6pub const FILMSTRIP_MIN_WIDTH: f32 = 160.;
7pub const SWAP_AFTER_SPEAKING: Duration = Duration::from_secs(2);
8pub const SWAP_INTERVAL: Duration = Duration::from_secs(5);
9const TILE_ASPECT: f32 = 16. / 9.;
10
11#[derive(Debug, Clone, Copy, PartialEq)]
12pub struct GalleryGrid {
13 pub columns: usize,
14 pub tile_width: f32,
15 pub tile_height: f32,
16}
17
18pub fn gallery_grid(cells: usize, stage_width: f32, stage_height: f32, gap: f32) -> GalleryGrid {
19 let cells = cells.max(1);
20 let mut best = GalleryGrid {
21 columns: 1,
22 tile_width: 0.,
23 tile_height: 0.,
24 };
25 for columns in 1..=cells {
26 let rows = cells.div_ceil(columns);
27 let cell_width = (stage_width - gap * (columns - 1) as f32) / columns as f32;
28 let cell_height = (stage_height - gap * (rows - 1) as f32) / rows as f32;
29 let tile_width = cell_width.min(cell_height * TILE_ASPECT).max(0.);
30 if tile_width > best.tile_width {
31 best = GalleryGrid {
32 columns,
33 tile_width,
34 tile_height: tile_width / TILE_ASPECT,
35 };
36 }
37 }
38 best
39}
40
41#[derive(Debug, Clone, Copy, PartialEq, Eq)]
42pub struct Overflow {
43 pub shown: usize,
44 pub hidden: usize,
45}
46
47pub fn split_overflow(others: usize, own_cells: usize, capacity: usize) -> Overflow {
48 if others + own_cells <= capacity {
49 return Overflow {
50 shown: others,
51 hidden: 0,
52 };
53 }
54 let shown = capacity.saturating_sub(own_cells + 1);
55 Overflow {
56 shown,
57 hidden: others - shown,
58 }
59}
60
61#[derive(Debug, Clone, Copy, PartialEq)]
62pub struct Filmstrip {
63 pub tile_width: f32,
64 pub tile_height: f32,
65 pub overflow: Overflow,
66}
67
68pub fn filmstrip(
69 others: usize,
70 own_cells: usize,
71 stage_width: f32,
72 gap: f32,
73 max_tile_width: f32,
74) -> Filmstrip {
75 let fitting = ((stage_width + gap) / (FILMSTRIP_MIN_WIDTH + gap)) as usize;
76 let capacity = FILMSTRIP_MAX.min(fitting.max(1));
77 let overflow = split_overflow(others, own_cells, capacity);
78 let cells = (overflow.shown + own_cells + usize::from(overflow.hidden > 0)).max(1);
79 let tile_width = ((stage_width - gap * (cells - 1) as f32) / cells as f32)
80 .clamp(FILMSTRIP_MIN_WIDTH, max_tile_width);
81 Filmstrip {
82 tile_width,
83 tile_height: tile_width / TILE_ASPECT,
84 overflow,
85 }
86}
87
88#[derive(Debug, Clone, Default)]
89pub struct VisibleRotation {
90 order: Vec<String>,
91 speaking_since: HashMap<String, Instant>,
92 last_spoke: HashMap<String, Instant>,
93 last_swap: Option<Instant>,
94}
95
96impl VisibleRotation {
97 pub fn order(&self) -> &[String] {
98 &self.order
99 }
100
101 pub fn last_speaker(&self) -> Option<&str> {
102 self.order
103 .iter()
104 .filter_map(|mri| Some((mri, self.last_spoke.get(mri)?)))
105 .max_by_key(|(_, spoke)| **spoke)
106 .map(|(mri, _)| mri.as_str())
107 }
108
109 pub fn update(
110 &mut self,
111 now: Instant,
112 members: &[String],
113 priority: &[String],
114 speaking: &[String],
115 capacity: usize,
116 ) -> bool {
117 let before = self.order.clone();
118 self.track_speakers(now, speaking);
119 self.order.retain(|mri| members.contains(mri));
120 let mut arrivals: Vec<(usize, &String)> = members
121 .iter()
122 .enumerate()
123 .filter(|(_, mri)| !self.order.contains(mri))
124 .collect();
125 arrivals.sort_by_key(|(index, mri)| {
126 (
127 !priority.contains(mri),
128 std::cmp::Reverse(self.last_spoke.get(*mri).copied()),
129 *index,
130 )
131 });
132 self.order
133 .extend(arrivals.into_iter().map(|(_, mri)| mri.clone()));
134 if capacity > 0 && capacity < self.order.len() {
135 self.pull_in_priority(priority, capacity);
136 self.pull_in_speaker(now, priority, capacity);
137 }
138 self.order != before
139 }
140
141 fn track_speakers(&mut self, now: Instant, speaking: &[String]) {
142 self.speaking_since.retain(|mri, _| speaking.contains(mri));
143 for mri in speaking {
144 self.speaking_since.entry(mri.clone()).or_insert(now);
145 self.last_spoke.insert(mri.clone(), now);
146 }
147 }
148
149 fn pull_in_priority(&mut self, priority: &[String], capacity: usize) {
150 for mri in priority {
151 if let Some(index) = self.order.iter().position(|other| other == mri)
152 && index >= capacity
153 {
154 self.swap_in(index, priority, capacity);
155 }
156 }
157 }
158
159 fn pull_in_speaker(&mut self, now: Instant, priority: &[String], capacity: usize) {
160 let rested = self
161 .last_swap
162 .is_none_or(|swapped| now.saturating_duration_since(swapped) >= SWAP_INTERVAL);
163 if !rested {
164 return;
165 }
166 let candidate = self.order[capacity..]
167 .iter()
168 .enumerate()
169 .filter_map(|(offset, mri)| Some((capacity + offset, *self.speaking_since.get(mri)?)))
170 .filter(|(_, since)| now.saturating_duration_since(*since) >= SWAP_AFTER_SPEAKING)
171 .min_by_key(|(_, since)| *since);
172 if let Some((index, _)) = candidate
173 && self.swap_in(index, priority, capacity)
174 {
175 self.last_swap = Some(now);
176 }
177 }
178
179 fn swap_in(&mut self, index: usize, priority: &[String], capacity: usize) -> bool {
180 let victim = self.order[..capacity]
181 .iter()
182 .enumerate()
183 .filter(|(_, mri)| !priority.contains(mri))
184 .min_by_key(|(position, mri)| {
185 (
186 self.last_spoke.get(*mri).copied(),
187 std::cmp::Reverse(*position),
188 )
189 })
190 .map(|(position, _)| position);
191 let Some(victim) = victim else {
192 return false;
193 };
194 self.order.swap(victim, index);
195 true
196 }
197}
198
199#[cfg(test)]
200mod tests {
201 use super::*;
202
203 fn names(count: usize) -> Vec<String> {
204 (0..count).map(|index| format!("p{index}")).collect()
205 }
206
207 fn visible(rotation: &VisibleRotation, capacity: usize) -> Vec<String> {
208 rotation.order()[..capacity].to_vec()
209 }
210
211 fn speak(mris: &[&str]) -> Vec<String> {
212 mris.iter().map(|mri| (*mri).to_owned()).collect()
213 }
214
215 #[test]
216 fn a_single_tile_takes_the_whole_stage() {
217 let grid = gallery_grid(1, 1600., 900., 20.);
218 assert_eq!(grid.columns, 1);
219 assert!((grid.tile_width - 1600.).abs() < 0.01);
220 }
221
222 #[test]
223 fn two_tiles_sit_side_by_side_on_a_wide_stage() {
224 let grid = gallery_grid(2, 1600., 900., 20.);
225 assert_eq!(grid.columns, 2);
226 assert_eq!(grid.tile_width, 790.);
227 }
228
229 #[test]
230 fn nine_tiles_make_three_by_three_and_fit_the_stage() {
231 let grid = gallery_grid(9, 1600., 900., 20.);
232 assert_eq!(grid.columns, 3);
233 assert!(grid.tile_width * 3. + 40. <= 1600.);
234 assert!(grid.tile_height * 3. + 40. <= 900.);
235 }
236
237 #[test]
238 fn a_tall_stage_prefers_fewer_columns() {
239 let grid = gallery_grid(4, 500., 1200., 20.);
240 assert_eq!(grid.columns, 1);
241 }
242
243 #[test]
244 fn tiles_stay_sixteen_by_nine() {
245 let grid = gallery_grid(7, 1234., 777., 20.);
246 assert!((grid.tile_width / grid.tile_height - 16. / 9.).abs() < 0.001);
247 }
248
249 #[test]
250 fn nine_people_fit_and_ten_end_in_a_plus_tile() {
251 assert_eq!(
252 split_overflow(8, 1, GALLERY_MAX),
253 Overflow {
254 shown: 8,
255 hidden: 0
256 }
257 );
258 assert_eq!(
259 split_overflow(9, 1, GALLERY_MAX),
260 Overflow {
261 shown: 7,
262 hidden: 2
263 }
264 );
265 assert_eq!(
266 split_overflow(12, 0, GALLERY_MAX),
267 Overflow {
268 shown: 8,
269 hidden: 4
270 }
271 );
272 }
273
274 #[test]
275 fn the_filmstrip_holds_six_tiles_then_a_plus_tile() {
276 let strip = filmstrip(5, 1, 1600., 12., 240.);
277 assert_eq!(strip.overflow.hidden, 0);
278 let strip = filmstrip(6, 1, 1600., 12., 240.);
279 assert_eq!(
280 strip.overflow,
281 Overflow {
282 shown: 4,
283 hidden: 2
284 }
285 );
286 assert_eq!(strip.tile_width, 240.);
287 }
288
289 #[test]
290 fn a_narrow_filmstrip_keeps_tiles_at_the_minimum_and_adds_the_plus_tile() {
291 let strip = filmstrip(5, 1, 504., 12., 240.);
292 assert_eq!(strip.tile_width, FILMSTRIP_MIN_WIDTH);
293 assert_eq!(strip.tile_height, 90.);
294 assert_eq!(
295 strip.overflow,
296 Overflow {
297 shown: 1,
298 hidden: 4
299 }
300 );
301 }
302
303 #[test]
304 fn new_members_start_in_priority_order_and_stay_put() {
305 let mut rotation = VisibleRotation::default();
306 let now = Instant::now();
307 let members = names(5);
308 rotation.update(now, &members, &speak(&["p3"]), &[], 4);
309 assert_eq!(rotation.order()[0], "p3");
310 let before = visible(&rotation, 4);
311 rotation.update(now, &members, &speak(&["p3"]), &[], 4);
312 assert_eq!(visible(&rotation, 4), before);
313 }
314
315 #[test]
316 fn an_outside_speaker_swaps_in_only_after_two_seconds_of_speech() {
317 let mut rotation = VisibleRotation::default();
318 let start = Instant::now();
319 let members = names(6);
320 rotation.update(start, &members, &[], &[], 4);
321 let outside = "p5";
322 rotation.update(start, &members, &[], &speak(&[outside]), 4);
323 rotation.update(
324 start + Duration::from_millis(1900),
325 &members,
326 &[],
327 &speak(&[outside]),
328 4,
329 );
330 assert!(!visible(&rotation, 4).contains(&outside.to_owned()));
331 rotation.update(
332 start + SWAP_AFTER_SPEAKING,
333 &members,
334 &[],
335 &speak(&[outside]),
336 4,
337 );
338 assert!(visible(&rotation, 4).contains(&outside.to_owned()));
339 }
340
341 #[test]
342 fn interrupted_speech_restarts_the_two_second_clock() {
343 let mut rotation = VisibleRotation::default();
344 let start = Instant::now();
345 let members = names(6);
346 rotation.update(start, &members, &[], &[], 4);
347 rotation.update(start, &members, &[], &speak(&["p5"]), 4);
348 rotation.update(start + Duration::from_millis(1500), &members, &[], &[], 4);
349 rotation.update(
350 start + Duration::from_millis(2500),
351 &members,
352 &[],
353 &speak(&["p5"]),
354 4,
355 );
356 rotation.update(
357 start + Duration::from_millis(3500),
358 &members,
359 &[],
360 &speak(&["p5"]),
361 4,
362 );
363 assert!(!visible(&rotation, 4).contains(&"p5".to_owned()));
364 }
365
366 #[test]
367 fn the_least_recently_speaking_visible_tile_is_replaced_and_the_others_keep_their_slots() {
368 let mut rotation = VisibleRotation::default();
369 let start = Instant::now();
370 let members = names(6);
371 rotation.update(start, &members, &[], &[], 4);
372 rotation.update(start, &members, &[], &speak(&["p0", "p1", "p3"]), 4);
373 let before = visible(&rotation, 4);
374 rotation.update(start, &members, &[], &speak(&["p5", "p0", "p1", "p3"]), 4);
375 rotation.update(
376 start + SWAP_AFTER_SPEAKING,
377 &members,
378 &[],
379 &speak(&["p5", "p0", "p1", "p3"]),
380 4,
381 );
382 let after = visible(&rotation, 4);
383 let slot = before.iter().position(|mri| mri == "p2").unwrap();
384 assert_eq!(after[slot], "p5");
385 for (index, mri) in before
386 .iter()
387 .enumerate()
388 .filter(|(index, _)| *index != slot)
389 {
390 assert_eq!(&after[index], mri);
391 }
392 }
393
394 #[test]
395 fn at_most_one_speaker_swaps_in_per_five_seconds() {
396 let mut rotation = VisibleRotation::default();
397 let start = Instant::now();
398 let members = names(7);
399 rotation.update(start, &members, &[], &[], 4);
400 let talking = speak(&["p5", "p6"]);
401 rotation.update(start, &members, &[], &talking, 4);
402 rotation.update(start + SWAP_AFTER_SPEAKING, &members, &[], &talking, 4);
403 let swapped = visible(&rotation, 4)
404 .iter()
405 .filter(|mri| *mri == "p5" || *mri == "p6")
406 .count();
407 assert_eq!(swapped, 1);
408 rotation.update(
409 start + SWAP_AFTER_SPEAKING + Duration::from_secs(4),
410 &members,
411 &[],
412 &talking,
413 4,
414 );
415 let still = visible(&rotation, 4)
416 .iter()
417 .filter(|mri| *mri == "p5" || *mri == "p6")
418 .count();
419 assert_eq!(still, 1);
420 rotation.update(
421 start + SWAP_AFTER_SPEAKING + SWAP_INTERVAL,
422 &members,
423 &[],
424 &talking,
425 4,
426 );
427 let both = visible(&rotation, 4)
428 .iter()
429 .filter(|mri| *mri == "p5" || *mri == "p6")
430 .count();
431 assert_eq!(both, 2);
432 }
433
434 #[test]
435 fn a_pinned_person_outside_the_grid_swaps_in_at_once_and_is_never_replaced() {
436 let mut rotation = VisibleRotation::default();
437 let start = Instant::now();
438 let members = names(6);
439 rotation.update(start, &members, &[], &[], 4);
440 let pinned = speak(&["p5"]);
441 rotation.update(start, &members, &pinned, &[], 4);
442 assert!(visible(&rotation, 4).contains(&"p5".to_owned()));
443 let talking = speak(&["p4"]);
444 rotation.update(
445 start + Duration::from_secs(1),
446 &members,
447 &pinned,
448 &talking,
449 4,
450 );
451 rotation.update(
452 start + Duration::from_secs(4),
453 &members,
454 &pinned,
455 &talking,
456 4,
457 );
458 assert!(visible(&rotation, 4).contains(&"p5".to_owned()));
459 }
460
461 #[test]
462 fn people_who_leave_drop_out_and_the_next_one_moves_up() {
463 let mut rotation = VisibleRotation::default();
464 let now = Instant::now();
465 let members = names(5);
466 rotation.update(now, &members, &[], &[], 3);
467 let remaining: Vec<String> = members.into_iter().filter(|mri| mri != "p1").collect();
468 rotation.update(now, &remaining, &[], &[], 3);
469 assert_eq!(visible(&rotation, 3), vec!["p0", "p2", "p3"]);
470 }
471}
crates/app/src/call/view_actions.rs added +277 −0
@@ -0,0 +1,277 @@
1 use std::time::{Duration, Instant};
2
3 use gpui_kit::*;
4
5 use super::bubbles::{BUBBLE_SHOWN, ChatBubble, push_bubble};
6 use super::fullscreen::{FullscreenState, HINT_SHOWN};
7 use super::view_settings::{CallLayout, ViewSettings};
8 use crate::app_state::{AppEvent, AppState};
9
10 const CHROME_TOUCH_THROTTLE: Duration = Duration::from_millis(250);
11 const DEMO_BUBBLE_START: Duration = Duration::from_secs(8);
12 const DEMO_BUBBLE_EVERY: Duration = Duration::from_secs(7);
13 const DEMO_BUBBLES: [(&str, &str); 4] = [
14 ("Jonas Ortega", "Slides are in the channel now"),
15 (
16 "Priya Nair",
17 "Can you share the release notes with us before we start the demo?",
18 ),
19 ("Lea Schneider", "Looks good to me, thanks"),
20 ("Tobias Klein", "I will join the retro in five minutes"),
21 ];
22 const TIMER_SLACK: Duration = Duration::from_millis(30);
23
24 impl AppState {
25 fn change_call_view(&mut self, change: impl FnOnce(&mut ViewSettings), cx: &mut Context<Self>) {
26 change(&mut self.call_view);
27 self.call_view.hide_me = false;
28 self.call_view.save(&self.store);
29 if let Some(call) = self.call.as_mut() {
30 let hide_me = call.model.view.hide_me;
31 call.model.view = self.call_view;
32 call.model.view.hide_me = hide_me;
33 call.model.refresh_layout(Instant::now());
34 }
35 cx.notify();
36 }
37
38 pub fn set_call_layout(&mut self, layout: CallLayout, cx: &mut Context<Self>) {
39 self.change_call_view(|view| view.choose(layout), cx);
40 }
41
42 pub fn toggle_call_hide_no_video(&mut self, cx: &mut Context<Self>) {
43 self.change_call_view(|view| view.hide_no_video = !view.hide_no_video, cx);
44 }
45
46 pub fn toggle_call_chat_bubbles(&mut self, cx: &mut Context<Self>) {
47 self.change_call_view(|view| view.chat_bubbles = !view.chat_bubbles, cx);
48 }
49
50 pub fn set_call_hide_me(&mut self, hidden: bool, cx: &mut Context<Self>) {
51 if let Some(call) = self.call.as_mut() {
52 call.model.view.hide_me = hidden;
53 call.model.refresh_layout(Instant::now());
54 cx.notify();
55 }
56 }
57
58 pub fn tick_call_layout(&mut self, cx: &mut Context<Self>) {
59 let changed = self
60 .call
61 .as_mut()
62 .is_some_and(|call| call.model.refresh_layout(Instant::now()));
63 if changed {
64 cx.notify();
65 }
66 }
67
68 pub fn toggle_call_fullscreen(&mut self, cx: &mut Context<Self>) {
69 let Some(call) = self.call.as_mut().filter(|call| call.viewing) else {
70 return;
71 };
72 call.fullscreen = match call.fullscreen {
73 Some(_) => None,
74 None => Some(FullscreenState::new(Instant::now())),
75 };
76 self.watch_fullscreen_chrome(cx);
77 cx.emit(AppEvent::Call);
78 cx.notify();
79 }
80
81 pub fn escape_call_fullscreen(&mut self, cx: &mut Context<Self>) {
82 if self.stage_fullscreen() {
83 self.leave_stage_fullscreen(cx);
84 return;
85 }
86 let Some(call) = self.call.as_mut().filter(|call| call.fullscreen.is_some()) else {
87 return;
88 };
89 call.fullscreen = None;
90 cx.emit(AppEvent::Call);
91 cx.notify();
92 }
93
94 pub fn call_fullscreen(&self) -> bool {
95 self.call
96 .as_ref()
97 .is_some_and(|call| call.viewing && call.fullscreen.is_some())
98 }
99
100 pub fn touch_call_chrome(&mut self, cx: &mut Context<Self>) {
101 let now = Instant::now();
102 let Some(fullscreen) = self.call.as_mut().and_then(|call| call.fullscreen.as_mut()) else {
103 return;
104 };
105 let was_visible = fullscreen.chrome_visible(now);
106 if was_visible
107 && now.saturating_duration_since(fullscreen.active_at) < CHROME_TOUCH_THROTTLE
108 {
109 return;
110 }
111 fullscreen.active_at = now;
112 if !was_visible {
113 self.watch_fullscreen_chrome(cx);
114 cx.notify();
115 }
116 }
117
118 pub fn set_call_chrome_hovered(&mut self, hovered: bool, cx: &mut Context<Self>) {
119 let Some(fullscreen) = self
120 .call
121 .as_mut()
122 .and_then(|call| call.fullscreen.as_mut())
123 .filter(|fullscreen| fullscreen.hovered != hovered)
124 else {
125 return;
126 };
127 fullscreen.hovered = hovered;
128 fullscreen.active_at = Instant::now();
129 self.watch_fullscreen_chrome(cx);
130 cx.notify();
131 }
132
133 fn watch_fullscreen_chrome(&mut self, cx: &mut Context<Self>) {
134 let Some(call) = self.call.as_mut() else {
135 return;
136 };
137 let call_id = call.id;
138 let Some(fullscreen) = call
139 .fullscreen
140 .as_mut()
141 .filter(|fullscreen| !fullscreen.timer_running)
142 else {
143 return;
144 };
145 fullscreen.timer_running = true;
146 cx.spawn(async move |this, cx| {
147 while let Ok(Some(wait)) =
148 this.update(cx, |state, cx| state.fullscreen_tick(call_id, cx))
149 {
150 cx.background_executor().timer(wait).await;
151 }
152 })
153 .detach();
154 }
155
156 fn fullscreen_tick(&mut self, call_id: u64, cx: &mut Context<Self>) -> Option<Duration> {
157 cx.notify();
158 let now = Instant::now();
159 let fullscreen = self
160 .call
161 .as_mut()
162 .filter(|call| call.id == call_id)
163 .and_then(|call| call.fullscreen.as_mut())?;
164 let hint_left =
165 HINT_SHOWN.saturating_sub(now.saturating_duration_since(fullscreen.entered));
166 let next = [
167 fullscreen.next_change(now),
168 (!hint_left.is_zero()).then_some(hint_left),
169 ]
170 .into_iter()
171 .flatten()
172 .min();
173 if next.is_none() {
174 fullscreen.timer_running = false;
175 }
176 next.map(|wait| wait + TIMER_SLACK)
177 }
178
179 pub fn note_call_chat_message(
180 &mut self,
181 conversation_id: &str,
182 message_id: &str,
183 sender_id: Option<String>,
184 sender_name: &str,
185 text: &str,
186 cx: &mut Context<Self>,
187 ) {
188 let Some(call) = self.call.as_mut().filter(|call| {
189 !call.chat_open
190 && call.model.view.chat_bubbles
191 && call.chat_thread() == Some(conversation_id)
192 }) else {
193 return;
194 };
195 push_bubble(
196 &mut call.bubbles,
197 ChatBubble {
198 id: message_id.to_owned(),
199 sender_id,
200 name: sender_name.to_owned(),
201 text: text.to_owned(),
202 at: Instant::now(),
203 },
204 );
205 cx.spawn(async move |this, cx| {
206 cx.background_executor()
207 .timer(BUBBLE_SHOWN + TIMER_SLACK)
208 .await;
209 this.update(cx, |_, cx| cx.notify()).ok();
210 })
211 .detach();
212 cx.notify();
213 }
214
215 pub fn set_call_share_menu(&mut self, open: bool, cx: &mut Context<Self>) {
216 if let Some(call) = self.call.as_mut() {
217 call.share_menu_open = open;
218 cx.notify();
219 }
220 }
221
222 pub fn set_call_lobby_list(&mut self, open: bool, cx: &mut Context<Self>) {
223 if let Some(call) = self.call.as_mut() {
224 call.lobby_list_open = open;
225 cx.notify();
226 }
227 }
228
229 pub fn toggle_call_share(&mut self, cx: &mut Context<Self>) {
230 let Some(call) = self.call.as_ref() else {
231 return;
232 };
233 if call.model.local_share.is_some() {
234 self.stop_call_share(cx);
235 return;
236 }
237 if call.model.can_share() {
238 self.show_call(true, cx);
239 self.set_call_share_menu(true, cx);
240 }
241 }
242
243 pub fn open_call_lobby_list(&mut self, cx: &mut Context<Self>) {
244 let waiting = self
245 .call
246 .as_ref()
247 .is_some_and(|call| call.model.can_admit() && !call.model.lobby_guests().is_empty());
248 if waiting {
249 self.show_call(true, cx);
250 self.set_call_lobby_list(true, cx);
251 }
252 }
253
254 pub(super) fn queue_demo_bubbles(&mut self, thread: &str, cx: &mut Context<Self>) {
255 let thread = thread.to_owned();
256 cx.spawn(async move |this, cx| {
257 cx.background_executor().timer(DEMO_BUBBLE_START).await;
258 for (index, (name, text)) in DEMO_BUBBLES.iter().enumerate() {
259 let sent = this.update(cx, |state, cx| {
260 state.note_call_chat_message(
261 &thread,
262 &format!("demo-bubble-{index}"),
263 Some(format!("demo-guest-{index}")),
264 name,
265 text,
266 cx,
267 )
268 });
269 if sent.is_err() {
270 return;
271 }
272 cx.background_executor().timer(DEMO_BUBBLE_EVERY).await;
273 }
274 })
275 .detach();
276 }
277 }
@@ -0,0 +1,277 @@
1use std::time::{Duration, Instant};
2
3use gpui_kit::*;
4
5use super::bubbles::{BUBBLE_SHOWN, ChatBubble, push_bubble};
6use super::fullscreen::{FullscreenState, HINT_SHOWN};
7use super::view_settings::{CallLayout, ViewSettings};
8use crate::app_state::{AppEvent, AppState};
9
10const CHROME_TOUCH_THROTTLE: Duration = Duration::from_millis(250);
11const DEMO_BUBBLE_START: Duration = Duration::from_secs(8);
12const DEMO_BUBBLE_EVERY: Duration = Duration::from_secs(7);
13const DEMO_BUBBLES: [(&str, &str); 4] = [
14 ("Jonas Ortega", "Slides are in the channel now"),
15 (
16 "Priya Nair",
17 "Can you share the release notes with us before we start the demo?",
18 ),
19 ("Lea Schneider", "Looks good to me, thanks"),
20 ("Tobias Klein", "I will join the retro in five minutes"),
21];
22const TIMER_SLACK: Duration = Duration::from_millis(30);
23
24impl AppState {
25 fn change_call_view(&mut self, change: impl FnOnce(&mut ViewSettings), cx: &mut Context<Self>) {
26 change(&mut self.call_view);
27 self.call_view.hide_me = false;
28 self.call_view.save(&self.store);
29 if let Some(call) = self.call.as_mut() {
30 let hide_me = call.model.view.hide_me;
31 call.model.view = self.call_view;
32 call.model.view.hide_me = hide_me;
33 call.model.refresh_layout(Instant::now());
34 }
35 cx.notify();
36 }
37
38 pub fn set_call_layout(&mut self, layout: CallLayout, cx: &mut Context<Self>) {
39 self.change_call_view(|view| view.choose(layout), cx);
40 }
41
42 pub fn toggle_call_hide_no_video(&mut self, cx: &mut Context<Self>) {
43 self.change_call_view(|view| view.hide_no_video = !view.hide_no_video, cx);
44 }
45
46 pub fn toggle_call_chat_bubbles(&mut self, cx: &mut Context<Self>) {
47 self.change_call_view(|view| view.chat_bubbles = !view.chat_bubbles, cx);
48 }
49
50 pub fn set_call_hide_me(&mut self, hidden: bool, cx: &mut Context<Self>) {
51 if let Some(call) = self.call.as_mut() {
52 call.model.view.hide_me = hidden;
53 call.model.refresh_layout(Instant::now());
54 cx.notify();
55 }
56 }
57
58 pub fn tick_call_layout(&mut self, cx: &mut Context<Self>) {
59 let changed = self
60 .call
61 .as_mut()
62 .is_some_and(|call| call.model.refresh_layout(Instant::now()));
63 if changed {
64 cx.notify();
65 }
66 }
67
68 pub fn toggle_call_fullscreen(&mut self, cx: &mut Context<Self>) {
69 let Some(call) = self.call.as_mut().filter(|call| call.viewing) else {
70 return;
71 };
72 call.fullscreen = match call.fullscreen {
73 Some(_) => None,
74 None => Some(FullscreenState::new(Instant::now())),
75 };
76 self.watch_fullscreen_chrome(cx);
77 cx.emit(AppEvent::Call);
78 cx.notify();
79 }
80
81 pub fn escape_call_fullscreen(&mut self, cx: &mut Context<Self>) {
82 if self.stage_fullscreen() {
83 self.leave_stage_fullscreen(cx);
84 return;
85 }
86 let Some(call) = self.call.as_mut().filter(|call| call.fullscreen.is_some()) else {
87 return;
88 };
89 call.fullscreen = None;
90 cx.emit(AppEvent::Call);
91 cx.notify();
92 }
93
94 pub fn call_fullscreen(&self) -> bool {
95 self.call
96 .as_ref()
97 .is_some_and(|call| call.viewing && call.fullscreen.is_some())
98 }
99
100 pub fn touch_call_chrome(&mut self, cx: &mut Context<Self>) {
101 let now = Instant::now();
102 let Some(fullscreen) = self.call.as_mut().and_then(|call| call.fullscreen.as_mut()) else {
103 return;
104 };
105 let was_visible = fullscreen.chrome_visible(now);
106 if was_visible
107 && now.saturating_duration_since(fullscreen.active_at) < CHROME_TOUCH_THROTTLE
108 {
109 return;
110 }
111 fullscreen.active_at = now;
112 if !was_visible {
113 self.watch_fullscreen_chrome(cx);
114 cx.notify();
115 }
116 }
117
118 pub fn set_call_chrome_hovered(&mut self, hovered: bool, cx: &mut Context<Self>) {
119 let Some(fullscreen) = self
120 .call
121 .as_mut()
122 .and_then(|call| call.fullscreen.as_mut())
123 .filter(|fullscreen| fullscreen.hovered != hovered)
124 else {
125 return;
126 };
127 fullscreen.hovered = hovered;
128 fullscreen.active_at = Instant::now();
129 self.watch_fullscreen_chrome(cx);
130 cx.notify();
131 }
132
133 fn watch_fullscreen_chrome(&mut self, cx: &mut Context<Self>) {
134 let Some(call) = self.call.as_mut() else {
135 return;
136 };
137 let call_id = call.id;
138 let Some(fullscreen) = call
139 .fullscreen
140 .as_mut()
141 .filter(|fullscreen| !fullscreen.timer_running)
142 else {
143 return;
144 };
145 fullscreen.timer_running = true;
146 cx.spawn(async move |this, cx| {
147 while let Ok(Some(wait)) =
148 this.update(cx, |state, cx| state.fullscreen_tick(call_id, cx))
149 {
150 cx.background_executor().timer(wait).await;
151 }
152 })
153 .detach();
154 }
155
156 fn fullscreen_tick(&mut self, call_id: u64, cx: &mut Context<Self>) -> Option<Duration> {
157 cx.notify();
158 let now = Instant::now();
159 let fullscreen = self
160 .call
161 .as_mut()
162 .filter(|call| call.id == call_id)
163 .and_then(|call| call.fullscreen.as_mut())?;
164 let hint_left =
165 HINT_SHOWN.saturating_sub(now.saturating_duration_since(fullscreen.entered));
166 let next = [
167 fullscreen.next_change(now),
168 (!hint_left.is_zero()).then_some(hint_left),
169 ]
170 .into_iter()
171 .flatten()
172 .min();
173 if next.is_none() {
174 fullscreen.timer_running = false;
175 }
176 next.map(|wait| wait + TIMER_SLACK)
177 }
178
179 pub fn note_call_chat_message(
180 &mut self,
181 conversation_id: &str,
182 message_id: &str,
183 sender_id: Option<String>,
184 sender_name: &str,
185 text: &str,
186 cx: &mut Context<Self>,
187 ) {
188 let Some(call) = self.call.as_mut().filter(|call| {
189 !call.chat_open
190 && call.model.view.chat_bubbles
191 && call.chat_thread() == Some(conversation_id)
192 }) else {
193 return;
194 };
195 push_bubble(
196 &mut call.bubbles,
197 ChatBubble {
198 id: message_id.to_owned(),
199 sender_id,
200 name: sender_name.to_owned(),
201 text: text.to_owned(),
202 at: Instant::now(),
203 },
204 );
205 cx.spawn(async move |this, cx| {
206 cx.background_executor()
207 .timer(BUBBLE_SHOWN + TIMER_SLACK)
208 .await;
209 this.update(cx, |_, cx| cx.notify()).ok();
210 })
211 .detach();
212 cx.notify();
213 }
214
215 pub fn set_call_share_menu(&mut self, open: bool, cx: &mut Context<Self>) {
216 if let Some(call) = self.call.as_mut() {
217 call.share_menu_open = open;
218 cx.notify();
219 }
220 }
221
222 pub fn set_call_lobby_list(&mut self, open: bool, cx: &mut Context<Self>) {
223 if let Some(call) = self.call.as_mut() {
224 call.lobby_list_open = open;
225 cx.notify();
226 }
227 }
228
229 pub fn toggle_call_share(&mut self, cx: &mut Context<Self>) {
230 let Some(call) = self.call.as_ref() else {
231 return;
232 };
233 if call.model.local_share.is_some() {
234 self.stop_call_share(cx);
235 return;
236 }
237 if call.model.can_share() {
238 self.show_call(true, cx);
239 self.set_call_share_menu(true, cx);
240 }
241 }
242
243 pub fn open_call_lobby_list(&mut self, cx: &mut Context<Self>) {
244 let waiting = self
245 .call
246 .as_ref()
247 .is_some_and(|call| call.model.can_admit() && !call.model.lobby_guests().is_empty());
248 if waiting {
249 self.show_call(true, cx);
250 self.set_call_lobby_list(true, cx);
251 }
252 }
253
254 pub(super) fn queue_demo_bubbles(&mut self, thread: &str, cx: &mut Context<Self>) {
255 let thread = thread.to_owned();
256 cx.spawn(async move |this, cx| {
257 cx.background_executor().timer(DEMO_BUBBLE_START).await;
258 for (index, (name, text)) in DEMO_BUBBLES.iter().enumerate() {
259 let sent = this.update(cx, |state, cx| {
260 state.note_call_chat_message(
261 &thread,
262 &format!("demo-bubble-{index}"),
263 Some(format!("demo-guest-{index}")),
264 name,
265 text,
266 cx,
267 )
268 });
269 if sent.is_err() {
270 return;
271 }
272 cx.background_executor().timer(DEMO_BUBBLE_EVERY).await;
273 }
274 })
275 .detach();
276 }
277}
crates/app/src/call/view_settings.rs added +139 −0
@@ -0,0 +1,139 @@
1 const LAYOUT_META_KEY: &str = "call_layout";
2 const HIDE_NO_VIDEO_META_KEY: &str = "call_hide_no_video";
3 const CHAT_BUBBLES_META_KEY: &str = "call_chat_bubbles";
4
5 #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
6 pub enum CallLayout {
7 #[default]
8 Gallery,
9 Speaker,
10 Content,
11 }
12
13 impl CallLayout {
14 pub fn label(self) -> &'static str {
15 match self {
16 CallLayout::Gallery => "Gallery",
17 CallLayout::Speaker => "Speaker",
18 CallLayout::Content => "Focus on content",
19 }
20 }
21
22 fn meta(self) -> &'static str {
23 match self {
24 CallLayout::Gallery => "gallery",
25 CallLayout::Speaker => "speaker",
26 CallLayout::Content => "content",
27 }
28 }
29
30 fn from_meta(value: &str) -> CallLayout {
31 match value {
32 "speaker" => CallLayout::Speaker,
33 "content" => CallLayout::Content,
34 _ => CallLayout::Gallery,
35 }
36 }
37 }
38
39 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
40 pub struct ViewSettings {
41 pub layout: CallLayout,
42 pub layout_before_content: CallLayout,
43 pub hide_no_video: bool,
44 pub chat_bubbles: bool,
45 pub hide_me: bool,
46 }
47
48 impl Default for ViewSettings {
49 fn default() -> Self {
50 ViewSettings {
51 layout: CallLayout::Gallery,
52 layout_before_content: CallLayout::Gallery,
53 hide_no_video: false,
54 chat_bubbles: true,
55 hide_me: false,
56 }
57 }
58 }
59
60 impl ViewSettings {
61 pub fn load(store: &store::Store) -> ViewSettings {
62 let flag = |key: &str, default: bool| match store.meta(key).ok().flatten().as_deref() {
63 Some("1") => true,
64 Some("0") => false,
65 _ => default,
66 };
67 let layout = store
68 .meta(LAYOUT_META_KEY)
69 .ok()
70 .flatten()
71 .map_or(CallLayout::Gallery, |value| CallLayout::from_meta(&value));
72 ViewSettings {
73 layout,
74 hide_no_video: flag(HIDE_NO_VIDEO_META_KEY, false),
75 chat_bubbles: flag(CHAT_BUBBLES_META_KEY, true),
76 ..ViewSettings::default()
77 }
78 }
79
80 pub fn save(&self, store: &store::Store) {
81 let _ = store.set_meta(LAYOUT_META_KEY, self.layout.meta());
82 let _ = store.set_meta(
83 HIDE_NO_VIDEO_META_KEY,
84 if self.hide_no_video { "1" } else { "0" },
85 );
86 let _ = store.set_meta(
87 CHAT_BUBBLES_META_KEY,
88 if self.chat_bubbles { "1" } else { "0" },
89 );
90 }
91
92 pub fn choose(&mut self, layout: CallLayout) {
93 if layout == CallLayout::Content && self.layout != CallLayout::Content {
94 self.layout_before_content = self.layout;
95 }
96 self.layout = layout;
97 }
98 }
99
100 #[cfg(test)]
101 mod tests {
102 use super::*;
103
104 #[test]
105 fn the_defaults_are_gallery_with_bubbles_on() {
106 let store = store::Store::open_in_memory().unwrap();
107 let settings = ViewSettings::load(&store);
108 assert_eq!(settings.layout, CallLayout::Gallery);
109 assert!(settings.chat_bubbles);
110 assert!(!settings.hide_no_video);
111 assert!(!settings.hide_me);
112 }
113
114 #[test]
115 fn choices_survive_a_restart() {
116 let store = store::Store::open_in_memory().unwrap();
117 let mut settings = ViewSettings::load(&store);
118 settings.choose(CallLayout::Speaker);
119 settings.hide_no_video = true;
120 settings.chat_bubbles = false;
121 settings.hide_me = true;
122 settings.save(&store);
123 let loaded = ViewSettings::load(&store);
124 assert_eq!(loaded.layout, CallLayout::Speaker);
125 assert!(loaded.hide_no_video);
126 assert!(!loaded.chat_bubbles);
127 assert!(!loaded.hide_me);
128 }
129
130 #[test]
131 fn content_remembers_the_layout_to_fall_back_to() {
132 let mut settings = ViewSettings::default();
133 settings.choose(CallLayout::Speaker);
134 settings.choose(CallLayout::Content);
135 assert_eq!(settings.layout_before_content, CallLayout::Speaker);
136 settings.choose(CallLayout::Content);
137 assert_eq!(settings.layout_before_content, CallLayout::Speaker);
138 }
139 }
@@ -0,0 +1,139 @@
1const LAYOUT_META_KEY: &str = "call_layout";
2const HIDE_NO_VIDEO_META_KEY: &str = "call_hide_no_video";
3const CHAT_BUBBLES_META_KEY: &str = "call_chat_bubbles";
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
6pub enum CallLayout {
7 #[default]
8 Gallery,
9 Speaker,
10 Content,
11}
12
13impl CallLayout {
14 pub fn label(self) -> &'static str {
15 match self {
16 CallLayout::Gallery => "Gallery",
17 CallLayout::Speaker => "Speaker",
18 CallLayout::Content => "Focus on content",
19 }
20 }
21
22 fn meta(self) -> &'static str {
23 match self {
24 CallLayout::Gallery => "gallery",
25 CallLayout::Speaker => "speaker",
26 CallLayout::Content => "content",
27 }
28 }
29
30 fn from_meta(value: &str) -> CallLayout {
31 match value {
32 "speaker" => CallLayout::Speaker,
33 "content" => CallLayout::Content,
34 _ => CallLayout::Gallery,
35 }
36 }
37}
38
39#[derive(Debug, Clone, Copy, PartialEq, Eq)]
40pub struct ViewSettings {
41 pub layout: CallLayout,
42 pub layout_before_content: CallLayout,
43 pub hide_no_video: bool,
44 pub chat_bubbles: bool,
45 pub hide_me: bool,
46}
47
48impl Default for ViewSettings {
49 fn default() -> Self {
50 ViewSettings {
51 layout: CallLayout::Gallery,
52 layout_before_content: CallLayout::Gallery,
53 hide_no_video: false,
54 chat_bubbles: true,
55 hide_me: false,
56 }
57 }
58}
59
60impl ViewSettings {
61 pub fn load(store: &store::Store) -> ViewSettings {
62 let flag = |key: &str, default: bool| match store.meta(key).ok().flatten().as_deref() {
63 Some("1") => true,
64 Some("0") => false,
65 _ => default,
66 };
67 let layout = store
68 .meta(LAYOUT_META_KEY)
69 .ok()
70 .flatten()
71 .map_or(CallLayout::Gallery, |value| CallLayout::from_meta(&value));
72 ViewSettings {
73 layout,
74 hide_no_video: flag(HIDE_NO_VIDEO_META_KEY, false),
75 chat_bubbles: flag(CHAT_BUBBLES_META_KEY, true),
76 ..ViewSettings::default()
77 }
78 }
79
80 pub fn save(&self, store: &store::Store) {
81 let _ = store.set_meta(LAYOUT_META_KEY, self.layout.meta());
82 let _ = store.set_meta(
83 HIDE_NO_VIDEO_META_KEY,
84 if self.hide_no_video { "1" } else { "0" },
85 );
86 let _ = store.set_meta(
87 CHAT_BUBBLES_META_KEY,
88 if self.chat_bubbles { "1" } else { "0" },
89 );
90 }
91
92 pub fn choose(&mut self, layout: CallLayout) {
93 if layout == CallLayout::Content && self.layout != CallLayout::Content {
94 self.layout_before_content = self.layout;
95 }
96 self.layout = layout;
97 }
98}
99
100#[cfg(test)]
101mod tests {
102 use super::*;
103
104 #[test]
105 fn the_defaults_are_gallery_with_bubbles_on() {
106 let store = store::Store::open_in_memory().unwrap();
107 let settings = ViewSettings::load(&store);
108 assert_eq!(settings.layout, CallLayout::Gallery);
109 assert!(settings.chat_bubbles);
110 assert!(!settings.hide_no_video);
111 assert!(!settings.hide_me);
112 }
113
114 #[test]
115 fn choices_survive_a_restart() {
116 let store = store::Store::open_in_memory().unwrap();
117 let mut settings = ViewSettings::load(&store);
118 settings.choose(CallLayout::Speaker);
119 settings.hide_no_video = true;
120 settings.chat_bubbles = false;
121 settings.hide_me = true;
122 settings.save(&store);
123 let loaded = ViewSettings::load(&store);
124 assert_eq!(loaded.layout, CallLayout::Speaker);
125 assert!(loaded.hide_no_video);
126 assert!(!loaded.chat_bubbles);
127 assert!(!loaded.hide_me);
128 }
129
130 #[test]
131 fn content_remembers_the_layout_to_fall_back_to() {
132 let mut settings = ViewSettings::default();
133 settings.choose(CallLayout::Speaker);
134 settings.choose(CallLayout::Content);
135 assert_eq!(settings.layout_before_content, CallLayout::Speaker);
136 settings.choose(CallLayout::Content);
137 assert_eq!(settings.layout_before_content, CallLayout::Speaker);
138 }
139}
crates/app/src/layout_guard.rs +64 −4
@@ -120,7 +120,13 @@ mod frames {
120 120 };
121 121 use store::Store;
122 122
123 use std::time::Instant;
124
125 use calling::{CallState, CallUpdate, RosterEntry, call_channel};
126 use gpui_kit::Entity;
127
123 128 use crate::app_state::{AppState, Mode};
129 use crate::call::{ActiveCall, CallModel};
124 130 use crate::demo;
125 131 use crate::user_activity::UserInput;
126 132 use crate::views::shell::{AppShell, Startup, bind_keys, install_globals};
@@ -138,6 +144,11 @@ mod frames {
138 144 "shell/islands/main",
139 145 "shell/status-bar",
140 146 ];
147 const CALL_GUARDED: &[&str] = &[
148 "shell/islands/main/call-header",
149 "shell/islands/main/call-stage",
150 "shell/islands/main/call-controls",
151 ];
141 152 const MENU: &str = "popup-menu";
142 153 const OWN_STATUS: &str = "shell/title-bar/own-status";
143 154 const SIZES: [(f32, f32); 2] = [(640., 480.), (1920., 1080.)];
@@ -149,6 +160,7 @@ mod frames {
149 160 enum Screen {
150 161 Tab(&'static str, Option<fn(&mut VisualTestContext)>),
151 162 StatusMenu,
163 Call,
152 164 }
153 165
154 166 fn parent_of(path: &str) -> Option<&str> {
@@ -263,12 +275,37 @@ mod frames {
263 275 }
264 276 GUARDED
265 277 .iter()
278 .chain(CALL_GUARDED)
266 279 .chain([&MENU])
267 280 .filter_map(|path| visual.debug_bounds(path).map(|bounds| (*path, bounds)))
268 281 .collect()
269 282 }
270 283
271 fn mount(cx: &mut TestAppContext) -> gpui_kit::AnyWindowHandle {
284 fn gallery_call() -> ActiveCall {
285 let (handle, _control) = call_channel();
286 let mut model = CallModel::meeting("Standup", false);
287 model.apply(CallUpdate::State(CallState::Connected {
288 since: Instant::now(),
289 }));
290 model.apply(CallUpdate::Roster(
291 (0..11)
292 .map(|index| RosterEntry {
293 mri: format!("8:orgid:guard-{index}"),
294 display_name: format!("Guest {index}"),
295 muted: false,
296 in_lobby: false,
297 has_video: false,
298 sharing: false,
299 hand: None,
300 spotlight: None,
301 organizer: false,
302 })
303 .collect(),
304 ));
305 ActiveCall::new(1, model, handle.commands, None, handle.video)
306 }
307
308 fn mount(cx: &mut TestAppContext) -> (gpui_kit::AnyWindowHandle, Entity<AppState>) {
272 309 cx.update(gpui_kit::init);
273 310 cx.update(|cx| {
274 311 crate::theme::apply(cx);
@@ -283,16 +320,18 @@ mod frames {
283 320 let state = cx.new(|_| AppState::new(Arc::new(store), mode));
284 321 install_globals(&state, UserInput::new(), cx);
285 322 demo::start_session(&state, cx);
323 let shared_state = state.clone();
286 324 let startup = Startup {
287 325 switcher_query: None,
288 326 composer_text: None,
289 327 reply_to_last: false,
290 328 };
291 gpui_kit::open_window(WindowOptions::default(), cx, move |window, cx| {
329 let window = gpui_kit::open_window(WindowOptions::default(), cx, move |window, cx| {
292 330 cx.new(|cx| AppShell::new(state, None, startup, window, cx))
293 331 })
294 332 .expect("open test window")
295 .0
333 .0;
334 (window, shared_state)
296 335 })
297 336 }
298 337
@@ -329,7 +368,7 @@ mod frames {
329 368
330 369 #[gpui_kit::test]
331 370 fn no_element_overlaps_or_leaves_its_container(cx: &mut TestAppContext) {
332 let handle = mount(cx);
371 let (handle, app) = mount(cx);
333 372 let mut visual = VisualTestContext::from_window(handle, cx);
334 373 let mut seen_known = HashSet::new();
335 374 let mut unexpected = Vec::new();
@@ -352,6 +391,7 @@ mod frames {
352 391 Screen::Tab("saved", Some(|visual| visual.dispatch_action(OpenSaved))),
353 392 Screen::Tab("calls", Some(|visual| visual.dispatch_action(OpenCallsTab))),
354 393 Screen::StatusMenu,
394 Screen::Call,
355 395 ];
356 396 for screen in screens {
357 397 let (screen_name, status_menu) = match screen {
@@ -361,6 +401,15 @@ mod frames {
361 401 }
362 402 (name, false)
363 403 }
404 Screen::Call => {
405 visual.update(|_, cx| {
406 app.update(cx, |state, cx| {
407 state.call = Some(gallery_call());
408 cx.notify();
409 })
410 });
411 ("call", false)
412 }
364 413 Screen::StatusMenu => {
365 414 let tags = collect(&mut visual, None);
366 415 let button = tags
@@ -374,6 +423,9 @@ mod frames {
374 423 };
375 424 let tags = collect(&mut visual, status_menu.then_some(MENU));
376 425 let mut expected = GUARDED.to_vec();
426 if screen_name == "call" {
427 expected.extend(CALL_GUARDED);
428 }
377 429 if status_menu {
378 430 expected.push(MENU);
379 431 }
@@ -402,6 +454,14 @@ mod frames {
402 454 visual.simulate_keystrokes("escape");
403 455 visual.run_until_parked();
404 456 }
457 if screen_name == "call" {
458 visual.update(|_, cx| {
459 app.update(cx, |state, cx| {
460 state.call = None;
461 cx.notify();
462 })
463 });
464 }
405 465 for (key, message) in found {
406 466 let full_key = format!("{screen_name}@{width}x{height}:{key}");
407 467 if KNOWN_VIOLATIONS.contains(&full_key.as_str()) {
@@ -120,7 +120,13 @@ mod frames {
120 };
120 };
121 use store::Store;
121 use store::Store;
122
122
123 use std::time::Instant;
124
125 use calling::{CallState, CallUpdate, RosterEntry, call_channel};
126 use gpui_kit::Entity;
127
123 use crate::app_state::{AppState, Mode};
128 use crate::app_state::{AppState, Mode};
129 use crate::call::{ActiveCall, CallModel};
124 use crate::demo;
130 use crate::demo;
125 use crate::user_activity::UserInput;
131 use crate::user_activity::UserInput;
126 use crate::views::shell::{AppShell, Startup, bind_keys, install_globals};
132 use crate::views::shell::{AppShell, Startup, bind_keys, install_globals};
@@ -138,6 +144,11 @@ mod frames {
138 "shell/islands/main",
144 "shell/islands/main",
139 "shell/status-bar",
145 "shell/status-bar",
140 ];
146 ];
147 const CALL_GUARDED: &[&str] = &[
148 "shell/islands/main/call-header",
149 "shell/islands/main/call-stage",
150 "shell/islands/main/call-controls",
151 ];
141 const MENU: &str = "popup-menu";
152 const MENU: &str = "popup-menu";
142 const OWN_STATUS: &str = "shell/title-bar/own-status";
153 const OWN_STATUS: &str = "shell/title-bar/own-status";
143 const SIZES: [(f32, f32); 2] = [(640., 480.), (1920., 1080.)];
154 const SIZES: [(f32, f32); 2] = [(640., 480.), (1920., 1080.)];
@@ -149,6 +160,7 @@ mod frames {
149 enum Screen {
160 enum Screen {
150 Tab(&'static str, Option<fn(&mut VisualTestContext)>),
161 Tab(&'static str, Option<fn(&mut VisualTestContext)>),
151 StatusMenu,
162 StatusMenu,
163 Call,
152 }
164 }
153
165
154 fn parent_of(path: &str) -> Option<&str> {
166 fn parent_of(path: &str) -> Option<&str> {
@@ -263,12 +275,37 @@ mod frames {
263 }
275 }
264 GUARDED
276 GUARDED
265 .iter()
277 .iter()
278 .chain(CALL_GUARDED)
266 .chain([&MENU])
279 .chain([&MENU])
267 .filter_map(|path| visual.debug_bounds(path).map(|bounds| (*path, bounds)))
280 .filter_map(|path| visual.debug_bounds(path).map(|bounds| (*path, bounds)))
268 .collect()
281 .collect()
269 }
282 }
270
283
271 fn mount(cx: &mut TestAppContext) -> gpui_kit::AnyWindowHandle {
284 fn gallery_call() -> ActiveCall {
285 let (handle, _control) = call_channel();
286 let mut model = CallModel::meeting("Standup", false);
287 model.apply(CallUpdate::State(CallState::Connected {
288 since: Instant::now(),
289 }));
290 model.apply(CallUpdate::Roster(
291 (0..11)
292 .map(|index| RosterEntry {
293 mri: format!("8:orgid:guard-{index}"),
294 display_name: format!("Guest {index}"),
295 muted: false,
296 in_lobby: false,
297 has_video: false,
298 sharing: false,
299 hand: None,
300 spotlight: None,
301 organizer: false,
302 })
303 .collect(),
304 ));
305 ActiveCall::new(1, model, handle.commands, None, handle.video)
306 }
307
308 fn mount(cx: &mut TestAppContext) -> (gpui_kit::AnyWindowHandle, Entity<AppState>) {
272 cx.update(gpui_kit::init);
309 cx.update(gpui_kit::init);
273 cx.update(|cx| {
310 cx.update(|cx| {
274 crate::theme::apply(cx);
311 crate::theme::apply(cx);
@@ -283,16 +320,18 @@ mod frames {
283 let state = cx.new(|_| AppState::new(Arc::new(store), mode));
320 let state = cx.new(|_| AppState::new(Arc::new(store), mode));
284 install_globals(&state, UserInput::new(), cx);
321 install_globals(&state, UserInput::new(), cx);
285 demo::start_session(&state, cx);
322 demo::start_session(&state, cx);
323 let shared_state = state.clone();
286 let startup = Startup {
324 let startup = Startup {
287 switcher_query: None,
325 switcher_query: None,
288 composer_text: None,
326 composer_text: None,
289 reply_to_last: false,
327 reply_to_last: false,
290 };
328 };
291 gpui_kit::open_window(WindowOptions::default(), cx, move |window, cx| {
329 let window = gpui_kit::open_window(WindowOptions::default(), cx, move |window, cx| {
292 cx.new(|cx| AppShell::new(state, None, startup, window, cx))
330 cx.new(|cx| AppShell::new(state, None, startup, window, cx))
293 })
331 })
294 .expect("open test window")
332 .expect("open test window")
295 .0
333 .0;
334 (window, shared_state)
296 })
335 })
297 }
336 }
298
337
@@ -329,7 +368,7 @@ mod frames {
329
368
330 #[gpui_kit::test]
369 #[gpui_kit::test]
331 fn no_element_overlaps_or_leaves_its_container(cx: &mut TestAppContext) {
370 fn no_element_overlaps_or_leaves_its_container(cx: &mut TestAppContext) {
332 let handle = mount(cx);
371 let (handle, app) = mount(cx);
333 let mut visual = VisualTestContext::from_window(handle, cx);
372 let mut visual = VisualTestContext::from_window(handle, cx);
334 let mut seen_known = HashSet::new();
373 let mut seen_known = HashSet::new();
335 let mut unexpected = Vec::new();
374 let mut unexpected = Vec::new();
@@ -352,6 +391,7 @@ mod frames {
352 Screen::Tab("saved", Some(|visual| visual.dispatch_action(OpenSaved))),
391 Screen::Tab("saved", Some(|visual| visual.dispatch_action(OpenSaved))),
353 Screen::Tab("calls", Some(|visual| visual.dispatch_action(OpenCallsTab))),
392 Screen::Tab("calls", Some(|visual| visual.dispatch_action(OpenCallsTab))),
354 Screen::StatusMenu,
393 Screen::StatusMenu,
394 Screen::Call,
355 ];
395 ];
356 for screen in screens {
396 for screen in screens {
357 let (screen_name, status_menu) = match screen {
397 let (screen_name, status_menu) = match screen {
@@ -361,6 +401,15 @@ mod frames {
361 }
401 }
362 (name, false)
402 (name, false)
363 }
403 }
404 Screen::Call => {
405 visual.update(|_, cx| {
406 app.update(cx, |state, cx| {
407 state.call = Some(gallery_call());
408 cx.notify();
409 })
410 });
411 ("call", false)
412 }
364 Screen::StatusMenu => {
413 Screen::StatusMenu => {
365 let tags = collect(&mut visual, None);
414 let tags = collect(&mut visual, None);
366 let button = tags
415 let button = tags
@@ -374,6 +423,9 @@ mod frames {
374 };
423 };
375 let tags = collect(&mut visual, status_menu.then_some(MENU));
424 let tags = collect(&mut visual, status_menu.then_some(MENU));
376 let mut expected = GUARDED.to_vec();
425 let mut expected = GUARDED.to_vec();
426 if screen_name == "call" {
427 expected.extend(CALL_GUARDED);
428 }
377 if status_menu {
429 if status_menu {
378 expected.push(MENU);
430 expected.push(MENU);
379 }
431 }
@@ -402,6 +454,14 @@ mod frames {
402 visual.simulate_keystrokes("escape");
454 visual.simulate_keystrokes("escape");
403 visual.run_until_parked();
455 visual.run_until_parked();
404 }
456 }
457 if screen_name == "call" {
458 visual.update(|_, cx| {
459 app.update(cx, |state, cx| {
460 state.call = None;
461 cx.notify();
462 })
463 });
464 }
405 for (key, message) in found {
465 for (key, message) in found {
406 let full_key = format!("{screen_name}@{width}x{height}:{key}");
466 let full_key = format!("{screen_name}@{width}x{height}:{key}");
407 if KNOWN_VIOLATIONS.contains(&full_key.as_str()) {
467 if KNOWN_VIOLATIONS.contains(&full_key.as_str()) {
crates/app/src/notify/center.rs +14 −0
@@ -302,6 +302,20 @@ impl NotificationCenter {
302 302 }
303 303
304 304 pub fn handle_incoming(&mut self, incoming: Incoming, cx: &mut Context<Self>) {
305 let bubble_text = match &incoming.preview {
306 Preview::Text(text) => text.replace('\n', " "),
307 Preview::Image => "Sent a picture".to_owned(),
308 };
309 self.app.update(cx, |state, cx| {
310 state.note_call_chat_message(
311 &incoming.conversation_id,
312 &incoming.message_id,
313 incoming.sender_id.clone(),
314 &incoming.sender_name,
315 &bubble_text,
316 cx,
317 )
318 });
305 319 let environment = self.environment(&incoming.conversation_id, cx);
306 320 if !environment.chat_in_foreground && incoming.mentions_me {
307 321 self.unread_mentions
@@ -302,6 +302,20 @@ impl NotificationCenter {
302 }
302 }
303
303
304 pub fn handle_incoming(&mut self, incoming: Incoming, cx: &mut Context<Self>) {
304 pub fn handle_incoming(&mut self, incoming: Incoming, cx: &mut Context<Self>) {
305 let bubble_text = match &incoming.preview {
306 Preview::Text(text) => text.replace('\n', " "),
307 Preview::Image => "Sent a picture".to_owned(),
308 };
309 self.app.update(cx, |state, cx| {
310 state.note_call_chat_message(
311 &incoming.conversation_id,
312 &incoming.message_id,
313 incoming.sender_id.clone(),
314 &incoming.sender_name,
315 &bubble_text,
316 cx,
317 )
318 });
305 let environment = self.environment(&incoming.conversation_id, cx);
319 let environment = self.environment(&incoming.conversation_id, cx);
306 if !environment.chat_in_foreground && incoming.mentions_me {
320 if !environment.chat_in_foreground && incoming.mentions_me {
307 self.unread_mentions
321 self.unread_mentions
crates/app/src/views/call_layouts.rs added +559 −0
@@ -0,0 +1,559 @@
1 use std::time::Instant;
2
3 use gpui_kit::assets::IconName;
4 use gpui_kit::component::{
5 button::{Button, ButtonVariants as _},
6 h_flex,
7 popover::Popover,
8 tooltip::Tooltip,
9 v_flex,
10 };
11 use gpui_kit::prelude::FluentBuilder as _;
12 use gpui_kit::*;
13
14 use super::avatar::person_avatar;
15 use super::call_organizer::render_focus_stage;
16 use super::call_view::{
17 GRID_PADDING, STRIP_GAP, STRIP_TILE, STRIP_VISIBLE, TILE_GAP, own_tile, person_tile,
18 };
19 use super::widgets::icon;
20 use crate::app_state::AppState;
21 use crate::call::{
22 ActiveCall, CallLayout, CallModel, GALLERY_MAX, Tile, TileSize, filmstrip, gallery_grid,
23 shown_bubbles, split_overflow,
24 };
25 use crate::theme;
26
27 const FALLBACK_STAGE: (f32, f32) = (900., 560.);
28 const MEASURE_TOLERANCE: f32 = 0.5;
29 const OVERLAY_INSET: f32 = 16.;
30 const CHIP_TOP: f32 = 12.;
31 const FILMSTRIP_TILE_MAX: f32 = 220.;
32 const TILE_RADIUS: f32 = 12.;
33 const HIDDEN_LIST_WIDTH: f32 = 260.;
34 const HIDDEN_LIST_HEIGHT: f32 = 320.;
35 const HIDDEN_AVATAR: f32 = 28.;
36 const STACK_MAX: usize = 3;
37 const STACK_OVERLAP: f32 = 0.35;
38 const BUBBLE_WIDTH: f32 = 340.;
39 const BUBBLE_AVATAR: f32 = 28.;
40 const BUBBLE_GAP: f32 = 8.;
41 const BUBBLE_FADE_FROM: f32 = 0.9;
42 const BUBBLE_BACKGROUND: f32 = 0.72;
43 const CHIP_BACKGROUND: f32 = 0.6;
44 pub const FULLSCREEN_HINT: &str = "Press Esc to exit full screen";
45
46 fn measured_stage(call: &ActiveCall) -> (f32, f32) {
47 let (width, height) = call.stage_size.get();
48 if width < 1. || height < 1. {
49 return FALLBACK_STAGE;
50 }
51 (width, height)
52 }
53
54 fn measure_stage(call: &ActiveCall) -> impl IntoElement {
55 let stage_size = call.stage_size.clone();
56 canvas(
57 |_, _, _| {},
58 move |bounds, _, window, _| {
59 let measured = (f32::from(bounds.size.width), f32::from(bounds.size.height));
60 let known = stage_size.get();
61 if (known.0 - measured.0).abs() > MEASURE_TOLERANCE
62 || (known.1 - measured.1).abs() > MEASURE_TOLERANCE
63 {
64 stage_size.set(measured);
65 window.refresh();
66 }
67 },
68 )
69 .absolute()
70 .size_full()
71 }
72
73 fn dark_chip() -> Div {
74 h_flex()
75 .h(px(30.))
76 .px(px(12.))
77 .gap(px(8.))
78 .items_center()
79 .rounded_full()
80 .bg(hsla(0., 0., 0., CHIP_BACKGROUND))
81 .text_color(theme::white())
82 .text_size(px(13.))
83 .font_weight(FontWeight::SEMIBOLD)
84 }
85
86 fn without_video_chip(app: &Entity<AppState>, model: &CallModel) -> Option<AnyElement> {
87 let count = model.hidden_without_video();
88 if !model.view.hide_no_video || count == 0 {
89 return None;
90 }
91 let app = app.clone();
92 Some(
93 div()
94 .absolute()
95 .top(px(CHIP_TOP))
96 .left_0()
97 .right_0()
98 .flex()
99 .justify_center()
100 .child(
101 dark_chip()
102 .id("call-no-video-chip")
103 .cursor_pointer()
104 .hover(|chip| chip.opacity(0.85))
105 .tooltip(|window, cx| {
106 Tooltip::new("Show people without video").build(window, cx)
107 })
108 .child(icon(IconName::VideoOff, 15., theme::white()))
109 .child(format!("{count} without video"))
110 .on_click(move |_, _, cx| {
111 app.update(cx, |state, cx| state.toggle_call_hide_no_video(cx))
112 }),
113 )
114 .into_any_element(),
115 )
116 }
117
118 fn show_me_pill(app: &Entity<AppState>, model: &CallModel, bottom: f32) -> Option<AnyElement> {
119 if !model.view.hide_me {
120 return None;
121 }
122 let app = app.clone();
123 Some(
124 div()
125 .absolute()
126 .right(px(OVERLAY_INSET))
127 .bottom(px(bottom))
128 .child(
129 dark_chip()
130 .id("call-show-me")
131 .cursor_pointer()
132 .hover(|chip| chip.opacity(0.85))
133 .tooltip(|window, cx| Tooltip::new("Show me").build(window, cx))
134 .child(icon(IconName::Eye, 15., theme::white()))
135 .child("You")
136 .on_click(move |_, _, cx| {
137 app.update(cx, |state, cx| state.set_call_hide_me(false, cx))
138 }),
139 )
140 .into_any_element(),
141 )
142 }
143
144 fn chat_bubbles(
145 app: &Entity<AppState>,
146 state: &AppState,
147 call: &ActiveCall,
148 now: Instant,
149 bottom: f32,
150 ) -> Option<AnyElement> {
151 if call.chat_open || !call.model.view.chat_bubbles {
152 return None;
153 }
154 let bubbles = shown_bubbles(&call.bubbles, now);
155 if bubbles.is_empty() {
156 return None;
157 }
158 let shown = crate::call::BUBBLE_SHOWN;
159 Some(
160 v_flex()
161 .absolute()
162 .left(px(OVERLAY_INSET))
163 .bottom(px(bottom))
164 .gap(px(BUBBLE_GAP))
165 .children(bubbles.into_iter().map(|bubble| {
166 let app = app.clone();
167 let id = SharedString::from(format!("call-bubble-{}", bubble.id));
168 h_flex()
169 .id(id.clone())
170 .max_w(px(BUBBLE_WIDTH))
171 .pl(px(6.))
172 .pr(px(14.))
173 .py(px(6.))
174 .gap(px(8.))
175 .items_center()
176 .rounded_full()
177 .bg(hsla(0., 0., 0., BUBBLE_BACKGROUND))
178 .text_color(theme::white())
179 .text_size(px(13.))
180 .cursor_pointer()
181 .child(person_avatar(
182 &state.directory,
183 bubble.sender_id.as_deref(),
184 &bubble.name,
185 BUBBLE_AVATAR,
186 ))
187 .child(
188 h_flex()
189 .min_w_0()
190 .flex_1()
191 .gap(px(6.))
192 .child(
193 div()
194 .flex_none()
195 .font_weight(FontWeight::BOLD)
196 .child(bubble.name.clone()),
197 )
198 .child(div().min_w_0().truncate().child(bubble.text.clone())),
199 )
200 .on_click(move |_, _, cx| {
201 app.update(cx, |state, cx| {
202 if state.call_chat_thread().is_none() {
203 state.toggle_call_chat(cx);
204 }
205 })
206 })
207 .with_animation(id, Animation::new(shown), |bubble, delta| {
208 let fade =
209 ((delta - BUBBLE_FADE_FROM) / (1. - BUBBLE_FADE_FROM)).clamp(0., 1.);
210 bubble.opacity(1. - fade)
211 })
212 }))
213 .into_any_element(),
214 )
215 }
216
217 fn fullscreen_hint(call: &ActiveCall, now: Instant, bottom: f32) -> Option<AnyElement> {
218 call.fullscreen
219 .filter(|fullscreen| fullscreen.hint_visible(now))
220 .map(|_| {
221 div()
222 .absolute()
223 .left_0()
224 .right_0()
225 .bottom(px(bottom))
226 .flex()
227 .justify_center()
228 .child(dark_chip().h(px(32.)).child(FULLSCREEN_HINT))
229 .into_any_element()
230 })
231 }
232
233 fn stacked_avatars(state: &AppState, hidden: &[&Tile], diameter: f32) -> Div {
234 let shown: Vec<&&Tile> = hidden.iter().take(STACK_MAX).collect();
235 let step = diameter * (1. - STACK_OVERLAP);
236 div()
237 .relative()
238 .h(px(diameter))
239 .w(px(diameter + step * (shown.len().saturating_sub(1)) as f32))
240 .children(shown.into_iter().enumerate().map(|(index, tile)| {
241 div()
242 .absolute()
243 .top_0()
244 .left(px(step * index as f32))
245 .rounded_full()
246 .bg(theme::row_hover())
247 .child(person_avatar(
248 &state.directory,
249 tile.user_id.as_deref(),
250 &tile.name,
251 diameter,
252 ))
253 }))
254 }
255
256 fn overflow_tile(
257 app: &Entity<AppState>,
258 state: &AppState,
259 size: TileSize,
260 hidden: &[&Tile],
261 ) -> AnyElement {
262 let people: Vec<(String, String, Option<String>)> = hidden
263 .iter()
264 .map(|tile| (tile.mri.clone(), tile.name.clone(), tile.user_id.clone()))
265 .collect();
266 let diameter = (size.height * 0.3).clamp(22., 44.);
267 let face = v_flex()
268 .w(px(size.width))
269 .h(px(size.height))
270 .items_center()
271 .justify_center()
272 .gap(px(size.height * 0.06))
273 .rounded(px(TILE_RADIUS))
274 .bg(theme::row_hover())
275 .child(stacked_avatars(state, hidden, diameter))
276 .child(
277 div()
278 .text_size(px((size.height * 0.2).clamp(14., 28.)))
279 .font_weight(FontWeight::SEMIBOLD)
280 .text_color(theme::text_muted())
281 .child(format!("+{}", hidden.len())),
282 );
283 let app = app.clone();
284 Popover::new("call-hidden-popover")
285 .anchor(Anchor::BottomLeft)
286 .offset(px(8.))
287 .trigger(
288 Button::new("call-hidden")
289 .ghost()
290 .p_0()
291 .w(px(size.width))
292 .h(px(size.height))
293 .rounded(px(TILE_RADIUS))
294 .child(face),
295 )
296 .content(move |_, _, cx| {
297 let popover = cx.entity().downgrade();
298 v_flex()
299 .id("call-hidden-list")
300 .w(px(HIDDEN_LIST_WIDTH))
301 .max_h(px(HIDDEN_LIST_HEIGHT))
302 .overflow_y_scroll()
303 .gap(px(2.))
304 .children(people.iter().map(|(mri, name, user_id)| {
305 let app_for_click = app.clone();
306 let popover = popover.clone();
307 let pinned_mri = mri.clone();
308 h_flex()
309 .id(SharedString::from(format!("call-hidden-{mri}")))
310 .w_full()
311 .px(px(8.))
312 .py(px(6.))
313 .gap(px(10.))
314 .items_center()
315 .rounded(px(8.))
316 .cursor_pointer()
317 .hover(|row| row.bg(theme::row_hover()))
318 .child(person_avatar(
319 &app.read(cx).directory,
320 user_id.as_deref(),
321 name,
322 HIDDEN_AVATAR,
323 ))
324 .child(div().min_w_0().flex_1().truncate().child(name.clone()))
325 .on_click(move |_, window, cx| {
326 app_for_click
327 .update(cx, |state, cx| state.toggle_call_pin(&pinned_mri, cx));
328 popover
329 .update(cx, |state, cx| state.dismiss(window, cx))
330 .ok();
331 })
332 }))
333 })
334 .into_any_element()
335 }
336
337 fn own_slot(model: &CallModel, shown: &[&Tile]) -> usize {
338 match model.own_hand {
339 None => shown.len(),
340 Some(rank) => shown
341 .iter()
342 .filter(|tile| tile.hand.is_some_and(|other| other < rank))
343 .count(),
344 }
345 }
346
347 fn rows_of(cells: Vec<AnyElement>, columns: usize) -> Vec<Div> {
348 let mut rows = Vec::new();
349 let mut remaining = cells.into_iter();
350 loop {
351 let row: Vec<AnyElement> = remaining.by_ref().take(columns).collect();
352 if row.is_empty() {
353 return rows;
354 }
355 rows.push(h_flex().gap(px(TILE_GAP)).justify_center().children(row));
356 }
357 }
358
359 fn gallery_body(
360 app: &Entity<AppState>,
361 state: &AppState,
362 model: &CallModel,
363 now: Instant,
364 stage: (f32, f32),
365 ) -> AnyElement {
366 let others = model.layout_tiles();
367 let own_cells = model.own_cells();
368 let overflow = split_overflow(others.len(), own_cells, GALLERY_MAX);
369 let cells = overflow.shown + own_cells + usize::from(overflow.hidden > 0);
370 let grid = gallery_grid(
371 cells,
372 stage.0 - 2. * GRID_PADDING,
373 stage.1 - 2. * GRID_PADDING,
374 TILE_GAP,
375 );
376 let size = TileSize::sixteen_by_nine(grid.tile_width.floor());
377 let shown = &others[..overflow.shown];
378 let mut tiles: Vec<AnyElement> = shown
379 .iter()
380 .map(|tile| person_tile(app, state, model, tile, size, now))
381 .collect();
382 if own_cells > 0 {
383 tiles.insert(
384 own_slot(model, shown),
385 own_tile(app, state, model, size, now),
386 );
387 }
388 if overflow.hidden > 0 {
389 tiles.push(overflow_tile(app, state, size, &others[overflow.shown..]));
390 }
391 v_flex()
392 .absolute()
393 .inset_0()
394 .items_center()
395 .justify_center()
396 .gap(px(TILE_GAP))
397 .children(rows_of(tiles, grid.columns))
398 .into_any_element()
399 }
400
401 fn speaker_body(
402 app: &Entity<AppState>,
403 state: &AppState,
404 model: &CallModel,
405 now: Instant,
406 stage: (f32, f32),
407 ) -> AnyElement {
408 let focus = model.speaker_focus();
409 let focus_mri = focus.as_ref().map(|focus| focus.mri.as_str());
410 let main = focus
411 .as_ref()
412 .and_then(|focus| render_focus_stage(app, state, focus, now));
413 let others: Vec<&Tile> = model
414 .layout_tiles()
415 .into_iter()
416 .filter(|tile| Some(tile.mri.as_str()) != focus_mri)
417 .collect();
418 let own_cells = usize::from(model.own_cells() > 0 && !focus.as_ref().is_some_and(|f| f.own));
419 let plan = filmstrip(
420 others.len(),
421 own_cells,
422 stage.0 - 2. * GRID_PADDING,
423 TILE_GAP,
424 FILMSTRIP_TILE_MAX,
425 );
426 let size = TileSize::sixteen_by_nine(plan.tile_width.floor());
427 let shown = &others[..plan.overflow.shown];
428 let mut tiles: Vec<AnyElement> = shown
429 .iter()
430 .map(|tile| person_tile(app, state, model, tile, size, now))
431 .collect();
432 if own_cells > 0 {
433 tiles.insert(
434 own_slot(model, shown),
435 own_tile(app, state, model, size, now),
436 );
437 }
438 if plan.overflow.hidden > 0 {
439 tiles.push(overflow_tile(
440 app,
441 state,
442 size,
443 &others[plan.overflow.shown..],
444 ));
445 }
446 v_flex()
447 .absolute()
448 .inset_0()
449 .p(px(GRID_PADDING))
450 .gap(px(TILE_GAP))
451 .child(
452 h_flex()
453 .flex_1()
454 .min_h_0()
455 .w_full()
456 .items_center()
457 .children(main),
458 )
459 .when(!tiles.is_empty(), |column| {
460 column.child(
461 h_flex()
462 .id("call-filmstrip")
463 .flex_none()
464 .w_full()
465 .gap(px(TILE_GAP))
466 .justify_center()
467 .children(tiles),
468 )
469 })
470 .into_any_element()
471 }
472
473 fn people_strip(
474 app: &Entity<AppState>,
475 state: &AppState,
476 model: &CallModel,
477 now: Instant,
478 ) -> Stateful<Div> {
479 let mut cells: Vec<AnyElement> = model
480 .strip_tiles()
481 .into_iter()
482 .filter(|tile| !model.hidden_for_no_video(tile))
483 .map(|remote| person_tile(app, state, model, remote, STRIP_TILE, now))
484 .collect();
485 if model.own_cells() > 0 {
486 let own_index = model.own_cell_index(cells.len());
487 cells.insert(own_index, own_tile(app, state, model, STRIP_TILE, now));
488 }
489 v_flex()
490 .id("call-strip")
491 .flex_none()
492 .w(px(STRIP_TILE.width))
493 .max_h(px(
494 STRIP_VISIBLE * (STRIP_TILE.height + STRIP_GAP) - STRIP_GAP
495 ))
496 .gap(px(STRIP_GAP))
497 .overflow_y_scroll()
498 .children(cells)
499 }
500
501 fn share_body(
502 app: &Entity<AppState>,
503 state: &AppState,
504 model: &CallModel,
505 now: Instant,
506 stage: AnyElement,
507 layout: CallLayout,
508 ) -> AnyElement {
509 h_flex()
510 .absolute()
511 .inset_0()
512 .p(px(GRID_PADDING))
513 .gap(px(TILE_GAP))
514 .items_center()
515 .child(stage)
516 .when(layout != CallLayout::Content, |row| {
517 row.child(people_strip(app, state, model, now))
518 })
519 .into_any_element()
520 }
521
522 pub(super) fn stage_region(
523 app: &Entity<AppState>,
524 state: &AppState,
525 call: &ActiveCall,
526 now: Instant,
527 hold: Option<AnyElement>,
528 share_stage: Option<AnyElement>,
529 ) -> AnyElement {
530 let model = &call.model;
531 let layout = model.effective_layout();
532 let stage = measured_stage(call);
533 let shows_people = hold.is_none() && !(share_stage.is_some() && layout == CallLayout::Content);
534 let body = match (hold, share_stage) {
535 (Some(hold), _) => v_flex().absolute().inset_0().child(hold).into_any_element(),
536 (None, Some(share)) => share_body(app, state, model, now, share, layout),
537 (None, None) if layout == CallLayout::Speaker => {
538 speaker_body(app, state, model, now, stage)
539 }
540 (None, None) => gallery_body(app, state, model, now, stage),
541 };
542 div()
543 .relative()
544 .debug_selector(|| "shell/islands/main/call-stage".into())
545 .flex_1()
546 .min_h_0()
547 .w_full()
548 .child(measure_stage(call))
549 .child(body)
550 .children(
551 without_video_chip(app, model)
552 .filter(|_| shows_people)
553 .into_iter()
554 .chain(show_me_pill(app, model, OVERLAY_INSET).filter(|_| shows_people))
555 .chain(chat_bubbles(app, state, call, now, OVERLAY_INSET))
556 .chain(fullscreen_hint(call, now, OVERLAY_INSET)),
557 )
558 .into_any_element()
559 }
@@ -0,0 +1,559 @@
1use std::time::Instant;
2
3use gpui_kit::assets::IconName;
4use gpui_kit::component::{
5 button::{Button, ButtonVariants as _},
6 h_flex,
7 popover::Popover,
8 tooltip::Tooltip,
9 v_flex,
10};
11use gpui_kit::prelude::FluentBuilder as _;
12use gpui_kit::*;
13
14use super::avatar::person_avatar;
15use super::call_organizer::render_focus_stage;
16use super::call_view::{
17 GRID_PADDING, STRIP_GAP, STRIP_TILE, STRIP_VISIBLE, TILE_GAP, own_tile, person_tile,
18};
19use super::widgets::icon;
20use crate::app_state::AppState;
21use crate::call::{
22 ActiveCall, CallLayout, CallModel, GALLERY_MAX, Tile, TileSize, filmstrip, gallery_grid,
23 shown_bubbles, split_overflow,
24};
25use crate::theme;
26
27const FALLBACK_STAGE: (f32, f32) = (900., 560.);
28const MEASURE_TOLERANCE: f32 = 0.5;
29const OVERLAY_INSET: f32 = 16.;
30const CHIP_TOP: f32 = 12.;
31const FILMSTRIP_TILE_MAX: f32 = 220.;
32const TILE_RADIUS: f32 = 12.;
33const HIDDEN_LIST_WIDTH: f32 = 260.;
34const HIDDEN_LIST_HEIGHT: f32 = 320.;
35const HIDDEN_AVATAR: f32 = 28.;
36const STACK_MAX: usize = 3;
37const STACK_OVERLAP: f32 = 0.35;
38const BUBBLE_WIDTH: f32 = 340.;
39const BUBBLE_AVATAR: f32 = 28.;
40const BUBBLE_GAP: f32 = 8.;
41const BUBBLE_FADE_FROM: f32 = 0.9;
42const BUBBLE_BACKGROUND: f32 = 0.72;
43const CHIP_BACKGROUND: f32 = 0.6;
44pub const FULLSCREEN_HINT: &str = "Press Esc to exit full screen";
45
46fn measured_stage(call: &ActiveCall) -> (f32, f32) {
47 let (width, height) = call.stage_size.get();
48 if width < 1. || height < 1. {
49 return FALLBACK_STAGE;
50 }
51 (width, height)
52}
53
54fn measure_stage(call: &ActiveCall) -> impl IntoElement {
55 let stage_size = call.stage_size.clone();
56 canvas(
57 |_, _, _| {},
58 move |bounds, _, window, _| {
59 let measured = (f32::from(bounds.size.width), f32::from(bounds.size.height));
60 let known = stage_size.get();
61 if (known.0 - measured.0).abs() > MEASURE_TOLERANCE
62 || (known.1 - measured.1).abs() > MEASURE_TOLERANCE
63 {
64 stage_size.set(measured);
65 window.refresh();
66 }
67 },
68 )
69 .absolute()
70 .size_full()
71}
72
73fn dark_chip() -> Div {
74 h_flex()
75 .h(px(30.))
76 .px(px(12.))
77 .gap(px(8.))
78 .items_center()
79 .rounded_full()
80 .bg(hsla(0., 0., 0., CHIP_BACKGROUND))
81 .text_color(theme::white())
82 .text_size(px(13.))
83 .font_weight(FontWeight::SEMIBOLD)
84}
85
86fn without_video_chip(app: &Entity<AppState>, model: &CallModel) -> Option<AnyElement> {
87 let count = model.hidden_without_video();
88 if !model.view.hide_no_video || count == 0 {
89 return None;
90 }
91 let app = app.clone();
92 Some(
93 div()
94 .absolute()
95 .top(px(CHIP_TOP))
96 .left_0()
97 .right_0()
98 .flex()
99 .justify_center()
100 .child(
101 dark_chip()
102 .id("call-no-video-chip")
103 .cursor_pointer()
104 .hover(|chip| chip.opacity(0.85))
105 .tooltip(|window, cx| {
106 Tooltip::new("Show people without video").build(window, cx)
107 })
108 .child(icon(IconName::VideoOff, 15., theme::white()))
109 .child(format!("{count} without video"))
110 .on_click(move |_, _, cx| {
111 app.update(cx, |state, cx| state.toggle_call_hide_no_video(cx))
112 }),
113 )
114 .into_any_element(),
115 )
116}
117
118fn show_me_pill(app: &Entity<AppState>, model: &CallModel, bottom: f32) -> Option<AnyElement> {
119 if !model.view.hide_me {
120 return None;
121 }
122 let app = app.clone();
123 Some(
124 div()
125 .absolute()
126 .right(px(OVERLAY_INSET))
127 .bottom(px(bottom))
128 .child(
129 dark_chip()
130 .id("call-show-me")
131 .cursor_pointer()
132 .hover(|chip| chip.opacity(0.85))
133 .tooltip(|window, cx| Tooltip::new("Show me").build(window, cx))
134 .child(icon(IconName::Eye, 15., theme::white()))
135 .child("You")
136 .on_click(move |_, _, cx| {
137 app.update(cx, |state, cx| state.set_call_hide_me(false, cx))
138 }),
139 )
140 .into_any_element(),
141 )
142}
143
144fn chat_bubbles(
145 app: &Entity<AppState>,
146 state: &AppState,
147 call: &ActiveCall,
148 now: Instant,
149 bottom: f32,
150) -> Option<AnyElement> {
151 if call.chat_open || !call.model.view.chat_bubbles {
152 return None;
153 }
154 let bubbles = shown_bubbles(&call.bubbles, now);
155 if bubbles.is_empty() {
156 return None;
157 }
158 let shown = crate::call::BUBBLE_SHOWN;
159 Some(
160 v_flex()
161 .absolute()
162 .left(px(OVERLAY_INSET))
163 .bottom(px(bottom))
164 .gap(px(BUBBLE_GAP))
165 .children(bubbles.into_iter().map(|bubble| {
166 let app = app.clone();
167 let id = SharedString::from(format!("call-bubble-{}", bubble.id));
168 h_flex()
169 .id(id.clone())
170 .max_w(px(BUBBLE_WIDTH))
171 .pl(px(6.))
172 .pr(px(14.))
173 .py(px(6.))
174 .gap(px(8.))
175 .items_center()
176 .rounded_full()
177 .bg(hsla(0., 0., 0., BUBBLE_BACKGROUND))
178 .text_color(theme::white())
179 .text_size(px(13.))
180 .cursor_pointer()
181 .child(person_avatar(
182 &state.directory,
183 bubble.sender_id.as_deref(),
184 &bubble.name,
185 BUBBLE_AVATAR,
186 ))
187 .child(
188 h_flex()
189 .min_w_0()
190 .flex_1()
191 .gap(px(6.))
192 .child(
193 div()
194 .flex_none()
195 .font_weight(FontWeight::BOLD)
196 .child(bubble.name.clone()),
197 )
198 .child(div().min_w_0().truncate().child(bubble.text.clone())),
199 )
200 .on_click(move |_, _, cx| {
201 app.update(cx, |state, cx| {
202 if state.call_chat_thread().is_none() {
203 state.toggle_call_chat(cx);
204 }
205 })
206 })
207 .with_animation(id, Animation::new(shown), |bubble, delta| {
208 let fade =
209 ((delta - BUBBLE_FADE_FROM) / (1. - BUBBLE_FADE_FROM)).clamp(0., 1.);
210 bubble.opacity(1. - fade)
211 })
212 }))
213 .into_any_element(),
214 )
215}
216
217fn fullscreen_hint(call: &ActiveCall, now: Instant, bottom: f32) -> Option<AnyElement> {
218 call.fullscreen
219 .filter(|fullscreen| fullscreen.hint_visible(now))
220 .map(|_| {
221 div()
222 .absolute()
223 .left_0()
224 .right_0()
225 .bottom(px(bottom))
226 .flex()
227 .justify_center()
228 .child(dark_chip().h(px(32.)).child(FULLSCREEN_HINT))
229 .into_any_element()
230 })
231}
232
233fn stacked_avatars(state: &AppState, hidden: &[&Tile], diameter: f32) -> Div {
234 let shown: Vec<&&Tile> = hidden.iter().take(STACK_MAX).collect();
235 let step = diameter * (1. - STACK_OVERLAP);
236 div()
237 .relative()
238 .h(px(diameter))
239 .w(px(diameter + step * (shown.len().saturating_sub(1)) as f32))
240 .children(shown.into_iter().enumerate().map(|(index, tile)| {
241 div()
242 .absolute()
243 .top_0()
244 .left(px(step * index as f32))
245 .rounded_full()
246 .bg(theme::row_hover())
247 .child(person_avatar(
248 &state.directory,
249 tile.user_id.as_deref(),
250 &tile.name,
251 diameter,
252 ))
253 }))
254}
255
256fn overflow_tile(
257 app: &Entity<AppState>,
258 state: &AppState,
259 size: TileSize,
260 hidden: &[&Tile],
261) -> AnyElement {
262 let people: Vec<(String, String, Option<String>)> = hidden
263 .iter()
264 .map(|tile| (tile.mri.clone(), tile.name.clone(), tile.user_id.clone()))
265 .collect();
266 let diameter = (size.height * 0.3).clamp(22., 44.);
267 let face = v_flex()
268 .w(px(size.width))
269 .h(px(size.height))
270 .items_center()
271 .justify_center()
272 .gap(px(size.height * 0.06))
273 .rounded(px(TILE_RADIUS))
274 .bg(theme::row_hover())
275 .child(stacked_avatars(state, hidden, diameter))
276 .child(
277 div()
278 .text_size(px((size.height * 0.2).clamp(14., 28.)))
279 .font_weight(FontWeight::SEMIBOLD)
280 .text_color(theme::text_muted())
281 .child(format!("+{}", hidden.len())),
282 );
283 let app = app.clone();
284 Popover::new("call-hidden-popover")
285 .anchor(Anchor::BottomLeft)
286 .offset(px(8.))
287 .trigger(
288 Button::new("call-hidden")
289 .ghost()
290 .p_0()
291 .w(px(size.width))
292 .h(px(size.height))
293 .rounded(px(TILE_RADIUS))
294 .child(face),
295 )
296 .content(move |_, _, cx| {
297 let popover = cx.entity().downgrade();
298 v_flex()
299 .id("call-hidden-list")
300 .w(px(HIDDEN_LIST_WIDTH))
301 .max_h(px(HIDDEN_LIST_HEIGHT))
302 .overflow_y_scroll()
303 .gap(px(2.))
304 .children(people.iter().map(|(mri, name, user_id)| {
305 let app_for_click = app.clone();
306 let popover = popover.clone();
307 let pinned_mri = mri.clone();
308 h_flex()
309 .id(SharedString::from(format!("call-hidden-{mri}")))
310 .w_full()
311 .px(px(8.))
312 .py(px(6.))
313 .gap(px(10.))
314 .items_center()
315 .rounded(px(8.))
316 .cursor_pointer()
317 .hover(|row| row.bg(theme::row_hover()))
318 .child(person_avatar(
319 &app.read(cx).directory,
320 user_id.as_deref(),
321 name,
322 HIDDEN_AVATAR,
323 ))
324 .child(div().min_w_0().flex_1().truncate().child(name.clone()))
325 .on_click(move |_, window, cx| {
326 app_for_click
327 .update(cx, |state, cx| state.toggle_call_pin(&pinned_mri, cx));
328 popover
329 .update(cx, |state, cx| state.dismiss(window, cx))
330 .ok();
331 })
332 }))
333 })
334 .into_any_element()
335}
336
337fn own_slot(model: &CallModel, shown: &[&Tile]) -> usize {
338 match model.own_hand {
339 None => shown.len(),
340 Some(rank) => shown
341 .iter()
342 .filter(|tile| tile.hand.is_some_and(|other| other < rank))
343 .count(),
344 }
345}
346
347fn rows_of(cells: Vec<AnyElement>, columns: usize) -> Vec<Div> {
348 let mut rows = Vec::new();
349 let mut remaining = cells.into_iter();
350 loop {
351 let row: Vec<AnyElement> = remaining.by_ref().take(columns).collect();
352 if row.is_empty() {
353 return rows;
354 }
355 rows.push(h_flex().gap(px(TILE_GAP)).justify_center().children(row));
356 }
357}
358
359fn gallery_body(
360 app: &Entity<AppState>,
361 state: &AppState,
362 model: &CallModel,
363 now: Instant,
364 stage: (f32, f32),
365) -> AnyElement {
366 let others = model.layout_tiles();
367 let own_cells = model.own_cells();
368 let overflow = split_overflow(others.len(), own_cells, GALLERY_MAX);
369 let cells = overflow.shown + own_cells + usize::from(overflow.hidden > 0);
370 let grid = gallery_grid(
371 cells,
372 stage.0 - 2. * GRID_PADDING,
373 stage.1 - 2. * GRID_PADDING,
374 TILE_GAP,
375 );
376 let size = TileSize::sixteen_by_nine(grid.tile_width.floor());
377 let shown = &others[..overflow.shown];
378 let mut tiles: Vec<AnyElement> = shown
379 .iter()
380 .map(|tile| person_tile(app, state, model, tile, size, now))
381 .collect();
382 if own_cells > 0 {
383 tiles.insert(
384 own_slot(model, shown),
385 own_tile(app, state, model, size, now),
386 );
387 }
388 if overflow.hidden > 0 {
389 tiles.push(overflow_tile(app, state, size, &others[overflow.shown..]));
390 }
391 v_flex()
392 .absolute()
393 .inset_0()
394 .items_center()
395 .justify_center()
396 .gap(px(TILE_GAP))
397 .children(rows_of(tiles, grid.columns))
398 .into_any_element()
399}
400
401fn speaker_body(
402 app: &Entity<AppState>,
403 state: &AppState,
404 model: &CallModel,
405 now: Instant,
406 stage: (f32, f32),
407) -> AnyElement {
408 let focus = model.speaker_focus();
409 let focus_mri = focus.as_ref().map(|focus| focus.mri.as_str());
410 let main = focus
411 .as_ref()
412 .and_then(|focus| render_focus_stage(app, state, focus, now));
413 let others: Vec<&Tile> = model
414 .layout_tiles()
415 .into_iter()
416 .filter(|tile| Some(tile.mri.as_str()) != focus_mri)
417 .collect();
418 let own_cells = usize::from(model.own_cells() > 0 && !focus.as_ref().is_some_and(|f| f.own));
419 let plan = filmstrip(
420 others.len(),
421 own_cells,
422 stage.0 - 2. * GRID_PADDING,
423 TILE_GAP,
424 FILMSTRIP_TILE_MAX,
425 );
426 let size = TileSize::sixteen_by_nine(plan.tile_width.floor());
427 let shown = &others[..plan.overflow.shown];
428 let mut tiles: Vec<AnyElement> = shown
429 .iter()
430 .map(|tile| person_tile(app, state, model, tile, size, now))
431 .collect();
432 if own_cells > 0 {
433 tiles.insert(
434 own_slot(model, shown),
435 own_tile(app, state, model, size, now),
436 );
437 }
438 if plan.overflow.hidden > 0 {
439 tiles.push(overflow_tile(
440 app,
441 state,
442 size,
443 &others[plan.overflow.shown..],
444 ));
445 }
446 v_flex()
447 .absolute()
448 .inset_0()
449 .p(px(GRID_PADDING))
450 .gap(px(TILE_GAP))
451 .child(
452 h_flex()
453 .flex_1()
454 .min_h_0()
455 .w_full()
456 .items_center()
457 .children(main),
458 )
459 .when(!tiles.is_empty(), |column| {
460 column.child(
461 h_flex()
462 .id("call-filmstrip")
463 .flex_none()
464 .w_full()
465 .gap(px(TILE_GAP))
466 .justify_center()
467 .children(tiles),
468 )
469 })
470 .into_any_element()
471}
472
473fn people_strip(
474 app: &Entity<AppState>,
475 state: &AppState,
476 model: &CallModel,
477 now: Instant,
478) -> Stateful<Div> {
479 let mut cells: Vec<AnyElement> = model
480 .strip_tiles()
481 .into_iter()
482 .filter(|tile| !model.hidden_for_no_video(tile))
483 .map(|remote| person_tile(app, state, model, remote, STRIP_TILE, now))
484 .collect();
485 if model.own_cells() > 0 {
486 let own_index = model.own_cell_index(cells.len());
487 cells.insert(own_index, own_tile(app, state, model, STRIP_TILE, now));
488 }
489 v_flex()
490 .id("call-strip")
491 .flex_none()
492 .w(px(STRIP_TILE.width))
493 .max_h(px(
494 STRIP_VISIBLE * (STRIP_TILE.height + STRIP_GAP) - STRIP_GAP
495 ))
496 .gap(px(STRIP_GAP))
497 .overflow_y_scroll()
498 .children(cells)
499}
500
501fn share_body(
502 app: &Entity<AppState>,
503 state: &AppState,
504 model: &CallModel,
505 now: Instant,
506 stage: AnyElement,
507 layout: CallLayout,
508) -> AnyElement {
509 h_flex()
510 .absolute()
511 .inset_0()
512 .p(px(GRID_PADDING))
513 .gap(px(TILE_GAP))
514 .items_center()
515 .child(stage)
516 .when(layout != CallLayout::Content, |row| {
517 row.child(people_strip(app, state, model, now))
518 })
519 .into_any_element()
520}
521
522pub(super) fn stage_region(
523 app: &Entity<AppState>,
524 state: &AppState,
525 call: &ActiveCall,
526 now: Instant,
527 hold: Option<AnyElement>,
528 share_stage: Option<AnyElement>,
529) -> AnyElement {
530 let model = &call.model;
531 let layout = model.effective_layout();
532 let stage = measured_stage(call);
533 let shows_people = hold.is_none() && !(share_stage.is_some() && layout == CallLayout::Content);
534 let body = match (hold, share_stage) {
535 (Some(hold), _) => v_flex().absolute().inset_0().child(hold).into_any_element(),
536 (None, Some(share)) => share_body(app, state, model, now, share, layout),
537 (None, None) if layout == CallLayout::Speaker => {
538 speaker_body(app, state, model, now, stage)
539 }
540 (None, None) => gallery_body(app, state, model, now, stage),
541 };
542 div()
543 .relative()
544 .debug_selector(|| "shell/islands/main/call-stage".into())
545 .flex_1()
546 .min_h_0()
547 .w_full()
548 .child(measure_stage(call))
549 .child(body)
550 .children(
551 without_video_chip(app, model)
552 .filter(|_| shows_people)
553 .into_iter()
554 .chain(show_me_pill(app, model, OVERLAY_INSET).filter(|_| shows_people))
555 .chain(chat_bubbles(app, state, call, now, OVERLAY_INSET))
556 .chain(fullscreen_hint(call, now, OVERLAY_INSET)),
557 )
558 .into_any_element()
559}
crates/app/src/views/call_organizer.rs +30 −8
@@ -111,7 +111,11 @@ fn lobby_list(app: &Entity<AppState>, guests: &[(String, String)]) -> Div {
111 111 }))
112 112 }
113 113
114 pub fn lobby_banner(app: &Entity<AppState>, model: &CallModel) -> Option<AnyElement> {
114 pub fn lobby_banner(
115 app: &Entity<AppState>,
116 model: &CallModel,
117 list_open: bool,
118 ) -> Option<AnyElement> {
115 119 if !model.can_admit() {
116 120 return None;
117 121 }
@@ -124,6 +128,7 @@ pub fn lobby_banner(app: &Entity<AppState>, model: &CallModel) -> Option<AnyElem
124 128 return None;
125 129 }
126 130 let list_app = app.clone();
131 let open_app = app.clone();
127 132 let admit_app = app.clone();
128 133 Some(
129 134 h_flex()
@@ -144,6 +149,10 @@ pub fn lobby_banner(app: &Entity<AppState>, model: &CallModel) -> Option<AnyElem
144 149 Popover::new("call-lobby-popover")
145 150 .anchor(Anchor::TopLeft)
146 151 .offset(px(8.))
152 .open(list_open)
153 .on_open_change(move |open, _, cx| {
154 open_app.update(cx, |state, cx| state.set_call_lobby_list(*open, cx))
155 })
147 156 .trigger(
148 157 Button::new("call-lobby-view")
149 158 .ghost()
@@ -196,6 +205,17 @@ fn confirm_remove(
196 205 });
197 206 }
198 207
208 fn own_tile_items(popup: PopupMenu, app: &Entity<AppState>) -> PopupMenu {
209 let hide_app = app.clone();
210 popup.min_w(px(MENU_WIDTH)).item(
211 PopupMenuItem::new("Hide for me")
212 .icon(IconName::EyeOff)
213 .on_click(move |_, _, cx| {
214 hide_app.update(cx, |state, cx| state.set_call_hide_me(true, cx))
215 }),
216 )
217 }
218
199 219 pub fn tile_menu(
200 220 popup: PopupMenu,
201 221 app: &Entity<AppState>,
@@ -204,14 +224,16 @@ pub fn tile_menu(
204 224 name: &str,
205 225 own: bool,
206 226 ) -> PopupMenu {
227 if own {
228 return own_tile_items(popup, app);
229 }
207 230 let pinned = model.is_pinned(mri);
208 231 let spotlighted = model.is_spotlighted(mri);
209 232 let organizes = model.organizes_meeting();
210 let raised = !own
211 && model
212 .tiles
213 .iter()
214 .any(|tile| tile.mri == mri && tile.hand.is_some());
233 let raised = model
234 .tiles
235 .iter()
236 .any(|tile| tile.mri == mri && tile.hand.is_some());
215 237 let muted = model.tiles.iter().any(|tile| tile.mri == mri && tile.muted);
216 238 let mut popup = popup.min_w(px(MENU_WIDTH));
217 239 let pin_app = app.clone();
@@ -239,7 +261,7 @@ pub fn tile_menu(
239 261 }),
240 262 );
241 263 }
242 if organizes && !own {
264 if organizes {
243 265 let (mute_app, mute_mri) = (app.clone(), mri.to_owned());
244 266 popup = popup.item(
245 267 PopupMenuItem::new("Mute")
@@ -258,7 +280,7 @@ pub fn tile_menu(
258 280 hand_app.update(cx, |state, cx| state.lower_call_hand(hand_mri.clone(), cx))
259 281 }));
260 282 }
261 if organizes && !own {
283 if organizes {
262 284 let (remove_app, remove_mri, remove_name) = (app.clone(), mri.to_owned(), name.to_owned());
263 285 popup = popup.separator().item(
264 286 PopupMenuItem::new("Remove from meeting...")
@@ -111,7 +111,11 @@ fn lobby_list(app: &Entity<AppState>, guests: &[(String, String)]) -> Div {
111 }))
111 }))
112}
112}
113
113
114pub fn lobby_banner(app: &Entity<AppState>, model: &CallModel) -> Option<AnyElement> {
114pub fn lobby_banner(
115 app: &Entity<AppState>,
116 model: &CallModel,
117 list_open: bool,
118) -> Option<AnyElement> {
115 if !model.can_admit() {
119 if !model.can_admit() {
116 return None;
120 return None;
117 }
121 }
@@ -124,6 +128,7 @@ pub fn lobby_banner(app: &Entity<AppState>, model: &CallModel) -> Option<AnyElem
124 return None;
128 return None;
125 }
129 }
126 let list_app = app.clone();
130 let list_app = app.clone();
131 let open_app = app.clone();
127 let admit_app = app.clone();
132 let admit_app = app.clone();
128 Some(
133 Some(
129 h_flex()
134 h_flex()
@@ -144,6 +149,10 @@ pub fn lobby_banner(app: &Entity<AppState>, model: &CallModel) -> Option<AnyElem
144 Popover::new("call-lobby-popover")
149 Popover::new("call-lobby-popover")
145 .anchor(Anchor::TopLeft)
150 .anchor(Anchor::TopLeft)
146 .offset(px(8.))
151 .offset(px(8.))
152 .open(list_open)
153 .on_open_change(move |open, _, cx| {
154 open_app.update(cx, |state, cx| state.set_call_lobby_list(*open, cx))
155 })
147 .trigger(
156 .trigger(
148 Button::new("call-lobby-view")
157 Button::new("call-lobby-view")
149 .ghost()
158 .ghost()
@@ -196,6 +205,17 @@ fn confirm_remove(
196 });
205 });
197}
206}
198
207
208fn own_tile_items(popup: PopupMenu, app: &Entity<AppState>) -> PopupMenu {
209 let hide_app = app.clone();
210 popup.min_w(px(MENU_WIDTH)).item(
211 PopupMenuItem::new("Hide for me")
212 .icon(IconName::EyeOff)
213 .on_click(move |_, _, cx| {
214 hide_app.update(cx, |state, cx| state.set_call_hide_me(true, cx))
215 }),
216 )
217}
218
199pub fn tile_menu(
219pub fn tile_menu(
200 popup: PopupMenu,
220 popup: PopupMenu,
201 app: &Entity<AppState>,
221 app: &Entity<AppState>,
@@ -204,14 +224,16 @@ pub fn tile_menu(
204 name: &str,
224 name: &str,
205 own: bool,
225 own: bool,
206) -> PopupMenu {
226) -> PopupMenu {
227 if own {
228 return own_tile_items(popup, app);
229 }
207 let pinned = model.is_pinned(mri);
230 let pinned = model.is_pinned(mri);
208 let spotlighted = model.is_spotlighted(mri);
231 let spotlighted = model.is_spotlighted(mri);
209 let organizes = model.organizes_meeting();
232 let organizes = model.organizes_meeting();
210 let raised = !own
233 let raised = model
211 && model
234 .tiles
212 .tiles
235 .iter()
213 .iter()
236 .any(|tile| tile.mri == mri && tile.hand.is_some());
214 .any(|tile| tile.mri == mri && tile.hand.is_some());
215 let muted = model.tiles.iter().any(|tile| tile.mri == mri && tile.muted);
237 let muted = model.tiles.iter().any(|tile| tile.mri == mri && tile.muted);
216 let mut popup = popup.min_w(px(MENU_WIDTH));
238 let mut popup = popup.min_w(px(MENU_WIDTH));
217 let pin_app = app.clone();
239 let pin_app = app.clone();
@@ -239,7 +261,7 @@ pub fn tile_menu(
239 }),
261 }),
240 );
262 );
241 }
263 }
242 if organizes && !own {
264 if organizes {
243 let (mute_app, mute_mri) = (app.clone(), mri.to_owned());
265 let (mute_app, mute_mri) = (app.clone(), mri.to_owned());
244 popup = popup.item(
266 popup = popup.item(
245 PopupMenuItem::new("Mute")
267 PopupMenuItem::new("Mute")
@@ -258,7 +280,7 @@ pub fn tile_menu(
258 hand_app.update(cx, |state, cx| state.lower_call_hand(hand_mri.clone(), cx))
280 hand_app.update(cx, |state, cx| state.lower_call_hand(hand_mri.clone(), cx))
259 }));
281 }));
260 }
282 }
261 if organizes && !own {
283 if organizes {
262 let (remove_app, remove_mri, remove_name) = (app.clone(), mri.to_owned(), name.to_owned());
284 let (remove_app, remove_mri, remove_name) = (app.clone(), mri.to_owned(), name.to_owned());
263 popup = popup.separator().item(
285 popup = popup.separator().item(
264 PopupMenuItem::new("Remove from meeting...")
286 PopupMenuItem::new("Remove from meeting...")
crates/app/src/views/call_stage.rs +13 −0
@@ -132,3 +132,16 @@ pub fn render_stage_overlay(app: &Entity<AppState>, state: &AppState) -> Option<
132 132 .into_any_element(),
133 133 )
134 134 }
135
136 pub fn render_call_overlay(view: AnyElement) -> AnyElement {
137 v_flex()
138 .id("call-fullscreen-overlay")
139 .occlude()
140 .absolute()
141 .top_0()
142 .left_0()
143 .size_full()
144 .bg(theme::background())
145 .child(view)
146 .into_any_element()
147 }
@@ -132,3 +132,16 @@ pub fn render_stage_overlay(app: &Entity<AppState>, state: &AppState) -> Option<
132 .into_any_element(),
132 .into_any_element(),
133 )
133 )
134}
134}
135
136pub fn render_call_overlay(view: AnyElement) -> AnyElement {
137 v_flex()
138 .id("call-fullscreen-overlay")
139 .occlude()
140 .absolute()
141 .top_0()
142 .left_0()
143 .size_full()
144 .bg(theme::background())
145 .child(view)
146 .into_any_element()
147}
crates/app/src/views/call_view.rs +83 −143
@@ -21,21 +21,20 @@ use super::call_extras::{
21 21 room_chip, whiteboard_stage,
22 22 };
23 23 use super::call_health::{health_banner, health_indicator};
24 use super::call_layouts::stage_region;
24 25 use super::call_organizer::{
25 26 camera_menu_button, captions_hint_chip, captions_overlay, chevron_button, lobby_banner,
26 more_button, pin_chip, render_focus_stage, spotlight_chip, with_tile_menu,
27 more_button, pin_chip, spotlight_chip, with_tile_menu,
27 28 };
28 29 use super::call_stage::render_stage;
30 use super::call_view_menu::view_button;
29 31 use super::conversation::ConversationView;
30 32 use super::shell::ISLAND_GAP;
31 33 use super::widgets::{Corner, corner_badge, count_badge, icon};
32 34 use crate::app_state::AppState;
33 35 use crate::call::REACTION_SHOWN;
34 36 use crate::call::TileSize;
35 use crate::call::{
36 CHAT_OPEN_TILES, CallKind, CallModel, GridLayout, MAX_TILES, Tile, TileState, grid_layout,
37 tile_size,
38 };
37 use crate::call::{CallKind, CallModel, Tile, TileState};
39 38 use crate::rows::reaction_glyph as chat_reaction_glyph;
40 39 use crate::theme;
41 40
@@ -48,16 +47,16 @@ pub(super) const MENU_WIDTH: f32 = 280.;
48 47 const PULSE_PERIOD: Duration = Duration::from_millis(1400);
49 48 const BLINK_HALF_PERIOD: Duration = Duration::from_millis(500);
50 49 const BLINK_DIMMED_OPACITY: f32 = 0.45;
51 const DISABLED_OPACITY: f32 = 0.4;
52 const TILE_GAP: f32 = 20.;
53 const GRID_PADDING: f32 = 24.;
54 const STRIP_TILE: TileSize = TileSize {
50 pub(super) const DISABLED_OPACITY: f32 = 0.4;
51 pub(super) const TILE_GAP: f32 = 20.;
52 pub(super) const GRID_PADDING: f32 = 24.;
53 pub(super) const STRIP_TILE: TileSize = TileSize {
55 54 width: 232.,
56 55 height: 131.,
57 56 avatar: 56.,
58 57 };
59 const STRIP_GAP: f32 = 12.;
60 const STRIP_VISIBLE: f32 = 4.;
58 pub(super) const STRIP_GAP: f32 = 12.;
59 pub(super) const STRIP_VISIBLE: f32 = 4.;
61 60 const TILE_RADIUS: f32 = 12.;
62 61 const NAME_PLATE_BACKGROUND: f32 = 0.6;
63 62 pub const NO_MICROPHONE_HINT: &str = "No microphone found";
@@ -311,23 +310,6 @@ fn tile(
311 310 .children(tile_overlays(extras))
312 311 }
313 312
314 fn overflow_tile(size: TileSize, hidden: usize) -> Div {
315 v_flex()
316 .w(px(size.width))
317 .h(px(size.height))
318 .items_center()
319 .justify_center()
320 .rounded(px(12.))
321 .bg(theme::row_hover())
322 .child(
323 div()
324 .text_size(px(size.avatar * 0.5))
325 .font_weight(FontWeight::SEMIBOLD)
326 .text_color(theme::text_muted())
327 .child(format!("+{hidden}")),
328 )
329 }
330
331 313 fn control_shell(id: &'static str, background: Hsla) -> Stateful<Div> {
332 314 div()
333 315 .id(id)
@@ -496,7 +478,12 @@ fn share_items(
496 478 popup
497 479 }
498 480
499 fn share_button(app: &Entity<AppState>, model: &CallModel, sound: bool) -> AnyElement {
481 fn share_button(
482 app: &Entity<AppState>,
483 model: &CallModel,
484 sound: bool,
485 menu_open: bool,
486 ) -> AnyElement {
500 487 if model.local_share.is_some() {
501 488 let app = app.clone();
502 489 return round_control(
@@ -526,6 +513,7 @@ fn share_button(app: &Entity<AppState>, model: &CallModel, sound: bool) -> AnyEl
526 513 .into_any_element();
527 514 }
528 515 let app = app.clone();
516 let open_app = app.clone();
529 517 let model = model.clone();
530 518 Button::new("call-share")
531 519 .ghost()
@@ -536,6 +524,10 @@ fn share_button(app: &Entity<AppState>, model: &CallModel, sound: bool) -> AnyEl
536 524 .dropdown_menu_with_anchor(Anchor::BottomLeft, move |popup, _, _| {
537 525 share_items(popup, &app, &model, sound)
538 526 })
527 .open(menu_open)
528 .on_open_change(move |open, _, cx| {
529 open_app.update(cx, |state, cx| state.set_call_share_menu(*open, cx))
530 })
539 531 .into_any_element()
540 532 }
541 533
@@ -817,7 +809,7 @@ fn mic_menu_button(app: &Entity<AppState>, model: &CallModel) -> impl IntoElemen
817 809 })
818 810 }
819 811
820 fn person_tile(
812 pub(super) fn person_tile(
821 813 app: &Entity<AppState>,
822 814 state: &AppState,
823 815 model: &CallModel,
@@ -895,7 +887,7 @@ fn person_tile_body(
895 887 .into_any_element()
896 888 }
897 889
898 fn own_tile(
890 pub(super) fn own_tile(
899 891 app: &Entity<AppState>,
900 892 state: &AppState,
901 893 model: &CallModel,
@@ -958,59 +950,11 @@ fn own_tile_body(
958 950 .into_any_element()
959 951 }
960 952
961 fn remote_tiles(
962 app: &Entity<AppState>,
963 state: &AppState,
964 model: &CallModel,
965 size: TileSize,
966 hidden_cap: GridLayout,
967 now: Instant,
968 ) -> Vec<AnyElement> {
969 let visible = model.visible_tiles();
970 let mut cells: Vec<AnyElement> = visible
971 .iter()
972 .take(hidden_cap.shown_others)
973 .map(|remote| person_tile(app, state, model, remote, size, now))
974 .collect();
975 if hidden_cap.hidden > 0 {
976 cells.push(overflow_tile(size, hidden_cap.hidden).into_any_element());
977 }
978 cells
979 }
980
981 fn people_strip(
982 app: &Entity<AppState>,
983 state: &AppState,
984 model: &CallModel,
985 now: Instant,
986 focused: Option<&str>,
987 ) -> Stateful<Div> {
988 let mut cells: Vec<AnyElement> = model
989 .strip_tiles()
990 .into_iter()
991 .filter(|remote| Some(remote.mri.as_str()) != focused)
992 .map(|remote| person_tile(app, state, model, remote, STRIP_TILE, now))
993 .collect();
994 if focused.is_none() || focused != model.own_mri.as_deref() {
995 let own_index = model.own_cell_index(cells.len());
996 cells.insert(own_index, own_tile(app, state, model, STRIP_TILE, now));
997 }
998 v_flex()
999 .id("call-strip")
1000 .flex_none()
1001 .w(px(STRIP_TILE.width))
1002 .max_h(px(
1003 STRIP_VISIBLE * (STRIP_TILE.height + STRIP_GAP) - STRIP_GAP
1004 ))
1005 .gap(px(STRIP_GAP))
1006 .overflow_y_scroll()
1007 .children(cells)
1008 }
1009
1010 953 pub fn render_call_view(
1011 954 app: &Entity<AppState>,
1012 955 state: &AppState,
1013 956 chat: Option<Entity<ConversationView>>,
957 fullscreen: bool,
1014 958 ) -> Option<AnyElement> {
1015 959 let call = state.call.as_ref()?;
1016 960 let model = &call.model;
@@ -1045,31 +989,9 @@ pub fn render_call_view(
1045 989 .child(div().flex_1())
1046 990 .children(return_button(app, model));
1047 991
1048 let max_tiles = if chat.is_some() {
1049 CHAT_OPEN_TILES
1050 } else {
1051 MAX_TILES
1052 };
1053 let layout = grid_layout(model.visible_tiles().len(), max_tiles);
1054 let cells_for_size = if chat.is_some() {
1055 MAX_TILES
1056 } else {
1057 layout.shown_others + usize::from(layout.hidden > 0) + 1
1058 };
1059 let size = tile_size(cells_for_size);
1060 let mut cells = remote_tiles(app, state, model, size, layout, now);
1061 let own_index = model.own_cell_index(cells.len());
1062 cells.insert(own_index, own_tile(app, state, model, size, now));
1063 let focus = model.focus().filter(|_| model.screen_sharer.is_none());
1064 let stage = render_stage(app, state, false)
1065 .or_else(|| whiteboard_stage(app, model))
1066 .or_else(|| {
1067 focus
1068 .as_ref()
1069 .and_then(|focus| render_focus_stage(app, state, focus, now))
1070 });
1071 992 let hold = hold_panel(app, model);
1072 let focused = focus.as_ref().map(|focus| focus.mri.as_str());
993 let share_stage = render_stage(app, state, false).or_else(|| whiteboard_stage(app, model));
994 let region = stage_region(app, state, call, now, hold, share_stage);
1073 995
1074 996 let controls = h_flex()
1075 997 .w_full()
@@ -1096,11 +1018,17 @@ pub fn render_call_view(
1096 1018 .child(camera_button(app, model))
1097 1019 .children(camera_menu_button(app, model, BackgroundMenu::of(state))),
1098 1020 )
1099 .child(share_button(app, model, state.call_share_sound))
1021 .child(share_button(
1022 app,
1023 model,
1024 state.call_share_sound,
1025 call.share_menu_open,
1026 ))
1100 1027 .when(model.has_reaction_controls(), |row| {
1101 1028 row.child(hand_button(app, model))
1102 1029 .child(reactions_button(app, model))
1103 1030 })
1031 .child(view_button(app, model, fullscreen))
1104 1032 .children(more_button(app, model))
1105 1033 .when(call.chat_thread().is_some(), |row| {
1106 1034 row.child(chat_button(app, call.chat_open, state.call_chat_unread()))
@@ -1110,52 +1038,52 @@ pub fn render_call_view(
1110 1038 row.child(leave_menu(app, model))
1111 1039 });
1112 1040
1113 let column = v_flex()
1041 let top = v_flex()
1042 .w_full()
1043 .flex_none()
1044 .child(header)
1045 .children(lobby_banner(app, model, call.lobby_list_open))
1046 .children(health_banner(app, model))
1047 .children(sharing_banner(app, model, state.call_share_sound))
1048 .children(consult_banner(app, state));
1049
1050 let chrome_visible = call
1051 .fullscreen
1052 .is_none_or(|fullscreen| fullscreen.chrome_visible(now));
1053 let move_app = app.clone();
1054 let base = v_flex()
1114 1055 .relative()
1115 1056 .flex_1()
1116 1057 .min_w_0()
1117 1058 .h_full()
1118 .rounded(px(10.))
1119 1059 .overflow_hidden()
1120 .bg(theme::surface())
1121 .child(header)
1122 .children(lobby_banner(app, model))
1123 .children(health_banner(app, model))
1124 .children(sharing_banner(app, model, state.call_share_sound))
1125 .children(consult_banner(app, state))
1126 .child(match stage {
1127 _ if hold.is_some() => hold.expect("checked above"),
1128 Some(stage) => h_flex()
1129 .flex_1()
1130 .min_h_0()
1131 .p(px(GRID_PADDING))
1132 .gap(px(TILE_GAP))
1133 .items_center()
1134 .child(stage)
1135 .child(people_strip(app, state, model, now, focused))
1136 .into_any_element(),
1137 None => h_flex()
1138 .id("call-grid")
1139 .flex_1()
1140 .min_h_0()
1141 .overflow_y_scroll()
1142 .flex_wrap()
1143 .content_center()
1144 .p(px(GRID_PADDING))
1145 .gap(px(TILE_GAP))
1146 .items_center()
1147 .justify_center()
1148 .children(cells)
1149 .into_any_element(),
1060 .bg(theme::surface());
1061 let column = if fullscreen {
1062 base.on_mouse_move(move |_, _, cx| {
1063 move_app.update(cx, |state, cx| state.touch_call_chrome(cx))
1150 1064 })
1151 .child(controls)
1152 .children(captions_overlay(model, now))
1153 .children(captions_hint_chip(model))
1154 .children(state.transfer_picker.clone())
1155 .children(consent_overlay(app, model));
1065 .when(chrome_visible, |column| {
1066 column.child(fullscreen_chrome("call-chrome-top", app, top))
1067 })
1068 .child(region)
1069 .when(chrome_visible, |column| {
1070 column.child(fullscreen_chrome("call-chrome-bottom", app, controls))
1071 })
1072 } else {
1073 base.rounded(px(10.))
1074 .child(top.debug_selector(|| "shell/islands/main/call-header".into()))
1075 .child(region)
1076 .child(controls.debug_selector(|| "shell/islands/main/call-controls".into()))
1077 }
1078 .children(captions_overlay(model, now))
1079 .children(captions_hint_chip(model))
1080 .children(state.transfer_picker.clone())
1081 .children(consent_overlay(app, model));
1156 1082 Some(
1157 1083 h_flex()
1158 .debug_selector(|| "shell/islands/main".into())
1084 .when(!fullscreen, |row| {
1085 row.debug_selector(|| "shell/islands/main".into())
1086 })
1159 1087 .flex_1()
1160 1088 .min_w_0()
1161 1089 .h_full()
@@ -1166,6 +1094,18 @@ pub fn render_call_view(
1166 1094 )
1167 1095 }
1168 1096
1097 fn fullscreen_chrome(id: &'static str, app: &Entity<AppState>, content: Div) -> Stateful<Div> {
1098 let hover_app = app.clone();
1099 div()
1100 .id(id)
1101 .w_full()
1102 .flex_none()
1103 .on_hover(move |hovered, _, cx| {
1104 hover_app.update(cx, |state, cx| state.set_call_chrome_hovered(*hovered, cx))
1105 })
1106 .child(content)
1107 }
1108
1169 1109 fn chat_panel(app: &Entity<AppState>, chat: Entity<ConversationView>) -> AnyElement {
1170 1110 let app = app.clone();
1171 1111 v_flex()
@@ -21,21 +21,20 @@ use super::call_extras::{
21 room_chip, whiteboard_stage,
21 room_chip, whiteboard_stage,
22};
22};
23use super::call_health::{health_banner, health_indicator};
23use super::call_health::{health_banner, health_indicator};
24use super::call_layouts::stage_region;
24use super::call_organizer::{
25use super::call_organizer::{
25 camera_menu_button, captions_hint_chip, captions_overlay, chevron_button, lobby_banner,
26 camera_menu_button, captions_hint_chip, captions_overlay, chevron_button, lobby_banner,
26 more_button, pin_chip, render_focus_stage, spotlight_chip, with_tile_menu,
27 more_button, pin_chip, spotlight_chip, with_tile_menu,
27};
28};
28use super::call_stage::render_stage;
29use super::call_stage::render_stage;
30use super::call_view_menu::view_button;
29use super::conversation::ConversationView;
31use super::conversation::ConversationView;
30use super::shell::ISLAND_GAP;
32use super::shell::ISLAND_GAP;
31use super::widgets::{Corner, corner_badge, count_badge, icon};
33use super::widgets::{Corner, corner_badge, count_badge, icon};
32use crate::app_state::AppState;
34use crate::app_state::AppState;
33use crate::call::REACTION_SHOWN;
35use crate::call::REACTION_SHOWN;
34use crate::call::TileSize;
36use crate::call::TileSize;
35use crate::call::{
37use crate::call::{CallKind, CallModel, Tile, TileState};
36 CHAT_OPEN_TILES, CallKind, CallModel, GridLayout, MAX_TILES, Tile, TileState, grid_layout,
37 tile_size,
38};
39use crate::rows::reaction_glyph as chat_reaction_glyph;
38use crate::rows::reaction_glyph as chat_reaction_glyph;
40use crate::theme;
39use crate::theme;
41
40
@@ -48,16 +47,16 @@ pub(super) const MENU_WIDTH: f32 = 280.;
48const PULSE_PERIOD: Duration = Duration::from_millis(1400);
47const PULSE_PERIOD: Duration = Duration::from_millis(1400);
49const BLINK_HALF_PERIOD: Duration = Duration::from_millis(500);
48const BLINK_HALF_PERIOD: Duration = Duration::from_millis(500);
50const BLINK_DIMMED_OPACITY: f32 = 0.45;
49const BLINK_DIMMED_OPACITY: f32 = 0.45;
51const DISABLED_OPACITY: f32 = 0.4;
50pub(super) const DISABLED_OPACITY: f32 = 0.4;
52const TILE_GAP: f32 = 20.;
51pub(super) const TILE_GAP: f32 = 20.;
53const GRID_PADDING: f32 = 24.;
52pub(super) const GRID_PADDING: f32 = 24.;
54const STRIP_TILE: TileSize = TileSize {
53pub(super) const STRIP_TILE: TileSize = TileSize {
55 width: 232.,
54 width: 232.,
56 height: 131.,
55 height: 131.,
57 avatar: 56.,
56 avatar: 56.,
58};
57};
59const STRIP_GAP: f32 = 12.;
58pub(super) const STRIP_GAP: f32 = 12.;
60const STRIP_VISIBLE: f32 = 4.;
59pub(super) const STRIP_VISIBLE: f32 = 4.;
61const TILE_RADIUS: f32 = 12.;
60const TILE_RADIUS: f32 = 12.;
62const NAME_PLATE_BACKGROUND: f32 = 0.6;
61const NAME_PLATE_BACKGROUND: f32 = 0.6;
63pub const NO_MICROPHONE_HINT: &str = "No microphone found";
62pub const NO_MICROPHONE_HINT: &str = "No microphone found";
@@ -311,23 +310,6 @@ fn tile(
311 .children(tile_overlays(extras))
310 .children(tile_overlays(extras))
312}
311}
313
312
314fn overflow_tile(size: TileSize, hidden: usize) -> Div {
315 v_flex()
316 .w(px(size.width))
317 .h(px(size.height))
318 .items_center()
319 .justify_center()
320 .rounded(px(12.))
321 .bg(theme::row_hover())
322 .child(
323 div()
324 .text_size(px(size.avatar * 0.5))
325 .font_weight(FontWeight::SEMIBOLD)
326 .text_color(theme::text_muted())
327 .child(format!("+{hidden}")),
328 )
329}
330
331fn control_shell(id: &'static str, background: Hsla) -> Stateful<Div> {
313fn control_shell(id: &'static str, background: Hsla) -> Stateful<Div> {
332 div()
314 div()
333 .id(id)
315 .id(id)
@@ -496,7 +478,12 @@ fn share_items(
496 popup
478 popup
497}
479}
498
480
499fn share_button(app: &Entity<AppState>, model: &CallModel, sound: bool) -> AnyElement {
481fn share_button(
482 app: &Entity<AppState>,
483 model: &CallModel,
484 sound: bool,
485 menu_open: bool,
486) -> AnyElement {
500 if model.local_share.is_some() {
487 if model.local_share.is_some() {
501 let app = app.clone();
488 let app = app.clone();
502 return round_control(
489 return round_control(
@@ -526,6 +513,7 @@ fn share_button(app: &Entity<AppState>, model: &CallModel, sound: bool) -> AnyEl
526 .into_any_element();
513 .into_any_element();
527 }
514 }
528 let app = app.clone();
515 let app = app.clone();
516 let open_app = app.clone();
529 let model = model.clone();
517 let model = model.clone();
530 Button::new("call-share")
518 Button::new("call-share")
531 .ghost()
519 .ghost()
@@ -536,6 +524,10 @@ fn share_button(app: &Entity<AppState>, model: &CallModel, sound: bool) -> AnyEl
536 .dropdown_menu_with_anchor(Anchor::BottomLeft, move |popup, _, _| {
524 .dropdown_menu_with_anchor(Anchor::BottomLeft, move |popup, _, _| {
537 share_items(popup, &app, &model, sound)
525 share_items(popup, &app, &model, sound)
538 })
526 })
527 .open(menu_open)
528 .on_open_change(move |open, _, cx| {
529 open_app.update(cx, |state, cx| state.set_call_share_menu(*open, cx))
530 })
539 .into_any_element()
531 .into_any_element()
540}
532}
541
533
@@ -817,7 +809,7 @@ fn mic_menu_button(app: &Entity<AppState>, model: &CallModel) -> impl IntoElemen
817 })
809 })
818}
810}
819
811
820fn person_tile(
812pub(super) fn person_tile(
821 app: &Entity<AppState>,
813 app: &Entity<AppState>,
822 state: &AppState,
814 state: &AppState,
823 model: &CallModel,
815 model: &CallModel,
@@ -895,7 +887,7 @@ fn person_tile_body(
895 .into_any_element()
887 .into_any_element()
896}
888}
897
889
898fn own_tile(
890pub(super) fn own_tile(
899 app: &Entity<AppState>,
891 app: &Entity<AppState>,
900 state: &AppState,
892 state: &AppState,
901 model: &CallModel,
893 model: &CallModel,
@@ -958,59 +950,11 @@ fn own_tile_body(
958 .into_any_element()
950 .into_any_element()
959}
951}
960
952
961fn remote_tiles(
962 app: &Entity<AppState>,
963 state: &AppState,
964 model: &CallModel,
965 size: TileSize,
966 hidden_cap: GridLayout,
967 now: Instant,
968) -> Vec<AnyElement> {
969 let visible = model.visible_tiles();
970 let mut cells: Vec<AnyElement> = visible
971 .iter()
972 .take(hidden_cap.shown_others)
973 .map(|remote| person_tile(app, state, model, remote, size, now))
974 .collect();
975 if hidden_cap.hidden > 0 {
976 cells.push(overflow_tile(size, hidden_cap.hidden).into_any_element());
977 }
978 cells
979}
980
981fn people_strip(
982 app: &Entity<AppState>,
983 state: &AppState,
984 model: &CallModel,
985 now: Instant,
986 focused: Option<&str>,
987) -> Stateful<Div> {
988 let mut cells: Vec<AnyElement> = model
989 .strip_tiles()
990 .into_iter()
991 .filter(|remote| Some(remote.mri.as_str()) != focused)
992 .map(|remote| person_tile(app, state, model, remote, STRIP_TILE, now))
993 .collect();
994 if focused.is_none() || focused != model.own_mri.as_deref() {
995 let own_index = model.own_cell_index(cells.len());
996 cells.insert(own_index, own_tile(app, state, model, STRIP_TILE, now));
997 }
998 v_flex()
999 .id("call-strip")
1000 .flex_none()
1001 .w(px(STRIP_TILE.width))
1002 .max_h(px(
1003 STRIP_VISIBLE * (STRIP_TILE.height + STRIP_GAP) - STRIP_GAP
1004 ))
1005 .gap(px(STRIP_GAP))
1006 .overflow_y_scroll()
1007 .children(cells)
1008}
1009
1010pub fn render_call_view(
953pub fn render_call_view(
1011 app: &Entity<AppState>,
954 app: &Entity<AppState>,
1012 state: &AppState,
955 state: &AppState,
1013 chat: Option<Entity<ConversationView>>,
956 chat: Option<Entity<ConversationView>>,
957 fullscreen: bool,
1014) -> Option<AnyElement> {
958) -> Option<AnyElement> {
1015 let call = state.call.as_ref()?;
959 let call = state.call.as_ref()?;
1016 let model = &call.model;
960 let model = &call.model;
@@ -1045,31 +989,9 @@ pub fn render_call_view(
1045 .child(div().flex_1())
989 .child(div().flex_1())
1046 .children(return_button(app, model));
990 .children(return_button(app, model));
1047
991
1048 let max_tiles = if chat.is_some() {
1049 CHAT_OPEN_TILES
1050 } else {
1051 MAX_TILES
1052 };
1053 let layout = grid_layout(model.visible_tiles().len(), max_tiles);
1054 let cells_for_size = if chat.is_some() {
1055 MAX_TILES
1056 } else {
1057 layout.shown_others + usize::from(layout.hidden > 0) + 1
1058 };
1059 let size = tile_size(cells_for_size);
1060 let mut cells = remote_tiles(app, state, model, size, layout, now);
1061 let own_index = model.own_cell_index(cells.len());
1062 cells.insert(own_index, own_tile(app, state, model, size, now));
1063 let focus = model.focus().filter(|_| model.screen_sharer.is_none());
1064 let stage = render_stage(app, state, false)
1065 .or_else(|| whiteboard_stage(app, model))
1066 .or_else(|| {
1067 focus
1068 .as_ref()
1069 .and_then(|focus| render_focus_stage(app, state, focus, now))
1070 });
1071 let hold = hold_panel(app, model);
992 let hold = hold_panel(app, model);
1072 let focused = focus.as_ref().map(|focus| focus.mri.as_str());
993 let share_stage = render_stage(app, state, false).or_else(|| whiteboard_stage(app, model));
994 let region = stage_region(app, state, call, now, hold, share_stage);
1073
995
1074 let controls = h_flex()
996 let controls = h_flex()
1075 .w_full()
997 .w_full()
@@ -1096,11 +1018,17 @@ pub fn render_call_view(
1096 .child(camera_button(app, model))
1018 .child(camera_button(app, model))
1097 .children(camera_menu_button(app, model, BackgroundMenu::of(state))),
1019 .children(camera_menu_button(app, model, BackgroundMenu::of(state))),
1098 )
1020 )
1099 .child(share_button(app, model, state.call_share_sound))
1021 .child(share_button(
1022 app,
1023 model,
1024 state.call_share_sound,
1025 call.share_menu_open,
1026 ))
1100 .when(model.has_reaction_controls(), |row| {
1027 .when(model.has_reaction_controls(), |row| {
1101 row.child(hand_button(app, model))
1028 row.child(hand_button(app, model))
1102 .child(reactions_button(app, model))
1029 .child(reactions_button(app, model))
1103 })
1030 })
1031 .child(view_button(app, model, fullscreen))
1104 .children(more_button(app, model))
1032 .children(more_button(app, model))
1105 .when(call.chat_thread().is_some(), |row| {
1033 .when(call.chat_thread().is_some(), |row| {
1106 row.child(chat_button(app, call.chat_open, state.call_chat_unread()))
1034 row.child(chat_button(app, call.chat_open, state.call_chat_unread()))
@@ -1110,52 +1038,52 @@ pub fn render_call_view(
1110 row.child(leave_menu(app, model))
1038 row.child(leave_menu(app, model))
1111 });
1039 });
1112
1040
1113 let column = v_flex()
1041 let top = v_flex()
1042 .w_full()
1043 .flex_none()
1044 .child(header)
1045 .children(lobby_banner(app, model, call.lobby_list_open))
1046 .children(health_banner(app, model))
1047 .children(sharing_banner(app, model, state.call_share_sound))
1048 .children(consult_banner(app, state));
1049
1050 let chrome_visible = call
1051 .fullscreen
1052 .is_none_or(|fullscreen| fullscreen.chrome_visible(now));
1053 let move_app = app.clone();
1054 let base = v_flex()
1114 .relative()
1055 .relative()
1115 .flex_1()
1056 .flex_1()
1116 .min_w_0()
1057 .min_w_0()
1117 .h_full()
1058 .h_full()
1118 .rounded(px(10.))
1119 .overflow_hidden()
1059 .overflow_hidden()
1120 .bg(theme::surface())
1060 .bg(theme::surface());
1121 .child(header)
1061 let column = if fullscreen {
1122 .children(lobby_banner(app, model))
1062 base.on_mouse_move(move |_, _, cx| {
1123 .children(health_banner(app, model))
1063 move_app.update(cx, |state, cx| state.touch_call_chrome(cx))
1124 .children(sharing_banner(app, model, state.call_share_sound))
1125 .children(consult_banner(app, state))
1126 .child(match stage {
1127 _ if hold.is_some() => hold.expect("checked above"),
1128 Some(stage) => h_flex()
1129 .flex_1()
1130 .min_h_0()
1131 .p(px(GRID_PADDING))
1132 .gap(px(TILE_GAP))
1133 .items_center()
1134 .child(stage)
1135 .child(people_strip(app, state, model, now, focused))
1136 .into_any_element(),
1137 None => h_flex()
1138 .id("call-grid")
1139 .flex_1()
1140 .min_h_0()
1141 .overflow_y_scroll()
1142 .flex_wrap()
1143 .content_center()
1144 .p(px(GRID_PADDING))
1145 .gap(px(TILE_GAP))
1146 .items_center()
1147 .justify_center()
1148 .children(cells)
1149 .into_any_element(),
1150 })
1064 })
1151 .child(controls)
1065 .when(chrome_visible, |column| {
1152 .children(captions_overlay(model, now))
1066 column.child(fullscreen_chrome("call-chrome-top", app, top))
1153 .children(captions_hint_chip(model))
1067 })
1154 .children(state.transfer_picker.clone())
1068 .child(region)
1155 .children(consent_overlay(app, model));
1069 .when(chrome_visible, |column| {
1070 column.child(fullscreen_chrome("call-chrome-bottom", app, controls))
1071 })
1072 } else {
1073 base.rounded(px(10.))
1074 .child(top.debug_selector(|| "shell/islands/main/call-header".into()))
1075 .child(region)
1076 .child(controls.debug_selector(|| "shell/islands/main/call-controls".into()))
1077 }
1078 .children(captions_overlay(model, now))
1079 .children(captions_hint_chip(model))
1080 .children(state.transfer_picker.clone())
1081 .children(consent_overlay(app, model));
1156 Some(
1082 Some(
1157 h_flex()
1083 h_flex()
1158 .debug_selector(|| "shell/islands/main".into())
1084 .when(!fullscreen, |row| {
1085 row.debug_selector(|| "shell/islands/main".into())
1086 })
1159 .flex_1()
1087 .flex_1()
1160 .min_w_0()
1088 .min_w_0()
1161 .h_full()
1089 .h_full()
@@ -1166,6 +1094,18 @@ pub fn render_call_view(
1166 )
1094 )
1167}
1095}
1168
1096
1097fn fullscreen_chrome(id: &'static str, app: &Entity<AppState>, content: Div) -> Stateful<Div> {
1098 let hover_app = app.clone();
1099 div()
1100 .id(id)
1101 .w_full()
1102 .flex_none()
1103 .on_hover(move |hovered, _, cx| {
1104 hover_app.update(cx, |state, cx| state.set_call_chrome_hovered(*hovered, cx))
1105 })
1106 .child(content)
1107}
1108
1169fn chat_panel(app: &Entity<AppState>, chat: Entity<ConversationView>) -> AnyElement {
1109fn chat_panel(app: &Entity<AppState>, chat: Entity<ConversationView>) -> AnyElement {
1170 let app = app.clone();
1110 let app = app.clone();
1171 v_flex()
1111 v_flex()
crates/app/src/views/call_view_menu.rs added +148 −0
@@ -0,0 +1,148 @@
1 use gpui_kit::assets::IconName;
2 use gpui_kit::component::{
3 button::{Button, ButtonVariants as _},
4 h_flex,
5 menu::{DropdownMenu as _, PopupMenu, PopupMenuItem},
6 switch::Switch,
7 };
8 use gpui_kit::prelude::FluentBuilder as _;
9 use gpui_kit::*;
10
11 use super::call_view::{CONTROL_SIZE, DISABLED_OPACITY, MENU_WIDTH, round_control};
12 use super::shortcuts::keys_for_label;
13 use crate::app_state::AppState;
14 use crate::call::{CallLayout, CallModel};
15 use crate::theme;
16
17 pub const FULL_SCREEN_LABEL: &str = "Full screen";
18 const CONTENT_HINT: &str = "Only while someone shares";
19
20 fn hint_row(label: &'static str, hint: String, dimmed: bool) -> Div {
21 h_flex()
22 .w_full()
23 .gap(px(16.))
24 .items_center()
25 .justify_between()
26 .when(dimmed, |row| row.opacity(DISABLED_OPACITY))
27 .child(label)
28 .child(
29 div()
30 .text_size(px(12.))
31 .text_color(theme::text_muted())
32 .child(hint),
33 )
34 }
35
36 fn layout_item(app: &Entity<AppState>, model: &CallModel, layout: CallLayout) -> PopupMenuItem {
37 let unavailable = layout == CallLayout::Content && !model.has_content();
38 let item = if unavailable {
39 PopupMenuItem::element(move |_, _| hint_row(layout.label(), CONTENT_HINT.to_owned(), true))
40 } else {
41 PopupMenuItem::new(layout.label())
42 };
43 let app = app.clone();
44 item.checked(layout == model.effective_layout())
45 .disabled(unavailable)
46 .on_click(move |_, _, cx| app.update(cx, |state, cx| state.set_call_layout(layout, cx)))
47 }
48
49 fn switch_item(
50 id: &'static str,
51 label: &'static str,
52 on: bool,
53 toggle: impl Fn(&mut AppState, &mut Context<AppState>) + Clone + 'static,
54 app: &Entity<AppState>,
55 ) -> PopupMenuItem {
56 let app = app.clone();
57 PopupMenuItem::element(move |_, _| {
58 h_flex()
59 .w_full()
60 .gap(px(16.))
61 .items_center()
62 .justify_between()
63 .child(label)
64 .child(Switch::new(id).checked(on))
65 })
66 .on_click(move |_, _, cx| app.update(cx, |state, cx| toggle(state, cx)))
67 }
68
69 fn view_items(
70 popup: PopupMenu,
71 app: &Entity<AppState>,
72 model: &CallModel,
73 fullscreen: bool,
74 ) -> PopupMenu {
75 let hide_me = model.view.hide_me;
76 let full_screen_app = app.clone();
77 let mut popup = popup
78 .min_w(px(MENU_WIDTH))
79 .item(PopupMenuItem::label("Layout"));
80 for layout in [
81 CallLayout::Gallery,
82 CallLayout::Speaker,
83 CallLayout::Content,
84 ] {
85 popup = popup.item(layout_item(app, model, layout));
86 }
87 popup
88 .separator()
89 .item(switch_item(
90 "call-view-hide-no-video",
91 "Hide people without video",
92 model.view.hide_no_video,
93 |state, cx| state.toggle_call_hide_no_video(cx),
94 app,
95 ))
96 .item(switch_item(
97 "call-view-hide-me",
98 "Hide me",
99 hide_me,
100 move |state, cx| state.set_call_hide_me(!hide_me, cx),
101 app,
102 ))
103 .item(switch_item(
104 "call-view-chat-bubbles",
105 "Chat bubbles",
106 model.view.chat_bubbles,
107 |state, cx| state.toggle_call_chat_bubbles(cx),
108 app,
109 ))
110 .separator()
111 .item(
112 PopupMenuItem::element(move |_, _| {
113 hint_row(
114 FULL_SCREEN_LABEL,
115 keys_for_label(FULL_SCREEN_LABEL).unwrap_or_default(),
116 false,
117 )
118 })
119 .checked(fullscreen)
120 .on_click(move |_, _, cx| {
121 full_screen_app.update(cx, |state, cx| state.toggle_call_fullscreen(cx))
122 }),
123 )
124 }
125
126 pub(super) fn view_button(
127 app: &Entity<AppState>,
128 model: &CallModel,
129 fullscreen: bool,
130 ) -> AnyElement {
131 let app = app.clone();
132 let model = model.clone();
133 Button::new("call-view")
134 .ghost()
135 .p_0()
136 .size(px(CONTROL_SIZE))
137 .rounded_full()
138 .child(round_control(
139 "call-view-face",
140 IconName::LayoutGrid,
141 theme::surface_raised(),
142 theme::text(),
143 ))
144 .dropdown_menu_with_anchor(Anchor::BottomRight, move |popup, _, _| {
145 view_items(popup, &app, &model, fullscreen)
146 })
147 .into_any_element()
148 }
@@ -0,0 +1,148 @@
1use gpui_kit::assets::IconName;
2use gpui_kit::component::{
3 button::{Button, ButtonVariants as _},
4 h_flex,
5 menu::{DropdownMenu as _, PopupMenu, PopupMenuItem},
6 switch::Switch,
7};
8use gpui_kit::prelude::FluentBuilder as _;
9use gpui_kit::*;
10
11use super::call_view::{CONTROL_SIZE, DISABLED_OPACITY, MENU_WIDTH, round_control};
12use super::shortcuts::keys_for_label;
13use crate::app_state::AppState;
14use crate::call::{CallLayout, CallModel};
15use crate::theme;
16
17pub const FULL_SCREEN_LABEL: &str = "Full screen";
18const CONTENT_HINT: &str = "Only while someone shares";
19
20fn hint_row(label: &'static str, hint: String, dimmed: bool) -> Div {
21 h_flex()
22 .w_full()
23 .gap(px(16.))
24 .items_center()
25 .justify_between()
26 .when(dimmed, |row| row.opacity(DISABLED_OPACITY))
27 .child(label)
28 .child(
29 div()
30 .text_size(px(12.))
31 .text_color(theme::text_muted())
32 .child(hint),
33 )
34}
35
36fn layout_item(app: &Entity<AppState>, model: &CallModel, layout: CallLayout) -> PopupMenuItem {
37 let unavailable = layout == CallLayout::Content && !model.has_content();
38 let item = if unavailable {
39 PopupMenuItem::element(move |_, _| hint_row(layout.label(), CONTENT_HINT.to_owned(), true))
40 } else {
41 PopupMenuItem::new(layout.label())
42 };
43 let app = app.clone();
44 item.checked(layout == model.effective_layout())
45 .disabled(unavailable)
46 .on_click(move |_, _, cx| app.update(cx, |state, cx| state.set_call_layout(layout, cx)))
47}
48
49fn switch_item(
50 id: &'static str,
51 label: &'static str,
52 on: bool,
53 toggle: impl Fn(&mut AppState, &mut Context<AppState>) + Clone + 'static,
54 app: &Entity<AppState>,
55) -> PopupMenuItem {
56 let app = app.clone();
57 PopupMenuItem::element(move |_, _| {
58 h_flex()
59 .w_full()
60 .gap(px(16.))
61 .items_center()
62 .justify_between()
63 .child(label)
64 .child(Switch::new(id).checked(on))
65 })
66 .on_click(move |_, _, cx| app.update(cx, |state, cx| toggle(state, cx)))
67}
68
69fn view_items(
70 popup: PopupMenu,
71 app: &Entity<AppState>,
72 model: &CallModel,
73 fullscreen: bool,
74) -> PopupMenu {
75 let hide_me = model.view.hide_me;
76 let full_screen_app = app.clone();
77 let mut popup = popup
78 .min_w(px(MENU_WIDTH))
79 .item(PopupMenuItem::label("Layout"));
80 for layout in [
81 CallLayout::Gallery,
82 CallLayout::Speaker,
83 CallLayout::Content,
84 ] {
85 popup = popup.item(layout_item(app, model, layout));
86 }
87 popup
88 .separator()
89 .item(switch_item(
90 "call-view-hide-no-video",
91 "Hide people without video",
92 model.view.hide_no_video,
93 |state, cx| state.toggle_call_hide_no_video(cx),
94 app,
95 ))
96 .item(switch_item(
97 "call-view-hide-me",
98 "Hide me",
99 hide_me,
100 move |state, cx| state.set_call_hide_me(!hide_me, cx),
101 app,
102 ))
103 .item(switch_item(
104 "call-view-chat-bubbles",
105 "Chat bubbles",
106 model.view.chat_bubbles,
107 |state, cx| state.toggle_call_chat_bubbles(cx),
108 app,
109 ))
110 .separator()
111 .item(
112 PopupMenuItem::element(move |_, _| {
113 hint_row(
114 FULL_SCREEN_LABEL,
115 keys_for_label(FULL_SCREEN_LABEL).unwrap_or_default(),
116 false,
117 )
118 })
119 .checked(fullscreen)
120 .on_click(move |_, _, cx| {
121 full_screen_app.update(cx, |state, cx| state.toggle_call_fullscreen(cx))
122 }),
123 )
124}
125
126pub(super) fn view_button(
127 app: &Entity<AppState>,
128 model: &CallModel,
129 fullscreen: bool,
130) -> AnyElement {
131 let app = app.clone();
132 let model = model.clone();
133 Button::new("call-view")
134 .ghost()
135 .p_0()
136 .size(px(CONTROL_SIZE))
137 .rounded_full()
138 .child(round_control(
139 "call-view-face",
140 IconName::LayoutGrid,
141 theme::surface_raised(),
142 theme::text(),
143 ))
144 .dropdown_menu_with_anchor(Anchor::BottomRight, move |popup, _, _| {
145 view_items(popup, &app, &model, fullscreen)
146 })
147 .into_any_element()
148}
crates/app/src/views/mod.rs +2 −0
@@ -6,11 +6,13 @@ pub mod avatar;
6 6 pub mod call_controls;
7 7 pub mod call_extras;
8 8 pub mod call_health;
9 pub mod call_layouts;
9 10 pub mod call_mini;
10 11 pub mod call_mini_window;
11 12 pub mod call_organizer;
12 13 pub mod call_stage;
13 14 pub mod call_view;
15 pub mod call_view_menu;
14 16 pub mod calls_tab;
15 17 pub mod card_carousel;
16 18 pub mod card_chart;
@@ -6,11 +6,13 @@ pub mod avatar;
6pub mod call_controls;
6pub mod call_controls;
7pub mod call_extras;
7pub mod call_extras;
8pub mod call_health;
8pub mod call_health;
9pub mod call_layouts;
9pub mod call_mini;
10pub mod call_mini;
10pub mod call_mini_window;
11pub mod call_mini_window;
11pub mod call_organizer;
12pub mod call_organizer;
12pub mod call_stage;
13pub mod call_stage;
13pub mod call_view;
14pub mod call_view;
15pub mod call_view_menu;
14pub mod calls_tab;
16pub mod calls_tab;
15pub mod card_carousel;
17pub mod card_carousel;
16pub mod card_chart;
18pub mod card_chart;
crates/app/src/views/shell.rs +65 −6
@@ -5,7 +5,7 @@ use gpui_kit::*;
5 5
6 6 use super::activity_panel::{ActivityPanel, ActivityPanelEvent};
7 7 use super::call_mini::render_call_mini;
8 use super::call_stage::render_stage_overlay;
8 use super::call_stage::{render_call_overlay, render_stage_overlay};
9 9 use super::call_view::render_call_view;
10 10 use super::conversation::{ConversationView, ReplyToHovered};
11 11 use super::dialog_overlay::render_task_dialog;
@@ -16,8 +16,9 @@ use super::rail::RailView;
16 16 use super::saved_panel::{SavedPanel, SavedPanelEvent};
17 17 use super::shortcuts::{
18 18 AcceptCall, DeclineCall, HangUpCall, NextConversation, OpenActivity, OpenCallsTab,
19 OpenChannelsTab, OpenChatsTab, OpenSaved, PreviousConversation, Scope, ShowShortcuts,
20 ToggleCallCamera, ToggleCallShare,
19 OpenChannelsTab, OpenChatsTab, OpenLobbyList, OpenSaved, PreviousConversation, Scope,
20 ShowShortcuts, StartAudioCall, StartVideoCall, ToggleCallCamera, ToggleCallFullscreen,
21 ToggleCallHand, ToggleCallShare,
21 22 };
22 23 use super::shortcuts_dialog::{ShortcutsDialog, ShortcutsDialogEvent};
23 24 use super::sidebar::{SIDEBAR_WIDTH, SidebarView};
@@ -91,6 +92,8 @@ pub struct AppShell {
91 92 agent_dialog: Option<Entity<StartDialog>>,
92 93 profile_card: Option<Entity<ProfileCard>>,
93 94 focus_handle: FocusHandle,
95 call_window_fullscreen: bool,
96 window_was_fullscreen: bool,
94 97 open_target: Option<OpenTarget>,
95 98 update: UpdateStatus,
96 99 user_input: Arc<UserInput>,
@@ -205,7 +208,7 @@ impl AppShell {
205 208 this.user_input.touch();
206 209 if event.keystroke.key == "escape" {
207 210 this.state
208 .update(cx, |state, cx| state.leave_stage_fullscreen(cx));
211 .update(cx, |state, cx| state.escape_call_fullscreen(cx));
209 212 }
210 213 });
211 214 let activation_observation = cx.observe_window_activation(window, |this, window, cx| {
@@ -232,6 +235,8 @@ impl AppShell {
232 235 agent_dialog: None,
233 236 profile_card: None,
234 237 focus_handle,
238 call_window_fullscreen: false,
239 window_was_fullscreen: false,
235 240 open_target,
236 241 update: UpdateStatus::UpToDate,
237 242 user_input,
@@ -562,6 +567,31 @@ impl AppShell {
562 567 cx.notify();
563 568 }
564 569
570 fn start_call_in_open_chat(&mut self, with_video: bool, cx: &mut Context<Self>) {
571 self.state.update(cx, |state, cx| {
572 if let Some(Selection::Chat(chat_id)) = state.selection.clone() {
573 if with_video {
574 state.start_chat_video_call(&chat_id, cx);
575 } else {
576 state.start_chat_call(&chat_id, cx);
577 }
578 }
579 });
580 }
581
582 fn sync_window_fullscreen(&mut self, wanted: bool, window: &mut Window) {
583 if wanted == self.call_window_fullscreen {
584 return;
585 }
586 self.call_window_fullscreen = wanted;
587 if wanted {
588 self.window_was_fullscreen = window.is_fullscreen();
589 }
590 if wanted != window.is_fullscreen() && (wanted || !self.window_was_fullscreen) {
591 window.toggle_fullscreen();
592 }
593 }
594
565 595 fn close_image_viewer(&mut self, window: &mut Window, cx: &mut Context<Self>) {
566 596 if self.image_viewer.take().is_some() {
567 597 window.focus(&self.focus_handle, cx);
@@ -683,8 +713,14 @@ impl Render for AppShell {
683 713 self.sync_call_chat(chat_thread, window, cx);
684 714 let chat_panel = self.call_chat.as_ref().map(|(_, view)| view.clone());
685 715 let state = self.state.read(cx);
686 let call_view =
687 render_call_view(&self.state, state, chat_panel).filter(|_| state.viewing_call());
716 let call_fullscreen = state.call_fullscreen();
717 let call_view = render_call_view(&self.state, state, chat_panel, call_fullscreen)
718 .filter(|_| state.viewing_call());
719 let (call_view, call_overlay) = match call_view {
720 Some(view) if call_fullscreen => (None, Some(render_call_overlay(view))),
721 view => (view, None),
722 };
723 self.sync_window_fullscreen(call_fullscreen, window);
688 724 let call_mini = render_call_mini(&self.state, state);
689 725 let stage_overlay = render_stage_overlay(&self.state, state);
690 726 let status = render_status_bar(
@@ -773,6 +809,28 @@ impl Render for AppShell {
773 809 this.state
774 810 .update(cx, |state, cx| state.toggle_call_share(cx));
775 811 }))
812 .on_action(cx.listener(|this, _: &ToggleCallHand, _, cx| {
813 this.state
814 .update(cx, |state, cx| state.toggle_call_hand(cx));
815 }))
816 .on_action(cx.listener(|this, _: &OpenLobbyList, _, cx| {
817 this.state
818 .update(cx, |state, cx| state.open_call_lobby_list(cx));
819 }))
820 .on_action(cx.listener(|this, _: &StartAudioCall, _, cx| {
821 this.start_call_in_open_chat(false, cx);
822 }))
823 .on_action(cx.listener(|this, _: &StartVideoCall, _, cx| {
824 this.start_call_in_open_chat(true, cx);
825 }))
826 .on_action(cx.listener(|this, _: &ToggleCallFullscreen, _, cx| {
827 if this.image_viewer.is_some() || !this.state.read(cx).viewing_call() {
828 cx.propagate();
829 return;
830 }
831 this.state
832 .update(cx, |state, cx| state.toggle_call_fullscreen(cx));
833 }))
776 834 .on_action(cx.listener(|this, _: &ReplyToHovered, window, cx| {
777 835 this.close_image_viewer(window, cx);
778 836 this.conversation.update(cx, |conversation, cx| {
@@ -795,6 +853,7 @@ impl Render for AppShell {
795 853 .child(status),
796 854 )
797 855 .children(call_mini)
856 .children(call_overlay)
798 857 .children(stage_overlay)
799 858 .children(self.image_viewer.clone())
800 859 .children(self.switcher.clone())
@@ -5,7 +5,7 @@ use gpui_kit::*;
5
5
6use super::activity_panel::{ActivityPanel, ActivityPanelEvent};
6use super::activity_panel::{ActivityPanel, ActivityPanelEvent};
7use super::call_mini::render_call_mini;
7use super::call_mini::render_call_mini;
8use super::call_stage::render_stage_overlay;
8use super::call_stage::{render_call_overlay, render_stage_overlay};
9use super::call_view::render_call_view;
9use super::call_view::render_call_view;
10use super::conversation::{ConversationView, ReplyToHovered};
10use super::conversation::{ConversationView, ReplyToHovered};
11use super::dialog_overlay::render_task_dialog;
11use super::dialog_overlay::render_task_dialog;
@@ -16,8 +16,9 @@ use super::rail::RailView;
16use super::saved_panel::{SavedPanel, SavedPanelEvent};
16use super::saved_panel::{SavedPanel, SavedPanelEvent};
17use super::shortcuts::{
17use super::shortcuts::{
18 AcceptCall, DeclineCall, HangUpCall, NextConversation, OpenActivity, OpenCallsTab,
18 AcceptCall, DeclineCall, HangUpCall, NextConversation, OpenActivity, OpenCallsTab,
19 OpenChannelsTab, OpenChatsTab, OpenSaved, PreviousConversation, Scope, ShowShortcuts,
19 OpenChannelsTab, OpenChatsTab, OpenLobbyList, OpenSaved, PreviousConversation, Scope,
20 ToggleCallCamera, ToggleCallShare,
20 ShowShortcuts, StartAudioCall, StartVideoCall, ToggleCallCamera, ToggleCallFullscreen,
21 ToggleCallHand, ToggleCallShare,
21};
22};
22use super::shortcuts_dialog::{ShortcutsDialog, ShortcutsDialogEvent};
23use super::shortcuts_dialog::{ShortcutsDialog, ShortcutsDialogEvent};
23use super::sidebar::{SIDEBAR_WIDTH, SidebarView};
24use super::sidebar::{SIDEBAR_WIDTH, SidebarView};
@@ -91,6 +92,8 @@ pub struct AppShell {
91 agent_dialog: Option<Entity<StartDialog>>,
92 agent_dialog: Option<Entity<StartDialog>>,
92 profile_card: Option<Entity<ProfileCard>>,
93 profile_card: Option<Entity<ProfileCard>>,
93 focus_handle: FocusHandle,
94 focus_handle: FocusHandle,
95 call_window_fullscreen: bool,
96 window_was_fullscreen: bool,
94 open_target: Option<OpenTarget>,
97 open_target: Option<OpenTarget>,
95 update: UpdateStatus,
98 update: UpdateStatus,
96 user_input: Arc<UserInput>,
99 user_input: Arc<UserInput>,
@@ -205,7 +208,7 @@ impl AppShell {
205 this.user_input.touch();
208 this.user_input.touch();
206 if event.keystroke.key == "escape" {
209 if event.keystroke.key == "escape" {
207 this.state
210 this.state
208 .update(cx, |state, cx| state.leave_stage_fullscreen(cx));
211 .update(cx, |state, cx| state.escape_call_fullscreen(cx));
209 }
212 }
210 });
213 });
211 let activation_observation = cx.observe_window_activation(window, |this, window, cx| {
214 let activation_observation = cx.observe_window_activation(window, |this, window, cx| {
@@ -232,6 +235,8 @@ impl AppShell {
232 agent_dialog: None,
235 agent_dialog: None,
233 profile_card: None,
236 profile_card: None,
234 focus_handle,
237 focus_handle,
238 call_window_fullscreen: false,
239 window_was_fullscreen: false,
235 open_target,
240 open_target,
236 update: UpdateStatus::UpToDate,
241 update: UpdateStatus::UpToDate,
237 user_input,
242 user_input,
@@ -562,6 +567,31 @@ impl AppShell {
562 cx.notify();
567 cx.notify();
563 }
568 }
564
569
570 fn start_call_in_open_chat(&mut self, with_video: bool, cx: &mut Context<Self>) {
571 self.state.update(cx, |state, cx| {
572 if let Some(Selection::Chat(chat_id)) = state.selection.clone() {
573 if with_video {
574 state.start_chat_video_call(&chat_id, cx);
575 } else {
576 state.start_chat_call(&chat_id, cx);
577 }
578 }
579 });
580 }
581
582 fn sync_window_fullscreen(&mut self, wanted: bool, window: &mut Window) {
583 if wanted == self.call_window_fullscreen {
584 return;
585 }
586 self.call_window_fullscreen = wanted;
587 if wanted {
588 self.window_was_fullscreen = window.is_fullscreen();
589 }
590 if wanted != window.is_fullscreen() && (wanted || !self.window_was_fullscreen) {
591 window.toggle_fullscreen();
592 }
593 }
594
565 fn close_image_viewer(&mut self, window: &mut Window, cx: &mut Context<Self>) {
595 fn close_image_viewer(&mut self, window: &mut Window, cx: &mut Context<Self>) {
566 if self.image_viewer.take().is_some() {
596 if self.image_viewer.take().is_some() {
567 window.focus(&self.focus_handle, cx);
597 window.focus(&self.focus_handle, cx);
@@ -683,8 +713,14 @@ impl Render for AppShell {
683 self.sync_call_chat(chat_thread, window, cx);
713 self.sync_call_chat(chat_thread, window, cx);
684 let chat_panel = self.call_chat.as_ref().map(|(_, view)| view.clone());
714 let chat_panel = self.call_chat.as_ref().map(|(_, view)| view.clone());
685 let state = self.state.read(cx);
715 let state = self.state.read(cx);
686 let call_view =
716 let call_fullscreen = state.call_fullscreen();
687 render_call_view(&self.state, state, chat_panel).filter(|_| state.viewing_call());
717 let call_view = render_call_view(&self.state, state, chat_panel, call_fullscreen)
718 .filter(|_| state.viewing_call());
719 let (call_view, call_overlay) = match call_view {
720 Some(view) if call_fullscreen => (None, Some(render_call_overlay(view))),
721 view => (view, None),
722 };
723 self.sync_window_fullscreen(call_fullscreen, window);
688 let call_mini = render_call_mini(&self.state, state);
724 let call_mini = render_call_mini(&self.state, state);
689 let stage_overlay = render_stage_overlay(&self.state, state);
725 let stage_overlay = render_stage_overlay(&self.state, state);
690 let status = render_status_bar(
726 let status = render_status_bar(
@@ -773,6 +809,28 @@ impl Render for AppShell {
773 this.state
809 this.state
774 .update(cx, |state, cx| state.toggle_call_share(cx));
810 .update(cx, |state, cx| state.toggle_call_share(cx));
775 }))
811 }))
812 .on_action(cx.listener(|this, _: &ToggleCallHand, _, cx| {
813 this.state
814 .update(cx, |state, cx| state.toggle_call_hand(cx));
815 }))
816 .on_action(cx.listener(|this, _: &OpenLobbyList, _, cx| {
817 this.state
818 .update(cx, |state, cx| state.open_call_lobby_list(cx));
819 }))
820 .on_action(cx.listener(|this, _: &StartAudioCall, _, cx| {
821 this.start_call_in_open_chat(false, cx);
822 }))
823 .on_action(cx.listener(|this, _: &StartVideoCall, _, cx| {
824 this.start_call_in_open_chat(true, cx);
825 }))
826 .on_action(cx.listener(|this, _: &ToggleCallFullscreen, _, cx| {
827 if this.image_viewer.is_some() || !this.state.read(cx).viewing_call() {
828 cx.propagate();
829 return;
830 }
831 this.state
832 .update(cx, |state, cx| state.toggle_call_fullscreen(cx));
833 }))
776 .on_action(cx.listener(|this, _: &ReplyToHovered, window, cx| {
834 .on_action(cx.listener(|this, _: &ReplyToHovered, window, cx| {
777 this.close_image_viewer(window, cx);
835 this.close_image_viewer(window, cx);
778 this.conversation.update(cx, |conversation, cx| {
836 this.conversation.update(cx, |conversation, cx| {
@@ -795,6 +853,7 @@ impl Render for AppShell {
795 .child(status),
853 .child(status),
796 )
854 )
797 .children(call_mini)
855 .children(call_mini)
856 .children(call_overlay)
798 .children(stage_overlay)
857 .children(stage_overlay)
799 .children(self.image_viewer.clone())
858 .children(self.image_viewer.clone())
800 .children(self.switcher.clone())
859 .children(self.switcher.clone())
crates/app/src/views/shortcuts.rs +11 −1
@@ -25,6 +25,11 @@ actions!(
25 25 HangUpCall,
26 26 ToggleCallCamera,
27 27 ToggleCallShare,
28 ToggleCallHand,
29 OpenLobbyList,
30 StartAudioCall,
31 StartVideoCall,
32 ToggleCallFullscreen,
28 33 ShowShortcuts
29 34 ]
30 35 );
@@ -112,7 +117,12 @@ pub const SHORTCUTS: &[Shortcut] = &[
112 117 shortcut!(Calls, GlobalOverTextFields, "Hang up or leave", "ctrl-shift-h", Some("cmd-shift-h"), HangUpCall),
113 118 shortcut!(Calls, GlobalOverTextFields, "Mute or unmute", "ctrl-shift-m", None, ToggleCallMute),
114 119 shortcut!(Calls, GlobalOverTextFields, "Turn camera on or off", "ctrl-shift-o", Some("cmd-shift-o"), ToggleCallCamera),
115 shortcut!(Calls, GlobalOverTextFields, "Start or stop sharing the screen", "ctrl-shift-e", Some("cmd-shift-e"), ToggleCallShare),
120 shortcut!(Calls, GlobalOverTextFields, "Open the share menu or stop sharing", "ctrl-shift-e", Some("cmd-shift-e"), ToggleCallShare),
121 shortcut!(Calls, GlobalOverTextFields, "Raise or lower hand", "ctrl-shift-k", Some("cmd-shift-k"), ToggleCallHand),
122 shortcut!(Calls, GlobalOverTextFields, "Open the lobby list", "ctrl-shift-y", Some("cmd-shift-y"), OpenLobbyList),
123 shortcut!(Calls, GlobalOverTextFields, "Start an audio call in this chat", "alt-shift-a", None, StartAudioCall),
124 shortcut!(Calls, GlobalOverTextFields, "Start a video call in this chat", "alt-shift-v", None, StartVideoCall),
125 shortcut!(Calls, GlobalOverTextFields, "Full screen", "f11", None, ToggleCallFullscreen),
116 126 ];
117 127
118 128 impl Shortcut {
@@ -25,6 +25,11 @@ actions!(
25 HangUpCall,
25 HangUpCall,
26 ToggleCallCamera,
26 ToggleCallCamera,
27 ToggleCallShare,
27 ToggleCallShare,
28 ToggleCallHand,
29 OpenLobbyList,
30 StartAudioCall,
31 StartVideoCall,
32 ToggleCallFullscreen,
28 ShowShortcuts
33 ShowShortcuts
29 ]
34 ]
30);
35);
@@ -112,7 +117,12 @@ pub const SHORTCUTS: &[Shortcut] = &[
112 shortcut!(Calls, GlobalOverTextFields, "Hang up or leave", "ctrl-shift-h", Some("cmd-shift-h"), HangUpCall),
117 shortcut!(Calls, GlobalOverTextFields, "Hang up or leave", "ctrl-shift-h", Some("cmd-shift-h"), HangUpCall),
113 shortcut!(Calls, GlobalOverTextFields, "Mute or unmute", "ctrl-shift-m", None, ToggleCallMute),
118 shortcut!(Calls, GlobalOverTextFields, "Mute or unmute", "ctrl-shift-m", None, ToggleCallMute),
114 shortcut!(Calls, GlobalOverTextFields, "Turn camera on or off", "ctrl-shift-o", Some("cmd-shift-o"), ToggleCallCamera),
119 shortcut!(Calls, GlobalOverTextFields, "Turn camera on or off", "ctrl-shift-o", Some("cmd-shift-o"), ToggleCallCamera),
115 shortcut!(Calls, GlobalOverTextFields, "Start or stop sharing the screen", "ctrl-shift-e", Some("cmd-shift-e"), ToggleCallShare),
120 shortcut!(Calls, GlobalOverTextFields, "Open the share menu or stop sharing", "ctrl-shift-e", Some("cmd-shift-e"), ToggleCallShare),
121 shortcut!(Calls, GlobalOverTextFields, "Raise or lower hand", "ctrl-shift-k", Some("cmd-shift-k"), ToggleCallHand),
122 shortcut!(Calls, GlobalOverTextFields, "Open the lobby list", "ctrl-shift-y", Some("cmd-shift-y"), OpenLobbyList),
123 shortcut!(Calls, GlobalOverTextFields, "Start an audio call in this chat", "alt-shift-a", None, StartAudioCall),
124 shortcut!(Calls, GlobalOverTextFields, "Start a video call in this chat", "alt-shift-v", None, StartVideoCall),
125 shortcut!(Calls, GlobalOverTextFields, "Full screen", "f11", None, ToggleCallFullscreen),
116];
126];
117
127
118impl Shortcut {
128impl Shortcut {
vendor/gpui-component/src/menu/dropdown_menu.rs +9 −0
@@ -39,6 +39,7 @@ pub struct DropdownMenuPopover<T: Selectable + IntoElement + 'static> {
39 39 trigger: T,
40 40 builder: Rc<dyn Fn(PopupMenu, &mut Window, &mut Context<PopupMenu>) -> PopupMenu>,
41 41 on_open_change: Option<Rc<dyn Fn(&bool, &mut Window, &mut App)>>,
42 open: Option<bool>,
42 43 }
43 44
44 45 impl<T> DropdownMenuPopover<T>
@@ -57,9 +58,16 @@ where
57 58 trigger,
58 59 builder: Rc::new(builder),
59 60 on_open_change: None,
61 open: None,
60 62 }
61 63 }
62 64
65 /// Control the open state from outside; pair it with `on_open_change`.
66 pub fn open(mut self, open: bool) -> Self {
67 self.open = Some(open);
68 self
69 }
70
63 71 /// Set the anchor corner for the dropdown menu popover.
64 72 pub fn anchor(mut self, anchor: impl Into<Anchor>) -> Self {
65 73 self.anchor = anchor.into();
@@ -114,6 +122,7 @@ where
114 122 .overlay_closable(false)
115 123 .trigger(self.trigger)
116 124 .anchor(self.anchor)
125 .when_some(self.open, |this, open| this.open(open))
117 126 .when_some(self.on_open_change, |this, callback| {
118 127 this.on_open_change(move |open, window, cx| callback(open, window, cx))
119 128 })
@@ -39,6 +39,7 @@ pub struct DropdownMenuPopover<T: Selectable + IntoElement + 'static> {
39 trigger: T,
39 trigger: T,
40 builder: Rc<dyn Fn(PopupMenu, &mut Window, &mut Context<PopupMenu>) -> PopupMenu>,
40 builder: Rc<dyn Fn(PopupMenu, &mut Window, &mut Context<PopupMenu>) -> PopupMenu>,
41 on_open_change: Option<Rc<dyn Fn(&bool, &mut Window, &mut App)>>,
41 on_open_change: Option<Rc<dyn Fn(&bool, &mut Window, &mut App)>>,
42 open: Option<bool>,
42}
43}
43
44
44impl<T> DropdownMenuPopover<T>
45impl<T> DropdownMenuPopover<T>
@@ -57,9 +58,16 @@ where
57 trigger,
58 trigger,
58 builder: Rc::new(builder),
59 builder: Rc::new(builder),
59 on_open_change: None,
60 on_open_change: None,
61 open: None,
60 }
62 }
61 }
63 }
62
64
65 /// Control the open state from outside; pair it with `on_open_change`.
66 pub fn open(mut self, open: bool) -> Self {
67 self.open = Some(open);
68 self
69 }
70
63 /// Set the anchor corner for the dropdown menu popover.
71 /// Set the anchor corner for the dropdown menu popover.
64 pub fn anchor(mut self, anchor: impl Into<Anchor>) -> Self {
72 pub fn anchor(mut self, anchor: impl Into<Anchor>) -> Self {
65 self.anchor = anchor.into();
73 self.anchor = anchor.into();
@@ -114,6 +122,7 @@ where
114 .overlay_closable(false)
122 .overlay_closable(false)
115 .trigger(self.trigger)
123 .trigger(self.trigger)
116 .anchor(self.anchor)
124 .anchor(self.anchor)
125 .when_some(self.open, |this, open| this.open(open))
117 .when_some(self.on_open_change, |this, callback| {
126 .when_some(self.on_open_change, |this, callback| {
118 this.on_open_change(move |open, window, cx| callback(open, window, cx))
127 this.on_open_change(move |open, window, cx| callback(open, window, cx))
119 })
128 })