1786042918
This commit is contained in:
102
src/trekstor.rs
102
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<MinimalSoftwareWindow>,
|
||||
queue: Queue,
|
||||
quit_flag: Arc<AtomicBool>,
|
||||
}
|
||||
|
||||
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<dyn FnOnce() + Send>;
|
||||
pub(crate) type Queue = Arc<Mutex<Vec<Closure>>>;
|
||||
|
||||
struct TrekstorEventProxy {
|
||||
// .. ????
|
||||
pub(crate) queue: Queue,
|
||||
pub(crate) quit_flag: Arc<AtomicBool>,
|
||||
}
|
||||
|
||||
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<dyn FnOnce() + Send>,
|
||||
) -> 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<Box<dyn EventLoopProxy>> {
|
||||
// // struct Proxy(
|
||||
// // winit::event_loop::EventLoopProxy<SlintEvent>,
|
||||
// // Arc<AtomicUsize>,
|
||||
// // );
|
||||
// // impl EventLoopProxy for Proxy {
|
||||
// // fn quit_event_loop(&self) -> Result<(), EventLoopError> {
|
||||
// // Err(EventLoopError::EventLoopTerminated)
|
||||
// // }
|
||||
|
||||
// // fn invoke_from_event_loop(
|
||||
// // &self,
|
||||
// // event: Box<dyn FnOnce() + Send>,
|
||||
// // ) -> 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<String> {
|
||||
// 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<Box<dyn EventLoopProxy>> {
|
||||
Some(Box::new(TrekstorEventProxy {
|
||||
queue: self.queue.clone(),
|
||||
quit_flag: self.quit_flag.clone(),
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user