|  | @@ -0,0 +1,53 @@
 | 
											
												
													
														|  | 
 |  | +#!/bin/bash
 | 
											
												
													
														|  | 
 |  | +# Brightness slider for external monitor using ddcutil
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +# Monitor configuration
 | 
											
												
													
														|  | 
 |  | +MONITOR_SERIAL="6L1M413"
 | 
											
												
													
														|  | 
 |  | +VCP_CODE=10
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +# Get current brightness (VCP code 10)
 | 
											
												
													
														|  | 
 |  | +current_output=$(ddcutil getvcp --sn "$MONITOR_SERIAL" "$VCP_CODE" 2>/dev/null)
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +if [ $? -ne 0 ] || [ -z "$current_output" ]; then
 | 
											
												
													
														|  | 
 |  | +    echo "Error: Could not communicate with monitor $MONITOR_SERIAL" >&2
 | 
											
												
													
														|  | 
 |  | +    exit 1
 | 
											
												
													
														|  | 
 |  | +fi
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +# Parse current brightness from output like "VCP code 0x10 (Brightness): current value = 50, max value = 100"
 | 
											
												
													
														|  | 
 |  | +current_percent=$(echo "$current_output" | grep -oP 'current value\s*=\s*\K\d+')
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +if [ -z "$current_percent" ]; then
 | 
											
												
													
														|  | 
 |  | +    echo "Error: Could not parse brightness value" >&2
 | 
											
												
													
														|  | 
 |  | +    exit 1
 | 
											
												
													
														|  | 
 |  | +fi
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +# Round to nearest 5
 | 
											
												
													
														|  | 
 |  | +current_percent=$(((current_percent + 2) / 5 * 5))
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +# Generate brightness levels
 | 
											
												
													
														|  | 
 |  | +levels=""
 | 
											
												
													
														|  | 
 |  | +for i in {0..100..5}; do
 | 
											
												
													
														|  | 
 |  | +    if [ "$i" -eq "$current_percent" ]; then
 | 
											
												
													
														|  | 
 |  | +        levels+="● $i%\n"
 | 
											
												
													
														|  | 
 |  | +    else
 | 
											
												
													
														|  | 
 |  | +        levels+="  $i%\n"
 | 
											
												
													
														|  | 
 |  | +    fi
 | 
											
												
													
														|  | 
 |  | +done
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +# Show menu and get selection
 | 
											
												
													
														|  | 
 |  | +selected=$(echo -e "$levels" | bemenu -l 15 -p " Monitor Brightness" --counter always -c -W 0.2 -B 10 \
 | 
											
												
													
														|  | 
 |  | +    --fixed-height --fn 'B612 11' \
 | 
											
												
													
														|  | 
 |  | +    --bdr "#323232" --tf "#FFFFFF" --hf "#FFFFFF")
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +# Exit if nothing selected
 | 
											
												
													
														|  | 
 |  | +if [ -z "$selected" ]; then
 | 
											
												
													
														|  | 
 |  | +    exit 0
 | 
											
												
													
														|  | 
 |  | +fi
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +# Extract percentage from selection
 | 
											
												
													
														|  | 
 |  | +percent=$(echo "$selected" | grep -oP '\d+(?=%)')
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +# Set brightness
 | 
											
												
													
														|  | 
 |  | +if [ -n "$percent" ]; then
 | 
											
												
													
														|  | 
 |  | +    ddcutil setvcp --sn "$MONITOR_SERIAL" "$VCP_CODE" "$percent"
 | 
											
												
													
														|  | 
 |  | +fi
 |