diff options
| author | Anant Sharma <anantsh.88@gmail.com> | 2024-07-25 23:41:33 +0530 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2024-07-26 11:51:29 +0300 |
| commit | 689338f05960f75082f71d213666978ebc431b40 (patch) | |
| tree | fe36dadeaa0e5749e0bbb95305baa906fc26ebfc | |
| parent | eee770514fb8dc1a2825d21070c7c54373d1aa05 (diff) | |
| download | niri-689338f05960f75082f71d213666978ebc431b40.tar.gz niri-689338f05960f75082f71d213666978ebc431b40.tar.bz2 niri-689338f05960f75082f71d213666978ebc431b40.zip | |
Add background color option for output
| -rw-r--r-- | niri-config/src/lib.rs | 9 | ||||
| -rw-r--r-- | src/niri.rs | 31 |
2 files changed, 37 insertions, 3 deletions
diff --git a/niri-config/src/lib.rs b/niri-config/src/lib.rs index 14446f87..9bb774f6 100644 --- a/niri-config/src/lib.rs +++ b/niri-config/src/lib.rs @@ -18,6 +18,8 @@ use smithay::input::keyboard::xkb::{keysym_from_name, KEYSYM_CASE_INSENSITIVE}; use smithay::input::keyboard::{Keysym, XkbConfig}; use smithay::reexports::input; +pub const DEFAULT_BACKGROUND_COLOR: Color = Color::from_array_unpremul([0.2, 0.2, 0.2, 1.]); + #[derive(knuffel::Decode, Debug, PartialEq)] pub struct Config { #[knuffel(child, default)] @@ -323,6 +325,8 @@ pub struct Output { pub mode: Option<ConfiguredMode>, #[knuffel(child)] pub variable_refresh_rate: bool, + #[knuffel(child, default = DEFAULT_BACKGROUND_COLOR)] + pub background_color: Color, } impl Default for Output { @@ -335,6 +339,7 @@ impl Default for Output { position: None, mode: None, variable_refresh_rate: false, + background_color: DEFAULT_BACKGROUND_COLOR, } } } @@ -551,7 +556,7 @@ impl Color { } } - pub fn from_array_unpremul([r, g, b, a]: [f32; 4]) -> Self { + pub const fn from_array_unpremul([r, g, b, a]: [f32; 4]) -> Self { Self { r, g, b, a } } @@ -2696,6 +2701,7 @@ mod tests { position x=10 y=20 mode "1920x1080@144" variable-refresh-rate + background-color "rgba(25, 25, 102, 1.0)" } layout { @@ -2879,6 +2885,7 @@ mod tests { refresh: Some(144.), }), variable_refresh_rate: true, + background_color: Color::from_rgba8_unpremul(25, 25, 102, 255), }]), layout: Layout { focus_ring: FocusRing { diff --git a/src/niri.rs b/src/niri.rs index 664aea67..aaf2ef7f 100644 --- a/src/niri.rs +++ b/src/niri.rs @@ -13,6 +13,7 @@ use anyhow::{ensure, Context}; use calloop::futures::Scheduler; use niri_config::{ Config, FloatOrInt, Key, Modifiers, PreviewRender, TrackLayout, WorkspaceReference, + DEFAULT_BACKGROUND_COLOR, }; use niri_ipc::Workspace; use smithay::backend::allocator::Fourcc; @@ -141,7 +142,6 @@ use crate::utils::{ use crate::window::{InitialConfigureState, Mapped, ResolvedWindowRules, Unmapped, WindowRef}; use crate::{animation, niri_render_elements}; -const CLEAR_COLOR: [f32; 4] = [0.2, 0.2, 0.2, 1.]; const CLEAR_COLOR_LOCKED: [f32; 4] = [0.3, 0.1, 0.1, 1.]; // We'll try to send frame callbacks at least once a second. We'll make a timer that fires once a @@ -1085,6 +1085,8 @@ impl State { pub fn reload_output_config(&mut self) { let mut resized_outputs = vec![]; + let mut recolored_outputs = vec![]; + for output in self.niri.global_space.outputs() { let name = output.name(); let config = self.niri.config.borrow_mut(); @@ -1120,11 +1122,29 @@ impl State { self.niri.ipc_outputs_changed = true; resized_outputs.push(output.clone()); } + + let mut background_color = config + .map(|c| c.background_color) + .unwrap_or(DEFAULT_BACKGROUND_COLOR) + .to_array_unpremul(); + background_color[3] = 1.; + + if let Some(state) = self.niri.output_state.get_mut(output) { + if state.background_buffer.color() != background_color { + state.background_buffer.set_color(background_color); + recolored_outputs.push(output.clone()); + } + } } + for output in resized_outputs { self.niri.output_resized(&output); } + for output in recolored_outputs { + self.niri.queue_redraw(&output); + } + self.backend.on_output_config_changed(&mut self.niri); self.niri.reposition_outputs(None); @@ -1935,6 +1955,13 @@ impl Niri { let mut transform = c .map(|c| ipc_transform_to_smithay(c.transform)) .unwrap_or(Transform::Normal); + + let mut background_color = c + .map(|c| c.background_color) + .unwrap_or(DEFAULT_BACKGROUND_COLOR) + .to_array_unpremul(); + background_color[3] = 1.; + // FIXME: fix winit damage on other transforms. if name == "winit" { transform = Transform::Flipped180; @@ -1966,7 +1993,7 @@ impl Niri { frame_clock: FrameClock::new(refresh_interval, vrr), last_drm_sequence: None, frame_callback_sequence: 0, - background_buffer: SolidColorBuffer::new(size, CLEAR_COLOR), + background_buffer: SolidColorBuffer::new(size, background_color), lock_render_state, lock_surface: None, lock_color_buffer: SolidColorBuffer::new(size, CLEAR_COLOR_LOCKED), |
