tty: reset surface state after changing monitor state
Browse files at this commitb813f99abd2d6e09eb72e8c0083e92b486b4b210Parent: d9b9cec5 changed files +25 -13
- Cargo.lock +2 -2
- src/backend/mod.rs +1 -1
- src/backend/tty.rs +18 -6
- src/input.rs +2 -2
- src/niri.rs +2 -2
Cargo.lockmodified+2 -2
| @@ -2716,7 +2716,7 @@ checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" | |||
| 2716 | [[package]] | 2716 | [[package]] |
| 2717 | name = "smithay" | 2717 | name = "smithay" |
| 2718 | version = "0.3.0" | 2718 | version = "0.3.0" |
| 2719 | -source = "git+https://github.com/Smithay/smithay.git#4a1b3ea4a1832089bac29fa4f76d57cd24745bde" | 2719 | +source = "git+https://github.com/Smithay/smithay.git#b9f6a478cf462c9274bb366cf62b04cee5a03466" |
| 2720 | dependencies = [ | 2720 | dependencies = [ |
| 2721 | "appendlist", | 2721 | "appendlist", |
| 2722 | "bitflags 2.4.2", | 2722 | "bitflags 2.4.2", |
| @@ -2788,7 +2788,7 @@ dependencies = [ | |||
| 2788 | [[package]] | 2788 | [[package]] |
| 2789 | name = "smithay-drm-extras" | 2789 | name = "smithay-drm-extras" |
| 2790 | version = "0.1.0" | 2790 | version = "0.1.0" |
| 2791 | -source = "git+https://github.com/Smithay/smithay.git#4a1b3ea4a1832089bac29fa4f76d57cd24745bde" | 2791 | +source = "git+https://github.com/Smithay/smithay.git#b9f6a478cf462c9274bb366cf62b04cee5a03466" |
| 2792 | dependencies = [ | 2792 | dependencies = [ |
| 2793 | "drm", | 2793 | "drm", |
| 2794 | "edid-rs", | 2794 | "edid-rs", |
src/backend/mod.rsmodified+1 -1
| @@ -138,7 +138,7 @@ impl Backend { | |||
| 138 | } | 138 | } |
| 139 | } | 139 | } |
| 140 | 140 | ||
| 141 | - pub fn set_monitors_active(&self, active: bool) { | 141 | + pub fn set_monitors_active(&mut self, active: bool) { |
| 142 | match self { | 142 | match self { |
| 143 | Backend::Tty(tty) => tty.set_monitors_active(active), | 143 | Backend::Tty(tty) => tty.set_monitors_active(active), |
| 144 | Backend::Winit(_) => (), | 144 | Backend::Winit(_) => (), |
src/backend/tty.rsmodified+18 -6
| @@ -728,7 +728,7 @@ impl Tty { | |||
| 728 | 728 | ||
| 729 | // Power on all monitors if necessary and queue a redraw on the new one. | 729 | // Power on all monitors if necessary and queue a redraw on the new one. |
| 730 | niri.event_loop.insert_idle(move |state| { | 730 | niri.event_loop.insert_idle(move |state| { |
| 731 | - state.niri.activate_monitors(&state.backend); | 731 | + state.niri.activate_monitors(&mut state.backend); |
| 732 | state.niri.queue_redraw(output); | 732 | state.niri.queue_redraw(output); |
| 733 | }); | 733 | }); |
| 734 | 734 | ||
| @@ -1031,7 +1031,7 @@ impl Tty { | |||
| 1031 | niri.send_dmabuf_feedbacks(output, dmabuf_feedback, &res.states); | 1031 | niri.send_dmabuf_feedbacks(output, dmabuf_feedback, &res.states); |
| 1032 | } | 1032 | } |
| 1033 | 1033 | ||
| 1034 | - if res.damage.is_some() { | 1034 | + if !res.is_empty { |
| 1035 | let presentation_feedbacks = | 1035 | let presentation_feedbacks = |
| 1036 | niri.take_presentation_feedbacks(output, &res.states); | 1036 | niri.take_presentation_feedbacks(output, &res.states); |
| 1037 | let data = (presentation_feedbacks, target_presentation_time); | 1037 | let data = (presentation_feedbacks, target_presentation_time); |
| @@ -1196,10 +1196,22 @@ impl Tty { | |||
| 1196 | self.devices.get(&self.primary_node).map(|d| d.gbm.clone()) | 1196 | self.devices.get(&self.primary_node).map(|d| d.gbm.clone()) |
| 1197 | } | 1197 | } |
| 1198 | 1198 | ||
| 1199 | - pub fn set_monitors_active(&self, active: bool) { | 1199 | + pub fn set_monitors_active(&mut self, active: bool) { |
| 1200 | - for device in self.devices.values() { | 1200 | + // We only disable the CRTC here, this will also reset the |
| 1201 | - for crtc in device.surfaces.keys() { | 1201 | + // surface state so that the next call to `render_frame` will |
| 1202 | - set_crtc_active(&device.drm, *crtc, active); | 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 | + } | ||
| 1203 | } | 1215 | } |
| 1204 | } | 1216 | } |
| 1205 | } | 1217 | } |
src/input.rsmodified+2 -2
| @@ -51,7 +51,7 @@ impl State { | |||
| 51 | 51 | ||
| 52 | // Power on monitors if they were off. | 52 | // Power on monitors if they were off. |
| 53 | if should_activate_monitors(&event) { | 53 | if should_activate_monitors(&event) { |
| 54 | - self.niri.activate_monitors(&self.backend); | 54 | + self.niri.activate_monitors(&mut self.backend); |
| 55 | } | 55 | } |
| 56 | 56 | ||
| 57 | let hide_hotkey_overlay = | 57 | let hide_hotkey_overlay = |
| @@ -284,7 +284,7 @@ impl State { | |||
| 284 | self.niri.suppressed_keys.clear(); | 284 | self.niri.suppressed_keys.clear(); |
| 285 | } | 285 | } |
| 286 | Action::PowerOffMonitors => { | 286 | Action::PowerOffMonitors => { |
| 287 | - self.niri.deactivate_monitors(&self.backend); | 287 | + self.niri.deactivate_monitors(&mut self.backend); |
| 288 | } | 288 | } |
| 289 | Action::ToggleDebugTint => { | 289 | Action::ToggleDebugTint => { |
| 290 | self.backend.toggle_debug_tint(); | 290 | self.backend.toggle_debug_tint(); |
src/niri.rsmodified+2 -2
| @@ -1310,7 +1310,7 @@ impl Niri { | |||
| 1310 | self.queue_redraw(output); | 1310 | self.queue_redraw(output); |
| 1311 | } | 1311 | } |
| 1312 | 1312 | ||
| 1313 | - pub fn deactivate_monitors(&mut self, backend: &Backend) { | 1313 | + pub fn deactivate_monitors(&mut self, backend: &mut Backend) { |
| 1314 | if !self.monitors_active { | 1314 | if !self.monitors_active { |
| 1315 | return; | 1315 | return; |
| 1316 | } | 1316 | } |
| @@ -1319,7 +1319,7 @@ impl Niri { | |||
| 1319 | backend.set_monitors_active(false); | 1319 | backend.set_monitors_active(false); |
| 1320 | } | 1320 | } |
| 1321 | 1321 | ||
| 1322 | - pub fn activate_monitors(&mut self, backend: &Backend) { | 1322 | + pub fn activate_monitors(&mut self, backend: &mut Backend) { |
| 1323 | if self.monitors_active { | 1323 | if self.monitors_active { |
| 1324 | return; | 1324 | return; |
| 1325 | } | 1325 | } |