forge
Explore
Log in

Don't you dare go Hollow

Drop mic/speaker popovers

Browse files at this commit

397f10bc21e00ed39f3bdfe74f9e1d76bec5968bAhmet Kaan GümüşParent: 31ab094
  • style
    • drop mic/speaker popovers
    • spectrum without high tilt and floor -48 dB so quiet highs stay flat, half the strokes
    • voice and share lines split the bar equally
    • ping has a fixed slot so the bar stops moving
  • feat
    • ping history line next to the ping
Show full message
🎨 style: drop mic/speaker popovers; spectrum without high tilt and floor -48 dB so quiet highs stay flat, half the strokes; voice and share lines split the bar equally; ping has a fixed slot so the bar stops moving; ✨ feat: ping history line next to the ping
crates/client/src/gui/call_bar.rsmodified+42 -21
@@ -18,7 +18,7 @@ pub struct CallBar {
18 pub place: SharedString,18 pub place: SharedString,
19 pub bands: Option<VecDeque<f32>>,19 pub bands: Option<VecDeque<f32>>,
20 pub voice: Voice,20 pub voice: Voice,
21- pub ping: Option<f32>,21+ pub pings: Vec<f32>,
22 pub muted: bool,22 pub muted: bool,
23 pub deafened: bool,23 pub deafened: bool,
24 pub camera: bool,24 pub camera: bool,
@@ -36,8 +36,6 @@ pub struct CallActions {
36 pub screen: Action,36 pub screen: Action,
37 pub leave: Action,37 pub leave: Action,
38 pub stats: Action,38 pub stats: Action,
39- pub mic_more: AnyElement,
40- pub speaker_more: AnyElement,
41 pub camera_more: AnyElement,39 pub camera_more: AnyElement,
42 pub screen_more: AnyElement,40 pub screen_more: AnyElement,
43 }41 }
@@ -57,8 +55,14 @@ pub fn view(bar: CallBar, actions: CallActions, t: Tokens) -> Div {
57 } else {55 } else {
58 Ink::Faint56 Ink::Faint
59 };57 };
58+ let pings = bar
59+ .pings
60+ .iter()
61+ .map(|ping| (ping / super::voice_stats::PING_SCALE).clamp(0., 1.))
62+ .collect();
60 let ping = bar63 let ping = bar
61- .ping64+ .pings
65+ .last()
62 .map_or_else(|| "–".to_string(), |ping| format!("{ping:.0} ms"));66 .map_or_else(|| "–".to_string(), |ping| format!("{ping:.0} ms"));
63 let stats = run(&actions.stats);67 let stats = run(&actions.stats);
64 let controls = band(space::XS)68 let controls = band(space::XS)
@@ -75,7 +79,6 @@ pub fn view(bar: CallBar, actions: CallActions, t: Tokens) -> Div {
75 t,79 t,
76 run(&actions.mute),80 run(&actions.mute),
77 ))81 ))
78- .child(actions.mic_more)
79 .child(icon_button(82 .child(icon_button(
80 format!("bar_deafen_{}", bar.deafened),83 format!("bar_deafen_{}", bar.deafened),
81 if bar.deafened {84 if bar.deafened {
@@ -88,7 +91,6 @@ pub fn view(bar: CallBar, actions: CallActions, t: Tokens) -> Div {
88 t,91 t,
89 run(&actions.deafen),92 run(&actions.deafen),
90 ))93 ))
91- .child(actions.speaker_more)
92 .when(!bar.ghost, |row| {94 .when(!bar.ghost, |row| {
93 row.child(icon_button(95 row.child(icon_button(
94 format!("bar_camera_{}", bar.camera),96 format!("bar_camera_{}", bar.camera),
@@ -173,16 +175,33 @@ pub fn view(bar: CallBar, actions: CallActions, t: Tokens) -> Div {
173 )175 )
174 .child(176 .child(
175 div()177 div()
176- .id("bar_ping")
177- .tip("Connection stats")
178- .cursor_pointer()
179 .flex_none()178 .flex_none()
180- .when(bar.stats, |ping| {179+ .w(px(size::ROW))
181- ping.border_b(px(super::style::stroke::LINE))180+ .h(px(size::ICON))
182- .border_color(t.paper())181+ .child(super::parts::spark(
183- })182+ pings,
184- .on_click(move |_, window, cx| stats(window, cx))183+ super::voice_stats::SAMPLE_HISTORY,
185- .child(words(ping, Text::Label, ping_ink, t)),184+ ping_ink.color(t),
185+ )),
186+ )
187+ .child(
188+ div()
189+ .flex_none()
190+ .w(px(size::ROW))
191+ .flex()
192+ .justify_end()
193+ .child(
194+ div()
195+ .id("bar_ping")
196+ .tip("Connection stats")
197+ .cursor_pointer()
198+ .when(bar.stats, |ping| {
199+ ping.border_b(px(super::style::stroke::LINE))
200+ .border_color(t.paper())
201+ })
202+ .on_click(move |_, window, cx| stats(window, cx))
203+ .child(words(ping, Text::Label, ping_ink, t)),
204+ ),
186 )205 )
187 .child(controls),206 .child(controls),
188 )207 )
@@ -190,15 +209,17 @@ pub fn view(bar: CallBar, actions: CallActions, t: Tokens) -> Div {
190 209
191 pub fn share_meter(bands: Option<&VecDeque<f32>>, color: gpui_kit::Hsla, t: Tokens) -> Div {210 pub fn share_meter(bands: Option<&VecDeque<f32>>, color: gpui_kit::Hsla, t: Tokens) -> Div {
192 band(space::XS)211 band(space::XS)
193- .flex_none()212+ .flex_1()
213+ .min_w(px(size::CONTROL))
194 .child(214 .child(
195 gpui_kit::component::Icon::new(IconName::ScreenShare)215 gpui_kit::component::Icon::new(IconName::ScreenShare)
196 .size(px(size::ICON_SM))216 .size(px(size::ICON_SM))
197 .text_color(t.faint()),217 .text_color(t.faint()),
198 )218 )
199- .child(div().w(px(size::THUMB)).h(px(size::ICON)).child(voice_line(219+ .child(
200- bands,220+ div()
201- Voice::Live(color),221+ .flex_1()
202- t,222+ .h(px(size::ICON))
203- )))223+ .child(voice_line(bands, Voice::Live(color), t)),
224+ )
204 }225 }
crates/client/src/gui/dock.rsmodified+7 -7
@@ -40,7 +40,13 @@ impl Yumush {
40 place: super::community_name(community).to_string().into(),40 place: super::community_name(community).to_string().into(),
41 bands: self.chat.waves.voice(me).cloned(),41 bands: self.chat.waves.voice(me).cloned(),
42 voice,42 voice,
43- ping: self.chat.stats.voice.back().map(|sample| sample.ping_ms),43+ pings: self
44+ .chat
45+ .stats
46+ .voice
47+ .iter()
48+ .map(|sample| sample.ping_ms)
49+ .collect(),
44 muted,50 muted,
45 deafened,51 deafened,
46 camera: self.network.share_source(Kind::Camera).is_some(),52 camera: self.network.share_source(Kind::Camera).is_some(),
@@ -78,12 +84,6 @@ impl Yumush {
78 yumush.toggle_stats(super::chat::StatsAt::Dock);84 yumush.toggle_stats(super::chat::StatsAt::Dock);
79 cx.notify();85 cx.notify();
80 })),86 })),
81- mic_more: self
82- .audio_button(entity, palette, super::voice_settings::Side::Input, cx)
83- .into_any_element(),
84- speaker_more: self
85- .audio_button(entity, palette, super::voice_settings::Side::Output, cx)
86- .into_any_element(),
87 camera_more: self87 camera_more: self
88 .share_settings_button(entity, palette, Kind::Camera, cx)88 .share_settings_button(entity, palette, Kind::Camera, cx)
89 .into_any_element(),89 .into_any_element(),
crates/client/src/gui/gallery.rsmodified+4 -6
@@ -325,10 +325,10 @@ fn call_page(state: State, t: Tokens) -> impl IntoElement {
325 State::Empty => Voice::Quiet,325 State::Empty => Voice::Quiet,
326 _ => Voice::Live(t.hue(Hue::Amber)),326 _ => Voice::Live(t.hue(Hue::Amber)),
327 },327 },
328- ping: match state {328+ pings: match state {
329- State::Empty => None,329+ State::Empty => Vec::new(),
330- State::Bad => Some(212.),330+ State::Bad => vec![40., 90., 160., 212.],
331- _ => Some(24.),331+ _ => vec![22., 30., 24., 26., 24.],
332 },332 },
333 muted: bad,333 muted: bad,
334 deafened: false,334 deafened: false,
@@ -347,8 +347,6 @@ fn call_page(state: State, t: Tokens) -> impl IntoElement {
347 screen: none(),347 screen: none(),
348 leave: none(),348 leave: none(),
349 stats: none(),349 stats: none(),
350- mic_more: super::parts::chevron_face(false, t).into_any_element(),
351- speaker_more: super::parts::chevron_face(false, t).into_any_element(),
352 camera_more: super::parts::chevron_face(false, t).into_any_element(),350 camera_more: super::parts::chevron_face(false, t).into_any_element(),
353 screen_more: super::parts::chevron_face(false, t).into_any_element(),351 screen_more: super::parts::chevron_face(false, t).into_any_element(),
354 };352 };
crates/client/src/gui/parts.rsmodified+2 -2
@@ -41,7 +41,7 @@ pub enum Ink {
41 }41 }
42 42
43 impl Ink {43 impl Ink {
44- fn color(self, t: Tokens) -> Hsla {44+ pub fn color(self, t: Tokens) -> Hsla {
45 match self {45 match self {
46 Ink::Paper => t.paper(),46 Ink::Paper => t.paper(),
47 Ink::Dim => t.dim(),47 Ink::Dim => t.dim(),
@@ -368,7 +368,7 @@ pub enum Voice {
368 368
369 const STILL: f32 = 0.02;369 const STILL: f32 = 0.02;
370 const EDGE: f32 = 16.;370 const EDGE: f32 = 16.;
371-const PEAK_SPACING: f32 = 5.;371+const PEAK_SPACING: f32 = 10.;
372 const MIN_PEAKS: usize = 6;372 const MIN_PEAKS: usize = 6;
373 373
374 pub fn voice_line(bands: Option<&VecDeque<f32>>, voice: Voice, t: Tokens) -> AnyElement {374 pub fn voice_line(bands: Option<&VecDeque<f32>>, voice: Voice, t: Tokens) -> AnyElement {
crates/client/src/gui/voice_settings.rsmodified+5 -58
@@ -1,14 +1,13 @@
1 use std::time::Duration;1 use std::time::Duration;
2 2
3 use gpui_kit::{3 use gpui_kit::{
4- Anchor, App, AppContext, Context, Div, Entity, InteractiveElement, IntoElement, KeyDownEvent,4+ App, AppContext, Context, Div, Entity, IntoElement, KeyDownEvent, KeyUpEvent, Keystroke,
5- KeyUpEvent, Keystroke, ModifiersChangedEvent, MouseButton, ParentElement, SharedString,5+ ModifiersChangedEvent, ParentElement, SharedString, Stateful, Styled, Subscription, Task,
6- Stateful, Styled, Subscription, Task, Window,6+ Window,
7 assets::IconName,7 assets::IconName,
8 component::{8 component::{
9 Icon, IndexPath,9 Icon, IndexPath,
10 kbd::Kbd,10 kbd::Kbd,
11- popover::Popover,
12 searchable_list::{SearchableListItem, SearchableVec},11 searchable_list::{SearchableListItem, SearchableVec},
13 select::{Select, SelectEvent, SelectState},12 select::{Select, SelectEvent, SelectState},
14 slider::{SliderEvent, SliderState},13 slider::{SliderEvent, SliderState},
@@ -17,7 +16,7 @@ use gpui_kit::{
17 };16 };
18 17
19 use super::{18 use super::{
20- Palette, Tooltip as _, Trigger, Yumush, clickable,19+ Palette, Yumush, clickable,
21 settings_page::{row, segmented},20 settings_page::{row, segmented},
22 style::{radius, size, space},21 style::{radius, size, space},
23 };22 };
@@ -517,7 +516,7 @@ impl Yumush {
517 }));516 }));
518 }517 }
519 518
520- pub(super) fn load_audio_devices(&self, window: &mut Window, cx: &mut Context<Self>) {519+ fn load_audio_devices(&self, window: &mut Window, cx: &mut Context<Self>) {
521 cx.spawn_in(window, async move |this, cx| {520 cx.spawn_in(window, async move |this, cx| {
522 let devices = cx521 let devices = cx
523 .background_executor()522 .background_executor()
@@ -560,55 +559,3 @@ fn test_button(
560 .font_weight(gpui_kit::FontWeight::MEDIUM)559 .font_weight(gpui_kit::FontWeight::MEDIUM)
561 .text_color(if active { palette.text } else { palette.muted })560 .text_color(if active { palette.text } else { palette.muted })
562 }561 }
563-
564-impl Yumush {
565- pub(super) fn audio_button(
566- &self,
567- entity: &Entity<Self>,
568- palette: Palette,
569- side: Side,
570- cx: &App,
571- ) -> impl IntoElement {
572- let (id, button, tip) = match side {
573- Side::Input => ("mic_settings", "mic_settings_button", "Microphone"),
574- Side::Output => ("speaker_settings", "speaker_settings_button", "Speaker"),
575- };
576- let refresh = entity.clone();
577- let content = entity.clone();
578- Popover::new(id)
579- .anchor(Anchor::BottomRight)
580- .appearance(false)
581- .trigger(Trigger::new(
582- super::parts::chevron_face(false, super::style::Tokens::of(cx))
583- .id(button)
584- .on_mouse_down(MouseButton::Left, move |_, window, cx| {
585- refresh.update(cx, |yumush, cx| yumush.load_audio_devices(window, cx));
586- })
587- .tip(tip),
588- ))
589- .content(move |_, _, cx| audio_card(content.read(cx), side, palette))
590- }
591-}
592-
593-fn audio_card(yumush: &Yumush, side: Side, palette: Palette) -> Div {
594- let voice = &yumush.settings.voice;
595- let controls = &yumush.voice;
596- let (devices, volume, value) = match side {
597- Side::Input => (&controls.inputs, &controls.input_volume, voice.input_volume),
598- Side::Output => (
599- &controls.outputs,
600- &controls.output_volume,
601- voice.output_volume,
602- ),
603- };
604- div()
605- .w(px(size::POPOVER))
606- .p(px(space::MD))
607- .flex()
608- .flex_col()
609- .gap(px(space::MD))
610- .rounded(px(radius::LG))
611- .bg(palette.field)
612- .child(Select::new(devices).appearance(false).w_full())
613- .child(volume_control(volume, value, palette))
614-}
crates/client/src/gui/voice_stats.rsmodified+1 -1
@@ -24,7 +24,7 @@ pub const SAMPLE_HISTORY: usize = 60;
24 const LABEL_W: f32 = size::ROW * 2.;24 const LABEL_W: f32 = size::ROW * 2.;
25 const VALUE_W: f32 = size::THUMB;25 const VALUE_W: f32 = size::THUMB;
26 const COLUMN_W: f32 = size::TALK + size::ROW * 2.;26 const COLUMN_W: f32 = size::TALK + size::ROW * 2.;
27-const PING_SCALE: f32 = 150.;27+pub const PING_SCALE: f32 = 150.;
28 pub(super) const GOOD_LOSS: f32 = 2.;28 pub(super) const GOOD_LOSS: f32 = 2.;
29 const FAIR_LOSS: f32 = 8.;29 const FAIR_LOSS: f32 = 8.;
30 30
crates/spectrum/src/lib.rsmodified+3 -14
@@ -7,9 +7,7 @@ pub const BANDS: usize = 32;
7 pub const WINDOW: usize = 2048;7 pub const WINDOW: usize = 2048;
8 const LOW_HZ: f32 = 60.0;8 const LOW_HZ: f32 = 60.0;
9 const HIGH_HZ: f32 = 12000.0;9 const HIGH_HZ: f32 = 12000.0;
10-const TILT_DB_PER_OCTAVE: f32 = 3.0;10+const FLOOR_DB: f32 = -48.0;
11-const TILT_PIVOT_HZ: f32 = 1000.0;
12-const FLOOR_DB: f32 = -60.0;
13 const CEIL_DB: f32 = -12.0;11 const CEIL_DB: f32 = -12.0;
14 12
15 pub struct Analyzer {13 pub struct Analyzer {
@@ -17,7 +15,6 @@ pub struct Analyzer {
17 hann: Vec<f32>,15 hann: Vec<f32>,
18 gain: f32,16 gain: f32,
19 edges: Vec<usize>,17 edges: Vec<usize>,
20- tilts: Vec<f32>,
21 }18 }
22 19
23 impl Analyzer {20 impl Analyzer {
@@ -33,14 +30,7 @@ impl Analyzer {
33 let previous = edges.last().map_or(0, |edge| edge + 1);30 let previous = edges.last().map_or(0, |edge| edge + 1);
34 edges.push(bin(hz).max(previous).min(WINDOW / 2));31 edges.push(bin(hz).max(previous).min(WINDOW / 2));
35 }32 }
36- let tilts = (0..BANDS)
37- .map(|band| {
38- let hz = LOW_HZ * (HIGH_HZ / LOW_HZ).powf((band as f32 + 0.5) / BANDS as f32);
39- TILT_DB_PER_OCTAVE * (hz / TILT_PIVOT_HZ).log2()
40- })
41- .collect();
42 Self {33 Self {
43- tilts,
44 fft: FftPlanner::new().plan_fft_forward(WINDOW),34 fft: FftPlanner::new().plan_fft_forward(WINDOW),
45 hann,35 hann,
46 gain,36 gain,
@@ -58,13 +48,12 @@ impl Analyzer {
58 self.fft.process(&mut buffer);48 self.fft.process(&mut buffer);
59 self.edges49 self.edges
60 .windows(2)50 .windows(2)
61- .zip(&self.tilts)51+ .map(|edge| {
62- .map(|(edge, tilt)| {
63 let peak = buffer[edge[0]..edge[1].max(edge[0] + 1)]52 let peak = buffer[edge[0]..edge[1].max(edge[0] + 1)]
64 .iter()53 .iter()
65 .map(|value| value.norm() * self.gain)54 .map(|value| value.norm() * self.gain)
66 .fold(0.0, f32::max);55 .fold(0.0, f32::max);
67- let db = 20.0 * peak.max(1e-6).log10() + tilt;56+ let db = 20.0 * peak.max(1e-6).log10();
68 ((db - FLOOR_DB) / (CEIL_DB - FLOOR_DB)).clamp(0.0, 1.0)57 ((db - FLOOR_DB) / (CEIL_DB - FLOOR_DB)).clamp(0.0, 1.0)
69 })58 })
70 .collect()59 .collect()