Alter.Org.UA
 << Back Home EN en   Donate Donate

Alt+Shift for Input switch under newer Ubuntu

Use Alt+Shift ot Ctrl+Shift

For some reason newer Ubuntu (e.g. 20) with Gnome prevents from setting Ctrl-Shift or Alf-Shift sequence for keybpoard layout switching. But there is a method to make it working in the was some of us are used to.

gsettings list-recursively | grep  org.gnome.desktop.wm.keybindings | grep input
org.gnome.desktop.wm.keybindings switch-input-source ['<Super>space', 'XF86Keyboard']
org.gnome.desktop.wm.keybindings switch-input-source-backward ['<Shift><Super>space', '<Shift>XF86Keyboard']

And now some magic

gsettings set org.gnome.desktop.wm.keybindings switch-input-source "['<Alt>Shift_L']"
or
gsettings set org.gnome.desktop.wm.keybindings switch-input-source "['<Control>Shift_L']"

Static layout switching order

A bit more complicated. Newer Gnome uses adaptive layout order, not cycling in the same order. If you want to have static order, e.g. always EN - RU - UK - EN ..., then you need external script :( We shall bind it to custom sequence. If you need legacy shortcut (Alt+Shift or Ctrl+Shift), follow instruction below

/usr/local/bin/kbd_static_order.sh

#!/bin/bash

if [ "x$1" = "x" ] ; then
  totalLang=$(gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell --method org.gnome.Shell.Eval "imports.ui.status.keyboard.getInputSourceManager()._mruSources.length" | grep -oP "(?<=').*?(?=')")
  currentLang=$(gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell --method org.gnome.Shell.Eval "imports.ui.status.keyboard.getInputSourceManager().currentSource.index" | grep -oP "(?<=').*?(?=')")
  declare -i math=$currentLang+1
else
  math=$1
  declare -i totalLang=$math+1
fi

if [ "$math" -lt "$totalLang" ]; then
  gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell --method org.gnome.Shell.Eval "imports.ui.status.keyboard.getInputSourceManager().inputSources["$currentLang+1"].activate()"
else
  gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell --method org.gnome.Shell.Eval "imports.ui.status.keyboard.getInputSourceManager().inputSources[0].activate()"
fi

Make it executable

sudo chmod 755 /usr/local/bin/kbd_static_order.sh

Now go to Settings - Keyboard shortcuts - Typing and reset Switch to next input source to default. Then add new custom shortcut at the bottom, lets name it Switch to next input source static with some shortcut, e.g. Alt-Z and path to executable /usr/local/bin/kbd_static_order.sh

sudo apt install dconf-cli
dconf dump /org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/
[custom0]
binding='<Alt>Z'
command='/usr/local/bin/kbd_static_order.sh'
name='Switch to next input source static'

And now change shortcut

dconf write "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/binding" \
      "'<Alt>Shift_L'"

Shortcuts to individual layouts

You need the same kbd_static_order.sh< with parameter. 0 corresponds to the 1st language in layout list. So, make custom shortcuts like Win+F1 with command '/usr/local/bin/kbd_static_order.sh 0', Win+F2 with '/usr/local/bin/kbd_static_order.sh 1', etc.

2022.09.15


FB or mail alterX@alter.org.ua (remove X)   Share
Автор: Alter (Александр А. Телятников) Сервер: Apache+PHP под FBSD © 2002-2024