summaryrefslogtreecommitdiff
path: root/waybar
diff options
context:
space:
mode:
Diffstat (limited to 'waybar')
-rwxr-xr-xwaybar/brightness69
-rw-r--r--waybar/config.jsonc14
-rw-r--r--waybar/style.css1
3 files changed, 82 insertions, 2 deletions
diff --git a/waybar/brightness b/waybar/brightness
new file mode 100755
index 0000000..138f5ee
--- /dev/null
+++ b/waybar/brightness
@@ -0,0 +1,69 @@
+#!/usr/bin/env 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
+ # ddcutil terse output format: "VCP 10 C <current> <max>"
+ initial_brightness=$(ddcutil --display $DISPLAY_NUM getvcp 10 -t 2>/dev/null | awk '{print $4}')
+ # Fallback to 50 if ddcutil fails or returns non-numeric
+ if ! [[ "$initial_brightness" =~ ^[0-9]+$ ]]; then
+ initial_brightness=50
+ fi
+ echo "$initial_brightness" >"$STATE_FILE"
+fi
+
+current=$(cat "$STATE_FILE")
+# Validate current is a number, fallback to 50 if corrupted
+if ! [[ "$current" =~ ^[0-9]+$ ]]; then
+ current=50
+ echo "$current" >"$STATE_FILE"
+fi
+
+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+9 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+9 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+9 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+9 waybar
+ ;;
+esac
diff --git a/waybar/config.jsonc b/waybar/config.jsonc
index fd82389..1583fe5 100644
--- a/waybar/config.jsonc
+++ b/waybar/config.jsonc
@@ -10,6 +10,7 @@
],
"modules-right": [
"tray",
+ "custom/brightness",
"network",
"pulseaudio",
"bluetooth",
@@ -66,8 +67,6 @@
"alsa_output.pci-0000_00_1f.3.analog-stereo": "",
"alsa_output.pci-0000_00_1f.3.analog-stereo-muted": "",
"headphone": "",
- "hands-free": "",
- "headset": "",
"phone": "",
"phone-muted": "",
"portable": "",
@@ -100,5 +99,16 @@
"exec": "~/.config/waybar/niri-workspaces",
"return-type": "json",
"format": "{}"
+ },
+ "custom/brightness": {
+ "format": "☀ {}%",
+ "tooltip-format": "EXT: ☀ {}%",
+ "interval": "once",
+ "signal": 9,
+ "exec": "~/.config/waybar/brightness get",
+ "on-scroll-up": "~/.config/waybar/brightness up",
+ "on-scroll-down": "~/.config/waybar/brightness down",
+ "on-click": "~/.config/waybar/brightness left_click",
+ "on-click-right": "~/.config/waybar/brightness right_click"
}
}
diff --git a/waybar/style.css b/waybar/style.css
index 6590d83..f6734ca 100644
--- a/waybar/style.css
+++ b/waybar/style.css
@@ -18,6 +18,7 @@ window#waybar {
#clock,
#battery,
#window,
+#custom-brightness,
#memory,
#network,
#mpris,