I installed input-remapper. I was able to create and apply a configuration using the GUI. But each time and log out or my machine goes to sleep, I have to restart the application to apply the configuration again.
How can the changes be permanent, so my mapping continues to work after a log-out or a sleep?
1 Like
Here is my solution. I made two services in my Nixos config file :
systemd.services.StartInputRemapperDaemonAtLogin = {
enable = true;
description = "Start input-remapper daemon after login";
unitConfig = {
Type = "simple";
};
script = lib.getExe(pkgs.writeShellApplication {
name = "start-input-mapper-daemon";
runtimeInputs = with pkgs; [input-remapper procps su];
text = ''
until pgrep -u pierre; do
sleep 1
done
sleep 2
until [ $(pgrep -c -u root "input-remapper") -eq 4 ]; do
input-remapper-service&
sleep 1
input-remapper-helper&
sleep 1
done
su pierre -c "input-remapper-control --command stop-all"
su pierre -c "input-remapper-control --command autoload"
sleep infinity
'';
});
wantedBy = [ "default.target" ];
};
systemd.services.ReloadInputRemapperAfterSleep = {
enable = true;
description = "Reload input-remapper config after sleep";
after = [ "suspend.target" ];
unitConfig = {
Type = "forking";
};
serviceConfig.User = "pierre";
script = lib.getExe(pkgs.writeShellApplication {
name = "reload-input-mapper-config";
runtimeInputs = with pkgs; [input-remapper ps gawk];
text = ''
until [[ $(ps aux | awk '$11~"input-remapper" && $12="<defunct>" {print $0}' | wc -l) -eq 0 ]]; do
input-remapper-control --command stop-all
input-remapper-control --command autoload
sleep 1
done
'';
});
wantedBy = [ "suspend.target" ];
};
Now, my mouse buttons are mapped automatically when I log in, and I don’t lose my mapping when my machine comes back from sleep.
When I log in, for a few seconds, I must both move my mouse because otherwise it is not always detected properly, and also avoid clicking mouse buttons for the mapping to work properly.
It is no longer working with NixOS 24.05 because of changes made in the new 2.0.1 Input-Remapper.
I updated my solution:
systemd.services.StartInputRemapperDaemonAtLogin = {
enable = true;
description = "Start input-remapper daemon after login";
serviceConfig = {
Type = "simple";
};
script = lib.getExe(pkgs.writeShellApplication {
name = "start-input-mapper-daemon";
runtimeInputs = with pkgs; [input-remapper procps su];
text = ''
until pgrep -u pierre; do
sleep 1
done
sleep 2
until [ $(pgrep -c -u root "input-remapper") -gt 1 ]; do
input-remapper-service&
sleep 1
input-remapper-reader-service&
sleep 1
done
su pierre -c "input-remapper-control --command stop-all"
su pierre -c "input-remapper-control --command autoload"
sleep infinity
'';
});
wantedBy = [ "default.target" ];
};
systemd.services.ReloadInputRemapperAfterSleep = {
enable = true;
description = "Reload input-remapper config after sleep";
after = [ "suspend.target" ];
serviceConfig = {
User = "pierre";
Type = "forking";
};
script = lib.getExe(pkgs.writeShellApplication {
name = "reload-input-mapper-config";
runtimeInputs = with pkgs; [input-remapper ps gawk];
text = ''
input-remapper-control --command stop-all
input-remapper-control --command autoload
sleep 1
until [[ $(ps aux | awk '$11~"input-remapper" && $12="<defunct>" {print $0}' | wc -l) -eq 0 ]]; do
input-remapper-control --command stop-all
input-remapper-control --command autoload
sleep 1
done
'';
});
wantedBy = [ "suspend.target" ];
};