forge
Explore
Log in

Don't you dare go Hollow

Restore gamma on TTY switch back

Browse files at this commit

0c57815fbf47c69af9ed11fa8ebc1b52158a3ba2Ivan MolodetskikhParent: cf89c78
src/backend/tty.rsmodified+20 -1
@@ -397,7 +397,7 @@ impl Tty {
397397 // Refresh the connectors.
398398 self.device_changed(node.dev_id(), niri);
399399
400- // Apply pending gamma changes.
400+ // Apply pending gamma changes and restore our existing gamma.
401401 let device = self.devices.get_mut(&node).unwrap();
402402 for (crtc, surface) in device.surfaces.iter_mut() {
403403 if let Some(ramp) = surface.pending_gamma_change.take() {
@@ -410,6 +410,10 @@ impl Tty {
410410 if let Err(err) = res {
411411 warn!("error applying pending gamma change: {err:?}");
412412 }
413+ } else if let Some(gamma_props) = &surface.gamma_props {
414+ if let Err(err) = gamma_props.restore_gamma(&device.drm) {
415+ warn!("error restoring gamma: {err:?}");
416+ }
413417 }
414418 }
415419 }
@@ -1708,6 +1712,21 @@ impl GammaProps {
17081712
17091713 Ok(())
17101714 }
1715+
1716+ fn restore_gamma(&self, device: &DrmDevice) -> anyhow::Result<()> {
1717+ let _span = tracy_client::span!("GammaProps::restore_gamma");
1718+
1719+ let blob = self.previous_blob.map(NonZeroU64::get).unwrap_or(0);
1720+ device
1721+ .set_property(
1722+ self.crtc,
1723+ self.gamma_lut,
1724+ property::Value::Blob(blob).into(),
1725+ )
1726+ .context("error setting GAMMA_LUT")?;
1727+
1728+ Ok(())
1729+ }
17111730 }
17121731
17131732 fn primary_node_from_config(config: &Config) -> Option<(DrmNode, DrmNode)> {