diff --git a/src/backend/udev.rs b/src/backend/udev.rs index 0d3ffae..2d79177 100644 --- a/src/backend/udev.rs +++ b/src/backend/udev.rs @@ -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( diff --git a/src/handlers/xdg_shell.rs b/src/handlers/xdg_shell.rs index eba89fc..158b05a 100644 --- a/src/handlers/xdg_shell.rs +++ b/src/handlers/xdg_shell.rs @@ -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!( diff --git a/src/state.rs b/src/state.rs index 9774f93..3a1da88 100644 --- a/src/state.rs +++ b/src/state.rs @@ -159,22 +159,6 @@ where on_commit(data); } -// Schedule something to be done when `condition` returns true. -pub fn schedule(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(&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(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 {