#!/bin/bash # blob:summary=Enable, disable, toggle, or recover the internal laptop display # blob:args= TOGGLE="internal-monitor-disable" TOGGLE_FLAG="$HOME/.local/state/blob/toggles/hypr/$TOGGLE.lua" MIRROR_TOGGLE="internal-monitor-mirror" INTERNAL=$(blob-hypr-monitor-laptop) wake() { hyprctl dispatch 'hl.dsp.dpms({ action = "enable" })' >/dev/null 2>&1 || true } on() { if blob-hypr-toggle-enabled $TOGGLE; then blob-hypr-toggle $TOGGLE off blob-notify-send -g 󰍹 "Laptop display enabled" fi wake } off() { if [[ -z $INTERNAL ]]; then blob-notify-send -g 󰍹 "No laptop display found" exit 1 fi # The name is written into generated Lua below, so only a plain connector # name may pass; anything else could execute on the next reload. if [[ ! $INTERNAL =~ ^[A-Za-z0-9._-]+$ ]]; then blob-notify-send -g 󰍹 "Refusing unsafe monitor name" exit 1 fi if ! blob-hypr-monitor-external; then blob-notify-send -g 󰍹 "Can't disable the only active display" exit 1 fi if blob-hypr-toggle-disabled $TOGGLE && blob-hypr-toggle-disabled $MIRROR_TOGGLE; then printf 'hl.monitor({ output = "%s", disabled = true })\n' "$INTERNAL" >"$TOGGLE_FLAG" blob-notify-send -g 󰍹 "Laptop display disabled" hyprctl reload fi } recover() { # Runs from the clamshell watcher every few seconds, so it must be a no-op # unless it actually re-enables a display: an unconditional wake here undoes # lock-screen blanking and races the resume modeset into a visible flash. blob-hypr-monitor-external && return 0 blob-hypr-toggle-enabled $TOGGLE || return 0 blob-hypr-toggle $TOGGLE off wake } toggle() { if blob-hypr-toggle-enabled $TOGGLE; then on else off fi } case "$1" in on) on ;; off) off ;; toggle) toggle ;; recover) recover ;; *) echo "Usage: $(basename "$0") {on|off|toggle|recover}" >&2 exit 1 ;; esac