Remove LoopData
Browse files at this commitcd4f7c0378e7ce3ed14a1d1b1a1146c7a7ef33bfParent: c422fda6 changed files +87 -101
- src/backend/tty.rs +40 -42
- src/backend/winit.rs +11 -14
- src/handlers/compositor.rs +4 -4
- src/main.rs +6 -11
- src/niri.rs +24 -28
- src/pw_utils.rs +2 -2
src/backend/tty.rsmodified+40 -42
| @@ -39,7 +39,7 @@ use smithay_drm_extras::edid::EdidInfo; | |||
| 39 | use crate::config::Config; | 39 | use crate::config::Config; |
| 40 | use crate::niri::{OutputRenderElements, State}; | 40 | use crate::niri::{OutputRenderElements, State}; |
| 41 | use crate::utils::get_monotonic_time; | 41 | use crate::utils::get_monotonic_time; |
| 42 | -use crate::{LoopData, Niri}; | 42 | +use crate::Niri; |
| 43 | 43 | ||
| 44 | const BACKGROUND_COLOR: [f32; 4] = [0.1, 0.1, 0.1, 1.]; | 44 | const BACKGROUND_COLOR: [f32; 4] = [0.1, 0.1, 0.1, 1.]; |
| 45 | const SUPPORTED_COLOR_FORMATS: &[Fourcc] = &[Fourcc::Argb8888, Fourcc::Abgr8888]; | 45 | const SUPPORTED_COLOR_FORMATS: &[Fourcc] = &[Fourcc::Argb8888, Fourcc::Abgr8888]; |
| @@ -47,7 +47,7 @@ const SUPPORTED_COLOR_FORMATS: &[Fourcc] = &[Fourcc::Argb8888, Fourcc::Abgr8888] | |||
| 47 | pub struct Tty { | 47 | pub struct Tty { |
| 48 | config: Rc<RefCell<Config>>, | 48 | config: Rc<RefCell<Config>>, |
| 49 | session: LibSeatSession, | 49 | session: LibSeatSession, |
| 50 | - udev_dispatcher: Dispatcher<'static, UdevBackend, LoopData>, | 50 | + udev_dispatcher: Dispatcher<'static, UdevBackend, State>, |
| 51 | primary_gpu_path: PathBuf, | 51 | primary_gpu_path: PathBuf, |
| 52 | output_device: Option<OutputDevice>, | 52 | output_device: Option<OutputDevice>, |
| 53 | connectors: Arc<Mutex<HashMap<String, Output>>>, | 53 | connectors: Arc<Mutex<HashMap<String, Output>>>, |
| @@ -94,45 +94,44 @@ struct Surface { | |||
| 94 | } | 94 | } |
| 95 | 95 | ||
| 96 | impl Tty { | 96 | impl Tty { |
| 97 | - pub fn new(config: Rc<RefCell<Config>>, event_loop: LoopHandle<'static, LoopData>) -> Self { | 97 | + pub fn new(config: Rc<RefCell<Config>>, event_loop: LoopHandle<'static, State>) -> Self { |
| 98 | let (session, notifier) = LibSeatSession::new().unwrap(); | 98 | let (session, notifier) = LibSeatSession::new().unwrap(); |
| 99 | let seat_name = session.seat(); | 99 | let seat_name = session.seat(); |
| 100 | 100 | ||
| 101 | let udev_backend = UdevBackend::new(session.seat()).unwrap(); | 101 | let udev_backend = UdevBackend::new(session.seat()).unwrap(); |
| 102 | - let udev_dispatcher = | 102 | + let udev_dispatcher = Dispatcher::new(udev_backend, move |event, _, state: &mut State| { |
| 103 | - Dispatcher::new(udev_backend, move |event, _, data: &mut LoopData| { | 103 | + let tty = state.backend.tty(); |
| 104 | - let tty = data.state.backend.tty(); | 104 | + let niri = &mut state.niri; |
| 105 | - let niri = &mut data.state.niri; | ||
| 106 | 105 | ||
| 107 | - match event { | 106 | + match event { |
| 108 | - UdevEvent::Added { device_id, path } => { | 107 | + UdevEvent::Added { device_id, path } => { |
| 109 | - if !tty.session.is_active() { | 108 | + if !tty.session.is_active() { |
| 110 | - debug!("skipping UdevEvent::Added as session is inactive"); | 109 | + debug!("skipping UdevEvent::Added as session is inactive"); |
| 111 | - return; | 110 | + return; |
| 112 | - } | ||
| 113 | - | ||
| 114 | - if let Err(err) = tty.device_added(device_id, &path, niri) { | ||
| 115 | - warn!("error adding device: {err:?}"); | ||
| 116 | - } | ||
| 117 | } | 111 | } |
| 118 | - UdevEvent::Changed { device_id } => { | ||
| 119 | - if !tty.session.is_active() { | ||
| 120 | - debug!("skipping UdevEvent::Changed as session is inactive"); | ||
| 121 | - return; | ||
| 122 | - } | ||
| 123 | 112 | ||
| 124 | - tty.device_changed(device_id, niri) | 113 | + if let Err(err) = tty.device_added(device_id, &path, niri) { |
| 114 | + warn!("error adding device: {err:?}"); | ||
| 115 | + } | ||
| 116 | + } | ||
| 117 | + UdevEvent::Changed { device_id } => { | ||
| 118 | + if !tty.session.is_active() { | ||
| 119 | + debug!("skipping UdevEvent::Changed as session is inactive"); | ||
| 120 | + return; | ||
| 125 | } | 121 | } |
| 126 | - UdevEvent::Removed { device_id } => { | ||
| 127 | - if !tty.session.is_active() { | ||
| 128 | - debug!("skipping UdevEvent::Removed as session is inactive"); | ||
| 129 | - return; | ||
| 130 | - } | ||
| 131 | 122 | ||
| 132 | - tty.device_removed(device_id, niri) | 123 | + tty.device_changed(device_id, niri) |
| 124 | + } | ||
| 125 | + UdevEvent::Removed { device_id } => { | ||
| 126 | + if !tty.session.is_active() { | ||
| 127 | + debug!("skipping UdevEvent::Removed as session is inactive"); | ||
| 128 | + return; | ||
| 133 | } | 129 | } |
| 130 | + | ||
| 131 | + tty.device_removed(device_id, niri) | ||
| 134 | } | 132 | } |
| 135 | - }); | 133 | + } |
| 134 | + }); | ||
| 136 | event_loop | 135 | event_loop |
| 137 | .register_dispatcher(udev_dispatcher.clone()) | 136 | .register_dispatcher(udev_dispatcher.clone()) |
| 138 | .unwrap(); | 137 | .unwrap(); |
| @@ -142,17 +141,17 @@ impl Tty { | |||
| 142 | 141 | ||
| 143 | let input_backend = LibinputInputBackend::new(libinput.clone()); | 142 | let input_backend = LibinputInputBackend::new(libinput.clone()); |
| 144 | event_loop | 143 | event_loop |
| 145 | - .insert_source(input_backend, |mut event, _, data| { | 144 | + .insert_source(input_backend, |mut event, _, state| { |
| 146 | - data.state.process_libinput_event(&mut event); | 145 | + state.process_libinput_event(&mut event); |
| 147 | - data.state.process_input_event(event); | 146 | + state.process_input_event(event); |
| 148 | }) | 147 | }) |
| 149 | .unwrap(); | 148 | .unwrap(); |
| 150 | 149 | ||
| 151 | let udev_dispatcher_c = udev_dispatcher.clone(); | 150 | let udev_dispatcher_c = udev_dispatcher.clone(); |
| 152 | event_loop | 151 | event_loop |
| 153 | - .insert_source(notifier, move |event, _, data| { | 152 | + .insert_source(notifier, move |event, _, state| { |
| 154 | - let tty = data.state.backend.tty(); | 153 | + let tty = state.backend.tty(); |
| 155 | - let niri = &mut data.state.niri; | 154 | + let niri = &mut state.niri; |
| 156 | 155 | ||
| 157 | match event { | 156 | match event { |
| 158 | SessionEvent::PauseSession => { | 157 | SessionEvent::PauseSession => { |
| @@ -303,8 +302,8 @@ impl Tty { | |||
| 303 | 302 | ||
| 304 | let token = niri | 303 | let token = niri |
| 305 | .event_loop | 304 | .event_loop |
| 306 | - .insert_source(drm_notifier, move |event, metadata, data| { | 305 | + .insert_source(drm_notifier, move |event, metadata, state| { |
| 307 | - let tty = data.state.backend.tty(); | 306 | + let tty = state.backend.tty(); |
| 308 | match event { | 307 | match event { |
| 309 | DrmEvent::VBlank(crtc) => { | 308 | DrmEvent::VBlank(crtc) => { |
| 310 | let now = get_monotonic_time(); | 309 | let now = get_monotonic_time(); |
| @@ -349,8 +348,7 @@ impl Tty { | |||
| 349 | .unwrap() | 348 | .unwrap() |
| 350 | .message(&message, 0); | 349 | .message(&message, 0); |
| 351 | 350 | ||
| 352 | - let output = data | 351 | + let output = state |
| 353 | - .state | ||
| 354 | .niri | 352 | .niri |
| 355 | .global_space | 353 | .global_space |
| 356 | .outputs() | 354 | .outputs() |
| @@ -360,7 +358,7 @@ impl Tty { | |||
| 360 | }) | 358 | }) |
| 361 | .unwrap() | 359 | .unwrap() |
| 362 | .clone(); | 360 | .clone(); |
| 363 | - let output_state = data.state.niri.output_state.get_mut(&output).unwrap(); | 361 | + let output_state = state.niri.output_state.get_mut(&output).unwrap(); |
| 364 | 362 | ||
| 365 | // Mark the last frame as submitted. | 363 | // Mark the last frame as submitted. |
| 366 | match surface.compositor.frame_submitted() { | 364 | match surface.compositor.frame_submitted() { |
| @@ -398,7 +396,7 @@ impl Tty { | |||
| 398 | 396 | ||
| 399 | output_state.waiting_for_vblank = false; | 397 | output_state.waiting_for_vblank = false; |
| 400 | output_state.frame_clock.presented(presentation_time); | 398 | output_state.frame_clock.presented(presentation_time); |
| 401 | - data.state.niri.queue_redraw(output); | 399 | + state.niri.queue_redraw(output); |
| 402 | } | 400 | } |
| 403 | DrmEvent::Error(error) => error!("DRM error: {error}"), | 401 | DrmEvent::Error(error) => error!("DRM error: {error}"), |
| 404 | }; | 402 | }; |
src/backend/winit.rsmodified+11 -14
| @@ -18,9 +18,9 @@ use smithay::utils::Transform; | |||
| 18 | use smithay::wayland::dmabuf::DmabufFeedback; | 18 | use smithay::wayland::dmabuf::DmabufFeedback; |
| 19 | 19 | ||
| 20 | use crate::config::Config; | 20 | use crate::config::Config; |
| 21 | -use crate::niri::OutputRenderElements; | 21 | +use crate::niri::{OutputRenderElements, State}; |
| 22 | use crate::utils::get_monotonic_time; | 22 | use crate::utils::get_monotonic_time; |
| 23 | -use crate::{LoopData, Niri}; | 23 | +use crate::Niri; |
| 24 | 24 | ||
| 25 | pub struct Winit { | 25 | pub struct Winit { |
| 26 | config: Rc<RefCell<Config>>, | 26 | config: Rc<RefCell<Config>>, |
| @@ -31,7 +31,7 @@ pub struct Winit { | |||
| 31 | } | 31 | } |
| 32 | 32 | ||
| 33 | impl Winit { | 33 | impl Winit { |
| 34 | - pub fn new(config: Rc<RefCell<Config>>, event_loop: LoopHandle<LoopData>) -> Self { | 34 | + pub fn new(config: Rc<RefCell<Config>>, event_loop: LoopHandle<State>) -> Self { |
| 35 | let builder = WindowBuilder::new() | 35 | let builder = WindowBuilder::new() |
| 36 | .with_inner_size(LogicalSize::new(1280.0, 800.0)) | 36 | .with_inner_size(LogicalSize::new(1280.0, 800.0)) |
| 37 | // .with_resizable(false) | 37 | // .with_resizable(false) |
| @@ -79,10 +79,10 @@ impl Winit { | |||
| 79 | 79 | ||
| 80 | let timer = Timer::immediate(); | 80 | let timer = Timer::immediate(); |
| 81 | event_loop | 81 | event_loop |
| 82 | - .insert_source(timer, move |_, _, data| { | 82 | + .insert_source(timer, move |_, _, state| { |
| 83 | let res = winit_event_loop.dispatch_new_events(|event| match event { | 83 | let res = winit_event_loop.dispatch_new_events(|event| match event { |
| 84 | WinitEvent::Resized { size, .. } => { | 84 | WinitEvent::Resized { size, .. } => { |
| 85 | - let winit = data.state.backend.winit(); | 85 | + let winit = state.backend.winit(); |
| 86 | winit.output.change_current_state( | 86 | winit.output.change_current_state( |
| 87 | Some(Mode { | 87 | Some(Mode { |
| 88 | size, | 88 | size, |
| @@ -92,24 +92,21 @@ impl Winit { | |||
| 92 | None, | 92 | None, |
| 93 | None, | 93 | None, |
| 94 | ); | 94 | ); |
| 95 | - data.state.niri.output_resized(winit.output.clone()); | 95 | + state.niri.output_resized(winit.output.clone()); |
| 96 | } | 96 | } |
| 97 | - WinitEvent::Input(event) => data.state.process_input_event(event), | 97 | + WinitEvent::Input(event) => state.process_input_event(event), |
| 98 | WinitEvent::Focus(_) => (), | 98 | WinitEvent::Focus(_) => (), |
| 99 | - WinitEvent::Refresh => data | 99 | + WinitEvent::Refresh => state |
| 100 | - .state | ||
| 101 | .niri | 100 | .niri |
| 102 | - .queue_redraw(data.state.backend.winit().output.clone()), | 101 | + .queue_redraw(state.backend.winit().output.clone()), |
| 103 | }); | 102 | }); |
| 104 | 103 | ||
| 105 | // I want this to stop compiling if more errors are added. | 104 | // I want this to stop compiling if more errors are added. |
| 106 | #[allow(clippy::single_match)] | 105 | #[allow(clippy::single_match)] |
| 107 | match res { | 106 | match res { |
| 108 | Err(WinitError::WindowClosed) => { | 107 | Err(WinitError::WindowClosed) => { |
| 109 | - data.state.niri.stop_signal.stop(); | 108 | + state.niri.stop_signal.stop(); |
| 110 | - data.state | 109 | + state.niri.remove_output(&state.backend.winit().output); |
| 111 | - .niri | ||
| 112 | - .remove_output(&data.state.backend.winit().output); | ||
| 113 | } | 110 | } |
| 114 | Ok(()) => (), | 111 | Ok(()) => (), |
| 115 | } | 112 | } |
src/handlers/compositor.rsmodified+4 -4
| @@ -47,11 +47,11 @@ impl CompositorHandler for State { | |||
| 47 | let res = state | 47 | let res = state |
| 48 | .niri | 48 | .niri |
| 49 | .event_loop | 49 | .event_loop |
| 50 | - .insert_source(source, move |_, _, data| { | 50 | + .insert_source(source, move |_, _, state| { |
| 51 | - let display_handle = data.state.niri.display_handle.clone(); | 51 | + let display_handle = state.niri.display_handle.clone(); |
| 52 | - data.state | 52 | + state |
| 53 | .client_compositor_state(&client) | 53 | .client_compositor_state(&client) |
| 54 | - .blocker_cleared(&mut data.state, &display_handle); | 54 | + .blocker_cleared(state, &display_handle); |
| 55 | Ok(()) | 55 | Ok(()) |
| 56 | }); | 56 | }); |
| 57 | if res.is_ok() { | 57 | if res.is_ok() { |
src/main.rsmodified+6 -11
| @@ -38,10 +38,6 @@ struct Cli { | |||
| 38 | command: Vec<OsString>, | 38 | command: Vec<OsString>, |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | -pub struct LoopData { | ||
| 42 | - state: State, | ||
| 43 | -} | ||
| 44 | - | ||
| 45 | fn main() { | 41 | fn main() { |
| 46 | env::set_var("RUST_BACKTRACE", "1"); | 42 | env::set_var("RUST_BACKTRACE", "1"); |
| 47 | 43 | ||
| @@ -68,13 +64,12 @@ fn main() { | |||
| 68 | 64 | ||
| 69 | let mut event_loop = EventLoop::try_new().unwrap(); | 65 | let mut event_loop = EventLoop::try_new().unwrap(); |
| 70 | let display = Display::new().unwrap(); | 66 | let display = Display::new().unwrap(); |
| 71 | - let state = State::new( | 67 | + let mut state = State::new( |
| 72 | config, | 68 | config, |
| 73 | event_loop.handle(), | 69 | event_loop.handle(), |
| 74 | event_loop.get_signal(), | 70 | event_loop.get_signal(), |
| 75 | display, | 71 | display, |
| 76 | ); | 72 | ); |
| 77 | - let mut data = LoopData { state }; | ||
| 78 | 73 | ||
| 79 | // Spawn commands from cli and auto-start. | 74 | // Spawn commands from cli and auto-start. |
| 80 | if let Some((command, args)) = cli.command.split_first() { | 75 | if let Some((command, args)) = cli.command.split_first() { |
| @@ -88,17 +83,17 @@ fn main() { | |||
| 88 | } | 83 | } |
| 89 | 84 | ||
| 90 | event_loop | 85 | event_loop |
| 91 | - .run(None, &mut data, move |data| { | 86 | + .run(None, &mut state, move |state| { |
| 92 | let _span = tracy_client::span!("loop callback"); | 87 | let _span = tracy_client::span!("loop callback"); |
| 93 | 88 | ||
| 94 | // These should be called periodically, before flushing the clients. | 89 | // These should be called periodically, before flushing the clients. |
| 95 | - data.state.niri.monitor_set.refresh(); | 90 | + state.niri.monitor_set.refresh(); |
| 96 | - data.state.niri.popups.cleanup(); | 91 | + state.niri.popups.cleanup(); |
| 97 | - data.state.update_focus(); | 92 | + state.update_focus(); |
| 98 | 93 | ||
| 99 | { | 94 | { |
| 100 | let _span = tracy_client::span!("flush_clients"); | 95 | let _span = tracy_client::span!("flush_clients"); |
| 101 | - data.state.niri.display_handle.flush_clients().unwrap(); | 96 | + state.niri.display_handle.flush_clients().unwrap(); |
| 102 | } | 97 | } |
| 103 | }) | 98 | }) |
| 104 | .unwrap(); | 99 | .unwrap(); |
src/niri.rsmodified+24 -28
| @@ -70,12 +70,11 @@ use crate::frame_clock::FrameClock; | |||
| 70 | use crate::layout::{MonitorRenderElement, MonitorSet}; | 70 | use crate::layout::{MonitorRenderElement, MonitorSet}; |
| 71 | use crate::pw_utils::{Cast, PipeWire}; | 71 | use crate::pw_utils::{Cast, PipeWire}; |
| 72 | use crate::utils::{center, get_monotonic_time, load_default_cursor, make_screenshot_path}; | 72 | use crate::utils::{center, get_monotonic_time, load_default_cursor, make_screenshot_path}; |
| 73 | -use crate::LoopData; | ||
| 74 | 73 | ||
| 75 | pub struct Niri { | 74 | pub struct Niri { |
| 76 | pub config: Rc<RefCell<Config>>, | 75 | pub config: Rc<RefCell<Config>>, |
| 77 | 76 | ||
| 78 | - pub event_loop: LoopHandle<'static, LoopData>, | 77 | + pub event_loop: LoopHandle<'static, State>, |
| 79 | pub stop_signal: LoopSignal, | 78 | pub stop_signal: LoopSignal, |
| 80 | pub display_handle: DisplayHandle, | 79 | pub display_handle: DisplayHandle, |
| 81 | 80 | ||
| @@ -139,7 +138,7 @@ pub struct State { | |||
| 139 | impl State { | 138 | impl State { |
| 140 | pub fn new( | 139 | pub fn new( |
| 141 | config: Config, | 140 | config: Config, |
| 142 | - event_loop: LoopHandle<'static, LoopData>, | 141 | + event_loop: LoopHandle<'static, State>, |
| 143 | stop_signal: LoopSignal, | 142 | stop_signal: LoopSignal, |
| 144 | display: Display<State>, | 143 | display: Display<State>, |
| 145 | ) -> Self { | 144 | ) -> Self { |
| @@ -201,7 +200,7 @@ impl State { | |||
| 201 | impl Niri { | 200 | impl Niri { |
| 202 | pub fn new( | 201 | pub fn new( |
| 203 | config: Rc<RefCell<Config>>, | 202 | config: Rc<RefCell<Config>>, |
| 204 | - event_loop: LoopHandle<'static, LoopData>, | 203 | + event_loop: LoopHandle<'static, State>, |
| 205 | stop_signal: LoopSignal, | 204 | stop_signal: LoopSignal, |
| 206 | display: Display<State>, | 205 | display: Display<State>, |
| 207 | backend: &Backend, | 206 | backend: &Backend, |
| @@ -244,9 +243,8 @@ impl Niri { | |||
| 244 | let socket_source = ListeningSocketSource::new_auto().unwrap(); | 243 | let socket_source = ListeningSocketSource::new_auto().unwrap(); |
| 245 | let socket_name = socket_source.socket_name().to_os_string(); | 244 | let socket_name = socket_source.socket_name().to_os_string(); |
| 246 | event_loop | 245 | event_loop |
| 247 | - .insert_source(socket_source, move |client, _, data| { | 246 | + .insert_source(socket_source, move |client, _, state| { |
| 248 | - if let Err(err) = data | 247 | + if let Err(err) = state |
| 249 | - .state | ||
| 250 | .niri | 248 | .niri |
| 251 | .display_handle | 249 | .display_handle |
| 252 | .insert_client(client, Arc::new(ClientState::default())) | 250 | .insert_client(client, Arc::new(ClientState::default())) |
| @@ -273,7 +271,7 @@ impl Niri { | |||
| 273 | event_loop | 271 | event_loop |
| 274 | .insert_source(from_screen_cast, { | 272 | .insert_source(from_screen_cast, { |
| 275 | let to_niri = to_niri.clone(); | 273 | let to_niri = to_niri.clone(); |
| 276 | - move |event, _, data| match event { | 274 | + move |event, _, state| match event { |
| 277 | calloop::channel::Event::Msg(msg) => match msg { | 275 | calloop::channel::Event::Msg(msg) => match msg { |
| 278 | ToNiriMsg::StartCast { | 276 | ToNiriMsg::StartCast { |
| 279 | session_id, | 277 | session_id, |
| @@ -285,7 +283,7 @@ impl Niri { | |||
| 285 | 283 | ||
| 286 | debug!(session_id, "StartCast"); | 284 | debug!(session_id, "StartCast"); |
| 287 | 285 | ||
| 288 | - let gbm = match data.state.backend.gbm_device() { | 286 | + let gbm = match state.backend.gbm_device() { |
| 289 | Some(gbm) => gbm, | 287 | Some(gbm) => gbm, |
| 290 | None => { | 288 | None => { |
| 291 | debug!("no GBM device available"); | 289 | debug!("no GBM device available"); |
| @@ -293,7 +291,7 @@ impl Niri { | |||
| 293 | } | 291 | } |
| 294 | }; | 292 | }; |
| 295 | 293 | ||
| 296 | - let pw = data.state.niri.pipewire.as_ref().unwrap(); | 294 | + let pw = state.niri.pipewire.as_ref().unwrap(); |
| 297 | match pw.start_cast( | 295 | match pw.start_cast( |
| 298 | to_niri.clone(), | 296 | to_niri.clone(), |
| 299 | gbm, | 297 | gbm, |
| @@ -303,7 +301,7 @@ impl Niri { | |||
| 303 | signal_ctx, | 301 | signal_ctx, |
| 304 | ) { | 302 | ) { |
| 305 | Ok(cast) => { | 303 | Ok(cast) => { |
| 306 | - data.state.niri.casts.push(cast); | 304 | + state.niri.casts.push(cast); |
| 307 | } | 305 | } |
| 308 | Err(err) => { | 306 | Err(err) => { |
| 309 | warn!("error starting screencast: {err:?}"); | 307 | warn!("error starting screencast: {err:?}"); |
| @@ -321,20 +319,19 @@ impl Niri { | |||
| 321 | 319 | ||
| 322 | debug!(session_id, "StopCast"); | 320 | debug!(session_id, "StopCast"); |
| 323 | 321 | ||
| 324 | - for i in (0..data.state.niri.casts.len()).rev() { | 322 | + for i in (0..state.niri.casts.len()).rev() { |
| 325 | - let cast = &data.state.niri.casts[i]; | 323 | + let cast = &state.niri.casts[i]; |
| 326 | if cast.session_id != session_id { | 324 | if cast.session_id != session_id { |
| 327 | continue; | 325 | continue; |
| 328 | } | 326 | } |
| 329 | 327 | ||
| 330 | - let cast = data.state.niri.casts.swap_remove(i); | 328 | + let cast = state.niri.casts.swap_remove(i); |
| 331 | if let Err(err) = cast.stream.disconnect() { | 329 | if let Err(err) = cast.stream.disconnect() { |
| 332 | warn!("error disconnecting stream: {err:?}"); | 330 | warn!("error disconnecting stream: {err:?}"); |
| 333 | } | 331 | } |
| 334 | } | 332 | } |
| 335 | 333 | ||
| 336 | - let server = | 334 | + let server = state.niri.zbus_conn.as_ref().unwrap().object_server(); |
| 337 | - data.state.niri.zbus_conn.as_ref().unwrap().object_server(); | ||
| 338 | let path = | 335 | let path = |
| 339 | format!("/org/gnome/Mutter/ScreenCast/Session/u{}", session_id); | 336 | format!("/org/gnome/Mutter/ScreenCast/Session/u{}", session_id); |
| 340 | if let Ok(iface) = | 337 | if let Ok(iface) = |
| @@ -360,11 +357,11 @@ impl Niri { | |||
| 360 | let (to_niri, from_screenshot) = calloop::channel::channel(); | 357 | let (to_niri, from_screenshot) = calloop::channel::channel(); |
| 361 | let (to_screenshot, from_niri) = async_channel::unbounded(); | 358 | let (to_screenshot, from_niri) = async_channel::unbounded(); |
| 362 | event_loop | 359 | event_loop |
| 363 | - .insert_source(from_screenshot, move |event, _, data| match event { | 360 | + .insert_source(from_screenshot, move |event, _, state| match event { |
| 364 | calloop::channel::Event::Msg(ScreenshotToNiri::TakeScreenshot { | 361 | calloop::channel::Event::Msg(ScreenshotToNiri::TakeScreenshot { |
| 365 | include_cursor, | 362 | include_cursor, |
| 366 | }) => { | 363 | }) => { |
| 367 | - let renderer = data.state.backend.renderer(); | 364 | + let renderer = state.backend.renderer(); |
| 368 | let on_done = { | 365 | let on_done = { |
| 369 | let to_screenshot = to_screenshot.clone(); | 366 | let to_screenshot = to_screenshot.clone(); |
| 370 | move |path| { | 367 | move |path| { |
| @@ -375,10 +372,9 @@ impl Niri { | |||
| 375 | } | 372 | } |
| 376 | }; | 373 | }; |
| 377 | 374 | ||
| 378 | - let res = | 375 | + let res = state |
| 379 | - data.state | 376 | + .niri |
| 380 | - .niri | 377 | + .screenshot_all_outputs(renderer, include_cursor, on_done); |
| 381 | - .screenshot_all_outputs(renderer, include_cursor, on_done); | ||
| 382 | 378 | ||
| 383 | if let Err(err) = res { | 379 | if let Err(err) = res { |
| 384 | warn!("error taking a screenshot: {err:?}"); | 380 | warn!("error taking a screenshot: {err:?}"); |
| @@ -536,10 +532,10 @@ impl Niri { | |||
| 536 | 532 | ||
| 537 | let display_source = Generic::new(display, Interest::READ, Mode::Level); | 533 | let display_source = Generic::new(display, Interest::READ, Mode::Level); |
| 538 | event_loop | 534 | event_loop |
| 539 | - .insert_source(display_source, |_, display, data| { | 535 | + .insert_source(display_source, |_, display, state| { |
| 540 | // SAFETY: we don't drop the display. | 536 | // SAFETY: we don't drop the display. |
| 541 | unsafe { | 537 | unsafe { |
| 542 | - display.get_mut().dispatch_clients(&mut data.state).unwrap(); | 538 | + display.get_mut().dispatch_clients(state).unwrap(); |
| 543 | } | 539 | } |
| 544 | Ok(PostAction::Continue) | 540 | Ok(PostAction::Continue) |
| 545 | }) | 541 | }) |
| @@ -624,8 +620,8 @@ impl Niri { | |||
| 624 | self.event_loop | 620 | self.event_loop |
| 625 | .insert_source( | 621 | .insert_source( |
| 626 | Timer::from_duration(Duration::from_secs(10)), | 622 | Timer::from_duration(Duration::from_secs(10)), |
| 627 | - move |_, _, data| { | 623 | + move |_, _, state| { |
| 628 | - data.state | 624 | + state |
| 629 | .niri | 625 | .niri |
| 630 | .display_handle | 626 | .display_handle |
| 631 | .remove_global::<State>(global.clone()); | 627 | .remove_global::<State>(global.clone()); |
| @@ -788,8 +784,8 @@ impl Niri { | |||
| 788 | 784 | ||
| 789 | // Timer::immediate() adds a millisecond of delay for some reason. | 785 | // Timer::immediate() adds a millisecond of delay for some reason. |
| 790 | // This should be fixed in calloop v0.11: https://github.com/Smithay/calloop/issues/142 | 786 | // This should be fixed in calloop v0.11: https://github.com/Smithay/calloop/issues/142 |
| 791 | - let idle = self.event_loop.insert_idle(move |data| { | 787 | + let idle = self.event_loop.insert_idle(move |state| { |
| 792 | - data.state.niri.redraw(&mut data.state.backend, &output); | 788 | + state.niri.redraw(&mut state.backend, &output); |
| 793 | }); | 789 | }); |
| 794 | state.queued_redraw = Some(idle); | 790 | state.queued_redraw = Some(idle); |
| 795 | } | 791 | } |
src/pw_utils.rsmodified+2 -2
| @@ -30,7 +30,7 @@ use smithay::reexports::gbm::Modifier; | |||
| 30 | use zbus::SignalContext; | 30 | use zbus::SignalContext; |
| 31 | 31 | ||
| 32 | use crate::dbus::mutter_screen_cast::{self, CursorMode, ToNiriMsg}; | 32 | use crate::dbus::mutter_screen_cast::{self, CursorMode, ToNiriMsg}; |
| 33 | -use crate::LoopData; | 33 | +use crate::niri::State; |
| 34 | 34 | ||
| 35 | pub struct PipeWire { | 35 | pub struct PipeWire { |
| 36 | _context: Context<MainLoop>, | 36 | _context: Context<MainLoop>, |
| @@ -50,7 +50,7 @@ pub struct Cast { | |||
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | impl PipeWire { | 52 | impl PipeWire { |
| 53 | - pub fn new(event_loop: &LoopHandle<'static, LoopData>) -> anyhow::Result<Self> { | 53 | + pub fn new(event_loop: &LoopHandle<'static, State>) -> anyhow::Result<Self> { |
| 54 | let main_loop = MainLoop::new().context("error creating MainLoop")?; | 54 | let main_loop = MainLoop::new().context("error creating MainLoop")?; |
| 55 | let context = Context::new(&main_loop).context("error creating Context")?; | 55 | let context = Context::new(&main_loop).context("error creating Context")?; |
| 56 | let core = context.connect(None).context("error creating Core")?; | 56 | let core = context.connect(None).context("error creating Core")?; |