Oh, and finally pushed the ai.py script I have been using for some time without pushing. I guess several months of testing should be fine. lol
71 lines
2.6 KiB
Bash
Executable File
71 lines
2.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# This file is part of I38.
|
|
|
|
# I38 is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation,
|
|
# either version 3 of the License, or (at your option) any later version.
|
|
|
|
# I38 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
# PURPOSE. See the GNU General Public License for more details.
|
|
|
|
# You should have received a copy of the GNU General Public License along with I38. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
# Not for multiple screens.
|
|
# Detect if we're on Wayland or X11
|
|
if [[ -n "${WAYLAND_DISPLAY}" ]]; then
|
|
# Sway/Wayland: Get the name of the first output
|
|
screenName="$(swaymsg -t get_outputs | jq -r '.[0].name')"
|
|
if [[ -z "$screenName" ]]; then
|
|
notify-send "Error: Could not detect output"
|
|
exit 1
|
|
fi
|
|
else
|
|
# i3/X11: Get the name of the screen
|
|
if ! command -v xrandr &> /dev/null; then
|
|
notify-send "Error: xrandr not found"
|
|
exit 1
|
|
fi
|
|
screenName="$(xrandr --query | grep "connected" | cut -d ' ' -f1 | head -n 1)"
|
|
fi
|
|
|
|
menuOptions=(
|
|
"1.0" "Maximum Brightness"
|
|
"0.75" "75 percent"
|
|
"0.5" "50 percent"
|
|
"0.25" "25 percent"
|
|
"0" "Screen Curtain"
|
|
)
|
|
|
|
brightness="$(yad --list --title "I38" --text "Set Screen Brightness" --columns 2 --hide-column 1 --column "" --column "Select" "${menuOptions[@]}")"
|
|
|
|
if [[ ${#brightness} -lt 1 ]]; then
|
|
exit 0
|
|
fi
|
|
|
|
# Apply brightness setting
|
|
if [[ -n "${WAYLAND_DISPLAY}" ]]; then
|
|
# Sway: Use swaymsg to set output brightness
|
|
# Note: Sway doesn't have native brightness control, using wlr-randr if available
|
|
if command -v wlr-randr &> /dev/null; then
|
|
wlr-randr --output "${screenName}" --brightness "${brightness%%|*}" &&
|
|
spd-say -P important -Cw "Screen set to ${brightness#*|}."
|
|
else
|
|
# Fallback to gamma adjustment via wl-gammactl or brightnessctl
|
|
if command -v brightnessctl &> /dev/null; then
|
|
brightnessValue=$(echo "${brightness%%|*} * 100" | bc)
|
|
brightnessctl set "${brightnessValue%.*}%" &&
|
|
spd-say -P important -Cw "Screen set to ${brightness#*|}."
|
|
else
|
|
notify-send "Error: wlr-randr or brightnessctl required for Sway brightness control"
|
|
exit 1
|
|
fi
|
|
fi
|
|
else
|
|
# i3: Use xrandr
|
|
xrandr --output "${screenName}" --brightness "${brightness%%|*}" &&
|
|
spd-say -P important -Cw "Screen set to ${brightness#*|}."
|
|
fi
|
|
|
|
exit 0
|