diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2023-09-14 22:28:26 +0400 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2023-09-14 22:43:24 +0400 |
| commit | 89f9e11f65d00290029e9fb1719f2165de5e8006 (patch) | |
| tree | 626d980fc1b7ef0a2f93f10c8829411b426b3995 /src | |
| parent | 092095ead005ff073344b723f00b08a5b845f186 (diff) | |
| download | niri-89f9e11f65d00290029e9fb1719f2165de5e8006.tar.gz niri-89f9e11f65d00290029e9fb1719f2165de5e8006.tar.bz2 niri-89f9e11f65d00290029e9fb1719f2165de5e8006.zip | |
Store Config as Rc<RefCell<>> field
Diffstat (limited to 'src')
| -rw-r--r-- | src/backend/mod.rs | 6 | ||||
| -rw-r--r-- | src/backend/tty.rs | 14 | ||||
| -rw-r--r-- | src/backend/winit.rs | 14 | ||||
| -rw-r--r-- | src/input.rs | 5 | ||||
| -rw-r--r-- | src/niri.rs | 47 |
5 files changed, 52 insertions, 34 deletions
diff --git a/src/backend/mod.rs b/src/backend/mod.rs index ea795921..8473ccc2 100644 --- a/src/backend/mod.rs +++ b/src/backend/mod.rs @@ -7,7 +7,6 @@ use smithay::backend::renderer::gles::GlesRenderer; use smithay::output::Output; use smithay::wayland::dmabuf::DmabufFeedback; -use crate::config::Config; use crate::input::CompositorMod; use crate::niri::OutputRenderElements; use crate::Niri; @@ -47,14 +46,13 @@ impl Backend { pub fn render( &mut self, - config: &Config, niri: &mut Niri, output: &Output, elements: &[OutputRenderElements<GlesRenderer>], ) -> Option<&DmabufFeedback> { match self { - Backend::Tty(tty) => tty.render(config, niri, output, elements), - Backend::Winit(winit) => winit.render(config, niri, output, elements), + Backend::Tty(tty) => tty.render(niri, output, elements), + Backend::Winit(winit) => winit.render(niri, output, elements), } } diff --git a/src/backend/tty.rs b/src/backend/tty.rs index f2144770..2fd17eca 100644 --- a/src/backend/tty.rs +++ b/src/backend/tty.rs @@ -1,6 +1,8 @@ +use std::cell::RefCell; use std::collections::{HashMap, HashSet}; use std::os::fd::FromRawFd; use std::path::{Path, PathBuf}; +use std::rc::Rc; use std::sync::{Mutex, Arc}; use std::time::Duration; @@ -42,6 +44,7 @@ const BACKGROUND_COLOR: [f32; 4] = [0.1, 0.1, 0.1, 1.]; const SUPPORTED_COLOR_FORMATS: &[Fourcc] = &[Fourcc::Argb8888, Fourcc::Abgr8888]; pub struct Tty { + config: Rc<RefCell<Config>>, session: LibSeatSession, udev_dispatcher: Dispatcher<'static, UdevBackend, LoopData>, primary_gpu_path: PathBuf, @@ -88,7 +91,7 @@ struct Surface { } impl Tty { - pub fn new(event_loop: LoopHandle<'static, LoopData>) -> Self { + pub fn new(config: Rc<RefCell<Config>>, event_loop: LoopHandle<'static, LoopData>) -> Self { let (session, notifier) = LibSeatSession::new().unwrap(); let seat_name = session.seat(); @@ -237,6 +240,7 @@ impl Tty { let primary_gpu_path = udev::primary_gpu(&seat_name).unwrap().unwrap(); Self { + config, session, udev_dispatcher, primary_gpu_path, @@ -627,7 +631,6 @@ impl Tty { pub fn render( &mut self, - config: &Config, niri: &mut Niri, output: &Output, elements: &[OutputRenderElements<GlesRenderer>], @@ -647,7 +650,12 @@ impl Tty { Ok(res) => { assert!(!res.needs_sync()); - if config.debug.wait_for_frame_completion_before_queueing { + if self + .config + .borrow() + .debug + .wait_for_frame_completion_before_queueing + { if let PrimaryPlaneElement::Swapchain(element) = res.primary_element { let _span = tracy_client::span!("wait for completion"); element.sync.wait(); diff --git a/src/backend/winit.rs b/src/backend/winit.rs index f30c0784..9f591e71 100644 --- a/src/backend/winit.rs +++ b/src/backend/winit.rs @@ -1,4 +1,6 @@ +use std::cell::RefCell; use std::collections::HashMap; +use std::rc::Rc; use std::sync::{Arc, Mutex}; use std::time::Duration; @@ -21,6 +23,7 @@ use crate::utils::get_monotonic_time; use crate::{LoopData, Niri}; pub struct Winit { + config: Rc<RefCell<Config>>, output: Output, backend: WinitGraphicsBackend<GlesRenderer>, damage_tracker: OutputDamageTracker, @@ -28,7 +31,7 @@ pub struct Winit { } impl Winit { - pub fn new(event_loop: LoopHandle<LoopData>) -> Self { + pub fn new(config: Rc<RefCell<Config>>, event_loop: LoopHandle<LoopData>) -> Self { let builder = WindowBuilder::new() .with_inner_size(LogicalSize::new(1280.0, 800.0)) // .with_resizable(false) @@ -105,6 +108,7 @@ impl Winit { .unwrap(); Self { + config, output, backend, damage_tracker, @@ -137,7 +141,6 @@ impl Winit { pub fn render( &mut self, - config: &Config, niri: &mut Niri, output: &Output, elements: &[OutputRenderElements<GlesRenderer>], @@ -151,7 +154,12 @@ impl Winit { .render_output(self.backend.renderer(), age, elements, [0.1, 0.1, 0.1, 1.0]) .unwrap(); if let Some(damage) = res.damage { - if config.debug.wait_for_frame_completion_before_queueing { + if self + .config + .borrow() + .debug + .wait_for_frame_completion_before_queueing + { let _span = tracy_client::span!("wait for completion"); res.sync.wait(); } diff --git a/src/input.rs b/src/input.rs index 3dfe7ae6..72cf9f77 100644 --- a/src/input.rs +++ b/src/input.rs @@ -123,7 +123,8 @@ impl State { time, |self_, mods, keysym| { if event.state() == KeyState::Pressed { - action(&self_.config, comp_mod, keysym, *mods).into() + let config = self_.niri.config.borrow(); + action(&config, comp_mod, keysym, *mods).into() } else { FilterResult::Forward } @@ -743,7 +744,7 @@ impl State { // According to Mutter code, this setting is specific to touchpads. let is_touchpad = device.config_tap_finger_count() > 0; if is_touchpad { - let c = &self.config.input.touchpad; + let c = &self.niri.config.borrow().input.touchpad; let _ = device.config_tap_set_enabled(c.tap); let _ = device.config_scroll_set_natural_scroll_enabled(c.natural_scroll); let _ = device.config_accel_set_speed(c.accel_speed); diff --git a/src/niri.rs b/src/niri.rs index 65a07d8f..6d497176 100644 --- a/src/niri.rs +++ b/src/niri.rs @@ -1,6 +1,8 @@ +use std::cell::RefCell; use std::collections::HashMap; use std::os::unix::io::AsRawFd; use std::process::Command; +use std::rc::Rc; use std::sync::{Arc, Mutex}; use std::time::Duration; use std::{env, thread}; @@ -68,6 +70,8 @@ use crate::utils::{center, get_monotonic_time, load_default_cursor}; use crate::LoopData; pub struct Niri { + pub config: Rc<RefCell<Config>>, + pub event_loop: LoopHandle<'static, LoopData>, pub stop_signal: LoopSignal, pub display_handle: DisplayHandle, @@ -125,7 +129,6 @@ pub struct OutputState { } pub struct State { - pub config: Config, pub backend: Backend, pub niri: Niri, } @@ -137,23 +140,21 @@ impl State { stop_signal: LoopSignal, display: &mut Display<State>, ) -> Self { + let config = Rc::new(RefCell::new(config)); + let has_display = env::var_os("WAYLAND_DISPLAY").is_some() || env::var_os("DISPLAY").is_some(); let mut backend = if has_display { - Backend::Winit(Winit::new(event_loop.clone())) + Backend::Winit(Winit::new(config.clone(), event_loop.clone())) } else { - Backend::Tty(Tty::new(event_loop.clone())) + Backend::Tty(Tty::new(config.clone(), event_loop.clone())) }; - let mut niri = Niri::new(&config, event_loop, stop_signal, display, &backend); + let mut niri = Niri::new(config.clone(), event_loop, stop_signal, display, &backend); backend.init(&mut niri); - Self { - config, - backend, - niri, - } + Self { backend, niri } } pub fn move_cursor(&mut self, location: Point<f64, Logical>) { @@ -194,13 +195,14 @@ impl State { impl Niri { pub fn new( - config: &Config, + config: Rc<RefCell<Config>>, event_loop: LoopHandle<'static, LoopData>, stop_signal: LoopSignal, display: &mut Display<State>, backend: &Backend, ) -> Self { let display_handle = display.handle(); + let config_ = config.borrow(); let compositor_state = CompositorState::new::<State>(&display_handle); let xdg_shell_state = XdgShellState::new_with_capabilities::<State>( @@ -220,11 +222,11 @@ impl Niri { let mut seat: Seat<State> = seat_state.new_wl_seat(&display_handle, backend.seat_name()); let xkb = XkbConfig { - rules: &config.input.keyboard.xkb.rules, - model: &config.input.keyboard.xkb.model, - layout: config.input.keyboard.xkb.layout.as_deref().unwrap_or("us"), - variant: &config.input.keyboard.xkb.variant, - options: config.input.keyboard.xkb.options.clone(), + rules: &config_.input.keyboard.xkb.rules, + model: &config_.input.keyboard.xkb.model, + layout: config_.input.keyboard.xkb.layout.as_deref().unwrap_or("us"), + variant: &config_.input.keyboard.xkb.variant, + options: config_.input.keyboard.xkb.options.clone(), }; seat.add_keyboard(xkb, 400, 30).unwrap(); seat.add_pointer(); @@ -387,7 +389,7 @@ impl Niri { ) .unwrap(); - if pipewire.is_some() && !config.debug.screen_cast_in_non_session_instances { + if pipewire.is_some() && !config_.debug.screen_cast_in_non_session_instances { conn = conn .name("org.gnome.Mutter.ScreenCast") .unwrap() @@ -435,7 +437,7 @@ impl Niri { warn!("error inhibiting power key: {err:?}"); } } - } else if pipewire.is_some() && config.debug.screen_cast_in_non_session_instances { + } else if pipewire.is_some() && config_.debug.screen_cast_in_non_session_instances { let conn = zbus::blocking::ConnectionBuilder::session() .unwrap() .name("org.gnome.Mutter.ScreenCast") @@ -466,7 +468,10 @@ impl Niri { }) .unwrap(); + drop(config_); Self { + config, + event_loop, stop_signal, display_handle, @@ -690,9 +695,7 @@ impl Niri { // Timer::immediate() adds a millisecond of delay for some reason. // This should be fixed in calloop v0.11: https://github.com/Smithay/calloop/issues/142 let idle = self.event_loop.insert_idle(move |data| { - data.state - .niri - .redraw(&data.state.config, &mut data.state.backend, &output); + data.state.niri.redraw(&mut data.state.backend, &output); }); state.queued_redraw = Some(idle); } @@ -837,7 +840,7 @@ impl Niri { elements } - fn redraw(&mut self, config: &Config, backend: &mut Backend, output: &Output) { + fn redraw(&mut self, backend: &mut Backend, output: &Output) { let _span = tracy_client::span!("Niri::redraw"); let state = self.output_state.get_mut(output).unwrap(); @@ -854,7 +857,7 @@ impl Niri { let elements = self.render(backend.renderer(), output); // Hand it over to the backend. - let dmabuf_feedback = backend.render(config, self, output, &elements); + let dmabuf_feedback = backend.render(self, output, &elements); // Send the dmabuf feedbacks. if let Some(feedback) = dmabuf_feedback { |
