From 5cdf4d5af96fb52c71d08a5ae6cc8c337dbcd2fe Mon Sep 17 00:00:00 2001 From: drendog Date: Sat, 17 Aug 2024 22:41:26 +0200 Subject: [PATCH] refactor: minor mathes refactor --- src/windowing/event_loop.rs | 12 +++--------- src/windowing/mod.rs | 23 +++++++++++------------ src/windowing/state/dispatches.rs | 24 ++++++++++-------------- 3 files changed, 24 insertions(+), 35 deletions(-) diff --git a/src/windowing/event_loop.rs b/src/windowing/event_loop.rs index b2fe174..5f46cbe 100644 --- a/src/windowing/event_loop.rs +++ b/src/windowing/event_loop.rs @@ -66,20 +66,14 @@ impl EventLoopHandler { state: &Rc>, window: &Rc, ) -> Result<()> { - connection - .flush() - .map_err(|e| anyhow!("Failed to flush connection: {}", e))?; + connection.flush()?; let mut event_queue = wayland_queue.borrow_mut(); if let Some(guard) = event_queue.prepare_read() { - guard - .read() - .map_err(|e| anyhow!("Failed to read Wayland events: {}", e))?; + guard.read()?; } - event_queue - .blocking_dispatch(&mut state.borrow_mut()) - .map_err(|e| anyhow!("Failed to dispatch Wayland events: {}", e))?; + event_queue.blocking_dispatch(&mut state.borrow_mut())?; slint::platform::update_timers_and_animations(); window.render_frame_if_dirty(); diff --git a/src/windowing/mod.rs b/src/windowing/mod.rs index 8befd3b..4fedcb8 100644 --- a/src/windowing/mod.rs +++ b/src/windowing/mod.rs @@ -138,11 +138,10 @@ impl WindowingSystemBuilder { } pub fn build(self) -> Result { - if self.config.component_definition.is_none() { - return Err(anyhow::anyhow!("Slint component not set")); + match self.config.component_definition { + Some(_) => WindowingSystem::new(self.config), + None => Err(anyhow::anyhow!("Slint component not set")), } - - WindowingSystem::new(self.config) } } @@ -271,17 +270,17 @@ impl WindowingSystem { let mut state = self.state.borrow_mut(); self.event_queue .borrow_mut() - .blocking_dispatch(&mut state) - .context("Failed to dispatch events")?; + .blocking_dispatch(&mut state)?; info!("Blocking dispatch completed"); + let size = state.output_size(); - if size.width > 1 && size.height > 1 { - info!("Configured output size: {:?}", size); - } else { - return Err(anyhow::anyhow!("Invalid output size: {:?}", size)); + match (size.width, size.height) { + (w, h) if w > 1 && h > 1 => { + info!("Configured output size: {:?}", size); + Ok(()) + } + _ => Err(anyhow::anyhow!("Invalid output size: {:?}", size)), } - debug!("Surface configuration complete"); - Ok(()) } fn initialize_renderer_and_ui(&mut self) -> Result<()> { diff --git a/src/windowing/state/dispatches.rs b/src/windowing/state/dispatches.rs index 3c88f1a..4ad5ae2 100644 --- a/src/windowing/state/dispatches.rs +++ b/src/windowing/state/dispatches.rs @@ -143,21 +143,17 @@ impl Dispatch for WindowState { state: button_state, .. } => { - let is_press = - matches!(button_state, WEnum::Value(wl_pointer::ButtonState::Pressed)); - let current_position = state.current_pointer_position(); + let event = match button_state { + WEnum::Value(wl_pointer::ButtonState::Pressed) => WindowEvent::PointerPressed { + button: PointerEventButton::Left, + position: state.current_pointer_position(), + }, + _ => WindowEvent::PointerReleased { + button: PointerEventButton::Left, + position: state.current_pointer_position(), + }, + }; if let Some(window) = state.window() { - let event = if is_press { - WindowEvent::PointerPressed { - button: PointerEventButton::Left, - position: current_position, - } - } else { - WindowEvent::PointerReleased { - button: PointerEventButton::Left, - position: current_position, - } - }; window.dispatch_event(event); } }