diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2024-03-14 08:32:23 +0400 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2024-03-15 13:29:36 +0400 |
| commit | 9ae3cad82b6dfe901b40510a3d6ff0eb655a11df (patch) | |
| tree | f0e87840a0636c35d15316526b64cabb4a1bf939 /src/handlers | |
| parent | 89dfaa6cac128887083c4e2fc195864c8de7d5fa (diff) | |
| download | niri-9ae3cad82b6dfe901b40510a3d6ff0eb655a11df.tar.gz niri-9ae3cad82b6dfe901b40510a3d6ff0eb655a11df.tar.bz2 niri-9ae3cad82b6dfe901b40510a3d6ff0eb655a11df.zip | |
gamma-control: Misc. clean ups and fixes
Diffstat (limited to 'src/handlers')
| -rw-r--r-- | src/handlers/mod.rs | 61 |
1 files changed, 17 insertions, 44 deletions
diff --git a/src/handlers/mod.rs b/src/handlers/mod.rs index 54a9b451..d027194c 100644 --- a/src/handlers/mod.rs +++ b/src/handlers/mod.rs @@ -8,7 +8,6 @@ use std::os::fd::OwnedFd; use std::sync::Arc; use std::thread; -use anyhow::anyhow; use smithay::backend::allocator::dmabuf::Dmabuf; use smithay::backend::drm::DrmNode; use smithay::desktop::{PopupKind, PopupManager}; @@ -16,7 +15,6 @@ use smithay::input::pointer::{CursorIcon, CursorImageStatus, PointerHandle}; use smithay::input::{keyboard, Seat, SeatHandler, SeatState}; use smithay::output::Output; use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel; -use smithay::reexports::wayland_server::backend::ObjectId; use smithay::reexports::wayland_server::protocol::wl_data_source::WlDataSource; use smithay::reexports::wayland_server::protocol::wl_output::WlOutput; use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; @@ -449,52 +447,27 @@ impl GammaControlHandler for State { &mut self.niri.gamma_control_manager_state } - fn set_gamma( - &mut self, - wl_output: &WlOutput, - ramp: Vec<u16>, - gamma_size: u32, - ) -> anyhow::Result<()> { - if ramp.len() != gamma_size as usize * 3 { - error!( - "gamma length wrong (expected {}, got {})", - gamma_size, - ramp.len() - ); - return Err(anyhow!("Gamma length wrong")); - } - - let Some(output) = Output::from_resource(wl_output) else { - return Err(anyhow!("No Output matching WlOutput")); - }; - - self.backend.tty().set_gamma(&mut self.niri, &output, ramp) - } - - fn get_gamma(&mut self, wl_output: &WlOutput) -> Option<Vec<u16>> { - let output = Output::from_resource(wl_output)?; - - let gamma_ramp = self.backend.tty().get_gamma(&output); - if gamma_ramp.is_none() { - warn!("Failed to get gamma ramp"); + fn get_gamma_size(&mut self, output: &Output) -> Option<u32> { + match self.backend.tty().get_gamma_size(output) { + Ok(size) => Some(size), + Err(err) => { + warn!( + "error getting gamma size for output {}: {err:?}", + output.name() + ); + None + } } - gamma_ramp } - fn destroy(&mut self, output_id: ObjectId) { - self.niri - .gamma_control_manager_state - .destroy_gamma_control(output_id) - } - - fn get_gamma_size(&mut self, wl_output: &WlOutput) -> Option<u32> { - let output = Output::from_resource(wl_output)?; - let gamma_size = self.backend.tty().get_gamma_length(&output); - if gamma_size.is_none() { - warn!("Failed to get gamma size"); + fn set_gamma(&mut self, output: &Output, ramp: Option<&[u16]>) -> Option<()> { + match self.backend.tty().set_gamma(output, ramp) { + Ok(()) => Some(()), + Err(err) => { + warn!("error setting gamma for output {}: {err:?}", output.name()); + None + } } - gamma_size } } - delegate_gamma_control!(State); |
