Restore gamma on TTY switch back
Browse files at this commit0c57815fbf47c69af9ed11fa8ebc1b52158a3ba2Parent: cf89c781 changed file +20 -1
- src/backend/tty.rs +20 -1
src/backend/tty.rsmodified+20 -1
| @@ -397,7 +397,7 @@ impl Tty { | ||
| 397 | 397 | // Refresh the connectors. |
| 398 | 398 | self.device_changed(node.dev_id(), niri); |
| 399 | 399 | |
| 400 | - // Apply pending gamma changes. | |
| 400 | + // Apply pending gamma changes and restore our existing gamma. | |
| 401 | 401 | let device = self.devices.get_mut(&node).unwrap(); |
| 402 | 402 | for (crtc, surface) in device.surfaces.iter_mut() { |
| 403 | 403 | if let Some(ramp) = surface.pending_gamma_change.take() { |
| @@ -410,6 +410,10 @@ impl Tty { | ||
| 410 | 410 | if let Err(err) = res { |
| 411 | 411 | warn!("error applying pending gamma change: {err:?}"); |
| 412 | 412 | } |
| 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 | + } | |
| 413 | 417 | } |
| 414 | 418 | } |
| 415 | 419 | } |
| @@ -1708,6 +1712,21 @@ impl GammaProps { | ||
| 1708 | 1712 | |
| 1709 | 1713 | Ok(()) |
| 1710 | 1714 | } |
| 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 | + } | |
| 1711 | 1730 | } |
| 1712 | 1731 | |
| 1713 | 1732 | fn primary_node_from_config(config: &Config) -> Option<(DrmNode, DrmNode)> { |