From bca72a9b0e78ba0f41da37dca6d6f4ffc9c12ee8 Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Fri, 11 Nov 2022 21:36:42 +0100 Subject: [PATCH] kms: Correctly apply disabled confs --- src/backend/kms/mod.rs | 63 ++++++++---------------------------------- src/backend/winit.rs | 5 +--- src/backend/x11.rs | 5 +--- src/config/mod.rs | 24 ++++++++++++++-- src/shell/mod.rs | 8 ++++++ 5 files changed, 43 insertions(+), 62 deletions(-) diff --git a/src/backend/kms/mod.rs b/src/backend/kms/mod.rs index 559fec51..2637313d 100644 --- a/src/backend/kms/mod.rs +++ b/src/backend/kms/mod.rs @@ -25,7 +25,6 @@ use smithay::{ libinput::{LibinputInputBackend, LibinputSessionInterface}, renderer::{ damage::DamageTrackedRenderer, - element::RenderElementStates, gles2::{Gles2Renderbuffer, Gles2Renderer}, multigpu::{egl::EglGlesBackend, GpuManager}, Bind, @@ -246,20 +245,13 @@ pub fn init_backend( } } } - data.state.common.output_configuration_state.update(); data.state.common.config.read_outputs( - data.state.common.output_configuration_state.outputs(), + &mut data.state.common.output_configuration_state, &mut data.state.backend, &mut data.state.common.shell, &data.state.common.event_loop_handle, ); - data.state.common.shell.refresh_outputs(); - data.state - .common - .config - .write_outputs(data.state.common.output_configuration_state.outputs()); - for surface in data .state .backend @@ -473,27 +465,12 @@ impl State { self.common .output_configuration_state .add_heads(wl_outputs.iter()); - self.common.output_configuration_state.update(); - for output in wl_outputs { - if let Err(err) = self.backend.kms().apply_config_for_output( - &output, - &mut self.common.shell, - false, - &self.common.event_loop_handle, - ) { - slog_scope::warn!("Failed to initialize output: {}", err); - } - } self.common.config.read_outputs( - self.common.output_configuration_state.outputs(), + &mut self.common.output_configuration_state, &mut self.backend, &mut self.common.shell, &self.common.event_loop_handle, ); - self.common.shell.refresh_outputs(); - self.common - .config - .write_outputs(self.common.output_configuration_state.outputs()); Ok(()) } @@ -541,30 +518,15 @@ impl State { self.common .output_configuration_state .add_heads(outputs_added.iter()); - for output in outputs_added { - if let Err(err) = self.backend.kms().apply_config_for_output( - &output, - &mut self.common.shell, - false, - &self.common.event_loop_handle, - ) { - slog_scope::warn!("Failed to initialize output: {}", err); - } - } for output in outputs_removed { self.common.shell.remove_output(&output); } - self.common.output_configuration_state.update(); self.common.config.read_outputs( - self.common.output_configuration_state.outputs(), + &mut self.common.output_configuration_state, &mut self.backend, &mut self.common.shell, &self.common.event_loop_handle, ); - self.common.shell.refresh_outputs(); - self.common - .config - .write_outputs(self.common.output_configuration_state.outputs()); Ok(()) } @@ -593,22 +555,19 @@ impl State { self.common .output_configuration_state .remove_heads(outputs_removed.iter()); - self.common.output_configuration_state.update(); if self.backend.kms().session.is_active() { for output in outputs_removed { self.common.shell.remove_output(&output); } self.common.config.read_outputs( - self.common.output_configuration_state.outputs(), + &mut self.common.output_configuration_state, &mut self.backend, &mut self.common.shell, &self.common.event_loop_handle, ); - self.common.shell.refresh_outputs(); - self.common - .config - .write_outputs(self.common.output_configuration_state.outputs()); + } else { + self.common.output_configuration_state.update(); } Ok(()) @@ -858,10 +817,11 @@ impl KmsState { if !output_config.enabled { if !test_only { + shell.remove_output(output); if surface.surface.take().is_some() { // just drop it - shell.remove_output(output); surface.pending = false; + surface.dirty = false; } } false @@ -885,7 +845,7 @@ impl KmsState { .ok_or(anyhow::anyhow!("Unknown mode"))?; if !test_only { - if let Some(gbm_surface) = surface.surface.as_mut() { + let res = if let Some(gbm_surface) = surface.surface.as_mut() { if output_config.vrr != surface.vrr { surface.vrr = drm_helpers::set_vrr( drm, @@ -917,9 +877,10 @@ impl KmsState { ) })?; surface.surface = Some(target); - shell.add_output(output); true - } + }; + shell.add_output(output); + res } else { false } diff --git a/src/backend/winit.rs b/src/backend/winit.rs index 3a154e9c..78965c6e 100644 --- a/src/backend/winit.rs +++ b/src/backend/winit.rs @@ -213,16 +213,13 @@ pub fn init_backend( .common .output_configuration_state .add_heads(std::iter::once(&output)); - state.common.output_configuration_state.update(); state.common.shell.add_output(&output); state.common.config.read_outputs( - std::iter::once(&output), + &mut state.common.output_configuration_state, &mut state.backend, &mut state.common.shell, &state.common.event_loop_handle, ); - state.common.shell.refresh_outputs(); - state.common.config.write_outputs(std::iter::once(&output)); Ok(()) } diff --git a/src/backend/x11.rs b/src/backend/x11.rs index 5ad7ba37..70ebd11b 100644 --- a/src/backend/x11.rs +++ b/src/backend/x11.rs @@ -287,16 +287,13 @@ pub fn init_backend( .common .output_configuration_state .add_heads(std::iter::once(&output)); - state.common.output_configuration_state.update(); state.common.shell.add_output(&output); state.common.config.read_outputs( - std::iter::once(&output), + &mut state.common.output_configuration_state, &mut state.backend, &mut state.common.shell, &state.common.event_loop_handle, ); - state.common.shell.refresh_outputs(); - state.common.config.write_outputs(std::iter::once(&output)); event_loop .handle() diff --git a/src/config/mod.rs b/src/config/mod.rs index 16dd0f23..289ff43e 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -2,7 +2,8 @@ use crate::{ shell::{focus::FocusDirection, layout::tiling::Direction, Shell, WorkspaceAmount}, - state::{BackendData, Data}, + state::{BackendData, Data, State}, + wayland::protocols::output_configuration::OutputConfigurationState, }; use serde::{Deserialize, Serialize}; pub use smithay::{ @@ -278,12 +279,12 @@ impl Config { pub fn read_outputs( &mut self, - outputs: impl Iterator>, + output_state: &mut OutputConfigurationState, backend: &mut BackendData, shell: &mut Shell, loop_handle: &LoopHandle<'_, Data>, ) { - let outputs = outputs.map(|x| x.borrow().clone()).collect::>(); + let outputs = output_state.outputs().collect::>(); let mut infos = outputs .iter() .cloned() @@ -307,6 +308,7 @@ impl Config { for (name, output_config) in infos.iter().map(|o| &o.connector).zip(configs.into_iter()) { let output = outputs.iter().find(|o| &o.name() == name).unwrap().clone(); + let enabled = output_config.enabled; *output .user_data() .get::>() @@ -322,6 +324,12 @@ impl Config { ); reset = true; break; + } else { + if enabled { + output_state.enable_head(&output); + } else { + output_state.disable_head(&output); + } } } @@ -331,6 +339,7 @@ impl Config { .into_iter() .zip(known_good_configs.into_iter()) { + let enabled = output_config.enabled; *output .user_data() .get::>() @@ -344,9 +353,18 @@ impl Config { output.name(), err ); + } else { + if enabled { + output_state.enable_head(&output); + } else { + output_state.disable_head(&output); + } } } } + + output_state.update(); + self.write_outputs(output_state.outputs()); } } diff --git a/src/shell/mod.rs b/src/shell/mod.rs index 7e32c841..ec546cd5 100644 --- a/src/shell/mod.rs +++ b/src/shell/mod.rs @@ -421,6 +421,10 @@ impl Shell { } pub fn add_output(&mut self, output: &Output) { + if self.outputs.contains(output) { + return; + } + self.outputs.push(output.clone()); let mut state = self.workspace_state.update(); @@ -445,6 +449,10 @@ impl Shell { } pub fn remove_output(&mut self, output: &Output) { + if !self.outputs.contains(output) { + return; + } + let mut state = self.workspace_state.update(); self.outputs.retain(|o| o != output);