Compare commits

..

No commits in common. "367d4c3c11008fd37dd505fc46cd844122fc8eca" and "10a70ff352361b8550d451ceef3bf61cd4056507" have entirely different histories.

6 changed files with 31 additions and 52 deletions

2
Cargo.lock generated
View file

@ -169,7 +169,7 @@ checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695"
[[package]] [[package]]
name = "kb-quiver" name = "kb-quiver"
version = "0.3.0" version = "0.2.0"
dependencies = [ dependencies = [
"clap", "clap",
"evdev", "evdev",

View file

@ -1,6 +1,6 @@
[package] [package]
name = "kb-quiver" name = "kb-quiver"
version = "0.3.0" version = "0.2.0"
edition = "2024" edition = "2024"
authors = ["Penelope Gwen <support@pogmom.me>", "TerminalLesbian <valeradhd@gmail.com>"] authors = ["Penelope Gwen <support@pogmom.me>", "TerminalLesbian <valeradhd@gmail.com>"]
license-file = "LICENSE.md" license-file = "LICENSE.md"

7
debian/changelog vendored
View file

@ -1,10 +1,3 @@
kb-quiver 0.3.0-1 bookworm; urgency=medium
* add support for configuring vibration length via config file which is read on start
* detect event device using evdev crate
-- Penelope Gwen <support@pogmom.me> Wed, 04 Apr 2026 00:18:54 -0700
kb-quiver 0.2.0-1 bookworm; urgency=medium kb-quiver 0.2.0-1 bookworm; urgency=medium
* add systemd service * add systemd service

2
debian/postinst vendored
View file

@ -1,6 +1,4 @@
#!/bin/sh #!/bin/sh
set -e set -e
echo "50" | tee /etc/kb-haptic-length
#DEBHELPER# #DEBHELPER#

7
debian/postrm vendored
View file

@ -1,7 +0,0 @@
#!/bin/sh
set -e
rm /etc/kb-haptic-length || true
#DEBHELPER#

View file

@ -1,17 +1,16 @@
use clap::Parser; use std::{path::{Path}, fs::{File, OpenOptions}};
use evdev::*;
use std::io::{Read, Write}; use std::io::{Read, Write};
use std::{ use clap::Parser;
fs::{File, OpenOptions}, use regex::Regex;
path::Path, use evdev::*;
};
const DEVICES_PATH: &str = "/proc/bus/input/devices";
const HAPTIC_PATH: &str = "/sys/class/timed_output/vibrator/enable"; const HAPTIC_PATH: &str = "/sys/class/timed_output/vibrator/enable";
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
#[command(version, about, long_about = None)] #[command(version, about, long_about = None)]
struct Args { struct Args {
/// config file containing vibration duration in milliseconds /// vibration duration in milliseconds
#[arg(short, long, default_value_t = String::from("/etc/kb-haptic-length"))] #[arg(short, long, default_value_t = String::from("/etc/kb-haptic-length"))]
config_path: String, config_path: String,
} }
@ -22,16 +21,12 @@ fn main() {
let haptic_length: String = { let haptic_length: String = {
let mut str = String::new(); let mut str = String::new();
match File::open(Path::new(&cli.config_path)) { match File::open(&Path::new(&cli.config_path)) {
Ok(mut f) => match f.read_to_string(&mut str) { Ok(mut f) => match f.read_to_string(&mut str) {
Ok(_) => (), Ok(_) => (),
Err(_) => { Err(_) => { str.push_str("50"); }
str.push_str("50");
}
},
_ => {
str.push_str("50");
} }
_ => { str.push_str("50"); }
} }
str str
@ -40,28 +35,28 @@ fn main() {
let mut haptic = OpenOptions::new() let mut haptic = OpenOptions::new()
.append(true) .append(true)
.open(HAPTIC_PATH) .open(HAPTIC_PATH)
.expect(&format!( .expect(&format!("Unable to access haptic drivers at {} for writing!", HAPTIC_PATH));
"Unable to access haptic drivers at {} for writing!",
HAPTIC_PATH
));
let device_path = enumerate() let devices_list: String = {
.find(|x| { let mut str = String::new();
x.1.name()
.unwrap_or_default()
.contains("Integrated keyboard")
})
.expect("No valid keyboard device found")
.0;
let mut device = File::open(Path::new(DEVICES_PATH)).expect(&format!("Unable to open {} to read devices list!", DEVICES_PATH))
Device::open(&device_path).expect(&format!("Unable to open device at {:?}", &device_path)); .read_to_string(&mut str).expect(&format!("Unable to read devices list at {}!", DEVICES_PATH));
str
};
let kbd_regex = Regex::new(r"(?ms)Integrated keyboard(.*?)kbd (?<event>.*?) \n").unwrap();
let event_num = &kbd_regex.captures(&devices_list).expect(&format!("No valid keyboard devices found in {}", DEVICES_PATH))["event"];
let device_path = format!("/dev/input/{}", event_num);
let mut device = Device::open(Path::new(&device_path)).expect(&format!("Unable to open device at {}", &device_path));
loop { loop {
for event in device.fetch_events().unwrap() { for event in device.fetch_events().unwrap() {
if let EventSummary::Key(_, _, 1) = event.destructure() if let EventSummary::Key(_, _, 1) = event.destructure() {
&& write!(haptic, "{}", haptic_length).is_err() match write!(haptic, "{}", haptic_length) {
{ Err(_) => println!("Unable to write to haptics!"),
println!("Unable to write to haptics!") _ => ()
};
} }
} }
} }