Signed-off-by: Frank Villaro-Dixon <frank@villaro-dixon.eu>
This commit is contained in:
Frank Villaro-Dixon 2024-05-16 22:35:08 +02:00
parent f0885efd27
commit 5456c6845e
4 changed files with 25 additions and 44 deletions

View file

@ -1,5 +1,3 @@
use std::thread::current;
pub struct BeoApps {
pub apps: Vec<Box<dyn App>>,
}
@ -51,14 +49,6 @@ impl Menu {
self.selected_submenu = Some(self.submenus[self.current_submenu_id].clone());
}
pub fn get_deepest_selected_submenu_mut(&mut self) -> &mut Menu {
// Use a loop to traverse to the deepest submenu
let mut current_menu = self;
while let Some(ref mut selected_submenu) = current_menu.selected_submenu {
current_menu = selected_submenu;
}
current_menu
}
pub fn get_deepest_selected_submenu(&self) -> &Menu {
// Use a loop to traverse to the deepest submenu
let mut current_menu = self;

View file

@ -9,6 +9,7 @@ use std::{
const LASER_POINTER_MAX: i32 = 121;
#[derive(Debug)]
#[allow(dead_code)]
pub enum Beo5Event {
LaserPosition(f32),
SelectionWheelRel(i32),
@ -49,10 +50,12 @@ impl Beo5Device {
nix::fcntl::fcntl(raw_fd, FcntlArg::F_SETFL(OFlag::O_NONBLOCK)).unwrap();
// Create epoll handle and attach raw_fd
#[allow(deprecated)]
let epoll_fd = epoll::epoll_create1(epoll::EpollCreateFlags::EPOLL_CLOEXEC).ok()?;
println!("epoll_fd: {epoll_fd}.");
let epoll_fd = unsafe { OwnedFd::from_raw_fd(epoll_fd) };
let mut event = epoll::EpollEvent::new(epoll::EpollFlags::EPOLLIN, 0);
#[allow(deprecated)]
epoll::epoll_ctl(
epoll_fd.as_raw_fd(),
epoll::EpollOp::EpollCtlAdd,
@ -61,8 +64,6 @@ impl Beo5Device {
)
.unwrap();
//loop {}
return Some(Beo5Device {
device: d,
evts_in_queue: VecDeque::new(),
@ -91,7 +92,8 @@ impl Beo5Device {
if x.kind() == std::io::ErrorKind::WouldBlock {
// Wait forever for bytes available on raw_fd
let mut events = [epoll::EpollEvent::empty(); 2];
epoll::epoll_wait(8, &mut events, -1);
#[allow(deprecated)]
let _ = epoll::epoll_wait(8, &mut events, -1);
} else {
println!("Error getting event: {x} - {}", x.kind());
//panic!("Error getting event: {x}");
@ -99,15 +101,14 @@ impl Beo5Device {
}
}
let ev = self.evts_in_queue.pop_front();
if ev.is_some() {
return Beo5Device::parse_event(ev.unwrap());
if let Some(e) = ev {
return Beo5Device::parse_event(e);
}
None
}
fn parse_event(ev: evdev::InputEvent) -> Option<Beo5Event> {
println!("Beosound event: {ev:?}");
// XXX What happens with the other events in the iterator?
#[allow(clippy::collapsible_match)]
match ev.kind() {
// Look at the beosound 5 kernel module for the correct event codes
evdev::InputEventKind::RelAxis(axis) => {
@ -123,6 +124,7 @@ impl Beo5Device {
}
}
evdev::InputEventKind::AbsAxis(axis) => {
#[allow(clippy::single_match)]
match axis {
evdev::AbsoluteAxisType::ABS_X => {
let pos_pct = (ev.value() as f32 / LASER_POINTER_MAX as f32).min(1.0);

View file

@ -13,7 +13,14 @@ use winit::{
mod helpers;
use helpers::PerfGraph;
// XXX rename to smth else
use glutin::prelude::*;
mod apps;
mod hid;
mod roundy_math;
mod ui;
#[allow(dead_code)]
struct Fonts {
sans: FontId,
bold: FontId,
@ -26,19 +33,6 @@ struct Fonts {
fn main() {
helpers::start(1024, 768, "Text demo");
}
use glutin::prelude::*;
mod apps;
mod hid;
mod roundy_math;
mod ui;
enum UiEvent<'e> {
WinitEvent(winit::event::Event<'e, ()>),
HardwareEvent(evdev::InputEvent),
}
fn run(
mut canvas: Canvas<OpenGl>,
el: EventLoop<()>,
@ -112,11 +106,8 @@ fn run(
*control_flow = ControlFlow::Poll;
let hw_event = beo_device.get_event_nonblocking();
match hw_event {
Some(ev) => {
beo.accept_event(ev);
}
None => {}
if let Some(ev) = hw_event {
beo.accept_event(ev);
}
match event {
@ -191,7 +182,6 @@ fn run(
canvas.set_size(size.width, size.height, dpi_factor as f32);
canvas.clear_rect(0, 0, size.width, size.height, Color::rgbf(0., 0., 0.));
let elapsed = start.elapsed().as_secs_f32();
let now = Instant::now();
let dt = (now - prevt).as_secs_f32();
prevt = now;

View file

@ -1,8 +1,8 @@
use femtovg::{Align, Baseline, Canvas, Color, Paint, Path, Renderer};
use femtovg::{Baseline, Canvas, Color, Paint, Path, Renderer};
use crate::{hid::Beo5Event, Fonts};
use crate::apps::{App, BeoApps, Menu};
use crate::apps::{App, BeoApps};
use crate::roundy_math;
pub struct BeoUi {
@ -227,12 +227,11 @@ impl BeoUi {
paint_selected.set_text_baseline(Baseline::Top);
for appid in 0..apps.len() {
let paint;
if self.current_app_id == Some(appid) {
paint = &paint_selected;
let paint = if self.current_app_id == Some(appid) {
&paint_selected
} else {
paint = &paint_normal;
}
&paint_normal
};
let app = &apps[appid];
let _ = canvas.fill_text(pts[appid].x, pts[appid].y, app.base().name(), paint);