Skip to content
This repository has been archived by the owner on Jul 5, 2019. It is now read-only.

Better way of lowering contrast after brightness #3

Open
MHX792 opened this issue Jan 26, 2019 · 5 comments
Open

Better way of lowering contrast after brightness #3

MHX792 opened this issue Jan 26, 2019 · 5 comments
Labels
enhancement New feature or request

Comments

@MHX792
Copy link

MHX792 commented Jan 26, 2019

First of all, thank you very much for fixing the infinite mouse sluggishness!

As my external monitor is still too high on the lowest brightness level, I activated the option to lower the contrast after brightness is set to 0. But the contrast drop was way too high and I missed an option to incremently lower it.

So I changed the func handle(mediaKey: MediaKey, event: KeyEvent?) method like so:

case .brightnessUp:
    if !prefs.bool(forKey: Utils.PrefKeys.lowerContrast.rawValue) {
        // default brightness increasing
        let brightnessValue = display.calcNewValue(for: BRIGHTNESS, withRel: +step)
        display.setBrightness(to: brightnessValue)
    } else {
        // first increase contrast value until default value, then start increasing brightness value
        let contrastValue = currentDisplay.calcNewValue(for: CONTRAST, withRel: +step)
        if contrastValue <= display.defaultContrastValue {
            display.setContrast(to: contrastValue)
            display.setBrightness(to: 0)
        } else {
            display.setContrast(to: display.defaultContrastValue)
            let brightnessValue = display.calcNewValue(for: BRIGHTNESS, withRel: +step)
            display.setBrightness(to: brightnessValue)
        }
    }

case .brightnessDown:
    if !prefs.bool(forKey: Utils.PrefKeys.lowerContrast.rawValue) {
        // default brightness descreasing
        let brightnessValue = currentDisplay.calcNewValue(for: BRIGHTNESS, withRel: -step)
        display.setBrightness(to: brightnessValue)
    } else {
        // first decrease brightness until 0, then start decreasing contrast value
        let brightnessValue = currentDisplay.calcNewValue(for: BRIGHTNESS, withRel: -step)
        if brightnessValue >= 0 {
            display.setBrightness(to: brightnessValue)
            display.setContrast(to: display.defaultContrastValue)
        } else {
            display.setBrightness(to: 0)
            let contrastValue = currentDisplay.calcNewValue(for: CONTRAST, withRel: -step)
            display.setContrast(to: contrastValue)
        }
    }

In Display.swift I added a hard-coded default value for the contrast and a method for decreasing the contrast:

let defaultContrastValue = 70
    
func setContrast(to value: Int) {
    let contrastValue = value < 0 ? 0 : value
    Utils.sendCommand(CONTRAST, toMonitor: identifier, withValue: contrastValue)
    if let slider = contrastSliderHandler?.slider {
        slider.intValue = Int32(contrastValue)
    }
    saveValue(contrastValue, for: CONTRAST)
}

func setBrightness(to value: Int) {
    let brightnessValue = value < 0 ? 0 : value
    Utils.sendCommand(BRIGHTNESS, toMonitor: identifier, withValue: brightnessValue)
    if let slider = brightnessSliderHandler?.slider {
        slider.intValue = Int32(brightnessValue)
    }
    showOsd(command: BRIGHTNESS, value: brightnessValue)
    saveValue(brightnessValue, for: BRIGHTNESS)
}

For this to work, the calcNewValue method needs to be able to return negative values:

func calcNewValue(for command: Int32, withRel rel: Int) -> Int {
    let currentValue = prefs.integer(forKey: "\(command)-\(identifier)")
    // return max(0, min(100, currentValue + rel))
    return min(100, currentValue + rel)
}

Works like a charm and my eyes are happy at night.

Things to improve:

  • Add option for manuelly setting a defaultContrastValue for each display
  • Maybe add an OSD for contrast or combine both into one like this:

screenshot 2019-01-26 at 11 57 44

@JoniVR
Copy link
Owner

JoniVR commented Jan 26, 2019

hi @MHX792

I'll look into your code when I get some time, the problem is that I don't have 2 monitors (only 1 external ultrawide) so I'm unable to test that part properly.

  • Maybe add an OSD for contrast or combine both into one like this:
screenshot 2019-01-26 at 11 57 44

I'm afraid that wouldn't be possible, since it's using the default OSD from Apple, which would be pretty hard to modify.


I'm currently a bit busy so it might take some time for me to look into this, just so you know. Also, if this is an issue with your monitor and not the other ones I won't fix it (obviously) because it simply depends on how well your monitor follows a certain standard.

Best regards
Joni

@MHX792
Copy link
Author

MHX792 commented Jan 26, 2019

Also, if this is an issue with your monitor and not the other ones I won't fix it (obviously) because it simply depends on how well your monitor follows a certain standard.

There is no issue with the app itself or hardware wise with my monitor. I just missed an option to finetune / further decrease the contrast after the brightness has reached level 0. :) The contrast drop was just way too high in my opinion.

I'm afraid that wouldn't be possible, since it's using the default OSD from Apple, which would be pretty hard to modify.

I saw it as a "nice to have" feature anyway. An alternative would be to create a custom OSD, which probably is not worth the effort.

@JoniVR
Copy link
Owner

JoniVR commented Jan 26, 2019

I tested it myself without your code (I never actually used the contrast stuff) and I see what you mean, if you decrease the brightness further after it is 0, it just jumps to the lowest, right?

@JoniVR JoniVR added the enhancement New feature or request label Jan 28, 2019
@JoniVR
Copy link
Owner

JoniVR commented Jan 28, 2019

Your code works but the handle(mediaKey: MediaKey, event: KeyEvent?) function becomes way to complex, so I'll look into refactoring it to make it a bit cleaner before I can add this feature.

JoniVR pushed a commit that referenced this issue Feb 22, 2019
- added a fallback when no initial value could be read from display. Instead we will read the last known value from prefs.
- implement better way to handle lowering contrast after brightness is 0, this way, contrast will slowly go down as the user keeps pressing brightness down until a default contrast value has been reached.
@JoniVR
Copy link
Owner

JoniVR commented May 7, 2019

Hi, just letting you know, I've been added as a contributor in the previous fork the0neyouseek/MonitorControl and will thus be focussing on improving that one.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants