LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Problems Swapping Alt_L and Super_L on MacBook (Xubuntu 10.10) (https://www.linuxquestions.org/questions/linux-software-2/problems-swapping-alt_l-and-super_l-on-macbook-xubuntu-10-10-a-863653/)

Berrex 02-18-2011 09:39 PM

Problems Swapping Alt_L and Super_L on MacBook (Xubuntu 10.10)
 
Hi everybody. I'm running into some trouble swapping my Alt_L and Super_L keys on my 2006 Apple MacBook. For starters, I'm running Xubuntu 10.10, and I want to swap the keys because Apple's standard key mapping has the two keys reversed. This is going to be a lengthy post with lots of information, and I apologize for that, but I'm hoping that this information will be helpful.

For starters, running "xmodmap -pk" without having made any prior modifications to .bashrc or .xmodmap shows me the following:
Code:

64            0xffe9 (Alt_L)        0xffe7 (Meta_L)        0xffe9 (Alt_L)        0xffe7 (Meta_L)       
 133            0xffeb (Super_L)        0x0000 (NoSymbol)        0xffeb (Super_L)       
 204            0x0000 (NoSymbol)        0xffe9 (Alt_L)        0x0000 (NoSymbol)        0xffe9 (Alt_L)       
 206            0x0000 (NoSymbol)        0xffeb (Super_L)        0x0000 (NoSymbol)        0xffeb (Super_L)

I've appended the following lines to my ~/.bashrc file:
Code:

xmodmap -e 'keycode 64 = Super_L'
xmodmap -e 'keycode 133 = Alt_L'

After logging out and back in, xev is reporting these keys properly as:
Code:

KeyPress event, serial 34, synthetic NO, window 0x5400001,
    root 0xad, subw 0x0, time 5496399, (102,126), root:(655,451),
    state 0x8, keycode 64 (keysym 0xffeb, Super_L), same_screen YES,
    XLookupString gives 0 bytes:
    XFilterEvent returns: False

KeyPress event, serial 34, synthetic NO, window 0x5400001,
    root 0xad, subw 0x0, time 5502975, (102,126), root:(655,451),
    state 0x0, keycode 133 (keysym 0xffeb, Super_L), same_screen YES,
    XKeysymToKeycode returns keycode: 64
    XLookupString gives 0 bytes:
    XmbLookupString gives 0 bytes:
    XFilterEvent returns: False

However, the changes do not seem to be taking effect. So, I also tried creating an ~/.xmodmap file with the following:
Code:

keycode 64 = Super_L
keycode 133 = Alt_L

After this, when I run $ xmodmap -pk in console, I notice that I have the following lines:
Code:

64            0xffeb (Super_L)        0x0000 (NoSymbol)        0xffeb (Super_L)
133            0xffe9 (Alt_L)        0x0000 (NoSymbol)        0xffe9 (Alt_L)
204            0x0000 (NoSymbol)        0xffe9 (Alt_L)        0x0000 (NoSymbol)        0xffe9 (Alt_L)               
206            0x0000 (NoSymbol)        0xffeb (Super_L)        0x0000 (NoSymbol)        0xffeb (Super_L)

So I modified ~/.xmodmap to read:
Code:

keycode 64 = Super_L
keycode 133 = Alt_L
keycode 204 = Super_L
keycode 206 = Alt_L

And now xev is reporting key 64 (what I want to be Super_L) as Alt_L and key 133 (which I want to be Alt_L) as Super_L. So I then proceeded to add two lines to my ~/.bashrc file so that it now reads:
Code:

xmodmap -e 'keycode 64 = Super_L'
xmodmap -e 'keycode 133 = Alt_L'
xmodmap -e 'keycode 204 = Super_L'
xmodmap -e 'keycode 206 = Alt_L'

Now when I start up, both xev and xmodmap -pk are reporting exactly the configuration I want, with Alt_L and Super_L swapped (Alt_L = 133 and 206; Super_L = 64 and 204), but these changes are not actually taking effect. I have no idea what gives with that. I have some suspicions about the duplicate entries for these keys when running "xmodmap -pk." Xev only reports the keys as 64 and 133, but xmodmap -pk reports both 64/133 and 204/206. Is it normal for these modifier keys to be listed twice in xmodmap like this?

For what it's worth, the only thing that works is running gnome-keyboard-properties, in which I have my keyboard layout settings adjusted so that Alt_L and Super_L are swapped. While this works perfectly after I open and close it, it's not exactly an optimal solution at all, as I also had to install all kinds of other GNOME applications along with it, including GNOME's appearance and startup management programs, which are interfering with XFCE's own settings. But, after running gnome-keyboard properties, the output of running "xmodmap" in terminal changes from (changes in bold):
Code:

shift      Shift_L (0x32),  Shift_R (0x3e)
lock        Caps_Lock (0x42)
control    Control_L (0x25),  Control_R (0x69)
mod1        Alt_L (0x40),  Alt_R (0x6c),  Meta_L (0xcd)
mod2        Num_Lock (0x4d)
mod3     
mod4        Super_L (0x85),  Super_R (0x86),  Super_L (0xce),  Hyper_L (0xcf)
mod5        ISO_Level3_Shift (0x5c),  Mode_switch (0xcb)

to:
Code:

shift      Shift_L (0x32),  Shift_R (0x3e)
lock        Caps_Lock (0x42)
control    Control_L (0x25),  Control_R (0x69)
mod1        Alt_R (0x6c),  Alt_L (0x85),  Meta_L (0xcd)
mod2        Num_Lock (0x4d)
mod3     
mod4        Super_L (0x40),  Super_L (0xce),  Hyper_L (0xcf)
mod5        ISO_Level3_Shift (0x5c),  Mode_switch (0xcb)

I am thoroughly confused; could somebody perhaps shed some light on what's going on? I will throw it out there that this is the first time I've attempted to use xmodmap to modify my keyboard mapping, and everything above is the result of researching on Google, so perhaps I'm missing a critical step.

Thanks a ton.

David the H. 02-20-2011 08:45 AM

Well, for one thing, .bashrc usually only gets read when you start a non-login bash terminal (see the INVOCATION section of the bash manpage), and your desktop environment probably doesn't use bash to set its environment anyway, so your commands aren't being loaded when your x-session starts. Try creating a script for the command and launch it with your DE's autostart function instead.

Berrex 02-20-2011 11:37 PM

Well I gave that a try, and no dice. Neither xev or xmodmap -pk report any changes at all after starting up, but they report correctly after I run the script manually after logging in. I'm guessing the script isn't running at startup for some reason, but either way, the changes still don't take effect on my keyboard after running the script.

Here's the script I made. I called it xmodmap-changes and it's located in ~/.scripts/xmodmap-changes.
Code:

#!/bin/bash
xmodmap -e 'keycode 64 = Super_L'
xmodmap -e 'keycode 133 = Alt_L'
xmodmap -e 'keycode 204 = Super_L'
xmodmap -e 'keycode 206 = Alt_L'

Then, I gave it executable permissions with chmod 755, and added this to my startup items: sh /home/berrex/.scripts/xmodmap-changes

Did I go wrong somewhere in that process?

Berrex 02-21-2011 04:06 PM

I found a command that actually works!

$ setxkbmap -option altwin:swap_lalt_lwin

And that's it! Alt_L and Super_L are then swapped and function properly. However, the changes are undone when restarting, so I removed the xmodmap commands from the original script and replaced them with the command above, added the script to my startup list, and everything is working beautifully now, with Alt_L and Super_L swapped. Hooray!

Thank you for the suggestion David the H. It did help me come to my final solution, and I learned a little about scripting to boot. :D


All times are GMT -5. The time now is 07:53 PM.