I was nervous at the beginning of this month, I still hadn’t finished the draft PR I opened last month. But last week, finally, I had a free weekend and decided to tackle the issue. So what was the issue?
The issue was that gamepad events like button clicks, triggers, and haptic effects weren’t handled correctly. They were bound to the main event loop, so for your button clicks to go through you had to move your mouse!1
The second issue was the gamepadconnected events, which tell browsers that there is a gamepad waiting to be listened to. They were firing before the browser fully initialized, so they were getting discarded in practice. For your gamepad to work you had to unplug and plug it back in, which was very annoying.
Following jdm’s advice I first put the gamepad event handler in a different thread. The only responsibility of the thread was to listen for gamepad events using a Rust library called Gilrs. That enabled Servo to handle gamepad events seperately. For example, in case of an error, the main event loop was not affected and vice versa.
The second part of the solution was to listen for haptic effects (aka vibrations) as well. These were triggered from the browser, so the opposite direction of buttons or triggers, after getting the browser event we had to let Gilrs know about the qualities of the vibration like delay, magnitude, etc. I first set up a channel between the main thread and the brand new gamepad thread, because haptic effects were triggered from the main thread. After the gamepad event poller I put another loop listening for new messages from the channel, and if there was an event it started or stopped the haptic effect.
That second part took some time to figure out but everything worked fine. But the main problem persisted, because the first gamepadconnected event got discarded, the browser didn’t even bother to react to regular and haptic events. First we had to tell the browser that the gamepad had in fact connected so it could start listening.
To solve this problem I first put connected gamepads on a vector and when there was a gamepad event I first checked if the gamepad was in there, if it was, before sending the original gamepad event I sent a synthetic gamepadconnected event. That solved the problem!
After a round of review my PR got merged! Thanks to jdm for the guidance and reviews.
I hope to contribute more this month. See you next month!
1 I found this very funny. ⮥
18 Temmuz 2026
© 2026 Furkan Erdem
Hakkımda
Yorumlar
Henüz yorum yok!