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/handlers | |
| 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/handlers')
| -rw-r--r-- | src/handlers/mod.rs | 60 |
1 files changed, 59 insertions, 1 deletions
diff --git a/src/handlers/mod.rs b/src/handlers/mod.rs index f97129c6..54a9b451 100644 --- a/src/handlers/mod.rs +++ b/src/handlers/mod.rs @@ -8,6 +8,7 @@ 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}; @@ -15,6 +16,7 @@ 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; @@ -58,9 +60,10 @@ use crate::niri::{ClientState, State}; use crate::protocols::foreign_toplevel::{ self, ForeignToplevelHandler, ForeignToplevelManagerState, }; +use crate::protocols::gamma_control::{GammaControlHandler, GammaControlManagerState}; use crate::protocols::screencopy::{Screencopy, ScreencopyHandler}; use crate::utils::output_size; -use crate::{delegate_foreign_toplevel, delegate_screencopy}; +use crate::{delegate_foreign_toplevel, delegate_gamma_control, delegate_screencopy}; impl SeatHandler for State { type KeyboardFocus = WlSurface; @@ -440,3 +443,58 @@ impl DrmLeaseHandler for State { delegate_drm_lease!(State); delegate_viewporter!(State); + +impl GammaControlHandler for State { + fn gamma_control_manager_state(&mut self) -> &mut GammaControlManagerState { + &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"); + } + 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"); + } + gamma_size + } +} + +delegate_gamma_control!(State); |
