Autoconfiguration of layout change at first start

i9 0.3.6
Dmitry Samoylik 3 months ago
parent 3344dbbfc8
commit 84daadda1c

@ -0,0 +1,9 @@
[Unit]
Description=Autoconfiguration of layout change at first start
[Service]
Type=oneshot
ExecStart=/usr/bin/gnome-keyboard-toogle-configure.sh
[Install]
WantedBy=multi-user.target

@ -0,0 +1,48 @@
#!/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
Loading…
Cancel
Save