1
0
Fork 0
forked from wry/wry

video: allow configuring the output brightness

This commit is contained in:
Julian Orth 2025-04-21 15:41:52 +02:00
parent 7d0c9e2c3f
commit 27025a565c
19 changed files with 343 additions and 40 deletions

View file

@ -73,7 +73,7 @@ impl Global for JayCompositorGlobal {
}
fn version(&self) -> u32 {
15
16
}
fn required_caps(&self) -> ClientCaps {

View file

@ -32,6 +32,7 @@ const TEARING_SINCE: Version = Version(3);
const FORMAT_SINCE: Version = Version(8);
const FLIP_MARGIN_SINCE: Version = Version(10);
const COLORIMETRY_SINCE: Version = Version(15);
const BRIGHTNESS_SINCE: Version = Version(16);
impl JayRandr {
pub fn new(id: JayRandrId, client: &Rc<Client>, version: Version) -> Self {
@ -187,6 +188,22 @@ impl JayRandr {
color_space: node.global.bcs.get().name(),
});
}
if self.version >= BRIGHTNESS_SINCE {
if let Some(lum) = node.global.luminance {
self.client.event(BrightnessRange {
self_id: self.id,
min: lum.min,
max: lum.max,
max_fall: lum.max_fall,
});
}
if let Some(lux) = node.global.persistent.brightness.get() {
self.client.event(Brightness {
self_id: self.id,
lux,
});
}
}
}
fn send_error(&self, msg: &str) {
@ -464,6 +481,26 @@ impl JayRandrRequestHandler for JayRandr {
c.connector.set_colors(cs, tf);
Ok(())
}
fn set_brightness(&self, req: SetBrightness<'_>, _slf: &Rc<Self>) -> Result<(), Self::Error> {
let Some(c) = self.get_output_node(req.output) else {
return Ok(());
};
c.global.set_brightness(Some(req.lux));
Ok(())
}
fn unset_brightness(
&self,
req: UnsetBrightness<'_>,
_slf: &Rc<Self>,
) -> Result<(), Self::Error> {
let Some(c) = self.get_output_node(req.output) else {
return Ok(());
};
c.global.set_brightness(None);
Ok(())
}
}
object_base! {

View file

@ -122,6 +122,7 @@ pub struct PersistentOutputState {
pub vrr_mode: Cell<&'static VrrMode>,
pub vrr_cursor_hz: Cell<Option<f64>>,
pub tearing_mode: Cell<&'static TearingMode>,
pub brightness: Cell<Option<f64>>,
}
#[derive(Eq, PartialEq, Hash, Debug)]
@ -332,9 +333,21 @@ impl WlOutputGlobal {
pub fn update_color_description(&self) -> bool {
let mut luminance = Luminance::SRGB;
let tf = match self.btf.get() {
BackendTransferFunction::Default => TransferFunction::Srgb,
BackendTransferFunction::Default => {
if let Some(brightness) = self.persistent.brightness.get() {
let output_max = match self.luminance {
None => 80.0,
Some(v) => v.max,
};
luminance.white.0 = luminance.max.0 * brightness / output_max;
}
TransferFunction::Srgb
}
BackendTransferFunction::Pq => {
luminance = Luminance::ST2084_PQ;
if let Some(brightness) = self.persistent.brightness.get() {
luminance.white.0 = brightness;
}
TransferFunction::St2084Pq
}
};
@ -368,6 +381,12 @@ impl WlOutputGlobal {
self.linear_color_description.set(cd_linear.clone());
self.color_description.set(cd.clone()).id != cd.id
}
pub fn set_brightness(&self, brightness: Option<f64>) {
self.persistent.brightness.set(brightness);
self.update_color_description();
self.state.damage(self.pos.get());
}
}
global_base!(WlOutputGlobal, WlOutput, WlOutputError);