7

How can I stop the Alt key from triggering the menu bar of applications in Ubuntu 19.10?

I know that there are these post 1, post 2, and post 3, as well as https://docs.substance3d.com/spdoc/impossible-to-use-the-alt-keyboard-shortcut-on-linux-143720782.html but those solutions are no longer applicable. I did try searching for a similar option to the one in the answer of those questions but with no success.

K7AAY
  • 17,202
Adam
  • 2,638
  • 1
    @K7AAY No I have tried this approach initially but in 19.10 that option doesn't exist. – Adam Mar 12 '20 at 22:14
  • 1
    @K7AAY I tried initially the first one you linked but after that I installed dconf-editor and tried it too. – Adam Mar 12 '20 at 22:15
  • @K7AAY It doesn't work either. There is a reason it doesn't have an accepted solution. – Adam Mar 12 '20 at 22:33
  • Thanks for trying them all. I've moved them into the Question so folks will know what not to do if they are troubled by this on their systems. – K7AAY Mar 12 '20 at 22:42
  • @K7AAY On the contrary thank you for finding all of them. I searched a lot and I didn't manage to find them all myself. :) – Adam Mar 12 '20 at 22:45

2 Answers2

5

You can do so by modifying the XKB configuration file like so:

  1. Edit the XKB /usr/share/X11/xkb/symbols/pc file by running the following command in the terminal:
sudo nano /usr/share/X11/xkb/symbols/pc
  1. Find the line that contain include "altwin(meta_alt)" like so:
key <ALT>  {        [ NoSymbol, Alt_L       ]       };
include "altwin(meta_alt)"
  1. Comment it out by adding // before it like so:
key <ALT>  {        [ NoSymbol, Alt_L       ]       };
// include "altwin(meta_alt)"
  1. Save the file and exit the editor by pressing Ctrl + X then press Y.

  2. Clear the XKB cache by running the following command in the terminal:

sudo rm -rf /var/lib/xkb/*
  1. Reboot your system to activate your new XKB configuration or alternatively you can avoid the reboot and try to reload the new XKB configuration by setting an XKB map layout using the following command in the terminal:
setxkbmap -layout us

Notice:

If you choose to avoid the reboot and reload the new XKB configuration withe this command, layout switching will only be possible through the terminal and layout switching using hotkeys or the GUI will stop responding until you reboot the system.

  1. Test your key.

This solution should disable the ALT functionality, but the physical key Alt itself will remain functional. So the key code can be detected by a utility like xev and then remapped for example to "Super Right" like so (replacing 64 with the detected key number):

xmodmap -e 'keycode 64 = Super_R'

It will then be available for use as a hot key or shortcut key exactly like ALT minus the undesired behavior.

Please refer to this answer for help

Raffa
  • 32,237
  • Will that not remove all Alt functionality? – vanadium Mar 13 '20 at 12:48
  • @vanadium It will, but the key itself will remain functional. So the key code can be detected by a utility like xev and remapped to for example to "Super Right" like so xmodmap -e 'keycode 64 = Super_R'. It will then be available for use as a hot key or shortcut key exactly like ALT minus the undesired behavior. This answer will help. – Raffa Mar 13 '20 at 15:37
  • Thank you but now I can't change the layout of my keyboard and so I can't write in a different language, which is far worse than just activating once in a while the menu bar. :P – Adam Mar 15 '20 at 18:28
  • @Adam Do not worry. Just reboot your system and layout switching will work again. This is because of changing the layout from the terminal to avoid the reboot. That is why a wrote in my answer "reboot" first :) – Raffa Mar 15 '20 at 19:23
  • I did reboot and that when it took effect. Before rebooting nothing had changed and the Alt key worked normally. – Adam Mar 15 '20 at 19:36
  • @Adam If you have Alt + Shift as the layout switching keys, then you need to chose another combination. You can remap the phisycal Alt key for example to "Super Right" like so xmodmap -e 'keycode NUMBER = Super_R' and reconfigure your hotkeys to be Syper R + Shift and you will end up using the same physical Alt + Shift keys to switch layouts without activating the app menu at all every time you press the Alt key. Meanwhile you can use the GUI by clicking on the layout indicator and selecting a different language. – Raffa Mar 15 '20 at 19:45
  • I have years of experience of switching using that combination so it is not easy to just change it thus I will have to tolerate the menu activation problem. Anyway given that your answer does the job (kind of) and it doesn't seem to appear a better one yet I will accept it. Thank you for posting it! – Adam Mar 15 '20 at 20:07
  • The problem that author is trying to solve is caused by this bug https://gitlab.freedesktop.org/xorg/xserver/-/issues/258 there are patches fixing it but they are intentionally ignored by xkb maintainers – ZAB Feb 10 '21 at 03:23
  • i know that its not ok to write here "thank you" and so on, so I will be happy to shake your hand when we meet in person! just one question: WTH is so complicated? it works, but it even uglier then snap – Vasilii Suricov Feb 14 '24 at 13:28
0

I had this issue on Ubuntu 18.04 and it was very annoying! I solved it by editing the following files:

~/.config/gtk-4.0/settings.ini
~/.config/gtk-3.0/settings.ini

and adding the following lines to it:

gtk-enable-mnemonics=0
gtk-auto-mnemonics=0

After this logout and then login.

Abhay Patil
  • 2,705
Udi
  • 1
  • If you're coming here from an ubuntu distro (e.g. pop-os), are a previous Mac user and using Kinto to get that mac-feel, and find yourself struggling with your ALT/OPT keyboard navigation to hop around the editor, textboxes... this is the way. if the settings.ini doesn't exist, go ahead and make it, add the lines, log out and back in. reinstall Kinto, and bam. problem solved. – Artokun May 22 '23 at 19:29