mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-23 02:05:33 +07:00
pw_utils: Store LoopHandle
This commit is contained in:
+4
-3
@@ -2029,7 +2029,8 @@ impl State {
|
|||||||
let pw = if let Some(pw) = &self.niri.pipewire {
|
let pw = if let Some(pw) = &self.niri.pipewire {
|
||||||
pw
|
pw
|
||||||
} else {
|
} else {
|
||||||
match PipeWire::new(&self.niri.event_loop, self.niri.pw_to_niri.clone()) {
|
match PipeWire::new(self.niri.event_loop.clone(), self.niri.pw_to_niri.clone())
|
||||||
|
{
|
||||||
Ok(pipewire) => self.niri.pipewire.insert(pipewire),
|
Ok(pipewire) => self.niri.pipewire.insert(pipewire),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
warn!(
|
warn!(
|
||||||
@@ -5019,7 +5020,7 @@ impl Niri {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if cast.check_time_and_schedule(&self.event_loop, output, target_presentation_time) {
|
if cast.check_time_and_schedule(output, target_presentation_time) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5085,7 +5086,7 @@ impl Niri {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if cast.check_time_and_schedule(&self.event_loop, output, target_presentation_time) {
|
if cast.check_time_and_schedule(output, target_presentation_time) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+12
-13
@@ -57,6 +57,7 @@ pub struct PipeWire {
|
|||||||
_context: Context,
|
_context: Context,
|
||||||
pub core: Core,
|
pub core: Core,
|
||||||
pub token: RegistrationToken,
|
pub token: RegistrationToken,
|
||||||
|
event_loop: LoopHandle<'static, State>,
|
||||||
to_niri: calloop::channel::Sender<PwToNiri>,
|
to_niri: calloop::channel::Sender<PwToNiri>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,6 +68,7 @@ pub enum PwToNiri {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct Cast {
|
pub struct Cast {
|
||||||
|
event_loop: LoopHandle<'static, State>,
|
||||||
pub session_id: usize,
|
pub session_id: usize,
|
||||||
pub stream_id: usize,
|
pub stream_id: usize,
|
||||||
pub stream: Stream,
|
pub stream: Stream,
|
||||||
@@ -143,7 +145,7 @@ macro_rules! make_params {
|
|||||||
|
|
||||||
impl PipeWire {
|
impl PipeWire {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
event_loop: &LoopHandle<'static, State>,
|
event_loop: LoopHandle<'static, State>,
|
||||||
to_niri: calloop::channel::Sender<PwToNiri>,
|
to_niri: calloop::channel::Sender<PwToNiri>,
|
||||||
) -> anyhow::Result<Self> {
|
) -> anyhow::Result<Self> {
|
||||||
let main_loop = MainLoop::new(None).context("error creating MainLoop")?;
|
let main_loop = MainLoop::new(None).context("error creating MainLoop")?;
|
||||||
@@ -185,6 +187,7 @@ impl PipeWire {
|
|||||||
_context: context,
|
_context: context,
|
||||||
core,
|
core,
|
||||||
token,
|
token,
|
||||||
|
event_loop,
|
||||||
to_niri,
|
to_niri,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -666,6 +669,7 @@ impl PipeWire {
|
|||||||
.context("error connecting stream")?;
|
.context("error connecting stream")?;
|
||||||
|
|
||||||
let cast = Cast {
|
let cast = Cast {
|
||||||
|
event_loop: self.event_loop.clone(),
|
||||||
session_id,
|
session_id,
|
||||||
stream_id,
|
stream_id,
|
||||||
stream,
|
stream,
|
||||||
@@ -784,12 +788,7 @@ impl Cast {
|
|||||||
Duration::ZERO
|
Duration::ZERO
|
||||||
}
|
}
|
||||||
|
|
||||||
fn schedule_redraw(
|
fn schedule_redraw(&mut self, output: Output, target_time: Duration) {
|
||||||
&mut self,
|
|
||||||
event_loop: &LoopHandle<'static, State>,
|
|
||||||
output: Output,
|
|
||||||
target_time: Duration,
|
|
||||||
) {
|
|
||||||
if self.scheduled_redraw.is_some() {
|
if self.scheduled_redraw.is_some() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -797,7 +796,8 @@ impl Cast {
|
|||||||
let now = get_monotonic_time();
|
let now = get_monotonic_time();
|
||||||
let duration = target_time.saturating_sub(now);
|
let duration = target_time.saturating_sub(now);
|
||||||
let timer = Timer::from_duration(duration);
|
let timer = Timer::from_duration(duration);
|
||||||
let token = event_loop
|
let token = self
|
||||||
|
.event_loop
|
||||||
.insert_source(timer, move |_, _, state| {
|
.insert_source(timer, move |_, _, state| {
|
||||||
// Guard against output disconnecting before the timer has a chance to run.
|
// Guard against output disconnecting before the timer has a chance to run.
|
||||||
if state.niri.output_state.contains_key(&output) {
|
if state.niri.output_state.contains_key(&output) {
|
||||||
@@ -810,9 +810,9 @@ impl Cast {
|
|||||||
self.scheduled_redraw = Some(token);
|
self.scheduled_redraw = Some(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn remove_scheduled_redraw(&mut self, event_loop: &LoopHandle<'static, State>) {
|
fn remove_scheduled_redraw(&mut self) {
|
||||||
if let Some(token) = self.scheduled_redraw.take() {
|
if let Some(token) = self.scheduled_redraw.take() {
|
||||||
event_loop.remove(token);
|
self.event_loop.remove(token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -825,17 +825,16 @@ impl Cast {
|
|||||||
/// [`Cast::dequeue_buffer_and_render()`].
|
/// [`Cast::dequeue_buffer_and_render()`].
|
||||||
pub fn check_time_and_schedule(
|
pub fn check_time_and_schedule(
|
||||||
&mut self,
|
&mut self,
|
||||||
event_loop: &LoopHandle<'static, State>,
|
|
||||||
output: &Output,
|
output: &Output,
|
||||||
target_frame_time: Duration,
|
target_frame_time: Duration,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let delay = self.compute_extra_delay(target_frame_time);
|
let delay = self.compute_extra_delay(target_frame_time);
|
||||||
if delay >= CAST_DELAY_ALLOWANCE {
|
if delay >= CAST_DELAY_ALLOWANCE {
|
||||||
trace!("delay >= allowance, scheduling redraw");
|
trace!("delay >= allowance, scheduling redraw");
|
||||||
self.schedule_redraw(event_loop, output.clone(), target_frame_time + delay);
|
self.schedule_redraw(output.clone(), target_frame_time + delay);
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
self.remove_scheduled_redraw(event_loop);
|
self.remove_scheduled_redraw();
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user