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, DevicePixels, Pixels, PlatformDisplay, Size, Task,
 17    WindowBackgroundAppearance, WindowContext, WindowKind, WindowOptions,
 18};
 19use panel_settings::MessageEditorSettings;
 20pub use panel_settings::{
 21    ChatPanelSettings, CollaborationPanelSettings, NotificationPanelSettings,
 22};
 23use settings::Settings;
 24use workspace::{notifications::DetachAndPromptErr, AppState};
 25
 26actions!(
 27    collab,
 28    [ToggleScreenSharing, ToggleMute, ToggleDeafen, LeaveCall]
 29);
 30
 31pub fn init(app_state: &Arc<AppState>, cx: &mut AppContext) {
 32    CollaborationPanelSettings::register(cx);
 33    ChatPanelSettings::register(cx);
 34    NotificationPanelSettings::register(cx);
 35    MessageEditorSettings::register(cx);
 36
 37    vcs_menu::init(cx);
 38    collab_titlebar_item::init(cx);
 39    collab_panel::init(cx);
 40    channel_view::init(cx);
 41    chat_panel::init(cx);
 42    notification_panel::init(cx);
 43    notifications::init(&app_state, cx);
 44}
 45
 46pub fn toggle_screen_sharing(_: &ToggleScreenSharing, cx: &mut WindowContext) {
 47    let call = ActiveCall::global(cx).read(cx);
 48    if let Some(room) = call.room().cloned() {
 49        let client = call.client();
 50        let toggle_screen_sharing = room.update(cx, |room, cx| {
 51            if room.is_screen_sharing() {
 52                report_call_event_for_room(
 53                    "disable screen share",
 54                    room.id(),
 55                    room.channel_id(),
 56                    &client,
 57                );
 58                Task::ready(room.unshare_screen(cx))
 59            } else {
 60                report_call_event_for_room(
 61                    "enable screen share",
 62                    room.id(),
 63                    room.channel_id(),
 64                    &client,
 65                );
 66                room.share_screen(cx)
 67            }
 68        });
 69        toggle_screen_sharing.detach_and_prompt_err("Sharing Screen Failed", cx, |e, _| Some(format!("{:?}\n\nPlease check that you have given Zed permissions to record your screen in Settings.", e)));
 70    }
 71}
 72
 73pub fn toggle_mute(_: &ToggleMute, cx: &mut AppContext) {
 74    let call = ActiveCall::global(cx).read(cx);
 75    if let Some(room) = call.room().cloned() {
 76        let client = call.client();
 77        room.update(cx, |room, cx| {
 78            let operation = if room.is_muted() {
 79                "enable microphone"
 80            } else {
 81                "disable microphone"
 82            };
 83            report_call_event_for_room(operation, room.id(), room.channel_id(), &client);
 84
 85            room.toggle_mute(cx)
 86        });
 87    }
 88}
 89
 90pub fn toggle_deafen(_: &ToggleDeafen, cx: &mut AppContext) {
 91    if let Some(room) = ActiveCall::global(cx).read(cx).room().cloned() {
 92        room.update(cx, |room, cx| room.toggle_deafen(cx));
 93    }
 94}
 95
 96fn notification_window_options(
 97    screen: Rc<dyn PlatformDisplay>,
 98    window_size: Size<Pixels>,
 99) -> WindowOptions {
100    let notification_margin_width = DevicePixels::from(16);
101    let notification_margin_height = DevicePixels::from(-0) - DevicePixels::from(48);
102
103    let screen_bounds = screen.bounds();
104    let size: Size<DevicePixels> = window_size.into();
105
106    let bounds = gpui::Bounds::<DevicePixels> {
107        origin: screen_bounds.upper_right()
108            - point(
109                size.width + notification_margin_width,
110                notification_margin_height,
111            ),
112        size: window_size.into(),
113    };
114
115    WindowOptions {
116        bounds: Some(bounds),
117        titlebar: None,
118        focus: false,
119        show: true,
120        kind: WindowKind::PopUp,
121        is_movable: false,
122        display_id: Some(screen.id()),
123        fullscreen: false,
124        window_background: WindowBackgroundAppearance::default(),
125    }
126}