#!/bin/sh
#241109 sfs
ll="`awk -F= '/^XKB_DEFAULT_LAYOUT=/ {print $2}' ~/.config/labwc/environment`"
lo="`awk -F= '/^XKB_DEFAULT_OPTIONS=/ {print $2}' ~/.config/labwc/environment |sed 's/^grp://'`"
l="$lo
`awk '/grp:/ {print $1}' /usr/share/X11/xkb/rules/xorg.lst |sort |sed 's/^grp://'`"
echo $ll; echo $lo
yad --version |grep -E '^0' && gtk=gtk || gtk=yad
l="`yad --title="Keyboard Layout" \
    --text="Keyboard Layout" \
    --image="input-keyboard" \
    --window-icon="input-keyboard" \
    --name="input-keyboard" \
    --item-separator="\n" \
    --fixed --image-on-top --center \
    --form \
    --field="XKB DEFAULT LAYOUT"  $ll \
    --field="XKB DEFAULT OPTIONS":CBE "$l" \
`"
[ "$l" ] || exit
ll="`echo $l |awk -F\| '{print $1}'`"
lo="`echo $l |awk -F\| '{print $2}'`"
echo $ll ;echo $lo
sed -i 's/XKB_DEFAULT_LAYOUT=.*/XKB_DEFAULT_LAYOUT='$ll'/' ~/.config/labwc/environment
sed -i 's/XKB_DEFAULT_OPTIONS=.*/XKB_DEFAULT_OPTIONS=grp:'$lo'/' ~/.config/labwc/environment
export XKB_DEFAULT_LAYOUT=="$ll"
export XKB_DEFAULT_OPTIONS="$lo"
labwc -r
