#!/bin/bash # This script is a workaround for xsecurelock not being able to lock the screen when a fullscreen window is active. # Lock the screen with xsecurelock and take care of picom lock_screen() { # kill the compositor so that xsecurelock doesn't complain pkill picom # xsecurelock configuration (you can find more flags here: https://github.com/google/xsecurelock) export XSECURELOCK_PASSWORD_PROMPT=time_hex export XSECURELOCK_FONT="Inconsolata:size=17" export XSECURELOCK_DATETIME_FORMAT=" <%H:%M>" export XSECURELOCK_SHOW_DATETIME=1 export XSECURELOCK_BACKGROUND_COLOR="#0a001f" export XSECURELOCK_AUTH_BACKGROUND_COLOR="#0a001f" export XSECURELOCK_AUTH_FOREGROUND_COLOR="#ace6f0" export XSECURELOCK_DISCARD_FIRST_KEYPRESS=0 export XSECURELOCK_BURNIN_MITIGATION=0 xsecurelock picom & } # Settings declare -a LIST_OF_WINDOW_TITLES_THAT_PREVENT_LOCKING=( "YouTube" "Netflix" "Twitch" #"Spotify" "MPlayer" "VLC" "mpv" "Google Meet" "Microsoft Teams" "Zoom" #"Discord" #"Slack" #"Plex" "CCTV" ) # Dependencies AWK=/usr/bin/awk GREP=/usr/bin/grep XPROP=/usr/bin/xprop # Find active window id get_active_id() { $XPROP -root | $AWK '$1 ~ /_NET_ACTIVE_WINDOW/ { print $5 }' } # Determine a window's title text by it's ID get_window_title() { # For mplayer or vlc, we might need to check WM_CLASS(STRING), idk. $XPROP -id $1 | $AWK -F '=' '$1 ~ /_NET_WM_NAME\(UTF8_STRING\)/ { print $2 }' } # Determine if a window is fullscreen based on it's ID is_fullscreen() { $XPROP -id $1 | $AWK -F '=' '$1 ~ /_NET_WM_STATE\(ATOM\)/ { for (i=2; i<=3; i++) if ($i ~ /FULLSCREEN/) exit 0; exit 1 }' return $? } # Determine if the locker command should run based on which windows are fullscreened. should_lock() { id=$(get_active_id) title=$(get_window_title $id) if is_fullscreen $id; then for i in "${LIST_OF_WINDOW_TITLES_THAT_PREVENT_LOCKING[@]}"; do if [[ $title =~ $i ]]; then return 0 fi done #echo "Fullscreen window detected: $title" return 0 else return 1 fi } # Debugging if should_lock; then echo "Locking the screen..." else echo "Not locking the screen..." fi # main() if should_lock; then dunstify -u critical "Screen will close" sleep 15 lock_screen fi