1
0
Fork 0
forked from wry/wry

head-management: add brightness-info-v1 extension

This commit is contained in:
Julian Orth 2025-07-14 16:47:25 +02:00
parent 1a306c4fa9
commit e0f1dd549d
10 changed files with 136 additions and 3 deletions

View file

@ -662,6 +662,7 @@ fn create_dummy_output(state: &Rc<State>) {
color_space: backend_state.color_space,
transfer_function: backend_state.transfer_function,
supported_formats: Default::default(),
brightness: None,
};
let connector_data = Rc::new(ConnectorData {
id,

View file

@ -67,7 +67,7 @@ struct HeadCommon {
pending: RefCell<Vec<HeadOp>>,
}
#[derive(Clone, Eq, PartialEq)]
#[derive(Clone, PartialEq)]
pub struct HeadState {
pub name: RcEq<String>,
pub wl_output: Option<GlobalName>,
@ -92,6 +92,7 @@ pub struct HeadState {
pub color_space: BackendColorSpace,
pub transfer_function: BackendTransferFunction,
pub supported_formats: RcEq<Vec<&'static Format>>,
pub brightness: Option<f64>,
}
impl HeadState {
@ -286,6 +287,11 @@ impl HeadManagers {
ext.send_supported(state);
head.session.schedule_done();
}
if let Some(ext) = &head.ext.brightness_info_v1 {
ext.send_implied_default_brightness(state);
ext.send_brightness(state);
head.session.schedule_done();
}
}
}
@ -491,6 +497,10 @@ impl HeadManagers {
ext.send_state(state);
head.session.schedule_done();
}
if let Some(ext) = &head.ext.brightness_info_v1 {
ext.send_implied_default_brightness(state);
head.session.schedule_done();
}
}
}
@ -505,4 +515,16 @@ impl HeadManagers {
}
}
}
pub fn handle_brightness_change(&self, brightness: Option<f64>) {
let state = &mut *self.state.borrow_mut();
state.brightness = brightness;
for head in self.managers.lock().values() {
skip_in_transaction!(head);
if let Some(ext) = &head.ext.brightness_info_v1 {
ext.send_brightness(state);
head.session.schedule_done();
}
}
}
}

View file

@ -410,4 +410,5 @@ declare_extensions! {
jay_tearing_mode_setter_v1: JayTearingModeSetterV1,
format_setter_v1: FormatSetterV1,
drm_color_space_setter_v1: DrmColorSpaceSetterV1,
brightness_info_v1: BrightnessInfoV1,
}

View file

@ -1,3 +1,4 @@
pub(super) mod jay_head_ext_brightness_info_v1;
pub(super) mod jay_head_ext_compositor_space_enabler_v1;
pub(super) mod jay_head_ext_compositor_space_info_v1;
pub(super) mod jay_head_ext_compositor_space_positioner_v1;

View file

@ -0,0 +1,77 @@
use {
crate::{
backend::BackendTransferFunction,
cmm::cmm_luminance::Luminance,
ifs::head_management::HeadState,
wire::{
jay_head_ext_brightness_info_v1::{
Brightness, DefaultBrightness, ImpliedDefaultBrightness,
JayHeadExtBrightnessInfoV1RequestHandler,
},
jay_head_manager_ext_brightness_info_v1::JayHeadManagerExtBrightnessInfoV1RequestHandler,
},
},
std::rc::Rc,
};
impl_brightness_info_v1! {
version = 1,
after_announce = after_announce,
after_transaction = after_transaction,
}
impl HeadName {
fn after_announce(&self, shared: &HeadState) {
self.send_implied_default_brightness(shared);
self.send_brightness(shared);
}
fn after_transaction(&self, shared: &HeadState, tran: &HeadState) {
if shared.transfer_function != tran.transfer_function {
self.send_implied_default_brightness(shared);
}
if shared.brightness != tran.brightness {
self.send_brightness(shared);
}
}
pub(in super::super) fn send_implied_default_brightness(&self, shared: &HeadState) {
let lux = match shared.transfer_function {
BackendTransferFunction::Default => shared
.monitor_info
.as_ref()
.and_then(|m| m.luminance.as_ref())
.map(|l| l.max)
.unwrap_or(Luminance::SRGB.white.0),
BackendTransferFunction::Pq => Luminance::ST2084_PQ.white.0,
};
self.client.event(ImpliedDefaultBrightness {
self_id: self.id,
lux: (lux as f32).to_bits(),
})
}
pub(in super::super) fn send_brightness(&self, shared: &HeadState) {
match shared.brightness {
None => self.client.event(DefaultBrightness { self_id: self.id }),
Some(b) => self.client.event(Brightness {
self_id: self.id,
lux: (b as f32).to_bits(),
}),
}
}
}
impl JayHeadManagerExtBrightnessInfoV1RequestHandler for MgrName {
type Error = ErrorName;
mgr_common_req!();
}
impl JayHeadExtBrightnessInfoV1RequestHandler for HeadName {
type Error = ErrorName;
head_common_req!();
}
error!();

View file

@ -392,6 +392,7 @@ impl JayHeadManagerSessionV1RequestHandler for JayHeadManagerSessionV1 {
TEARING_MODE_INFO = 1 << 9,
FORMAT_INFO = 1 << 10,
DRM_COLOR_SPACE_INFO = 1 << 11,
BRIGHTNESS_INFO = 1 << 12,
COMPOSITOR_SPACE_INFO_ENABLED = 1 << 13,
}
for head in self.heads.lock().values() {
@ -452,6 +453,7 @@ impl JayHeadManagerSessionV1RequestHandler for JayHeadManagerSessionV1 {
HeadOp::SetTransferFunction(e) => {
state.transfer_function = e;
to_send |= DRM_COLOR_SPACE_INFO;
to_send |= BRIGHTNESS_INFO;
}
HeadOp::SetColorSpace(c) => {
state.color_space = c;

View file

@ -68,6 +68,7 @@ pub fn handle(state: &Rc<State>, connector: &Rc<dyn Connector>) {
color_space: backend_state.color_space,
transfer_function: backend_state.transfer_function,
supported_formats: Default::default(),
brightness: None,
};
let data = Rc::new(ConnectorData {
id,

View file

@ -913,8 +913,14 @@ impl OutputNode {
}
pub fn set_brightness(&self, brightness: Option<f64>) {
self.global.persistent.brightness.set(brightness);
let old = self.global.persistent.brightness.replace(brightness);
if old != brightness {
self.update_color_description();
self.global
.connector
.head_managers
.handle_brightness_change(brightness);
}
}
fn find_stacked_at(

View file

@ -0,0 +1,15 @@
request destroy (destructor) {
}
event implied_default_brightness {
lux: u32,
}
event default_brightness {
}
event brightness {
lux: u32,
}

View file

@ -0,0 +1,7 @@
request destroy (destructor) {
}
event head {
head: id(jay_head_ext_brightness_info_v1) (new),
}