Refactor toggles and notifications

This commit is contained in:
David Heinemeier Hansson
2026-05-10 11:26:59 +02:00
parent d3a082ef11
commit 26c1f9c546
7 changed files with 126 additions and 80 deletions
+22 -12
View File
@@ -10,34 +10,44 @@ MIRROR_TOGGLE="internal-monitor-mirror"
# Get internal monitor name dynamically
INTERNAL=$(hyprctl monitors -j | jq -r '.[] | select(.name | contains("eDP")).name' | head -n 1)
enable() {
if omarchy-hyprland-toggle-enabled "$TOGGLE"; then
omarchy-hyprland-toggle --disabled-notification "󰍹 Laptop display enabled" "$TOGGLE"
on() {
if omarchy-hyprland-toggle-enabled $TOGGLE; then
omarchy-hyprland-toggle $TOGGLE off
omarchy-notification-send -g 󰍹 "Laptop display enabled"
fi
}
disable() {
off() {
if ! omarchy-hw-external-monitors; then
notify-send -u low "󰍹 Can't disable the only active display"
omarchy-notification-send -g 󰍹 "Can't disable the only active display"
exit 1
fi
if omarchy-hyprland-toggle-disabled "$TOGGLE" && omarchy-hyprland-toggle-disabled "$MIRROR_TOGGLE"; then
if omarchy-hyprland-toggle-disabled $TOGGLE && omarchy-hyprland-toggle-disabled $MIRROR_TOGGLE; then
echo "monitor=$INTERNAL,disable" >"$TOGGLE_FLAG"
notify-send -u low "󰍹 Laptop display disabled"
omarchy-notification-send -g 󰍹 "Laptop display disabled"
hyprctl reload
fi
}
recover() {
if ! omarchy-hw-external-monitors && omarchy-hyprland-toggle-enabled "$TOGGLE"; then
omarchy-hyprland-toggle "$TOGGLE"
if ! omarchy-hw-external-monitors; then
omarchy-hyprland-toggle $TOGGLE off
fi
}
toggle() {
if omarchy-hyprland-toggle-enabled $TOGGLE; then
on
else
off
fi
}
case "$1" in
on) enable ;;
off) disable ;;
toggle) if omarchy-hyprland-toggle-enabled "$TOGGLE"; then enable; else disable; fi ;;
on) on ;;
off) off ;;
toggle) toggle ;;
recover) recover ;;
*)
echo "Usage: $(basename "$0") {on|off|toggle|recover}" >&2
+24 -20
View File
@@ -12,44 +12,48 @@ INTERNAL=$(hyprctl monitors -j | jq -r '.[] | select(.name | contains("eDP")).na
# Get the first available external monitor
EXTERNAL=$(hyprctl monitors -j | jq -r '.[] | select(.name | contains("eDP") | not).name' | head -n 1)
enable() {
if [[ -z "$EXTERNAL" ]]; then
notify-send -u low "󰍹 No external monitors found for mirror"
on() {
if [[ -z $EXTERNAL ]]; then
omarchy-notification-send -g 󰍹 "No external monitors found for mirror"
exit 1
fi
if [[ -z "$INTERNAL" ]]; then
notify-send -u low "󰍹 No laptop monitor found to mirror"
if [[ -z $INTERNAL ]]; then
omarchy-notification-send -g 󰍹 "No laptop monitor found to mirror"
exit 1
fi
if omarchy-hyprland-toggle-enabled "$DISABLE_TOGGLE"; then
omarchy-hyprland-toggle "$DISABLE_TOGGLE"
fi
omarchy-hyprland-toggle $DISABLE_TOGGLE off
echo "monitor=$EXTERNAL, preferred, auto, 1, mirror, $INTERNAL" >"$TOGGLE_FLAG"
omarchy-notification-send -g 󰍹 "Mirroring enabled ($EXTERNAL)"
hyprctl reload
}
if omarchy-hyprland-toggle-disabled "$TOGGLE"; then
echo "monitor=$EXTERNAL, preferred, auto, 1, mirror, $INTERNAL" > "$TOGGLE_FLAG"
notify-send -u low "󰍹 Mirroring enabled ($EXTERNAL)"
hyprctl reload
off() {
if omarchy-hyprland-toggle-enabled $TOGGLE; then
omarchy-hyprland-toggle $TOGGLE off
omarchy-notification-send -g 󰍹 "Extended mode restored"
fi
}
disable() {
if omarchy-hyprland-toggle-enabled "$TOGGLE"; then
omarchy-hyprland-toggle --disabled-notification "󰍹 Extended mode restored" "$TOGGLE"
toggle() {
if omarchy-hyprland-toggle-enabled $TOGGLE; then
off
else
on
fi
}
recover() {
if ! omarchy-hw-external-monitors && omarchy-hyprland-toggle-enabled "$TOGGLE"; then
omarchy-hyprland-toggle "$TOGGLE"
if ! omarchy-hw-external-monitors; then
omarchy-hyprland-toggle $TOGGLE off
fi
}
case "$1" in
on) enable ;;
off) disable ;;
toggle) if omarchy-hyprland-toggle-enabled "$TOGGLE"; then disable; else enable; fi ;;
on) on ;;
off) off ;;
toggle) toggle ;;
recover) recover ;;
*)
echo "Usage: $(basename "$0") {on|off|toggle|recover}" >&2
+36 -23
View File
@@ -1,32 +1,45 @@
#!/bin/bash
# omarchy:summary=Toggle permanent Hyprland flags by copying them into a directory that's sourced entirely.
# omarchy:args=[--enabled-notification <text>] [--disabled-notification <text>] <flag-name>
ENABLED_NOTIFICATION=""
DISABLED_NOTIFICATION=""
while [[ $# -gt 1 ]]; do
case $1 in
--enabled-notification) ENABLED_NOTIFICATION="$2"; shift 2 ;;
--disabled-notification) DISABLED_NOTIFICATION="$2"; shift 2 ;;
*) break ;;
esac
done
# omarchy:args=<flag-name> [on|off]
FLAG_NAME="$1"
ACTION="${2:-toggle}"
FLAG="$HOME/.local/state/omarchy/toggles/hypr/$FLAG_NAME.conf"
FLAG_SOURCE="$OMARCHY_PATH/default/hypr/toggles/$FLAG_NAME.conf"
if [[ -f $FLAG ]]; then
rm $FLAG
[[ -n $DISABLED_NOTIFICATION ]] && notify-send -u low "$DISABLED_NOTIFICATION"
elif [[ -f $FLAG_SOURCE ]]; then
cp $FLAG_SOURCE $FLAG
[[ -n $ENABLED_NOTIFICATION ]] && notify-send -u low "$ENABLED_NOTIFICATION"
else
echo "Flag not found: $FLAG_NAME"
exit 1
fi
on() {
if [[ -f $FLAG_SOURCE ]]; then
mkdir -p "$(dirname "$FLAG")"
cp "$FLAG_SOURCE" "$FLAG"
echo "on"
else
echo "Flag not found: $FLAG_NAME"
exit 1
fi
}
hyprctl reload
off() {
rm -f "$FLAG"
echo "off"
}
toggle() {
if [[ -f $FLAG ]]; then
off
else
on
fi
}
case $ACTION in
on) on ;;
off) off ;;
toggle) toggle ;;
*)
echo "Usage: omarchy-hyprland-toggle <flag-name> [on|off]"
exit 1
;;
esac
hyprctl reload >/dev/null
@@ -2,7 +2,7 @@
# omarchy:summary=Toggle single-window square aspect ratio.
omarchy-hyprland-toggle \
--enabled-notification "Enable single-window square aspect ratio" \
--disabled-notification "Disable single-window square aspect ratio" \
single-window-aspect-ratio
case $(omarchy-hyprland-toggle single-window-aspect-ratio) in
on) omarchy-notification-send -g  "Enable single-window square aspect ratio" ;;
off) omarchy-notification-send -g  "Disable single-window square aspect ratio" ;;
esac
+32 -13
View File
@@ -1,32 +1,51 @@
#!/bin/bash
# omarchy:summary=Send a desktop notification with Omarchy glyph and body spacing
# omarchy:args=<glyph> <headline> [description] [notify-send options]
# omarchy:examples=omarchy notification send "󰔛" "Reminder" "5 minutes are up" -u critical
# omarchy:args=<headline> [description] [-g <glyph>] [-u <low|normal|critical>] [notify-send options]
# omarchy:examples=omarchy notification send "Reminder" "5 minutes are up" -g 󰔛 -u critical
set -euo pipefail
if (($# < 2)); then
echo "Usage: omarchy-notification-send <glyph> <headline> [description] [notify-send options]"
if (($# < 1)); then
echo "Usage: omarchy-notification-send <headline> [description] [-g <glyph>] [-u <low|normal|critical>] [notify-send options]"
exit 1
fi
glyph=$1
headline=$2
description=${3:-}
shift 2
headline=$1
description=""
glyph=""
urgency="low"
args=()
shift
if (($# > 0)) && [[ $1 != -* ]]; then
description=$1
shift
else
description=""
fi
while (($# > 0)); do
case $1 in
-g|--glyph)
glyph="$2"
shift 2
;;
-u|--urgency)
urgency="$2"
shift 2
;;
*)
args+=("$1")
shift
;;
esac
done
summary="$glyph $headline"
args+=("-u" "$urgency")
if [[ -n $description ]]; then
description=$(sed 's/^/ /' <<<"$description")
notify-send "$@" "$summary" "$description"
description=$(printf '%b' "$description" | sed 's/^/ /')
notify-send "${args[@]}" "$summary" "$description"
else
notify-send "$@" "$summary"
notify-send "${args[@]}" "$summary"
fi
+5 -5
View File
@@ -68,9 +68,9 @@ show_reminders() {
done < <(systemctl --user list-timers --all --output=json "omarchy-reminder-*.timer" 2>/dev/null | jq -r '.[] | [.unit, .next] | @tsv')
if [[ -z $body ]]; then
omarchy-notification-send "󰔛" "Upcoming reminders" "No outstanding reminders" -u low
omarchy-notification-send -g 󰔛 "Upcoming reminders" "No outstanding reminders"
else
omarchy-notification-send "󰔛" "Upcoming reminders" "${body%$'\n'}" -u low
omarchy-notification-send -g 󰔛 "Upcoming reminders" "${body%$'\n'}"
fi
}
@@ -85,7 +85,7 @@ clear_reminders() {
fi
rm -f "$reminder_dir"/omarchy-reminder-*.message 2>/dev/null || true
omarchy-notification-send "󰔛" "All reminders have been cleared" -u low
omarchy-notification-send -g 󰔛 "All reminders have been cleared"
}
case ${1:-} in
@@ -131,6 +131,6 @@ if [[ -n $custom_message ]]; then
fi
systemd-run --user --quiet --collect --on-active="${minutes}m" --unit="$unit" \
bash -c 'omarchy-notification-send "󰔛" "Reminder" "$1" -u critical; rm -f "$2"' bash "$message" "$message_file"
bash -c 'omarchy-notification-send -g 󰔛 "Reminder" "$1" -u critical; rm -f "$2"' bash "$message" "$message_file"
omarchy-notification-send "󰔛" "$confirmation_title" "$confirmation" -u low
omarchy-notification-send -g 󰔛 "$confirmation_title" "$confirmation"
+3 -3
View File
@@ -193,14 +193,14 @@ main() {
output=$(output_path "$input" "$format" "$resolution")
if [[ $type == "video" ]]; then
omarchy-notification-send "" "Transcoding video…" "$(basename -- "$input") to $format ($resolution)"
omarchy-notification-send -g  "Transcoding video…" "$(basename -- "$input") to $format ($resolution)"
transcode_video "$input" "$format" "$resolution" "$output"
copy_to_clipboard "$output"
omarchy-notification-send "" "Transcoded to $resolution $format" "Saved and copied to clipboard."
omarchy-notification-send -g  "Transcoded to $resolution $format" "Saved and copied to clipboard."
else
transcode_picture "$input" "$format" "$resolution" "$output"
copy_to_clipboard "$output"
omarchy-notification-send "" "Transcoded to $resolution $format" "Saved and copied to clipboard."
omarchy-notification-send -g  "Transcoded to $resolution $format" "Saved and copied to clipboard."
fi
}