aboutsummaryrefslogtreecommitdiff
path: root/src/niri.rs
diff options
context:
space:
mode:
authorIvan Molodetskikh <yalterz@gmail.com>2023-10-27 08:34:00 +0400
committerIvan Molodetskikh <yalterz@gmail.com>2023-10-29 10:45:24 +0400
commite73f33d6a3cfc8703d8ae79b97f29ad30bfa24e4 (patch)
treee317e2eab8cced62545b2b72a1d4b08fefe6867c /src/niri.rs
parent27e2648bd4d8b9f379d257862b54e01d84b923a5 (diff)
downloadniri-e73f33d6a3cfc8703d8ae79b97f29ad30bfa24e4.tar.gz
niri-e73f33d6a3cfc8703d8ae79b97f29ad30bfa24e4.tar.bz2
niri-e73f33d6a3cfc8703d8ae79b97f29ad30bfa24e4.zip
Draw background with a solid color buffer
Diffstat (limited to 'src/niri.rs')
-rw-r--r--src/niri.rs33
1 files changed, 25 insertions, 8 deletions
diff --git a/src/niri.rs b/src/niri.rs
index 0835fc94..91878e2e 100644
--- a/src/niri.rs
+++ b/src/niri.rs
@@ -86,8 +86,8 @@ use crate::layout::{output_size, Layout, MonitorRenderElement};
use crate::pw_utils::{Cast, PipeWire};
use crate::utils::{center, get_monotonic_time, make_screenshot_path, write_png_rgba8};
-pub const CLEAR_COLOR: [f32; 4] = [0.2, 0.2, 0.2, 1.];
-pub const CLEAR_COLOR_LOCKED: [f32; 4] = [0.3, 0.1, 0.1, 1.];
+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.];
pub struct Niri {
pub config: Rc<RefCell<Config>>,
@@ -169,6 +169,9 @@ pub struct OutputState {
/// If there are no commits, then we won't have a timer running, so the estimated sequence will
/// not increase.
pub current_estimated_sequence: Option<u32>,
+ /// Solid color buffer for the background that we use instead of clearing to avoid damage
+ /// tracking issues and make screenshots easier.
+ pub background_buffer: SolidColorBuffer,
pub lock_render_state: LockRenderState,
pub lock_surface: Option<LockSurface>,
pub lock_color_buffer: SolidColorBuffer,
@@ -750,6 +753,7 @@ impl Niri {
unfinished_animations_remain: false,
frame_clock: FrameClock::new(refresh_interval),
current_estimated_sequence: None,
+ background_buffer: SolidColorBuffer::new(size, CLEAR_COLOR),
lock_render_state,
lock_surface: None,
lock_color_buffer: SolidColorBuffer::new(size, CLEAR_COLOR_LOCKED),
@@ -817,12 +821,16 @@ impl Niri {
}
pub fn output_resized(&mut self, output: Output) {
+ let output_size = output_size(&output);
+ let is_locked = self.is_locked();
+
layer_map_for_output(&output).arrange();
self.layout.update_output_size(&output);
- let is_locked = self.is_locked();
if let Some(state) = self.output_state.get_mut(&output) {
- state.lock_color_buffer.resize(output_size(&output));
+ state.background_buffer.resize(output_size);
+
+ state.lock_color_buffer.resize(output_size);
if is_locked {
if let Some(lock_surface) = &state.lock_surface {
configure_lock_surface(lock_surface, &output);
@@ -1309,6 +1317,19 @@ impl Niri {
extend_from_layer(&mut elements, Layer::Bottom);
extend_from_layer(&mut elements, Layer::Background);
+ // Then the background.
+ let state = self.output_state.get(output).unwrap();
+ elements.push(
+ SolidColorRenderElement::from_buffer(
+ &state.background_buffer,
+ (0, 0),
+ output_scale,
+ 1.,
+ Kind::Unspecified,
+ )
+ .into(),
+ );
+
elements
}
@@ -2079,10 +2100,6 @@ fn render_to_dmabuf(
.render(size, Transform::Normal)
.context("error starting frame")?;
- frame
- .clear(CLEAR_COLOR, &[output_rect])
- .context("error clearing")?;
-
for element in elements.iter().rev() {
let src = element.src();
let dst = element.geometry(scale);