kms: Correctly apply disabled confs

This commit is contained in:
Victoria Brekenfeld 2022-11-11 21:36:42 +01:00
parent 544acecd2e
commit bca72a9b0e
5 changed files with 43 additions and 62 deletions

View file

@ -25,7 +25,6 @@ use smithay::{
libinput::{LibinputInputBackend, LibinputSessionInterface}, libinput::{LibinputInputBackend, LibinputSessionInterface},
renderer::{ renderer::{
damage::DamageTrackedRenderer, damage::DamageTrackedRenderer,
element::RenderElementStates,
gles2::{Gles2Renderbuffer, Gles2Renderer}, gles2::{Gles2Renderbuffer, Gles2Renderer},
multigpu::{egl::EglGlesBackend, GpuManager}, multigpu::{egl::EglGlesBackend, GpuManager},
Bind, 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.config.read_outputs(
data.state.common.output_configuration_state.outputs(), &mut data.state.common.output_configuration_state,
&mut data.state.backend, &mut data.state.backend,
&mut data.state.common.shell, &mut data.state.common.shell,
&data.state.common.event_loop_handle, &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 for surface in data
.state .state
.backend .backend
@ -473,27 +465,12 @@ impl State {
self.common self.common
.output_configuration_state .output_configuration_state
.add_heads(wl_outputs.iter()); .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.config.read_outputs(
self.common.output_configuration_state.outputs(), &mut self.common.output_configuration_state,
&mut self.backend, &mut self.backend,
&mut self.common.shell, &mut self.common.shell,
&self.common.event_loop_handle, &self.common.event_loop_handle,
); );
self.common.shell.refresh_outputs();
self.common
.config
.write_outputs(self.common.output_configuration_state.outputs());
Ok(()) Ok(())
} }
@ -541,30 +518,15 @@ impl State {
self.common self.common
.output_configuration_state .output_configuration_state
.add_heads(outputs_added.iter()); .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 { for output in outputs_removed {
self.common.shell.remove_output(&output); self.common.shell.remove_output(&output);
} }
self.common.output_configuration_state.update();
self.common.config.read_outputs( self.common.config.read_outputs(
self.common.output_configuration_state.outputs(), &mut self.common.output_configuration_state,
&mut self.backend, &mut self.backend,
&mut self.common.shell, &mut self.common.shell,
&self.common.event_loop_handle, &self.common.event_loop_handle,
); );
self.common.shell.refresh_outputs();
self.common
.config
.write_outputs(self.common.output_configuration_state.outputs());
Ok(()) Ok(())
} }
@ -593,22 +555,19 @@ impl State {
self.common self.common
.output_configuration_state .output_configuration_state
.remove_heads(outputs_removed.iter()); .remove_heads(outputs_removed.iter());
self.common.output_configuration_state.update();
if self.backend.kms().session.is_active() { if self.backend.kms().session.is_active() {
for output in outputs_removed { for output in outputs_removed {
self.common.shell.remove_output(&output); self.common.shell.remove_output(&output);
} }
self.common.config.read_outputs( self.common.config.read_outputs(
self.common.output_configuration_state.outputs(), &mut self.common.output_configuration_state,
&mut self.backend, &mut self.backend,
&mut self.common.shell, &mut self.common.shell,
&self.common.event_loop_handle, &self.common.event_loop_handle,
); );
self.common.shell.refresh_outputs(); } else {
self.common self.common.output_configuration_state.update();
.config
.write_outputs(self.common.output_configuration_state.outputs());
} }
Ok(()) Ok(())
@ -858,10 +817,11 @@ impl KmsState {
if !output_config.enabled { if !output_config.enabled {
if !test_only { if !test_only {
shell.remove_output(output);
if surface.surface.take().is_some() { if surface.surface.take().is_some() {
// just drop it // just drop it
shell.remove_output(output);
surface.pending = false; surface.pending = false;
surface.dirty = false;
} }
} }
false false
@ -885,7 +845,7 @@ impl KmsState {
.ok_or(anyhow::anyhow!("Unknown mode"))?; .ok_or(anyhow::anyhow!("Unknown mode"))?;
if !test_only { 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 { if output_config.vrr != surface.vrr {
surface.vrr = drm_helpers::set_vrr( surface.vrr = drm_helpers::set_vrr(
drm, drm,
@ -917,9 +877,10 @@ impl KmsState {
) )
})?; })?;
surface.surface = Some(target); surface.surface = Some(target);
shell.add_output(output);
true true
} };
shell.add_output(output);
res
} else { } else {
false false
} }

View file

@ -213,16 +213,13 @@ pub fn init_backend(
.common .common
.output_configuration_state .output_configuration_state
.add_heads(std::iter::once(&output)); .add_heads(std::iter::once(&output));
state.common.output_configuration_state.update();
state.common.shell.add_output(&output); state.common.shell.add_output(&output);
state.common.config.read_outputs( state.common.config.read_outputs(
std::iter::once(&output), &mut state.common.output_configuration_state,
&mut state.backend, &mut state.backend,
&mut state.common.shell, &mut state.common.shell,
&state.common.event_loop_handle, &state.common.event_loop_handle,
); );
state.common.shell.refresh_outputs();
state.common.config.write_outputs(std::iter::once(&output));
Ok(()) Ok(())
} }

View file

@ -287,16 +287,13 @@ pub fn init_backend(
.common .common
.output_configuration_state .output_configuration_state
.add_heads(std::iter::once(&output)); .add_heads(std::iter::once(&output));
state.common.output_configuration_state.update();
state.common.shell.add_output(&output); state.common.shell.add_output(&output);
state.common.config.read_outputs( state.common.config.read_outputs(
std::iter::once(&output), &mut state.common.output_configuration_state,
&mut state.backend, &mut state.backend,
&mut state.common.shell, &mut state.common.shell,
&state.common.event_loop_handle, &state.common.event_loop_handle,
); );
state.common.shell.refresh_outputs();
state.common.config.write_outputs(std::iter::once(&output));
event_loop event_loop
.handle() .handle()

View file

@ -2,7 +2,8 @@
use crate::{ use crate::{
shell::{focus::FocusDirection, layout::tiling::Direction, Shell, WorkspaceAmount}, shell::{focus::FocusDirection, layout::tiling::Direction, Shell, WorkspaceAmount},
state::{BackendData, Data}, state::{BackendData, Data, State},
wayland::protocols::output_configuration::OutputConfigurationState,
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
pub use smithay::{ pub use smithay::{
@ -278,12 +279,12 @@ impl Config {
pub fn read_outputs( pub fn read_outputs(
&mut self, &mut self,
outputs: impl Iterator<Item = impl std::borrow::Borrow<Output>>, output_state: &mut OutputConfigurationState<State>,
backend: &mut BackendData, backend: &mut BackendData,
shell: &mut Shell, shell: &mut Shell,
loop_handle: &LoopHandle<'_, Data>, loop_handle: &LoopHandle<'_, Data>,
) { ) {
let outputs = outputs.map(|x| x.borrow().clone()).collect::<Vec<_>>(); let outputs = output_state.outputs().collect::<Vec<_>>();
let mut infos = outputs let mut infos = outputs
.iter() .iter()
.cloned() .cloned()
@ -307,6 +308,7 @@ impl Config {
for (name, output_config) in infos.iter().map(|o| &o.connector).zip(configs.into_iter()) 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 output = outputs.iter().find(|o| &o.name() == name).unwrap().clone();
let enabled = output_config.enabled;
*output *output
.user_data() .user_data()
.get::<RefCell<OutputConfig>>() .get::<RefCell<OutputConfig>>()
@ -322,6 +324,12 @@ impl Config {
); );
reset = true; reset = true;
break; break;
} else {
if enabled {
output_state.enable_head(&output);
} else {
output_state.disable_head(&output);
}
} }
} }
@ -331,6 +339,7 @@ impl Config {
.into_iter() .into_iter()
.zip(known_good_configs.into_iter()) .zip(known_good_configs.into_iter())
{ {
let enabled = output_config.enabled;
*output *output
.user_data() .user_data()
.get::<RefCell<OutputConfig>>() .get::<RefCell<OutputConfig>>()
@ -344,9 +353,18 @@ impl Config {
output.name(), output.name(),
err err
); );
} else {
if enabled {
output_state.enable_head(&output);
} else {
output_state.disable_head(&output);
}
} }
} }
} }
output_state.update();
self.write_outputs(output_state.outputs());
} }
} }

View file

@ -421,6 +421,10 @@ impl Shell {
} }
pub fn add_output(&mut self, output: &Output) { pub fn add_output(&mut self, output: &Output) {
if self.outputs.contains(output) {
return;
}
self.outputs.push(output.clone()); self.outputs.push(output.clone());
let mut state = self.workspace_state.update(); let mut state = self.workspace_state.update();
@ -445,6 +449,10 @@ impl Shell {
} }
pub fn remove_output(&mut self, output: &Output) { pub fn remove_output(&mut self, output: &Output) {
if !self.outputs.contains(output) {
return;
}
let mut state = self.workspace_state.update(); let mut state = self.workspace_state.update();
self.outputs.retain(|o| o != output); self.outputs.retain(|o| o != output);