LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 02-18-2011, 09:39 PM   #1
Berrex
LQ Newbie
 
Registered: Feb 2011
Distribution: Arch
Posts: 6

Rep: Reputation: 0
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.

Last edited by Berrex; 02-18-2011 at 09:42 PM.
 
Old 02-20-2011, 08:45 AM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946
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.
 
Old 02-20-2011, 11:37 PM   #3
Berrex
LQ Newbie
 
Registered: Feb 2011
Distribution: Arch
Posts: 6

Original Poster
Rep: Reputation: 0
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?
 
Old 02-21-2011, 04:06 PM   #4
Berrex
LQ Newbie
 
Registered: Feb 2011
Distribution: Arch
Posts: 6

Original Poster
Rep: Reputation: 0
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[macbook] various problems, touchpad, skype, etc fox91 Debian 0 11-22-2007 08:14 AM
Linux on a macbook/macbook pro... any experiences/problems, or is it even necessary? enigma_0Z Linux - Laptop and Netbook 13 09-14-2007 10:29 PM
Xubuntu on Macbook pro - video lag, and compile requirements? rose_bud4201 Ubuntu 2 03-14-2007 10:42 PM
How to make Control_L + Alt_L act like Alt_R (Alt Gr)? THROBiX Linux - General 3 07-26-2006 08:53 AM
KDE Intercepts the Super_L Key Tim Johnson Linux - General 7 08-22-2005 11:12 AM


All times are GMT -5. The time now is 05:34 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration