refactor: minor mathes refactor

WIP/draft
drendog 2024-08-17 22:41:26 +02:00
parent 130059b979
commit 5cdf4d5af9
Signed by: dwenya
GPG Key ID: 8DD77074645332D0
3 changed files with 24 additions and 35 deletions

View File

@ -66,20 +66,14 @@ impl EventLoopHandler {
state: &Rc<RefCell<WindowState>>, state: &Rc<RefCell<WindowState>>,
window: &Rc<FemtoVGWindow>, window: &Rc<FemtoVGWindow>,
) -> Result<()> { ) -> Result<()> {
connection connection.flush()?;
.flush()
.map_err(|e| anyhow!("Failed to flush connection: {}", e))?;
let mut event_queue = wayland_queue.borrow_mut(); let mut event_queue = wayland_queue.borrow_mut();
if let Some(guard) = event_queue.prepare_read() { if let Some(guard) = event_queue.prepare_read() {
guard guard.read()?;
.read()
.map_err(|e| anyhow!("Failed to read Wayland events: {}", e))?;
} }
event_queue event_queue.blocking_dispatch(&mut state.borrow_mut())?;
.blocking_dispatch(&mut state.borrow_mut())
.map_err(|e| anyhow!("Failed to dispatch Wayland events: {}", e))?;
slint::platform::update_timers_and_animations(); slint::platform::update_timers_and_animations();
window.render_frame_if_dirty(); window.render_frame_if_dirty();

View File

@ -138,11 +138,10 @@ impl WindowingSystemBuilder {
} }
pub fn build(self) -> Result<WindowingSystem> { pub fn build(self) -> Result<WindowingSystem> {
if self.config.component_definition.is_none() { match self.config.component_definition {
return Err(anyhow::anyhow!("Slint component not set")); Some(_) => WindowingSystem::new(self.config),
None => Err(anyhow::anyhow!("Slint component not set")),
} }
WindowingSystem::new(self.config)
} }
} }
@ -271,18 +270,18 @@ impl WindowingSystem {
let mut state = self.state.borrow_mut(); let mut state = self.state.borrow_mut();
self.event_queue self.event_queue
.borrow_mut() .borrow_mut()
.blocking_dispatch(&mut state) .blocking_dispatch(&mut state)?;
.context("Failed to dispatch events")?;
info!("Blocking dispatch completed"); info!("Blocking dispatch completed");
let size = state.output_size(); let size = state.output_size();
if size.width > 1 && size.height > 1 { match (size.width, size.height) {
(w, h) if w > 1 && h > 1 => {
info!("Configured output size: {:?}", size); info!("Configured output size: {:?}", size);
} else {
return Err(anyhow::anyhow!("Invalid output size: {:?}", size));
}
debug!("Surface configuration complete");
Ok(()) Ok(())
} }
_ => Err(anyhow::anyhow!("Invalid output size: {:?}", size)),
}
}
fn initialize_renderer_and_ui(&mut self) -> Result<()> { fn initialize_renderer_and_ui(&mut self) -> Result<()> {
let renderer = self.create_renderer()?; let renderer = self.create_renderer()?;

View File

@ -143,21 +143,17 @@ impl Dispatch<WlPointer, ()> for WindowState {
state: button_state, state: button_state,
.. ..
} => { } => {
let is_press = let event = match button_state {
matches!(button_state, WEnum::Value(wl_pointer::ButtonState::Pressed)); WEnum::Value(wl_pointer::ButtonState::Pressed) => WindowEvent::PointerPressed {
let current_position = state.current_pointer_position();
if let Some(window) = state.window() {
let event = if is_press {
WindowEvent::PointerPressed {
button: PointerEventButton::Left, button: PointerEventButton::Left,
position: current_position, position: state.current_pointer_position(),
} },
} else { _ => WindowEvent::PointerReleased {
WindowEvent::PointerReleased {
button: PointerEventButton::Left, button: PointerEventButton::Left,
position: current_position, position: state.current_pointer_position(),
} },
}; };
if let Some(window) = state.window() {
window.dispatch_event(event); window.dispatch_event(event);
} }
} }