dotfiles

My PC Dotfiles & Website
commit c31dd171c020f7f838e4992bf465cb46558ddd6f
parent e91ac43ffbbe19dc2042addc9ce9bc15606e26b7
Author: maydayv7 <maydayv7@gmail.com>
Date:   Fri, 22 Mar 2024 13:53:46 +0530

feat: Revamp `hyprutils`

Diffstat:

Mmodules/gui/desktop/hyprland/apps/bar.nix | 6++++--
Mmodules/gui/desktop/hyprland/apps/security.nix | 2+-
Mmodules/gui/desktop/hyprland/settings/keybindings.nix | 24++++++++++++------------
Mscripts/hyprutils.nix | 307++++++++++++++++++++++++++++++++++++++++++++++---------------------------------
4 files changed, 195 insertions(+), 144 deletions(-)

diff --git a/modules/gui/desktop/hyprland/apps/bar.nix b/modules/gui/desktop/hyprland/apps/bar.nix @@ -219,6 +219,8 @@ in rec { dynamic-separator = ""; format = " {player} {dynamic}"; format-paused = "󰏤 <i>{player}</i>"; + format-stopped = ""; + tooltip-format-stopped = "Not Playing"; }; backlight = { @@ -244,7 +246,7 @@ in rec { tooltip-format = "Battery: {capacity}%"; format-charging = ""; format-icons = ["" "" "" "" ""]; - on-click-right = "hyprutils toggle_fancy"; + on-click-right = "hyprutils toggle fancy"; states = { good = 80; warning = 20; @@ -326,7 +328,7 @@ in rec { idle_inhibitor = { format = "{icon}"; - on-click = "hyprutils toggle_idle"; + on-click = "hyprutils toggle idle"; tooltip-format-activated = "Idle Inhibitor: On"; tooltip-format-deactivated = "Idle Inhibitor: Off"; format-icons = { diff --git a/modules/gui/desktop/hyprland/apps/security.nix b/modules/gui/desktop/hyprland/apps/security.nix @@ -40,7 +40,7 @@ in { } { event = "lock"; - command = let toggle = "${getExe pkgs.custom.hyprutils} toggle_media"; in "sh -c '${toggle}; ${getExe locker}; ${toggle}'"; + command = let toggle = "${getExe pkgs.custom.hyprutils} toggle media"; in "sh -c '${toggle}; ${getExe locker}; ${toggle}'"; } ]; timeouts = [ diff --git a/modules/gui/desktop/hyprland/settings/keybindings.nix b/modules/gui/desktop/hyprland/settings/keybindings.nix @@ -62,10 +62,6 @@ _: { ", Print, exec, grimblast --notify copysave area" "CTRL, Print, exec, grimblast --notify --cursor copysave output" "SHIFT, Print, exec, grimblast --notify --cursor copysave screen" - - # Magnifier - ''$mod, equal, exec, pypr zoom "$(hyprctl getoption misc:cursor_zoom_factor | grep float | awk '{print $2 + 1}')"'' - ''$mod, minus, exec, pypr zoom "$(hyprctl getoption misc:cursor_zoom_factor | grep float | awk '{print $2 - 1}')"'' ] ++ # Workspaces @@ -92,23 +88,27 @@ _: { # Ignore Locked State bindl = [ # Media Controls - ", XF86AudioPlay, exec, hyprutils play_pause" - ", XF86AudioPrev, exec, hyprutils prev_track" - ", XF86AudioNext, exec, hyprutils next_track" + ", XF86AudioPlay, exec, hyprutils media toggle" + ", XF86AudioPrev, exec, hyprutils media previous" + ", XF86AudioNext, exec, hyprutils media next" # Volume - ", XF86AudioMute, exec, hyprutils volume_mute" + ", XF86AudioMute, exec, hyprutils volume mute" ]; # Repeat on Hold bindle = [ # Volume - ", XF86AudioRaiseVolume, exec, hyprutils volume_up" - ", XF86AudioLowerVolume, exec, hyprutils volume_down" + ", XF86AudioRaiseVolume, exec, hyprutils volume up" + ", XF86AudioLowerVolume, exec, hyprutils volume down" # Backlight - ", XF86MonBrightnessUp, exec, hyprutils brightness_up" - ", XF86MonBrightnessDown, exec, hyprutils brightness_down" + ", XF86MonBrightnessUp, exec, hyprutils brightness up" + ", XF86MonBrightnessDown, exec, hyprutils brightness down" + + # Magnifier + "$mod, equal, exec, hyprutils zoom in" + "$mod, minus, exec, hyprutils zoom out" ]; }; } diff --git a/scripts/hyprutils.nix b/scripts/hyprutils.nix @@ -8,17 +8,17 @@ help = '' # Legend # - xxx - Command[s] - Description + xxx - Command [modifiers] - Description # Usage # - brightness_[up,down] - Increase/Decrease screen brightness - volume_[up,down,mute] - Increase/Decrease/Mute audio - [next,prev]_track - Skip to previous/next audio track - play_pause - Toggle audio playing state - toggle_[] - media - Persist and toggle audio playing state - idle - Toggle Idle Daemon service - fancy - Toggle Compositor Effects + brightness [up,down] - Screen Brightness Controls + volume [up,down,mute] - Volume Controls + media [next,previous,toggle] - Media Controls + zoom [in,out] - Screen Zoom + toggle [] + media - Persist and toggle audio playing state + idle - Toggle Idle Daemon service + fancy - Toggle Compositor Effects ''; in recursiveUpdate { @@ -32,6 +32,7 @@ in } (pkgs.writeShellApplication { name = "hyprutils"; runtimeInputs = with pkgs; [ + hyprland coreutils dunst gnugrep @@ -56,11 +57,6 @@ in notify-send -a "utility" -t 1000 -h string:x-dunst-stack-tag:"$1" "''${@:2}" } - brightness_notification() { - brightness=$(brillo | grep -Po '[0-9]{1,3}' | head -n 1) - notify brightness -i "display" -h int:value:"$brightness" " $brightness%" - } - get_media_icon() { media_icon="audio-speakers" if $show_album_art @@ -78,128 +74,181 @@ in fi } - volume_notification() { - volume=$(amixer get Master | grep '%' | head -n 1 | cut -d '[' -f 2 | cut -d '%' -f 1) - mute=$(amixer get Master | grep '%' | grep -oE '[^ ]+$' | grep off | head -n1) - if [ "$volume" -eq 0 ] || [ "$mute" == "[off]" ] - then - volume_icon="" - else - volume_icon="" - fi - - song_title=$(playerctl -f "{{title}}" metadata) - get_media_icon - if $show_music_in_volume_indicator && [ -n "$song_title" ] - then - song_artist=$(playerctl -f "{{artist}}" metadata) - if [ -z "$song_artist" ] - then - notify volume -h int:value:"$volume" -i "$media_icon" "$volume_icon $volume%" "$song_title" - else - notify volume -h int:value:"$volume" -i "$media_icon" "$volume_icon $volume%" "$song_title\nBy $song_artist" - fi - else - notify volume -h int:value:"$volume" -i "$media_icon" "$volume_icon $volume%" - fi - } - - music_notification() { - song_title=$(playerctl -f "{{title}}" metadata) - song_artist=$(playerctl -f "{{artist}}" metadata) - song_album=$(playerctl -f "{{album}}" metadata) - get_media_icon - if [ -z "$song_album" ] - then - if [ -z "$song_artist" ] - then - notify music -i "$media_icon" "$song_title" - else - notify music -i "$media_icon" "$song_title" "By $song_artist" - fi - else - notify music -i "$media_icon" "$song_title" "By $song_artist from $song_album" - fi - } - case "$1" in "") error "Expected an Option" "${help}";; "help") echo -e "## Hyprland Utility Script ##\n${help}";; - "volume_up") - amixer set Master on - amixer sset Master 5%+ - volume_notification - ;; - "volume_down") - amixer set Master on - amixer sset Master 5%- - volume_notification - ;; - "volume_mute") - amixer set Master 1+ toggle - volume_notification - ;; - "brightness_up") - brillo -u 300000 -A 5 - brightness_notification - ;; - "brightness_down") - brillo -u 300000 -U 5 - brightness_notification - ;; - "next_track") - playerctl next - sleep 0.5 && music_notification - ;; - "prev_track") - playerctl previous - sleep 0.5 && music_notification + "volume") + volume_notification() { + volume=$(amixer get Master | grep '%' | head -n 1 | cut -d '[' -f 2 | cut -d '%' -f 1) + mute=$(amixer get Master | grep '%' | grep -oE '[^ ]+$' | grep off | head -n1) + if [ "$volume" -eq 0 ] || [ "$mute" == "[off]" ] + then + volume_icon="" + else + volume_icon="" + fi + + song_title=$(playerctl -f "{{title}}" metadata) + get_media_icon + if $show_music_in_volume_indicator && [ -n "$song_title" ] + then + song_artist=$(playerctl -f "{{artist}}" metadata) + if [ -z "$song_artist" ] + then + notify volume -h int:value:"$volume" -i "$media_icon" "$volume_icon $volume%" "$song_title" + else + notify volume -h int:value:"$volume" -i "$media_icon" "$volume_icon $volume%" "$song_title\nBy $song_artist" + fi + else + notify volume -h int:value:"$volume" -i "$media_icon" "$volume_icon $volume%" + fi + } + case "$2" in + "up") + amixer set Master on + amixer sset Master 5%+ + volume_notification + ;; + "down") + amixer set Master on + amixer sset Master 5%- + volume_notification + ;; + "mute") + amixer set Master 1+ toggle + volume_notification + ;; + *) + error "Unexpected Option 'volume $2'" "Try 'hyprutils help' for more information" + ;; + esac ;; - "play_pause") - playerctl play-pause - music_notification + "brightness") + brightness_notification() { + brightness=$(brillo | grep -Po '[0-9]{1,3}' | head -n 1) + notify brightness -i "display" -h int:value:"$brightness" " $brightness%" + } + case "$2" in + "up") + brillo -u 300000 -A 5 + brightness_notification + ;; + "down") + brillo -u 300000 -U 5 + brightness_notification + ;; + *) + error "Unexpected Option 'brightness $2'" "Try 'hyprutils help' for more information" + ;; + esac ;; - "toggle_media") - FILE="$TEMP/toggle_media" - if test -f "$FILE" - then - rm "$FILE" - playerctl play - exit 0 - fi - if playerctl status | grep Playing - then - touch "$FILE" - playerctl pause -a - fi + "media") + music_notification() { + song_title=$(playerctl -f "{{title}}" metadata) + song_artist=$(playerctl -f "{{artist}}" metadata) + song_album=$(playerctl -f "{{album}}" metadata) + get_media_icon + if [ -z "$song_album" ] + then + if [ -z "$song_artist" ] + then + notify music -i "$media_icon" "$song_title" + else + notify music -i "$media_icon" "$song_title" "By $song_artist" + fi + else + notify music -i "$media_icon" "$song_title" "By $song_artist from $song_album" + fi + } + case "$2" in + "next") + playerctl next + sleep 0.5 && music_notification + ;; + "previous") + playerctl previous + sleep 0.5 && music_notification + ;; + "toggle") + playerctl play-pause + music_notification + ;; + *) + error "Unexpected Option 'media $2'" "Try 'hyprutils help' for more information" + ;; + esac ;; - "toggle_idle") - if systemctl --user is-active swayidle - then - systemctl --user stop swayidle - notify idle -i "system-lock-screen" "Stopped Idle Daemon" - else - systemctl --user restart swayidle - notify idle -i "system-lock-screen" "Started Idle Daemon" - fi + "zoom") + ZOOM=$(hyprctl getoption misc:cursor_zoom_factor | grep float | awk '{print $2}') + case "$2" in + "in") + ZOOM=$(echo "$ZOOM" | awk '{print $1 + 0.2}') + hyprctl keyword misc:cursor_zoom_factor "$ZOOM" + hyprctl notify 1 1000 0 "Zoomed In ($ZOOM""x)" + ;; + "out") + if [ "$ZOOM" = "1.000000" ] + then + hyprctl notify 3 2000 0 "Already zoomed out" + else + ZOOM=$(echo "$ZOOM" | awk '{print $1 - 0.2}') + hyprctl keyword misc:cursor_zoom_factor "$ZOOM" + hyprctl notify 1 1000 0 "Zoomed Out ($ZOOM""x)" + fi + ;; + *) + error "Unexpected Option 'zoom $2'" "Try 'hyprutils help' for more information" + ;; + esac ;; - "toggle_fancy") - FANCY=$(hyprctl getoption animations:enabled | awk 'NR==1{print $2}') - if [ "$FANCY" = 1 ] - then - hyprctl notify 1 2000 0 "Compositor Effects Disabled" - hyprctl --batch "\ - keyword animations:enabled 0;\ - keyword decoration:drop_shadow 0;\ - keyword decoration:blur:enabled 0;\ - keyword general:gaps_in 0;\ - keyword general:gaps_out 0;\ - keyword general:border_size 1;\ - keyword decoration:rounding 0" - exit - fi - hyprctl notify 1 2000 0 "Compositor Effects Enabled" - hyprctl reload + "toggle") + case "$2" in + "media") + FILE="$TEMP/toggle_media" + if test -f "$FILE" + then + rm "$FILE" + playerctl play + exit 0 + fi + if playerctl status | grep Playing + then + touch "$FILE" + playerctl pause -a + fi + ;; + "idle") + if systemctl --user is-active swayidle + then + systemctl --user stop swayidle + notify idle -i "system-lock-screen" "Stopped Idle Daemon" + else + systemctl --user restart swayidle + notify idle -i "system-lock-screen" "Started Idle Daemon" + fi + ;; + "fancy") + FANCY=$(hyprctl getoption animations:enabled | awk 'NR==1{print $2}') + if [ "$FANCY" = 1 ] + then + hyprctl notify 1 2000 0 "Compositor Effects Disabled" + hyprctl --batch "\ + keyword animations:enabled 0;\ + keyword decoration:drop_shadow 0;\ + keyword decoration:blur:enabled 0;\ + keyword general:gaps_in 0;\ + keyword general:gaps_out 0;\ + keyword general:border_size 1;\ + keyword decoration:rounding 0" + exit + fi + hyprctl notify 1 2000 0 "Compositor Effects Enabled" + hyprctl reload + ;; + *) + error "Unexpected Option 'toggle $2'" "Try 'hyprutils help' for more information" + ;; + esac ;; esac '';