feat(linux): Wayland screen share via desktop ScreenCast portal
Under Wayland, share screen or window through the portal dialog instead of an empty thumbnail list. Cancel stays quiet; missing portal shows a notice.
@@ -61,7 +61,7 @@
61
61
**Calls**
62
62
- Test call to the Teams Echo bot from the avatar menu: native WebRTC audio, mute (`Ctrl+Shift+M`), device switching, mini window while you read other chats
63
63
- Phone button in 1:1 and group chat headers: callee tiles show Calling and Ringing, Cancel while ringing, notices like "Bea declined" or "No answer"
64
- Video and screen sharing: H264 tiles, shared screen on a stage (double click for full window, Esc back), camera and screen share buttons with a "You are sharing" banner. Linux needs glib at run time
64
- Video and screen sharing: H264 tiles, shared screen on a stage (double click for full window, Esc back), camera and screen share buttons with a "You are sharing" banner. Linux needs glib at run time. On Wayland, sharing opens the desktop ScreenCast portal dialog, including on KDE, GNOME and Hyprland
65
65
- Incoming calls: topmost ring toast with Decline and Accept, ring tone, missed calls in Activity
66
66
- Join a running meeting from its chat (audio): roster tiles, speaking ring, lobby state, Leave or End meeting for the organizer
67
67
- After every call a pseudonymized test report (JSON and Markdown, newest 30) is saved to the app data folder `call-reports`; toast "Test report saved" with Open folder, Settings > Devices switch
@@ -74,6 +74,11 @@
74
74
- One-click install for Claude Code, Codex CLI, Copilot CLI, VS Code and Cursor, Windows and WSL. WSL needs `networkingMode=mirrored`
75
75
- Delegate a message to a coding-agent CLI (Claude Code, Copilot, any CLI) from the hover toolbar: progress chip, Agents page, toast when it finishes, Open session
76
76
77
**Calendar (fork)**
78
- Outlook calendar as today, plus optional Google Calendar accounts (Settings > Calendar)
79
- Merge by iCal UID / Teams join URL; New meeting writes to the home calendar and optional extra targets
80
- Google OAuth Desktop (PKCE): set `TEAMS_GOOGLE_CLIENT_ID` and optionally `TEAMS_GOOGLE_CLIENT_SECRET` before Connect
81
77
82
**App**
78
83
- Dark theme, opens instantly from the cache
79
84
- Self-update from an update folder
@@ -84,7 +89,7 @@
84
89
| Platform | State |
85
90
|---|---|
86
91
| 🪟 Windows | Main target. Login through an embedded WebView2 |
87
| 🐧 Linux | Connects to a Chrome started with `--remote-debugging-port=9222` and signed in to Teams on the web. The app opens an Outlook on the web tab next to it when missing (some tenants grant chat scopes only to Outlook). Built-in login is planned |
92
| 🐧 Linux | Starts Google Chrome or Chromium on its own (debug port 9222, own profile in the XDG data folder) and keeps it headless in the background. When Teams asks for a login, the Chrome window shows itself and goes back to the background once you are signed in. `--endpoint` connects to a Chrome you started yourself instead. The app opens an Outlook on the web tab next to Teams when missing (some tenants grant chat scopes only to Outlook). Color emoji use a bundled bitmap Noto Color Emoji font; a system COLRv1 face of the same name is left out of the font list. The window id is `rusty-teams`. Copy `crates/app/assets/linux/rusty-teams.desktop` to `~/.local/share/applications/` and `crates/app/assets/icon/teams-fast-256.png` to `~/.local/share/icons/hicolor/256x256/apps/rusty-teams.png` so the dock can match it. Built-in login without Chrome is planned |
88
93
| 🍎 macOS | Experimental. Universal arm64 + x86_64 binary, connects to a Chrome like Linux |
89
94
90
95
The remaining gaps are planned, see [ROADMAP.md](ROADMAP.md).
@@ -97,6 +102,21 @@ Try it with demo data, no account needed:
97
102
cargo run -p app -- --demo
98
103
```
99
104
105
### Google Calendar (optional)
106
107
1. Create an OAuth Desktop client in Google Cloud Console with redirect `http://127.0.0.1:<port>/` (loopback; the app picks a free port).
108
2. Export before starting the app:
109
110
```bash
111
export TEAMS_GOOGLE_CLIENT_ID="….apps.googleusercontent.com"
112
# only if the client has a secret:
113
export TEAMS_GOOGLE_CLIENT_SECRET="…"
114
```
115
116
3. Settings > Calendar > Connect Google, then choose home calendar and optional dual-write targets.
117
118
Without these env vars the calendar stays Outlook-only.
119
100
120
| Task | Command |
101
121
|---|---|
102
122
| Linux build needs clang 21+ (libwebrtc's hermetic libc++) + mold (set in `.cargo/config.toml`); sccache shares compiled deps across worktrees | `sudo apt install clang mold sccache`, clang from [apt.llvm.org](https://apt.llvm.org) if the distro one is older than 21 |
@@ -61,7 +61,7 @@61
**Calls**61
**Calls**62
- Test call to the Teams Echo bot from the avatar menu: native WebRTC audio, mute (`Ctrl+Shift+M`), device switching, mini window while you read other chats62
- Test call to the Teams Echo bot from the avatar menu: native WebRTC audio, mute (`Ctrl+Shift+M`), device switching, mini window while you read other chats63
- Phone button in 1:1 and group chat headers: callee tiles show Calling and Ringing, Cancel while ringing, notices like "Bea declined" or "No answer"63
- Phone button in 1:1 and group chat headers: callee tiles show Calling and Ringing, Cancel while ringing, notices like "Bea declined" or "No answer"64
- Video and screen sharing: H264 tiles, shared screen on a stage (double click for full window, Esc back), camera and screen share buttons with a "You are sharing" banner. Linux needs glib at run time64
- Video and screen sharing: H264 tiles, shared screen on a stage (double click for full window, Esc back), camera and screen share buttons with a "You are sharing" banner. Linux needs glib at run time. On Wayland, sharing opens the desktop ScreenCast portal dialog, including on KDE, GNOME and Hyprland65
- Incoming calls: topmost ring toast with Decline and Accept, ring tone, missed calls in Activity65
- Incoming calls: topmost ring toast with Decline and Accept, ring tone, missed calls in Activity66
- Join a running meeting from its chat (audio): roster tiles, speaking ring, lobby state, Leave or End meeting for the organizer66
- Join a running meeting from its chat (audio): roster tiles, speaking ring, lobby state, Leave or End meeting for the organizer67
- After every call a pseudonymized test report (JSON and Markdown, newest 30) is saved to the app data folder `call-reports`; toast "Test report saved" with Open folder, Settings > Devices switch67
- After every call a pseudonymized test report (JSON and Markdown, newest 30) is saved to the app data folder `call-reports`; toast "Test report saved" with Open folder, Settings > Devices switch@@ -74,6 +74,11 @@74
- One-click install for Claude Code, Codex CLI, Copilot CLI, VS Code and Cursor, Windows and WSL. WSL needs `networkingMode=mirrored`74
- One-click install for Claude Code, Codex CLI, Copilot CLI, VS Code and Cursor, Windows and WSL. WSL needs `networkingMode=mirrored`75
- Delegate a message to a coding-agent CLI (Claude Code, Copilot, any CLI) from the hover toolbar: progress chip, Agents page, toast when it finishes, Open session75
- Delegate a message to a coding-agent CLI (Claude Code, Copilot, any CLI) from the hover toolbar: progress chip, Agents page, toast when it finishes, Open session76
76
77
**Calendar (fork)**78
- Outlook calendar as today, plus optional Google Calendar accounts (Settings > Calendar)79
- Merge by iCal UID / Teams join URL; New meeting writes to the home calendar and optional extra targets80
- Google OAuth Desktop (PKCE): set `TEAMS_GOOGLE_CLIENT_ID` and optionally `TEAMS_GOOGLE_CLIENT_SECRET` before Connect81
77
**App**82
**App**78
- Dark theme, opens instantly from the cache83
- Dark theme, opens instantly from the cache79
- Self-update from an update folder84
- Self-update from an update folder@@ -84,7 +89,7 @@84
| Platform | State |89
| Platform | State |85
|---|---|90
|---|---|86
| 🪟 Windows | Main target. Login through an embedded WebView2 |91
| 🪟 Windows | Main target. Login through an embedded WebView2 |87
| 🐧 Linux | Connects to a Chrome started with `--remote-debugging-port=9222` and signed in to Teams on the web. The app opens an Outlook on the web tab next to it when missing (some tenants grant chat scopes only to Outlook). Built-in login is planned |92
| 🐧 Linux | Starts Google Chrome or Chromium on its own (debug port 9222, own profile in the XDG data folder) and keeps it headless in the background. When Teams asks for a login, the Chrome window shows itself and goes back to the background once you are signed in. `--endpoint` connects to a Chrome you started yourself instead. The app opens an Outlook on the web tab next to Teams when missing (some tenants grant chat scopes only to Outlook). Color emoji use a bundled bitmap Noto Color Emoji font; a system COLRv1 face of the same name is left out of the font list. The window id is `rusty-teams`. Copy `crates/app/assets/linux/rusty-teams.desktop` to `~/.local/share/applications/` and `crates/app/assets/icon/teams-fast-256.png` to `~/.local/share/icons/hicolor/256x256/apps/rusty-teams.png` so the dock can match it. Built-in login without Chrome is planned |88
| 🍎 macOS | Experimental. Universal arm64 + x86_64 binary, connects to a Chrome like Linux |93
| 🍎 macOS | Experimental. Universal arm64 + x86_64 binary, connects to a Chrome like Linux |89
94
90
The remaining gaps are planned, see [ROADMAP.md](ROADMAP.md).95
The remaining gaps are planned, see [ROADMAP.md](ROADMAP.md).@@ -97,6 +102,21 @@ Try it with demo data, no account needed:97
cargo run -p app -- --demo102
cargo run -p app -- --demo98
```103
```99
104
105
### Google Calendar (optional)106
107
1. Create an OAuth Desktop client in Google Cloud Console with redirect `http://127.0.0.1:<port>/` (loopback; the app picks a free port).108
2. Export before starting the app:109
110
```bash111
export TEAMS_GOOGLE_CLIENT_ID="….apps.googleusercontent.com"112
# only if the client has a secret:113
export TEAMS_GOOGLE_CLIENT_SECRET="…"114
```115
116
3. Settings > Calendar > Connect Google, then choose home calendar and optional dual-write targets.117
118
Without these env vars the calendar stays Outlook-only.119
100
| Task | Command |120
| Task | Command |101
|---|---|121
|---|---|102
| Linux build needs clang 21+ (libwebrtc's hermetic libc++) + mold (set in `.cargo/config.toml`); sccache shares compiled deps across worktrees | `sudo apt install clang mold sccache`, clang from [apt.llvm.org](https://apt.llvm.org) if the distro one is older than 21 |122
| Linux build needs clang 21+ (libwebrtc's hermetic libc++) + mold (set in `.cargo/config.toml`); sccache shares compiled deps across worktrees | `sudo apt install clang mold sccache`, clang from [apt.llvm.org](https://apt.llvm.org) if the distro one is older than 21 |@@ -18,9 +18,6 @@ use crate::app_state::AppState;
18
18
use crate::notify::platform::{self, NativeHandle, ScreenRect, ShareGeometry, WorkArea};
19
19
use crate::views::call_mini_window::MiniWindowView;
20
20
use crate::views::call_pop_out::{POP_OUT_SIZE, POP_OUT_TITLE, SharePopOutView};
21
use crate::views::call_window::{
22
CALL_WINDOW_MIN_SIZE, CALL_WINDOW_SIZE, CallWindowView, call_window_title,
23
};
24
21
use crate::views::call_share_gallery::ShareGalleryView;
25
22
use crate::views::share_bar::{ShareBarView, ShareBorderView};
26
23
@@ -37,17 +34,6 @@ enum Role {
37
34
Border(usize),
38
35
}
39
36
40
impl Role {
41
fn surface(self) -> Surface {
42
match self {
43
Role::Bar => Surface::ShareBar,
44
Role::Mini => Surface::Mini,
45
Role::Gallery => Surface::Gallery,
46
Role::Border(_) => Surface::Border,
47
}
48
}
49
}
50
51
37
struct Placed {
52
38
handle: AnyWindowHandle,
53
39
native: Option<NativeHandle>,
@@ -102,12 +88,8 @@ struct ShareSession {
102
88
103
89
pub struct CallWindows {
104
90
app: Entity<AppState>,
91
main_window: AnyWindowHandle,
105
92
main_native: Option<NativeHandle>,
106
stage: Option<AnyWindowHandle>,
107
stage_native: Option<NativeHandle>,
108
stage_opening: bool,
109
stage_closed_by_user: bool,
110
seen_viewing: Option<bool>,
111
93
work_area: Option<WorkArea>,
112
94
minimized: bool,
113
95
windows: HashMap<Role, Placed>,
@@ -125,6 +107,7 @@ pub struct CallWindows {
125
107
gallery_seen: Option<(i32, i32)>,
126
108
gallery_layout: GalleryLayout,
127
109
speaker_only: bool,
110
main_excluded: bool,
128
111
minimized_for_share: bool,
129
112
ticks: u32,
130
113
}
@@ -181,12 +164,8 @@ impl CallWindows {
181
164
let gallery_saved = saved_position(GALLERY_POSITION_KEY, cx);
182
165
let windows = CallWindows {
183
166
app,
167
main_window: window.window_handle(),
184
168
main_native: platform::native_handle(window),
185
stage: None,
186
stage_native: None,
187
stage_opening: false,
188
stage_closed_by_user: false,
189
seen_viewing: None,
190
169
work_area: None,
191
170
minimized: false,
192
171
windows: HashMap::new(),
@@ -204,6 +183,7 @@ impl CallWindows {
204
183
gallery_seen: None,
205
184
gallery_layout: gallery_layout(0, true, f32::MAX),
206
185
speaker_only: false,
186
main_excluded: false,
207
187
minimized_for_share: false,
208
188
ticks: 0,
209
189
};
@@ -275,128 +255,21 @@ impl CallWindows {
275
255
}
276
256
277
257
pub fn return_to_call(&mut self, cx: &mut Context<Self>) {
278
self.raise_stage(cx);
279
self.app.update(cx, |state, cx| state.show_call(true, cx));
280
}
281
282
fn raise_stage(&mut self, cx: &mut Context<Self>) {
283
if let Some(native) = self.stage_native {
258
if let Some(native) = self.main_native {
284
259
platform::restore_and_raise(native);
285
260
}
286
if let Some(stage) = self.stage {
287
stage.update(cx, |_, window, _| window.activate_window()).ok();
288
}
289
}
290
291
fn stage_wanted(&self, cx: &App) -> bool {
292
let state = self.app.read(cx);
293
state.call.is_some() || state.call_end.is_some() || state.prejoin.is_some()
294
}
295
296
fn sync_stage(&mut self, cx: &mut Context<Self>) {
297
let wanted = self.stage_wanted(cx);
298
if self.stage_closed_by_user {
299
if !wanted {
300
self.stage_closed_by_user = false;
301
} else if self.app.read(cx).call.is_none() {
302
self.app.update(cx, |state, cx| state.dismiss_call_end(cx));
303
}
304
return;
305
}
306
match (wanted, self.stage) {
307
(true, None) => self.open_stage(cx),
308
(false, Some(stage)) => {
309
self.forget_stage();
310
stage.update(cx, |_, window, _| window.remove_window()).ok();
311
}
312
(true, Some(stage)) => {
313
if stage.update(cx, |_, _, _| ()).is_err() {
314
self.forget_stage();
315
self.stage_closed_by_user = true;
316
}
317
}
318
(false, None) => {}
319
}
320
}
321
322
fn forget_stage(&mut self) {
323
self.stage = None;
324
self.stage_native = None;
325
self.minimized = false;
326
self.minimized_for_share = false;
327
self.seen_viewing = None;
328
}
329
330
fn open_stage(&mut self, cx: &mut Context<Self>) {
331
if self.stage_opening {
332
return;
333
}
334
self.stage_opening = true;
335
let controller = cx.entity();
336
let app = self.app.clone();
337
let mut options = gpui_kit::component::TitleBar::window_options();
338
options.window_bounds = Some(WindowBounds::Windowed(Bounds::centered(
339
None,
340
size(px(CALL_WINDOW_SIZE.0), px(CALL_WINDOW_SIZE.1)),
341
cx,
342
)));
343
options.window_min_size = Some(size(px(CALL_WINDOW_MIN_SIZE.0), px(CALL_WINDOW_MIN_SIZE.1)));
344
if let Some(titlebar) = options.titlebar.as_mut() {
345
titlebar.title = Some(call_window_title(self.app.read(cx)).into());
346
}
347
// open_window draws right away, and the view reads the app entity while rendering.
348
cx.defer(move |cx| {
349
let opened = gpui_kit::open_window(options, cx, move |window, cx| {
350
cx.new(|cx| CallWindowView::new(app, window, cx))
351
});
352
let stage = opened.ok().map(|(handle, _)| handle);
353
let native = stage.and_then(|stage| {
354
stage
355
.update(cx, |_, window, _| platform::native_handle(window))
356
.ok()
357
.flatten()
358
});
359
controller.update(cx, |this, _| {
360
this.stage_opening = false;
361
this.stage = stage;
362
this.stage_native = native;
363
});
364
});
365
}
366
367
fn sync_viewing(&mut self, cx: &mut Context<Self>) {
368
let Some(viewing) = self.app.read(cx).call.as_ref().map(|call| call.viewing) else {
369
return;
370
};
371
let Some(stage) = self.stage else {
372
return;
373
};
374
match self.seen_viewing {
375
Some(seen) if seen == viewing => {
376
if self.stage_native.is_some() && viewing == self.minimized {
377
self.seen_viewing = Some(!viewing);
378
self.app.update(cx, |state, cx| state.show_call(!viewing, cx));
379
}
380
}
381
_ => {
382
self.seen_viewing = Some(viewing);
383
if viewing && self.minimized {
384
self.raise_stage(cx);
385
} else if !viewing && !self.minimized {
386
stage.update(cx, |_, window, _| window.minimize_window()).ok();
387
}
388
}
389
}
261
self.main_window
262
.update(cx, |_, window, _| window.activate_window())
263
.ok();
264
self.app.update(cx, |state, cx| state.show_call(true, cx));
390
265
}
391
266
392
267
fn idle(&self, cx: &App) -> bool {
393
!self.stage_wanted(cx)
394
&& self.stage.is_none()
395
&& !self.stage_opening
396
&& !self.stage_closed_by_user
268
self.app.read(cx).call.is_none()
397
269
&& self.share.is_none()
398
270
&& self.windows.is_empty()
399
271
&& self.opening.is_empty()
272
&& !self.main_excluded
400
273
}
401
274
402
275
fn tick(&mut self, cx: &mut Context<Self>) -> Duration {
@@ -405,10 +278,9 @@ impl CallWindows {
405
278
}
406
279
self.ticks = self.ticks.wrapping_add(1);
407
280
let slow = self.ticks % SLOW_TICK_EVERY == 0;
408
self.sync_stage(cx);
409
self.refresh_stage_window();
410
self.sync_viewing(cx);
281
self.refresh_main_window();
411
282
self.sync_share(slow, cx);
283
self.sync_capture_exclusion();
412
284
self.sync_pop_out(cx);
413
285
self.sync_monitor(cx);
414
286
if slow {
@@ -418,11 +290,11 @@ impl CallWindows {
418
290
TICK
419
291
}
420
292
421
fn refresh_stage_window(&mut self) {
422
let Some(native) = self.stage_native.or(self.main_native) else {
293
fn refresh_main_window(&mut self) {
294
let Some(native) = self.main_native else {
423
295
return;
424
296
};
425
let minimized = self.stage_native.is_some_and(platform::window_minimized);
297
let minimized = platform::window_minimized(native);
426
298
if self.minimized && !minimized {
427
299
self.minimized_for_share = false;
428
300
}
@@ -435,13 +307,27 @@ impl CallWindows {
435
307
fn local_share(&self, cx: &App) -> Option<Option<ShareSource>> {
436
308
let model = &self.app.read(cx).call.as_ref()?.model;
437
309
let label = model.local_share.as_ref()?;
438
Some(
439
model
440
.share_sources
441
.iter()
442
.find(|source| &source.label() == label)
443
.cloned(),
444
)
310
if let Some(source) = model
311
.share_sources
312
.iter()
313
.find(|source| &source.label() == label)
314
.cloned()
315
{
316
return Some(Some(source));
317
}
318
Some(model.share_kind.map(|kind| ShareSource {
319
id: 0,
320
kind,
321
title: label.clone(),
322
}))
323
}
324
325
fn portal_picker(&self, cx: &App) -> bool {
326
self.app
327
.read(cx)
328
.call
329
.as_ref()
330
.is_some_and(|call| call.model.uses_portal_picker())
445
331
}
446
332
447
333
fn sync_share(&mut self, refresh_geometry: bool, cx: &mut Context<Self>) {
@@ -533,19 +419,36 @@ impl CallWindows {
533
419
}
534
420
535
421
fn minimize_for_share(&mut self, shared: Option<ScreenRect>, cx: &mut Context<Self>) {
536
let Some(native) = self.stage_native.filter(|_| !self.minimized) else {
422
let Some(native) = self.main_native.filter(|_| !self.minimized) else {
537
423
return;
538
424
};
539
425
if !minimize_on_share_start(
540
426
self.local_share_mode(),
541
427
platform::window_rect(native),
542
428
shared,
429
self.portal_picker(cx),
543
430
) {
544
431
return;
545
432
}
546
433
self.minimized_for_share = true;
547
if let Some(stage) = self.stage {
548
stage.update(cx, |_, window, _| window.minimize_window()).ok();
434
self.main_window
435
.update(cx, |_, window, _| window.minimize_window())
436
.ok();
437
}
438
439
fn sync_capture_exclusion(&mut self) {
440
let Some(native) = self.main_native else {
441
return;
442
};
443
let wanted = excluded_from_capture(Surface::Main, self.local_share_mode());
444
if wanted == self.main_excluded {
445
return;
446
}
447
self.main_excluded = wanted;
448
if wanted {
449
platform::exclude_from_capture(native);
450
} else {
451
platform::include_in_capture(native);
549
452
}
550
453
}
551
454
@@ -777,9 +680,7 @@ impl CallWindows {
777
680
.flatten();
778
681
if let Some(native) = native {
779
682
platform::prepare_toast_window(native);
780
if excluded_from_capture(role.surface()) {
781
platform::exclude_from_capture(native);
782
}
683
platform::exclude_from_capture(native);
783
684
}
784
685
if matches!(role, Role::Border(_)) {
785
686
handle
@@ -18,9 +18,6 @@ use crate::app_state::AppState;18
use crate::notify::platform::{self, NativeHandle, ScreenRect, ShareGeometry, WorkArea};18
use crate::notify::platform::{self, NativeHandle, ScreenRect, ShareGeometry, WorkArea};19
use crate::views::call_mini_window::MiniWindowView;19
use crate::views::call_mini_window::MiniWindowView;20
use crate::views::call_pop_out::{POP_OUT_SIZE, POP_OUT_TITLE, SharePopOutView};20
use crate::views::call_pop_out::{POP_OUT_SIZE, POP_OUT_TITLE, SharePopOutView};21
use crate::views::call_window::{22
CALL_WINDOW_MIN_SIZE, CALL_WINDOW_SIZE, CallWindowView, call_window_title,23
};24
use crate::views::call_share_gallery::ShareGalleryView;21
use crate::views::call_share_gallery::ShareGalleryView;25
use crate::views::share_bar::{ShareBarView, ShareBorderView};22
use crate::views::share_bar::{ShareBarView, ShareBorderView};26
23
@@ -37,17 +34,6 @@ enum Role {37
Border(usize),34
Border(usize),38
}35
}39
36
40
impl Role {41
fn surface(self) -> Surface {42
match self {43
Role::Bar => Surface::ShareBar,44
Role::Mini => Surface::Mini,45
Role::Gallery => Surface::Gallery,46
Role::Border(_) => Surface::Border,47
}48
}49
}50
51
struct Placed {37
struct Placed {52
handle: AnyWindowHandle,38
handle: AnyWindowHandle,53
native: Option<NativeHandle>,39
native: Option<NativeHandle>,@@ -102,12 +88,8 @@ struct ShareSession {102
88
103
pub struct CallWindows {89
pub struct CallWindows {104
app: Entity<AppState>,90
app: Entity<AppState>,91
main_window: AnyWindowHandle,105
main_native: Option<NativeHandle>,92
main_native: Option<NativeHandle>,106
stage: Option<AnyWindowHandle>,107
stage_native: Option<NativeHandle>,108
stage_opening: bool,109
stage_closed_by_user: bool,110
seen_viewing: Option<bool>,111
work_area: Option<WorkArea>,93
work_area: Option<WorkArea>,112
minimized: bool,94
minimized: bool,113
windows: HashMap<Role, Placed>,95
windows: HashMap<Role, Placed>,@@ -125,6 +107,7 @@ pub struct CallWindows {125
gallery_seen: Option<(i32, i32)>,107
gallery_seen: Option<(i32, i32)>,126
gallery_layout: GalleryLayout,108
gallery_layout: GalleryLayout,127
speaker_only: bool,109
speaker_only: bool,110
main_excluded: bool,128
minimized_for_share: bool,111
minimized_for_share: bool,129
ticks: u32,112
ticks: u32,130
}113
}@@ -181,12 +164,8 @@ impl CallWindows {181
let gallery_saved = saved_position(GALLERY_POSITION_KEY, cx);164
let gallery_saved = saved_position(GALLERY_POSITION_KEY, cx);182
let windows = CallWindows {165
let windows = CallWindows {183
app,166
app,167
main_window: window.window_handle(),184
main_native: platform::native_handle(window),168
main_native: platform::native_handle(window),185
stage: None,186
stage_native: None,187
stage_opening: false,188
stage_closed_by_user: false,189
seen_viewing: None,190
work_area: None,169
work_area: None,191
minimized: false,170
minimized: false,192
windows: HashMap::new(),171
windows: HashMap::new(),@@ -204,6 +183,7 @@ impl CallWindows {204
gallery_seen: None,183
gallery_seen: None,205
gallery_layout: gallery_layout(0, true, f32::MAX),184
gallery_layout: gallery_layout(0, true, f32::MAX),206
speaker_only: false,185
speaker_only: false,186
main_excluded: false,207
minimized_for_share: false,187
minimized_for_share: false,208
ticks: 0,188
ticks: 0,209
};189
};@@ -275,128 +255,21 @@ impl CallWindows {275
}255
}276
256
277
pub fn return_to_call(&mut self, cx: &mut Context<Self>) {257
pub fn return_to_call(&mut self, cx: &mut Context<Self>) {278
self.raise_stage(cx);258
if let Some(native) = self.main_native {279
self.app.update(cx, |state, cx| state.show_call(true, cx));280
}281
282
fn raise_stage(&mut self, cx: &mut Context<Self>) {283
if let Some(native) = self.stage_native {284
platform::restore_and_raise(native);259
platform::restore_and_raise(native);285
}260
}286
if let Some(stage) = self.stage {261
self.main_window287
stage.update(cx, |_, window, _| window.activate_window()).ok();262
.update(cx, |_, window, _| window.activate_window())288
}263
.ok();289
}264
self.app.update(cx, |state, cx| state.show_call(true, cx));290
291
fn stage_wanted(&self, cx: &App) -> bool {292
let state = self.app.read(cx);293
state.call.is_some() || state.call_end.is_some() || state.prejoin.is_some()294
}295
296
fn sync_stage(&mut self, cx: &mut Context<Self>) {297
let wanted = self.stage_wanted(cx);298
if self.stage_closed_by_user {299
if !wanted {300
self.stage_closed_by_user = false;301
} else if self.app.read(cx).call.is_none() {302
self.app.update(cx, |state, cx| state.dismiss_call_end(cx));303
}304
return;305
}306
match (wanted, self.stage) {307
(true, None) => self.open_stage(cx),308
(false, Some(stage)) => {309
self.forget_stage();310
stage.update(cx, |_, window, _| window.remove_window()).ok();311
}312
(true, Some(stage)) => {313
if stage.update(cx, |_, _, _| ()).is_err() {314
self.forget_stage();315
self.stage_closed_by_user = true;316
}317
}318
(false, None) => {}319
}320
}321
322
fn forget_stage(&mut self) {323
self.stage = None;324
self.stage_native = None;325
self.minimized = false;326
self.minimized_for_share = false;327
self.seen_viewing = None;328
}329
330
fn open_stage(&mut self, cx: &mut Context<Self>) {331
if self.stage_opening {332
return;333
}334
self.stage_opening = true;335
let controller = cx.entity();336
let app = self.app.clone();337
let mut options = gpui_kit::component::TitleBar::window_options();338
options.window_bounds = Some(WindowBounds::Windowed(Bounds::centered(339
None,340
size(px(CALL_WINDOW_SIZE.0), px(CALL_WINDOW_SIZE.1)),341
cx,342
)));343
options.window_min_size = Some(size(px(CALL_WINDOW_MIN_SIZE.0), px(CALL_WINDOW_MIN_SIZE.1)));344
if let Some(titlebar) = options.titlebar.as_mut() {345
titlebar.title = Some(call_window_title(self.app.read(cx)).into());346
}347
// open_window draws right away, and the view reads the app entity while rendering.348
cx.defer(move |cx| {349
let opened = gpui_kit::open_window(options, cx, move |window, cx| {350
cx.new(|cx| CallWindowView::new(app, window, cx))351
});352
let stage = opened.ok().map(|(handle, _)| handle);353
let native = stage.and_then(|stage| {354
stage355
.update(cx, |_, window, _| platform::native_handle(window))356
.ok()357
.flatten()358
});359
controller.update(cx, |this, _| {360
this.stage_opening = false;361
this.stage = stage;362
this.stage_native = native;363
});364
});365
}366
367
fn sync_viewing(&mut self, cx: &mut Context<Self>) {368
let Some(viewing) = self.app.read(cx).call.as_ref().map(|call| call.viewing) else {369
return;370
};371
let Some(stage) = self.stage else {372
return;373
};374
match self.seen_viewing {375
Some(seen) if seen == viewing => {376
if self.stage_native.is_some() && viewing == self.minimized {377
self.seen_viewing = Some(!viewing);378
self.app.update(cx, |state, cx| state.show_call(!viewing, cx));379
}380
}381
_ => {382
self.seen_viewing = Some(viewing);383
if viewing && self.minimized {384
self.raise_stage(cx);385
} else if !viewing && !self.minimized {386
stage.update(cx, |_, window, _| window.minimize_window()).ok();387
}388
}389
}390
}265
}391
266
392
fn idle(&self, cx: &App) -> bool {267
fn idle(&self, cx: &App) -> bool {393
!self.stage_wanted(cx)268
self.app.read(cx).call.is_none()394
&& self.stage.is_none()395
&& !self.stage_opening396
&& !self.stage_closed_by_user397
&& self.share.is_none()269
&& self.share.is_none()398
&& self.windows.is_empty()270
&& self.windows.is_empty()399
&& self.opening.is_empty()271
&& self.opening.is_empty()272
&& !self.main_excluded400
}273
}401
274
402
fn tick(&mut self, cx: &mut Context<Self>) -> Duration {275
fn tick(&mut self, cx: &mut Context<Self>) -> Duration {@@ -405,10 +278,9 @@ impl CallWindows {405
}278
}406
self.ticks = self.ticks.wrapping_add(1);279
self.ticks = self.ticks.wrapping_add(1);407
let slow = self.ticks % SLOW_TICK_EVERY == 0;280
let slow = self.ticks % SLOW_TICK_EVERY == 0;408
self.sync_stage(cx);281
self.refresh_main_window();409
self.refresh_stage_window();410
self.sync_viewing(cx);411
self.sync_share(slow, cx);282
self.sync_share(slow, cx);283
self.sync_capture_exclusion();412
self.sync_pop_out(cx);284
self.sync_pop_out(cx);413
self.sync_monitor(cx);285
self.sync_monitor(cx);414
if slow {286
if slow {@@ -418,11 +290,11 @@ impl CallWindows {418
TICK290
TICK419
}291
}420
292
421
fn refresh_stage_window(&mut self) {293
fn refresh_main_window(&mut self) {422
let Some(native) = self.stage_native.or(self.main_native) else {294
let Some(native) = self.main_native else {423
return;295
return;424
};296
};425
let minimized = self.stage_native.is_some_and(platform::window_minimized);297
let minimized = platform::window_minimized(native);426
if self.minimized && !minimized {298
if self.minimized && !minimized {427
self.minimized_for_share = false;299
self.minimized_for_share = false;428
}300
}@@ -435,13 +307,27 @@ impl CallWindows {435
fn local_share(&self, cx: &App) -> Option<Option<ShareSource>> {307
fn local_share(&self, cx: &App) -> Option<Option<ShareSource>> {436
let model = &self.app.read(cx).call.as_ref()?.model;308
let model = &self.app.read(cx).call.as_ref()?.model;437
let label = model.local_share.as_ref()?;309
let label = model.local_share.as_ref()?;438
Some(310
if let Some(source) = model439
model311
.share_sources440
.share_sources312
.iter()441
.iter()313
.find(|source| &source.label() == label)442
.find(|source| &source.label() == label)314
.cloned()443
.cloned(),315
{444
)316
return Some(Some(source));317
}318
Some(model.share_kind.map(|kind| ShareSource {319
id: 0,320
kind,321
title: label.clone(),322
}))323
}324
325
fn portal_picker(&self, cx: &App) -> bool {326
self.app327
.read(cx)328
.call329
.as_ref()330
.is_some_and(|call| call.model.uses_portal_picker())445
}331
}446
332
447
fn sync_share(&mut self, refresh_geometry: bool, cx: &mut Context<Self>) {333
fn sync_share(&mut self, refresh_geometry: bool, cx: &mut Context<Self>) {@@ -533,19 +419,36 @@ impl CallWindows {533
}419
}534
420
535
fn minimize_for_share(&mut self, shared: Option<ScreenRect>, cx: &mut Context<Self>) {421
fn minimize_for_share(&mut self, shared: Option<ScreenRect>, cx: &mut Context<Self>) {536
let Some(native) = self.stage_native.filter(|_| !self.minimized) else {422
let Some(native) = self.main_native.filter(|_| !self.minimized) else {537
return;423
return;538
};424
};539
if !minimize_on_share_start(425
if !minimize_on_share_start(540
self.local_share_mode(),426
self.local_share_mode(),541
platform::window_rect(native),427
platform::window_rect(native),542
shared,428
shared,429
self.portal_picker(cx),543
) {430
) {544
return;431
return;545
}432
}546
self.minimized_for_share = true;433
self.minimized_for_share = true;547
if let Some(stage) = self.stage {434
self.main_window548
stage.update(cx, |_, window, _| window.minimize_window()).ok();435
.update(cx, |_, window, _| window.minimize_window())436
.ok();437
}438
439
fn sync_capture_exclusion(&mut self) {440
let Some(native) = self.main_native else {441
return;442
};443
let wanted = excluded_from_capture(Surface::Main, self.local_share_mode());444
if wanted == self.main_excluded {445
return;446
}447
self.main_excluded = wanted;448
if wanted {449
platform::exclude_from_capture(native);450
} else {451
platform::include_in_capture(native);549
}452
}550
}453
}551
454
@@ -777,9 +680,7 @@ impl CallWindows {777
.flatten();680
.flatten();778
if let Some(native) = native {681
if let Some(native) = native {779
platform::prepare_toast_window(native);682
platform::prepare_toast_window(native);780
if excluded_from_capture(role.surface()) {683
platform::exclude_from_capture(native);781
platform::exclude_from_capture(native);782
}783
}684
}784
if matches!(role, Role::Border(_)) {685
if matches!(role, Role::Border(_)) {785
handle686
handle@@ -0,0 +1,183 @@
1
use std::time::Instant;
2
3
use calling::VideoKey;
4
use gpui_kit::assets::IconName;
5
use gpui_kit::component::h_flex;
6
use gpui_kit::*;
7
8
use super::call_mini_window::{
9
chip, controls_row, self_view, speaker_layer, speaker_name_chip, speaker_speaking, tinted_chip,
10
ControlIds, WINDOW_RADIUS,
11
};
12
use super::call_view::status_line;
13
use super::toolbar_placement::TimelineBounds;
14
use super::widgets::icon;
15
use crate::app_state::AppState;
16
use crate::theme;
17
use app_ui_kit::layout::ROW_PADDING;
18
19
const MINI_WIDTH: f32 = 256.;
20
const MINI_HEIGHT: f32 = 144.;
21
const SHARE_MINI_WIDTH: f32 = 320.;
22
const SHARE_MINI_HEIGHT: f32 = 180.;
23
const MINI_RIGHT: f32 = 16.;
24
const MINI_BOTTOM: f32 = 40.;
25
26
pub struct CallMiniView {
27
app: Entity<AppState>,
28
timeline: TimelineBounds,
29
_app_subscription: Subscription,
30
_media_subscription: Option<Subscription>,
31
}
32
33
impl CallMiniView {
34
pub fn new(app: Entity<AppState>, timeline: TimelineBounds, cx: &mut Context<Self>) -> Self {
35
let app_subscription = cx.observe(&app, |_, _, cx| cx.notify());
36
let media_subscription = app
37
.read(cx)
38
.call_media
39
.clone()
40
.map(|media| cx.observe(&media, |_, _, cx| cx.notify()));
41
CallMiniView {
42
app,
43
timeline,
44
_app_subscription: app_subscription,
45
_media_subscription: media_subscription,
46
}
47
}
48
}
49
50
fn stop_sharing_pill(app: &Entity<AppState>) -> Stateful<Div> {
51
let stop_app = app.clone();
52
div()
53
.id("call-mini-stop-sharing")
54
.absolute()
55
.top(px(8.))
56
.right(px(8.))
57
.h(px(24.))
58
.px(px(10.))
59
.flex()
60
.items_center()
61
.gap(px(4.))
62
.rounded_full()
63
.bg(theme::red())
64
.text_color(theme::white())
65
.text_size(px(12.))
66
.font_weight(FontWeight::SEMIBOLD)
67
.cursor_pointer()
68
.hover(|button| button.opacity(0.85))
69
.child(icon(IconName::ScreenShare, 14., theme::white()))
70
.child("Stop")
71
.on_click(move |_, _, cx| {
72
cx.stop_propagation();
73
stop_app.update(cx, |state, cx| state.stop_call_share(cx));
74
})
75
}
76
77
impl Render for CallMiniView {
78
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
79
let state = self.app.read(cx);
80
let Some(call) = state.call.as_ref().filter(|call| !call.viewing) else {
81
return div().into_any_element();
82
};
83
let model = &call.model;
84
let now = Instant::now();
85
let (status, _) = status_line(model, now);
86
let viewport = window.viewport_size();
87
let (right, bottom) =
88
self.timeline
89
.get()
90
.map_or((px(MINI_RIGHT), px(MINI_BOTTOM)), |timeline| {
91
(
92
viewport.width - timeline.right() + px(ROW_PADDING),
93
viewport.height - timeline.bottom() + px(MINI_RIGHT),
94
)
95
});
96
let sharing = model.local_share.is_some();
97
let share_image = sharing
98
.then(|| {
99
state
100
.call
101
.as_ref()
102
.and_then(|call| call.pictures.live(&VideoKey::LocalScreen, now))
103
})
104
.flatten();
105
let open_app = self.app.clone();
106
let back_app = self.app.clone();
107
let speaker_name = speaker_name_chip(state, model, now);
108
let border = if sharing {
109
theme::red()
110
} else if speaker_speaking(model) {
111
theme::green()
112
} else {
113
theme::border_strong()
114
};
115
let top_left = if sharing {
116
tinted_chip("Sharing".to_owned(), theme::red())
117
} else {
118
chip(status)
119
};
120
div()
121
.id("call-mini")
122
.group("call-mini")
123
.occlude()
124
.absolute()
125
.right(right)
126
.bottom(bottom)
127
.w(px(if sharing {
128
SHARE_MINI_WIDTH
129
} else {
130
MINI_WIDTH
131
}))
132
.h(px(if sharing {
133
SHARE_MINI_HEIGHT
134
} else {
135
MINI_HEIGHT
136
}))
137
.overflow_hidden()
138
.rounded(px(WINDOW_RADIUS))
139
.bg(theme::surface())
140
.border_2()
141
.border_color(border)
142
.text_color(theme::text())
143
.shadow(theme::flyout_shadow())
144
.cursor_pointer()
145
.on_click(move |_, _, cx| {
146
open_app.update(cx, |state, cx| state.show_call(true, cx));
147
})
148
.child(match share_image {
149
Some(image) => div()
150
.size_full()
151
.bg(hsla(0., 0., 0.04, 1.))
152
.child(
153
img(ImageSource::Render(image))
154
.size_full()
155
.object_fit(ObjectFit::Contain),
156
)
157
.into_any_element(),
158
None => speaker_layer(state, model, now),
159
})
160
.child(div().absolute().top(px(8.)).left(px(8.)).child(top_left))
161
.children(
162
speaker_name
163
.map(|name| h_flex().absolute().bottom(px(6.)).left(px(8.)).child(name)),
164
)
165
.children(if sharing {
166
Some(stop_sharing_pill(&self.app).into_any_element())
167
} else {
168
self_view(state, model, now)
169
})
170
.child(controls_row(
171
&self.app,
172
model,
173
ControlIds {
174
mute: "call-mini-mute",
175
back: "call-mini-back",
176
leave: "call-mini-leave",
177
},
178
"call-mini",
179
move |cx| back_app.update(cx, |state, cx| state.show_call(true, cx)),
180
))
181
.into_any_element()
182
}
183
}
@@ -0,0 +1,183 @@1
use std::time::Instant;2
3
use calling::VideoKey;4
use gpui_kit::assets::IconName;5
use gpui_kit::component::h_flex;6
use gpui_kit::*;7
8
use super::call_mini_window::{9
chip, controls_row, self_view, speaker_layer, speaker_name_chip, speaker_speaking, tinted_chip,10
ControlIds, WINDOW_RADIUS,11
};12
use super::call_view::status_line;13
use super::toolbar_placement::TimelineBounds;14
use super::widgets::icon;15
use crate::app_state::AppState;16
use crate::theme;17
use app_ui_kit::layout::ROW_PADDING;18
19
const MINI_WIDTH: f32 = 256.;20
const MINI_HEIGHT: f32 = 144.;21
const SHARE_MINI_WIDTH: f32 = 320.;22
const SHARE_MINI_HEIGHT: f32 = 180.;23
const MINI_RIGHT: f32 = 16.;24
const MINI_BOTTOM: f32 = 40.;25
26
pub struct CallMiniView {27
app: Entity<AppState>,28
timeline: TimelineBounds,29
_app_subscription: Subscription,30
_media_subscription: Option<Subscription>,31
}32
33
impl CallMiniView {34
pub fn new(app: Entity<AppState>, timeline: TimelineBounds, cx: &mut Context<Self>) -> Self {35
let app_subscription = cx.observe(&app, |_, _, cx| cx.notify());36
let media_subscription = app37
.read(cx)38
.call_media39
.clone()40
.map(|media| cx.observe(&media, |_, _, cx| cx.notify()));41
CallMiniView {42
app,43
timeline,44
_app_subscription: app_subscription,45
_media_subscription: media_subscription,46
}47
}48
}49
50
fn stop_sharing_pill(app: &Entity<AppState>) -> Stateful<Div> {51
let stop_app = app.clone();52
div()53
.id("call-mini-stop-sharing")54
.absolute()55
.top(px(8.))56
.right(px(8.))57
.h(px(24.))58
.px(px(10.))59
.flex()60
.items_center()61
.gap(px(4.))62
.rounded_full()63
.bg(theme::red())64
.text_color(theme::white())65
.text_size(px(12.))66
.font_weight(FontWeight::SEMIBOLD)67
.cursor_pointer()68
.hover(|button| button.opacity(0.85))69
.child(icon(IconName::ScreenShare, 14., theme::white()))70
.child("Stop")71
.on_click(move |_, _, cx| {72
cx.stop_propagation();73
stop_app.update(cx, |state, cx| state.stop_call_share(cx));74
})75
}76
77
impl Render for CallMiniView {78
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {79
let state = self.app.read(cx);80
let Some(call) = state.call.as_ref().filter(|call| !call.viewing) else {81
return div().into_any_element();82
};83
let model = &call.model;84
let now = Instant::now();85
let (status, _) = status_line(model, now);86
let viewport = window.viewport_size();87
let (right, bottom) =88
self.timeline89
.get()90
.map_or((px(MINI_RIGHT), px(MINI_BOTTOM)), |timeline| {91
(92
viewport.width - timeline.right() + px(ROW_PADDING),93
viewport.height - timeline.bottom() + px(MINI_RIGHT),94
)95
});96
let sharing = model.local_share.is_some();97
let share_image = sharing98
.then(|| {99
state100
.call101
.as_ref()102
.and_then(|call| call.pictures.live(&VideoKey::LocalScreen, now))103
})104
.flatten();105
let open_app = self.app.clone();106
let back_app = self.app.clone();107
let speaker_name = speaker_name_chip(state, model, now);108
let border = if sharing {109
theme::red()110
} else if speaker_speaking(model) {111
theme::green()112
} else {113
theme::border_strong()114
};115
let top_left = if sharing {116
tinted_chip("Sharing".to_owned(), theme::red())117
} else {118
chip(status)119
};120
div()121
.id("call-mini")122
.group("call-mini")123
.occlude()124
.absolute()125
.right(right)126
.bottom(bottom)127
.w(px(if sharing {128
SHARE_MINI_WIDTH129
} else {130
MINI_WIDTH131
}))132
.h(px(if sharing {133
SHARE_MINI_HEIGHT134
} else {135
MINI_HEIGHT136
}))137
.overflow_hidden()138
.rounded(px(WINDOW_RADIUS))139
.bg(theme::surface())140
.border_2()141
.border_color(border)142
.text_color(theme::text())143
.shadow(theme::flyout_shadow())144
.cursor_pointer()145
.on_click(move |_, _, cx| {146
open_app.update(cx, |state, cx| state.show_call(true, cx));147
})148
.child(match share_image {149
Some(image) => div()150
.size_full()151
.bg(hsla(0., 0., 0.04, 1.))152
.child(153
img(ImageSource::Render(image))154
.size_full()155
.object_fit(ObjectFit::Contain),156
)157
.into_any_element(),158
None => speaker_layer(state, model, now),159
})160
.child(div().absolute().top(px(8.)).left(px(8.)).child(top_left))161
.children(162
speaker_name163
.map(|name| h_flex().absolute().bottom(px(6.)).left(px(8.)).child(name)),164
)165
.children(if sharing {166
Some(stop_sharing_pill(&self.app).into_any_element())167
} else {168
self_view(state, model, now)169
})170
.child(controls_row(171
&self.app,172
model,173
ControlIds {174
mute: "call-mini-mute",175
back: "call-mini-back",176
leave: "call-mini-leave",177
},178
"call-mini",179
move |cx| back_app.update(cx, |state, cx| state.show_call(true, cx)),180
))181
.into_any_element()182
}183
}@@ -1,7 +1,7 @@
1
1
use std::sync::Arc;
2
2
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
3
3
4
use calling::{DeviceEntry, MicSettings, NoiseSuppression, Reaction, VideoKey};
4
use calling::{DeviceEntry, MicSettings, NoiseSuppression, Reaction, ShareKind, VideoKey};
5
5
use gpui_kit::assets::IconName;
6
6
use gpui_kit::component::{
7
7
button::{Button, ButtonVariants as _},
@@ -16,32 +16,32 @@ use gpui_kit::prelude::FluentBuilder as _;
16
16
use gpui_kit::*;
17
17
18
18
use super::avatar::person_avatar;
19
use super::call_control_fold::{Foldable, FoldedControls, fixed_controls_width, folded_for_width, in_more_menu};
20
use super::call_toolbar::{
21
GROUP_GAP, LEAVE_HEIGHT, group_divider, SPLIT_CHEVRON_WIDTH, TOOL_GAP, tool_face, tool_trigger, split_chevron,
19
use super::call_control_fold::{
20
fixed_controls_width, folded_for_width, Foldable, FoldedControls, CONTROLS_PADDING, CONTROL_GAP,
22
21
};
23
22
use super::call_extras::{
24
CameraMenu, consent_overlay, consult_banner, hold_panel, recording_chip, return_button,
25
room_chip, whiteboard_stage,
23
consent_overlay, consult_banner, hold_panel, recording_chip, return_button, room_chip,
24
whiteboard_stage, CameraMenu,
26
25
};
27
26
use super::call_health::{health_banner, health_indicator};
28
27
use super::call_layouts::stage_region;
29
use crate::call::measured_stage;
30
28
use super::call_organizer::{
31
camera_menu_button, captions_hint_chip, captions_overlay, lobby_banner,
29
camera_menu_button, captions_hint_chip, captions_overlay, chevron_button, lobby_banner,
32
30
more_button, pin_chip, spotlight_chip, with_tile_menu,
33
31
};
34
32
use super::call_people::{lock_banner, lock_chip, options_dialog, people_button, people_panel};
35
use super::call_stage::{POP_OUT_TOOLTIP, StageMode, popped_placeholder, render_stage};
33
use super::call_stage::{popped_placeholder, render_stage, StageMode, WAITING_TEXT};
36
34
use super::call_view_menu::view_button;
37
use app_ui_kit::layout::ISLAND_GAP;
38
use super::widgets::{Corner, corner_badge, count_badge, icon};
35
use super::widgets::{corner_badge, count_badge, icon, Corner};
39
36
use crate::app_state::AppState;
40
use crate::call::REACTION_SHOWN;
37
use crate::call::measured_stage;
38
use crate::call::model::ShareMenuEntry;
41
39
use crate::call::TileSize;
40
use crate::call::REACTION_SHOWN;
42
41
use crate::call::{ActiveCall, CallKind, CallModel, Tile, TileState};
43
42
use crate::rows::reaction_glyph as chat_reaction_glyph;
44
43
use crate::theme;
44
use app_ui_kit::layout::ISLAND_GAP;
45
45
46
46
const HEADER_HEIGHT: f32 = 60.;
47
47
const RING_WIDTH: f32 = 3.;
@@ -64,7 +64,6 @@ pub const NO_CAMERA_HINT: &str = "No camera found";
64
64
pub const NO_SHARE_HINT: &str = "Sharing starts once the call is connected";
65
65
pub const NO_WINDOWS_HINT: &str = "No windows found";
66
66
pub(super) const BANNER_HEIGHT: f32 = 40.;
67
const MAX_WINDOW_ITEMS: usize = 12;
68
67
pub const SHARE_THUMBNAIL_TAG: &str = "call/share-menu/thumbnail";
69
68
const SCREEN_THUMBNAIL: (f32, f32) = (128., 72.);
70
69
const WINDOW_THUMBNAIL: (f32, f32) = (96., 54.);
@@ -73,8 +72,7 @@ const THUMBNAIL_ICON: f32 = 22.;
73
72
pub const LOBBY_TEXT: &str = "Waiting in the lobby...";
74
73
pub(super) const CHAT_PANEL_WIDTH: f32 = 320.;
75
74
pub(super) const OVERLAY_BELOW: f32 = 720.;
76
const HEADER_END_PADDING: f32 = 8.;
77
const LEAVE_RADIUS: f32 = 6.;
75
const CONTROLS_HEIGHT: f32 = 2. * 16. + CONTROL_SIZE;
78
76
const CHAT_HEADER_HEIGHT: f32 = 48.;
79
77
const REACTION_RISE: f32 = 24.;
80
78
const REACTION_FADE_FROM: f32 = 0.75;
@@ -90,8 +88,13 @@ const PUSH_TO_TALK_TOP: f32 = 12.;
90
88
91
89
pub fn reaction_glyph(reaction: &Reaction) -> String {
92
90
match reaction {
91
Reaction::Like => "\u{1F44D}".to_owned(),
92
// Keep VS16 so the heart stays emoji-style, not a text outline.
93
Reaction::Heart => "\u{2764}\u{FE0F}".to_owned(),
93
94
Reaction::Applause => "\u{1F44F}".to_owned(),
94
other => chat_reaction_glyph(other.name()),
95
Reaction::Laugh => "\u{1F606}".to_owned(),
96
Reaction::Surprised => "\u{1F62E}".to_owned(),
97
Reaction::Other(name) => chat_reaction_glyph(name),
95
98
}
96
99
}
97
100
@@ -143,6 +146,7 @@ fn reaction_chip(reaction: Reaction, serial: u64) -> AnyElement {
143
146
.rounded_full()
144
147
.bg(theme::popup())
145
148
.text_size(px(if emoji { 20. } else { 13. }))
149
.when(emoji, |chip| chip.font_family(theme::EMOJI_FONT_FAMILY))
146
150
.child(glyph)
147
151
.with_animation(
148
152
("call-reaction", serial as usize),
@@ -251,9 +255,23 @@ struct NamePlate {
251
255
252
256
fn name_plate_metrics(size: TileSize) -> NamePlate {
253
257
if size.height < COMPACT_PLATE_BELOW {
254
NamePlate { inset: 4., padding_x: 6., padding_y: 2., radius: 4., text_size: 11., max_width_share: 0.6 }
258
NamePlate {
259
inset: 4.,
260
padding_x: 6.,
261
padding_y: 2.,
262
radius: 4.,
263
text_size: 11.,
264
max_width_share: 0.6,
265
}
255
266
} else {
256
NamePlate { inset: 8., padding_x: 8., padding_y: 4., radius: 6., text_size: 12., max_width_share: 1. }
267
NamePlate {
268
inset: 8.,
269
padding_x: 8.,
270
padding_y: 4.,
271
radius: 6.,
272
text_size: 12.,
273
max_width_share: 1.,
274
}
257
275
}
258
276
}
259
277
@@ -263,7 +281,9 @@ fn name_plate(size: TileSize, name: &str) -> Div {
263
281
.absolute()
264
282
.left(px(plate.inset))
265
283
.bottom(px(plate.inset))
266
.max_w(px(((size.width - 3. * plate.inset) * plate.max_width_share).max(0.)))
284
.max_w(px(((size.width - 3. * plate.inset)
285
* plate.max_width_share)
286
.max(0.)))
267
287
.truncate()
268
288
.px(px(plate.padding_x))
269
289
.py(px(plate.padding_y))
@@ -385,19 +405,7 @@ pub fn mute_button(
385
405
} else {
386
406
(IconName::Mic, theme::surface_raised(), theme::text())
387
407
};
388
mic_action(round_control(id, glyph, background, foreground).size(px(size)), app, model)
389
}
390
391
fn toolbar_mic(app: &Entity<AppState>, model: &CallModel) -> Stateful<Div> {
392
let glyph = if model.muted {
393
IconName::MicOff
394
} else {
395
IconName::Mic
396
};
397
mic_action(tool_face("call-mute", glyph, "Mic", false), app, model)
398
}
399
400
fn mic_action(button: Stateful<Div>, app: &Entity<AppState>, model: &CallModel) -> Stateful<Div> {
408
let button = round_control(id, glyph, background, foreground).size(px(size));
401
409
if !model.can_unmute() {
402
410
let hint = if model.audio_off {
403
411
AUDIO_OFF_HINT
@@ -430,8 +438,8 @@ pub fn leave_button(
430
438
let app = app.clone();
431
439
h_flex()
432
440
.id(id)
433
.h(px(if compact { 28. } else { LEAVE_HEIGHT }))
434
.px(px(if compact { 10. } else { 14. }))
441
.h(px(if compact { 28. } else { CONTROL_SIZE }))
442
.px(px(if compact { 10. } else { 20. }))
435
443
.gap(px(8.))
436
444
.flex_none()
437
445
.items_center()
@@ -439,13 +447,13 @@ pub fn leave_button(
439
447
.rounded_full()
440
448
.bg(theme::red())
441
449
.text_color(theme::white())
442
.text_size(px(if compact { 12. } else { 13. }))
450
.text_size(px(if compact { 12. } else { 14. }))
443
451
.font_weight(FontWeight::SEMIBOLD)
444
452
.cursor_pointer()
445
453
.hover(|button| button.opacity(0.85))
446
454
.child(icon(
447
455
IconName::PhoneOff,
448
if compact { 14. } else { 16. },
456
if compact { 14. } else { 18. },
449
457
theme::white(),
450
458
))
451
459
.child(label)
@@ -455,7 +463,11 @@ pub fn leave_button(
455
463
})
456
464
}
457
465
458
fn share_stage_element(app: &Entity<AppState>, state: &AppState, call: &ActiveCall) -> Option<AnyElement> {
466
fn share_stage_element(
467
app: &Entity<AppState>,
468
state: &AppState,
469
call: &ActiveCall,
470
) -> Option<AnyElement> {
459
471
if call.share_stage.popped && call.model.screen_sharer.is_some() {
460
472
return Some(popped_placeholder(app));
461
473
}
@@ -468,19 +480,7 @@ pub(super) fn camera_button(app: &Entity<AppState>, model: &CallModel) -> Statef
468
480
} else {
469
481
(IconName::VideoOff, theme::surface_raised(), theme::text())
470
482
};
471
camera_action(round_control("call-camera", glyph, background, foreground), app, model)
472
}
473
474
fn toolbar_camera(app: &Entity<AppState>, model: &CallModel) -> Stateful<Div> {
475
let glyph = if model.camera_on {
476
IconName::Video
477
} else {
478
IconName::VideoOff
479
};
480
camera_action(tool_face("call-camera", glyph, "Camera", false), app, model)
481
}
482
483
fn camera_action(button: Stateful<Div>, app: &Entity<AppState>, model: &CallModel) -> Stateful<Div> {
483
let button = round_control("call-camera", glyph, background, foreground);
484
484
if !model.can_use_camera() {
485
485
return button
486
486
.opacity(DISABLED_OPACITY)
@@ -550,7 +550,9 @@ fn standout_switch_item(app: &Entity<AppState>, standout: bool, camera_on: bool)
550
550
})
551
551
})
552
552
.disabled(!camera_on)
553
.on_click(move |_, _, cx| app.update(cx, |state, cx| state.set_call_share_standout(!standout, cx)))
553
.on_click(move |_, _, cx| {
554
app.update(cx, |state, cx| state.set_call_share_standout(!standout, cx))
555
})
554
556
}
555
557
556
558
fn music_mode_item(app: &Entity<AppState>, mic: MicSettings) -> PopupMenuItem {
@@ -624,46 +626,104 @@ fn share_items(
624
626
model: &CallModel,
625
627
options: ShareOptions,
626
628
) -> PopupMenu {
627
let screens = model.screens();
628
let single_screen = screens.len() == 1;
629
<<<<<<< ours
630
let single_screen = model.screens().len() == 1;
631
let mut screen_index = 0usize;
632
let mut separated = false;
633
let mut popup = popup.min_w(px(SHARE_MENU_WIDTH));
634
for entry in model.share_menu_entries() {
635
popup = match entry {
636
ShareMenuEntry::Sound => popup.item(sound_switch_item(app, options.sound)),
637
ShareMenuEntry::Motion => popup.item(motion_switch_item(app, options.motion)),
638
ShareMenuEntry::Standout => {
639
popup.item(standout_switch_item(app, options.standout, model.camera_on))
640
}
641
ShareMenuEntry::Portal(kind) => {
642
if !separated {
643
popup = popup.separator();
644
separated = true;
645
}
646
let label = match kind {
647
ShareKind::Screen => "Share entire screen",
648
ShareKind::Window => "Share a window",
649
};
650
let app = app.clone();
651
popup.item(PopupMenuItem::new(label).on_click(move |_, _, cx| {
652
app.update(cx, |state, cx| state.start_portal_share(kind, cx))
653
}))
654
}
655
ShareMenuEntry::Source(source) => {
656
if !separated {
657
popup = popup.separator();
658
separated = true;
659
}
660
let (label, thumbnail, icon, size) = if source.kind == ShareKind::Screen {
661
screen_index += 1;
662
let label = if single_screen {
663
"Share entire screen".to_owned()
664
} else {
665
format!("Share screen {screen_index}")
666
};
667
(
668
label,
669
model.share_thumbnail(&source),
670
IconName::Monitor,
671
SCREEN_THUMBNAIL,
672
)
673
} else {
674
(
675
source.label(),
676
model.share_thumbnail(&source),
677
IconName::AppWindow,
678
WINDOW_THUMBNAIL,
679
)
680
};
681
let app = app.clone();
682
popup.item(share_source_item(label, thumbnail, icon, size).on_click(
683
move |_, _, cx| {
684
app.update(cx, |state, cx| state.start_call_share(source.clone(), cx))
685
},
686
))
687
}
688
ShareMenuEntry::WindowHeader => popup
689
.separator()
690
.item(PopupMenuItem::label("Share a window...")),
691
ShareMenuEntry::NoWindows => {
692
popup.item(PopupMenuItem::new(NO_WINDOWS_HINT).disabled(true))
693
}
694
=======
629
695
let mut popup = popup
630
696
.min_w(px(SHARE_MENU_WIDTH))
631
697
.item(sound_switch_item(app, options.sound))
632
698
.item(motion_switch_item(app, options.motion))
633
699
.item(standout_switch_item(app, options.standout, model.camera_on))
634
700
.separator();
701
if model.uses_portal_picker() {
702
let screen_app = app.clone();
703
let window_app = app.clone();
704
return popup
705
.item(
706
PopupMenuItem::new("Share entire screen").on_click(move |_, _, cx| {
707
screen_app.update(cx, |state, cx| {
708
state.start_portal_share(ShareKind::Screen, cx)
709
})
710
}),
711
)
712
.item(PopupMenuItem::new("Share a window").on_click(move |_, _, cx| {
713
window_app.update(cx, |state, cx| {
714
state.start_portal_share(ShareKind::Window, cx)
715
})
716
}));
717
}
718
let screens = model.screens();
719
let single_screen = screens.len() == 1;
635
720
for (index, source) in screens.into_iter().enumerate() {
636
721
let label = if single_screen {
637
722
"Share entire screen".to_owned()
638
723
} else {
639
724
format!("Share screen {}", index + 1)
725
>>>>>>> theirs
640
726
};
641
let thumbnail = model.share_thumbnail(source);
642
let source = source.clone();
643
let app = app.clone();
644
popup = popup.item(
645
share_source_item(label, thumbnail, IconName::Monitor, SCREEN_THUMBNAIL).on_click(
646
move |_, _, cx| app.update(cx, |state, cx| state.start_call_share(source.clone(), cx)),
647
),
648
);
649
}
650
popup = popup
651
.separator()
652
.item(PopupMenuItem::label("Share a window..."));
653
let windows = model.windows();
654
if windows.is_empty() {
655
return popup.item(PopupMenuItem::new(NO_WINDOWS_HINT).disabled(true));
656
}
657
for source in windows.into_iter().take(MAX_WINDOW_ITEMS) {
658
let label = source.label();
659
let thumbnail = model.share_thumbnail(source);
660
let source = source.clone();
661
let app = app.clone();
662
popup = popup.item(
663
share_source_item(label, thumbnail, IconName::AppWindow, WINDOW_THUMBNAIL).on_click(
664
move |_, _, cx| app.update(cx, |state, cx| state.start_call_share(source.clone(), cx)),
665
),
666
);
667
727
}
668
728
popup
669
729
}
@@ -716,7 +776,12 @@ fn share_button(
716
776
) -> AnyElement {
717
777
if model.local_share.is_some() {
718
778
let app = app.clone();
719
return tool_face("call-share-stop", IconName::ScreenShareOff, "Stop", true)
779
return round_control(
780
"call-share-stop",
781
IconName::ScreenShareOff,
782
theme::accent(),
783
theme::on_accent(),
784
)
720
785
.tooltip(|window, cx| Tooltip::new("Stop sharing").build(window, cx))
721
786
.on_click(move |_, _, cx| {
722
787
cx.stop_propagation();
@@ -724,7 +789,12 @@ fn share_button(
724
789
})
725
790
.into_any_element();
726
791
}
727
let face = tool_face("call-share-face", IconName::ScreenShare, "Share", false);
792
let face = round_control(
793
"call-share-face",
794
IconName::ScreenShare,
795
theme::surface_raised(),
796
theme::text(),
797
);
728
798
if !model.can_share() {
729
799
return face
730
800
.opacity(DISABLED_OPACITY)
@@ -735,8 +805,13 @@ fn share_button(
735
805
let app = app.clone();
736
806
let open_app = app.clone();
737
807
let model = model.clone();
738
tool_trigger("call-share", face)
739
.dropdown_menu_with_anchor(Anchor::TopRight, move |popup, _, _| {
808
Button::new("call-share")
809
.ghost()
810
.p_0()
811
.size(px(CONTROL_SIZE))
812
.rounded_full()
813
.child(face)
814
.dropdown_menu_with_anchor(Anchor::BottomLeft, move |popup, _, _| {
740
815
share_items(popup, &app, &model, options)
741
816
})
742
817
.open(menu_open)
@@ -809,7 +884,12 @@ fn sharing_banner(app: &Entity<AppState>, model: &CallModel, sound: bool) -> Opt
809
884
810
885
fn chat_button(app: &Entity<AppState>, open: bool, unread: u32) -> Stateful<Div> {
811
886
let app = app.clone();
812
tool_face("call-chat", IconName::MessageCircle, "Chat", open)
887
let (background, foreground) = if open {
888
(theme::accent(), theme::on_accent())
889
} else {
890
(theme::surface_raised(), theme::text())
891
};
892
round_control("call-chat", IconName::MessageCircle, background, foreground)
813
893
.relative()
814
894
.tooltip(move |window, cx| {
815
895
Tooltip::new(if open {
@@ -825,9 +905,41 @@ fn chat_button(app: &Entity<AppState>, open: bool, unread: u32) -> Stateful<Div>
825
905
.on_click(move |_, _, cx| app.update(cx, |state, cx| state.toggle_call_chat(cx)))
826
906
}
827
907
828
fn reactions_button(app: &Entity<AppState>, model: &CallModel) -> AnyElement {
908
fn hand_button(app: &Entity<AppState>, model: &CallModel) -> Stateful<Div> {
829
909
let raised = model.own_hand.is_some();
830
let face = tool_face("call-reactions-face", IconName::FaceSlightlySmiling, "React", raised);
910
let background = if raised {
911
theme::accent()
912
} else {
913
theme::surface_raised()
914
};
915
let foreground = if raised {
916
theme::on_accent()
917
} else {
918
theme::text()
919
};
920
let button = control_shell("call-hand", background).child(icon(
921
IconName::Hand,
922
CONTROL_ICON,
923
foreground,
924
));
925
let tooltip = if raised { "Lower hand" } else { "Raise hand" };
926
let button = button.tooltip(move |window, cx| Tooltip::new(tooltip).build(window, cx));
927
if !model.can_react() {
928
return button.opacity(DISABLED_OPACITY).cursor_default();
929
}
930
let app = app.clone();
931
button.on_click(move |_, _, cx| {
932
cx.stop_propagation();
933
app.update(cx, |state, cx| state.toggle_call_hand(cx));
934
})
935
}
936
937
fn reactions_button(app: &Entity<AppState>, model: &CallModel) -> AnyElement {
938
let face = control_shell("call-reactions-face", theme::surface_raised()).child(icon(
939
IconName::FaceSlightlySmiling,
940
CONTROL_ICON,
941
theme::text(),
942
));
831
943
if !model.can_react() {
832
944
return face
833
945
.opacity(DISABLED_OPACITY)
@@ -836,14 +948,19 @@ fn reactions_button(app: &Entity<AppState>, model: &CallModel) -> AnyElement {
836
948
}
837
949
let app = app.clone();
838
950
Popover::new("call-reactions-popover")
839
.anchor(Anchor::TopRight)
840
.offset(px(6.))
841
.trigger(tool_trigger("call-reactions", face))
951
.anchor(Anchor::BottomLeft)
952
.offset(px(10.))
953
.trigger(
954
Button::new("call-reactions")
955
.ghost()
956
.p_0()
957
.size(px(CONTROL_SIZE))
958
.rounded_full()
959
.child(face),
960
)
842
961
.content(move |_, _, cx| {
843
962
let popover = cx.entity().downgrade();
844
let hand_app = app.clone();
845
let hand_popover = popover.clone();
846
let reactions = h_flex()
963
h_flex()
847
964
.id("call-reactions-row")
848
965
.gap(px(4.))
849
966
.children(Reaction::ALL.into_iter().map(|reaction| {
@@ -857,68 +974,23 @@ fn reactions_button(app: &Entity<AppState>, model: &CallModel) -> AnyElement {
857
974
.justify_center()
858
975
.rounded(px(8.))
859
976
.text_size(px(24.))
977
.font_family(theme::EMOJI_FONT_FAMILY)
860
978
.cursor_pointer()
861
979
.hover(|cell| cell.bg(theme::border_strong()))
862
980
.child(reaction_glyph(&reaction))
863
981
.on_click(move |_, window, cx| {
864
app.update(cx, |state, cx| state.send_call_reaction(reaction.clone(), cx));
982
app.update(cx, |state, cx| {
983
state.send_call_reaction(reaction.clone(), cx)
984
});
865
985
popover
866
986
.update(cx, |state, cx| state.dismiss(window, cx))
867
987
.ok();
868
988
})
869
}));
870
v_flex()
871
.gap(px(6.))
872
.child(reactions)
873
.child(
874
h_flex()
875
.id("call-hand")
876
.h(px(36.))
877
.px(px(10.))
878
.gap(px(8.))
879
.items_center()
880
.rounded(px(8.))
881
.cursor_pointer()
882
.when(raised, |row| row.bg(theme::accent_soft()))
883
.hover(|row| row.bg(theme::border_strong()))
884
.child(icon(IconName::Hand, 18., if raised { theme::accent_text() } else { theme::text() }))
885
.child(div().text_size(px(13.)).child(if raised { "Lower hand" } else { "Raise hand" }))
886
.on_click(move |_, window, cx| {
887
hand_app.update(cx, |state, cx| state.toggle_call_hand(cx));
888
hand_popover
889
.update(cx, |state, cx| state.dismiss(window, cx))
890
.ok();
891
}),
892
)
989
}))
893
990
})
894
991
.into_any_element()
895
992
}
896
993
897
fn pop_out_tool(app: &Entity<AppState>) -> Stateful<Div> {
898
let app = app.clone();
899
tool_face("call-pop-out", IconName::ExternalLink, POP_OUT_TOOLTIP, false)
900
.on_click(move |_, _, cx| app.update(cx, |state, cx| state.pop_out_stage(cx)))
901
}
902
903
fn shows_pop_out(call: &ActiveCall) -> bool {
904
call.model.screen_sharer.is_some() && !call.share_stage.popped
905
}
906
907
fn leave_group(app: &Entity<AppState>, model: &CallModel) -> AnyElement {
908
let leave = leave_button(app, model, "call-leave", false)
909
.rounded(px(LEAVE_RADIUS))
910
.debug_selector(|| "shell/islands/main/call-header/leave".into());
911
if !has_leave_menu(model) {
912
return leave.into_any_element();
913
}
914
h_flex()
915
.flex_none()
916
.gap(px(1.))
917
.child(leave.rounded_r(px(0.)))
918
.child(leave_menu(app, model))
919
.into_any_element()
920
}
921
922
994
fn has_leave_menu(model: &CallModel) -> bool {
923
995
model.kind == CallKind::Meeting
924
996
&& (model.can_end_meeting || (model.can_lower_hands() && model.any_hand_raised()))
@@ -932,23 +1004,15 @@ fn leave_menu(app: &Entity<AppState>, model: &CallModel) -> impl IntoElement {
932
1004
Button::new("call-leave-menu")
933
1005
.ghost()
934
1006
.p_0()
935
.w(px(SPLIT_CHEVRON_WIDTH + 4.))
936
.h(px(LEAVE_HEIGHT))
937
.rounded_r(px(LEAVE_RADIUS))
938
.child(
939
div()
940
.id("call-leave-menu-face")
941
.size_full()
942
.flex()
943
.items_center()
944
.justify_center()
945
.rounded_r(px(LEAVE_RADIUS))
946
.bg(theme::red())
947
.cursor_pointer()
948
.hover(|face| face.opacity(0.85))
949
.child(icon(IconName::ChevronDown, 12., theme::white())),
950
)
951
.dropdown_menu_with_anchor(Anchor::TopRight, move |popup, _, _| {
1007
.size(px(CONTROL_SIZE))
1008
.rounded_full()
1009
.child(round_control(
1010
"call-leave-menu-face",
1011
IconName::ChevronUp,
1012
theme::surface_raised(),
1013
theme::text(),
1014
))
1015
.dropdown_menu_with_anchor(Anchor::BottomRight, move |popup, _, _| {
952
1016
let end_app = end_app.clone();
953
1017
let lower_app = lower_app.clone();
954
1018
let popup = popup.min_w(px(MENU_WIDTH));
@@ -1057,11 +1121,15 @@ fn devices_menu(
1057
1121
popup
1058
1122
}
1059
1123
1060
fn mic_menu_button(app: &Entity<AppState>, model: &CallModel, mic: MicSettings) -> impl IntoElement {
1124
fn mic_menu_button(
1125
app: &Entity<AppState>,
1126
model: &CallModel,
1127
mic: MicSettings,
1128
) -> impl IntoElement {
1061
1129
let app = app.clone();
1062
1130
let model = model.clone();
1063
split_chevron("call-mic-menu", "call-mic-menu-face")
1064
.dropdown_menu_with_anchor(Anchor::TopRight, move |popup, _, _| {
1131
chevron_button("call-mic-menu", "call-mic-menu-face")
1132
.dropdown_menu_with_anchor(Anchor::BottomLeft, move |popup, _, _| {
1065
1133
devices_menu(popup, &app, &model, mic)
1066
1134
})
1067
1135
}
@@ -1180,7 +1248,9 @@ pub(super) fn plain_own_tile(
1180
1248
let extras = TileExtras {
1181
1249
hand: model.own_hand.map(|rank| model.hand_position(rank)),
1182
1250
own: true,
1183
reaction: model.own_chip(now).map(|chip| (chip.reaction.clone(), chip.serial)),
1251
reaction: model
1252
.own_chip(now)
1253
.map(|chip| (chip.reaction.clone(), chip.serial)),
1184
1254
spotlight: model.own_spotlight.is_some(),
1185
1255
pinned: model.is_pinned(own_mri),
1186
1256
fitted: false,
@@ -1235,9 +1305,9 @@ fn folded_controls(state: &AppState, call: &ActiveCall, fullscreen: bool) -> Fol
1235
1305
if !has_more {
1236
1306
return FoldedControls::default();
1237
1307
}
1238
let mut present = Vec::new();
1308
let mut present = vec![Foldable::View];
1239
1309
if model.has_reaction_controls() {
1240
present.push(Foldable::Reactions);
1310
present.extend([Foldable::Reactions, Foldable::RaiseHand]);
1241
1311
}
1242
1312
if model.kind != CallKind::Test {
1243
1313
present.push(Foldable::People);
@@ -1245,14 +1315,9 @@ fn folded_controls(state: &AppState, call: &ActiveCall, fullscreen: bool) -> Fol
1245
1315
if call.chat_thread().is_some() {
1246
1316
present.push(Foldable::Chat);
1247
1317
}
1248
let fixed = fixed_controls_width(
1249
model.can_use_camera(),
1250
has_more,
1251
has_leave_menu(model),
1252
shows_pop_out(call),
1253
);
1318
let fixed = fixed_controls_width(model.can_use_camera(), has_more, has_leave_menu(model));
1254
1319
FoldedControls {
1255
items: in_more_menu(folded_for_width(measured_stage(call).0, fixed, &present)),
1320
items: folded_for_width(measured_stage(call).0, fixed, &present),
1256
1321
fullscreen,
1257
1322
people_open: call.people_open,
1258
1323
chat_open: call.chat_open,
@@ -1275,14 +1340,7 @@ pub fn render_call_view(
1275
1340
.w_full()
1276
1341
.h(px(HEADER_HEIGHT))
1277
1342
.flex_none()
1278
.pl(px(20.))
1279
.pr(px(HEADER_END_PADDING))
1280
.gap(px(12.))
1281
.items_center();
1282
let title_group = h_flex()
1283
.flex_1()
1284
.flex_basis(px(0.))
1285
.min_w_0()
1343
.px(px(20.))
1286
1344
.gap(px(12.))
1287
1345
.items_center()
1288
1346
.child(icon(IconName::Phone, 18., theme::accent_text()))
@@ -1304,59 +1362,40 @@ pub fn render_call_view(
1304
1362
.children(health_indicator(model))
1305
1363
.children(recording_chip(model))
1306
1364
.children(lock_chip(model))
1307
.children(room_chip(model));
1308
let end_group = h_flex()
1309
.flex_1()
1310
.flex_basis(px(0.))
1311
.min_w_0()
1312
.justify_end()
1313
.gap(px(GROUP_GAP))
1314
.items_center()
1315
.children(return_button(app, model))
1316
.child(leave_group(app, model));
1365
.children(room_chip(model))
1366
.child(div().flex_1())
1367
.children(return_button(app, model));
1317
1368
1318
1369
let hold = hold_panel(app, model);
1319
1370
let share_stage = share_stage_element(app, state, call);
1320
1371
let region = stage_region(app, state, call, now, hold, share_stage);
1321
1372
1322
1373
let folded = folded_controls(state, call, fullscreen);
1323
let panels_and_reactions = h_flex()
1324
.gap(px(TOOL_GAP))
1325
.items_center()
1326
.when(
1327
model.has_reaction_controls() && !folded.folds(Foldable::Reactions),
1328
|row| row.child(reactions_button(app, model)),
1329
)
1330
.when(
1331
call.chat_thread().is_some() && !folded.folds(Foldable::Chat),
1332
|row| row.child(chat_button(app, call.chat_open, state.call_chat_unread())),
1333
)
1334
.when(
1335
model.kind != CallKind::Test && !folded.folds(Foldable::People),
1336
|row| row.child(people_button(app, call.people_open, model.raised_hands())),
1337
);
1338
let stage_and_more = h_flex()
1339
.gap(px(TOOL_GAP))
1340
.items_center()
1341
.when(shows_pop_out(call), |row| row.child(pop_out_tool(app)))
1342
.when(!folded.folds(Foldable::View), |row| {
1343
row.child(view_button(app, model, fullscreen))
1344
})
1345
.children(more_button(app, model, &folded));
1346
let devices = h_flex()
1347
.gap(px(TOOL_GAP))
1374
let controls = h_flex()
1375
.w_full()
1376
.flex_none()
1377
.py(px(16.))
1378
.px(px(CONTROLS_PADDING))
1379
.gap(px(CONTROL_GAP))
1348
1380
.items_center()
1381
.justify_center()
1349
1382
.child(
1350
1383
h_flex()
1351
.debug_selector(|| "shell/islands/main/call-header/controls/mic".into())
1384
.debug_selector(|| "shell/islands/main/call-controls/mic".into())
1385
.h(px(CONTROL_SIZE))
1352
1386
.items_center()
1353
.child(toolbar_mic(app, model))
1387
.rounded_full()
1388
.bg(theme::surface_raised())
1389
.child(mute_button(app, model, "call-mute", CONTROL_SIZE))
1354
1390
.child(mic_menu_button(app, model, state.call_mic)),
1355
1391
)
1356
1392
.child(
1357
1393
h_flex()
1394
.h(px(CONTROL_SIZE))
1358
1395
.items_center()
1359
.child(toolbar_camera(app, model))
1396
.rounded_full()
1397
.bg(theme::surface_raised())
1398
.child(camera_button(app, model))
1360
1399
.children(camera_menu_button(app, model, CameraMenu::of(state))),
1361
1400
)
1362
1401
.child(share_button(
@@ -1364,18 +1403,34 @@ pub fn render_call_view(
1364
1403
model,
1365
1404
ShareOptions::of(state),
1366
1405
call.share_menu_open,
1367
));
1368
let controls = h_flex()
1369
.debug_selector(|| "shell/islands/main/call-header/controls".into())
1370
.flex_none()
1371
.gap(px(GROUP_GAP))
1372
.items_center()
1373
.child(devices)
1374
.child(group_divider())
1375
.child(panels_and_reactions)
1376
.child(group_divider())
1377
.child(stage_and_more);
1378
let header = header.child(title_group).child(controls).child(end_group);
1406
))
1407
.when(
1408
model.has_reaction_controls() && !folded.folds(Foldable::RaiseHand),
1409
|row| row.child(hand_button(app, model)),
1410
)
1411
.when(
1412
model.has_reaction_controls() && !folded.folds(Foldable::Reactions),
1413
|row| row.child(reactions_button(app, model)),
1414
)
1415
.when(!folded.folds(Foldable::View), |row| {
1416
row.child(view_button(app, model, fullscreen))
1417
})
1418
.children(more_button(app, model, &folded))
1419
.when(
1420
model.kind != CallKind::Test && !folded.folds(Foldable::People),
1421
|row| row.child(people_button(app, call.people_open, model.raised_hands())),
1422
)
1423
.when(
1424
call.chat_thread().is_some() && !folded.folds(Foldable::Chat),
1425
|row| row.child(chat_button(app, call.chat_open, state.call_chat_unread())),
1426
)
1427
.child(
1428
leave_button(app, model, "call-leave", false)
1429
.debug_selector(|| "shell/islands/main/call-controls/leave".into()),
1430
)
1431
.when(has_leave_menu(model), |row| {
1432
row.child(leave_menu(app, model))
1433
});
1379
1434
1380
1435
let top = v_flex()
1381
1436
.w_full()
@@ -1406,19 +1461,28 @@ pub fn render_call_view(
1406
1461
column.child(fullscreen_chrome("call-chrome-top", app, top))
1407
1462
})
1408
1463
.child(region)
1464
.when(chrome_visible, |column| {
1465
column.child(fullscreen_chrome("call-chrome-bottom", app, controls))
1466
})
1409
1467
} else {
1410
1468
base.rounded(px(10.))
1411
1469
.child(top.debug_selector(|| "shell/islands/main/call-header".into()))
1412
1470
.child(region)
1471
.child(controls.debug_selector(|| "shell/islands/main/call-controls".into()))
1413
1472
}
1414
1473
.children(captions_overlay(model, now))
1415
1474
.children(captions_hint_chip(model))
1416
1475
.children(push_to_talk_chip(call))
1417
1476
.children(state.transfer_picker.clone())
1418
1477
.children(options_dialog(app, call))
1419
.children(consent_overlay(app, model));
1478
.children(consent_overlay(app, model))
1479
.children(local_share_float(app, state));
1480
let share_in_chat = call
1481
.chat_open
1482
.then(|| local_share_window(app, state, CHAT_PANEL_WIDTH))
1483
.flatten();
1420
1484
let panels: Vec<AnyElement> = chat
1421
.map(|chat| chat_panel(app, chat))
1485
.map(|chat| chat_panel(app, share_in_chat, chat))
1422
1486
.into_iter()
1423
1487
.chain(
1424
1488
call.transcript_open
@@ -1452,17 +1516,15 @@ fn side_panels(panels: Vec<AnyElement>, island_width: f32) -> Vec<AnyElement> {
1452
1516
if island_width - panels_width >= OVERLAY_BELOW {
1453
1517
return panels;
1454
1518
}
1455
vec![
1456
h_flex()
1457
.absolute()
1458
.top(px(HEADER_HEIGHT))
1459
.right_0()
1460
.bottom_0()
1461
.gap(px(ISLAND_GAP))
1462
.w(px(panels_width.min(island_width)))
1463
.children(panels)
1464
.into_any_element(),
1465
]
1519
vec![h_flex()
1520
.absolute()
1521
.top_0()
1522
.right_0()
1523
.bottom(px(CONTROLS_HEIGHT))
1524
.gap(px(ISLAND_GAP))
1525
.w(px(panels_width.min(island_width)))
1526
.children(panels)
1527
.into_any_element()]
1466
1528
}
1467
1529
1468
1530
fn fullscreen_chrome(id: &'static str, app: &Entity<AppState>, content: Div) -> Stateful<Div> {
@@ -1477,19 +1539,146 @@ fn fullscreen_chrome(id: &'static str, app: &Entity<AppState>, content: Div) ->
1477
1539
.child(content)
1478
1540
}
1479
1541
1480
fn chat_panel(app: &Entity<AppState>, chat: AnyView) -> AnyElement {
1542
fn chat_panel(app: &Entity<AppState>, share: Option<AnyElement>, chat: AnyView) -> AnyElement {
1481
1543
let app = app.clone();
1544
let body = v_flex()
1545
.w_full()
1546
.flex_1()
1547
.min_h_0()
1548
.children(share)
1549
.child(div().flex_1().min_h_0().overflow_hidden().child(chat));
1482
1550
side_panel(
1483
1551
"call-chat-panel",
1484
1552
"Chat",
1485
1553
"Close the chat",
1486
1554
move |cx| app.update(cx, |state, cx| state.toggle_call_chat(cx)),
1487
chat,
1555
body,
1488
1556
)
1489
1557
.debug_selector(|| CHAT_PANEL_TAG.into())
1490
1558
.into_any_element()
1491
1559
}
1492
1560
1561
const SHARE_WINDOW_INSET: f32 = 12.;
1562
const SHARE_WINDOW_RATIO: f32 = 9. / 16.;
1563
const SHARE_FLOAT_WIDTH: f32 = 320.;
1564
1565
/// The live local share, pinned in the meeting chat or floating on the call
1566
/// when the chat is closed.
1567
fn local_share_window(app: &Entity<AppState>, state: &AppState, width: f32) -> Option<AnyElement> {
1568
let call = state.call.as_ref()?;
1569
let label = call.model.local_share.clone()?;
1570
let image = call.pictures.live(&VideoKey::LocalScreen, Instant::now());
1571
Some(share_window(app, &label, image, width))
1572
}
1573
1574
fn local_share_float(app: &Entity<AppState>, state: &AppState) -> Option<AnyElement> {
1575
let call = state.call.as_ref()?;
1576
if call.chat_open {
1577
return None;
1578
}
1579
let window = local_share_window(app, state, SHARE_FLOAT_WIDTH)?;
1580
Some(
1581
div()
1582
.absolute()
1583
.right(px(16.))
1584
.bottom(px(CONTROLS_HEIGHT + 12.))
1585
.w(px(SHARE_FLOAT_WIDTH))
1586
.rounded(px(10.))
1587
.overflow_hidden()
1588
.bg(theme::surface())
1589
.shadow(theme::flyout_shadow())
1590
.child(window)
1591
.into_any_element(),
1592
)
1593
}
1594
1595
fn share_window(
1596
app: &Entity<AppState>,
1597
label: &str,
1598
image: Option<Arc<RenderImage>>,
1599
width: f32,
1600
) -> AnyElement {
1601
let picture_width = (width - 2. * SHARE_WINDOW_INSET).max(0.);
1602
let picture_height = picture_width * SHARE_WINDOW_RATIO;
1603
let stop = app.clone();
1604
v_flex()
1605
.w_full()
1606
.flex_none()
1607
.p(px(SHARE_WINDOW_INSET))
1608
.child(
1609
div()
1610
.id("call-share-window")
1611
.relative()
1612
.w(px(picture_width))
1613
.h(px(picture_height))
1614
.rounded(px(8.))
1615
.overflow_hidden()
1616
.bg(hsla(0., 0., 0.04, 1.))
1617
.child(share_picture(image))
1618
.child(
1619
div()
1620
.absolute()
1621
.top(px(8.))
1622
.left(px(8.))
1623
.max_w(px(picture_width * 0.62))
1624
.h(px(22.))
1625
.px(px(8.))
1626
.flex()
1627
.items_center()
1628
.rounded_full()
1629
.bg(hsla(0., 0., 0., 0.6))
1630
.text_size(px(11.))
1631
.text_color(theme::white())
1632
.child(div().truncate().child(label.to_owned())),
1633
)
1634
.child(share_stop(stop)),
1635
)
1636
.into_any_element()
1637
}
1638
1639
fn share_picture(image: Option<Arc<RenderImage>>) -> AnyElement {
1640
let Some(image) = image else {
1641
return div()
1642
.size_full()
1643
.flex()
1644
.items_center()
1645
.justify_center()
1646
.px(px(12.))
1647
.text_size(px(12.))
1648
.text_color(theme::text_muted())
1649
.child(WAITING_TEXT)
1650
.into_any_element();
1651
};
1652
img(ImageSource::Render(image))
1653
.size_full()
1654
.object_fit(ObjectFit::Contain)
1655
.into_any_element()
1656
}
1657
1658
fn share_stop(app: Entity<AppState>) -> Stateful<Div> {
1659
div()
1660
.id("call-share-window-stop")
1661
.absolute()
1662
.top(px(8.))
1663
.right(px(8.))
1664
.h(px(22.))
1665
.px(px(8.))
1666
.flex()
1667
.items_center()
1668
.rounded_full()
1669
.bg(theme::red())
1670
.text_color(theme::white())
1671
.text_size(px(11.))
1672
.font_weight(FontWeight::SEMIBOLD)
1673
.cursor_pointer()
1674
.hover(|button| button.opacity(0.85))
1675
.child("Stop")
1676
.on_click(move |_, _, cx| {
1677
cx.stop_propagation();
1678
app.update(cx, |state, cx| state.stop_call_share(cx));
1679
})
1680
}
1681
1493
1682
pub fn side_panel(
1494
1683
panel_id: &'static str,
1495
1684
title: &'static str,
@@ -1541,14 +1730,25 @@ pub fn side_panel(
1541
1730
1542
1731
#[cfg(test)]
1543
1732
mod tests {
1544
use super::{TileSize, name_plate_metrics};
1733
use super::{name_plate_metrics, TileSize};
1545
1734
1546
1735
#[test]
1547
1736
fn small_strip_tiles_get_a_compact_name_plate() {
1548
let strip = name_plate_metrics(TileSize { width: 216., height: 121.5, avatar: 48. });
1549
assert_eq!((strip.text_size, strip.inset, strip.padding_y), (11., 4., 2.));
1737
let strip = name_plate_metrics(TileSize {
1738
width: 216.,
1739
height: 121.5,
1740
avatar: 48.,
1741
});
1742
assert_eq!(
1743
(strip.text_size, strip.inset, strip.padding_y),
1744
(11., 4., 2.)
1745
);
1550
1746
assert!(strip.max_width_share < 1.);
1551
let stage = name_plate_metrics(TileSize { width: 640., height: 360., avatar: 96. });
1747
let stage = name_plate_metrics(TileSize {
1748
width: 640.,
1749
height: 360.,
1750
avatar: 96.,
1751
});
1552
1752
assert_eq!((stage.text_size, stage.inset), (12., 8.));
1553
1753
}
1554
1754
}
@@ -1,7 +1,7 @@1
use std::sync::Arc;1
use std::sync::Arc;2
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};2
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};3
3
4
use calling::{DeviceEntry, MicSettings, NoiseSuppression, Reaction, VideoKey};4
use calling::{DeviceEntry, MicSettings, NoiseSuppression, Reaction, ShareKind, VideoKey};5
use gpui_kit::assets::IconName;5
use gpui_kit::assets::IconName;6
use gpui_kit::component::{6
use gpui_kit::component::{7
button::{Button, ButtonVariants as _},7
button::{Button, ButtonVariants as _},@@ -16,32 +16,32 @@ use gpui_kit::prelude::FluentBuilder as _;16
use gpui_kit::*;16
use gpui_kit::*;17
17
18
use super::avatar::person_avatar;18
use super::avatar::person_avatar;19
use super::call_control_fold::{Foldable, FoldedControls, fixed_controls_width, folded_for_width, in_more_menu};19
use super::call_control_fold::{20
use super::call_toolbar::{20
fixed_controls_width, folded_for_width, Foldable, FoldedControls, CONTROLS_PADDING, CONTROL_GAP,21
GROUP_GAP, LEAVE_HEIGHT, group_divider, SPLIT_CHEVRON_WIDTH, TOOL_GAP, tool_face, tool_trigger, split_chevron,22
};21
};23
use super::call_extras::{22
use super::call_extras::{24
CameraMenu, consent_overlay, consult_banner, hold_panel, recording_chip, return_button,23
consent_overlay, consult_banner, hold_panel, recording_chip, return_button, room_chip,25
room_chip, whiteboard_stage,24
whiteboard_stage, CameraMenu,26
};25
};27
use super::call_health::{health_banner, health_indicator};26
use super::call_health::{health_banner, health_indicator};28
use super::call_layouts::stage_region;27
use super::call_layouts::stage_region;29
use crate::call::measured_stage;30
use super::call_organizer::{28
use super::call_organizer::{31
camera_menu_button, captions_hint_chip, captions_overlay, lobby_banner,29
camera_menu_button, captions_hint_chip, captions_overlay, chevron_button, lobby_banner,32
more_button, pin_chip, spotlight_chip, with_tile_menu,30
more_button, pin_chip, spotlight_chip, with_tile_menu,33
};31
};34
use super::call_people::{lock_banner, lock_chip, options_dialog, people_button, people_panel};32
use super::call_people::{lock_banner, lock_chip, options_dialog, people_button, people_panel};35
use super::call_stage::{POP_OUT_TOOLTIP, StageMode, popped_placeholder, render_stage};33
use super::call_stage::{popped_placeholder, render_stage, StageMode, WAITING_TEXT};36
use super::call_view_menu::view_button;34
use super::call_view_menu::view_button;37
use app_ui_kit::layout::ISLAND_GAP;35
use super::widgets::{corner_badge, count_badge, icon, Corner};38
use super::widgets::{Corner, corner_badge, count_badge, icon};39
use crate::app_state::AppState;36
use crate::app_state::AppState;40
use crate::call::REACTION_SHOWN;37
use crate::call::measured_stage;38
use crate::call::model::ShareMenuEntry;41
use crate::call::TileSize;39
use crate::call::TileSize;40
use crate::call::REACTION_SHOWN;42
use crate::call::{ActiveCall, CallKind, CallModel, Tile, TileState};41
use crate::call::{ActiveCall, CallKind, CallModel, Tile, TileState};43
use crate::rows::reaction_glyph as chat_reaction_glyph;42
use crate::rows::reaction_glyph as chat_reaction_glyph;44
use crate::theme;43
use crate::theme;44
use app_ui_kit::layout::ISLAND_GAP;45
45
46
const HEADER_HEIGHT: f32 = 60.;46
const HEADER_HEIGHT: f32 = 60.;47
const RING_WIDTH: f32 = 3.;47
const RING_WIDTH: f32 = 3.;@@ -64,7 +64,6 @@ pub const NO_CAMERA_HINT: &str = "No camera found";64
pub const NO_SHARE_HINT: &str = "Sharing starts once the call is connected";64
pub const NO_SHARE_HINT: &str = "Sharing starts once the call is connected";65
pub const NO_WINDOWS_HINT: &str = "No windows found";65
pub const NO_WINDOWS_HINT: &str = "No windows found";66
pub(super) const BANNER_HEIGHT: f32 = 40.;66
pub(super) const BANNER_HEIGHT: f32 = 40.;67
const MAX_WINDOW_ITEMS: usize = 12;68
pub const SHARE_THUMBNAIL_TAG: &str = "call/share-menu/thumbnail";67
pub const SHARE_THUMBNAIL_TAG: &str = "call/share-menu/thumbnail";69
const SCREEN_THUMBNAIL: (f32, f32) = (128., 72.);68
const SCREEN_THUMBNAIL: (f32, f32) = (128., 72.);70
const WINDOW_THUMBNAIL: (f32, f32) = (96., 54.);69
const WINDOW_THUMBNAIL: (f32, f32) = (96., 54.);@@ -73,8 +72,7 @@ const THUMBNAIL_ICON: f32 = 22.;73
pub const LOBBY_TEXT: &str = "Waiting in the lobby...";72
pub const LOBBY_TEXT: &str = "Waiting in the lobby...";74
pub(super) const CHAT_PANEL_WIDTH: f32 = 320.;73
pub(super) const CHAT_PANEL_WIDTH: f32 = 320.;75
pub(super) const OVERLAY_BELOW: f32 = 720.;74
pub(super) const OVERLAY_BELOW: f32 = 720.;76
const HEADER_END_PADDING: f32 = 8.;75
const CONTROLS_HEIGHT: f32 = 2. * 16. + CONTROL_SIZE;77
const LEAVE_RADIUS: f32 = 6.;78
const CHAT_HEADER_HEIGHT: f32 = 48.;76
const CHAT_HEADER_HEIGHT: f32 = 48.;79
const REACTION_RISE: f32 = 24.;77
const REACTION_RISE: f32 = 24.;80
const REACTION_FADE_FROM: f32 = 0.75;78
const REACTION_FADE_FROM: f32 = 0.75;@@ -90,8 +88,13 @@ const PUSH_TO_TALK_TOP: f32 = 12.;90
88
91
pub fn reaction_glyph(reaction: &Reaction) -> String {89
pub fn reaction_glyph(reaction: &Reaction) -> String {92
match reaction {90
match reaction {91
Reaction::Like => "\u{1F44D}".to_owned(),92
// Keep VS16 so the heart stays emoji-style, not a text outline.93
Reaction::Heart => "\u{2764}\u{FE0F}".to_owned(),93
Reaction::Applause => "\u{1F44F}".to_owned(),94
Reaction::Applause => "\u{1F44F}".to_owned(),94
other => chat_reaction_glyph(other.name()),95
Reaction::Laugh => "\u{1F606}".to_owned(),96
Reaction::Surprised => "\u{1F62E}".to_owned(),97
Reaction::Other(name) => chat_reaction_glyph(name),95
}98
}96
}99
}97
100
@@ -143,6 +146,7 @@ fn reaction_chip(reaction: Reaction, serial: u64) -> AnyElement {143
.rounded_full()146
.rounded_full()144
.bg(theme::popup())147
.bg(theme::popup())145
.text_size(px(if emoji { 20. } else { 13. }))148
.text_size(px(if emoji { 20. } else { 13. }))149
.when(emoji, |chip| chip.font_family(theme::EMOJI_FONT_FAMILY))146
.child(glyph)150
.child(glyph)147
.with_animation(151
.with_animation(148
("call-reaction", serial as usize),152
("call-reaction", serial as usize),@@ -251,9 +255,23 @@ struct NamePlate {251
255
252
fn name_plate_metrics(size: TileSize) -> NamePlate {256
fn name_plate_metrics(size: TileSize) -> NamePlate {253
if size.height < COMPACT_PLATE_BELOW {257
if size.height < COMPACT_PLATE_BELOW {254
NamePlate { inset: 4., padding_x: 6., padding_y: 2., radius: 4., text_size: 11., max_width_share: 0.6 }258
NamePlate {259
inset: 4.,260
padding_x: 6.,261
padding_y: 2.,262
radius: 4.,263
text_size: 11.,264
max_width_share: 0.6,265
}255
} else {266
} else {256
NamePlate { inset: 8., padding_x: 8., padding_y: 4., radius: 6., text_size: 12., max_width_share: 1. }267
NamePlate {268
inset: 8.,269
padding_x: 8.,270
padding_y: 4.,271
radius: 6.,272
text_size: 12.,273
max_width_share: 1.,274
}257
}275
}258
}276
}259
277
@@ -263,7 +281,9 @@ fn name_plate(size: TileSize, name: &str) -> Div {263
.absolute()281
.absolute()264
.left(px(plate.inset))282
.left(px(plate.inset))265
.bottom(px(plate.inset))283
.bottom(px(plate.inset))266
.max_w(px(((size.width - 3. * plate.inset) * plate.max_width_share).max(0.)))284
.max_w(px(((size.width - 3. * plate.inset)285
* plate.max_width_share)286
.max(0.)))267
.truncate()287
.truncate()268
.px(px(plate.padding_x))288
.px(px(plate.padding_x))269
.py(px(plate.padding_y))289
.py(px(plate.padding_y))@@ -385,19 +405,7 @@ pub fn mute_button(385
} else {405
} else {386
(IconName::Mic, theme::surface_raised(), theme::text())406
(IconName::Mic, theme::surface_raised(), theme::text())387
};407
};388
mic_action(round_control(id, glyph, background, foreground).size(px(size)), app, model)408
let button = round_control(id, glyph, background, foreground).size(px(size));389
}390
391
fn toolbar_mic(app: &Entity<AppState>, model: &CallModel) -> Stateful<Div> {392
let glyph = if model.muted {393
IconName::MicOff394
} else {395
IconName::Mic396
};397
mic_action(tool_face("call-mute", glyph, "Mic", false), app, model)398
}399
400
fn mic_action(button: Stateful<Div>, app: &Entity<AppState>, model: &CallModel) -> Stateful<Div> {401
if !model.can_unmute() {409
if !model.can_unmute() {402
let hint = if model.audio_off {410
let hint = if model.audio_off {403
AUDIO_OFF_HINT411
AUDIO_OFF_HINT@@ -430,8 +438,8 @@ pub fn leave_button(430
let app = app.clone();438
let app = app.clone();431
h_flex()439
h_flex()432
.id(id)440
.id(id)433
.h(px(if compact { 28. } else { LEAVE_HEIGHT }))441
.h(px(if compact { 28. } else { CONTROL_SIZE }))434
.px(px(if compact { 10. } else { 14. }))442
.px(px(if compact { 10. } else { 20. }))435
.gap(px(8.))443
.gap(px(8.))436
.flex_none()444
.flex_none()437
.items_center()445
.items_center()@@ -439,13 +447,13 @@ pub fn leave_button(439
.rounded_full()447
.rounded_full()440
.bg(theme::red())448
.bg(theme::red())441
.text_color(theme::white())449
.text_color(theme::white())442
.text_size(px(if compact { 12. } else { 13. }))450
.text_size(px(if compact { 12. } else { 14. }))443
.font_weight(FontWeight::SEMIBOLD)451
.font_weight(FontWeight::SEMIBOLD)444
.cursor_pointer()452
.cursor_pointer()445
.hover(|button| button.opacity(0.85))453
.hover(|button| button.opacity(0.85))446
.child(icon(454
.child(icon(447
IconName::PhoneOff,455
IconName::PhoneOff,448
if compact { 14. } else { 16. },456
if compact { 14. } else { 18. },449
theme::white(),457
theme::white(),450
))458
))451
.child(label)459
.child(label)@@ -455,7 +463,11 @@ pub fn leave_button(455
})463
})456
}464
}457
465
458
fn share_stage_element(app: &Entity<AppState>, state: &AppState, call: &ActiveCall) -> Option<AnyElement> {466
fn share_stage_element(467
app: &Entity<AppState>,468
state: &AppState,469
call: &ActiveCall,470
) -> Option<AnyElement> {459
if call.share_stage.popped && call.model.screen_sharer.is_some() {471
if call.share_stage.popped && call.model.screen_sharer.is_some() {460
return Some(popped_placeholder(app));472
return Some(popped_placeholder(app));461
}473
}@@ -468,19 +480,7 @@ pub(super) fn camera_button(app: &Entity<AppState>, model: &CallModel) -> Statef468
} else {480
} else {469
(IconName::VideoOff, theme::surface_raised(), theme::text())481
(IconName::VideoOff, theme::surface_raised(), theme::text())470
};482
};471
camera_action(round_control("call-camera", glyph, background, foreground), app, model)483
let button = round_control("call-camera", glyph, background, foreground);472
}473
474
fn toolbar_camera(app: &Entity<AppState>, model: &CallModel) -> Stateful<Div> {475
let glyph = if model.camera_on {476
IconName::Video477
} else {478
IconName::VideoOff479
};480
camera_action(tool_face("call-camera", glyph, "Camera", false), app, model)481
}482
483
fn camera_action(button: Stateful<Div>, app: &Entity<AppState>, model: &CallModel) -> Stateful<Div> {484
if !model.can_use_camera() {484
if !model.can_use_camera() {485
return button485
return button486
.opacity(DISABLED_OPACITY)486
.opacity(DISABLED_OPACITY)@@ -550,7 +550,9 @@ fn standout_switch_item(app: &Entity<AppState>, standout: bool, camera_on: bool)550
})550
})551
})551
})552
.disabled(!camera_on)552
.disabled(!camera_on)553
.on_click(move |_, _, cx| app.update(cx, |state, cx| state.set_call_share_standout(!standout, cx)))553
.on_click(move |_, _, cx| {554
app.update(cx, |state, cx| state.set_call_share_standout(!standout, cx))555
})554
}556
}555
557
556
fn music_mode_item(app: &Entity<AppState>, mic: MicSettings) -> PopupMenuItem {558
fn music_mode_item(app: &Entity<AppState>, mic: MicSettings) -> PopupMenuItem {@@ -624,46 +626,104 @@ fn share_items(624
model: &CallModel,626
model: &CallModel,625
options: ShareOptions,627
options: ShareOptions,626
) -> PopupMenu {628
) -> PopupMenu {627
let screens = model.screens();629
<<<<<<< ours628
let single_screen = screens.len() == 1;630
let single_screen = model.screens().len() == 1;631
let mut screen_index = 0usize;632
let mut separated = false;633
let mut popup = popup.min_w(px(SHARE_MENU_WIDTH));634
for entry in model.share_menu_entries() {635
popup = match entry {636
ShareMenuEntry::Sound => popup.item(sound_switch_item(app, options.sound)),637
ShareMenuEntry::Motion => popup.item(motion_switch_item(app, options.motion)),638
ShareMenuEntry::Standout => {639
popup.item(standout_switch_item(app, options.standout, model.camera_on))640
}641
ShareMenuEntry::Portal(kind) => {642
if !separated {643
popup = popup.separator();644
separated = true;645
}646
let label = match kind {647
ShareKind::Screen => "Share entire screen",648
ShareKind::Window => "Share a window",649
};650
let app = app.clone();651
popup.item(PopupMenuItem::new(label).on_click(move |_, _, cx| {652
app.update(cx, |state, cx| state.start_portal_share(kind, cx))653
}))654
}655
ShareMenuEntry::Source(source) => {656
if !separated {657
popup = popup.separator();658
separated = true;659
}660
let (label, thumbnail, icon, size) = if source.kind == ShareKind::Screen {661
screen_index += 1;662
let label = if single_screen {663
"Share entire screen".to_owned()664
} else {665
format!("Share screen {screen_index}")666
};667
(668
label,669
model.share_thumbnail(&source),670
IconName::Monitor,671
SCREEN_THUMBNAIL,672
)673
} else {674
(675
source.label(),676
model.share_thumbnail(&source),677
IconName::AppWindow,678
WINDOW_THUMBNAIL,679
)680
};681
let app = app.clone();682
popup.item(share_source_item(label, thumbnail, icon, size).on_click(683
move |_, _, cx| {684
app.update(cx, |state, cx| state.start_call_share(source.clone(), cx))685
},686
))687
}688
ShareMenuEntry::WindowHeader => popup689
.separator()690
.item(PopupMenuItem::label("Share a window...")),691
ShareMenuEntry::NoWindows => {692
popup.item(PopupMenuItem::new(NO_WINDOWS_HINT).disabled(true))693
}694
=======629
let mut popup = popup695
let mut popup = popup630
.min_w(px(SHARE_MENU_WIDTH))696
.min_w(px(SHARE_MENU_WIDTH))631
.item(sound_switch_item(app, options.sound))697
.item(sound_switch_item(app, options.sound))632
.item(motion_switch_item(app, options.motion))698
.item(motion_switch_item(app, options.motion))633
.item(standout_switch_item(app, options.standout, model.camera_on))699
.item(standout_switch_item(app, options.standout, model.camera_on))634
.separator();700
.separator();701
if model.uses_portal_picker() {702
let screen_app = app.clone();703
let window_app = app.clone();704
return popup705
.item(706
PopupMenuItem::new("Share entire screen").on_click(move |_, _, cx| {707
screen_app.update(cx, |state, cx| {708
state.start_portal_share(ShareKind::Screen, cx)709
})710
}),711
)712
.item(PopupMenuItem::new("Share a window").on_click(move |_, _, cx| {713
window_app.update(cx, |state, cx| {714
state.start_portal_share(ShareKind::Window, cx)715
})716
}));717
}718
let screens = model.screens();719
let single_screen = screens.len() == 1;635
for (index, source) in screens.into_iter().enumerate() {720
for (index, source) in screens.into_iter().enumerate() {636
let label = if single_screen {721
let label = if single_screen {637
"Share entire screen".to_owned()722
"Share entire screen".to_owned()638
} else {723
} else {639
format!("Share screen {}", index + 1)724
format!("Share screen {}", index + 1)725
>>>>>>> theirs640
};726
};641
let thumbnail = model.share_thumbnail(source);642
let source = source.clone();643
let app = app.clone();644
popup = popup.item(645
share_source_item(label, thumbnail, IconName::Monitor, SCREEN_THUMBNAIL).on_click(646
move |_, _, cx| app.update(cx, |state, cx| state.start_call_share(source.clone(), cx)),647
),648
);649
}650
popup = popup651
.separator()652
.item(PopupMenuItem::label("Share a window..."));653
let windows = model.windows();654
if windows.is_empty() {655
return popup.item(PopupMenuItem::new(NO_WINDOWS_HINT).disabled(true));656
}657
for source in windows.into_iter().take(MAX_WINDOW_ITEMS) {658
let label = source.label();659
let thumbnail = model.share_thumbnail(source);660
let source = source.clone();661
let app = app.clone();662
popup = popup.item(663
share_source_item(label, thumbnail, IconName::AppWindow, WINDOW_THUMBNAIL).on_click(664
move |_, _, cx| app.update(cx, |state, cx| state.start_call_share(source.clone(), cx)),665
),666
);667
}727
}668
popup728
popup669
}729
}@@ -716,7 +776,12 @@ fn share_button(716
) -> AnyElement {776
) -> AnyElement {717
if model.local_share.is_some() {777
if model.local_share.is_some() {718
let app = app.clone();778
let app = app.clone();719
return tool_face("call-share-stop", IconName::ScreenShareOff, "Stop", true)779
return round_control(780
"call-share-stop",781
IconName::ScreenShareOff,782
theme::accent(),783
theme::on_accent(),784
)720
.tooltip(|window, cx| Tooltip::new("Stop sharing").build(window, cx))785
.tooltip(|window, cx| Tooltip::new("Stop sharing").build(window, cx))721
.on_click(move |_, _, cx| {786
.on_click(move |_, _, cx| {722
cx.stop_propagation();787
cx.stop_propagation();@@ -724,7 +789,12 @@ fn share_button(724
})789
})725
.into_any_element();790
.into_any_element();726
}791
}727
let face = tool_face("call-share-face", IconName::ScreenShare, "Share", false);792
let face = round_control(793
"call-share-face",794
IconName::ScreenShare,795
theme::surface_raised(),796
theme::text(),797
);728
if !model.can_share() {798
if !model.can_share() {729
return face799
return face730
.opacity(DISABLED_OPACITY)800
.opacity(DISABLED_OPACITY)@@ -735,8 +805,13 @@ fn share_button(735
let app = app.clone();805
let app = app.clone();736
let open_app = app.clone();806
let open_app = app.clone();737
let model = model.clone();807
let model = model.clone();738
tool_trigger("call-share", face)808
Button::new("call-share")739
.dropdown_menu_with_anchor(Anchor::TopRight, move |popup, _, _| {809
.ghost()810
.p_0()811
.size(px(CONTROL_SIZE))812
.rounded_full()813
.child(face)814
.dropdown_menu_with_anchor(Anchor::BottomLeft, move |popup, _, _| {740
share_items(popup, &app, &model, options)815
share_items(popup, &app, &model, options)741
})816
})742
.open(menu_open)817
.open(menu_open)@@ -809,7 +884,12 @@ fn sharing_banner(app: &Entity<AppState>, model: &CallModel, sound: bool) -> Opt809
884
810
fn chat_button(app: &Entity<AppState>, open: bool, unread: u32) -> Stateful<Div> {885
fn chat_button(app: &Entity<AppState>, open: bool, unread: u32) -> Stateful<Div> {811
let app = app.clone();886
let app = app.clone();812
tool_face("call-chat", IconName::MessageCircle, "Chat", open)887
let (background, foreground) = if open {888
(theme::accent(), theme::on_accent())889
} else {890
(theme::surface_raised(), theme::text())891
};892
round_control("call-chat", IconName::MessageCircle, background, foreground)813
.relative()893
.relative()814
.tooltip(move |window, cx| {894
.tooltip(move |window, cx| {815
Tooltip::new(if open {895
Tooltip::new(if open {@@ -825,9 +905,41 @@ fn chat_button(app: &Entity<AppState>, open: bool, unread: u32) -> Stateful<Div>825
.on_click(move |_, _, cx| app.update(cx, |state, cx| state.toggle_call_chat(cx)))905
.on_click(move |_, _, cx| app.update(cx, |state, cx| state.toggle_call_chat(cx)))826
}906
}827
907
828
fn reactions_button(app: &Entity<AppState>, model: &CallModel) -> AnyElement {908
fn hand_button(app: &Entity<AppState>, model: &CallModel) -> Stateful<Div> {829
let raised = model.own_hand.is_some();909
let raised = model.own_hand.is_some();830
let face = tool_face("call-reactions-face", IconName::FaceSlightlySmiling, "React", raised);910
let background = if raised {911
theme::accent()912
} else {913
theme::surface_raised()914
};915
let foreground = if raised {916
theme::on_accent()917
} else {918
theme::text()919
};920
let button = control_shell("call-hand", background).child(icon(921
IconName::Hand,922
CONTROL_ICON,923
foreground,924
));925
let tooltip = if raised { "Lower hand" } else { "Raise hand" };926
let button = button.tooltip(move |window, cx| Tooltip::new(tooltip).build(window, cx));927
if !model.can_react() {928
return button.opacity(DISABLED_OPACITY).cursor_default();929
}930
let app = app.clone();931
button.on_click(move |_, _, cx| {932
cx.stop_propagation();933
app.update(cx, |state, cx| state.toggle_call_hand(cx));934
})935
}936
937
fn reactions_button(app: &Entity<AppState>, model: &CallModel) -> AnyElement {938
let face = control_shell("call-reactions-face", theme::surface_raised()).child(icon(939
IconName::FaceSlightlySmiling,940
CONTROL_ICON,941
theme::text(),942
));831
if !model.can_react() {943
if !model.can_react() {832
return face944
return face833
.opacity(DISABLED_OPACITY)945
.opacity(DISABLED_OPACITY)@@ -836,14 +948,19 @@ fn reactions_button(app: &Entity<AppState>, model: &CallModel) -> AnyElement {836
}948
}837
let app = app.clone();949
let app = app.clone();838
Popover::new("call-reactions-popover")950
Popover::new("call-reactions-popover")839
.anchor(Anchor::TopRight)951
.anchor(Anchor::BottomLeft)840
.offset(px(6.))952
.offset(px(10.))841
.trigger(tool_trigger("call-reactions", face))953
.trigger(954
Button::new("call-reactions")955
.ghost()956
.p_0()957
.size(px(CONTROL_SIZE))958
.rounded_full()959
.child(face),960
)842
.content(move |_, _, cx| {961
.content(move |_, _, cx| {843
let popover = cx.entity().downgrade();962
let popover = cx.entity().downgrade();844
let hand_app = app.clone();963
h_flex()845
let hand_popover = popover.clone();846
let reactions = h_flex()847
.id("call-reactions-row")964
.id("call-reactions-row")848
.gap(px(4.))965
.gap(px(4.))849
.children(Reaction::ALL.into_iter().map(|reaction| {966
.children(Reaction::ALL.into_iter().map(|reaction| {@@ -857,68 +974,23 @@ fn reactions_button(app: &Entity<AppState>, model: &CallModel) -> AnyElement {857
.justify_center()974
.justify_center()858
.rounded(px(8.))975
.rounded(px(8.))859
.text_size(px(24.))976
.text_size(px(24.))977
.font_family(theme::EMOJI_FONT_FAMILY)860
.cursor_pointer()978
.cursor_pointer()861
.hover(|cell| cell.bg(theme::border_strong()))979
.hover(|cell| cell.bg(theme::border_strong()))862
.child(reaction_glyph(&reaction))980
.child(reaction_glyph(&reaction))863
.on_click(move |_, window, cx| {981
.on_click(move |_, window, cx| {864
app.update(cx, |state, cx| state.send_call_reaction(reaction.clone(), cx));982
app.update(cx, |state, cx| {983
state.send_call_reaction(reaction.clone(), cx)984
});865
popover985
popover866
.update(cx, |state, cx| state.dismiss(window, cx))986
.update(cx, |state, cx| state.dismiss(window, cx))867
.ok();987
.ok();868
})988
})869
}));989
}))870
v_flex()871
.gap(px(6.))872
.child(reactions)873
.child(874
h_flex()875
.id("call-hand")876
.h(px(36.))877
.px(px(10.))878
.gap(px(8.))879
.items_center()880
.rounded(px(8.))881
.cursor_pointer()882
.when(raised, |row| row.bg(theme::accent_soft()))883
.hover(|row| row.bg(theme::border_strong()))884
.child(icon(IconName::Hand, 18., if raised { theme::accent_text() } else { theme::text() }))885
.child(div().text_size(px(13.)).child(if raised { "Lower hand" } else { "Raise hand" }))886
.on_click(move |_, window, cx| {887
hand_app.update(cx, |state, cx| state.toggle_call_hand(cx));888
hand_popover889
.update(cx, |state, cx| state.dismiss(window, cx))890
.ok();891
}),892
)893
})990
})894
.into_any_element()991
.into_any_element()895
}992
}896
993
897
fn pop_out_tool(app: &Entity<AppState>) -> Stateful<Div> {898
let app = app.clone();899
tool_face("call-pop-out", IconName::ExternalLink, POP_OUT_TOOLTIP, false)900
.on_click(move |_, _, cx| app.update(cx, |state, cx| state.pop_out_stage(cx)))901
}902
903
fn shows_pop_out(call: &ActiveCall) -> bool {904
call.model.screen_sharer.is_some() && !call.share_stage.popped905
}906
907
fn leave_group(app: &Entity<AppState>, model: &CallModel) -> AnyElement {908
let leave = leave_button(app, model, "call-leave", false)909
.rounded(px(LEAVE_RADIUS))910
.debug_selector(|| "shell/islands/main/call-header/leave".into());911
if !has_leave_menu(model) {912
return leave.into_any_element();913
}914
h_flex()915
.flex_none()916
.gap(px(1.))917
.child(leave.rounded_r(px(0.)))918
.child(leave_menu(app, model))919
.into_any_element()920
}921
922
fn has_leave_menu(model: &CallModel) -> bool {994
fn has_leave_menu(model: &CallModel) -> bool {923
model.kind == CallKind::Meeting995
model.kind == CallKind::Meeting924
&& (model.can_end_meeting || (model.can_lower_hands() && model.any_hand_raised()))996
&& (model.can_end_meeting || (model.can_lower_hands() && model.any_hand_raised()))@@ -932,23 +1004,15 @@ fn leave_menu(app: &Entity<AppState>, model: &CallModel) -> impl IntoElement {932
Button::new("call-leave-menu")1004
Button::new("call-leave-menu")933
.ghost()1005
.ghost()934
.p_0()1006
.p_0()935
.w(px(SPLIT_CHEVRON_WIDTH + 4.))1007
.size(px(CONTROL_SIZE))936
.h(px(LEAVE_HEIGHT))1008
.rounded_full()937
.rounded_r(px(LEAVE_RADIUS))1009
.child(round_control(938
.child(1010
"call-leave-menu-face",939
div()1011
IconName::ChevronUp,940
.id("call-leave-menu-face")1012
theme::surface_raised(),941
.size_full()1013
theme::text(),942
.flex()1014
))943
.items_center()1015
.dropdown_menu_with_anchor(Anchor::BottomRight, move |popup, _, _| {944
.justify_center()945
.rounded_r(px(LEAVE_RADIUS))946
.bg(theme::red())947
.cursor_pointer()948
.hover(|face| face.opacity(0.85))949
.child(icon(IconName::ChevronDown, 12., theme::white())),950
)951
.dropdown_menu_with_anchor(Anchor::TopRight, move |popup, _, _| {952
let end_app = end_app.clone();1016
let end_app = end_app.clone();953
let lower_app = lower_app.clone();1017
let lower_app = lower_app.clone();954
let popup = popup.min_w(px(MENU_WIDTH));1018
let popup = popup.min_w(px(MENU_WIDTH));@@ -1057,11 +1121,15 @@ fn devices_menu(1057
popup1121
popup1058
}1122
}1059
1123
1060
fn mic_menu_button(app: &Entity<AppState>, model: &CallModel, mic: MicSettings) -> impl IntoElement {1124
fn mic_menu_button(1125
app: &Entity<AppState>,1126
model: &CallModel,1127
mic: MicSettings,1128
) -> impl IntoElement {1061
let app = app.clone();1129
let app = app.clone();1062
let model = model.clone();1130
let model = model.clone();1063
split_chevron("call-mic-menu", "call-mic-menu-face")1131
chevron_button("call-mic-menu", "call-mic-menu-face")1064
.dropdown_menu_with_anchor(Anchor::TopRight, move |popup, _, _| {1132
.dropdown_menu_with_anchor(Anchor::BottomLeft, move |popup, _, _| {1065
devices_menu(popup, &app, &model, mic)1133
devices_menu(popup, &app, &model, mic)1066
})1134
})1067
}1135
}@@ -1180,7 +1248,9 @@ pub(super) fn plain_own_tile(1180
let extras = TileExtras {1248
let extras = TileExtras {1181
hand: model.own_hand.map(|rank| model.hand_position(rank)),1249
hand: model.own_hand.map(|rank| model.hand_position(rank)),1182
own: true,1250
own: true,1183
reaction: model.own_chip(now).map(|chip| (chip.reaction.clone(), chip.serial)),1251
reaction: model1252
.own_chip(now)1253
.map(|chip| (chip.reaction.clone(), chip.serial)),1184
spotlight: model.own_spotlight.is_some(),1254
spotlight: model.own_spotlight.is_some(),1185
pinned: model.is_pinned(own_mri),1255
pinned: model.is_pinned(own_mri),1186
fitted: false,1256
fitted: false,@@ -1235,9 +1305,9 @@ fn folded_controls(state: &AppState, call: &ActiveCall, fullscreen: bool) -> Fol1235
if !has_more {1305
if !has_more {1236
return FoldedControls::default();1306
return FoldedControls::default();1237
}1307
}1238
let mut present = Vec::new();1308
let mut present = vec![Foldable::View];1239
if model.has_reaction_controls() {1309
if model.has_reaction_controls() {1240
present.push(Foldable::Reactions);1310
present.extend([Foldable::Reactions, Foldable::RaiseHand]);1241
}1311
}1242
if model.kind != CallKind::Test {1312
if model.kind != CallKind::Test {1243
present.push(Foldable::People);1313
present.push(Foldable::People);@@ -1245,14 +1315,9 @@ fn folded_controls(state: &AppState, call: &ActiveCall, fullscreen: bool) -> Fol1245
if call.chat_thread().is_some() {1315
if call.chat_thread().is_some() {1246
present.push(Foldable::Chat);1316
present.push(Foldable::Chat);1247
}1317
}1248
let fixed = fixed_controls_width(1318
let fixed = fixed_controls_width(model.can_use_camera(), has_more, has_leave_menu(model));1249
model.can_use_camera(),1250
has_more,1251
has_leave_menu(model),1252
shows_pop_out(call),1253
);1254
FoldedControls {1319
FoldedControls {1255
items: in_more_menu(folded_for_width(measured_stage(call).0, fixed, &present)),1320
items: folded_for_width(measured_stage(call).0, fixed, &present),1256
fullscreen,1321
fullscreen,1257
people_open: call.people_open,1322
people_open: call.people_open,1258
chat_open: call.chat_open,1323
chat_open: call.chat_open,@@ -1275,14 +1340,7 @@ pub fn render_call_view(1275
.w_full()1340
.w_full()1276
.h(px(HEADER_HEIGHT))1341
.h(px(HEADER_HEIGHT))1277
.flex_none()1342
.flex_none()1278
.pl(px(20.))1343
.px(px(20.))1279
.pr(px(HEADER_END_PADDING))1280
.gap(px(12.))1281
.items_center();1282
let title_group = h_flex()1283
.flex_1()1284
.flex_basis(px(0.))1285
.min_w_0()1286
.gap(px(12.))1344
.gap(px(12.))1287
.items_center()1345
.items_center()1288
.child(icon(IconName::Phone, 18., theme::accent_text()))1346
.child(icon(IconName::Phone, 18., theme::accent_text()))@@ -1304,59 +1362,40 @@ pub fn render_call_view(1304
.children(health_indicator(model))1362
.children(health_indicator(model))1305
.children(recording_chip(model))1363
.children(recording_chip(model))1306
.children(lock_chip(model))1364
.children(lock_chip(model))1307
.children(room_chip(model));1365
.children(room_chip(model))1308
let end_group = h_flex()1366
.child(div().flex_1())1309
.flex_1()1367
.children(return_button(app, model));1310
.flex_basis(px(0.))1311
.min_w_0()1312
.justify_end()1313
.gap(px(GROUP_GAP))1314
.items_center()1315
.children(return_button(app, model))1316
.child(leave_group(app, model));1317
1368
1318
let hold = hold_panel(app, model);1369
let hold = hold_panel(app, model);1319
let share_stage = share_stage_element(app, state, call);1370
let share_stage = share_stage_element(app, state, call);1320
let region = stage_region(app, state, call, now, hold, share_stage);1371
let region = stage_region(app, state, call, now, hold, share_stage);1321
1372
1322
let folded = folded_controls(state, call, fullscreen);1373
let folded = folded_controls(state, call, fullscreen);1323
let panels_and_reactions = h_flex()1374
let controls = h_flex()1324
.gap(px(TOOL_GAP))1375
.w_full()1325
.items_center()1376
.flex_none()1326
.when(1377
.py(px(16.))1327
model.has_reaction_controls() && !folded.folds(Foldable::Reactions),1378
.px(px(CONTROLS_PADDING))1328
|row| row.child(reactions_button(app, model)),1379
.gap(px(CONTROL_GAP))1329
)1330
.when(1331
call.chat_thread().is_some() && !folded.folds(Foldable::Chat),1332
|row| row.child(chat_button(app, call.chat_open, state.call_chat_unread())),1333
)1334
.when(1335
model.kind != CallKind::Test && !folded.folds(Foldable::People),1336
|row| row.child(people_button(app, call.people_open, model.raised_hands())),1337
);1338
let stage_and_more = h_flex()1339
.gap(px(TOOL_GAP))1340
.items_center()1341
.when(shows_pop_out(call), |row| row.child(pop_out_tool(app)))1342
.when(!folded.folds(Foldable::View), |row| {1343
row.child(view_button(app, model, fullscreen))1344
})1345
.children(more_button(app, model, &folded));1346
let devices = h_flex()1347
.gap(px(TOOL_GAP))1348
.items_center()1380
.items_center()1381
.justify_center()1349
.child(1382
.child(1350
h_flex()1383
h_flex()1351
.debug_selector(|| "shell/islands/main/call-header/controls/mic".into())1384
.debug_selector(|| "shell/islands/main/call-controls/mic".into())1385
.h(px(CONTROL_SIZE))1352
.items_center()1386
.items_center()1353
.child(toolbar_mic(app, model))1387
.rounded_full()1388
.bg(theme::surface_raised())1389
.child(mute_button(app, model, "call-mute", CONTROL_SIZE))1354
.child(mic_menu_button(app, model, state.call_mic)),1390
.child(mic_menu_button(app, model, state.call_mic)),1355
)1391
)1356
.child(1392
.child(1357
h_flex()1393
h_flex()1394
.h(px(CONTROL_SIZE))1358
.items_center()1395
.items_center()1359
.child(toolbar_camera(app, model))1396
.rounded_full()1397
.bg(theme::surface_raised())1398
.child(camera_button(app, model))1360
.children(camera_menu_button(app, model, CameraMenu::of(state))),1399
.children(camera_menu_button(app, model, CameraMenu::of(state))),1361
)1400
)1362
.child(share_button(1401
.child(share_button(@@ -1364,18 +1403,34 @@ pub fn render_call_view(1364
model,1403
model,1365
ShareOptions::of(state),1404
ShareOptions::of(state),1366
call.share_menu_open,1405
call.share_menu_open,1367
));1406
))1368
let controls = h_flex()1407
.when(1369
.debug_selector(|| "shell/islands/main/call-header/controls".into())1408
model.has_reaction_controls() && !folded.folds(Foldable::RaiseHand),1370
.flex_none()1409
|row| row.child(hand_button(app, model)),1371
.gap(px(GROUP_GAP))1410
)1372
.items_center()1411
.when(1373
.child(devices)1412
model.has_reaction_controls() && !folded.folds(Foldable::Reactions),1374
.child(group_divider())1413
|row| row.child(reactions_button(app, model)),1375
.child(panels_and_reactions)1414
)1376
.child(group_divider())1415
.when(!folded.folds(Foldable::View), |row| {1377
.child(stage_and_more);1416
row.child(view_button(app, model, fullscreen))1378
let header = header.child(title_group).child(controls).child(end_group);1417
})1418
.children(more_button(app, model, &folded))1419
.when(1420
model.kind != CallKind::Test && !folded.folds(Foldable::People),1421
|row| row.child(people_button(app, call.people_open, model.raised_hands())),1422
)1423
.when(1424
call.chat_thread().is_some() && !folded.folds(Foldable::Chat),1425
|row| row.child(chat_button(app, call.chat_open, state.call_chat_unread())),1426
)1427
.child(1428
leave_button(app, model, "call-leave", false)1429
.debug_selector(|| "shell/islands/main/call-controls/leave".into()),1430
)1431
.when(has_leave_menu(model), |row| {1432
row.child(leave_menu(app, model))1433
});1379
1434
1380
let top = v_flex()1435
let top = v_flex()1381
.w_full()1436
.w_full()@@ -1406,19 +1461,28 @@ pub fn render_call_view(1406
column.child(fullscreen_chrome("call-chrome-top", app, top))1461
column.child(fullscreen_chrome("call-chrome-top", app, top))1407
})1462
})1408
.child(region)1463
.child(region)1464
.when(chrome_visible, |column| {1465
column.child(fullscreen_chrome("call-chrome-bottom", app, controls))1466
})1409
} else {1467
} else {1410
base.rounded(px(10.))1468
base.rounded(px(10.))1411
.child(top.debug_selector(|| "shell/islands/main/call-header".into()))1469
.child(top.debug_selector(|| "shell/islands/main/call-header".into()))1412
.child(region)1470
.child(region)1471
.child(controls.debug_selector(|| "shell/islands/main/call-controls".into()))1413
}1472
}1414
.children(captions_overlay(model, now))1473
.children(captions_overlay(model, now))1415
.children(captions_hint_chip(model))1474
.children(captions_hint_chip(model))1416
.children(push_to_talk_chip(call))1475
.children(push_to_talk_chip(call))1417
.children(state.transfer_picker.clone())1476
.children(state.transfer_picker.clone())1418
.children(options_dialog(app, call))1477
.children(options_dialog(app, call))1419
.children(consent_overlay(app, model));1478
.children(consent_overlay(app, model))1479
.children(local_share_float(app, state));1480
let share_in_chat = call1481
.chat_open1482
.then(|| local_share_window(app, state, CHAT_PANEL_WIDTH))1483
.flatten();1420
let panels: Vec<AnyElement> = chat1484
let panels: Vec<AnyElement> = chat1421
.map(|chat| chat_panel(app, chat))1485
.map(|chat| chat_panel(app, share_in_chat, chat))1422
.into_iter()1486
.into_iter()1423
.chain(1487
.chain(1424
call.transcript_open1488
call.transcript_open@@ -1452,17 +1516,15 @@ fn side_panels(panels: Vec<AnyElement>, island_width: f32) -> Vec<AnyElement> {1452
if island_width - panels_width >= OVERLAY_BELOW {1516
if island_width - panels_width >= OVERLAY_BELOW {1453
return panels;1517
return panels;1454
}1518
}1455
vec![1519
vec![h_flex()1456
h_flex()1520
.absolute()1457
.absolute()1521
.top_0()1458
.top(px(HEADER_HEIGHT))1522
.right_0()1459
.right_0()1523
.bottom(px(CONTROLS_HEIGHT))1460
.bottom_0()1524
.gap(px(ISLAND_GAP))1461
.gap(px(ISLAND_GAP))1525
.w(px(panels_width.min(island_width)))1462
.w(px(panels_width.min(island_width)))1526
.children(panels)1463
.children(panels)1527
.into_any_element()]1464
.into_any_element(),1465
]1466
}1528
}1467
1529
1468
fn fullscreen_chrome(id: &'static str, app: &Entity<AppState>, content: Div) -> Stateful<Div> {1530
fn fullscreen_chrome(id: &'static str, app: &Entity<AppState>, content: Div) -> Stateful<Div> {@@ -1477,19 +1539,146 @@ fn fullscreen_chrome(id: &'static str, app: &Entity<AppState>, content: Div) ->1477
.child(content)1539
.child(content)1478
}1540
}1479
1541
1480
fn chat_panel(app: &Entity<AppState>, chat: AnyView) -> AnyElement {1542
fn chat_panel(app: &Entity<AppState>, share: Option<AnyElement>, chat: AnyView) -> AnyElement {1481
let app = app.clone();1543
let app = app.clone();1544
let body = v_flex()1545
.w_full()1546
.flex_1()1547
.min_h_0()1548
.children(share)1549
.child(div().flex_1().min_h_0().overflow_hidden().child(chat));1482
side_panel(1550
side_panel(1483
"call-chat-panel",1551
"call-chat-panel",1484
"Chat",1552
"Chat",1485
"Close the chat",1553
"Close the chat",1486
move |cx| app.update(cx, |state, cx| state.toggle_call_chat(cx)),1554
move |cx| app.update(cx, |state, cx| state.toggle_call_chat(cx)),1487
chat,1555
body,1488
)1556
)1489
.debug_selector(|| CHAT_PANEL_TAG.into())1557
.debug_selector(|| CHAT_PANEL_TAG.into())1490
.into_any_element()1558
.into_any_element()1491
}1559
}1492
1560
1561
const SHARE_WINDOW_INSET: f32 = 12.;1562
const SHARE_WINDOW_RATIO: f32 = 9. / 16.;1563
const SHARE_FLOAT_WIDTH: f32 = 320.;1564
1565
/// The live local share, pinned in the meeting chat or floating on the call1566
/// when the chat is closed.1567
fn local_share_window(app: &Entity<AppState>, state: &AppState, width: f32) -> Option<AnyElement> {1568
let call = state.call.as_ref()?;1569
let label = call.model.local_share.clone()?;1570
let image = call.pictures.live(&VideoKey::LocalScreen, Instant::now());1571
Some(share_window(app, &label, image, width))1572
}1573
1574
fn local_share_float(app: &Entity<AppState>, state: &AppState) -> Option<AnyElement> {1575
let call = state.call.as_ref()?;1576
if call.chat_open {1577
return None;1578
}1579
let window = local_share_window(app, state, SHARE_FLOAT_WIDTH)?;1580
Some(1581
div()1582
.absolute()1583
.right(px(16.))1584
.bottom(px(CONTROLS_HEIGHT + 12.))1585
.w(px(SHARE_FLOAT_WIDTH))1586
.rounded(px(10.))1587
.overflow_hidden()1588
.bg(theme::surface())1589
.shadow(theme::flyout_shadow())1590
.child(window)1591
.into_any_element(),1592
)1593
}1594
1595
fn share_window(1596
app: &Entity<AppState>,1597
label: &str,1598
image: Option<Arc<RenderImage>>,1599
width: f32,1600
) -> AnyElement {1601
let picture_width = (width - 2. * SHARE_WINDOW_INSET).max(0.);1602
let picture_height = picture_width * SHARE_WINDOW_RATIO;1603
let stop = app.clone();1604
v_flex()1605
.w_full()1606
.flex_none()1607
.p(px(SHARE_WINDOW_INSET))1608
.child(1609
div()1610
.id("call-share-window")1611
.relative()1612
.w(px(picture_width))1613
.h(px(picture_height))1614
.rounded(px(8.))1615
.overflow_hidden()1616
.bg(hsla(0., 0., 0.04, 1.))1617
.child(share_picture(image))1618
.child(1619
div()1620
.absolute()1621
.top(px(8.))1622
.left(px(8.))1623
.max_w(px(picture_width * 0.62))1624
.h(px(22.))1625
.px(px(8.))1626
.flex()1627
.items_center()1628
.rounded_full()1629
.bg(hsla(0., 0., 0., 0.6))1630
.text_size(px(11.))1631
.text_color(theme::white())1632
.child(div().truncate().child(label.to_owned())),1633
)1634
.child(share_stop(stop)),1635
)1636
.into_any_element()1637
}1638
1639
fn share_picture(image: Option<Arc<RenderImage>>) -> AnyElement {1640
let Some(image) = image else {1641
return div()1642
.size_full()1643
.flex()1644
.items_center()1645
.justify_center()1646
.px(px(12.))1647
.text_size(px(12.))1648
.text_color(theme::text_muted())1649
.child(WAITING_TEXT)1650
.into_any_element();1651
};1652
img(ImageSource::Render(image))1653
.size_full()1654
.object_fit(ObjectFit::Contain)1655
.into_any_element()1656
}1657
1658
fn share_stop(app: Entity<AppState>) -> Stateful<Div> {1659
div()1660
.id("call-share-window-stop")1661
.absolute()1662
.top(px(8.))1663
.right(px(8.))1664
.h(px(22.))1665
.px(px(8.))1666
.flex()1667
.items_center()1668
.rounded_full()1669
.bg(theme::red())1670
.text_color(theme::white())1671
.text_size(px(11.))1672
.font_weight(FontWeight::SEMIBOLD)1673
.cursor_pointer()1674
.hover(|button| button.opacity(0.85))1675
.child("Stop")1676
.on_click(move |_, _, cx| {1677
cx.stop_propagation();1678
app.update(cx, |state, cx| state.stop_call_share(cx));1679
})1680
}1681
1493
pub fn side_panel(1682
pub fn side_panel(1494
panel_id: &'static str,1683
panel_id: &'static str,1495
title: &'static str,1684
title: &'static str,@@ -1541,14 +1730,25 @@ pub fn side_panel(1541
1730
1542
#[cfg(test)]1731
#[cfg(test)]1543
mod tests {1732
mod tests {1544
use super::{TileSize, name_plate_metrics};1733
use super::{name_plate_metrics, TileSize};1545
1734
1546
#[test]1735
#[test]1547
fn small_strip_tiles_get_a_compact_name_plate() {1736
fn small_strip_tiles_get_a_compact_name_plate() {1548
let strip = name_plate_metrics(TileSize { width: 216., height: 121.5, avatar: 48. });1737
let strip = name_plate_metrics(TileSize {1549
assert_eq!((strip.text_size, strip.inset, strip.padding_y), (11., 4., 2.));1738
width: 216.,1739
height: 121.5,1740
avatar: 48.,1741
});1742
assert_eq!(1743
(strip.text_size, strip.inset, strip.padding_y),1744
(11., 4., 2.)1745
);1550
assert!(strip.max_width_share < 1.);1746
assert!(strip.max_width_share < 1.);1551
let stage = name_plate_metrics(TileSize { width: 640., height: 360., avatar: 96. });1747
let stage = name_plate_metrics(TileSize {1748
width: 640.,1749
height: 360.,1750
avatar: 96.,1751
});1552
assert_eq!((stage.text_size, stage.inset), (12., 8.));1752
assert_eq!((stage.text_size, stage.inset), (12., 8.));1553
}1753
}1554
}1754
}@@ -1,15 +1,17 @@
1
use std::sync::atomic::{AtomicBool, AtomicU32, Ordering};
1
2
use std::sync::{Arc, Mutex};
2
use std::sync::atomic::{AtomicU32, Ordering};
3
3
use std::time::Duration;
4
4
5
use libwebrtc::desktop_capturer::{CaptureSource, DesktopCaptureSourceType, DesktopCapturer, DesktopCapturerOptions};
5
use libwebrtc::desktop_capturer::{
6
CaptureSource, DesktopCaptureSourceType, DesktopCapturer, DesktopCapturerOptions,
7
PortalPickerEvent,
8
};
6
9
use libwebrtc::native::yuv_helper::argb_to_i420;
7
10
use libwebrtc::video_frame::I420Buffer;
8
11
9
12
use crate::capture::Capture;
10
use crate::video_frame::VideoPicture;
11
13
use crate::error::{Error, Result};
12
14
use crate::video_frame::VideoPicture;
13
15
14
16
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
15
17
pub enum ShareKind {
@@ -50,7 +52,9 @@ fn capturer(kind: ShareKind) -> Option<DesktopCapturer> {
50
52
}
51
53
52
54
fn sources_of(kind: ShareKind) -> Vec<(ShareSource, CaptureSource)> {
53
let Some(capturer) = capturer(kind) else { return Vec::new() };
55
let Some(capturer) = capturer(kind) else {
56
return Vec::new();
57
};
54
58
capturer
55
59
.get_source_list()
56
60
.into_iter()
@@ -77,22 +81,34 @@ pub fn list_share_sources() -> Vec<ShareSource> {
77
81
const THUMBNAIL_ATTEMPTS: u32 = 5;
78
82
const THUMBNAIL_RETRY: Duration = Duration::from_millis(40);
79
83
80
pub fn share_thumbnail(wanted: &ShareSource, max_width: u32, max_height: u32) -> Option<VideoPicture> {
81
let source = sources_of(wanted.kind).into_iter().find(|(source, _)| source.id == wanted.id).map(|(_, raw)| raw)?;
84
pub fn share_thumbnail(
85
wanted: &ShareSource,
86
max_width: u32,
87
max_height: u32,
88
) -> Option<VideoPicture> {
89
let source = sources_of(wanted.kind)
90
.into_iter()
91
.find(|(source, _)| source.id == wanted.id)
92
.map(|(_, raw)| raw)?;
82
93
let mut capturer = capturer(wanted.kind)?;
83
94
let captured: Arc<Mutex<Option<VideoPicture>>> = Arc::default();
84
95
let sink = captured.clone();
85
96
capturer.start_capture(Some(source), move |result| {
86
97
let Ok(frame) = result else { return };
87
98
let (width, height) = (frame.width().max(0) as u32, frame.height().max(0) as u32);
88
if let Some(picture) = scaled_bgra(frame.data(), width, height, frame.stride(), max_width, max_height)
89
&& let Ok(mut slot) = sink.lock()
99
if let Some(picture) = scaled_bgra(
100
frame.data(),
101
width,
102
height,
103
frame.stride(),
104
max_width,
105
max_height,
106
) && let Ok(mut slot) = sink.lock()
90
107
{
91
108
*slot = Some(picture);
92
109
}
93
110
});
94
111
for _ in 0..THUMBNAIL_ATTEMPTS {
95
pump_messages();
96
112
capturer.capture_frame();
97
113
if let Some(picture) = captured.lock().ok().and_then(|mut slot| slot.take()) {
98
114
return Some(picture);
@@ -102,28 +118,28 @@ pub fn share_thumbnail(wanted: &ShareSource, max_width: u32, max_height: u32) ->
102
118
None
103
119
}
104
120
105
// Windows Graphics Capture hands frames to a DispatcherQueue on this thread; without a pump none arrive.
106
#[cfg(windows)]
107
fn pump_messages() {
108
use windows::Win32::UI::WindowsAndMessaging::{DispatchMessageW, MSG, PM_REMOVE, PeekMessageW, TranslateMessage};
109
let mut message = MSG::default();
110
unsafe {
111
while PeekMessageW(&mut message, None, 0, 0, PM_REMOVE).as_bool() {
112
let _ = TranslateMessage(&message);
113
let _ = DispatchMessageW(&message);
114
}
115
}
116
}
117
118
#[cfg(not(windows))]
119
fn pump_messages() {}
120
121
fn scaled_bgra(bytes: &[u8], width: u32, height: u32, stride: u32, max_width: u32, max_height: u32) -> Option<VideoPicture> {
122
if width == 0 || height == 0 || (stride as usize) < width as usize * 4 || bytes.len() < stride as usize * height as usize {
121
fn scaled_bgra(
122
bytes: &[u8],
123
width: u32,
124
height: u32,
125
stride: u32,
126
max_width: u32,
127
max_height: u32,
128
) -> Option<VideoPicture> {
129
if width == 0
130
|| height == 0
131
|| (stride as usize) < width as usize * 4
132
|| bytes.len() < stride as usize * height as usize
133
{
123
134
return None;
124
135
}
125
let scale = (max_width as f32 / width as f32).min(max_height as f32 / height as f32).min(1.);
126
let (target_width, target_height) = (((width as f32 * scale) as u32).max(1), ((height as f32 * scale) as u32).max(1));
136
let scale = (max_width as f32 / width as f32)
137
.min(max_height as f32 / height as f32)
138
.min(1.);
139
let (target_width, target_height) = (
140
((width as f32 * scale) as u32).max(1),
141
((height as f32 * scale) as u32).max(1),
142
);
127
143
let mut bgra = Vec::with_capacity(target_width as usize * target_height as usize * 4);
128
144
for row in 0..target_height {
129
145
let source_row = (row as u64 * height as u64 / target_height as u64) as usize;
@@ -133,14 +149,29 @@ fn scaled_bgra(bytes: &[u8], width: u32, height: u32, stride: u32, max_width: u3
133
149
bgra.extend_from_slice(&[bytes[offset], bytes[offset + 1], bytes[offset + 2], u8::MAX]);
134
150
}
135
151
}
136
Some(VideoPicture { width: target_width, height: target_height, bgra })
152
Some(VideoPicture {
153
width: target_width,
154
height: target_height,
155
bgra,
156
})
137
157
}
138
158
139
159
fn i420_from_bgra(bytes: &[u8], width: u32, height: u32, stride: u32) -> I420Buffer {
140
160
let mut buffer = I420Buffer::new(width, height);
141
161
let (stride_y, stride_u, stride_v) = buffer.strides();
142
162
let (plane_y, plane_u, plane_v) = buffer.data_mut();
143
argb_to_i420(bytes, stride, plane_y, stride_y, plane_u, stride_u, plane_v, stride_v, width as i32, height as i32);
163
argb_to_i420(
164
bytes,
165
stride,
166
plane_y,
167
stride_y,
168
plane_u,
169
stride_u,
170
plane_v,
171
stride_v,
172
width as i32,
173
height as i32,
174
);
144
175
buffer
145
176
}
146
177
@@ -150,8 +181,19 @@ pub fn start_screen_capture(
150
181
mut deliver: impl FnMut(I420Buffer) + Send + 'static,
151
182
failed: impl FnOnce(String) + Send + 'static,
152
183
) -> Result<Capture> {
184
if current_share_picker() == SharePicker::Portal {
185
return start_portal_capture(wanted.kind, fps, deliver, move |follow| {
186
if let PortalFollowUp::Notice(text) = follow {
187
failed(text.to_owned());
188
}
189
});
190
}
153
191
Capture::spawn_thread("screen-capture", move |stop| {
154
let Some(source) = sources_of(wanted.kind).into_iter().find(|(source, _)| source.id == wanted.id).map(|(_, raw)| raw) else {
192
let Some(source) = sources_of(wanted.kind)
193
.into_iter()
194
.find(|(source, _)| source.id == wanted.id)
195
.map(|(_, raw)| raw)
196
else {
155
197
return failed("the shared source is gone".to_owned());
156
198
};
157
199
let Some(mut capturer) = capturer(wanted.kind) else {
@@ -165,7 +207,6 @@ pub fn start_screen_capture(
165
207
}
166
208
});
167
209
while !stop.load(Ordering::SeqCst) {
168
pump_messages();
169
210
capturer.capture_frame();
170
211
std::thread::sleep(Duration::from_secs(1) / fps.load(Ordering::Relaxed).max(1));
171
212
}
@@ -173,15 +214,147 @@ pub fn start_screen_capture(
173
214
.map_err(|error| Error::Webrtc(format!("screen thread: {error}")))
174
215
}
175
216
217
/// Where the share menu gets its sources. Wayland uses the desktop dialog.
218
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
219
pub enum SharePicker {
220
List,
221
Portal,
222
}
223
224
pub fn share_picker_for(wayland_display: Option<&str>) -> SharePicker {
225
match wayland_display {
226
Some(value) if !value.is_empty() => SharePicker::Portal,
227
_ => SharePicker::List,
228
}
229
}
230
231
pub fn current_share_picker() -> SharePicker {
232
share_picker_for(std::env::var("WAYLAND_DISPLAY").ok().as_deref())
233
}
234
235
/// Portal menus must not enumerate or thumbnail sources. That would open the dialog early.
236
pub fn share_sources_for_menu(picker: SharePicker, sources: Vec<ShareSource>) -> Vec<ShareSource> {
237
match picker {
238
SharePicker::Portal => Vec::new(),
239
SharePicker::List => sources,
240
}
241
}
242
243
pub const PORTAL_UNAVAILABLE_NOTICE: &str =
244
"Screen sharing needs the desktop share dialog, and it could not open.";
245
246
#[derive(Debug, Clone, PartialEq, Eq)]
247
pub enum PortalFollowUp {
248
Share(ShareSource),
249
Quiet,
250
Notice(&'static str),
251
}
252
253
pub fn portal_follow_up(event: PortalPickerEvent, source: Option<ShareSource>) -> PortalFollowUp {
254
match event {
255
PortalPickerEvent::Selected => match source {
256
Some(source) => PortalFollowUp::Share(source),
257
None => PortalFollowUp::Notice(PORTAL_UNAVAILABLE_NOTICE),
258
},
259
PortalPickerEvent::Cancelled => PortalFollowUp::Quiet,
260
PortalPickerEvent::Failed => PortalFollowUp::Notice(PORTAL_UNAVAILABLE_NOTICE),
261
}
262
}
263
264
pub(crate) fn start_portal_capture(
265
kind: ShareKind,
266
fps: Arc<AtomicU32>,
267
mut deliver: impl FnMut(I420Buffer) + Send + 'static,
268
outcome: impl FnOnce(PortalFollowUp) + Send + 'static,
269
) -> Result<Capture> {
270
Capture::spawn_thread("portal-share", move |stop| {
271
libwebrtc::desktop_capturer::ensure_shared_glib_loop();
272
let Some(mut capturer) = capturer(kind) else {
273
outcome(PortalFollowUp::Notice(PORTAL_UNAVAILABLE_NOTICE));
274
return;
275
};
276
let selected = Arc::new(AtomicBool::new(false));
277
let gate = selected.clone();
278
capturer.start_capture(None, move |result| {
279
if !gate.load(Ordering::SeqCst) {
280
return;
281
}
282
let Ok(frame) = result else { return };
283
let (width, height) = (frame.width() as u32 & !1, frame.height() as u32 & !1);
284
if width >= 2 && height >= 2 {
285
deliver(i420_from_bgra(frame.data(), width, height, frame.stride()));
286
}
287
});
288
if !capturer.has_delegated_picker() {
289
outcome(PortalFollowUp::Notice(PORTAL_UNAVAILABLE_NOTICE));
290
return;
291
}
292
let (sender, receiver) = std::sync::mpsc::channel();
293
capturer.watch_picker(move |event| {
294
let _ = sender.send(event);
295
});
296
capturer.ensure_picker_visible();
297
let event = loop {
298
if stop.load(Ordering::SeqCst) {
299
return;
300
}
301
match receiver.recv_timeout(Duration::from_millis(40)) {
302
Ok(event) => break event,
303
Err(std::sync::mpsc::RecvTimeoutError::Timeout) => continue,
304
Err(std::sync::mpsc::RecvTimeoutError::Disconnected) => {
305
outcome(PortalFollowUp::Notice(PORTAL_UNAVAILABLE_NOTICE));
306
return;
307
}
308
}
309
};
310
if stop.load(Ordering::SeqCst) {
311
return;
312
}
313
// The portal already bound this stream. Looking the source up again, or
314
// selecting that id, is what used to tear the stream down and report
315
// "the shared source is gone".
316
let source = if event == PortalPickerEvent::Selected {
317
selected.store(true, Ordering::SeqCst);
318
Some(ShareSource {
319
id: 0,
320
kind,
321
title: String::new(),
322
})
323
} else {
324
None
325
};
326
let follow = portal_follow_up(event, source);
327
if !matches!(follow, PortalFollowUp::Share(_)) {
328
outcome(follow);
329
return;
330
}
331
capturer.capture_frame();
332
outcome(follow);
333
while !stop.load(Ordering::SeqCst) {
334
capturer.capture_frame();
335
std::thread::sleep(Duration::from_secs(1) / fps.load(Ordering::Relaxed).max(1));
336
}
337
})
338
.map_err(|error| Error::Webrtc(format!("portal thread: {error}")))
339
}
340
176
341
#[cfg(test)]
177
342
mod tests {
178
343
use super::*;
179
344
180
345
#[test]
181
346
fn sources_get_readable_labels() {
182
let screen = ShareSource { id: 1, kind: ShareKind::Screen, title: String::new() };
347
let screen = ShareSource {
348
id: 1,
349
kind: ShareKind::Screen,
350
title: String::new(),
351
};
183
352
assert_eq!(screen.label(), "Entire screen");
184
let window = ShareSource { id: 2, kind: ShareKind::Window, title: " Notes ".into() };
353
let window = ShareSource {
354
id: 2,
355
kind: ShareKind::Window,
356
title: " Notes ".into(),
357
};
185
358
assert_eq!(window.label(), "Notes");
186
359
}
187
360
}
@@ -207,3 +380,116 @@ mod thumbnail_tests {
207
380
assert!(scaled_bgra(&bytes, width, height, 8, 4, 4).is_none());
208
381
}
209
382
}
383
384
#[cfg(test)]
385
mod portal_mode_tests {
386
use super::{ShareKind, SharePicker, ShareSource, share_picker_for, share_sources_for_menu};
387
388
#[test]
389
fn portal_mode_follows_wayland_display_and_skips_the_menu_list() {
390
assert_eq!(share_picker_for(None), SharePicker::List);
391
assert_eq!(share_picker_for(Some("")), SharePicker::List);
392
assert_eq!(share_picker_for(Some("wayland-1")), SharePicker::Portal);
393
let sources = vec![ShareSource {
394
id: 1,
395
kind: ShareKind::Screen,
396
title: "Desk".into(),
397
}];
398
assert!(share_sources_for_menu(SharePicker::Portal, sources.clone()).is_empty());
399
assert_eq!(
400
share_sources_for_menu(SharePicker::List, sources.clone()),
401
sources
402
);
403
}
404
}
405
406
#[cfg(test)]
407
mod portal_share_tests {
408
use libwebrtc::desktop_capturer::PortalPickerEvent;
409
410
use super::{
411
PORTAL_UNAVAILABLE_NOTICE, PortalFollowUp, ShareKind, ShareSource, portal_follow_up,
412
};
413
414
#[test]
415
fn portal_share_cancel_is_quiet_and_failure_is_a_notice() {
416
let source = ShareSource {
417
id: 7,
418
kind: ShareKind::Screen,
419
title: "Desk".into(),
420
};
421
assert!(matches!(
422
portal_follow_up(PortalPickerEvent::Selected, Some(source.clone())),
423
PortalFollowUp::Share(chosen) if chosen == source
424
));
425
assert!(matches!(
426
portal_follow_up(PortalPickerEvent::Selected, None),
427
PortalFollowUp::Notice(PORTAL_UNAVAILABLE_NOTICE)
428
));
429
assert!(matches!(
430
portal_follow_up(PortalPickerEvent::Cancelled, Some(source.clone())),
431
PortalFollowUp::Quiet
432
));
433
assert!(matches!(
434
portal_follow_up(PortalPickerEvent::Failed, Some(source)),
435
PortalFollowUp::Notice(PORTAL_UNAVAILABLE_NOTICE)
436
));
437
}
438
}
439
440
#[cfg(all(test, target_os = "linux"))]
441
mod portal_loop_tests {
442
#[test]
443
fn portal_loop_stays_up_across_ensures() {
444
libwebrtc::desktop_capturer::ensure_shared_glib_loop();
445
let id = libwebrtc::desktop_capturer::shared_glib_loop_id();
446
assert_ne!(id, 0);
447
libwebrtc::desktop_capturer::ensure_shared_glib_loop();
448
assert_eq!(id, libwebrtc::desktop_capturer::shared_glib_loop_id());
449
}
450
}
451
452
#[cfg(all(test, target_os = "linux"))]
453
mod portal_smoke {
454
use std::sync::Arc;
455
use std::sync::atomic::{AtomicU32, Ordering};
456
use std::time::Duration;
457
458
use super::{PortalFollowUp, ShareKind, start_portal_capture};
459
460
#[test]
461
fn portal_smoke_captures_after_the_dialog() {
462
if std::env::var("PORTAL_SMOKE").ok().as_deref() != Some("1") {
463
return;
464
}
465
let frames = Arc::new(AtomicU32::new(0));
466
let counter = frames.clone();
467
let (sender, receiver) = std::sync::mpsc::channel();
468
let capture = start_portal_capture(
469
ShareKind::Screen,
470
Arc::new(AtomicU32::new(5)),
471
move |_| {
472
counter.fetch_add(1, Ordering::Relaxed);
473
},
474
move |follow| {
475
eprintln!("PORTAL_FOLLOW={follow:?}");
476
let _ = sender.send(follow);
477
},
478
)
479
.expect("portal thread");
480
let follow = receiver
481
.recv_timeout(Duration::from_secs(40))
482
.expect("no portal result in 40s");
483
std::thread::sleep(Duration::from_millis(700));
484
let count = frames.load(Ordering::Relaxed);
485
eprintln!("PORTAL_FRAMES={count}");
486
drop(capture);
487
match follow {
488
PortalFollowUp::Share(_) => {
489
assert!(count > 0, "the dialog confirmed, but no frame arrived")
490
}
491
PortalFollowUp::Quiet => panic!("the dialog was cancelled"),
492
PortalFollowUp::Notice(text) => panic!("portal notice: {text}"),
493
}
494
}
495
}
@@ -1,15 +1,17 @@1
use std::sync::atomic::{AtomicBool, AtomicU32, Ordering};1
use std::sync::{Arc, Mutex};2
use std::sync::{Arc, Mutex};2
use std::sync::atomic::{AtomicU32, Ordering};3
use std::time::Duration;3
use std::time::Duration;4
4
5
use libwebrtc::desktop_capturer::{CaptureSource, DesktopCaptureSourceType, DesktopCapturer, DesktopCapturerOptions};5
use libwebrtc::desktop_capturer::{6
CaptureSource, DesktopCaptureSourceType, DesktopCapturer, DesktopCapturerOptions,7
PortalPickerEvent,8
};6
use libwebrtc::native::yuv_helper::argb_to_i420;9
use libwebrtc::native::yuv_helper::argb_to_i420;7
use libwebrtc::video_frame::I420Buffer;10
use libwebrtc::video_frame::I420Buffer;8
11
9
use crate::capture::Capture;12
use crate::capture::Capture;10
use crate::video_frame::VideoPicture;11
use crate::error::{Error, Result};13
use crate::error::{Error, Result};12
14
use crate::video_frame::VideoPicture;13
15
14
#[derive(Debug, Clone, Copy, PartialEq, Eq)]16
#[derive(Debug, Clone, Copy, PartialEq, Eq)]15
pub enum ShareKind {17
pub enum ShareKind {@@ -50,7 +52,9 @@ fn capturer(kind: ShareKind) -> Option<DesktopCapturer> {50
}52
}51
53
52
fn sources_of(kind: ShareKind) -> Vec<(ShareSource, CaptureSource)> {54
fn sources_of(kind: ShareKind) -> Vec<(ShareSource, CaptureSource)> {53
let Some(capturer) = capturer(kind) else { return Vec::new() };55
let Some(capturer) = capturer(kind) else {56
return Vec::new();57
};54
capturer58
capturer55
.get_source_list()59
.get_source_list()56
.into_iter()60
.into_iter()@@ -77,22 +81,34 @@ pub fn list_share_sources() -> Vec<ShareSource> {77
const THUMBNAIL_ATTEMPTS: u32 = 5;81
const THUMBNAIL_ATTEMPTS: u32 = 5;78
const THUMBNAIL_RETRY: Duration = Duration::from_millis(40);82
const THUMBNAIL_RETRY: Duration = Duration::from_millis(40);79
83
80
pub fn share_thumbnail(wanted: &ShareSource, max_width: u32, max_height: u32) -> Option<VideoPicture> {84
pub fn share_thumbnail(81
let source = sources_of(wanted.kind).into_iter().find(|(source, _)| source.id == wanted.id).map(|(_, raw)| raw)?;85
wanted: &ShareSource,86
max_width: u32,87
max_height: u32,88
) -> Option<VideoPicture> {89
let source = sources_of(wanted.kind)90
.into_iter()91
.find(|(source, _)| source.id == wanted.id)92
.map(|(_, raw)| raw)?;82
let mut capturer = capturer(wanted.kind)?;93
let mut capturer = capturer(wanted.kind)?;83
let captured: Arc<Mutex<Option<VideoPicture>>> = Arc::default();94
let captured: Arc<Mutex<Option<VideoPicture>>> = Arc::default();84
let sink = captured.clone();95
let sink = captured.clone();85
capturer.start_capture(Some(source), move |result| {96
capturer.start_capture(Some(source), move |result| {86
let Ok(frame) = result else { return };97
let Ok(frame) = result else { return };87
let (width, height) = (frame.width().max(0) as u32, frame.height().max(0) as u32);98
let (width, height) = (frame.width().max(0) as u32, frame.height().max(0) as u32);88
if let Some(picture) = scaled_bgra(frame.data(), width, height, frame.stride(), max_width, max_height)99
if let Some(picture) = scaled_bgra(89
&& let Ok(mut slot) = sink.lock()100
frame.data(),101
width,102
height,103
frame.stride(),104
max_width,105
max_height,106
) && let Ok(mut slot) = sink.lock()90
{107
{91
*slot = Some(picture);108
*slot = Some(picture);92
}109
}93
});110
});94
for _ in 0..THUMBNAIL_ATTEMPTS {111
for _ in 0..THUMBNAIL_ATTEMPTS {95
pump_messages();96
capturer.capture_frame();112
capturer.capture_frame();97
if let Some(picture) = captured.lock().ok().and_then(|mut slot| slot.take()) {113
if let Some(picture) = captured.lock().ok().and_then(|mut slot| slot.take()) {98
return Some(picture);114
return Some(picture);@@ -102,28 +118,28 @@ pub fn share_thumbnail(wanted: &ShareSource, max_width: u32, max_height: u32) ->102
None118
None103
}119
}104
120
105
// Windows Graphics Capture hands frames to a DispatcherQueue on this thread; without a pump none arrive.121
fn scaled_bgra(106
#[cfg(windows)]122
bytes: &[u8],107
fn pump_messages() {123
width: u32,108
use windows::Win32::UI::WindowsAndMessaging::{DispatchMessageW, MSG, PM_REMOVE, PeekMessageW, TranslateMessage};124
height: u32,109
let mut message = MSG::default();125
stride: u32,110
unsafe {126
max_width: u32,111
while PeekMessageW(&mut message, None, 0, 0, PM_REMOVE).as_bool() {127
max_height: u32,112
let _ = TranslateMessage(&message);128
) -> Option<VideoPicture> {113
let _ = DispatchMessageW(&message);129
if width == 0114
}130
|| height == 0115
}131
|| (stride as usize) < width as usize * 4116
}132
|| bytes.len() < stride as usize * height as usize117
133
{118
#[cfg(not(windows))]119
fn pump_messages() {}120
121
fn scaled_bgra(bytes: &[u8], width: u32, height: u32, stride: u32, max_width: u32, max_height: u32) -> Option<VideoPicture> {122
if width == 0 || height == 0 || (stride as usize) < width as usize * 4 || bytes.len() < stride as usize * height as usize {123
return None;134
return None;124
}135
}125
let scale = (max_width as f32 / width as f32).min(max_height as f32 / height as f32).min(1.);136
let scale = (max_width as f32 / width as f32)126
let (target_width, target_height) = (((width as f32 * scale) as u32).max(1), ((height as f32 * scale) as u32).max(1));137
.min(max_height as f32 / height as f32)138
.min(1.);139
let (target_width, target_height) = (140
((width as f32 * scale) as u32).max(1),141
((height as f32 * scale) as u32).max(1),142
);127
let mut bgra = Vec::with_capacity(target_width as usize * target_height as usize * 4);143
let mut bgra = Vec::with_capacity(target_width as usize * target_height as usize * 4);128
for row in 0..target_height {144
for row in 0..target_height {129
let source_row = (row as u64 * height as u64 / target_height as u64) as usize;145
let source_row = (row as u64 * height as u64 / target_height as u64) as usize;@@ -133,14 +149,29 @@ fn scaled_bgra(bytes: &[u8], width: u32, height: u32, stride: u32, max_width: u3133
bgra.extend_from_slice(&[bytes[offset], bytes[offset + 1], bytes[offset + 2], u8::MAX]);149
bgra.extend_from_slice(&[bytes[offset], bytes[offset + 1], bytes[offset + 2], u8::MAX]);134
}150
}135
}151
}136
Some(VideoPicture { width: target_width, height: target_height, bgra })152
Some(VideoPicture {153
width: target_width,154
height: target_height,155
bgra,156
})137
}157
}138
158
139
fn i420_from_bgra(bytes: &[u8], width: u32, height: u32, stride: u32) -> I420Buffer {159
fn i420_from_bgra(bytes: &[u8], width: u32, height: u32, stride: u32) -> I420Buffer {140
let mut buffer = I420Buffer::new(width, height);160
let mut buffer = I420Buffer::new(width, height);141
let (stride_y, stride_u, stride_v) = buffer.strides();161
let (stride_y, stride_u, stride_v) = buffer.strides();142
let (plane_y, plane_u, plane_v) = buffer.data_mut();162
let (plane_y, plane_u, plane_v) = buffer.data_mut();143
argb_to_i420(bytes, stride, plane_y, stride_y, plane_u, stride_u, plane_v, stride_v, width as i32, height as i32);163
argb_to_i420(164
bytes,165
stride,166
plane_y,167
stride_y,168
plane_u,169
stride_u,170
plane_v,171
stride_v,172
width as i32,173
height as i32,174
);144
buffer175
buffer145
}176
}146
177
@@ -150,8 +181,19 @@ pub fn start_screen_capture(150
mut deliver: impl FnMut(I420Buffer) + Send + 'static,181
mut deliver: impl FnMut(I420Buffer) + Send + 'static,151
failed: impl FnOnce(String) + Send + 'static,182
failed: impl FnOnce(String) + Send + 'static,152
) -> Result<Capture> {183
) -> Result<Capture> {184
if current_share_picker() == SharePicker::Portal {185
return start_portal_capture(wanted.kind, fps, deliver, move |follow| {186
if let PortalFollowUp::Notice(text) = follow {187
failed(text.to_owned());188
}189
});190
}153
Capture::spawn_thread("screen-capture", move |stop| {191
Capture::spawn_thread("screen-capture", move |stop| {154
let Some(source) = sources_of(wanted.kind).into_iter().find(|(source, _)| source.id == wanted.id).map(|(_, raw)| raw) else {192
let Some(source) = sources_of(wanted.kind)193
.into_iter()194
.find(|(source, _)| source.id == wanted.id)195
.map(|(_, raw)| raw)196
else {155
return failed("the shared source is gone".to_owned());197
return failed("the shared source is gone".to_owned());156
};198
};157
let Some(mut capturer) = capturer(wanted.kind) else {199
let Some(mut capturer) = capturer(wanted.kind) else {@@ -165,7 +207,6 @@ pub fn start_screen_capture(165
}207
}166
});208
});167
while !stop.load(Ordering::SeqCst) {209
while !stop.load(Ordering::SeqCst) {168
pump_messages();169
capturer.capture_frame();210
capturer.capture_frame();170
std::thread::sleep(Duration::from_secs(1) / fps.load(Ordering::Relaxed).max(1));211
std::thread::sleep(Duration::from_secs(1) / fps.load(Ordering::Relaxed).max(1));171
}212
}@@ -173,15 +214,147 @@ pub fn start_screen_capture(173
.map_err(|error| Error::Webrtc(format!("screen thread: {error}")))214
.map_err(|error| Error::Webrtc(format!("screen thread: {error}")))174
}215
}175
216
217
/// Where the share menu gets its sources. Wayland uses the desktop dialog.218
#[derive(Debug, Clone, Copy, PartialEq, Eq)]219
pub enum SharePicker {220
List,221
Portal,222
}223
224
pub fn share_picker_for(wayland_display: Option<&str>) -> SharePicker {225
match wayland_display {226
Some(value) if !value.is_empty() => SharePicker::Portal,227
_ => SharePicker::List,228
}229
}230
231
pub fn current_share_picker() -> SharePicker {232
share_picker_for(std::env::var("WAYLAND_DISPLAY").ok().as_deref())233
}234
235
/// Portal menus must not enumerate or thumbnail sources. That would open the dialog early.236
pub fn share_sources_for_menu(picker: SharePicker, sources: Vec<ShareSource>) -> Vec<ShareSource> {237
match picker {238
SharePicker::Portal => Vec::new(),239
SharePicker::List => sources,240
}241
}242
243
pub const PORTAL_UNAVAILABLE_NOTICE: &str =244
"Screen sharing needs the desktop share dialog, and it could not open.";245
246
#[derive(Debug, Clone, PartialEq, Eq)]247
pub enum PortalFollowUp {248
Share(ShareSource),249
Quiet,250
Notice(&'static str),251
}252
253
pub fn portal_follow_up(event: PortalPickerEvent, source: Option<ShareSource>) -> PortalFollowUp {254
match event {255
PortalPickerEvent::Selected => match source {256
Some(source) => PortalFollowUp::Share(source),257
None => PortalFollowUp::Notice(PORTAL_UNAVAILABLE_NOTICE),258
},259
PortalPickerEvent::Cancelled => PortalFollowUp::Quiet,260
PortalPickerEvent::Failed => PortalFollowUp::Notice(PORTAL_UNAVAILABLE_NOTICE),261
}262
}263
264
pub(crate) fn start_portal_capture(265
kind: ShareKind,266
fps: Arc<AtomicU32>,267
mut deliver: impl FnMut(I420Buffer) + Send + 'static,268
outcome: impl FnOnce(PortalFollowUp) + Send + 'static,269
) -> Result<Capture> {270
Capture::spawn_thread("portal-share", move |stop| {271
libwebrtc::desktop_capturer::ensure_shared_glib_loop();272
let Some(mut capturer) = capturer(kind) else {273
outcome(PortalFollowUp::Notice(PORTAL_UNAVAILABLE_NOTICE));274
return;275
};276
let selected = Arc::new(AtomicBool::new(false));277
let gate = selected.clone();278
capturer.start_capture(None, move |result| {279
if !gate.load(Ordering::SeqCst) {280
return;281
}282
let Ok(frame) = result else { return };283
let (width, height) = (frame.width() as u32 & !1, frame.height() as u32 & !1);284
if width >= 2 && height >= 2 {285
deliver(i420_from_bgra(frame.data(), width, height, frame.stride()));286
}287
});288
if !capturer.has_delegated_picker() {289
outcome(PortalFollowUp::Notice(PORTAL_UNAVAILABLE_NOTICE));290
return;291
}292
let (sender, receiver) = std::sync::mpsc::channel();293
capturer.watch_picker(move |event| {294
let _ = sender.send(event);295
});296
capturer.ensure_picker_visible();297
let event = loop {298
if stop.load(Ordering::SeqCst) {299
return;300
}301
match receiver.recv_timeout(Duration::from_millis(40)) {302
Ok(event) => break event,303
Err(std::sync::mpsc::RecvTimeoutError::Timeout) => continue,304
Err(std::sync::mpsc::RecvTimeoutError::Disconnected) => {305
outcome(PortalFollowUp::Notice(PORTAL_UNAVAILABLE_NOTICE));306
return;307
}308
}309
};310
if stop.load(Ordering::SeqCst) {311
return;312
}313
// The portal already bound this stream. Looking the source up again, or314
// selecting that id, is what used to tear the stream down and report315
// "the shared source is gone".316
let source = if event == PortalPickerEvent::Selected {317
selected.store(true, Ordering::SeqCst);318
Some(ShareSource {319
id: 0,320
kind,321
title: String::new(),322
})323
} else {324
None325
};326
let follow = portal_follow_up(event, source);327
if !matches!(follow, PortalFollowUp::Share(_)) {328
outcome(follow);329
return;330
}331
capturer.capture_frame();332
outcome(follow);333
while !stop.load(Ordering::SeqCst) {334
capturer.capture_frame();335
std::thread::sleep(Duration::from_secs(1) / fps.load(Ordering::Relaxed).max(1));336
}337
})338
.map_err(|error| Error::Webrtc(format!("portal thread: {error}")))339
}340
176
#[cfg(test)]341
#[cfg(test)]177
mod tests {342
mod tests {178
use super::*;343
use super::*;179
344
180
#[test]345
#[test]181
fn sources_get_readable_labels() {346
fn sources_get_readable_labels() {182
let screen = ShareSource { id: 1, kind: ShareKind::Screen, title: String::new() };347
let screen = ShareSource {348
id: 1,349
kind: ShareKind::Screen,350
title: String::new(),351
};183
assert_eq!(screen.label(), "Entire screen");352
assert_eq!(screen.label(), "Entire screen");184
let window = ShareSource { id: 2, kind: ShareKind::Window, title: " Notes ".into() };353
let window = ShareSource {354
id: 2,355
kind: ShareKind::Window,356
title: " Notes ".into(),357
};185
assert_eq!(window.label(), "Notes");358
assert_eq!(window.label(), "Notes");186
}359
}187
}360
}@@ -207,3 +380,116 @@ mod thumbnail_tests {207
assert!(scaled_bgra(&bytes, width, height, 8, 4, 4).is_none());380
assert!(scaled_bgra(&bytes, width, height, 8, 4, 4).is_none());208
}381
}209
}382
}383
384
#[cfg(test)]385
mod portal_mode_tests {386
use super::{ShareKind, SharePicker, ShareSource, share_picker_for, share_sources_for_menu};387
388
#[test]389
fn portal_mode_follows_wayland_display_and_skips_the_menu_list() {390
assert_eq!(share_picker_for(None), SharePicker::List);391
assert_eq!(share_picker_for(Some("")), SharePicker::List);392
assert_eq!(share_picker_for(Some("wayland-1")), SharePicker::Portal);393
let sources = vec![ShareSource {394
id: 1,395
kind: ShareKind::Screen,396
title: "Desk".into(),397
}];398
assert!(share_sources_for_menu(SharePicker::Portal, sources.clone()).is_empty());399
assert_eq!(400
share_sources_for_menu(SharePicker::List, sources.clone()),401
sources402
);403
}404
}405
406
#[cfg(test)]407
mod portal_share_tests {408
use libwebrtc::desktop_capturer::PortalPickerEvent;409
410
use super::{411
PORTAL_UNAVAILABLE_NOTICE, PortalFollowUp, ShareKind, ShareSource, portal_follow_up,412
};413
414
#[test]415
fn portal_share_cancel_is_quiet_and_failure_is_a_notice() {416
let source = ShareSource {417
id: 7,418
kind: ShareKind::Screen,419
title: "Desk".into(),420
};421
assert!(matches!(422
portal_follow_up(PortalPickerEvent::Selected, Some(source.clone())),423
PortalFollowUp::Share(chosen) if chosen == source424
));425
assert!(matches!(426
portal_follow_up(PortalPickerEvent::Selected, None),427
PortalFollowUp::Notice(PORTAL_UNAVAILABLE_NOTICE)428
));429
assert!(matches!(430
portal_follow_up(PortalPickerEvent::Cancelled, Some(source.clone())),431
PortalFollowUp::Quiet432
));433
assert!(matches!(434
portal_follow_up(PortalPickerEvent::Failed, Some(source)),435
PortalFollowUp::Notice(PORTAL_UNAVAILABLE_NOTICE)436
));437
}438
}439
440
#[cfg(all(test, target_os = "linux"))]441
mod portal_loop_tests {442
#[test]443
fn portal_loop_stays_up_across_ensures() {444
libwebrtc::desktop_capturer::ensure_shared_glib_loop();445
let id = libwebrtc::desktop_capturer::shared_glib_loop_id();446
assert_ne!(id, 0);447
libwebrtc::desktop_capturer::ensure_shared_glib_loop();448
assert_eq!(id, libwebrtc::desktop_capturer::shared_glib_loop_id());449
}450
}451
452
#[cfg(all(test, target_os = "linux"))]453
mod portal_smoke {454
use std::sync::Arc;455
use std::sync::atomic::{AtomicU32, Ordering};456
use std::time::Duration;457
458
use super::{PortalFollowUp, ShareKind, start_portal_capture};459
460
#[test]461
fn portal_smoke_captures_after_the_dialog() {462
if std::env::var("PORTAL_SMOKE").ok().as_deref() != Some("1") {463
return;464
}465
let frames = Arc::new(AtomicU32::new(0));466
let counter = frames.clone();467
let (sender, receiver) = std::sync::mpsc::channel();468
let capture = start_portal_capture(469
ShareKind::Screen,470
Arc::new(AtomicU32::new(5)),471
move |_| {472
counter.fetch_add(1, Ordering::Relaxed);473
},474
move |follow| {475
eprintln!("PORTAL_FOLLOW={follow:?}");476
let _ = sender.send(follow);477
},478
)479
.expect("portal thread");480
let follow = receiver481
.recv_timeout(Duration::from_secs(40))482
.expect("no portal result in 40s");483
std::thread::sleep(Duration::from_millis(700));484
let count = frames.load(Ordering::Relaxed);485
eprintln!("PORTAL_FRAMES={count}");486
drop(capture);487
match follow {488
PortalFollowUp::Share(_) => {489
assert!(count > 0, "the dialog confirmed, but no frame arrived")490
}491
PortalFollowUp::Quiet => panic!("the dialog was cancelled"),492
PortalFollowUp::Notice(text) => panic!("portal notice: {text}"),493
}494
}495
}