From 4080bad9df44ab5041b3a2bfd931bfec6032995d Mon Sep 17 00:00:00 2001 From: Ryan Yin Date: Sun, 1 Jun 2025 01:03:56 +0800 Subject: [PATCH] chore(home/linux/gui/hyprland): remove scripts & unused packages, use hyprlock & hypridle --- README.md | 3 +- .../linux/gui/hyprland/conf/configs/exec.conf | 9 ++- .../hyprland/conf/configs/keybindings.conf | 23 ++---- home/linux/gui/hyprland/conf/hypridle.conf | 19 +++++ .../gui/hyprland/conf/scripts/colorpicker | 20 ----- .../gui/hyprland/conf/scripts/lockscreen | 10 --- home/linux/gui/hyprland/conf/scripts/menu | 7 -- .../gui/hyprland/conf/scripts/notifications | 9 --- home/linux/gui/hyprland/conf/scripts/startup | 25 ------ .../linux/gui/hyprland/conf/scripts/statusbar | 10 --- home/linux/gui/hyprland/conf/scripts/volume | 76 ------------------- home/linux/gui/hyprland/conf/scripts/wlogout | 18 ----- .../gui/hyprland/conf/waybar/config.jsonc | 4 +- home/linux/gui/hyprland/values/hyprland.nix | 24 ++++-- home/linux/gui/hyprland/values/packages.nix | 15 +--- modules/nixos/desktop.nix | 2 +- 16 files changed, 60 insertions(+), 214 deletions(-) create mode 100644 home/linux/gui/hyprland/conf/hypridle.conf delete mode 100755 home/linux/gui/hyprland/conf/scripts/colorpicker delete mode 100755 home/linux/gui/hyprland/conf/scripts/lockscreen delete mode 100755 home/linux/gui/hyprland/conf/scripts/menu delete mode 100755 home/linux/gui/hyprland/conf/scripts/notifications delete mode 100755 home/linux/gui/hyprland/conf/scripts/startup delete mode 100755 home/linux/gui/hyprland/conf/scripts/statusbar delete mode 100755 home/linux/gui/hyprland/conf/scripts/volume delete mode 100755 home/linux/gui/hyprland/conf/scripts/wlogout diff --git a/README.md b/README.md index 564e4435..63683625 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ You don't have to go through the pain I've experienced again! Check out my | **Text Editor** | [Neovim][Neovim] | | **Fonts** | [Nerd fonts][Nerd fonts] | | **Image Viewer** | [imv][imv] | -| **Screenshot Software** | [flameshot][flameshot] + [grim][grim] | +| **Screenshot Software** | [flameshot][flameshot] | | **Screen Recording** | [OBS][OBS] | | **Filesystem & Encryption** | tmpfs on `/`, [Btrfs][Btrfs] subvolumes on a [LUKS][LUKS] encrypted partition for persistent, unlock via passphrase | | **Secure Boot** | [lanzaboote][lanzaboote] | @@ -193,7 +193,6 @@ Other dotfiles that inspired me: [Neovim]: https://github.com/neovim/neovim [AstroNvim]: https://github.com/AstroNvim/AstroNvim [flameshot]: https://github.com/flameshot-org/flameshot -[grim]: https://github.com/emersion/grim [flameshot]: https://github.com/flameshot-org/flameshot [imv]: https://sr.ht/~exec64/imv/ [OBS]: https://obsproject.com diff --git a/home/linux/gui/hyprland/conf/configs/exec.conf b/home/linux/gui/hyprland/conf/configs/exec.conf index bedc0a64..360406a7 100644 --- a/home/linux/gui/hyprland/conf/configs/exec.conf +++ b/home/linux/gui/hyprland/conf/configs/exec.conf @@ -1,2 +1,9 @@ #-- Startup ---------------------------------------------------- -exec-once=~/.config/hypr/scripts/startup +exec-once = waybar --bar main-bar --log-level error + +#-- Idle Daemon -- +exec-once = hypridle + +## Fix anyrun +## https://github.com/anyrun-org/anyrun/issues/153 +exec-once = ln -s "$XDG_RUNTIME_DIR/hypr" /tmp/hypr diff --git a/home/linux/gui/hyprland/conf/configs/keybindings.conf b/home/linux/gui/hyprland/conf/configs/keybindings.conf index 2c584f8d..95db28a5 100644 --- a/home/linux/gui/hyprland/conf/configs/keybindings.conf +++ b/home/linux/gui/hyprland/conf/configs/keybindings.conf @@ -1,10 +1,6 @@ #-- Keybindings ---------------------------------------------------- $term = foot -$app_launcher = ~/.config/hypr/scripts/menu -$volume = ~/.config/hypr/scripts/volume -$lockscreen = ~/.config/hypr/scripts/lockscreen -$wlogout = ~/.config/hypr/scripts/wlogout -$colorpicker = ~/.config/hypr/scripts/colorpicker +$app_launcher = anyrun $files = thunar $browser = firefox @@ -23,9 +19,8 @@ bind=SUPER,S,pseudo, # -- Misc -- bind=SUPER,N,exec,nm-connection-editor # need install network-manager-applet -bind=SUPER,P,exec,$colorpicker -bind=CTRLALT,L,exec,$lockscreen -bind=SUPERSHIFT,X,exec,$wlogout +bind=CTRLALT,L,exec,hyprlock +bind=SUPERSHIFT,X,exec,wlogout # -- Some nice mouse binds -- bindm=SUPER,mouse:272,movewindow @@ -34,14 +29,10 @@ bindm=SUPER,mouse:273,resizewindow # -- Function keys -- # bind=,XF86MonBrightnessUp,exec,$backlight --inc # bind=,XF86MonBrightnessDown,exec,$backlight --dec -bind=,XF86AudioRaiseVolume,exec,$volume --inc -bind=,XF86AudioLowerVolume,exec,$volume --dec -bind=,XF86AudioMute,exec,$volume --toggle -bind=,XF86AudioMicMute,exec,$volume --toggle-mic -bind=,XF86AudioNext,exec,mpc next -bind=,XF86AudioPrev,exec,mpc prev -bind=,XF86AudioPlay,exec,mpc toggle -bind=,XF86AudioStop,exec,mpc stop +# bind=,XF86AudioRaiseVolume,exec,$volume --inc +# bind=,XF86AudioLowerVolume,exec,$volume --dec +# bind=,XF86AudioMute,exec,$volume --toggle +# bind=,XF86AudioMicMute,exec,$volume --toggle-mic # -- Screenshots -- bind=,Print,exec,hyprshot -m output -o ~/Pictures/Screenshots -- imv diff --git a/home/linux/gui/hyprland/conf/hypridle.conf b/home/linux/gui/hyprland/conf/hypridle.conf new file mode 100644 index 00000000..6229527d --- /dev/null +++ b/home/linux/gui/hyprland/conf/hypridle.conf @@ -0,0 +1,19 @@ + +general { + lock_cmd = pidof hyprlock || hyprlock # avoid starting multiple instances + before_sleep_cmd = loginctl lock-session # lock before suspend + after_sleep_cmd = hyprctl dispatch dpms on # resume dpms after suspend + ignore_dbus_inhibit = false # whether to ignore dbus-sent idle-inhibit requests +} + +listener { + timeout = 290 # 4 minutes and 50 seconds + on-timeout = pidof hyprlock || hyprlock # lock screen + on-resume = hyprctl dispatch dpms on # monitor wake up +} + +listener { + timeout = 300 # 5 minutes + on-timeout = hyprctl dispatch dpms off # screen off + on-resume = hyprctl dispatch dpms on # monitor wake up +} diff --git a/home/linux/gui/hyprland/conf/scripts/colorpicker b/home/linux/gui/hyprland/conf/scripts/colorpicker deleted file mode 100755 index f83e4f97..00000000 --- a/home/linux/gui/hyprland/conf/scripts/colorpicker +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env bash - -## Simple Script To Pick Color Quickly. - -color=$(grim -g "$(slurp -b 1B1F2800 -p)" -t ppm - | convert - -format '%[pixel:p{0,0}]' txt:- | tail -n1 | cut -d' ' -f4) -image=/tmp/${color}.png - -main() { - if [[ "$color" ]]; then - # copy color code to clipboard - echo $color | tr -d "\n" | wl-copy - # generate preview - convert -size 48x48 xc:"$color" ${image} - # notify about it - notify-send -h string:x-canonical-private-synchronous:sys-notify -u low -i ${image} "$color, copied to clipboard." - fi -} - -# Run the script -main diff --git a/home/linux/gui/hyprland/conf/scripts/lockscreen b/home/linux/gui/hyprland/conf/scripts/lockscreen deleted file mode 100755 index 423be188..00000000 --- a/home/linux/gui/hyprland/conf/scripts/lockscreen +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash - -# Times the screen off and puts it to background -swayidle \ - timeout 300 'swaymsg "output * power off"' \ - resume 'swaymsg "output * power on"' & -# Locks the screen immediately -swaylock -# Kills last background task so idle timer doesn't keep running -kill %% \ No newline at end of file diff --git a/home/linux/gui/hyprland/conf/scripts/menu b/home/linux/gui/hyprland/conf/scripts/menu deleted file mode 100755 index 33ddb986..00000000 --- a/home/linux/gui/hyprland/conf/scripts/menu +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash - -if [[ ! $(pidof anyrun) ]]; then - anyrun -else - pkill anyrun -fi diff --git a/home/linux/gui/hyprland/conf/scripts/notifications b/home/linux/gui/hyprland/conf/scripts/notifications deleted file mode 100755 index cf214567..00000000 --- a/home/linux/gui/hyprland/conf/scripts/notifications +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env bash - -## launch mako with alt config - -CONFIG="$HOME/.config/hypr/mako/config" - -if [[ ! $(pidof mako) ]]; then - mako --config ${CONFIG} -fi diff --git a/home/linux/gui/hyprland/conf/scripts/startup b/home/linux/gui/hyprland/conf/scripts/startup deleted file mode 100755 index 6719a4be..00000000 --- a/home/linux/gui/hyprland/conf/scripts/startup +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env bash - -## Fix anyrun -## https://github.com/anyrun-org/anyrun/issues/153 -ln -s $XDG_RUNTIME_DIR/hypr /tmp/hypr - -## Autostart Programs - -# Kill already running process -_ps=(waybar mako) -for _prs in "${_ps[@]}"; do - if [[ $(pidof ${_prs}) ]]; then - killall -9 ${_prs} - fi -done - -# Set wallpaper via a wallpaper.service -# it will by start by home-manager automatically, do not need to restart it here. -# systemctl --user restart wallpaper.service - -# Launch notification daemon (mako) -~/.config/hypr/scripts/notifications & - -# Launch statusbar (waybar) -~/.config/hypr/scripts/statusbar & diff --git a/home/linux/gui/hyprland/conf/scripts/statusbar b/home/linux/gui/hyprland/conf/scripts/statusbar deleted file mode 100755 index 76154833..00000000 --- a/home/linux/gui/hyprland/conf/scripts/statusbar +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash - -## launch waybar with alt config - -CONFIG="$HOME/.config/hypr/waybar/config.jsonc" -STYLE="$HOME/.config/hypr/waybar/style.css" - -if [[ ! $(pidof waybar) ]]; then - waybar --bar main-bar --log-level error --config ${CONFIG} --style ${STYLE} -fi diff --git a/home/linux/gui/hyprland/conf/scripts/volume b/home/linux/gui/hyprland/conf/scripts/volume deleted file mode 100755 index eae7aef7..00000000 --- a/home/linux/gui/hyprland/conf/scripts/volume +++ /dev/null @@ -1,76 +0,0 @@ -#!/usr/bin/env bash - -## Script To Manage Speaker Volume(in Wayland). - -iDIR="$HOME/.config/hypr/mako/icons" - -# Get Volume -get_volume() { - volume=$(amixer get Master | tail -n1 | awk -F ' ' '{print $5}' | tr -d '[]') - echo "$volume" -} - -# Get icons -get_icon() { - vol="$(get_volume)" - current="${vol%%%}" - if [[ "$current" -eq "0" ]]; then - icon="$iDIR/volume-mute.png" - elif [[ ("$current" -ge "0") && ("$current" -le "30") ]]; then - icon="$iDIR/volume-low.png" - elif [[ ("$current" -ge "30") && ("$current" -le "60") ]]; then - icon="$iDIR/volume-mid.png" - elif [[ ("$current" -ge "60") && ("$current" -le "100") ]]; then - icon="$iDIR/volume-high.png" - fi -} - -# Notify -notify_user() { - notify-send -h string:x-canonical-private-synchronous:sys-notify -u low -i "$icon" "Volume : $(get_volume)" -} - -# Increase Volume -inc_volume() { - amixer -Mq set Master,0 5%+ unmute && get_icon && notify_user -} - -# Decrease Volume -dec_volume() { - amixer -Mq set Master,0 5%- unmute && get_icon && notify_user -} - -# Toggle Mute -toggle_mute() { - amixer get Master | grep '\[on\]' &>/dev/null - if [[ "$?" == 0 ]]; then - amixer set Master toggle && notify-send -h string:x-canonical-private-synchronous:sys-notify -u low -i "$iDIR/volume-mute.png" "Mute" - else - amixer set Master toggle && get_icon && notify-send -h string:x-canonical-private-synchronous:sys-notify -u low -i "$icon" "Unmute" - fi -} - -# Toggle Mic -toggle_mic() { - amixer get Capture | grep '\[on\]' &>/dev/null - if [[ "$?" == 0 ]]; then - amixer -D pulse sset Capture toggle && notify-send -h string:x-canonical-private-synchronous:sys-notify -u low -i "$iDIR/microphone-mute.png" "Microphone Switched OFF" - else - amixer -D pulse sset Capture toggle && get_icon && notify-send -h string:x-canonical-private-synchronous:sys-notify -u low -i "$iDIR/microphone.png" "Microphone Switched ON" - fi -} - -# Execute accordingly -if [[ "$1" == "--get" ]]; then - get_volume -elif [[ "$1" == "--inc" ]]; then - inc_volume -elif [[ "$1" == "--dec" ]]; then - dec_volume -elif [[ "$1" == "--toggle" ]]; then - toggle_mute -elif [[ "$1" == "--toggle-mic" ]]; then - toggle_mic -else - get_volume -fi diff --git a/home/linux/gui/hyprland/conf/scripts/wlogout b/home/linux/gui/hyprland/conf/scripts/wlogout deleted file mode 100755 index 0a654eca..00000000 --- a/home/linux/gui/hyprland/conf/scripts/wlogout +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env bash - -## wlogout with alt layout and style file - -LAYOUT="$HOME/.config/hypr/wlogout/layout" -STYLE="$HOME/.config/hypr/wlogout/style.css" - -if [[ ! $(pidof wlogout) ]]; then - wlogout --layout ${LAYOUT} --css ${STYLE} \ - --column-spacing 20 \ - --row-spacing 20 \ - --margin-top 200 \ - --margin-bottom 200 \ - --margin-left 150 \ - --margin-right 150 -else - pkill wlogout -fi diff --git a/home/linux/gui/hyprland/conf/waybar/config.jsonc b/home/linux/gui/hyprland/conf/waybar/config.jsonc index e98ed979..f71c0edb 100644 --- a/home/linux/gui/hyprland/conf/waybar/config.jsonc +++ b/home/linux/gui/hyprland/conf/waybar/config.jsonc @@ -50,14 +50,14 @@ }, "custom/launcher": { "format": "\uf313 ", - "on-click": "$HOME/.config/hypr/scripts/menu", + "on-click": "anyrun", "on-click-middle": "exec default_wall", "on-click-right": "exec wallpaper_random", "tooltip": false, }, "custom/powermenu": { "format": "\uf011", - "on-click": "$HOME/.config/hypr/scripts/wlogout", + "on-click": "wlogout", "tooltip": false, }, "idle_inhibitor": { diff --git a/home/linux/gui/hyprland/values/hyprland.nix b/home/linux/gui/hyprland/values/hyprland.nix index fc0af44a..978538cc 100644 --- a/home/linux/gui/hyprland/values/hyprland.nix +++ b/home/linux/gui/hyprland/values/hyprland.nix @@ -7,18 +7,32 @@ }: let package = pkgs.hyprland; in { - # hyprland configs, based on https://github.com/notwidow/hyprland xdg.configFile = let mkSymlink = config.lib.file.mkOutOfStoreSymlink; hyprPath = "${config.home.homeDirectory}/nix-config/home/linux/gui/hyprland/conf"; in { + "mako".source = mkSymlink "${hyprPath}/mako"; + "waybar".source = mkSymlink "${hyprPath}/waybar"; + "wlogout".source = mkSymlink "${hyprPath}/wlogout"; + "hypr/hypridle.conf".source = mkSymlink "${hyprPath}/hypridle.conf"; "hypr/configs".source = mkSymlink "${hyprPath}/configs"; - "hypr/mako".source = mkSymlink "${hyprPath}/mako"; - "hypr/scripts".source = mkSymlink "${hyprPath}/scripts"; - "hypr/waybar".source = mkSymlink "${hyprPath}/waybar"; - "hypr/wlogout".source = mkSymlink "${hyprPath}/wlogout"; }; + # status bar + programs.waybar.enable = true; + + # screen locker + programs.hyprlock.enable = true; + + # Logout Menu + programs.wlogout.enable = true; + + # Hyprland idle daemon + services.hypridle.enable = true; + + # notification daemon, the same as dunst + services.mako.enable = true; + # NOTE: # We have to enable hyprland/i3's systemd user service in home-manager, # so that gammastep/wallpaper-switcher's user service can be start correctly! diff --git a/home/linux/gui/hyprland/values/packages.nix b/home/linux/gui/hyprland/values/packages.nix index c2e80c93..59ecf1eb 100644 --- a/home/linux/gui/hyprland/values/packages.nix +++ b/home/linux/gui/hyprland/values/packages.nix @@ -1,26 +1,17 @@ { pkgs, - pkgs-unstable, ... }: { + + home.packages = with pkgs; [ - waybar # the status bar swaybg # the wallpaper - swayidle # the idle timeout - swaylock # locking the screen - wlogout # logout menu wl-clipboard # copying and pasting hyprpicker # color picker - pkgs-unstable.hyprshot # screen shot - grim # taking screenshots - slurp # selecting a region to screenshot + hyprshot # screen shot wf-recorder # screen recording - mako # the notification daemon, the same as dunst - - yad # a fork of zenity, for creating dialogs - # audio alsa-utils # provides amixer/alsamixer/... networkmanagerapplet # provide GUI app: nm-connection-editor diff --git a/modules/nixos/desktop.nix b/modules/nixos/desktop.nix index 9712063d..e2f6c91a 100644 --- a/modules/nixos/desktop.nix +++ b/modules/nixos/desktop.nix @@ -45,7 +45,7 @@ in { }; # fix https://github.com/ryan4yin/nix-config/issues/10 - security.pam.services.swaylock = {}; + security.pam.services.hyprlock = {}; }) ]; }