From 447dfd21334ec3e28acb127f2b56a0e9d5d61e97 Mon Sep 17 00:00:00 2001 From: MarcusGrass <34198073+MarcusGrass@users.noreply.github.com> Date: Sat, 20 Aug 2022 00:26:03 -0700 Subject: [PATCH] Use added methods in x11rb to prevent crashing on start if no resource db is available (#11) --- pgwm/src/error.rs | 2 -- pgwm/src/wm.rs | 20 ++------------------ 2 files changed, 2 insertions(+), 20 deletions(-) diff --git a/pgwm/src/error.rs b/pgwm/src/error.rs index 1c5514e..893b903 100644 --- a/pgwm/src/error.rs +++ b/pgwm/src/error.rs @@ -18,8 +18,6 @@ pub(crate) enum Error { X11IdCreation(#[from] ReplyOrIdError), #[error("Failed to parse event")] X11EventParse, - #[error("Failed to open default db")] - X11OpenDefaultDb, #[error("Number of glyph ids not corresponding to number of metrics")] GlyphMismatch, #[error("Could not become wm, access denied, there is likely another WM running")] diff --git a/pgwm/src/wm.rs b/pgwm/src/wm.rs index d8b02c5..6e0caab 100644 --- a/pgwm/src/wm.rs +++ b/pgwm/src/wm.rs @@ -81,24 +81,8 @@ pub(crate) fn run_wm() -> Result<()> { call_wrapper.try_become_wm(screen)?; pgwm_core::debug!("Became wm"); - //let resource_db = x11rb::resource_manager::new_from_resource_manager(&connection)? - // .ok_or(Error::X11OpenDefaultDb)?; - let rdb = x11rb::resource_manager::protocol::Database::GET_RESOURCE_DATABASE; - let get_prop = x11rb::xcb::xproto::get_property( - call_wrapper.inner_mut(), - rdb.delete, - screen.root, - rdb.property, - rdb.type_, - rdb.long_offset, - rdb.long_length, - false, - )? - .reply(call_wrapper.inner_mut())?; pgwm_core::debug!("Got resource database properties"); - let resource_db = - x11rb::resource_manager::protocol::Database::new_from_get_property_reply(&get_prop) - .ok_or(Error::X11OpenDefaultDb)?; + let resource_db = x11rb::resource_manager::new_from_default(call_wrapper.inner_mut())?; let cursor_handle = x11rb::cursor::Handle::new(call_wrapper.inner_mut(), 0, &resource_db)?; let visual = find_render_visual_info(call_wrapper.inner_mut(), screen)?; let loaded = load_alloc_fonts(&mut call_wrapper, &visual, &fonts, &char_remap)?; @@ -265,7 +249,7 @@ fn handle_event<'a>( state: &mut State, ) -> Result<()> { // Ripped from xcb_connection_protocol, non-public small parsing functions - let response_type = raw.get(0).map(|x| x & 0x7f).ok_or(Error::X11EventParse)?; + let response_type = raw.first().map(|x| x & 0x7f).ok_or(Error::X11EventParse)?; let seq = raw .get(2..4) .map(|b| u16::from_ne_bytes(b.try_into().unwrap()))