-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Add interactive screensaver & idle settings TUI (Setup → Config → Screensaver) #6086
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
acidkill
wants to merge
2
commits into
basecamp:dev
Choose a base branch
from
acidkill:feature/screensaver-config
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+209
−1
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,195 @@ | ||
| #!/bin/bash | ||
|
|
||
| # omarchy:summary=Configure idle behavior: screensaver, display blanking, and idle lock | ||
| # omarchy:group=config | ||
| # omarchy:name=screensaver | ||
|
|
||
| # Interactive editor for ~/.config/hypr/hypridle.conf. Lets you choose what happens | ||
| # when the session goes idle (animated screensaver, blank the displays, or nothing), | ||
| # how long to wait, and whether the session locks. Changes are written to the user | ||
| # config with a timestamped backup and applied by restarting hypridle. "Restore | ||
| # Omarchy defaults" reverts to the shipped config via omarchy-refresh-config. | ||
|
|
||
| HYPRIDLE_CONF="$HOME/.config/hypr/hypridle.conf" | ||
|
|
||
| read_settings() { | ||
| action=screensaver | ||
| idle=150 | ||
| lock=on | ||
| lockdelay=2 | ||
|
|
||
| [[ -f $HYPRIDLE_CONF ]] || return | ||
|
|
||
| mapfile -t timeouts < <(grep -oP 'timeout\s*=\s*\K[0-9]+' "$HYPRIDLE_CONF") | ||
|
|
||
| if grep -q "omarchy-launch-screensaver" "$HYPRIDLE_CONF"; then | ||
| action=screensaver | ||
| elif grep -q "dpms off" "$HYPRIDLE_CONF"; then | ||
| action=dpms | ||
| else | ||
| action=none | ||
| fi | ||
|
|
||
| if grep -qE "on-timeout = omarchy-system-lock$" "$HYPRIDLE_CONF"; then | ||
| lock=on | ||
| else | ||
| lock=off | ||
| fi | ||
|
|
||
| if [[ $action != none ]]; then | ||
| [[ -n ${timeouts[0]:-} ]] && idle=${timeouts[0]} | ||
| if [[ $lock == on && -n ${timeouts[1]:-} ]]; then | ||
| ((lockdelay = timeouts[1] - idle)) | ||
| ((lockdelay < 0)) && lockdelay=2 | ||
| fi | ||
| elif [[ $lock == on && -n ${timeouts[0]:-} ]]; then | ||
| idle=${timeouts[0]} | ||
| lockdelay=0 | ||
| fi | ||
| } | ||
|
|
||
| write_settings() { | ||
| mkdir -p "$(dirname "$HYPRIDLE_CONF")" | ||
| [[ -f $HYPRIDLE_CONF ]] && cp -f "$HYPRIDLE_CONF" "$HYPRIDLE_CONF.bak.$(date +%s)" | ||
|
|
||
| { | ||
| cat <<'GENERAL' | ||
| general { | ||
| lock_cmd = omarchy-system-lock # lock screen and 1password | ||
| before_sleep_cmd = OMARCHY_LOCK_ONLY=true omarchy-system-lock # lock before suspend without scheduling display off. | ||
| after_sleep_cmd = sleep 1 && omarchy-system-wake # delay for PAM readiness, then turn on display. | ||
| inhibit_sleep = 3 # wait until screen is locked | ||
| } | ||
| GENERAL | ||
|
|
||
| case $action in | ||
| screensaver) | ||
| printf '\n# Start screensaver after %s seconds of inactivity\nlistener {\n timeout = %s\n on-timeout = pidof hyprlock || omarchy-launch-screensaver\n}\n' "$idle" "$idle" | ||
| ;; | ||
| dpms) | ||
| printf '\n# Turn off displays after %s seconds of inactivity\nlistener {\n timeout = %s\n on-timeout = hyprctl dispatch dpms off\n on-resume = hyprctl dispatch dpms on\n}\n' "$idle" "$idle" | ||
| ;; | ||
| esac | ||
|
|
||
| if [[ $lock == on ]]; then | ||
| printf '\n# Lock the session after inactivity\nlistener {\n timeout = %s\n on-timeout = omarchy-system-lock\n on-resume = omarchy-system-wake\n}\n' "$((idle + lockdelay))" | ||
| fi | ||
| } >"$HYPRIDLE_CONF" | ||
|
|
||
| omarchy-restart-hypridle | ||
| } | ||
|
|
||
| fmt_action() { | ||
| case $1 in | ||
| screensaver) echo "Show screensaver" ;; | ||
| dpms) echo "Turn off displays" ;; | ||
| none) echo "Do nothing" ;; | ||
| esac | ||
| } | ||
|
|
||
| fmt_mins() { awk "BEGIN { printf \"%g\", $1 / 60 }"; } | ||
|
|
||
| choose_action() { | ||
| local choice | ||
| choice=$(gum choose --header "When the session goes idle:" \ | ||
| "Show screensaver" "Turn off displays" "Do nothing") || return | ||
| case $choice in | ||
| "Show screensaver") action=screensaver ;; | ||
| "Turn off displays") action=dpms ;; | ||
| "Do nothing") action=none ;; | ||
| esac | ||
| dirty=1 | ||
| } | ||
|
|
||
| choose_timeout() { | ||
| if [[ $action == none ]]; then | ||
| echo "Pick a screen action first (screensaver or turn off displays)." | ||
| sleep 1.5 | ||
| return | ||
| fi | ||
| local choice secs | ||
| choice=$(gum choose --header "Idle timeout:" \ | ||
| "1 minute" "2.5 minutes" "5 minutes" "10 minutes" "30 minutes" "Custom…") || return | ||
| case $choice in | ||
| "1 minute") idle=60 ;; | ||
| "2.5 minutes") idle=150 ;; | ||
| "5 minutes") idle=300 ;; | ||
| "10 minutes") idle=600 ;; | ||
| "30 minutes") idle=1800 ;; | ||
| "Custom…") | ||
| secs=$(gum input --header "Idle timeout in seconds (min 5):" --value "$idle") || return | ||
| if [[ $secs =~ ^[0-9]+$ ]] && ((secs >= 5)); then | ||
| idle=$secs | ||
| else | ||
| echo "Invalid value." | ||
| sleep 1.5 | ||
| return | ||
| fi | ||
| ;; | ||
| esac | ||
| dirty=1 | ||
| } | ||
|
|
||
| choose_lock() { | ||
| local choice | ||
| choice=$(gum choose --header "Lock the session when idle?" "Yes" "No") || return | ||
| [[ $choice == "Yes" ]] && lock=on || lock=off | ||
| dirty=1 | ||
| } | ||
|
|
||
| apply_settings() { | ||
| write_settings | ||
| dirty=0 | ||
| notify-send -u low "Idle settings applied" \ | ||
| "$(fmt_action "$action") • timeout ${idle}s • lock: $lock" 2>/dev/null | ||
| echo "Applied." | ||
| sleep 1 | ||
| } | ||
|
|
||
| command -v gum &>/dev/null || { | ||
| echo "gum is required" >&2 | ||
| exit 1 | ||
| } | ||
|
|
||
| read_settings | ||
| dirty=0 | ||
|
|
||
| while true; do | ||
| clear | ||
| echo "Screensaver & idle settings" | ||
| echo | ||
| echo " When idle : $(fmt_action "$action")" | ||
| [[ $action != none ]] && echo " Idle timeout : ${idle}s ($(fmt_mins "$idle") min)" | ||
| if [[ $lock == on ]]; then | ||
| echo " Idle lock : on (locks after $((idle + lockdelay))s)" | ||
| else | ||
| echo " Idle lock : off" | ||
| fi | ||
| ((dirty)) && echo -e "\n * unapplied changes" | ||
| echo | ||
|
|
||
| choice=$(gum choose --header "Edit:" \ | ||
| "When idle" "Idle timeout" "Idle lock" "Apply" "Restore Omarchy defaults" "Quit") || exit 0 | ||
|
|
||
| case $choice in | ||
| "When idle") choose_action ;; | ||
| "Idle timeout") choose_timeout ;; | ||
| "Idle lock") choose_lock ;; | ||
| "Apply") apply_settings ;; | ||
| "Restore Omarchy defaults") | ||
| if gum confirm "Restore the default Omarchy idle configuration?"; then | ||
| omarchy-refresh-config hypr/hypridle.conf >/dev/null | ||
| omarchy-restart-hypridle | ||
| read_settings | ||
| dirty=0 | ||
| notify-send -u low "Restored default Omarchy idle settings" 2>/dev/null | ||
| fi | ||
| ;; | ||
| "Quit") | ||
| if ((dirty)) && gum confirm "Apply changes before quitting?"; then | ||
| apply_settings | ||
| fi | ||
| exit 0 | ||
| ;; | ||
| esac | ||
| done | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.