Bug 82482

Summary: RFE: Support for remapping keys of bluetooth keyboards
Product: systemd Reporter: Jamie Lentin <jm>
Component: generalAssignee: systemd-bugs
Status: RESOLVED FIXED QA Contact: systemd-bugs
Severity: normal    
Priority: medium CC: dh.herrmann, kay
Version: unspecified   
Hardware: Other   
OS: All   
Whiteboard:
i915 platform: i915 features:
Attachments: udev: Allow key mapping for bluetooth keyboards

Description Jamie Lentin 2014-08-11 22:34:18 UTC
Before I could use /lib/udev/keymap to reassign keys on a bluetooth keyboard, since upgrading to udev 208 with hwdb this appears to be unimplemented or purposefully broken.

/lib/udev/rules.d/60-keyboard.rules says:-

# ignore all bluetooth devices
SUBSYSTEMS=="bluetooth", GOTO="keyboard_end"

Commenting out this line allows me to do the following:-

keyboard:name:ThinkPad Compact Bluetooth Keyboard with TrackPoint:*
 KEYBOARD_KEY_70049=pageup
 KEYBOARD_KEY_7004c=pagedown

And everything seems to work, although it's obviously not the neatest way to match a keyboard.

Why are they explicitly enabled? Would a rule to match say the HID device be accepted (presuming that it's possible)?
Comment 1 Jamie Lentin 2014-08-12 08:34:08 UTC
Ooops, s/explicitly enabled\?/explicitly disabled\?/
Comment 2 Kay Sievers 2014-08-26 14:54:44 UTC
Hmm, I think we never supported bluetooth keyboards, even with the old
keymap stuff:
  http://cgit.freedesktop.org/systemd/systemd/tree/src/udev/keymap/95-keymap.rules?id=v205#n11

How would a match on the HID device look like?
Comment 3 Jamie Lentin 2014-09-01 12:46:44 UTC
Before with /lib/udev/keymap it was pretty easy to write a custom udev rule to apply a keymap:

SUBSYSTEM=="input", \
  ATTRS{name}=="ThinkPad Compact Bluetooth Keyboard with TrackPoint", \
  RUN+="keymap $name /etc/udev/keymaps/thinkpad-bluetooth-keyboard.map"

...so I wouldn't have noticed that the default rules don't play around with bluetooth keyboards. NB: my remappings themselves are not worthy of upstream, just my own odd quirks.

Now with hwdb I have 2 levels of indirection to mine through. I presume adding my own rule (and associated hwdb entry) like this would work:

SUBSYSTEM=="input", \
  ATTRS{name}=="ThinkPad Compact Bluetooth Keyboard with TrackPoint", \
  IMPORT{builtin}="hwdb 'keyboard:custom:compact-bluetooth-keyboard'", \
  RUN{builtin}+="keyboard"

However, adding this udev rule and inventing my own namespace seems unnecessary. A hwdb mapping for bluetooth devices, or bluetooth devices using using the "keyboard:name:" mapping would mean I just have to add entries to hwdb, as with other keyboard types.

Unfortunately I am currently away, however will suggest a patch next week.
Comment 4 Jamie Lentin 2014-09-09 21:25:34 UTC
Created attachment 106011 [details] [review]
udev: Allow key mapping for bluetooth keyboards
Comment 5 Jamie Lentin 2014-09-09 21:28:43 UTC
The attached patch allows me to do "keyboard:hid:b*5g*v*17EFp*6048" for my keyboard in a .hwdb file.

I notice that bluetoothctl reports "Modalias: usb:v17EFp6048d0309" for the keyboard, but I can't find a node in /sys that matches this modalias that we can use. having the "usb:" prefix is somewhat confusing anyway.
Comment 6 Zbigniew Jedrzejewski-Szmek 2015-02-05 00:59:07 UTC
Looks legit. Kay?
Comment 7 Kay Sievers 2015-02-05 17:12:25 UTC
(In reply to Zbigniew Jedrzejewski-Szmek from comment #6)
> Looks legit. Kay?

I don't remember why we blacklisted bluetooth and we should not remove that
without finding out first.

But, I talked to David Herrmann, and we think, we could just match all HID
devices, instead of making a specific rule for bluetooth HID devices only.
Comment 8 Jamie Lentin 2015-02-07 11:05:46 UTC
> I don't remember why we blacklisted bluetooth and we should not remove that
> without finding out first.

I did try digging into history to work this out at the time, but didn't find anything conclusive.

> But, I talked to David Herrmann, and we think, we could just match all HID
> devices, instead of making a specific rule for bluetooth HID devices only.

That'd make a lot of sense IMO.
Comment 9 Zbigniew Jedrzejewski-Szmek 2015-02-07 16:54:24 UTC
Yep, I don't see anything interesting in git history or on the mailing list either.

I guess we want the rule to be as narrow as possible to avoid unnecessary processing on devices that cannot match. Kay, David, you're the experts here.
How should the general rule for HID devices look?
Comment 10 Zbigniew Jedrzejewski-Szmek 2015-02-14 16:00:41 UTC
Jamie, can you update your rule to apply to abitrary hids?
Comment 11 David Herrmann 2015-03-16 11:35:39 UTC
This is now fixed in -git. To add bluetooth devices, please provide the MODALIAS from /sys/class/input/inputX/uevent. We only match on name/dmi information if absolutely necessary.

I will now mark this issue as resolved. Jamie, please feel free to paste your device information here and I will add it.
Comment 12 Jamie Lentin 2015-03-16 13:31:39 UTC
David, thanks! Apologies for not getting around to a new patch, this slipped off my queue. The /sys/class/input/input*/uevent file for my keyboard has "MODALIAS=input:b0005v17EFp6048e0309-...", so this should work fine.

There isn't any generic remapping to do, so no need to add anything (any generic remapping is handled in the HID driver). However, it's nice to have the hook to handle my own quirks.

Thanks again,

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.