Skip to content

Commit f6f838b

Browse files
author
nnyyxxxx
committed
fix issues with set brightness
1 parent 3c4a5dc commit f6f838b

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

core/tabs/utils/monitor-control/set_brightness.sh

100644100755
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,14 @@
66
adjust_monitor_brightness() {
77
while true; do
88
monitor_list=$(detect_connected_monitors)
9-
monitor_array=$(echo "$monitor_list" | tr '\n' ' ')
10-
set -- "$monitor_array"
119
count=1
1210

1311
clear
1412
printf "%b\n" "${YELLOW}=========================================${RC}"
1513
printf "%b\n" "${YELLOW} Adjust Monitor Brightness${RC}"
1614
printf "%b\n" "${YELLOW}=========================================${RC}"
1715
printf "%b\n" "${YELLOW}Choose a monitor to adjust brightness:${RC}"
18-
for monitor in "$@"; do
16+
echo "$monitor_list" | while IFS= read -r monitor; do
1917
echo "$count. $monitor"
2018
count=$((count + 1))
2119
done
@@ -35,18 +33,18 @@ adjust_monitor_brightness() {
3533
continue
3634
fi
3735

38-
if [ "$monitor_choice" -lt 1 ] || [ "$monitor_choice" -gt "$#" ]; then
36+
monitor_count=$(echo "$monitor_list" | wc -l)
37+
if [ "$monitor_choice" -lt 1 ] || [ "$monitor_choice" -gt "$monitor_count" ]; then
3938
printf "%b\n" "${RED}Invalid selection. Please try again.${RC}"
4039
printf "Press [Enter] to continue..."
4140
read -r dummy
4241
continue
4342
fi
4443

45-
monitor_name=$(eval echo "\${$monitor_choice}")
44+
monitor_name=$(echo "$monitor_list" | sed -n "${monitor_choice}p")
4645
current_brightness=$(get_current_brightness "$monitor_name")
4746

48-
# Correctly calculate the brightness percentage
49-
current_brightness_percentage=$(awk "BEGIN {printf \"%.0f\", $current_brightness * 100}")
47+
current_brightness_percentage=$(awk -v brightness="$current_brightness" 'BEGIN {printf "%.0f", brightness * 100}')
5048
printf "%b\n" "${YELLOW}Current brightness for $monitor_name${RC}: ${GREEN}$current_brightness_percentage%${RC}"
5149

5250
while true; do

0 commit comments

Comments
 (0)