collab: Add screen selector (#31506)

Instead of selecting a screen to share arbitrarily, we'll now allow user
to select the screen to share. Note that sharing multiple screens at the
time is still not supported (though prolly not too far-fetched).

Related to #4666

![image](https://github.com/user-attachments/assets/1afb664f-3cdb-4e0a-bb29-9d7093d87fa5)

Release Notes:

- Added screen selector dropdown to screen share button

---------

Co-authored-by: Kirill Bulatov <kirill@zed.dev>
Co-authored-by: Cole Miller <cole@zed.dev>
This commit is contained in:
Piotr Osiewicz 2025-07-21 13:44:51 +02:00 committed by GitHub
parent 57ab09c2da
commit 88af35fe47
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
26 changed files with 473 additions and 145 deletions

View file

@ -85,7 +85,7 @@ pub(crate) use test::*;
pub(crate) use windows::*;
#[cfg(any(test, feature = "test-support"))]
pub use test::{TestDispatcher, TestScreenCaptureSource};
pub use test::{TestDispatcher, TestScreenCaptureSource, TestScreenCaptureStream};
/// Returns a background executor for the current platform.
pub fn background_executor() -> BackgroundExecutor {
@ -189,13 +189,12 @@ pub(crate) trait Platform: 'static {
false
}
#[cfg(feature = "screen-capture")]
fn screen_capture_sources(
&self,
) -> oneshot::Receiver<Result<Vec<Box<dyn ScreenCaptureSource>>>>;
fn screen_capture_sources(&self)
-> oneshot::Receiver<Result<Vec<Rc<dyn ScreenCaptureSource>>>>;
#[cfg(not(feature = "screen-capture"))]
fn screen_capture_sources(
&self,
) -> oneshot::Receiver<anyhow::Result<Vec<Box<dyn ScreenCaptureSource>>>> {
) -> oneshot::Receiver<anyhow::Result<Vec<Rc<dyn ScreenCaptureSource>>>> {
let (sources_tx, sources_rx) = oneshot::channel();
sources_tx
.send(Err(anyhow::anyhow!(
@ -293,10 +292,23 @@ pub trait PlatformDisplay: Send + Sync + Debug {
}
}
/// Metadata for a given [ScreenCaptureSource]
#[derive(Clone)]
pub struct SourceMetadata {
/// Opaque identifier of this screen.
pub id: u64,
/// Human-readable label for this source.
pub label: Option<SharedString>,
/// Whether this source is the main display.
pub is_main: Option<bool>,
/// Video resolution of this source.
pub resolution: Size<DevicePixels>,
}
/// A source of on-screen video content that can be captured.
pub trait ScreenCaptureSource {
/// Returns the video resolution of this source.
fn resolution(&self) -> Result<Size<DevicePixels>>;
/// Returns metadata for this source.
fn metadata(&self) -> Result<SourceMetadata>;
/// Start capture video from this source, invoking the given callback
/// with each frame.
@ -308,7 +320,10 @@ pub trait ScreenCaptureSource {
}
/// A video stream captured from a screen.
pub trait ScreenCaptureStream {}
pub trait ScreenCaptureStream {
/// Returns metadata for this source.
fn metadata(&self) -> Result<SourceMetadata>;
}
/// A frame of video captured from a screen.
pub struct ScreenCaptureFrame(pub PlatformScreenCaptureFrame);