forge
Explore
Log in

Don't you dare go Hollow

Move LoopData into niri file

Browse files at this commit

dcc6a557774c8af0dc62839308130ee6a71fc629Ivan MolodetskikhParent: 73d7a1d
src/backend/tty.rsmodified+30 -31
@@ -31,15 +31,15 @@ use smithay_drm_extras::drm_scanner::{DrmScanEvent, DrmScanner};
31 use smithay_drm_extras::edid::EdidInfo;31 use smithay_drm_extras::edid::EdidInfo;
32 32
33 use crate::input::{BackendAction, CompositorMod};33 use crate::input::{BackendAction, CompositorMod};
34-use crate::niri::OutputRenderElements;34+use crate::niri::{Data, OutputRenderElements};
35-use crate::{LoopData, Niri};35+use crate::Niri;
36 36
37 const BACKGROUND_COLOR: [f32; 4] = [0.1, 0.1, 0.1, 1.];37 const BACKGROUND_COLOR: [f32; 4] = [0.1, 0.1, 0.1, 1.];
38 const SUPPORTED_COLOR_FORMATS: &[Fourcc] = &[Fourcc::Argb8888, Fourcc::Abgr8888];38 const SUPPORTED_COLOR_FORMATS: &[Fourcc] = &[Fourcc::Argb8888, Fourcc::Abgr8888];
39 39
40 pub struct Tty {40 pub struct Tty {
41 session: LibSeatSession,41 session: LibSeatSession,
42- udev_dispatcher: Dispatcher<'static, UdevBackend, LoopData>,42+ udev_dispatcher: Dispatcher<'static, UdevBackend, Data>,
43 primary_gpu_path: PathBuf,43 primary_gpu_path: PathBuf,
44 output_device: Option<OutputDevice>,44 output_device: Option<OutputDevice>,
45 }45 }
@@ -69,45 +69,44 @@ struct TtyOutputState {
69 }69 }
70 70
71 impl Tty {71 impl Tty {
72- pub fn new(event_loop: LoopHandle<'static, LoopData>) -> Self {72+ pub fn new(event_loop: LoopHandle<'static, Data>) -> Self {
73 let (session, notifier) = LibSeatSession::new().unwrap();73 let (session, notifier) = LibSeatSession::new().unwrap();
74 let seat_name = session.seat();74 let seat_name = session.seat();
75 75
76 let udev_backend = UdevBackend::new(session.seat()).unwrap();76 let udev_backend = UdevBackend::new(session.seat()).unwrap();
77- let udev_dispatcher =77+ let udev_dispatcher = Dispatcher::new(udev_backend, move |event, _, data: &mut Data| {
78- Dispatcher::new(udev_backend, move |event, _, data: &mut LoopData| {78+ let tty = data.backend.tty().unwrap();
79- let tty = data.backend.tty().unwrap();79+ let niri = &mut data.niri;
80- let niri = &mut data.niri;
81-
82- match event {
83- UdevEvent::Added { device_id, path } => {
84- if !tty.session.is_active() {
85- debug!("skipping UdevEvent::Added as session is inactive");
86- return;
87- }
88 80
89- if let Err(err) = tty.device_added(device_id, &path, niri) {81+ match event {
90- warn!("error adding device: {err:?}");82+ UdevEvent::Added { device_id, path } => {
91- }83+ if !tty.session.is_active() {
84+ debug!("skipping UdevEvent::Added as session is inactive");
85+ return;
92 }86 }
93- UdevEvent::Changed { device_id } => {
94- if !tty.session.is_active() {
95- debug!("skipping UdevEvent::Changed as session is inactive");
96- return;
97- }
98 87
99- tty.device_changed(device_id, niri)88+ if let Err(err) = tty.device_added(device_id, &path, niri) {
89+ warn!("error adding device: {err:?}");
90+ }
91+ }
92+ UdevEvent::Changed { device_id } => {
93+ if !tty.session.is_active() {
94+ debug!("skipping UdevEvent::Changed as session is inactive");
95+ return;
100 }96 }
101- UdevEvent::Removed { device_id } => {
102- if !tty.session.is_active() {
103- debug!("skipping UdevEvent::Removed as session is inactive");
104- return;
105- }
106 97
107- tty.device_removed(device_id, niri)98+ tty.device_changed(device_id, niri)
99+ }
100+ UdevEvent::Removed { device_id } => {
101+ if !tty.session.is_active() {
102+ debug!("skipping UdevEvent::Removed as session is inactive");
103+ return;
108 }104 }
105+
106+ tty.device_removed(device_id, niri)
109 }107 }
110- });108+ }
109+ });
111 event_loop110 event_loop
112 .register_dispatcher(udev_dispatcher.clone())111 .register_dispatcher(udev_dispatcher.clone())
113 .unwrap();112 .unwrap();
src/backend/winit.rsmodified+3 -3
@@ -13,9 +13,9 @@ use smithay::reexports::winit::window::WindowBuilder;
13 use smithay::utils::Transform;13 use smithay::utils::Transform;
14 14
15 use crate::input::{BackendAction, CompositorMod};15 use crate::input::{BackendAction, CompositorMod};
16-use crate::niri::OutputRenderElements;16+use crate::niri::{Data, OutputRenderElements};
17 use crate::utils::get_monotonic_time;17 use crate::utils::get_monotonic_time;
18-use crate::{LoopData, Niri};18+use crate::Niri;
19 19
20 pub struct Winit {20 pub struct Winit {
21 output: Output,21 output: Output,
@@ -25,7 +25,7 @@ pub struct Winit {
25 }25 }
26 26
27 impl Winit {27 impl Winit {
28- pub fn new(event_loop: LoopHandle<LoopData>) -> Self {28+ pub fn new(event_loop: LoopHandle<Data>) -> Self {
29 let builder = WindowBuilder::new()29 let builder = WindowBuilder::new()
30 .with_inner_size(LogicalSize::new(1280.0, 800.0))30 .with_inner_size(LogicalSize::new(1280.0, 800.0))
31 // .with_resizable(false)31 // .with_resizable(false)
src/main.rsmodified+2 -37
@@ -15,11 +15,9 @@ mod utils;
15 use std::env;15 use std::env;
16 use std::ffi::OsString;16 use std::ffi::OsString;
17 17
18-use backend::{Backend, Tty, Winit};
19 use clap::Parser;18 use clap::Parser;
20-use niri::Niri;19+use niri::{Data, Niri};
21 use smithay::reexports::calloop::EventLoop;20 use smithay::reexports::calloop::EventLoop;
22-use smithay::reexports::wayland_server::Display;
23 use tracing_subscriber::EnvFilter;21 use tracing_subscriber::EnvFilter;
24 22
25 #[derive(Parser)]23 #[derive(Parser)]
@@ -30,15 +28,6 @@ struct Cli {
30 command: Vec<OsString>,28 command: Vec<OsString>,
31 }29 }
32 30
33-pub struct LoopData {
34- niri: Niri,
35- backend: Backend,
36-
37- // Last so that it's dropped after the Smithay state in Niri and related state in Tty.
38- // Otherwise it will segfault on quit.
39- display: Display<Niri>,
40-}
41-
42 fn main() {31 fn main() {
43 env::set_var("RUST_BACKTRACE", "1");32 env::set_var("RUST_BACKTRACE", "1");
44 33
@@ -54,31 +43,7 @@ fn main() {
54 let _client = tracy_client::Client::start();43 let _client = tracy_client::Client::start();
55 44
56 let mut event_loop = EventLoop::try_new().unwrap();45 let mut event_loop = EventLoop::try_new().unwrap();
57-46+ let mut data = Data::new(event_loop.handle(), event_loop.get_signal());
58- let has_display = env::var_os("WAYLAND_DISPLAY").is_some() || env::var_os("DISPLAY").is_some();
59-
60- let backend = if has_display {
61- Backend::Winit(Winit::new(event_loop.handle()))
62- } else {
63- Backend::Tty(Tty::new(event_loop.handle()))
64- };
65-
66- let mut display = Display::new().unwrap();
67- let niri = Niri::new(
68- event_loop.handle(),
69- event_loop.get_signal(),
70- &mut display,
71- backend.seat_name(),
72- );
73-
74- let mut data = LoopData {
75- niri,
76- display,
77-
78- backend,
79- };
80-
81- data.backend.init(&mut data.niri);
82 47
83 if let Some((command, args)) = cli.command.split_first() {48 if let Some((command, args)) = cli.command.split_first() {
84 if let Err(err) = std::process::Command::new(command).args(args).spawn() {49 if let Err(err) = std::process::Command::new(command).args(args).spawn() {
src/niri.rsmodified+33 -5
@@ -2,8 +2,8 @@ use std::collections::HashMap;
2 use std::os::unix::io::AsRawFd;2 use std::os::unix::io::AsRawFd;
3 use std::process::Command;3 use std::process::Command;
4 use std::sync::{Arc, Mutex};4 use std::sync::{Arc, Mutex};
5-use std::thread;
6 use std::time::Duration;5 use std::time::Duration;
6+use std::{env, thread};
7 7
8 use anyhow::Context;8 use anyhow::Context;
9 use directories::UserDirs;9 use directories::UserDirs;
@@ -53,16 +53,15 @@ use smithay::wayland::socket::ListeningSocketSource;
53 use smithay::wayland::tablet_manager::TabletManagerState;53 use smithay::wayland::tablet_manager::TabletManagerState;
54 use time::OffsetDateTime;54 use time::OffsetDateTime;
55 55
56-use crate::backend::Backend;56+use crate::backend::{Backend, Tty, Winit};
57 use crate::dbus::mutter_service_channel::ServiceChannel;57 use crate::dbus::mutter_service_channel::ServiceChannel;
58 use crate::frame_clock::FrameClock;58 use crate::frame_clock::FrameClock;
59 use crate::layout::{MonitorRenderElement, MonitorSet};59 use crate::layout::{MonitorRenderElement, MonitorSet};
60 use crate::utils::{center, get_monotonic_time, load_default_cursor};60 use crate::utils::{center, get_monotonic_time, load_default_cursor};
61-use crate::LoopData;
62 61
63 pub struct Niri {62 pub struct Niri {
64 pub start_time: std::time::Instant,63 pub start_time: std::time::Instant,
65- pub event_loop: LoopHandle<'static, LoopData>,64+ pub event_loop: LoopHandle<'static, Data>,
66 pub stop_signal: LoopSignal,65 pub stop_signal: LoopSignal,
67 pub display_handle: DisplayHandle,66 pub display_handle: DisplayHandle,
68 67
@@ -113,9 +112,38 @@ pub struct OutputState {
113 pub frame_clock: FrameClock,112 pub frame_clock: FrameClock,
114 }113 }
115 114
115+pub struct Data {
116+ pub display: Display<Niri>,
117+ pub backend: Backend,
118+ pub niri: Niri,
119+}
120+
121+impl Data {
122+ pub fn new(event_loop: LoopHandle<'static, Self>, stop_signal: LoopSignal) -> Self {
123+ let has_display =
124+ env::var_os("WAYLAND_DISPLAY").is_some() || env::var_os("DISPLAY").is_some();
125+
126+ let mut backend = if has_display {
127+ Backend::Winit(Winit::new(event_loop.clone()))
128+ } else {
129+ Backend::Tty(Tty::new(event_loop.clone()))
130+ };
131+
132+ let mut display = Display::new().unwrap();
133+ let mut niri = Niri::new(event_loop, stop_signal, &mut display, backend.seat_name());
134+ backend.init(&mut niri);
135+
136+ Self {
137+ display,
138+ backend,
139+ niri,
140+ }
141+ }
142+}
143+
116 impl Niri {144 impl Niri {
117 pub fn new(145 pub fn new(
118- event_loop: LoopHandle<'static, LoopData>,146+ event_loop: LoopHandle<'static, Data>,
119 stop_signal: LoopSignal,147 stop_signal: LoopSignal,
120 display: &mut Display<Self>,148 display: &mut Display<Self>,
121 seat_name: String,149 seat_name: String,