Make monitor resource freeing better

This commit is contained in:
Brian Tarricone 2022-05-27 18:11:20 -07:00
parent a516a25a9f
commit e89b6cb604
2 changed files with 11 additions and 5 deletions

View File

@ -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,

View File

@ -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 {