space: change output_for_window to return Vec
This commit is contained in:
parent
7578fab9cf
commit
25b74e2eaa
|
@ -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
|
||||||
|
.outputs
|
||||||
|
.iter()
|
||||||
|
.cloned()
|
||||||
|
.filter(|o| {
|
||||||
let o_geo = self.output_geometry(o).unwrap();
|
let o_geo = self.output_geometry(o).unwrap();
|
||||||
if w_geo.overlaps(o_geo) {
|
w_geo.overlaps(o_geo)
|
||||||
return Some(o.clone());
|
})
|
||||||
}
|
.collect::<Vec<Output>>();
|
||||||
}
|
outputs.sort_by(|o1, o2| {
|
||||||
|
let overlap = |rect1: Rectangle<i32, Logical>, rect2: Rectangle<i32, Logical>| -> i32 {
|
||||||
// TODO primary output
|
// x overlap
|
||||||
self.outputs.get(0).cloned()
|
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) {
|
||||||
|
|
Loading…
Reference in New Issue