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