billziss-gh/EnergyBar

Brightness does not work when using external screens

roderik opened this issue · 9 comments

The brightness widget only works when my macbook is not connected to external screens. Not working meaning changing the slider does nothing to the macbook screen brightness. When running unconnected, it works as expected.

When I'm turning down the brightness to zero and nearly close the lid, the brightness will turn up again immediately. After fully opening the lid the slider remains on the left - with an active display. Disabling the auto adjust brightness feature doesn't make any difference.

This may be caused by the same reason.

We may have to reverse engineer more of Apple's "CoreBrightness" private framework to really fix this problem.

EnergyBar currently uses IOKit (Brightness.c) to get/set the display brightness and CoreBrightness (CBBlueLightClient.h) for night shift.

I'm the author of another Touch Bar app (BetterTouchTool) and just stumbled upon your nice project.

I'm using the DisplayServices.framework in order to set the brightness, here is a quick example:

   CGError		err;
    int			i;
    CGDisplayCount	max;
    CGDirectDisplayID	displayIDs[8];

    err = CGGetOnlineDisplayList(8, displayIDs, &max);
    if(err != kCGErrorSuccess) {
        return;
    }
  
      NSEventModifierFlags flags = [NSEvent modifierFlags];
    for(i = 0; i < max; i++ ) {
        CGDirectDisplayID display = displayIDs[ i ];
        if (( CGDisplayIsBuiltin(display) && !(flags & NSEventModifierFlagControl)) || (!CGDisplayIsBuiltin(display) && (flags & NSEventModifierFlagControl))) {
            DisplayServicesSetBrightnessWithType(display, brightnessValue, 1, 1);
        }
    }

@fifafu thank you. This is very helpful.

EnergyBar version 1.3 is out.

I have changed how the brightness control works to always control the "main" display. If this is not desirable, we can also attempt to control the "builtin" display as per @fifafu's suggestion.

Please try this release and let me know if it works for you or what further changes you would want.

It works. Good job!

Thanks :)

Indeed!

It did not wokt for me, but I changed it and created a pull request:
#24