refactor(hypr): overhaul some scripts to use systemd-run

This commit is contained in:
Price Hiller 2024-02-19 01:04:29 -06:00
parent 2a180b9cd7
commit 529e913d40
Signed by: Price
GPG Key ID: C3FADDE7A8534BEB
3 changed files with 31 additions and 10 deletions

View File

@ -4,14 +4,13 @@ source = ~/.config/hypr/wm/bindings.conf
source = ~/.config/hypr/wm/appearance.conf
source = ~/.config/hypr/wm/monitors.conf
source = ~/.config/hypr/wm/window-rules.conf
exec-once = ~/.config/hypr/scripts/launchers/events-monitor.bash
exec-once = ~/.config/hypr/scripts/launchers/launch-swww.bash
exec-once = mako --history 1
exec-once = udiskie --tray
exec-once = blueman-applet
exec-once = slimbookbattery --minimize
exec = clight-gui --tray
exec = systemd-run --user -u wallpaper-manager ~/.config/hypr/scripts/init-wallpapers.bash || systemctl --user restart wallpaper-manager
exec = systemd-run --user --unit=events-monitor ~/.config/hypr/scripts/launchers/events-monitor.bash || systemctl --user restart events-monitor
exec = systemd-run --user --unit=wallpapers ~/.config/hypr/scripts/launchers/launch-swww.bash || systemctl --user restart wallpapers
exec-once = xwaylandvideobridge
exec-once = systemctl --user import-environment WAYLAND_DISPLAY XDG_CURRENT_DESKTOP PATH
exec-once = /usr/lib/polkit-kde-authentication-agent-1

View File

@ -1,5 +1,11 @@
#!/usr/bin/env bash
log() {
local monitor="${1}"
local msg="${2}"
printf "%s: %s\n" "${monitor}" "${msg}"
}
monitor-dir() {
local event="${1}"
local directory="${2}"
@ -20,8 +26,10 @@ monitor-ssid() {
ssid="$(printf "%s" "${ssid}" | xargs)"
if [[ "${ssid}" != "${previous_ssid}" ]]; then
if [[ -z "${ssid// /}" ]]; then
log "SSID" "Wifi Disconnected"
notify-send "${notify_title}" "Wifi Disconnected" -a "${notify_app}"
else
log "SSID" "Wifi Connected to ${ssid}"
notify-send "${notify_title}" "Wifi Connected to ${ssid}" -a "${notify_app}"
fi
previous_ssid="${ssid}"
@ -39,14 +47,22 @@ monitor-laptop-lid() {
case "${laptop_lid_state}" in
"CLOSED")
if hyprctl monitors -j | jq -er '.[] | select(.name=="eDP-1") | .name' >/dev/null; then
hyprctl keyword monitor "eDP-1, disable" >/dev/null && printf "Disabled laptop screen as the laptop was shut\n"
printf "Laptop screen was shut, attempting to disable it...\n"
if hyprctl keyword monitor "eDP-1, disable"; then
local msg="Laptop screen successfully disabled"
log "Laptop Clamshell" "${msg}"
notify-send "Laptop Clamshell Error" "${msg}" -a "Laptop Clamshell"
else
local msg="Received an error when disabling the laptop screen in clamshell mode!\n"
log "Laptop Clamshell" "${msg}"
notify-send "Laptop Clamshell Error" "${msg}" -a "Laptop Clamshell"
fi
fi
;;
esac
sleep 1
done
}
kill -9 "$(pgrep -f "${BASH_SOURCE[0]}" | grep -v "${$}")"
monitor-ssid &
monitor-laptop-lid &
wait

View File

@ -2,7 +2,7 @@
log() {
printf "%s\n" "${*}"
systemd-cat -t init-wallpapers -p info echo "${*}"
systemd-cat -t wallpaper -p info echo "${*}"
}
get-monitor-wallpaper() {
@ -23,8 +23,11 @@ set-wallpaper() {
}
set-wallpapers() {
log "Setting wallpapers"
### Set default wallpaper ###
local default_wallpaper="${HOME}/.dot_files/dots/.local/share/wallpapers/Nebula.jpg"
local wallpapers_dir
wallpapers_dir="$(realpath "${XDG_DATA_HOME}/wallpapers")"
local default_wallpaper="${wallpapers_dir}/Nebula.jpg"
# Monitors to not set a default for, to be set later down the script
local excluded_monitors=("eDP-1")
@ -38,16 +41,18 @@ set-wallpapers() {
break
fi
done
if "${set_mon_wallpaper}"; then
if ${set_mon_wallpaper}; then
set-wallpaper "${monitor}" "${default_wallpaper}"
fi
done < <(hyprctl monitors -j | jq -r '.[].name')
### Set any non defaults ###
set-wallpaper "eDP-1" "${HOME}/.dot_files/dots/.local/share/wallpapers/Industrial-Shaded.png"
set-wallpaper "eDP-1" "${wallpapers_dir}/Industrial-Shaded.png"
}
init() {
log "Killing existing swww daemon if an swww daemon is running"
swww kill >/dev/null || true
until swww init; do
sleep .1
done
@ -55,7 +60,9 @@ init() {
}
main() {
log "Starting up swww!"
init
while :; do
while IFS= read -r line
do
@ -65,7 +72,6 @@ main() {
sleep .1
done < <(swww query)
sleep .5
init
done
}