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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AVRENKftQqGoEeswiR9TDQ
This commit is contained in:
Claude committed 2026-10-08 14:20:36 +00:00
1 parent 3b2711cea7
commit 0f7d73de02
17 files changed
+468 -172

No files matched your search

+33 -18
View File
@@ -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();
+21 -1
View File
@@ -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::<Theme>();
if let Some(window) = &self.studio.window {
copy_theme(&theme, &window.global::<Theme>());
}
if let Some(window) = &self.popout.window {
copy_theme(&theme, &window.global::<Theme>());
}
}
/// 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());
}
+3 -3
View File
@@ -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::<Bridge>());
settings::wire(ui);
emoji::wire(ui);
social::wire(ui);
+9 -11
View File
@@ -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::<Bridge>();
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));
+17 -14
View File
@@ -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:<home|servers|chat|activity|you>` (phone layout); `friends[:<uid>]`,
//! `messages[:<uid>]` (a private chat), `inbox` (offline messages),
//! `library`, `events`, `event-form`, `search[:<text>]`,
@@ -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 (`<name>-window.png`) and
//! draws it over the main window.
//! A screenshot also saves the studio's window, or the stream's
//! (`<name>-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)
}
+1
View File
@@ -18,6 +18,7 @@ mod members;
mod messages;
#[cfg(not(target_os = "android"))]
mod myts;
mod popout;
mod previews;
mod servers;
mod settings;
+140
View File
@@ -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<ViewerWindow>,
/// 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::<Bridge>());
}
if let Some(window) = &self.popout.window {
f(&window.global::<Bridge>());
}
}
/// `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::<Bridge>(), window.window()),
(None, Some(ui)) => f(&ui.global::<Bridge>(), 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::<Bridge>();
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>();
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::<Bridge>().set_viewer_frame(window.global::<Bridge>().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<ViewerWindow> {
let window = self.popout.window.take()?;
self.popout.on_top = window.global::<Bridge>().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<SharedPixelBuffer<Rgba8Pixel>> {
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();
}
}
+3 -2
View File
@@ -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();
+105 -64
View File
@@ -79,7 +79,7 @@ fn demo_viewers() -> Vec<ViewerInfo> {
/// The stream in the viewer.
pub(crate) struct Watch {
/// `None` for the local demo stream.
session: Option<i64>,
pub(crate) session: Option<i64>,
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::<Bridge>();
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::<Bridge>();
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::<Bridge>().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::<Vec<_>>()
.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>();
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::<Bridge>().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::<Bridge>();
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);
}
});
}
}
+7 -25
View File
@@ -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<StudioWindow>,
pub(crate) window: Option<StudioWindow>,
run: Option<Running>,
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::<Nav>().get_page() == Page::Studio {
ui.global::<Nav>().set_page(Page::Server);
}
self.theme_windows();
if let Some(ui) = self.ui.upgrade()
&& ui.global::<Nav>().get_page() == Page::Studio
{
ui.global::<Nav>().set_page(Page::Server);
}
}
// The next picture goes to both windows with the flag.
@@ -2151,15 +2142,6 @@ impl App {
});
}
/// The studio window follows the main window's theme.
pub(crate) fn studio_theme(&self) {
let (Some(ui), Some(window)) = (self.ui.upgrade(), &self.studio.window) else { return };
let (from, to) = (ui.global::<Theme>(), window.global::<Theme>());
to.set_mode(from.get_mode());
to.set_font_scale(from.get_font_scale());
to.set_system_dark(from.get_system_dark());
}
/// A picture of the studio window (screenshots, dev.rs).
pub(crate) fn studio_snapshot(&self) -> Option<SharedPixelBuffer<Rgba8Pixel>> {
self.studio.window.as_ref()?.window().take_snapshot().ok()
+4 -1
View File
@@ -43,6 +43,8 @@ export { Nav, Page, MobileTab, SettingsSection } from "nav.slint";
// The Stream Studio: its data, and its own window (src/studio.rs).
export { StudioBridge, StudioNav, StudioScene, StudioSource, StudioAudio, StudioLayer, StudioViewer, StudioPick, StudioStatus, StudioForm, StudioSourceForm, StudioSettingsForm } from "studio-bridge.slint";
export { StudioWindow } from "studio-window.slint";
// The stream we watch in a window of its own (src/popout.rs).
export { ViewerWindow } from "viewer-window.slint";
export component MainWindow inherits Window {
title: Bridge.app-name;
@@ -79,7 +81,8 @@ export component MainWindow inherits Window {
// The viewer takes the whole window in full screen and in theatre mode
// (a narrow window keeps the phone layout).
property <bool> chrome: !(Bridge.viewer-open && (Bridge.viewer-fullscreen || (Nav.theatre && !Nav.narrow)));
// Theatre mode ends with the viewer.
// Theatre mode ends with the viewer here, which is also when it moves
// into a window of its own (Rust sets viewer-open false meanwhile).
property <bool> viewer-open: Bridge.viewer-open;
changed viewer-open => {
if !viewer-open {
+9 -1
View File
@@ -999,8 +999,13 @@ export global Bridge {
// Whether capture and encoding are built in.
in property <bool> can-share: true;
// The stream shown in the viewer.
// The stream shown in the viewer. Open: the player is in this window
// (the main window's is not while the stream plays in its own).
in property <bool> viewer-open;
// The stream plays in a window of its own (desktop, src/popout.rs),
// which can stay over the other windows.
in property <bool> viewer-popped;
in-out property <bool> viewer-on-top;
in property <image> viewer-frame;
in property <bool> viewer-has-frame;
in property <string> viewer-title;
@@ -1136,6 +1141,9 @@ export global Bridge {
callback leave-stream();
callback set-stream-volume(float);
callback toggle-fullscreen();
// The player into a window of its own (true) or back into the main
// window.
callback pop-out-viewer(bool);
// Show or hide the pointer over the window: the player hides it with
// its controls in full screen.
callback show-cursor(bool);
+26 -15
View File
@@ -85,11 +85,12 @@ component StreamCard inherits Rectangle {
accessible-label: @tr("Watch {}", stream.name);
clicked => { Bridge.watch-stream(stream.id); }
}
// Also back from a window of its own.
if stream.watching && !Bridge.viewer-open: Button {
horizontal-stretch: 1;
small: true;
icon: Icons.monitor;
text: @tr("Show");
icon: Bridge.viewer-popped ? Icons.minimize-2 : Icons.monitor;
text: Bridge.viewer-popped ? @tr("Bring back") : @tr("Show");
clicked => { Bridge.show-viewer(); }
}
if stream.watching: Button {
@@ -233,15 +234,15 @@ component StreamQuality inherits HorizontalLayout {
}
// The player: the picture with the controls over its bottom. `compact`
// (full screen, the phone) also has the streamer, the title and LIVE over
// its top, and Leave; otherwise the header shows them.
// (full screen, the phone, a window of its own) also has the streamer, the
// title and LIVE over its top, and Leave; otherwise the header shows them.
//
// The controls hide 2.5 s after the pointer last moved over the picture,
// once it has been there (in full screen it is), and come back when it
// moves; with the pointer elsewhere, as in a screenshot, they stay. A
// status and the end of the stream keep them. A touch screen has no
// pointer to move: a tap on the picture shows or hides them.
component StreamPlayer inherits Rectangle {
export component StreamPlayer inherits Rectangle {
in property <bool> compact;
property <bool> touch: !Bridge.desktop;
property <bool> pinned: Bridge.viewer-status != "" || Bridge.viewer-ended;
@@ -446,7 +447,7 @@ component StreamPlayer inherits Rectangle {
vertical-alignment: center;
overflow: elide;
}
if !Bridge.viewer-fullscreen && !Nav.narrow: IconButton {
if !Bridge.viewer-fullscreen && !Nav.narrow && !Bridge.viewer-popped: IconButton {
icon: Icons.minimize-2;
label: @tr("Back to the chat (keeps watching)");
tooltip: root.up ? self.label : "";
@@ -457,7 +458,7 @@ component StreamPlayer inherits Rectangle {
// Theatre mode: the window without the shell. Checked, it has
// the accent's colours, as elsewhere (white would not show on
// the light theme's).
if !Bridge.viewer-fullscreen && !Nav.narrow: IconButton {
if !Bridge.viewer-fullscreen && !Nav.narrow && !Bridge.viewer-popped: IconButton {
icon: Icons.rectangle-horizontal;
label: Nav.theatre ? @tr("Exit theatre mode") : @tr("Theatre mode");
tooltip: root.up ? self.label : "";
@@ -466,16 +467,26 @@ component StreamPlayer inherits Rectangle {
y: (parent.height - self.height) / 2;
clicked => { Nav.theatre = !Nav.theatre; }
}
// Until the viewer has a window of its own, popping out is
// theatre mode.
if !Nav.narrow: IconButton {
icon: Icons.external-link;
label: Nav.theatre ? @tr("Back to the window") : @tr("Pop out");
// In a window of its own: over the other windows or not
// (picture in picture).
if Bridge.viewer-popped: IconButton {
icon: Icons.pin;
label: Bridge.viewer-on-top ? @tr("Stop keeping on top") : @tr("Keep on top");
tooltip: root.up ? self.label : "";
checked: Nav.theatre;
tint: Nav.theatre ? Theme.accent-text : #ffffff;
checked: Bridge.viewer-on-top;
tint: Bridge.viewer-on-top ? Theme.accent-text : #ffffff;
y: (parent.height - self.height) / 2;
clicked => { Nav.theatre = !Nav.theatre; }
clicked => { Bridge.viewer-on-top = !Bridge.viewer-on-top; }
}
// Into a window of its own and back (a phone has one window).
if Bridge.desktop && !Nav.narrow: IconButton {
icon: Icons.external-link;
label: Bridge.viewer-popped ? @tr("Back into the main window") : @tr("Pop out");
tooltip: root.up ? self.label : "";
checked: Bridge.viewer-popped;
tint: Bridge.viewer-popped ? Theme.accent-text : #ffffff;
y: (parent.height - self.height) / 2;
clicked => { Bridge.pop-out-viewer(!Bridge.viewer-popped); }
}
IconButton {
icon: Bridge.viewer-fullscreen ? Icons.minimize-2 : Icons.maximize;
+23 -9
View File
@@ -110,16 +110,18 @@ export component Participant inherits VerticalLayout {
}
// A stream in the channel: LIVE, the title, who streams it, and Watch (or
// Show, while we watch it). A large card with the picture while we watch
// it (else the streamer on a painted scene), the viewers, the kind, the
// bitrate and the sound; compact, a row with the streamer's avatar that
// says where it is.
// Show, while we watch it; Bring back, while it plays in a window of its
// own). A large card with the picture while we watch it here (else the
// streamer on a painted scene), the viewers, the kind, the bitrate and the
// sound; compact, a row with the streamer's avatar that says where it is.
export component StreamCard inherits Rectangle {
in property <StreamItem> stream;
in property <bool> compact;
// We watch it in a window of its own: the picture is there.
property <bool> popped: stream.watching && Bridge.viewer-popped;
// The picture: the stream while we watch it (the viewer hidden behind
// the chat), or our own from the studio while it is live.
property <bool> watched: stream.watching && Bridge.viewer-has-frame;
property <bool> watched: stream.watching && Bridge.viewer-has-frame && !root.popped;
property <bool> previewed: stream.studio && StudioBridge.status.live && StudioBridge.has-preview;
height: compact ? 76px : 236px;
border-radius: Theme.radius-lg;
@@ -199,13 +201,22 @@ export component StreamCard inherits Rectangle {
large: true;
y: (parent.height - self.height) / 2;
}
if stream.viewers > 0: Chip {
// Popped out, that window counts the viewers, and the card
// has room for one chip beside LIVE.
if stream.viewers > 0 && !root.popped: Chip {
text: @tr("{} watching", stream.viewers);
icon: Icons.eye;
tint: #ffffff;
fill: #060a18a0;
y: (parent.height - self.height) / 2;
}
if root.popped: Chip {
text: @tr("Playing in its own window");
icon: Icons.external-link;
tint: #ffffff;
fill: #060a18a0;
y: (parent.height - self.height) / 2;
}
}
}
// Not conditional, so the card keeps its minimum size.
@@ -251,6 +262,7 @@ export component StreamCard inherits Rectangle {
Text {
text: !root.compact ? (stream.kind != "" ? stream.streamer + " • " + stream.kind : stream.streamer)
: stream.id == "" ? (stream.channel == "" ? @tr("Looking it up…") : @tr("In {}; looking it up…", stream.channel))
: root.popped ? @tr("Playing in its own window")
: stream.own ? @tr("Your stream")
: stream.channel != "" ? @tr("{} · in {}", stream.streamer, stream.channel)
: stream.viewers > 0 ? @tr("{} · {} watching", stream.streamer, stream.viewers)
@@ -288,10 +300,12 @@ export component StreamCard inherits Rectangle {
kind: root.compact ? ButtonKind.primary : ButtonKind.secondary;
small: root.compact;
checked: !root.compact;
icon: stream.watching ? Icons.monitor : root.compact ? Icons.eye : Icons.external-link;
text: stream.watching ? (root.compact ? @tr("Show") : @tr("Show Stream")) : root.compact ? @tr("Watch") : @tr("Watch Stream");
icon: root.popped ? Icons.minimize-2 : stream.watching ? Icons.monitor : root.compact ? Icons.eye : Icons.external-link;
text: root.popped ? @tr("Bring back") : stream.watching ? (root.compact ? @tr("Show") : @tr("Show Stream")) : root.compact ? @tr("Watch") : @tr("Watch Stream");
clicked => {
if stream.watching {
if root.popped {
Bridge.pop-out-viewer(false);
} else if stream.watching {
Bridge.show-viewer();
} else {
Bridge.watch-stream(stream.id);
+52
View File
@@ -0,0 +1,52 @@
// The stream we watch in a window of its own (desktop), while the main
// window goes on: the player alone, as in full screen, optionally over the
// other windows. It has its own globals, which Rust fills like the main
// window's (src/popout.rs). Closing it brings the stream back into the
// main window.
import { Palette } from "std-widgets.slint";
import { Theme } from "theme.slint";
import { Icons } from "icons.slint";
import { Bridge } from "bridge.slint";
import { StreamPlayer } from "screens/streams.slint";
export component ViewerWindow inherits Window {
title: Bridge.viewer-title;
preferred-width: 960px;
preferred-height: 540px;
min-width: 480px;
min-height: 270px;
// Under the player, which is black.
background: Theme.bg-app;
default-font-family: "Inter";
default-font-size: Theme.font-body;
icon: Icons.logo;
always-on-top: Bridge.viewer-on-top;
// Scroll bars and menus follow the theme (Rust copies the main
// window's Theme here).
property <bool> dark: Theme.dark;
changed dark => { Palette.color-scheme = Theme.dark ? ColorScheme.dark : ColorScheme.light; }
init => {
Palette.color-scheme = Theme.dark ? ColorScheme.dark : ColorScheme.light;
keys.focus();
}
// Into full screen and out of it the clicked button keeps the focus:
// the keys take it back, so Escape works.
property <bool> fullscreen: Bridge.viewer-fullscreen;
changed fullscreen => { keys.focus(); }
keys := FocusScope {
// Escape leaves full screen.
key-pressed(event) => {
if event.text == Key.Escape && Bridge.viewer-fullscreen {
Bridge.toggle-fullscreen();
return accept;
}
reject
}
StreamPlayer {
compact: true;
}
}
}