diff options
| author | Syndamia <kamen@syndamia.com> | 2022-07-19 11:51:30 +0300 |
|---|---|---|
| committer | Syndamia <kamen@syndamia.com> | 2022-07-19 11:51:30 +0300 |
| commit | 64d438f07fd46bf0972aca66bf29045a2ce6e5b9 (patch) | |
| tree | f96590be13a8c9bb0a64f3e737b6daa2e64d77be /scripts | |
| parent | 68429f7bd64fbb01c18984aaf51e081c6da9422b (diff) | |
| download | dotfiles-64d438f07fd46bf0972aca66bf29045a2ce6e5b9.tar dotfiles-64d438f07fd46bf0972aca66bf29045a2ce6e5b9.tar.gz dotfiles-64d438f07fd46bf0972aca66bf29045a2ce6e5b9.zip | |
Moved i3lock to scripts/system folder
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/system/lock.sh | 118 | ||||
| -rwxr-xr-x | scripts/system/on-wm-logout.sh | 8 | ||||
| -rwxr-xr-x | scripts/system/on-wm-session.sh | 4 |
3 files changed, 128 insertions, 2 deletions
diff --git a/scripts/system/lock.sh b/scripts/system/lock.sh new file mode 100755 index 0000000..e226b20 --- /dev/null +++ b/scripts/system/lock.sh @@ -0,0 +1,118 @@ +#!/bin/bash + +## Helper functions +res () { + pkill $@ + nohup $@ 2>&1 & + disown +} + +# ++=================================++ +# || Actions before and after unlock || +# ++=================================++ + +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 + sleep 0.1 # Could fix notifications sometimes being shown https://github.com/dunst-project/dunst/issues/697#issuecomment-1045122705 +} + +before_suspend () { + # Keep track of time when machine is suspended, as well as how long it has been up for + uptime >> ~/.i3lock/suspend-history +} + +when_unlocked () { + dunstctl set-paused false # Enables my notification daemon + + # Resets programs, in case resolution changes + res ~/.fehbg # wallpaper + res lead # hot corners, this is MageJohn's fork: https://github.com/MageJohn/lead +} + +when_unlocked_after_suspend () { + gtk-launch picom # sometimes my compositor stops working after suspend, this makes sure it's running +} + +# ++==================================++ +# || Prevent locking because of audio || +# ++==================================++ + +# This makes sure to not lock the screen if audio is playing and there are no arguments given +# It's mainly for preventing automatic screen locking while a video/music is playing +# If you still want to lock, just give it some argument, doesn't matter what +if [ $(grep -r 'RUNNING' /proc/asound | wc -l) -gt 0 ] && [ $# -eq 0 ]; then + exit +fi + +# 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, script execution is stopped. +if [ $(grep -r 'RUNNING' /proc/asound | wc -l) -gt 1 ] && [[ "$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 xmessage)" ]; then + xmessage -center "$message" + elif [ -x "$(command -v notify-send)" ]; then + notify-send -u critical "$message" + fi + echo $message + + exit +fi + +# ++============================++ +# || Lock if not locked already || +# ++============================++ + +if ! pgrep i3lock 1>&2; then + # 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 highly 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 + ) & +fi + +# ++=========++ +# || Suspend || +# ++=========++ + +if [[ "$1" == 'suspend' ]]; then + before_suspend + + # A file is created to indicate that the system was suspended + # After i3lock is done (unlocked), existence of this file is checked to determine if + # script should run when_unlocked_after_suspend function + touch /tmp/slept + + # Wait for the lock screen to appear, before suspending + # Without this, sometimes you could awaken the computer and see the desktop for a second, before the lock screen loads. + # During that time, your input is processed by the desktop, giving you control of it, which is a big no-no (even if it's for a second) + while [ $(xdotool search --onlyvisible --classname i3lock | wc -l) -eq 0 ]; do + sleep 0.2 + done + + # 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 contains: + # + # #!/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 + # systemctl suspend + loginctl suspend +fi diff --git a/scripts/system/on-wm-logout.sh b/scripts/system/on-wm-logout.sh new file mode 100755 index 0000000..90ebab2 --- /dev/null +++ b/scripts/system/on-wm-logout.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +# Gracefully close certain programs +grace=(brave) + +for $app in $grace; do + timeout 5 pkill -TERM $app +done diff --git a/scripts/system/on-wm-session.sh b/scripts/system/on-wm-session.sh index 85b7999..e35f4a5 100755 --- a/scripts/system/on-wm-session.sh +++ b/scripts/system/on-wm-session.sh @@ -10,7 +10,7 @@ sleep 1 && /usr/libexec/polkit-gnome-authentication-agent-1 & dunst & # notification daemon lxpolkit & # polkit -xautolock -detectsleep -secure -time 15 -locker ~/.i3lock/lock.sh & # auto lock screen +xautolock -detectsleep -secure -time 15 -locker ~/scripts/system/lock.sh & # auto lock screen tint2 & # taskbar picom & # compositor setxkbmap -layout "us,bg" -variant ",phonetic" -option "grp:alt_shift_toggle" & # keyboard switching @@ -20,7 +20,7 @@ if [[ $device == "desktop" ]]; then fi if [[ $device == "laptop" ]]; then - while :; do if grep -Fq "closed" /proc/acpi/button/lid/LID0/state; then ~/.i3lock/lock.sh suspend && sleep 3; fi; sleep 0.5; done & # lock screen on lid closing; you'll also need to uncomment the HandleLidSwitch variable and assign to it "lock" (HandleLidSwitch=lock) inside /etc/systemd/logind.conf + while :; do if grep -Fq "closed" /proc/acpi/button/lid/LID0/state; then ~/scripts/system/lock.sh suspend && sleep 3; fi; sleep 0.5; done & # lock screen on lid closing; you'll also need to uncomment the HandleLidSwitch variable and assign to it "lock" (HandleLidSwitch=lock) inside /etc/systemd/logind.conf libinput-gestures-setup start & # start gestures blueberry & # bluetooth app fi |
