x11: pass XCB conn error back through XcbConnection::new()
This commit is contained in:
parent
da2c12dd25
commit
b5dfbd946e
2 changed files with 11 additions and 6 deletions
|
@ -25,7 +25,8 @@ impl Window {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Connect to the X server
|
// 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 (?)
|
// Get screen information (?)
|
||||||
let setup = xcb_connection.conn.get_setup();
|
let setup = xcb_connection.conn.get_setup();
|
||||||
|
|
|
@ -13,15 +13,19 @@ pub struct XcbConnection {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl XcbConnection {
|
impl XcbConnection {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Result<Self, xcb::base::ConnError> {
|
||||||
let (conn, xlib_display) = xcb::Connection::connect_with_xlib_display().unwrap();
|
xcb::Connection::connect_with_xlib_display()
|
||||||
Self { conn, xlib_display }
|
.map(|(conn, xlib_display)|
|
||||||
|
Self {
|
||||||
|
conn,
|
||||||
|
xlib_display
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to get the scaling with this function first.
|
// Try to get the scaling with this function first.
|
||||||
// If this gives you `None`, fall back to `get_scaling_screen_dimensions`.
|
// 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.
|
// If neither work, I guess just assume 96.0 and don't do any scaling.
|
||||||
pub fn get_scaling_xft(&self) -> Option<f64> {
|
fn get_scaling_xft(&self) -> Option<f64> {
|
||||||
use x11::xlib::{
|
use x11::xlib::{
|
||||||
XResourceManagerString, XrmDestroyDatabase, XrmGetResource, XrmGetStringDatabase, XrmValue,
|
XResourceManagerString, XrmDestroyDatabase, XrmGetResource, XrmGetStringDatabase, XrmValue,
|
||||||
};
|
};
|
||||||
|
@ -71,7 +75,7 @@ impl XcbConnection {
|
||||||
// Try to get the scaling with `get_scaling_xft` first.
|
// Try to get the scaling with `get_scaling_xft` first.
|
||||||
// Only use this function as a fallback.
|
// Only use this function as a fallback.
|
||||||
// If neither work, I guess just assume 96.0 and don't do any scaling.
|
// If neither work, I guess just assume 96.0 and don't do any scaling.
|
||||||
pub fn get_scaling_screen_dimensions(&self) -> Option<f64> {
|
fn get_scaling_screen_dimensions(&self) -> Option<f64> {
|
||||||
// Figure out screen information
|
// Figure out screen information
|
||||||
let setup = self.conn.get_setup();
|
let setup = self.conn.get_setup();
|
||||||
let screen = setup
|
let screen = setup
|
||||||
|
|
Loading…
Add table
Reference in a new issue