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

darwin: add option to open device in non-exclusive mode #397

Merged
merged 1 commit into from
Apr 23, 2022

Conversation

Youw
Copy link
Member

@Youw Youw commented Mar 16, 2022

Resolves: #27
Resolves: #344

@Youw Youw requested a review from z3ntu March 16, 2022 19:11
@Youw
Copy link
Member Author

Youw commented Mar 16, 2022

@dnaq try if this works for you.

@dnaq
Copy link

dnaq commented Mar 16, 2022

That looks like it would work beautifully for my use case.

@mcuee mcuee added the macOS Related to macOS backend label Mar 17, 2022
@DJm00n
Copy link
Contributor

DJm00n commented Apr 13, 2022

I thought that hidapi idea is to provide generic crossplatform API if possible.
We can add such option for Windows too (do not pass FILE_SHARE_READ and FILE_SHARE_WRITE to CreateFile). Maybe its better to do not-os-specific hid_open_path instead?

@Youw
Copy link
Member Author

Youw commented Apr 13, 2022

I already had this conversation somewhere (but I can't find it, so here it goes again):

  1. HID Standard doesn't define such things like sharing the device on host side, so we can't reference to any existing specification or smth;
  2. Not all platforms supports such notion at all:
    • You can do Exclusive or Non-Exclusive Open on macOS;
    • (apparently) You can do Shared or Non-Shared Open on Windows (I never checked the actual behavior when you do Non-Shared Open on Windows);
    • Both LIBUSB and HIDRAW backends do not support Non-Exclusive Open due to OS/API specifics;

Having a "cross-platform" function that is known only to work for some platforms defeats the whole "cross-platform" idea.

Pretty much the same thing we can tell about similar option: ReadWrite or ReadOnly Open: supported by Windows and HIDRAW, but not supported by macOS and LIBUSB. More than that - on Window you can open a device without specifying ReadWrite or ReadOnly, and on HIDRAW you have to specify one of them.


There is also a question of consistency, e.g.: "shouldn't a cross-platform application behave consistently across platforms?".
I.e. since we open on Windows in shared mode, why don't we open in Non-Exclusive mode on macOS by default?
I already asked myself this question here.
In addition to that: on LIBUSB we open with exclusive access (and there is no option to do otherwise), so current behavior on macOS is consistent with LIBUSB.


Given all of the above, my strategy is:

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

Successfully merging this pull request may close these issues.

Composite hid device that's also a keyboard on Mac OS X mac: Option to open device in non-exclusive mode
4 participants