From 6695e8192b775e019e48ba09dc43554d2db61984 Mon Sep 17 00:00:00 2001 From: coolnsx Date: Sun, 31 May 2026 15:20:26 +0530 Subject: [PATCH] Feat: moved all the startup script to systemd services --- .gitignore | 3 + env.example | 10 ++++ hypr/battery | 56 ++++++++++++------ hypr/hyprland.conf | 25 +++++--- hypr/hyprlock.conf | 1 - hypr/ntfy.png | Bin 0 -> 3627 bytes hypr/ntfy_sub | 24 ++++++++ hypr/virt-monitor | 2 +- hypr/workspace | 2 +- mimeapps.list | 9 +-- nvim/lazy-lock.json | 14 ++--- .../xdg-user-dirs.service | 1 + systemd/user/monitor-battery.service | 9 +++ systemd/user/ntfy_sub.service | 8 +++ systemd/user/power-mode@.service | 2 +- systemd/user/set-background@.service | 8 +++ systemd/user/theme.service | 6 ++ systemd/user/workspace.service | 9 +++ 18 files changed, 148 insertions(+), 41 deletions(-) create mode 100644 hypr/ntfy.png create mode 100755 hypr/ntfy_sub create mode 120000 systemd/user/graphical-session-pre.target.wants/xdg-user-dirs.service create mode 100644 systemd/user/monitor-battery.service create mode 100644 systemd/user/ntfy_sub.service create mode 100644 systemd/user/set-background@.service create mode 100644 systemd/user/theme.service create mode 100644 systemd/user/workspace.service diff --git a/.gitignore b/.gitignore index 54497c2..ff0ac5d 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,6 @@ zoom* systemd sunshine uad +intelephense +rustdesk +ristretto diff --git a/env.example b/env.example index 2235abd..17aaf86 100644 --- a/env.example +++ b/env.example @@ -40,3 +40,13 @@ matrix_creds() { MX_TOKEN= MX_URL= } + +navidrome_creds() { + # unload + [ "$1" = "unload" ] && unset ND_USER ND_PASS ND_URL && return 0 + + # load + ND_USER= + ND_PASS= + ND_URL= +} diff --git a/hypr/battery b/hypr/battery index 1df0f7e..a7f5da5 100755 --- a/hypr/battery +++ b/hypr/battery @@ -1,7 +1,7 @@ #!/bin/sh notify() { - notify-send -e -i "$icon_dir/$1" -h "string:x-canonical-private-synchronous:${0##*/}" "$2" -u "${3:-normal}" + notify-send -e -t 5000 -i "${icon_dir}${1}" -h "string:x-canonical-private-synchronous:${0##*/}" "$2" -u "${3:-normal}" } print_sleep() { @@ -9,36 +9,54 @@ print_sleep() { sleep "$1" } +switch_to_ac_mode() { + charge_icon=$(printf "%03d" "$((charge / 10))0") + hyprctl keyword monitor 'eDP-1',preferred,auto,1.5,bitdepth,10 + hyprctl keyword decoration:blur:enabled true + hyprctl keyword decoration:shadow:enabled true + notify "battery-$charge_icon-charging.svg" "AC Mode ($charge%, Charging)" + exit 0 +} + +switch_to_battery_mode() { + charge_icon=$(printf "%03d" "$((charge / 10))0") + hyprctl keyword monitor 'eDP-1',$battery_resolution,auto,1.5,bitdepth,10 + hyprctl keyword decoration:blur:enabled false + hyprctl keyword decoration:shadow:enabled false + notify "battery-$charge_icon.svg" "Battery Mode ($charge%, Discharging)" + exit 0 +} #declaration +dir="/sys/class/power_supply/" battery="BAT0" #change accordingly -dir="/sys/class/power_supply/$battery/" +battery_dir="${dir}${battery}/" icon_dir="/usr/share/icons/Papirus-Dark/22x22/panel/" #change accordingly i=0 status="normal" -charge=$(cat "$dir"/capacity) -power_status=$(cat "$dir"/status) +charge=$(cat "$battery_dir"/capacity) +battery_resolution="2880x1800@48" # widthxheight@refresh_rate case "$1" in - ac) - notify "battery-$(( charge / 10))0-charging.svg" "Power: AC Mode ($charge % $power_status)" - hyprctl keyword decoration:blur:enabled true - hyprctl keyword decoration:shadow:enabled true - exit 0 - ;; + ac) + switch_to_ac_mode + ;; - battery) - notify "battery-$(( charge / 10))0.svg" "Power: Battery Mode ($charge % $power_status)" - hyprctl keyword decoration:blur:enabled false - hyprctl keyword decoration:shadow:enabled false - exit 0 - ;; + battery) + switch_to_battery_mode + ;; + check) + if [ "$(cat "$dir/ADP1/online")" -eq 0 ]; then + switch_to_battery_mode + fi + exit 0 + ;; - *) ;; + *) ;; esac #infinite loop -while charge=$(cat "$dir"/capacity); do - if [ "$(cat "$dir"/status)" = "Charging" ]; then +while charge=$(cat "$battery_dir"/capacity); do + if [ "$(cat "$battery_dir"/status)" = "Charging" ]; then i=300 #default polling time, it's 5 minutes else case $charge in diff --git a/hypr/hyprland.conf b/hypr/hyprland.conf index 276d9b7..f975c3a 100644 --- a/hypr/hyprland.conf +++ b/hypr/hyprland.conf @@ -4,7 +4,7 @@ monitorv2 { mode = preferred position = auto scale = 1.5 - vrr = 2 + vrr = 1 bitdepth = 10 } @@ -294,10 +294,21 @@ workspace = special, on-created-empty:[float] foot #startup applications exec-once = systemctl --user import-environment DBUS_SESSION_BUS_ADDRESS WAYLAND_DISPLAY XDG_SESSION_TYPE XDG_CURRENT_DESKTOP XDG_SESSION_DESKTOP QT_QPA_PLATFORMTHEME GTK_THEME exec-once = dbus-update-activation-environment --systemd --all -exec-once = hypridle -exec-once = ssh-agent + +# misc +exec-once = systemctl --user start ssh-agent +exec-once = systemctl --user start ntfy_sub +exec-once = systemctl --user start workspace + +# hypr ecosystem exec-once = systemctl --user start hyprpolkitagent -exec-once = swaybg -i $HOME/.config/wall/1.png -m fill -exec-once = $hypr_dir/workspace focus -exec-once = $hypr_dir/battery -exec-once = $hypr_dir/themes +exec-once = systemctl --user start hypridle + +# power +exec-once = systemctl --user start power-mode@check +exec-once = systemctl --user start monitor-battery + +# UI +exec-once = systemctl --user start theme +exec-once = systemctl --user start set-background@1.png + diff --git a/hypr/hyprlock.conf b/hypr/hyprlock.conf index dd2bd80..08f0c7a 100644 --- a/hypr/hyprlock.conf +++ b/hypr/hyprlock.conf @@ -48,7 +48,6 @@ input-field { check_color = rgb(204, 136, 34) fail_color = rgb(204, 34, 34) fail_text = $FAIL ($ATTEMPTS) - fail_transition = 300 capslock_color = -1 numlock_color = -1 bothlock_color = -1 diff --git a/hypr/ntfy.png b/hypr/ntfy.png new file mode 100644 index 0000000000000000000000000000000000000000..6b969a846efc6c3dac70510793c72253e04389c9 GIT binary patch literal 3627 zcmV+`4%G39P)XbFClKy8~u8T@K#2U}z9I9j!6Ye%LtbjEg| z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Z9RYl$C0IQBDzw%%ptZIE)#X#&=x*F19*_4w z^UO1Yknc?lZfp7G21+m{>qyPCDzw%%qOGHRYi%PMW?b&v`w56xEH}_Q4L#(>3x&Tv6@p`@U3gGL6hhZ4;p`oF_x3#rBcJ%1c5VB;@8$>I`UPVgg zjNIe#)VlAl5qH_6-QC@R0d zJ3KtR=c%Wj+VJ$#PxnJk(*zmBcnAI6t@Ie<+?FRpw?+YALP{VIm;-VFMd^)U#KPh5 zXG23nyI*?gr9Z7+z4}wg3nbN+AH;Zvjuh2j&fn$IlG4=Fv_#pvVHojvynke5V-MV!V$iF8Am}dl? zA-TwysO0cl`dA4aDGbSlWts?{ko1DnOf$@gm}n(S1=YALk5yH^_y8uj*V8|~!brQS zegfv1F;U5&$ZMQtr^GbqjQdl~e!C=07Gi8ecgoAZFG~Lab)XNhRb$I{)002ovPDHLkV1hiF+kOB5 literal 0 HcmV?d00001 diff --git a/hypr/ntfy_sub b/hypr/ntfy_sub new file mode 100755 index 0000000..25d715c --- /dev/null +++ b/hypr/ntfy_sub @@ -0,0 +1,24 @@ +#!/bin/sh + +notify () { + notify-send -i "$icon_path" -e -h "string:x-canonical-private-synchronous:${0##*/}" "[$1] ${2}" "$3" +} + +env_file="${XDG_CONFIG_HOME:-$HOME/.config}/.env" +. "$env_file" + +ntfy_creds load + +token="$(printf 'Basic %s' "$(printf ':%s' "$NTFY_TOKEN" | base64)" | base64 | tr -d '=')" +icon_path="$(dirname "$0")/ntfy.png" + +trap "ntfy_creds unload" EXIT +trap "ntfy_creds unload; exit 1" INT HUP + +websocat --no-close "wss://${NTFY_URL#https://}/$NTFY_TOPIC_LISTEN/ws?auth=$token" | while IFS= read -r line; do + title=$(printf '%s' "$line" | sed -nE 's|.*,"title":"([^"]*)",.*|\1|p') + topic=$(printf '%s' "$line" | sed -nE 's|.*,"topic":"([^"]*)",?.*|\1|p') + message=$(printf '%s' "$line" | sed -nE 's|.*,"message":"([^"]*)",.*|\1|p') + printf '%s' "$line" | grep -q '"open"' && notify "NTFY" "Listening" "$topic" + [ -z "$message" ] || notify "$topic" "${title:-NO TITLE}" "$message" +done diff --git a/hypr/virt-monitor b/hypr/virt-monitor index 72f6947..170c706 100755 --- a/hypr/virt-monitor +++ b/hypr/virt-monitor @@ -19,7 +19,7 @@ load() { ip r # start sunshine - sunshine > /dev/null + sunshine >/dev/null } unload() { diff --git a/hypr/workspace b/hypr/workspace index c47c36b..3e9df0e 100755 --- a/hypr/workspace +++ b/hypr/workspace @@ -46,7 +46,7 @@ case $1 in ;; focus) #shows the workspace number as notification whenever u switch workspaces and also handles the dual monitor setup on the fly(perfect for laptop users) - socat - "UNIX-CONNECT:$XDG_RUNTIME_DIR/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock" | while read -r line; do + socat -u "UNIX-CONNECT:$XDG_RUNTIME_DIR/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock" - | while read -r line; do printf "%s" "$line" | grep -qE "monitoraddedv2.*HEADLESS" && continue printf "%s" "$line" | grep -q "monitoraddedv2" && handle_it "$line" #recent workspace switcher diff --git a/mimeapps.list b/mimeapps.list index 72915d0..93f119d 100644 --- a/mimeapps.list +++ b/mimeapps.list @@ -1,14 +1,14 @@ [Default Applications] inode/directory=pcmanfm.desktop -image/jpeg=nsxiv.desktop +image/jpeg=org.xfce.ristretto.desktop application/pdf=firefox.desktop text/html=firefox.desktop x-scheme-handler/http=firefox.desktop x-scheme-handler/https=firefox.desktop x-scheme-handler/about=firefox.desktop x-scheme-handler/unknown=firefox.desktop -image/png=nsxiv.desktop -image/webp=nsxiv.desktop +image/png=org.xfce.ristretto.desktop +image/webp=org.xfce.ristretto.desktop plain/text=nvim.desktop text/x-python=nvim.desktop text/english=nvim.deskop @@ -41,10 +41,11 @@ application/x-bittorrent=torrent.desktop x-scheme-handler/magnet=torrent.desktop hoppscotch=hoppscotch-handler.desktop audio/flac=mpv.desktop +application/octet-stream=nvim.desktop [Added Associations] video/x-matroska=mpv.desktop; -application/octet-stream=mpv.desktop;firefox.desktop; +application/octet-stream=nvim.desktop;mpv.desktop;firefox.desktop; video/vnd.radgamettools.bink=mpv.desktop; x-scheme-handler/mailto=firefox.desktop; x-scheme-handler/http=firefox.desktop diff --git a/nvim/lazy-lock.json b/nvim/lazy-lock.json index 37bffbd..0295949 100644 --- a/nvim/lazy-lock.json +++ b/nvim/lazy-lock.json @@ -1,5 +1,5 @@ { - "LuaSnip": { "branch": "master", "commit": "a62e1083a3cfe8b6b206e7d3d33a51091df25357" }, + "LuaSnip": { "branch": "master", "commit": "0abc8f390b278c3b4aabc4c004ac8a088b65cf24" }, "cmp-buffer": { "branch": "main", "commit": "b74fab3656eea9de20a9b8116afa3cfc4ec09657" }, "cmp-cmdline": { "branch": "main", "commit": "d126061b624e0af6c3a556428712dd4d4194ec6d" }, "cmp-nvim-lsp": { "branch": "main", "commit": "cbc7b02bb99fae35cb42f514762b89b5126651ef" }, @@ -9,18 +9,18 @@ "friendly-snippets": { "branch": "main", "commit": "6cd7280adead7f586db6fccbd15d2cac7e2188b9" }, "lazy.nvim": { "branch": "main", "commit": "306a05526ada86a7b30af95c5cc81ffba93fef97" }, "lualine.nvim": { "branch": "master", "commit": "131a558e13f9f28b15cd235557150ccb23f89286" }, - "mason-lspconfig.nvim": { "branch": "main", "commit": "0c2823e0418f3d9230ff8b201c976e84de1cb401" }, - "mason.nvim": { "branch": "main", "commit": "cb8445f8ce85d957416c106b780efd51c6298f89" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "7b01e2974a47d489bb92f47a41e4c0088ea8f86e" }, + "mason.nvim": { "branch": "main", "commit": "cbf8d285e1462dd24acf3507817be2bbcb035919" }, "monokai-pro.nvim": { "branch": "main", "commit": "8ba1fea7774e7c522b006091a9adb32b5cef95b9" }, - "nvim-autopairs": { "branch": "master", "commit": "59bce2eef357189c3305e25bc6dd2d138c1683f5" }, + "nvim-autopairs": { "branch": "master", "commit": "7b9923abad60b903ece7c52940e1321d39eccc79" }, "nvim-cmp": { "branch": "main", "commit": "a1d504892f2bc56c2e79b65c6faded2fd21f3eca" }, "nvim-colorizer.lua": { "branch": "master", "commit": "a065833f35a3a7cc3ef137ac88b5381da2ba302e" }, - "nvim-dap": { "branch": "master", "commit": "45a69eba683a2c448dd9ecfc4de89511f0646b5f" }, + "nvim-dap": { "branch": "master", "commit": "531771530d4f82ad2d21e436e3cc052d68d7aebb" }, "nvim-dap-python": { "branch": "master", "commit": "1808458eba2b18f178f990e01376941a42c7f93b" }, - "nvim-lspconfig": { "branch": "master", "commit": "31026a13eefb20681124706a79fc1df6bf11ab27" }, + "nvim-lspconfig": { "branch": "master", "commit": "deb0df61b2d6691e745b16a42755e10ad38218e9" }, "nvim-parinfer": { "branch": "master", "commit": "3968e669d9f02589aa311d33cb475b16b27c5fbb" }, "nvim-treesitter": { "branch": "master", "commit": "cf12346a3414fa1b06af75c79faebe7f76df080a" }, "packer.nvim": { "branch": "master", "commit": "ea0cc3c59f67c440c5ff0bbe4fb9420f4350b9a3" }, "plenary.nvim": { "branch": "master", "commit": "74b06c6c75e4eeb3108ec01852001636d85a932b" }, - "telescope.nvim": { "branch": "master", "commit": "ec009610d5d259ec59a6edf0219ef3f7ee4732e5" } + "telescope.nvim": { "branch": "master", "commit": "7d324792b7943e4aa16ad007212e6acc6f9fe335" } } diff --git a/systemd/user/graphical-session-pre.target.wants/xdg-user-dirs.service b/systemd/user/graphical-session-pre.target.wants/xdg-user-dirs.service new file mode 120000 index 0000000..457b4d4 --- /dev/null +++ b/systemd/user/graphical-session-pre.target.wants/xdg-user-dirs.service @@ -0,0 +1 @@ +/usr/lib/systemd/user/xdg-user-dirs.service \ No newline at end of file diff --git a/systemd/user/monitor-battery.service b/systemd/user/monitor-battery.service new file mode 100644 index 0000000..e2bf7c7 --- /dev/null +++ b/systemd/user/monitor-battery.service @@ -0,0 +1,9 @@ +[Unit] +Description=Monitors the battery Power and State. + +[Service] +Type=simple +ExecStart=%h/.config/hypr/battery +Restart=on-failure +RestartSec=5 + diff --git a/systemd/user/ntfy_sub.service b/systemd/user/ntfy_sub.service new file mode 100644 index 0000000..731225c --- /dev/null +++ b/systemd/user/ntfy_sub.service @@ -0,0 +1,8 @@ +[Unit] +Description=Ntfy Subscribe Notifications + +[Service] +Type=simple +ExecStart=%h/.config/hypr/ntfy_sub +Restart=on-failure +RestartSec=5 diff --git a/systemd/user/power-mode@.service b/systemd/user/power-mode@.service index 2889e23..7c820f2 100644 --- a/systemd/user/power-mode@.service +++ b/systemd/user/power-mode@.service @@ -3,4 +3,4 @@ Description=Power Mode (%i) [Service] Type=oneshot -ExecStart=/home/tanveer/.config/hypr/battery %i +ExecStart=%h/.config/hypr/battery %i diff --git a/systemd/user/set-background@.service b/systemd/user/set-background@.service new file mode 100644 index 0000000..490c187 --- /dev/null +++ b/systemd/user/set-background@.service @@ -0,0 +1,8 @@ +[Unit] +Description=Set Background (%i) + +[Service] +Type=simple +ExecStartPre=-/usr/bin/pkill -x swaybg +ExecStart=/usr/sbin/swaybg -i %h/.config/wall/%i -m fill +Restart=on-failure diff --git a/systemd/user/theme.service b/systemd/user/theme.service new file mode 100644 index 0000000..096230d --- /dev/null +++ b/systemd/user/theme.service @@ -0,0 +1,6 @@ +[Unit] +Description=Set GTK Theme + +[Service] +Type=oneshot +ExecStart=%h/.config/hypr/themes diff --git a/systemd/user/workspace.service b/systemd/user/workspace.service new file mode 100644 index 0000000..b6e4170 --- /dev/null +++ b/systemd/user/workspace.service @@ -0,0 +1,9 @@ +[Unit] +Description=Monitors current Workspace + +[Service] +Type=simple +ExecStart=%h/.config/hypr/workspace focus +Restart=on-failure +RestartSec=5 +