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

Automatically adjust external display based on internal display + Touch Bar support #27

Closed
funbben opened this issue Apr 13, 2018 · 20 comments
Assignees
Labels
Status: Done Work on this issue is complete. Will be available on next release Type: Feature Request Issue is a new feature proposal
Projects
Milestone

Comments

@funbben
Copy link

funbben commented Apr 13, 2018

It would be nice to be able to use the mac "auto adjust brightness" to set the brightness of external display automatically

https://i.stack.imgur.com/eYQuM.png

@the0neyouseek the0neyouseek self-assigned this Apr 14, 2018
@the0neyouseek the0neyouseek added the Type: Enhancement Issue is an app enhancement label Apr 14, 2018
@the0neyouseek
Copy link
Member

Hi @funbben,

Thats a great idea but would be quite difficult to implement because this feature depends on the ambient light sensor (located next to the camera) of your Macbook Pro/iMac and not all external screen have one.

I'll leave this issue open for now to see if anyone has a better idea about tackling this.

PS. We could, for exemple use the one present on your MBP/iMac if we have one, but I'm not sure how. I'll look into it.

@funbben
Copy link
Author

funbben commented Apr 14, 2018

The idea was to use mac internal sensor and apply same setting as Mac display

@retrography
Copy link

I think the idea @funbben described is actually very interesting. The only thing is: One will have to check first whether the computer is a laptop and whether it is running the clamshell mode or not.

@rowanalex123
Copy link

rowanalex123 commented Jul 18, 2018

Hammerspoon provides the lux reading from the ambient light sensor on Macs. Apprently they use the raw value from the sensor and run Mozilla's algorithm to convert it to lux

@retrography
Copy link

@rowanalex123 Have you actually tried that? The function only returns an error for me -- which is a -1 (on MacBook Pro 2016).

@rowanalex123
Copy link

I tried it now. It returns -1 for me as well on a 2017 Mac pro

@arnoappenzeller
Copy link

I would really like this idea with using the Mac Books ambient sensor.

Has someone already tried this code for reading the data?

I think I'm gonna play around a bit with it soon

@the0neyouseek
Copy link
Member

Hi, first of all sorry for the late response.
I'll try to work on this feature this week-end.

@the0neyouseek the0neyouseek added the Priority: Trivial Issue is trivial (e.g. i18n, typos…) label May 23, 2019
@jcastro
Copy link

jcastro commented Aug 30, 2019

Just something that might be of interest. The new LG 2019 Ultrafine 5k is finally using the light sensor (see https://twitter.com/jonatan/status/1167163794281455616) so maybe there's a chance to use that information to automatically change others' display brightness (probably with a configurable offset for the value)

@jcastro
Copy link

jcastro commented Oct 14, 2019

Another interesting fact, looks like now even the older LG Ultrafine 5k that didn't have the auto-brightness working now it's enabled if you are on Catalina.

@rshev
Copy link

rshev commented May 4, 2020

Just found this app, mainly because I'd like to have different brightness during the day and in the evenings, and immediately thought of this idea. Has anyone had any luck reading ambient light values? I might help, I do swift for a living.

@dmatora
Copy link

dmatora commented Jul 3, 2020

@the0neyouseek

  1. There is an open source console app that allows automatically changing brightness on old UltraFine 4K/5K monitors that don't have ambient light support built into maOS.
    https://github.com/qvacua/ultrafine-auto-brightness
    I own old UltraFine 4K monitor and would love to see it's ambient light sensor support in MonitorControl

  2. It would also be awesome to trigger dark theme based on ambient light sensor value, like this (not very user friendly) open source app does http://codes.kary.us/health/starlight

  3. And finally there is an open source app that allows to use Macbook sensor to adjust brightness of external monitor https://github.com/OCJvanDijk/Brightness-Sync it's code can be used for those who use regular monitors with no ambient light sensor

@stale
Copy link

stale bot commented Aug 3, 2021

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require attention? This issue may be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Status: Abandoned Issue will not be worked on anymore (reason in comment) label Aug 3, 2021
@sraka1
Copy link

sraka1 commented Aug 6, 2021

Feature request is still pending. Commenting so it's not auto-closed.

@stale stale bot removed the Status: Abandoned Issue will not be worked on anymore (reason in comment) label Aug 6, 2021
@waydabber waydabber self-assigned this Aug 20, 2021
@waydabber waydabber added the Type: Feature Request Issue is a new feature proposal label Aug 20, 2021
@waydabber
Copy link
Member

This might be a bit out of focus for MonitorControl right now but still we might add this function in the future as apparently this is among the core ideas all the way back to 2018. :)

There is an app called Lunar however made by @alin23 that already does this thing for those who are impatient for a solution.

@alin23
Copy link

alin23 commented Aug 20, 2021

Thanks @waydabber for letting people know about Lunar! Indeed, Lunar has Sync mode which takes advantage of Automatically adjust brightness by syncing the already adjusted brightness of the built-in display to the external monitors.

The problem with reading the sensor directly is that:

  1. It's not possible at all on Intel Macs (or at least I couldn't find a way to do it, the I/O Kit registry doesn't seem to expose any kind of lux or raw value)
  2. It's very hard to map the lux value to a brightness value when each single external monitor has its own lightness (nits) range
  3. You'll get more accurate results by reading the already adapted brightness of the builtin display because the system has an internal representation of the lightness curve of the display and can map it very well to the lux readings of the sensor.

If anyone is interested in reading the lux value on M1 Macs, because that is possible there, here is how to retrieve it from the command line:

ioreg -r -c AppleSPUCT720 | awk '/CurrentLux/{print $4}'

Doing that in Swift would require iterating the I/O Kit registry by matching the class AppleSPUCT720 and then extracting the CurrentLux property. Probably something like this:

#!/usr/bin/env swift

import IOKit
import Foundation

func getLux() -> Float? {
    let sensor: io_service_t
    if #available(macOS 12.0, *) {
        sensor = IOServiceGetMatchingService(kIOMainPortDefault, IOServiceMatching("AppleSPUCT720"))
    } else {
        sensor = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("AppleSPUCT720"))
    }

    guard sensor != 0 else {
        return nil
    }

    guard let luxProp = IORegistryEntryCreateCFProperty(sensor, "CurrentLux" as CFString, kCFAllocatorDefault, 0),
          let lux = luxProp.takeRetainedValue() as? Float
    else { return nil }

    return lux
}

print(getLux() ?? -1)

@waydabber waydabber mentioned this issue Aug 20, 2021
2 tasks
@waydabber
Copy link
Member

Wow @alin23 thanks for the detailed info! I wanted to go on the route of reading the internal display brightness (as that will also help on an other request, namely the use of the MBP touch bar slider for brightness change - I think we have a similar situation there that we can only infer the selected brightness only from the display's brightness itself, but I am not entirely sure, since I don't have an MBP myself and hate the idea of the touchbar. :))

But there is a rather long list of other accumulated issues to be dealt with so I am afraid this one does not have the highest prioirty at the moment.

@waydabber waydabber removed Type: Enhancement Issue is an app enhancement Priority: Trivial Issue is trivial (e.g. i18n, typos…) labels Aug 21, 2021
@waydabber waydabber changed the title Automatically adjust brightness Automatically adjust external display based on internal display + Touch Bar support Aug 26, 2021
@waydabber
Copy link
Member

Here is what we can do regarding the ambient light sensor, the touch bar slider and the Control Center brightness slider:

  • we cannot directly access the ambient light sensor on Intel macs (there is a way for M1 macs).
  • we cannot directly access the Touch Bar and Control Center brightness sliders.
  • we cannot receive a notification if the internal display (or external Apple display) brightness is changed.
  • we can poll the current brightness level of the internal display (or external Apple displays with built in ambient light sensor).

Based on this, we can do brightness change replication from the internal display to the external displays. The issues are still numerous:

  • How frequently should we poll? We might continuously poll the brightness level every 1 second and then if we detect change, increase the polling level. This will still not result in an immediate replication if the sliders are used but better then nothing. Increasing polling frequency taxes the system.
  • Currently MonitorControl changes the brightness of the screen that has the mouse cursor. Should the synchronization affect all screens or only the screen with the pointer? The eariler is logical if the goal is to have a general ambient light sensor synchronization thing, the latter is if we want the macbook slider to change the brightness of the current screen in focus (+ the built in screen since we can't do anything stopping that).
  • If we want synchronization to affect all screens, then we also need a mechanism to "calibrate" relative brightness levels of the external displays (or mandate software dimming since with that we can replicate better the full range of internal screen's brightness range which typically a magnitude better than what most displays have). Or we might want to do an offset based synchronization and allow for quick calibration whenever the user wants his/her external display to be brighter or dimmer than what the app is setting, independently from the internal display.

This issue is related if we want all out synchronization: #418

I am not yet sure where to go with this and how well would the end result work. :)

@waydabber
Copy link
Member

waydabber commented Sep 11, 2021

Just some info about the progress regarding this issue:

@waydabber waydabber added the Status: In progress Issue currently being worked on label Sep 13, 2021
@waydabber waydabber added this to In progress in v4.0.0 Sep 13, 2021
@waydabber waydabber added this to the v3.1.0 milestone Sep 13, 2021
@waydabber waydabber assigned waydabber and unassigned the0neyouseek Sep 13, 2021
@waydabber waydabber added Status: Done Work on this issue is complete. Will be available on next release and removed Status: In progress Issue currently being worked on labels Sep 19, 2021
@waydabber waydabber moved this from In progress to Done in v4.0.0 Sep 19, 2021
@waydabber
Copy link
Member

Brightness change synchronization from Built-In and Apple displays to other displays is now added. This makes Touch Bar, Ambient light sensor, Control Center and System Preferences induced changes affect all displays. Synchronization is not direct, but only changes are replicated - the user can intervene and adjust at any time.

#596

@waydabber waydabber removed this from the v3.1.0 milestone Sep 20, 2021
@waydabber waydabber added this to the 4.0.0 milestone Sep 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Done Work on this issue is complete. Will be available on next release Type: Feature Request Issue is a new feature proposal
Projects
Development

No branches or pull requests