Move schedule to impl

This commit is contained in:
Ottatop 2023-08-31 20:35:54 -05:00
parent 1b4c636160
commit 39d5454a7f
3 changed files with 60 additions and 49 deletions

View file

@ -853,38 +853,6 @@ impl State {
device_id: node,
});
// Run any connected callbacks
{
let clone = output.clone();
self.loop_handle.insert_idle(|data| {
crate::state::schedule(
data,
|dt| dt.state.api_state.stream.is_some(),
move |dt| {
let stream = dt
.state
.api_state
.stream
.as_ref()
.expect("Stream doesn't exist");
let mut stream = stream.lock().expect("Couldn't lock stream");
for callback_id in dt.state.output_callback_ids.iter() {
crate::api::send_to_client(
&mut stream,
&OutgoingMsg::CallCallback {
callback_id: *callback_id,
args: Some(Args::ConnectForAllOutputs {
output_name: clone.name(),
}),
},
)
.expect("Send to client failed");
}
},
)
});
}
let allocator = GbmAllocator::new(
device.gbm.clone(),
GbmBufferFlags::RENDERING | GbmBufferFlags::SCANOUT,
@ -980,6 +948,35 @@ impl State {
device.surfaces.insert(crtc, surface);
self.schedule_initial_render(node, crtc, self.loop_handle.clone());
// Run any connected callbacks
{
let clone = output.clone();
self.schedule(
|dt| dt.state.api_state.stream.is_some(),
move |dt| {
let stream = dt
.state
.api_state
.stream
.as_ref()
.expect("Stream doesn't exist");
let mut stream = stream.lock().expect("Couldn't lock stream");
for callback_id in dt.state.output_callback_ids.iter() {
crate::api::send_to_client(
&mut stream,
&OutgoingMsg::CallCallback {
callback_id: *callback_id,
args: Some(Args::ConnectForAllOutputs {
output_name: clone.name(),
}),
},
)
.expect("Send to client failed");
}
},
);
}
}
fn connector_disconnected(

View file

@ -91,8 +91,9 @@ impl XdgShellHandler for State {
// note to self: don't reorder this
// TODO: fix it so that reordering this doesn't break stuff
self.windows.push(window.clone());
// self.space.map_element(window.clone(), (0, 0), true);
if let Some(focused_output) = self.focus_state.focused_output.clone() {
// FIXME: ignoring initial configure here
self.update_windows(&focused_output);
BLOCKER_COUNTER.store(1, std::sync::atomic::Ordering::SeqCst);
tracing::debug!(

View file

@ -159,22 +159,6 @@ where
on_commit(data);
}
// Schedule something to be done when `condition` returns true.
pub fn schedule<F1, F2>(data: &mut CalloopData, condition: F1, run: F2)
where
F1: Fn(&mut CalloopData) -> bool + 'static,
F2: FnOnce(&mut CalloopData) + 'static,
{
if !condition(data) {
data.state.loop_handle.insert_idle(|data| {
schedule(data, condition, run);
});
return;
}
run(data);
}
impl State {
pub fn init(
backend: Backend,
@ -393,6 +377,35 @@ impl State {
xdisplay: None,
})
}
/// Schedule `run` to run when `condition` returns true.
///
/// This will continually reschedule `run` in the event loop if `condition` returns false.
pub fn schedule<F1, F2>(&self, condition: F1, run: F2)
where
F1: Fn(&mut CalloopData) -> bool + 'static,
F2: FnOnce(&mut CalloopData) + 'static,
{
self.loop_handle.insert_idle(|data| {
Self::schedule_inner(data, condition, run);
});
}
// Schedule something to be done when `condition` returns true.
fn schedule_inner<F1, F2>(data: &mut CalloopData, condition: F1, run: F2)
where
F1: Fn(&mut CalloopData) -> bool + 'static,
F2: FnOnce(&mut CalloopData) + 'static,
{
if !condition(data) {
data.state.loop_handle.insert_idle(|data| {
Self::schedule_inner(data, condition, run);
});
return;
}
run(data);
}
}
fn get_config_dir() -> PathBuf {