-
Notifications
You must be signed in to change notification settings - Fork 580
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
hs.brightness.get() returns nil on M1 #2668
Comments
See also #2663 - the display Subsystem on M1 macs seems to be completely different and the old APIs for getting brightness and screen names don't work. Hopefully we'll be able to figure out replacements at some point! |
For now I've added a note to the docs for hs.brightness, to indicate that the module is not working on M1 Macs. |
@cmsj Closing not resolved issue is passé. 😢 |
@limakzi - Unfortunately there's not much that can be done, unless someone in the open source community can work out how Apple's doing it, and track down a hidden API or workaround. Hopefully one of these issues on other repos will come up with a fix:
|
I found that these private APIs from the DisplayServices framework work for getting and setting brightness on my M1 MacBook Air's built-in display: extern int DisplayServicesGetBrightness(int display, float *brightness);
extern int DisplayServicesSetBrightness(int display, float brightness);
// Change brightness
float brightness = 0.8;
int err = DisplayServicesSetBrightness(1, brightness);
// Get current brightness
err = DisplayServicesGetBrightness(1, &brightness); |
Can anyone try these out on an intel mac, and ideally as far back as Mojave? |
Ok, it works on the M1 MacBook, but doesn't on an Intel iMac running Catalina (the previous method did work on it) or an intel MacBook running Big Sur. I need to figure out how to determine architecture at runtime (which should be easy, just haven't had to do it yet) and select the method based on that. I should have a pull request up later today. This still doesn't make |
I believe the ambient brightness can be read with: I'm looking into whether there's a way to get this using a private API instead of parsing log output, although I think parsing the plist produced by corebrightnessdiag is not a terrible solution (for some applications—not sure about the hammerspoon project). Example of parsing the output here. |
@jtbandes where did you come across DisplayServicesSetBrightness and DisplayServicesGetBrightness? Is there a link you can share that has more information? I can get it to work in The other possibilities I'm considering are to muck around with dlsym and try to validate them that way (annoying, tedious, and may hit the same wall) or more likely convert Further crappy news... apparently even |
Open up Interestingly, I don't have |
This seems to work and give the same result as the // Link with /System/Library/PrivateFrameworks/CoreBrightness.framework
NSNumber* lux = [[NSClassFromString(@"DisplayServicesClient") new] copyPropertyForKey:@"AggregatedLux"]; It also works if you use It looks like these classes use XPC to communicate with com.apple.backlightd, but I haven't found which process actually provides that service so I don't know where to dig for a non-XPC way of getting the lux info. Anyway, this should work well enough |
I've been looking around to try and find a way to read brightness and this was the best I could find. I've been using Hopper to look at DisplayServices, CoreBrightness, and CoreDisplay frameworks. These functions seemed like the most direct and low-level ones to get brightness. There are also lots of other functions in DisplayServices that may be useful for various purposes. The ambient lighting stuff (and much other functionality) looks like it's implemented in some CBModule subclasses in CoreBrightness, however I don't really know how to correctly instantiate these classes and that's why I took the approach of using the BrightnessSystemClient (I think I got this idea from disassembling corebrightnessdiag). FYI, there is a man page for corebrightnessdiag that says "Collects Night Shift Information for sysdiagnose".
Does DisplayServices or CoreBrightness not work? It's been working in my simple tests (a standalone Obj-C program). (BTW, apologies if I say irrelevant things here — I'm not actually familiar with the hammerspoon project, just wanted to share my discoveries about Big Sur brightness APIs with others who've been struggling with them!) |
Ok, adding I think I have some consistent behaviors now that I can try and wrap up into a pull request that you guys can test, hopefully later tonight or tomorrow at the latest. As to the ambient stuff... I'll take a closer look after I get the brightness stuff working. |
I have found an issue on Apple Silicon M1.
hs.brightness
returnsnil
and returns false on each function execution.I think this is related to: #2663.
The text was updated successfully, but these errors were encountered: