Skip to content

Commit

Permalink
Improved handling of screen removal
Browse files Browse the repository at this point in the history
* now, redraws are triggered when necessary, as pointed out in #26
  • Loading branch information
ibabushkin committed Nov 19, 2016
1 parent 284c403 commit 735f669
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
13 changes: 9 additions & 4 deletions src/wm/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,7 @@ impl ScreenSet {
}
}

/// Get an immutable reference to the set of screens.
pub fn screens(&self) -> &[(Crtc, Screen)] {
&self.screens
}
Expand Down Expand Up @@ -799,17 +800,21 @@ impl ScreenSet {
}
}

/// Remove a CRTC from our list of screens.
pub fn remove(&mut self, old_crtc: Crtc) {
if let Some(&(crtc, _)) = self.screens.get(self.current_screen) {
/// Remove a CRTC from our list of screens and return whether a redraw is necessary.
pub fn remove(&mut self, old_crtc: Crtc) -> bool {
let ret = if let Some(&(crtc, _)) = self.screens.get(self.current_screen) {
if crtc == old_crtc {
self.current_screen = 0;
true
} else {
false
}
} else {
panic!("logic error in ScreenSet :O");
}
};

self.screens.retain(|&(crtc, _)| crtc != old_crtc);
ret
}

/// Apply a screen matching to all screens (that is, CRTCs) that we know of.
Expand Down
6 changes: 4 additions & 2 deletions src/wm/window_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ impl<'a> Wm<'a> {
root: root,
randr_base: 0,
border_width: config.border_width,
// TODO: remove this ugly hack
safe_x: screen.width_in_pixels() as u32,
border_colors: colors,
screens: try!(Wm::setup_screens(con, root)),
Expand Down Expand Up @@ -503,8 +502,11 @@ impl<'a> Wm<'a> {
let crtc_change: randr::CrtcChange = ev.u().cc();

if crtc_change.mode() == 0 {
self.screens.remove(crtc_change.crtc());
info!("a crtc/screen removed from the screen set");
if self.screens.remove(crtc_change.crtc()) {
self.arrange_windows();
self.reset_focus();
}
} else {
self.screens.update(&crtc_change);
info!("a crtc/screen from the screen set changed");
Expand Down

0 comments on commit 735f669

Please sign in to comment.