From b813f99abd2d6e09eb72e8c0083e92b486b4b210 Mon Sep 17 00:00:00 2001 From: Christian Meissl Date: Sun, 28 Jan 2024 16:18:52 +0100 Subject: tty: reset surface state after changing monitor state changing the "ACTIVE" property of a surface requires to re-evaluate the surface state. --- Cargo.lock | 4 ++-- src/backend/mod.rs | 2 +- src/backend/tty.rs | 24 ++++++++++++++++++------ src/input.rs | 4 ++-- src/niri.rs | 4 ++-- 5 files changed, 25 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bb2f5de1..78fd9803 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2716,7 +2716,7 @@ checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" [[package]] name = "smithay" version = "0.3.0" -source = "git+https://github.com/Smithay/smithay.git#4a1b3ea4a1832089bac29fa4f76d57cd24745bde" +source = "git+https://github.com/Smithay/smithay.git#b9f6a478cf462c9274bb366cf62b04cee5a03466" dependencies = [ "appendlist", "bitflags 2.4.2", @@ -2788,7 +2788,7 @@ dependencies = [ [[package]] name = "smithay-drm-extras" version = "0.1.0" -source = "git+https://github.com/Smithay/smithay.git#4a1b3ea4a1832089bac29fa4f76d57cd24745bde" +source = "git+https://github.com/Smithay/smithay.git#b9f6a478cf462c9274bb366cf62b04cee5a03466" dependencies = [ "drm", "edid-rs", diff --git a/src/backend/mod.rs b/src/backend/mod.rs index 595b8513..588a6d33 100644 --- a/src/backend/mod.rs +++ b/src/backend/mod.rs @@ -138,7 +138,7 @@ impl Backend { } } - pub fn set_monitors_active(&self, active: bool) { + pub fn set_monitors_active(&mut self, active: bool) { match self { Backend::Tty(tty) => tty.set_monitors_active(active), Backend::Winit(_) => (), diff --git a/src/backend/tty.rs b/src/backend/tty.rs index 85e3c998..c1fba4e1 100644 --- a/src/backend/tty.rs +++ b/src/backend/tty.rs @@ -728,7 +728,7 @@ impl Tty { // Power on all monitors if necessary and queue a redraw on the new one. niri.event_loop.insert_idle(move |state| { - state.niri.activate_monitors(&state.backend); + state.niri.activate_monitors(&mut state.backend); state.niri.queue_redraw(output); }); @@ -1031,7 +1031,7 @@ impl Tty { niri.send_dmabuf_feedbacks(output, dmabuf_feedback, &res.states); } - if res.damage.is_some() { + if !res.is_empty { let presentation_feedbacks = niri.take_presentation_feedbacks(output, &res.states); let data = (presentation_feedbacks, target_presentation_time); @@ -1196,10 +1196,22 @@ impl Tty { self.devices.get(&self.primary_node).map(|d| d.gbm.clone()) } - pub fn set_monitors_active(&self, active: bool) { - for device in self.devices.values() { - for crtc in device.surfaces.keys() { - set_crtc_active(&device.drm, *crtc, active); + pub fn set_monitors_active(&mut self, active: bool) { + // We only disable the CRTC here, this will also reset the + // surface state so that the next call to `render_frame` will + // always produce a new frame and `queue_frame` will change + // the CRTC to active. This makes sure we always enable a CRTC + // within an atomic operation. + if active { + return; + } + + for device in self.devices.values_mut() { + for (crtc, surface) in device.surfaces.iter_mut() { + set_crtc_active(&device.drm, *crtc, false); + if let Err(err) = surface.compositor.reset_state() { + warn!("error resetting surface state: {err:?}"); + } } } } diff --git a/src/input.rs b/src/input.rs index b9b91545..0b671b4d 100644 --- a/src/input.rs +++ b/src/input.rs @@ -51,7 +51,7 @@ impl State { // Power on monitors if they were off. if should_activate_monitors(&event) { - self.niri.activate_monitors(&self.backend); + self.niri.activate_monitors(&mut self.backend); } let hide_hotkey_overlay = @@ -284,7 +284,7 @@ impl State { self.niri.suppressed_keys.clear(); } Action::PowerOffMonitors => { - self.niri.deactivate_monitors(&self.backend); + self.niri.deactivate_monitors(&mut self.backend); } Action::ToggleDebugTint => { self.backend.toggle_debug_tint(); diff --git a/src/niri.rs b/src/niri.rs index 1bb8a6d0..e0f5a498 100644 --- a/src/niri.rs +++ b/src/niri.rs @@ -1310,7 +1310,7 @@ impl Niri { self.queue_redraw(output); } - pub fn deactivate_monitors(&mut self, backend: &Backend) { + pub fn deactivate_monitors(&mut self, backend: &mut Backend) { if !self.monitors_active { return; } @@ -1319,7 +1319,7 @@ impl Niri { backend.set_monitors_active(false); } - pub fn activate_monitors(&mut self, backend: &Backend) { + pub fn activate_monitors(&mut self, backend: &mut Backend) { if self.monitors_active { return; } -- cgit