anvil.window_map: add WindowMap::geometry

This commit is contained in:
Ivan Molodetskikh 2020-02-03 16:23:04 +03:00
parent 9fd9db82ae
commit 546ff48af5
No known key found for this signature in database
GPG Key ID: 02CE38DA47E9D691
1 changed files with 18 additions and 0 deletions

View File

@ -144,6 +144,16 @@ where
height: max_y - min_y,
};
}
/// Returns the geometry of this window.
pub fn geometry(&self, ctoken: CompositorToken<R>) -> Rectangle {
// It's the set geometry with the full bounding box as the fallback.
ctoken
.with_surface_data(self.toplevel.get_surface().unwrap(), |attributes| {
attributes.user_data.get::<SurfaceData>().unwrap().geometry
})
.unwrap_or(self.bbox)
}
}
pub struct WindowMap<R> {
@ -236,4 +246,12 @@ where
w.self_update(self.ctoken);
}
}
/// Returns the geometry of the toplevel, if it exists.
pub fn geometry(&self, toplevel: &Kind<R>) -> Option<Rectangle> {
self.windows
.iter()
.find(|w| w.toplevel.equals(toplevel))
.map(|w| w.geometry(self.ctoken))
}
}