From 8a2a6a3185c5eacef24225bce73b3ca5bdeeecf0 Mon Sep 17 00:00:00 2001 From: Ottatop Date: Fri, 16 Feb 2024 22:37:53 -0600 Subject: [PATCH] Remove `CalloopData` This was a remnant of Anvil --- src/backend/udev.rs | 63 +++++++++--------- src/backend/winit.rs | 22 +++---- src/config.rs | 17 +++-- src/handlers.rs | 26 ++++---- src/handlers/xwayland.rs | 134 +++++++++++++++++---------------------- src/state.rs | 55 ++++++---------- 6 files changed, 137 insertions(+), 180 deletions(-) diff --git a/src/backend/udev.rs b/src/backend/udev.rs index 4e0581f..e3948cc 100644 --- a/src/backend/udev.rs +++ b/src/backend/udev.rs @@ -76,7 +76,7 @@ use crate::{ config::ConnectorSavedState, output::OutputName, render::{pointer::PointerElement, take_presentation_feedback}, - state::{CalloopData, State, SurfaceDmabufFeedback, WithState}, + state::{State, SurfaceDmabufFeedback, WithState}, window::WindowElement, }; @@ -131,7 +131,7 @@ impl Backend { impl Udev { /// Schedule a new render that will cause the compositor to redraw everything. - pub fn schedule_render(&mut self, loop_handle: &LoopHandle, output: &Output) { + pub fn schedule_render(&mut self, loop_handle: &LoopHandle, output: &Output) { // tracing::debug!("schedule_render on output {}", output.name()); let Some(surface) = render_surface_for_output(output, &mut self.backends) else { @@ -141,8 +141,8 @@ impl Udev { match &surface.render_state { RenderState::Idle => { let output = output.clone(); - let token = loop_handle.insert_idle(move |data| { - data.state.render_surface(&output); + let token = loop_handle.insert_idle(move |state| { + state.render_surface(&output); }); surface.render_state = RenderState::Scheduled(token); @@ -189,8 +189,8 @@ impl State { // Wait for the clear to commit before switching self.schedule( - |data| { - let udev = data.state.backend.udev(); + |state| { + let udev = state.backend.udev(); !udev .backends .values() @@ -198,8 +198,8 @@ impl State { .map(|surface| surface.compositor.surface()) .any(|drm_surf| drm_surf.commit_pending()) }, - move |data| { - let udev = data.state.backend.udev_mut(); + move |state| { + let udev = state.backend.udev_mut(); if let Err(err) = udev.session.change_vt(vt) { tracing::error!("Failed to switch to vt {vt}: {err}"); } @@ -301,25 +301,25 @@ pub fn run_udev() -> anyhow::Result<()> { event_loop .handle() - .insert_source(udev_backend, move |event, _, data| match event { + .insert_source(udev_backend, move |event, _, state| match event { // GPU connected UdevEvent::Added { device_id, path } => { if let Err(err) = DrmNode::from_dev_id(device_id) .map_err(DeviceAddError::DrmNode) - .and_then(|node| data.state.device_added(node, &path)) + .and_then(|node| state.device_added(node, &path)) { tracing::error!("Skipping device {device_id}: {err}"); } } UdevEvent::Changed { device_id } => { if let Ok(node) = DrmNode::from_dev_id(device_id) { - data.state.device_changed(node) + state.device_changed(node) } } // GPU disconnected UdevEvent::Removed { device_id } => { if let Ok(node) = DrmNode::from_dev_id(device_id) { - data.state.device_removed(node) + state.device_removed(node) } } }) @@ -338,9 +338,9 @@ pub fn run_udev() -> anyhow::Result<()> { let insert_ret = event_loop .handle() - .insert_source(libinput_backend, move |event, _, data| { - data.state.apply_libinput_settings(&event); - data.state.process_input_event(event); + .insert_source(libinput_backend, move |event, _, state| { + state.apply_libinput_settings(&event); + state.process_input_event(event); }); if let Err(err) = insert_ret { @@ -349,8 +349,8 @@ pub fn run_udev() -> anyhow::Result<()> { event_loop .handle() - .insert_source(notifier, move |event, _, data| { - let udev = data.state.backend.udev_mut(); + .insert_source(notifier, move |event, _, state| { + let udev = state.backend.udev_mut(); match event { session::Event::PauseSession => { @@ -398,13 +398,12 @@ pub fn run_udev() -> anyhow::Result<()> { for (node, connectors) in connectors { for (connector, crtc) in connectors { - data.state - .connector_disconnected(node, connector.clone(), crtc); - data.state.connector_connected(node, connector, crtc); + state.connector_disconnected(node, connector.clone(), crtc); + state.connector_connected(node, connector, crtc); } } - for output in data.state.space.outputs().cloned().collect::>() { - data.state.schedule_render(&output); + for output in state.space.outputs().cloned().collect::>() { + state.schedule_render(&output); } } } @@ -515,18 +514,16 @@ pub fn run_udev() -> anyhow::Result<()> { event_loop.run( Some(Duration::from_micros(((1.0 / 144.0) * 1000000.0) as u64)), - &mut CalloopData { - state, - display_handle, - }, - |data| { - data.state.space.refresh(); - data.state.popup_manager.cleanup(); - data.display_handle + &mut state, + |state| { + state.space.refresh(); + state.popup_manager.cleanup(); + state + .display_handle .flush_clients() .expect("failed to flush_clients"); - data.state.focus_state.fix_up_focus(&mut data.state.space); + state.focus_state.fix_up_focus(&mut state.space); }, )?; @@ -743,7 +740,7 @@ impl State { let registration_token = self .loop_handle - .insert_source(notifier, move |event, metadata, data| match event { + .insert_source(notifier, move |event, metadata, state| match event { DrmEvent::VBlank(crtc) => { // { TODO: // let udev = data.state.backend.udev_mut(); @@ -753,7 +750,7 @@ impl State { // // tracing::debug!(time = diff.as_secs_f64(), "Time since last vblank"); // udev.last_vblank_time = now; // } - data.state.on_vblank(node, crtc, metadata); + state.on_vblank(node, crtc, metadata); } DrmEvent::Error(error) => { tracing::error!("{:?}", error); diff --git a/src/backend/winit.rs b/src/backend/winit.rs index 5871288..728030f 100644 --- a/src/backend/winit.rs +++ b/src/backend/winit.rs @@ -30,7 +30,7 @@ use smithay::{ use crate::{ render::{pointer::PointerElement, take_presentation_feedback}, - state::{CalloopData, State}, + state::State, }; use super::{Backend, BackendData}; @@ -63,7 +63,7 @@ impl Backend { /// Start Pinnacle as a window in a graphical environment. pub fn run_winit() -> anyhow::Result<()> { - let mut event_loop: EventLoop = EventLoop::try_new()?; + let mut event_loop: EventLoop = EventLoop::try_new()?; let display: Display = Display::new()?; let display_handle = display.handle(); @@ -190,9 +190,7 @@ pub fn run_winit() -> anyhow::Result<()> { let insert_ret = state .loop_handle - .insert_source(Timer::immediate(), move |_instant, _metadata, data| { - let state = &mut data.state; - + .insert_source(Timer::immediate(), move |_instant, _metadata, state| { let status = winit_evt_loop.dispatch_new_events(|event| match event { WinitEvent::Resized { size, @@ -237,14 +235,12 @@ pub fn run_winit() -> anyhow::Result<()> { event_loop.run( Some(Duration::from_micros(((1.0 / 144.0) * 1000000.0) as u64)), - &mut CalloopData { - display_handle, - state, - }, - |data| { - data.state.space.refresh(); - data.state.popup_manager.cleanup(); - data.display_handle + &mut state, + |state| { + state.space.refresh(); + state.popup_manager.cleanup(); + state + .display_handle .flush_clients() .expect("failed to flush client buffers"); }, diff --git a/src/config.rs b/src/config.rs index cceb124..67d1eed 100644 --- a/src/config.rs +++ b/src/config.rs @@ -4,7 +4,6 @@ use crate::{ }, input::ModifierMask, output::OutputName, - state::CalloopData, tag::Tag, window::rules::{WindowRule, WindowRuleCondition}, }; @@ -173,7 +172,7 @@ pub struct Config { } impl Config { - pub fn clear(&mut self, loop_handle: &LoopHandle) { + pub fn clear(&mut self, loop_handle: &LoopHandle) { self.window_rules.clear(); self.output_callback_senders.clear(); self.connector_saved_states.clear(); @@ -358,9 +357,9 @@ impl State { let token = self .loop_handle - .insert_source(ping_source, move |_, _, data| { + .insert_source(ping_source, move |_, _, state| { tracing::error!("Config crashed! Falling back to default Lua config"); - data.state + state .start_config(&default_lua_config_dir) .expect("failed to start default lua config"); })?; @@ -435,8 +434,8 @@ impl State { calloop::channel::channel::>(); self.loop_handle - .insert_source(grpc_receiver, |msg, _, data| match msg { - Event::Msg(f) => f(&mut data.state), + .insert_source(grpc_receiver, |msg, _, state| match msg { + Event::Msg(f) => f(state), Event::Closed => tracing::error!("grpc receiver was closed"), }) .expect("failed to insert grpc_receiver into loop"); @@ -490,9 +489,9 @@ impl State { // | fast at startup then I think there's a chance that the gRPC server // | could get started twice. None => self.schedule( - |data| data.state.xdisplay.is_some(), - move |data| { - data.state.grpc_server_join_handle = Some(tokio::spawn(async move { + |state| state.xdisplay.is_some(), + move |state| { + state.grpc_server_join_handle = Some(tokio::spawn(async move { if let Err(err) = grpc_server.serve_with_incoming(uds_stream).await { tracing::error!("gRPC server error: {err}"); } diff --git a/src/handlers.rs b/src/handlers.rs index 49adc65..6b05cdc 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -59,7 +59,7 @@ use smithay::{ use crate::{ focus::FocusTarget, - state::{CalloopData, ClientState, State, WithState}, + state::{ClientState, State, WithState}, window::WindowElement, }; @@ -90,10 +90,10 @@ impl CompositorHandler for State { let client = surface .client() .expect("Surface has no client/is no longer alive"); - let res = state.loop_handle.insert_source(source, move |_, _, data| { - data.state + let res = state.loop_handle.insert_source(source, move |_, _, state| { + state .client_compositor_state(&client) - .blocker_cleared(&mut data.state, &data.display_handle); + .blocker_cleared(state, &state.display_handle.clone()); Ok(()) }); if res.is_ok() { @@ -107,9 +107,9 @@ impl CompositorHandler for State { fn commit(&mut self, surface: &WlSurface) { tracing::trace!("commit on surface {surface:?}"); - X11Wm::commit_hook::(surface); + X11Wm::commit_hook::(surface); - utils::on_commit_buffer_handler::(surface); + utils::on_commit_buffer_handler::(surface); self.backend.early_import(surface); let mut root = surface.clone(); @@ -167,13 +167,13 @@ impl CompositorHandler for State { ); } - self.loop_handle.insert_idle(move |data| { - data.state + self.loop_handle.insert_idle(move |state| { + state .seat .get_keyboard() .expect("Seat had no keyboard") // FIXME: actually handle error .set_focus( - &mut data.state, + state, Some(FocusTarget::Window(new_window)), SERIAL_COUNTER.next_serial(), ); @@ -527,8 +527,8 @@ impl WlrLayerShellHandler for State { .expect("failed to map layer surface"); drop(map); // wow i really love refcells haha - self.loop_handle.insert_idle(move |data| { - data.state.update_windows(&output); + self.loop_handle.insert_idle(move |state| { + state.update_windows(&output); }); } @@ -547,8 +547,8 @@ impl WlrLayerShellHandler for State { } if let Some(output) = output { - self.loop_handle.insert_idle(move |data| { - data.state.update_windows(&output); + self.loop_handle.insert_idle(move |state| { + state.update_windows(&output); }); } } diff --git a/src/handlers/xwayland.rs b/src/handlers/xwayland.rs index dad2697..71628a3 100644 --- a/src/handlers/xwayland.rs +++ b/src/handlers/xwayland.rs @@ -23,13 +23,13 @@ use smithay::{ use crate::{ focus::FocusTarget, - state::{CalloopData, WithState}, + state::{State, WithState}, window::{window_state::FloatingOrTiled, WindowElement}, }; -impl XwmHandler for CalloopData { +impl XwmHandler for State { fn xwm_state(&mut self, _xwm: XwmId) -> &mut X11Wm { - self.state.xwm.as_mut().expect("xwm not in state") + self.xwm.as_mut().expect("xwm not in state") } fn new_window(&mut self, _xwm: XwmId, _window: X11Surface) {} @@ -42,24 +42,21 @@ impl XwmHandler for CalloopData { assert!(!window.is_override_redirect()); let window = WindowElement::X11(window); - self.state.space.map_element(window.clone(), (0, 0), true); + self.space.map_element(window.clone(), (0, 0), true); let bbox = self - .state .space .element_bbox(&window) .expect("called element_bbox on an unmapped window"); let output_size = self - .state .focus_state .focused_output .as_ref() - .and_then(|op| self.state.space.output_geometry(op)) + .and_then(|op| self.space.output_geometry(op)) .map(|geo| geo.size) .unwrap_or((2, 2).into()); let output_loc = self - .state .focus_state .focused_output .as_ref() @@ -79,7 +76,7 @@ impl XwmHandler for CalloopData { unreachable!() }; - self.state.space.map_element(window.clone(), loc, true); + self.space.map_element(window.clone(), loc, true); surface.set_mapped(true).expect("failed to map x11 window"); let bbox = Rectangle::from_loc_and_size(loc, bbox.size); @@ -91,8 +88,8 @@ impl XwmHandler for CalloopData { // TODO: ssd if let (Some(output), _) | (None, Some(output)) = ( - &self.state.focus_state.focused_output, - self.state.space.outputs().next(), + &self.focus_state.focused_output, + self.space.outputs().next(), ) { window.place_on_output(output); } @@ -103,23 +100,23 @@ impl XwmHandler for CalloopData { }); } - self.state.windows.push(window.clone()); + self.windows.push(window.clone()); - self.state.focus_state.set_focus(window.clone()); + self.focus_state.set_focus(window.clone()); - self.state.apply_window_rules(&window); + self.apply_window_rules(&window); - if let Some(output) = window.output(&self.state) { - self.state.update_windows(&output); + if let Some(output) = window.output(self) { + self.update_windows(&output); } - self.state.loop_handle.insert_idle(move |data| { - data.state + self.loop_handle.insert_idle(move |state| { + state .seat .get_keyboard() .expect("Seat had no keyboard") // FIXME: actually handle error .set_focus( - &mut data.state, + state, Some(FocusTarget::Window(window)), SERIAL_COUNTER.next_serial(), ); @@ -134,54 +131,52 @@ impl XwmHandler for CalloopData { let loc = window.geometry().loc; let window = WindowElement::X11OverrideRedirect(window); - self.state.windows.push(window.clone()); + self.windows.push(window.clone()); if let (Some(output), _) | (None, Some(output)) = ( - &self.state.focus_state.focused_output, - self.state.space.outputs().next(), + &self.focus_state.focused_output, + self.space.outputs().next(), ) { window.place_on_output(output); } - self.state.space.map_element(window.clone(), loc, true); - self.state.focus_state.set_focus(window); + self.space.map_element(window.clone(), loc, true); + self.focus_state.set_focus(window); } fn unmapped_window(&mut self, _xwm: XwmId, window: X11Surface) { - self.state.focus_state.focus_stack.retain(|win| { + self.focus_state.focus_stack.retain(|win| { win.wl_surface() .is_some_and(|surf| Some(surf) != window.wl_surface()) }); let win = self - .state .space .elements() .find(|elem| matches!(elem, WindowElement::X11(surface) if surface == &window)) .cloned(); if let Some(win) = win { - self.state.space.unmap_elem(&win); + self.space.unmap_elem(&win); - if let Some(output) = win.output(&self.state) { - self.state.update_windows(&output); + if let Some(output) = win.output(self) { + self.update_windows(&output); - let focus = self.state.focused_window(&output).map(FocusTarget::Window); + let focus = self.focused_window(&output).map(FocusTarget::Window); if let Some(FocusTarget::Window(win)) = &focus { - self.state.space.raise_element(win, true); + self.space.raise_element(win, true); if let WindowElement::Wayland(win) = &win { win.toplevel().send_configure(); } } - self.state - .seat + self.seat .get_keyboard() .expect("Seat had no keyboard") - .set_focus(&mut self.state, focus, SERIAL_COUNTER.next_serial()); + .set_focus(self, focus, SERIAL_COUNTER.next_serial()); - self.state.schedule_render(&output); + self.schedule_render(&output); } } @@ -192,13 +187,12 @@ impl XwmHandler for CalloopData { } fn destroyed_window(&mut self, _xwm: XwmId, window: X11Surface) { - self.state.focus_state.focus_stack.retain(|win| { + self.focus_state.focus_stack.retain(|win| { win.wl_surface() .is_some_and(|surf| Some(surf) != window.wl_surface()) }); let win = self - .state .windows .iter() .find(|elem| { @@ -215,30 +209,28 @@ impl XwmHandler for CalloopData { tracing::debug!("removing x11 window from windows"); // INFO: comparing the windows doesn't work so wlsurface it is - // self.state.windows.retain(|elem| &win != elem); - self.state - .windows + // self.windows.retain(|elem| &win != elem); + self.windows .retain(|elem| win.wl_surface() != elem.wl_surface()); - if let Some(output) = win.output(&self.state) { - self.state.update_windows(&output); + if let Some(output) = win.output(self) { + self.update_windows(&output); - let focus = self.state.focused_window(&output).map(FocusTarget::Window); + let focus = self.focused_window(&output).map(FocusTarget::Window); if let Some(FocusTarget::Window(win)) = &focus { - self.state.space.raise_element(win, true); + self.space.raise_element(win, true); if let WindowElement::Wayland(win) = &win { win.toplevel().send_configure(); } } - self.state - .seat + self.seat .get_keyboard() .expect("Seat had no keyboard") - .set_focus(&mut self.state, focus, SERIAL_COUNTER.next_serial()); + .set_focus(self, focus, SERIAL_COUNTER.next_serial()); - self.state.schedule_render(&output); + self.schedule_render(&output); } } tracing::debug!("destroyed x11 window"); @@ -275,7 +267,6 @@ impl XwmHandler for CalloopData { _above: Option, ) { let Some(win) = self - .state .space .elements() .find(|elem| matches!(elem, WindowElement::X11(surface) if surface == &window)) @@ -284,7 +275,7 @@ impl XwmHandler for CalloopData { return; }; - self.state.space.map_element(win, geometry.loc, true); + self.space.map_element(win, geometry.loc, true); } fn maximize_request(&mut self, _xwm: XwmId, window: X11Surface) { @@ -294,7 +285,7 @@ impl XwmHandler for CalloopData { let Some(window) = window .wl_surface() - .and_then(|surf| self.state.window_for_surface(&surf)) + .and_then(|surf| self.window_for_surface(&surf)) else { return; }; @@ -311,7 +302,7 @@ impl XwmHandler for CalloopData { let Some(window) = window .wl_surface() - .and_then(|surf| self.state.window_for_surface(&surf)) + .and_then(|surf| self.window_for_surface(&surf)) else { return; }; @@ -328,7 +319,7 @@ impl XwmHandler for CalloopData { let Some(window) = window .wl_surface() - .and_then(|surf| self.state.window_for_surface(&surf)) + .and_then(|surf| self.window_for_surface(&surf)) else { return; }; @@ -345,7 +336,7 @@ impl XwmHandler for CalloopData { let Some(window) = window .wl_surface() - .and_then(|surf| self.state.window_for_surface(&surf)) + .and_then(|surf| self.window_for_surface(&surf)) else { return; }; @@ -363,12 +354,12 @@ impl XwmHandler for CalloopData { resize_edge: smithay::xwayland::xwm::ResizeEdge, ) { let Some(wl_surf) = window.wl_surface() else { return }; - let seat = self.state.seat.clone(); + let seat = self.seat.clone(); // We use the server one and not the client because windows like Steam don't provide // GrabStartData, so we need to create it ourselves. crate::grab::resize_grab::resize_request_server( - &mut self.state, + self, &wl_surf, &seat, SERIAL_COUNTER.next_serial(), @@ -379,12 +370,12 @@ impl XwmHandler for CalloopData { fn move_request(&mut self, _xwm: XwmId, window: X11Surface, button: u32) { let Some(wl_surf) = window.wl_surface() else { return }; - let seat = self.state.seat.clone(); + let seat = self.seat.clone(); // We use the server one and not the client because windows like Steam don't provide // GrabStartData, so we need to create it ourselves. crate::grab::move_grab::move_request_server( - &mut self.state, + self, &wl_surf, &seat, SERIAL_COUNTER.next_serial(), @@ -393,8 +384,7 @@ impl XwmHandler for CalloopData { } fn allow_selection_access(&mut self, xwm: XwmId, _selection: SelectionTarget) -> bool { - self.state - .seat + self.seat .get_keyboard() .and_then(|kb| kb.current_focus()) .is_some_and(|focus| { @@ -415,9 +405,7 @@ impl XwmHandler for CalloopData { ) { match selection { SelectionTarget::Clipboard => { - if let Err(err) = - request_data_device_client_selection(&self.state.seat, mime_type, fd) - { + if let Err(err) = request_data_device_client_selection(&self.seat, mime_type, fd) { tracing::error!( ?err, "Failed to request current wayland clipboard for XWayland" @@ -425,8 +413,7 @@ impl XwmHandler for CalloopData { } } SelectionTarget::Primary => { - if let Err(err) = request_primary_client_selection(&self.state.seat, mime_type, fd) - { + if let Err(err) = request_primary_client_selection(&self.seat, mime_type, fd) { tracing::error!( ?err, "Failed to request current wayland primary selection for XWayland" @@ -439,15 +426,10 @@ impl XwmHandler for CalloopData { fn new_selection(&mut self, _xwm: XwmId, selection: SelectionTarget, mime_types: Vec) { match selection { SelectionTarget::Clipboard => { - set_data_device_selection( - &self.state.display_handle, - &self.state.seat, - mime_types, - (), - ); + set_data_device_selection(&self.display_handle, &self.seat, mime_types, ()); } SelectionTarget::Primary => { - set_primary_selection(&self.state.display_handle, &self.state.seat, mime_types, ()); + set_primary_selection(&self.display_handle, &self.seat, mime_types, ()); } } } @@ -455,13 +437,13 @@ impl XwmHandler for CalloopData { fn cleared_selection(&mut self, _xwm: XwmId, selection: SelectionTarget) { match selection { SelectionTarget::Clipboard => { - if current_data_device_selection_userdata(&self.state.seat).is_some() { - clear_data_device_selection(&self.state.display_handle, &self.state.seat); + if current_data_device_selection_userdata(&self.seat).is_some() { + clear_data_device_selection(&self.display_handle, &self.seat); } } SelectionTarget::Primary => { - if current_primary_selection_userdata(&self.state.seat).is_some() { - clear_primary_selection(&self.state.display_handle, &self.state.seat); + if current_primary_selection_userdata(&self.seat).is_some() { + clear_primary_selection(&self.display_handle, &self.seat); } } } diff --git a/src/state.rs b/src/state.rs index f0d7924..592cc4b 100644 --- a/src/state.rs +++ b/src/state.rs @@ -43,7 +43,7 @@ pub struct State { /// A loop signal used to stop the compositor pub loop_signal: LoopSignal, /// A handle to the event loop - pub loop_handle: LoopHandle<'static, CalloopData>, + pub loop_handle: LoopHandle<'static, Self>, pub display_handle: DisplayHandle, pub clock: Clock, @@ -99,7 +99,7 @@ impl State { backend: Backend, display: Display, loop_signal: LoopSignal, - loop_handle: LoopHandle<'static, CalloopData>, + loop_handle: LoopHandle<'static, Self>, ) -> anyhow::Result { let socket = ListeningSocketSource::new_auto()?; let socket_name = socket.socket_name().to_os_string(); @@ -137,20 +137,20 @@ impl State { loop_handle.insert_source( Generic::new(display, Interest::READ, Mode::Level), - |_readiness, display, data| { + |_readiness, display, state| { // Safety: we don't drop the display unsafe { display .get_mut() - .dispatch_clients(&mut data.state) + .dispatch_clients(state) .expect("failed to dispatch clients"); } Ok(PostAction::Continue) }, )?; - loop_handle.insert_idle(|data| { - if let Err(err) = data.state.start_config(crate::config::get_config_dir()) { + loop_handle.insert_idle(|state| { + if let Err(err) = state.start_config(crate::config::get_config_dir()) { panic!("failed to start config: {err}"); } }); @@ -166,7 +166,7 @@ impl State { let (xwayland, channel) = XWayland::new(&display_handle); let clone = display_handle.clone(); tracing::debug!("inserting into loop"); - let res = loop_handle.insert_source(channel, move |event, _, data| match event { + let res = loop_handle.insert_source(channel, move |event, _, state| match event { XWaylandEvent::Ready { connection, client, @@ -174,7 +174,7 @@ impl State { display, } => { let mut wm = X11Wm::start_wm( - data.state.loop_handle.clone(), + state.loop_handle.clone(), clone.clone(), connection, client, @@ -192,13 +192,13 @@ impl State { tracing::debug!("setting xwm and xdisplay"); - data.state.xwm = Some(wm); - data.state.xdisplay = Some(display); + state.xwm = Some(wm); + state.xdisplay = Some(display); std::env::set_var("DISPLAY", format!(":{display}")); } XWaylandEvent::Exited => { - data.state.xwm.take(); + state.xwm.take(); } }); if let Err(err) = res { @@ -274,41 +274,24 @@ impl State { /// 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, + F1: Fn(&mut Self) -> bool + 'static, + F2: FnOnce(&mut Self) + 'static, { - self.loop_handle.insert_idle(|data| { - Self::schedule_inner(data, condition, run); + self.loop_handle.insert_idle(|state| { + if !condition(state) { + state.schedule(condition, run); + } else { + run(state); + } }); } - /// 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); - } - pub fn shutdown(&self) { tracing::info!("Shutting down Pinnacle"); self.loop_signal.stop(); } } -pub struct CalloopData { - pub display_handle: DisplayHandle, - pub state: State, -} - #[derive(Default)] pub struct ClientState { pub compositor_state: CompositorClientState,