Check all event devices for KEY_ENTER presence.

main
Shinyzenith 2 years ago
parent ffd8b998b2
commit 8bbd34c4df
No known key found for this signature in database
GPG Key ID: 6DD485917B553B7B

@ -1,29 +0,0 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
name: Python application
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics

3
.gitignore vendored

@ -1 +1,2 @@
__pycache__
target
src/Makefile

119
Cargo.lock generated

@ -0,0 +1,119 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "autocfg"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
[[package]]
name = "bitflags"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bitvec"
version = "0.22.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5237f00a8c86130a0cc317830e558b966dd7850d48a953d998c813f01a41b527"
dependencies = [
"funty",
"radium",
"tap",
"wyz",
]
[[package]]
name = "cc"
version = "1.0.72"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22a9137b95ea06864e018375b72adfb7db6e6f68cfc8df5a04d00288050485ee"
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "evdev"
version = "0.11.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5fd975dc56c85a845d56e5dce9a8eb0b058e7a22441b3fb15fad324e0476e7c4"
dependencies = [
"bitvec",
"libc",
"nix",
]
[[package]]
name = "funty"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1847abb9cb65d566acd5942e94aea9c8f547ad02c98e1649326fc0e8910b8b1e"
[[package]]
name = "glob"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574"
[[package]]
name = "libc"
version = "0.2.112"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b03d17f364a3a042d5e5d46b053bbbf82c92c9430c592dd4c064dc6ee997125"
[[package]]
name = "memoffset"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce"
dependencies = [
"autocfg",
]
[[package]]
name = "nix"
version = "0.23.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f866317acbd3a240710c63f065ffb1e4fd466259045ccb504130b7f668f35c6"
dependencies = [
"bitflags",
"cc",
"cfg-if",
"libc",
"memoffset",
]
[[package]]
name = "radium"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "643f8f41a8ebc4c5dc4515c82bb8abd397b527fc20fd681b7c011c2aee5d44fb"
[[package]]
name = "swhkd"
version = "0.1.0"
dependencies = [
"evdev",
"glob",
]
[[package]]
name = "tap"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369"
[[package]]
name = "wyz"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "129e027ad65ce1453680623c3fb5163cbf7107bfe1aa32257e7d0e63f9ced188"
dependencies = [
"tap",
]

@ -0,0 +1,12 @@
[package]
name = "swhkd"
version = "0.1.0"
edition = "2021"
[dependencies]
evdev = "0.11.3"
glob = "0.3.0"
[[bin]]
name = "swhkd"
path = "src/main.rs"

@ -0,0 +1,29 @@
all: build
build:
@cargo build --release --target=x86_64-unknown-linux-musl
install:
@mkdir -p /usr/local/bin
@cp ./target/x86_64-unknown-linux-musl/release/swhkd /usr/local/bin/swhkd
@chmod +x /usr/local/bin/swhkd
uninstall:
@rm /usr/local/bin/swhkd
run:
@cargo run --target=x86_64-unknown-linux-musl
check:
@cargo fmt
@cargo check --target=x86_64-unknown-linux-musl
clean:
@cargo clean
setup:
@rustup install stable
@rustup default stable
@rustup target add x86_64-unknown-linux-musl
.PHONY: check clean setup all run install build

@ -1,17 +1,9 @@
# swhkd
**S**imple **W**ayland **H**ot**K**ey **D**aemon
This project is still very new and I'm making new decisions everyday as to where I should drive this project.
I'm using libevdev which technically makes swhkd display protocol indepdent, but we'll need to put that to the test before claiming anything.
Currently I have only been able to achieve the grabbing of input evdev, I don't know how I will process chains of keybinds, but we'll get to that soon.
# Python:
Adressing the elephant in the room, python. Python is good enough for the prototype stage of the project, once I have a clear idea and a working prototype,
I will port the project to go or zig if I get time.
# Contributors:
<img src="https://contrib.rocks/image?repo=shinyzenith/swhkd" />
# Compiling:
1) Clone this repos
2) Install rustup
3) `make setup`
4) `make`
5) `sudo make install`

@ -0,0 +1,28 @@
use evdev::Device;
use evdev::Key;
use glob::glob;
pub fn main() {
for entry in glob("/dev/input/event*").expect("Failed to read /dev/input/event*.") {
match entry {
Ok(path) => {
check_keyboard(path.into_os_string().into_string().unwrap());
}
Err(_) => continue,
}
}
}
pub fn check_keyboard(input_path: String) -> bool {
let device = Device::open(&input_path).expect("Failed to open device.");
if device
.supported_keys()
.map_or(false, |keys| keys.contains(Key::KEY_ENTER))
{
println!("{} is a keyboard.", input_path);
return true;
} else {
println!("{} is not a keyboard.", input_path);
return false;
}
}
Loading…
Cancel
Save