Restore gamma on TTY switch back

This commit is contained in:
Ivan Molodetskikh 2024-03-15 22:02:29 +04:00
parent cf89c789c3
commit 0c57815fbf

View File

@ -397,7 +397,7 @@ impl Tty {
// Refresh the connectors.
self.device_changed(node.dev_id(), niri);
// Apply pending gamma changes.
// Apply pending gamma changes and restore our existing gamma.
let device = self.devices.get_mut(&node).unwrap();
for (crtc, surface) in device.surfaces.iter_mut() {
if let Some(ramp) = surface.pending_gamma_change.take() {
@ -410,6 +410,10 @@ impl Tty {
if let Err(err) = res {
warn!("error applying pending gamma change: {err:?}");
}
} else if let Some(gamma_props) = &surface.gamma_props {
if let Err(err) = gamma_props.restore_gamma(&device.drm) {
warn!("error restoring gamma: {err:?}");
}
}
}
}
@ -1708,6 +1712,21 @@ impl GammaProps {
Ok(())
}
fn restore_gamma(&self, device: &DrmDevice) -> anyhow::Result<()> {
let _span = tracy_client::span!("GammaProps::restore_gamma");
let blob = self.previous_blob.map(NonZeroU64::get).unwrap_or(0);
device
.set_property(
self.crtc,
self.gamma_lut,
property::Value::Blob(blob).into(),
)
.context("error setting GAMMA_LUT")?;
Ok(())
}
}
fn primary_node_from_config(config: &Config) -> Option<(DrmNode, DrmNode)> {