google / xsecurelock

X11 screen lock utility with security in mind
Apache License 2.0
876 stars 65 forks source link

Expose screen saver index via $XSCREENSAVER_SAVER_INDEX #144

Closed jtrees closed 2 years ago

jtrees commented 2 years ago

Fixes #143.

Example Usage

saver_feh

#!/usr/bin/env bash

set -euo pipefail

if [ "$XSCREENSAVER_SAVER_INDEX" = "1" ]; then
  IMAGE_PATH="$XSECURELOCK_IMAGE_PATH_1"
else
  IMAGE_PATH="$XSECURELOCK_IMAGE_PATH_0"
fi

feh \
  --window-id="$XSCREENSAVER_WINDOW" \
  --xinerama-index="$XSCREENSAVER_SAVER_INDEX" \
  -F "$IMAGE_PATH

Invocation

XSECURELOCK_IMAGE_PATH_0="$HOME/Pictures/left-screen.png" \
XSECURELOCK_IMAGE_PATH_1="$HOME/Pictures/right-screen.png" \
XSECURELOCK_SAVER=saver_feh \
xsecurelock
google-cla[bot] commented 2 years ago

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

For more information, open the CLA check for this pull request.

divVerent commented 2 years ago

Thanks!

ghost commented 1 year ago

This only works on two monitors, not 3 or 4 =( Should be something likes this or similar;

XSECURELOCK_IMAGE_PATH_0=dir/left.jpg
XSECURELOCK_IMAGE_PATH_1=dir/center.jpg
XSECURELOCK_IMAGE_PATH_2=dir/right.jpg
XSECURELOCK_IMAGE_PATH_3=dir/top.jpg
jtrees commented 1 year ago

@tuxy Yes, well spotted. You would have to tweak the examples for more monitors.

Some quick and dirty (untested) changes:

saver_feh

# saver_feh

#!/usr/bin/env bash

set -euo pipefail

case $XSCREENSAVER_SAVER_INDEX in
  1)
    IMAGE_PATH="$XSECURELOCK_IMAGE_PATH_1"
    ;;
  2)
    IMAGE_PATH="$XSECURELOCK_IMAGE_PATH_2"
    ;;
  3)
    IMAGE_PATH="$XSECURELOCK_IMAGE_PATH_3"
    ;;
  *)
    IMAGE_PATH="$XSECURELOCK_IMAGE_PATH_0"
    ;;
esac

feh \
  --window-id="$XSCREENSAVER_WINDOW" \
  --xinerama-index="$XSCREENSAVER_SAVER_INDEX" \
  -F "$IMAGE_PATH

Invocation

XSECURELOCK_IMAGE_PATH_0="$HOME/Pictures/left-screen.png" \
XSECURELOCK_IMAGE_PATH_1="$HOME/Pictures/center-screen.png" \
XSECURELOCK_IMAGE_PATH_2="$HOME/Pictures/right-screen.png" \
XSECURELOCK_IMAGE_PATH_3="$HOME/Pictures/top-screen.png" \
XSECURELOCK_SAVER=saver_feh \
xsecurelock

Note

At this point it would be cleaner to use a bash array instead of the spaghetti code above but I'll leave figuring that out as an exercise.