desktop: api cleanups

This commit is contained in:
Victor Brekenfeld 2021-12-16 13:04:00 +01:00
parent d7350d18ee
commit d84a66e053
4 changed files with 34 additions and 17 deletions

View File

@ -117,7 +117,12 @@ impl LayerMap {
bbox bbox
} }
pub fn layer_under(&self, layer: WlrLayer, point: Point<f64, Logical>) -> Option<&LayerSurface> { pub fn layer_under<P: Into<Point<f64, Logical>>>(
&self,
layer: WlrLayer,
point: P,
) -> Option<&LayerSurface> {
let point = point.into();
self.layers_on(layer).rev().find(|l| { self.layers_on(layer).rev().find(|l| {
let bbox = self.layer_geometry(l); let bbox = self.layer_geometry(l);
bbox.to_f64().contains(point) bbox.to_f64().contains(point)
@ -401,7 +406,11 @@ impl LayerSurface {
/// Finds the topmost surface under this point if any and returns it together with the location of this /// Finds the topmost surface under this point if any and returns it together with the location of this
/// surface. /// surface.
pub fn surface_under(&self, point: Point<f64, Logical>) -> Option<(WlSurface, Point<i32, Logical>)> { pub fn surface_under<P: Into<Point<f64, Logical>>>(
&self,
point: P,
) -> Option<(WlSurface, Point<i32, Logical>)> {
let point = point.into();
if let Some(surface) = self.get_surface() { if let Some(surface) = self.get_surface() {
for (popup, location) in PopupManager::popups_for_surface(surface) for (popup, location) in PopupManager::popups_for_surface(surface)
.ok() .ok()
@ -457,12 +466,12 @@ impl LayerSurface {
} }
} }
pub fn draw_layer<R, E, F, T>( pub fn draw_layer<R, E, F, T, P>(
renderer: &mut R, renderer: &mut R,
frame: &mut F, frame: &mut F,
layer: &LayerSurface, layer: &LayerSurface,
scale: f64, scale: f64,
location: Point<i32, Logical>, location: P,
damage: &[Rectangle<i32, Logical>], damage: &[Rectangle<i32, Logical>],
log: &slog::Logger, log: &slog::Logger,
) -> Result<(), R::Error> ) -> Result<(), R::Error>
@ -471,7 +480,9 @@ where
F: Frame<Error = E, TextureId = T>, F: Frame<Error = E, TextureId = T>,
E: std::error::Error, E: std::error::Error,
T: Texture + 'static, T: Texture + 'static,
P: Into<Point<i32, Logical>>,
{ {
let location = location.into();
if let Some(surface) = layer.get_surface() { if let Some(surface) = layer.get_surface() {
draw_surface_tree(renderer, frame, surface, scale, location, damage, log)?; draw_surface_tree(renderer, frame, surface, scale, location, damage, log)?;
for (popup, p_location) in PopupManager::popups_for_surface(surface) for (popup, p_location) in PopupManager::popups_for_surface(surface)

View File

@ -98,22 +98,22 @@ impl Drop for Space {
impl Space { impl Space {
pub fn new<L>(log: L) -> Space pub fn new<L>(log: L) -> Space
where where
L: Into<slog::Logger>, L: Into<Option<slog::Logger>>,
{ {
Space { Space {
id: next_space_id(), id: next_space_id(),
windows: IndexSet::new(), windows: IndexSet::new(),
outputs: Vec::new(), outputs: Vec::new(),
logger: log.into(), logger: crate::slog_or_fallback(log),
} }
} }
/// Map window and moves it to top of the stack /// Map window and moves it to top of the stack
/// ///
/// This can safely be called on an already mapped window /// This can safely be called on an already mapped window
pub fn map_window(&mut self, window: &Window, location: Point<i32, Logical>) { pub fn map_window<P: Into<Point<i32, Logical>>>(&mut self, window: &Window, location: P) {
self.insert_window(window); self.insert_window(window);
window_state(self.id, window).location = location; window_state(self.id, window).location = location.into();
} }
pub fn raise_window(&mut self, window: &Window) { pub fn raise_window(&mut self, window: &Window) {
@ -148,7 +148,8 @@ impl Space {
} }
/// Get a reference to the window under a given point, if any /// Get a reference to the window under a given point, if any
pub fn window_under(&self, point: Point<f64, Logical>) -> Option<&Window> { pub fn window_under<P: Into<Point<f64, Logical>>>(&self, point: P) -> Option<&Window> {
let point = point.into();
self.windows.iter().rev().find(|w| { self.windows.iter().rev().find(|w| {
let bbox = window_rect(w, &self.id); let bbox = window_rect(w, &self.id);
bbox.to_f64().contains(point) bbox.to_f64().contains(point)
@ -156,7 +157,8 @@ impl Space {
} }
/// Get a reference to the output under a given point, if any /// Get a reference to the output under a given point, if any
pub fn output_under(&self, point: Point<f64, Logical>) -> Option<&Output> { pub fn output_under<P: Into<Point<f64, Logical>>>(&self, point: P) -> Option<&Output> {
let point = point.into();
self.outputs.iter().rev().find(|o| { self.outputs.iter().rev().find(|o| {
let bbox = self.output_geometry(o); let bbox = self.output_geometry(o);
bbox.map(|bbox| bbox.to_f64().contains(point)).unwrap_or(false) bbox.map(|bbox| bbox.to_f64().contains(point)).unwrap_or(false)
@ -199,10 +201,10 @@ impl Space {
Some(window_rect(w, &self.id)) Some(window_rect(w, &self.id))
} }
pub fn map_output(&mut self, output: &Output, scale: f64, location: Point<i32, Logical>) { pub fn map_output<P: Into<Point<i32, Logical>>>(&mut self, output: &Output, scale: f64, location: P) {
let mut state = output_state(self.id, output); let mut state = output_state(self.id, output);
*state = OutputState { *state = OutputState {
location, location: location.into(),
render_scale: scale, render_scale: scale,
..Default::default() ..Default::default()
}; };

View File

@ -21,7 +21,8 @@ impl SurfaceState {
.map(|dims| dims.to_logical(self.buffer_scale)) .map(|dims| dims.to_logical(self.buffer_scale))
} }
fn contains_point(&self, attrs: &SurfaceAttributes, point: Point<f64, Logical>) -> bool { fn contains_point<P: Into<Point<f64, Logical>>>(&self, attrs: &SurfaceAttributes, point: P) -> bool {
let point = point.into();
let size = match self.size() { let size = match self.size() {
None => return false, // If the surface has no size, it can't have an input region. None => return false, // If the surface has no size, it can't have an input region.
Some(size) => size, Some(size) => size,

View File

@ -221,10 +221,11 @@ impl Window {
/// Finds the topmost surface under this point if any and returns it together with the location of this /// Finds the topmost surface under this point if any and returns it together with the location of this
/// surface. /// surface.
pub fn surface_under( pub fn surface_under<P: Into<Point<f64, Logical>>>(
&self, &self,
point: Point<f64, Logical>, point: P,
) -> Option<(wl_surface::WlSurface, Point<i32, Logical>)> { ) -> Option<(wl_surface::WlSurface, Point<i32, Logical>)> {
let point = point.into();
if let Some(surface) = self.0.toplevel.get_surface() { if let Some(surface) = self.0.toplevel.get_surface() {
for (popup, location) in PopupManager::popups_for_surface(surface) for (popup, location) in PopupManager::popups_for_surface(surface)
.ok() .ok()
@ -276,12 +277,12 @@ impl Window {
} }
} }
pub fn draw_window<R, E, F, T>( pub fn draw_window<R, E, F, T, P>(
renderer: &mut R, renderer: &mut R,
frame: &mut F, frame: &mut F,
window: &Window, window: &Window,
scale: f64, scale: f64,
location: Point<i32, Logical>, location: P,
damage: &[Rectangle<i32, Logical>], damage: &[Rectangle<i32, Logical>],
log: &slog::Logger, log: &slog::Logger,
) -> Result<(), R::Error> ) -> Result<(), R::Error>
@ -290,7 +291,9 @@ where
F: Frame<Error = E, TextureId = T>, F: Frame<Error = E, TextureId = T>,
E: std::error::Error, E: std::error::Error,
T: Texture + 'static, T: Texture + 'static,
P: Into<Point<i32, Logical>>,
{ {
let location = location.into();
if let Some(surface) = window.toplevel().get_surface() { if let Some(surface) = window.toplevel().get_surface() {
draw_surface_tree(renderer, frame, surface, scale, location, damage, log)?; draw_surface_tree(renderer, frame, surface, scale, location, damage, log)?;
for (popup, p_location) in PopupManager::popups_for_surface(surface) for (popup, p_location) in PopupManager::popups_for_surface(surface)