2025-06-29 22:39:17 -05:00
|
|
|
// client/src/output/layout.rs
|
|
|
|
|
|
|
|
|
|
use super::display::MonitorInfo;
|
|
|
|
|
use tracing::debug;
|
|
|
|
|
|
|
|
|
|
#[derive(Clone, Copy, Debug)]
|
2025-12-01 11:38:51 -03:00
|
|
|
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],
|
2025-12-01 11:38:51 -03:00
|
|
|
streams: &[(&str, i32, i32)], // (name, w, h)
|
2025-06-29 22:39:17 -05:00
|
|
|
) -> Vec<Rect> {
|
2025-12-01 11:38:51 -03:00
|
|
|
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() {
|
2025-12-01 11:38:51 -03:00
|
|
|
0 => return rects, // impossible, but keep compiler happy
|
2025-06-29 22:39:17 -05:00
|
|
|
1 => {
|
2026-04-08 20:00:14 -03:00
|
|
|
// One monitor: side-by-side layout, full height
|
2025-06-29 22:39:17 -05:00
|
|
|
let m = &monitors[0].geometry;
|
2026-04-08 20:00:14 -03:00
|
|
|
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();
|
2026-04-08 20:00:14 -03:00
|
|
|
for (idx, _stream) in streams.iter().enumerate() {
|
|
|
|
|
let w = if idx == streams.len() - 1 {
|
|
|
|
|
m.width() - base_w * (count - 1)
|
|
|
|
|
} else {
|
|
|
|
|
base_w
|
|
|
|
|
};
|
2025-12-01 11:38:51 -03:00
|
|
|
rects[idx] = Rect {
|
|
|
|
|
x,
|
|
|
|
|
y: m.y(),
|
2026-04-08 20:00:14 -03:00
|
|
|
w,
|
|
|
|
|
h: m.height(),
|
2025-12-01 11:38:51 -03:00
|
|
|
};
|
2026-04-08 20:00:14 -03:00
|
|
|
x += w;
|
2025-06-29 22:39:17 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_ => {
|
2026-04-08 20:00:14 -03:00
|
|
|
// ≥2 monitors: map 1-to-1 until we run out, full screen per monitor
|
|
|
|
|
for (idx, _stream) in streams.iter().enumerate() {
|
2025-12-01 11:38:51 -03:00
|
|
|
if idx >= monitors.len() {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let m = &monitors[idx];
|
|
|
|
|
let geom = m.geometry;
|
|
|
|
|
rects[idx] = Rect {
|
2026-04-08 20:00:14 -03:00
|
|
|
x: geom.x(),
|
|
|
|
|
y: geom.y(),
|
|
|
|
|
w: geom.width(),
|
|
|
|
|
h: geom.height(),
|
2025-12-01 11:38:51 -03:00
|
|
|
};
|
2025-06-29 22:39:17 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
debug!("📐 final rectangles = {:?}", rects);
|
|
|
|
|
rects
|
|
|
|
|
}
|