mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Much better handling of keys
This commit is contained in:
@@ -4,19 +4,25 @@ use dbus::{
|
||||
tree::{Factory, MethodErr},
|
||||
};
|
||||
use log::{error, info, warn};
|
||||
use rog_lib::core::RogCore;
|
||||
use rog_lib::{
|
||||
core::RogCore,
|
||||
laptops::{match_laptop, Laptop},
|
||||
};
|
||||
use std::error::Error;
|
||||
use std::time::Duration;
|
||||
use std::{cell::RefCell, rc::Rc};
|
||||
|
||||
pub struct Daemon {
|
||||
rogcore: RogCore,
|
||||
laptop: Box<dyn Laptop>,
|
||||
}
|
||||
|
||||
impl Daemon {
|
||||
pub fn new() -> Self {
|
||||
let laptop = match_laptop();
|
||||
|
||||
Daemon {
|
||||
rogcore: RogCore::new().map_or_else(
|
||||
rogcore: RogCore::new(&*laptop).map_or_else(
|
||||
|err| {
|
||||
error!("{}", err);
|
||||
panic!("{}", err);
|
||||
@@ -26,6 +32,7 @@ impl Daemon {
|
||||
daemon
|
||||
},
|
||||
),
|
||||
laptop,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,8 +67,12 @@ impl Daemon {
|
||||
move |m| {
|
||||
// Reads the args passed to the method
|
||||
let bytes: Vec<u8> = m.msg.read1()?;
|
||||
|
||||
match daemon.borrow_mut().rogcore.aura_set_and_save(&bytes[..])
|
||||
let supported =
|
||||
Vec::from(daemon.borrow().laptop.supported_modes());
|
||||
match daemon
|
||||
.borrow_mut()
|
||||
.rogcore
|
||||
.aura_set_and_save(&supported, &bytes[..])
|
||||
{
|
||||
Ok(_) => {
|
||||
let s = format!("Wrote {:x?}", bytes);
|
||||
@@ -86,6 +97,7 @@ impl Daemon {
|
||||
tree.start_receive(&connection);
|
||||
|
||||
let mut key_buf = [0u8; 32];
|
||||
let hotkey_group_bytes = Vec::from(daemon.borrow().laptop.hotkey_group_bytes());
|
||||
loop {
|
||||
connection
|
||||
.process(Duration::from_millis(10))
|
||||
@@ -96,15 +108,18 @@ impl Daemon {
|
||||
// READ KEYBOARD
|
||||
// TODO: this needs to move to a thread, but there is unsafety
|
||||
let mut borrowed_daemon = daemon.borrow_mut();
|
||||
match borrowed_daemon.rogcore.poll_keyboard(&mut key_buf) {
|
||||
match borrowed_daemon
|
||||
.rogcore
|
||||
.poll_keyboard(&hotkey_group_bytes, &mut key_buf)
|
||||
{
|
||||
Ok(read) => {
|
||||
// Doing this because the Laptop trait takes RogCore, but RogCore contains laptop
|
||||
// and this makes the borrow checker unhappy, but it's safe for this
|
||||
let mut rogcore = unsafe { &mut (*daemon.as_ptr()).rogcore };
|
||||
let laptop = borrowed_daemon.rogcore.laptop();
|
||||
|
||||
if let Some(_count) = read {
|
||||
laptop
|
||||
borrowed_daemon
|
||||
.laptop
|
||||
.do_hotkey_action(&mut rogcore, key_buf[1])
|
||||
.unwrap_or_else(|err| {
|
||||
warn!("{:?}", err);
|
||||
|
||||
Reference in New Issue
Block a user