lesavka/client/src/output/layout.rs

73 lines
1.9 KiB
Rust
Raw Normal View History

2025-06-29 22:39:17 -05:00
// client/src/output/layout.rs
use super::display::MonitorInfo;
use tracing::debug;
#[derive(Clone, Copy, Debug)]
pub struct Rect {
pub x: i32,
pub y: i32,
pub w: i32,
pub h: i32,
}
2025-06-29 22:39:17 -05:00
/// Compute rectangles for N video streams (all 16:9 here).
pub fn assign_rectangles(
monitors: &[MonitorInfo],
streams: &[(&str, i32, i32)], // (name, w, h)
2025-06-29 22:39:17 -05:00
) -> Vec<Rect> {
let mut rects = vec![
Rect {
x: 0,
y: 0,
w: 0,
h: 0
};
streams.len()
];
2025-06-29 22:39:17 -05:00
match monitors.len() {
0 => return rects, // impossible, but keep compiler happy
2025-06-29 22:39:17 -05:00
1 => {
// One monitor: side-by-side layout, full height
2025-06-29 22:39:17 -05:00
let m = &monitors[0].geometry;
let count = streams.len().max(1) as i32;
let base_w = m.width() / count;
2025-06-29 22:39:17 -05:00
let mut x = m.x();
for (idx, _stream) in streams.iter().enumerate() {
let w = if idx == streams.len() - 1 {
m.width() - base_w * (count - 1)
} else {
base_w
};
rects[idx] = Rect {
x,
y: m.y(),
w,
h: m.height(),
};
x += w;
2025-06-29 22:39:17 -05:00
}
}
_ => {
// ≥2 monitors: map 1-to-1 until we run out, full screen per monitor
for (idx, _stream) in streams.iter().enumerate() {
if idx >= monitors.len() {
break;
}
let m = &monitors[idx];
let geom = m.geometry;
rects[idx] = Rect {
x: geom.x(),
y: geom.y(),
w: geom.width(),
h: geom.height(),
};
2025-06-29 22:39:17 -05:00
}
}
}
debug!("📐 final rectangles = {:?}", rects);
rects
}