Global keybindings for X.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Ash fe3edd870b
update readme
11 months ago
src add missing i in XF86AudioStop 1 year ago
.gitignore first commit 1 year ago
Cargo.lock fix indentation 1 year ago
Cargo.toml first commit 1 year ago
LICENSE public domain 11 months ago
README.md update readme 11 months ago

README.md

bindings

license

A program written in Rust which contains hardcoded global keybindings that work across X.

Table of Contents:
Usage
Modification
Modification/Finding the keysym of the key you want to bind
Modification/How to bind the key and make it do something
Thanks!

Usage

After modifying to your liking, cargo build and sudo ./target/debug/bindings to check that it works.

Due to the way libinput works, the program must be run as root.

After you think you have it the way you like it, cargo build --release
and either move ./target/release/bindings to somewhere in your $PATH
or cargo install --path . (inside the root dir of the git repo) and ensure
$HOME/.cargo/bin is in your $PATH.

Note: Has the same deps as inputbot, so please check out their repo.

Modification

You'll need to modify the source to fit your needs. Currently, it is
set up for my usage which is setting the XF86Audio keys to run my
specified mpc commands.

How to find the keysym of the key you want to bind

I use the program called xev. When you run it, a big blank window should open.
When it does, press the key you want to find the keysym of
(I'll use XF86AudioPlay for this example). After that, close the window and look through the output.
You'll see a lot of it, but the main section you want to look for will look like this:

KeyPress event, serial 35, synthetic NO, window 0x1400001,
    root 0x294, subw 0x416ee3, time 688908125, (184,95), root:(184,95),
    state 0x10, keycode 172 (keysym 0x1008ff14, XF86AudioPlay), same_screen YES,
    XLookupString gives 0 bytes: 
    XmbLookupString gives 0 bytes: 
    XFilterEvent returns: False

The part you'd want is the 0x1008ff14 part of keysym 0x1008ff14 (or the equivalent for your key anyways).

How to actually bind the key and make it do something

Now here's the part you've been waiting for, how to bind the key and how to make it
do something (for example, run the command mpc toggle).

You need to use OtherKey since inputbot doesn't currently support media keys yet,
so to just bind it you'd need to use:

use inputbot::handle_input_events;
use inputbot::KeybdKey::*;

fn main() {
	OtherKey(0x1008ff14).bind(||);
	handle_input_events();
}

Of course, this on it's own will fail since there is nothing for it to actually do inside of .bind(||).
Now to make it actually run mpc toggle, you'd need to do:

use inputbot::handle_input_events;
use inputbot::KeybdKey::*;
use std::process::Command;

fn main() {
	OtherKey(0x1008ff14).bind(|| { Command::new("mpc").arg("toggle").output(); });
	handle_input_events();
}

After compiling and running, you should be able to press XF86AudioPlay
and have it run the command mpc toggle.

Thanks

This program was possible because of inputbot, a library
for creating keybindings among other things.