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 e575a126..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, @@ -203,12 +210,22 @@ where .collect::>(); for output in new_outputs { - output.user_data().insert_if_missing(|| { + let added = output.user_data().insert_if_missing(|| { OutputState::new(OutputStateInner { enabled: true, global: None, }) }); + if !added { + // If head was previous added, enable it again + let mut inner = output + .user_data() + .get::() + .unwrap() + .lock() + .unwrap(); + inner.enabled = true; + } self.outputs.push(output.clone()); } } @@ -219,8 +236,7 @@ where self.removed_outputs.push(output.clone()); if let Some(inner) = output.user_data().get::() { let mut inner = inner.lock().unwrap(); - // if it gets re-added it should start with being enabled and no global - inner.enabled = true; + inner.enabled = false; if let Some(global) = inner.global.take() { self.dh.remove_global::(global); }