Skip to content

Commit

Permalink
Merge branch 'main' into udev_async
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinyzenith authored Jul 20, 2023
2 parents ce4eb29 + ddada68 commit b3c10c2
Show file tree
Hide file tree
Showing 14 changed files with 136 additions and 32 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ target
*.out
com.github.swhkd.pkexec.policy
*rc
.direnv
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Detection of added/removed devices (e.g., when plugging or unplugging a
keyboard). The devices are grabbed by `swhkd` if they match the `--device`
parameters if present or if they are recognized as keyboard devices otherwise.
- `Altgr` modifier added (https://github.com/waycrate/swhkd/pull/213).

### Changed

- The project `Makefile` now builds the polkit policy file dynamically depending
on the target installation directories.
- Alt modifier no longer maps to the right aly key. It only maps to the left alt key. Right alt is referred to as Altgr (alt graph).
- Tokio version bumped from 1.23.0 to 1.24.2 (https://github.com/waycrate/swhkd/pull/198).

### Fixed

- Mouse cursors and other devices are no longer blocked when running `swhkd`.
- Option prefixes on modifiers are now properly parsed. e.g., `~control` is now
understood by `swhkd` as the `control` modifier with an option
- Install mandocs in the correct locations.
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ install:
@find ./docs -type f -iname "*.1.gz" \
-exec install -Dm 644 {} -t $(DESTDIR)/$(MAN1_DIR) \;
@find ./docs -type f -iname "*.5.gz" \
-exec install -Dm 644 {} -t $(DESTDIR)/$(MAN1_DIR) \;
-exec install -Dm 644 {} -t $(DESTDIR)/$(MAN5_DIR) \;
@install -Dm 755 ./target/release/$(DAEMON_BINARY) -t $(DESTDIR)/$(TARGET_DIR)
@install -Dm 755 ./target/release/$(SERVER_BINARY) -t $(DESTDIR)/$(TARGET_DIR)
@install -Dm 644 -o root ./$(POLKIT_POLICY_FILE) -t $(DESTDIR)/$(POLKIT_DIR)
Expand Down
67 changes: 43 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<p align=center>
<img src="https://git.sr.ht/~shinyzenith/swhkd/blob/main/assets/swhkd.png" alt=SWHKD width=60%>

<p align=center>A next-generation hotkey daemon for Wayland/X11 written in Rust.</p>
<p align="center">A next-generation hotkey daemon for Wayland/X11 written in <a href="https://www.rust-lang.org/">Rust</a>.</p>

<p align="center">
<a href="./LICENSE.md"><img src="https://img.shields.io/github/license/waycrate/swhkd?style=flat-square&logo=appveyor"></a>
Expand All @@ -12,66 +12,85 @@
</p>
</p>

## SWHKD:
## SWHKD

**S**imple **W**ayland **H**ot**K**ey **D**aemon

swhkd is a display protocol-independent hotkey daemon made in Rust. swhkd uses an easy-to-use configuration system inspired by sxhkd so you can easily add or remove hotkeys.
`swhkd` is a display protocol-independent hotkey daemon made in
[Rust](https://www.rust-lang.org). `swhkd` uses an easy-to-use configuration
system inspired by `sxhkd`, so you can easily add or remove hotkeys.

It also attempts to be a drop-in replacement for sxhkd, meaning your sxhkd config file is also compatible with swhkd.
It also attempts to be a drop-in replacement for `sxhkd`, meaning your `sxhkd`
config file is also compatible with `swhkd`.

Because swhkd can be used anywhere, the same swhkd config can be used across Xorg or Wayland desktops, and you can even use swhkd in a tty.
Because `swhkd` can be used anywhere, the same `swhkd` config can be used across
Xorg or Wayland desktops, and you can even use `swhkd` in a TTY.

## Installation and Building:
## Installation and Building

[Installation and building instructions can be found here.](./INSTALL.md)

## Running:
## Running

```bash
swhks &
pkexec swhkd
```

## Runtime signals:
## Runtime signals

After opening swhkd, you can control the program through signals:
After opening `swhkd`, you can control the program through signals:

- `sudo pkill -USR1 swhkd` - Pause key checking
- `sudo pkill -USR2 swhkd` - Resume key checking
- `sudo pkill -HUP swhkd` - Reload config file
- `sudo pkill -USR1 swhkd` Pause key checking
- `sudo pkill -USR2 swhkd` Resume key checking
- `sudo pkill -HUP swhkd` Reload config file

## Configuration:
## Configuration

Swhkd closely follows sxhkd syntax, so most existing sxhkd configs should be functional with swhkd.
`swhkd` closely follows `sxhkd` syntax, so most existing `sxhkd` configs should
be functional with `swhkd`.

The default configuration file is in `/etc/swhkd/swhkdrc`. If you don't like having to edit the file as root every single time, you can create a symlink from `~/.config/swhkd/swhkdrc` to `/etc/swhkd/swhkdrc`.
The default configuration file is in `/etc/swhkd/swhkdrc`. If you don't like
having to edit the file as root every single time, you can create a symlink from
`~/.config/swhkd/swhkdrc` to `/etc/swhkd/swhkdrc`.

If you use Vim, you can get swhkd config syntax highlighting with the
If you use Vim, you can get `swhkd` config syntax highlighting with the
[swhkd-vim](https://github.com/waycrate/swhkd-vim) plugin. Install it in
vim-plug with `Plug 'waycrate/swhkd-vim'`.

All supported key and modifier names are listed in `man 5 swhkd-keys`.

## Autostart:
## Autostart

### To autostart swhkd you can do one of two things:
### To autostart `swhkd` you can do one of two things

1. Add the commands from the ["Running" section](https://github.com/waycrate/swhkd#running) to your window managers configuration file.
1. Enable the [service file](https://github.com/waycrate/swhkd/tree/main/contrib/init) for your respective init system. Currently only systemd and OpenRC service files exist and more will be added soon including Runit.
1. Add the commands from the ["Running"
section](https://github.com/waycrate/swhkd#running) to your window managers
configuration file.
1. Enable the [service
file](https://github.com/waycrate/swhkd/tree/main/contrib/init) for your
respective init system. Currently, only systemd and OpenRC service files
exist and more will be added soon including Runit.

## Security:
## Security

We use a server-client model to keep you safe. The daemon ( swhkd - privileged process ) communicates to the server ( swhks - running as non root user ) after checking for valid keybinds. Since the daemon is totally separate from the server, no other process can read your keystrokes. As for shell commands, you might be thinking that any program can send shell commands to the server and that's true! But the server runs the commands as the currently logged in user so no extra permissions are provided ( This is essentially the same as any app on your desktop calling shell commands ).
We use a server-client model to keep you safe. The daemon (`swhkd` — privileged
process) communicates to the server (`swhks` — running as non-root user) after
checking for valid keybindings. Since the daemon is totally separate from the
server, no other process can read your keystrokes. As for shell commands, you
might be thinking that any program can send shell commands to the server and
that's true! But the server runs the commands as the currently logged-in user,
so no extra permissions are provided (This is essentially the same as any app on
your desktop calling shell commands).

So yes, you're safe!

## Support:
## Support

1. https://matrix.to/#/#waycrate-tools:matrix.org
1. https://discord.gg/KKZRDYrRYW

## Contributors:
## Contributors

<a href="https://github.com/Shinyzenith/swhkd/graphs/contributors">
<img src="https://contrib.rocks/image?repo=waycrate/swhkd" />
Expand Down
4 changes: 3 additions & 1 deletion docs/swhkd-keys.5.scd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ swhkd(5) "github.com/waycrate/swhkd" "File Formats Manual"

# NAME

swhkd - Hotkey daemon inspired by sxhkd written in rust
swhkd - Hotkey daemon inspired by sxhkd written in Rust

# VALID MODIFIERS

Expand All @@ -12,6 +12,8 @@ swhkd - Hotkey daemon inspired by sxhkd written in rust
- Mod4
- Alt
- Mod1
- Altgr
- Mod5
- Shift

# VALID KEYS
Expand Down
2 changes: 1 addition & 1 deletion docs/swhkd.1.scd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ swhkd(1) "github.com/shinyzenith/swhkd" "General Commands Manual"

# NAME

swhkd - Hotkey daemon inspired by sxhkd written in rust
swhkd - Hotkey daemon inspired by sxhkd written in Rust

# SYNOPSIS

Expand Down
2 changes: 1 addition & 1 deletion docs/swhkd.5.scd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ swhkd(5) "github.com/waycrate/swhkd" "File Formats Manual"

# NAME

swhkd - Hotkey daemon inspired by sxhkd written in rust
swhkd - Hotkey daemon inspired by sxhkd written in Rust

# CONFIG FILE

Expand Down
27 changes: 27 additions & 0 deletions flake.lock

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

40 changes: 40 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
description = "Swhkd devel";

inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; };

outputs = { self, nixpkgs, ... }:
let
pkgsFor = system:
import nixpkgs {
inherit system;
overlays = [ ];
};

targetSystems = [ "aarch64-linux" "x86_64-linux" ];
in {
devShells = nixpkgs.lib.genAttrs targetSystems (system:
let pkgs = pkgsFor system;
in {
default = pkgs.mkShell {
name = "Swhkd-devel";
nativeBuildInputs = with pkgs; [
# Compilers
cargo
rustc
scdoc

# Tools
zip
rustfmt
clippy
gdb
gnumake
rust-analyzer
strace
valgrind
];
};
});
};
}
2 changes: 1 addition & 1 deletion swhkd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ nix = "0.23.1"
signal-hook = "0.3.13"
signal-hook-tokio = { version = "0.3.1", features = ["futures-v0_3"] }
sysinfo = "0.23.5"
tokio = { version = "1.17.0", features = ["full"] }
tokio = { version = "1.24.2", features = ["full"] }
tokio-stream = "0.1.8"
tokio-udev = { git = "https://github.com/jeandudey/tokio-udev.git" }

Expand Down
3 changes: 3 additions & 0 deletions swhkd/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ pub struct Hotkey {
pub enum Modifier {
Super,
Alt,
Altgr,
Control,
Shift,
Any,
Expand Down Expand Up @@ -452,6 +453,8 @@ pub fn parse_contents(path: PathBuf, contents: String) -> Result<Vec<Mode>, Erro
("mod4", Modifier::Super),
("alt", Modifier::Alt),
("mod1", Modifier::Alt),
("altgr", Modifier::Altgr),
("mod5", Modifier::Altgr),
("shift", Modifier::Shift),
("any", Modifier::Any),
]);
Expand Down
2 changes: 1 addition & 1 deletion swhkd/src/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
(Key::KEY_LEFTMETA, config::Modifier::Super),
(Key::KEY_RIGHTMETA, config::Modifier::Super),
(Key::KEY_LEFTALT, config::Modifier::Alt),
(Key::KEY_RIGHTALT, config::Modifier::Alt),
(Key::KEY_RIGHTALT, config::Modifier::Altgr),
(Key::KEY_LEFTCTRL, config::Modifier::Control),
(Key::KEY_RIGHTCTRL, config::Modifier::Control),
(Key::KEY_LEFTSHIFT, config::Modifier::Shift),
Expand Down
8 changes: 8 additions & 0 deletions swhkd/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,9 @@ control + 5
alt + 2
notify-send 'Hello world!'
altgr + i
notify-send 'Hello world!'
super + z
notify-send 'Hello world!'
";
Expand All @@ -418,6 +421,11 @@ super + z
vec![Modifier::Alt],
"notify-send 'Hello world!'".to_string(),
),
Hotkey::new(
evdev::Key::KEY_I,
vec![Modifier::Altgr],
"notify-send 'Hello world!'".to_string(),
),
Hotkey::new(
evdev::Key::KEY_Z,
vec![Modifier::Super],
Expand Down

0 comments on commit b3c10c2

Please sign in to comment.