BlueGit

ict rusty-teams

feat(calls): zoom, pop out, divider, motion and standout for screen sharing

- Ctrl+wheel zoom 1x-4x around the pointer, drag to pan, Alt+Shift+Plus/Minus/0, zoom chip resets
- draggable divider between content and people strip, 160-400 px, remembered
- "Pop out" opens the shared content in its own window, closing it returns it
- share menu "Optimize for motion": maintain framerate and 30 fps, off = maintain resolution and 15 fps
- share menu "Show me over my content": rounded camera cut-out bottom right, skipped without a mask
- X11 red border windows get an empty input region, Wayland is skipped
- demo scene "sharing", layout guard screen for the share stage

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

metis Daniel Däschle · pushed by metis

Authored 2026-10-13 · 7 weeks ago

Hash
410dacc6f483fc7adc54bb08e77d2f74a765a960
Parent
b608e9a1
31 files changed +1351 −73
Cargo.lock +1 −0
@@ -301,6 +301,7 @@ dependencies = [
301 301 "uuid",
302 302 "webview",
303 303 "windows 0.62.2",
304 "x11rb",
304 305 ]
305 306
306 307 [[package]]
@@ -301,6 +301,7 @@ dependencies = [
301 "uuid",
301 "uuid",
302 "webview",
302 "webview",
303 "windows 0.62.2",
303 "windows 0.62.2",
304 "x11rb",
304]
305]
305
306
306[[package]]
307[[package]]
ROADMAP.md +4 −2
@@ -2,7 +2,7 @@
2 2
3 3 Feature parity with the Microsoft Teams desktop client.
4 4
5 **Parity: 89 %** (81 done, 15 partial, 4 missing of 100). Partial counts half.
5 **Parity: 88 %** (81 done, 17 partial, 4 missing of 102). Partial counts half.
6 6
7 7 ## By area
8 8
@@ -18,7 +18,7 @@ Feature parity with the Microsoft Teams desktop client.
18 18 | [Search and navigation](#search-and-navigation) | 100 % | 5 | 0 | 0 |
19 19 | [Presence and people](#presence-and-people) | 100 % | 4 | 0 | 0 |
20 20 | [Look and settings](#look-and-settings) | 50 % | 2 | 0 | 2 |
21 | [Calls and meetings](#calls-and-meetings) | 61 % | 4 | 14 | 0 |
21 | [Calls and meetings](#calls-and-meetings) | 60 % | 4 | 16 | 0 |
22 22
23 23 ## Next
24 24
@@ -182,6 +182,8 @@ Feature parity with the Microsoft Teams desktop client.
182 182 | Breakout rooms (participant) | Partial | Move message from the participant update or the replacement invite: notice "Moving you to <room>", leave and join the room, "Return to main meeting" in the header, a closed room goes back to the main meeting. Parsing unit tested; needs an organizer who moves people |
183 183 | Call health and encryption | Partial | Header shows signal bars and a shield; click opens "Call health" with loss, round trip, jitter, bitrate, "Secured by Teams encryption", DTLS-SRTP cipher and media path (direct or via Microsoft media server). Unstable network banner with "Turn off incoming video", overloaded computer banner with "Turn off effects". Thresholds unit tested; not yet seen on a bad live network |
184 184 | View and layout | Partial | "View" button between share and "...": Gallery (up to 3x3 of 16:9 tiles, "+N" tile with a pin list; visible tiles only swap after 2 s of speech, one swap per 5 s), Speaker (stage plus filmstrip of up to 6), Focus on content (only while someone shares), Hide people without video with a count chip, Hide me / Show me, Chat bubbles, Full screen (F11, controls hide after 3 s). Choice, Hide people without video and Chat bubbles are remembered. Checked with the demo gallery scene only; not yet in a large live meeting |
185 | Gallery video slots | Partial | Meetings offer 9 receive lines (mids 2-10, share on 11), so a 3x3 gallery shows up to 9 live videos. Only visible tiles get a slot: "+N" people and people hidden by "Hide people without video" are not requested. Speaker stage asks for 3600 macroblocks (max-fs), filmstrip, strip and big-gallery tiles for 920. 1:1 calls unchanged. Slot plan and offer layout unit tested; not yet seen with nine people on a live mixer |
186 | Sharing tools | Partial | Received share: Ctrl+wheel zoom 1x-4x around the pointer, drag to pan, Alt+Shift+Plus / Minus / 0, "250%" chip resets; draggable divider (strip 160-400 px, remembered); "Pop out" opens the content in its own window, closing it returns it. Share menu: "Optimize for motion" (maintain framerate, 30 fps; off = maintain resolution, 15 fps) and "Show me over my content" (camera cut-out bottom right, 22 % wide, rounded; skipped without a mask). Linux: red border windows ignore the mouse on X11. Checked in the demo and unit tests; not yet live with a second person |
185 187 | Whiteboard | Partial | Stage shows "<name> is sharing a whiteboard" with Open in browser, "..." > Whiteboard opens the meeting's board. State parsing unit tested; the share callback link is registered on join but not yet seen live |
186 188 | Call history | Done | Calls tab (Ctrl+5) from the Teams call log: avatar, name, Missed call in red, Outgoing / Incoming / Meeting with duration, time like the chat list. Click calls back or opens the meeting chat; right-click Call back and Open chat. Refreshes on tab open and after a call ends. Read live (counts and shapes); no realtime update |
187 189 | Join by link or meeting ID | Done | "Join with ID" dialog, "Paste a meeting link", Join chip next to Teams meeting links in the composer and messages. IDs and /meet/ links resolve through a roster-only conversation like Teams web; verified live with a self-created scheduled meeting (same meeting chat found) |
@@ -2,7 +2,7 @@
2
2
3Feature parity with the Microsoft Teams desktop client.
3Feature parity with the Microsoft Teams desktop client.
4
4
5**Parity: 89 %** (81 done, 15 partial, 4 missing of 100). Partial counts half.
5**Parity: 88 %** (81 done, 17 partial, 4 missing of 102). Partial counts half.
6
6
7## By area
7## By area
8
8
@@ -18,7 +18,7 @@ Feature parity with the Microsoft Teams desktop client.
18| [Search and navigation](#search-and-navigation) | 100 % | 5 | 0 | 0 |
18| [Search and navigation](#search-and-navigation) | 100 % | 5 | 0 | 0 |
19| [Presence and people](#presence-and-people) | 100 % | 4 | 0 | 0 |
19| [Presence and people](#presence-and-people) | 100 % | 4 | 0 | 0 |
20| [Look and settings](#look-and-settings) | 50 % | 2 | 0 | 2 |
20| [Look and settings](#look-and-settings) | 50 % | 2 | 0 | 2 |
21| [Calls and meetings](#calls-and-meetings) | 61 % | 4 | 14 | 0 |
21| [Calls and meetings](#calls-and-meetings) | 60 % | 4 | 16 | 0 |
22
22
23## Next
23## Next
24
24
@@ -182,6 +182,8 @@ Feature parity with the Microsoft Teams desktop client.
182| Breakout rooms (participant) | Partial | Move message from the participant update or the replacement invite: notice "Moving you to <room>", leave and join the room, "Return to main meeting" in the header, a closed room goes back to the main meeting. Parsing unit tested; needs an organizer who moves people |
182| Breakout rooms (participant) | Partial | Move message from the participant update or the replacement invite: notice "Moving you to <room>", leave and join the room, "Return to main meeting" in the header, a closed room goes back to the main meeting. Parsing unit tested; needs an organizer who moves people |
183| Call health and encryption | Partial | Header shows signal bars and a shield; click opens "Call health" with loss, round trip, jitter, bitrate, "Secured by Teams encryption", DTLS-SRTP cipher and media path (direct or via Microsoft media server). Unstable network banner with "Turn off incoming video", overloaded computer banner with "Turn off effects". Thresholds unit tested; not yet seen on a bad live network |
183| Call health and encryption | Partial | Header shows signal bars and a shield; click opens "Call health" with loss, round trip, jitter, bitrate, "Secured by Teams encryption", DTLS-SRTP cipher and media path (direct or via Microsoft media server). Unstable network banner with "Turn off incoming video", overloaded computer banner with "Turn off effects". Thresholds unit tested; not yet seen on a bad live network |
184| View and layout | Partial | "View" button between share and "...": Gallery (up to 3x3 of 16:9 tiles, "+N" tile with a pin list; visible tiles only swap after 2 s of speech, one swap per 5 s), Speaker (stage plus filmstrip of up to 6), Focus on content (only while someone shares), Hide people without video with a count chip, Hide me / Show me, Chat bubbles, Full screen (F11, controls hide after 3 s). Choice, Hide people without video and Chat bubbles are remembered. Checked with the demo gallery scene only; not yet in a large live meeting |
184| View and layout | Partial | "View" button between share and "...": Gallery (up to 3x3 of 16:9 tiles, "+N" tile with a pin list; visible tiles only swap after 2 s of speech, one swap per 5 s), Speaker (stage plus filmstrip of up to 6), Focus on content (only while someone shares), Hide people without video with a count chip, Hide me / Show me, Chat bubbles, Full screen (F11, controls hide after 3 s). Choice, Hide people without video and Chat bubbles are remembered. Checked with the demo gallery scene only; not yet in a large live meeting |
185| Gallery video slots | Partial | Meetings offer 9 receive lines (mids 2-10, share on 11), so a 3x3 gallery shows up to 9 live videos. Only visible tiles get a slot: "+N" people and people hidden by "Hide people without video" are not requested. Speaker stage asks for 3600 macroblocks (max-fs), filmstrip, strip and big-gallery tiles for 920. 1:1 calls unchanged. Slot plan and offer layout unit tested; not yet seen with nine people on a live mixer |
186| Sharing tools | Partial | Received share: Ctrl+wheel zoom 1x-4x around the pointer, drag to pan, Alt+Shift+Plus / Minus / 0, "250%" chip resets; draggable divider (strip 160-400 px, remembered); "Pop out" opens the content in its own window, closing it returns it. Share menu: "Optimize for motion" (maintain framerate, 30 fps; off = maintain resolution, 15 fps) and "Show me over my content" (camera cut-out bottom right, 22 % wide, rounded; skipped without a mask). Linux: red border windows ignore the mouse on X11. Checked in the demo and unit tests; not yet live with a second person |
185| Whiteboard | Partial | Stage shows "<name> is sharing a whiteboard" with Open in browser, "..." > Whiteboard opens the meeting's board. State parsing unit tested; the share callback link is registered on join but not yet seen live |
187| Whiteboard | Partial | Stage shows "<name> is sharing a whiteboard" with Open in browser, "..." > Whiteboard opens the meeting's board. State parsing unit tested; the share callback link is registered on join but not yet seen live |
186| Call history | Done | Calls tab (Ctrl+5) from the Teams call log: avatar, name, Missed call in red, Outgoing / Incoming / Meeting with duration, time like the chat list. Click calls back or opens the meeting chat; right-click Call back and Open chat. Refreshes on tab open and after a call ends. Read live (counts and shapes); no realtime update |
188| Call history | Done | Calls tab (Ctrl+5) from the Teams call log: avatar, name, Missed call in red, Outgoing / Incoming / Meeting with duration, time like the chat list. Click calls back or opens the meeting chat; right-click Call back and Open chat. Refreshes on tab open and after a call ends. Read live (counts and shapes); no realtime update |
187| Join by link or meeting ID | Done | "Join with ID" dialog, "Paste a meeting link", Join chip next to Teams meeting links in the composer and messages. IDs and /meet/ links resolve through a roster-only conversation like Teams web; verified live with a self-created scheduled meeting (same meeting chat found) |
189| Join by link or meeting ID | Done | "Join with ID" dialog, "Paste a meeting link", Join chip next to Teams meeting links in the composer and messages. IDs and /meet/ links resolve through a roster-only conversation like Teams web; verified live with a self-created scheduled meeting (same meeting chat found) |
crates/app/Cargo.toml +4 −0
@@ -38,6 +38,10 @@ tokio.workspace = true
38 38 uuid.workspace = true
39 39 image = { version = "0.25", default-features = false, features = ["bmp", "gif", "jpeg", "png", "webp"] }
40 40
41 [target.'cfg(target_os = "linux")'.dependencies]
42 raw-window-handle = "0.6"
43 x11rb = { version = "0.13", features = ["shape"] }
44
41 45 [target.'cfg(windows)'.dependencies]
42 46 webview.workspace = true
43 47 raw-window-handle = "0.6"
@@ -38,6 +38,10 @@ tokio.workspace = true
38uuid.workspace = true
38uuid.workspace = true
39image = { version = "0.25", default-features = false, features = ["bmp", "gif", "jpeg", "png", "webp"] }
39image = { version = "0.25", default-features = false, features = ["bmp", "gif", "jpeg", "png", "webp"] }
40
40
41[target.'cfg(target_os = "linux")'.dependencies]
42raw-window-handle = "0.6"
43x11rb = { version = "0.13", features = ["shape"] }
44
41[target.'cfg(windows)'.dependencies]
45[target.'cfg(windows)'.dependencies]
42webview.workspace = true
46webview.workspace = true
43raw-window-handle = "0.6"
47raw-window-handle = "0.6"
crates/app/src/app_state.rs +9 −0
@@ -124,6 +124,9 @@ pub struct AppState {
124 124 pub call_launcher: Option<Arc<CallLauncher>>,
125 125 pub call_count: u64,
126 126 pub call_share_sound: bool,
127 pub call_share_motion: bool,
128 pub call_share_standout: bool,
129 pub call_strip_width: f32,
127 130 pub call_view: crate::call::ViewSettings,
128 131 pub call_background: crate::call::BackgroundPick,
129 132 pub call_camera: calling::DeviceChoice,
@@ -224,6 +227,9 @@ impl AppState {
224 227 call_launcher: None,
225 228 call_count: 0,
226 229 call_share_sound: false,
230 call_share_motion: false,
231 call_share_standout: false,
232 call_strip_width: crate::call::STRIP_DEFAULT_WIDTH,
227 233 call_view: crate::call::ViewSettings::default(),
228 234 call_background: crate::call::BackgroundPick::None,
229 235 call_camera: calling::DeviceChoice::SystemDefault,
@@ -245,6 +251,9 @@ impl AppState {
245 251 state.local_previews = load_local_previews(&state.store);
246 252 state.collapsed = state.load_collapsed();
247 253 state.call_share_sound = crate::call::load_share_sound(&state.store);
254 state.call_share_motion = crate::call::load_flag(&state.store, crate::call::SHARE_MOTION_META_KEY);
255 state.call_share_standout = crate::call::load_flag(&state.store, crate::call::SHARE_STANDOUT_META_KEY);
256 state.call_strip_width = crate::call::load_strip_width(&state.store);
248 257 state.call_view = crate::call::ViewSettings::load(&state.store);
249 258 state.call_background = crate::call::load_background(&state.store);
250 259 state.call_camera = crate::call::load_camera(&state.store);
@@ -124,6 +124,9 @@ pub struct AppState {
124 pub call_launcher: Option<Arc<CallLauncher>>,
124 pub call_launcher: Option<Arc<CallLauncher>>,
125 pub call_count: u64,
125 pub call_count: u64,
126 pub call_share_sound: bool,
126 pub call_share_sound: bool,
127 pub call_share_motion: bool,
128 pub call_share_standout: bool,
129 pub call_strip_width: f32,
127 pub call_view: crate::call::ViewSettings,
130 pub call_view: crate::call::ViewSettings,
128 pub call_background: crate::call::BackgroundPick,
131 pub call_background: crate::call::BackgroundPick,
129 pub call_camera: calling::DeviceChoice,
132 pub call_camera: calling::DeviceChoice,
@@ -224,6 +227,9 @@ impl AppState {
224 call_launcher: None,
227 call_launcher: None,
225 call_count: 0,
228 call_count: 0,
226 call_share_sound: false,
229 call_share_sound: false,
230 call_share_motion: false,
231 call_share_standout: false,
232 call_strip_width: crate::call::STRIP_DEFAULT_WIDTH,
227 call_view: crate::call::ViewSettings::default(),
233 call_view: crate::call::ViewSettings::default(),
228 call_background: crate::call::BackgroundPick::None,
234 call_background: crate::call::BackgroundPick::None,
229 call_camera: calling::DeviceChoice::SystemDefault,
235 call_camera: calling::DeviceChoice::SystemDefault,
@@ -245,6 +251,9 @@ impl AppState {
245 state.local_previews = load_local_previews(&state.store);
251 state.local_previews = load_local_previews(&state.store);
246 state.collapsed = state.load_collapsed();
252 state.collapsed = state.load_collapsed();
247 state.call_share_sound = crate::call::load_share_sound(&state.store);
253 state.call_share_sound = crate::call::load_share_sound(&state.store);
254 state.call_share_motion = crate::call::load_flag(&state.store, crate::call::SHARE_MOTION_META_KEY);
255 state.call_share_standout = crate::call::load_flag(&state.store, crate::call::SHARE_STANDOUT_META_KEY);
256 state.call_strip_width = crate::call::load_strip_width(&state.store);
248 state.call_view = crate::call::ViewSettings::load(&state.store);
257 state.call_view = crate::call::ViewSettings::load(&state.store);
249 state.call_background = crate::call::load_background(&state.store);
258 state.call_background = crate::call::load_background(&state.store);
250 state.call_camera = crate::call::load_camera(&state.store);
259 state.call_camera = crate::call::load_camera(&state.store);
crates/app/src/call/actions.rs +7 −0
@@ -227,6 +227,12 @@ impl AppState {
227 227 if self.call_share_sound {
228 228 self.send_call_command(CallCommand::SetShareSound(true));
229 229 }
230 if self.call_share_motion {
231 self.send_call_command(CallCommand::SetShareMotion(true));
232 }
233 if self.call_share_standout {
234 self.send_call_command(CallCommand::SetShareStandout(true));
235 }
230 236 if self.call_mic != MicSettings::default() {
231 237 self.send_call_command(CallCommand::SetMicSettings(self.call_mic));
232 238 }
@@ -352,6 +358,7 @@ impl AppState {
352 358 call.model.apply(update);
353 359 if call.model.screen_sharer.is_none() {
354 360 call.stage_fullscreen = false;
361 call.share_stage.end();
355 362 call.pictures.forget(&VideoKey::Screen, cx);
356 363 }
357 364 if !call.model.camera_on {
@@ -227,6 +227,12 @@ impl AppState {
227 if self.call_share_sound {
227 if self.call_share_sound {
228 self.send_call_command(CallCommand::SetShareSound(true));
228 self.send_call_command(CallCommand::SetShareSound(true));
229 }
229 }
230 if self.call_share_motion {
231 self.send_call_command(CallCommand::SetShareMotion(true));
232 }
233 if self.call_share_standout {
234 self.send_call_command(CallCommand::SetShareStandout(true));
235 }
230 if self.call_mic != MicSettings::default() {
236 if self.call_mic != MicSettings::default() {
231 self.send_call_command(CallCommand::SetMicSettings(self.call_mic));
237 self.send_call_command(CallCommand::SetMicSettings(self.call_mic));
232 }
238 }
@@ -352,6 +358,7 @@ impl AppState {
352 call.model.apply(update);
358 call.model.apply(update);
353 if call.model.screen_sharer.is_none() {
359 if call.model.screen_sharer.is_none() {
354 call.stage_fullscreen = false;
360 call.stage_fullscreen = false;
361 call.share_stage.end();
355 call.pictures.forget(&VideoKey::Screen, cx);
362 call.pictures.forget(&VideoKey::Screen, cx);
356 }
363 }
357 if !call.model.camera_on {
364 if !call.model.camera_on {
crates/app/src/call/demo.rs +11 −3
@@ -92,6 +92,7 @@ pub enum DemoScene {
92 92 Whiteboard,
93 93 Network,
94 94 Gallery,
95 Sharing,
95 96 }
96 97
97 98 impl DemoScene {
@@ -106,6 +107,7 @@ impl DemoScene {
106 107 "whiteboard" => DemoScene::Whiteboard,
107 108 "network" => DemoScene::Network,
108 109 "gallery" => DemoScene::Gallery,
110 "sharing" => DemoScene::Sharing,
109 111 _ => return None,
110 112 })
111 113 }
@@ -115,7 +117,11 @@ impl DemoScene {
115 117 }
116 118
117 119 pub fn guests(self) -> Option<usize> {
118 (self == DemoScene::Gallery).then_some(DEMO_GALLERY_GUESTS)
120 match self {
121 DemoScene::Gallery => Some(DEMO_GALLERY_GUESTS),
122 DemoScene::Sharing => Some(DEMO_SHARING_GUESTS),
123 _ => None,
124 }
119 125 }
120 126
121 127 fn cameras(self) -> usize {
@@ -134,6 +140,7 @@ impl DemoScene {
134 140 }
135 141
136 142 pub const DEMO_GALLERY_GUESTS: usize = 12;
143 const DEMO_SHARING_GUESTS: usize = 6;
137 144 const BREAKOUT_AT_TICKS: u32 = 20;
138 145 const WHITEBOARD_AT_TICKS: u32 = 5;
139 146 const DEMO_BOARD_URL: &str = "https://app.whiteboard.microsoft.com/me/whiteboards/demo";
@@ -396,6 +403,7 @@ fn start_scene(control: &CallControl, scene: DemoScene) {
396 403 | DemoScene::Breakout
397 404 | DemoScene::Whiteboard
398 405 | DemoScene::Gallery
406 | DemoScene::Sharing
399 407 | DemoScene::Plain => {}
400 408 }
401 409 }
@@ -478,7 +486,7 @@ async fn speak_until_hangup(
478 486 tokio::select! {
479 487 _ = video_tick.tick(), if video || camera_on => {
480 488 let elapsed = started.elapsed();
481 let share_now = sharer.is_some() && (SHARE_START..SHARE_END).contains(&elapsed);
489 let share_now = sharer.is_some() && (scene == DemoScene::Sharing || (SHARE_START..SHARE_END).contains(&elapsed));
482 490 if share_now != sharing {
483 491 sharing = share_now;
484 492 control.send(CallUpdate::ScreenShare(sharer.clone().filter(|_| sharing)));
@@ -596,7 +604,7 @@ async fn speak_until_hangup(
596 604 people.iter().for_each(|(mri, _)| control.video.forget(&VideoKey::Person(mri.clone())));
597 605 control.send(CallUpdate::IncomingVideo(enabled));
598 606 }
599 Some(CallCommand::SetCameraEffects(_) | CallCommand::SetVideoWants(_)) => {}
607 Some(CallCommand::SetCameraEffects(_) | CallCommand::SetVideoWants(_) | CallCommand::SetShareMotion(_) | CallCommand::SetShareStandout(_)) => {}
600 608 Some(CallCommand::SetRecording { on, .. }) => control.send(CallUpdate::Recording(on)),
601 609 Some(CallCommand::ConsentToRecording) => control.send(CallUpdate::ConsentRequired(false)),
602 610 Some(CallCommand::Hold(hold)) => control.send(CallUpdate::Hold(if hold { HoldState::Local } else { HoldState::Active })),
@@ -92,6 +92,7 @@ pub enum DemoScene {
92 Whiteboard,
92 Whiteboard,
93 Network,
93 Network,
94 Gallery,
94 Gallery,
95 Sharing,
95}
96}
96
97
97impl DemoScene {
98impl DemoScene {
@@ -106,6 +107,7 @@ impl DemoScene {
106 "whiteboard" => DemoScene::Whiteboard,
107 "whiteboard" => DemoScene::Whiteboard,
107 "network" => DemoScene::Network,
108 "network" => DemoScene::Network,
108 "gallery" => DemoScene::Gallery,
109 "gallery" => DemoScene::Gallery,
110 "sharing" => DemoScene::Sharing,
109 _ => return None,
111 _ => return None,
110 })
112 })
111 }
113 }
@@ -115,7 +117,11 @@ impl DemoScene {
115 }
117 }
116
118
117 pub fn guests(self) -> Option<usize> {
119 pub fn guests(self) -> Option<usize> {
118 (self == DemoScene::Gallery).then_some(DEMO_GALLERY_GUESTS)
120 match self {
121 DemoScene::Gallery => Some(DEMO_GALLERY_GUESTS),
122 DemoScene::Sharing => Some(DEMO_SHARING_GUESTS),
123 _ => None,
124 }
119 }
125 }
120
126
121 fn cameras(self) -> usize {
127 fn cameras(self) -> usize {
@@ -134,6 +140,7 @@ impl DemoScene {
134}
140}
135
141
136pub const DEMO_GALLERY_GUESTS: usize = 12;
142pub const DEMO_GALLERY_GUESTS: usize = 12;
143const DEMO_SHARING_GUESTS: usize = 6;
137const BREAKOUT_AT_TICKS: u32 = 20;
144const BREAKOUT_AT_TICKS: u32 = 20;
138const WHITEBOARD_AT_TICKS: u32 = 5;
145const WHITEBOARD_AT_TICKS: u32 = 5;
139const DEMO_BOARD_URL: &str = "https://app.whiteboard.microsoft.com/me/whiteboards/demo";
146const DEMO_BOARD_URL: &str = "https://app.whiteboard.microsoft.com/me/whiteboards/demo";
@@ -396,6 +403,7 @@ fn start_scene(control: &CallControl, scene: DemoScene) {
396 | DemoScene::Breakout
403 | DemoScene::Breakout
397 | DemoScene::Whiteboard
404 | DemoScene::Whiteboard
398 | DemoScene::Gallery
405 | DemoScene::Gallery
406 | DemoScene::Sharing
399 | DemoScene::Plain => {}
407 | DemoScene::Plain => {}
400 }
408 }
401}
409}
@@ -478,7 +486,7 @@ async fn speak_until_hangup(
478 tokio::select! {
486 tokio::select! {
479 _ = video_tick.tick(), if video || camera_on => {
487 _ = video_tick.tick(), if video || camera_on => {
480 let elapsed = started.elapsed();
488 let elapsed = started.elapsed();
481 let share_now = sharer.is_some() && (SHARE_START..SHARE_END).contains(&elapsed);
489 let share_now = sharer.is_some() && (scene == DemoScene::Sharing || (SHARE_START..SHARE_END).contains(&elapsed));
482 if share_now != sharing {
490 if share_now != sharing {
483 sharing = share_now;
491 sharing = share_now;
484 control.send(CallUpdate::ScreenShare(sharer.clone().filter(|_| sharing)));
492 control.send(CallUpdate::ScreenShare(sharer.clone().filter(|_| sharing)));
@@ -596,7 +604,7 @@ async fn speak_until_hangup(
596 people.iter().for_each(|(mri, _)| control.video.forget(&VideoKey::Person(mri.clone())));
604 people.iter().for_each(|(mri, _)| control.video.forget(&VideoKey::Person(mri.clone())));
597 control.send(CallUpdate::IncomingVideo(enabled));
605 control.send(CallUpdate::IncomingVideo(enabled));
598 }
606 }
599 Some(CallCommand::SetCameraEffects(_) | CallCommand::SetVideoWants(_)) => {}
607 Some(CallCommand::SetCameraEffects(_) | CallCommand::SetVideoWants(_) | CallCommand::SetShareMotion(_) | CallCommand::SetShareStandout(_)) => {}
600 Some(CallCommand::SetRecording { on, .. }) => control.send(CallUpdate::Recording(on)),
608 Some(CallCommand::SetRecording { on, .. }) => control.send(CallUpdate::Recording(on)),
601 Some(CallCommand::ConsentToRecording) => control.send(CallUpdate::ConsentRequired(false)),
609 Some(CallCommand::ConsentToRecording) => control.send(CallUpdate::ConsentRequired(false)),
602 Some(CallCommand::Hold(hold)) => control.send(CallUpdate::Hold(if hold { HoldState::Local } else { HoldState::Active })),
610 Some(CallCommand::Hold(hold)) => control.send(CallUpdate::Hold(if hold { HoldState::Local } else { HoldState::Active })),
crates/app/src/call/mod.rs +4 −0
@@ -20,6 +20,8 @@ mod overlay_layout;
20 20 mod pictures;
21 21 mod preview;
22 22 mod push_to_talk;
23 mod share_actions;
24 mod share_view;
23 25 mod ring;
24 26 mod stage_layout;
25 27 mod target;
@@ -49,6 +51,8 @@ pub use model::{
49 51 TileState,
50 52 };
51 53 pub use overlay::CallWindows;
54 pub use share_actions::ZoomStep;
55 pub use share_view::{SHARE_MOTION_META_KEY, SHARE_STANDOUT_META_KEY, STRIP_DEFAULT_WIDTH, ShareStage, load_flag, load_strip_width};
52 56 pub use preview::{CameraPreview, preview_backgrounds};
53 57 pub use ring::{MissedCall, RingEntry, Rings};
54 58 pub use stage_layout::{FILMSTRIP_MAX, Filmstrip, GALLERY_MAX, Overflow, filmstrip, gallery_grid, split_overflow};
@@ -20,6 +20,8 @@ mod overlay_layout;
20mod pictures;
20mod pictures;
21mod preview;
21mod preview;
22mod push_to_talk;
22mod push_to_talk;
23mod share_actions;
24mod share_view;
23mod ring;
25mod ring;
24mod stage_layout;
26mod stage_layout;
25mod target;
27mod target;
@@ -49,6 +51,8 @@ pub use model::{
49 TileState,
51 TileState,
50};
52};
51pub use overlay::CallWindows;
53pub use overlay::CallWindows;
54pub use share_actions::ZoomStep;
55pub use share_view::{SHARE_MOTION_META_KEY, SHARE_STANDOUT_META_KEY, STRIP_DEFAULT_WIDTH, ShareStage, load_flag, load_strip_width};
52pub use preview::{CameraPreview, preview_backgrounds};
56pub use preview::{CameraPreview, preview_backgrounds};
53pub use ring::{MissedCall, RingEntry, Rings};
57pub use ring::{MissedCall, RingEntry, Rings};
54pub use stage_layout::{FILMSTRIP_MAX, Filmstrip, GALLERY_MAX, Overflow, filmstrip, gallery_grid, split_overflow};
58pub use stage_layout::{FILMSTRIP_MAX, Filmstrip, GALLERY_MAX, Overflow, filmstrip, gallery_grid, split_overflow};
crates/app/src/call/model.rs +3 −0
@@ -18,6 +18,7 @@ use super::pictures::CallPictures;
18 18 use super::stage_layout::{FILMSTRIP_MAX, GALLERY_MAX, RECENT_SPEAKER, SPEAKER_HOLD, VisibleRotation, split_overflow};
19 19 use super::view_settings::{CallLayout, ViewSettings};
20 20 use super::push_to_talk::PushToTalk;
21 use super::share_view::ShareStage;
21 22
22 23 pub const TEST_CALL_TITLE: &str = "Test call";
23 24 pub const ECHO_NAME: &str = "Teams echo";
@@ -43,6 +44,7 @@ pub struct ActiveCall {
43 44 pub fullscreen: Option<FullscreenState>,
44 45 pub stage_size: Rc<Cell<(f32, f32)>>,
45 46 pub sent_wants: Vec<VideoWant>,
47 pub share_stage: ShareStage,
46 48 pub bubbles: Vec<ChatBubble>,
47 49 pub share_menu_open: bool,
48 50 pub lobby_list_open: bool,
@@ -107,6 +109,7 @@ impl ActiveCall {
107 109 fullscreen: None,
108 110 stage_size: Rc::default(),
109 111 sent_wants: Vec::new(),
112 share_stage: ShareStage::default(),
110 113 bubbles: Vec::new(),
111 114 share_menu_open: false,
112 115 lobby_list_open: false,
@@ -18,6 +18,7 @@ use super::pictures::CallPictures;
18use super::stage_layout::{FILMSTRIP_MAX, GALLERY_MAX, RECENT_SPEAKER, SPEAKER_HOLD, VisibleRotation, split_overflow};
18use super::stage_layout::{FILMSTRIP_MAX, GALLERY_MAX, RECENT_SPEAKER, SPEAKER_HOLD, VisibleRotation, split_overflow};
19use super::view_settings::{CallLayout, ViewSettings};
19use super::view_settings::{CallLayout, ViewSettings};
20use super::push_to_talk::PushToTalk;
20use super::push_to_talk::PushToTalk;
21use super::share_view::ShareStage;
21
22
22pub const TEST_CALL_TITLE: &str = "Test call";
23pub const TEST_CALL_TITLE: &str = "Test call";
23pub const ECHO_NAME: &str = "Teams echo";
24pub const ECHO_NAME: &str = "Teams echo";
@@ -43,6 +44,7 @@ pub struct ActiveCall {
43 pub fullscreen: Option<FullscreenState>,
44 pub fullscreen: Option<FullscreenState>,
44 pub stage_size: Rc<Cell<(f32, f32)>>,
45 pub stage_size: Rc<Cell<(f32, f32)>>,
45 pub sent_wants: Vec<VideoWant>,
46 pub sent_wants: Vec<VideoWant>,
47 pub share_stage: ShareStage,
46 pub bubbles: Vec<ChatBubble>,
48 pub bubbles: Vec<ChatBubble>,
47 pub share_menu_open: bool,
49 pub share_menu_open: bool,
48 pub lobby_list_open: bool,
50 pub lobby_list_open: bool,
@@ -107,6 +109,7 @@ impl ActiveCall {
107 fullscreen: None,
109 fullscreen: None,
108 stage_size: Rc::default(),
110 stage_size: Rc::default(),
109 sent_wants: Vec::new(),
111 sent_wants: Vec::new(),
112 share_stage: ShareStage::default(),
110 bubbles: Vec::new(),
113 bubbles: Vec::new(),
111 share_menu_open: false,
114 share_menu_open: false,
112 lobby_list_open: false,
115 lobby_list_open: false,
crates/app/src/call/overlay.rs +65 −3
@@ -12,6 +12,7 @@ use super::overlay_layout::{
12 12 use crate::app_state::AppState;
13 13 use crate::notify::platform::{self, NativeHandle, ScreenRect, ShareGeometry, WorkArea};
14 14 use crate::views::call_mini_window::MiniWindowView;
15 use crate::views::call_pop_out::{POP_OUT_SIZE, POP_OUT_TITLE, SharePopOutView};
15 16 use crate::views::share_bar::{ShareBarView, ShareBorderView};
16 17
17 18 const TICK: Duration = Duration::from_millis(100);
@@ -61,6 +62,8 @@ pub struct CallWindows {
61 62 windows: HashMap<Role, Placed>,
62 63 opening: HashSet<Role>,
63 64 share: Option<ShareSession>,
65 pop_out: Option<AnyWindowHandle>,
66 pop_out_opening: bool,
64 67 pinned: bool,
65 68 bar_idle_since: Instant,
66 69 bar_collapsed: bool,
@@ -126,6 +129,8 @@ impl CallWindows {
126 129 windows: HashMap::new(),
127 130 opening: HashSet::new(),
128 131 share: None,
132 pop_out: None,
133 pop_out_opening: false,
129 134 pinned: false,
130 135 bar_idle_since: Instant::now(),
131 136 bar_collapsed: false,
@@ -213,6 +218,7 @@ impl CallWindows {
213 218 let slow = self.ticks % SLOW_TICK_EVERY == 0;
214 219 self.refresh_main_window();
215 220 self.sync_share(slow, cx);
221 self.sync_pop_out(cx);
216 222 self.sync_mini(cx);
217 223 if slow {
218 224 self.track_mini_position(cx);
@@ -316,6 +322,60 @@ impl CallWindows {
316 322 }
317 323 }
318 324
325 fn sync_pop_out(&mut self, cx: &mut Context<Self>) {
326 let wanted = self
327 .app
328 .read(cx)
329 .call
330 .as_ref()
331 .is_some_and(|call| call.share_stage.popped && call.model.screen_sharer.is_some());
332 match (wanted, self.pop_out) {
333 (true, None) => self.open_pop_out(cx),
334 (false, Some(handle)) => {
335 self.pop_out = None;
336 handle.update(cx, |_, window, _| window.remove_window()).ok();
337 }
338 (true, Some(handle)) => {
339 if handle.update(cx, |_, _, _| ()).is_err() {
340 self.pop_out = None;
341 self.app.update(cx, |state, cx| state.return_stage_from_pop_out(cx));
342 }
343 }
344 (false, None) => {}
345 }
346 }
347
348 fn open_pop_out(&mut self, cx: &mut Context<Self>) {
349 if self.pop_out_opening {
350 return;
351 }
352 self.pop_out_opening = true;
353 let controller = cx.entity();
354 let app = self.app.clone();
355 let options = WindowOptions {
356 window_bounds: Some(WindowBounds::Windowed(Bounds::centered(
357 None,
358 size(px(POP_OUT_SIZE.0), px(POP_OUT_SIZE.1)),
359 cx,
360 ))),
361 titlebar: Some(TitlebarOptions {
362 title: Some(POP_OUT_TITLE.into()),
363 ..Default::default()
364 }),
365 ..Default::default()
366 };
367 // open_window draws right away, and the view reads the app entity while rendering.
368 cx.defer(move |cx| {
369 let opened = gpui_kit::open_window(options, cx, move |window, cx| {
370 cx.new(|cx| SharePopOutView::new(app, window, cx))
371 });
372 controller.update(cx, |this, _| {
373 this.pop_out_opening = false;
374 this.pop_out = opened.ok().map(|(handle, _)| handle);
375 });
376 });
377 }
378
319 379 fn sync_mini(&mut self, cx: &mut Context<Self>) {
320 380 let in_call = self.app.read(cx).call.is_some();
321 381 let work = self.work_area.or_else(|| display_work_area(cx));
@@ -406,9 +466,11 @@ impl CallWindows {
406 466 if let Some(native) = native {
407 467 platform::prepare_toast_window(native);
408 468 platform::exclude_from_capture(native);
409 if matches!(role, Role::Border(_)) {
410 platform::make_click_through(native);
411 }
469 }
470 if matches!(role, Role::Border(_)) {
471 handle
472 .update(cx, |_, window, _| platform::make_window_click_through(window))
473 .ok();
412 474 }
413 475 Placed {
414 476 handle,
@@ -12,6 +12,7 @@ use super::overlay_layout::{
12use crate::app_state::AppState;
12use crate::app_state::AppState;
13use crate::notify::platform::{self, NativeHandle, ScreenRect, ShareGeometry, WorkArea};
13use crate::notify::platform::{self, NativeHandle, ScreenRect, ShareGeometry, WorkArea};
14use crate::views::call_mini_window::MiniWindowView;
14use crate::views::call_mini_window::MiniWindowView;
15use crate::views::call_pop_out::{POP_OUT_SIZE, POP_OUT_TITLE, SharePopOutView};
15use crate::views::share_bar::{ShareBarView, ShareBorderView};
16use crate::views::share_bar::{ShareBarView, ShareBorderView};
16
17
17const TICK: Duration = Duration::from_millis(100);
18const TICK: Duration = Duration::from_millis(100);
@@ -61,6 +62,8 @@ pub struct CallWindows {
61 windows: HashMap<Role, Placed>,
62 windows: HashMap<Role, Placed>,
62 opening: HashSet<Role>,
63 opening: HashSet<Role>,
63 share: Option<ShareSession>,
64 share: Option<ShareSession>,
65 pop_out: Option<AnyWindowHandle>,
66 pop_out_opening: bool,
64 pinned: bool,
67 pinned: bool,
65 bar_idle_since: Instant,
68 bar_idle_since: Instant,
66 bar_collapsed: bool,
69 bar_collapsed: bool,
@@ -126,6 +129,8 @@ impl CallWindows {
126 windows: HashMap::new(),
129 windows: HashMap::new(),
127 opening: HashSet::new(),
130 opening: HashSet::new(),
128 share: None,
131 share: None,
132 pop_out: None,
133 pop_out_opening: false,
129 pinned: false,
134 pinned: false,
130 bar_idle_since: Instant::now(),
135 bar_idle_since: Instant::now(),
131 bar_collapsed: false,
136 bar_collapsed: false,
@@ -213,6 +218,7 @@ impl CallWindows {
213 let slow = self.ticks % SLOW_TICK_EVERY == 0;
218 let slow = self.ticks % SLOW_TICK_EVERY == 0;
214 self.refresh_main_window();
219 self.refresh_main_window();
215 self.sync_share(slow, cx);
220 self.sync_share(slow, cx);
221 self.sync_pop_out(cx);
216 self.sync_mini(cx);
222 self.sync_mini(cx);
217 if slow {
223 if slow {
218 self.track_mini_position(cx);
224 self.track_mini_position(cx);
@@ -316,6 +322,60 @@ impl CallWindows {
316 }
322 }
317 }
323 }
318
324
325 fn sync_pop_out(&mut self, cx: &mut Context<Self>) {
326 let wanted = self
327 .app
328 .read(cx)
329 .call
330 .as_ref()
331 .is_some_and(|call| call.share_stage.popped && call.model.screen_sharer.is_some());
332 match (wanted, self.pop_out) {
333 (true, None) => self.open_pop_out(cx),
334 (false, Some(handle)) => {
335 self.pop_out = None;
336 handle.update(cx, |_, window, _| window.remove_window()).ok();
337 }
338 (true, Some(handle)) => {
339 if handle.update(cx, |_, _, _| ()).is_err() {
340 self.pop_out = None;
341 self.app.update(cx, |state, cx| state.return_stage_from_pop_out(cx));
342 }
343 }
344 (false, None) => {}
345 }
346 }
347
348 fn open_pop_out(&mut self, cx: &mut Context<Self>) {
349 if self.pop_out_opening {
350 return;
351 }
352 self.pop_out_opening = true;
353 let controller = cx.entity();
354 let app = self.app.clone();
355 let options = WindowOptions {
356 window_bounds: Some(WindowBounds::Windowed(Bounds::centered(
357 None,
358 size(px(POP_OUT_SIZE.0), px(POP_OUT_SIZE.1)),
359 cx,
360 ))),
361 titlebar: Some(TitlebarOptions {
362 title: Some(POP_OUT_TITLE.into()),
363 ..Default::default()
364 }),
365 ..Default::default()
366 };
367 // open_window draws right away, and the view reads the app entity while rendering.
368 cx.defer(move |cx| {
369 let opened = gpui_kit::open_window(options, cx, move |window, cx| {
370 cx.new(|cx| SharePopOutView::new(app, window, cx))
371 });
372 controller.update(cx, |this, _| {
373 this.pop_out_opening = false;
374 this.pop_out = opened.ok().map(|(handle, _)| handle);
375 });
376 });
377 }
378
319 fn sync_mini(&mut self, cx: &mut Context<Self>) {
379 fn sync_mini(&mut self, cx: &mut Context<Self>) {
320 let in_call = self.app.read(cx).call.is_some();
380 let in_call = self.app.read(cx).call.is_some();
321 let work = self.work_area.or_else(|| display_work_area(cx));
381 let work = self.work_area.or_else(|| display_work_area(cx));
@@ -406,9 +466,11 @@ impl CallWindows {
406 if let Some(native) = native {
466 if let Some(native) = native {
407 platform::prepare_toast_window(native);
467 platform::prepare_toast_window(native);
408 platform::exclude_from_capture(native);
468 platform::exclude_from_capture(native);
409 if matches!(role, Role::Border(_)) {
469 }
410 platform::make_click_through(native);
470 if matches!(role, Role::Border(_)) {
411 }
471 handle
472 .update(cx, |_, window, _| platform::make_window_click_through(window))
473 .ok();
412 }
474 }
413 Placed {
475 Placed {
414 handle,
476 handle,
crates/app/src/call/share_actions.rs added +110 −0
@@ -0,0 +1,110 @@
1 use calling::CallCommand;
2 use gpui_kit::*;
3
4 use super::share_view::{
5 SHARE_MOTION_META_KEY, SHARE_STANDOUT_META_KEY, STRIP_WIDTH_META_KEY, StripDrag, clamp_strip_width,
6 };
7 use crate::app_state::{AppEvent, AppState};
8
9 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
10 pub enum ZoomStep {
11 In,
12 Out,
13 Reset,
14 }
15
16 fn flag_text(on: bool) -> &'static str {
17 if on { "1" } else { "0" }
18 }
19
20 impl AppState {
21 fn change_share_stage(&mut self, cx: &mut Context<Self>, change: impl FnOnce(&mut super::share_view::ShareStage)) {
22 let Some(call) = self.call.as_mut().filter(|call| call.model.screen_sharer.is_some()) else {
23 return;
24 };
25 change(&mut call.share_stage);
26 cx.emit(AppEvent::Call);
27 cx.notify();
28 }
29
30 pub fn zoom_share_wheel(&mut self, scroll_pixels: f32, position: (f32, f32), cx: &mut Context<Self>) {
31 self.change_share_stage(cx, |stage| {
32 let (pointer, size) = (stage.pointer(position), stage.size());
33 stage.view.zoom_wheel(scroll_pixels, pointer, size);
34 });
35 }
36
37 pub fn zoom_share(&mut self, step: ZoomStep, cx: &mut Context<Self>) {
38 self.change_share_stage(cx, |stage| {
39 let size = stage.size();
40 match step {
41 ZoomStep::In => stage.view.step_in(size),
42 ZoomStep::Out => stage.view.step_out(size),
43 ZoomStep::Reset => stage.view.reset(),
44 }
45 });
46 }
47
48 pub fn begin_share_pan(&mut self, position: (f32, f32), cx: &mut Context<Self>) {
49 self.change_share_stage(cx, |stage| stage.pan_from = Some(position));
50 }
51
52 pub fn pan_share_to(&mut self, position: (f32, f32), cx: &mut Context<Self>) {
53 self.change_share_stage(cx, |stage| {
54 let Some(from) = stage.pan_from.replace(position) else {
55 return;
56 };
57 let size = stage.size();
58 stage.view.pan_by((position.0 - from.0, position.1 - from.1), size);
59 });
60 }
61
62 pub fn end_share_pan(&mut self, cx: &mut Context<Self>) {
63 self.change_share_stage(cx, |stage| stage.pan_from = None);
64 }
65
66 pub fn begin_strip_drag(&mut self, pointer_x: f32, cx: &mut Context<Self>) {
67 let start_width = self.call_strip_width;
68 self.change_share_stage(cx, |stage| stage.strip_drag = Some(StripDrag { start_pointer: pointer_x, start_width }));
69 }
70
71 pub fn drag_strip_to(&mut self, pointer_x: f32, cx: &mut Context<Self>) {
72 let Some(drag) = self.call.as_ref().and_then(|call| call.share_stage.strip_drag) else {
73 return;
74 };
75 self.call_strip_width = drag.width_at(pointer_x);
76 cx.notify();
77 }
78
79 pub fn end_strip_drag(&mut self, cx: &mut Context<Self>) {
80 if self.call.as_ref().is_none_or(|call| call.share_stage.strip_drag.is_none()) {
81 return;
82 }
83 let width = clamp_strip_width(self.call_strip_width);
84 self.call_strip_width = width;
85 let _ = self.store.set_meta(STRIP_WIDTH_META_KEY, &width.to_string());
86 self.change_share_stage(cx, |stage| stage.strip_drag = None);
87 }
88
89 pub fn pop_out_stage(&mut self, cx: &mut Context<Self>) {
90 self.change_share_stage(cx, |stage| stage.popped = true);
91 }
92
93 pub fn return_stage_from_pop_out(&mut self, cx: &mut Context<Self>) {
94 self.change_share_stage(cx, |stage| stage.popped = false);
95 }
96
97 pub fn set_call_share_motion(&mut self, on: bool, cx: &mut Context<Self>) {
98 self.call_share_motion = on;
99 let _ = self.store.set_meta(SHARE_MOTION_META_KEY, flag_text(on));
100 self.send_call_command(CallCommand::SetShareMotion(on));
101 cx.notify();
102 }
103
104 pub fn set_call_share_standout(&mut self, on: bool, cx: &mut Context<Self>) {
105 self.call_share_standout = on;
106 let _ = self.store.set_meta(SHARE_STANDOUT_META_KEY, flag_text(on));
107 self.send_call_command(CallCommand::SetShareStandout(on));
108 cx.notify();
109 }
110 }
@@ -0,0 +1,110 @@
1use calling::CallCommand;
2use gpui_kit::*;
3
4use super::share_view::{
5 SHARE_MOTION_META_KEY, SHARE_STANDOUT_META_KEY, STRIP_WIDTH_META_KEY, StripDrag, clamp_strip_width,
6};
7use crate::app_state::{AppEvent, AppState};
8
9#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10pub enum ZoomStep {
11 In,
12 Out,
13 Reset,
14}
15
16fn flag_text(on: bool) -> &'static str {
17 if on { "1" } else { "0" }
18}
19
20impl AppState {
21 fn change_share_stage(&mut self, cx: &mut Context<Self>, change: impl FnOnce(&mut super::share_view::ShareStage)) {
22 let Some(call) = self.call.as_mut().filter(|call| call.model.screen_sharer.is_some()) else {
23 return;
24 };
25 change(&mut call.share_stage);
26 cx.emit(AppEvent::Call);
27 cx.notify();
28 }
29
30 pub fn zoom_share_wheel(&mut self, scroll_pixels: f32, position: (f32, f32), cx: &mut Context<Self>) {
31 self.change_share_stage(cx, |stage| {
32 let (pointer, size) = (stage.pointer(position), stage.size());
33 stage.view.zoom_wheel(scroll_pixels, pointer, size);
34 });
35 }
36
37 pub fn zoom_share(&mut self, step: ZoomStep, cx: &mut Context<Self>) {
38 self.change_share_stage(cx, |stage| {
39 let size = stage.size();
40 match step {
41 ZoomStep::In => stage.view.step_in(size),
42 ZoomStep::Out => stage.view.step_out(size),
43 ZoomStep::Reset => stage.view.reset(),
44 }
45 });
46 }
47
48 pub fn begin_share_pan(&mut self, position: (f32, f32), cx: &mut Context<Self>) {
49 self.change_share_stage(cx, |stage| stage.pan_from = Some(position));
50 }
51
52 pub fn pan_share_to(&mut self, position: (f32, f32), cx: &mut Context<Self>) {
53 self.change_share_stage(cx, |stage| {
54 let Some(from) = stage.pan_from.replace(position) else {
55 return;
56 };
57 let size = stage.size();
58 stage.view.pan_by((position.0 - from.0, position.1 - from.1), size);
59 });
60 }
61
62 pub fn end_share_pan(&mut self, cx: &mut Context<Self>) {
63 self.change_share_stage(cx, |stage| stage.pan_from = None);
64 }
65
66 pub fn begin_strip_drag(&mut self, pointer_x: f32, cx: &mut Context<Self>) {
67 let start_width = self.call_strip_width;
68 self.change_share_stage(cx, |stage| stage.strip_drag = Some(StripDrag { start_pointer: pointer_x, start_width }));
69 }
70
71 pub fn drag_strip_to(&mut self, pointer_x: f32, cx: &mut Context<Self>) {
72 let Some(drag) = self.call.as_ref().and_then(|call| call.share_stage.strip_drag) else {
73 return;
74 };
75 self.call_strip_width = drag.width_at(pointer_x);
76 cx.notify();
77 }
78
79 pub fn end_strip_drag(&mut self, cx: &mut Context<Self>) {
80 if self.call.as_ref().is_none_or(|call| call.share_stage.strip_drag.is_none()) {
81 return;
82 }
83 let width = clamp_strip_width(self.call_strip_width);
84 self.call_strip_width = width;
85 let _ = self.store.set_meta(STRIP_WIDTH_META_KEY, &width.to_string());
86 self.change_share_stage(cx, |stage| stage.strip_drag = None);
87 }
88
89 pub fn pop_out_stage(&mut self, cx: &mut Context<Self>) {
90 self.change_share_stage(cx, |stage| stage.popped = true);
91 }
92
93 pub fn return_stage_from_pop_out(&mut self, cx: &mut Context<Self>) {
94 self.change_share_stage(cx, |stage| stage.popped = false);
95 }
96
97 pub fn set_call_share_motion(&mut self, on: bool, cx: &mut Context<Self>) {
98 self.call_share_motion = on;
99 let _ = self.store.set_meta(SHARE_MOTION_META_KEY, flag_text(on));
100 self.send_call_command(CallCommand::SetShareMotion(on));
101 cx.notify();
102 }
103
104 pub fn set_call_share_standout(&mut self, on: bool, cx: &mut Context<Self>) {
105 self.call_share_standout = on;
106 let _ = self.store.set_meta(SHARE_STANDOUT_META_KEY, flag_text(on));
107 self.send_call_command(CallCommand::SetShareStandout(on));
108 cx.notify();
109 }
110}
crates/app/src/call/share_view.rs added +211 −0
@@ -0,0 +1,211 @@
1 use std::cell::Cell;
2 use std::rc::Rc;
3
4 pub const ZOOM_MIN: f32 = 1.;
5 pub const ZOOM_MAX: f32 = 4.;
6 const ZOOM_STEP: f32 = 1.25;
7 const WHEEL_ZOOM_PER_PIXEL: f32 = 0.0015;
8 pub const STRIP_MIN_WIDTH: f32 = 160.;
9 pub const STRIP_MAX_WIDTH: f32 = 400.;
10 pub const STRIP_DEFAULT_WIDTH: f32 = 232.;
11 pub const STRIP_WIDTH_META_KEY: &str = "call_strip_width";
12 pub const SHARE_MOTION_META_KEY: &str = "call_share_motion";
13 pub const SHARE_STANDOUT_META_KEY: &str = "call_share_standout";
14
15 #[derive(Debug, Clone, Copy, PartialEq)]
16 pub struct ShareView {
17 zoom: f32,
18 offset: (f32, f32),
19 }
20
21 impl Default for ShareView {
22 fn default() -> Self {
23 ShareView { zoom: ZOOM_MIN, offset: (0., 0.) }
24 }
25 }
26
27 fn clamp_axis(offset: f32, extent: f32, zoom: f32) -> f32 {
28 offset.clamp(extent - extent * zoom, 0.)
29 }
30
31 impl ShareView {
32 pub fn zoom(&self) -> f32 {
33 self.zoom
34 }
35
36 pub fn is_zoomed(&self) -> bool {
37 self.zoom > ZOOM_MIN
38 }
39
40 pub fn percent(&self) -> u32 {
41 (self.zoom * 100.).round() as u32
42 }
43
44 pub fn offset(&self, stage: (f32, f32)) -> (f32, f32) {
45 (clamp_axis(self.offset.0, stage.0, self.zoom), clamp_axis(self.offset.1, stage.1, self.zoom))
46 }
47
48 pub fn reset(&mut self) {
49 *self = ShareView::default();
50 }
51
52 pub fn zoom_around(&mut self, factor: f32, pointer: (f32, f32), stage: (f32, f32)) {
53 let target = (self.zoom * factor).clamp(ZOOM_MIN, ZOOM_MAX);
54 if target <= ZOOM_MIN {
55 self.reset();
56 return;
57 }
58 let (offset_x, offset_y) = self.offset(stage);
59 let ratio = target / self.zoom;
60 self.zoom = target;
61 self.offset = (pointer.0 - (pointer.0 - offset_x) * ratio, pointer.1 - (pointer.1 - offset_y) * ratio);
62 self.offset = self.offset(stage);
63 }
64
65 pub fn zoom_wheel(&mut self, scroll_pixels: f32, pointer: (f32, f32), stage: (f32, f32)) {
66 self.zoom_around((scroll_pixels * WHEEL_ZOOM_PER_PIXEL).exp(), pointer, stage);
67 }
68
69 pub fn step_in(&mut self, stage: (f32, f32)) {
70 self.zoom_around(ZOOM_STEP, (stage.0 / 2., stage.1 / 2.), stage);
71 }
72
73 pub fn step_out(&mut self, stage: (f32, f32)) {
74 self.zoom_around(1. / ZOOM_STEP, (stage.0 / 2., stage.1 / 2.), stage);
75 }
76
77 pub fn pan_by(&mut self, delta: (f32, f32), stage: (f32, f32)) {
78 if !self.is_zoomed() {
79 return;
80 }
81 let (offset_x, offset_y) = self.offset(stage);
82 self.offset = (offset_x + delta.0, offset_y + delta.1);
83 self.offset = self.offset(stage);
84 }
85 }
86
87 pub fn clamp_strip_width(width: f32) -> f32 {
88 width.clamp(STRIP_MIN_WIDTH, STRIP_MAX_WIDTH)
89 }
90
91 pub fn load_strip_width(store: &store::Store) -> f32 {
92 store
93 .meta(STRIP_WIDTH_META_KEY)
94 .ok()
95 .flatten()
96 .and_then(|text| text.parse().ok())
97 .map_or(STRIP_DEFAULT_WIDTH, clamp_strip_width)
98 }
99
100 pub fn load_flag(store: &store::Store, key: &str) -> bool {
101 store.meta(key).ok().flatten().as_deref() == Some("1")
102 }
103
104 #[derive(Debug, Clone, Copy, PartialEq)]
105 pub struct StripDrag {
106 pub start_pointer: f32,
107 pub start_width: f32,
108 }
109
110 impl StripDrag {
111 pub fn width_at(&self, pointer: f32) -> f32 {
112 clamp_strip_width(self.start_width + self.start_pointer - pointer)
113 }
114 }
115
116 #[derive(Default)]
117 pub struct ShareStage {
118 pub view: ShareView,
119 pub pan_from: Option<(f32, f32)>,
120 pub strip_drag: Option<StripDrag>,
121 pub popped: bool,
122 pub bounds: Rc<Cell<(f32, f32, f32, f32)>>,
123 }
124
125 impl ShareStage {
126 pub fn size(&self) -> (f32, f32) {
127 let (_, _, width, height) = self.bounds.get();
128 (width, height)
129 }
130
131 pub fn pointer(&self, position: (f32, f32)) -> (f32, f32) {
132 let (left, top, _, _) = self.bounds.get();
133 (position.0 - left, position.1 - top)
134 }
135
136 pub fn end(&mut self) {
137 self.view.reset();
138 self.pan_from = None;
139 self.popped = false;
140 }
141 }
142
143 #[cfg(test)]
144 mod tests {
145 use super::*;
146
147 const STAGE: (f32, f32) = (800., 450.);
148
149 #[test]
150 fn zooming_keeps_the_point_under_the_pointer_still() {
151 let mut view = ShareView::default();
152 let pointer = (600., 100.);
153 view.zoom_around(2., pointer, STAGE);
154 let (offset_x, offset_y) = view.offset(STAGE);
155 let content = ((pointer.0 - offset_x) / view.zoom(), (pointer.1 - offset_y) / view.zoom());
156 assert!((content.0 - 600.).abs() < 0.01 && (content.1 - 100.).abs() < 0.01);
157 }
158
159 #[test]
160 fn zoom_stays_between_one_and_four_times() {
161 let mut view = ShareView::default();
162 view.zoom_around(100., (400., 225.), STAGE);
163 assert_eq!(view.zoom(), ZOOM_MAX);
164 view.zoom_around(0.0001, (400., 225.), STAGE);
165 assert!(!view.is_zoomed());
166 assert_eq!(view.offset(STAGE), (0., 0.));
167 }
168
169 #[test]
170 fn panning_never_leaves_the_content() {
171 let mut view = ShareView::default();
172 view.pan_by((50., 50.), STAGE);
173 assert_eq!(view.offset(STAGE), (0., 0.));
174 view.zoom_around(2., (0., 0.), STAGE);
175 view.pan_by((-5000., -5000.), STAGE);
176 assert_eq!(view.offset(STAGE), (-800., -450.));
177 view.pan_by((5000., 5000.), STAGE);
178 assert_eq!(view.offset(STAGE), (0., 0.));
179 }
180
181 #[test]
182 fn keyboard_steps_zoom_around_the_center_and_zero_resets() {
183 let mut view = ShareView::default();
184 view.step_in(STAGE);
185 view.step_in(STAGE);
186 assert_eq!(view.percent(), 156);
187 view.step_out(STAGE);
188 assert_eq!(view.percent(), 125);
189 view.reset();
190 assert_eq!(view.percent(), 100);
191 }
192
193 #[test]
194 fn wheel_up_zooms_in_and_down_zooms_out() {
195 let mut view = ShareView::default();
196 view.zoom_wheel(120., (400., 225.), STAGE);
197 assert!(view.zoom() > 1.);
198 let zoomed = view.zoom();
199 view.zoom_wheel(-60., (400., 225.), STAGE);
200 assert!(view.zoom() < zoomed);
201 }
202
203 #[test]
204 fn the_strip_width_stays_between_160_and_400_and_follows_the_pointer() {
205 let drag = StripDrag { start_pointer: 900., start_width: 232. };
206 assert_eq!(drag.width_at(880.), 252.);
207 assert_eq!(drag.width_at(0.), STRIP_MAX_WIDTH);
208 assert_eq!(drag.width_at(2000.), STRIP_MIN_WIDTH);
209 assert_eq!(clamp_strip_width(10.), STRIP_MIN_WIDTH);
210 }
211 }
@@ -0,0 +1,211 @@
1use std::cell::Cell;
2use std::rc::Rc;
3
4pub const ZOOM_MIN: f32 = 1.;
5pub const ZOOM_MAX: f32 = 4.;
6const ZOOM_STEP: f32 = 1.25;
7const WHEEL_ZOOM_PER_PIXEL: f32 = 0.0015;
8pub const STRIP_MIN_WIDTH: f32 = 160.;
9pub const STRIP_MAX_WIDTH: f32 = 400.;
10pub const STRIP_DEFAULT_WIDTH: f32 = 232.;
11pub const STRIP_WIDTH_META_KEY: &str = "call_strip_width";
12pub const SHARE_MOTION_META_KEY: &str = "call_share_motion";
13pub const SHARE_STANDOUT_META_KEY: &str = "call_share_standout";
14
15#[derive(Debug, Clone, Copy, PartialEq)]
16pub struct ShareView {
17 zoom: f32,
18 offset: (f32, f32),
19}
20
21impl Default for ShareView {
22 fn default() -> Self {
23 ShareView { zoom: ZOOM_MIN, offset: (0., 0.) }
24 }
25}
26
27fn clamp_axis(offset: f32, extent: f32, zoom: f32) -> f32 {
28 offset.clamp(extent - extent * zoom, 0.)
29}
30
31impl ShareView {
32 pub fn zoom(&self) -> f32 {
33 self.zoom
34 }
35
36 pub fn is_zoomed(&self) -> bool {
37 self.zoom > ZOOM_MIN
38 }
39
40 pub fn percent(&self) -> u32 {
41 (self.zoom * 100.).round() as u32
42 }
43
44 pub fn offset(&self, stage: (f32, f32)) -> (f32, f32) {
45 (clamp_axis(self.offset.0, stage.0, self.zoom), clamp_axis(self.offset.1, stage.1, self.zoom))
46 }
47
48 pub fn reset(&mut self) {
49 *self = ShareView::default();
50 }
51
52 pub fn zoom_around(&mut self, factor: f32, pointer: (f32, f32), stage: (f32, f32)) {
53 let target = (self.zoom * factor).clamp(ZOOM_MIN, ZOOM_MAX);
54 if target <= ZOOM_MIN {
55 self.reset();
56 return;
57 }
58 let (offset_x, offset_y) = self.offset(stage);
59 let ratio = target / self.zoom;
60 self.zoom = target;
61 self.offset = (pointer.0 - (pointer.0 - offset_x) * ratio, pointer.1 - (pointer.1 - offset_y) * ratio);
62 self.offset = self.offset(stage);
63 }
64
65 pub fn zoom_wheel(&mut self, scroll_pixels: f32, pointer: (f32, f32), stage: (f32, f32)) {
66 self.zoom_around((scroll_pixels * WHEEL_ZOOM_PER_PIXEL).exp(), pointer, stage);
67 }
68
69 pub fn step_in(&mut self, stage: (f32, f32)) {
70 self.zoom_around(ZOOM_STEP, (stage.0 / 2., stage.1 / 2.), stage);
71 }
72
73 pub fn step_out(&mut self, stage: (f32, f32)) {
74 self.zoom_around(1. / ZOOM_STEP, (stage.0 / 2., stage.1 / 2.), stage);
75 }
76
77 pub fn pan_by(&mut self, delta: (f32, f32), stage: (f32, f32)) {
78 if !self.is_zoomed() {
79 return;
80 }
81 let (offset_x, offset_y) = self.offset(stage);
82 self.offset = (offset_x + delta.0, offset_y + delta.1);
83 self.offset = self.offset(stage);
84 }
85}
86
87pub fn clamp_strip_width(width: f32) -> f32 {
88 width.clamp(STRIP_MIN_WIDTH, STRIP_MAX_WIDTH)
89}
90
91pub fn load_strip_width(store: &store::Store) -> f32 {
92 store
93 .meta(STRIP_WIDTH_META_KEY)
94 .ok()
95 .flatten()
96 .and_then(|text| text.parse().ok())
97 .map_or(STRIP_DEFAULT_WIDTH, clamp_strip_width)
98}
99
100pub fn load_flag(store: &store::Store, key: &str) -> bool {
101 store.meta(key).ok().flatten().as_deref() == Some("1")
102}
103
104#[derive(Debug, Clone, Copy, PartialEq)]
105pub struct StripDrag {
106 pub start_pointer: f32,
107 pub start_width: f32,
108}
109
110impl StripDrag {
111 pub fn width_at(&self, pointer: f32) -> f32 {
112 clamp_strip_width(self.start_width + self.start_pointer - pointer)
113 }
114}
115
116#[derive(Default)]
117pub struct ShareStage {
118 pub view: ShareView,
119 pub pan_from: Option<(f32, f32)>,
120 pub strip_drag: Option<StripDrag>,
121 pub popped: bool,
122 pub bounds: Rc<Cell<(f32, f32, f32, f32)>>,
123}
124
125impl ShareStage {
126 pub fn size(&self) -> (f32, f32) {
127 let (_, _, width, height) = self.bounds.get();
128 (width, height)
129 }
130
131 pub fn pointer(&self, position: (f32, f32)) -> (f32, f32) {
132 let (left, top, _, _) = self.bounds.get();
133 (position.0 - left, position.1 - top)
134 }
135
136 pub fn end(&mut self) {
137 self.view.reset();
138 self.pan_from = None;
139 self.popped = false;
140 }
141}
142
143#[cfg(test)]
144mod tests {
145 use super::*;
146
147 const STAGE: (f32, f32) = (800., 450.);
148
149 #[test]
150 fn zooming_keeps_the_point_under_the_pointer_still() {
151 let mut view = ShareView::default();
152 let pointer = (600., 100.);
153 view.zoom_around(2., pointer, STAGE);
154 let (offset_x, offset_y) = view.offset(STAGE);
155 let content = ((pointer.0 - offset_x) / view.zoom(), (pointer.1 - offset_y) / view.zoom());
156 assert!((content.0 - 600.).abs() < 0.01 && (content.1 - 100.).abs() < 0.01);
157 }
158
159 #[test]
160 fn zoom_stays_between_one_and_four_times() {
161 let mut view = ShareView::default();
162 view.zoom_around(100., (400., 225.), STAGE);
163 assert_eq!(view.zoom(), ZOOM_MAX);
164 view.zoom_around(0.0001, (400., 225.), STAGE);
165 assert!(!view.is_zoomed());
166 assert_eq!(view.offset(STAGE), (0., 0.));
167 }
168
169 #[test]
170 fn panning_never_leaves_the_content() {
171 let mut view = ShareView::default();
172 view.pan_by((50., 50.), STAGE);
173 assert_eq!(view.offset(STAGE), (0., 0.));
174 view.zoom_around(2., (0., 0.), STAGE);
175 view.pan_by((-5000., -5000.), STAGE);
176 assert_eq!(view.offset(STAGE), (-800., -450.));
177 view.pan_by((5000., 5000.), STAGE);
178 assert_eq!(view.offset(STAGE), (0., 0.));
179 }
180
181 #[test]
182 fn keyboard_steps_zoom_around_the_center_and_zero_resets() {
183 let mut view = ShareView::default();
184 view.step_in(STAGE);
185 view.step_in(STAGE);
186 assert_eq!(view.percent(), 156);
187 view.step_out(STAGE);
188 assert_eq!(view.percent(), 125);
189 view.reset();
190 assert_eq!(view.percent(), 100);
191 }
192
193 #[test]
194 fn wheel_up_zooms_in_and_down_zooms_out() {
195 let mut view = ShareView::default();
196 view.zoom_wheel(120., (400., 225.), STAGE);
197 assert!(view.zoom() > 1.);
198 let zoomed = view.zoom();
199 view.zoom_wheel(-60., (400., 225.), STAGE);
200 assert!(view.zoom() < zoomed);
201 }
202
203 #[test]
204 fn the_strip_width_stays_between_160_and_400_and_follows_the_pointer() {
205 let drag = StripDrag { start_pointer: 900., start_width: 232. };
206 assert_eq!(drag.width_at(880.), 252.);
207 assert_eq!(drag.width_at(0.), STRIP_MAX_WIDTH);
208 assert_eq!(drag.width_at(2000.), STRIP_MIN_WIDTH);
209 assert_eq!(clamp_strip_width(10.), STRIP_MIN_WIDTH);
210 }
211}
crates/app/src/layout_guard.rs +30 −2
@@ -150,6 +150,12 @@ mod frames {
150 150 "shell/islands/main/call-stage",
151 151 "shell/islands/main/call-controls",
152 152 ];
153 const SHARE_GUARDED: &[&str] = &[
154 "shell/islands/main/call-stage/share-content",
155 "shell/islands/main/call-stage/share-content/zoom-chip",
156 "shell/islands/main/call-stage/share-divider",
157 "shell/islands/main/call-stage/share-strip",
158 ];
153 159 const MENU: &str = "popup-menu";
154 160 const OWN_STATUS: &str = "shell/title-bar/own-status";
155 161 const RECAP_TAB: &str = "shell/islands/main/recap-tab";
@@ -164,6 +170,7 @@ mod frames {
164 170 Tab(&'static str, Option<fn(&mut VisualTestContext)>),
165 171 StatusMenu,
166 172 Call,
173 CallShare,
167 174 }
168 175
169 176 fn parent_of(path: &str) -> Option<&str> {
@@ -279,11 +286,19 @@ mod frames {
279 286 GUARDED
280 287 .iter()
281 288 .chain(CALL_GUARDED)
289 .chain(SHARE_GUARDED)
282 290 .chain([&MENU, &RECAP_TAB, &RECAP_REGION])
283 291 .filter_map(|path| visual.debug_bounds(path).map(|bounds| (*path, bounds)))
284 292 .collect()
285 293 }
286 294
295 fn sharing_call() -> ActiveCall {
296 let mut call = gallery_call();
297 call.model.apply(CallUpdate::ScreenShare(Some("8:orgid:guard-1".to_owned())));
298 call.share_stage.view.step_in((800., 450.));
299 call
300 }
301
287 302 fn gallery_call() -> ActiveCall {
288 303 let (handle, _control) = call_channel();
289 304 let mut model = CallModel::meeting("Standup", false);
@@ -395,6 +410,7 @@ mod frames {
395 410 Screen::Tab("calls", Some(|visual| visual.dispatch_action(OpenCallsTab))),
396 411 Screen::StatusMenu,
397 412 Screen::Call,
413 Screen::CallShare,
398 414 ];
399 415 for screen in screens {
400 416 let (screen_name, status_menu) = match screen {
@@ -413,6 +429,15 @@ mod frames {
413 429 });
414 430 ("call", false)
415 431 }
432 Screen::CallShare => {
433 visual.update(|_, cx| {
434 app.update(cx, |state, cx| {
435 state.call = Some(sharing_call());
436 cx.notify();
437 })
438 });
439 ("call-share", false)
440 }
416 441 Screen::StatusMenu => {
417 442 let tags = collect(&mut visual, None);
418 443 let button = tags
@@ -426,9 +451,12 @@ mod frames {
426 451 };
427 452 let tags = collect(&mut visual, status_menu.then_some(MENU));
428 453 let mut expected = GUARDED.to_vec();
429 if screen_name == "call" {
454 if matches!(screen_name, "call" | "call-share") {
430 455 expected.extend(CALL_GUARDED);
431 456 }
457 if screen_name == "call-share" {
458 expected.extend(SHARE_GUARDED);
459 }
432 460 if status_menu {
433 461 expected.push(MENU);
434 462 }
@@ -457,7 +485,7 @@ mod frames {
457 485 visual.simulate_keystrokes("escape");
458 486 visual.run_until_parked();
459 487 }
460 if screen_name == "call" {
488 if matches!(screen_name, "call" | "call-share") {
461 489 visual.update(|_, cx| {
462 490 app.update(cx, |state, cx| {
463 491 state.call = None;
@@ -150,6 +150,12 @@ mod frames {
150 "shell/islands/main/call-stage",
150 "shell/islands/main/call-stage",
151 "shell/islands/main/call-controls",
151 "shell/islands/main/call-controls",
152 ];
152 ];
153 const SHARE_GUARDED: &[&str] = &[
154 "shell/islands/main/call-stage/share-content",
155 "shell/islands/main/call-stage/share-content/zoom-chip",
156 "shell/islands/main/call-stage/share-divider",
157 "shell/islands/main/call-stage/share-strip",
158 ];
153 const MENU: &str = "popup-menu";
159 const MENU: &str = "popup-menu";
154 const OWN_STATUS: &str = "shell/title-bar/own-status";
160 const OWN_STATUS: &str = "shell/title-bar/own-status";
155 const RECAP_TAB: &str = "shell/islands/main/recap-tab";
161 const RECAP_TAB: &str = "shell/islands/main/recap-tab";
@@ -164,6 +170,7 @@ mod frames {
164 Tab(&'static str, Option<fn(&mut VisualTestContext)>),
170 Tab(&'static str, Option<fn(&mut VisualTestContext)>),
165 StatusMenu,
171 StatusMenu,
166 Call,
172 Call,
173 CallShare,
167 }
174 }
168
175
169 fn parent_of(path: &str) -> Option<&str> {
176 fn parent_of(path: &str) -> Option<&str> {
@@ -279,11 +286,19 @@ mod frames {
279 GUARDED
286 GUARDED
280 .iter()
287 .iter()
281 .chain(CALL_GUARDED)
288 .chain(CALL_GUARDED)
289 .chain(SHARE_GUARDED)
282 .chain([&MENU, &RECAP_TAB, &RECAP_REGION])
290 .chain([&MENU, &RECAP_TAB, &RECAP_REGION])
283 .filter_map(|path| visual.debug_bounds(path).map(|bounds| (*path, bounds)))
291 .filter_map(|path| visual.debug_bounds(path).map(|bounds| (*path, bounds)))
284 .collect()
292 .collect()
285 }
293 }
286
294
295 fn sharing_call() -> ActiveCall {
296 let mut call = gallery_call();
297 call.model.apply(CallUpdate::ScreenShare(Some("8:orgid:guard-1".to_owned())));
298 call.share_stage.view.step_in((800., 450.));
299 call
300 }
301
287 fn gallery_call() -> ActiveCall {
302 fn gallery_call() -> ActiveCall {
288 let (handle, _control) = call_channel();
303 let (handle, _control) = call_channel();
289 let mut model = CallModel::meeting("Standup", false);
304 let mut model = CallModel::meeting("Standup", false);
@@ -395,6 +410,7 @@ mod frames {
395 Screen::Tab("calls", Some(|visual| visual.dispatch_action(OpenCallsTab))),
410 Screen::Tab("calls", Some(|visual| visual.dispatch_action(OpenCallsTab))),
396 Screen::StatusMenu,
411 Screen::StatusMenu,
397 Screen::Call,
412 Screen::Call,
413 Screen::CallShare,
398 ];
414 ];
399 for screen in screens {
415 for screen in screens {
400 let (screen_name, status_menu) = match screen {
416 let (screen_name, status_menu) = match screen {
@@ -413,6 +429,15 @@ mod frames {
413 });
429 });
414 ("call", false)
430 ("call", false)
415 }
431 }
432 Screen::CallShare => {
433 visual.update(|_, cx| {
434 app.update(cx, |state, cx| {
435 state.call = Some(sharing_call());
436 cx.notify();
437 })
438 });
439 ("call-share", false)
440 }
416 Screen::StatusMenu => {
441 Screen::StatusMenu => {
417 let tags = collect(&mut visual, None);
442 let tags = collect(&mut visual, None);
418 let button = tags
443 let button = tags
@@ -426,9 +451,12 @@ mod frames {
426 };
451 };
427 let tags = collect(&mut visual, status_menu.then_some(MENU));
452 let tags = collect(&mut visual, status_menu.then_some(MENU));
428 let mut expected = GUARDED.to_vec();
453 let mut expected = GUARDED.to_vec();
429 if screen_name == "call" {
454 if matches!(screen_name, "call" | "call-share") {
430 expected.extend(CALL_GUARDED);
455 expected.extend(CALL_GUARDED);
431 }
456 }
457 if screen_name == "call-share" {
458 expected.extend(SHARE_GUARDED);
459 }
432 if status_menu {
460 if status_menu {
433 expected.push(MENU);
461 expected.push(MENU);
434 }
462 }
@@ -457,7 +485,7 @@ mod frames {
457 visual.simulate_keystrokes("escape");
485 visual.simulate_keystrokes("escape");
458 visual.run_until_parked();
486 visual.run_until_parked();
459 }
487 }
460 if screen_name == "call" {
488 if matches!(screen_name, "call" | "call-share") {
461 visual.update(|_, cx| {
489 visual.update(|_, cx| {
462 app.update(cx, |state, cx| {
490 app.update(cx, |state, cx| {
463 state.call = None;
491 state.call = None;
crates/app/src/notify/platform/mod.rs +2 −0
@@ -3,6 +3,8 @@ mod windows_impl;
3 3 #[cfg(windows)]
4 4 pub use windows_impl::*;
5 5
6 #[cfg(target_os = "linux")]
7 mod x11_input;
6 8 #[cfg(not(windows))]
7 9 mod stub;
8 10 #[cfg(not(windows))]
@@ -3,6 +3,8 @@ mod windows_impl;
3#[cfg(windows)]
3#[cfg(windows)]
4pub use windows_impl::*;
4pub use windows_impl::*;
5
5
6#[cfg(target_os = "linux")]
7mod x11_input;
6#[cfg(not(windows))]
8#[cfg(not(windows))]
7mod stub;
9mod stub;
8#[cfg(not(windows))]
10#[cfg(not(windows))]
crates/app/src/notify/platform/stub.rs +7 −1
@@ -26,7 +26,13 @@ pub fn place(_handle: NativeHandle, _x: i32, _y: i32, _width: i32, _height: i32)
26 26
27 27 pub fn exclude_from_capture(_handle: NativeHandle) {}
28 28
29 pub fn make_click_through(_handle: NativeHandle) {}
29 #[cfg(target_os = "linux")]
30 pub fn make_window_click_through(window: &Window) {
31 super::x11_input::make_input_transparent(window);
32 }
33
34 #[cfg(not(target_os = "linux"))]
35 pub fn make_window_click_through(_window: &Window) {}
30 36
31 37 pub fn window_minimized(_handle: NativeHandle) -> bool {
32 38 false
@@ -26,7 +26,13 @@ pub fn place(_handle: NativeHandle, _x: i32, _y: i32, _width: i32, _height: i32)
26
26
27pub fn exclude_from_capture(_handle: NativeHandle) {}
27pub fn exclude_from_capture(_handle: NativeHandle) {}
28
28
29pub fn make_click_through(_handle: NativeHandle) {}
29#[cfg(target_os = "linux")]
30pub fn make_window_click_through(window: &Window) {
31 super::x11_input::make_input_transparent(window);
32}
33
34#[cfg(not(target_os = "linux"))]
35pub fn make_window_click_through(_window: &Window) {}
30
36
31pub fn window_minimized(_handle: NativeHandle) -> bool {
37pub fn window_minimized(_handle: NativeHandle) -> bool {
32 false
38 false
crates/app/src/notify/platform/windows_impl.rs +7 −1
@@ -197,7 +197,13 @@ pub fn exclude_from_capture(handle: NativeHandle) {
197 197 }
198 198 }
199 199
200 pub fn make_click_through(handle: NativeHandle) {
200 pub fn make_window_click_through(window: &Window) {
201 if let Some(handle) = native_handle(window) {
202 make_click_through(handle);
203 }
204 }
205
206 fn make_click_through(handle: NativeHandle) {
201 207 unsafe {
202 208 let style = GetWindowLongPtrW(hwnd(handle), GWL_EXSTYLE);
203 209 let added = (WS_EX_LAYERED | WS_EX_TRANSPARENT | WS_EX_NOACTIVATE).0 as isize;
@@ -197,7 +197,13 @@ pub fn exclude_from_capture(handle: NativeHandle) {
197 }
197 }
198}
198}
199
199
200pub fn make_click_through(handle: NativeHandle) {
200pub fn make_window_click_through(window: &Window) {
201 if let Some(handle) = native_handle(window) {
202 make_click_through(handle);
203 }
204}
205
206fn make_click_through(handle: NativeHandle) {
201 unsafe {
207 unsafe {
202 let style = GetWindowLongPtrW(hwnd(handle), GWL_EXSTYLE);
208 let style = GetWindowLongPtrW(hwnd(handle), GWL_EXSTYLE);
203 let added = (WS_EX_LAYERED | WS_EX_TRANSPARENT | WS_EX_NOACTIVATE).0 as isize;
209 let added = (WS_EX_LAYERED | WS_EX_TRANSPARENT | WS_EX_NOACTIVATE).0 as isize;
crates/app/src/notify/platform/x11_input.rs added +84 −0
@@ -0,0 +1,84 @@
1 use gpui_kit::Window;
2 use raw_window_handle::{HasWindowHandle, RawWindowHandle};
3 use x11rb::protocol::shape::{ConnectionExt as _, SK, SO};
4 use x11rb::protocol::xproto::ClipOrdering;
5 use x11rb::rust_connection::RustConnection;
6
7 fn x11_window_id(window: &Window) -> Option<u32> {
8 match HasWindowHandle::window_handle(window).ok()?.as_raw() {
9 RawWindowHandle::Xcb(handle) => Some(handle.window.get()),
10 RawWindowHandle::Xlib(handle) => u32::try_from(handle.window).ok(),
11 _ => None,
12 }
13 }
14
15 pub fn empty_input_region(display: Option<&str>, window: u32) -> Result<(), Box<dyn std::error::Error>> {
16 let (connection, _) = RustConnection::connect(display)?;
17 connection
18 .shape_rectangles(SO::SET, SK::INPUT, ClipOrdering::UNSORTED, window, 0, 0, &[])?
19 .check()?;
20 Ok(())
21 }
22
23 pub fn make_input_transparent(window: &Window) {
24 if let Some(id) = x11_window_id(window) {
25 let _ = empty_input_region(None, id);
26 }
27 }
28
29 #[cfg(test)]
30 mod tests {
31 use std::process::{Child, Command, Stdio};
32 use std::time::Duration;
33
34 use x11rb::connection::Connection;
35 use x11rb::protocol::xproto::{ConnectionExt as _, CreateWindowAux, WindowClass};
36 use x11rb::COPY_DEPTH_FROM_PARENT;
37
38 use super::*;
39
40 struct Server(Child);
41
42 impl Drop for Server {
43 fn drop(&mut self) {
44 let _ = self.0.kill();
45 }
46 }
47
48 fn start_server(display: &str) -> Option<Server> {
49 let child = Command::new("Xvfb")
50 .args([display, "-screen", "0", "320x200x24", "-nolisten", "tcp", "-noreset"])
51 .stdout(Stdio::null())
52 .stderr(Stdio::null())
53 .spawn()
54 .ok()?;
55 let server = Server(child);
56 for _ in 0..50 {
57 if RustConnection::connect(Some(display)).is_ok() {
58 return Some(server);
59 }
60 std::thread::sleep(Duration::from_millis(100));
61 }
62 None
63 }
64
65 #[test]
66 fn the_border_window_gets_an_empty_input_region() {
67 let display = ":87";
68 let Some(_server) = start_server(display) else {
69 return;
70 };
71 let (connection, screen_number) = RustConnection::connect(Some(display)).unwrap();
72 let root = connection.setup().roots[screen_number].root;
73 let window = connection.generate_id().unwrap();
74 connection
75 .create_window(COPY_DEPTH_FROM_PARENT, window, root, 0, 0, 100, 100, 0, WindowClass::INPUT_OUTPUT, 0, &CreateWindowAux::new())
76 .unwrap();
77 connection.flush().unwrap();
78 let before = connection.shape_get_rectangles(window, SK::INPUT).unwrap().reply().unwrap();
79 assert_eq!(before.rectangles.len(), 1);
80 empty_input_region(Some(display), window).unwrap();
81 let after = connection.shape_get_rectangles(window, SK::INPUT).unwrap().reply().unwrap();
82 assert!(after.rectangles.is_empty());
83 }
84 }
@@ -0,0 +1,84 @@
1use gpui_kit::Window;
2use raw_window_handle::{HasWindowHandle, RawWindowHandle};
3use x11rb::protocol::shape::{ConnectionExt as _, SK, SO};
4use x11rb::protocol::xproto::ClipOrdering;
5use x11rb::rust_connection::RustConnection;
6
7fn x11_window_id(window: &Window) -> Option<u32> {
8 match HasWindowHandle::window_handle(window).ok()?.as_raw() {
9 RawWindowHandle::Xcb(handle) => Some(handle.window.get()),
10 RawWindowHandle::Xlib(handle) => u32::try_from(handle.window).ok(),
11 _ => None,
12 }
13}
14
15pub fn empty_input_region(display: Option<&str>, window: u32) -> Result<(), Box<dyn std::error::Error>> {
16 let (connection, _) = RustConnection::connect(display)?;
17 connection
18 .shape_rectangles(SO::SET, SK::INPUT, ClipOrdering::UNSORTED, window, 0, 0, &[])?
19 .check()?;
20 Ok(())
21}
22
23pub fn make_input_transparent(window: &Window) {
24 if let Some(id) = x11_window_id(window) {
25 let _ = empty_input_region(None, id);
26 }
27}
28
29#[cfg(test)]
30mod tests {
31 use std::process::{Child, Command, Stdio};
32 use std::time::Duration;
33
34 use x11rb::connection::Connection;
35 use x11rb::protocol::xproto::{ConnectionExt as _, CreateWindowAux, WindowClass};
36 use x11rb::COPY_DEPTH_FROM_PARENT;
37
38 use super::*;
39
40 struct Server(Child);
41
42 impl Drop for Server {
43 fn drop(&mut self) {
44 let _ = self.0.kill();
45 }
46 }
47
48 fn start_server(display: &str) -> Option<Server> {
49 let child = Command::new("Xvfb")
50 .args([display, "-screen", "0", "320x200x24", "-nolisten", "tcp", "-noreset"])
51 .stdout(Stdio::null())
52 .stderr(Stdio::null())
53 .spawn()
54 .ok()?;
55 let server = Server(child);
56 for _ in 0..50 {
57 if RustConnection::connect(Some(display)).is_ok() {
58 return Some(server);
59 }
60 std::thread::sleep(Duration::from_millis(100));
61 }
62 None
63 }
64
65 #[test]
66 fn the_border_window_gets_an_empty_input_region() {
67 let display = ":87";
68 let Some(_server) = start_server(display) else {
69 return;
70 };
71 let (connection, screen_number) = RustConnection::connect(Some(display)).unwrap();
72 let root = connection.setup().roots[screen_number].root;
73 let window = connection.generate_id().unwrap();
74 connection
75 .create_window(COPY_DEPTH_FROM_PARENT, window, root, 0, 0, 100, 100, 0, WindowClass::INPUT_OUTPUT, 0, &CreateWindowAux::new())
76 .unwrap();
77 connection.flush().unwrap();
78 let before = connection.shape_get_rectangles(window, SK::INPUT).unwrap().reply().unwrap();
79 assert_eq!(before.rectangles.len(), 1);
80 empty_input_region(Some(display), window).unwrap();
81 let after = connection.shape_get_rectangles(window, SK::INPUT).unwrap().reply().unwrap();
82 assert!(after.rectangles.is_empty());
83 }
84}
crates/app/src/views/call_layouts.rs +62 −13
@@ -14,7 +14,7 @@ use gpui_kit::*;
14 14 use super::avatar::person_avatar;
15 15 use super::call_organizer::render_focus_stage;
16 16 use super::call_view::{
17 GRID_PADDING, STRIP_GAP, STRIP_TILE, STRIP_VISIBLE, TILE_GAP, own_tile, person_tile,
17 GRID_PADDING, STRIP_GAP, STRIP_VISIBLE, TILE_GAP, own_tile, person_tile,
18 18 };
19 19 use super::widgets::icon;
20 20 use crate::app_state::AppState;
@@ -28,6 +28,8 @@ use crate::theme;
28 28 const FALLBACK_STAGE: (f32, f32) = (900., 560.);
29 29 const MEASURE_TOLERANCE: f32 = 0.5;
30 30 const OVERLAY_INSET: f32 = 16.;
31 const DIVIDER_LINE: f32 = 4.;
32 const DIVIDER_LENGTH: f32 = 48.;
31 33 const CHIP_TOP: f32 = 12.;
32 34 const FILMSTRIP_TILE_MAX: f32 = 220.;
33 35 const TILE_RADIUS: f32 = 12.;
@@ -497,46 +499,93 @@ fn people_strip(
497 499 state: &AppState,
498 500 model: &CallModel,
499 501 now: Instant,
502 available: (f32, f32),
500 503 ) -> Stateful<Div> {
504 let strip_width = state.call_strip_width.min(((available.0 - TILE_GAP) / 2.).max(0.));
505 let tile = TileSize::sixteen_by_nine(strip_width);
501 506 let mut cells: Vec<AnyElement> = model
502 507 .strip_tiles()
503 508 .into_iter()
504 .filter(|tile| !model.hidden_for_no_video(tile))
505 .map(|remote| person_tile(app, state, model, remote, STRIP_TILE, now))
509 .filter(|tile_model| !model.hidden_for_no_video(tile_model))
510 .map(|remote| person_tile(app, state, model, remote, tile, now))
506 511 .collect();
507 512 if model.own_cells() > 0 {
508 513 let own_index = model.own_cell_index(cells.len());
509 cells.insert(own_index, own_tile(app, state, model, STRIP_TILE, now));
514 cells.insert(own_index, own_tile(app, state, model, tile, now));
510 515 }
511 516 v_flex()
512 517 .id("call-strip")
518 .debug_selector(|| "shell/islands/main/call-stage/share-strip".into())
513 519 .flex_none()
514 .w(px(STRIP_TILE.width))
515 .max_h(px(
516 STRIP_VISIBLE * (STRIP_TILE.height + STRIP_GAP) - STRIP_GAP
517 ))
520 .w(px(tile.width))
521 .max_h(px((STRIP_VISIBLE * (tile.height + STRIP_GAP) - STRIP_GAP).min(available.1)))
518 522 .gap(px(STRIP_GAP))
519 523 .overflow_y_scroll()
520 524 .children(cells)
521 525 }
522 526
527 fn strip_divider(app: &Entity<AppState>, dragging: bool) -> Stateful<Div> {
528 let app = app.clone();
529 h_flex()
530 .id("call-strip-divider")
531 .debug_selector(|| "shell/islands/main/call-stage/share-divider".into())
532 .flex_none()
533 .w(px(TILE_GAP))
534 .h_full()
535 .items_center()
536 .justify_center()
537 .cursor_col_resize()
538 .child(
539 div()
540 .w(px(DIVIDER_LINE))
541 .h(px(DIVIDER_LENGTH))
542 .rounded_full()
543 .bg(if dragging { theme::accent() } else { theme::border() }),
544 )
545 .on_mouse_down(MouseButton::Left, move |event, _, cx| {
546 let pointer_x = f32::from(event.position.x);
547 app.update(cx, |state, cx| state.begin_strip_drag(pointer_x, cx));
548 })
549 }
550
523 551 fn share_body(
524 552 app: &Entity<AppState>,
525 553 state: &AppState,
526 554 model: &CallModel,
527 555 now: Instant,
528 stage: AnyElement,
556 share: AnyElement,
529 557 layout: CallLayout,
558 stage: (f32, f32),
530 559 ) -> AnyElement {
560 let move_app = app.clone();
561 let up_app = app.clone();
562 let up_out_app = app.clone();
563 let dragging = state.call.as_ref().is_some_and(|call| call.share_stage.strip_drag.is_some());
531 564 h_flex()
565 .id("call-share-body")
532 566 .absolute()
533 567 .inset_0()
534 568 .p(px(GRID_PADDING))
535 .gap(px(TILE_GAP))
536 569 .items_center()
537 .child(stage)
570 .on_mouse_move(move |event, _, cx| {
571 let pointer_x = f32::from(event.position.x);
572 move_app.update(cx, |state, cx| state.drag_strip_to(pointer_x, cx));
573 })
574 .on_mouse_up(MouseButton::Left, move |_, _, cx| {
575 up_app.update(cx, |state, cx| state.end_strip_drag(cx));
576 })
577 .on_mouse_up_out(MouseButton::Left, move |_, _, cx| {
578 up_out_app.update(cx, |state, cx| state.end_strip_drag(cx));
579 })
580 .child(share)
538 581 .when(layout != CallLayout::Content, |row| {
539 row.child(people_strip(app, state, model, now))
582 row.child(strip_divider(app, dragging)).child(people_strip(
583 app,
584 state,
585 model,
586 now,
587 (stage.0 - 2. * GRID_PADDING, stage.1 - 2. * GRID_PADDING),
588 ))
540 589 })
541 590 .into_any_element()
542 591 }
@@ -588,7 +637,7 @@ pub(super) fn stage_region(
588 637 let shows_people = hold.is_none() && !(share_stage.is_some() && layout == CallLayout::Content);
589 638 let body = match (hold, share_stage) {
590 639 (Some(hold), _) => v_flex().absolute().inset_0().child(hold).into_any_element(),
591 (None, Some(share)) => share_body(app, state, model, now, share, layout),
640 (None, Some(share)) => share_body(app, state, model, now, share, layout, stage),
592 641 (None, None) if layout == CallLayout::Speaker => {
593 642 speaker_body(app, state, model, now, stage)
594 643 }
@@ -14,7 +14,7 @@ use gpui_kit::*;
14use super::avatar::person_avatar;
14use super::avatar::person_avatar;
15use super::call_organizer::render_focus_stage;
15use super::call_organizer::render_focus_stage;
16use super::call_view::{
16use super::call_view::{
17 GRID_PADDING, STRIP_GAP, STRIP_TILE, STRIP_VISIBLE, TILE_GAP, own_tile, person_tile,
17 GRID_PADDING, STRIP_GAP, STRIP_VISIBLE, TILE_GAP, own_tile, person_tile,
18};
18};
19use super::widgets::icon;
19use super::widgets::icon;
20use crate::app_state::AppState;
20use crate::app_state::AppState;
@@ -28,6 +28,8 @@ use crate::theme;
28const FALLBACK_STAGE: (f32, f32) = (900., 560.);
28const FALLBACK_STAGE: (f32, f32) = (900., 560.);
29const MEASURE_TOLERANCE: f32 = 0.5;
29const MEASURE_TOLERANCE: f32 = 0.5;
30const OVERLAY_INSET: f32 = 16.;
30const OVERLAY_INSET: f32 = 16.;
31const DIVIDER_LINE: f32 = 4.;
32const DIVIDER_LENGTH: f32 = 48.;
31const CHIP_TOP: f32 = 12.;
33const CHIP_TOP: f32 = 12.;
32const FILMSTRIP_TILE_MAX: f32 = 220.;
34const FILMSTRIP_TILE_MAX: f32 = 220.;
33const TILE_RADIUS: f32 = 12.;
35const TILE_RADIUS: f32 = 12.;
@@ -497,46 +499,93 @@ fn people_strip(
497 state: &AppState,
499 state: &AppState,
498 model: &CallModel,
500 model: &CallModel,
499 now: Instant,
501 now: Instant,
502 available: (f32, f32),
500) -> Stateful<Div> {
503) -> Stateful<Div> {
504 let strip_width = state.call_strip_width.min(((available.0 - TILE_GAP) / 2.).max(0.));
505 let tile = TileSize::sixteen_by_nine(strip_width);
501 let mut cells: Vec<AnyElement> = model
506 let mut cells: Vec<AnyElement> = model
502 .strip_tiles()
507 .strip_tiles()
503 .into_iter()
508 .into_iter()
504 .filter(|tile| !model.hidden_for_no_video(tile))
509 .filter(|tile_model| !model.hidden_for_no_video(tile_model))
505 .map(|remote| person_tile(app, state, model, remote, STRIP_TILE, now))
510 .map(|remote| person_tile(app, state, model, remote, tile, now))
506 .collect();
511 .collect();
507 if model.own_cells() > 0 {
512 if model.own_cells() > 0 {
508 let own_index = model.own_cell_index(cells.len());
513 let own_index = model.own_cell_index(cells.len());
509 cells.insert(own_index, own_tile(app, state, model, STRIP_TILE, now));
514 cells.insert(own_index, own_tile(app, state, model, tile, now));
510 }
515 }
511 v_flex()
516 v_flex()
512 .id("call-strip")
517 .id("call-strip")
518 .debug_selector(|| "shell/islands/main/call-stage/share-strip".into())
513 .flex_none()
519 .flex_none()
514 .w(px(STRIP_TILE.width))
520 .w(px(tile.width))
515 .max_h(px(
521 .max_h(px((STRIP_VISIBLE * (tile.height + STRIP_GAP) - STRIP_GAP).min(available.1)))
516 STRIP_VISIBLE * (STRIP_TILE.height + STRIP_GAP) - STRIP_GAP
517 ))
518 .gap(px(STRIP_GAP))
522 .gap(px(STRIP_GAP))
519 .overflow_y_scroll()
523 .overflow_y_scroll()
520 .children(cells)
524 .children(cells)
521}
525}
522
526
527fn strip_divider(app: &Entity<AppState>, dragging: bool) -> Stateful<Div> {
528 let app = app.clone();
529 h_flex()
530 .id("call-strip-divider")
531 .debug_selector(|| "shell/islands/main/call-stage/share-divider".into())
532 .flex_none()
533 .w(px(TILE_GAP))
534 .h_full()
535 .items_center()
536 .justify_center()
537 .cursor_col_resize()
538 .child(
539 div()
540 .w(px(DIVIDER_LINE))
541 .h(px(DIVIDER_LENGTH))
542 .rounded_full()
543 .bg(if dragging { theme::accent() } else { theme::border() }),
544 )
545 .on_mouse_down(MouseButton::Left, move |event, _, cx| {
546 let pointer_x = f32::from(event.position.x);
547 app.update(cx, |state, cx| state.begin_strip_drag(pointer_x, cx));
548 })
549}
550
523fn share_body(
551fn share_body(
524 app: &Entity<AppState>,
552 app: &Entity<AppState>,
525 state: &AppState,
553 state: &AppState,
526 model: &CallModel,
554 model: &CallModel,
527 now: Instant,
555 now: Instant,
528 stage: AnyElement,
556 share: AnyElement,
529 layout: CallLayout,
557 layout: CallLayout,
558 stage: (f32, f32),
530) -> AnyElement {
559) -> AnyElement {
560 let move_app = app.clone();
561 let up_app = app.clone();
562 let up_out_app = app.clone();
563 let dragging = state.call.as_ref().is_some_and(|call| call.share_stage.strip_drag.is_some());
531 h_flex()
564 h_flex()
565 .id("call-share-body")
532 .absolute()
566 .absolute()
533 .inset_0()
567 .inset_0()
534 .p(px(GRID_PADDING))
568 .p(px(GRID_PADDING))
535 .gap(px(TILE_GAP))
536 .items_center()
569 .items_center()
537 .child(stage)
570 .on_mouse_move(move |event, _, cx| {
571 let pointer_x = f32::from(event.position.x);
572 move_app.update(cx, |state, cx| state.drag_strip_to(pointer_x, cx));
573 })
574 .on_mouse_up(MouseButton::Left, move |_, _, cx| {
575 up_app.update(cx, |state, cx| state.end_strip_drag(cx));
576 })
577 .on_mouse_up_out(MouseButton::Left, move |_, _, cx| {
578 up_out_app.update(cx, |state, cx| state.end_strip_drag(cx));
579 })
580 .child(share)
538 .when(layout != CallLayout::Content, |row| {
581 .when(layout != CallLayout::Content, |row| {
539 row.child(people_strip(app, state, model, now))
582 row.child(strip_divider(app, dragging)).child(people_strip(
583 app,
584 state,
585 model,
586 now,
587 (stage.0 - 2. * GRID_PADDING, stage.1 - 2. * GRID_PADDING),
588 ))
540 })
589 })
541 .into_any_element()
590 .into_any_element()
542}
591}
@@ -588,7 +637,7 @@ pub(super) fn stage_region(
588 let shows_people = hold.is_none() && !(share_stage.is_some() && layout == CallLayout::Content);
637 let shows_people = hold.is_none() && !(share_stage.is_some() && layout == CallLayout::Content);
589 let body = match (hold, share_stage) {
638 let body = match (hold, share_stage) {
590 (Some(hold), _) => v_flex().absolute().inset_0().child(hold).into_any_element(),
639 (Some(hold), _) => v_flex().absolute().inset_0().child(hold).into_any_element(),
591 (None, Some(share)) => share_body(app, state, model, now, share, layout),
640 (None, Some(share)) => share_body(app, state, model, now, share, layout, stage),
592 (None, None) if layout == CallLayout::Speaker => {
641 (None, None) if layout == CallLayout::Speaker => {
593 speaker_body(app, state, model, now, stage)
642 speaker_body(app, state, model, now, stage)
594 }
643 }
crates/app/src/views/call_pop_out.rs added +67 −0
@@ -0,0 +1,67 @@
1 use gpui_kit::component::v_flex;
2 use gpui_kit::*;
3
4 use super::call_stage::{StageMode, render_stage};
5 use super::shortcuts::{ZoomShareIn, ZoomShareOut, ZoomShareReset};
6 use crate::app_state::AppState;
7 use crate::call::ZoomStep;
8 use crate::theme;
9
10 pub const POP_OUT_TITLE: &str = "Shared content";
11 pub const POP_OUT_SIZE: (f32, f32) = (960., 600.);
12 const KEY_CONTEXT: &str = "SharePopOut";
13
14 pub struct SharePopOutView {
15 app: Entity<AppState>,
16 focus: FocusHandle,
17 _app_subscription: Subscription,
18 _media_subscription: Option<Subscription>,
19 }
20
21 impl SharePopOutView {
22 pub fn new(app: Entity<AppState>, window: &mut Window, cx: &mut Context<Self>) -> Self {
23 let app_subscription = cx.observe(&app, |_, _, cx| cx.notify());
24 let media_subscription = app
25 .read(cx)
26 .call_media
27 .clone()
28 .map(|media| cx.observe(&media, |_, _, cx| cx.notify()));
29 let closing_app = app.clone();
30 window.on_window_should_close(cx, move |_, cx| {
31 closing_app.update(cx, |state, cx| state.return_stage_from_pop_out(cx));
32 true
33 });
34 let focus = cx.focus_handle();
35 window.focus(&focus, cx);
36 SharePopOutView {
37 app,
38 focus,
39 _app_subscription: app_subscription,
40 _media_subscription: media_subscription,
41 }
42 }
43 }
44
45 pub fn zoom_listener<A: Action>(
46 app: &Entity<AppState>,
47 step: ZoomStep,
48 ) -> impl Fn(&A, &mut Window, &mut App) + 'static {
49 let app = app.clone();
50 move |_, _, cx| app.update(cx, |state, cx| state.zoom_share(step, cx))
51 }
52
53 impl Render for SharePopOutView {
54 fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
55 let state = self.app.read(cx);
56 v_flex()
57 .id("share-pop-out")
58 .key_context(KEY_CONTEXT)
59 .track_focus(&self.focus)
60 .size_full()
61 .bg(theme::background())
62 .on_action(zoom_listener::<ZoomShareIn>(&self.app, ZoomStep::In))
63 .on_action(zoom_listener::<ZoomShareOut>(&self.app, ZoomStep::Out))
64 .on_action(zoom_listener::<ZoomShareReset>(&self.app, ZoomStep::Reset))
65 .children(render_stage(&self.app, state, StageMode::PopOut))
66 }
67 }
@@ -0,0 +1,67 @@
1use gpui_kit::component::v_flex;
2use gpui_kit::*;
3
4use super::call_stage::{StageMode, render_stage};
5use super::shortcuts::{ZoomShareIn, ZoomShareOut, ZoomShareReset};
6use crate::app_state::AppState;
7use crate::call::ZoomStep;
8use crate::theme;
9
10pub const POP_OUT_TITLE: &str = "Shared content";
11pub const POP_OUT_SIZE: (f32, f32) = (960., 600.);
12const KEY_CONTEXT: &str = "SharePopOut";
13
14pub struct SharePopOutView {
15 app: Entity<AppState>,
16 focus: FocusHandle,
17 _app_subscription: Subscription,
18 _media_subscription: Option<Subscription>,
19}
20
21impl SharePopOutView {
22 pub fn new(app: Entity<AppState>, window: &mut Window, cx: &mut Context<Self>) -> Self {
23 let app_subscription = cx.observe(&app, |_, _, cx| cx.notify());
24 let media_subscription = app
25 .read(cx)
26 .call_media
27 .clone()
28 .map(|media| cx.observe(&media, |_, _, cx| cx.notify()));
29 let closing_app = app.clone();
30 window.on_window_should_close(cx, move |_, cx| {
31 closing_app.update(cx, |state, cx| state.return_stage_from_pop_out(cx));
32 true
33 });
34 let focus = cx.focus_handle();
35 window.focus(&focus, cx);
36 SharePopOutView {
37 app,
38 focus,
39 _app_subscription: app_subscription,
40 _media_subscription: media_subscription,
41 }
42 }
43}
44
45pub fn zoom_listener<A: Action>(
46 app: &Entity<AppState>,
47 step: ZoomStep,
48) -> impl Fn(&A, &mut Window, &mut App) + 'static {
49 let app = app.clone();
50 move |_, _, cx| app.update(cx, |state, cx| state.zoom_share(step, cx))
51}
52
53impl Render for SharePopOutView {
54 fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
55 let state = self.app.read(cx);
56 v_flex()
57 .id("share-pop-out")
58 .key_context(KEY_CONTEXT)
59 .track_focus(&self.focus)
60 .size_full()
61 .bg(theme::background())
62 .on_action(zoom_listener::<ZoomShareIn>(&self.app, ZoomStep::In))
63 .on_action(zoom_listener::<ZoomShareOut>(&self.app, ZoomStep::Out))
64 .on_action(zoom_listener::<ZoomShareReset>(&self.app, ZoomStep::Reset))
65 .children(render_stage(&self.app, state, StageMode::PopOut))
66 }
67}
crates/app/src/views/call_stage.rs +211 −19
@@ -7,8 +7,11 @@ use gpui_kit::component::{h_flex, v_flex};
7 7 use gpui_kit::prelude::FluentBuilder as _;
8 8 use gpui_kit::*;
9 9
10 use gpui_kit::component::tooltip::Tooltip;
11
10 12 use super::widgets::icon;
11 13 use crate::app_state::AppState;
14 use crate::call::{ShareStage, ZoomStep};
12 15 use crate::theme;
13 16
14 17 const STAGE_RADIUS: f32 = 12.;
@@ -17,6 +20,17 @@ const STAGE_BACKGROUND: f32 = 0.04;
17 20 const LABEL_BACKGROUND: f32 = 0.6;
18 21 pub const WAITING_TEXT: &str = "Loading the shared screen...";
19 22 pub const FULL_WINDOW_HINT: &str = "Double-click or press Esc to leave full window";
23 pub const POP_OUT_TOOLTIP: &str = "Pop out";
24 pub const POPPED_TEXT: &str = "Shared content is open in its own window";
25 const LINE_HEIGHT: f32 = 20.;
26 const CHIP_HEIGHT: f32 = 30.;
27
28 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
29 pub enum StageMode {
30 Docked,
31 Fullscreen,
32 PopOut,
33 }
20 34
21 35 fn stage_black() -> Hsla {
22 36 hsla(0., 0., STAGE_BACKGROUND, 1.)
@@ -40,13 +54,9 @@ fn label_chip(text: String) -> Div {
40 54 .child(text)
41 55 }
42 56
43 fn picture(image: Option<Arc<RenderImage>>) -> AnyElement {
44 match image {
45 Some(image) => img(ImageSource::Render(image))
46 .size_full()
47 .object_fit(ObjectFit::Contain)
48 .into_any_element(),
49 None => div()
57 fn picture(image: Option<Arc<RenderImage>>, stage: &ShareStage) -> AnyElement {
58 let Some(image) = image else {
59 return div()
50 60 .size_full()
51 61 .flex()
52 62 .items_center()
@@ -54,25 +64,170 @@ fn picture(image: Option<Arc<RenderImage>>) -> AnyElement {
54 64 .text_size(px(14.))
55 65 .text_color(theme::text_muted())
56 66 .child(WAITING_TEXT)
57 .into_any_element(),
67 .into_any_element();
68 };
69 let size = stage.size();
70 let (offset_x, offset_y) = stage.view.offset(size);
71 let zoom = stage.view.zoom();
72 div()
73 .absolute()
74 .left(px(offset_x))
75 .top(px(offset_y))
76 .w(px(size.0 * zoom))
77 .h(px(size.1 * zoom))
78 .child(
79 img(ImageSource::Render(image))
80 .size_full()
81 .object_fit(ObjectFit::Contain),
82 )
83 .into_any_element()
84 }
85
86 fn measure(stage: &ShareStage) -> impl IntoElement {
87 let bounds = stage.bounds.clone();
88 canvas(
89 |_, _, _| {},
90 move |area, _, window, _| {
91 let measured = (
92 f32::from(area.origin.x),
93 f32::from(area.origin.y),
94 f32::from(area.size.width),
95 f32::from(area.size.height),
96 );
97 if bounds.get() != measured {
98 bounds.set(measured);
99 window.refresh();
100 }
101 },
102 )
103 .absolute()
104 .size_full()
105 }
106
107 fn zoom_chip(app: &Entity<AppState>, stage: &ShareStage) -> Option<AnyElement> {
108 if !stage.view.is_zoomed() {
109 return None;
58 110 }
111 let app = app.clone();
112 Some(
113 div()
114 .absolute()
115 .top(px(LABEL_OFFSET))
116 .right(px(LABEL_OFFSET))
117 .debug_selector(|| "shell/islands/main/call-stage/share-content/zoom-chip".into())
118 .child(
119 h_flex()
120 .id("call-stage-zoom")
121 .h(px(CHIP_HEIGHT))
122 .px(px(12.))
123 .gap(px(8.))
124 .items_center()
125 .rounded_full()
126 .bg(hsla(0., 0., 0., LABEL_BACKGROUND))
127 .text_color(theme::white())
128 .text_size(px(13.))
129 .font_weight(FontWeight::SEMIBOLD)
130 .cursor_pointer()
131 .hover(|chip| chip.opacity(0.85))
132 .tooltip(|window, cx| Tooltip::new("Reset zoom").build(window, cx))
133 .child(icon(IconName::Search, 15., theme::white()))
134 .child(format!("{}%", stage.view.percent()))
135 .on_click(move |_, _, cx| {
136 cx.stop_propagation();
137 app.update(cx, |state, cx| state.zoom_share(ZoomStep::Reset, cx));
138 }),
139 )
140 .into_any_element(),
141 )
142 }
143
144 fn pop_out_button(app: &Entity<AppState>) -> AnyElement {
145 let app = app.clone();
146 div()
147 .absolute()
148 .bottom(px(LABEL_OFFSET))
149 .right(px(LABEL_OFFSET))
150 .child(
151 h_flex()
152 .id("call-stage-pop-out")
153 .h(px(CHIP_HEIGHT))
154 .px(px(12.))
155 .gap(px(8.))
156 .items_center()
157 .rounded_full()
158 .bg(hsla(0., 0., 0., LABEL_BACKGROUND))
159 .text_color(theme::white())
160 .text_size(px(13.))
161 .font_weight(FontWeight::SEMIBOLD)
162 .cursor_pointer()
163 .hover(|chip| chip.opacity(0.85))
164 .child(icon(IconName::ExternalLink, 15., theme::white()))
165 .child(POP_OUT_TOOLTIP)
166 .on_click(move |_, _, cx| {
167 cx.stop_propagation();
168 app.update(cx, |state, cx| state.pop_out_stage(cx));
169 }),
170 )
171 .into_any_element()
172 }
173
174 pub fn popped_placeholder(app: &Entity<AppState>) -> AnyElement {
175 let app = app.clone();
176 v_flex()
177 .id("call-stage-popped")
178 .flex_1()
179 .min_w_0()
180 .h_full()
181 .items_center()
182 .justify_center()
183 .gap(px(12.))
184 .rounded(px(STAGE_RADIUS))
185 .bg(stage_black())
186 .text_size(px(14.))
187 .text_color(theme::text_muted())
188 .child(POPPED_TEXT)
189 .child(
190 h_flex()
191 .id("call-stage-bring-back")
192 .h(px(CHIP_HEIGHT))
193 .px(px(14.))
194 .items_center()
195 .rounded_full()
196 .bg(theme::accent())
197 .text_color(theme::on_accent())
198 .font_weight(FontWeight::SEMIBOLD)
199 .cursor_pointer()
200 .hover(|button| button.opacity(0.9))
201 .child("Bring back")
202 .on_click(move |_, _, cx| {
203 app.update(cx, |state, cx| state.return_stage_from_pop_out(cx))
204 }),
205 )
206 .into_any_element()
59 207 }
60 208
61 209 pub fn render_stage(
62 210 app: &Entity<AppState>,
63 211 state: &AppState,
64 fullscreen: bool,
212 mode: StageMode,
65 213 ) -> Option<AnyElement> {
66 214 let call = state.call.as_ref()?;
67 215 let label = call.model.sharing_label()?;
68 216 let image = call.pictures.live(&VideoKey::Screen, Instant::now());
217 let share_stage = &call.share_stage;
69 218 let toggle_app = app.clone();
219 let wheel_app = app.clone();
220 let down_app = app.clone();
221 let move_app = app.clone();
222 let up_app = app.clone();
223 let up_out_app = app.clone();
224 let position = |point: Point<Pixels>| (f32::from(point.x), f32::from(point.y));
70 225 Some(
71 226 div()
72 .id(if fullscreen {
73 "call-stage-full"
74 } else {
75 "call-stage"
227 .id(match mode {
228 StageMode::Docked => "call-stage",
229 StageMode::Fullscreen => "call-stage-full",
230 StageMode::PopOut => "call-stage-pop-out-window",
76 231 })
77 232 .relative()
78 233 .flex_1()
@@ -80,16 +235,53 @@ pub fn render_stage(
80 235 .h_full()
81 236 .overflow_hidden()
82 237 .bg(stage_black())
83 .when(!fullscreen, |stage| stage.rounded(px(STAGE_RADIUS)))
84 .cursor_pointer()
238 .when(mode == StageMode::Docked, |stage| {
239 stage
240 .rounded(px(STAGE_RADIUS))
241 .debug_selector(|| "shell/islands/main/call-stage/share-content".into())
242 })
243 .map(|stage| {
244 if share_stage.view.is_zoomed() {
245 stage.cursor_grab()
246 } else {
247 stage.cursor_pointer()
248 }
249 })
250 .on_scroll_wheel(move |event, _, cx| {
251 if !event.modifiers.control {
252 return;
253 }
254 let scroll = f32::from(event.delta.pixel_delta(px(LINE_HEIGHT)).y);
255 wheel_app.update(cx, |state, cx| {
256 state.zoom_share_wheel(scroll, position(event.position), cx)
257 });
258 cx.stop_propagation();
259 })
260 .on_mouse_down(MouseButton::Left, move |event, _, cx| {
261 down_app.update(cx, |state, cx| state.begin_share_pan(position(event.position), cx));
262 })
263 .on_mouse_move(move |event, _, cx| {
264 if event.pressed_button == Some(MouseButton::Left) {
265 move_app.update(cx, |state, cx| state.pan_share_to(position(event.position), cx));
266 }
267 })
268 .on_mouse_up(MouseButton::Left, move |_, _, cx| {
269 up_app.update(cx, |state, cx| state.end_share_pan(cx));
270 })
271 .on_mouse_up_out(MouseButton::Left, move |_, _, cx| {
272 up_out_app.update(cx, |state, cx| state.end_share_pan(cx));
273 })
85 274 .on_click(move |event, _, cx| {
86 if event.click_count() >= 2 {
275 if mode != StageMode::PopOut && event.click_count() >= 2 {
87 276 toggle_app.update(cx, |state, cx| state.toggle_stage_fullscreen(cx));
88 277 }
89 278 })
90 .child(picture(image))
279 .child(measure(share_stage))
280 .child(picture(image, share_stage))
91 281 .child(label_chip(label))
92 .when(fullscreen, |stage| {
282 .children(zoom_chip(app, share_stage))
283 .when(mode == StageMode::Docked, |stage| stage.child(pop_out_button(app)))
284 .when(mode == StageMode::Fullscreen, |stage| {
93 285 stage.child(
94 286 div()
95 287 .absolute()
@@ -118,7 +310,7 @@ pub fn render_stage_overlay(app: &Entity<AppState>, state: &AppState) -> Option<
118 310 if !state.stage_fullscreen() {
119 311 return None;
120 312 }
121 let stage = render_stage(app, state, true)?;
313 let stage = render_stage(app, state, StageMode::Fullscreen)?;
122 314 Some(
123 315 v_flex()
124 316 .id("call-stage-overlay")
@@ -7,8 +7,11 @@ use gpui_kit::component::{h_flex, v_flex};
7use gpui_kit::prelude::FluentBuilder as _;
7use gpui_kit::prelude::FluentBuilder as _;
8use gpui_kit::*;
8use gpui_kit::*;
9
9
10use gpui_kit::component::tooltip::Tooltip;
11
10use super::widgets::icon;
12use super::widgets::icon;
11use crate::app_state::AppState;
13use crate::app_state::AppState;
14use crate::call::{ShareStage, ZoomStep};
12use crate::theme;
15use crate::theme;
13
16
14const STAGE_RADIUS: f32 = 12.;
17const STAGE_RADIUS: f32 = 12.;
@@ -17,6 +20,17 @@ const STAGE_BACKGROUND: f32 = 0.04;
17const LABEL_BACKGROUND: f32 = 0.6;
20const LABEL_BACKGROUND: f32 = 0.6;
18pub const WAITING_TEXT: &str = "Loading the shared screen...";
21pub const WAITING_TEXT: &str = "Loading the shared screen...";
19pub const FULL_WINDOW_HINT: &str = "Double-click or press Esc to leave full window";
22pub const FULL_WINDOW_HINT: &str = "Double-click or press Esc to leave full window";
23pub const POP_OUT_TOOLTIP: &str = "Pop out";
24pub const POPPED_TEXT: &str = "Shared content is open in its own window";
25const LINE_HEIGHT: f32 = 20.;
26const CHIP_HEIGHT: f32 = 30.;
27
28#[derive(Debug, Clone, Copy, PartialEq, Eq)]
29pub enum StageMode {
30 Docked,
31 Fullscreen,
32 PopOut,
33}
20
34
21fn stage_black() -> Hsla {
35fn stage_black() -> Hsla {
22 hsla(0., 0., STAGE_BACKGROUND, 1.)
36 hsla(0., 0., STAGE_BACKGROUND, 1.)
@@ -40,13 +54,9 @@ fn label_chip(text: String) -> Div {
40 .child(text)
54 .child(text)
41}
55}
42
56
43fn picture(image: Option<Arc<RenderImage>>) -> AnyElement {
57fn picture(image: Option<Arc<RenderImage>>, stage: &ShareStage) -> AnyElement {
44 match image {
58 let Some(image) = image else {
45 Some(image) => img(ImageSource::Render(image))
59 return div()
46 .size_full()
47 .object_fit(ObjectFit::Contain)
48 .into_any_element(),
49 None => div()
50 .size_full()
60 .size_full()
51 .flex()
61 .flex()
52 .items_center()
62 .items_center()
@@ -54,25 +64,170 @@ fn picture(image: Option<Arc<RenderImage>>) -> AnyElement {
54 .text_size(px(14.))
64 .text_size(px(14.))
55 .text_color(theme::text_muted())
65 .text_color(theme::text_muted())
56 .child(WAITING_TEXT)
66 .child(WAITING_TEXT)
57 .into_any_element(),
67 .into_any_element();
68 };
69 let size = stage.size();
70 let (offset_x, offset_y) = stage.view.offset(size);
71 let zoom = stage.view.zoom();
72 div()
73 .absolute()
74 .left(px(offset_x))
75 .top(px(offset_y))
76 .w(px(size.0 * zoom))
77 .h(px(size.1 * zoom))
78 .child(
79 img(ImageSource::Render(image))
80 .size_full()
81 .object_fit(ObjectFit::Contain),
82 )
83 .into_any_element()
84}
85
86fn measure(stage: &ShareStage) -> impl IntoElement {
87 let bounds = stage.bounds.clone();
88 canvas(
89 |_, _, _| {},
90 move |area, _, window, _| {
91 let measured = (
92 f32::from(area.origin.x),
93 f32::from(area.origin.y),
94 f32::from(area.size.width),
95 f32::from(area.size.height),
96 );
97 if bounds.get() != measured {
98 bounds.set(measured);
99 window.refresh();
100 }
101 },
102 )
103 .absolute()
104 .size_full()
105}
106
107fn zoom_chip(app: &Entity<AppState>, stage: &ShareStage) -> Option<AnyElement> {
108 if !stage.view.is_zoomed() {
109 return None;
58 }
110 }
111 let app = app.clone();
112 Some(
113 div()
114 .absolute()
115 .top(px(LABEL_OFFSET))
116 .right(px(LABEL_OFFSET))
117 .debug_selector(|| "shell/islands/main/call-stage/share-content/zoom-chip".into())
118 .child(
119 h_flex()
120 .id("call-stage-zoom")
121 .h(px(CHIP_HEIGHT))
122 .px(px(12.))
123 .gap(px(8.))
124 .items_center()
125 .rounded_full()
126 .bg(hsla(0., 0., 0., LABEL_BACKGROUND))
127 .text_color(theme::white())
128 .text_size(px(13.))
129 .font_weight(FontWeight::SEMIBOLD)
130 .cursor_pointer()
131 .hover(|chip| chip.opacity(0.85))
132 .tooltip(|window, cx| Tooltip::new("Reset zoom").build(window, cx))
133 .child(icon(IconName::Search, 15., theme::white()))
134 .child(format!("{}%", stage.view.percent()))
135 .on_click(move |_, _, cx| {
136 cx.stop_propagation();
137 app.update(cx, |state, cx| state.zoom_share(ZoomStep::Reset, cx));
138 }),
139 )
140 .into_any_element(),
141 )
142}
143
144fn pop_out_button(app: &Entity<AppState>) -> AnyElement {
145 let app = app.clone();
146 div()
147 .absolute()
148 .bottom(px(LABEL_OFFSET))
149 .right(px(LABEL_OFFSET))
150 .child(
151 h_flex()
152 .id("call-stage-pop-out")
153 .h(px(CHIP_HEIGHT))
154 .px(px(12.))
155 .gap(px(8.))
156 .items_center()
157 .rounded_full()
158 .bg(hsla(0., 0., 0., LABEL_BACKGROUND))
159 .text_color(theme::white())
160 .text_size(px(13.))
161 .font_weight(FontWeight::SEMIBOLD)
162 .cursor_pointer()
163 .hover(|chip| chip.opacity(0.85))
164 .child(icon(IconName::ExternalLink, 15., theme::white()))
165 .child(POP_OUT_TOOLTIP)
166 .on_click(move |_, _, cx| {
167 cx.stop_propagation();
168 app.update(cx, |state, cx| state.pop_out_stage(cx));
169 }),
170 )
171 .into_any_element()
172}
173
174pub fn popped_placeholder(app: &Entity<AppState>) -> AnyElement {
175 let app = app.clone();
176 v_flex()
177 .id("call-stage-popped")
178 .flex_1()
179 .min_w_0()
180 .h_full()
181 .items_center()
182 .justify_center()
183 .gap(px(12.))
184 .rounded(px(STAGE_RADIUS))
185 .bg(stage_black())
186 .text_size(px(14.))
187 .text_color(theme::text_muted())
188 .child(POPPED_TEXT)
189 .child(
190 h_flex()
191 .id("call-stage-bring-back")
192 .h(px(CHIP_HEIGHT))
193 .px(px(14.))
194 .items_center()
195 .rounded_full()
196 .bg(theme::accent())
197 .text_color(theme::on_accent())
198 .font_weight(FontWeight::SEMIBOLD)
199 .cursor_pointer()
200 .hover(|button| button.opacity(0.9))
201 .child("Bring back")
202 .on_click(move |_, _, cx| {
203 app.update(cx, |state, cx| state.return_stage_from_pop_out(cx))
204 }),
205 )
206 .into_any_element()
59}
207}
60
208
61pub fn render_stage(
209pub fn render_stage(
62 app: &Entity<AppState>,
210 app: &Entity<AppState>,
63 state: &AppState,
211 state: &AppState,
64 fullscreen: bool,
212 mode: StageMode,
65) -> Option<AnyElement> {
213) -> Option<AnyElement> {
66 let call = state.call.as_ref()?;
214 let call = state.call.as_ref()?;
67 let label = call.model.sharing_label()?;
215 let label = call.model.sharing_label()?;
68 let image = call.pictures.live(&VideoKey::Screen, Instant::now());
216 let image = call.pictures.live(&VideoKey::Screen, Instant::now());
217 let share_stage = &call.share_stage;
69 let toggle_app = app.clone();
218 let toggle_app = app.clone();
219 let wheel_app = app.clone();
220 let down_app = app.clone();
221 let move_app = app.clone();
222 let up_app = app.clone();
223 let up_out_app = app.clone();
224 let position = |point: Point<Pixels>| (f32::from(point.x), f32::from(point.y));
70 Some(
225 Some(
71 div()
226 div()
72 .id(if fullscreen {
227 .id(match mode {
73 "call-stage-full"
228 StageMode::Docked => "call-stage",
74 } else {
229 StageMode::Fullscreen => "call-stage-full",
75 "call-stage"
230 StageMode::PopOut => "call-stage-pop-out-window",
76 })
231 })
77 .relative()
232 .relative()
78 .flex_1()
233 .flex_1()
@@ -80,16 +235,53 @@ pub fn render_stage(
80 .h_full()
235 .h_full()
81 .overflow_hidden()
236 .overflow_hidden()
82 .bg(stage_black())
237 .bg(stage_black())
83 .when(!fullscreen, |stage| stage.rounded(px(STAGE_RADIUS)))
238 .when(mode == StageMode::Docked, |stage| {
84 .cursor_pointer()
239 stage
240 .rounded(px(STAGE_RADIUS))
241 .debug_selector(|| "shell/islands/main/call-stage/share-content".into())
242 })
243 .map(|stage| {
244 if share_stage.view.is_zoomed() {
245 stage.cursor_grab()
246 } else {
247 stage.cursor_pointer()
248 }
249 })
250 .on_scroll_wheel(move |event, _, cx| {
251 if !event.modifiers.control {
252 return;
253 }
254 let scroll = f32::from(event.delta.pixel_delta(px(LINE_HEIGHT)).y);
255 wheel_app.update(cx, |state, cx| {
256 state.zoom_share_wheel(scroll, position(event.position), cx)
257 });
258 cx.stop_propagation();
259 })
260 .on_mouse_down(MouseButton::Left, move |event, _, cx| {
261 down_app.update(cx, |state, cx| state.begin_share_pan(position(event.position), cx));
262 })
263 .on_mouse_move(move |event, _, cx| {
264 if event.pressed_button == Some(MouseButton::Left) {
265 move_app.update(cx, |state, cx| state.pan_share_to(position(event.position), cx));
266 }
267 })
268 .on_mouse_up(MouseButton::Left, move |_, _, cx| {
269 up_app.update(cx, |state, cx| state.end_share_pan(cx));
270 })
271 .on_mouse_up_out(MouseButton::Left, move |_, _, cx| {
272 up_out_app.update(cx, |state, cx| state.end_share_pan(cx));
273 })
85 .on_click(move |event, _, cx| {
274 .on_click(move |event, _, cx| {
86 if event.click_count() >= 2 {
275 if mode != StageMode::PopOut && event.click_count() >= 2 {
87 toggle_app.update(cx, |state, cx| state.toggle_stage_fullscreen(cx));
276 toggle_app.update(cx, |state, cx| state.toggle_stage_fullscreen(cx));
88 }
277 }
89 })
278 })
90 .child(picture(image))
279 .child(measure(share_stage))
280 .child(picture(image, share_stage))
91 .child(label_chip(label))
281 .child(label_chip(label))
92 .when(fullscreen, |stage| {
282 .children(zoom_chip(app, share_stage))
283 .when(mode == StageMode::Docked, |stage| stage.child(pop_out_button(app)))
284 .when(mode == StageMode::Fullscreen, |stage| {
93 stage.child(
285 stage.child(
94 div()
286 div()
95 .absolute()
287 .absolute()
@@ -118,7 +310,7 @@ pub fn render_stage_overlay(app: &Entity<AppState>, state: &AppState) -> Option<
118 if !state.stage_fullscreen() {
310 if !state.stage_fullscreen() {
119 return None;
311 return None;
120 }
312 }
121 let stage = render_stage(app, state, true)?;
313 let stage = render_stage(app, state, StageMode::Fullscreen)?;
122 Some(
314 Some(
123 v_flex()
315 v_flex()
124 .id("call-stage-overlay")
316 .id("call-stage-overlay")
crates/app/src/views/call_view.rs +80 −12
@@ -26,7 +26,7 @@ use super::call_organizer::{
26 26 camera_menu_button, captions_hint_chip, captions_overlay, chevron_button, lobby_banner,
27 27 more_button, pin_chip, spotlight_chip, with_tile_menu,
28 28 };
29 use super::call_stage::render_stage;
29 use super::call_stage::{StageMode, popped_placeholder, render_stage};
30 30 use super::call_view_menu::view_button;
31 31 use super::conversation::ConversationView;
32 32 use super::shell::ISLAND_GAP;
@@ -50,11 +50,6 @@ const BLINK_DIMMED_OPACITY: f32 = 0.45;
50 50 pub(super) const DISABLED_OPACITY: f32 = 0.4;
51 51 pub(super) const TILE_GAP: f32 = 20.;
52 52 pub(super) const GRID_PADDING: f32 = 24.;
53 pub(super) const STRIP_TILE: TileSize = TileSize {
54 width: 232.,
55 height: 131.,
56 avatar: 56.,
57 };
58 53 pub(super) const STRIP_GAP: f32 = 12.;
59 54 pub(super) const STRIP_VISIBLE: f32 = 4.;
60 55 const TILE_RADIUS: f32 = 12.;
@@ -72,6 +67,9 @@ const REACTION_RISE: f32 = 24.;
72 67 const REACTION_FADE_FROM: f32 = 0.75;
73 68 const REACTION_CELL: f32 = 40.;
74 69 const SHARE_SOUND_LABEL: &str = "Include computer sound";
70 const SHARE_MOTION_LABEL: &str = "Optimize for motion";
71 const SHARE_STANDOUT_LABEL: &str = "Show me over my content";
72 const SHARE_STANDOUT_NEEDS_CAMERA: &str = "Turn your camera on first";
75 73 const NOISE_SUPPRESSION_LABEL: &str = "Noise suppression";
76 74 const MUSIC_MODE_LABEL: &str = "Music mode";
77 75 const PUSH_TO_TALK_HINT: &str = "Unmuted - release Ctrl+Space to mute";
@@ -401,6 +399,13 @@ pub fn leave_button(
401 399 })
402 400 }
403 401
402 fn share_stage_element(app: &Entity<AppState>, state: &AppState, call: &ActiveCall) -> Option<AnyElement> {
403 if call.share_stage.popped && call.model.screen_sharer.is_some() {
404 return Some(popped_placeholder(app));
405 }
406 render_stage(app, state, StageMode::Docked).or_else(|| whiteboard_stage(app, &call.model))
407 }
408
404 409 pub(super) fn camera_button(app: &Entity<AppState>, model: &CallModel) -> Stateful<Div> {
405 410 let (glyph, background, foreground) = if model.camera_on {
406 411 (IconName::Video, theme::accent(), theme::on_accent())
@@ -436,6 +441,50 @@ fn sound_switch_item(app: &Entity<AppState>, sound: bool) -> PopupMenuItem {
436 441 .on_click(move |_, _, cx| app.update(cx, |state, cx| state.set_call_share_sound(!sound, cx)))
437 442 }
438 443
444 fn motion_switch_item(app: &Entity<AppState>, motion: bool) -> PopupMenuItem {
445 let app = app.clone();
446 PopupMenuItem::element(move |_, _| {
447 h_flex()
448 .id("call-share-motion-row")
449 .w_full()
450 .gap(px(16.))
451 .items_center()
452 .justify_between()
453 .child(SHARE_MOTION_LABEL)
454 .child(Switch::new("call-share-motion").checked(motion))
455 })
456 .on_click(move |_, _, cx| app.update(cx, |state, cx| state.set_call_share_motion(!motion, cx)))
457 }
458
459 fn standout_switch_item(app: &Entity<AppState>, standout: bool, camera_on: bool) -> PopupMenuItem {
460 let app = app.clone();
461 PopupMenuItem::element(move |_, _| {
462 v_flex()
463 .id("call-share-standout-row")
464 .w_full()
465 .when(!camera_on, |row| row.opacity(DISABLED_OPACITY))
466 .child(
467 h_flex()
468 .w_full()
469 .gap(px(16.))
470 .items_center()
471 .justify_between()
472 .child(SHARE_STANDOUT_LABEL)
473 .child(Switch::new("call-share-standout").checked(standout && camera_on)),
474 )
475 .when(!camera_on, |row| {
476 row.child(
477 div()
478 .text_size(px(11.))
479 .text_color(theme::text_muted())
480 .child(SHARE_STANDOUT_NEEDS_CAMERA),
481 )
482 })
483 })
484 .disabled(!camera_on)
485 .on_click(move |_, _, cx| app.update(cx, |state, cx| state.set_call_share_standout(!standout, cx)))
486 }
487
439 488 fn music_mode_item(app: &Entity<AppState>, mic: MicSettings) -> PopupMenuItem {
440 489 let app = app.clone();
441 490 PopupMenuItem::element(move |_, _| {
@@ -484,17 +533,36 @@ fn push_to_talk_chip(call: &ActiveCall) -> Option<AnyElement> {
484 533 })
485 534 }
486 535
536 #[derive(Debug, Clone, Copy)]
537 pub(super) struct ShareOptions {
538 pub sound: bool,
539 pub motion: bool,
540 pub standout: bool,
541 }
542
543 impl ShareOptions {
544 pub(super) fn of(state: &AppState) -> Self {
545 ShareOptions {
546 sound: state.call_share_sound,
547 motion: state.call_share_motion,
548 standout: state.call_share_standout,
549 }
550 }
551 }
552
487 553 fn share_items(
488 554 popup: PopupMenu,
489 555 app: &Entity<AppState>,
490 556 model: &CallModel,
491 sound: bool,
557 options: ShareOptions,
492 558 ) -> PopupMenu {
493 559 let screens = model.screens();
494 560 let single_screen = screens.len() == 1;
495 561 let mut popup = popup
496 562 .min_w(px(MENU_WIDTH))
497 .item(sound_switch_item(app, sound))
563 .item(sound_switch_item(app, options.sound))
564 .item(motion_switch_item(app, options.motion))
565 .item(standout_switch_item(app, options.standout, model.camera_on))
498 566 .separator();
499 567 for (index, source) in screens.into_iter().enumerate() {
500 568 let label = if single_screen {
@@ -533,7 +601,7 @@ fn share_items(
533 601 fn share_button(
534 602 app: &Entity<AppState>,
535 603 model: &CallModel,
536 sound: bool,
604 options: ShareOptions,
537 605 menu_open: bool,
538 606 ) -> AnyElement {
539 607 if model.local_share.is_some() {
@@ -574,7 +642,7 @@ fn share_button(
574 642 .rounded_full()
575 643 .child(face)
576 644 .dropdown_menu_with_anchor(Anchor::BottomLeft, move |popup, _, _| {
577 share_items(popup, &app, &model, sound)
645 share_items(popup, &app, &model, options)
578 646 })
579 647 .open(menu_open)
580 648 .on_open_change(move |open, _, cx| {
@@ -1070,7 +1138,7 @@ pub fn render_call_view(
1070 1138 .children(return_button(app, model));
1071 1139
1072 1140 let hold = hold_panel(app, model);
1073 let share_stage = render_stage(app, state, false).or_else(|| whiteboard_stage(app, model));
1141 let share_stage = share_stage_element(app, state, call);
1074 1142 let region = stage_region(app, state, call, now, hold, share_stage);
1075 1143
1076 1144 let controls = h_flex()
@@ -1101,7 +1169,7 @@ pub fn render_call_view(
1101 1169 .child(share_button(
1102 1170 app,
1103 1171 model,
1104 state.call_share_sound,
1172 ShareOptions::of(state),
1105 1173 call.share_menu_open,
1106 1174 ))
1107 1175 .when(model.has_reaction_controls(), |row| {
@@ -26,7 +26,7 @@ use super::call_organizer::{
26 camera_menu_button, captions_hint_chip, captions_overlay, chevron_button, lobby_banner,
26 camera_menu_button, captions_hint_chip, captions_overlay, chevron_button, lobby_banner,
27 more_button, pin_chip, spotlight_chip, with_tile_menu,
27 more_button, pin_chip, spotlight_chip, with_tile_menu,
28};
28};
29use super::call_stage::render_stage;
29use super::call_stage::{StageMode, popped_placeholder, render_stage};
30use super::call_view_menu::view_button;
30use super::call_view_menu::view_button;
31use super::conversation::ConversationView;
31use super::conversation::ConversationView;
32use super::shell::ISLAND_GAP;
32use super::shell::ISLAND_GAP;
@@ -50,11 +50,6 @@ const BLINK_DIMMED_OPACITY: f32 = 0.45;
50pub(super) const DISABLED_OPACITY: f32 = 0.4;
50pub(super) const DISABLED_OPACITY: f32 = 0.4;
51pub(super) const TILE_GAP: f32 = 20.;
51pub(super) const TILE_GAP: f32 = 20.;
52pub(super) const GRID_PADDING: f32 = 24.;
52pub(super) const GRID_PADDING: f32 = 24.;
53pub(super) const STRIP_TILE: TileSize = TileSize {
54 width: 232.,
55 height: 131.,
56 avatar: 56.,
57};
58pub(super) const STRIP_GAP: f32 = 12.;
53pub(super) const STRIP_GAP: f32 = 12.;
59pub(super) const STRIP_VISIBLE: f32 = 4.;
54pub(super) const STRIP_VISIBLE: f32 = 4.;
60const TILE_RADIUS: f32 = 12.;
55const TILE_RADIUS: f32 = 12.;
@@ -72,6 +67,9 @@ const REACTION_RISE: f32 = 24.;
72const REACTION_FADE_FROM: f32 = 0.75;
67const REACTION_FADE_FROM: f32 = 0.75;
73const REACTION_CELL: f32 = 40.;
68const REACTION_CELL: f32 = 40.;
74const SHARE_SOUND_LABEL: &str = "Include computer sound";
69const SHARE_SOUND_LABEL: &str = "Include computer sound";
70const SHARE_MOTION_LABEL: &str = "Optimize for motion";
71const SHARE_STANDOUT_LABEL: &str = "Show me over my content";
72const SHARE_STANDOUT_NEEDS_CAMERA: &str = "Turn your camera on first";
75const NOISE_SUPPRESSION_LABEL: &str = "Noise suppression";
73const NOISE_SUPPRESSION_LABEL: &str = "Noise suppression";
76const MUSIC_MODE_LABEL: &str = "Music mode";
74const MUSIC_MODE_LABEL: &str = "Music mode";
77const PUSH_TO_TALK_HINT: &str = "Unmuted - release Ctrl+Space to mute";
75const PUSH_TO_TALK_HINT: &str = "Unmuted - release Ctrl+Space to mute";
@@ -401,6 +399,13 @@ pub fn leave_button(
401 })
399 })
402}
400}
403
401
402fn share_stage_element(app: &Entity<AppState>, state: &AppState, call: &ActiveCall) -> Option<AnyElement> {
403 if call.share_stage.popped && call.model.screen_sharer.is_some() {
404 return Some(popped_placeholder(app));
405 }
406 render_stage(app, state, StageMode::Docked).or_else(|| whiteboard_stage(app, &call.model))
407}
408
404pub(super) fn camera_button(app: &Entity<AppState>, model: &CallModel) -> Stateful<Div> {
409pub(super) fn camera_button(app: &Entity<AppState>, model: &CallModel) -> Stateful<Div> {
405 let (glyph, background, foreground) = if model.camera_on {
410 let (glyph, background, foreground) = if model.camera_on {
406 (IconName::Video, theme::accent(), theme::on_accent())
411 (IconName::Video, theme::accent(), theme::on_accent())
@@ -436,6 +441,50 @@ fn sound_switch_item(app: &Entity<AppState>, sound: bool) -> PopupMenuItem {
436 .on_click(move |_, _, cx| app.update(cx, |state, cx| state.set_call_share_sound(!sound, cx)))
441 .on_click(move |_, _, cx| app.update(cx, |state, cx| state.set_call_share_sound(!sound, cx)))
437}
442}
438
443
444fn motion_switch_item(app: &Entity<AppState>, motion: bool) -> PopupMenuItem {
445 let app = app.clone();
446 PopupMenuItem::element(move |_, _| {
447 h_flex()
448 .id("call-share-motion-row")
449 .w_full()
450 .gap(px(16.))
451 .items_center()
452 .justify_between()
453 .child(SHARE_MOTION_LABEL)
454 .child(Switch::new("call-share-motion").checked(motion))
455 })
456 .on_click(move |_, _, cx| app.update(cx, |state, cx| state.set_call_share_motion(!motion, cx)))
457}
458
459fn standout_switch_item(app: &Entity<AppState>, standout: bool, camera_on: bool) -> PopupMenuItem {
460 let app = app.clone();
461 PopupMenuItem::element(move |_, _| {
462 v_flex()
463 .id("call-share-standout-row")
464 .w_full()
465 .when(!camera_on, |row| row.opacity(DISABLED_OPACITY))
466 .child(
467 h_flex()
468 .w_full()
469 .gap(px(16.))
470 .items_center()
471 .justify_between()
472 .child(SHARE_STANDOUT_LABEL)
473 .child(Switch::new("call-share-standout").checked(standout && camera_on)),
474 )
475 .when(!camera_on, |row| {
476 row.child(
477 div()
478 .text_size(px(11.))
479 .text_color(theme::text_muted())
480 .child(SHARE_STANDOUT_NEEDS_CAMERA),
481 )
482 })
483 })
484 .disabled(!camera_on)
485 .on_click(move |_, _, cx| app.update(cx, |state, cx| state.set_call_share_standout(!standout, cx)))
486}
487
439fn music_mode_item(app: &Entity<AppState>, mic: MicSettings) -> PopupMenuItem {
488fn music_mode_item(app: &Entity<AppState>, mic: MicSettings) -> PopupMenuItem {
440 let app = app.clone();
489 let app = app.clone();
441 PopupMenuItem::element(move |_, _| {
490 PopupMenuItem::element(move |_, _| {
@@ -484,17 +533,36 @@ fn push_to_talk_chip(call: &ActiveCall) -> Option<AnyElement> {
484 })
533 })
485}
534}
486
535
536#[derive(Debug, Clone, Copy)]
537pub(super) struct ShareOptions {
538 pub sound: bool,
539 pub motion: bool,
540 pub standout: bool,
541}
542
543impl ShareOptions {
544 pub(super) fn of(state: &AppState) -> Self {
545 ShareOptions {
546 sound: state.call_share_sound,
547 motion: state.call_share_motion,
548 standout: state.call_share_standout,
549 }
550 }
551}
552
487fn share_items(
553fn share_items(
488 popup: PopupMenu,
554 popup: PopupMenu,
489 app: &Entity<AppState>,
555 app: &Entity<AppState>,
490 model: &CallModel,
556 model: &CallModel,
491 sound: bool,
557 options: ShareOptions,
492) -> PopupMenu {
558) -> PopupMenu {
493 let screens = model.screens();
559 let screens = model.screens();
494 let single_screen = screens.len() == 1;
560 let single_screen = screens.len() == 1;
495 let mut popup = popup
561 let mut popup = popup
496 .min_w(px(MENU_WIDTH))
562 .min_w(px(MENU_WIDTH))
497 .item(sound_switch_item(app, sound))
563 .item(sound_switch_item(app, options.sound))
564 .item(motion_switch_item(app, options.motion))
565 .item(standout_switch_item(app, options.standout, model.camera_on))
498 .separator();
566 .separator();
499 for (index, source) in screens.into_iter().enumerate() {
567 for (index, source) in screens.into_iter().enumerate() {
500 let label = if single_screen {
568 let label = if single_screen {
@@ -533,7 +601,7 @@ fn share_items(
533fn share_button(
601fn share_button(
534 app: &Entity<AppState>,
602 app: &Entity<AppState>,
535 model: &CallModel,
603 model: &CallModel,
536 sound: bool,
604 options: ShareOptions,
537 menu_open: bool,
605 menu_open: bool,
538) -> AnyElement {
606) -> AnyElement {
539 if model.local_share.is_some() {
607 if model.local_share.is_some() {
@@ -574,7 +642,7 @@ fn share_button(
574 .rounded_full()
642 .rounded_full()
575 .child(face)
643 .child(face)
576 .dropdown_menu_with_anchor(Anchor::BottomLeft, move |popup, _, _| {
644 .dropdown_menu_with_anchor(Anchor::BottomLeft, move |popup, _, _| {
577 share_items(popup, &app, &model, sound)
645 share_items(popup, &app, &model, options)
578 })
646 })
579 .open(menu_open)
647 .open(menu_open)
580 .on_open_change(move |open, _, cx| {
648 .on_open_change(move |open, _, cx| {
@@ -1070,7 +1138,7 @@ pub fn render_call_view(
1070 .children(return_button(app, model));
1138 .children(return_button(app, model));
1071
1139
1072 let hold = hold_panel(app, model);
1140 let hold = hold_panel(app, model);
1073 let share_stage = render_stage(app, state, false).or_else(|| whiteboard_stage(app, model));
1141 let share_stage = share_stage_element(app, state, call);
1074 let region = stage_region(app, state, call, now, hold, share_stage);
1142 let region = stage_region(app, state, call, now, hold, share_stage);
1075
1143
1076 let controls = h_flex()
1144 let controls = h_flex()
@@ -1101,7 +1169,7 @@ pub fn render_call_view(
1101 .child(share_button(
1169 .child(share_button(
1102 app,
1170 app,
1103 model,
1171 model,
1104 state.call_share_sound,
1172 ShareOptions::of(state),
1105 call.share_menu_open,
1173 call.share_menu_open,
1106 ))
1174 ))
1107 .when(model.has_reaction_controls(), |row| {
1175 .when(model.has_reaction_controls(), |row| {
crates/app/src/views/mod.rs +1 −0
@@ -10,6 +10,7 @@ pub mod call_layouts;
10 10 pub mod call_mini;
11 11 pub mod call_mini_window;
12 12 pub mod call_organizer;
13 pub mod call_pop_out;
13 14 pub mod call_stage;
14 15 pub mod call_view;
15 16 pub mod call_view_menu;
@@ -10,6 +10,7 @@ pub mod call_layouts;
10pub mod call_mini;
10pub mod call_mini;
11pub mod call_mini_window;
11pub mod call_mini_window;
12pub mod call_organizer;
12pub mod call_organizer;
13pub mod call_pop_out;
13pub mod call_stage;
14pub mod call_stage;
14pub mod call_view;
15pub mod call_view;
15pub mod call_view_menu;
16pub mod call_view_menu;
crates/app/src/views/shell.rs +6 −2
@@ -18,8 +18,9 @@ use super::shortcuts::{
18 18 AcceptCall, DeclineCall, HangUpCall, NextConversation, OpenActivity, OpenCallsTab,
19 19 OpenChannelsTab, OpenChatsTab, OpenLobbyList, OpenSaved, PreviousConversation, PushToTalk, Scope,
20 20 ShowShortcuts, StartAudioCall, StartVideoCall, ToggleCallCamera, ToggleCallFullscreen,
21 ToggleCallHand, ToggleCallShare,
21 ToggleCallHand, ToggleCallShare, ZoomShareIn, ZoomShareOut, ZoomShareReset,
22 22 };
23 use super::call_pop_out::zoom_listener;
23 24 use super::shortcuts_dialog::{ShortcutsDialog, ShortcutsDialogEvent};
24 25 use super::sidebar::{SIDEBAR_WIDTH, SidebarView};
25 26 use super::status_bar::render_status_bar;
@@ -30,7 +31,7 @@ use super::title_bar::render_title_bar;
30 31 use crate::activity::ActivityCenter;
31 32 use crate::agents::{AgentRunsEvent, StartDialog, StartDialogEvent, StartRequest};
32 33 use crate::app_state::{AppEvent, AppState, Selection};
33 use crate::call::{CallMedia, CallWindows};
34 use crate::call::{CallMedia, CallWindows, ZoomStep};
34 35 use crate::notice::NoticeAction;
35 36 use crate::notify::{NotificationCenter, selection_for};
36 37 use crate::sidebar_model::Step;
@@ -851,6 +852,9 @@ impl Render for AppShell {
851 852 this.state
852 853 .update(cx, |state, cx| state.toggle_call_fullscreen(cx));
853 854 }))
855 .on_action(zoom_listener::<ZoomShareIn>(&self.state, ZoomStep::In))
856 .on_action(zoom_listener::<ZoomShareOut>(&self.state, ZoomStep::Out))
857 .on_action(zoom_listener::<ZoomShareReset>(&self.state, ZoomStep::Reset))
854 858 .on_action(cx.listener(|this, _: &ReplyToHovered, window, cx| {
855 859 this.close_image_viewer(window, cx);
856 860 this.conversation.update(cx, |conversation, cx| {
@@ -18,8 +18,9 @@ use super::shortcuts::{
18 AcceptCall, DeclineCall, HangUpCall, NextConversation, OpenActivity, OpenCallsTab,
18 AcceptCall, DeclineCall, HangUpCall, NextConversation, OpenActivity, OpenCallsTab,
19 OpenChannelsTab, OpenChatsTab, OpenLobbyList, OpenSaved, PreviousConversation, PushToTalk, Scope,
19 OpenChannelsTab, OpenChatsTab, OpenLobbyList, OpenSaved, PreviousConversation, PushToTalk, Scope,
20 ShowShortcuts, StartAudioCall, StartVideoCall, ToggleCallCamera, ToggleCallFullscreen,
20 ShowShortcuts, StartAudioCall, StartVideoCall, ToggleCallCamera, ToggleCallFullscreen,
21 ToggleCallHand, ToggleCallShare,
21 ToggleCallHand, ToggleCallShare, ZoomShareIn, ZoomShareOut, ZoomShareReset,
22};
22};
23use super::call_pop_out::zoom_listener;
23use super::shortcuts_dialog::{ShortcutsDialog, ShortcutsDialogEvent};
24use super::shortcuts_dialog::{ShortcutsDialog, ShortcutsDialogEvent};
24use super::sidebar::{SIDEBAR_WIDTH, SidebarView};
25use super::sidebar::{SIDEBAR_WIDTH, SidebarView};
25use super::status_bar::render_status_bar;
26use super::status_bar::render_status_bar;
@@ -30,7 +31,7 @@ use super::title_bar::render_title_bar;
30use crate::activity::ActivityCenter;
31use crate::activity::ActivityCenter;
31use crate::agents::{AgentRunsEvent, StartDialog, StartDialogEvent, StartRequest};
32use crate::agents::{AgentRunsEvent, StartDialog, StartDialogEvent, StartRequest};
32use crate::app_state::{AppEvent, AppState, Selection};
33use crate::app_state::{AppEvent, AppState, Selection};
33use crate::call::{CallMedia, CallWindows};
34use crate::call::{CallMedia, CallWindows, ZoomStep};
34use crate::notice::NoticeAction;
35use crate::notice::NoticeAction;
35use crate::notify::{NotificationCenter, selection_for};
36use crate::notify::{NotificationCenter, selection_for};
36use crate::sidebar_model::Step;
37use crate::sidebar_model::Step;
@@ -851,6 +852,9 @@ impl Render for AppShell {
851 this.state
852 this.state
852 .update(cx, |state, cx| state.toggle_call_fullscreen(cx));
853 .update(cx, |state, cx| state.toggle_call_fullscreen(cx));
853 }))
854 }))
855 .on_action(zoom_listener::<ZoomShareIn>(&self.state, ZoomStep::In))
856 .on_action(zoom_listener::<ZoomShareOut>(&self.state, ZoomStep::Out))
857 .on_action(zoom_listener::<ZoomShareReset>(&self.state, ZoomStep::Reset))
854 .on_action(cx.listener(|this, _: &ReplyToHovered, window, cx| {
858 .on_action(cx.listener(|this, _: &ReplyToHovered, window, cx| {
855 this.close_image_viewer(window, cx);
859 this.close_image_viewer(window, cx);
856 this.conversation.update(cx, |conversation, cx| {
860 this.conversation.update(cx, |conversation, cx| {
crates/app/src/views/shortcuts.rs +21 −1
@@ -10,6 +10,7 @@ use super::shell::{NewChat, OpenSwitcher, ToggleCallMute};
10 10 const TEXT_FIELD_CONTEXT: &str = "Input";
11 11 const OUTSIDE_COMPOSER_CONTEXT: &str = "!Composer";
12 12 const OUTSIDE_TEXT_FIELD_CONTEXT: &str = "!Input";
13 const ALTERNATE_KEYS: &[(&str, &str)] = &[("alt-shift-=", "alt-shift-+")];
13 14
14 15 actions!(
15 16 teams,
@@ -32,6 +33,9 @@ actions!(
32 33 StartVideoCall,
33 34 ToggleCallFullscreen,
34 35 PushToTalk,
36 ZoomShareIn,
37 ZoomShareOut,
38 ZoomShareReset,
35 39 ShowShortcuts
36 40 ]
37 41 );
@@ -126,6 +130,9 @@ pub const SHORTCUTS: &[Shortcut] = &[
126 130 shortcut!(Calls, GlobalOverTextFields, "Start an audio call in this chat", "alt-shift-a", None, StartAudioCall),
127 131 shortcut!(Calls, GlobalOverTextFields, "Start a video call in this chat", "alt-shift-v", None, StartVideoCall),
128 132 shortcut!(Calls, GlobalOverTextFields, "Full screen", "f11", None, ToggleCallFullscreen),
133 shortcut!(Calls, GlobalOverTextFields, "Zoom in on shared content", "alt-shift-=", None, ZoomShareIn),
134 shortcut!(Calls, GlobalOverTextFields, "Zoom out on shared content", "alt-shift--", None, ZoomShareOut),
135 shortcut!(Calls, GlobalOverTextFields, "Reset zoom on shared content", "alt-shift-0", None, ZoomShareReset),
129 136 shortcut!(Calls, OutsideTextFields, "Hold to talk while muted", "ctrl-space", None, PushToTalk),
130 137 ];
131 138
@@ -150,6 +157,7 @@ impl Shortcut {
150 157 Scope::Composer => &[Some(COMPOSER_CONTEXT)],
151 158 };
152 159 let mut keys = vec![self.keys];
160 keys.extend(ALTERNATE_KEYS.iter().filter(|(primary, _)| *primary == self.keys).map(|(_, alternate)| *alternate));
153 161 keys.extend(self.mac_keys.filter(|_| cfg!(target_os = "macos")));
154 162 keys.iter()
155 163 .flat_map(|keys| contexts.iter().map(|context| (self.bind)(keys, *context)))
@@ -165,7 +173,14 @@ pub fn keys_for_label(label: &str) -> Option<String> {
165 173 }
166 174
167 175 pub fn display_keys(keys: &str) -> String {
168 keys.split('-')
176 let (modifiers, key) = match keys.strip_suffix("--") {
177 Some(modifiers) => (modifiers, "-"),
178 None => keys.rsplit_once('-').unwrap_or(("", keys)),
179 };
180 modifiers
181 .split('-')
182 .filter(|part| !part.is_empty())
183 .chain([key])
169 184 .map(|part| match part {
170 185 "ctrl" => "Ctrl".to_owned(),
171 186 "cmd" => "Cmd".to_owned(),
@@ -175,6 +190,8 @@ pub fn display_keys(keys: &str) -> String {
175 190 "down" => "Down".to_owned(),
176 191 "enter" => "Enter".to_owned(),
177 192 "space" => "Space".to_owned(),
193 "=" => "Plus".to_owned(),
194 "-" => "Minus".to_owned(),
178 195 other => other.to_uppercase(),
179 196 })
180 197 .collect::<Vec<_>>()
@@ -317,5 +334,8 @@ mod tests {
317 334 assert_eq!(display_keys("alt-up"), "Alt+Up");
318 335 assert_eq!(display_keys("ctrl-."), "Ctrl+.");
319 336 assert_eq!(display_keys("ctrl-space"), "Ctrl+Space");
337 assert_eq!(display_keys("alt-shift-="), "Alt+Shift+Plus");
338 assert_eq!(display_keys("alt-shift--"), "Alt+Shift+Minus");
339 assert_eq!(display_keys("alt-shift-0"), "Alt+Shift+0");
320 340 }
321 341 }
@@ -10,6 +10,7 @@ use super::shell::{NewChat, OpenSwitcher, ToggleCallMute};
10const TEXT_FIELD_CONTEXT: &str = "Input";
10const TEXT_FIELD_CONTEXT: &str = "Input";
11const OUTSIDE_COMPOSER_CONTEXT: &str = "!Composer";
11const OUTSIDE_COMPOSER_CONTEXT: &str = "!Composer";
12const OUTSIDE_TEXT_FIELD_CONTEXT: &str = "!Input";
12const OUTSIDE_TEXT_FIELD_CONTEXT: &str = "!Input";
13const ALTERNATE_KEYS: &[(&str, &str)] = &[("alt-shift-=", "alt-shift-+")];
13
14
14actions!(
15actions!(
15 teams,
16 teams,
@@ -32,6 +33,9 @@ actions!(
32 StartVideoCall,
33 StartVideoCall,
33 ToggleCallFullscreen,
34 ToggleCallFullscreen,
34 PushToTalk,
35 PushToTalk,
36 ZoomShareIn,
37 ZoomShareOut,
38 ZoomShareReset,
35 ShowShortcuts
39 ShowShortcuts
36 ]
40 ]
37);
41);
@@ -126,6 +130,9 @@ pub const SHORTCUTS: &[Shortcut] = &[
126 shortcut!(Calls, GlobalOverTextFields, "Start an audio call in this chat", "alt-shift-a", None, StartAudioCall),
130 shortcut!(Calls, GlobalOverTextFields, "Start an audio call in this chat", "alt-shift-a", None, StartAudioCall),
127 shortcut!(Calls, GlobalOverTextFields, "Start a video call in this chat", "alt-shift-v", None, StartVideoCall),
131 shortcut!(Calls, GlobalOverTextFields, "Start a video call in this chat", "alt-shift-v", None, StartVideoCall),
128 shortcut!(Calls, GlobalOverTextFields, "Full screen", "f11", None, ToggleCallFullscreen),
132 shortcut!(Calls, GlobalOverTextFields, "Full screen", "f11", None, ToggleCallFullscreen),
133 shortcut!(Calls, GlobalOverTextFields, "Zoom in on shared content", "alt-shift-=", None, ZoomShareIn),
134 shortcut!(Calls, GlobalOverTextFields, "Zoom out on shared content", "alt-shift--", None, ZoomShareOut),
135 shortcut!(Calls, GlobalOverTextFields, "Reset zoom on shared content", "alt-shift-0", None, ZoomShareReset),
129 shortcut!(Calls, OutsideTextFields, "Hold to talk while muted", "ctrl-space", None, PushToTalk),
136 shortcut!(Calls, OutsideTextFields, "Hold to talk while muted", "ctrl-space", None, PushToTalk),
130];
137];
131
138
@@ -150,6 +157,7 @@ impl Shortcut {
150 Scope::Composer => &[Some(COMPOSER_CONTEXT)],
157 Scope::Composer => &[Some(COMPOSER_CONTEXT)],
151 };
158 };
152 let mut keys = vec![self.keys];
159 let mut keys = vec![self.keys];
160 keys.extend(ALTERNATE_KEYS.iter().filter(|(primary, _)| *primary == self.keys).map(|(_, alternate)| *alternate));
153 keys.extend(self.mac_keys.filter(|_| cfg!(target_os = "macos")));
161 keys.extend(self.mac_keys.filter(|_| cfg!(target_os = "macos")));
154 keys.iter()
162 keys.iter()
155 .flat_map(|keys| contexts.iter().map(|context| (self.bind)(keys, *context)))
163 .flat_map(|keys| contexts.iter().map(|context| (self.bind)(keys, *context)))
@@ -165,7 +173,14 @@ pub fn keys_for_label(label: &str) -> Option<String> {
165}
173}
166
174
167pub fn display_keys(keys: &str) -> String {
175pub fn display_keys(keys: &str) -> String {
168 keys.split('-')
176 let (modifiers, key) = match keys.strip_suffix("--") {
177 Some(modifiers) => (modifiers, "-"),
178 None => keys.rsplit_once('-').unwrap_or(("", keys)),
179 };
180 modifiers
181 .split('-')
182 .filter(|part| !part.is_empty())
183 .chain([key])
169 .map(|part| match part {
184 .map(|part| match part {
170 "ctrl" => "Ctrl".to_owned(),
185 "ctrl" => "Ctrl".to_owned(),
171 "cmd" => "Cmd".to_owned(),
186 "cmd" => "Cmd".to_owned(),
@@ -175,6 +190,8 @@ pub fn display_keys(keys: &str) -> String {
175 "down" => "Down".to_owned(),
190 "down" => "Down".to_owned(),
176 "enter" => "Enter".to_owned(),
191 "enter" => "Enter".to_owned(),
177 "space" => "Space".to_owned(),
192 "space" => "Space".to_owned(),
193 "=" => "Plus".to_owned(),
194 "-" => "Minus".to_owned(),
178 other => other.to_uppercase(),
195 other => other.to_uppercase(),
179 })
196 })
180 .collect::<Vec<_>>()
197 .collect::<Vec<_>>()
@@ -317,5 +334,8 @@ mod tests {
317 assert_eq!(display_keys("alt-up"), "Alt+Up");
334 assert_eq!(display_keys("alt-up"), "Alt+Up");
318 assert_eq!(display_keys("ctrl-."), "Ctrl+.");
335 assert_eq!(display_keys("ctrl-."), "Ctrl+.");
319 assert_eq!(display_keys("ctrl-space"), "Ctrl+Space");
336 assert_eq!(display_keys("ctrl-space"), "Ctrl+Space");
337 assert_eq!(display_keys("alt-shift-="), "Alt+Shift+Plus");
338 assert_eq!(display_keys("alt-shift--"), "Alt+Shift+Minus");
339 assert_eq!(display_keys("alt-shift-0"), "Alt+Shift+0");
320 }
340 }
321}
341}
crates/calling/src/blur.rs +24 −2
@@ -8,6 +8,7 @@ use tract_onnx::prelude::*;
8 8 use crate::background::BackgroundPicture;
9 9 use crate::effects::CameraEffects;
10 10 use crate::error::{Error, Result};
11 use crate::standout::Cutout;
11 12
12 13 const MODEL: &[u8] = include_bytes!("../assets/selfie_segmentation_landscape.onnx");
13 14 pub const MASK_WIDTH: usize = 256;
@@ -76,7 +77,7 @@ fn model_input(rgba: &[u8], width: usize, height: usize) -> Tensor {
76 77 Tensor::from_shape(&[1, 3, MASK_HEIGHT, MASK_WIDTH], &data).expect("shape matches data")
77 78 }
78 79
79 fn smoothstep(value: f32) -> f32 {
80 pub(crate) fn smoothstep(value: f32) -> f32 {
80 81 let t = ((value - EDGE_LOW) / (EDGE_HIGH - EDGE_LOW)).clamp(0., 1.);
81 82 t * t * (3. - 2. * t)
82 83 }
@@ -229,9 +230,11 @@ pub fn compose_image(rgba: &mut [u8], width: usize, height: usize, mask: &[f32],
229 230 #[derive(Default)]
230 231 pub struct BlurSettings {
231 232 enabled: AtomicBool,
233 standout: AtomicBool,
232 234 average_micros: AtomicU32,
233 235 picture: Mutex<Option<Arc<BackgroundPicture>>>,
234 236 effects: Mutex<CameraEffects>,
237 cutout: Mutex<Option<Arc<Cutout>>>,
235 238 }
236 239
237 240 impl BlurSettings {
@@ -243,6 +246,25 @@ impl BlurSettings {
243 246 self.enabled.load(Ordering::Relaxed)
244 247 }
245 248
249 pub fn set_standout(&self, standout: bool) {
250 self.standout.store(standout, Ordering::Relaxed);
251 if !standout {
252 self.set_cutout(None);
253 }
254 }
255
256 pub fn standout(&self) -> bool {
257 self.standout.load(Ordering::Relaxed)
258 }
259
260 pub fn set_cutout(&self, cutout: Option<Arc<Cutout>>) {
261 *self.cutout.lock().expect("cutout lock") = cutout;
262 }
263
264 pub fn cutout(&self) -> Option<Arc<Cutout>> {
265 self.cutout.lock().expect("cutout lock").clone()
266 }
267
246 268 pub fn set_picture(&self, picture: Option<Arc<BackgroundPicture>>) {
247 269 *self.picture.lock().expect("picture lock") = picture;
248 270 }
@@ -260,7 +282,7 @@ impl BlurSettings {
260 282 }
261 283
262 284 pub fn active(&self) -> bool {
263 self.enabled() || self.effects().alters_frame()
285 self.enabled() || self.standout() || self.effects().alters_frame()
264 286 }
265 287
266 288 pub fn average_ms(&self) -> f32 {
@@ -8,6 +8,7 @@ use tract_onnx::prelude::*;
8use crate::background::BackgroundPicture;
8use crate::background::BackgroundPicture;
9use crate::effects::CameraEffects;
9use crate::effects::CameraEffects;
10use crate::error::{Error, Result};
10use crate::error::{Error, Result};
11use crate::standout::Cutout;
11
12
12const MODEL: &[u8] = include_bytes!("../assets/selfie_segmentation_landscape.onnx");
13const MODEL: &[u8] = include_bytes!("../assets/selfie_segmentation_landscape.onnx");
13pub const MASK_WIDTH: usize = 256;
14pub const MASK_WIDTH: usize = 256;
@@ -76,7 +77,7 @@ fn model_input(rgba: &[u8], width: usize, height: usize) -> Tensor {
76 Tensor::from_shape(&[1, 3, MASK_HEIGHT, MASK_WIDTH], &data).expect("shape matches data")
77 Tensor::from_shape(&[1, 3, MASK_HEIGHT, MASK_WIDTH], &data).expect("shape matches data")
77}
78}
78
79
79fn smoothstep(value: f32) -> f32 {
80pub(crate) fn smoothstep(value: f32) -> f32 {
80 let t = ((value - EDGE_LOW) / (EDGE_HIGH - EDGE_LOW)).clamp(0., 1.);
81 let t = ((value - EDGE_LOW) / (EDGE_HIGH - EDGE_LOW)).clamp(0., 1.);
81 t * t * (3. - 2. * t)
82 t * t * (3. - 2. * t)
82}
83}
@@ -229,9 +230,11 @@ pub fn compose_image(rgba: &mut [u8], width: usize, height: usize, mask: &[f32],
229#[derive(Default)]
230#[derive(Default)]
230pub struct BlurSettings {
231pub struct BlurSettings {
231 enabled: AtomicBool,
232 enabled: AtomicBool,
233 standout: AtomicBool,
232 average_micros: AtomicU32,
234 average_micros: AtomicU32,
233 picture: Mutex<Option<Arc<BackgroundPicture>>>,
235 picture: Mutex<Option<Arc<BackgroundPicture>>>,
234 effects: Mutex<CameraEffects>,
236 effects: Mutex<CameraEffects>,
237 cutout: Mutex<Option<Arc<Cutout>>>,
235}
238}
236
239
237impl BlurSettings {
240impl BlurSettings {
@@ -243,6 +246,25 @@ impl BlurSettings {
243 self.enabled.load(Ordering::Relaxed)
246 self.enabled.load(Ordering::Relaxed)
244 }
247 }
245
248
249 pub fn set_standout(&self, standout: bool) {
250 self.standout.store(standout, Ordering::Relaxed);
251 if !standout {
252 self.set_cutout(None);
253 }
254 }
255
256 pub fn standout(&self) -> bool {
257 self.standout.load(Ordering::Relaxed)
258 }
259
260 pub fn set_cutout(&self, cutout: Option<Arc<Cutout>>) {
261 *self.cutout.lock().expect("cutout lock") = cutout;
262 }
263
264 pub fn cutout(&self) -> Option<Arc<Cutout>> {
265 self.cutout.lock().expect("cutout lock").clone()
266 }
267
246 pub fn set_picture(&self, picture: Option<Arc<BackgroundPicture>>) {
268 pub fn set_picture(&self, picture: Option<Arc<BackgroundPicture>>) {
247 *self.picture.lock().expect("picture lock") = picture;
269 *self.picture.lock().expect("picture lock") = picture;
248 }
270 }
@@ -260,7 +282,7 @@ impl BlurSettings {
260 }
282 }
261
283
262 pub fn active(&self) -> bool {
284 pub fn active(&self) -> bool {
263 self.enabled() || self.effects().alters_frame()
285 self.enabled() || self.standout() || self.effects().alters_frame()
264 }
286 }
265
287
266 pub fn average_ms(&self) -> f32 {
288 pub fn average_ms(&self) -> f32 {
crates/calling/src/call.rs +2 −0
@@ -1540,6 +1540,8 @@ async fn drive(
1540 1540 send_receive_change(control, video.reselect(&roster));
1541 1541 }
1542 1542 }
1543 Some(CallCommand::SetShareMotion(on)) => local_video.set_motion(on),
1544 Some(CallCommand::SetShareStandout(on)) => local_video.set_standout(on),
1543 1545 Some(CallCommand::SetCameraEffects(effects)) => local_video.set_effects(effects),
1544 1546 Some(CallCommand::SendReaction(reaction)) => {
1545 1547 if let Err(error) = remote.signaling.send_reaction(&remote.conversation, &remote.participant, reaction).await {
@@ -1540,6 +1540,8 @@ async fn drive(
1540 send_receive_change(control, video.reselect(&roster));
1540 send_receive_change(control, video.reselect(&roster));
1541 }
1541 }
1542 }
1542 }
1543 Some(CallCommand::SetShareMotion(on)) => local_video.set_motion(on),
1544 Some(CallCommand::SetShareStandout(on)) => local_video.set_standout(on),
1543 Some(CallCommand::SetCameraEffects(effects)) => local_video.set_effects(effects),
1545 Some(CallCommand::SetCameraEffects(effects)) => local_video.set_effects(effects),
1544 Some(CallCommand::SendReaction(reaction)) => {
1546 Some(CallCommand::SendReaction(reaction)) => {
1545 if let Err(error) = remote.signaling.send_reaction(&remote.conversation, &remote.participant, reaction).await {
1547 if let Err(error) = remote.signaling.send_reaction(&remote.conversation, &remote.participant, reaction).await {
crates/calling/src/control.rs +2 −0
@@ -35,6 +35,8 @@ pub enum CallCommand {
35 35 StartShare(ShareSource),
36 36 StopShare,
37 37 SetShareSound(bool),
38 SetShareMotion(bool),
39 SetShareStandout(bool),
38 40 RefreshShareSources,
39 41 SetHand(bool),
40 42 LowerHand { mri: String },
@@ -35,6 +35,8 @@ pub enum CallCommand {
35 StartShare(ShareSource),
35 StartShare(ShareSource),
36 StopShare,
36 StopShare,
37 SetShareSound(bool),
37 SetShareSound(bool),
38 SetShareMotion(bool),
39 SetShareStandout(bool),
38 RefreshShareSources,
40 RefreshShareSources,
39 SetHand(bool),
41 SetHand(bool),
40 LowerHand { mri: String },
42 LowerHand { mri: String },
crates/calling/src/effects.rs +16 −5
@@ -6,6 +6,7 @@ use libwebrtc::video_frame::{I420Buffer, VideoBuffer as _};
6 6
7 7 use crate::blur::{BlurSettings, BlurStage, MASK_HEIGHT, MASK_WIDTH, MaskSource};
8 8 use crate::camera::i420_from_rgba;
9 use crate::standout::Cutout;
9 10 use crate::framing::{CropPlanner, Subject, crop_and_scale, find_subject, is_full_frame};
10 11 use crate::luma_effects::{apply_table, gamma_table, mean_luma, smooth_gamma, soften_luma, target_gamma};
11 12
@@ -94,7 +95,8 @@ impl EffectsStage {
94 95 pub fn apply_i420(&mut self, mut buffer: I420Buffer) -> I420Buffer {
95 96 let effects = self.settings.effects();
96 97 let blur = self.settings.enabled();
97 if !blur && !effects.alters_frame() {
98 let standout = self.settings.standout();
99 if !blur && !standout && !effects.alters_frame() {
98 100 self.previous_frame = None;
99 101 return buffer;
100 102 }
@@ -104,11 +106,14 @@ impl EffectsStage {
104 106 if effects.adjust_brightness {
105 107 self.adjust_brightness(&mut buffer, width, height, elapsed);
106 108 }
107 if (blur || effects.needs_mask()) && self.load_masks() {
108 self.refresh_mask(&mut buffer, effects.auto_framing);
109 if (blur || standout || effects.needs_mask()) && self.load_masks() {
110 let fresh = self.refresh_mask(&mut buffer, effects.auto_framing);
109 111 if effects.soft_focus {
110 112 self.soften(&mut buffer, width, height, effects.soft_focus_strength);
111 113 }
114 if standout && fresh {
115 self.publish_cutout(&mut buffer);
116 }
112 117 if blur {
113 118 buffer = self.compose_background(buffer, width, height);
114 119 }
@@ -138,12 +143,18 @@ impl EffectsStage {
138 143 !self.unavailable
139 144 }
140 145
141 fn refresh_mask(&mut self, buffer: &mut I420Buffer, track_subject: bool) {
142 let Some(masks) = self.masks.as_mut() else { return };
146 fn refresh_mask(&mut self, buffer: &mut I420Buffer, track_subject: bool) -> bool {
147 let Some(masks) = self.masks.as_mut() else { return false };
143 148 let fresh = masks.refresh(|| mask_input(buffer));
144 149 if track_subject && fresh {
145 150 self.subject = find_subject(masks.mask(), MASK_WIDTH, MASK_HEIGHT);
146 151 }
152 fresh
153 }
154
155 fn publish_cutout(&self, buffer: &mut I420Buffer) {
156 let Some(masks) = self.masks.as_ref() else { return };
157 self.settings.set_cutout(Cutout::from_camera(buffer, masks.mask()).map(Arc::new));
147 158 }
148 159
149 160 fn soften(&self, buffer: &mut I420Buffer, width: usize, height: usize, strength: u8) {
@@ -6,6 +6,7 @@ use libwebrtc::video_frame::{I420Buffer, VideoBuffer as _};
6
6
7use crate::blur::{BlurSettings, BlurStage, MASK_HEIGHT, MASK_WIDTH, MaskSource};
7use crate::blur::{BlurSettings, BlurStage, MASK_HEIGHT, MASK_WIDTH, MaskSource};
8use crate::camera::i420_from_rgba;
8use crate::camera::i420_from_rgba;
9use crate::standout::Cutout;
9use crate::framing::{CropPlanner, Subject, crop_and_scale, find_subject, is_full_frame};
10use crate::framing::{CropPlanner, Subject, crop_and_scale, find_subject, is_full_frame};
10use crate::luma_effects::{apply_table, gamma_table, mean_luma, smooth_gamma, soften_luma, target_gamma};
11use crate::luma_effects::{apply_table, gamma_table, mean_luma, smooth_gamma, soften_luma, target_gamma};
11
12
@@ -94,7 +95,8 @@ impl EffectsStage {
94 pub fn apply_i420(&mut self, mut buffer: I420Buffer) -> I420Buffer {
95 pub fn apply_i420(&mut self, mut buffer: I420Buffer) -> I420Buffer {
95 let effects = self.settings.effects();
96 let effects = self.settings.effects();
96 let blur = self.settings.enabled();
97 let blur = self.settings.enabled();
97 if !blur && !effects.alters_frame() {
98 let standout = self.settings.standout();
99 if !blur && !standout && !effects.alters_frame() {
98 self.previous_frame = None;
100 self.previous_frame = None;
99 return buffer;
101 return buffer;
100 }
102 }
@@ -104,11 +106,14 @@ impl EffectsStage {
104 if effects.adjust_brightness {
106 if effects.adjust_brightness {
105 self.adjust_brightness(&mut buffer, width, height, elapsed);
107 self.adjust_brightness(&mut buffer, width, height, elapsed);
106 }
108 }
107 if (blur || effects.needs_mask()) && self.load_masks() {
109 if (blur || standout || effects.needs_mask()) && self.load_masks() {
108 self.refresh_mask(&mut buffer, effects.auto_framing);
110 let fresh = self.refresh_mask(&mut buffer, effects.auto_framing);
109 if effects.soft_focus {
111 if effects.soft_focus {
110 self.soften(&mut buffer, width, height, effects.soft_focus_strength);
112 self.soften(&mut buffer, width, height, effects.soft_focus_strength);
111 }
113 }
114 if standout && fresh {
115 self.publish_cutout(&mut buffer);
116 }
112 if blur {
117 if blur {
113 buffer = self.compose_background(buffer, width, height);
118 buffer = self.compose_background(buffer, width, height);
114 }
119 }
@@ -138,12 +143,18 @@ impl EffectsStage {
138 !self.unavailable
143 !self.unavailable
139 }
144 }
140
145
141 fn refresh_mask(&mut self, buffer: &mut I420Buffer, track_subject: bool) {
146 fn refresh_mask(&mut self, buffer: &mut I420Buffer, track_subject: bool) -> bool {
142 let Some(masks) = self.masks.as_mut() else { return };
147 let Some(masks) = self.masks.as_mut() else { return false };
143 let fresh = masks.refresh(|| mask_input(buffer));
148 let fresh = masks.refresh(|| mask_input(buffer));
144 if track_subject && fresh {
149 if track_subject && fresh {
145 self.subject = find_subject(masks.mask(), MASK_WIDTH, MASK_HEIGHT);
150 self.subject = find_subject(masks.mask(), MASK_WIDTH, MASK_HEIGHT);
146 }
151 }
152 fresh
153 }
154
155 fn publish_cutout(&self, buffer: &mut I420Buffer) {
156 let Some(masks) = self.masks.as_ref() else { return };
157 self.settings.set_cutout(Cutout::from_camera(buffer, masks.mask()).map(Arc::new));
147 }
158 }
148
159
149 fn soften(&self, buffer: &mut I420Buffer, width: usize, height: usize, strength: u8) {
160 fn soften(&self, buffer: &mut I420Buffer, width: usize, height: usize, strength: u8) {
crates/calling/src/lib.rs +1 −0
@@ -41,6 +41,7 @@ pub mod sdp;
41 41 pub mod signaling;
42 42 pub mod software_audio;
43 43 pub mod sound_capture;
44 pub mod standout;
44 45 pub mod state;
45 46 pub mod timeline;
46 47 pub mod transfer;
@@ -41,6 +41,7 @@ pub mod sdp;
41pub mod signaling;
41pub mod signaling;
42pub mod software_audio;
42pub mod software_audio;
43pub mod sound_capture;
43pub mod sound_capture;
44pub mod standout;
44pub mod state;
45pub mod state;
45pub mod timeline;
46pub mod timeline;
46pub mod transfer;
47pub mod transfer;
crates/calling/src/screen.rs +4 −4
@@ -1,4 +1,5 @@
1 use std::sync::atomic::Ordering;
1 use std::sync::Arc;
2 use std::sync::atomic::{AtomicU32, Ordering};
2 3 use std::time::Duration;
3 4
4 5 use libwebrtc::desktop_capturer::{CaptureSource, DesktopCaptureSourceType, DesktopCapturer, DesktopCapturerOptions};
@@ -7,7 +8,6 @@ use libwebrtc::video_frame::I420Buffer;
7 8
8 9 use crate::capture::Capture;
9 10 use crate::error::{Error, Result};
10 use crate::video_pattern::PatternKind;
11 11
12 12
13 13 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -83,10 +83,10 @@ fn i420_from_bgra(bytes: &[u8], width: u32, height: u32, stride: u32) -> I420Buf
83 83
84 84 pub fn start_screen_capture(
85 85 wanted: ShareSource,
86 fps: Arc<AtomicU32>,
86 87 mut deliver: impl FnMut(I420Buffer) + Send + 'static,
87 88 failed: impl FnOnce(String) + Send + 'static,
88 89 ) -> Result<Capture> {
89 let period = Duration::from_secs(1) / PatternKind::Screen.fps();
90 90 Capture::spawn_thread("screen-capture", move |stop| {
91 91 let Some(source) = sources_of(wanted.kind).into_iter().find(|(source, _)| source.id == wanted.id).map(|(_, raw)| raw) else {
92 92 return failed("the shared source is gone".to_owned());
@@ -103,7 +103,7 @@ pub fn start_screen_capture(
103 103 });
104 104 while !stop.load(Ordering::SeqCst) {
105 105 capturer.capture_frame();
106 std::thread::sleep(period);
106 std::thread::sleep(Duration::from_secs(1) / fps.load(Ordering::Relaxed).max(1));
107 107 }
108 108 })
109 109 .map_err(|error| Error::Webrtc(format!("screen thread: {error}")))
@@ -1,4 +1,5 @@
1use std::sync::atomic::Ordering;
1use std::sync::Arc;
2use std::sync::atomic::{AtomicU32, Ordering};
2use std::time::Duration;
3use std::time::Duration;
3
4
4use libwebrtc::desktop_capturer::{CaptureSource, DesktopCaptureSourceType, DesktopCapturer, DesktopCapturerOptions};
5use libwebrtc::desktop_capturer::{CaptureSource, DesktopCaptureSourceType, DesktopCapturer, DesktopCapturerOptions};
@@ -7,7 +8,6 @@ use libwebrtc::video_frame::I420Buffer;
7
8
8use crate::capture::Capture;
9use crate::capture::Capture;
9use crate::error::{Error, Result};
10use crate::error::{Error, Result};
10use crate::video_pattern::PatternKind;
11
11
12
12
13#[derive(Debug, Clone, Copy, PartialEq, Eq)]
13#[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -83,10 +83,10 @@ fn i420_from_bgra(bytes: &[u8], width: u32, height: u32, stride: u32) -> I420Buf
83
83
84pub fn start_screen_capture(
84pub fn start_screen_capture(
85 wanted: ShareSource,
85 wanted: ShareSource,
86 fps: Arc<AtomicU32>,
86 mut deliver: impl FnMut(I420Buffer) + Send + 'static,
87 mut deliver: impl FnMut(I420Buffer) + Send + 'static,
87 failed: impl FnOnce(String) + Send + 'static,
88 failed: impl FnOnce(String) + Send + 'static,
88) -> Result<Capture> {
89) -> Result<Capture> {
89 let period = Duration::from_secs(1) / PatternKind::Screen.fps();
90 Capture::spawn_thread("screen-capture", move |stop| {
90 Capture::spawn_thread("screen-capture", move |stop| {
91 let Some(source) = sources_of(wanted.kind).into_iter().find(|(source, _)| source.id == wanted.id).map(|(_, raw)| raw) else {
91 let Some(source) = sources_of(wanted.kind).into_iter().find(|(source, _)| source.id == wanted.id).map(|(_, raw)| raw) else {
92 return failed("the shared source is gone".to_owned());
92 return failed("the shared source is gone".to_owned());
@@ -103,7 +103,7 @@ pub fn start_screen_capture(
103 });
103 });
104 while !stop.load(Ordering::SeqCst) {
104 while !stop.load(Ordering::SeqCst) {
105 capturer.capture_frame();
105 capturer.capture_frame();
106 std::thread::sleep(period);
106 std::thread::sleep(Duration::from_secs(1) / fps.load(Ordering::Relaxed).max(1));
107 }
107 }
108 })
108 })
109 .map_err(|error| Error::Webrtc(format!("screen thread: {error}")))
109 .map_err(|error| Error::Webrtc(format!("screen thread: {error}")))
crates/calling/src/standout.rs added +245 −0
@@ -0,0 +1,245 @@
1 use std::sync::Arc;
2
3 use libwebrtc::video_frame::{I420Buffer, VideoBuffer as _};
4
5 use crate::blur::{MASK_HEIGHT, MASK_WIDTH, axis, smoothstep};
6 use crate::blur::BlurSettings;
7
8 const CUTOUT_WIDTH: u32 = 480;
9 const WIDTH_SHARE: f32 = 0.22;
10 const MARGIN_SHARE: f32 = 0.03;
11 const CORNER_SHARE: f32 = 0.1;
12 const MIN_TARGET_WIDTH: usize = 64;
13
14 pub struct Cutout {
15 width: usize,
16 height: usize,
17 luma: Vec<u8>,
18 chroma_blue: Vec<u8>,
19 chroma_red: Vec<u8>,
20 alpha: Vec<u8>,
21 }
22
23 fn corner_coverage(column: usize, row: usize, width: usize, height: usize, radius: f32) -> f32 {
24 let x = column as f32 + 0.5;
25 let y = row as f32 + 0.5;
26 let inner_x = x.clamp(radius, width as f32 - radius);
27 let inner_y = y.clamp(radius, height as f32 - radius);
28 let distance = ((x - inner_x).powi(2) + (y - inner_y).powi(2)).sqrt();
29 (radius - distance + 0.5).clamp(0., 1.)
30 }
31
32 impl Cutout {
33 pub fn from_camera(camera: &mut I420Buffer, mask: &[f32]) -> Option<Cutout> {
34 if mask.len() != MASK_WIDTH * MASK_HEIGHT || camera.width() < 2 || camera.height() < 2 {
35 return None;
36 }
37 let width = CUTOUT_WIDTH.min(camera.width()) & !1;
38 let height = (u64::from(camera.height()) * u64::from(width) / u64::from(camera.width())) as u32 & !1;
39 let scaled = camera.scale(width as i32, height as i32);
40 let (width, height) = (width as usize, height as usize);
41 let (stride_y, stride_u, stride_v) = scaled.strides();
42 let (plane_y, plane_u, plane_v) = scaled.data();
43 let mask_x = axis(width, MASK_WIDTH);
44 let mask_y = axis(height, MASK_HEIGHT);
45 let radius = width as f32 * CORNER_SHARE;
46 let mut cutout = Cutout {
47 width,
48 height,
49 luma: Vec::with_capacity(width * height),
50 chroma_blue: Vec::with_capacity(width * height),
51 chroma_red: Vec::with_capacity(width * height),
52 alpha: Vec::with_capacity(width * height),
53 };
54 for row in 0..height {
55 let (top, bottom, vertical) = (mask_y.first[row] * MASK_WIDTH, mask_y.second[row] * MASK_WIDTH, mask_y.weight[row]);
56 for column in 0..width {
57 let (left, right, across) = (mask_x.first[column], mask_x.second[column], mask_x.weight[column]);
58 let upper = mask[top + left] * (1. - across) + mask[top + right] * across;
59 let lower = mask[bottom + left] * (1. - across) + mask[bottom + right] * across;
60 let person = smoothstep(upper * (1. - vertical) + lower * vertical);
61 let coverage = person * corner_coverage(column, row, width, height, radius);
62 cutout.luma.push(plane_y[row * stride_y as usize + column]);
63 cutout.chroma_blue.push(plane_u[(row / 2) * stride_u as usize + column / 2]);
64 cutout.chroma_red.push(plane_v[(row / 2) * stride_v as usize + column / 2]);
65 cutout.alpha.push((coverage * 255. + 0.5) as u8);
66 }
67 }
68 Some(cutout)
69 }
70
71 fn scaled_to(&self, width: usize, height: usize) -> Cutout {
72 let across = axis(width, self.width);
73 let down = axis(height, self.height);
74 let resample = |plane: &[u8]| -> Vec<u8> {
75 let mut output = Vec::with_capacity(width * height);
76 for row in 0..height {
77 let (top, bottom, vertical) = (down.first[row] * self.width, down.second[row] * self.width, down.weight[row]);
78 for column in 0..width {
79 let (left, right, horizontal) = (across.first[column], across.second[column], across.weight[column]);
80 let sample = |index: usize| f32::from(plane[index]);
81 let upper = sample(top + left) * (1. - horizontal) + sample(top + right) * horizontal;
82 let lower = sample(bottom + left) * (1. - horizontal) + sample(bottom + right) * horizontal;
83 output.push((upper * (1. - vertical) + lower * vertical + 0.5) as u8);
84 }
85 }
86 output
87 };
88 Cutout {
89 width,
90 height,
91 luma: resample(&self.luma),
92 chroma_blue: resample(&self.chroma_blue),
93 chroma_red: resample(&self.chroma_red),
94 alpha: resample(&self.alpha),
95 }
96 }
97
98 fn blend_onto(&self, target: &mut I420Buffer, left: usize, top: usize) {
99 let (stride_y, stride_u, stride_v) = target.strides();
100 let (plane_y, plane_u, plane_v) = target.data_mut();
101 let mix = |below: u8, above: u8, alpha: u8| {
102 let weight = u32::from(alpha);
103 ((u32::from(below) * (255 - weight) + u32::from(above) * weight + 127) / 255) as u8
104 };
105 for row in 0..self.height {
106 for column in 0..self.width {
107 let alpha = self.alpha[row * self.width + column];
108 if alpha == 0 {
109 continue;
110 }
111 let (x, y) = (left + column, top + row);
112 let source = row * self.width + column;
113 let luma = &mut plane_y[y * stride_y as usize + x];
114 *luma = mix(*luma, self.luma[source], alpha);
115 if x % 2 == 0 && y % 2 == 0 {
116 let chroma_index = (y / 2) * stride_u as usize + x / 2;
117 plane_u[chroma_index] = mix(plane_u[chroma_index], self.chroma_blue[source], alpha);
118 let chroma_index = (y / 2) * stride_v as usize + x / 2;
119 plane_v[chroma_index] = mix(plane_v[chroma_index], self.chroma_red[source], alpha);
120 }
121 }
122 }
123 }
124 }
125
126 pub struct StandoutOverlay {
127 settings: Arc<BlurSettings>,
128 scaled: Option<ScaledCutout>,
129 }
130
131 struct ScaledCutout {
132 source: Arc<Cutout>,
133 frame: (usize, usize),
134 cutout: Cutout,
135 }
136
137 impl StandoutOverlay {
138 pub fn new(settings: Arc<BlurSettings>) -> Self {
139 StandoutOverlay { settings, scaled: None }
140 }
141
142 pub fn apply(&mut self, mut frame: I420Buffer) -> I420Buffer {
143 if !self.settings.standout() {
144 return frame;
145 }
146 let Some(source) = self.settings.cutout() else { return frame };
147 let (frame_width, frame_height) = (frame.width() as usize, frame.height() as usize);
148 let width = (frame_width as f32 * WIDTH_SHARE) as usize & !1;
149 if width < MIN_TARGET_WIDTH {
150 return frame;
151 }
152 let height = (width * source.height / source.width) & !1;
153 let margin = (frame_width as f32 * MARGIN_SHARE) as usize;
154 if height + margin >= frame_height || width + margin >= frame_width {
155 return frame;
156 }
157 let fresh = self.scaled.as_ref().is_some_and(|scaled| Arc::ptr_eq(&scaled.source, &source) && scaled.frame == (frame_width, frame_height));
158 if !fresh {
159 self.scaled = Some(ScaledCutout { cutout: source.scaled_to(width, height), source, frame: (frame_width, frame_height) });
160 }
161 if let Some(scaled) = &self.scaled {
162 let left = (frame_width - width - margin) & !1;
163 let top = (frame_height - height - margin) & !1;
164 scaled.cutout.blend_onto(&mut frame, left, top);
165 }
166 frame
167 }
168 }
169
170 #[cfg(test)]
171 mod tests {
172 use super::*;
173
174 fn gray_frame(width: u32, height: u32, luma: u8) -> I420Buffer {
175 let mut buffer = I420Buffer::new(width, height);
176 let (stride_y, stride_u, stride_v) = buffer.strides();
177 let (plane_y, plane_u, plane_v) = buffer.data_mut();
178 for row in 0..height as usize {
179 plane_y[row * stride_y as usize..][..width as usize].fill(luma);
180 }
181 for row in 0..height as usize / 2 {
182 plane_u[row * stride_u as usize..][..width as usize / 2].fill(128);
183 plane_v[row * stride_v as usize..][..width as usize / 2].fill(128);
184 }
185 buffer
186 }
187
188 fn full_mask(value: f32) -> Vec<f32> {
189 vec![value; MASK_WIDTH * MASK_HEIGHT]
190 }
191
192 fn luma_at(buffer: &I420Buffer, x: usize, y: usize) -> u8 {
193 buffer.data().0[y * buffer.strides().0 as usize + x]
194 }
195
196 fn overlay_with(person: f32) -> (StandoutOverlay, Arc<BlurSettings>) {
197 let settings = Arc::new(BlurSettings::default());
198 settings.set_standout(true);
199 let mut camera = gray_frame(640, 360, 235);
200 settings.set_cutout(Cutout::from_camera(&mut camera, &full_mask(person)).map(Arc::new));
201 (StandoutOverlay::new(settings.clone()), settings)
202 }
203
204 #[test]
205 fn the_person_lands_bottom_right_and_the_rest_of_the_screen_stays() {
206 let (mut overlay, _) = overlay_with(1.);
207 let frame = overlay.apply(gray_frame(1280, 720, 16));
208 assert_eq!(luma_at(&frame, 100, 100), 16);
209 assert!(luma_at(&frame, 1280 - 100, 720 - 100) > 200);
210 }
211
212 #[test]
213 fn corners_are_rounded() {
214 let (mut overlay, _) = overlay_with(1.);
215 let frame = overlay.apply(gray_frame(1280, 720, 16));
216 let width = (1280. * WIDTH_SHARE) as usize & !1;
217 let left = (1280 - width - (1280. * MARGIN_SHARE) as usize) & !1;
218 let top = (720 - ((width * 9 / 16) & !1) - (1280. * MARGIN_SHARE) as usize) & !1;
219 assert_eq!(luma_at(&frame, left, top), 16);
220 assert!(luma_at(&frame, left + width / 2, top + 20) > 200);
221 }
222
223 #[test]
224 fn no_person_in_the_mask_changes_nothing() {
225 let (mut overlay, _) = overlay_with(0.);
226 let frame = overlay.apply(gray_frame(1280, 720, 16));
227 assert_eq!(luma_at(&frame, 1280 - 100, 720 - 100), 16);
228 }
229
230 #[test]
231 fn switched_off_or_without_a_cutout_the_frame_passes_through() {
232 let (mut overlay, settings) = overlay_with(1.);
233 settings.set_standout(false);
234 assert_eq!(luma_at(&overlay.apply(gray_frame(1280, 720, 16)), 1280 - 100, 720 - 100), 16);
235 settings.set_standout(true);
236 settings.set_cutout(None);
237 assert_eq!(luma_at(&overlay.apply(gray_frame(1280, 720, 16)), 1280 - 100, 720 - 100), 16);
238 }
239
240 #[test]
241 fn a_missing_mask_gives_no_cutout() {
242 let mut camera = gray_frame(640, 360, 100);
243 assert!(Cutout::from_camera(&mut camera, &[]).is_none());
244 }
245 }
@@ -0,0 +1,245 @@
1use std::sync::Arc;
2
3use libwebrtc::video_frame::{I420Buffer, VideoBuffer as _};
4
5use crate::blur::{MASK_HEIGHT, MASK_WIDTH, axis, smoothstep};
6use crate::blur::BlurSettings;
7
8const CUTOUT_WIDTH: u32 = 480;
9const WIDTH_SHARE: f32 = 0.22;
10const MARGIN_SHARE: f32 = 0.03;
11const CORNER_SHARE: f32 = 0.1;
12const MIN_TARGET_WIDTH: usize = 64;
13
14pub struct Cutout {
15 width: usize,
16 height: usize,
17 luma: Vec<u8>,
18 chroma_blue: Vec<u8>,
19 chroma_red: Vec<u8>,
20 alpha: Vec<u8>,
21}
22
23fn corner_coverage(column: usize, row: usize, width: usize, height: usize, radius: f32) -> f32 {
24 let x = column as f32 + 0.5;
25 let y = row as f32 + 0.5;
26 let inner_x = x.clamp(radius, width as f32 - radius);
27 let inner_y = y.clamp(radius, height as f32 - radius);
28 let distance = ((x - inner_x).powi(2) + (y - inner_y).powi(2)).sqrt();
29 (radius - distance + 0.5).clamp(0., 1.)
30}
31
32impl Cutout {
33 pub fn from_camera(camera: &mut I420Buffer, mask: &[f32]) -> Option<Cutout> {
34 if mask.len() != MASK_WIDTH * MASK_HEIGHT || camera.width() < 2 || camera.height() < 2 {
35 return None;
36 }
37 let width = CUTOUT_WIDTH.min(camera.width()) & !1;
38 let height = (u64::from(camera.height()) * u64::from(width) / u64::from(camera.width())) as u32 & !1;
39 let scaled = camera.scale(width as i32, height as i32);
40 let (width, height) = (width as usize, height as usize);
41 let (stride_y, stride_u, stride_v) = scaled.strides();
42 let (plane_y, plane_u, plane_v) = scaled.data();
43 let mask_x = axis(width, MASK_WIDTH);
44 let mask_y = axis(height, MASK_HEIGHT);
45 let radius = width as f32 * CORNER_SHARE;
46 let mut cutout = Cutout {
47 width,
48 height,
49 luma: Vec::with_capacity(width * height),
50 chroma_blue: Vec::with_capacity(width * height),
51 chroma_red: Vec::with_capacity(width * height),
52 alpha: Vec::with_capacity(width * height),
53 };
54 for row in 0..height {
55 let (top, bottom, vertical) = (mask_y.first[row] * MASK_WIDTH, mask_y.second[row] * MASK_WIDTH, mask_y.weight[row]);
56 for column in 0..width {
57 let (left, right, across) = (mask_x.first[column], mask_x.second[column], mask_x.weight[column]);
58 let upper = mask[top + left] * (1. - across) + mask[top + right] * across;
59 let lower = mask[bottom + left] * (1. - across) + mask[bottom + right] * across;
60 let person = smoothstep(upper * (1. - vertical) + lower * vertical);
61 let coverage = person * corner_coverage(column, row, width, height, radius);
62 cutout.luma.push(plane_y[row * stride_y as usize + column]);
63 cutout.chroma_blue.push(plane_u[(row / 2) * stride_u as usize + column / 2]);
64 cutout.chroma_red.push(plane_v[(row / 2) * stride_v as usize + column / 2]);
65 cutout.alpha.push((coverage * 255. + 0.5) as u8);
66 }
67 }
68 Some(cutout)
69 }
70
71 fn scaled_to(&self, width: usize, height: usize) -> Cutout {
72 let across = axis(width, self.width);
73 let down = axis(height, self.height);
74 let resample = |plane: &[u8]| -> Vec<u8> {
75 let mut output = Vec::with_capacity(width * height);
76 for row in 0..height {
77 let (top, bottom, vertical) = (down.first[row] * self.width, down.second[row] * self.width, down.weight[row]);
78 for column in 0..width {
79 let (left, right, horizontal) = (across.first[column], across.second[column], across.weight[column]);
80 let sample = |index: usize| f32::from(plane[index]);
81 let upper = sample(top + left) * (1. - horizontal) + sample(top + right) * horizontal;
82 let lower = sample(bottom + left) * (1. - horizontal) + sample(bottom + right) * horizontal;
83 output.push((upper * (1. - vertical) + lower * vertical + 0.5) as u8);
84 }
85 }
86 output
87 };
88 Cutout {
89 width,
90 height,
91 luma: resample(&self.luma),
92 chroma_blue: resample(&self.chroma_blue),
93 chroma_red: resample(&self.chroma_red),
94 alpha: resample(&self.alpha),
95 }
96 }
97
98 fn blend_onto(&self, target: &mut I420Buffer, left: usize, top: usize) {
99 let (stride_y, stride_u, stride_v) = target.strides();
100 let (plane_y, plane_u, plane_v) = target.data_mut();
101 let mix = |below: u8, above: u8, alpha: u8| {
102 let weight = u32::from(alpha);
103 ((u32::from(below) * (255 - weight) + u32::from(above) * weight + 127) / 255) as u8
104 };
105 for row in 0..self.height {
106 for column in 0..self.width {
107 let alpha = self.alpha[row * self.width + column];
108 if alpha == 0 {
109 continue;
110 }
111 let (x, y) = (left + column, top + row);
112 let source = row * self.width + column;
113 let luma = &mut plane_y[y * stride_y as usize + x];
114 *luma = mix(*luma, self.luma[source], alpha);
115 if x % 2 == 0 && y % 2 == 0 {
116 let chroma_index = (y / 2) * stride_u as usize + x / 2;
117 plane_u[chroma_index] = mix(plane_u[chroma_index], self.chroma_blue[source], alpha);
118 let chroma_index = (y / 2) * stride_v as usize + x / 2;
119 plane_v[chroma_index] = mix(plane_v[chroma_index], self.chroma_red[source], alpha);
120 }
121 }
122 }
123 }
124}
125
126pub struct StandoutOverlay {
127 settings: Arc<BlurSettings>,
128 scaled: Option<ScaledCutout>,
129}
130
131struct ScaledCutout {
132 source: Arc<Cutout>,
133 frame: (usize, usize),
134 cutout: Cutout,
135}
136
137impl StandoutOverlay {
138 pub fn new(settings: Arc<BlurSettings>) -> Self {
139 StandoutOverlay { settings, scaled: None }
140 }
141
142 pub fn apply(&mut self, mut frame: I420Buffer) -> I420Buffer {
143 if !self.settings.standout() {
144 return frame;
145 }
146 let Some(source) = self.settings.cutout() else { return frame };
147 let (frame_width, frame_height) = (frame.width() as usize, frame.height() as usize);
148 let width = (frame_width as f32 * WIDTH_SHARE) as usize & !1;
149 if width < MIN_TARGET_WIDTH {
150 return frame;
151 }
152 let height = (width * source.height / source.width) & !1;
153 let margin = (frame_width as f32 * MARGIN_SHARE) as usize;
154 if height + margin >= frame_height || width + margin >= frame_width {
155 return frame;
156 }
157 let fresh = self.scaled.as_ref().is_some_and(|scaled| Arc::ptr_eq(&scaled.source, &source) && scaled.frame == (frame_width, frame_height));
158 if !fresh {
159 self.scaled = Some(ScaledCutout { cutout: source.scaled_to(width, height), source, frame: (frame_width, frame_height) });
160 }
161 if let Some(scaled) = &self.scaled {
162 let left = (frame_width - width - margin) & !1;
163 let top = (frame_height - height - margin) & !1;
164 scaled.cutout.blend_onto(&mut frame, left, top);
165 }
166 frame
167 }
168}
169
170#[cfg(test)]
171mod tests {
172 use super::*;
173
174 fn gray_frame(width: u32, height: u32, luma: u8) -> I420Buffer {
175 let mut buffer = I420Buffer::new(width, height);
176 let (stride_y, stride_u, stride_v) = buffer.strides();
177 let (plane_y, plane_u, plane_v) = buffer.data_mut();
178 for row in 0..height as usize {
179 plane_y[row * stride_y as usize..][..width as usize].fill(luma);
180 }
181 for row in 0..height as usize / 2 {
182 plane_u[row * stride_u as usize..][..width as usize / 2].fill(128);
183 plane_v[row * stride_v as usize..][..width as usize / 2].fill(128);
184 }
185 buffer
186 }
187
188 fn full_mask(value: f32) -> Vec<f32> {
189 vec![value; MASK_WIDTH * MASK_HEIGHT]
190 }
191
192 fn luma_at(buffer: &I420Buffer, x: usize, y: usize) -> u8 {
193 buffer.data().0[y * buffer.strides().0 as usize + x]
194 }
195
196 fn overlay_with(person: f32) -> (StandoutOverlay, Arc<BlurSettings>) {
197 let settings = Arc::new(BlurSettings::default());
198 settings.set_standout(true);
199 let mut camera = gray_frame(640, 360, 235);
200 settings.set_cutout(Cutout::from_camera(&mut camera, &full_mask(person)).map(Arc::new));
201 (StandoutOverlay::new(settings.clone()), settings)
202 }
203
204 #[test]
205 fn the_person_lands_bottom_right_and_the_rest_of_the_screen_stays() {
206 let (mut overlay, _) = overlay_with(1.);
207 let frame = overlay.apply(gray_frame(1280, 720, 16));
208 assert_eq!(luma_at(&frame, 100, 100), 16);
209 assert!(luma_at(&frame, 1280 - 100, 720 - 100) > 200);
210 }
211
212 #[test]
213 fn corners_are_rounded() {
214 let (mut overlay, _) = overlay_with(1.);
215 let frame = overlay.apply(gray_frame(1280, 720, 16));
216 let width = (1280. * WIDTH_SHARE) as usize & !1;
217 let left = (1280 - width - (1280. * MARGIN_SHARE) as usize) & !1;
218 let top = (720 - ((width * 9 / 16) & !1) - (1280. * MARGIN_SHARE) as usize) & !1;
219 assert_eq!(luma_at(&frame, left, top), 16);
220 assert!(luma_at(&frame, left + width / 2, top + 20) > 200);
221 }
222
223 #[test]
224 fn no_person_in_the_mask_changes_nothing() {
225 let (mut overlay, _) = overlay_with(0.);
226 let frame = overlay.apply(gray_frame(1280, 720, 16));
227 assert_eq!(luma_at(&frame, 1280 - 100, 720 - 100), 16);
228 }
229
230 #[test]
231 fn switched_off_or_without_a_cutout_the_frame_passes_through() {
232 let (mut overlay, settings) = overlay_with(1.);
233 settings.set_standout(false);
234 assert_eq!(luma_at(&overlay.apply(gray_frame(1280, 720, 16)), 1280 - 100, 720 - 100), 16);
235 settings.set_standout(true);
236 settings.set_cutout(None);
237 assert_eq!(luma_at(&overlay.apply(gray_frame(1280, 720, 16)), 1280 - 100, 720 - 100), 16);
238 }
239
240 #[test]
241 fn a_missing_mask_gives_no_cutout() {
242 let mut camera = gray_frame(640, 360, 100);
243 assert!(Cutout::from_camera(&mut camera, &[]).is_none());
244 }
245}
crates/calling/src/video_send.rs +50 −3
@@ -1,8 +1,10 @@
1 1 use std::sync::Arc;
2 use std::sync::atomic::{AtomicU32, Ordering};
2 3 use std::time::{Instant, SystemTime, UNIX_EPOCH};
3 4
4 5 use libwebrtc::media_stream_track::MediaStreamTrack;
5 6 use libwebrtc::peer_connection_factory::PeerConnectionFactory;
7 use libwebrtc::rtp_parameters::DegradationPreference;
6 8 use libwebrtc::rtp_sender::RtpSender;
7 9 use libwebrtc::peer_connection_factory::native::PeerConnectionFactoryExt;
8 10 use libwebrtc::video_frame::{I420Buffer, VideoFrame, VideoRotation};
@@ -20,6 +22,7 @@ use crate::control::CallUpdate;
20 22 use crate::devices::DeviceChoice;
21 23 use crate::error::{Error, Result};
22 24 use crate::screen::{ShareSource, start_screen_capture};
25 use crate::standout::StandoutOverlay;
23 26 use crate::video_frame::{FrameGate, PERSON_FPS, SCREEN_FPS, VideoHub, VideoKey, picture_from_i420};
24 27 use crate::video_layout::VideoLines;
25 28 use crate::video_pattern::{PatternKind, spawn_pattern};
@@ -27,6 +30,8 @@ use crate::video_pattern::{PatternKind, spawn_pattern};
27 30 pub const VIDEO_MODE_ENV: &str = "CALLING_VIDEO";
28 31 const CAMERA_LABEL: &str = "camera";
29 32 const SCREEN_LABEL: &str = "screen";
33 pub const SCREEN_SHARE_FPS: u32 = 15;
34 pub const MOTION_SHARE_FPS: u32 = 30;
30 35
31 36 #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
32 37 pub enum VideoMode {
@@ -55,6 +60,7 @@ pub struct LocalSink {
55 60 source: NativeVideoSource,
56 61 self_view: Option<(Arc<VideoHub>, VideoKey, FrameGate)>,
57 62 mirror: Option<Arc<BlurSettings>>,
63 standout: Option<StandoutOverlay>,
58 64 }
59 65
60 66 impl LocalSink {
@@ -63,7 +69,7 @@ impl LocalSink {
63 69 let fps = if matches!(key, VideoKey::LocalScreen) { SCREEN_FPS } else { PERSON_FPS };
64 70 (hub, key, FrameGate::new(fps))
65 71 });
66 LocalSink { source, self_view, mirror: None }
72 LocalSink { source, self_view, mirror: None, standout: None }
67 73 }
68 74
69 75 pub fn mirrored_by(mut self, settings: Arc<BlurSettings>) -> Self {
@@ -71,7 +77,16 @@ impl LocalSink {
71 77 self
72 78 }
73 79
80 pub fn with_standout(mut self, settings: Arc<BlurSettings>) -> Self {
81 self.standout = Some(StandoutOverlay::new(settings));
82 self
83 }
84
74 85 pub fn push(&mut self, buffer: I420Buffer) {
86 let buffer = match &mut self.standout {
87 Some(overlay) => overlay.apply(buffer),
88 None => buffer,
89 };
75 90 let mut frame = VideoFrame::new(VideoRotation::VideoRotation0, buffer);
76 91 frame.timestamp_us = SystemTime::now().duration_since(UNIX_EPOCH).map_or(0, |elapsed| elapsed.as_micros() as i64);
77 92 self.source.capture_frame(&frame);
@@ -111,6 +126,8 @@ pub struct LocalVideo {
111 126 screen: Outgoing,
112 127 lines: Option<VideoLines>,
113 128 blur: Arc<BlurSettings>,
129 motion: bool,
130 share_fps: Arc<AtomicU32>,
114 131 }
115 132
116 133 impl LocalVideo {
@@ -123,7 +140,35 @@ impl LocalVideo {
123 140 screen: Outgoing::new(factory, SCREEN_LABEL, PatternKind::Screen, true),
124 141 lines: None,
125 142 blur: Arc::new(BlurSettings::default()),
143 motion: false,
144 share_fps: Arc::new(AtomicU32::new(SCREEN_SHARE_FPS)),
145 }
146 }
147
148 pub fn set_motion(&mut self, motion: bool) {
149 self.motion = motion;
150 self.share_fps.store(if motion { MOTION_SHARE_FPS } else { SCREEN_SHARE_FPS }, Ordering::Relaxed);
151 if let Some(share) = self.lines.as_ref().and_then(|lines| lines.share.as_ref()).filter(|_| self.sharing()) {
152 let _ = self.tune_share(&share.sender());
153 }
154 }
155
156 pub fn set_standout(&self, standout: bool) {
157 self.blur.set_standout(standout);
158 }
159
160 fn tune_share(&self, sender: &RtpSender) -> Result<()> {
161 let mut parameters = sender.parameters();
162 parameters.set_degradation_preference(if self.motion {
163 DegradationPreference::MaintainFramerate
164 } else {
165 DegradationPreference::MaintainResolution
166 });
167 let fps = f64::from(self.share_fps.load(Ordering::Relaxed));
168 for encoding in &mut parameters.encodings {
169 encoding.max_framerate = Some(fps);
126 170 }
171 sender.set_parameters(parameters).map_err(|error| Error::Webrtc(error.to_string()))
127 172 }
128 173
129 174 pub fn set_background(&self, enabled: bool, picture: Option<Arc<BackgroundPicture>>) {
@@ -216,6 +261,7 @@ impl LocalVideo {
216 261
217 262 pub fn stop_camera(&mut self) {
218 263 self.camera.capture = None;
264 self.blur.set_cutout(None);
219 265 if let Some(lines) = &self.lines {
220 266 let _ = Self::set_active(&lines.camera.sender(), false);
221 267 }
@@ -229,12 +275,13 @@ impl LocalVideo {
229 275 return Err(Error::Webrtc("video is switched off".into()));
230 276 }
231 277 self.screen.capture = None;
232 let mut sink = LocalSink::new(self.screen.source.clone(), None);
278 let mut sink = LocalSink::new(self.screen.source.clone(), None).with_standout(self.blur.clone());
233 279 let capture = match self.mode {
234 280 VideoMode::Pattern => Capture::Task(spawn_pattern(sink, PatternKind::Screen, None)),
235 _ => start_screen_capture(source.clone(), move |buffer| sink.push(buffer), self.report_failure("Screen share"))?,
281 _ => start_screen_capture(source.clone(), self.share_fps.clone(), move |buffer| sink.push(buffer), self.report_failure("Screen share"))?,
236 282 };
237 283 Self::begin_sending(&share.sender(), &self.screen.track)?;
284 let _ = self.tune_share(&share.sender());
238 285 self.screen.capture = Some(capture);
239 286 Ok(())
240 287 }
@@ -1,8 +1,10 @@
1use std::sync::Arc;
1use std::sync::Arc;
2use std::sync::atomic::{AtomicU32, Ordering};
2use std::time::{Instant, SystemTime, UNIX_EPOCH};
3use std::time::{Instant, SystemTime, UNIX_EPOCH};
3
4
4use libwebrtc::media_stream_track::MediaStreamTrack;
5use libwebrtc::media_stream_track::MediaStreamTrack;
5use libwebrtc::peer_connection_factory::PeerConnectionFactory;
6use libwebrtc::peer_connection_factory::PeerConnectionFactory;
7use libwebrtc::rtp_parameters::DegradationPreference;
6use libwebrtc::rtp_sender::RtpSender;
8use libwebrtc::rtp_sender::RtpSender;
7use libwebrtc::peer_connection_factory::native::PeerConnectionFactoryExt;
9use libwebrtc::peer_connection_factory::native::PeerConnectionFactoryExt;
8use libwebrtc::video_frame::{I420Buffer, VideoFrame, VideoRotation};
10use libwebrtc::video_frame::{I420Buffer, VideoFrame, VideoRotation};
@@ -20,6 +22,7 @@ use crate::control::CallUpdate;
20use crate::devices::DeviceChoice;
22use crate::devices::DeviceChoice;
21use crate::error::{Error, Result};
23use crate::error::{Error, Result};
22use crate::screen::{ShareSource, start_screen_capture};
24use crate::screen::{ShareSource, start_screen_capture};
25use crate::standout::StandoutOverlay;
23use crate::video_frame::{FrameGate, PERSON_FPS, SCREEN_FPS, VideoHub, VideoKey, picture_from_i420};
26use crate::video_frame::{FrameGate, PERSON_FPS, SCREEN_FPS, VideoHub, VideoKey, picture_from_i420};
24use crate::video_layout::VideoLines;
27use crate::video_layout::VideoLines;
25use crate::video_pattern::{PatternKind, spawn_pattern};
28use crate::video_pattern::{PatternKind, spawn_pattern};
@@ -27,6 +30,8 @@ use crate::video_pattern::{PatternKind, spawn_pattern};
27pub const VIDEO_MODE_ENV: &str = "CALLING_VIDEO";
30pub const VIDEO_MODE_ENV: &str = "CALLING_VIDEO";
28const CAMERA_LABEL: &str = "camera";
31const CAMERA_LABEL: &str = "camera";
29const SCREEN_LABEL: &str = "screen";
32const SCREEN_LABEL: &str = "screen";
33pub const SCREEN_SHARE_FPS: u32 = 15;
34pub const MOTION_SHARE_FPS: u32 = 30;
30
35
31#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
36#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
32pub enum VideoMode {
37pub enum VideoMode {
@@ -55,6 +60,7 @@ pub struct LocalSink {
55 source: NativeVideoSource,
60 source: NativeVideoSource,
56 self_view: Option<(Arc<VideoHub>, VideoKey, FrameGate)>,
61 self_view: Option<(Arc<VideoHub>, VideoKey, FrameGate)>,
57 mirror: Option<Arc<BlurSettings>>,
62 mirror: Option<Arc<BlurSettings>>,
63 standout: Option<StandoutOverlay>,
58}
64}
59
65
60impl LocalSink {
66impl LocalSink {
@@ -63,7 +69,7 @@ impl LocalSink {
63 let fps = if matches!(key, VideoKey::LocalScreen) { SCREEN_FPS } else { PERSON_FPS };
69 let fps = if matches!(key, VideoKey::LocalScreen) { SCREEN_FPS } else { PERSON_FPS };
64 (hub, key, FrameGate::new(fps))
70 (hub, key, FrameGate::new(fps))
65 });
71 });
66 LocalSink { source, self_view, mirror: None }
72 LocalSink { source, self_view, mirror: None, standout: None }
67 }
73 }
68
74
69 pub fn mirrored_by(mut self, settings: Arc<BlurSettings>) -> Self {
75 pub fn mirrored_by(mut self, settings: Arc<BlurSettings>) -> Self {
@@ -71,7 +77,16 @@ impl LocalSink {
71 self
77 self
72 }
78 }
73
79
80 pub fn with_standout(mut self, settings: Arc<BlurSettings>) -> Self {
81 self.standout = Some(StandoutOverlay::new(settings));
82 self
83 }
84
74 pub fn push(&mut self, buffer: I420Buffer) {
85 pub fn push(&mut self, buffer: I420Buffer) {
86 let buffer = match &mut self.standout {
87 Some(overlay) => overlay.apply(buffer),
88 None => buffer,
89 };
75 let mut frame = VideoFrame::new(VideoRotation::VideoRotation0, buffer);
90 let mut frame = VideoFrame::new(VideoRotation::VideoRotation0, buffer);
76 frame.timestamp_us = SystemTime::now().duration_since(UNIX_EPOCH).map_or(0, |elapsed| elapsed.as_micros() as i64);
91 frame.timestamp_us = SystemTime::now().duration_since(UNIX_EPOCH).map_or(0, |elapsed| elapsed.as_micros() as i64);
77 self.source.capture_frame(&frame);
92 self.source.capture_frame(&frame);
@@ -111,6 +126,8 @@ pub struct LocalVideo {
111 screen: Outgoing,
126 screen: Outgoing,
112 lines: Option<VideoLines>,
127 lines: Option<VideoLines>,
113 blur: Arc<BlurSettings>,
128 blur: Arc<BlurSettings>,
129 motion: bool,
130 share_fps: Arc<AtomicU32>,
114}
131}
115
132
116impl LocalVideo {
133impl LocalVideo {
@@ -123,7 +140,35 @@ impl LocalVideo {
123 screen: Outgoing::new(factory, SCREEN_LABEL, PatternKind::Screen, true),
140 screen: Outgoing::new(factory, SCREEN_LABEL, PatternKind::Screen, true),
124 lines: None,
141 lines: None,
125 blur: Arc::new(BlurSettings::default()),
142 blur: Arc::new(BlurSettings::default()),
143 motion: false,
144 share_fps: Arc::new(AtomicU32::new(SCREEN_SHARE_FPS)),
145 }
146 }
147
148 pub fn set_motion(&mut self, motion: bool) {
149 self.motion = motion;
150 self.share_fps.store(if motion { MOTION_SHARE_FPS } else { SCREEN_SHARE_FPS }, Ordering::Relaxed);
151 if let Some(share) = self.lines.as_ref().and_then(|lines| lines.share.as_ref()).filter(|_| self.sharing()) {
152 let _ = self.tune_share(&share.sender());
153 }
154 }
155
156 pub fn set_standout(&self, standout: bool) {
157 self.blur.set_standout(standout);
158 }
159
160 fn tune_share(&self, sender: &RtpSender) -> Result<()> {
161 let mut parameters = sender.parameters();
162 parameters.set_degradation_preference(if self.motion {
163 DegradationPreference::MaintainFramerate
164 } else {
165 DegradationPreference::MaintainResolution
166 });
167 let fps = f64::from(self.share_fps.load(Ordering::Relaxed));
168 for encoding in &mut parameters.encodings {
169 encoding.max_framerate = Some(fps);
126 }
170 }
171 sender.set_parameters(parameters).map_err(|error| Error::Webrtc(error.to_string()))
127 }
172 }
128
173
129 pub fn set_background(&self, enabled: bool, picture: Option<Arc<BackgroundPicture>>) {
174 pub fn set_background(&self, enabled: bool, picture: Option<Arc<BackgroundPicture>>) {
@@ -216,6 +261,7 @@ impl LocalVideo {
216
261
217 pub fn stop_camera(&mut self) {
262 pub fn stop_camera(&mut self) {
218 self.camera.capture = None;
263 self.camera.capture = None;
264 self.blur.set_cutout(None);
219 if let Some(lines) = &self.lines {
265 if let Some(lines) = &self.lines {
220 let _ = Self::set_active(&lines.camera.sender(), false);
266 let _ = Self::set_active(&lines.camera.sender(), false);
221 }
267 }
@@ -229,12 +275,13 @@ impl LocalVideo {
229 return Err(Error::Webrtc("video is switched off".into()));
275 return Err(Error::Webrtc("video is switched off".into()));
230 }
276 }
231 self.screen.capture = None;
277 self.screen.capture = None;
232 let mut sink = LocalSink::new(self.screen.source.clone(), None);
278 let mut sink = LocalSink::new(self.screen.source.clone(), None).with_standout(self.blur.clone());
233 let capture = match self.mode {
279 let capture = match self.mode {
234 VideoMode::Pattern => Capture::Task(spawn_pattern(sink, PatternKind::Screen, None)),
280 VideoMode::Pattern => Capture::Task(spawn_pattern(sink, PatternKind::Screen, None)),
235 _ => start_screen_capture(source.clone(), move |buffer| sink.push(buffer), self.report_failure("Screen share"))?,
281 _ => start_screen_capture(source.clone(), self.share_fps.clone(), move |buffer| sink.push(buffer), self.report_failure("Screen share"))?,
236 };
282 };
237 Self::begin_sending(&share.sender(), &self.screen.track)?;
283 Self::begin_sending(&share.sender(), &self.screen.track)?;
284 let _ = self.tune_share(&share.sender());
238 self.screen.capture = Some(capture);
285 self.screen.capture = Some(capture);
239 Ok(())
286 Ok(())
240 }
287 }