i3lock Issue in Manjaro Openbox

When locking screen in Manjaro Openbox either from the Openbox Menu or Ctrl + Alt + L, it uses the command lockscreen -- scrot.

Instead of having i3block just have a blurry background when locked, I want it to have a specific background.

In ~/.config/openbox, rc.xml & kbinds.txt are the files to update to change the keybinds, and menu.xml is to update the openbox menu. Alternatively, you can use the GUI via Openbox menu -> Preferences -> Openbox -> GUI Menu / Keybind Editor.

I replaced the lockscreen -- scrot with i3lock -i ~/.config/i3lock/lockscreen.png in all 3 files. Using the openbox menu to lock screen works, but using Ctrl + Alt + L is still using lockscreen -- scrot I believe. I do not know what is causing this, or there is something underlying that is overwriting the command with priority. Also, can't really find much information about lockscreen besides from lockscreen --help.

Anyone know how to fix this issue?

Tagging @linux-aarhus since they're the maintainer.

rc.xml defines keyboard shortcuts so you will have to change the command there. As an alternative you can copy the locksreen script to your ~/bin folder and modify to your preferred command.

Your bin folder is placed first in your $PATH so creating a script with the same name in ~/bin will override the script in /usr/bin.

lockscreen is a bash script which can be modified to use a supplied png as background instead of using a screenprint.

~ >>> cat /usr/bin/lockscreen                                                   
#!/usr/bin/env bash
# Author: Dolores Portalatin <hello@doloresportalatin.info>
# Dependencies: imagemagick, i3lock-color-git, scrot, wmctrl (optional)
set -o errexit -o noclobber -o nounset

# get path where the script is located to find the lock icon
scriptpath=$(readlink -f -- "$0")
scriptpath=${scriptpath%/*}
iconpath="/usr/share/manjaro"

hue=(-level "0%,100%,0.6")
effect=(-filter Gaussian -resize 20% -define "filter:sigma=1.5" -resize 500.5%)
# default system sans-serif font
font=$(convert -list font | awk "{ a[NR] = \$2 } /family: $(fc-match sans -f "%{family}\n")/ { print a[NR-1]; exit }")
image=$(mktemp --suffix=.png)
shot=(import -window root)
desktop=""
i3lock_cmd=(i3lock -i "$image")
shot_custom=false

options="Options:
    -h, --help       This help menu.
    -d, --desktop    Attempt to minimize all windows before locking.
    -g, --greyscale  Set background to greyscale instead of color.
    -p, --pixelate   Pixelate the background instead of blur, runs faster.
    -f <fontname>, --font <fontname>  Set a custom font.
    -t <text>, --text <text> Set a custom text prompt.
    -l, --listfonts  Display a list of possible fonts for use with -f/--font.
                     Note: this option will not lock the screen, it displays
                     the list and exits immediately.
    -n, --nofork     Do not fork i3lock after starting.
    --               Must be last option. Set command to use for taking a
                     screenshot. Default is 'import -window root'. Using 'scrot'
                     or 'maim' will increase script speed and allow setting
                     custom flags like having a delay."

# move pipefail down as for some reason "convert -list font" returns 1
set -o pipefail
trap 'rm -f "$image"' EXIT
temp="$(getopt -o :hdnpglt:f: -l desktop,help,listfonts,nofork,pixelate,greyscale,text:,font: --name "$0" -- "$@")"
eval set -- "$temp"

# l10n support
text="Type password to unlock"
case "${LANG:-}" in
    de_* ) text="Bitte Passwort eingeben" ;; # Deutsch
    da_* ) text="Indtast adgangskode" ;; # Danish
    en_* ) text="Type password to unlock" ;; # English
    es_* ) text="Ingrese su contraseña" ;; # Española
    fr_* ) text="Entrez votre mot de passe" ;; # Français
    id_* ) text="Masukkan kata sandi Anda" ;; # Bahasa Indonesia
    it_* ) text="Inserisci la password" ;; # Italian
    lv_* ) text="Ievadi paroli" ;; # Latvian
    pl_* ) text="Podaj hasło" ;; # Polish
    pt_* ) text="Digite a senha para desbloquear" ;; # Português
    ru_* ) text="Введите пароль" ;; # Russian
    * ) text="Type password to unlock" ;; # Default to English
esac

while true ; do
    case "$1" in
        -h|--help)
            printf "Usage: %s [options]\n\n%s\n\n" "${0##*/}" "$options"; exit 1 ;;
        -d|--desktop) desktop=$(command -V wmctrl) ; shift ;;
        -g|--greyscale) hue=(-level "0%,100%,0.6" -set colorspace Gray -average) ; shift ;;
        -p|--pixelate) effect=(-scale 10% -scale 1000%) ; shift ;;
        -f|--font)
            case "$2" in
                "") shift 2 ;;
                *) font=$2 ; shift 2 ;;
            esac ;;
        -t|--text) text=$2 ; shift 2 ;;
        -l|--listfonts)
	    convert -list font | awk -F: '/Font: / { print $2 }' | sort -du | command -- ${PAGER:-less}
	    exit 0 ;;
	-n|--nofork) i3lock_cmd+=(--nofork) ; shift ;;
        --) shift; shot_custom=true; break ;;
        *) echo "error" ; exit 1 ;;
    esac
done

if "$shot_custom" && [[ $# -gt 0 ]]; then
    shot=("$@");
fi

command -- "${shot[@]}" "$image"

value="60" #brightness value to compare to

color=$(convert "$image" -gravity center -crop 100x100+0+0 +repage -colorspace hsb \
    -resize 1x1 txt:- | awk -F '[%$]' 'NR==2{gsub(",",""); printf "%.0f\n", $(NF-1)}');

if [[ $color -gt $value ]]; then #white background image and black text
    bw="black"
    icon="$iconpath/icons/lockdark.png"
    param=("--textcolor=00000000" "--insidecolor=0000001c" "--ringcolor=0000003e" \
        "--linecolor=00000000" "--keyhlcolor=ffffff80" "--ringvercolor=ffffff00" \
        "--separatorcolor=22222260" "--insidevercolor=ffffff1c" \
        "--ringwrongcolor=ffffff55" "--insidewrongcolor=ffffff1c")
else #black
    bw="white"
    icon="$iconpath/icons/lock.png"
    param=("--textcolor=ffffff00" "--insidecolor=ffffff1c" "--ringcolor=ffffff3e" \
        "--linecolor=ffffff00" "--keyhlcolor=00000080" "--ringvercolor=00000000" \
        "--separatorcolor=22222260" "--insidevercolor=0000001c" \
        "--ringwrongcolor=00000055" "--insidewrongcolor=0000001c")
fi

convert "$image" "${hue[@]}" "${effect[@]}" -font "$font" -pointsize 26 -fill "$bw" -gravity center \
    -annotate +0+160 "$text" "$icon" -gravity center -composite "$image"

# If invoked with -d/--desktop, we'll attempt to minimize all windows (ie. show
# the desktop) before locking.
${desktop} ${desktop:+-k on}

# try to use i3lock with prepared parameters
if ! "${i3lock_cmd[@]}" "${param[@]}" >/dev/null 2>&1; then
    # We have failed, lets get back to stock one
    "${i3lock_cmd[@]}"
fi

# As above, if we were passed -d/--desktop, we'll attempt to restore all windows
# after unlocking.
${desktop} ${desktop:+-k off}

The issue is that I did modify that, but it still isn't working. Seems like something has priority over the rc.xml file for this keybind.

    <keybind key="C-S-l">
      <action name="Execute">
        <command>i3lock -i ~/.config/i3lock/lockscreen.png</command>
      </action>
    </keybind>

I can make a new keybind combination and it works fine, but I am trying to figure out why something have priority over the rc.xml file for Ctrl + Alt + L.

Please check the xfce keyboard shortcuts from the xfce settings manager.

Because xfce shortcuts occationaly interferes with openbox - the shortcut is defined in xfce as well.

Found the culprit!


I've changed the command but... it seems to be using i3lock instead of the whole command string I entered in. When I try to lock the screen with Ctrl + Alt + L, it's just a white screen, without the image, which is what plain i3lock does.

It works fine if I create a new keybind through the openbox keybind config file, but not this xfce keybind.

That one I can't say.

Does it make a difference if you use /home/user_name/ instead of ~/ in the command?

2 Likes

Interesting, that did the trick. I wonder why ~/ doesn't work in XFCE keybind settings but works in openbox keybinds.

I noticed this behaviour in Xfce when I wanted to assign keyboard shortcuts to some scripts located in the home directory.

No idea why this happens though - I couldn't find any relevant information online.