3

I use xmodmap to swith Ctrl and Alt keys:

~ $> cat .Xmodmap
!
! based on: http://www.emacswiki.org/emacs/SwapControlAltAndCapsLock#toc8
!

!----------------------------------------------------------
! Swap Control and Alt keys, both sides
!----------------------------------------------------------

! First clear all modifiers & control
clear control
clear mod1
clear mod4

! Swap Control_L and Alt_L
keycode  64 = Control_L
keycode  37 = Alt_L Meta_L

! Menu becomes Alt_R Meta_R (AltGr)
! keycode 135 = Alt_R Meta_R

! Define Control_R and Alt_R similar to Control_L and Alt_L
keycode 108 = Control_L
keycode 105 = Alt_L Meta_L

! We need to set keycodes first, as some programs (emacs!) read
! the key names and seem to ignore what's below.
add mod1    = Alt_L Alt_R Meta_L Meta_R
add mod4    = Super_L Super_R
add control = Control_L Control_R


!------------------------------------------
! Caps_Lock becomes an additional BackSpace
!------------------------------------------
! remove lock = Caps_Lock
! keysym Caps_Lock = BackSpaceclear control
! clear mod1
! keycode 37 = Alt_L Meta_L
! keycode 64 = Control_L
! keycode 105 = Alt_R Meta_R
! keycode 108 = Control_R
! add control = Control_L Control_R
! add mod1 = Alt_L Meta_L Alt_R Meta_R

That works fine; however, when I start ibus, the key mappings are overtaken by ibus. Is there a way to avoid this?

Nick
  • 155

4 Answers4

1

Did you already try the following.

...try enabling the “Use system keyboard layout” option under the “Advanced” tab in the IBus Preferences.

Hint from http://tots.1o24.org/how-to-stop-ibus-from-removing-your-xmodmap-mappings/

f01
  • 246
1

It's not exactly an IBus problem (IBus has problems, a lot(1), but I do not think this one).

Ubuntu, as any modern Linux, uses xkb extension to define the keyboard. xmodmap is sort-of legacy thing that is not guaranteed to work with it.

The documentation is quite lacking. Arch Linux (as ever) has a good page. I have managed to adapt my keyboard to avoid switching, which is plagued by bugs in Ubuntu Gnome(2).

The system is complex --- I found some help here, and here. But understanding how to change modifiers is still out of my set of skills... and I suspect very few people around understand it (scary).


Footnotes:

(1) Keyboard keeps defaulting to wrong layout, https://bugs.launchpad.net/ubuntu/+source/gnome-settings-daemon/+bug/1246272, much more...

(2) https://bugs.launchpad.net/ubuntu/+source/gnome-settings-daemon/+bug/1218322, https://bugs.launchpad.net/gnome-settings-daemon/+bug/1244090

Rmano
  • 31,947
  • Thank you. The problem seems comlicated. Is there another way to remap key except xmodmap? That is, get ibus work first, and then remap ctrl and alt keys. – Nick Dec 02 '14 at 09:27
  • ...probably it's possible, but never tried it. Another link could be http://xkbconfig.livejournal.com/7996.html. – Rmano Dec 02 '14 at 09:34
  • ...maybe this one: http://unix.stackexchange.com/a/10008/52205 --- it's a bit of a hammer way, but may work. Or more cleanly here: http://unix.stackexchange.com/questions/65507/use-setxkbmap-to-swap-the-left-shift-and-left-control/65600#65600 (although seems that the second one conflicts with IBus, again. I hate IBus). – Rmano Dec 02 '14 at 10:05
1
  • Actually, there is an ibus option hidden from its setup GUI to reload .xmodmap on method change.

    dconf write /desktop/ibus/general/use-xmodmap true
    

    I couldn't tried it yet, but you may check /etc/dconf/db/ibus.d/00-upstream-settings for available options.

    I'm using Xubuntu 16.04, it could be different than 14.04.

  • Another way

    1. Stop ibus from using system keymaps

      dconf write /desktop/ibus/general/use-system-keyboard-layout false
      

      or using ibus-setup

    2. Change its own key mappings

      $ cat /usr/share/ibus/keymaps/modifiers 
      keycode 29 = Control_L
      keycode 42 = Shift_L
      keycode 54 = Shift_R
      keycode 56 = Alt_L
      keycode 97 = Control_R
      keycode 100 = Alt_R
      keycode 125 = Super_L
      keycode 126 = Super_R
      keycode 127 = Menu
      

      Reference: for configuration path

      ibus_keymap_get ()

      IBusKeymap * ibus_keymap_get  (const gchar *name);
      
      Get an IBusKeymap associated with the giving name.
      
      This function loads the keymap file specified in name in
       the IBUS_DATA_DIR/keymaps directory.
      
      name :
        The keymap file to be loaded, such as 'us', 'jp'.
      
      Returns :
        An IBusKeymap associated with the giving name; or NULL if failed.
      
user.dz
  • 48,105
0

I've already faced this problem before and finally found out a solution for this by making a keyboard shortcut executing a command that has two jobs:

  • Send Alt + Shift keystroke to system (this key combination will change the input source of IBUS)
  • Load my xmodmap profile into system keymap

Take a look on my post for more detailed information about this solution: http://blog.z1k.pw/?p=60

TheOdd
  • 3,012
GiapLv
  • 1