forge
Explore
Log in

Don't you dare go Hollow

Stats panel follows the design (network cells, ping line, total up/down mirror, layer rows, receiving rows, cpu/gpu from /proc), viewer gets a quality pill + stream stats card, dock gets per-device settings chevrons, whole mic group mutes, hover + tooltips, viewer bar stays up 2.5s after the last mouse move

Browse files at this commit

599fbc4af0cf284b2f23dcc5b0bb658061024f61Ahmet Kaan GümüşParent: f0b8daa
  • ui
    • stats panel follows the design (network cells, ping line, total up/down mirror, layer rows, receiving rows, cpu/gpu from /proc), viewer gets a quality pill + stream stats card, dock gets per-device settings chevrons, whole mic group mutes, hover + tooltips, viewer bar stays up 2.5s after the last mouse move
Show full message
💄 ui: stats panel follows the design (network cells, ping line, total up/down mirror, layer rows, receiving rows, cpu/gpu from /proc), viewer gets a quality pill + stream stats card, dock gets per-device settings chevrons, whole mic group mutes, hover + tooltips, viewer bar stays up 2.5s after the last mouse move
crates/client/src/gui/camera_view.rsmodified+1 -0
@@ -435,6 +435,7 @@ fn grid_cell(
435 if shared {435 if shared {
436 let entity = entity.clone();436 let entity = entity.clone();
437 cell.cursor_pointer()437 cell.cursor_pointer()
438+ .tip("Watch")
438 .on_click(move |_, window, cx| {439 .on_click(move |_, window, cx| {
439 entity.update(cx, |yumush, cx| {440 entity.update(cx, |yumush, cx| {
440 yumush.toggle_viewer(user_id, kind, window, cx)441 yumush.toggle_viewer(user_id, kind, window, cx)
crates/client/src/gui/chat.rsmodified+35 -2
@@ -253,9 +253,12 @@ pub struct Chat {
253 pub(super) voice_task: Option<Task<()>>,253 pub(super) voice_task: Option<Task<()>>,
254 pub(super) user_volume: Option<UserVolume>,254 pub(super) user_volume: Option<UserVolume>,
255 pub(super) voice_samples: VecDeque<VoiceSample>,255 pub(super) voice_samples: VecDeque<VoiceSample>,
256+ pub(super) traffic: VecDeque<(f32, f32)>,
256 pub(super) share_sample: ShareSample,257 pub(super) share_sample: ShareSample,
257 pub(super) share_loss: HashMap<(Id, Kind), VecDeque<f32>>,258 pub(super) share_loss: HashMap<(Id, Kind), VecDeque<f32>>,
258 pub(super) stats_open: bool,259 pub(super) stats_open: bool,
260+ pub(super) usage: Option<crate::usage::Usage>,
261+ pub(super) usage_sampler: crate::usage::Sampler,
259 pub(super) ringing: HashSet<Id>,262 pub(super) ringing: HashSet<Id>,
260 pub(super) ring_task: Option<Task<()>>,263 pub(super) ring_task: Option<Task<()>>,
261 pub(super) media: Media,264 pub(super) media: Media,
@@ -495,9 +498,12 @@ impl Chat {
495 builder_voice_rooms: Vec::new(),498 builder_voice_rooms: Vec::new(),
496 voice_task: None,499 voice_task: None,
497 voice_samples: VecDeque::new(),500 voice_samples: VecDeque::new(),
501+ traffic: VecDeque::new(),
498 share_sample: ShareSample::default(),502 share_sample: ShareSample::default(),
499 share_loss: HashMap::new(),503 share_loss: HashMap::new(),
500 stats_open: false,504 stats_open: false,
505+ usage: None,
506+ usage_sampler: crate::usage::Sampler::default(),
501 ringing: HashSet::new(),507 ringing: HashSet::new(),
502 ring_task: None,508 ring_task: None,
503 typing: HashMap::new(),509 typing: HashMap::new(),
@@ -1163,6 +1169,7 @@ impl Chat {
1163 self.waves.clear();1169 self.waves.clear();
1164 self.voice_task = None;1170 self.voice_task = None;
1165 self.voice_samples.clear();1171 self.voice_samples.clear();
1172+ self.traffic.clear();
1166 self.share_sample = ShareSample::default();1173 self.share_sample = ShareSample::default();
1167 self.share_loss.clear();1174 self.share_loss.clear();
1168 }1175 }
@@ -1364,7 +1371,7 @@ impl Yumush {
1364 (self.chat.stats_open && self.in_stage_chat()).then(|| {1371 (self.chat.stats_open && self.in_stage_chat()).then(|| {
1365 div()1372 div()
1366 .id("stats_side")1373 .id("stats_side")
1367- .w(px(340.))1374+ .w(px(380.))
1368 .flex_shrink_0()1375 .flex_shrink_0()
1369 .p(px(10.))1376 .p(px(10.))
1370 .border_l_1()1377 .border_l_1()
@@ -2258,6 +2265,25 @@ impl Yumush {
2258 if yumush.chat.voice_community().is_none() {2265 if yumush.chat.voice_community().is_none() {
2259 return false;2266 return false;
2260 }2267 }
2268+ if let (Some(sample), Some(share)) = (&sample, &share) {
2269+ let up = sample.traffic.up_kbps
2270+ + share
2271+ .sending
2272+ .iter()
2273+ .map(|(_, layer)| layer.kbps as f32)
2274+ .sum::<f32>();
2275+ let down = sample.traffic.down_kbps
2276+ + share
2277+ .watching
2278+ .iter()
2279+ .map(|(_, _, stats)| stats.kbps as f32)
2280+ .sum::<f32>();
2281+ let traffic = &mut yumush.chat.traffic;
2282+ traffic.push_back((up, down));
2283+ while traffic.len() > SAMPLE_HISTORY {
2284+ traffic.pop_front();
2285+ }
2286+ }
2261 if let Some(sample) = sample {2287 if let Some(sample) = sample {
2262 let samples = &mut yumush.chat.voice_samples;2288 let samples = &mut yumush.chat.voice_samples;
2263 tracing::debug!(2289 tracing::debug!(
@@ -2278,6 +2304,9 @@ impl Yumush {
2278 yumush.chat.record_share(share);2304 yumush.chat.record_share(share);
2279 cx.notify();2305 cx.notify();
2280 }2306 }
2307+ if due && yumush.chat.stats_open {
2308+ yumush.chat.usage = yumush.chat.usage_sampler.sample();
2309+ }
2281 yumush.update_waves(levels, cx);2310 yumush.update_waves(levels, cx);
2282 true2311 true
2283 });2312 });
@@ -3069,7 +3098,11 @@ fn stats_button(entity: &Entity<Yumush>, palette: Palette, open: bool) -> impl I
3069 cx.notify();3098 cx.notify();
3070 }),3099 }),
3071 )3100 )
3072- .tip(if open { "Hide stats" } else { "Stats" })3101+ .tip(if open {
3102+ "Hide connection stats"
3103+ } else {
3104+ "Connection stats"
3105+ })
3073 .size(px(26.))3106 .size(px(26.))
3074 .flex()3107 .flex()
3075 .items_center()3108 .items_center()
crates/client/src/gui/dock.rsmodified+75 -60
@@ -5,13 +5,13 @@ use common::{
5 share::Kind,5 share::Kind,
6 };6 };
7 use gpui_kit::{7 use gpui_kit::{
8- App, Div, Entity, FontWeight, Hsla, IntoElement, ParentElement, Stateful, Styled, Window,8+ App, Div, Entity, FontWeight, Hsla, InteractiveElement, IntoElement, ParentElement, Stateful,
9- assets::IconName, component::Icon, div, px,9+ StatefulInteractiveElement, Styled, Window, assets::IconName, component::Icon, div, px,
10 };10 };
11 11
12 use super::{12 use super::{
13 Palette, Tooltip as _, Yumush, chat::VoiceState, clickable, community_name, entity_action,13 Palette, Tooltip as _, Yumush, chat::VoiceState, clickable, community_name, entity_action,
14- share_view::kind_icon, text, voice_stats, wave, widget::icon_button,14+ hoverable_with, share_view::kind_icon, text, voice_stats, wave, widget::icon_button,
15 };15 };
16 16
17 const PING_BARS: usize = 12;17 const PING_BARS: usize = 12;
@@ -89,7 +89,7 @@ impl Yumush {
89 .gap(px(7.))89 .gap(px(7.))
90 .child(90 .child(
91 clickable("dock_go", palette, go)91 clickable("dock_go", palette, go)
92- .tip("Go to call")92+ .tip("Go to channel")
93 .min_w_0()93 .min_w_0()
94 .truncate()94 .truncate()
95 .text_size(text(12.))95 .text_size(text(12.))
@@ -106,6 +106,8 @@ impl Yumush {
106 .child(div().flex_1())106 .child(div().flex_1())
107 .child(107 .child(
108 div()108 div()
109+ .id("dock_ping")
110+ .tip("Ping")
109 .flex_shrink_0()111 .flex_shrink_0()
110 .h(px(22.))112 .h(px(22.))
111 .px(px(7.))113 .px(px(7.))
@@ -134,7 +136,8 @@ impl Yumush {
134 }),136 }),
135 )137 )
136 .bg(palette.danger.opacity(0.13))138 .bg(palette.danger.opacity(0.13))
137- .text_color(palette.danger),139+ .text_color(palette.danger)
140+ .hover(|style| style.bg(palette.danger.opacity(0.22))),
138 )141 )
139 }142 }
140 143
@@ -151,8 +154,8 @@ impl Yumush {
151 } else {154 } else {
152 palette.ok155 palette.ok
153 };156 };
154- let mic_entity = entity.clone();
155 let deafen_entity = entity.clone();157 let deafen_entity = entity.clone();
158+ let mic_action = entity_action(entity, |yumush, window, cx| yumush.toggle_mute(window, cx));
156 let ghost = self.hidden_in_voice();159 let ghost = self.hidden_in_voice();
157 let mic_icon = if muted {160 let mic_icon = if muted {
158 IconName::MicOff161 IconName::MicOff
@@ -169,36 +172,38 @@ impl Yumush {
169 } else {172 } else {
170 IconName::Headphones173 IconName::Headphones
171 };174 };
172- let (deafen_bg, deafen_tone) = if deafened {175+ let (deafen_bg, deafen_tone, deafen_hover) = if deafened {
173- (palette.danger.opacity(0.13), palette.danger)176+ (
177+ palette.danger.opacity(0.13),
178+ palette.danger,
179+ palette.danger.opacity(0.22),
180+ )
174 } else {181 } else {
175- (palette.hover, palette.text)182+ (palette.hover, palette.text, palette.hover)
176 };183 };
177 184
178- let mic = icon_button(
179- format!("dock_mic_{muted}_{ghost}"),
180- palette,
181- mic_icon,
182- mic_tip,
183- move |window, cx| mic_entity.update(cx, |yumush, cx| yumush.toggle_mute(window, cx)),
184- )
185- .text_color(tone);
186 let voice = div()185 let voice = div()
187 .flex_1()186 .flex_1()
188 .flex()187 .flex()
189 .justify_center()188 .justify_center()
190 .child(wave::wave_slot(self.chat.waves.voice(me), 14., tone));189 .child(wave::wave_slot(self.chat.waves.voice(me), 14., tone));
191- let group = div()190+ let group = hoverable_with(
192- .flex_1()191+ "dock_mic",
193- .h(px(30.))192+ div()
194- .px(px(8.))193+ .flex_1()
195- .rounded(px(7.))194+ .h(px(30.))
196- .bg(tone.opacity(0.12))195+ .px(px(8.))
197- .flex()196+ .rounded(px(7.))
198- .items_center()197+ .bg(tone.opacity(0.12))
199- .gap(px(4.))198+ .flex()
200- .child(mic)199+ .items_center()
201- .child(voice);200+ .gap(px(4.)),
201+ tone.opacity(0.2),
202+ )
203+ .tip(mic_tip)
204+ .on_click(move |_, window, cx| mic_action(window, cx))
205+ .child(Icon::new(mic_icon).w(px(14.)).h(px(14.)).text_color(tone))
206+ .child(voice);
202 let deafen = icon_button(207 let deafen = icon_button(
203 format!("dock_deafen_{deafened}"),208 format!("dock_deafen_{deafened}"),
204 palette,209 palette,
@@ -210,7 +215,8 @@ impl Yumush {
210 .h(px(30.))215 .h(px(30.))
211 .rounded(px(7.))216 .rounded(px(7.))
212 .bg(deafen_bg)217 .bg(deafen_bg)
213- .text_color(deafen_tone);218+ .text_color(deafen_tone)
219+ .hover(move |style| style.bg(deafen_hover));
214 220
215 div()221 div()
216 .flex()222 .flex()
@@ -230,23 +236,26 @@ impl Yumush {
230 .collect();236 .collect();
231 if !off.is_empty() {237 if !off.is_empty() {
232 rows.push(238 rows.push(
233- div().flex().items_center().gap(px(4.)).children(239+ div()
234- off.into_iter()240+ .flex()
235- .map(|kind| start_button(entity, kind, palette)),241+ .items_center()
236- ),242+ .gap(px(4.))
243+ .children(off.into_iter().map(|kind| {
244+ div()
245+ .flex_1()
246+ .flex()
247+ .items_center()
248+ .gap(px(2.))
249+ .child(start_button(entity, kind, palette))
250+ .child(self.share_settings_button(entity, palette, kind))
251+ })),
237 );252 );
238 }253 }
239- if let Some(last) = rows.pop() {
240- rows.push(last.child(self.share_settings_button(entity, palette, Kind::Screen)));
241- }
242 div().flex().flex_col().gap(px(4.)).children(rows)254 div().flex().flex_col().gap(px(4.)).children(rows)
243 }255 }
244 256
245 fn device_row(&self, entity: &Entity<Self>, me: Id, kind: Kind, palette: Palette) -> Div {257 fn device_row(&self, entity: &Entity<Self>, me: Id, kind: Kind, palette: Palette) -> Div {
246- let tone = match kind {258+ let tone = tone(palette, kind);
247- Kind::Camera => palette.camera,
248- Kind::Screen => palette.screen,
249- };
250 let stop_tip = match kind {259 let stop_tip = match kind {
251 Kind::Camera => "Turn off camera",260 Kind::Camera => "Turn off camera",
252 Kind::Screen => "Stop sharing",261 Kind::Screen => "Stop sharing",
@@ -275,6 +284,8 @@ impl Yumush {
275 if let Some(history) = self.chat.waves.share(me).filter(|_| kind == Kind::Screen) {284 if let Some(history) = self.chat.waves.share(me).filter(|_| kind == Kind::Screen) {
276 row = row.child(285 row = row.child(
277 div()286 div()
287+ .id("dock_audio")
288+ .tip("Screen audio")
278 .h(px(20.))289 .h(px(20.))
279 .px(px(5.))290 .px(px(5.))
280 .rounded(px(5.))291 .rounded(px(5.))
@@ -291,35 +302,31 @@ impl Yumush {
291 .child(wave::mini_wave(history, 10., tone)),302 .child(wave::mini_wave(history, 10., tone)),
292 );303 );
293 }304 }
294- row.child(div().flex_1()).child(305+ row.child(div().flex_1())
295- icon_button(306+ .child(self.share_settings_button(entity, palette, kind))
296- format!("dock_stop_{kind:?}"),307+ .child(
297- palette,308+ icon_button(
298- IconName::X,309+ format!("dock_stop_{kind:?}"),
299- stop_tip,310+ palette,
300- toggle_action(entity, kind),311+ IconName::X,
312+ stop_tip,
313+ toggle_action(entity, kind),
314+ )
315+ .text_color(palette.danger),
301 )316 )
302- .text_color(palette.danger),
303- )
304 }317 }
305 318
306 fn mode_text(&self, kind: Kind) -> String {319 fn mode_text(&self, kind: Kind) -> String {
307- let best = self320+ let quality = self
308 .chat321 .chat
309 .share_sample322 .share_sample
310 .sending323 .sending
311 .iter()324 .iter()
312 .filter(|(sent, _)| *sent == kind)325 .filter(|(sent, _)| *sent == kind)
313- .map(|(_, stats)| stats)326+ .map(|(_, stats)| stats.layer.quality)
314- .max_by(|a, b| a.fps.total_cmp(&b.fps));327+ .max_by_key(|quality| quality.resolution.height())
315- match best {328+ .unwrap_or_else(|| self.settings.share.top(kind));
316- Some(stats) => format!(329+ format!("{}p{}", quality.resolution.height(), quality.fps.value())
317- "{}p{}",
318- stats.layer.quality.resolution.height(),
319- stats.layer.quality.fps.value()
320- ),
321- None => "…".to_string(),
322- }
323 }330 }
324 331
325 fn is_on(&self, kind: Kind) -> bool {332 fn is_on(&self, kind: Kind) -> bool {
@@ -342,6 +349,14 @@ fn start_button(entity: &Entity<Yumush>, kind: Kind, palette: Palette) -> Statef
342 .h(px(30.))349 .h(px(30.))
343 .rounded(px(7.))350 .rounded(px(7.))
344 .bg(palette.hover)351 .bg(palette.hover)
352+ .hover(move |style| style.bg(tone(palette, kind).opacity(0.2)))
353+}
354+
355+fn tone(palette: Palette, kind: Kind) -> Hsla {
356+ match kind {
357+ Kind::Camera => palette.camera,
358+ Kind::Screen => palette.screen,
359+ }
345 }360 }
346 361
347 fn toggle_action(entity: &Entity<Yumush>, kind: Kind) -> impl Fn(&mut Window, &mut App) + 'static {362 fn toggle_action(entity: &Entity<Yumush>, kind: Kind) -> impl Fn(&mut Window, &mut App) + 'static {
crates/client/src/gui/share_view.rsmodified+79 -37
@@ -1,5 +1,8 @@
1 use common::model::Id;1 use common::model::Id;
2-use std::{sync::Arc, time::Duration};2+use std::{
3+ sync::Arc,
4+ time::{Duration, Instant},
5+};
3 6
4 use common::share::{Codec, Fps, Kind, Quality, Resolution, Source, options};7 use common::share::{Codec, Fps, Kind, Quality, Resolution, Source, options};
5 8
@@ -31,6 +34,7 @@ use super::{
31 media_view::into_render_image,34 media_view::into_render_image,
32 notify_error, pop_in,35 notify_error, pop_in,
33 settings_page::segmented,36 settings_page::segmented,
37+ stream_stats::{quality_label, stream_card, watch_stats},
34 surface::Surface,38 surface::Surface,
35 text,39 text,
36 widget::{icon_button, spawn_warn},40 widget::{icon_button, spawn_warn},
@@ -44,6 +48,8 @@ use crate::{
44 },48 },
45 };49 };
46 50
51+const BAR_TTL: Duration = Duration::from_millis(2500);
52+
47 pub(super) const FRAME_TICK: Duration = Duration::from_millis(16);53 pub(super) const FRAME_TICK: Duration = Duration::from_millis(16);
48 const RESOLUTIONS: [(Resolution, &str); 6] = [54 const RESOLUTIONS: [(Resolution, &str); 6] = [
49 (Resolution::P360, "360"),55 (Resolution::P360, "360"),
@@ -93,6 +99,8 @@ pub(super) struct Viewer {
93 pub(super) fullscreen: bool,99 pub(super) fullscreen: bool,
94 volume: Entity<SliderState>,100 volume: Entity<SliderState>,
95 restore: f32,101 restore: f32,
102+ active: Instant,
103+ stats: bool,
96 _subscriptions: Vec<Subscription>,104 _subscriptions: Vec<Subscription>,
97 _tick: Task<()>,105 _tick: Task<()>,
98 }106 }
@@ -292,6 +300,8 @@ impl Yumush {
292 fullscreen: false,300 fullscreen: false,
293 volume,301 volume,
294 restore: FULL_VOLUME,302 restore: FULL_VOLUME,
303+ active: Instant::now(),
304+ stats: false,
295 _subscriptions: subscriptions,305 _subscriptions: subscriptions,
296 _tick: tick,306 _tick: tick,
297 });307 });
@@ -478,31 +488,9 @@ impl Yumush {
478 Kind::Screen => palette.screen,488 Kind::Screen => palette.screen,
479 Kind::Camera => palette.camera,489 Kind::Camera => palette.camera,
480 };490 };
481- let hud = self491+ let (user_id, kind) = (viewer.user_id, viewer.kind);
482- .chat492+ let stats = watch_stats(self, user_id, kind);
483- .share_sample493+ let bar = viewer.active.elapsed() < BAR_TTL;
484- .watching
485- .iter()
486- .find(|(user_id, kind, _)| *user_id == viewer.user_id && *kind == viewer.kind)
487- .map(|(_, _, stats)| {
488- let quality = stats.layer.as_ref().map_or("…".to_string(), |layer| {
489- format!(
490- "{}p{}",
491- layer.quality.resolution.height(),
492- layer.quality.fps.value()
493- )
494- });
495- let loss = if stats.loss * 100. > 0.5 {
496- format!(" · {:.1}% loss", stats.loss * 100.)
497- } else {
498- String::new()
499- };
500- format!(
501- "{quality} · {} · {:.0} fps{loss}",
502- super::voice_stats::rate(stats.kbps),
503- stats.fps
504- )
505- });
506 494
507 div()495 div()
508 .flex_1()496 .flex_1()
@@ -510,7 +498,20 @@ impl Yumush {
510 .relative()498 .relative()
511 .occlude()499 .occlude()
512 .bg(gpui_kit::black())500 .bg(gpui_kit::black())
513- .group("viewer")501+ .on_mouse_move({
502+ let entity = entity.clone();
503+ move |_, _, cx| {
504+ entity.update(cx, |yumush, cx| {
505+ if let Some(viewer) = yumush.chat.viewer.as_mut() {
506+ let hidden = viewer.active.elapsed() >= BAR_TTL;
507+ viewer.active = Instant::now();
508+ if hidden {
509+ cx.notify();
510+ }
511+ }
512+ })
513+ }
514+ })
514 .child(515 .child(
515 div()516 div()
516 .id("viewer_video")517 .id("viewer_video")
@@ -527,21 +528,63 @@ impl Yumush {
527 .left(px(10.))528 .left(px(10.))
528 .top(px(10.)),529 .top(px(10.)),
529 )530 )
530- .children(hud.map(|hud| {531+ .children(stats.map(|stats| {
532+ let entity = entity.clone();
531 div()533 div()
534+ .occlude()
532 .absolute()535 .absolute()
533 .right(px(10.))536 .right(px(10.))
534 .top(px(10.))537 .top(px(10.))
535- .h(px(24.))
536- .px(px(8.))
537 .flex()538 .flex()
538 .items_center()539 .items_center()
539- .rounded(px(12.))540+ .gap(px(6.))
540- .bg(gpui_kit::black().opacity(0.72))541+ .child(
541- .text_size(text(11.))542+ div()
542- .text_color(tone)543+ .h(px(22.))
543- .child(hud)544+ .px(px(8.))
545+ .flex()
546+ .items_center()
547+ .rounded(px(11.))
548+ .bg(gpui_kit::black().opacity(0.72))
549+ .text_size(text(11.))
550+ .text_color(tone)
551+ .child(quality_label(stats)),
552+ )
553+ .child(
554+ div()
555+ .id("viewer_stats_button")
556+ .tip("Stream stats")
557+ .size(px(26.))
558+ .flex()
559+ .flex_shrink_0()
560+ .items_center()
561+ .justify_center()
562+ .rounded(px(6.))
563+ .cursor_pointer()
564+ .bg(gpui_kit::black().opacity(0.72))
565+ .text_color(if viewer.stats { tone } else { palette.muted })
566+ .hover(|style| style.bg(palette.hover).text_color(palette.text))
567+ .on_click(move |_, _, cx| {
568+ entity.update(cx, |yumush, cx| {
569+ if let Some(viewer) = yumush.chat.viewer.as_mut() {
570+ viewer.stats = !viewer.stats;
571+ }
572+ cx.notify();
573+ })
574+ })
575+ .child(Icon::new(IconName::ChartBar).w(px(14.)).h(px(14.))),
576+ )
544 }))577 }))
578+ .when(viewer.stats, |this| {
579+ this.child(
580+ div()
581+ .occlude()
582+ .absolute()
583+ .right(px(10.))
584+ .top(px(42.))
585+ .child(stream_card(self, user_id, kind, palette)),
586+ )
587+ })
545 .child(588 .child(
546 div()589 div()
547 .absolute()590 .absolute()
@@ -551,8 +594,7 @@ impl Yumush {
551 .flex()594 .flex()
552 .justify_center()595 .justify_center()
553 .on_mouse_up(MouseButton::Left, |_, _, cx| cx.stop_propagation())596 .on_mouse_up(MouseButton::Left, |_, _, cx| cx.stop_propagation())
554- .opacity(0.)597+ .when(!bar, |this| this.opacity(0.))
555- .group_hover("viewer", |style| style.opacity(1.))
556 .child(598 .child(
557 div()599 div()
558 .h(px(38.))600 .h(px(38.))
crates/client/src/gui/sidebar.rsmodified+20 -2
@@ -144,6 +144,8 @@ impl Yumush {
144 let ids = self.chat.voice_ids(community_id);144 let ids = self.chat.voice_ids(community_id);
145 let wave = ids.iter().find_map(|id| self.chat.waves.voice(*id));145 let wave = ids.iter().find_map(|id| self.chat.waves.voice(*id));
146 div()146 div()
147+ .id(format!("voice_chip_{community_id}"))
148+ .tip("In call")
147 .h(px(18.))149 .h(px(18.))
148 .px(px(5.))150 .px(px(5.))
149 .flex()151 .flex()
@@ -251,12 +253,22 @@ impl Yumush {
251 entity,253 entity,
252 identity,254 identity,
253 )))255 )))
254- .children(camera.then(|| watch_pill(entity, user_id, Kind::Camera, None, palette)))256+ .children(camera.then(|| {
257+ watch_pill(
258+ entity,
259+ user_id,
260+ Kind::Camera,
261+ self.is_watching(user_id, Kind::Camera),
262+ None,
263+ palette,
264+ )
265+ }))
255 .children(screen.then(|| {266 .children(screen.then(|| {
256 watch_pill(267 watch_pill(
257 entity,268 entity,
258 user_id,269 user_id,
259 Kind::Screen,270 Kind::Screen,
271+ self.is_watching(user_id, Kind::Screen),
260 self.chat.waves.share(user_id),272 self.chat.waves.share(user_id),
261 palette,273 palette,
262 )274 )
@@ -849,6 +861,7 @@ fn watch_pill(
849 entity: &Entity<Yumush>,861 entity: &Entity<Yumush>,
850 user_id: Id,862 user_id: Id,
851 kind: Kind,863 kind: Kind,
864+ watching: bool,
852 wave: Option<&VecDeque<f32>>,865 wave: Option<&VecDeque<f32>>,
853 palette: Palette,866 palette: Palette,
854 ) -> impl IntoElement {867 ) -> impl IntoElement {
@@ -856,6 +869,11 @@ fn watch_pill(
856 Kind::Camera => (palette.camera, IconName::Video),869 Kind::Camera => (palette.camera, IconName::Video),
857 Kind::Screen => (palette.screen, IconName::ScreenShare),870 Kind::Screen => (palette.screen, IconName::ScreenShare),
858 };871 };
872+ let tip = match (watching, kind) {
873+ (true, _) => "Stop watching",
874+ (false, Kind::Camera) => "Watch camera",
875+ (false, Kind::Screen) => "Watch screen",
876+ };
859 clickable(877 clickable(
860 format!("voice_watch_{user_id}_{kind:?}"),878 format!("voice_watch_{user_id}_{kind:?}"),
861 palette,879 palette,
@@ -863,7 +881,7 @@ fn watch_pill(
863 yumush.toggle_viewer(user_id, kind, window, cx)881 yumush.toggle_viewer(user_id, kind, window, cx)
864 }),882 }),
865 )883 )
866- .tip("Watch")884+ .tip(tip)
867 .h(px(18.))885 .h(px(18.))
868 .px(px(5.))886 .px(px(5.))
869 .flex()887 .flex()
crates/client/src/gui/stream_stats.rsmodified+195 -0
@@ -1 +1,196 @@
1+use common::{model::Id, share::Kind};
2+use gpui_kit::{Div, FontWeight, Hsla, ParentElement, Styled, component::Icon, div, px};
1 3
4+use super::{Palette, Yumush, share_view::kind_icon, text, voice_stats::rate};
5+use crate::{media::decode::Engine, share::session::WatchStats};
6+
7+const GRAPH_HEIGHT: f32 = 48.;
8+const AXIS_WIDTH: f32 = 34.;
9+
10+pub(super) fn watch_stats(yumush: &Yumush, user_id: Id, kind: Kind) -> Option<&WatchStats> {
11+ yumush
12+ .chat
13+ .share_sample
14+ .watching
15+ .iter()
16+ .find(|(id, sent, _)| *id == user_id && *sent == kind)
17+ .map(|(_, _, stats)| stats)
18+}
19+
20+pub(super) fn quality_label(stats: &WatchStats) -> String {
21+ stats.layer.as_ref().map_or("…".to_string(), |layer| {
22+ format!("{}p{:.0}", layer.quality.resolution.height(), stats.fps)
23+ })
24+}
25+
26+pub(super) fn stream_card(yumush: &Yumush, user_id: Id, kind: Kind, palette: Palette) -> Div {
27+ let (tone, noun) = match kind {
28+ Kind::Screen => (palette.screen, "screen"),
29+ Kind::Camera => (palette.camera, "camera"),
30+ };
31+ let user = yumush
32+ .chat
33+ .author(user_id)
34+ .map_or("Someone", |user| user.username.as_str());
35+ let stats = watch_stats(yumush, user_id, kind);
36+ let losses: Vec<f32> = yumush
37+ .chat
38+ .share_loss
39+ .get(&(user_id, kind))
40+ .into_iter()
41+ .flatten()
42+ .copied()
43+ .collect();
44+ let value = |format: fn(&WatchStats) -> String| stats.map_or("…".to_string(), format);
45+
46+ div()
47+ .w(px(300.))
48+ .p(px(12.))
49+ .flex()
50+ .flex_col()
51+ .gap(px(12.))
52+ .text_size(text(12.))
53+ .rounded(px(10.))
54+ .border_1()
55+ .border_color(palette.border)
56+ .bg(palette.panel)
57+ .child(
58+ div()
59+ .flex()
60+ .items_center()
61+ .gap(px(6.))
62+ .child(
63+ Icon::new(kind_icon(kind))
64+ .w(px(14.))
65+ .h(px(14.))
66+ .flex_none()
67+ .text_color(tone),
68+ )
69+ .child(
70+ div()
71+ .font_weight(FontWeight::SEMIBOLD)
72+ .child(format!("{user}'s {noun}")),
73+ ),
74+ )
75+ .child(graph(&losses, tone, palette))
76+ .child(section(
77+ "Stream",
78+ vec![
79+ row(
80+ "Resolution",
81+ value(|stats| {
82+ stats.layer.as_ref().map_or("…".to_string(), |layer| {
83+ format!("{}p", layer.quality.resolution.height())
84+ })
85+ }),
86+ palette,
87+ ),
88+ row("FPS", value(|stats| format!("{:.0}", stats.fps)), palette),
89+ row(
90+ "Engine",
91+ value(|stats| {
92+ match stats.engine {
93+ Some(Engine::Hardware) => "HW",
94+ Some(Engine::Software) => "SW",
95+ None => "…",
96+ }
97+ .to_string()
98+ }),
99+ palette,
100+ ),
101+ row("Bitrate", value(|stats| rate(stats.kbps)), palette),
102+ ],
103+ palette,
104+ ))
105+ .child(section(
106+ "Network",
107+ vec![
108+ row(
109+ "Loss",
110+ value(|stats| format!("{:.1} %", stats.loss * 100.)),
111+ palette,
112+ ),
113+ row(
114+ "Buffer",
115+ value(|stats| format!("{} ms", stats.buffer_ms)),
116+ palette,
117+ ),
118+ row(
119+ "Latency",
120+ value(|stats| {
121+ stats
122+ .latency_ms
123+ .map_or("…".to_string(), |ms| format!("{ms} ms"))
124+ }),
125+ palette,
126+ ),
127+ row(
128+ "Keyframes",
129+ value(|stats| stats.keyframes.to_string()),
130+ palette,
131+ ),
132+ row("NACKs", value(|stats| stats.nacks.to_string()), palette),
133+ ],
134+ palette,
135+ ))
136+}
137+
138+fn graph(losses: &[f32], color: Hsla, palette: Palette) -> Div {
139+ let top = losses.iter().fold(1_f32, |top, loss| top.max(loss * 100.));
140+ let levels: Vec<f32> = losses.iter().map(|loss| loss * 100. / top).collect();
141+
142+ div()
143+ .flex()
144+ .gap(px(6.))
145+ .h(px(GRAPH_HEIGHT))
146+ .child(
147+ div()
148+ .w(px(AXIS_WIDTH))
149+ .h_full()
150+ .flex()
151+ .flex_col()
152+ .justify_between()
153+ .text_size(text(10.))
154+ .text_color(palette.muted)
155+ .children([top, top / 2., 0.].map(|value| div().child(format!("{value:.1}%")))),
156+ )
157+ .child(
158+ div()
159+ .flex_1()
160+ .h_full()
161+ .rounded(px(4.))
162+ .bg(palette.window)
163+ .child(super::wave::line(levels, color)),
164+ )
165+}
166+
167+fn section(title: &'static str, rows: Vec<Div>, palette: Palette) -> Div {
168+ div()
169+ .flex()
170+ .flex_col()
171+ .gap(px(4.))
172+ .child(
173+ div()
174+ .text_size(text(11.))
175+ .font_weight(FontWeight::SEMIBOLD)
176+ .text_color(palette.muted)
177+ .child(title),
178+ )
179+ .children(rows)
180+}
181+
182+fn row(key: &'static str, value: String, palette: Palette) -> Div {
183+ div()
184+ .flex()
185+ .items_center()
186+ .justify_between()
187+ .gap(px(8.))
188+ .text_size(text(11.))
189+ .child(div().text_color(palette.muted).child(key))
190+ .child(
191+ div()
192+ .font_family(super::MONO_FONT)
193+ .text_color(palette.text)
194+ .child(value),
195+ )
196+}
crates/client/src/gui/voice_stats.rsmodified+419 -195
@@ -6,18 +6,19 @@ use common::{
6 };6 };
7 use gpui_kit::{7 use gpui_kit::{
8 Div, FontWeight, Hsla, ParentElement, Styled, assets::IconName, component::Icon, div, hsla,8 Div, FontWeight, Hsla, ParentElement, Styled, assets::IconName, component::Icon, div, hsla,
9- prelude::FluentBuilder as _, px,9+ prelude::FluentBuilder as _, px, relative, rgb,
10 };10 };
11 11
12-use super::{Palette, chat::Chat, share_view::kind_icon, text};12+use super::{Palette, chat::Chat, share_view::kind_icon, text, wave};
13 use crate::media::decode::Engine;13 use crate::media::decode::Engine;
14 use crate::share::session::{LayerStats, WatchStats};14 use crate::share::session::{LayerStats, WatchStats};
15+use crate::usage::{Gpu, Usage};
15 use crate::voice::VoiceSample;16 use crate::voice::VoiceSample;
16 17
17 pub const SAMPLE_HISTORY: usize = 60;18 pub const SAMPLE_HISTORY: usize = 60;
18 const GRAPH_HEIGHT: f32 = 32.;19 const GRAPH_HEIGHT: f32 = 32.;
20+const MIRROR_HALF: f32 = 22.;
19 const PING_SCALE: f32 = 150.;21 const PING_SCALE: f32 = 150.;
20-const LOSS_SCALE: f32 = 10.;
21 const GOOD_LOSS: f32 = 2.;22 const GOOD_LOSS: f32 = 2.;
22 const FAIR_LOSS: f32 = 8.;23 const FAIR_LOSS: f32 = 8.;
23 24
@@ -51,6 +52,14 @@ impl Quality {
51 }52 }
52 }53 }
53 54
55+ fn word(self) -> &'static str {
56+ match self {
57+ Self::Good => "good",
58+ Self::Fair => "fair",
59+ Self::Poor => "poor",
60+ }
61+ }
62+
54 pub fn color(self, palette: Palette) -> Hsla {63 pub fn color(self, palette: Palette) -> Hsla {
55 match self {64 match self {
56 Self::Good => palette.ok,65 Self::Good => palette.ok,
@@ -69,61 +78,128 @@ pub fn stats_panel(chat: &Chat, palette: Palette) -> Div {
69 div()78 div()
70 .flex()79 .flex()
71 .flex_col()80 .flex_col()
72- .gap(px(10.))81+ .gap(px(16.))
73 .child(network_block(chat, palette))82 .child(network_block(chat, palette))
74 .children(sending_blocks(&share.sending, palette))83 .children(sending_blocks(&share.sending, palette))
75- .children(84+ .child(receiving_block(&share.watching, chat, palette))
76- share.watching.iter().map(|(user_id, kind, stats)| {85+ .children(chat.usage.map(|usage| usage_block(usage, palette)))
77- watching_block(*user_id, *kind, stats, chat, palette)
78- }),
79- )
80 }86 }
81 87
82 fn network_block(chat: &Chat, palette: Palette) -> Div {88 fn network_block(chat: &Chat, palette: Palette) -> Div {
83 let latest = chat.voice_samples.back();89 let latest = chat.voice_samples.back();
84- let value = |format: fn(&VoiceSample) -> String| latest.map_or("…".to_string(), format);
85 let color = latest.map_or(palette.ok, |sample| Quality::of(sample).color(palette));90 let color = latest.map_or(palette.ok, |sample| Quality::of(sample).color(palette));
86- block(91+ let word = latest.map_or("…", |sample| Quality::of(sample).word());
87- color,92+ let ping = latest.map_or("…".into(), |sample| format!("{:.0} ms", sample.ping_ms));
88- IconName::Activity,93+ let jitter = latest.map_or("…".into(), |sample| {
89- "Network",94+ format!("{:.0} ms", sample.traffic.jitter_ms)
90- value(|sample| format!("{:.0} ms", sample.ping_ms)),95+ });
91- )96+ let loss = latest.map_or("…".into(), |sample| {
92- .child(graph(97+ format!("{:.1} %", sample.traffic.loss * 100.)
93- "Ping",98+ });
94- chat.voice_samples99+ let buffer = latest.map_or("…".into(), |sample| {
95- .iter()100+ format!("{:.0} ms", sample.traffic.buffer_ms)
96- .map(|sample| {101+ });
97- (102+
98- sample.ping_ms / PING_SCALE,103+ div()
99- Quality::of(sample).color(palette),104+ .flex()
105+ .flex_col()
106+ .gap(px(8.))
107+ .child(header(IconName::Activity, "Network", color).child(chip(word, color)))
108+ .child(
109+ div()
110+ .flex()
111+ .gap(px(8.))
112+ .child(stat_cell("ping", ping, color, palette))
113+ .child(stat_cell("jitter", jitter, color, palette))
114+ .child(stat_cell("loss", loss, color, palette))
115+ .child(stat_cell("buffer", buffer, palette.text, palette)),
116+ )
117+ .child(
118+ div()
119+ .h(px(GRAPH_HEIGHT))
120+ .p(px(2.))
121+ .rounded(px(4.))
122+ .bg(palette.window)
123+ .child(wave::line(
124+ chat.voice_samples
125+ .iter()
126+ .map(|sample| (sample.ping_ms / PING_SCALE).clamp(0., 1.))
127+ .collect(),
128+ color,
129+ )),
130+ )
131+ .child(traffic(chat, palette))
132+}
133+
134+fn traffic(chat: &Chat, palette: Palette) -> Div {
135+ let up: Vec<f32> = chat.traffic.iter().map(|(up, _)| *up).collect();
136+ let down: Vec<f32> = chat.traffic.iter().map(|(_, down)| *down).collect();
137+ let up_latest = up.last().copied().unwrap_or_default();
138+ let down_latest = down.last().copied().unwrap_or_default();
139+ let max = up.iter().chain(&down).copied().fold(1., f32::max);
140+
141+ div()
142+ .flex()
143+ .flex_col()
144+ .gap(px(2.))
145+ .text_size(text(10.))
146+ .child(
147+ div()
148+ .text_color(up_color())
149+ .child(format!("↑ {}", rate(up_latest as u32))),
150+ )
151+ .child(
152+ div()
153+ .h(px(MIRROR_HALF * 2.))
154+ .flex()
155+ .flex_col()
156+ .child(
157+ div()
158+ .h(px(MIRROR_HALF))
159+ .flex()
160+ .items_end()
161+ .gap(px(1.))
162+ .children(bars(&up, max, up_color())),
100 )163 )
101- })164+ .child(div().h(px(1.)).bg(palette.border))
102- .collect(),165+ .child(
103- palette,166+ div()
104- ))167+ .h(px(MIRROR_HALF))
105- .child(row(168+ .flex()
106- "Jitter",169+ .items_start()
107- value(|sample| format!("{:.0} ms", sample.traffic.jitter_ms)),170+ .gap(px(1.))
108- palette.text,171+ .children(bars(&down, max, down_color())),
109- palette,172+ ),
110- ))173+ )
111- .child(row(174+ .child(
112- "Loss",175+ div()
113- value(|sample| format!("{:.1} %", sample.traffic.loss * 100.)),176+ .text_color(down_color())
114- palette.text,177+ .child(format!("↓ {}", rate(down_latest as u32))),
115- palette,178+ )
116- ))179+}
117- .child(row(180+
118- "Bitrate",181+fn bars(values: &[f32], max: f32, color: Hsla) -> Vec<Div> {
119- value(|sample| format!("{} kbps", sample.bitrate_kbps)),182+ let empty = SAMPLE_HISTORY.saturating_sub(values.len());
120- palette.text,183+ (0..empty)
121- palette,184+ .map(|_| div().flex_1())
122- ))185+ .chain(
186+ values
187+ .iter()
188+ .map(|value| div().flex_1().h(px(value / max * MIRROR_HALF)).bg(color)),
189+ )
190+ .collect()
191+}
192+
193+fn up_color() -> Hsla {
194+ rgb(0xa78bfa).into()
195+}
196+
197+fn down_color() -> Hsla {
198+ rgb(0x22d3ee).into()
123 }199 }
124 200
125 fn sending_blocks(sending: &[(Kind, LayerStats)], palette: Palette) -> Vec<Div> {201 fn sending_blocks(sending: &[(Kind, LayerStats)], palette: Palette) -> Vec<Div> {
126- [Kind::Camera, Kind::Screen]202+ [Kind::Screen, Kind::Camera]
127 .into_iter()203 .into_iter()
128 .filter_map(|kind| {204 .filter_map(|kind| {
129 let layers: Vec<&LayerStats> = sending205 let layers: Vec<&LayerStats> = sending
@@ -137,79 +213,223 @@ fn sending_blocks(sending: &[(Kind, LayerStats)], palette: Palette) -> Vec<Div>
137 }213 }
138 214
139 fn sending_block(kind: Kind, layers: &[&LayerStats], palette: Palette) -> Div {215 fn sending_block(kind: Kind, layers: &[&LayerStats], palette: Palette) -> Div {
140- let total: u32 = layers.iter().map(|stats| stats.kbps).sum();216+ let color = kind_color(kind, palette);
141- let mut panel = block(217+ let max = largest(layers.iter().map(|stats| stats.kbps));
142- kind_color(kind, palette),218+ let engine = layers
143- kind_icon(kind),219+ .last()
144- format!("{kind:?}"),220+ .map_or("…", |stats| engine_label(stats.engine));
145- rate(total),221+ div()
146- );222+ .flex()
147- for stats in layers {223+ .flex_col()
148- panel = panel.child(row(224+ .gap(px(6.))
149- layer_text(stats.layer, stats.engine),225+ .child(header(kind_icon(kind), kind_name(kind), color).child(label(engine, color)))
150- format!("{:.0} fps · {}", stats.fps, rate(stats.kbps)),226+ .children(
151- palette.text,227+ layers
152- palette,228+ .iter()
153- ));229+ .enumerate()
154- }230+ .rev()
155- panel231+ .map(|(index, stats)| layer_row(index, stats, max, kind, palette)),
232+ )
156 }233 }
157 234
158-fn watching_block(235+fn layer_row(index: usize, stats: &LayerStats, max: f32, kind: Kind, palette: Palette) -> Div {
159- user_id: Id,236+ let color = kind_color(kind, palette);
160- kind: Kind,237+ div()
161- stats: &WatchStats,238+ .flex()
162- chat: &Chat,239+ .items_center()
163- palette: Palette,240+ .gap(px(8.))
164-) -> Div {241+ .h(px(28.))
242+ .px(px(8.))
243+ .rounded(px(7.))
244+ .bg(color.opacity(0.08))
245+ .text_size(text(11.))
246+ .when(stats.kbps == 0, |this| this.opacity(0.45))
247+ .child(
248+ div()
249+ .w(px(22.))
250+ .flex_none()
251+ .font_weight(FontWeight::SEMIBOLD)
252+ .text_color(color)
253+ .child(format!("L{index}")),
254+ )
255+ .child(
256+ div()
257+ .w(px(70.))
258+ .flex_none()
259+ .text_color(palette.text)
260+ .child(resolution_text(stats.layer, stats.fps)),
261+ )
262+ .child(bar(stats.kbps as f32 / max, color, palette))
263+ .child(
264+ div()
265+ .w(px(52.))
266+ .flex_none()
267+ .text_right()
268+ .text_color(palette.text)
269+ .child(rate(stats.kbps)),
270+ )
271+}
272+
273+fn receiving_block(watching: &[(Id, Kind, WatchStats)], chat: &Chat, palette: Palette) -> Div {
274+ div()
275+ .flex()
276+ .flex_col()
277+ .gap(px(6.))
278+ .child(header(IconName::Eye, "Receiving", palette.text))
279+ .children(
280+ watching
281+ .iter()
282+ .map(|(user_id, kind, stats)| watch_row(chat, *user_id, *kind, stats, palette)),
283+ )
284+}
285+
286+fn watch_row(chat: &Chat, user_id: Id, kind: Kind, stats: &WatchStats, palette: Palette) -> Div {
165 let name = chat287 let name = chat
166 .author(user_id)288 .author(user_id)
167 .map_or_else(|| user_id.to_string(), |user| user.username.clone());289 .map_or_else(|| user_id.to_string(), |user| user.username.clone());
290+ let color = palette.tinted(user_id);
168 let loss = stats.loss * 100.;291 let loss = stats.loss * 100.;
169- let losses = chat292+ let loss_color = Quality::of_loss(loss).color(palette);
170- .share_loss293+ let latency = stats
171- .get(&(user_id, kind))294+ .latency_ms
172- .into_iter()295+ .map_or("…".to_string(), |ms| format!("{ms} ms"));
173- .flatten()296+ div()
174- .map(|loss| {297+ .flex()
175- (298+ .items_center()
176- loss * 100. / LOSS_SCALE,299+ .gap(px(4.))
177- Quality::of_loss(loss * 100.).color(palette),300+ .h(px(30.))
178- )301+ .px(px(6.))
179- })302+ .rounded(px(7.))
180- .collect();303+ .bg(kind_color(kind, palette).opacity(0.06))
181- block(304+ .text_size(text(11.))
182- kind_color(kind, palette),305+ .child(avatar_dot(&name, color))
183- kind_icon(kind),306+ .child(
184- name,307+ div()
185- rate(stats.kbps),308+ .flex_1()
186- )309+ .min_w_0()
187- .child(row("Layer", watch_layer_text(stats), palette.text, palette))310+ .truncate()
188- .child(row(311+ .font_weight(FontWeight::SEMIBOLD)
189- "FPS",312+ .text_color(color)
190- format!("{:.0}", stats.fps),313+ .child(name),
191- palette.text,314+ )
192- palette,315+ .child(
193- ))316+ Icon::new(kind_icon(kind))
194- .child(row(317+ .w(px(11.))
195- "Loss",318+ .h(px(11.))
196- format!("{loss:.1} %"),319+ .flex_none()
197- Quality::of_loss(loss).color(palette),320+ .text_color(kind_color(kind, palette)),
198- palette,321+ )
199- ))322+ .child(
200- .child(row(323+ div().w(px(64.)).flex_none().text_color(palette.text).child(
201- "Buffer",324+ stats
202- format!("{} ms", stats.buffer_ms),325+ .layer
203- palette.text,326+ .map_or("…".to_string(), |layer| resolution_text(layer, stats.fps)),
204- palette,327+ ),
205- ))328+ )
206- .child(row(329+ .child(
207- "Keyframes",330+ div()
208- stats.keyframes.to_string(),331+ .w(px(20.))
209- palette.text,332+ .flex_none()
333+ .text_color(palette.muted)
334+ .child(stats.engine.map_or("…", engine_label)),
335+ )
336+ .child(
337+ div()
338+ .w(px(44.))
339+ .flex_none()
340+ .text_right()
341+ .text_color(palette.text)
342+ .child(rate(stats.kbps)),
343+ )
344+ .child(
345+ div()
346+ .w(px(52.))
347+ .flex_none()
348+ .text_right()
349+ .text_color(palette.muted)
350+ .child(latency),
351+ )
352+ .child(chip(format!("{loss:.1}%"), loss_color))
353+}
354+
355+fn usage_block(usage: Usage, palette: Palette) -> Div {
356+ let cpu = div()
357+ .flex()
358+ .flex_col()
359+ .gap(px(6.))
360+ .flex_1()
361+ .min_w_0()
362+ .child(header(IconName::Cpu, "CPU", palette.text))
363+ .child(meter("total", usage.total, palette.text, palette))
364+ .child(meter("gui", usage.gui, palette.accent, palette))
365+ .child(meter("camera", usage.camera, palette.camera, palette))
366+ .child(meter("encode", usage.encode, palette.screen, palette))
367+ .child(meter("decode", usage.decode, palette.ok, palette));
368+ div()
369+ .flex()
370+ .gap(px(20.))
371+ .child(cpu)
372+ .children(usage.gpu.map(|gpu| gpu_column(gpu, palette)))
373+}
374+
375+fn gpu_column(gpu: Gpu, palette: Palette) -> Div {
376+ div()
377+ .flex()
378+ .flex_col()
379+ .gap(px(6.))
380+ .flex_1()
381+ .min_w_0()
382+ .child(header(IconName::MemoryStick, "GPU", palette.text))
383+ .child(meter("3d", gpu.gfx, palette.accent, palette))
384+ .child(meter("encode", gpu.encode, palette.screen, palette))
385+ .child(meter("decode", gpu.decode, palette.ok, palette))
386+ .child(meter_value(
387+ "vram",
388+ format!("{} MB", gpu.vram_mb),
389+ 0.,
390+ palette.muted,
391+ palette,
392+ ))
393+}
394+
395+fn meter(label: &'static str, percent: f32, color: Hsla, palette: Palette) -> Div {
396+ meter_value(
397+ label,
398+ format!("{percent:.1} %"),
399+ percent / 100.,
400+ color,
210 palette,401 palette,
211- ))402+ )
212- .child(graph("Loss", losses, palette))403+}
404+
405+fn meter_value(
406+ label: &'static str,
407+ value: String,
408+ fraction: f32,
409+ color: Hsla,
410+ palette: Palette,
411+) -> Div {
412+ div()
413+ .flex()
414+ .items_center()
415+ .gap(px(6.))
416+ .text_size(text(11.))
417+ .child(
418+ div()
419+ .w(px(46.))
420+ .flex_none()
421+ .text_color(palette.muted)
422+ .child(label),
423+ )
424+ .child(bar(fraction, color, palette))
425+ .child(
426+ div()
427+ .w(px(56.))
428+ .flex_none()
429+ .text_right()
430+ .text_color(palette.text)
431+ .child(value),
432+ )
213 }433 }
214 434
215 fn kind_color(kind: Kind, palette: Palette) -> Hsla {435 fn kind_color(kind: Kind, palette: Palette) -> Hsla {
@@ -219,6 +439,17 @@ fn kind_color(kind: Kind, palette: Palette) -> Hsla {
219 }439 }
220 }440 }
221 441
442+fn kind_name(kind: Kind) -> &'static str {
443+ match kind {
444+ Kind::Camera => "Camera",
445+ Kind::Screen => "Screen",
446+ }
447+}
448+
449+fn largest(values: impl Iterator<Item = u32>) -> f32 {
450+ values.max().unwrap_or(0).max(1) as f32
451+}
452+
222 pub fn rate(kbps: u32) -> String {453 pub fn rate(kbps: u32) -> String {
223 match kbps {454 match kbps {
224 0..1000 => format!("{kbps} kb"),455 0..1000 => format!("{kbps} kb"),
@@ -226,113 +457,106 @@ pub fn rate(kbps: u32) -> String {
226 }457 }
227 }458 }
228 459
229-fn layer_text(layer: Layer, engine: Engine) -> String {460+fn engine_label(engine: Engine) -> &'static str {
461+ match engine {
462+ Engine::Hardware => "HW",
463+ Engine::Software => "SW",
464+ }
465+}
466+
467+fn resolution_text(layer: Layer, fps: f32) -> String {
230 format!(468 format!(
231- "{}p{} · {}",469+ "{}p{}",
232 layer.quality.resolution.height(),470 layer.quality.resolution.height(),
233- layer.quality.fps.value(),471+ fps.round() as u32
234- match engine {
235- Engine::Hardware => "HW",
236- Engine::Software => "SW",
237- }
238 )472 )
239 }473 }
240 474
241-fn watch_layer_text(stats: &WatchStats) -> String {475+fn header(icon: IconName, title: &'static str, color: Hsla) -> Div {
242- match (stats.layer, stats.engine) {
243- (Some(layer), Some(engine)) => layer_text(layer, engine),
244- _ => "…".to_string(),
245- }
246-}
247-
248-fn block(
249- color: Hsla,
250- icon: IconName,
251- title: impl gpui_kit::IntoElement,
252- summary: impl gpui_kit::IntoElement,
253-) -> Div {
254 div()476 div()
255- .rounded(px(10.))
256- .p(px(8.))
257- .bg(color.opacity(0.07))
258 .flex()477 .flex()
259- .flex_col()478+ .items_center()
260- .gap(px(4.))479+ .gap(px(7.))
480+ .child(
481+ Icon::new(icon)
482+ .w(px(13.))
483+ .h(px(13.))
484+ .flex_none()
485+ .text_color(color),
486+ )
261 .child(487 .child(
262 div()488 div()
263- .flex()489+ .font_weight(FontWeight::SEMIBOLD)
264- .items_center()490+ .text_size(text(12.))
265- .gap(px(6.))491+ .text_color(color)
266- .child(492+ .child(title),
267- Icon::new(icon)
268- .w(px(14.))
269- .h(px(14.))
270- .flex_none()
271- .text_color(color),
272- )
273- .child(
274- div()
275- .flex_1()
276- .font_weight(FontWeight::SEMIBOLD)
277- .text_size(text(12.))
278- .text_color(color)
279- .child(title),
280- )
281- .child(
282- div()
283- .flex_none()
284- .text_size(text(11.))
285- .text_color(color)
286- .child(summary),
287- ),
288 )493 )
494+ .child(div().flex_1())
289 }495 }
290 496
291-fn row(497+fn label(value: &'static str, color: Hsla) -> Div {
292- label: impl gpui_kit::IntoElement,498+ div().text_size(text(11.)).text_color(color).child(value)
293- value: impl gpui_kit::IntoElement,
294- value_color: Hsla,
295- palette: Palette,
296-) -> Div {
297- div()
298- .flex()
299- .items_center()
300- .justify_between()
301- .gap(px(6.))
302- .text_size(text(11.))
303- .child(div().text_color(palette.muted).child(label))
304- .child(div().text_color(value_color).child(value))
305 }499 }
306 500
307-fn graph(label: &'static str, bars: Vec<(f32, Hsla)>, palette: Palette) -> Div {501+fn chip(value: impl gpui_kit::IntoElement, color: Hsla) -> Div {
308- let empty = SAMPLE_HISTORY.saturating_sub(bars.len());502+ div()
309- let empty_bars = bars.is_empty();503+ .flex_none()
310- let bars = bars.into_iter().map(|(level, color)| {504+ .px(px(6.))
311- let height = level.clamp(0.04, 1.) * GRAPH_HEIGHT;505+ .py(px(1.))
312- div().flex_1().h(px(height)).rounded_t(px(1.)).bg(color)506+ .rounded(px(5.))
313- });507+ .bg(color.opacity(0.13))
508+ .text_size(text(10.))
509+ .text_color(color)
510+ .child(value)
511+}
314 512
513+fn stat_cell(label: &'static str, value: String, color: Hsla, palette: Palette) -> Div {
315 div()514 div()
515+ .flex_1()
516+ .min_w_0()
316 .flex()517 .flex()
317 .flex_col()518 .flex_col()
318- .gap(px(4.))519+ .gap(px(2.))
319 .child(520 .child(
320 div()521 div()
321 .text_size(text(10.))522 .text_size(text(10.))
322 .text_color(palette.muted)523 .text_color(palette.muted)
323 .child(label),524 .child(label),
324 )525 )
526+ .child(div().text_size(text(14.)).text_color(color).child(value))
527+}
528+
529+fn avatar_dot(name: &str, color: Hsla) -> Div {
530+ let initial = name
531+ .chars()
532+ .next()
533+ .map_or('?', |letter| letter.to_ascii_uppercase());
534+ div()
535+ .size(px(18.))
536+ .flex_none()
537+ .rounded_full()
538+ .flex()
539+ .items_center()
540+ .justify_center()
541+ .bg(color)
542+ .text_size(text(9.))
543+ .font_weight(FontWeight::BOLD)
544+ .text_color(hsla(0., 0., 0.07, 1.))
545+ .child(initial.to_string())
546+}
547+
548+fn bar(fraction: f32, color: Hsla, palette: Palette) -> Div {
549+ div()
550+ .flex_1()
551+ .min_w_0()
552+ .h(px(4.))
553+ .rounded_full()
554+ .bg(palette.border)
325 .child(555 .child(
326 div()556 div()
327- .h(px(GRAPH_HEIGHT))557+ .h_full()
328- .p(px(2.))558+ .w(relative(fraction.clamp(0., 1.)))
329- .flex()559+ .rounded_full()
330- .items_end()560+ .bg(color),
331- .gap(px(1.))
332- .rounded(px(4.))
333- .bg(palette.window)
334- .children((0..empty).map(|_| div().flex_1()))
335- .children(bars)
336- .when(empty_bars, |this| this.opacity(0.5)),
337 )561 )
338 }562 }
crates/client/src/gui/wave.rsmodified+29 -1
@@ -1,7 +1,11 @@
1 use std::collections::{HashMap, HashSet, VecDeque};1 use std::collections::{HashMap, HashSet, VecDeque};
2 2
3 use common::model::Id;3 use common::model::Id;
4-use gpui_kit::{Div, Hsla, ParentElement, Styled, div, px};4+use gpui_kit::{
5+ Div, Hsla, IntoElement, ParentElement, PathBuilder, Styled, canvas, div, point, px,
6+};
7+
8+use super::voice_stats::SAMPLE_HISTORY;
5 9
6 use crate::net::Levels;10 use crate::net::Levels;
7 11
@@ -137,3 +141,27 @@ fn wave(bars: &[f32], size: f32, color: Hsla) -> Div {
137 .bg(color)141 .bg(color)
138 }))142 }))
139 }143 }
144+
145+pub fn line(levels: Vec<f32>, color: Hsla) -> impl IntoElement {
146+ canvas(
147+ |_, _, _| {},
148+ move |bounds, _, window, _| {
149+ let first = SAMPLE_HISTORY.saturating_sub(levels.len());
150+ let mut path = PathBuilder::stroke(px(1.5));
151+ for (index, &level) in levels.iter().enumerate() {
152+ let step = (first + index) as f32 / (SAMPLE_HISTORY - 1) as f32;
153+ let x = bounds.origin.x + bounds.size.width * step;
154+ let y = bounds.origin.y + bounds.size.height * (1. - level);
155+ if index == 0 {
156+ path.move_to(point(x, y));
157+ } else {
158+ path.line_to(point(x, y));
159+ }
160+ }
161+ if let Ok(path) = path.build() {
162+ window.paint_path(path, color);
163+ }
164+ },
165+ )
166+ .size_full()
167+}
crates/client/src/usage.rsmodified+197 -0
@@ -1 +1,198 @@
1+#[derive(Clone, Copy, Default)]
2+pub struct Usage {
3+ pub total: f32,
4+ pub gui: f32,
5+ pub camera: f32,
6+ pub encode: f32,
7+ pub decode: f32,
8+ pub gpu: Option<Gpu>,
9+}
1 10
11+#[derive(Clone, Copy, Default)]
12+pub struct Gpu {
13+ pub gfx: f32,
14+ pub encode: f32,
15+ pub decode: f32,
16+ pub vram_mb: u32,
17+}
18+
19+#[cfg(target_os = "linux")]
20+pub use linux::Sampler;
21+
22+#[cfg(not(target_os = "linux"))]
23+#[derive(Default)]
24+pub struct Sampler;
25+
26+#[cfg(not(target_os = "linux"))]
27+impl Sampler {
28+ pub fn sample(&mut self) -> Option<Usage> {
29+ None
30+ }
31+}
32+
33+#[cfg(target_os = "linux")]
34+mod linux {
35+ use std::{collections::HashMap, fs, time::Instant};
36+
37+ use super::{Gpu, Usage};
38+
39+ #[derive(Clone, Copy, Default)]
40+ struct Ticks {
41+ total: u64,
42+ gui: u64,
43+ camera: u64,
44+ encode: u64,
45+ decode: u64,
46+ }
47+
48+ #[derive(Clone, Copy, Default)]
49+ struct Engines {
50+ gfx: u64,
51+ encode: u64,
52+ decode: u64,
53+ vram_kib: u64,
54+ }
55+
56+ #[derive(Clone, Copy)]
57+ struct Snapshot {
58+ at: Instant,
59+ ticks: Ticks,
60+ gpu: Option<Engines>,
61+ }
62+
63+ #[derive(Default)]
64+ pub struct Sampler {
65+ previous: Option<Snapshot>,
66+ }
67+
68+ impl Sampler {
69+ pub fn sample(&mut self) -> Option<Usage> {
70+ let current = Snapshot::read()?;
71+ let previous = self.previous.replace(current)?;
72+ let wall = current.at.duration_since(previous.at);
73+ let seconds = wall.as_secs_f32().max(f32::EPSILON);
74+ let nanos = (wall.as_nanos() as f32).max(1.);
75+ let cpu = |now: u64, before: u64| now.saturating_sub(before) as f32 / seconds;
76+ let (now, then) = (current.ticks, previous.ticks);
77+ Some(Usage {
78+ total: cpu(now.total, then.total),
79+ gui: cpu(now.gui, then.gui),
80+ camera: cpu(now.camera, then.camera),
81+ encode: cpu(now.encode, then.encode),
82+ decode: cpu(now.decode, then.decode),
83+ gpu: current.gpu.map(|gpu| {
84+ let before = previous.gpu.unwrap_or(gpu);
85+ let share =
86+ |now: u64, then: u64| now.saturating_sub(then) as f32 / nanos * 100.;
87+ Gpu {
88+ gfx: share(gpu.gfx, before.gfx),
89+ encode: share(gpu.encode, before.encode),
90+ decode: share(gpu.decode, before.decode),
91+ vram_mb: (gpu.vram_kib / 1024) as u32,
92+ }
93+ }),
94+ })
95+ }
96+ }
97+
98+ impl Snapshot {
99+ fn read() -> Option<Self> {
100+ let ticks = Ticks::read()?;
101+ Some(Self {
102+ at: Instant::now(),
103+ ticks,
104+ gpu: read_gpu(),
105+ })
106+ }
107+ }
108+
109+ impl Ticks {
110+ fn read() -> Option<Self> {
111+ let pid = std::process::id().to_string();
112+ let mut ticks = Self {
113+ total: stat_ticks(&fs::read_to_string("/proc/self/stat").ok()?)?,
114+ ..Self::default()
115+ };
116+ for entry in fs::read_dir("/proc/self/task").ok()?.flatten() {
117+ let path = entry.path();
118+ let Ok(name) = fs::read_to_string(path.join("comm")) else {
119+ continue;
120+ };
121+ let Some(used) = fs::read_to_string(path.join("stat"))
122+ .ok()
123+ .and_then(|stat| stat_ticks(&stat))
124+ else {
125+ continue;
126+ };
127+ let main = entry.file_name().to_str() == Some(pid.as_str());
128+ let name = name.trim();
129+ if main {
130+ ticks.gui += used;
131+ } else if name.starts_with("camera") || name.starts_with("share-capture") {
132+ ticks.camera += used;
133+ } else if name == "share-encode" {
134+ ticks.encode += used;
135+ } else if name == "media-decode" || name.contains("video") {
136+ ticks.decode += used;
137+ }
138+ }
139+ Some(ticks)
140+ }
141+ }
142+
143+ fn stat_ticks(stat: &str) -> Option<u64> {
144+ let rest = stat.get(stat.rfind(')')? + 1..)?;
145+ let fields: Vec<&str> = rest.split_whitespace().collect();
146+ let utime: u64 = fields.get(11)?.parse().ok()?;
147+ let stime: u64 = fields.get(12)?.parse().ok()?;
148+ Some(utime + stime)
149+ }
150+
151+ fn read_gpu() -> Option<Engines> {
152+ let mut clients: HashMap<String, Engines> = HashMap::new();
153+ for entry in fs::read_dir("/proc/self/fdinfo").ok()?.flatten() {
154+ let Ok(info) = fs::read_to_string(entry.path()) else {
155+ continue;
156+ };
157+ let mut engines = Engines::default();
158+ let mut client = None;
159+ let mut drm = false;
160+ for line in info.lines().filter(|line| line.starts_with("drm-")) {
161+ drm = true;
162+ let Some((key, value)) = line.split_once(':') else {
163+ continue;
164+ };
165+ let Some(number) = value
166+ .split_whitespace()
167+ .next()
168+ .and_then(|value| value.parse::<u64>().ok())
169+ else {
170+ continue;
171+ };
172+ match key {
173+ "drm-client-id" => client = Some(number),
174+ "drm-engine-gfx" => engines.gfx = number,
175+ "drm-engine-enc" => engines.encode = number,
176+ "drm-engine-dec" => engines.decode = number,
177+ "drm-memory-vram" => engines.vram_kib = number,
178+ _ => {}
179+ }
180+ }
181+ if drm {
182+ let key =
183+ client.map_or_else(|| entry.path().display().to_string(), |id| id.to_string());
184+ clients.insert(key, engines);
185+ }
186+ }
187+ (!clients.is_empty()).then(|| {
188+ clients
189+ .values()
190+ .fold(Engines::default(), |sum, engines| Engines {
191+ gfx: sum.gfx + engines.gfx,
192+ encode: sum.encode + engines.encode,
193+ decode: sum.decode + engines.decode,
194+ vram_kib: sum.vram_kib + engines.vram_kib,
195+ })
196+ })
197+ }
198+}