From 3780c1aab59683b4f295935c070eac145eae309a Mon Sep 17 00:00:00 2001 From: Avii Date: Thu, 6 Aug 2026 21:01:58 +0200 Subject: [PATCH] 1786042918 --- src/trekstor.rs | 102 ++++++++++++++++++++++-------------------------- 1 file changed, 47 insertions(+), 55 deletions(-) diff --git a/src/trekstor.rs b/src/trekstor.rs index bdcc3a0..3f9318d 100644 --- a/src/trekstor.rs +++ b/src/trekstor.rs @@ -1,4 +1,6 @@ use std::rc::Rc; +use std::sync::atomic::{AtomicBool, Ordering}; +use std::sync::{Arc, Mutex}; use evdev::KeyCode; use linfb::shape::Color; @@ -19,30 +21,46 @@ pub struct Context { pub struct Trekstor { window: Rc, + queue: Queue, + quit_flag: Arc, } impl Trekstor { pub fn new() -> Self { let window = MinimalSoftwareWindow::new(RepaintBufferType::NewBuffer); - Self { window } + Self { + window, + queue: Arc::new(Mutex::new(Vec::new())), + quit_flag: Arc::new(AtomicBool::new(false)), + } } } +pub(crate) type Closure = Box; +pub(crate) type Queue = Arc>>; + struct TrekstorEventProxy { - // .. ???? + pub(crate) queue: Queue, + pub(crate) quit_flag: Arc, } impl EventLoopProxy for TrekstorEventProxy { fn quit_event_loop(&self) -> Result<(), EventLoopError> { + self.quit_flag.store(true, Ordering::SeqCst); Ok(()) } - fn invoke_from_event_loop( - &self, - event: Box, - ) -> Result<(), EventLoopError> { - // dafuq am i supposed to do with this ?? + fn invoke_from_event_loop(&self, event: Closure) -> Result<(), EventLoopError> { + // Don't queue if the loop is shutting down, the closure would never + // run, and any caller blocking on a channel send inside it would hang. + if self.quit_flag.load(Ordering::SeqCst) { + return Err(EventLoopError::EventLoopTerminated); + } + self.queue + .lock() + .expect("event loop closure queue poisoned") + .push(event); Ok(()) } } @@ -100,6 +118,20 @@ impl Platform for Trekstor { .unwrap(); } + let pending: Vec<_> = self + .queue + .lock() + .expect("event loop closure queue poisoned") + .drain(..) + .collect(); + for c in pending { + c(); + } + + if self.quit_flag.load(Ordering::SeqCst) { + break; + } + self.window.draw_if_needed(|renderer| { renderer.render(&mut buffer1, window_width as usize); @@ -117,54 +149,14 @@ impl Platform for Trekstor { ctx.input.finish(); } + + Ok(()) } - // fn new_event_loop_proxy(&self) -> Option> { - // // struct Proxy( - // // winit::event_loop::EventLoopProxy, - // // Arc, - // // ); - // // impl EventLoopProxy for Proxy { - // // fn quit_event_loop(&self) -> Result<(), EventLoopError> { - // // Err(EventLoopError::EventLoopTerminated) - // // } - - // // fn invoke_from_event_loop( - // // &self, - // // event: Box, - // // ) -> Result<(), EventLoopError> { - // // self.0 - // // .send_event(SlintEvent(CustomEvent::UserEvent(event))) - // // .map_err(|_| EventLoopError::EventLoopTerminated) - // // } - // // } - // // Some(Box::new(Proxy( - // // self.shared_data.event_loop_proxy.clone(), - // // Arc::clone(&self.shared_data.event_loop_generation), - // // ))) - // None - // } - - // fn click_interval(&self) -> core::time::Duration { - // // 500ms is the default delay according to https://en.wikipedia.org/wiki/Double-click#Speed_and_timing - // core::time::Duration::from_millis(500) - // } - - // fn cursor_flash_cycle(&self) -> core::time::Duration { - // core::time::Duration::from_millis(1000) - // } - - // fn set_clipboard_text(&self, _text: &str, _clipboard: slint::platform::Clipboard) {} - - // fn clipboard_text(&self, _clipboard: slint::platform::Clipboard) -> Option { - // None - // } - - // fn debug_log(&self, _arguments: core::fmt::Arguments) { - // crate::debug_log::default_log_message(_arguments); - // } - - // fn open_url(&self, _url: &str) -> Result<(), slint::PlatformError> { - // Err(slint::PlatformError::Unsupported) - // } + fn new_event_loop_proxy(&self) -> Option> { + Some(Box::new(TrekstorEventProxy { + queue: self.queue.clone(), + quit_flag: self.quit_flag.clone(), + })) + } }