refactor: minor mathes refactor
parent
130059b979
commit
5cdf4d5af9
|
@ -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();
|
||||||
|
|
|
@ -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,17 +270,17 @@ 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) {
|
||||||
info!("Configured output size: {:?}", size);
|
(w, h) if w > 1 && h > 1 => {
|
||||||
} else {
|
info!("Configured output size: {:?}", size);
|
||||||
return Err(anyhow::anyhow!("Invalid output size: {:?}", size));
|
Ok(())
|
||||||
|
}
|
||||||
|
_ => Err(anyhow::anyhow!("Invalid output size: {:?}", size)),
|
||||||
}
|
}
|
||||||
debug!("Surface configuration complete");
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn initialize_renderer_and_ui(&mut self) -> Result<()> {
|
fn initialize_renderer_and_ui(&mut self) -> Result<()> {
|
||||||
|
|
|
@ -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();
|
button: PointerEventButton::Left,
|
||||||
|
position: state.current_pointer_position(),
|
||||||
|
},
|
||||||
|
_ => WindowEvent::PointerReleased {
|
||||||
|
button: PointerEventButton::Left,
|
||||||
|
position: state.current_pointer_position(),
|
||||||
|
},
|
||||||
|
};
|
||||||
if let Some(window) = state.window() {
|
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);
|
window.dispatch_event(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue