I have always found the integration of X11 apps in Mac OS X quite alright, apart from the fact that for a native Mac application you use the apple key for keyboard shortcut and for an X11 app you use the control key. So, for instance, if you want to copy and cut a text between, let’s say, Firefox (native) and OpenOffice (X11), you need to remember to use apple+c in Firefox and ctrl+v in OpenOffice. Needless to say it is a hassle and it makes the interoperability between native and X11 applications quite useless (did I mention I bought M$ Office on Mac for this very reason?).
A first solution to solve that problem would be to switch the mapping between the ctrl and apple key inside X11, for instance using the tool xmodmap. But then we would have the disadvantage that we would need to use the apple key instead of ctrl in every situation, e.g. including within command line tools in xterm (the X11 terminal). Then, when using the command line text editor nano within xterm, we would need to press apple+o to save a text and apple+x to exit, while for nano within the non-X11 terminal, we would need to use the control key instead. So this solution appears to me as unideal.
In fact, as I am not using the meta key in X11, which is originally at the place of the apple key, I can just assign the control key to the apple key and get rid of the meta. This would ensure that I can go on using the apple key for keyboard shortcuts inside X11 — e.g. apple + c in OpenOffice — while keeping the mapping of the control key for use with command line tools.
This modification is pretty straightforward. Just create a .Xmodmap file inside your home folder with the following lines (or extend it accordingly if it already exists):
! ~/.Xmodmap
clear Mod2
clear control
keycode 63 = Control_L
keycode 67 = Control_L
add control = Control_L
In fact, what we do here is first to clear the two logical keys corresponding to meta and control, assign Control_L to the two key we want, and recreate uniquely the control logical key. When restarting X11, your new mapping will be automatically activated. You can test it using xev or xmodmap -p.
Any comment welcome.
February 9th, 2007 at 6:52 pm
That would be great for Gimpshop but it didn’t work for me.
I created a .Xmodmap file at $HOME like you said.
control still roles X11.
I have auto focus windows on.
Any thoughts ?
February 9th, 2007 at 9:57 pm
Hi Pedro,
You can check that the mapping is right by using (under X11) the xev tool. An output for the right configuration while pressing and releasing the command (keycode 67) and then the control key (63) is the following:
KeyPress event, serial 24, synthetic NO, window 0×800001,
root 0×57, subw 0×0, time 341536879, (1,105), root:(723,310),
state 0×0, keycode 67 (keysym 0xffe3, Control_L), same_screen YES,
XKeysymToKeycode returns keycode: 63
XLookupString gives 0 bytes:
XmbLookupString gives 0 bytes:
XFilterEvent returns: False
KeyRelease event, serial 24, synthetic NO, window 0×800001,
root 0×57, subw 0×0, time 341536950, (1,105), root:(723,310),
state 0×4, keycode 67 (keysym 0xffe3, Control_L), same_screen YES,
XKeysymToKeycode returns keycode: 63
XLookupString gives 0 bytes:
KeyPress event, serial 24, synthetic NO, window 0×800001,
root 0×57, subw 0×0, time 341537919, (1,105), root:(723,310),
state 0×0, keycode 63 (keysym 0xffe3, Control_L), same_screen YES,
XLookupString gives 0 bytes:
XmbLookupString gives 0 bytes:
XFilterEvent returns: False
KeyRelease event, serial 24, synthetic NO, window 0×800001,
root 0×57, subw 0×0, time 341537974, (1,105), root:(723,310),
state 0×4, keycode 63 (keysym 0xffe3, Control_L), same_screen YES,
XLookupString gives 0 bytes:
In both cases, the Control_L logical key is associated with the physical key. Does it help you further? If not, which version of Mac OS X do you have (I have tested this solution with OS X 10.4.8). Can you also post the output of xev and xmodmap -p for your mapping?
Cheers,
February 10th, 2007 at 12:03 am
Nope. Does not work here with Mac OS 10.4 and latest Apple X11.
Here is what xev gives me. I even tried running the Xmodmap file by hand, line by line, with the xmodmap -e command.
KeyRelease event, serial 25, synthetic NO, window 0×2200001,
root 0×57, subw 0×0, time 358902231, (131,245), root:(231,367),
state 0×4, keycode 67 (keysym 0xffe3, Control_L), same_screen YES,
XLookupString gives 0 bytes:
xmodmap -p gives me
$ xmodmap -p
xmodmap: up to 2 keys per modifier, (keycodes in parentheses):
shift Shift_L (0×40), Shift_R (0×44)
lock Caps_Lock (0×41)
control Control_L (0×43), Control_R (0×46)
mod1 Mode_switch (0×42), Mode_switch (0×45)
mod2 Meta_L (0×3f)
mod3
mod4
mod5
KeyPress event, serial 25, synthetic NO, window 0×2200001,
root 0×57, subw 0×0, time 358903824, (131,245), root:(231,367),
state 0×0, keycode 63 (keysym 0xffe7, Meta_L), same_screen YES,
XLookupString gives 0 bytes:
XmbLookupString gives 0 bytes:
XFilterEvent returns: False
February 10th, 2007 at 12:56 am
Hi Daniel,
From your output of xev, I see that the key mapping for the Command key (67) has not been changed, as it is still associated with Meta_L. The output of xmodmap -p shows also that mod2 is still defined, which should not be the case anymore. My output of xmodmap -p is the following:
shift Shift_L (0×40), Shift_R (0×44)
lock Caps_Lock (0×41)
control Control_L (0×3f), Control_L (0×43)
mod1 Mode_switch (0×42), Mode_switch (0×45)
mod2
mod3
mod4
mod5
Which hardware are you running Mac OS 10.4 on? I use a MacBook.
February 10th, 2007 at 7:06 am
We are having an issue with Mac and a Java applet in OSX, it worked fine in panther but now the tab key wont work… do you think xmodmap could help or since java isnt part of x11 it wouldnt have any effect ?
The java applet does execute x11 code on the server it is connecting to, it doesnt invoke the lil X app on my mac.
February 10th, 2007 at 11:31 am
Hi Mike,
Unfortunately, I think xmodmap can just be used within X11 to change or tune the key mapping. It won’t have any effect for native OS X applications.
There should be another way to solve your problem.
Cheers,
February 12th, 2007 at 3:00 am
Hi pajai,
This is my xev output:
KeyPress event, serial 24, synthetic NO, window 0xa00001,
root 0×57, subw 0×0, time 5053848, (55,141), root:(591,185),
state 0×0, keycode 63 (keysym 0xffe7, Meta_L), same_screen YES,
XLookupString gives 0 bytes:
XmbLookupString gives 0 bytes:
XFilterEvent returns: False
KeyRelease event, serial 24, synthetic NO, window 0xa00001,
root 0×57, subw 0×0, time 5054145, (55,141), root:(591,185),
state 0×10, keycode 63 (keysym 0xffe7, Meta_L), same_screen YES,
XLookupString gives 0 bytes:
____
checking or unchecking “unable keyboard shortcut” didn’t help either.
Running a MacBook Pro with all the latest and greatest updates.
February 12th, 2007 at 8:32 am
Hi Pedro,
Can you post also the output of xmodmap -p?
Cheers,
February 12th, 2007 at 2:56 pm
xmodmap: up to 2 keys per modifier, (keycodes in parentheses):
shift Shift_L (0×40), Shift_R (0×44)
lock Caps_Lock (0×41)
control Control_L (0×43), Control_R (0×46)
mod1 Mode_switch (0×42), Mode_switch (0×45)
mod2 Meta_L (0×3f)
mod3
mod4
mod5
Thanks a lot for the help!
February 14th, 2007 at 8:47 am
Hi Pedro,
It seems that xmodmap has not loaded correctly the .Xmodmap file. I see this because mod2 is still set (should be cleared) and there is no mapping for the keycode 63 (hex 0×3f) in the row regarding control. (I see also that you have a Control_R defined, what I don’t have on my MacBook).
Can you try to execute manually xmodmap by launching ‘xmodmap ~/.Xmodmap’? Do you still get the same output when checking with xmodmap -p?
Cheers,
February 15th, 2007 at 4:09 am
For this to work, you must make sure that in the X11 preferences on the “Input” tab “Follow system keyboard layout” is *unchecked*. Also, if you uncheck “Enable keyboard shortcuts under X11″ will prevent that some shortcuts will be used by X11 itself, like COMMAND+Q, etc.
Cheers
February 27th, 2007 at 3:06 pm
Hi pajai,
It worked !
I manually executed “modmap ~/.Xmodmap” and it’s great. Thanks !
Sorry for the late reply.
February 27th, 2007 at 11:15 pm
Hi pedro,
Thank you for your feedback. Nice to see that it worked.
Cheers,
June 30th, 2007 at 2:22 pm
Hi pat - I just got this working thanks to your comments here. I am now a very happy gimpshop user. Thanks, Justin.
July 11th, 2007 at 10:43 am
Hi there. I would like to create a Xmodmap file as well, but unfortunately I have not the slightest idea how to do that. Can somebody please tell me? the home folder your talking about is the one with house icon I take it?
Thanks
Kourouma
January 2nd, 2008 at 9:04 pm
Thanks for this post. Now my favorite applications are almost enjoyable to use in OSX. I wrote up a how-to on my blog covering some of the issues your readers had and issues I had myself. It also covers a few aspects of using Vi since I had to look that up!
X11: Switch Control Key To Apple/Command Key
January 3rd, 2008 at 4:08 am
Cool. Glad it was useful. Your blog entry seems nice indeed.
Cheers,
September 14th, 2008 at 11:58 pm
Hi!
I’m confused. I have osx 10.5 and i can’t get this xmodmap thing to work. Looks like Pedro had the same problem, but i’m not understanding the solution. I’m just trying to get gimp to use command instead of control. Thanks!
Becca
September 15th, 2008 at 8:34 pm
Hi Becca,
I just checked it on my laptop with OSX 10.5. Make sure you have the following two options *unchecked* in the X11 preferences (under ‘input’): ‘Follow system keyboard layout’ and ‘Enable key equivalent under X11′. Now it is working on my laptop.
Cheers,