forge
Explore
Log in

Don't you dare go Hollow

pw_utils: Store LoopHandle

Browse files at this commit

43577f4d97bdf00e6df47005499e74968193ff92Ivan MolodetskikhParent: 8fba696
src/niri.rsmodified+4 -3
@@ -2029,7 +2029,8 @@ impl State {
2029 let pw = if let Some(pw) = &self.niri.pipewire {2029 let pw = if let Some(pw) = &self.niri.pipewire {
2030 pw2030 pw
2031 } else {2031 } else {
2032- match PipeWire::new(&self.niri.event_loop, self.niri.pw_to_niri.clone()) {2032+ match PipeWire::new(self.niri.event_loop.clone(), self.niri.pw_to_niri.clone())
2033+ {
2033 Ok(pipewire) => self.niri.pipewire.insert(pipewire),2034 Ok(pipewire) => self.niri.pipewire.insert(pipewire),
2034 Err(err) => {2035 Err(err) => {
2035 warn!(2036 warn!(
@@ -5019,7 +5020,7 @@ impl Niri {
5019 }5020 }
5020 }5021 }
5021 5022
5022- if cast.check_time_and_schedule(&self.event_loop, output, target_presentation_time) {5023+ if cast.check_time_and_schedule(output, target_presentation_time) {
5023 continue;5024 continue;
5024 }5025 }
5025 5026
@@ -5085,7 +5086,7 @@ impl Niri {
5085 }5086 }
5086 }5087 }
5087 5088
5088- if cast.check_time_and_schedule(&self.event_loop, output, target_presentation_time) {5089+ if cast.check_time_and_schedule(output, target_presentation_time) {
5089 continue;5090 continue;
5090 }5091 }
5091 5092
src/pw_utils.rsmodified+12 -13
@@ -57,6 +57,7 @@ pub struct PipeWire {
57 _context: Context,57 _context: Context,
58 pub core: Core,58 pub core: Core,
59 pub token: RegistrationToken,59 pub token: RegistrationToken,
60+ event_loop: LoopHandle<'static, State>,
60 to_niri: calloop::channel::Sender<PwToNiri>,61 to_niri: calloop::channel::Sender<PwToNiri>,
61 }62 }
62 63
@@ -67,6 +68,7 @@ pub enum PwToNiri {
67 }68 }
68 69
69 pub struct Cast {70 pub struct Cast {
71+ event_loop: LoopHandle<'static, State>,
70 pub session_id: usize,72 pub session_id: usize,
71 pub stream_id: usize,73 pub stream_id: usize,
72 pub stream: Stream,74 pub stream: Stream,
@@ -143,7 +145,7 @@ macro_rules! make_params {
143 145
144 impl PipeWire {146 impl PipeWire {
145 pub fn new(147 pub fn new(
146- event_loop: &LoopHandle<'static, State>,148+ event_loop: LoopHandle<'static, State>,
147 to_niri: calloop::channel::Sender<PwToNiri>,149 to_niri: calloop::channel::Sender<PwToNiri>,
148 ) -> anyhow::Result<Self> {150 ) -> anyhow::Result<Self> {
149 let main_loop = MainLoop::new(None).context("error creating MainLoop")?;151 let main_loop = MainLoop::new(None).context("error creating MainLoop")?;
@@ -185,6 +187,7 @@ impl PipeWire {
185 _context: context,187 _context: context,
186 core,188 core,
187 token,189 token,
190+ event_loop,
188 to_niri,191 to_niri,
189 })192 })
190 }193 }
@@ -666,6 +669,7 @@ impl PipeWire {
666 .context("error connecting stream")?;669 .context("error connecting stream")?;
667 670
668 let cast = Cast {671 let cast = Cast {
672+ event_loop: self.event_loop.clone(),
669 session_id,673 session_id,
670 stream_id,674 stream_id,
671 stream,675 stream,
@@ -784,12 +788,7 @@ impl Cast {
784 Duration::ZERO788 Duration::ZERO
785 }789 }
786 790
787- fn schedule_redraw(791+ fn schedule_redraw(&mut self, output: Output, target_time: Duration) {
788- &mut self,
789- event_loop: &LoopHandle<'static, State>,
790- output: Output,
791- target_time: Duration,
792- ) {
793 if self.scheduled_redraw.is_some() {792 if self.scheduled_redraw.is_some() {
794 return;793 return;
795 }794 }
@@ -797,7 +796,8 @@ impl Cast {
797 let now = get_monotonic_time();796 let now = get_monotonic_time();
798 let duration = target_time.saturating_sub(now);797 let duration = target_time.saturating_sub(now);
799 let timer = Timer::from_duration(duration);798 let timer = Timer::from_duration(duration);
800- let token = event_loop799+ let token = self
800+ .event_loop
801 .insert_source(timer, move |_, _, state| {801 .insert_source(timer, move |_, _, state| {
802 // Guard against output disconnecting before the timer has a chance to run.802 // Guard against output disconnecting before the timer has a chance to run.
803 if state.niri.output_state.contains_key(&output) {803 if state.niri.output_state.contains_key(&output) {
@@ -810,9 +810,9 @@ impl Cast {
810 self.scheduled_redraw = Some(token);810 self.scheduled_redraw = Some(token);
811 }811 }
812 812
813- fn remove_scheduled_redraw(&mut self, event_loop: &LoopHandle<'static, State>) {813+ fn remove_scheduled_redraw(&mut self) {
814 if let Some(token) = self.scheduled_redraw.take() {814 if let Some(token) = self.scheduled_redraw.take() {
815- event_loop.remove(token);815+ self.event_loop.remove(token);
816 }816 }
817 }817 }
818 818
@@ -825,17 +825,16 @@ impl Cast {
825 /// [`Cast::dequeue_buffer_and_render()`].825 /// [`Cast::dequeue_buffer_and_render()`].
826 pub fn check_time_and_schedule(826 pub fn check_time_and_schedule(
827 &mut self,827 &mut self,
828- event_loop: &LoopHandle<'static, State>,
829 output: &Output,828 output: &Output,
830 target_frame_time: Duration,829 target_frame_time: Duration,
831 ) -> bool {830 ) -> bool {
832 let delay = self.compute_extra_delay(target_frame_time);831 let delay = self.compute_extra_delay(target_frame_time);
833 if delay >= CAST_DELAY_ALLOWANCE {832 if delay >= CAST_DELAY_ALLOWANCE {
834 trace!("delay >= allowance, scheduling redraw");833 trace!("delay >= allowance, scheduling redraw");
835- self.schedule_redraw(event_loop, output.clone(), target_frame_time + delay);834+ self.schedule_redraw(output.clone(), target_frame_time + delay);
836 true835 true
837 } else {836 } else {
838- self.remove_scheduled_redraw(event_loop);837+ self.remove_scheduled_redraw();
839 false838 false
840 }839 }
841 }840 }