Prevent xautolock/i3lock when watching fullscreen video
Asked Answered
R

1

6

I use the i3 window manager and have

set $Locker i3lock --color=000000 && sleep 1
exec --no-startup-id xautolock -time 5 -locker "$Locker"

in its config file, so that it locks after 5 minutes.

The problem is that the 5 minutes timer counts down even when I'm whatching a video, which I definitely don't like. (Btw, I usually watch movies with mplayer, but sometimes I go on streaming websites as well, using qutebrowser.) On the contrary, I'd like to prevent xautolocks action in such situations.

One possible solution I was thinking of is changing the second line to

exec --no-startup-id myscript -time 5 -locker "$Locker"

where myscript is a bash/whatever script/program passing all options to xautolock only if I'm not watching some video stuff. But I don't know what to check with this hypothetical script.

Retortion answered 6/11, 2018 at 18:11 Comment(1)
I'm having lots of trouble with this too. You can use the -corners setting of xautolock, so you just move your mouse to the corner, and it won't sleep, but unfortunately some players will always show the overlay if your mouse is in a corner!Paleogeography
M
12

One possible way to do this, without needing to implement all of xautolock's options in myscript would be to write your $Locker as a script or program to determine if the conditions are met to prevent locking. Otherwise, call the screen locker:

xautolock -locker should_screen_lock.sh
                                   |
                   Yes <- fullscreen YouTube? -> No
                    |                            |
                  Abort                         Lock

You can use xprop -root to learn the ID of the active window in the window manager and xprop -id against that ID to see if it's running in fullscreen mode.

From there, it's just putting the two together and calling your window locker (i3lock in this case, but you could also have that as a custom script for a fancier lock screen).

Here's my attempt at doing exactly this. Of note, I don't run xautolock from i3's config: It's a systemd user service. The locker (lock_screen.sh), however, is bound to a the keyboard so that I may bypass xautolock in case I have something in full screen.

Monopode answered 7/5, 2019 at 22:7 Comment(3)
Wow, this is a really good anwer, thank you! Your code is extremely readable, security-compliant (as far as I know what security is), and reasonably short! Welcome to StackOverflow!Retortion
your bash scripting is very logical and nice. I wonder if there's a way to tell if the youtube video is playing or not.Dufour
Indeed a very nice answer! Thank you!Elledge

© 2022 - 2024 — McMap. All rights reserved.