1
0
Fork 0
forked from wry/wry

tree: split output helpers

This commit is contained in:
kossLAN 2026-05-29 20:35:58 -04:00
parent 7d9ee6e696
commit c482a2b99d
No known key found for this signature in database
3 changed files with 210 additions and 191 deletions

View file

@ -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<dyn GfxTexture>,
pub ws: Rc<WorkspaceNode>,
}
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<OutputWorkspaceRenderData>,
pub bar_separator: Rect,
pub inactive_workspaces: Vec<Rect>,
pub attention_requested_workspaces: Vec<Rect>,
pub captured_inactive_workspaces: Vec<Rect>,
pub titles: Vec<OutputTitle>,
pub status: Option<OutputStatus>,
}
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<VrrSurfaceRequirements>,
},
}
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq)]
pub struct VrrSurfaceRequirements {
pub content_type: Option<VrrContentTypeRequirements>,
}
#[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<TearingSurfaceRequirements>,
},
}
#[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,
}
}
}

155
src/tree/output/policy.rs Normal file
View file

@ -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<VrrSurfaceRequirements>,
},
}
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq)]
pub struct VrrSurfaceRequirements {
pub content_type: Option<VrrContentTypeRequirements>,
}
#[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<TearingSurfaceRequirements>,
},
}
#[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,
}
}
}

View file

@ -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<dyn GfxTexture>,
pub ws: Rc<WorkspaceNode>,
}
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<OutputWorkspaceRenderData>,
pub bar_separator: Rect,
pub inactive_workspaces: Vec<Rect>,
pub attention_requested_workspaces: Vec<Rect>,
pub captured_inactive_workspaces: Vec<Rect>,
pub titles: Vec<OutputTitle>,
pub status: Option<OutputStatus>,
}
impl OutputRenderData {
pub(super) fn clear(&mut self) {
self.titles.clear();
self.status.take();
}
}