Fix trackpads and graphics tablets being recognized as controllers on Linux/*BSD
On my setup, my DualSense is finally at controller ID 0 as the ASRock LED Controller is no longer registered and takes up ID 0 as a result. The DualSense's trackpad is also no longer seen as a separate (non-functional) controller.
Tested both with udev=yes and udev=no, including hotplugging. Thanks to @geekley for providing the list of banned words (to which I added led) :slightly_smiling_face:
- This closes https://github.com/godotengine/godot/issues/59250.
Testing project: https://github.com/godotengine/godot-demo-projects/tree/master/misc/joypads
Thanks for the PR and the ping @Calinou ! Just for clarity, this PR is a bit different from the scripts as it considers only space (U+0020) as word separator:
for (const String &word : name.to_lower().split(" ")) {
Whereas the GDScript codes consider more characters as word separators. Any ASCII non-letters in the current gist:
static func is_ascii_non_letter(c: String) -> bool:
return c.unicode_at(0) < 128 and not (c >= 'a' and c <= 'z' or c >= 'A' and c <= 'Z')
\b word boundary in the previous RegEx version:
static var pattern := RegEx.create_from_string('\\b(?i:(?:touch|track|click)pad|mouse|pen)\\b')
I'm not saying this method is better, I'm just pointing out the difference, since some cases would be handled differently.
E.g.: okWord-bannedWord, okWord_bannedWord, okWord2bannedWord, okWord\tbannedWord, etc.
I don't have an opinion on whether it's safer to consider what is a "word" more strictly or more broadly, because this is only theoretical, I didn't encounter these cases in practice; and also didn't do any sort of test or research on device names (though I consider this list and this repo's files to be good sources if anyone wants some sort of reference).
While on one hand these other word separators should be pretty safe assumptions, on the other, from https://github.com/godotengine/godot/pull/59412#issuecomment-1759087924:
We'd rather have false positives than false negatives.
Still, even with fewer separators, maybe it's worth adding at least _ and \t as alternatives to space, just in case?
Regarding - (minus / hyphen), I have no idea. Maybe it's safer to not consider it a separator, as there are small words like "pen" and "led" that could be part of a larger word, like a brand name.
Still, even with fewer separators, maybe it's worth adding at least _ and \t as alternatives to space, just in case?
I've never seen a controller name contain _ or \t personally.
Yeah, I though so too after I took a look at the lists of names I linked. Though these only list actual controllers, not other devices like mouse, etc. it's probably safe to use just space.
I've added keyboard to the list of banned words following https://github.com/deathkiller/jazz2-native/issues/56. Quoting Jazz² Resurrection 2.7.0's release notes:
- Blacklisted every gamepad containing
KeyboardandMousein name, because it's usually wrongly detected as gamepad on Linux
Note that analog keyboards (such as the Wooting two HE I have) are smart enough about this; none of them should have keyboard in their controller name.
Thanks!