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

Add experimental CoreDisplay API (fixes #26) #31

Closed

Conversation

farkmarnum
Copy link

This adds an option to use the undocumented private CoreDisplay and DisplayServices APIs to modify brightness, which should resolve issues on Mac OS 10.12.4 and later with brightness reverting.

Main changes:

  • Adds NSMenuItem experimental to toggle the use of the new API. This defaults to true if OS version is >= 10.12.4.
  • Adds isUsingNewAPI and toggleExperimentalMode to BrightnessController to manage this state.
  • Adds getBrightessNewAPI, setBrightnessNewAPI, and notifySystemOfNewBrightness to BrightnessController, using code adapted from fnesveda/ExternalDisplayBrightness.

Also:

  • Adds .DS_Store to .gitignore to avoid polluting repo.

This works on my MacBookPro16,1 with AMD Radeon Pro 5300M running Mac OS 10.15.7. I'm able to run f.lux without the brightness changes of lumen being reverted after a few seconds (as in #26). @anishathalye I haven't written Objective-C before, and I'm open to any improvements! What do we think?

@anishathalye
Copy link
Owner

anishathalye commented Dec 26, 2020

I was previously running macOS 10.14, and I skipped over Catalina to Big Sur. The current released version of Lumen seems to work fine for me on macOS 11.

Is IOKit deprecated? Looking at Apple's IOKit Functions, IODisplayGetFloatParameter etc. aren't marked as deprecated. Have you seen official docs saying that this functionality that we're relying on is no longer supported? I'd like to avoid switching to undocumented private APIs without good reason.


Some notes / links to references, partially written down for myself, for later:

@farkmarnum
Copy link
Author

To clarify what I meant by "issues on Mac OS 10.12.4 and later with brightness reverting," the only issues that I'm aware of occur when running Lumen alongside f.lux. Without that, it works fine.

As for any official documentation of the new DisplayServices and CoreDisplay private APIs overruling brightness set by IOKit, there is none. Since they're private APIs, they are completely undocumented and only intended for internal use. They're inherently unstable and could break in the future.

However, some users may want to use Lumen along with other softwares that modify the display. In this PR, I added an option to use the private APIs, and made it default to on if the OS version was >= 10.12.4 (when those APIs were introduced). It would be safer to have it default to off in all cases and just remember the user's preference. But it may be that some users are installing Lumen, finding that it doesn't work since they're also running f.lux (which is quite popular) and uninstalling Lumen without leaving an issue on GitHub. You might have a better perspective on that if you have telemetry data on installs/usage/etc.

But, If Lumen doesn't want to use the undocumented APIs, that's understandable.


Here are some resources I've found from other brightness-related projects that have switched over to the private APIs or discussed it:

Searching GitHub for code that uses the private api methods reveals more as well.

@MentalGear
Copy link

Would be a nice feature!

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

Successfully merging this pull request may close these issues.

3 participants