From ae944e76a3428fa319bd03e47169321028809fe8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Thu, 26 Nov 2026 02:28:34 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20stage=20strip=20for=20camer?= =?UTF-8?q?as=20and=20screens,=20auto=20watch=20quality,=20voice=20panel?= =?UTF-8?q?=20keeps=20call=20members?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/client/src/gui/camera_view.rs | 127 +++++++++++++++------ crates/client/src/gui/chat.rs | 85 +++++++++----- crates/client/src/gui/share_view.rs | 160 ++++++++------------------- crates/client/src/gui/sidebar.rs | 16 ++- crates/client/src/net/media.rs | 1 - crates/client/src/settings.rs | 12 +- 6 files changed, 209 insertions(+), 192 deletions(-) diff --git a/crates/client/src/gui/camera_view.rs b/crates/client/src/gui/camera_view.rs index c11caac..1dee2fe 100644 --- a/crates/client/src/gui/camera_view.rs +++ b/crates/client/src/gui/camera_view.rs @@ -4,14 +4,17 @@ use std::sync::Arc; use common::share::{Fps, Kind, Quality, Resolution}; use gpui_kit::{ Context, Entity, InteractiveElement, IntoElement, ObjectFit, ParentElement, RenderImage, - StatefulInteractiveElement, Styled, StyledImage, Task, Window, assets::IconName, div, img, px, + StatefulInteractiveElement, Styled, StyledImage, Task, Window, + assets::IconName, + component::Icon, + div, img, px, }; use super::{ - Palette, Tooltip as _, Yumush, clickable, + Palette, Tooltip as _, Yumush, avatar, clickable, media_view::to_render_image, notify_error, - share_view::FRAME_TICK, + share_view::{self, FRAME_TICK}, text, widget::{icon_button, spawn_warn}, }; @@ -131,35 +134,50 @@ impl Yumush { .detach(); } - pub(super) fn camera_row( + pub(super) fn stage_sources(&self) -> Vec<(Id, Kind)> { + let Some(community_id) = self.chat.voice_community() else { + return Vec::new(); + }; + let mut sources: Vec<(Id, Kind)> = self + .chat + .shares + .get(&community_id) + .into_iter() + .flatten() + .map(|share| (share.user_id, share.kind)) + .collect(); + sources.sort(); + sources + } + + pub(super) fn stage_strip( &self, entity: &Entity, palette: Palette, ) -> Option { - if self.chat.cameras.is_empty() { + let sources = self.stage_sources(); + if self.chat.stage_hidden + || sources.is_empty() + || self.chat.selected_community_id != self.chat.voice_community() + { return None; } - let tiles: Vec<_> = self - .chat - .cameras - .iter() - .map(|(user_id, tile)| { - let name = self - .chat - .author(*user_id) - .map_or("Someone", |user| user.username.as_str()); - camera_tile(entity, *user_id, name, tile, palette) - }) + let tiles: Vec<_> = sources + .into_iter() + .map(|source| stage_tile(entity, self, palette, source)) .collect(); Some( div() - .id("camera_row") + .id("stage_strip") .flex() .flex_shrink_0() + .h(px(108.)) .gap(px(6.)) .p(px(6.)) .overflow_x_scroll() + .border_b_1() + .border_color(palette.border) .children(tiles), ) } @@ -206,33 +224,72 @@ pub(super) fn camera_toggle( .text_color(if on { palette.ok } else { palette.muted }) } -fn camera_tile( +fn stage_tile( entity: &Entity, - user_id: Id, - name: &str, - tile: &CameraTile, + yumush: &Yumush, palette: Palette, + (user_id, kind): (Id, Kind), ) -> impl IntoElement { let entity = entity.clone(); + let focused = yumush.is_watching(user_id, kind); + let speaking = yumush.chat.waves.speaking.contains(&user_id); + let frame = match kind { + Kind::Camera => yumush + .chat + .cameras + .get(&user_id) + .and_then(|tile| tile.frame.clone()), + Kind::Screen => yumush.viewer_frame(user_id, kind), + }; + let user = yumush.chat.author(user_id); + let name = user.map_or("Someone", |user| user.username.as_str()); + let content = match (frame, user) { + (Some(frame), _) => img(frame) + .size_full() + .object_fit(ObjectFit::Cover) + .into_any_element(), + (None, Some(user)) => div() + .size_full() + .flex() + .items_center() + .justify_center() + .child(avatar( + palette, + user, + px(36.), + text(14.), + &yumush.chat.avatars, + )) + .into_any_element(), + (None, None) => div().into_any_element(), + }; - clickable(format!("camera_{user_id}"), palette, move |window, cx| { - entity.update(cx, |yumush, cx| { - yumush.toggle_viewer(user_id, Kind::Camera, window, cx) - }); - }) + clickable( + format!("stage_{user_id}_{kind:?}"), + palette, + move |window, cx| { + entity.update(cx, |yumush, cx| { + yumush.toggle_viewer(user_id, kind, window, cx) + }); + }, + ) .tip("Watch") .relative() .flex_shrink_0() - .w(px(213.)) - .h(px(120.)) + .w(px(171.)) + .h(px(96.)) .rounded(px(8.)) .overflow_hidden() .bg(gpui_kit::black()) - .children( - tile.frame - .clone() - .map(|frame| img(frame).size_full().object_fit(ObjectFit::Cover)), - ) + .border_2() + .border_color(if focused { + palette.accent + } else if speaking { + palette.ok + } else { + palette.ok.opacity(0.) + }) + .child(content) .child( div() .absolute() @@ -243,6 +300,10 @@ fn camera_tile( .rounded(px(4.)) .bg(palette.panel) .text_size(text(11.)) + .flex() + .items_center() + .gap(px(4.)) + .child(Icon::new(share_view::kind_icon(kind)).w(px(12.)).h(px(12.))) .child(name.to_string()), ) } diff --git a/crates/client/src/gui/chat.rs b/crates/client/src/gui/chat.rs index 9798ed7..db79161 100644 --- a/crates/client/src/gui/chat.rs +++ b/crates/client/src/gui/chat.rs @@ -22,7 +22,7 @@ use crate::gui::{ primary_button, profile::profile_popover, rank_tag, - share_view::{self, Viewer}, + share_view::Viewer, sidebar::{SidebarTab, unread_badge}, snippet, voice_note::{self, VoiceNote}, @@ -257,6 +257,7 @@ pub struct Chat { pub(super) viewer: Option, pub(super) cameras: BTreeMap, pub(super) camera_task: Option>, + pub(super) stage_hidden: bool, pub(super) typing: HashMap>, pub(super) typing_sent: HashMap, } @@ -487,6 +488,7 @@ impl Chat { viewer: None, cameras: BTreeMap::new(), camera_task: None, + stage_hidden: false, composer: Composer::Compose { reply: None }, } } @@ -703,7 +705,8 @@ impl Chat { self.delete_step = DeleteStep::Idle; } self.selected_community_id = community_id; - self.members.clear(); + self.users + .extend(self.members.drain(..).map(|member| (member.user.id, member.user))); self.bans.clear(); self.logs.clear(); self.pending_user_delete = None; @@ -896,16 +899,22 @@ impl Chat { } fn missing_authors(&self) -> Vec { - if self.members.is_empty() { - return vec![]; + let mut ids: Vec = if self.members.is_empty() { + vec![] + } else { + self.messages + .iter() + .flat_map(|message| { + std::iter::once(message.user_id) + .chain(message.reply.as_ref().map(|quote| quote.user_id)) + }) + .collect() + }; + if let Some(community_id) = self.voice_community() { + ids.extend_from_slice(self.voice_ids(community_id)); } - let mut missing: Vec = self - .messages - .iter() - .flat_map(|message| { - std::iter::once(message.user_id) - .chain(message.reply.as_ref().map(|quote| quote.user_id)) - }) + let mut missing: Vec = ids + .into_iter() .filter(|id| self.author(*id).is_none() && !self.user_requests.contains(id)) .collect(); missing.sort(); @@ -1103,10 +1112,6 @@ impl Chat { .find(|share| share.user_id == user_id && share.kind == kind) } - pub fn is_sharing(&self, community_id: Id, user_id: Id) -> bool { - self.share_of(community_id, user_id, Kind::Screen).is_some() - } - pub fn voice_ids(&self, community_id: Id) -> &[Id] { self.voice .get(&community_id) @@ -1270,7 +1275,7 @@ impl Yumush { View::Chat => match self.chat.selected_community_id { Some(_) => panel .child(self.header(entity, themed)) - .children(self.camera_row(entity, themed)) + .children(self.stage_strip(entity, themed)) .children(self.unread_bar(entity, themed)) .children(self.poll_banner(entity, themed)) .map(|panel| match self.inline_viewer(entity, themed) { @@ -1737,7 +1742,11 @@ impl Yumush { .users .insert(member.user.id, member.user.clone()); } - yumush.chat.members = members; + let old = std::mem::replace(&mut yumush.chat.members, members); + yumush + .chat + .users + .extend(old.into_iter().map(|member| (member.user.id, member.user))); yumush.load_bans(window, cx); yumush.request_authors(cx); cx.notify(); @@ -1956,6 +1965,7 @@ impl Yumush { let _ = this.update(cx, |yumush, cx| { yumush.chat.voice.insert(community_id, participants); + yumush.request_authors(cx); cx.notify(); }); }) @@ -2005,6 +2015,7 @@ impl Yumush { muted || yumush.is_server_muted() || yumush.hidden_in(community_id); yumush.network.set_muted(muted); yumush.chat.voice.insert(community_id, participants); + yumush.request_authors(cx); yumush.load_shares(community_id, cx); yumush.chat.voice_state = VoiceState::In { community_id, @@ -2444,11 +2455,8 @@ impl Yumush { if users.is_empty() { return None; } - let sharers: Vec = users - .iter() - .filter(|user| self.chat.is_sharing(community_id, user.id)) - .map(|user| user.id) - .collect(); + let stage = self.stage_sources().len(); + let hidden = self.chat.stage_hidden; Some( div() @@ -2474,14 +2482,31 @@ impl Yumush { .when(index > 0, |this| this.ml(px(-6.))), ) })) - .children(sharers.iter().map(|user_id| { - share_view::share_badge( - entity, - *user_id, - self.chat.waves.share(*user_id), - palette, - ) - })), + .children( + (stage > 0 && self.chat.selected_community_id == self.chat.voice_community()) + .then(|| { + clickable( + "stage_toggle", + palette, + entity_action(entity, |yumush: &mut Yumush, _, cx| { + yumush.chat.stage_hidden = !yumush.chat.stage_hidden; + cx.notify(); + }), + ) + .tip(if hidden { "Show stage" } else { "Hide stage" }) + .ml(px(8.)) + .h(px(22.)) + .px(px(6.)) + .flex() + .items_center() + .gap(px(4.)) + .rounded(px(6.)) + .text_size(text(11.)) + .text_color(if hidden { palette.muted } else { palette.accent }) + .child(Icon::new(IconName::LayoutDashboard).w(px(14.)).h(px(14.))) + .child(stage.to_string()) + }), + ), ) } diff --git a/crates/client/src/gui/share_view.rs b/crates/client/src/gui/share_view.rs index dd6fbdc..35f0a0e 100644 --- a/crates/client/src/gui/share_view.rs +++ b/crates/client/src/gui/share_view.rs @@ -1,9 +1,9 @@ use common::model::Id; -use std::{collections::VecDeque, sync::Arc, time::Duration}; +use std::{sync::Arc, time::Duration}; -use common::share::{Codec, Fps, Kind, Quality, Resolution, Source, options}; +use common::share::{Codec, Fps, Kind, Resolution, Source, options}; use gpui_kit::{ - Anchor, AnyElement, AppContext, Context, Div, Entity, FontWeight, InteractiveElement, + Anchor, AnyElement, AppContext, Context, Div, Entity, InteractiveElement, IntoElement, MouseButton, ObjectFit, ParentElement, RenderImage, StatefulInteractiveElement, Styled, StyledImage, Subscription, Task, Window, assets::IconName, @@ -28,7 +28,7 @@ use super::{ widget::{icon_button, spawn_warn}, }; use crate::{ - settings::{self, SHARE_QUALITY, ShareAudio, ShareCodec, ShareSettings}, + settings::{self, ShareAudio, ShareCodec, ShareSettings}, share::{ audio::{AudioApp, AudioKind}, encode::capabilities, @@ -192,10 +192,6 @@ impl Yumush { }); } - pub(super) fn set_share_watch(&mut self, watch: WatchQuality, cx: &mut Context) { - self.update_share(cx, |settings| settings.watch = watch); - } - pub(super) fn is_watching(&self, user_id: Id, kind: Kind) -> bool { self.chat .viewer @@ -203,6 +199,14 @@ impl Yumush { .is_some_and(|viewer| viewer.user_id == user_id && viewer.kind == kind) } + pub(super) fn viewer_frame(&self, user_id: Id, kind: Kind) -> Option> { + self.chat + .viewer + .as_ref() + .filter(|viewer| viewer.user_id == user_id && viewer.kind == kind) + .and_then(|viewer| viewer.frame.clone()) + } + pub(super) fn viewing_camera(&self) -> Option { self.chat .viewer @@ -261,7 +265,7 @@ impl Yumush { }); let network = self.network.clone(); - let watch = self.settings.share.watch; + let watch = WatchQuality::Auto; let volume = self.settings.share.volume; let choice = self.settings.voice.choice.clone(); if kind == Kind::Camera && self.chat.cameras.contains_key(&user_id) { @@ -405,7 +409,8 @@ impl Yumush { .chat .viewer .as_ref() - .filter(|viewer| !viewer.fullscreen)?; + .filter(|viewer| !viewer.fullscreen) + .filter(|_| self.chat.selected_community_id == self.chat.voice_community())?; Some(self.viewer_pane(viewer, entity, palette)) } @@ -422,21 +427,17 @@ impl Yumush { ) } - fn share_top(&self, user_id: Id, kind: Kind) -> Quality { - self.chat - .voice_community() - .and_then(|community_id| self.chat.share_of(community_id, user_id, kind)) - .map_or(SHARE_QUALITY, |share| share.source.top) - } - fn viewer_pane(&self, viewer: &Viewer, entity: &Entity, palette: Palette) -> Div { let (fullscreen_icon, fullscreen_tip) = if viewer.fullscreen { (IconName::Minimize, "Exit fullscreen") } else { (IconName::Maximize, "Fullscreen") }; - let top = self.share_top(viewer.user_id, viewer.kind); let audio = viewer.kind == Kind::Screen; + let name = self + .chat + .author(viewer.user_id) + .map_or("Someone", |user| user.username.as_str()); div() .flex_1() @@ -454,6 +455,24 @@ impl Yumush { div() .absolute() .left(px(10.)) + .top(px(10.)) + .px(px(8.)) + .py(px(4.)) + .flex() + .items_center() + .gap(px(6.)) + .rounded(px(6.)) + .border_1() + .border_color(palette.border) + .bg(palette.panel) + .occlude() + .text_size(text(12.)) + .child(Icon::new(kind_icon(viewer.kind)).w(px(14.)).h(px(14.))) + .child(name.to_string()), + ) + .child( + div() + .absolute() .right(px(10.)) .bottom(px(10.)) .p(px(6.)) @@ -466,13 +485,6 @@ impl Yumush { .bg(palette.panel) .occlude() .text_size(text(12.)) - .child(quality_chips( - entity, - self.settings.share.watch, - top, - palette, - )) - .child(div().flex_1()) .children( audio .then(|| { @@ -490,7 +502,11 @@ impl Yumush { .text_color(palette.muted) })) .children( - audio.then(|| Slider::new(&viewer.volume).bg(palette.muted).w(px(80.))), + audio.then(|| { + div() + .w(px(100.)) + .child(Slider::new(&viewer.volume).bg(palette.muted)) + }), ) .child(icon_button( "share_fullscreen".to_string(), @@ -510,95 +526,13 @@ impl Yumush { } } -fn quality_chips( - entity: &Entity, - watch: WatchQuality, - top: Quality, - palette: Palette, -) -> Div { - let fps = match watch { - WatchQuality::Auto => top.fps, - WatchQuality::Fixed(quality) => quality.fps, - }; - let resolutions = std::iter::once((WatchQuality::Auto, "Auto")).chain( - RESOLUTIONS - .into_iter() - .filter(|(resolution, _)| resolution.height() <= top.resolution.height()) - .map(|(resolution, label)| (WatchQuality::Fixed(Quality { resolution, fps }), label)), - ); - let row = div().flex().items_center().gap(px(6.)).child(segmented( - resolutions, - watch, - entity, - palette, - Yumush::set_share_watch, - )); - - match watch { - WatchQuality::Auto => row, - WatchQuality::Fixed(quality) => { - let fps = FPS - .into_iter() - .filter(|(fps, _)| fps.value() <= top.fps.value()) - .map(|(fps, label)| { - ( - WatchQuality::Fixed(Quality { - resolution: quality.resolution, - fps, - }), - label, - ) - }); - row.child(segmented( - fps, - watch, - entity, - palette, - Yumush::set_share_watch, - )) - } +pub(super) fn kind_icon(kind: Kind) -> IconName { + match kind { + Kind::Screen => IconName::ScreenShare, + Kind::Camera => IconName::Video, } } -pub(super) fn share_badge( - entity: &Entity, - user_id: Id, - sound: Option<&VecDeque>, - palette: Palette, -) -> impl IntoElement { - let entity = entity.clone(); - - clickable( - format!("share_badge_{user_id}"), - palette, - move |window, cx| { - entity.update(cx, |yumush, cx| { - yumush.toggle_viewer(user_id, Kind::Screen, window, cx) - }); - }, - ) - .tip("Watch") - .ml(px(6.)) - .h(px(18.)) - .px(px(5.)) - .flex() - .items_center() - .gap(px(3.)) - .rounded(px(4.)) - .bg(palette.alert) - .text_color(palette.on_accent) - .text_size(text(10.)) - .font_weight(FontWeight::SEMIBOLD) - .child(match sound { - Some(history) => wave(history, 10., palette.on_accent).into_any_element(), - None => Icon::new(IconName::ScreenShare) - .w(px(10.)) - .h(px(10.)) - .into_any_element(), - }) - .child("Live") -} - fn settings_card(entity: &Entity, yumush: &Yumush, palette: Palette) -> Div { let settings = &yumush.settings.share; let (resolutions, fps) = share_limits(yumush.network.share_source()); @@ -690,7 +624,7 @@ fn audio_list(entity: &Entity, yumush: &Yumush, palette: Palette) -> Opt apps.into_iter() .map(|app| exclude_row(entity, settings, app)), ); - field("Exclude", app_list(rows), palette).into_any_element() + field("Include", app_list(rows), palette).into_any_element() }) } ShareAudio::Source(selected) => Some( diff --git a/crates/client/src/gui/sidebar.rs b/crates/client/src/gui/sidebar.rs index 36dcfed..77facf5 100644 --- a/crates/client/src/gui/sidebar.rs +++ b/crates/client/src/gui/sidebar.rs @@ -3,6 +3,7 @@ use common::model::Id; use common::{ model::{Community, CommunityKind, Invitation, Role, Unread, User}, permission, + share::Kind, validate::validate_community_name, }; use gpui_kit::{ @@ -236,8 +237,8 @@ impl Yumush { palette: Palette, ) -> impl IntoElement { let speaking = self.chat.waves.speaking.contains(&user.id); - let share = self.chat.waves.share(user.id); - let sharing = share.is_none() && self.chat.is_sharing(community_id, user.id); + let screen = self.chat.share_of(community_id, user.id, Kind::Screen).is_some(); + let camera = self.chat.share_of(community_id, user.id, Kind::Camera).is_some(); profile_popover( format!("voice_member_{}", user.id), @@ -271,7 +272,7 @@ impl Yumush { .text_color(palette.text) .child(user.username.clone()), ) - .when(sharing, |row| { + .when(screen, |row| { row.child( Icon::new(IconName::ScreenShare) .w(px(12.)) @@ -279,7 +280,14 @@ impl Yumush { .text_color(palette.alert), ) }) - .children(share.map(|history| wave(history, 12., palette.alert))) + .when(camera, |row| { + row.child( + Icon::new(IconName::Video) + .w(px(12.)) + .h(px(12.)) + .text_color(palette.alert), + ) + }) .children( self.chat .waves diff --git a/crates/client/src/net/media.rs b/crates/client/src/net/media.rs index 0f742b1..45360e8 100644 --- a/crates/client/src/net/media.rs +++ b/crates/client/src/net/media.rs @@ -673,7 +673,6 @@ impl NetworkHandle { for ((_, kind), watching) in self.media().lock().watching.iter_mut() { if *kind == Kind::Screen { watching.set_volume(settings.volume); - watching.set_quality(settings.watch); } } } diff --git a/crates/client/src/settings.rs b/crates/client/src/settings.rs index 969373d..1d5f7c9 100644 --- a/crates/client/src/settings.rs +++ b/crates/client/src/settings.rs @@ -14,7 +14,7 @@ use gpui_kit::{ use crate::{ read_config, - share::{audio::AudioMode, encode::capabilities, session::WatchQuality}, + share::{audio::AudioMode, encode::capabilities}, voice::audio::Choice, write_config, }; @@ -145,7 +145,6 @@ pub struct ShareSettings { pub codec: ShareCodec, pub audio: ShareAudio, pub excluded: Vec, - pub watch: WatchQuality, pub volume: f32, } @@ -156,7 +155,6 @@ impl Default for ShareSettings { codec: ShareCodec::Auto, audio: ShareAudio::Everything, excluded: Vec::new(), - watch: WatchQuality::Auto, volume: 100.0, } } @@ -293,9 +291,6 @@ pub fn load() -> Settings { excluded: text("share.excluded") .map(|value| value.split('\t').map(str::to_string).collect()) .unwrap_or_default(), - watch: text("share.watch") - .and_then(|value| parse_quality(&value)) - .map_or(WatchQuality::Auto, WatchQuality::Fixed), volume: number("share.volume", defaults.share.volume, &VOLUME), }; @@ -325,10 +320,6 @@ pub fn save(settings: &Settings) { ShareAudio::Everything => ("everything", ""), ShareAudio::Source(name) => ("source", name.as_str()), }; - let watch = match share.watch { - WatchQuality::Auto => "auto".to_string(), - WatchQuality::Fixed(quality) => quality_text(quality), - }; let content = [ line("theme", settings.theme.as_str()), line("font_size", settings.font_size.as_str()), @@ -367,7 +358,6 @@ pub fn save(settings: &Settings) { line("share.audio", audio), line("share.audio_source", source), line("share.excluded", share.excluded.join("\t")), - line("share.watch", watch), line("share.volume", share.volume), ] .concat();