v0.3.0 prep

This commit is contained in:
Penelope Gwen 2026-04-04 00:26:43 -07:00
parent 10a70ff352
commit 9a9594b2e7
6 changed files with 68 additions and 25 deletions

2
Cargo.lock generated
View file

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

View file

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

7
debian/changelog vendored
View file

@ -1,3 +1,10 @@
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
* add systemd service

2
debian/postinst vendored
View file

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

7
debian/postrm vendored Executable file
View file

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

View file

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