Compare commits
3 commits
10a70ff352
...
367d4c3c11
| Author | SHA1 | Date | |
|---|---|---|---|
| 367d4c3c11 | |||
|
|
4a40cf473e | ||
|
|
9a9594b2e7 |
6 changed files with 51 additions and 30 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
|
@ -169,7 +169,7 @@ checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "kb-quiver"
|
name = "kb-quiver"
|
||||||
version = "0.2.0"
|
version = "0.3.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"evdev",
|
"evdev",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "kb-quiver"
|
name = "kb-quiver"
|
||||||
version = "0.2.0"
|
version = "0.3.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
7
debian/changelog
vendored
|
|
@ -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
|
kb-quiver 0.2.0-1 bookworm; urgency=medium
|
||||||
|
|
||||||
* add systemd service
|
* add systemd service
|
||||||
|
|
|
||||||
2
debian/postinst
vendored
2
debian/postinst
vendored
|
|
@ -1,4 +1,6 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
echo "50" | tee /etc/kb-haptic-length
|
||||||
|
|
||||||
#DEBHELPER#
|
#DEBHELPER#
|
||||||
|
|
|
||||||
7
debian/postrm
vendored
Executable file
7
debian/postrm
vendored
Executable file
|
|
@ -0,0 +1,7 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
rm /etc/kb-haptic-length || true
|
||||||
|
|
||||||
|
#DEBHELPER#
|
||||||
57
src/main.rs
57
src/main.rs
|
|
@ -1,16 +1,17 @@
|
||||||
use std::{path::{Path}, fs::{File, OpenOptions}};
|
|
||||||
use std::io::{Read, Write};
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use regex::Regex;
|
|
||||||
use evdev::*;
|
use evdev::*;
|
||||||
|
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";
|
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 {
|
||||||
/// vibration duration in milliseconds
|
/// config file containing 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,
|
||||||
}
|
}
|
||||||
|
|
@ -21,12 +22,16 @@ 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(_) => { str.push_str("50"); }
|
Err(_) => {
|
||||||
|
str.push_str("50");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
_ => {
|
||||||
|
str.push_str("50");
|
||||||
}
|
}
|
||||||
_ => { str.push_str("50"); }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
str
|
str
|
||||||
|
|
@ -35,28 +40,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!("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 device_path = enumerate()
|
||||||
let mut str = String::new();
|
.find(|x| {
|
||||||
|
x.1.name()
|
||||||
|
.unwrap_or_default()
|
||||||
|
.contains("Integrated keyboard")
|
||||||
|
})
|
||||||
|
.expect("No valid keyboard device found")
|
||||||
|
.0;
|
||||||
|
|
||||||
File::open(Path::new(DEVICES_PATH)).expect(&format!("Unable to open {} to read devices list!", DEVICES_PATH))
|
let mut device =
|
||||||
.read_to_string(&mut str).expect(&format!("Unable to read devices list at {}!", DEVICES_PATH));
|
Device::open(&device_path).expect(&format!("Unable to open device at {:?}", &device_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()
|
||||||
match write!(haptic, "{}", haptic_length) {
|
&& write!(haptic, "{}", haptic_length).is_err()
|
||||||
Err(_) => println!("Unable to write to haptics!"),
|
{
|
||||||
_ => ()
|
println!("Unable to write to haptics!")
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue