I am trying to improve my screen locking script but I am kind of stuck. It opens a terminal emulator, put it on fullscreen mode and on top it locks the screen (i3 lock is just fully transparent so only the terminal is visible).
Now the problem is that it relies on time delay which is not always long enough (making it longer just screws it for normal use).
#!/bin/bash
alacritty -e bash -ic "cmatrix -ab" &
sleep 0.5 # This is bad
i3-msg fullscreen
i3lock -n -t -c000000
i3-msg kill
i3-msg can directly reference the alacritty window with its ID. (e.g. i3-msg "[id=90177542] fullscreen").
I can get the window ID with the command below but it requires clicking on the window with a mouse pointer.
Do you know if it is possible to get id of the terminal window when it is starting directly in the bash script (and store it in a variable)?
i3wm with X11
I have i3lock transparent so I can see what is behind it.
The point is that cmatrix in alacritty is running in fullscreen just before the screen is locked. This way I can have a dynamically chaning background.
As far as I know i3lock can work only with a static image. So when it is opaque the background is not changing in time.
If there is as lock screen software that can display cmatrix output directly that would be much better option but I have not found one.
As you are deliberately using cmatrix - then try the package xlockmore as it has a matrix mode - the delay is used get the desired effect - depending on how fast your system is - a higher value gives the better effect
This actually helped me. Thank you. It required a little bit more tuning to make it work as I want.
Here is full script if anyone wants it.
#!/bin/bash
terminal=alacritty
command="~/cmatrix -ab"
loop_delay=0.05
# get list of open windows before the script actually do anything
before_list=$(mktemp)
xdotool search --desktop $(xdotool get_desktop) --class "${terminal}" | sort > "${before_list}"
# launch terminal window with "screensaver"
$terminal -e bash -ic "${command}" &
# find window id for currently lauched terminal - a polling loop
counter=0
while [ -z $window_id ]; do
window_id=$(xdotool search --desktop $(xdotool get_desktop) --class "${terminal}" | sort | comm -23 - "${before_list}")
((counter++))
sleep $loop_delay
if [ $counter -ge 1000 ]; then
notify-send "error: Lockscreen took too long to start"
rm "${before_list}"
exit 1
fi
done
# cleanup
rm "${before_list}"
# put the terminal to fullscreen, lock the screen and wait until it is unlocked and then close the terminal
i3-msg "[id=${window_id}] fullscreen"
$@ & # fork additional command - e.g. calling "lock-screen systemctl suspend" will still show the terminal window when woken up from suspend
i3lock -n -t -c000000
i3-msg "[id=${window_id}] kill"
Maybe, maybe not. That is why I’ve put it all in the first post.
Anyway, the graphics for xlock and xscreensaver is not very appealing for me. And I do not see and option to adjust font, color or character set as I can do with the terminal.
And now I can also use it with @Kresimir’s clock. How cool is that, right?
Edit: added $@ & so it is possible to lock the screen and suspend the computer with a simple lock-screen systemctl suspend (lock-screen is name of this script).