Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support MAC address as the identifier for bluetooth devices #3487

Merged
merged 1 commit into from
May 26, 2023

Conversation

stackia
Copy link
Contributor

@stackia stackia commented May 12, 2023

This PR adds device_address (which is the MAC of Bluetooth devices) as a matchable device identifier.

(pqrs-org/cpp-osx-iokit_hid_device#1 should be merged as a prerequisite)

image

device_address is usually helpful for Bluetooth mouse/keyboards when the manufacturer doesn't send a valid vendor_id / product_id. For devices that have conflict vendor_id / product_id, we can also use device_address to distinguish between them (location_id can achieve the same thing, but MAC address should be more straightforward for users).

For example, we can now use such conditions in manipulators to match a device with a given MAC address.

    "manipulators": [
        {
          "type": "basic",
          "conditions": [
            {
              "type": "device_if",
              "identifiers": [
                {
                  "device_address": "ec-ba-73-21-e6-f4"
                }
              ]
            },

The setting UI has also been updated to reflect the change:

image image

(The H (Adafruit Industries) above has vendor_id/product_id both set to 0, so only device_address is displayed.)

This may fix these related issues:

if (auto c = reinterpret_cast<libkrbn_connected_devices_class*>(p)) {
const auto& devices = c->get_connected_devices().get_devices();
if (index < devices.size()) {
return devices[index].get_identifiers().get_device_address().c_str();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be changed because it returns a pointer to data on the stack.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I misunderstood and this code is fine.
(I misunderstood it as device_properties::get_device_address)

@tekezo
Copy link
Member

tekezo commented May 17, 2023

Thanks!
I'll add small changes before merging. Please wait for a while.

@tekezo
Copy link
Member

tekezo commented May 18, 2023

I've identified a problem with Magic Mouse and Magic Keyboard not getting the device address properly, so I'm trying to fix it.

@tekezo
Copy link
Member

tekezo commented May 24, 2023

Magic Mouse and Magic Keyboard support will be available soon.
I'll fix the cpp-osx-iokit_hid_device.

@tekezo
Copy link
Member

tekezo commented May 27, 2023

@stackia
I've merged and released v14.12.2.
Please confirm it!
https://github.com/pqrs-org/Karabiner-Elements/releases/tag/beta

@stackia
Copy link
Contributor Author

stackia commented May 27, 2023

Thanks @tekezo !

I just checked v14.12.2 works great for my BLE keyboards!

@tekezo
Copy link
Member

tekezo commented May 27, 2023

If device-specific Simple Modifications had already been registered in previous versions, they were hidden in the Settings UI.
I'll fix the issue.

@tekezo
Copy link
Member

tekezo commented May 27, 2023

FYI: My BT devices also have Vendor ID and Product ID, so I have been able to configure them using the previous Karabiner-Elements.

When device_address is newly appended in device_identifiers, it will be judged as a different device from the previous one, so I will modify the policy to use device_address only when Vendor ID and Product ID cannot be taken or are zero.

Screenshot 2023-05-27 at 13 22 57

@tekezo
Copy link
Member

tekezo commented May 27, 2023

@stackia
Adjustments have been made in v14.12.3 to the handling of device_address as described above.
I don't think the device_address handling will change much anymore. Please check again!

@stackia
Copy link
Contributor Author

stackia commented May 28, 2023

@stackia Adjustments have been made in v14.12.3 to the handling of device_address as described above. I don't think the device_address handling will change much anymore. Please check again!

Thanks, I tried 14.12.3 and it looks good so far!

@tekezo
Copy link
Member

tekezo commented May 28, 2023

Thanks, I tried 14.12.3 and it looks good so far!

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants