From 3461c66d2ce8fb53e2a709b27868229786604256 Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Thu, 18 Jan 2024 21:16:36 +0400 Subject: [PATCH] Redraw upon starting PW stream Otherwise it may take a while for the first frame to arrive. --- src/dbus/mutter_screen_cast.rs | 1 + src/niri.rs | 1 + src/pw_utils.rs | 12 +++++++++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/dbus/mutter_screen_cast.rs b/src/dbus/mutter_screen_cast.rs index 68c53e5df..4b367d27e 100644 --- a/src/dbus/mutter_screen_cast.rs +++ b/src/dbus/mutter_screen_cast.rs @@ -64,6 +64,7 @@ pub enum ScreenCastToNiri { StopCast { session_id: usize, }, + Redraw(Output), } #[dbus_interface(name = "org.gnome.Mutter.ScreenCast")] diff --git a/src/niri.rs b/src/niri.rs index 16e0f2d66..93b50be3b 100644 --- a/src/niri.rs +++ b/src/niri.rs @@ -705,6 +705,7 @@ impl State { } } ScreenCastToNiri::StopCast { session_id } => self.niri.stop_cast(session_id), + ScreenCastToNiri::Redraw(output) => self.niri.queue_redraw(output), } } diff --git a/src/pw_utils.rs b/src/pw_utils.rs index 7a85a7a2d..097cfdd7e 100644 --- a/src/pw_utils.rs +++ b/src/pw_utils.rs @@ -95,11 +95,20 @@ impl PipeWire { ) -> anyhow::Result { let _span = tracy_client::span!("PipeWire::start_cast"); + let to_niri_ = to_niri.clone(); let stop_cast = move || { - if let Err(err) = to_niri.send(ScreenCastToNiri::StopCast { session_id }) { + if let Err(err) = to_niri_.send(ScreenCastToNiri::StopCast { session_id }) { warn!("error sending StopCast to niri: {err:?}"); } }; + let weak = output.downgrade(); + let redraw = move || { + if let Some(output) = weak.upgrade() { + if let Err(err) = to_niri.send(ScreenCastToNiri::Redraw(output)) { + warn!("error sending Redraw to niri: {err:?}"); + } + } + }; let mode = output.current_mode().unwrap(); let size = mode.size; @@ -158,6 +167,7 @@ impl PipeWire { StreamState::Connecting => (), StreamState::Streaming => { is_active.set(true); + redraw(); } } }