diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 68 |
1 files changed, 37 insertions, 31 deletions
diff --git a/src/main.rs b/src/main.rs index 946c0ca..5b15b9a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -83,37 +83,8 @@ impl<'a> WM<'a> { pub fn event_loop(&mut self) -> Result<()> { loop { match self.conn.wait_for_event() { - Ok(x) => { - debug!("received event: {x:?}"); - - match x { - // See keys.rs - Event::X(x::Event::KeyPress(e)) => self.handle_key_press(&e), - Event::X(x::Event::MappingNotify(e)) => self.handle_mapping_notify(&e)?, - - // See buttons.rs - Event::X(x::Event::ButtonPress(e)) => self.handle_button_press(&e), - - // See clients/mod.rs - Event::X(x::Event::ConfigureRequest(e)) => { - self.handle_configure_request(&e)?; - } - Event::X(x::Event::ConfigureNotify(e)) => { - self.handle_configure_notify(&e)?; - } - Event::X(x::Event::DestroyNotify(e)) => self.handle_destroy_notify(&e), - Event::X(x::Event::MapRequest(e)) => self.handle_map_request(&e)?, - Event::X(x::Event::UnmapNotify(e)) => self.handle_unmap_notify(&e), - - // See focus.rs - Event::X(x::Event::EnterNotify(e)) => self.handle_enter_notify(&e), - Event::X(x::Event::FocusIn(e)) => self.handle_focus_in(&e), - - // See below - Event::X(x::Event::PropertyNotify(e)) => self.handle_property_notify(&e), - Event::X(x::Event::ClientMessage(e)) => self.handle_client_message(&e), - _ => {} - } + Ok(e) => { + self.dispatch_event(e)?; } Err(Error::Xcb(xcb::Error::Protocol(e))) => { eprintln!("protocol error in event loop: {e:#?}\ncontinuing anyway"); @@ -127,6 +98,41 @@ impl<'a> WM<'a> { } } + pub fn dispatch_event(&mut self, e: xcb::Event) -> Result<()> { + debug!("received event: {e:?}"); + + match e { + // See keys.rs + Event::X(x::Event::KeyPress(e)) => self.handle_key_press(&e), + Event::X(x::Event::MappingNotify(e)) => self.handle_mapping_notify(&e)?, + + // See buttons.rs + Event::X(x::Event::ButtonPress(e)) => self.handle_button_press(&e), + + // See clients/mod.rs + Event::X(x::Event::ConfigureRequest(e)) => { + self.handle_configure_request(&e)?; + } + Event::X(x::Event::ConfigureNotify(e)) => { + self.handle_configure_notify(&e)?; + } + Event::X(x::Event::DestroyNotify(e)) => self.handle_destroy_notify(&e), + Event::X(x::Event::MapRequest(e)) => self.handle_map_request(&e)?, + Event::X(x::Event::UnmapNotify(e)) => self.handle_unmap_notify(&e), + + // See focus.rs + Event::X(x::Event::EnterNotify(e)) => self.handle_enter_notify(&e), + Event::X(x::Event::FocusIn(e)) => self.handle_focus_in(&e), + + // See below + Event::X(x::Event::PropertyNotify(e)) => self.handle_property_notify(&e), + Event::X(x::Event::ClientMessage(e)) => self.handle_client_message(&e), + _ => {} + } + + Ok(()) + } + /// Update client properties when they change in X11. fn handle_property_notify(&mut self, e: &PropertyNotifyEvent) { if x::ATOM_WM_HINTS == e.atom() { |