From a6caffa5797299d96c8f017a8b94c10798d31459 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 8 Oct 2026 13:06:15 +0000 Subject: [PATCH] ui: streams pop out into a window of their own Pop out now opens ViewerWindow: the player alone, titled with the stream, which a pin keeps on top of other windows (always-on-top). The main window goes on; the stream's card on the voice page says it plays in its own window, with Bring back; closing the window brings it back too, on the stream's server, and Leave closes it. Pictures go only to the window that shows the player, so none is scaled twice; full screen and the cursor follow that window. The stream callbacks take a Bridge, the models attach to any Bridge, the theme is copied to every window of its own, and one main-window close handler, installed at start, closes the studio's and the stream's windows (the studio installed its own before). Desktop only. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AVRENKftQqGoEeswiR9TDQ --- CHANGELOG.md | 3 + crates/voelin-ui/src/app.rs | 51 ++++-- crates/voelin-ui/src/appearance.rs | 22 ++- crates/voelin-ui/src/bind/mod.rs | 6 +- crates/voelin-ui/src/bind/streams.rs | 20 +-- crates/voelin-ui/src/dev.rs | 31 ++-- crates/voelin-ui/src/lib.rs | 1 + crates/voelin-ui/src/popout.rs | 140 +++++++++++++++ crates/voelin-ui/src/servers.rs | 5 +- crates/voelin-ui/src/streams.rs | 169 +++++++++++------- crates/voelin-ui/src/studio.rs | 32 +--- crates/voelin-ui/ui/app.slint | 5 +- crates/voelin-ui/ui/bridge.slint | 10 +- crates/voelin-ui/ui/screens/streams.slint | 41 +++-- crates/voelin-ui/ui/screens/voice-parts.slint | 32 +++- crates/voelin-ui/ui/viewer-window.slint | 52 ++++++ docs/ui.md | 20 ++- 17 files changed, 468 insertions(+), 172 deletions(-) create mode 100644 crates/voelin-ui/src/popout.rs create mode 100644 crates/voelin-ui/ui/viewer-window.slint diff --git a/CHANGELOG.md b/CHANGELOG.md index 30dac05..91488bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -78,6 +78,9 @@ User-visible changes of the apps and the `tsgw` gateway. The format follows - A theatre mode for streams: the stream viewer's new button fills the window with the stream and its chat, without the servers, the channels and the members. Escape leaves it, and full screen too. +- Streams pop out into a window of their own on the desktop, optionally + kept on top of other windows, while the main window goes on; closing it + brings the stream back. ### Changed diff --git a/crates/voelin-ui/src/app.rs b/crates/voelin-ui/src/app.rs index 2cbe19b..2d32d5b 100644 --- a/crates/voelin-ui/src/app.rs +++ b/crates/voelin-ui/src/app.rs @@ -542,26 +542,32 @@ impl Models { gateway_perms: Rc::default(), all_settings: Rc::default(), }; - bridge.set_servers(ModelRc::from(models.servers.clone())); - bridge.set_tree(ModelRc::from(models.tree.clone())); - bridge.set_members(ModelRc::from(models.members.clone())); - bridge.set_server_members(ModelRc::from(models.server_members.clone())); - bridge.set_tabs(ModelRc::from(models.tabs.clone())); - bridge.set_streams(ModelRc::from(models.streams.clone())); - bridge.set_share_viewers(ModelRc::from(models.viewers.clone())); - bridge.set_pins(ModelRc::from(models.pins.clone())); - bridge.set_topics(ModelRc::from(models.topics.clone())); - bridge.set_topic_messages(ModelRc::from(models.topic_messages.clone())); - bridge.set_viewer_qualities(ModelRc::from(models.qualities.clone())); - bridge.set_messages(ModelRc::from(models.no_chat.clone())); - bridge.set_layers(ModelRc::from(models.layers.clone())); - bridge.set_audio_sources(ModelRc::from(models.audio_sources.clone())); - bridge.set_identities(ModelRc::from(models.identities.clone())); - bridge.set_gateway_config(ModelRc::from(models.gateway_config.clone())); - bridge.set_gateway_perms(ModelRc::from(models.gateway_perms.clone())); - bridge.set_all_settings(ModelRc::from(models.all_settings.clone())); + models.attach(bridge); models } + + /// Show the models in `bridge`: the main window's, and the viewer's own + /// window's (its player reads the stream's qualities). + pub(crate) fn attach(&self, bridge: &Bridge) { + bridge.set_servers(ModelRc::from(self.servers.clone())); + bridge.set_tree(ModelRc::from(self.tree.clone())); + bridge.set_members(ModelRc::from(self.members.clone())); + bridge.set_server_members(ModelRc::from(self.server_members.clone())); + bridge.set_tabs(ModelRc::from(self.tabs.clone())); + bridge.set_streams(ModelRc::from(self.streams.clone())); + bridge.set_share_viewers(ModelRc::from(self.viewers.clone())); + bridge.set_pins(ModelRc::from(self.pins.clone())); + bridge.set_topics(ModelRc::from(self.topics.clone())); + bridge.set_topic_messages(ModelRc::from(self.topic_messages.clone())); + bridge.set_viewer_qualities(ModelRc::from(self.qualities.clone())); + bridge.set_messages(ModelRc::from(self.no_chat.clone())); + bridge.set_layers(ModelRc::from(self.layers.clone())); + bridge.set_audio_sources(ModelRc::from(self.audio_sources.clone())); + bridge.set_identities(ModelRc::from(self.identities.clone())); + bridge.set_gateway_config(ModelRc::from(self.gateway_config.clone())); + bridge.set_gateway_perms(ModelRc::from(self.gateway_perms.clone())); + bridge.set_all_settings(ModelRc::from(self.all_settings.clone())); + } } pub(crate) struct App { @@ -649,6 +655,8 @@ pub(crate) struct App { pub pages: crate::settings_pages::Pages, /// The Stream Studio (studio.rs). pub studio: crate::studio::StudioState, + /// The stream's own window (popout.rs). + pub popout: crate::popout::Popout, } thread_local! { @@ -879,9 +887,16 @@ pub fn run(options: RunOptions) -> Result<()> { social: Default::default(), pages: Default::default(), studio: Default::default(), + popout: Default::default(), }; APP.with(|a| *a.borrow_mut() = Some(app)); crate::bind::wire(&ui); + // The studio's and the stream's windows close with the main window, + // so the app ends. + ui.window().on_close_requested(|| { + with_app(App::close_windows); + slint::CloseRequestResponse::HideWindow + }); with_app(|app| { app.apply_appearance(); app.load_own_uids(); diff --git a/crates/voelin-ui/src/appearance.rs b/crates/voelin-ui/src/appearance.rs index a24486b..310e4aa 100644 --- a/crates/voelin-ui/src/appearance.rs +++ b/crates/voelin-ui/src/appearance.rs @@ -40,7 +40,20 @@ impl App { image_cache_mb: cache_mb as f32, }); bridge.set_image_cache_usage(images::usage_text().into()); - self.studio_theme(); + self.theme_windows(); + } + + /// The windows of their own (the studio's, the stream's) follow the main + /// window's theme. + pub(crate) fn theme_windows(&self) { + let Some(ui) = self.ui.upgrade() else { return }; + let theme = ui.global::(); + if let Some(window) = &self.studio.window { + copy_theme(&theme, &window.global::()); + } + if let Some(window) = &self.popout.window { + copy_theme(&theme, &window.global::()); + } } /// The settings page changed the form: store the keys (they apply @@ -86,3 +99,10 @@ impl App { } } } + +/// Each window has its own Theme global. +fn copy_theme(from: &Theme, to: &Theme) { + to.set_mode(from.get_mode()); + to.set_font_scale(from.get_font_scale()); + to.set_system_dark(from.get_system_dark()); +} diff --git a/crates/voelin-ui/src/bind/mod.rs b/crates/voelin-ui/src/bind/mod.rs index 74eef87..a47c447 100644 --- a/crates/voelin-ui/src/bind/mod.rs +++ b/crates/voelin-ui/src/bind/mod.rs @@ -7,18 +7,18 @@ mod pages; mod servers; mod settings; mod social; -mod streams; +pub(crate) mod streams; pub(crate) mod studio; use slint::ComponentHandle; -use crate::app::{MainWindow, StudioBridge}; +use crate::app::{Bridge, MainWindow, StudioBridge}; /// Connect every callback of the window. pub(crate) fn wire(ui: &MainWindow) { servers::wire(ui); chat::wire(ui); - streams::wire(ui); + streams::wire(&ui.global::()); settings::wire(ui); emoji::wire(ui); social::wire(ui); diff --git a/crates/voelin-ui/src/bind/streams.rs b/crates/voelin-ui/src/bind/streams.rs index 1717ef9..93b02b9 100644 --- a/crates/voelin-ui/src/bind/streams.rs +++ b/crates/voelin-ui/src/bind/streams.rs @@ -1,11 +1,9 @@ -//! The streams panel, the share dialog and the viewer. +//! The streams panel, the share dialog and the viewer, for the main window +//! and for the viewer's own window (each has its own Bridge global). -use slint::ComponentHandle; +use crate::app::{Bridge, with_app}; -use crate::app::{Bridge, MainWindow, with_app}; - -pub(super) fn wire(ui: &MainWindow) { - let bridge = ui.global::(); +pub(crate) fn wire(bridge: &Bridge) { bridge.on_open_share(|| with_app(|app| app.open_share()).unwrap_or_default()); bridge.on_start_share(|form| { with_app(|app| app.start_share(form)); @@ -42,11 +40,11 @@ pub(super) fn wire(ui: &MainWindow) { bridge.on_toggle_fullscreen(|| { with_app(|app| app.toggle_fullscreen()); }); - let window = ui.as_weak(); - bridge.on_show_cursor(move |shown| { - if let Some(ui) = window.upgrade() { - crate::streams::show_cursor(ui.window(), shown); - } + bridge.on_pop_out_viewer(|out| { + with_app(|app| if out { app.viewer_pop_out() } else { app.viewer_dock() }); + }); + bridge.on_show_cursor(|shown| { + with_app(|app| app.viewer_cursor(shown)); }); bridge.on_set_stream_quality(|index| { with_app(|app| app.set_stream_quality(index)); diff --git a/crates/voelin-ui/src/dev.rs b/crates/voelin-ui/src/dev.rs index f4b0e86..c0f0216 100644 --- a/crates/voelin-ui/src/dev.rs +++ b/crates/voelin-ui/src/dev.rs @@ -39,8 +39,7 @@ //! opened: the server dialog filled in from it, or in voice on its //! server a move into its channel), `watch` (the first stream; with //! sample data the local test pattern in its place), `theatre` (after -//! `watch`: in theatre mode), `popout` (`watch` popped out; for now the -//! same as `watch,theatre`), +//! `watch`: in theatre mode), `popout` (`watch` in a window of its own), //! `tab:` (phone layout); `friends[:]`, //! `messages[:]` (a private chat), `inbox` (offline messages), //! `library`, `events`, `event-form`, `search[:]`, @@ -55,8 +54,8 @@ //! `studio:live,server,voice` shows our stream's card with the studio's //! picture), `studio:record`, or a dialog: `studio:source`, //! `studio:audio`, `studio:camera`, `studio:scene`, `studio:settings`. -//! A screenshot also saves the studio's window (`-window.png`) and -//! draws it over the main window. +//! A screenshot also saves the studio's window, or the stream's +//! (`-window.png`), and draws it over the main window. //! - `VOELIN_AUTOWATCH=1`: watch the first stream that shows up. //! - `VOELIN_AUTOSHARE=test-pattern`: share the test pattern (accepting //! everyone) once connected to a TeamSpeak 6 server. @@ -333,15 +332,17 @@ pub(crate) fn start(ui: &MainWindow, switches: &Switches) -> Running { } // As a link from the platform comes. "link" => crate::inbox::request(crate::inbox::Request::OpenLink(arg.to_owned())), - // Until the viewer has a window of its own, `popout` is theatre - // mode too. "watch" | "popout" => { with_app(|app| { - if switches.demo_ui { app.demo_watch() } else { app.watch_first_stream() } + if switches.demo_ui { + app.demo_watch(); + } else { + app.watch_first_stream(); + } + if what == "popout" { + app.viewer_pop_out(); + } }); - if what == "popout" { - nav.set_theatre(true); - } } "theatre" => nav.set_theatre(true), // Home, friends, messages, events, the bell, the search. @@ -436,7 +437,8 @@ pub(crate) fn start(ui: &MainWindow, switches: &Switches) -> Running { eprintln!("screenshot failed: {e}"); } let _ = ui.hide(); - // Also when the studio's own window is open. + // Also when the studio's or the stream's own window is + // open. let _ = slint::quit_event_loop(); } }, @@ -468,10 +470,11 @@ fn open_unread(app: &mut App, back: usize) { fn save_screenshot(ui: &MainWindow, path: &std::path::Path) -> Result<()> { let mut image = ui.window().take_snapshot()?; - if let Some(studio) = with_app(|app| app.studio_snapshot()).flatten() { + let window = with_app(|app| app.studio_snapshot().or_else(|| app.viewer_snapshot())).flatten(); + if let Some(window) = window { let stem = path.file_stem().unwrap_or_default().to_string_lossy(); - save_png(&studio, &path.with_file_name(format!("{stem}-window.png")))?; - paste(&mut image, &studio); + save_png(&window, &path.with_file_name(format!("{stem}-window.png")))?; + paste(&mut image, &window); } save_png(&image, path) } diff --git a/crates/voelin-ui/src/lib.rs b/crates/voelin-ui/src/lib.rs index 11a6dd6..3671c57 100644 --- a/crates/voelin-ui/src/lib.rs +++ b/crates/voelin-ui/src/lib.rs @@ -18,6 +18,7 @@ mod members; mod messages; #[cfg(not(target_os = "android"))] mod myts; +mod popout; mod previews; mod servers; mod settings; diff --git a/crates/voelin-ui/src/popout.rs b/crates/voelin-ui/src/popout.rs new file mode 100644 index 0000000..e577681 --- /dev/null +++ b/crates/voelin-ui/src/popout.rs @@ -0,0 +1,140 @@ +//! The stream we watch in a window of its own (desktop): the player alone, +//! optionally over the other windows, while the main window goes on. Its +//! Bridge global is filled like the main window's (`viewer_each`); the +//! pictures go only to the window that shows the player, as each window +//! scales them again. Closing it brings the stream back into the main +//! window. + +use slint::{ComponentHandle, Rgba8Pixel, SharedPixelBuffer}; +use tracing::warn; + +use crate::app::{App, Bridge, Page, ViewerWindow, later}; + +/// The window, while there is one. +#[derive(Default)] +pub(crate) struct Popout { + pub window: Option, + /// The last window stayed over the others: the next does too. + on_top: bool, +} + +impl App { + /// `f` on the Bridge of the main window and of the viewer's window. + pub(crate) fn viewer_each(&self, f: impl Fn(&Bridge)) { + if let Some(ui) = self.ui.upgrade() { + f(&ui.global::()); + } + if let Some(window) = &self.popout.window { + f(&window.global::()); + } + } + + /// `f` on the Bridge and the window that show the player: the viewer's + /// own while it has one, else the main window. + pub(crate) fn with_player(&self, f: impl FnOnce(&Bridge, &slint::Window)) { + match (&self.popout.window, self.ui.upgrade()) { + (Some(window), _) => f(&window.global::(), window.window()), + (None, Some(ui)) => f(&ui.global::(), ui.window()), + _ => {} + } + } + + /// The player into a window of its own. + pub(crate) fn viewer_pop_out(&mut self) { + // One window on Android. + if cfg!(target_os = "android") || self.popout.window.is_some() || self.watch.is_none() { + return; + } + // The main window's full screen was the player's. + self.set_fullscreen(false); + let window = match ViewerWindow::new() { + Ok(window) => window, + Err(e) => { + self.set_status(format!("Cannot open the stream's window: {e}")); + return; + } + }; + let bridge = window.global::(); + crate::bind::streams::wire(&bridge); + self.models.attach(&bridge); + bridge.set_desktop(true); + bridge.set_viewer_on_top(self.popout.on_top); + window.window().on_close_requested(|| { + // After this event: the window goes away then. + later(|app| app.viewer_dock()); + slint::CloseRequestResponse::HideWindow + }); + // Without its window the stream stays in the main window. + if let Err(e) = window.show() { + warn!("cannot show the stream's window: {e}"); + self.set_status(format!("Cannot open the stream's window: {e}")); + return; + } + // The picture moves with the player. + if let Some(ui) = self.ui.upgrade() { + let main = ui.global::(); + bridge.set_viewer_frame(main.get_viewer_frame()); + main.set_viewer_frame(slint::Image::default()); + } + self.popout.window = Some(window); + self.theme_windows(); + self.refresh_viewer(); + // Our channel's people no longer lead the members panel. + self.refresh_tree(); + } + + /// The player back into the main window, on the stream's server page. + pub(crate) fn viewer_dock(&mut self) { + let Some(window) = self.close_popout() else { return }; + if let Some(watch) = &mut self.watch { + watch.shown = true; + } + if let Some(ui) = self.ui.upgrade() { + ui.global::().set_viewer_frame(window.global::().get_viewer_frame()); + } + // The main window may have gone to another server meanwhile: else + // the stream would play on, unseen. + let session = + self.watch.as_ref().and_then(|w| w.session).filter(|id| self.sessions.contains_key(id)); + if let Some(id) = session + && self.current != Some(id) + { + self.select_server(id); + } + self.refresh_viewer(); + self.refresh_streams(); + self.refresh_tree(); + if self.watch_here() { + // Showing the page runs Nav code that calls back into the app. + self.navigate(|nav| nav.invoke_show(Page::Server)); + } + } + + /// Hide the viewer's window and forget it (leaving the stream, docking). + pub(crate) fn close_popout(&mut self) -> Option { + let window = self.popout.window.take()?; + self.popout.on_top = window.global::().get_viewer_on_top(); + let _ = window.hide(); + Some(window) + } + + /// The pointer over the player's window shows or hides (it hides with + /// the controls in full screen). + pub(crate) fn viewer_cursor(&self, shown: bool) { + self.with_player(|_, window| crate::streams::show_cursor(window, shown)); + } + + /// A picture of the viewer's window (screenshots, dev.rs). + pub(crate) fn viewer_snapshot(&self) -> Option> { + self.popout.window.as_ref()?.window().take_snapshot().ok() + } + + /// The main window closes: the studio's and the stream's windows go + /// with it, so the app ends. + pub(crate) fn close_windows(&mut self) { + if let Some(window) = self.studio.window.take() { + let _ = window.hide(); + } + self.close_popout(); + } +} diff --git a/crates/voelin-ui/src/servers.rs b/crates/voelin-ui/src/servers.rs index 77782cb..796feba 100644 --- a/crates/voelin-ui/src/servers.rs +++ b/crates/voelin-ui/src/servers.rs @@ -571,8 +571,9 @@ impl App { let connected = view.state.voice == VoiceState::Connected; let members = if connected { vm::tree::members(&input) } else { Vec::new() }; vm::list::sync(&self.models.members, &members); - // The people in our channel first while their view is shown. - let watching = self.watch.as_ref().is_some_and(|w| w.shown); + // The people in our channel first while their view is shown (not + // while the stream plays in a window of its own). + let watching = self.watch.as_ref().is_some_and(|w| w.shown) && self.popout.window.is_none(); let voice_first = connected && (self.voice_view || watching); let everyone = vm::tree::server_members(&input, voice_first); let filter = self.member_filter.trim().to_lowercase(); diff --git a/crates/voelin-ui/src/streams.rs b/crates/voelin-ui/src/streams.rs index 5da0ac4..46ca1f7 100644 --- a/crates/voelin-ui/src/streams.rs +++ b/crates/voelin-ui/src/streams.rs @@ -79,7 +79,7 @@ fn demo_viewers() -> Vec { /// The stream in the viewer. pub(crate) struct Watch { /// `None` for the local demo stream. - session: Option, + pub(crate) session: Option, stream_id: String, title: String, streamer: String, @@ -311,10 +311,11 @@ impl App { // Our own stream from the studio shows its preview. let studio = current.is_some_and(|c| self.studio_streams_to(c)); for s in streams { - let watching = self - .watch - .as_ref() - .is_some_and(|w| w.session == current && w.stream_id == s.id && !w.ended); + // Also the sample data's test pattern dressed as this stream + // (`VOELIN_OPEN=watch`), which has no session. + let watching = self.watch.as_ref().is_some_and(|w| { + (w.session == current || w.session.is_none()) && w.stream_id == s.id && !w.ended + }); let own = view.state.own_client == Some(s.streamer.0); items.push(StreamItem { id: s.id.clone().into(), @@ -410,70 +411,97 @@ impl App { bridge.set_share_status(status.into()); } + /// The viewer in the main window and in its own: the same facts, but + /// the main window's player only while the stream is not popped out. pub(crate) fn refresh_viewer(&self) { - let Some(ui) = self.ui.upgrade() else { return }; - let bridge = ui.global::(); + let popped = self.popout.window.is_some(); let Some(watch) = &self.watch else { - bridge.set_viewer_open(false); - bridge.set_viewer_has_frame(false); - bridge.set_viewer_frame(slint::Image::default()); + self.viewer_each(|bridge| { + bridge.set_viewer_open(false); + bridge.set_viewer_popped(popped); + bridge.set_viewer_has_frame(false); + bridge.set_viewer_frame(slint::Image::default()); + }); return; }; - let open = watch.shown && (watch.session.is_none() || watch.session == self.current); - if !open && bridge.get_viewer_open() && bridge.get_viewer_fullscreen() { - // The player goes, still in full screen: it may have hidden the cursor. - show_cursor(ui.window(), true); + if let Some(ui) = self.ui.upgrade() { + let bridge = ui.global::(); + let open = watch.shown && !popped && self.watch_here(); + if !open && bridge.get_viewer_open() && bridge.get_viewer_fullscreen() { + // The player goes, still in full screen: it may have hidden the cursor. + show_cursor(ui.window(), true); + } + bridge.set_viewer_open(open); } - bridge.set_viewer_open(open); - bridge.set_viewer_title(watch.title.clone().into()); - bridge.set_viewer_status(watch.status.clone().into()); - bridge.set_viewer_ended(watch.ended); - bridge.set_viewer_has_frame(watch.has_frame); - bridge.set_viewer_volume(self.stream_volume); + if let Some(window) = &self.popout.window { + window.global::().set_viewer_open(true); + } + // The watched stream's server, which the main window may have left + // while the stream plays in its own. + let view = match watch.session { + Some(id) => self.sessions.get(&id), + None => self.view(), + }; let decoded = watch.decoder.as_ref().map(Decoder::info).unwrap_or_default(); let info = [format!("by {}", watch.streamer), decoded.clone()] .into_iter() .filter(|s| !s.is_empty()) .collect::>() .join(" · "); - bridge.set_viewer_info(info.into()); - bridge.set_viewer_streamer(watch.streamer.clone().into()); - let streamer = self - .view() + let streamer = view .and_then(|v| v.streams.iter().find(|s| s.id == watch.stream_id)) .map_or(-1, |s| i32::from(s.streamer.0)); let face = crate::vm::streams::streamer( &watch.streamer, - self.view().zip(u16::try_from(streamer).ok()).and_then(|(v, id)| v.avatar(id)), + view.zip(u16::try_from(streamer).ok()).and_then(|(v, id)| v.avatar(id)), ); - bridge.set_viewer_streamer_avatar(face.avatar); - bridge.set_viewer_streamer_initials(face.initials); - bridge.set_viewer_streamer_tint(face.tint); + // The members are the current server's. let members = &self.models.members; - bridge.set_viewer_streamer_admin( - (0..members.row_count()) + let admin = self.watch_here() + && (0..members.row_count()) .filter_map(|i| members.row_data(i)) - .any(|m| m.id == streamer && m.admin), - ); + .any(|m| m.id == streamer && m.admin); let channel = u16::try_from(streamer).ok().and_then(|id| { - let view = self.view()?; + let view = view?; let channel = view.presence.channels.get(&view.channel_of(id)?)?; Some(crate::vm::tree::channel_title(channel).0.to_owned()) }); - bridge.set_viewer_channel(channel.unwrap_or_default().into()); - bridge.set_viewer_elapsed(watch.elapsed().into()); - let viewers = self.view().and_then(|v| viewer_count(v, &watch.stream_id)); - bridge.set_viewer_count(viewers.unwrap_or(0) as i32); + let channel = slint::SharedString::from(channel.unwrap_or_default()); + let elapsed = slint::SharedString::from(watch.elapsed()); + let viewers = view.and_then(|v| viewer_count(v, &watch.stream_id)); let qualities = watch.qualities(); let chosen = watch .layer .and_then(|id| watch.layers.iter().position(|l| l.id == id)) .map_or(0, |i| i as i32 + 1); crate::vm::list::sync(&self.models.qualities, &qualities); - if bridge.get_viewer_quality() != chosen { - bridge.set_viewer_quality(chosen); - } - bridge.set_viewer_quality_detail(decoded.into()); + self.viewer_each(|bridge| { + bridge.set_viewer_popped(popped); + bridge.set_viewer_title(watch.title.as_str().into()); + bridge.set_viewer_status(watch.status.as_str().into()); + bridge.set_viewer_ended(watch.ended); + bridge.set_viewer_has_frame(watch.has_frame); + bridge.set_viewer_volume(self.stream_volume); + bridge.set_viewer_info(info.as_str().into()); + bridge.set_viewer_streamer(watch.streamer.as_str().into()); + bridge.set_viewer_streamer_avatar(face.avatar.clone()); + bridge.set_viewer_streamer_initials(face.initials.clone()); + bridge.set_viewer_streamer_tint(face.tint); + bridge.set_viewer_streamer_admin(admin); + bridge.set_viewer_channel(channel.clone()); + bridge.set_viewer_elapsed(elapsed.clone()); + bridge.set_viewer_count(viewers.unwrap_or(0) as i32); + if bridge.get_viewer_quality() != chosen { + bridge.set_viewer_quality(chosen); + } + bridge.set_viewer_quality_detail(decoded.as_str().into()); + }); + } + + /// The watched stream is on the server on screen (or is the local test + /// stream). + pub(crate) fn watch_here(&self) -> bool { + self.watch.as_ref().is_some_and(|w| w.session.is_none() || w.session == self.current) } /// A simulcast layer of the watched stream (0: follow the bandwidth @@ -773,7 +801,8 @@ impl App { let streamer = view.nickname(info.streamer.0); let title = if info.name.is_empty() { format!("{streamer}'s stream") } else { info.name.clone() }; - self.leave_stream(); + // A window of its own stays, for this stream. + self.stop_watching(); self.engine .send(Command::WatchStream { session: session as u64, stream_id: stream_id.clone() }); if self.stream_volume != 100.0 { @@ -842,7 +871,7 @@ impl App { /// The local test stream in the viewer (`VOELIN_DEMO_STREAM`). pub(crate) fn start_demo(&mut self) { - self.leave_stream(); + self.stop_watching(); self.watch = Some(Watch { session: None, stream_id: "demo".into(), @@ -889,6 +918,8 @@ impl App { (watch.stream_id, watch.title, watch.streamer) = (id, title, streamer); } self.refresh_viewer(); + // Its card shows it as watched. + self.refresh_streams(); } /// A decoded picture is waiting. @@ -901,16 +932,19 @@ impl App { watch.status.clear(); watch.since = Some(std::time::Instant::now()); } - if let Some(ui) = self.ui.upgrade() { - let bridge = ui.global::(); - bridge.set_viewer_frame(image); - if first { - self.refresh_viewer(); - } + // Only the window with the player: each would scale it again. + self.with_player(|bridge, _| bridge.set_viewer_frame(image)); + if first { + self.refresh_viewer(); } } pub(crate) fn show_viewer(&mut self, shown: bool) { + // Shown in the main window: from a window of its own, it comes back. + if shown && self.popout.window.is_some() { + self.viewer_dock(); + return; + } if let Some(watch) = &mut self.watch { watch.shown = shown; } @@ -923,8 +957,14 @@ impl App { self.refresh_tree(); } - /// Stop watching and close the viewer. + /// Stop watching and close the viewer, its own window too. pub(crate) fn leave_stream(&mut self) { + self.close_popout(); + self.stop_watching(); + } + + /// Stop watching; a window of its own stays (for the next stream). + fn stop_watching(&mut self) { if let Some(watch) = self.watch.take() && let Some(session) = watch.session && !watch.ended @@ -953,23 +993,24 @@ impl App { } pub(crate) fn toggle_fullscreen(&mut self) { - let Some(ui) = self.ui.upgrade() else { return }; - let full = !ui.global::().get_viewer_fullscreen(); + let mut full = false; + self.with_player(|bridge, _| full = !bridge.get_viewer_fullscreen()); self.set_fullscreen(full); } - fn set_fullscreen(&self, full: bool) { - let Some(ui) = self.ui.upgrade() else { return }; - let bridge = ui.global::(); - if bridge.get_viewer_fullscreen() == full { - return; - } - bridge.set_viewer_fullscreen(full); - ui.window().set_fullscreen(full); - if !full { - // The player that hid the cursor may be gone already. - show_cursor(ui.window(), true); - } + /// The window with the player in full screen, or back. + pub(crate) fn set_fullscreen(&self, full: bool) { + self.with_player(|bridge, window| { + if bridge.get_viewer_fullscreen() == full { + return; + } + bridge.set_viewer_fullscreen(full); + window.set_fullscreen(full); + if !full { + // The player that hid the cursor may be gone already. + show_cursor(window, true); + } + }); } } diff --git a/crates/voelin-ui/src/studio.rs b/crates/voelin-ui/src/studio.rs index 8078c93..72fa21a 100644 --- a/crates/voelin-ui/src/studio.rs +++ b/crates/voelin-ui/src/studio.rs @@ -50,7 +50,7 @@ use voelin_store::MessageSource; use crate::app::{ App, ChatLine, Nav, Page, StudioAudio, StudioBridge, StudioForm, StudioLayer, StudioNav, StudioPick, StudioScene, StudioSettingsForm, StudioSource, StudioSourceForm, StudioStatus, - StudioViewer, StudioWindow, Theme, later, with_app, + StudioViewer, StudioWindow, later, with_app, }; use crate::settings::parse_positive; use crate::video::CaptureRequest; @@ -170,7 +170,7 @@ pub(crate) struct StudioState { /// The main window's globals have the models. attached: bool, /// The studio in a window of its own. - window: Option, + pub(crate) window: Option, run: Option, starting: bool, /// Why it does not run or cannot stream. @@ -2115,20 +2115,11 @@ impl App { slint::CloseRequestResponse::HideWindow }); self.studio.window = Some(window); - self.studio_theme(); - // The main window closes the studio's with it. - if let Some(ui) = self.ui.upgrade() { - ui.window().on_close_requested(|| { - with_app(|app| { - if let Some(window) = app.studio.window.take() { - let _ = window.hide(); - } - }); - slint::CloseRequestResponse::HideWindow - }); - if ui.global::