Switch keyboard layout on the fly

Quick to answer questions about finding your way around Linux Mint as a new user.
Forum rules
There are no such things as "stupid" questions. However if you think your question is a bit stupid, then this is the right place for you to post it. Stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions use the other forums in the support section.
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
regmar
Level 3
Level 3
Posts: 106
Joined: Sun Aug 26, 2018 7:44 pm
Location: Canada

Switch keyboard layout on the fly

Post by regmar »

When I click on Thunderbird icon, I would like this app to use a keyboard layout different than the default one. Something possible?
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.
Mint 21.3 Cinnamon - Intel NUC11
dave0808
Level 5
Level 5
Posts: 971
Joined: Sat May 16, 2015 1:02 pm

Re: Switch keyboard layout on the fly

Post by dave0808 »

It should be possible. Though I am unable to help with all the details.

The launcher should simply be invoking the command thunderbird (it does on my system), which will mean that your user's PATH will be used to determine which command to launch. Therefore you can effectively intercept this by creating a shell script with the same name in $HOME/.local/bin. In the script, set the keyboard layout that you require, before launching the actual program.

For example:-

Code: Select all

echo -e '#!/bin/bash\n\n#some command here\n/bin/thunderbird $@\n' > $HOME/.local/bin/thunderbird
chmod 700 $HOME/.local/bin/thunderbird
The keyboard layout can apparently be changed with the setxkbmap command. I don't have multiple layouts, so haven't used this personally. It may also be necessary to change the general keyboard settings for your user to allow different layouts for individual windows. This is done within "System Settings" -> "Keyboard" (in the Hardware section) -> Layouts.

Hope this helps. Make sure to take a backup before messing about with the settings in case you do something that you can't recover from.
regmar
Level 3
Level 3
Posts: 106
Joined: Sun Aug 26, 2018 7:44 pm
Location: Canada

Re: Switch keyboard layout on the fly

Post by regmar »

I tried your suggestion before I posted. I have a script to launch Thunderbird and I added setxkbmap -layout ca but the layout is changed for all apps unless I misunderstood something. In addition, setxkbmap removes the keyboard applet from the bottom right panel.
Mint 21.3 Cinnamon - Intel NUC11
cfb
Level 3
Level 3
Posts: 153
Joined: Sun Nov 08, 2015 3:36 am

Re: Switch keyboard layout on the fly

Post by cfb »

You don't say which desktop environment you use, but at least in Xfce you can add a keyboard-layout-switcher to the panel. In its properties you can select if it should manage the keyboard layout per application, per window or globally.
If you select "per application" I believe you can set a layout when Thunderbird is open and active, and then it will automatically switch to that layout whenever Thunderbird is opened.

I must admit I have not tried it.
regmar
Level 3
Level 3
Posts: 106
Joined: Sun Aug 26, 2018 7:44 pm
Location: Canada

Re: Switch keyboard layout on the fly

Post by regmar »

Thanks for your reply, I use Cinnamon. Right now, I can press Alt+Shift to switch layout for a specific window, which is okay but I would like to go one step further and have it done during application launch. As far as I know, I cannot manage the keyboard layout per application as it seems the case for Xfce.
Mint 21.3 Cinnamon - Intel NUC11
User avatar
spamegg
Level 13
Level 13
Posts: 4856
Joined: Mon Oct 28, 2019 2:34 am
Contact:

Re: Switch keyboard layout on the fly

Post by spamegg »

regmar wrote: Fri Dec 03, 2021 12:10 pm Thanks for your reply, I use Cinnamon. Right now, I can press Alt+Shift to switch layout for a specific window, which is okay but I would like to go one step further and have it done during application launch. As far as I know, I cannot manage the keyboard layout per application as it seems the case for Xfce.
There is a setting "Allow different layouts for individual windows", does that help you?
keyb.png
regmar
Level 3
Level 3
Posts: 106
Joined: Sun Aug 26, 2018 7:44 pm
Location: Canada

Re: Switch keyboard layout on the fly

Post by regmar »

The setting "Allow different layouts for individual windows" allows to switch layout with Alt+Shift (or other keys) for a specific window leaving the others to default layout. This is what I am using now. However if I switch the layout say for Thunderbird and later I close this application, I loose the specific layout, Thunderbird will come back to the default layout once reopened. This is why I would like to be able to switch the layout at launch time from a command within a script.
Mint 21.3 Cinnamon - Intel NUC11
Locked

Return to “Beginner Questions”