From 57aeeaa882067218de83084fcebc6a7c4d4fdb2e Mon Sep 17 00:00:00 2001 From: Dorota Czaplejewicz Date: Wed, 6 Apr 2022 08:40:59 +0000 Subject: [PATCH] output: Store physical size --- src/outputs.rs | 44 +++++++++++++++++++++++++++++++++++--------- src/state.rs | 3 ++- src/util.rs | 6 ++++++ 3 files changed, 43 insertions(+), 10 deletions(-) diff --git a/src/outputs.rs b/src/outputs.rs index 13c1b5d3..cb17efa8 100644 --- a/src/outputs.rs +++ b/src/outputs.rs @@ -126,7 +126,7 @@ pub mod c { outputs: COutputs, wl_output: WlOutput, _x: i32, _y: i32, - _phys_width: i32, _phys_height: i32, + phys_width: i32, phys_height: i32, _subpixel: i32, _make: *const c_char, _model: *const c_char, transform: i32, @@ -144,7 +144,19 @@ pub mod c { .find_output_mut(wl_output) .map(|o| &mut o.pending); match output_state { - Some(state) => { state.transform = Some(transform) }, + Some(state) => { + fn maybe_mm(value: i32) -> Option { + 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!( logging::Level::Warning, "Got geometry on unknown output", @@ -286,13 +298,17 @@ pub mod c { // TODO: handle unregistration } + /// Generic size -#[derive(Clone)] -pub struct Size { - pub width: u32, - pub height: u32, +#[derive(Clone, Copy, Debug)] +pub struct GSize { + pub width: Unit, + pub height: Unit, } +/// Unspecified size (TODO: transitional, remove) +pub type Size = GSize; + /// wl_output mode #[derive(Clone, Copy, Debug)] pub struct Mode { @@ -300,10 +316,20 @@ pub struct Mode { 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>, +} + #[derive(Clone, Copy, Debug)] pub struct OutputState { pub current_mode: Option, - pub transform: Option, + pub geometry: Option, pub scale: i32, } @@ -317,7 +343,7 @@ impl OutputState { fn uninitialized() -> OutputState { OutputState { current_mode: None, - transform: None, + geometry: None, scale: 1, } } @@ -327,7 +353,7 @@ impl OutputState { match self { OutputState { current_mode: Some(Mode { width, height } ), - transform: Some(transform), + geometry: Some(Geometry { transform, .. } ), scale: _, } => Some( match transform { diff --git a/src/state.rs b/src/state.rs index 5254a940..58d8e50e 100644 --- a/src/state.rs +++ b/src/state.rs @@ -10,6 +10,7 @@ use crate::imservice::{ ContentHint, ContentPurpose }; use crate::main::{ Commands, PanelCommand, PixelSize }; use crate::outputs; use crate::outputs::{OutputId, OutputState}; +use crate::util::Rational; use std::cmp; use std::collections::HashMap; use std::time::Instant; @@ -341,7 +342,7 @@ pub mod test { id, OutputState { current_mode: None, - transform: None, + geometry: None, scale: 1, }, ); diff --git a/src/util.rs b/src/util.rs index d5109066..f4eb4f52 100644 --- a/src/util.rs +++ b/src/util.rs @@ -157,6 +157,12 @@ pub fn find_max_double(iterator: I, get: F) .0 } +#[derive(Debug, Clone, Copy)] +pub struct Rational { + pub numerator: i32, + pub denominator: u32, +} + /// Compares pointers but not internal values of Rc pub struct Pointer(pub Rc);