From 518901da7e7f746da7319f0f27cb3a2596f4477d Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Wed, 13 Nov 2024 12:55:08 -0800 Subject: [PATCH] Use new primary scanout output if old output is disabled `Output` in Smithay doesn't track if the output still exists, other than based on whether or not it has strong references. Which doesn't seem to be working correctly. There may be leaked strong references to `Output`s somewhere, and maybe Smithay should track if an output is still valid, generally when it is exposed as a Wayland global (https://github.com/Smithay/smithay/issues/1584). But a check like this works for now. Addresses https://github.com/pop-os/cosmic-comp/issues/985. --- src/state.rs | 17 +++++++++++++++-- .../protocols/output_configuration/mod.rs | 7 +++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/state.rs b/src/state.rs index a5e68943..747754c0 100644 --- a/src/state.rs +++ b/src/state.rs @@ -38,7 +38,7 @@ use smithay::{ renderer::{ element::{ default_primary_scanout_output_compare, utils::select_dmabuf_feedback, - RenderElementStates, + RenderElementState, RenderElementStates, }, ImportDma, }, @@ -649,6 +649,19 @@ impl State { } } +fn primary_scanout_output_compare<'a>( + current_output: &'a Output, + current_state: &RenderElementState, + next_output: &'a Output, + next_state: &RenderElementState, +) -> &'a Output { + if !crate::wayland::protocols::output_configuration::head_is_enabled(current_output) { + return next_output; + } + + default_primary_scanout_output_compare(current_output, current_state, next_output, next_state) +} + impl Common { pub fn update_primary_output( &self, @@ -662,7 +675,7 @@ impl Common { output, states, render_element_states, - default_primary_scanout_output_compare, + primary_scanout_output_compare, ); if let Some(output) = primary_scanout_output { with_fractional_scale(states, |fraction_scale| { diff --git a/src/wayland/protocols/output_configuration/mod.rs b/src/wayland/protocols/output_configuration/mod.rs index 9ba707fb..e82b922d 100644 --- a/src/wayland/protocols/output_configuration/mod.rs +++ b/src/wayland/protocols/output_configuration/mod.rs @@ -27,6 +27,13 @@ use std::{convert::TryFrom, sync::Mutex}; mod handlers; +pub fn head_is_enabled(output: &Output) -> bool { + output + .user_data() + .get::() + .map_or(false, |inner| inner.lock().unwrap().enabled) +} + #[derive(Debug)] pub struct OutputConfigurationState { outputs: Vec,