hyprdots icon indicating copy to clipboard operation
hyprdots copied to clipboard

feat: scripts - ddcutil script to handle brightness control for extern…

Open Melk0rr opened this issue 1 year ago • 5 comments

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)
  • [x] 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:

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

Screenshots

screenshot_20240822_17h55m26s

Additional context

Melk0rr avatar Aug 22 '24 16:08 Melk0rr

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

guoyatingg avatar Aug 25 '24 08:08 guoyatingg

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

Melk0rr avatar Aug 25 '24 12:08 Melk0rr

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.

kRHYME7 avatar Aug 26 '24 02:08 kRHYME7

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

abenezerw avatar Sep 27 '24 06:09 abenezerw

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

abenezerw avatar Sep 27 '24 06:09 abenezerw

@Melk0rr Can I add this script in HyDE repo?

kRHYME7 avatar Aug 31 '25 23:08 kRHYME7

@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

Melk0rr avatar Sep 01 '25 13:09 Melk0rr