You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
msvsphere-configs/gnome-keyboard-toogle-confi.../gnome-keyboard-toogle-confi...

49 lines
2.0 KiB

#!/bin/bash
exec &>/var/log/gnome-keyboard-toogle-configure.log
SERVICE_NAME='gnome-keyboard-toogle-configure.service'
GSCHEMA_FILE='/usr/share/glib-2.0/schemas/org.gnome.desktop.wm.keybindings.gschema.override'
X11_OPTIONS=$(localectl | awk '{if($0 ~ /X11\s+Options/ ){split($3,arr,",");for(ind in arr) {togl=arr[ind]; sub(/grp:/,"",togl); print togl}}}')
SWITCH_INPUT_OPT=''
echo "X11_OPTIONS=\"$X11_OPTIONS\""
for X11_OPTION in $X11_OPTIONS; do
case "$X11_OPTION" in
'alt_shift_toggle') SWITCH_INPUT_OPT="['<Alt>Shift_L', '<Shift>Alt_R', '<Alt>Shift_R', '<Shift>Alt_L']"; break ;;
'ctrl_alt_toggle') SWITCH_INPUT_OPT="['<Control>Alt_L', '<Alt>Control_R', '<Control>Alt_R', '<Alt>Control_L']"; break ;;
'ctrl_shift_toggle') SWITCH_INPUT_OPT="['<Control>Shift_L', '<Shift>Control_R', '<Control>Shift_R', '<Shift>Control_L']"; break ;;
'lalt_lshift_toggle') SWITCH_INPUT_OPT="['<Alt>Shift_L']"; break ;;
'lctrl_lshift_toggle') SWITCH_INPUT_OPT="['<Control>Shift_L']"; break ;;
'rctrl_rshift_toggle') SWITCH_INPUT_OPT="['<Control>Shift_R']"; break ;;
'alts_toggle') SWITCH_INPUT_OPT="['<Alt>Alt_L', '<Alt>Alt_R']"; break ;;
'ctrls_toggle') SWITCH_INPUT_OPT="['<Control>Control_L', '<Control>Control_R']"; break ;;
'shifts_toggle') SWITCH_INPUT_OPT="['<Shift>Shift_L', '<Shift>Shift_R']"; break ;;
'alt_caps_toggle') SWITCH_INPUT_OPT="['<Alt>Caps_Lock']"; break ;;
'shift_caps_toggle') SWITCH_INPUT_OPT="['<Shift>Caps_Lock']"; break ;;
'win_space_toggle') SWITCH_INPUT_OPT="['<Super>space']"; break ;;
*) ;;
esac
done
systemctl disable $SERVICE_NAME
[ -z "$SWITCH_INPUT_OPT" ] && exit
if [ -f $GSCHEMA_FILE ]; then
TMP_FILE=$(mktemp /tmp/gnome-keyboard-toogle-configure_XXXXXXXXX)
sed "s/switch-input-source-backward.*$/switch-input-source-backward=${SWITCH_INPUT_OPT}/g" $GSCHEMA_FILE >$TMP_FILE || exit 1
mv -f $TMP_FILE $GSCHEMA_FILE
else
cat <<EOF >$GSCHEMA_FILE
[org.gnome.desktop.wm.keybindings]
switch-input-source-backward=$SWITCH_INPUT_OPT
EOF
fi
glib-compile-schemas /usr/share/glib-2.0/schemas