11 Aug 2006 aristeu   » (Master)

fn <-> ctrl
OK, I'm getting closer to finally swap this 'fn' key with ctrl on mac's keyboard. And I need to do it quickly, before I get used with it. Lemme explain the problem first.
This powerbook has its keyboard and other keys (power button, eject button, etc) behind a bus, called ADB. I heard about some Apple notebooks using USB for its keyboard. But it's not my case. The problem with this is this keyboard controller, even reporting Fn key as a regular key (some controllers don't even let you know that there's a Fn key, making it impossible to do) but do some Fn + key sequence translation in hardware. For example: you have to configure this controller to tell if the F1-F7 keys, while pressed alone will generate a F1-F7 key event or the special functions. This could be pretty anoying: to have F1 key you should press Fn too: ctrl + alt + fn + f1 to switch from console to X. Anyway, the question here is that the keyboard controller _won't_ tell you that Fn + F1 key were pressed, only a F1 key event will show up (or brightness down).
If this processing were done in kernel level (i.e. Fn keypress + F1 would generate a brightness down, processed in kernel) it would be a lot easier to just swap the Fn with Ctrl before this processing and that would have a chance to be included in Linus' tree. But it isn't that simple.
To have this done, we have to know how the controller is configured and translate all the keys back. e.g.: if keypad's '3' is pressed, we must check if fn key were pressed before and if it were, we must generate Ctrl + 'l'. If 'l' is pressed, we must check if Ctrl is pressed and translate it to keypad's '3' killing the other 2 events. Definitely something that should be done in user level. We'll be back to this shortly.
Why don't you buy a real mouse?
One of the top issues for an Anything-but-Mac user to begin to use a mac is the mouse. On desktops it can be easily replaced by other, real, mouse. But in notebooks, it isn't so easy. You can't ignore the touchpad. It's there, built-in, doesn't waste more space in your backpack or workspace. To solve this, some sysctl options were created to emulate the second and third mouse buttons using keyboard keys. On MacOS, instead, applications usually have a modifier + mouse button to emulate other keys. This is a lot nicer because you don't lose one of your keyboard keys. Doing this on kernel isn't easy: this PowerBook has the keyboard behind ADB but the touchpad is an USB device and communicating one with other would be a big kludge and probably won't be accepted for inclusion (I agree with them). So, Michael Hanselmann began to work on inputd, a generic userspace daemon to do this kind of remap. Just for fun, I decided to write a simple application only to solve this specific problem: emulate second and third buttons using a key modifier: apple_mouse was born. But I wasn't satisfied with this. I really hate this Fn key, so I could use it as key modifier to use with apple_mouse. Not long time later I discovered Fn key isn't being reported by adbhid. While doing this, I decided it was time to fix another problem: the default SYSRQ key on macs doesn't exists in my PowerBook (and probably in other models too). Two nights later, I got these three patches. They're still waiting for comments on linuxppc-dev list, but it's safe to use them already (I'm not having problems with them). The result is that KEY_FN event is generated anyway (so you can use with apple_mouse) and you may configure the SYSRQ key on /sys/classes/keyboard0.
so?
So, while doing this stuff, I figured that now it's possible to remap Fn/Ctrl in userspace, where this kind of stuff belongs. Now just wait for an inspired night to do so. BTW, while working on apple_mouse, I was able to fix lots of bugs on libuinput and it's now functional.
more input madness
I decided to try out something new and got a trackball. I don't use mouse so much while working, so couldn't be so bad to get used with. And it wasn't. Actually it's really fun. Kinda like when you first tried to use a regular mouse. I got a lot better with it: I'm able to get flawlessly up to level 5 in xbill and played warcraft III without problem. FPS games still requires a bit more training...

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!