tty: Make sure to cleanup all CRTCs except used ones
Browse files at this commit1ae489813ea36adb1dbf5c8b7d113ab8f3daeaffParent: c7226341 changed file +16 -45
- src/backend/tty.rs +16 -45
src/backend/tty.rsmodified+16 -45
| @@ -228,47 +228,31 @@ impl OutputDevice { | |||
| 228 | ) -> anyhow::Result<()> { | 228 | ) -> anyhow::Result<()> { |
| 229 | let _span = tracy_client::span!("OutputDevice::cleanup_disconnected_resources"); | 229 | let _span = tracy_client::span!("OutputDevice::cleanup_disconnected_resources"); |
| 230 | 230 | ||
| 231 | - let mut req = AtomicModeReq::new(); | 231 | + let res_handles = self |
| 232 | + .drm | ||
| 233 | + .resource_handles() | ||
| 234 | + .context("error getting plane handles")?; | ||
| 232 | let plane_handles = self | 235 | let plane_handles = self |
| 233 | .drm | 236 | .drm |
| 234 | .plane_handles() | 237 | .plane_handles() |
| 235 | .context("error getting plane handles")?; | 238 | .context("error getting plane handles")?; |
| 236 | 239 | ||
| 237 | - let mut cleanup = HashSet::new(); | 240 | + let mut req = AtomicModeReq::new(); |
| 238 | - let mut should_be_off_conn = HashSet::new(); | ||
| 239 | - | ||
| 240 | - for (conn, info) in self.drm_scanner.connectors() { | ||
| 241 | - let Some(enc) = info.current_encoder() else { | ||
| 242 | - // Not enabled. | ||
| 243 | - continue; | ||
| 244 | - }; | ||
| 245 | - | ||
| 246 | - let enc = match self.drm.get_encoder(enc) { | ||
| 247 | - Ok(x) => x, | ||
| 248 | - Err(err) => { | ||
| 249 | - debug!("couldn't get encoder: {err:?}"); | ||
| 250 | - continue; | ||
| 251 | - } | ||
| 252 | - }; | ||
| 253 | 241 | ||
| 254 | - let Some(crtc) = enc.crtc() else { | 242 | + // We want to disable all CRTCs that do not correspond to a connector we're using. |
| 255 | - // Encoder has no CRTC? | 243 | + let mut cleanup = HashSet::<crtc::Handle>::new(); |
| 256 | - continue; | 244 | + cleanup.extend(res_handles.crtcs()); |
| 257 | - }; | ||
| 258 | 245 | ||
| 259 | - // All Connected connectors are returned by the DrmScanner and will be attempted for | 246 | + for (conn, info) in self.drm_scanner.connectors() { |
| 260 | - // connection. | 247 | + // We only keep the connector if it has a CRTC and the output isn't off in niri. |
| 261 | - if info.state() == connector::State::Connected { | 248 | + if let Some(crtc) = self.drm_scanner.crtc_for_connector(conn) { |
| 262 | - // But we also need to clear the connectors that should be off according to our | ||
| 263 | - // config, since those ones will not be cleared elsewhere. | ||
| 264 | if !should_be_off(crtc, info) { | 249 | if !should_be_off(crtc, info) { |
| 250 | + // Keep the corresponding CRTC. | ||
| 251 | + cleanup.remove(&crtc); | ||
| 265 | continue; | 252 | continue; |
| 266 | } | 253 | } |
| 267 | - should_be_off_conn.insert(conn); | ||
| 268 | } | 254 | } |
| 269 | 255 | ||
| 270 | - cleanup.insert(crtc); | ||
| 271 | - | ||
| 272 | // Clear the connector. | 256 | // Clear the connector. |
| 273 | let Some((crtc_id, _, _)) = find_drm_property(&self.drm, *conn, "CRTC_ID") else { | 257 | let Some((crtc_id, _, _)) = find_drm_property(&self.drm, *conn, "CRTC_ID") else { |
| 274 | debug!("couldn't find connector CRTC_ID property"); | 258 | debug!("couldn't find connector CRTC_ID property"); |
| @@ -278,24 +262,11 @@ impl OutputDevice { | |||
| 278 | req.add_property(*conn, crtc_id, property::Value::CRTC(None)); | 262 | req.add_property(*conn, crtc_id, property::Value::CRTC(None)); |
| 279 | } | 263 | } |
| 280 | 264 | ||
| 281 | - // Don't cleanup CRTCs that also correspond to some connected connectors. | ||
| 282 | - for (conn, crtc) in self.drm_scanner.crtcs() { | ||
| 283 | - // If the connector is enabled, but we're about to disable it, then it will be present | ||
| 284 | - // in the DrmScanner; keep it in the cleanup list. | ||
| 285 | - if should_be_off_conn.contains(&conn.handle()) { | ||
| 286 | - continue; | ||
| 287 | - } | ||
| 288 | - | ||
| 289 | - cleanup.remove(&crtc); | ||
| 290 | - } | ||
| 291 | - | ||
| 292 | // Legacy fallback. | 265 | // Legacy fallback. |
| 293 | if !self.drm.is_atomic() { | 266 | if !self.drm.is_atomic() { |
| 294 | - if let Ok(res_handles) = self.drm.resource_handles() { | 267 | + for crtc in res_handles.crtcs() { |
| 295 | - for crtc in res_handles.crtcs() { | 268 | + #[allow(deprecated)] |
| 296 | - #[allow(deprecated)] | 269 | + let _ = self.drm.set_cursor(*crtc, Option::<&DumbBuffer>::None); |
| 297 | - let _ = self.drm.set_cursor(*crtc, Option::<&DumbBuffer>::None); | ||
| 298 | - } | ||
| 299 | } | 270 | } |
| 300 | for crtc in cleanup { | 271 | for crtc in cleanup { |
| 301 | let _ = self.drm.set_crtc(crtc, None, (0, 0), &[], None); | 272 | let _ = self.drm.set_crtc(crtc, None, (0, 0), &[], None); |