collab_ui.rs

  1pub mod channel_view;
  2pub mod chat_panel;
  3pub mod collab_panel;
  4mod collab_titlebar_item;
  5mod face_pile;
  6pub mod notification_panel;
  7pub mod notifications;
  8mod panel_settings;
  9
 10use std::{rc::Rc, sync::Arc};
 11
 12use call::{report_call_event_for_room, ActiveCall};
 13pub use collab_panel::CollabPanel;
 14pub use collab_titlebar_item::CollabTitlebarItem;
 15use gpui::{
 16    actions, point, AppContext, GlobalPixels, Pixels, PlatformDisplay, Size, Task, WindowBounds,
 17    WindowKind, WindowOptions,
 18};
 19pub use panel_settings::{
 20    ChatPanelSettings, CollaborationPanelSettings, NotificationPanelSettings,
 21};
 22use settings::Settings;
 23use workspace::AppState;
 24
 25actions!(
 26    collab,
 27    [ToggleScreenSharing, ToggleMute, ToggleDeafen, LeaveCall]
 28);
 29
 30pub fn init(app_state: &Arc<AppState>, cx: &mut AppContext) {
 31    CollaborationPanelSettings::register(cx);
 32    ChatPanelSettings::register(cx);
 33    NotificationPanelSettings::register(cx);
 34
 35    vcs_menu::init(cx);
 36    collab_titlebar_item::init(cx);
 37    collab_panel::init(cx);
 38    channel_view::init(cx);
 39    chat_panel::init(cx);
 40    notification_panel::init(cx);
 41    notifications::init(&app_state, cx);
 42}
 43
 44pub fn toggle_screen_sharing(_: &ToggleScreenSharing, cx: &mut AppContext) {
 45    let call = ActiveCall::global(cx).read(cx);
 46    if let Some(room) = call.room().cloned() {
 47        let client = call.client();
 48        let toggle_screen_sharing = room.update(cx, |room, cx| {
 49            if room.is_screen_sharing() {
 50                report_call_event_for_room(
 51                    "disable screen share",
 52                    room.id(),
 53                    room.channel_id(),
 54                    &client,
 55                );
 56                Task::ready(room.unshare_screen(cx))
 57            } else {
 58                report_call_event_for_room(
 59                    "enable screen share",
 60                    room.id(),
 61                    room.channel_id(),
 62                    &client,
 63                );
 64                room.share_screen(cx)
 65            }
 66        });
 67        toggle_screen_sharing.detach_and_log_err(cx);
 68    }
 69}
 70
 71pub fn toggle_mute(_: &ToggleMute, cx: &mut AppContext) {
 72    let call = ActiveCall::global(cx).read(cx);
 73    if let Some(room) = call.room().cloned() {
 74        let client = call.client();
 75        room.update(cx, |room, cx| {
 76            let operation = if room.is_muted() {
 77                "enable microphone"
 78            } else {
 79                "disable microphone"
 80            };
 81            report_call_event_for_room(operation, room.id(), room.channel_id(), &client);
 82
 83            room.toggle_mute(cx)
 84        });
 85    }
 86}
 87
 88pub fn toggle_deafen(_: &ToggleDeafen, cx: &mut AppContext) {
 89    if let Some(room) = ActiveCall::global(cx).read(cx).room().cloned() {
 90        room.update(cx, |room, cx| room.toggle_deafen(cx));
 91    }
 92}
 93
 94fn notification_window_options(
 95    screen: Rc<dyn PlatformDisplay>,
 96    window_size: Size<Pixels>,
 97) -> WindowOptions {
 98    let notification_margin_width = GlobalPixels::from(16.);
 99    let notification_margin_height = GlobalPixels::from(-0.) - GlobalPixels::from(48.);
100
101    let screen_bounds = screen.bounds();
102    let size: Size<GlobalPixels> = window_size.into();
103
104    let bounds = gpui::Bounds::<GlobalPixels> {
105        origin: screen_bounds.upper_right()
106            - point(
107                size.width + notification_margin_width,
108                notification_margin_height,
109            ),
110        size: window_size.into(),
111    };
112    WindowOptions {
113        bounds: WindowBounds::Fixed(bounds),
114        titlebar: None,
115        center: false,
116        focus: false,
117        show: true,
118        kind: WindowKind::PopUp,
119        is_movable: false,
120        display_id: Some(screen.id()),
121    }
122}