bugfix
[hband-tools.git] / xwin-tools / xlock
blob3f2ab41faa4fad53487402bbe79ce0f88d3632f6
1 #!/bin/bash
3 true <<EOF
4 =pod
6 =head1 NAME
8 xlock - Lock X11 screen by disable (enable) input devices
10 xunlock - Unlock X11 screen by disable (enable) input devices
12 =cut
14 EOF
17 if expr "$0" : .*unlock >/dev/null
18 then
19 xinputs_enable=1
20 xsetroot=(-cursor_name left_ptr)
21 else
22 xinputs_enable=0
23 #xsetroot=(-cursor_name bogosity)
26 xinput_enable_disable()
28 local xinputs_enable=$1
29 local device_id
30 for device_id in $2
32 xinput set-int-prop "$device_id" "Device Enabled" 8 $xinputs_enable 2>/dev/null
33 xinput list-props "$device_id" | sed -ne "1p;/Device Enabled/p"
34 done
37 set_xinputs()
39 echo "$0: DISPLAY=$DISPLAY" >&2
41 if [ $xinputs_enable = 1 ]
42 then
43 device_ids=`xinput list --id-only`
44 xinput_enable_disable "$xinputs_enable" "$device_ids"
46 run-parts ~/.local/share/xunlock.d
47 else
48 export -f xinput_enable_disable
50 device_ids=`xinput list | grep -vw core | sed -ne "s/.*id=\([0-9]\+\).*/\1/p"`
51 set-xcursor-lock-and-run bash -c "xinput_enable_disable $xinputs_enable '$device_ids'"
53 run-parts ~/.local/share/xlock.d
56 if [ -n "$xsetroot" ]
57 then
58 xsetroot "${xsetroot[@]}"
62 if [ -z "$DISPLAY" ]
63 then
64 echo "$0: all Xorg displays ..." >&2
65 for DISPLAY in `xdpys`
67 export DISPLAY
68 set_xinputs
69 done
70 else
71 set_xinputs