From b5dfbd946e53e35270117213f7c642cb25708fda Mon Sep 17 00:00:00 2001 From: William Light Date: Fri, 11 Sep 2020 15:47:00 +0200 Subject: [PATCH] x11: pass XCB conn error back through XcbConnection::new() --- src/x11/window.rs | 3 ++- src/x11/xcb_connection.rs | 14 +++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/x11/window.rs b/src/x11/window.rs index 4951a01..51a2dd0 100644 --- a/src/x11/window.rs +++ b/src/x11/window.rs @@ -25,7 +25,8 @@ impl Window { }; // Connect to the X server - let xcb_connection = XcbConnection::new(); + // FIXME: baseview error type instead of unwrap() + let xcb_connection = XcbConnection::new().unwrap(); // Get screen information (?) let setup = xcb_connection.conn.get_setup(); diff --git a/src/x11/xcb_connection.rs b/src/x11/xcb_connection.rs index e0725f6..f4bab15 100644 --- a/src/x11/xcb_connection.rs +++ b/src/x11/xcb_connection.rs @@ -13,15 +13,19 @@ pub struct XcbConnection { } impl XcbConnection { - pub fn new() -> Self { - let (conn, xlib_display) = xcb::Connection::connect_with_xlib_display().unwrap(); - Self { conn, xlib_display } + pub fn new() -> Result { + xcb::Connection::connect_with_xlib_display() + .map(|(conn, xlib_display)| + Self { + conn, + xlib_display + }) } // Try to get the scaling with this function first. // If this gives you `None`, fall back to `get_scaling_screen_dimensions`. // If neither work, I guess just assume 96.0 and don't do any scaling. - pub fn get_scaling_xft(&self) -> Option { + fn get_scaling_xft(&self) -> Option { use x11::xlib::{ XResourceManagerString, XrmDestroyDatabase, XrmGetResource, XrmGetStringDatabase, XrmValue, }; @@ -71,7 +75,7 @@ impl XcbConnection { // Try to get the scaling with `get_scaling_xft` first. // Only use this function as a fallback. // If neither work, I guess just assume 96.0 and don't do any scaling. - pub fn get_scaling_screen_dimensions(&self) -> Option { + fn get_scaling_screen_dimensions(&self) -> Option { // Figure out screen information let setup = self.conn.get_setup(); let screen = setup