diff --git a/users/price/dots/.config/hypr/conf/core/monitors.conf b/users/price/dots/.config/hypr/conf/core/monitors.conf index b1604a0c..a36e6d0b 100644 --- a/users/price/dots/.config/hypr/conf/core/monitors.conf +++ b/users/price/dots/.config/hypr/conf/core/monitors.conf @@ -1,4 +1,4 @@ monitor = ,preferred,auto,auto monitor=eDP-1,preferred,0x0,1.5 -bindl=,switch:off:Lid Switch,exec,brightnessctl s 50% -bindl=,switch:on:Lid Switch,exec,brightnessctl s 0% +bindl=,switch:off:Lid Switch,exec,systemd-run --user ~/.config/hypr/scripts/laptop-lid.bash +bindl=,switch:on:Lid Switch,exec,systemd-run --user ~/.config/hypr/scripts/laptop-lid.bash diff --git a/users/price/dots/.config/hypr/hyprland.conf b/users/price/dots/.config/hypr/hyprland.conf index f0d69527..bc747c54 100644 --- a/users/price/dots/.config/hypr/hyprland.conf +++ b/users/price/dots/.config/hypr/hyprland.conf @@ -4,9 +4,9 @@ exec = systemd-run --user --unit=udiskie udiskie --tray || systemctl --user rest exec = systemd-run --user --unit=blueman-applet blueman-applet || systemctl --user restart blueman-applet exec = systemd-run --user --unit=slimbookbattery slimbookbattery --minimize || systemctl --user restart slimbookbattery exec = systemd-run --user --unit=clight-gui clight-gui --tray || systemctl --user restart clight-gui -exec = systemd-run --user --unit=events-monitor ~/.config/hypr/scripts/launchers/events-monitor.bash || systemctl --user restart events-monitor +exec = systemd-run --user --unit=monitor-ssid ~/.config/hypr/scripts/monitor-ssid.bash || systemctl --user restart monitor-ssid exec = systemd-run --user --unit=xwaylandvideobridge xwaylandvideobridge || systemctl --user restart xwaylandvideobridge exec = systemd-run --user --unit=polkit-agent /usr/lib/polkit-gnome/polkit-gnome-authentication-agent-1 || systemctl --user restart polkit-agent exec-once = systemctl --user import-environment WAYLAND_DISPLAY XDG_CURRENT_DESKTOP PATH exec = sleep 1 && systemctl --user restart compositor.target -exec-once = swaylock \ No newline at end of file +exec-once = swaylock diff --git a/users/price/dots/.config/hypr/scripts/laptop-lid.bash b/users/price/dots/.config/hypr/scripts/laptop-lid.bash new file mode 100644 index 00000000..b5ecbf5c --- /dev/null +++ b/users/price/dots/.config/hypr/scripts/laptop-lid.bash @@ -0,0 +1,76 @@ +#!/usr/bin/env bash + +set -eEuo pipefail + +log() { + local syslog_id="laptop-lid" + local title="Laptop Clamshell" + local level="INFO" + local args="${*}" + if (($# > 1)); then + local level="${1}" + shift + fi + local msg="${*}" + case "${level^^}" in + "TRACE") + systemd-cat -t "$syslog_id" -p "debug" <<<"$msg" + logger --stderr -p "user.debug" "$syslog_id" "$msg" + ;; + "INFO") + systemd-cat -t "$syslog_id" -p "notice" <<<"$msg" + notify-send "$title" "$msg" -a "$title" + ;; + "ERROR") + systemd-cat -t "$syslog_id" -p "error" <<<"$msg" + notify-send "$title" "$msg" -a "$title" -u "critical" + ;; + *) + systemd-cat -t "$syslog_id" -p "error" <<-__EOS__ + Invalid log level passed! + + Received input as: '${args}' + __EOS__ + return 1 + ;; + esac +} + +handle-laptop-lid() { + local laptop_lid_state + local laptop_mon="${1:-"eDP-1"}" + local laptop_lid_acpi_path="${2:-"/proc/acpi/button/lid/LID0/state"}" + if [[ ! -r "$laptop_lid_acpi_path" ]]; then + log "ERROR" "Unable to read laptop state from ACPI path: '${laptop_lid_acpi_path}'" + return 1 + fi + log "TRACE" "Checking monitor laptop lid state at: '${laptop_lid_acpi_path}'" + laptop_lid_state="$(/dev/null; then + log "TRACE" "Laptop lid is open, attempting to enable it..." + if hyprctl keyword monitor "${laptop_mon},enable" >/dev/null; then + log "Laptop screen enabled" + else + log "ERROR" "Received an error when enabling the laptop screen!" + fi + fi + ;; + "CLOSED") + if hyprctl monitors -j | jq -er '.[] | select(.name=="eDP-1")' >/dev/null; then + log "TRACE" "Laptop lid is shut, attempting to disable it..." + if hyprctl keyword monitor "${laptop_mon},disable" >/dev/null; then + log "Laptop screen disabled" + else + log "ERROR" "Received an error when disabling the laptop screen in clamshell mode!" + fi + fi + ;; + esac +} + +handle-laptop-lid "${@}" diff --git a/users/price/dots/.config/hypr/scripts/launchers/events-monitor.bash b/users/price/dots/.config/hypr/scripts/launchers/events-monitor.bash deleted file mode 100755 index ab58227e..00000000 --- a/users/price/dots/.config/hypr/scripts/launchers/events-monitor.bash +++ /dev/null @@ -1,87 +0,0 @@ -#!/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}" - local message_title="${3}" - - inotifywait -m -e "${event}" --format '%w%f' "${directory}" | while read -r NEWFILE; do - notify-send "${message_title}" "${NEWFILE}" -a "Device Monitor" - done -} - -monitor-ssid() { - local notify_title="Wifi State Changed" - local notify_app="Wifi State" - local previous_ssid="" - local ssid - while :; do - ssid="$(iwctl station wlan0 show | grep 'Connected network' | awk '{print $3}')" - 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}" - fi - sleep 1 - done -} - -monitor-laptop-lid() { - local laptop_lid_state - local laptop_lid_last_state - while :; do - sleep 1 - laptop_lid_state="$(/dev/null; then - printf "Laptop screen was opened, attempting to enable it...\n" - if hyprctl dispatch dpms on eDP-1; then - laptop_lid_last_state="${laptop_lid_state}" - local msg="Laptop screen successfully enabled" - log "Laptop Clamshell" "${msg}" - notify-send "Laptop Clamshell" "${msg}" -a "Laptop Clamshell" - else - local msg="Received an error when enabling the laptop screen!\n" - log "Laptop Clamshell" "${msg}" - notify-send "Laptop Clamshell Error" "${msg}" -a "Laptop Clamshell" - fi - fi - ;; - "CLOSED") - if hyprctl monitors -j | jq -er '.[] | select(.name=="eDP-1") | .name' >/dev/null; then - printf "Laptop screen was shut, attempting to disable it...\n" - if hyprctl dispatch dpms off eDP-1; then - laptop_lid_last_state="${laptop_lid_state}" - local msg="Laptop screen successfully disabled" - log "Laptop Clamshell" "${msg}" - notify-send "Laptop Clamshell" "${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 - done -} -monitor-ssid & -wait diff --git a/users/price/dots/.config/hypr/scripts/monitor-ssid.bash b/users/price/dots/.config/hypr/scripts/monitor-ssid.bash new file mode 100644 index 00000000..9d0d100f --- /dev/null +++ b/users/price/dots/.config/hypr/scripts/monitor-ssid.bash @@ -0,0 +1,49 @@ +#!/usr/bin/env bash + +log() { + local title="Wifi State Changed" + local app="Wifi State" + local level="INFO" + if (($# > 1)); then + local level="${1}" + fi + local msg="${*}" + case "${level^^}" in + "TRACE") + printf "[TRACE] %s: %s\n" "$title" "$msg" + ;; + "INFO") + printf "[INFO] %s: %s\n" "$title" "$msg" + notify-send "$title" "$msg" -a "$app" + ;; + "ERROR") + printf "[ERROR] %s: %s\n" "$title" "$msg" + notify-send "$title" "$msg" -a "$app" -u "critical" + ;; + *) + printf "INVALID LOG LEVEL PASSED!\n" >&2 + return 1 + ;; + esac + printf "Laptop Clamshell: %s\n""$msg" +} + +monitor-ssid() { + local previous_ssid="" + local ssid + while :; do + ssid="$(iwctl station wlan0 show | grep 'Connected network' | awk '{print $3}')" + ssid="$(printf "%s" "$ssid" | xargs)" + if [[ "$ssid" != "$previous_ssid" ]]; then + if [[ -z "${ssid// /}" ]]; then + log "Wifi Disconnected" + else + log "Wifi Connected to ${ssid}" + fi + previous_ssid="$ssid" + fi + sleep 1 + done +} + +monitor-ssid