output: Store physical size

This commit is contained in:
Dorota Czaplejewicz
2022-04-06 08:40:59 +00:00
parent 5a210712f6
commit 57aeeaa882
3 changed files with 43 additions and 10 deletions

View File

@ -126,7 +126,7 @@ pub mod c {
outputs: COutputs, outputs: COutputs,
wl_output: WlOutput, wl_output: WlOutput,
_x: i32, _y: i32, _x: i32, _y: i32,
_phys_width: i32, _phys_height: i32, phys_width: i32, phys_height: i32,
_subpixel: i32, _subpixel: i32,
_make: *const c_char, _model: *const c_char, _make: *const c_char, _model: *const c_char,
transform: i32, transform: i32,
@ -144,7 +144,19 @@ pub mod c {
.find_output_mut(wl_output) .find_output_mut(wl_output)
.map(|o| &mut o.pending); .map(|o| &mut o.pending);
match output_state { match output_state {
Some(state) => { state.transform = Some(transform) }, Some(state) => {
fn maybe_mm(value: i32) -> Option<Millimeter> {
if value == 0 { None }
else { Some(Millimeter(value)) }
}
state.geometry = Some(Geometry {
phys_size: GSize {
width: maybe_mm(phys_width),
height: maybe_mm(phys_height),
},
transform,
});
},
None => log_print!( None => log_print!(
logging::Level::Warning, logging::Level::Warning,
"Got geometry on unknown output", "Got geometry on unknown output",
@ -286,13 +298,17 @@ pub mod c {
// TODO: handle unregistration // TODO: handle unregistration
} }
/// Generic size /// Generic size
#[derive(Clone)] #[derive(Clone, Copy, Debug)]
pub struct Size { pub struct GSize<Unit> {
pub width: u32, pub width: Unit,
pub height: u32, pub height: Unit,
} }
/// Unspecified size (TODO: transitional, remove)
pub type Size = GSize<u32>;
/// wl_output mode /// wl_output mode
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
pub struct Mode { pub struct Mode {
@ -300,10 +316,20 @@ pub struct Mode {
height: i32, height: i32,
} }
#[derive(Clone, Copy, Debug)]
pub struct Millimeter(pub i32);
/// All geometry parameters
#[derive(Clone, Copy, Debug)]
pub struct Geometry {
pub transform: c::Transform,
pub phys_size: GSize<Option<Millimeter>>,
}
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
pub struct OutputState { pub struct OutputState {
pub current_mode: Option<Mode>, pub current_mode: Option<Mode>,
pub transform: Option<c::Transform>, pub geometry: Option<Geometry>,
pub scale: i32, pub scale: i32,
} }
@ -317,7 +343,7 @@ impl OutputState {
fn uninitialized() -> OutputState { fn uninitialized() -> OutputState {
OutputState { OutputState {
current_mode: None, current_mode: None,
transform: None, geometry: None,
scale: 1, scale: 1,
} }
} }
@ -327,7 +353,7 @@ impl OutputState {
match self { match self {
OutputState { OutputState {
current_mode: Some(Mode { width, height } ), current_mode: Some(Mode { width, height } ),
transform: Some(transform), geometry: Some(Geometry { transform, .. } ),
scale: _, scale: _,
} => Some( } => Some(
match transform { match transform {

View File

@ -10,6 +10,7 @@ use crate::imservice::{ ContentHint, ContentPurpose };
use crate::main::{ Commands, PanelCommand, PixelSize }; use crate::main::{ Commands, PanelCommand, PixelSize };
use crate::outputs; use crate::outputs;
use crate::outputs::{OutputId, OutputState}; use crate::outputs::{OutputId, OutputState};
use crate::util::Rational;
use std::cmp; use std::cmp;
use std::collections::HashMap; use std::collections::HashMap;
use std::time::Instant; use std::time::Instant;
@ -341,7 +342,7 @@ pub mod test {
id, id,
OutputState { OutputState {
current_mode: None, current_mode: None,
transform: None, geometry: None,
scale: 1, scale: 1,
}, },
); );

View File

@ -157,6 +157,12 @@ pub fn find_max_double<T, I, F>(iterator: I, get: F)
.0 .0
} }
#[derive(Debug, Clone, Copy)]
pub struct Rational {
pub numerator: i32,
pub denominator: u32,
}
/// Compares pointers but not internal values of Rc /// Compares pointers but not internal values of Rc
pub struct Pointer<T>(pub Rc<T>); pub struct Pointer<T>(pub Rc<T>);