diff --git a/locker/src/monitor.rs b/locker/src/monitor.rs index 2d97249..4ad1c25 100644 --- a/locker/src/monitor.rs +++ b/locker/src/monitor.rs @@ -2,7 +2,7 @@ use log::{debug, warn}; use std::cmp; use xcb::{x, randr, Xid}; -use bscreensaver_util::{BSCREENSAVER_WM_CLASS, create_atom, destroy_pixmap}; +use bscreensaver_util::{BSCREENSAVER_WM_CLASS, create_atom, destroy_cursor, destroy_pixmap, destroy_gc, destroy_window}; const BACKLIGHT_ATOM_NAME: &[u8] = b"Backlight"; const BACKLIGHT_FALLBACK_ATOM_NAME: &[u8] = b"BACKLIGHT"; @@ -88,6 +88,13 @@ impl Monitor { Ok(monitors) } + pub fn release(self, conn: &xcb::Connection) { + let _ = destroy_cursor(conn, self.blank_cursor); + let _ = destroy_window(&conn, self.unlock_window); + let _ = destroy_window(&conn, self.blanker_window); + let _ = destroy_gc(&conn, self.black_gc); + } + pub fn geometry(&self) -> x::Rectangle { x::Rectangle { x: self.x, diff --git a/locker/src/screensaver.rs b/locker/src/screensaver.rs index 90925b0..7e18a3b 100644 --- a/locker/src/screensaver.rs +++ b/locker/src/screensaver.rs @@ -130,10 +130,9 @@ impl<'a> Screensaver<'a> { match event { xcb::Event::RandR(randr::Event::Notify(ev)) => { debug!("Got xrandr notify event: {:#?}", ev); - for monitor in &self.monitors { - destroy_window(&conn, monitor.unlock_window)?; - destroy_window(&conn, monitor.blanker_window)?; - destroy_gc(&conn, monitor.black_gc)?; + let old_monitors = std::mem::replace(&mut self.monitors, Vec::new()); + for monitor in old_monitors { + monitor.release(conn); } self.monitors = Monitor::set_up_all(conn)?; match self.blanker_state {