From 0c57815fbf47c69af9ed11fa8ebc1b52158a3ba2 Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Fri, 15 Mar 2024 22:02:29 +0400 Subject: Restore gamma on TTY switch back --- src/backend/tty.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/backend/tty.rs b/src/backend/tty.rs index e7b60900..7d80c251 100644 --- a/src/backend/tty.rs +++ b/src/backend/tty.rs @@ -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)> { -- cgit