diff --git a/src/desktop/space.rs b/src/desktop/space.rs index 93bedf0..28a1280 100644 --- a/src/desktop/space.rs +++ b/src/desktop/space.rs @@ -117,16 +117,10 @@ impl Space { /// Map window and moves it to top of the stack /// /// This can safely be called on an already mapped window - pub fn map_window(&mut self, window: &Window, location: Point) -> Result<(), SpaceError> { - window_state(self.id, window).location = location; + pub fn map_window(&mut self, window: &Window, location: Point) { + window_state(self.id, window).location = location - window.geometry().loc; self.windows.shift_remove(window); self.windows.insert(window.clone()); - Ok(()) - } - - pub fn raise_window(&mut self, window: &Window) { - let loc = window_state(self.id, window).location; - let _ = self.map_window(window, loc); // TODO: should this be handled by us? window.set_activated(true); @@ -137,6 +131,11 @@ impl Space { } } + pub fn raise_window(&mut self, window: &Window) { + let loc = window_geo(window, &self.id).loc; + self.map_window(window, loc); + } + /// Unmap a window from this space by its id pub fn unmap_window(&mut self, window: &Window) { if let Some(map) = window.user_data().get::() { @@ -153,9 +152,7 @@ impl Space { /// Get a reference to the window under a given point, if any pub fn window_under(&self, point: Point) -> Option<&Window> { self.windows.iter().find(|w| { - let loc = window_state(self.id, w).location; - let mut bbox = w.bbox(); - bbox.loc += loc; + let bbox = window_rect(w, &self.id); bbox.to_f64().contains(point) }) } @@ -175,6 +172,14 @@ impl Space { return None; } + Some(window_geo(w, &self.id)) + } + + pub fn window_bbox(&self, w: &Window) -> Option> { + if !self.windows.contains(w) { + return None; + } + Some(window_rect(w, &self.id)) } @@ -397,7 +402,7 @@ impl Space { }) .collect::>>() { - slog::debug!(self.logger, "Removing window at: {:?}", old_window); + slog::trace!(self.logger, "Removing window at: {:?}", old_window); damage.push(old_window); } @@ -456,7 +461,7 @@ impl Space { |renderer, frame| { // First clear all damaged regions for geo in &damage { - slog::debug!(self.logger, "Clearing at {:?}", geo); + slog::trace!(self.logger, "Clearing at {:?}", geo); frame.clear( clear_color, Some(geo.to_f64().to_physical(state.render_scale).to_i32_ceil()), @@ -469,7 +474,7 @@ impl Space { let mut loc = window_loc(window, &self.id); if damage.iter().any(|geo| wgeo.overlaps(*geo)) { loc -= output_geo.loc; - slog::debug!(self.logger, "Rendering window at {:?}", wgeo); + slog::trace!(self.logger, "Rendering window at {:?}", wgeo); draw_window(renderer, frame, window, state.render_scale, loc, &self.logger)?; window_state(self.id, window).drawn = true; } @@ -520,9 +525,18 @@ pub enum RenderError { OutputNoMode, } +fn window_geo(window: &Window, space_id: &usize) -> Rectangle { + let loc = window_loc(window, space_id); + let mut wgeo = window.geometry(); + wgeo.loc += loc; + wgeo +} + fn window_rect(window: &Window, space_id: &usize) -> Rectangle { let loc = window_loc(window, space_id); - window_bbox_with_pos(window, loc) + let mut wgeo = window.bbox(); + wgeo.loc += loc; + wgeo } fn window_loc(window: &Window, space_id: &usize) -> Point { @@ -535,9 +549,3 @@ fn window_loc(window: &Window, space_id: &usize) -> Point { .unwrap() .location } - -fn window_bbox_with_pos(window: &Window, pos: Point) -> Rectangle { - let mut wgeo = window.bbox(); - wgeo.loc += pos; - wgeo -}