diff --git a/CHANGELOG.md b/CHANGELOG.md index b7139bc..3400fe6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,8 +45,9 @@ User-visible changes of the apps and the `tsgw` gateway. The format follows same, and what is folded and selected is kept for each server (setting `ui.tree`). The panel on the right lists everyone on the server in sections, with a search; a click on a person opens their card. A person who starts or - stops talking redraws the members panel and nothing else of the window (the - tree does not mark who talks), and the pictures the engine writes again show + stops talking is marked in the tree (the ring on their avatar and the bars on + their row, as in the Slint app) and the members panel, which are redrawn for + it and nothing else of the window, and the pictures the engine writes again show at once. `VOELIN_METER=1` counts the renders of each pane; `VOELIN_DEMO_SERVER` and `VOELIN_DEMO_TALK` pick the sample server and make a sample person talk (docs/ui.md, "The channel tree and the members"). diff --git a/crates/voelin-gpui/src/shell/channels.rs b/crates/voelin-gpui/src/shell/channels.rs index 61832ba..013c150 100644 --- a/crates/voelin-gpui/src/shell/channels.rs +++ b/crates/voelin-gpui/src/shell/channels.rs @@ -29,7 +29,7 @@ use super::actions::{ EditChannel, JoinChannel, MoveClient, OpenClient, OpenMember, SelectChannel, ToggleChannel, }; use super::tree_model::{Emptiness, TreeEvent, TreeModel, debug_check}; -use super::widgets::{Avatar, banner_scrim, icon, live_badge, small_picture}; +use super::widgets::{Avatar, banner_scrim, icon, live_badge, small_picture, speaking_bars}; use crate::meter::Counters; use crate::pictures::{PictureKey, picture}; use crate::theme::{VoelinTheme, hsla}; @@ -336,7 +336,8 @@ fn client_row(theme: &VoelinTheme, item: &TreeItem) -> AnyElement { .gap(px(m.space_3)) .child( Avatar::new(("tree-avatar", id), 22.0, &item.initials, item.tint) - .image(item.avatar.clone()), + .image(item.avatar.clone()) + .speaking(item.talking), ) .child( div() @@ -355,6 +356,16 @@ fn client_row(theme: &VoelinTheme, item: &TreeItem) -> AnyElement { .filter_map(|badge| small_picture(badge, 14.0)), ), ) + // The Slint bars move; these stand still (nothing here draws the window + // anew with the clock). + .when(item.talking, |row| { + row.child( + div() + .debug_selector(move || format!("tree-speaking-{id}")) + .flex_none() + .child(speaking_bars(theme, 14.0)), + ) + }) .when(item.streaming, |row| row.child(live_badge(theme))) .when(item.local_muted, |row| row.child(mark("volume-x", c.warning))) .when(!item.local_muted && item.local_volume != 100, |row| { diff --git a/crates/voelin-gpui/src/shell/members.rs b/crates/voelin-gpui/src/shell/members.rs index d91032b..4b77a1c 100644 --- a/crates/voelin-gpui/src/shell/members.rs +++ b/crates/voelin-gpui/src/shell/members.rs @@ -5,9 +5,9 @@ //! //! [`MembersPane`] is a cached pane over a virtual list that follows //! [`TreeModel`] as the tree does ([`TreeEvent::People`]: the row operations -//! the list applies). It is the pane a talker redraws: a person's row has the -//! speaking ring, "Speaking" and the bars, and nothing else of the window is -//! told. [`MemberCardView`] is the card, a card over the window with a scrim +//! the list applies). A talker redraws it, with the tree: a person's row has +//! the speaking ring, "Speaking" and the bars, and no other pane of the window +//! is told. [`MemberCardView`] is the card, a card over the window with a scrim //! that a click outside closes; its buttons (the volume, a message, a poke, //! friends, blocking) come with the slices that have those dialogs. diff --git a/crates/voelin-gpui/src/shell/tree_model.rs b/crates/voelin-gpui/src/shell/tree_model.rs index 826af69..d841a8e 100644 --- a/crates/voelin-gpui/src/shell/tree_model.rs +++ b/crates/voelin-gpui/src/shell/tree_model.rs @@ -11,11 +11,11 @@ //! inserted, not a list that starts again at the top. A change that moves none //! of what a pane shows emits nothing. //! -//! **The tree does not mark who is talking.** Its rows are built with -//! `talking` cleared: a talker changes the rows of the members panel (and the -//! sidebar's own card), not the tree's, which therefore is not drawn again -//! with every start and stop of someone's voice. The Slint tree draws speaking -//! bars on the row; docs/ui.md records the difference. +//! **The tree marks who is talking**, as the Slint tree does (the ring on the +//! avatar and the speaking bars on the row): someone who starts or stops +//! talking changes one row of the tree and one of the members panel, so each +//! of the two panes is drawn again once for it, and no other pane is +//! (docs/ui.md, "What a change costs"). use std::sync::Arc; @@ -124,13 +124,10 @@ impl Snapshot { fn of(app: &AppState) -> Self { let vm = &app.vm; let view = vm.current.and_then(|id| vm.sessions.get(&id)); - let (mut rows, people, total) = match logic::tree_view(vm, false) { + let (rows, people, total) = match logic::tree_view(vm, false) { Some(tree) => (tree.rows, tree.server_members, tree.member_total), None => (Vec::new(), Vec::new(), 0), }; - for row in &mut rows { - row.talking = false; - } Self { rows, people, diff --git a/crates/voelin-gpui/src/view.rs b/crates/voelin-gpui/src/view.rs index e69e3a4..a8014ec 100644 --- a/crates/voelin-gpui/src/view.rs +++ b/crates/voelin-gpui/src/view.rs @@ -975,7 +975,8 @@ mod tests { /// The sample server's channels and people are the rows of the tree, in /// the Slint tree's order and nesting, with its spacers, the locked - /// channel and the counts, each on screen; none of them marks a talker. + /// channel and the counts, each on screen; Kairo, who talks as the sample + /// starts, is marked. #[gpui::test] fn a_server_with_channels_and_people_fills_the_tree_with_its_rows(cx: &mut TestAppContext) { let (shell, cx) = open(cx, Backend::in_memory().unwrap(), Switches::default()); @@ -1012,7 +1013,8 @@ mod tests { assert_eq!((channel("Gaming").spacer, channel("Staff").spacer), (2, 3), "centred, right"); assert_eq!(rows.iter().find(|r| r.spacer == 4).map(|r| r.is_channel), Some(true)); assert!(channel("Officers").locked && !channel("Lobby").locked); - assert!(rows.iter().all(|r| !r.talking), "Kairo talks; the tree does not say so"); + let talking: Vec<&str> = rows.iter().filter(|r| r.talking).map(|r| &*r.name).collect(); + assert_eq!(talking, ["Kairo"], "Kairo talks, and the tree says so"); assert!(at(cx, "tree-empty").is_none()); for row in rows.iter() { let selector = if row.is_channel { @@ -1338,26 +1340,41 @@ mod tests { assert!(at(cx, "tree-empty").is_some(), "the tree says it is loading"); } - /// Who talks changes the members panel and the sidebar's own card, not the - /// tree: its pane is not drawn for a talker, and its rows stay as they - /// were. + /// Who talks is marked on the tree's row, as the Slint tree marks it (the + /// ring on the avatar, the bars on the row): each start and stop changes + /// exactly that person's row, the tree pane is drawn once for it, and the + /// row says so on screen. #[gpui::test] - fn a_talker_does_not_draw_the_tree_again(cx: &mut TestAppContext) { + fn a_talker_changes_one_row_and_draws_the_tree_once(cx: &mut TestAppContext) { let (shell, cx) = open(cx, Backend::in_memory().unwrap(), Switches::default()); sample_server(&shell, cx); - let rows = tree_rows(&shell, cx); + let kairo = |shell: &Shell, cx: &mut VisualTestContext| { + shell.view.read_with(cx, |view, cx| { + let tree = view.channel_tree().read(cx); + tree.rows().iter().position(|r| !r.is_channel && r.id == 3).unwrap() + }) + }; + let place = kairo(&shell, cx); + assert!(tree_rows(&shell, cx)[place].talking, "Kairo talks as the sample starts"); let (log, _subscription) = tree_events(&shell, cx); let drawn = |shell: &Shell| shell.counters.panes.tree.get(); - let before = drawn(&shell); for talking in [false, true, false, true] { + let before = drawn(&shell); + log.borrow_mut().clear(); let event = Event::Talking { session: sample::DEMO as u64, client: 3, talking }; shell.events.send(event).unwrap(); frame(cx); + let told = rows_told(&log); + let [(changes, carried)] = &told[..] else { panic!("{:?}", log.borrow()) }; + assert_eq!(*changes, Changes(vec![Change::Update(place)]), "only Kairo's row"); + assert_eq!(carried[place].talking, talking); + assert_eq!(drawn(&shell), before + 1, "the tree pane was drawn once"); + let pane = shell + .view + .read_with(cx, |view, cx| view.channel_tree().read(cx).rows()[place].talking); + assert_eq!(pane, talking, "the pane has it"); + assert_eq!(at(cx, "tree-speaking-3").is_some(), talking, "and the bars are on screen"); } - assert!(rows_told(&log).is_empty(), "the model told the tree nothing: {:?}", log.borrow()); - assert_eq!(log.borrow().len(), 4, "and the members panel four times"); - assert_eq!(drawn(&shell), before, "the tree pane was not rendered"); - assert_eq!(tree_rows(&shell, cx), rows); assert!( shell.app.read_with(cx, |app, _| app.vm.sessions[&sample::DEMO].talking.contains(&3)) ); @@ -1426,11 +1443,11 @@ mod tests { assert_eq!(shell.app.read_with(cx, |app, _| app.vm.member_filter.clone()), ""); } - /// Someone who starts or stops talking redraws the members panel and no - /// other pane: not the tree, the rail, the top bar nor the main area. The + /// Someone who starts or stops talking redraws the members panel and the + /// tree and no other pane: not the rail, the top bar nor the main area. The /// row says so while they talk. #[gpui::test] - fn a_talker_redraws_the_members_panel_and_no_other_pane(cx: &mut TestAppContext) { + fn a_talker_redraws_the_tree_and_the_members_panel_and_no_other_pane(cx: &mut TestAppContext) { let (shell, cx) = open(cx, Backend::in_memory().unwrap(), Switches::default()); sample_server(&shell, cx); let panes = &shell.counters.panes; @@ -1453,10 +1470,11 @@ mod tests { } let after = seen(); assert!(after[4] > before[4], "the members panel was drawn: {before:?} -> {after:?}"); + assert!(after[2] > before[2], "and the tree: {before:?} -> {after:?}"); assert_eq!( - [after[0], after[1], after[2], after[3]], - [before[0], before[1], before[2], before[3]], - "the rail, the top bar, the tree and the main area were not" + [after[0], after[1], after[3]], + [before[0], before[1], before[3]], + "the rail, the top bar and the main area were not" ); } diff --git a/docs/ui.md b/docs/ui.md index c2a095f..05273f2 100644 --- a/docs/ui.md +++ b/docs/ui.md @@ -1053,8 +1053,8 @@ crates/voelin-gpui/ not told), the channel tree and the members panel on the sample server's events (the rows, folds kept in the settings and found by the next run, a double-click that joins, the password prompt, a move and a mute as their - exact row operations, a talker that redraws the members panel and no other - pane, the member card, an avatar written again), a connect through a real + exact row operations, a talker that redraws the tree and the members panel + and no other pane, the member card, an avatar written again), a connect through a real engine that has no connector (it answers that none serves the address, which reaches the status line), the store on a directory of its own, the theme (it reaches gpui-component, follows the window's @@ -1508,12 +1508,18 @@ the tests: scroll stays where it was) and to the rows it has, and keeps the rows the event carries, not the model's at the moment it hears of them; a change that moves none of the rows of a pane emits nothing to it. -- **The tree carries no `talking`.** Its rows are built with the flag cleared, - so someone who starts or stops talking changes the members panel (and the - sidebar's own card when it is us) and not the tree: its pane is not rendered - (the `a_talker_does_not_draw_the_tree_again` test counts it). The Slint tree - draws speaking bars on the row, which would redraw the tree with every start - and stop of someone's voice; this front end leaves them to the members panel. +- **The tree marks who talks, and is drawn once for each start and stop.** Its + rows keep `talking`, so the avatar has the green ring and the row the three + speaking bars, as `channels.slint` draws them (the bars stand still: nothing + here draws the window with the clock). Someone who starts or stops talking + changes one row of the tree and one of the members panel, and each of those + two panes is rendered once for it, with the sidebar, which every frame + renders; no other pane is (the `a_talker_changes_one_row_and_draws_the_tree_once` + and `a_talker_redraws_the_tree_and_the_members_panel_and_no_other_pane` tests + count it). The first version of the slice cleared the flag to keep the tree out + of it; the gate ruled for parity with the Slint tree, and the cost was + measured: 9.97 renders of the tree a second for 9.97 starts and stops a second + ([what a change costs](#what-a-change-costs)). #### What a change costs @@ -1535,20 +1541,18 @@ window's frames, and each pane's passes): A window nobody touches is not drawn, with the tree and the panel on screen as before (the shell alone was 192.7 MiB; the pictures and the two panes' state are the difference, not itemized). Someone who talks is one engine event and so -one frame: the members panel is the only pane that is rendered for it, and the -sidebar, which every frame renders (its cards are small and have no size of -their own to cache at); the rail, the top bar, the main area and the tree are -not rendered at all in the 570 events of the run. GPUI's own thread spends 5 % +one frame: the members panel was the only pane that was rendered for it (the +tree carried no `talking` then; the figures of the talking marks are below), +and the sidebar, which every frame renders (its cards are small and have no size +of their own to cache at); the rail, the top bar, the main area and the tree +were not rendered at all in the 570 events of the run. GPUI's own thread spends 5 % of a core on the 9.7 frames a second (the first run, of the `aa640cf` tree on a quieter machine, 3.4 % at 10.0 frames, with `llvmpipe` at 100.9 % and 105.4 % in all; the loaded machine starved the process of a frame in ten). The rest is the software device: `llvmpipe` draws the whole 1440 by 960 window again for every frame, about 90 ms of CPU a frame on this machine, which a GPU does; so the figure that says what a talker costs the app is the thread's, and -the one that says what a window nobody touches costs is the idle row. (The -Slint tree draws speaking bars on its rows; with them the tree pane would be -rendered for each of those frames too, which is why this one does not: not -measured.) +the one that says what a window nobody touches costs is the idle row. **Again after the review's fixes** (the banner veil, one letter on small avatars and the password prompt change what a row draws, not when a pane is rendered): @@ -1559,6 +1563,23 @@ person talking 10 times a second: 106.4 % (111 %) in all, `llvmpipe` 102.3 %, GPUI's thread 3.1 %, 225.9 MiB, 10.0 frames a second, rendered per second 0, 0, 10.0, 0, 0, 10.0 (the sidebar and the members panel only, as above). +**Again with the talking marks on the tree** (the speaking ring and bars on the +tree's rows, which the gate's ruling restored; they make the tree pane change +with every start and stop): the talking run on the release build of the commit +that restored them, lavapipe (Mesa 26.2.5, `llvmpipe (LLVM 21.1.8, 256 bits)` +through Vulkan) on Xvfb `:231` of 3840 by 2160 with openbox, 1440 by 960, the +state under the checkout's `.scratch/`, the machine at a load average of 83 at +the start and 41 at the end, 60 samples after the first 15 of 75. A sample person +talking 10 times a second (`VOELIN_DEMO_TALK=10`): 102.2 % (112 %) in all, +`llvmpipe` 95.6 %, GPUI's thread 5.0 % (8 % at most), 224.0 MiB, 9.97 engine +events and 9.97 window frames a second, rendered per second 0, 0, 9.97, 9.97, 0, +9.97 (rail, top bar, sidebar, tree, main, members): the tree pane is rendered +once for each start and stop, as the members panel is, and the rail, the top bar +and the main area not at all. The tree's pane costs no measurable CPU on top: the +thread's 5.0 % is the figure of the first run (5.0 %) and above the second's +(3.1 %), a spread the load of the machine makes, and `llvmpipe` draws the whole +window for a frame whichever pane asked for it. + **Seen against a server** (the TeamSpeak 3 development server of `dev/docker-compose.yml`, 3.13.8, release build of the tree committed as `aa640cf` (built just before that commit, whose own changes to the tests came @@ -1634,7 +1655,7 @@ seventh standing in for the chat. The callbacks are GPUI actions | Slint property (used by) | Here | |---|---| -| `tree` (`channels.slint`) | `TreeModel::rows`, the `talking` flag cleared | +| `tree` (`channels.slint`) | `TreeModel::rows` | | `server_members` (`members.slint`) | `TreeModel::people` | | `member_total` (`members.slint`) | `TreeModel::total` ("Members — N") | | `member_card` (`members.slint`) | `TreeModel::card` (`voelin_ui_vm::tree::member_card`), shown by `MemberCardView` | @@ -1650,7 +1671,7 @@ seventh standing in for the chat. The callbacks are GPUI actions dialog) are the other server callbacks of the Bridge that these panes will meet later; neither file uses them. -What differs from the Slint tree and panel, beside the tree's talkers above: +What differs from the Slint tree and panel: the speaking bars stand still (nothing here may draw the window with the clock); the lists scroll with the wheel and have no scrollbar; a click on a channel selects it where Slint opens its chat; the card has no buttons; the members