space: change output_for_window to return Vec

This commit is contained in:
Victor Brekenfeld 2021-12-02 12:45:21 +01:00
parent 7578fab9cf
commit 25b74e2eaa
1 changed files with 24 additions and 12 deletions

View File

@ -229,21 +229,33 @@ impl Space {
Some(state.render_scale) Some(state.render_scale)
} }
pub fn output_for_window(&self, w: &Window) -> Option<Output> { pub fn outputs_for_window(&self, w: &Window) -> Vec<Output> {
if !self.windows.contains(w) { if !self.windows.contains(w) {
return None; return Vec::new();
} }
let w_geo = self.window_geometry(w).unwrap(); let w_geo = window_rect(w, &self.id);
for o in &self.outputs { let mut outputs = self
let o_geo = self.output_geometry(o).unwrap(); .outputs
if w_geo.overlaps(o_geo) { .iter()
return Some(o.clone()); .cloned()
} .filter(|o| {
} let o_geo = self.output_geometry(o).unwrap();
w_geo.overlaps(o_geo)
// TODO primary output })
self.outputs.get(0).cloned() .collect::<Vec<Output>>();
outputs.sort_by(|o1, o2| {
let overlap = |rect1: Rectangle<i32, Logical>, rect2: Rectangle<i32, Logical>| -> i32 {
// x overlap
std::cmp::max(0, std::cmp::min(rect1.loc.x + rect1.size.w, rect2.loc.x + rect2.size.w) - std::cmp::max(rect1.loc.x, rect2.loc.x))
// y overlap
* std::cmp::max(0, std::cmp::min(rect1.loc.y + rect1.size.h, rect2.loc.y + rect2.size.h) - std::cmp::max(rect1.loc.y, rect2.loc.y))
};
let o1_area = overlap(self.output_geometry(o1).unwrap(), w_geo);
let o2_area = overlap(self.output_geometry(o2).unwrap(), w_geo);
o1_area.cmp(&o2_area)
});
outputs
} }
pub fn refresh(&mut self) { pub fn refresh(&mut self) {