DEV Community

Nur Kholis M
Nur Kholis M

Posted on

Change Brightness in Linux Desktop

Issue

I don't know why PC doesn't have brightness screen control in linux desktop. Only laptop have it.

Some recommend to use ddcutil:

$ sudo ddcutil detect
Display 1
   I2C bus:  /dev/i2c-6
   DRM connector:           card1-DP-3
   EDID synopsis:
      Mfg id:               SKY - SKYDATA S.P.A.
      Model:                H24G30Q
      Product code:         9233  (0x2411)
      Serial number:        0000000000000
      Binary serial number: 0 (0x00000000)
      Manufacture year:     2024,  Week: 34
   VCP version:         2.1
$ sudo ddcutil getvcp 10
VCP code 0x10 (Brightness            ): current value = 0, max value = 100
Enter fullscreen mode Exit fullscreen mode

My monitor already have 0 brightness but it still look too bright for me. Until i found xrandr, it can make my screen brightness to black completely.

$ xrandr --output DP-3 --brigtness 0.0
Enter fullscreen mode Exit fullscreen mode

Then I make bash-script change-brightness.sh to make it simpler. but everytime I want to change brightness I have to go to terminal, I want to just click the systray icon and slide the brightness just like regular people.

Fix

Then I found yad which can turn bash script into UI using GTK. I then change my script:

$ cat ~/.local/bin/change-brightness.sh
#!/bin/sh
MON=$(xrandr -q | grep " connected" | cut -f1 -d ' ')
XR=$(xrandr --verbose | grep -i brightness | cut -f2 -d ' ' | head -n1)
BrCur=`awk "BEGIN {print $XR*100}"`
BrMax="100"
BrMin="5"
Step="5"

yad --text "Output: $MON" --text-align=left \
    --scale --step $Step --mouse --skip-taskbar --min-value $BrMin --max-value $BrMax \
    --value $BrCur --print-partial --undecorated --width 300 \
    --on-top --escape-ok --no-buttons  --close-on-unfocus \
| while read BrNew; do
    xrandr --output $MON --brightness $(awk "BEGIN {print $BrNew/100}")
done
Enter fullscreen mode Exit fullscreen mode

Add to xfce-panel

Open xfce4-panel Preferences > Items > Add "Launcher"

Click and Edit "Laucher"

Click "Add a new empty item"

Add your script here. make sure to use full path:

Now I can change my screen brightness from systray icon. 🎉

Top comments (0)