From 761b906fb7e7d10882b6e933dbf6136bae46d33a Mon Sep 17 00:00:00 2001 From: "Brian J. Tarricone" Date: Fri, 27 May 2022 18:16:02 -0700 Subject: [PATCH] Split Monitor detection/creation --- locker/src/monitor.rs | 69 ++++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 33 deletions(-) diff --git a/locker/src/monitor.rs b/locker/src/monitor.rs index 4ad1c25..b1c1524 100644 --- a/locker/src/monitor.rs +++ b/locker/src/monitor.rs @@ -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 { + 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);