BlueGit

ict rusty-teams

feat(macos): screen share via ScreenCaptureKit system dialog

Open the system picker for screen/window share instead of an empty
source list, matching the Wayland portal behaviour.

metis Joachim Mild · pushed by metis

Authored 2026-11-12 · 2 weeks ago

Hash
69a912d4732a0b304aabe41ddbfe09cd2f8b9cc5
Parent
2470dc6c
3 files changed +66 −9
crates/app-call-model/src/model.rs +22 −2
@@ -7,7 +7,7 @@ use std::time::{Duration, Instant};
7 7 use calling::{
8 8 AttendeeLimits, CallCommand, CallState, CallUpdate, CameraDevice, CaptionEntry, CaptionState, ContentShare,
9 9 DeviceChoice, DeviceLists, EndKind, EndReason, HoldState, MeetingCapability, MeetingRole,
10 MeetingTarget, Progress, Reaction, Replacement, RosterEntry, ShareKind, ShareSource, SpeakingDetector, StatsSample, VideoHub,
10 MeetingTarget, Progress, Reaction, Replacement, RosterEntry, ShareKind, SharePicker, ShareSource, SpeakingDetector, StatsSample, VideoHub,
11 11 VideoWant,
12 12 };
13 13 use teams_core::RecordingPolicy;
@@ -299,6 +299,8 @@ pub struct CallModel {
299 299 pub cameras: Vec<CameraDevice>,
300 300 pub camera: DeviceChoice,
301 301 pub local_share: Option<String>,
302 pub share_picker: SharePicker,
303 pub share_kind: Option<ShareKind>,
302 304 pub share_sources: Vec<ShareSource>,
303 305 pub share_thumbnails: Vec<(ShareSource, Arc<gpui_kit::RenderImage>)>,
304 306 pub last_sample: Option<StatsSample>,
@@ -369,6 +371,8 @@ impl CallModel {
369 371 cameras: Vec::new(),
370 372 camera: DeviceChoice::SystemDefault,
371 373 local_share: None,
374 share_picker: SharePicker::List,
375 share_kind: None,
372 376 share_sources: Vec::new(),
373 377 share_thumbnails: Vec::new(),
374 378 last_sample: None,
@@ -508,6 +512,8 @@ impl CallModel {
508 512 }
509 513 self.local_share = label;
510 514 }
515 CallUpdate::SharePicker(picker) => self.share_picker = picker,
516 CallUpdate::ShareKind(kind) => self.share_kind = kind,
511 517 CallUpdate::ShareSources(sources) => {
512 518 self.share_thumbnails.retain(|(source, _)| sources.contains(source));
513 519 self.share_sources = sources;
@@ -1191,7 +1197,11 @@ impl CallModel {
1191 1197 }
1192 1198
1193 1199 pub fn can_share(&self) -> bool {
1194 !self.share_sources.is_empty() && self.is_live()
1200 self.is_live() && (self.uses_portal_picker() || !self.share_sources.is_empty())
1201 }
1202
1203 pub fn uses_portal_picker(&self) -> bool {
1204 self.share_picker == SharePicker::Portal
1195 1205 }
1196 1206
1197 1207 pub fn is_live(&self) -> bool {
@@ -1948,6 +1958,16 @@ mod tests {
1948 1958 assert!(!model.share_sound);
1949 1959 }
1950 1960
1961 #[test]
1962 fn portal_share_works_without_a_source_list() {
1963 let mut model = connected_model();
1964 assert!(model.share_sources.is_empty());
1965 assert!(!model.can_share());
1966 model.apply(CallUpdate::SharePicker(SharePicker::Portal));
1967 assert!(model.uses_portal_picker());
1968 assert!(model.can_share());
1969 }
1970
1951 1971 #[test]
1952 1972 fn lobby_guests_are_listed_for_organizers_who_may_admit() {
1953 1973 let mut model = meeting_with_me();
@@ -7,7 +7,7 @@ use std::time::{Duration, Instant};
7use calling::{
7use calling::{
8 AttendeeLimits, CallCommand, CallState, CallUpdate, CameraDevice, CaptionEntry, CaptionState, ContentShare,
8 AttendeeLimits, CallCommand, CallState, CallUpdate, CameraDevice, CaptionEntry, CaptionState, ContentShare,
9 DeviceChoice, DeviceLists, EndKind, EndReason, HoldState, MeetingCapability, MeetingRole,
9 DeviceChoice, DeviceLists, EndKind, EndReason, HoldState, MeetingCapability, MeetingRole,
10 MeetingTarget, Progress, Reaction, Replacement, RosterEntry, ShareKind, ShareSource, SpeakingDetector, StatsSample, VideoHub,
10 MeetingTarget, Progress, Reaction, Replacement, RosterEntry, ShareKind, SharePicker, ShareSource, SpeakingDetector, StatsSample, VideoHub,
11 VideoWant,
11 VideoWant,
12};
12};
13use teams_core::RecordingPolicy;
13use teams_core::RecordingPolicy;
@@ -299,6 +299,8 @@ pub struct CallModel {
299 pub cameras: Vec<CameraDevice>,
299 pub cameras: Vec<CameraDevice>,
300 pub camera: DeviceChoice,
300 pub camera: DeviceChoice,
301 pub local_share: Option<String>,
301 pub local_share: Option<String>,
302 pub share_picker: SharePicker,
303 pub share_kind: Option<ShareKind>,
302 pub share_sources: Vec<ShareSource>,
304 pub share_sources: Vec<ShareSource>,
303 pub share_thumbnails: Vec<(ShareSource, Arc<gpui_kit::RenderImage>)>,
305 pub share_thumbnails: Vec<(ShareSource, Arc<gpui_kit::RenderImage>)>,
304 pub last_sample: Option<StatsSample>,
306 pub last_sample: Option<StatsSample>,
@@ -369,6 +371,8 @@ impl CallModel {
369 cameras: Vec::new(),
371 cameras: Vec::new(),
370 camera: DeviceChoice::SystemDefault,
372 camera: DeviceChoice::SystemDefault,
371 local_share: None,
373 local_share: None,
374 share_picker: SharePicker::List,
375 share_kind: None,
372 share_sources: Vec::new(),
376 share_sources: Vec::new(),
373 share_thumbnails: Vec::new(),
377 share_thumbnails: Vec::new(),
374 last_sample: None,
378 last_sample: None,
@@ -508,6 +512,8 @@ impl CallModel {
508 }
512 }
509 self.local_share = label;
513 self.local_share = label;
510 }
514 }
515 CallUpdate::SharePicker(picker) => self.share_picker = picker,
516 CallUpdate::ShareKind(kind) => self.share_kind = kind,
511 CallUpdate::ShareSources(sources) => {
517 CallUpdate::ShareSources(sources) => {
512 self.share_thumbnails.retain(|(source, _)| sources.contains(source));
518 self.share_thumbnails.retain(|(source, _)| sources.contains(source));
513 self.share_sources = sources;
519 self.share_sources = sources;
@@ -1191,7 +1197,11 @@ impl CallModel {
1191 }
1197 }
1192
1198
1193 pub fn can_share(&self) -> bool {
1199 pub fn can_share(&self) -> bool {
1194 !self.share_sources.is_empty() && self.is_live()
1200 self.is_live() && (self.uses_portal_picker() || !self.share_sources.is_empty())
1201 }
1202
1203 pub fn uses_portal_picker(&self) -> bool {
1204 self.share_picker == SharePicker::Portal
1195 }
1205 }
1196
1206
1197 pub fn is_live(&self) -> bool {
1207 pub fn is_live(&self) -> bool {
@@ -1948,6 +1958,16 @@ mod tests {
1948 assert!(!model.share_sound);
1958 assert!(!model.share_sound);
1949 }
1959 }
1950
1960
1961 #[test]
1962 fn portal_share_works_without_a_source_list() {
1963 let mut model = connected_model();
1964 assert!(model.share_sources.is_empty());
1965 assert!(!model.can_share());
1966 model.apply(CallUpdate::SharePicker(SharePicker::Portal));
1967 assert!(model.uses_portal_picker());
1968 assert!(model.can_share());
1969 }
1970
1951 #[test]
1971 #[test]
1952 fn lobby_guests_are_listed_for_organizers_who_may_admit() {
1972 fn lobby_guests_are_listed_for_organizers_who_may_admit() {
1953 let mut model = meeting_with_me();
1973 let mut model = meeting_with_me();
crates/app/src/views/call_view.rs +3 −0
@@ -626,6 +626,7 @@ fn share_items(
626 626 model: &CallModel,
627 627 options: ShareOptions,
628 628 ) -> PopupMenu {
629 <<<<<<< ours
629 630 <<<<<<< ours
630 631 let single_screen = model.screens().len() == 1;
631 632 let mut screen_index = 0usize;
@@ -692,6 +693,8 @@ fn share_items(
692 693 popup.item(PopupMenuItem::new(NO_WINDOWS_HINT).disabled(true))
693 694 }
694 695 =======
696 =======
697 >>>>>>> theirs
695 698 let mut popup = popup
696 699 .min_w(px(SHARE_MENU_WIDTH))
697 700 .item(sound_switch_item(app, options.sound))
@@ -626,6 +626,7 @@ fn share_items(
626 model: &CallModel,
626 model: &CallModel,
627 options: ShareOptions,
627 options: ShareOptions,
628) -> PopupMenu {
628) -> PopupMenu {
629<<<<<<< ours
629<<<<<<< ours
630<<<<<<< ours
630 let single_screen = model.screens().len() == 1;
631 let single_screen = model.screens().len() == 1;
631 let mut screen_index = 0usize;
632 let mut screen_index = 0usize;
@@ -692,6 +693,8 @@ fn share_items(
692 popup.item(PopupMenuItem::new(NO_WINDOWS_HINT).disabled(true))
693 popup.item(PopupMenuItem::new(NO_WINDOWS_HINT).disabled(true))
693 }
694 }
694=======
695=======
696=======
697>>>>>>> theirs
695 let mut popup = popup
698 let mut popup = popup
696 .min_w(px(SHARE_MENU_WIDTH))
699 .min_w(px(SHARE_MENU_WIDTH))
697 .item(sound_switch_item(app, options.sound))
700 .item(sound_switch_item(app, options.sound))
crates/calling/src/screen.rs +41 −7
@@ -109,6 +109,7 @@ pub fn share_thumbnail(
109 109 }
110 110 });
111 111 for _ in 0..THUMBNAIL_ATTEMPTS {
112 pump_messages();
112 113 capturer.capture_frame();
113 114 if let Some(picture) = captured.lock().ok().and_then(|mut slot| slot.take()) {
114 115 return Some(picture);
@@ -118,6 +119,22 @@ pub fn share_thumbnail(
118 119 None
119 120 }
120 121
122 // Windows Graphics Capture hands frames to a DispatcherQueue on this thread; without a pump none arrive.
123 #[cfg(windows)]
124 fn pump_messages() {
125 use windows::Win32::UI::WindowsAndMessaging::{DispatchMessageW, MSG, PM_REMOVE, PeekMessageW, TranslateMessage};
126 let mut message = MSG::default();
127 unsafe {
128 while PeekMessageW(&mut message, None, 0, 0, PM_REMOVE).as_bool() {
129 let _ = TranslateMessage(&message);
130 let _ = DispatchMessageW(&message);
131 }
132 }
133 }
134
135 #[cfg(not(windows))]
136 fn pump_messages() {}
137
121 138 fn scaled_bgra(
122 139 bytes: &[u8],
123 140 width: u32,
@@ -207,6 +224,7 @@ pub fn start_screen_capture(
207 224 }
208 225 });
209 226 while !stop.load(Ordering::SeqCst) {
227 pump_messages();
210 228 capturer.capture_frame();
211 229 std::thread::sleep(Duration::from_secs(1) / fps.load(Ordering::Relaxed).max(1));
212 230 }
@@ -214,7 +232,7 @@ pub fn start_screen_capture(
214 232 .map_err(|error| Error::Webrtc(format!("screen thread: {error}")))
215 233 }
216 234
217 /// Where the share menu gets its sources. Wayland uses the desktop dialog.
235 /// Where the share menu gets its sources. Wayland and macOS use a system dialog.
218 236 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
219 237 pub enum SharePicker {
220 238 List,
@@ -222,6 +240,13 @@ pub enum SharePicker {
222 240 }
223 241
224 242 pub fn share_picker_for(wayland_display: Option<&str>) -> SharePicker {
243 share_picker_for_host(cfg!(target_os = "macos"), wayland_display)
244 }
245
246 pub fn share_picker_for_host(macos: bool, wayland_display: Option<&str>) -> SharePicker {
247 if macos {
248 return SharePicker::Portal;
249 }
225 250 match wayland_display {
226 251 Some(value) if !value.is_empty() => SharePicker::Portal,
227 252 _ => SharePicker::List,
@@ -240,8 +265,7 @@ pub fn share_sources_for_menu(picker: SharePicker, sources: Vec<ShareSource>) ->
240 265 }
241 266 }
242 267
243 pub const PORTAL_UNAVAILABLE_NOTICE: &str =
244 "Screen sharing needs the desktop share dialog, and it could not open.";
268 pub use crate::notices::PORTAL_UNAVAILABLE_NOTICE;
245 269
246 270 #[derive(Debug, Clone, PartialEq, Eq)]
247 271 pub enum PortalFollowUp {
@@ -383,13 +407,23 @@ mod thumbnail_tests {
383 407
384 408 #[cfg(test)]
385 409 mod portal_mode_tests {
386 use super::{ShareKind, SharePicker, ShareSource, share_picker_for, share_sources_for_menu};
410 use super::{
411 ShareKind, SharePicker, ShareSource, share_picker_for_host, share_sources_for_menu,
412 };
387 413
388 414 #[test]
389 415 fn portal_mode_follows_wayland_display_and_skips_the_menu_list() {
390 assert_eq!(share_picker_for(None), SharePicker::List);
391 assert_eq!(share_picker_for(Some("")), SharePicker::List);
392 assert_eq!(share_picker_for(Some("wayland-1")), SharePicker::Portal);
416 assert_eq!(share_picker_for_host(false, None), SharePicker::List);
417 assert_eq!(share_picker_for_host(false, Some("")), SharePicker::List);
418 assert_eq!(
419 share_picker_for_host(false, Some("wayland-1")),
420 SharePicker::Portal
421 );
422 assert_eq!(share_picker_for_host(true, None), SharePicker::Portal);
423 assert_eq!(
424 share_picker_for_host(true, Some("")),
425 SharePicker::Portal
426 );
393 427 let sources = vec![ShareSource {
394 428 id: 1,
395 429 kind: ShareKind::Screen,
@@ -109,6 +109,7 @@ pub fn share_thumbnail(
109 }
109 }
110 });
110 });
111 for _ in 0..THUMBNAIL_ATTEMPTS {
111 for _ in 0..THUMBNAIL_ATTEMPTS {
112 pump_messages();
112 capturer.capture_frame();
113 capturer.capture_frame();
113 if let Some(picture) = captured.lock().ok().and_then(|mut slot| slot.take()) {
114 if let Some(picture) = captured.lock().ok().and_then(|mut slot| slot.take()) {
114 return Some(picture);
115 return Some(picture);
@@ -118,6 +119,22 @@ pub fn share_thumbnail(
118 None
119 None
119}
120}
120
121
122// Windows Graphics Capture hands frames to a DispatcherQueue on this thread; without a pump none arrive.
123#[cfg(windows)]
124fn pump_messages() {
125 use windows::Win32::UI::WindowsAndMessaging::{DispatchMessageW, MSG, PM_REMOVE, PeekMessageW, TranslateMessage};
126 let mut message = MSG::default();
127 unsafe {
128 while PeekMessageW(&mut message, None, 0, 0, PM_REMOVE).as_bool() {
129 let _ = TranslateMessage(&message);
130 let _ = DispatchMessageW(&message);
131 }
132 }
133}
134
135#[cfg(not(windows))]
136fn pump_messages() {}
137
121fn scaled_bgra(
138fn scaled_bgra(
122 bytes: &[u8],
139 bytes: &[u8],
123 width: u32,
140 width: u32,
@@ -207,6 +224,7 @@ pub fn start_screen_capture(
207 }
224 }
208 });
225 });
209 while !stop.load(Ordering::SeqCst) {
226 while !stop.load(Ordering::SeqCst) {
227 pump_messages();
210 capturer.capture_frame();
228 capturer.capture_frame();
211 std::thread::sleep(Duration::from_secs(1) / fps.load(Ordering::Relaxed).max(1));
229 std::thread::sleep(Duration::from_secs(1) / fps.load(Ordering::Relaxed).max(1));
212 }
230 }
@@ -214,7 +232,7 @@ pub fn start_screen_capture(
214 .map_err(|error| Error::Webrtc(format!("screen thread: {error}")))
232 .map_err(|error| Error::Webrtc(format!("screen thread: {error}")))
215}
233}
216
234
217/// Where the share menu gets its sources. Wayland uses the desktop dialog.
235/// Where the share menu gets its sources. Wayland and macOS use a system dialog.
218#[derive(Debug, Clone, Copy, PartialEq, Eq)]
236#[derive(Debug, Clone, Copy, PartialEq, Eq)]
219pub enum SharePicker {
237pub enum SharePicker {
220 List,
238 List,
@@ -222,6 +240,13 @@ pub enum SharePicker {
222}
240}
223
241
224pub fn share_picker_for(wayland_display: Option<&str>) -> SharePicker {
242pub fn share_picker_for(wayland_display: Option<&str>) -> SharePicker {
243 share_picker_for_host(cfg!(target_os = "macos"), wayland_display)
244}
245
246pub fn share_picker_for_host(macos: bool, wayland_display: Option<&str>) -> SharePicker {
247 if macos {
248 return SharePicker::Portal;
249 }
225 match wayland_display {
250 match wayland_display {
226 Some(value) if !value.is_empty() => SharePicker::Portal,
251 Some(value) if !value.is_empty() => SharePicker::Portal,
227 _ => SharePicker::List,
252 _ => SharePicker::List,
@@ -240,8 +265,7 @@ pub fn share_sources_for_menu(picker: SharePicker, sources: Vec<ShareSource>) ->
240 }
265 }
241}
266}
242
267
243pub const PORTAL_UNAVAILABLE_NOTICE: &str =
268pub use crate::notices::PORTAL_UNAVAILABLE_NOTICE;
244 "Screen sharing needs the desktop share dialog, and it could not open.";
245
269
246#[derive(Debug, Clone, PartialEq, Eq)]
270#[derive(Debug, Clone, PartialEq, Eq)]
247pub enum PortalFollowUp {
271pub enum PortalFollowUp {
@@ -383,13 +407,23 @@ mod thumbnail_tests {
383
407
384#[cfg(test)]
408#[cfg(test)]
385mod portal_mode_tests {
409mod portal_mode_tests {
386 use super::{ShareKind, SharePicker, ShareSource, share_picker_for, share_sources_for_menu};
410 use super::{
411 ShareKind, SharePicker, ShareSource, share_picker_for_host, share_sources_for_menu,
412 };
387
413
388 #[test]
414 #[test]
389 fn portal_mode_follows_wayland_display_and_skips_the_menu_list() {
415 fn portal_mode_follows_wayland_display_and_skips_the_menu_list() {
390 assert_eq!(share_picker_for(None), SharePicker::List);
416 assert_eq!(share_picker_for_host(false, None), SharePicker::List);
391 assert_eq!(share_picker_for(Some("")), SharePicker::List);
417 assert_eq!(share_picker_for_host(false, Some("")), SharePicker::List);
392 assert_eq!(share_picker_for(Some("wayland-1")), SharePicker::Portal);
418 assert_eq!(
419 share_picker_for_host(false, Some("wayland-1")),
420 SharePicker::Portal
421 );
422 assert_eq!(share_picker_for_host(true, None), SharePicker::Portal);
423 assert_eq!(
424 share_picker_for_host(true, Some("")),
425 SharePicker::Portal
426 );
393 let sources = vec![ShareSource {
427 let sources = vec![ShareSource {
394 id: 1,
428 id: 1,
395 kind: ShareKind::Screen,
429 kind: ShareKind::Screen,