Skip to content

Commit

Permalink
Update and re-enable xbindkeys for media keys
Browse files Browse the repository at this point in the history
  • Loading branch information
rake5k committed Oct 4, 2024
1 parent bd4761b commit e869513
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 52 deletions.
1 change: 1 addition & 0 deletions home/roles/desktop/xserver/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ in
cursors.enable = true;
locker.enable = true;
redshift.enable = true;
xbindkeys.enable = true;

xmonad = {
inherit (cfg) colorScheme;
Expand Down
91 changes: 39 additions & 52 deletions home/roles/desktop/xserver/xbindkeys/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,77 +4,64 @@ with lib;

let

xCfg = config.custom.roles.desktop.xserver;
cfg = xCfg.xbindkeys;
terminalCfg = xCfg.terminal;
desktopCfg = config.custom.roles.desktop;
cfg = desktopCfg.xserver.xbindkeys;
terminalCfg = desktopCfg.terminal;

defaultKeymap = {
XF86AudioLowerVolume = "wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%-";
XF86AudioRaiseVolume = "wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%+";
XF86AudioMute = "wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle";
XF86AudioMicMute = "wpctl set-source-mute @DEFAULT_SOURCE@ toggle";
XF86AudioPlay = "playerctl play-pause";
XF86AudioStop = "playerctl stop";
XF86AudioPause = "playerctl pause";
XF86AudioNext = "playerctl next";
XF86AudioPrev = "playerctl previous";
XF86Bluetooth = "${getExe pkgs.bash} -c \"if rfkill list bluetooth|grep -q 'yes$';then rfkill unblock bluetooth;else rfkill block bluetooth;fi\"";
XF86MonBrightnessDown = "brightnessctl set 10%-";
XF86MonBrightnessUp = "brightnessctl set 10%+";
XF86Calculator = "${terminalCfg.commandSpawnCmd} ${getExe pkgs.eva}";
XF86Explorer = "${terminalCfg.commandSpawnCmd} ${getExe pkgs.ranger}";
XF86HomePage = "xdg-open";
};

mkRcEntry = keymap:
concatStringsSep "\n" (
mapAttrsToList (code: command: ''
"${command}"
${code}
'') keymap
);

in

{
options = {
custom.roles.desktop.xserver.xbindkeys = {
enable = mkEnableOption "Xbindkeys";

keymap = mkOption {
type = with types; attrsOf str;
description = "Key mapping";
default = defaultKeymap;
};
};
};

config = mkIf cfg.enable {
custom.roles.desktop.terminal.enable = true;

home.packages = with pkgs; [
# Audio control
playerctl
terminalCfg.package

brightnessctl
playerctl
xbindkeys
] + [
terminalCfg.package
];

xdg.configFile."xbindkeysrc" = {
text = ''
"pactl set-sink-volume 0 -5%"
XF86AudioLowerVolume
"pactl set-sink-volume 0 +5%"
XF86AudioRaiseVolume
"pactl set-sink-mute 0 toggle"
XF86AudioMute
"pactl set-source-mute 1 toggle"
XF86AudioMicMute
"playerctl play"
XF86AudioPlay
"playerctl stop"
XF86AudioStop
"playerctl pause"
XF86AudioPause
"playerctl next"
XF86AudioNext
"playerctl previous"
XF86AudioPrev
"bash -c \"if rfkill list bluetooth|grep -q 'yes$';then rfkill unblock bluetooth;else rfkill block bluetooth;fi\""
XF86Bluetooth
# FIXME Only working once?
"${terminalCfg.commandSpawnCmd} eva"
XF86Calculator
"${terminalCfg.commandSpawnCmd} ranger"
XF86Explorer
"xdg-open"
XF86HomePage
# TODO:
#"gsettings"
# XF86Tools
'';
text = mkRcEntry (defaultKeymap // cfg.keymap);
target = config.home.homeDirectory + "/.xbindkeysrc";
};

Expand Down

0 comments on commit e869513

Please sign in to comment.