Add ability to auto watch screens (#54839)

This PR adds a feature to automatically cycle through screen shares
during calls, designed for demo days or any call that has a lot of
screen share use.

This is a preliminary attempt behind a feature flag so we can dogfood
and iterate, or toss it out.

There's a new toggle next to the active channel name in the collab
panel: **Auto Watch Screens**.


https://github.com/user-attachments/assets/ae6eccec-7921-4c1f-8921-c8093631c705

This video demonstrates some cases:

Basic auto-watch
- Toggle on → automatically opens the next screen share that starts
- When the watched screen share ends, switches to the next available
share

Queuing
- Someone starts sharing while another share is active → doesn't
interrupt the current share
- When the current share ends, the queued share is picked up
automatically

Paused while sharing
- Auto-watch pauses when you start sharing your own screen, so other
shares don't pop up during your presentation
- When you stop sharing, auto-watch resumes and opens the next available
share

Multiple watchers
- Multiple people can have auto-watch enabled independently — they all
see the same transitions

Note that we don't manage the screenshares, livekit does, so this change
is entirely on the client. I think that's mostly fine, but there is a
chance 2 separate clients queues up a different person as the next
watched peer if they both engage screenshare around the same time,
depending on how it hits the clients, but it seems pretty edge case. We
can move the implementation to collab, but it will be more of a project,
and adding a secondary source alongside of livekit that could get out of
sync and have its own issues.

UI/UX needs work (@danilo-leal for suggestions)

Self-Review Checklist:

- [X] I've reviewed my own diff for quality, security, and reliability
- [X] Unsafe blocks (if any) have justifying comments
- [X] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [X] Tests cover the new/changed behavior
- [X] Performance impact has been considered and is acceptable

Closes #ISSUE

Release Notes:

- N/A

---------

Co-authored-by: Yara 🏳️‍⚧️ <11743287+yara-blue@users.noreply.github.com>
This commit is contained in:
Joseph T. LyonsandYara 🏳️‍⚧️ authored and GitHub committed 2026-05-01 17:29:27 +00:00
1 parent 90b3ef0c65
commit 6b28db5ef5
10 files changed
+579 -13

No files matched your search

+120 -2
View File
@@ -1363,6 +1363,7 @@ pub struct Workspace {
project: Entity<Project>,
follower_states: HashMap<CollaboratorId, FollowerState>,
last_leaders_by_pane: HashMap<WeakEntity<Pane>, CollaboratorId>,
auto_watch: AutoWatch,
window_edited: bool,
last_window_title: Option<String>,
dirty_items: HashMap<EntityId, Subscription>,
@@ -1415,6 +1416,19 @@ pub struct FollowerState {
items_by_leader_view_id: HashMap<ViewId, FollowerView>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AutoWatch {
Off,
Active { watched_peer: Option<PeerId> },
Paused,
}
impl AutoWatch {
pub fn enabled(&self) -> bool {
matches!(self, AutoWatch::Active { .. } | AutoWatch::Paused)
}
}
struct FollowerView {
view: Box<dyn FollowableItemHandle>,
location: Option<proto::PanelId>,
@@ -1793,6 +1807,7 @@ impl Workspace {
project: project.clone(),
follower_states: Default::default(),
last_leaders_by_pane: Default::default(),
auto_watch: AutoWatch::Off,
dispatching_keystrokes: Default::default(),
window_edited: false,
last_window_title: None,
@@ -4783,6 +4798,93 @@ impl Workspace {
}
}
pub fn auto_watch_state(&self) -> &AutoWatch {
&self.auto_watch
}
fn next_watched_peer(&self, cx: &App) -> Option<PeerId> {
self.active_call()
.and_then(|call| call.peer_ids_with_video_tracks(cx).first().copied())
}
pub fn toggle_auto_watch(&mut self, window: &mut Window, cx: &mut Context<Self>) {
if self.auto_watch.enabled() {
self.auto_watch = AutoWatch::Off;
cx.notify();
return;
}
let active_pane = self.active_pane.clone();
self.unfollow_in_pane(&active_pane, window, cx);
let local_is_sharing = self
.active_call()
.map_or(false, |call| call.is_sharing_screen(cx));
if local_is_sharing {
self.auto_watch = AutoWatch::Paused;
} else {
let watched_peer = self.next_watched_peer(cx);
self.auto_watch = AutoWatch::Active { watched_peer };
if let Some(peer_id) = watched_peer {
self.open_shared_screen(peer_id, window, cx);
}
}
cx.notify();
}
fn handle_auto_watch_video_tracks_changed(
&mut self,
peer_id: PeerId,
window: &mut Window,
cx: &mut Context<Self>,
) {
let AutoWatch::Active { watched_peer } = self.auto_watch else {
return;
};
let peer_is_sharing = self.active_call().map_or(false, |call| {
call.peer_ids_with_video_tracks(cx).contains(&peer_id)
});
let should_watch_peer = peer_is_sharing && watched_peer.is_none();
let watched_peer_stopped_sharing = watched_peer == Some(peer_id) && !peer_is_sharing;
if should_watch_peer || watched_peer_stopped_sharing {
let next_watched_peer = if should_watch_peer {
Some(peer_id)
} else {
self.next_watched_peer(cx)
};
self.auto_watch = AutoWatch::Active {
watched_peer: next_watched_peer,
};
if let Some(next_watched_peer) = next_watched_peer {
self.open_shared_screen(next_watched_peer, window, cx);
}
}
}
fn handle_auto_watch_local_share_stopped(
&mut self,
window: &mut Window,
cx: &mut Context<Self>,
) {
let AutoWatch::Paused = self.auto_watch else {
return;
};
let watched_peer = self.next_watched_peer(cx);
self.auto_watch = AutoWatch::Active { watched_peer };
if let Some(peer_id) = watched_peer {
self.open_shared_screen(peer_id, window, cx);
}
}
pub fn activate_item(
&mut self,
item: &dyn ItemHandle,
@@ -6512,10 +6614,22 @@ impl Workspace {
cx: &mut Context<Self>,
) {
match event {
ActiveCallEvent::ParticipantLocationChanged { participant_id }
| ActiveCallEvent::RemoteVideoTracksChanged { participant_id } => {
ActiveCallEvent::ParticipantLocationChanged { participant_id } => {
self.leader_updated(participant_id, window, cx);
}
ActiveCallEvent::RemoteVideoTracksChanged { participant_id } => {
self.leader_updated(participant_id, window, cx);
self.handle_auto_watch_video_tracks_changed(*participant_id, window, cx);
}
ActiveCallEvent::LocalScreenShareStarted => {
if let AutoWatch::Active { .. } = self.auto_watch {
self.auto_watch = AutoWatch::Paused;
cx.notify();
}
}
ActiveCallEvent::LocalScreenShareStopped => {
self.handle_auto_watch_local_share_stopped(window, cx);
}
}
}
@@ -7879,6 +7993,7 @@ pub trait AnyActiveCall {
fn unshare_project(&self, _: Entity<Project>, _: &mut App) -> Result<()>;
fn remote_participant_for_peer_id(&self, _: PeerId, _: &App) -> Option<RemoteCollaborator>;
fn is_sharing_project(&self, _: &App) -> bool;
fn is_sharing_screen(&self, _: &App) -> bool;
fn has_remote_participants(&self, _: &App) -> bool;
fn local_participant_is_guest(&self, _: &App) -> bool;
fn client(&self, _: &App) -> Arc<Client>;
@@ -7908,6 +8023,7 @@ pub trait AnyActiveCall {
_: &mut Window,
_: &mut App,
) -> Option<Entity<SharedScreen>>;
fn peer_ids_with_video_tracks(&self, _: &App) -> Vec<PeerId>;
}
#[derive(Clone)]
@@ -7961,6 +8077,8 @@ pub struct RemoteCollaborator {
pub enum ActiveCallEvent {
ParticipantLocationChanged { participant_id: PeerId },
RemoteVideoTracksChanged { participant_id: PeerId },
LocalScreenShareStarted,
LocalScreenShareStopped,
}
fn leader_border_for_pane(