From a2c5b7fa4973af263ffafbd89e3d4b06ba911baf Mon Sep 17 00:00:00 2001 From: krizej Date: Fri, 27 Sep 2024 22:56:36 +0200 Subject: [PATCH] i3status updates via signals --- modules/stuff/i3.nix | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/modules/stuff/i3.nix b/modules/stuff/i3.nix index fde53e7..683d009 100644 --- a/modules/stuff/i3.nix +++ b/modules/stuff/i3.nix @@ -92,11 +92,17 @@ in { ] ++ optionals config.chuj.stuff.mpd.enable [ { command = "${pkgs.writeShellScriptBin "mpdstatus" '' + trap "echo SIG" USR1 EXIT + while true; do + sleep 1 & + wait + status=$(mpc status | sed -n 2p | cut -d' ' -f1) title=$(basename "$(mpc current -f '%file%')" .mp3) echo "$status $title" > /tmp/i3-mpd-status-stuff - sleep 1 + echo update!! + done ''}/bin/mpdstatus &"; notification = false; } ]; @@ -120,6 +126,9 @@ in { mod = modifier; execns = "exec --no-startup-id"; cmd_and_center = cmd: "${execns} i3-msg '${cmd}' && i3custom-center-mouse-on-focus"; + killall = "${pkgs.killall}/bin/killall"; + update_mpdstatus = "${killall} -USR1 mpdstatus && sleep 0.05"; # hack as fack xd + update_i3status = "${killall} -USR1 i3status"; in mergeAttrs { # Program keybinds "${mod}+Return" = ''${execns} ${if config.chuj.stuff.alacritty.enable then "alacritty" else "i3-sensible-terminal"}''; @@ -129,9 +138,9 @@ in { "--release ${mod}+k" = "${execns} xkill"; # Volume control - "Ctrl+F9" = "${execns} pamixer --toggle-mute"; - "Ctrl+F10" = "${execns} pamixer --decrease 5"; - "Ctrl+F11" = "${execns} pamixer --increase 5"; + "Ctrl+F9" = "${execns} pamixer --toggle-mute && ${update_i3status}"; + "Ctrl+F10" = "${execns} pamixer --decrease 5 && ${update_i3status}"; + "Ctrl+F11" = "${execns} pamixer --increase 5 && ${update_i3status}"; # General i3 keybindings "${mod}+f" = cmd_and_center "fullscreen toggle"; @@ -181,12 +190,12 @@ in { "${mod}+Shift+0" = cmd_and_center "move container to workspace number 10"; } (optionalAttrs config.chuj.stuff.mpd.enable { # MPD controls - "Ctrl+F5" = "exec mpdfdial.sh"; - "Ctrl+F6" = "exec mpc prev"; - "Ctrl+F7" = "exec mpc toggle"; - "Ctrl+F8" = "exec mpc next"; + "Ctrl+F5" = "exec mpdfdial.sh && ${update_mpdstatus} && ${update_i3status}"; + "Ctrl+F6" = "exec mpc prev && ${update_mpdstatus} && ${update_i3status}"; + "Ctrl+F7" = "exec mpc toggle && ${update_mpdstatus} && ${update_i3status}"; + "Ctrl+F8" = "exec mpc next && ${update_mpdstatus} && ${update_i3status}"; "Ctrl+Shift+F6" = "exec mpc seek -3"; - "Ctrl+Shift+F7" = "exec mpc clear"; + "Ctrl+Shift+F7" = "exec mpc clear && ${update_mpdstatus} && ${update_i3status}"; "Ctrl+Shift+F8" = "exec mpc seek +3"; "Ctrl+Shift+F10" = ''exec mpc volume -5 && dunstify "mpc $(mpc volume)" -r 420''; "Ctrl+Shift+F11" = ''exec mpc volume +5 && dunstify "mpc $(mpc volume)" -r 420'';