Skip to content

Commit

Permalink
Add idle inhibit on joystick input
Browse files Browse the repository at this point in the history
Merge wljoywake branch adding functionality akin to the wljoywake branch
handling idle_inhibition on joystick input

https://github.com/nowrep/wljoywake
  • Loading branch information
fishman committed Oct 25, 2024
1 parent d5aa392 commit 95312d6
Show file tree
Hide file tree
Showing 8 changed files with 494 additions and 332 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ anyhow = "1.0.75"
bytemuck = "1.18.0"
clap = { version = "4.4.8", features = ["derive"] }
env_logger = "0.10.1"
evdev = { version = "0.12.2", features = ["tokio"] }
futures = { version = "0.3.29", features = ["compat"] }
inotify = "0.10.2"
lazy_static = "1.5.0"
libc = "0.2.161"
log = "0.4.20"
mlua = { version = "0.9.1", features = ["async", "luau", "send"] }
nix = { version = "0.29.0", features = ["fs", "poll", "signal", "time"] }
Expand Down
2 changes: 2 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
pub const APP_NAME: &str = "sleepwatcher-rs";
pub const CONFIG_FILE_NAME: &str = "idle_config.lua";
pub const CONFIG_FILE: &str = include_str!("../lua_configs/idle_config.lua");
pub const TIMEOUT_SEC: u64 = 30;
2 changes: 1 addition & 1 deletion src/dbus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub async fn upower_watcher(tx: mpsc::Sender<Request>) -> anyhow::Result<()> {
while let Some(on_battery_changed) = power_stream.next().await {
match on_battery_changed.get().await {
Ok(on_battery) => {
let _ = tx.send(Request::OnBattery(on_battery)).await.unwrap();
tx.send(Request::OnBattery(on_battery)).await.unwrap();
}
Err(e) => {
error!("Error, getting on_battery property {}", e)
Expand Down
54 changes: 54 additions & 0 deletions src/joystick_handler.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
use evdev::{Device, InputEventKind};
use log::{debug, info};
use std::path::Path;
use tokio::sync::mpsc;

use crate::types::Request;

#[derive(Debug)]
pub struct JoystickHandler {
syspath: String,
tx: mpsc::Sender<Request>,
}

impl JoystickHandler {
pub fn new(syspath: String, tx: mpsc::Sender<Request>) -> Self {
Self { syspath, tx }
}

pub async fn js_handler(&self) -> anyhow::Result<()> {
let device_path = Path::new("/dev/input").join(&self.syspath);
let device = Device::open(device_path)?;
//let absinfo = device.get_abs_state();
let mut event_stream = device.into_event_stream()?;

loop {
tokio::select! {
ev = event_stream.next_event() => {
match ev {
Ok(ev) => {
match ev.kind() {
InputEventKind::Key(key) => {
debug!("Key event: {:?}, value: {}", key, ev.value());
self.tx.send(Request::Inhibit).await.unwrap();
}
// Ignore axis and synchronization events for now. For Axis events
// it's not currently clear how to get absinfo
InputEventKind::AbsAxis(..) => {
}
InputEventKind::Synchronization(..) => {}
_ => {
debug!("Other event: {:?}", ev);
}
}
}
Err(e) => {
info!("Error reading event: {:?}", e);
break Ok(());
}
}
}
}
}
}
}
Loading

0 comments on commit 95312d6

Please # to comment.