Split Monitor detection/creation

This commit is contained in:
Brian Tarricone 2022-05-27 18:16:02 -07:00
parent e89b6cb604
commit 761b906fb7

View File

@ -48,39 +48,8 @@ impl Monitor {
crtc: output_info.crtc(),
config_timestamp,
});
let reply = conn.wait_for_reply(cookie)?;
let (blanker_window, unlock_window) = create_windows(conn, &screen, &reply)?;
let blank_cursor = create_blank_cursor(conn, &screen)?;
let black_gc: x::Gcontext = conn.generate_id();
conn.send_and_check_request(&x::CreateGc {
cid: black_gc,
drawable: x::Drawable::Window(screen.root()),
value_list: &[
x::Gc::Foreground(screen.black_pixel()),
x::Gc::Background(screen.black_pixel()),
],
})?;
let backlight_control = find_backlight_control(conn, *output);
if let Err(err) = &backlight_control {
warn!("Failed to find backlight control: {}", err);
}
monitors.push(Monitor {
root: screen.root(),
black_gc,
output: *output,
blanker_window,
unlock_window,
blank_cursor,
x: reply.x(),
y: reply.y(),
width: reply.width(),
height: reply.height(),
backlight_control: backlight_control.ok().flatten(),
});
let crtc_info = conn.wait_for_reply(cookie)?;
monitors.push(Monitor::new(conn, &screen, *output, &crtc_info)?);
}
}
}
@ -88,6 +57,40 @@ impl Monitor {
Ok(monitors)
}
pub fn new(conn: &xcb::Connection, screen: &x::Screen, output: randr::Output, crtc_info: &randr::GetCrtcInfoReply) -> xcb::Result<Monitor> {
let (blanker_window, unlock_window) = create_windows(conn, &screen, &crtc_info)?;
let blank_cursor = create_blank_cursor(conn, &screen)?;
let black_gc: x::Gcontext = conn.generate_id();
conn.send_and_check_request(&x::CreateGc {
cid: black_gc,
drawable: x::Drawable::Window(screen.root()),
value_list: &[
x::Gc::Foreground(screen.black_pixel()),
x::Gc::Background(screen.black_pixel()),
],
})?;
let backlight_control = find_backlight_control(conn, output);
if let Err(err) = &backlight_control {
warn!("Failed to find backlight control: {}", err);
}
Ok(Monitor {
root: screen.root(),
black_gc,
output,
blanker_window,
unlock_window,
blank_cursor,
x: crtc_info.x(),
y: crtc_info.y(),
width: crtc_info.width(),
height: crtc_info.height(),
backlight_control: backlight_control.ok().flatten(),
})
}
pub fn release(self, conn: &xcb::Connection) {
let _ = destroy_cursor(conn, self.blank_cursor);
let _ = destroy_window(&conn, self.unlock_window);