summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-x.a/sys/lock.sh60
-rw-r--r--.b/etc/elogind/logind.conf54
-rwxr-xr-x.b/etc/elogind/system-sleep/run-lock.sh10
-rw-r--r--.config/jgmenu/append.csv2
4 files changed, 77 insertions, 49 deletions
diff --git a/.a/sys/lock.sh b/.a/sys/lock.sh
index 727b4af..9e65f42 100755
--- a/.a/sys/lock.sh
+++ b/.a/sys/lock.sh
@@ -1,9 +1,12 @@
#!/bin/bash
+# Suspend is managed by elogind
+# Refer to ~/.b/etc/elogind/logind.conf
+# ~/.b/etc/elogind/system-sleep/run-lock.sh
## Helper functions
res () {
pkill $@
- nohup $@ 2>&1 &
+ $@ 2>&1 >~/nohup.out &
disown
}
@@ -18,7 +21,7 @@ before_locking () {
dunstctl set-paused true
sleep 0.1 # Could fix notifications sometimes being shown https://github.com/dunst-project/dunst/issues/697#issuecomment-1045122705
- touch /tmp/locksh-locked
+ touch ~/.tmp/locksh-locked
}
before_suspend () {
@@ -31,15 +34,9 @@ when_unlocked () {
# Resets programs, in case resolution changes
res ~/.fehbg # wallpaper
- res lead # hot corners, this is MageJohn's fork: https://github.com/MageJohn/lead
+ # res lead # hot corners, this is MageJohn's fork: https://github.com/MageJohn/lead
- rm /tmp/locksh-locked
-}
-
-when_unlocked_after_suspend () {
- gtk-launch picom # sometimes my compositor stops working after suspend, this makes sure it's running
-
- rm /tmp/locksh-slept
+ rm ~/.tmp/locksh-locked
}
# ++==================================++
@@ -50,13 +47,13 @@ when_unlocked_after_suspend () {
# 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
+ exit 1
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
+if [ $(grep -r 'RUNNING' /proc/asound | wc -l) -gt 1 ]; then
message='Please, stop all playing audio before trying to suspend!'
if [ -x "$(command -v zenity)" ]; then
@@ -68,14 +65,14 @@ if [ $(grep -r 'RUNNING' /proc/asound | wc -l) -gt 1 ] && [[ "$1" == 'suspend' ]
fi
echo $message
- exit
+ exit 1
fi
# ++============================++
# || Lock if not locked already ||
# ++============================++
-if ! [ -f /tmp/locksh-locked ]; then
+if [ ! -f ~/.tmp/locksh-locked ]; 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
@@ -86,39 +83,6 @@ if ! [ -f /tmp/locksh-locked ]; then
--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 && [ -f '/tmp/locksh-slept' ] && when_unlocked_after_suspend
+ ; when_unlocked
) &
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/locksh-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/.b/etc/elogind/logind.conf b/.b/etc/elogind/logind.conf
new file mode 100644
index 0000000..71639c8
--- /dev/null
+++ b/.b/etc/elogind/logind.conf
@@ -0,0 +1,54 @@
+# This file is part of elogind.
+#
+# elogind is free software; you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation; either version 2.1 of the License, or
+# (at your option) any later version.
+#
+# Entries in this file show the compile time defaults.
+# You can change settings by editing this file.
+# Defaults can be restored by simply deleting this file.
+#
+# See logind.conf(5) for details.
+
+[Login]
+#KillUserProcesses=no
+#KillOnlyUsers=
+#KillExcludeUsers=root
+#InhibitDelayMaxSec=5
+#HandlePowerKey=poweroff
+#HandleSuspendKey=suspend
+#HandleHibernateKey=hibernate
+#HandleLidSwitch=suspend
+#HandleLidSwitchExternalPower=suspend
+#HandleLidSwitchDocked=ignore
+#PowerKeyIgnoreInhibited=no
+#SuspendKeyIgnoreInhibited=no
+#HibernateKeyIgnoreInhibited=no
+#LidSwitchIgnoreInhibited=yes
+HoldoffTimeoutSec=1s
+#IdleAction=ignore
+#IdleActionSec=30min
+#RuntimeDirectorySize=10%
+#RuntimeDirectoryInodes=400k
+#RemoveIPC=yes
+#InhibitorsMax=8192
+#SessionsMax=8192
+
+[Sleep]
+#AllowSuspend=yes
+#AllowHibernation=yes
+#AllowSuspendThenHibernate=yes
+#AllowHybridSleep=yes
+#AllowPowerOffInterrupts=no
+#BroadcastPowerOffInterrupts=yes
+#AllowSuspendInterrupts=no
+#BroadcastSuspendInterrupts=yes
+#HandleNvidiaSleep=no
+#SuspendState=mem standby freeze
+#SuspendMode=
+#HibernateState=disk
+#HibernateMode=platform shutdown
+#HybridSleepState=disk
+#HybridSleepMode=suspend platform shutdown
+#HibernateDelaySec=10800
diff --git a/.b/etc/elogind/system-sleep/run-lock.sh b/.b/etc/elogind/system-sleep/run-lock.sh
new file mode 100755
index 0000000..35e6691
--- /dev/null
+++ b/.b/etc/elogind/system-sleep/run-lock.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+# Thanks https://wiki.gentoo.org/wiki/Elogind#Suspend.2FHibernate_Resume.2FThaw_hook_scripts
+case $1/$2 in
+ pre/*) # Put here any commands expected to be run when suspending or hibernating.
+ export DISPLAY=:0
+ sudo -H -u kamen bash -c '~/.a/sys/lock.sh && until xdotool search --onlyvisible --classname i3lock; do sleep 0.2; done'
+ ;;
+ post/*) # Put here any commands expected to be run when resuming from suspension or thawing from hibernation.
+ ;;
+esac
diff --git a/.config/jgmenu/append.csv b/.config/jgmenu/append.csv
index fcda0c2..81ca4bc 100644
--- a/.config/jgmenu/append.csv
+++ b/.config/jgmenu/append.csv
@@ -2,6 +2,6 @@
Log Out,~/.a/sys/on-wm-logout.sh && loginctl terminate-user $USER,system-log-out
Lock Now,~/.a/sys/lock.sh now,system-lock-screen
^sep()
-Suspend,~/.a/sys/lock.sh suspend,system-suspend
+Suspend,loginctl suspend,system-suspend
Reboot,~/.a/sys/on-wm-logout.sh && loginctl reboot,system-reboot
Shutdown,~/.a/sys/on-wm-logout.sh && loginctl poweroff,system-shutdown