diff --git a/src/tree/output.rs b/src/tree/output.rs index b55fcdae..b06b951e 100644 --- a/src/tree/output.rs +++ b/src/tree/output.rs @@ -1,3 +1,15 @@ +mod policy; +mod render_data; + +#[allow(unused_imports)] +pub use { + policy::{ + TearingMode, TearingSurfaceRequirements, VrrContentTypeRequirements, VrrMode, + VrrSurfaceRequirements, calculate_logical_size, + }, + render_data::{OutputRenderData, OutputStatus, OutputTitle, OutputWorkspaceRenderData}, +}; + use { crate::{ backend::{ @@ -66,7 +78,6 @@ use { }, }, ahash::AHashMap, - jay_config::video::{TearingMode as ConfigTearingMode, VrrMode as ConfigVrrMode}, numeric_sort::cmp, smallvec::SmallVec, std::{ @@ -1543,45 +1554,6 @@ impl OutputNode { } } -pub struct OutputTitle { - pub x1: i32, - pub x2: i32, - pub tex_x: i32, - pub tex_y: i32, - pub tex: Rc, - pub ws: Rc, -} - -pub struct OutputStatus { - pub tex_x: i32, - pub tex: TextTexture, -} - -#[derive(Copy, Clone)] -pub struct OutputWorkspaceRenderData { - pub rect: Rect, - pub captured: bool, -} - -#[derive(Default)] -pub struct OutputRenderData { - pub full_area: Rect, - pub active_workspace: Option, - pub bar_separator: Rect, - pub inactive_workspaces: Vec, - pub attention_requested_workspaces: Vec, - pub captured_inactive_workspaces: Vec, - pub titles: Vec, - pub status: Option, -} - -impl OutputRenderData { - fn clear(&mut self) { - self.titles.clear(); - self.status.take(); - } -} - impl Debug for OutputNode { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { f.debug_struct("OutputNode").finish_non_exhaustive() @@ -1890,154 +1862,3 @@ impl Node for OutputNode { } } } - -pub fn calculate_logical_size( - mode: (i32, i32), - transform: Transform, - scale: crate::scale::Scale, -) -> (i32, i32) { - let (mut width, mut height) = transform.maybe_swap(mode); - if scale != 1 { - let scale = scale.to_f64(); - width = (width as f64 / scale).round() as _; - height = (height as f64 / scale).round() as _; - } - (width, height) -} - -#[derive(Copy, Clone, Debug, Eq, PartialEq, Default)] -pub enum VrrMode { - #[default] - Never, - Always, - Fullscreen { - surface: Option, - }, -} - -#[derive(Copy, Clone, Debug, Default, Eq, PartialEq)] -pub struct VrrSurfaceRequirements { - pub content_type: Option, -} - -#[derive(Copy, Clone, Debug, Eq, PartialEq)] -pub struct VrrContentTypeRequirements { - pub photo: bool, - pub video: bool, - pub game: bool, -} - -impl Default for VrrContentTypeRequirements { - fn default() -> Self { - Self { - photo: true, - video: true, - game: true, - } - } -} - -impl VrrMode { - pub const NEVER: &'static Self = &Self::Never; - pub const ALWAYS: &'static Self = &Self::Always; - pub const VARIANT_1: &'static Self = &Self::Fullscreen { surface: None }; - pub const VARIANT_2: &'static Self = &Self::Fullscreen { - surface: Some(VrrSurfaceRequirements { content_type: None }), - }; - pub const VARIANT_3: &'static Self = &Self::Fullscreen { - surface: Some(VrrSurfaceRequirements { - content_type: Some(VrrContentTypeRequirements { - photo: false, - video: true, - game: true, - }), - }), - }; - - pub fn from_config(mode: ConfigVrrMode) -> Option<&'static Self> { - let res = match mode { - ConfigVrrMode::NEVER => Self::NEVER, - ConfigVrrMode::ALWAYS => Self::ALWAYS, - ConfigVrrMode::VARIANT_1 => Self::VARIANT_1, - ConfigVrrMode::VARIANT_2 => Self::VARIANT_2, - ConfigVrrMode::VARIANT_3 => Self::VARIANT_3, - _ => return None, - }; - Some(res) - } - - pub fn to_config(&self) -> ConfigVrrMode { - match self { - Self::NEVER => ConfigVrrMode::NEVER, - Self::ALWAYS => ConfigVrrMode::ALWAYS, - Self::VARIANT_1 => ConfigVrrMode::VARIANT_1, - Self::VARIANT_2 => ConfigVrrMode::VARIANT_2, - Self::VARIANT_3 => ConfigVrrMode::VARIANT_3, - _ => { - log::error!("VRR mode {self:?} has no config representation"); - ConfigVrrMode::NEVER - } - } - } -} - -#[derive(Copy, Clone, Debug, Eq, PartialEq, Default)] -pub enum TearingMode { - #[default] - Never, - Always, - Fullscreen { - surface: Option, - }, -} - -#[derive(Copy, Clone, Debug, Eq, PartialEq)] -pub struct TearingSurfaceRequirements { - pub tearing_requested: bool, -} - -impl Default for TearingSurfaceRequirements { - fn default() -> Self { - Self { - tearing_requested: true, - } - } -} - -impl TearingMode { - pub const NEVER: &'static Self = &Self::Never; - pub const ALWAYS: &'static Self = &Self::Always; - pub const VARIANT_1: &'static Self = &Self::Fullscreen { surface: None }; - pub const VARIANT_2: &'static Self = &Self::Fullscreen { - surface: Some(TearingSurfaceRequirements { - tearing_requested: false, - }), - }; - pub const VARIANT_3: &'static Self = &Self::Fullscreen { - surface: Some(TearingSurfaceRequirements { - tearing_requested: true, - }), - }; - - pub fn from_config(mode: ConfigTearingMode) -> Option<&'static Self> { - let res = match mode { - ConfigTearingMode::NEVER => Self::NEVER, - ConfigTearingMode::ALWAYS => Self::ALWAYS, - ConfigTearingMode::VARIANT_1 => Self::VARIANT_1, - ConfigTearingMode::VARIANT_2 => Self::VARIANT_2, - ConfigTearingMode::VARIANT_3 => Self::VARIANT_3, - _ => return None, - }; - Some(res) - } - - pub fn to_config(&self) -> ConfigTearingMode { - match self { - Self::NEVER => ConfigTearingMode::NEVER, - Self::ALWAYS => ConfigTearingMode::ALWAYS, - Self::VARIANT_1 => ConfigTearingMode::VARIANT_1, - Self::VARIANT_2 => ConfigTearingMode::VARIANT_2, - Self::VARIANT_3 => ConfigTearingMode::VARIANT_3, - } - } -} diff --git a/src/tree/output/policy.rs b/src/tree/output/policy.rs new file mode 100644 index 00000000..80118c48 --- /dev/null +++ b/src/tree/output/policy.rs @@ -0,0 +1,155 @@ +use { + crate::tree::Transform, + jay_config::video::{TearingMode as ConfigTearingMode, VrrMode as ConfigVrrMode}, +}; + +pub fn calculate_logical_size( + mode: (i32, i32), + transform: Transform, + scale: crate::scale::Scale, +) -> (i32, i32) { + let (mut width, mut height) = transform.maybe_swap(mode); + if scale != 1 { + let scale = scale.to_f64(); + width = (width as f64 / scale).round() as _; + height = (height as f64 / scale).round() as _; + } + (width, height) +} + +#[derive(Copy, Clone, Debug, Eq, PartialEq, Default)] +pub enum VrrMode { + #[default] + Never, + Always, + Fullscreen { + surface: Option, + }, +} + +#[derive(Copy, Clone, Debug, Default, Eq, PartialEq)] +pub struct VrrSurfaceRequirements { + pub content_type: Option, +} + +#[derive(Copy, Clone, Debug, Eq, PartialEq)] +pub struct VrrContentTypeRequirements { + pub photo: bool, + pub video: bool, + pub game: bool, +} + +impl Default for VrrContentTypeRequirements { + fn default() -> Self { + Self { + photo: true, + video: true, + game: true, + } + } +} + +impl VrrMode { + pub const NEVER: &'static Self = &Self::Never; + pub const ALWAYS: &'static Self = &Self::Always; + pub const VARIANT_1: &'static Self = &Self::Fullscreen { surface: None }; + pub const VARIANT_2: &'static Self = &Self::Fullscreen { + surface: Some(VrrSurfaceRequirements { content_type: None }), + }; + pub const VARIANT_3: &'static Self = &Self::Fullscreen { + surface: Some(VrrSurfaceRequirements { + content_type: Some(VrrContentTypeRequirements { + photo: false, + video: true, + game: true, + }), + }), + }; + + pub fn from_config(mode: ConfigVrrMode) -> Option<&'static Self> { + let res = match mode { + ConfigVrrMode::NEVER => Self::NEVER, + ConfigVrrMode::ALWAYS => Self::ALWAYS, + ConfigVrrMode::VARIANT_1 => Self::VARIANT_1, + ConfigVrrMode::VARIANT_2 => Self::VARIANT_2, + ConfigVrrMode::VARIANT_3 => Self::VARIANT_3, + _ => return None, + }; + Some(res) + } + + pub fn to_config(&self) -> ConfigVrrMode { + match self { + Self::NEVER => ConfigVrrMode::NEVER, + Self::ALWAYS => ConfigVrrMode::ALWAYS, + Self::VARIANT_1 => ConfigVrrMode::VARIANT_1, + Self::VARIANT_2 => ConfigVrrMode::VARIANT_2, + Self::VARIANT_3 => ConfigVrrMode::VARIANT_3, + _ => { + log::error!("VRR mode {self:?} has no config representation"); + ConfigVrrMode::NEVER + } + } + } +} + +#[derive(Copy, Clone, Debug, Eq, PartialEq, Default)] +pub enum TearingMode { + #[default] + Never, + Always, + Fullscreen { + surface: Option, + }, +} + +#[derive(Copy, Clone, Debug, Eq, PartialEq)] +pub struct TearingSurfaceRequirements { + pub tearing_requested: bool, +} + +impl Default for TearingSurfaceRequirements { + fn default() -> Self { + Self { + tearing_requested: true, + } + } +} + +impl TearingMode { + pub const NEVER: &'static Self = &Self::Never; + pub const ALWAYS: &'static Self = &Self::Always; + pub const VARIANT_1: &'static Self = &Self::Fullscreen { surface: None }; + pub const VARIANT_2: &'static Self = &Self::Fullscreen { + surface: Some(TearingSurfaceRequirements { + tearing_requested: false, + }), + }; + pub const VARIANT_3: &'static Self = &Self::Fullscreen { + surface: Some(TearingSurfaceRequirements { + tearing_requested: true, + }), + }; + + pub fn from_config(mode: ConfigTearingMode) -> Option<&'static Self> { + let res = match mode { + ConfigTearingMode::NEVER => Self::NEVER, + ConfigTearingMode::ALWAYS => Self::ALWAYS, + ConfigTearingMode::VARIANT_1 => Self::VARIANT_1, + ConfigTearingMode::VARIANT_2 => Self::VARIANT_2, + ConfigTearingMode::VARIANT_3 => Self::VARIANT_3, + _ => return None, + }; + Some(res) + } + + pub fn to_config(&self) -> ConfigTearingMode { + match self { + Self::NEVER => ConfigTearingMode::NEVER, + Self::ALWAYS => ConfigTearingMode::ALWAYS, + Self::VARIANT_1 => ConfigTearingMode::VARIANT_1, + Self::VARIANT_2 => ConfigTearingMode::VARIANT_2, + Self::VARIANT_3 => ConfigTearingMode::VARIANT_3, + } + } +} diff --git a/src/tree/output/render_data.rs b/src/tree/output/render_data.rs new file mode 100644 index 00000000..17da0c37 --- /dev/null +++ b/src/tree/output/render_data.rs @@ -0,0 +1,43 @@ +use { + crate::{gfx_api::GfxTexture, rect::Rect, text::TextTexture, tree::WorkspaceNode}, + std::rc::Rc, +}; + +pub struct OutputTitle { + pub x1: i32, + pub x2: i32, + pub tex_x: i32, + pub tex_y: i32, + pub tex: Rc, + pub ws: Rc, +} + +pub struct OutputStatus { + pub tex_x: i32, + pub tex: TextTexture, +} + +#[derive(Copy, Clone)] +pub struct OutputWorkspaceRenderData { + pub rect: Rect, + pub captured: bool, +} + +#[derive(Default)] +pub struct OutputRenderData { + pub full_area: Rect, + pub active_workspace: Option, + pub bar_separator: Rect, + pub inactive_workspaces: Vec, + pub attention_requested_workspaces: Vec, + pub captured_inactive_workspaces: Vec, + pub titles: Vec, + pub status: Option, +} + +impl OutputRenderData { + pub(super) fn clear(&mut self) { + self.titles.clear(); + self.status.take(); + } +}