forge
Explore
Log in

Don't you dare go Hollow

tty: reset surface state after changing monitor state

Browse files at this commit

b813f99abd2d6e09eb72e8c0083e92b486b4b210Christian MeisslParent: d9b9cec
changing the "ACTIVE" property of a surface requires
to re-evaluate the surface state.
Cargo.lockmodified+2 -2
@@ -2716,7 +2716,7 @@ checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7"
27162716 [[package]]
27172717 name = "smithay"
27182718 version = "0.3.0"
2719-source = "git+https://github.com/Smithay/smithay.git#4a1b3ea4a1832089bac29fa4f76d57cd24745bde"
2719+source = "git+https://github.com/Smithay/smithay.git#b9f6a478cf462c9274bb366cf62b04cee5a03466"
27202720 dependencies = [
27212721 "appendlist",
27222722 "bitflags 2.4.2",
@@ -2788,7 +2788,7 @@ dependencies = [
27882788 [[package]]
27892789 name = "smithay-drm-extras"
27902790 version = "0.1.0"
2791-source = "git+https://github.com/Smithay/smithay.git#4a1b3ea4a1832089bac29fa4f76d57cd24745bde"
2791+source = "git+https://github.com/Smithay/smithay.git#b9f6a478cf462c9274bb366cf62b04cee5a03466"
27922792 dependencies = [
27932793 "drm",
27942794 "edid-rs",
src/backend/mod.rsmodified+1 -1
@@ -138,7 +138,7 @@ impl Backend {
138138 }
139139 }
140140
141- pub fn set_monitors_active(&self, active: bool) {
141+ pub fn set_monitors_active(&mut self, active: bool) {
142142 match self {
143143 Backend::Tty(tty) => tty.set_monitors_active(active),
144144 Backend::Winit(_) => (),
src/backend/tty.rsmodified+18 -6
@@ -728,7 +728,7 @@ impl Tty {
728728
729729 // Power on all monitors if necessary and queue a redraw on the new one.
730730 niri.event_loop.insert_idle(move |state| {
731- state.niri.activate_monitors(&state.backend);
731+ state.niri.activate_monitors(&mut state.backend);
732732 state.niri.queue_redraw(output);
733733 });
734734
@@ -1031,7 +1031,7 @@ impl Tty {
10311031 niri.send_dmabuf_feedbacks(output, dmabuf_feedback, &res.states);
10321032 }
10331033
1034- if res.damage.is_some() {
1034+ if !res.is_empty {
10351035 let presentation_feedbacks =
10361036 niri.take_presentation_feedbacks(output, &res.states);
10371037 let data = (presentation_feedbacks, target_presentation_time);
@@ -1196,10 +1196,22 @@ impl Tty {
11961196 self.devices.get(&self.primary_node).map(|d| d.gbm.clone())
11971197 }
11981198
1199- pub fn set_monitors_active(&self, active: bool) {
1200- for device in self.devices.values() {
1201- for crtc in device.surfaces.keys() {
1202- set_crtc_active(&device.drm, *crtc, active);
1199+ pub fn set_monitors_active(&mut self, active: bool) {
1200+ // We only disable the CRTC here, this will also reset the
1201+ // surface state so that the next call to `render_frame` will
1202+ // always produce a new frame and `queue_frame` will change
1203+ // the CRTC to active. This makes sure we always enable a CRTC
1204+ // within an atomic operation.
1205+ if active {
1206+ return;
1207+ }
1208+
1209+ for device in self.devices.values_mut() {
1210+ for (crtc, surface) in device.surfaces.iter_mut() {
1211+ set_crtc_active(&device.drm, *crtc, false);
1212+ if let Err(err) = surface.compositor.reset_state() {
1213+ warn!("error resetting surface state: {err:?}");
1214+ }
12031215 }
12041216 }
12051217 }
src/input.rsmodified+2 -2
@@ -51,7 +51,7 @@ impl State {
5151
5252 // Power on monitors if they were off.
5353 if should_activate_monitors(&event) {
54- self.niri.activate_monitors(&self.backend);
54+ self.niri.activate_monitors(&mut self.backend);
5555 }
5656
5757 let hide_hotkey_overlay =
@@ -284,7 +284,7 @@ impl State {
284284 self.niri.suppressed_keys.clear();
285285 }
286286 Action::PowerOffMonitors => {
287- self.niri.deactivate_monitors(&self.backend);
287+ self.niri.deactivate_monitors(&mut self.backend);
288288 }
289289 Action::ToggleDebugTint => {
290290 self.backend.toggle_debug_tint();
src/niri.rsmodified+2 -2
@@ -1310,7 +1310,7 @@ impl Niri {
13101310 self.queue_redraw(output);
13111311 }
13121312
1313- pub fn deactivate_monitors(&mut self, backend: &Backend) {
1313+ pub fn deactivate_monitors(&mut self, backend: &mut Backend) {
13141314 if !self.monitors_active {
13151315 return;
13161316 }
@@ -1319,7 +1319,7 @@ impl Niri {
13191319 backend.set_monitors_active(false);
13201320 }
13211321
1322- pub fn activate_monitors(&mut self, backend: &Backend) {
1322+ pub fn activate_monitors(&mut self, backend: &mut Backend) {
13231323 if self.monitors_active {
13241324 return;
13251325 }