Joystick Hat in X-Plane in Linux
Preface: this is a long rant. If you just want your joystick hat to work in X-Plane, download jhat and follow the instructions in the README.
Linux reports joystick hats as axes, because that's what the device reports them as. Windows drivers often put up a façade where the directional hat is translated into 4 buttons. X-Plane is Windows-centric and therefore directional hats don't work in X-Plane in Linux.
I submitted a bug report, and was told
i cant do that
i have to use what is reported
but you can assign an AXIS to look around.. it is one of the joystick axis options...
Actually, you can't use the "look around" axis, because the joystick hat is not analog, but tristate. It's either left, middle, or right (or up, middle, or down for the vertical axis). So you are either looking behind you, in front of you, or behind you - not the most useful combination. I informed him of the situation, and provided him with some pseudocode for handling the axes. I'm always amused when developers try to delude the user and themselves into thinking some bug or feature is impossible to fix or implement. Human nature is a funny thing. Sometimes we even believe it ourselves. His reply to my information and pseudocode:
the code would be easy, but i wont write a whole new type of axis response just for a few computers that are not working right
it is too much confusion for too little gain
sorry!
Wow, this task has gone from being impossible to being easy in one short day! Well of course it's easy. I knew that. He knew that. Now we're on the same page. The real reason he won't do it is because he doesn't want to. It would be easy, but it would be inconvenient. And those darned pesky Linux freaks aren't worth the trouble. Now, at this point I'm struggling to be cordial, but I believe it's important to remain cordial until the bitter end. I replied with my condolences that he has so few Linux customers that he shouldn't care if his software is broken in Linux. I also tossed out some more ideas - a different type of axis behavior for scrolling instead of absolute positioning, etc. His reply,
i have very few linux users, this is true
also, it seems obvious to me that the OS should report the hardware properly... not that the app should work backwards and add more confusion for EVERYONE because ONE person did not do his job properly!
Now he's getting defensive. The truth hurts sometimes. Let's step back and review. The joystick reports the directional hat as 2 axes. It's a HID device, so there is no need for special drivers. However, somewhere along the line (I don't know the history), some joystick driver writer in Windows (probably before HID even existed) decided that directional hats should be represented at 4 buttons. Does one make more sense than the other? I don't think so. I think they're both valid viewpoints. I'm not surprised the engineers chose to use axes. I'm not surprised the programmers wanted to use 4 buttons. Two valid viewpoints. What we have, however, is a lack of standards. There is nothing to my knowledge that says joystick hats should be buttons, it's just Windows convention. Windows convention is fine and dandy in a Windows world, but Windows convention doesn't stand up very well as a challenger to the appropriateness of faithfully representing what the HID device itself reports. This is not about a Linux developer slacking on the job. This is about the world being a complicated place where sometimes things are implemented differently for perfectly valid reasons. If you want to play the portability game, you have to deal with this stuff. He knows that, I'm sure. It's just laziness, hubris, and now a personal resolution to not give in to this pesky Linux freak.
One more cordial reply from me, stating that both can be right, and a terse reply from him:
no, i think linux is wrong here
a button is a button, not an axis
I didn't reply anymore, it would serve no purpose. I could say, "an axis is
an axis, not a button", because it is an axis after all. But I see I'm not
going to change his mind or convince him. So I took a different tack. I visited
the old forum thread with the not-really-feasible joydev.c patch that others
came up with and encouraged them to encourage the author to consider treating
us Linux customers to a simple bug fix.
But the gauntlet was down. I can't just leave a technical problem like this,
that should be so easy, in eternal limbo. I have to see if it can be solved. I
read through joydev.c in the kernel and thought about what it would take to
make a robust patch that wouldn't have problems with plugging things in in
different orders and wouldn't ruin other joysticks' behavior. I thought of a
way, but I didn't implement it. I decided there had to be a better way. An
easier way. A userspace way. And so there was.
I knew it was easy to read the joystick events in user space. I figured there
just had to be a way to synthesize the fake joystick events that I needed. I
tried to grok the input core and event subsystems. I read articles in Linux
Journal. I groped through kernel changelogs and looked high and low for what
this weird uevent file in sysfs was (completely unrelated—it's a buffer to
aid hotplug in managing coldplug events). I exhausted poor Dr. Google. And then
I stumbled upon a manpage for the XTest X extension. In a flood the blinds were
lifted and I realized that what I needed was not to synthesize joystick events
(hard), but to synthesize the keyboard events (easier). Not only that, but I
didn't have to synthesize them at the kernel level, I could synthesize them in
X (easy).
An hour or two later I had finished the task. It's a beautiful thing, to be able to look around in X-Plane. I call it jhat because I was feeling pretty unimaginative at the time. It uses xautomation to do the XTest stuff because I was feeling pretty lazy at the time. Grab the tarball.Now I have two flight simulators that I can stand to fly. I prefer FlightGear for many reasons, not the least of which is this whole fiasco (I could have submitted a patch in the first place and nobody would have gotten hurt). But I do like X-Plane because some of the planes that are available I do so enjoy flying, like the Mooney M20K.
So, as a follow up to my earlier post on respecting your bug reporters, let this be a lesson to you developers out there: every user matters. Especially paying users. If you don't want to support Linux, then by all means don't support Linux. You're not fooling anyone when you do a half-baked job of supporting his platform.
Posted in linux | 8 comments |