#!/bin/bash # This script is a workaround for xsecurelock not being able to lock the screen when a fullscreen window is in focus. # 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" "Disney+" "Prime Video" "Hulu" "HBO Max" "Twitch" "Spotify" "Spotube" "MPlayer" "VLC" "mpv" "Zoom" "Google Meet" "Microsoft Teams" "Discord" "Slack" "Plex" "Kodi" "Jellyfish" "OBS" "CCTV" ) # Dependencies AWK=/bin/awk GREP=/bin/grep XPROP=/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 some apps you may need to check WM_CLASS(STRING) instead $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) if [[ $id == "" ]]; then echo "No active window found in the workspace" return 0 fi echo "$id" title=$(get_window_title $id) echo "Active window:$title" if is_fullscreen $id; then echo "Fullscreen window detected:$title" return 1 else for i in "${LIST_OF_WINDOW_TITLES_THAT_PREVENT_LOCKING[@]}"; do if [[ $title =~ $i ]]; then echo "$i was found in$title" return 1 fi done return 0 fi } # Debugging #if should_lock; then #echo "Locking the screen..." #/bin/dunstify -u low "Locking the screen..." #else #echo "Not locking the screen..." #/bin/dunstify -u low "Not locking the screen..." #fi # main() if should_lock; then lock_screen fi