Skip to content

Instantly share code, notes, and snippets.

@negoro26
Last active October 22, 2025 10:29
Show Gist options
  • Save negoro26/c59167fb4c08da46c4e08e1fdcd7aeb1 to your computer and use it in GitHub Desktop.
Save negoro26/c59167fb4c08da46c4e08e1fdcd7aeb1 to your computer and use it in GitHub Desktop.
Waybar DDC/CI brightness control script

Control external monitor brightness using ddcutil with Waybar integration.

Features

  • Left click: Set brightness to 100%
  • Right click: Set brightness to 0%
  • Scroll: Fine adjustment (optional)
  • Instant updates via signals

Requirements

  • ddcutil installed

Usage

  • Make sure to make the script executable!
  • chmod +x brightness-control.sh

Waybar config

"custom/brightness": {
    "format": " {text}%",
    "signal": 8,
    "exec": "~/.config/waybar/scripts/brightness.sh get",
    "on-scroll-up": "~/.config/waybar/scripts/brightness.sh up",
    "on-scroll-down": "~/.config/waybar/scripts/brightness.sh down",
    "on-click": "~/.config/waybar/scripts/brightness.sh left_click",
    "on-click-right":  "~/.config/waybar/scripts/brightness.sh right_click"
},
#!/bin/bash
# --- CONFIGURATION ---
DISPLAY_NUM=1
STEP=5
STATE_FILE="/tmp/waybar_brightness.tmp"
# ---------------------
# Function to send the actual DDC/CI command in the background
set_brightness_in_background() {
pkill -f "ddcutil.*setvcp 10"
(ddcutil --display $DISPLAY_NUM setvcp 10 $1) &
}
# Ensure state file exists, or create it by querying the monitor
if [ ! -f "$STATE_FILE" ]; then
initial_brightness=$(ddcutil --display $DISPLAY_NUM getvcp 10 -t | awk '/value/ {print $4}' || echo "?")
echo "$initial_brightness" > "$STATE_FILE"
fi
current=$(cat "$STATE_FILE")
case "$1" in
"get")
echo " $current"
;;
"up")
new_brightness=$((current + STEP > 100 ? 100 : current + STEP))
if [ "$current" -ne "$new_brightness" ]; then
echo "$new_brightness" > "$STATE_FILE"
set_brightness_in_background "$new_brightness"
fi
pkill -RTMIN+8 waybar # Can add whatever RTMIN+n you please, as long as it's an integer. Make sure the signals match between the config and script.
;;
"down")
new_brightness=$((current - STEP < 0 ? 0 : current - STEP))
if [ "$current" -ne "$new_brightness" ]; then
echo "$new_brightness" > "$STATE_FILE"
set_brightness_in_background "$new_brightness"
fi
pkill -RTMIN+8 waybar
;;
"right_click")
new_brightness=0
if [ "$current" -ne "$new_brightness" ]; then
echo "$new_brightness" > "$STATE_FILE"
set_brightness_in_background "$new_brightness"
fi
pkill -RTMIN+8 waybar
;;
"left_click")
new_brightness=100
if [ "$current" -ne "$new_brightness" ]; then
echo "$new_brightness" > "$STATE_FILE"
set_brightness_in_background "$new_brightness"
fi
pkill -RTMIN+8 waybar
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment