diff options
| author | phuhl <git@ph-uhl.com> | 2024-03-03 20:36:13 +0100 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2024-03-15 13:29:36 +0400 |
| commit | 89dfaa6cac128887083c4e2fc195864c8de7d5fa (patch) | |
| tree | c3f6d03d54870095ec42d2d5e5eed981d27d9cf9 /src/backend | |
| parent | f6ffe8b3ab28ae572ed61d6ee2961ba7ef411179 (diff) | |
| download | niri-89dfaa6cac128887083c4e2fc195864c8de7d5fa.tar.gz niri-89dfaa6cac128887083c4e2fc195864c8de7d5fa.tar.bz2 niri-89dfaa6cac128887083c4e2fc195864c8de7d5fa.zip | |
Adds support for wlr_gamma_control_unstable_v1 protocol
Diffstat (limited to 'src/backend')
| -rw-r--r-- | src/backend/tty.rs | 61 |
1 files changed, 60 insertions, 1 deletions
diff --git a/src/backend/tty.rs b/src/backend/tty.rs index 2b6ee89e..6d954a62 100644 --- a/src/backend/tty.rs +++ b/src/backend/tty.rs @@ -8,7 +8,7 @@ use std::sync::{Arc, Mutex}; use std::time::Duration; use std::{io, mem}; -use anyhow::{anyhow, bail, Context}; +use anyhow::{anyhow, bail, ensure, Context}; use libc::dev_t; use niri_config::Config; use smithay::backend::allocator::dmabuf::Dmabuf; @@ -1244,6 +1244,65 @@ impl Tty { } } + pub fn get_gamma_length(&self, output: &Output) -> Option<u32> { + let tty_state = output.user_data().get::<TtyOutputState>().unwrap(); + let device = self.devices.get(&tty_state.node)?; + let crtc_info = device.drm.get_crtc(tty_state.crtc.clone()).ok()?; + return Some(crtc_info.gamma_length()); + } + + pub fn get_gamma(&self, output: &Output) -> Option<Vec<u16>> { + let tty_state = output.user_data().get::<TtyOutputState>().unwrap(); + let device = self.devices.get(&tty_state.node)?; + let crtc_info = device.drm.get_crtc(tty_state.crtc.clone()).ok()?; + let crtc = tty_state.crtc.clone(); + let gamma_length = crtc_info.gamma_length() as usize; + let mut red = vec![0; gamma_length]; + let mut green = vec![0; gamma_length]; + let mut blue = vec![0; gamma_length]; + if let Err(err) = device.drm.get_gamma(crtc, &mut red, &mut green, &mut blue) { + warn!("error getting gamma for crtc {crtc:?}: {err:?}"); + return None; + } + red.extend(green); + red.extend(blue); + return Some(red); + } + + pub fn set_gamma( + &self, + niri: &mut Niri, + output: &Output, + ramp: Vec<u16>, + ) -> anyhow::Result<()> { + let tty_state = output.user_data().get::<TtyOutputState>().unwrap(); + let device = self + .devices + .get(&tty_state.node) + .context("missing device")?; + + let crtc_info = device.drm.get_crtc(tty_state.crtc.clone())?; + let crtc = tty_state.crtc.clone(); + let gamma_length = crtc_info.gamma_length() as usize; + + ensure!(ramp.len() == gamma_length * 3, "wrong gamma length"); + let mut red = ramp.clone(); + red.truncate(gamma_length); + let mut green = ramp.clone(); + green.drain(0..gamma_length); + green.truncate(gamma_length); + let mut blue = ramp; + blue.drain(0..gamma_length * 2); + blue.truncate(gamma_length); + + device + .drm + .set_gamma(crtc, &mut red, &mut green, &mut blue) + .context("error setting gamma")?; + niri.queue_redraw(output.clone()); + Ok(()) + } + fn refresh_ipc_outputs(&self) { let _span = tracy_client::span!("Tty::refresh_ipc_outputs"); |
