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>>,
window: &Rc<FemtoVGWindow>,
) -> 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();

View File

@ -138,11 +138,10 @@ impl WindowingSystemBuilder {
}
pub fn build(self) -> Result<WindowingSystem> {
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<()> {

View File

@ -143,21 +143,17 @@ impl Dispatch<WlPointer, ()> 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);
}
}