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