Display call notifications on all screens

This commit is contained in:
Antonio Scandurra 2022-10-26 12:05:56 +02:00
parent 5a8061ac7b
commit 5984be3d84
3 changed files with 58 additions and 44 deletions

View file

@ -18,20 +18,21 @@ pub fn init(cx: &mut MutableAppContext) {
let mut incoming_call = ActiveCall::global(cx).read(cx).incoming(); let mut incoming_call = ActiveCall::global(cx).read(cx).incoming();
cx.spawn(|mut cx| async move { cx.spawn(|mut cx| async move {
let mut notification_window = None; let mut notification_windows = Vec::new();
while let Some(incoming_call) = incoming_call.next().await { while let Some(incoming_call) = incoming_call.next().await {
if let Some(window_id) = notification_window.take() { for window_id in notification_windows.drain(..) {
cx.remove_window(window_id); cx.remove_window(window_id);
} }
if let Some(incoming_call) = incoming_call { if let Some(incoming_call) = incoming_call {
const PADDING: f32 = 16.; const PADDING: f32 = 16.;
let screen_size = cx.platform().screen_size();
let window_size = cx.read(|cx| { let window_size = cx.read(|cx| {
let theme = &cx.global::<Settings>().theme.incoming_call_notification; let theme = &cx.global::<Settings>().theme.incoming_call_notification;
vec2f(theme.window_width, theme.window_height) vec2f(theme.window_width, theme.window_height)
}); });
for screen in cx.platform().screens() {
let screen_size = screen.size();
let (window_id, _) = cx.add_window( let (window_id, _) = cx.add_window(
WindowOptions { WindowOptions {
bounds: WindowBounds::Fixed(RectF::new( bounds: WindowBounds::Fixed(RectF::new(
@ -42,10 +43,12 @@ pub fn init(cx: &mut MutableAppContext) {
center: false, center: false,
kind: WindowKind::PopUp, kind: WindowKind::PopUp,
is_movable: false, is_movable: false,
screen: Some(screen),
}, },
|_| IncomingCallNotification::new(incoming_call), |_| IncomingCallNotification::new(incoming_call.clone()),
); );
notification_window = Some(window_id); notification_windows.push(window_id);
}
} }
} }
}) })

View file

@ -27,10 +27,11 @@ pub fn init(cx: &mut MutableAppContext) {
worktree_root_names, worktree_root_names,
} => { } => {
const PADDING: f32 = 16.; const PADDING: f32 = 16.;
let screen_size = cx.platform().screen_size();
let theme = &cx.global::<Settings>().theme.project_shared_notification; let theme = &cx.global::<Settings>().theme.project_shared_notification;
let window_size = vec2f(theme.window_width, theme.window_height); let window_size = vec2f(theme.window_width, theme.window_height);
for screen in cx.platform().screens() {
let screen_size = screen.size();
let (window_id, _) = cx.add_window( let (window_id, _) = cx.add_window(
WindowOptions { WindowOptions {
bounds: WindowBounds::Fixed(RectF::new( bounds: WindowBounds::Fixed(RectF::new(
@ -41,6 +42,7 @@ pub fn init(cx: &mut MutableAppContext) {
center: false, center: false,
kind: WindowKind::PopUp, kind: WindowKind::PopUp,
is_movable: false, is_movable: false,
screen: Some(screen),
}, },
|_| { |_| {
ProjectSharedNotification::new( ProjectSharedNotification::new(
@ -50,18 +52,26 @@ pub fn init(cx: &mut MutableAppContext) {
) )
}, },
); );
notification_windows.insert(*project_id, window_id); notification_windows
.entry(*project_id)
.or_insert(Vec::new())
.push(window_id);
}
} }
room::Event::RemoteProjectUnshared { project_id } => { room::Event::RemoteProjectUnshared { project_id } => {
if let Some(window_id) = notification_windows.remove(&project_id) { if let Some(window_ids) = notification_windows.remove(&project_id) {
for window_id in window_ids {
cx.remove_window(window_id); cx.remove_window(window_id);
} }
} }
}
room::Event::Left => { room::Event::Left => {
for (_, window_id) in notification_windows.drain() { for (_, window_ids) in notification_windows.drain() {
for window_id in window_ids {
cx.remove_window(window_id); cx.remove_window(window_id);
} }
} }
}
_ => {} _ => {}
}) })
.detach(); .detach();

View file

@ -344,6 +344,7 @@ pub fn build_window_options() -> WindowOptions<'static> {
center: false, center: false,
kind: WindowKind::Normal, kind: WindowKind::Normal,
is_movable: true, is_movable: true,
screen: None,
} }
} }