hyprutils.nix (4951B)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | { lib, pkgs, files, ... }: let inherit (lib) licenses recursiveUpdate; help = '' # Legend # xxx - Command [action] - Description # Usage # help - Show this information gamemode - Toggle Game Mode magnify [level] - Adjust magnification toggle float - Toggle window floating in current workspace minimized - Show minimized windows monitor 'name' - Toggle specified Monitor shader - Toggle Compositor Shader touchpad - Toggle touchpad ''; in recursiveUpdate { meta = { mainProgram = "hyprutils"; description = "Hyprland Utility Script"; homepage = files.path.repo; license = licenses.gpl3Only; maintainers = ["maydayv7"]; }; } ( pkgs.writeShellApplication { name = "hyprutils"; runtimeInputs = with pkgs; [ coreutils gnugrep zenity hyprshade hyprland ]; text = '' set +eu ${files.scripts.commands} hyprnotify() { hyprctl notify "$1" 1500 0 " $2 " } fail() { error "$1" "Try 'hyprutils help' for more information" } temp hyprutils-gamemode 3 GAMEMODE_STATE="$TEMP" game_mode_active() { [ -d "$GAMEMODE_STATE" ] } case "$1" in "") error "Expected an Option" "${help}";; "help") echo -e "## Hyprland Utility Script ##\n${help}";; "gamemode") if game_mode_active then if pypr gamemode then temp hyprutils-gamemode 2 fi elif pypr gamemode then temp hyprutils-gamemode 1 hyprctl keyword plugin:dynamic_cursors:enabled false hyprshade off pypr zoom 0 fi ;; "magnify") if game_mode_active then hyprnotify 0 "Magnification disabled in Game Mode" elif [ -n "$2" ] then pypr zoom "$2" else pypr zoom 0 fi ;; "toggle") case "$2" in "float") WORKSPACE=$(hyprctl activeworkspace | grep "workspace ID" | awk '{print $3}') hyprnotify 1 "Toggled window floating on Workspace $WORKSPACE" hyprctl eval 'local ws = hl.get_active_workspace(); if ws then for _, w in ipairs(hl.get_workspace_windows(ws)) do hl.dispatch(hl.dsp.window.float({ action = "toggle", window = w })) end end' hyprctl dispatch 'hl.dsp.event("floatcheck")' ;; "minimized") if hyprctl workspaces | grep "special:minimized" then hyprctl dispatch 'hl.dsp.focus({ workspace = "special:minimized" })' hyprctl dispatch 'hl.dsp.submap("minimized")' else hyprnotify 1 "No minimized windows present" fi ;; "monitor") if [ -z "$3" ] then fail "Expected monitor name" fi if hyprctl monitors | grep "Monitor $3" then hyprctl eval 'hl.monitor({ output = "'"$3"'", disabled = true })' else hyprctl eval 'hl.monitor({ output = "'"$3"'", mode = "preferred", position = "auto", scale = 1 })' fi ;; "shader") if game_mode_active then hyprnotify 0 "Shaders disabled in Game Mode" else hyprshade off mapfile SHADERS < <(hyprshade ls) SHADER=$(zenity --list --title="Compositor Shader Toggle" --column="Shaders" "''${SHADERS[@]}" | sed "s/^[ \t]*//") hyprshade on "$SHADER" && hyprctl seterror "" fi ;; "touchpad") touchpad=$(hyprctl devices | grep touchpad | xargs) hyprctl eval ' if __touchpad_enabled == nil then __touchpad_enabled = true end __touchpad_enabled = not __touchpad_enabled hl.device({ name = "'"$touchpad"'", enabled = __touchpad_enabled }) hl.notification.create({ text = " Touchpad " .. (__touchpad_enabled and "Enabled" or "Disabled") .. " ", duration = 1500, icon = 1, }) ' ;; "") fail "Expected an Option" ;; *) fail "Unexpected Option 'toggle $2'" ;; esac ;; *) fail "Unexpected Option '$1'" ;; esac ''; } ) |