Toggling between pairs of keyboard layouts

Questions about other topics - please check if your question fits better in another category before posting here
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
pomatador

Toggling between pairs of keyboard layouts

Post by pomatador »

So I generally find the Mint solution to multiple keyboard layouts to be a problem, for two reasons:
  • Only supporting up to four layouts
  • With a full four layouts, it can be a pain to quickly toggle between two that I may want to use concurrently (which I might solve with a keyboard shortcut to toggle between the current & last-used layout, in addition to one to cycle through all layouts)
Currently I have a keyboard shortcut that runs the following script, which cycles through a list of secondary layouts saved to a file, keeping Dvorak as the primary layout:

Code: Select all

#!/bin/bash

# Read kblist, a text file containing a list of layout,variant pairs
num=1
# Initialize lists of options with primary layout dvorak,
layouts=(dvorak)
variants=("")
while IFS= read -r line
do
  # Read layout,variant from file
  settings=(${line//,/ })
  layouts[$num]=${settings[0]}
  variants[$num]=${settings[1]}
  num=`expr $num + 1`
done < [my path]/kblist1

# Cycle second through last options
numm=`expr $num - 1`

layout2=${layouts[1]}
variant2=${variants[1]}
numm=`expr $num - 1`
for n in `seq 2 $numm`; do
  nm=`expr $n - 1`
  layouts[$nm]=${layouts[$n]}
  variants[$nm]=${variants[$n]}
done
layouts[$numm]=$layout2
variants[$numm]=$variant2

# Set layout with new second option
# This line is essentially all of what I have questions about
setxkbmap -layout ${layouts[0]},${layouts[1]} \
  -variant ${variants[0]},${variants[1]}
  
# Save new order of layouts
for n in `seq 1 $numm`; do
  echo ${layouts[$n]},${variants[$n]}
done > [my path]/kblist1
And after I run this to get to the right secondary layout, I can use the shortcut to change layouts in order to

The problems I'm running into with this, which are basically coming out of shortcomings of how I'm using the setxkbmap command, are:
  1. Diverse operations such as connecting to Bluetooth speakers or disabling my touchpad (it has issues) reset the list of layout options (to the last thing I set using the keyboard settings window)
  2. When I use this, it reverts to the first option (Dvorak) which is a problem inasmuch as I'd prefer to follow the option I'm selecting in the Keyboard Layouts item on the panel. (I believe it didn't change back like that when I was using cinnamon; I recently switched to xfce but also rewrote parts of the above script when I did.) Not knowing a way to emulate the behavior of the change-layout shortcut from the command line, the obvious thing to do would be just to switch dvorak and the secondary layout. However, that changes the behavior of shortcuts, so that they're based on the layout I want to be secondary, rather than based on Dvorak. (That also wasn't a problem in cinnamon.)
Which is to say that what I'm trying to do is, within this script,
  1. Set selection of layouts in a persistent way, like I can in the keyboard settings window, and
  2. Set the current layout option in a way that doesn't affect keyboard shortcuts, or equivalently select the layout to use for keyboard shortcuts in a way that doesn't affect the current layout option
Thanks for any help! My basic system info is

Code: Select all

$ inxi -S
System:    Host: ******** Kernel: 3.19.0-32-generic x86_64 (64 bit)
           Desktop: Xfce 4.12.2 Distro: Linux Mint 17.3 Rosa
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Locked

Return to “Other topics”