diff options
| author | Syndamia <kamen.d.mladenov@protonmail.com> | 2021-07-01 10:44:22 +0300 |
|---|---|---|
| committer | Syndamia <kamen.d.mladenov@protonmail.com> | 2021-07-01 10:44:22 +0300 |
| commit | 37e18d1359c99cb52cc3e9c0e5078840d9a1e5c0 (patch) | |
| tree | 27f51ddb18e7b8c144ae9a5630aa48c686bc11d0 | |
| parent | dcbcabce98fa116ceb3f4206c30bccf6354b03ea (diff) | |
| download | dotfiles-37e18d1359c99cb52cc3e9c0e5078840d9a1e5c0.tar dotfiles-37e18d1359c99cb52cc3e9c0e5078840d9a1e5c0.tar.gz dotfiles-37e18d1359c99cb52cc3e9c0e5078840d9a1e5c0.zip | |
Fully reworked how lock script handles before and after lock/suspend commands
| -rwxr-xr-x | .i3lock/lock.sh | 85 |
1 files changed, 55 insertions, 30 deletions
diff --git a/.i3lock/lock.sh b/.i3lock/lock.sh index eec9c69..76a0ec5 100755 --- a/.i3lock/lock.sh +++ b/.i3lock/lock.sh @@ -1,40 +1,65 @@ #!/bin/bash -if [ $(grep -r "RUNNING" /proc/asound | wc -l) -eq 0 ] || [[ $# -ne 0 ]]; then +before_locking () { # Disables dunst, my notification daemon, so I don't see notification on lock screen # https://github.com/dunst-project/dunst/issues/697 # https://wiki.archlinux.org/title/Dunst#Disable_dunst_temporarily dunstctl set-paused true +} - # The first line is normal i3lock arguments, while the rest of the lines are i3lock-color ones - # If you want to use i3lock, remove those lines (and the \ at the end) - # But I hightly advise you to use i3lock-color, it's amazing: https://github.com/Raymo111/i3lock-color - i3lock -f -c d49408 -i /home/kamen/.i3lock/lockscreen.png \ - -F -k --indicator --keylayout 1 --radius 95 --pass-volume-keys \ - --date-str="%d.%m.%Y" --verif-text="Verifying…" --wrong-text="Wrong!" --noinput-text="No Input!" \ - --insidever-color d47408cc --ringver-color d47408 --insidewrong-color c35b5bcc --ringwrong-color c35b5b \ - --layout-color ffeede --time-color ffeede --date-color ffeede --greeter-color ffeede --verif-color ffeede --wrong-color ffeede - - if [[ "$1" == "suspend" ]]; then - # Apps that are playing audio could stop being able to play audio after suspend (to fix, restart app) - # By restarting pipewire, I try to make sure that any audio that might be playing, stops - systemctl --user restart pipewire - - # Usually suspending should be done with "systemctl suspend", but I've had issues with that so I directly tell the kernel to sleep the system - # For that I have a script in /usr/loca/sbin that just continains: - # - # #!/bin/bash - # echo -n mem>/sys/power/state - # - # And I've added the following to /etc/sudoers (where kamen is my username), so I don't need to put in my password: - # - # kamen ALL = (root) NOPASSWD: /usr/local/sbin/sleep.sh - sudo -u root /usr/local/sbin/sleep.sh - sleep 0.5 # a hack to make sure it doesn't execute anything, after being put to sleep but before everything sleeps - - pkill tint2; gtk-launch tint2 # sometimes tint2 get's messed up and transparency breaks, this makes sure that this doesn't happen - gtk-launch picom # sometimes my compositor stops working after suspend, this makes sure it's running +when_unlocked () { + dunstctl set-paused false # Enables my notification daemon +} + +when_unlocked_after_suspend () { + gtk-launch picom # sometimes my compositor stops working after suspend, this makes sure it's running +} + +# Show an error message if user is trying to suspend, while audio is playing, because that can mess up sound servers +# It tries to send a message via zenity, xmessage or notify-send, depending on which is installed +# but it always sends a text message to stdout. In the end, scrit execution is stopped. +if [ $(grep -r "RUNNING" /proc/asound | wc -l) -ne 0 ] && [[ "$1" == "suspend" ]]; then + message="Please, stop all playing audio before trying to suspend!" + + if ![ -x "$(command -v zenity)" ]; then + zenity --error --no-wrap --text="$message" + elif [ -x "$(command -v zenity)" ]; then + xmessage -center "$message" + elif [ -x "$(command -v notify-send)" ]; then + notify-send -u critical "$message" fi + echo $message - dunstctl set-paused false # Enables my notification daemon + exit +fi + +# The first line of i3lock arguments uses standard arguments, while the rest of the lines are i3lock-color ones +# If you want to use i3lock, remove those lines (and the \ at the end) +# But I hightly advise you to use i3lock-color, it's amazing: https://github.com/Raymo111/i3lock-color +( +before_locking && \ +i3lock -f -c d49408 -i /home/kamen/.i3lock/lockscreen.png -n \ + -F -k --indicator --keylayout 1 --radius 95 --pass-volume-keys \ + --date-str="%d.%m.%Y" --verif-text="Verifying…" --wrong-text="Wrong!" --noinput-text="No Input!" \ + --insidever-color d47408cc --ringver-color d47408 --insidewrong-color c35b5bcc --ringwrong-color c35b5b \ + --layout-color ffeede --time-color ffeede --date-color ffeede --greeter-color ffeede --verif-color ffeede --wrong-color ffeede \ +&& when_unlocked && if [ -f "/tmp/slept" ]; then when_unlocked_after_suspend; rm /tmp/slept; fi +) & + +if [[ "$1" == "suspend" ]]; then + # A file is created to indicate that the system was suspended + # After i3lock is done (unlocked), existance of this file is checked to determine if + # script should run when_unlocked_after_suspend function + touch /tmp/slept + + # Usually suspending should be done with "systemctl suspend", but I've had issues with that so I directly tell the kernel to sleep the system + # For that I have a script in /usr/loca/sbin that just continains: + # + # #!/bin/bash + # echo -n mem>/sys/power/state + # + # And I've added the following to /etc/sudoers (where kamen is my username), so I don't need to put in my password: + # + # kamen ALL = (root) NOPASSWD: /usr/local/sbin/sleep.sh + sudo -u root /usr/local/sbin/sleep.sh fi |
