From dbb51e827d3f18e3c17d771ddd0f7892545b3bdf Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Mon, 18 Nov 2024 18:36:44 +0100 Subject: [PATCH] kms: Fix enabling outputs --- src/backend/kms/device.rs | 8 ++--- src/backend/kms/mod.rs | 66 +++++++++++++++++++++++++-------------- 2 files changed, 46 insertions(+), 28 deletions(-) diff --git a/src/backend/kms/device.rs b/src/backend/kms/device.rs index 687e3b89..1da09203 100644 --- a/src/backend/kms/device.rs +++ b/src/backend/kms/device.rs @@ -253,8 +253,6 @@ impl State { self.backend.kms().drm_devices.insert(drm_node, device); } - self.backend.kms().refresh_used_devices()?; - self.common .output_configuration_state .add_heads(wl_outputs.iter()); @@ -267,6 +265,8 @@ impl State { &self.common.xdg_activation_state, self.common.startup_done.clone(), ); + + self.backend.kms().refresh_used_devices()?; self.common.refresh(); Ok(()) @@ -349,8 +349,6 @@ impl State { } } - self.backend.kms().refresh_used_devices()?; - self.common .output_configuration_state .remove_heads(outputs_removed.iter()); @@ -376,6 +374,8 @@ impl State { self.common.refresh(); } + self.backend.kms().refresh_used_devices()?; + Ok(()) } diff --git a/src/backend/kms/mod.rs b/src/backend/kms/mod.rs index 24327509..e01f5065 100644 --- a/src/backend/kms/mod.rs +++ b/src/backend/kms/mod.rs @@ -528,7 +528,6 @@ impl KmsState { return Ok(Vec::new()); } - let mut all_outputs = Vec::new(); for device in self.drm_devices.values_mut() { // we only want outputs exposed to wayland - not leased ones // but that is also not all surface, because that doesn't contain all detected, but unmapped outputs @@ -587,7 +586,7 @@ impl KmsState { .flat_map(|encoder_handle| device.drm.get_encoder(*encoder_handle)) { for crtc in res_handles.filter_crtcs(encoder_info.possible_crtcs()) { - if !free_crtcs.contains(&crtc) { + if free_crtcs.contains(&crtc) { new_pairings.insert(conn, crtc); break 'outer; } @@ -607,7 +606,34 @@ impl KmsState { } } - // reconfigure existing + // add new ones + let mut w = shell.read().unwrap().global_space().size.w as u32; + if !test_only { + for (conn, crtc) in new_pairings { + let (output, _) = device.connector_added( + self.primary_node.as_ref(), + conn, + Some(crtc), + (w, 0), + loop_handle, + shell.clone(), + startup_done.clone(), + )?; + if output.mirroring().is_none() { + w += output.config().transformed_size().w as u32; + } + } + } + } + + if !test_only { + self.refresh_used_devices() + .context("Failed to enable devices")?; + } + + let mut all_outputs = Vec::new(); + for device in self.drm_devices.values_mut() { + // reconfigure for (crtc, surface) in device.surfaces.iter_mut() { let output_config = surface.output.config(); @@ -673,27 +699,19 @@ impl KmsState { } } - // add new ones - let mut w = shell.read().unwrap().global_space().size.w as u32; - if !test_only { - for (conn, crtc) in new_pairings { - let (output, _) = device.connector_added( - self.primary_node.as_ref(), - conn, - Some(crtc), - (0, w), - loop_handle, - shell.clone(), - startup_done.clone(), - )?; - if output.mirroring().is_none() { - w += output.config().transformed_size().w as u32; - } - all_outputs.push(output); - } - } - - all_outputs.extend(outputs); + all_outputs.extend( + device + .outputs + .iter() + .filter(|(conn, _)| { + !device + .leased_connectors + .iter() + .any(|(leased_conn, _)| *conn == leased_conn) + }) + .map(|(_, output)| output.clone()) + .collect::>(), + ); } // we need to handle mirroring, after all outputs have been enabled