Skip to content

Commit

Permalink
Check all event devices for KEY_ENTER presence.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinyzenith committed Jan 4, 2022
1 parent ffd8b99 commit 8bbd34c
Show file tree
Hide file tree
Showing 7 changed files with 196 additions and 44 deletions.
29 changes: 0 additions & 29 deletions .github/workflows/python-app.yml

This file was deleted.

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
__pycache__
target
src/Makefile
119 changes: 119 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
29 changes: 29 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
20 changes: 6 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -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`
28 changes: 28 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 8bbd34c

Please sign in to comment.