desktop: map_window remove unnecessary Result and activate
This commit is contained in:
parent
2c0ae025de
commit
7578fab9cf
|
@ -117,16 +117,10 @@ impl Space {
|
||||||
/// 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>) -> Result<(), SpaceError> {
|
pub fn map_window(&mut self, window: &Window, location: Point<i32, Logical>) {
|
||||||
window_state(self.id, window).location = location;
|
window_state(self.id, window).location = location - window.geometry().loc;
|
||||||
self.windows.shift_remove(window);
|
self.windows.shift_remove(window);
|
||||||
self.windows.insert(window.clone());
|
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?
|
// TODO: should this be handled by us?
|
||||||
window.set_activated(true);
|
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
|
/// Unmap a window from this space by its id
|
||||||
pub fn unmap_window(&mut self, window: &Window) {
|
pub fn unmap_window(&mut self, window: &Window) {
|
||||||
if let Some(map) = window.user_data().get::<WindowUserdata>() {
|
if let Some(map) = window.user_data().get::<WindowUserdata>() {
|
||||||
|
@ -153,9 +152,7 @@ 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(&self, point: Point<f64, Logical>) -> Option<&Window> {
|
||||||
self.windows.iter().find(|w| {
|
self.windows.iter().find(|w| {
|
||||||
let loc = window_state(self.id, w).location;
|
let bbox = window_rect(w, &self.id);
|
||||||
let mut bbox = w.bbox();
|
|
||||||
bbox.loc += loc;
|
|
||||||
bbox.to_f64().contains(point)
|
bbox.to_f64().contains(point)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -175,6 +172,14 @@ impl Space {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Some(window_geo(w, &self.id))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn window_bbox(&self, w: &Window) -> Option<Rectangle<i32, Logical>> {
|
||||||
|
if !self.windows.contains(w) {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
Some(window_rect(w, &self.id))
|
Some(window_rect(w, &self.id))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -397,7 +402,7 @@ impl Space {
|
||||||
})
|
})
|
||||||
.collect::<Vec<Rectangle<i32, Logical>>>()
|
.collect::<Vec<Rectangle<i32, Logical>>>()
|
||||||
{
|
{
|
||||||
slog::debug!(self.logger, "Removing window at: {:?}", old_window);
|
slog::trace!(self.logger, "Removing window at: {:?}", old_window);
|
||||||
damage.push(old_window);
|
damage.push(old_window);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -456,7 +461,7 @@ impl Space {
|
||||||
|renderer, frame| {
|
|renderer, frame| {
|
||||||
// First clear all damaged regions
|
// First clear all damaged regions
|
||||||
for geo in &damage {
|
for geo in &damage {
|
||||||
slog::debug!(self.logger, "Clearing at {:?}", geo);
|
slog::trace!(self.logger, "Clearing at {:?}", geo);
|
||||||
frame.clear(
|
frame.clear(
|
||||||
clear_color,
|
clear_color,
|
||||||
Some(geo.to_f64().to_physical(state.render_scale).to_i32_ceil()),
|
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);
|
let mut loc = window_loc(window, &self.id);
|
||||||
if damage.iter().any(|geo| wgeo.overlaps(*geo)) {
|
if damage.iter().any(|geo| wgeo.overlaps(*geo)) {
|
||||||
loc -= output_geo.loc;
|
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)?;
|
draw_window(renderer, frame, window, state.render_scale, loc, &self.logger)?;
|
||||||
window_state(self.id, window).drawn = true;
|
window_state(self.id, window).drawn = true;
|
||||||
}
|
}
|
||||||
|
@ -520,9 +525,18 @@ pub enum RenderError<R: Renderer> {
|
||||||
OutputNoMode,
|
OutputNoMode,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn window_geo(window: &Window, space_id: &usize) -> Rectangle<i32, Logical> {
|
||||||
|
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<i32, Logical> {
|
fn window_rect(window: &Window, space_id: &usize) -> Rectangle<i32, Logical> {
|
||||||
let loc = window_loc(window, space_id);
|
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<i32, Logical> {
|
fn window_loc(window: &Window, space_id: &usize) -> Point<i32, Logical> {
|
||||||
|
@ -535,9 +549,3 @@ fn window_loc(window: &Window, space_id: &usize) -> Point<i32, Logical> {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.location
|
.location
|
||||||
}
|
}
|
||||||
|
|
||||||
fn window_bbox_with_pos(window: &Window, pos: Point<i32, Logical>) -> Rectangle<i32, Logical> {
|
|
||||||
let mut wgeo = window.bbox();
|
|
||||||
wgeo.loc += pos;
|
|
||||||
wgeo
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue