| 1 | use std::sync::Arc; |
| 2 | use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH}; |
| 3 | |
| 4 | use calling::{DeviceEntry, MicSettings, NoiseSuppression, Reaction, ShareKind, VideoKey}; |
| 5 | use gpui_kit::assets::IconName; |
| 6 | use gpui_kit::component::{ |
| 7 | button::{Button, ButtonVariants as _}, |
| 8 | h_flex, |
| 9 | menu::{DropdownMenu as _, PopupMenu, PopupMenuItem}, |
| 10 | popover::Popover, |
| 11 | switch::Switch, |
| 12 | tooltip::Tooltip, |
| 13 | v_flex, |
| 14 | }; |
| 15 | use gpui_kit::prelude::FluentBuilder as _; |
| 16 | use gpui_kit::*; |
| 17 | |
| 18 | use super::avatar::person_avatar; |
| 19 | use super::call_control_fold::{ |
| 20 | Foldable, FoldedControls, fixed_controls_width, folded_for_width, in_more_menu, |
| 21 | }; |
| 22 | use super::call_extras::{ |
| 23 | CameraMenu, consent_overlay, consult_banner, hold_panel, recording_chip, return_button, |
| 24 | room_chip, whiteboard_stage, |
| 25 | }; |
| 26 | use super::call_health::{health_banner, health_indicator}; |
| 27 | use super::call_layouts::stage_region; |
| 28 | use super::call_organizer::{ |
| 29 | camera_menu_button, captions_hint_chip, captions_overlay, lobby_banner, more_button, pin_chip, |
| 30 | spotlight_chip, with_tile_menu, |
| 31 | }; |
| 32 | use super::call_people::{lock_banner, lock_chip, options_dialog, people_button, people_panel}; |
| 33 | use super::call_stage::{POP_OUT_TOOLTIP, StageMode, popped_placeholder, render_stage}; |
| 34 | use super::call_toolbar::{ |
| 35 | GROUP_GAP, LEAVE_HEIGHT, SPLIT_CHEVRON_WIDTH, TOOL_GAP, group_divider, split_chevron, |
| 36 | tool_face, tool_trigger, |
| 37 | }; |
| 38 | use super::call_view_menu::view_button; |
| 39 | use super::widgets::{Corner, corner_badge, count_badge, icon}; |
| 40 | use crate::app_state::AppState; |
| 41 | use crate::call::REACTION_SHOWN; |
| 42 | use crate::call::TileSize; |
| 43 | use crate::call::measured_stage; |
| 44 | use crate::call::{ActiveCall, CallKind, CallModel, Tile, TileState}; |
| 45 | use crate::rows::reaction_glyph as chat_reaction_glyph; |
| 46 | use crate::theme; |
| 47 | use app_ui_kit::layout::ISLAND_GAP; |
| 48 | |
| 49 | const HEADER_HEIGHT: f32 = 60.; |
| 50 | const RING_WIDTH: f32 = 3.; |
| 51 | const RING_GAP: f32 = 4.; |
| 52 | pub(super) const CONTROL_SIZE: f32 = 44.; |
| 53 | const CONTROL_ICON: f32 = 20.; |
| 54 | pub(super) const MENU_WIDTH: f32 = 280.; |
| 55 | const SHARE_MENU_WIDTH: f32 = 360.; |
| 56 | const PULSE_PERIOD: Duration = Duration::from_millis(1400); |
| 57 | const BLINK_HALF_PERIOD: Duration = Duration::from_millis(500); |
| 58 | const BLINK_DIMMED_OPACITY: f32 = 0.45; |
| 59 | pub(super) const DISABLED_OPACITY: f32 = 0.4; |
| 60 | const TILE_RADIUS: f32 = 12.; |
| 61 | const NAME_PLATE_BACKGROUND: f32 = 0.6; |
| 62 | const COMPACT_PLATE_BELOW: f32 = 200.; |
| 63 | pub const CHAT_PANEL_TAG: &str = "shell/islands/main/call-chat-panel"; |
| 64 | pub const NO_MICROPHONE_HINT: &str = "No microphone found"; |
| 65 | const AUDIO_OFF_HINT: &str = "Audio is off for this meeting"; |
| 66 | pub const NO_CAMERA_HINT: &str = "No camera found"; |
| 67 | pub const NO_SHARE_HINT: &str = "Sharing starts once the call is connected"; |
| 68 | pub const NO_WINDOWS_HINT: &str = "No windows found"; |
| 69 | pub(super) const BANNER_HEIGHT: f32 = 40.; |
| 70 | const MAX_WINDOW_ITEMS: usize = 12; |
| 71 | pub const SHARE_THUMBNAIL_TAG: &str = "call/share-menu/thumbnail"; |
| 72 | const SCREEN_THUMBNAIL: (f32, f32) = (128., 72.); |
| 73 | const WINDOW_THUMBNAIL: (f32, f32) = (96., 54.); |
| 74 | const THUMBNAIL_RADIUS: f32 = 6.; |
| 75 | const THUMBNAIL_ICON: f32 = 22.; |
| 76 | pub const LOBBY_TEXT: &str = "Waiting in the lobby..."; |
| 77 | pub(super) const CHAT_PANEL_WIDTH: f32 = 320.; |
| 78 | pub(super) const OVERLAY_BELOW: f32 = 720.; |
| 79 | const HEADER_END_PADDING: f32 = 8.; |
| 80 | const LEAVE_RADIUS: f32 = 6.; |
| 81 | const CHAT_HEADER_HEIGHT: f32 = 48.; |
| 82 | const REACTION_RISE: f32 = 24.; |
| 83 | const REACTION_FADE_FROM: f32 = 0.75; |
| 84 | const REACTION_CELL: f32 = 40.; |
| 85 | const SHARE_SOUND_LABEL: &str = "Include computer sound"; |
| 86 | const SHARE_MOTION_LABEL: &str = "Optimize for motion"; |
| 87 | const SHARE_STANDOUT_LABEL: &str = "Show me over my content"; |
| 88 | const SHARE_STANDOUT_NEEDS_CAMERA: &str = "Turn your camera on first"; |
| 89 | const NOISE_SUPPRESSION_LABEL: &str = "Noise suppression"; |
| 90 | const MUSIC_MODE_LABEL: &str = "Music mode"; |
| 91 | const PUSH_TO_TALK_HINT: &str = "Unmuted - release Ctrl+Space to mute"; |
| 92 | const PUSH_TO_TALK_TOP: f32 = 12.; |
| 93 | |
| 94 | pub fn reaction_glyph(reaction: &Reaction) -> String { |
| 95 | match reaction { |
| 96 | Reaction::Applause => "\u{1F44F}".to_owned(), |
| 97 | other => chat_reaction_glyph(other.name()), |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | fn is_emoji_glyph(glyph: &str) -> bool { |
| 102 | !glyph.is_ascii() |
| 103 | } |
| 104 | |
| 105 | #[derive(Default)] |
| 106 | struct TileExtras { |
| 107 | hand: Option<usize>, |
| 108 | own: bool, |
| 109 | reaction: Option<(Reaction, u64)>, |
| 110 | spotlight: bool, |
| 111 | pinned: bool, |
| 112 | fitted: bool, |
| 113 | } |
| 114 | |
| 115 | fn hand_badge(position: usize, own: bool) -> Div { |
| 116 | h_flex() |
| 117 | .h(px(24.)) |
| 118 | .px(px(8.)) |
| 119 | .gap(px(4.)) |
| 120 | .items_center() |
| 121 | .rounded_full() |
| 122 | .bg(theme::amber()) |
| 123 | .text_color(hsla(0., 0., 0.08, 1.)) |
| 124 | .text_size(px(12.)) |
| 125 | .font_weight(FontWeight::SEMIBOLD) |
| 126 | .child(if own { |
| 127 | "Hand raised".to_owned() |
| 128 | } else { |
| 129 | format!("Hand {position}") |
| 130 | }) |
| 131 | } |
| 132 | |
| 133 | fn reaction_chip(reaction: Reaction, serial: u64) -> AnyElement { |
| 134 | let glyph = reaction_glyph(&reaction); |
| 135 | let emoji = is_emoji_glyph(&glyph); |
| 136 | div() |
| 137 | .absolute() |
| 138 | .right(px(12.)) |
| 139 | .bottom(px(32.)) |
| 140 | .h(px(36.)) |
| 141 | .min_w(px(36.)) |
| 142 | .when(!emoji, |chip| chip.px(px(12.))) |
| 143 | .flex() |
| 144 | .items_center() |
| 145 | .justify_center() |
| 146 | .rounded_full() |
| 147 | .bg(theme::popup()) |
| 148 | .text_size(px(if emoji { 20. } else { 13. })) |
| 149 | .child(glyph) |
| 150 | .with_animation( |
| 151 | ("call-reaction", serial as usize), |
| 152 | Animation::new(REACTION_SHOWN), |
| 153 | |chip, delta| { |
| 154 | let fade = ((delta - REACTION_FADE_FROM) / (1. - REACTION_FADE_FROM)).clamp(0., 1.); |
| 155 | chip.bottom(px(32. + REACTION_RISE * delta)) |
| 156 | .opacity(1. - fade) |
| 157 | }, |
| 158 | ) |
| 159 | .into_any_element() |
| 160 | } |
| 161 | |
| 162 | fn tile_overlays(extras: &TileExtras) -> Vec<AnyElement> { |
| 163 | let badges = (extras.hand.is_some() || extras.spotlight || extras.pinned).then(|| { |
| 164 | h_flex() |
| 165 | .absolute() |
| 166 | .top(px(8.)) |
| 167 | .left(px(8.)) |
| 168 | .gap(px(6.)) |
| 169 | .children(extras.hand.map(|position| hand_badge(position, extras.own))) |
| 170 | .when(extras.spotlight, |row| row.child(spotlight_chip())) |
| 171 | .when(extras.pinned, |row| row.child(pin_chip())) |
| 172 | .into_any_element() |
| 173 | }); |
| 174 | let reaction = extras |
| 175 | .reaction |
| 176 | .clone() |
| 177 | .map(|(reaction, serial)| reaction_chip(reaction, serial)); |
| 178 | badges.into_iter().chain(reaction).collect() |
| 179 | } |
| 180 | |
| 181 | pub fn status_line(model: &CallModel, now: Instant) -> (String, Hsla) { |
| 182 | if model.lobby { |
| 183 | (LOBBY_TEXT.to_owned(), theme::amber()) |
| 184 | } else if model.is_connecting() { |
| 185 | (model.connecting_text().to_owned(), theme::text_muted()) |
| 186 | } else if model.is_reconnecting() { |
| 187 | ("Reconnecting...".to_owned(), theme::amber()) |
| 188 | } else if model.view.hide_timer { |
| 189 | (String::new(), theme::text_muted()) |
| 190 | } else { |
| 191 | (model.timer_text(now), theme::text_muted()) |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | pub fn pulsing(element: impl IntoElement + 'static, id: &'static str) -> AnyElement { |
| 196 | div() |
| 197 | .child(element) |
| 198 | .with_animation( |
| 199 | id, |
| 200 | Animation::new(PULSE_PERIOD).repeat(), |
| 201 | |element, delta| { |
| 202 | let wave = 1. - (delta * 2. - 1.).abs(); |
| 203 | element.opacity(0.45 + 0.55 * wave) |
| 204 | }, |
| 205 | ) |
| 206 | .into_any_element() |
| 207 | } |
| 208 | |
| 209 | fn blinking(element: impl IntoElement + 'static) -> AnyElement { |
| 210 | let dimmed = SystemTime::now() |
| 211 | .duration_since(UNIX_EPOCH) |
| 212 | .is_ok_and(|elapsed| (elapsed.as_millis() / BLINK_HALF_PERIOD.as_millis()) % 2 == 1); |
| 213 | div() |
| 214 | .child(element) |
| 215 | .opacity(if dimmed { BLINK_DIMMED_OPACITY } else { 1. }) |
| 216 | .into_any_element() |
| 217 | } |
| 218 | |
| 219 | fn speaking_ring(avatar: AnyElement, speaking: bool) -> Div { |
| 220 | div() |
| 221 | .p(px(RING_GAP)) |
| 222 | .rounded_full() |
| 223 | .border(px(RING_WIDTH)) |
| 224 | .border_color(if speaking { |
| 225 | theme::green() |
| 226 | } else { |
| 227 | transparent_black() |
| 228 | }) |
| 229 | .child(avatar) |
| 230 | } |
| 231 | |
| 232 | fn mute_badge() -> Div { |
| 233 | div() |
| 234 | .absolute() |
| 235 | .top(px(8.)) |
| 236 | .right(px(8.)) |
| 237 | .size(px(24.)) |
| 238 | .flex() |
| 239 | .items_center() |
| 240 | .justify_center() |
| 241 | .rounded_full() |
| 242 | .bg(theme::red()) |
| 243 | .child(icon(IconName::MicOff, 13., theme::white())) |
| 244 | } |
| 245 | |
| 246 | struct NamePlate { |
| 247 | inset: f32, |
| 248 | padding_x: f32, |
| 249 | padding_y: f32, |
| 250 | radius: f32, |
| 251 | text_size: f32, |
| 252 | max_width_share: f32, |
| 253 | } |
| 254 | |
| 255 | fn name_plate_metrics(size: TileSize) -> NamePlate { |
| 256 | if size.height < COMPACT_PLATE_BELOW { |
| 257 | NamePlate { |
| 258 | inset: 4., |
| 259 | padding_x: 6., |
| 260 | padding_y: 2., |
| 261 | radius: 4., |
| 262 | text_size: 11., |
| 263 | max_width_share: 0.6, |
| 264 | } |
| 265 | } else { |
| 266 | NamePlate { |
| 267 | inset: 8., |
| 268 | padding_x: 8., |
| 269 | padding_y: 4., |
| 270 | radius: 6., |
| 271 | text_size: 12., |
| 272 | max_width_share: 1., |
| 273 | } |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | fn name_plate(size: TileSize, name: &str) -> Div { |
| 278 | let plate = name_plate_metrics(size); |
| 279 | div() |
| 280 | .absolute() |
| 281 | .left(px(plate.inset)) |
| 282 | .bottom(px(plate.inset)) |
| 283 | .max_w(px(((size.width - 3. * plate.inset) |
| 284 | * plate.max_width_share) |
| 285 | .max(0.))) |
| 286 | .truncate() |
| 287 | .px(px(plate.padding_x)) |
| 288 | .py(px(plate.padding_y)) |
| 289 | .rounded(px(plate.radius)) |
| 290 | .bg(hsla(0., 0., 0., NAME_PLATE_BACKGROUND)) |
| 291 | .text_size(px(plate.text_size)) |
| 292 | .font_weight(FontWeight::SEMIBOLD) |
| 293 | .text_color(theme::white()) |
| 294 | .child(name.to_owned()) |
| 295 | } |
| 296 | |
| 297 | fn video_tile( |
| 298 | size: TileSize, |
| 299 | image: Arc<RenderImage>, |
| 300 | name: &str, |
| 301 | speaking: bool, |
| 302 | muted: bool, |
| 303 | extras: &TileExtras, |
| 304 | ) -> Div { |
| 305 | div() |
| 306 | .relative() |
| 307 | .w(px(size.width)) |
| 308 | .h(px(size.height)) |
| 309 | .flex_none() |
| 310 | .overflow_hidden() |
| 311 | .rounded(px(TILE_RADIUS)) |
| 312 | .bg(theme::row_hover()) |
| 313 | .border_2() |
| 314 | .border_color(if speaking { |
| 315 | theme::green() |
| 316 | } else { |
| 317 | transparent_black() |
| 318 | }) |
| 319 | .child( |
| 320 | img(ImageSource::Render(image)) |
| 321 | .size_full() |
| 322 | .object_fit(if extras.fitted { |
| 323 | ObjectFit::Contain |
| 324 | } else { |
| 325 | ObjectFit::Cover |
| 326 | }) |
| 327 | .rounded(px(TILE_RADIUS)), |
| 328 | ) |
| 329 | .child(name_plate(size, name)) |
| 330 | .when(muted, |tile| tile.child(mute_badge())) |
| 331 | .children(tile_overlays(extras)) |
| 332 | } |
| 333 | |
| 334 | fn tile( |
| 335 | size: TileSize, |
| 336 | avatar: AnyElement, |
| 337 | name: &str, |
| 338 | speaking: bool, |
| 339 | muted: bool, |
| 340 | caption: Option<AnyElement>, |
| 341 | extras: &TileExtras, |
| 342 | ) -> Div { |
| 343 | let badge = mute_badge(); |
| 344 | v_flex() |
| 345 | .relative() |
| 346 | .w(px(size.width)) |
| 347 | .h(px(size.height)) |
| 348 | .items_center() |
| 349 | .justify_center() |
| 350 | .gap(px(12.)) |
| 351 | .rounded(px(12.)) |
| 352 | .bg(theme::row_hover()) |
| 353 | .child(speaking_ring(avatar, speaking)) |
| 354 | .child( |
| 355 | v_flex() |
| 356 | .items_center() |
| 357 | .gap(px(2.)) |
| 358 | .max_w(px(size.width - 16.)) |
| 359 | .child( |
| 360 | div() |
| 361 | .max_w_full() |
| 362 | .truncate() |
| 363 | .text_size(px(14.)) |
| 364 | .font_weight(FontWeight::SEMIBOLD) |
| 365 | .child(name.to_owned()), |
| 366 | ) |
| 367 | .children(caption), |
| 368 | ) |
| 369 | .when(muted, |tile| tile.child(badge)) |
| 370 | .children(tile_overlays(extras)) |
| 371 | } |
| 372 | |
| 373 | fn control_shell(id: &'static str, background: Hsla) -> Stateful<Div> { |
| 374 | div() |
| 375 | .id(id) |
| 376 | .size(px(CONTROL_SIZE)) |
| 377 | .flex() |
| 378 | .flex_none() |
| 379 | .items_center() |
| 380 | .justify_center() |
| 381 | .rounded_full() |
| 382 | .bg(background) |
| 383 | .cursor_pointer() |
| 384 | .hover(|button| button.opacity(0.85)) |
| 385 | } |
| 386 | |
| 387 | pub(super) fn round_control( |
| 388 | id: &'static str, |
| 389 | glyph: IconName, |
| 390 | background: Hsla, |
| 391 | foreground: Hsla, |
| 392 | ) -> Stateful<Div> { |
| 393 | control_shell(id, background).child(icon(glyph, CONTROL_ICON, foreground)) |
| 394 | } |
| 395 | |
| 396 | pub fn mute_button( |
| 397 | app: &Entity<AppState>, |
| 398 | model: &CallModel, |
| 399 | id: &'static str, |
| 400 | size: f32, |
| 401 | ) -> Stateful<Div> { |
| 402 | let (glyph, background, foreground) = if model.muted { |
| 403 | (IconName::MicOff, theme::red(), theme::white()) |
| 404 | } else { |
| 405 | (IconName::Mic, theme::surface_raised(), theme::text()) |
| 406 | }; |
| 407 | mic_action( |
| 408 | round_control(id, glyph, background, foreground).size(px(size)), |
| 409 | app, |
| 410 | model, |
| 411 | ) |
| 412 | } |
| 413 | |
| 414 | fn toolbar_mic(app: &Entity<AppState>, model: &CallModel) -> Stateful<Div> { |
| 415 | let glyph = if model.muted { |
| 416 | IconName::MicOff |
| 417 | } else { |
| 418 | IconName::Mic |
| 419 | }; |
| 420 | mic_action(tool_face("call-mute", glyph, "Mic", false), app, model) |
| 421 | } |
| 422 | |
| 423 | fn mic_action(button: Stateful<Div>, app: &Entity<AppState>, model: &CallModel) -> Stateful<Div> { |
| 424 | if !model.can_unmute() { |
| 425 | let hint = if model.audio_off { |
| 426 | AUDIO_OFF_HINT |
| 427 | } else { |
| 428 | NO_MICROPHONE_HINT |
| 429 | }; |
| 430 | return button |
| 431 | .opacity(DISABLED_OPACITY) |
| 432 | .cursor_default() |
| 433 | .tooltip(move |window, cx| Tooltip::new(hint).build(window, cx)); |
| 434 | } |
| 435 | let app = app.clone(); |
| 436 | button.on_click(move |_, _, cx| { |
| 437 | cx.stop_propagation(); |
| 438 | app.update(cx, |state, cx| state.toggle_call_mute(cx)); |
| 439 | }) |
| 440 | } |
| 441 | |
| 442 | pub fn leave_button( |
| 443 | app: &Entity<AppState>, |
| 444 | model: &CallModel, |
| 445 | id: &'static str, |
| 446 | compact: bool, |
| 447 | ) -> Stateful<Div> { |
| 448 | let label = if model.is_connecting() { |
| 449 | "Cancel" |
| 450 | } else { |
| 451 | "Leave" |
| 452 | }; |
| 453 | let app = app.clone(); |
| 454 | h_flex() |
| 455 | .id(id) |
| 456 | .h(px(if compact { 28. } else { LEAVE_HEIGHT })) |
| 457 | .px(px(if compact { 10. } else { 14. })) |
| 458 | .gap(px(8.)) |
| 459 | .flex_none() |
| 460 | .items_center() |
| 461 | .justify_center() |
| 462 | .rounded_full() |
| 463 | .bg(theme::red()) |
| 464 | .text_color(theme::white()) |
| 465 | .text_size(px(if compact { 12. } else { 13. })) |
| 466 | .font_weight(FontWeight::SEMIBOLD) |
| 467 | .cursor_pointer() |
| 468 | .hover(|button| button.opacity(0.85)) |
| 469 | .child(icon( |
| 470 | IconName::PhoneOff, |
| 471 | if compact { 14. } else { 16. }, |
| 472 | theme::white(), |
| 473 | )) |
| 474 | .child(label) |
| 475 | .on_click(move |_, _, cx| { |
| 476 | cx.stop_propagation(); |
| 477 | app.update(cx, |state, cx| state.leave_call(cx)); |
| 478 | }) |
| 479 | } |
| 480 | |
| 481 | fn share_stage_element( |
| 482 | app: &Entity<AppState>, |
| 483 | state: &AppState, |
| 484 | call: &ActiveCall, |
| 485 | ) -> Option<AnyElement> { |
| 486 | if call.share_stage.popped && call.model.screen_sharer.is_some() { |
| 487 | return Some(popped_placeholder(app)); |
| 488 | } |
| 489 | render_stage(app, state, StageMode::Docked).or_else(|| whiteboard_stage(app, &call.model)) |
| 490 | } |
| 491 | |
| 492 | pub(super) fn camera_button(app: &Entity<AppState>, model: &CallModel) -> Stateful<Div> { |
| 493 | let (glyph, background, foreground) = if model.camera_on { |
| 494 | (IconName::Video, theme::accent(), theme::on_accent()) |
| 495 | } else { |
| 496 | (IconName::VideoOff, theme::surface_raised(), theme::text()) |
| 497 | }; |
| 498 | camera_action( |
| 499 | round_control("call-camera", glyph, background, foreground), |
| 500 | app, |
| 501 | model, |
| 502 | ) |
| 503 | } |
| 504 | |
| 505 | fn toolbar_camera(app: &Entity<AppState>, model: &CallModel) -> Stateful<Div> { |
| 506 | let glyph = if model.camera_on { |
| 507 | IconName::Video |
| 508 | } else { |
| 509 | IconName::VideoOff |
| 510 | }; |
| 511 | camera_action(tool_face("call-camera", glyph, "Camera", false), app, model) |
| 512 | } |
| 513 | |
| 514 | fn camera_action( |
| 515 | button: Stateful<Div>, |
| 516 | app: &Entity<AppState>, |
| 517 | model: &CallModel, |
| 518 | ) -> Stateful<Div> { |
| 519 | if !model.can_use_camera() { |
| 520 | return button |
| 521 | .opacity(DISABLED_OPACITY) |
| 522 | .cursor_default() |
| 523 | .tooltip(|window, cx| Tooltip::new(NO_CAMERA_HINT).build(window, cx)); |
| 524 | } |
| 525 | let app = app.clone(); |
| 526 | button.on_click(move |_, _, cx| { |
| 527 | cx.stop_propagation(); |
| 528 | app.update(cx, |state, cx| state.toggle_call_camera(cx)); |
| 529 | }) |
| 530 | } |
| 531 | |
| 532 | fn sound_switch_item(app: &Entity<AppState>, sound: bool) -> PopupMenuItem { |
| 533 | let app = app.clone(); |
| 534 | PopupMenuItem::element(move |_, _| { |
| 535 | h_flex() |
| 536 | .id("call-share-sound-row") |
| 537 | .w_full() |
| 538 | .gap(px(16.)) |
| 539 | .items_center() |
| 540 | .justify_between() |
| 541 | .child(SHARE_SOUND_LABEL) |
| 542 | .child(Switch::new("call-share-sound").checked(sound)) |
| 543 | }) |
| 544 | .on_click(move |_, _, cx| app.update(cx, |state, cx| state.set_call_share_sound(!sound, cx))) |
| 545 | } |
| 546 | |
| 547 | fn motion_switch_item(app: &Entity<AppState>, motion: bool) -> PopupMenuItem { |
| 548 | let app = app.clone(); |
| 549 | PopupMenuItem::element(move |_, _| { |
| 550 | h_flex() |
| 551 | .id("call-share-motion-row") |
| 552 | .w_full() |
| 553 | .gap(px(16.)) |
| 554 | .items_center() |
| 555 | .justify_between() |
| 556 | .child(SHARE_MOTION_LABEL) |
| 557 | .child(Switch::new("call-share-motion").checked(motion)) |
| 558 | }) |
| 559 | .on_click(move |_, _, cx| app.update(cx, |state, cx| state.set_call_share_motion(!motion, cx))) |
| 560 | } |
| 561 | |
| 562 | fn standout_switch_item(app: &Entity<AppState>, standout: bool, camera_on: bool) -> PopupMenuItem { |
| 563 | let app = app.clone(); |
| 564 | PopupMenuItem::element(move |_, _| { |
| 565 | v_flex() |
| 566 | .id("call-share-standout-row") |
| 567 | .w_full() |
| 568 | .when(!camera_on, |row| row.opacity(DISABLED_OPACITY)) |
| 569 | .child( |
| 570 | h_flex() |
| 571 | .w_full() |
| 572 | .gap(px(16.)) |
| 573 | .items_center() |
| 574 | .justify_between() |
| 575 | .child(SHARE_STANDOUT_LABEL) |
| 576 | .child(Switch::new("call-share-standout").checked(standout && camera_on)), |
| 577 | ) |
| 578 | .when(!camera_on, |row| { |
| 579 | row.child( |
| 580 | div() |
| 581 | .text_size(px(11.)) |
| 582 | .text_color(theme::text_muted()) |
| 583 | .child(SHARE_STANDOUT_NEEDS_CAMERA), |
| 584 | ) |
| 585 | }) |
| 586 | }) |
| 587 | .disabled(!camera_on) |
| 588 | .on_click(move |_, _, cx| { |
| 589 | app.update(cx, |state, cx| state.set_call_share_standout(!standout, cx)) |
| 590 | }) |
| 591 | } |
| 592 | |
| 593 | fn music_mode_item(app: &Entity<AppState>, mic: MicSettings) -> PopupMenuItem { |
| 594 | let app = app.clone(); |
| 595 | PopupMenuItem::element(move |_, _| { |
| 596 | h_flex() |
| 597 | .id("call-music-mode-row") |
| 598 | .w_full() |
| 599 | .gap(px(16.)) |
| 600 | .items_center() |
| 601 | .justify_between() |
| 602 | .child(MUSIC_MODE_LABEL) |
| 603 | .child(Switch::new("call-music-mode").checked(mic.music_mode)) |
| 604 | }) |
| 605 | .on_click(move |_, _, cx| { |
| 606 | app.update(cx, |state, cx| { |
| 607 | let settings = MicSettings { |
| 608 | music_mode: !mic.music_mode, |
| 609 | ..state.call_mic |
| 610 | }; |
| 611 | state.set_call_mic(settings, cx) |
| 612 | }) |
| 613 | }) |
| 614 | } |
| 615 | |
| 616 | fn push_to_talk_chip(call: &ActiveCall) -> Option<AnyElement> { |
| 617 | call.push_to_talk.is_held().then(|| { |
| 618 | div() |
| 619 | .id("call-push-to-talk") |
| 620 | .absolute() |
| 621 | .top(px(HEADER_HEIGHT + PUSH_TO_TALK_TOP)) |
| 622 | .left_0() |
| 623 | .right_0() |
| 624 | .flex() |
| 625 | .justify_center() |
| 626 | .child( |
| 627 | div() |
| 628 | .debug_selector(|| "call/push-to-talk".into()) |
| 629 | .px(px(12.)) |
| 630 | .py(px(6.)) |
| 631 | .rounded_full() |
| 632 | .bg(hsla(0., 0., 0., NAME_PLATE_BACKGROUND)) |
| 633 | .text_color(theme::white()) |
| 634 | .text_size(px(13.)) |
| 635 | .child(PUSH_TO_TALK_HINT), |
| 636 | ) |
| 637 | .into_any_element() |
| 638 | }) |
| 639 | } |
| 640 | |
| 641 | #[derive(Debug, Clone, Copy)] |
| 642 | pub(super) struct ShareOptions { |
| 643 | pub sound: bool, |
| 644 | pub motion: bool, |
| 645 | pub standout: bool, |
| 646 | } |
| 647 | |
| 648 | impl ShareOptions { |
| 649 | pub(super) fn of(state: &AppState) -> Self { |
| 650 | ShareOptions { |
| 651 | sound: state.call_share_sound, |
| 652 | motion: state.call_share_motion, |
| 653 | standout: state.call_share_standout, |
| 654 | } |
| 655 | } |
| 656 | } |
| 657 | |
| 658 | fn share_items( |
| 659 | popup: PopupMenu, |
| 660 | app: &Entity<AppState>, |
| 661 | model: &CallModel, |
| 662 | options: ShareOptions, |
| 663 | ) -> PopupMenu { |
| 664 | let mut popup = popup |
| 665 | .min_w(px(SHARE_MENU_WIDTH)) |
| 666 | .item(sound_switch_item(app, options.sound)) |
| 667 | .item(motion_switch_item(app, options.motion)) |
| 668 | .item(standout_switch_item(app, options.standout, model.camera_on)) |
| 669 | .separator(); |
| 670 | if model.uses_portal_picker() { |
| 671 | let screen_app = app.clone(); |
| 672 | let window_app = app.clone(); |
| 673 | return popup |
| 674 | .item( |
| 675 | PopupMenuItem::new("Share entire screen").on_click(move |_, _, cx| { |
| 676 | screen_app.update(cx, |state, cx| { |
| 677 | state.start_portal_share(ShareKind::Screen, cx) |
| 678 | }) |
| 679 | }), |
| 680 | ) |
| 681 | .item( |
| 682 | PopupMenuItem::new("Share a window").on_click(move |_, _, cx| { |
| 683 | window_app.update(cx, |state, cx| { |
| 684 | state.start_portal_share(ShareKind::Window, cx) |
| 685 | }) |
| 686 | }), |
| 687 | ); |
| 688 | } |
| 689 | let screens = model.screens(); |
| 690 | let single_screen = screens.len() == 1; |
| 691 | for (index, source) in screens.into_iter().enumerate() { |
| 692 | let label = if single_screen { |
| 693 | "Share entire screen".to_owned() |
| 694 | } else { |
| 695 | format!("Share screen {}", index + 1) |
| 696 | }; |
| 697 | let thumbnail = model.share_thumbnail(source); |
| 698 | let source = source.clone(); |
| 699 | let app = app.clone(); |
| 700 | popup = popup.item( |
| 701 | share_source_item(label, thumbnail, IconName::Monitor, SCREEN_THUMBNAIL).on_click( |
| 702 | move |_, _, cx| { |
| 703 | app.update(cx, |state, cx| state.start_call_share(source.clone(), cx)) |
| 704 | }, |
| 705 | ), |
| 706 | ); |
| 707 | } |
| 708 | popup = popup |
| 709 | .separator() |
| 710 | .item(PopupMenuItem::label("Share a window...")); |
| 711 | let windows = model.windows(); |
| 712 | if windows.is_empty() { |
| 713 | return popup.item(PopupMenuItem::new(NO_WINDOWS_HINT).disabled(true)); |
| 714 | } |
| 715 | for source in windows.into_iter().take(MAX_WINDOW_ITEMS) { |
| 716 | let label = source.label(); |
| 717 | let thumbnail = model.share_thumbnail(source); |
| 718 | let source = source.clone(); |
| 719 | let app = app.clone(); |
| 720 | popup = popup.item( |
| 721 | share_source_item(label, thumbnail, IconName::AppWindow, WINDOW_THUMBNAIL).on_click( |
| 722 | move |_, _, cx| { |
| 723 | app.update(cx, |state, cx| state.start_call_share(source.clone(), cx)) |
| 724 | }, |
| 725 | ), |
| 726 | ); |
| 727 | } |
| 728 | popup |
| 729 | } |
| 730 | |
| 731 | fn share_source_item( |
| 732 | label: String, |
| 733 | thumbnail: Option<Arc<RenderImage>>, |
| 734 | fallback: IconName, |
| 735 | (width, height): (f32, f32), |
| 736 | ) -> PopupMenuItem { |
| 737 | PopupMenuItem::element(move |_, _| { |
| 738 | let preview = div() |
| 739 | .debug_selector(|| SHARE_THUMBNAIL_TAG.into()) |
| 740 | .flex_none() |
| 741 | .w(px(width)) |
| 742 | .h(px(height)) |
| 743 | .rounded(px(THUMBNAIL_RADIUS)) |
| 744 | .bg(theme::popup_hover()) |
| 745 | .flex() |
| 746 | .items_center() |
| 747 | .justify_center(); |
| 748 | let preview = match &thumbnail { |
| 749 | Some(image) => preview.child( |
| 750 | img(ImageSource::Render(image.clone())) |
| 751 | .size_full() |
| 752 | .object_fit(ObjectFit::Contain) |
| 753 | .rounded(px(THUMBNAIL_RADIUS)), |
| 754 | ), |
| 755 | None => preview.child( |
| 756 | gpui_kit::component::Icon::new(fallback.clone()) |
| 757 | .size(px(THUMBNAIL_ICON)) |
| 758 | .text_color(theme::text_muted()), |
| 759 | ), |
| 760 | }; |
| 761 | h_flex() |
| 762 | .w_full() |
| 763 | .py(px(4.)) |
| 764 | .gap(px(12.)) |
| 765 | .items_center() |
| 766 | .child(preview) |
| 767 | .child(div().flex_1().min_w_0().truncate().child(label.clone())) |
| 768 | }) |
| 769 | } |
| 770 | |
| 771 | fn share_button( |
| 772 | app: &Entity<AppState>, |
| 773 | model: &CallModel, |
| 774 | options: ShareOptions, |
| 775 | menu_open: bool, |
| 776 | ) -> AnyElement { |
| 777 | if model.local_share.is_some() { |
| 778 | let app = app.clone(); |
| 779 | return tool_face("call-share-stop", IconName::ScreenShareOff, "Stop", true) |
| 780 | .tooltip(|window, cx| Tooltip::new("Stop sharing").build(window, cx)) |
| 781 | .on_click(move |_, _, cx| { |
| 782 | cx.stop_propagation(); |
| 783 | app.update(cx, |state, cx| state.stop_call_share(cx)); |
| 784 | }) |
| 785 | .into_any_element(); |
| 786 | } |
| 787 | let face = tool_face("call-share-face", IconName::ScreenShare, "Share", false); |
| 788 | if !model.can_share() { |
| 789 | return face |
| 790 | .opacity(DISABLED_OPACITY) |
| 791 | .cursor_default() |
| 792 | .tooltip(|window, cx| Tooltip::new(NO_SHARE_HINT).build(window, cx)) |
| 793 | .into_any_element(); |
| 794 | } |
| 795 | let app = app.clone(); |
| 796 | let open_app = app.clone(); |
| 797 | let model = model.clone(); |
| 798 | tool_trigger("call-share", face) |
| 799 | .dropdown_menu_with_anchor(Anchor::TopRight, move |popup, _, _| { |
| 800 | share_items(popup, &app, &model, options) |
| 801 | }) |
| 802 | .open(menu_open) |
| 803 | .on_open_change(move |open, _, cx| { |
| 804 | open_app.update(cx, |state, cx| state.set_call_share_menu(*open, cx)) |
| 805 | }) |
| 806 | .into_any_element() |
| 807 | } |
| 808 | |
| 809 | fn sharing_banner(app: &Entity<AppState>, model: &CallModel, sound: bool) -> Option<AnyElement> { |
| 810 | let label = model.local_share.as_ref()?; |
| 811 | let sound_app = app.clone(); |
| 812 | let app = app.clone(); |
| 813 | Some( |
| 814 | h_flex() |
| 815 | .id("call-sharing-banner") |
| 816 | .w_full() |
| 817 | .h(px(BANNER_HEIGHT)) |
| 818 | .flex_none() |
| 819 | .px(px(20.)) |
| 820 | .gap(px(12.)) |
| 821 | .items_center() |
| 822 | .justify_center() |
| 823 | .bg(theme::accent()) |
| 824 | .text_color(theme::on_accent()) |
| 825 | .text_size(px(13.)) |
| 826 | .font_weight(FontWeight::SEMIBOLD) |
| 827 | .child(icon(IconName::ScreenShare, 16., theme::on_accent())) |
| 828 | .child(format!("You are sharing: {label}")) |
| 829 | .child( |
| 830 | div() |
| 831 | .id("call-sharing-sound") |
| 832 | .h(px(26.)) |
| 833 | .px(px(12.)) |
| 834 | .flex() |
| 835 | .items_center() |
| 836 | .rounded_full() |
| 837 | .bg(theme::on_accent().opacity(0.2)) |
| 838 | .cursor_pointer() |
| 839 | .hover(|button| button.opacity(0.9)) |
| 840 | .child(if sound { |
| 841 | "Computer sound on" |
| 842 | } else { |
| 843 | "Computer sound off" |
| 844 | }) |
| 845 | .on_click(move |_, _, cx| { |
| 846 | sound_app.update(cx, |state, cx| state.set_call_share_sound(!sound, cx)) |
| 847 | }), |
| 848 | ) |
| 849 | .child( |
| 850 | div() |
| 851 | .id("call-sharing-stop") |
| 852 | .h(px(26.)) |
| 853 | .px(px(12.)) |
| 854 | .flex() |
| 855 | .items_center() |
| 856 | .rounded_full() |
| 857 | .bg(theme::on_accent()) |
| 858 | .text_color(theme::accent()) |
| 859 | .cursor_pointer() |
| 860 | .hover(|button| button.opacity(0.9)) |
| 861 | .child("Stop sharing") |
| 862 | .on_click(move |_, _, cx| { |
| 863 | app.update(cx, |state, cx| state.stop_call_share(cx)) |
| 864 | }), |
| 865 | ) |
| 866 | .into_any_element(), |
| 867 | ) |
| 868 | } |
| 869 | |
| 870 | fn chat_button(app: &Entity<AppState>, open: bool, unread: u32) -> Stateful<Div> { |
| 871 | let app = app.clone(); |
| 872 | tool_face("call-chat", IconName::MessageCircle, "Chat", open) |
| 873 | .relative() |
| 874 | .tooltip(move |window, cx| { |
| 875 | Tooltip::new(if open { |
| 876 | "Close the chat" |
| 877 | } else { |
| 878 | "Open the chat" |
| 879 | }) |
| 880 | .build(window, cx) |
| 881 | }) |
| 882 | .when(unread > 0, |button| { |
| 883 | button.child(corner_badge(Corner::TopRight, 4.).child(count_badge(unread, false))) |
| 884 | }) |
| 885 | .on_click(move |_, _, cx| app.update(cx, |state, cx| state.toggle_call_chat(cx))) |
| 886 | } |
| 887 | |
| 888 | fn reactions_button(app: &Entity<AppState>, model: &CallModel) -> AnyElement { |
| 889 | let raised = model.own_hand.is_some(); |
| 890 | let face = tool_face( |
| 891 | "call-reactions-face", |
| 892 | IconName::FaceSlightlySmiling, |
| 893 | "React", |
| 894 | raised, |
| 895 | ); |
| 896 | if !model.can_react() { |
| 897 | return face |
| 898 | .opacity(DISABLED_OPACITY) |
| 899 | .cursor_default() |
| 900 | .into_any_element(); |
| 901 | } |
| 902 | let app = app.clone(); |
| 903 | Popover::new("call-reactions-popover") |
| 904 | .anchor(Anchor::TopRight) |
| 905 | .offset(px(6.)) |
| 906 | .trigger(tool_trigger("call-reactions", face)) |
| 907 | .content(move |_, _, cx| { |
| 908 | let popover = cx.entity().downgrade(); |
| 909 | let hand_app = app.clone(); |
| 910 | let hand_popover = popover.clone(); |
| 911 | let reactions = h_flex().id("call-reactions-row").gap(px(4.)).children( |
| 912 | Reaction::ALL.into_iter().map(|reaction| { |
| 913 | let app = app.clone(); |
| 914 | let popover = popover.clone(); |
| 915 | div() |
| 916 | .id(ElementId::Name(reaction.name().to_owned().into())) |
| 917 | .size(px(REACTION_CELL)) |
| 918 | .flex() |
| 919 | .items_center() |
| 920 | .justify_center() |
| 921 | .rounded(px(8.)) |
| 922 | .text_size(px(24.)) |
| 923 | .cursor_pointer() |
| 924 | .hover(|cell| cell.bg(theme::border_strong())) |
| 925 | .child(reaction_glyph(&reaction)) |
| 926 | .on_click(move |_, window, cx| { |
| 927 | app.update(cx, |state, cx| { |
| 928 | state.send_call_reaction(reaction.clone(), cx) |
| 929 | }); |
| 930 | popover |
| 931 | .update(cx, |state, cx| state.dismiss(window, cx)) |
| 932 | .ok(); |
| 933 | }) |
| 934 | }), |
| 935 | ); |
| 936 | v_flex().gap(px(6.)).child(reactions).child( |
| 937 | h_flex() |
| 938 | .id("call-hand") |
| 939 | .h(px(36.)) |
| 940 | .px(px(10.)) |
| 941 | .gap(px(8.)) |
| 942 | .items_center() |
| 943 | .rounded(px(8.)) |
| 944 | .cursor_pointer() |
| 945 | .when(raised, |row| row.bg(theme::accent_soft())) |
| 946 | .hover(|row| row.bg(theme::border_strong())) |
| 947 | .child(icon( |
| 948 | IconName::Hand, |
| 949 | 18., |
| 950 | if raised { |
| 951 | theme::accent_text() |
| 952 | } else { |
| 953 | theme::text() |
| 954 | }, |
| 955 | )) |
| 956 | .child(div().text_size(px(13.)).child(if raised { |
| 957 | "Lower hand" |
| 958 | } else { |
| 959 | "Raise hand" |
| 960 | })) |
| 961 | .on_click(move |_, window, cx| { |
| 962 | hand_app.update(cx, |state, cx| state.toggle_call_hand(cx)); |
| 963 | hand_popover |
| 964 | .update(cx, |state, cx| state.dismiss(window, cx)) |
| 965 | .ok(); |
| 966 | }), |
| 967 | ) |
| 968 | }) |
| 969 | .into_any_element() |
| 970 | } |
| 971 | |
| 972 | fn pop_out_tool(app: &Entity<AppState>) -> Stateful<Div> { |
| 973 | let app = app.clone(); |
| 974 | tool_face( |
| 975 | "call-pop-out", |
| 976 | IconName::ExternalLink, |
| 977 | POP_OUT_TOOLTIP, |
| 978 | false, |
| 979 | ) |
| 980 | .on_click(move |_, _, cx| app.update(cx, |state, cx| state.pop_out_stage(cx))) |
| 981 | } |
| 982 | |
| 983 | fn shows_pop_out(call: &ActiveCall) -> bool { |
| 984 | call.model.screen_sharer.is_some() && !call.share_stage.popped |
| 985 | } |
| 986 | |
| 987 | fn leave_group(app: &Entity<AppState>, model: &CallModel) -> AnyElement { |
| 988 | let leave = leave_button(app, model, "call-leave", false) |
| 989 | .rounded(px(LEAVE_RADIUS)) |
| 990 | .debug_selector(|| "shell/islands/main/call-header/leave".into()); |
| 991 | if !has_leave_menu(model) { |
| 992 | return leave.into_any_element(); |
| 993 | } |
| 994 | h_flex() |
| 995 | .flex_none() |
| 996 | .gap(px(1.)) |
| 997 | .child(leave.rounded_r(px(0.))) |
| 998 | .child(leave_menu(app, model)) |
| 999 | .into_any_element() |
| 1000 | } |
| 1001 | |
| 1002 | fn has_leave_menu(model: &CallModel) -> bool { |
| 1003 | model.kind == CallKind::Meeting |
| 1004 | && (model.can_end_meeting || (model.can_lower_hands() && model.any_hand_raised())) |
| 1005 | } |
| 1006 | |
| 1007 | fn leave_menu(app: &Entity<AppState>, model: &CallModel) -> impl IntoElement { |
| 1008 | let end_app = app.clone(); |
| 1009 | let can_end = model.can_end_meeting; |
| 1010 | let lower_app = app.clone(); |
| 1011 | let can_lower_all = model.can_lower_hands() && model.any_hand_raised(); |
| 1012 | Button::new("call-leave-menu") |
| 1013 | .ghost() |
| 1014 | .p_0() |
| 1015 | .w(px(SPLIT_CHEVRON_WIDTH + 4.)) |
| 1016 | .h(px(LEAVE_HEIGHT)) |
| 1017 | .rounded_r(px(LEAVE_RADIUS)) |
| 1018 | .child( |
| 1019 | div() |
| 1020 | .id("call-leave-menu-face") |
| 1021 | .size_full() |
| 1022 | .flex() |
| 1023 | .items_center() |
| 1024 | .justify_center() |
| 1025 | .rounded_r(px(LEAVE_RADIUS)) |
| 1026 | .bg(theme::red()) |
| 1027 | .cursor_pointer() |
| 1028 | .hover(|face| face.opacity(0.85)) |
| 1029 | .child(icon(IconName::ChevronDown, 12., theme::white())), |
| 1030 | ) |
| 1031 | .dropdown_menu_with_anchor(Anchor::TopRight, move |popup, _, _| { |
| 1032 | let end_app = end_app.clone(); |
| 1033 | let lower_app = lower_app.clone(); |
| 1034 | let popup = popup.min_w(px(MENU_WIDTH)); |
| 1035 | let popup = if can_lower_all { |
| 1036 | popup.item( |
| 1037 | PopupMenuItem::new("Lower all hands").on_click(move |_, _, cx| { |
| 1038 | lower_app.update(cx, |state, cx| state.lower_all_call_hands(cx)) |
| 1039 | }), |
| 1040 | ) |
| 1041 | } else { |
| 1042 | popup |
| 1043 | }; |
| 1044 | if can_end { |
| 1045 | popup.item( |
| 1046 | PopupMenuItem::new("End meeting for everyone") |
| 1047 | .icon(IconName::PhoneOff) |
| 1048 | .on_click(move |_, _, cx| { |
| 1049 | end_app.update(cx, |state, cx| state.end_meeting_for_all(cx)) |
| 1050 | }), |
| 1051 | ) |
| 1052 | } else { |
| 1053 | popup |
| 1054 | } |
| 1055 | }) |
| 1056 | } |
| 1057 | |
| 1058 | pub(super) fn device_items( |
| 1059 | entries: Vec<DeviceEntry>, |
| 1060 | selected: &calling::DeviceChoice, |
| 1061 | pick: impl Fn(calling::DeviceChoice, &mut App) + Clone + 'static, |
| 1062 | ) -> Vec<PopupMenuItem> { |
| 1063 | entries |
| 1064 | .into_iter() |
| 1065 | .map(|entry| { |
| 1066 | let pick = pick.clone(); |
| 1067 | let choice = entry.choice.clone(); |
| 1068 | PopupMenuItem::new(entry.label) |
| 1069 | .checked(&entry.choice == selected) |
| 1070 | .on_click(move |_, _, cx| pick(choice.clone(), cx)) |
| 1071 | }) |
| 1072 | .collect() |
| 1073 | } |
| 1074 | |
| 1075 | fn devices_menu( |
| 1076 | popup: PopupMenu, |
| 1077 | app: &Entity<AppState>, |
| 1078 | model: &CallModel, |
| 1079 | mic: MicSettings, |
| 1080 | ) -> PopupMenu { |
| 1081 | if model.audio_off { |
| 1082 | return popup.item(PopupMenuItem::new(AUDIO_OFF_HINT).disabled(true)); |
| 1083 | } |
| 1084 | let input_app = app.clone(); |
| 1085 | let output_app = app.clone(); |
| 1086 | let inputs = device_items( |
| 1087 | model.devices.input_entries(), |
| 1088 | &model.input, |
| 1089 | move |choice, cx| { |
| 1090 | input_app.update(cx, |state, cx| state.select_call_input(choice, cx)); |
| 1091 | }, |
| 1092 | ); |
| 1093 | let outputs = device_items( |
| 1094 | model.devices.output_entries(), |
| 1095 | &model.output, |
| 1096 | move |choice, cx| { |
| 1097 | output_app.update(cx, |state, cx| state.select_call_output(choice, cx)); |
| 1098 | }, |
| 1099 | ); |
| 1100 | let mut popup = popup |
| 1101 | .min_w(px(MENU_WIDTH)) |
| 1102 | .item(PopupMenuItem::label("Microphone")); |
| 1103 | if model.listen_only { |
| 1104 | popup = popup.item(PopupMenuItem::new(NO_MICROPHONE_HINT).disabled(true)); |
| 1105 | } else { |
| 1106 | for item in inputs { |
| 1107 | popup = popup.item(item); |
| 1108 | } |
| 1109 | } |
| 1110 | popup = popup |
| 1111 | .separator() |
| 1112 | .item(PopupMenuItem::label(NOISE_SUPPRESSION_LABEL)); |
| 1113 | for level in NoiseSuppression::ALL { |
| 1114 | let level_app = app.clone(); |
| 1115 | popup = popup.item( |
| 1116 | PopupMenuItem::new(level.label()) |
| 1117 | .checked(level == mic.noise_suppression) |
| 1118 | .disabled(mic.music_mode) |
| 1119 | .on_click(move |_, _, cx| { |
| 1120 | level_app.update(cx, |state, cx| { |
| 1121 | let settings = MicSettings { |
| 1122 | noise_suppression: level, |
| 1123 | ..state.call_mic |
| 1124 | }; |
| 1125 | state.set_call_mic(settings, cx) |
| 1126 | }) |
| 1127 | }), |
| 1128 | ); |
| 1129 | } |
| 1130 | popup = popup |
| 1131 | .item(music_mode_item(app, mic)) |
| 1132 | .separator() |
| 1133 | .item(PopupMenuItem::label("Speaker")); |
| 1134 | for item in outputs { |
| 1135 | popup = popup.item(item); |
| 1136 | } |
| 1137 | popup |
| 1138 | } |
| 1139 | |
| 1140 | fn mic_menu_button( |
| 1141 | app: &Entity<AppState>, |
| 1142 | model: &CallModel, |
| 1143 | mic: MicSettings, |
| 1144 | ) -> impl IntoElement { |
| 1145 | let app = app.clone(); |
| 1146 | let model = model.clone(); |
| 1147 | split_chevron("call-mic-menu", "call-mic-menu-face") |
| 1148 | .dropdown_menu_with_anchor(Anchor::TopRight, move |popup, _, _| { |
| 1149 | devices_menu(popup, &app, &model, mic) |
| 1150 | }) |
| 1151 | } |
| 1152 | |
| 1153 | pub(super) fn person_tile( |
| 1154 | app: &Entity<AppState>, |
| 1155 | state: &AppState, |
| 1156 | model: &CallModel, |
| 1157 | remote: &Tile, |
| 1158 | size: TileSize, |
| 1159 | now: Instant, |
| 1160 | ) -> AnyElement { |
| 1161 | let element = plain_person_tile(state, model, remote, size, now); |
| 1162 | with_tile_menu(app, model, &remote.mri, &remote.name, false, element) |
| 1163 | } |
| 1164 | |
| 1165 | pub(super) fn plain_person_tile( |
| 1166 | state: &AppState, |
| 1167 | model: &CallModel, |
| 1168 | remote: &Tile, |
| 1169 | size: TileSize, |
| 1170 | now: Instant, |
| 1171 | ) -> AnyElement { |
| 1172 | let extras = TileExtras { |
| 1173 | hand: remote.hand.map(|rank| model.hand_position(rank)), |
| 1174 | own: false, |
| 1175 | reaction: model |
| 1176 | .chip_of(&remote.mri, now) |
| 1177 | .map(|chip| (chip.reaction.clone(), chip.serial)), |
| 1178 | spotlight: remote.spotlight.is_some(), |
| 1179 | pinned: model.is_pinned(&remote.mri), |
| 1180 | fitted: model.is_fitted(&remote.mri), |
| 1181 | }; |
| 1182 | person_tile_body(state, model, remote, size, now, &extras) |
| 1183 | } |
| 1184 | |
| 1185 | fn person_tile_body( |
| 1186 | state: &AppState, |
| 1187 | model: &CallModel, |
| 1188 | remote: &Tile, |
| 1189 | size: TileSize, |
| 1190 | now: Instant, |
| 1191 | extras: &TileExtras, |
| 1192 | ) -> AnyElement { |
| 1193 | let video = state |
| 1194 | .call |
| 1195 | .as_ref() |
| 1196 | .filter(|_| remote.has_video || model.is_one_to_one()) |
| 1197 | .and_then(|call| { |
| 1198 | call.pictures |
| 1199 | .live(&VideoKey::Person(remote.mri.clone()), now) |
| 1200 | }); |
| 1201 | if let Some(image) = video { |
| 1202 | return video_tile( |
| 1203 | size, |
| 1204 | image, |
| 1205 | &remote.name, |
| 1206 | model.tile_speaking(remote), |
| 1207 | remote.muted, |
| 1208 | extras, |
| 1209 | ) |
| 1210 | .into_any_element(); |
| 1211 | } |
| 1212 | let waiting = remote.state == TileState::Invited; |
| 1213 | let avatar = person_avatar( |
| 1214 | &state.directory, |
| 1215 | remote.user_id.as_deref(), |
| 1216 | &remote.name, |
| 1217 | size.avatar, |
| 1218 | ); |
| 1219 | let caption = model.tile_caption(remote).map(|text| { |
| 1220 | let label = div() |
| 1221 | .text_size(px(12.)) |
| 1222 | .text_color(theme::text_muted()) |
| 1223 | .child(text); |
| 1224 | if waiting { |
| 1225 | blinking(label) |
| 1226 | } else { |
| 1227 | label.into_any_element() |
| 1228 | } |
| 1229 | }); |
| 1230 | tile( |
| 1231 | size, |
| 1232 | avatar, |
| 1233 | &remote.name, |
| 1234 | model.tile_speaking(remote), |
| 1235 | remote.muted, |
| 1236 | caption, |
| 1237 | extras, |
| 1238 | ) |
| 1239 | .into_any_element() |
| 1240 | } |
| 1241 | |
| 1242 | pub(super) fn own_tile( |
| 1243 | app: &Entity<AppState>, |
| 1244 | state: &AppState, |
| 1245 | model: &CallModel, |
| 1246 | size: TileSize, |
| 1247 | now: Instant, |
| 1248 | ) -> AnyElement { |
| 1249 | let own_mri = model.own_mri.clone().unwrap_or_default(); |
| 1250 | let element = plain_own_tile(state, model, size, now); |
| 1251 | if own_mri.is_empty() { |
| 1252 | return element; |
| 1253 | } |
| 1254 | with_tile_menu(app, model, &own_mri, "You", true, element) |
| 1255 | } |
| 1256 | |
| 1257 | pub(super) fn plain_own_tile( |
| 1258 | state: &AppState, |
| 1259 | model: &CallModel, |
| 1260 | size: TileSize, |
| 1261 | now: Instant, |
| 1262 | ) -> AnyElement { |
| 1263 | let own_mri = model.own_mri.as_deref().unwrap_or_default(); |
| 1264 | let extras = TileExtras { |
| 1265 | hand: model.own_hand.map(|rank| model.hand_position(rank)), |
| 1266 | own: true, |
| 1267 | reaction: model |
| 1268 | .own_chip(now) |
| 1269 | .map(|chip| (chip.reaction.clone(), chip.serial)), |
| 1270 | spotlight: model.own_spotlight.is_some(), |
| 1271 | pinned: model.is_pinned(own_mri), |
| 1272 | fitted: false, |
| 1273 | }; |
| 1274 | own_tile_body(state, model, size, now, &extras) |
| 1275 | } |
| 1276 | |
| 1277 | fn own_tile_body( |
| 1278 | state: &AppState, |
| 1279 | model: &CallModel, |
| 1280 | size: TileSize, |
| 1281 | now: Instant, |
| 1282 | extras: &TileExtras, |
| 1283 | ) -> AnyElement { |
| 1284 | let me = state.directory.me.as_ref(); |
| 1285 | let self_view = state |
| 1286 | .call |
| 1287 | .as_ref() |
| 1288 | .and_then(|call| call.pictures.live(&VideoKey::LocalCamera, now)); |
| 1289 | if let Some(image) = self_view { |
| 1290 | return video_tile( |
| 1291 | size, |
| 1292 | image, |
| 1293 | "You", |
| 1294 | model.local_speaking, |
| 1295 | model.muted, |
| 1296 | extras, |
| 1297 | ) |
| 1298 | .into_any_element(); |
| 1299 | } |
| 1300 | let avatar = person_avatar( |
| 1301 | &state.directory, |
| 1302 | me.map(|person| person.user_id.as_str()), |
| 1303 | me.map_or("You", |person| person.display_name.as_str()), |
| 1304 | size.avatar, |
| 1305 | ); |
| 1306 | tile( |
| 1307 | size, |
| 1308 | avatar, |
| 1309 | "You", |
| 1310 | model.local_speaking, |
| 1311 | model.muted, |
| 1312 | None, |
| 1313 | extras, |
| 1314 | ) |
| 1315 | .into_any_element() |
| 1316 | } |
| 1317 | |
| 1318 | fn folded_controls(state: &AppState, call: &ActiveCall, fullscreen: bool) -> FoldedControls { |
| 1319 | let model = &call.model; |
| 1320 | let has_more = model.kind != CallKind::Test; |
| 1321 | if !has_more { |
| 1322 | return FoldedControls::default(); |
| 1323 | } |
| 1324 | let mut present = Vec::new(); |
| 1325 | if model.has_reaction_controls() { |
| 1326 | present.push(Foldable::Reactions); |
| 1327 | } |
| 1328 | if model.kind != CallKind::Test { |
| 1329 | present.push(Foldable::People); |
| 1330 | } |
| 1331 | if call.chat_thread().is_some() { |
| 1332 | present.push(Foldable::Chat); |
| 1333 | } |
| 1334 | let fixed = fixed_controls_width( |
| 1335 | model.can_use_camera(), |
| 1336 | has_more, |
| 1337 | has_leave_menu(model), |
| 1338 | shows_pop_out(call), |
| 1339 | ); |
| 1340 | FoldedControls { |
| 1341 | items: in_more_menu(folded_for_width(measured_stage(call).0, fixed, &present)), |
| 1342 | fullscreen, |
| 1343 | people_open: call.people_open, |
| 1344 | chat_open: call.chat_open, |
| 1345 | chat_unread: state.call_chat_unread(), |
| 1346 | } |
| 1347 | } |
| 1348 | |
| 1349 | pub fn render_call_view( |
| 1350 | app: &Entity<AppState>, |
| 1351 | state: &AppState, |
| 1352 | chat: Option<AnyView>, |
| 1353 | fullscreen: bool, |
| 1354 | island_width: f32, |
| 1355 | ) -> Option<AnyElement> { |
| 1356 | let call = state.call.as_ref()?; |
| 1357 | let model = &call.model; |
| 1358 | let now = Instant::now(); |
| 1359 | let (status, status_color) = status_line(model, now); |
| 1360 | let header = h_flex() |
| 1361 | .w_full() |
| 1362 | .h(px(HEADER_HEIGHT)) |
| 1363 | .flex_none() |
| 1364 | .pl(px(20.)) |
| 1365 | .pr(px(HEADER_END_PADDING)) |
| 1366 | .gap(px(12.)) |
| 1367 | .items_center(); |
| 1368 | let title_group = h_flex() |
| 1369 | .flex_1() |
| 1370 | .flex_basis(px(0.)) |
| 1371 | .min_w_0() |
| 1372 | .gap(px(12.)) |
| 1373 | .items_center() |
| 1374 | .child(icon(IconName::Phone, 18., theme::accent_text())) |
| 1375 | .child( |
| 1376 | div() |
| 1377 | .min_w_0() |
| 1378 | .truncate() |
| 1379 | .text_size(px(16.)) |
| 1380 | .font_weight(FontWeight::SEMIBOLD) |
| 1381 | .child(model.title.clone()), |
| 1382 | ) |
| 1383 | .child( |
| 1384 | div() |
| 1385 | .flex_none() |
| 1386 | .text_size(px(13.)) |
| 1387 | .text_color(status_color) |
| 1388 | .child(status), |
| 1389 | ) |
| 1390 | .children(health_indicator(model)) |
| 1391 | .children(recording_chip(model)) |
| 1392 | .children(lock_chip(model)) |
| 1393 | .children(room_chip(model)); |
| 1394 | let end_group = h_flex() |
| 1395 | .flex_1() |
| 1396 | .flex_basis(px(0.)) |
| 1397 | .min_w_0() |
| 1398 | .justify_end() |
| 1399 | .gap(px(GROUP_GAP)) |
| 1400 | .items_center() |
| 1401 | .children(return_button(app, model)) |
| 1402 | .child(leave_group(app, model)); |
| 1403 | |
| 1404 | let hold = hold_panel(app, model); |
| 1405 | let share_stage = share_stage_element(app, state, call); |
| 1406 | let region = stage_region(app, state, call, now, hold, share_stage); |
| 1407 | |
| 1408 | let folded = folded_controls(state, call, fullscreen); |
| 1409 | let panels_and_reactions = h_flex() |
| 1410 | .gap(px(TOOL_GAP)) |
| 1411 | .items_center() |
| 1412 | .when( |
| 1413 | model.has_reaction_controls() && !folded.folds(Foldable::Reactions), |
| 1414 | |row| row.child(reactions_button(app, model)), |
| 1415 | ) |
| 1416 | .when( |
| 1417 | call.chat_thread().is_some() && !folded.folds(Foldable::Chat), |
| 1418 | |row| row.child(chat_button(app, call.chat_open, state.call_chat_unread())), |
| 1419 | ) |
| 1420 | .when( |
| 1421 | model.kind != CallKind::Test && !folded.folds(Foldable::People), |
| 1422 | |row| row.child(people_button(app, call.people_open, model.raised_hands())), |
| 1423 | ); |
| 1424 | let stage_and_more = h_flex() |
| 1425 | .gap(px(TOOL_GAP)) |
| 1426 | .items_center() |
| 1427 | .when(shows_pop_out(call), |row| row.child(pop_out_tool(app))) |
| 1428 | .when(!folded.folds(Foldable::View), |row| { |
| 1429 | row.child(view_button(app, model, fullscreen)) |
| 1430 | }) |
| 1431 | .children(more_button(app, model, &folded)); |
| 1432 | let devices = h_flex() |
| 1433 | .gap(px(TOOL_GAP)) |
| 1434 | .items_center() |
| 1435 | .child( |
| 1436 | h_flex() |
| 1437 | .debug_selector(|| "shell/islands/main/call-header/controls/mic".into()) |
| 1438 | .items_center() |
| 1439 | .child(toolbar_mic(app, model)) |
| 1440 | .child(mic_menu_button(app, model, state.call_mic)), |
| 1441 | ) |
| 1442 | .child( |
| 1443 | h_flex() |
| 1444 | .items_center() |
| 1445 | .child(toolbar_camera(app, model)) |
| 1446 | .children(camera_menu_button(app, model, CameraMenu::of(state))), |
| 1447 | ) |
| 1448 | .child(share_button( |
| 1449 | app, |
| 1450 | model, |
| 1451 | ShareOptions::of(state), |
| 1452 | call.share_menu_open, |
| 1453 | )); |
| 1454 | let controls = h_flex() |
| 1455 | .debug_selector(|| "shell/islands/main/call-header/controls".into()) |
| 1456 | .flex_none() |
| 1457 | .gap(px(GROUP_GAP)) |
| 1458 | .items_center() |
| 1459 | .child(devices) |
| 1460 | .child(group_divider()) |
| 1461 | .child(panels_and_reactions) |
| 1462 | .child(group_divider()) |
| 1463 | .child(stage_and_more); |
| 1464 | let header = header.child(title_group).child(controls).child(end_group); |
| 1465 | |
| 1466 | let top = v_flex() |
| 1467 | .w_full() |
| 1468 | .flex_none() |
| 1469 | .child(header) |
| 1470 | .children(lobby_banner(app, model, call.lobby_list_open)) |
| 1471 | .children(lock_banner(app, model)) |
| 1472 | .children(health_banner(app, model)) |
| 1473 | .children(sharing_banner(app, model, state.call_share_sound)) |
| 1474 | .children(consult_banner(app, state)); |
| 1475 | |
| 1476 | let chrome_visible = call |
| 1477 | .fullscreen |
| 1478 | .is_none_or(|fullscreen| fullscreen.chrome_visible(now)); |
| 1479 | let move_app = app.clone(); |
| 1480 | let base = v_flex() |
| 1481 | .relative() |
| 1482 | .flex_1() |
| 1483 | .min_w_0() |
| 1484 | .h_full() |
| 1485 | .overflow_hidden() |
| 1486 | .bg(theme::surface()); |
| 1487 | let column = if fullscreen { |
| 1488 | base.on_mouse_move(move |_, _, cx| { |
| 1489 | move_app.update(cx, |state, cx| state.touch_call_chrome(cx)) |
| 1490 | }) |
| 1491 | .when(chrome_visible, |column| { |
| 1492 | column.child(fullscreen_chrome("call-chrome-top", app, top)) |
| 1493 | }) |
| 1494 | .child(region) |
| 1495 | } else { |
| 1496 | base.rounded(px(10.)) |
| 1497 | .child(top.debug_selector(|| "shell/islands/main/call-header".into())) |
| 1498 | .child(region) |
| 1499 | } |
| 1500 | .children(captions_overlay(model, now)) |
| 1501 | .children(captions_hint_chip(model)) |
| 1502 | .children(push_to_talk_chip(call)) |
| 1503 | .children(state.transfer_picker.clone()) |
| 1504 | .children(options_dialog(app, call)) |
| 1505 | .children(consent_overlay(app, model)); |
| 1506 | let panels: Vec<AnyElement> = chat |
| 1507 | .map(|chat| chat_panel(app, chat)) |
| 1508 | .into_iter() |
| 1509 | .chain( |
| 1510 | call.transcript_open |
| 1511 | .then(|| state.transcript_panel.clone()) |
| 1512 | .flatten() |
| 1513 | .map(IntoElement::into_any_element), |
| 1514 | ) |
| 1515 | .chain(people_panel(app, state, call)) |
| 1516 | .collect(); |
| 1517 | Some( |
| 1518 | h_flex() |
| 1519 | .relative() |
| 1520 | .when(!fullscreen, |row| { |
| 1521 | row.debug_selector(|| "shell/islands/main".into()) |
| 1522 | }) |
| 1523 | .flex_1() |
| 1524 | .min_w_0() |
| 1525 | .h_full() |
| 1526 | .gap(px(ISLAND_GAP)) |
| 1527 | .child(column) |
| 1528 | .children(side_panels(panels, island_width)) |
| 1529 | .into_any_element(), |
| 1530 | ) |
| 1531 | } |
| 1532 | |
| 1533 | fn side_panels(panels: Vec<AnyElement>, island_width: f32) -> Vec<AnyElement> { |
| 1534 | if panels.is_empty() { |
| 1535 | return panels; |
| 1536 | } |
| 1537 | let panels_width = (CHAT_PANEL_WIDTH + ISLAND_GAP) * panels.len() as f32; |
| 1538 | if island_width - panels_width >= OVERLAY_BELOW { |
| 1539 | return panels; |
| 1540 | } |
| 1541 | vec![ |
| 1542 | h_flex() |
| 1543 | .absolute() |
| 1544 | .top(px(HEADER_HEIGHT)) |
| 1545 | .right_0() |
| 1546 | .bottom_0() |
| 1547 | .gap(px(ISLAND_GAP)) |
| 1548 | .w(px(panels_width.min(island_width))) |
| 1549 | .children(panels) |
| 1550 | .into_any_element(), |
| 1551 | ] |
| 1552 | } |
| 1553 | |
| 1554 | fn fullscreen_chrome(id: &'static str, app: &Entity<AppState>, content: Div) -> Stateful<Div> { |
| 1555 | let hover_app = app.clone(); |
| 1556 | div() |
| 1557 | .id(id) |
| 1558 | .w_full() |
| 1559 | .flex_none() |
| 1560 | .on_hover(move |hovered, _, cx| { |
| 1561 | hover_app.update(cx, |state, cx| state.set_call_chrome_hovered(*hovered, cx)) |
| 1562 | }) |
| 1563 | .child(content) |
| 1564 | } |
| 1565 | |
| 1566 | fn chat_panel(app: &Entity<AppState>, chat: AnyView) -> AnyElement { |
| 1567 | let app = app.clone(); |
| 1568 | side_panel( |
| 1569 | "call-chat-panel", |
| 1570 | "Chat", |
| 1571 | "Close the chat", |
| 1572 | move |cx| app.update(cx, |state, cx| state.toggle_call_chat(cx)), |
| 1573 | chat, |
| 1574 | ) |
| 1575 | .debug_selector(|| CHAT_PANEL_TAG.into()) |
| 1576 | .into_any_element() |
| 1577 | } |
| 1578 | |
| 1579 | pub fn side_panel( |
| 1580 | panel_id: &'static str, |
| 1581 | title: &'static str, |
| 1582 | close_tooltip: &'static str, |
| 1583 | on_close: impl Fn(&mut App) + 'static, |
| 1584 | body: impl IntoElement, |
| 1585 | ) -> Stateful<Div> { |
| 1586 | v_flex() |
| 1587 | .id(panel_id) |
| 1588 | .w(px(CHAT_PANEL_WIDTH)) |
| 1589 | .h_full() |
| 1590 | .flex_shrink(1.) |
| 1591 | .min_w_0() |
| 1592 | .rounded(px(10.)) |
| 1593 | .overflow_hidden() |
| 1594 | .bg(theme::surface()) |
| 1595 | .child( |
| 1596 | h_flex() |
| 1597 | .w_full() |
| 1598 | .h(px(CHAT_HEADER_HEIGHT)) |
| 1599 | .flex_none() |
| 1600 | .pl(px(20.)) |
| 1601 | .pr(px(12.)) |
| 1602 | .items_center() |
| 1603 | .justify_between() |
| 1604 | .child( |
| 1605 | div() |
| 1606 | .text_size(px(15.)) |
| 1607 | .font_weight(FontWeight::SEMIBOLD) |
| 1608 | .child(title), |
| 1609 | ) |
| 1610 | .child( |
| 1611 | div() |
| 1612 | .id(ElementId::Name(format!("{panel_id}-close").into())) |
| 1613 | .size(px(28.)) |
| 1614 | .flex() |
| 1615 | .items_center() |
| 1616 | .justify_center() |
| 1617 | .rounded(px(7.)) |
| 1618 | .cursor_pointer() |
| 1619 | .hover(|button| button.bg(theme::row_hover())) |
| 1620 | .tooltip(move |window, cx| Tooltip::new(close_tooltip).build(window, cx)) |
| 1621 | .child(icon(IconName::Close, 14., theme::text_muted())) |
| 1622 | .on_click(move |_, _, cx| on_close(cx)), |
| 1623 | ), |
| 1624 | ) |
| 1625 | .child(body) |
| 1626 | } |
| 1627 | |
| 1628 | #[cfg(test)] |
| 1629 | mod tests { |
| 1630 | use super::{TileSize, name_plate_metrics}; |
| 1631 | |
| 1632 | #[test] |
| 1633 | fn small_strip_tiles_get_a_compact_name_plate() { |
| 1634 | let strip = name_plate_metrics(TileSize { |
| 1635 | width: 216., |
| 1636 | height: 121.5, |
| 1637 | avatar: 48., |
| 1638 | }); |
| 1639 | assert_eq!( |
| 1640 | (strip.text_size, strip.inset, strip.padding_y), |
| 1641 | (11., 4., 2.) |
| 1642 | ); |
| 1643 | assert!(strip.max_width_share < 1.); |
| 1644 | let stage = name_plate_metrics(TileSize { |
| 1645 | width: 640., |
| 1646 | height: 360., |
| 1647 | avatar: 96., |
| 1648 | }); |
| 1649 | assert_eq!((stage.text_size, stage.inset), (12., 8.)); |
| 1650 | } |
| 1651 | } |