Skip to content

Conversation

@Melk0rr
Copy link

@Melk0rr Melk0rr commented Aug 22, 2024

A new script based on the default brightnesscontrol.sh but using ddcutil to control the brightness of external monitors.

The main issue is : DDC/CI protocol is slow

Pull Request

Description

  • This script tries to achieve what the original brightnesscontrol script does with brightnessctl but for external monitors
  • As I use 3 external monitors, I lacked a utility to easily change brightness. So here it is
  • Dependencies: ddcutil only
  • Related issue

Type of change

Please put an x in the boxes that apply:

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update (non-breaking change; modified files are limited to the documentations)
  • Technical debt (a code change that does not fix a bug or add a feature but makes something clearer for devs)
  • Other (provide details below)

Checklist

Please put an x in the boxes that apply:

  • I have read the CONTRIBUTING document.
  • My code follows the code style of this project.
  • My commit message follows the commit guidelines.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added a changelog entry.
  • I have added necessary comments/documentation to my code.
  • I have added tests to cover my changes.
  • I have tested my code locally and it works as expected.
  • All new and existing tests passed.

Screenshots

screenshot_20240822_17h55m26s

Additional context

…al monitors

A new script based on the default brightnesscontrol.sh but using ddcutil to control the brightness of external monitors.

The main issue is : DDC/CI protocol is slow
@Melk0rr Melk0rr changed the title new: scripts - ddcutil script to handle brightness control for extern… feat: scripts - ddcutil script to handle brightness control for extern… Aug 22, 2024
Tweaked comments and print_error
@guoyatingg
Copy link

Good afternoon, I'm not a programmer at all, but I changed something in your script and it seems to work faster
brightnesscontrol.zip

@Melk0rr
Copy link
Author

Melk0rr commented Aug 25, 2024

Yep, you're right, updated to implement a variable

@kRHYME7
Copy link
Collaborator

kRHYME7 commented Aug 26, 2024

Sadly I can't test this one yet as my external monitor don't have ddc/ci, will try to find someone having that proto.

@abenezerw
Copy link
Contributor

image
This works, would be nice to control external monitor brightness from ui.

@abenezerw
Copy link
Contributor

but for some reason cant control it with scroll wheel over waybar though. just from terminal. is that also possible? @Melk0rr

@Melk0rr Melk0rr closed this by deleting the head repository Aug 31, 2025
@kRHYME7
Copy link
Collaborator

kRHYME7 commented Aug 31, 2025

@Melk0rr Can I add this script in HyDE repo?

@Melk0rr
Copy link
Author

Melk0rr commented Sep 1, 2025

@Melk0rr Can I add this script in HyDE repo?

Hi, yes no problem !
I improved it a bit on my end if you're interested:

#!/usr/bin/bash

ScrDir=$(dirname "$(realpath "$0")")
source "$ScrDir/globalcontrol.sh"

monitorInfo=$(ddcutil detect)
mapfile monitors < <(echo "$monitorInfo" | grep "I2C bus:" | cut -s -f 2 -d :)
model=$(echo "$monitorInfo" | grep "Model:" | cut -s -f 2 -d : | head -n 1 | xargs)

print_error() {
  cat <<"EOF"
    ./brightnesscontrol.sh <action>
    ...valid actions are...
        i -- <i>ncrease  brightness [+5%]
        d -- <d>ecrease  brightness [-5%]
        s -- <s>et VALUE brightness [VALUE%]
        g -- <g>et       brightness
EOF
}

get_brightness() {
  ddcutil getvcp 10 | awk -F 'current value = ' '{print $2}' | grep -o '[0-9]\+' | head -n 1
}

send_notification() {
  brightness=$(get_brightness)
  angle=$((((brightness + 2) / 5) * 5))
  ico="$HOME/.config/dunst/icons/vol/vol-${angle}.svg"

  notify-send -a "t2" -r 91190 -t 800 -i "${ico}" "Brightness ${brightness}" "${model}"
}

set_brightness() {
  for v in "${monitors[@]}"; do
    bus=$(echo "$v" | cut -s -f 2 -d -)

    case $1 in
    i)
      ddcutil setvcp 10 + "$2" --bus="$bus"
      ;;
    d)
      ddcutil setvcp 10 - "$2" --bus="$bus"
      ;;
    *)
      ddcutil setvcp 10 "$2" --bus="$bus"
      ;;
    esac
  done
}

case $1 in
i)
  currentBrightness=$(get_brightness)
  if [[ "$currentBrightness" -lt 10 ]]; then
    # Increase the brightness by 1% if less than 10%
    set_brightness i 1
  else
    # Increase the brightness by 5% otherwise
    set_brightness i 5
  fi
  send_notification
  ;;
d)
  currentBrightness=$(get_brightness)
  if [[ "$currentBrightness" -le 2 ]]; then
    # Avoid 0% brightness
    set_brightness s 2
  elif [[ "$currentBrightness" -le 10 ]]; then
    # Decrease the brightness by 1% if less than 10%
    set_brightness d 1
  else
    # Decrease the brightness by 5% otherwise
    set_brightness d 5
  fi
  send_notification
  ;;
s)
  if [[ $2 -le 2 ]]; then
    # Avoid 0% brightness
    set_brightness s 2
  else
    set_brightness s "$2"
  fi
  send_notification
  ;;
g)
  send_notification
  ;;
*)
  print_error
  ;;
esac

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.

4 participants