Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

package request: keyd - "A key remapping daemon for linux" #132474

Closed
colemickens opened this issue Aug 2, 2021 · 5 comments · Fixed by #158793 or #181361
Closed

package request: keyd - "A key remapping daemon for linux" #132474

colemickens opened this issue Aug 2, 2021 · 5 comments · Fixed by #158793 or #181361
Labels
0.kind: packaging request Request for a new package to be added

Comments

@colemickens
Copy link
Member

Project description

https://github.com/rvaiya/keyd

A key remapping daemon for linux.

Linux lacks a good key remapping solution. In order to achieve satisfactory results a medley of tools need to be employed (e.g xcape, xmodmap) with the end result often being tethered to a specified environment (X11). keyd attempts to solve this problem by providing a flexible system wide daemon which remaps keys using kernel level input primitives (evdev, uinput).

Features
keyd has several unique features many of which are traditionally only found in custom keyboard firmware like QMK. Some of the more interesting ones include:

Layers.
Key overloading (different behaviour on tap/hold).
Per keyboard configuration.
Instantaneous remapping (no flashing required).
A simple and intuitive config format.
Being display server agnostic (works on wayland and virtual console alike).

Metadata

@colemickens colemickens added the 0.kind: packaging request Request for a new package to be added label Aug 2, 2021
@foolnotion
Copy link
Contributor

I tried making a rudimentary derivation but currently I don't have a lot of time to spend on this. It would be nice if someone more experienced could pick this up and turn it into a proper derivation. Notably the paths for the config file, log file and lock file should be made into options or be set to some standard nix paths.

{ lib, stdenv, fetchgit, udev, git }:

let
  pname = "keyd";
  version = "1.1.2";
in stdenv.mkDerivation rec {
  inherit version pname;

  src = fetchgit {
    url = "https://github.com/rvaiya/keyd.git";
    rev = "refs/tags/v${version}";
    sha256 = "sha256-E9WHCJxTGwvkrwm4zXFye53nJU9GFtovIxRrpoL/VtM=";
  };

  buildInputs = [ git udev ];

  patches = [
    ./keyd.patch
  ];

  buildPhase = ''
    make LOCK_FILE=/home/xxx/.keyd/keyd.lock LOG_FILE=/home/xxx/.keyd/keyd.log CONFIG_DIR=/home/xxx/.keyd
  '';

  installPhase = ''
    make install DESTDIR=$out PREFIX=
  '';

  meta = {
    description = "A key remapping daemon for linux.";
    license = lib.licenses.mit;
    platforms = lib.platforms.linux;
  };
}

The C source and Makefile had to be patched to allow for path customization, but this should probably be taken up with upstream.

diff --git a/Makefile b/Makefile
index 8f90462..3563b80 100644
--- a/Makefile
+++ b/Makefile
@@ -3,9 +3,13 @@
 DESTDIR=
 PREFIX=/usr
 
+CONFIG_DIR=/etc/keyd
+LOCK_FILE=/var/lock/keyd.lock
+LOG_FILE=/var/log/keyd.log
+
 VERSION=1.1.2
 GIT_HASH=$(shell git describe --no-match --always --abbrev=40 --dirty)
-CFLAGS=-DVERSION=\"$(VERSION)\" -DGIT_COMMIT_HASH=\"$(GIT_HASH)\"
+CFLAGS=-DVERSION=\"$(VERSION)\" -DGIT_COMMIT_HASH=\"$(GIT_HASH)\" -DLOCK_FILE=\"$(LOCK_FILE)\" -DLOG_FILE=\"$(LOG_FILE)\" -DCONFIG_DIR=\"$(CONFIG_DIR)\"
 
 all:
 	mkdir -p bin
diff --git a/src/config.h b/src/config.h
index a6465b8..3a53043 100644
--- a/src/config.h
+++ b/src/config.h
@@ -29,7 +29,11 @@
 #include "keys.h"
 
 #define MAX_LAYERS 32
+
+#ifndef CONFIG_DIR
 #define CONFIG_DIR "/etc/keyd"
+#endif
+
 #define MAX_LAYER_NAME_LEN 256
 #define MAX_MACRO_SIZE 256
 #define MAX_MACROS 256
diff --git a/src/main.c b/src/main.c
index 86dbc7e..a697170 100644
--- a/src/main.c
+++ b/src/main.c
@@ -42,8 +42,14 @@
 
 #define UINPUT_DEVICE_NAME "keyd virtual keyboard"
 #define MAX_KEYBOARDS 256
+
+#ifndef LOCK_FILE
 #define LOCK_FILE "/var/lock/keyd.lock"
+#endif
+
+#ifndef LOG_FILE
 #define LOG_FILE "/var/log/keyd.log" //Only used when running as a daemon.
+#endif
 
 #ifdef DEBUG
 	#define dbg(fmt, ...) warn("%s:%d: "fmt, __FILE__, __LINE__, ## __VA_ARGS__)

One can also define a systemd service for it (but I'm not using it that way so I haven't tested it).

systemd.user.services."keyd" = {
  Unit = {
    Description = "key remapping daemon";
    #Requires = "local-fs.target";
    #After = "local-fs.target";
  };

  Service = {
    Type = "simple";
    ExecStart = "${pkgs.keyd}/bin/keyd";
  };
};

@dit7ya
Copy link
Member

dit7ya commented Sep 17, 2021

I am new to Nix and was thinking of contributing to it by submitting this package. I am curious, @foolnotion, what is wrong with letting the config directories etc. stay that the way they are? Of course I would want more control over the dotfiles but that is an upstream issue, right?

@foolnotion
Copy link
Contributor

@dit7ya I am actually not sure about the proper "nix" way to package this, as nix does not strictly adhere to the FHS standard, but I thought it'd be nice to be able to configure the path. It seems more logical to me to keep the config files under /home/$USER/.config/keyd rather than system-wide in /etc. I had made an issue upstream so the paths are configurable at build time but not at runtime.

@stale
Copy link

stale bot commented Apr 25, 2022

I marked this as stale due to inactivity. → More info

@peterhoeg
Copy link
Member

I've been carrying this locally for ages - apologies for not upstreaming it earlier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: packaging request Request for a new package to be added
Projects
None yet
4 participants