Created
October 26, 2021 22:36
-
-
Save notpushkin/00b256c89c60f1eb6d303f285db436f3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Wrapper for brightnessctl, adding: | |
# - custom maximum value (useful when you override PWM settings) | |
# - smooooooooooooooooooooooooooooooooothiness | |
# - desktop notification | |
# | |
# Author: Alexander Pushkov <[email protected]> | |
# SPDX-License-Identifier: Apache-2.0 OR ISC | |
DELTA=2 | |
STEP=35 | |
MAX=560 | |
NOTIFICATION_ICON="contrast" | |
NOTIFICATION_EXPIRE_TIME=3000 | |
NOTIFICATION_ID_PATH="${XDG_RUNTIME_DIR}/backlit_notification_id" | |
notify() { | |
touch "${NOTIFICATION_ID_PATH}" | |
notification_id="$(cat ${NOTIFICATION_ID_PATH})" | |
if [[ "${notification_id}x" -eq "x" ]]; then | |
notification_id="0" | |
fi | |
gdbus call --session \ | |
--dest org.freedesktop.Notifications \ | |
--object-path /org/freedesktop/Notifications \ | |
--method org.freedesktop.Notifications.Notify \ | |
-- "" "${notification_id}" "${NOTIFICATION_ICON}" "" "" "[]" "{\"value\": <int32 ${1}>}" "int32 ${NOTIFICATION_EXPIRE_TIME}" \ | |
| sed 's/(uint32 \([0-9]\+\),)/\1/g' \ | |
> "${NOTIFICATION_ID_PATH}" | |
} | |
case "$1" in | |
-inc) | |
notify $(( ( $(brightnessctl --machine-readable | cut -d ',' -f3) + ${DELTA} * ${STEP}) * 100 / "${MAX}" )) & | |
for i in $(seq "${STEP}"); do | |
brightnessctl s "+${DELTA}" > /dev/null | |
done | |
[[ "$(brightnessctl --machine-readable | cut -d ',' -f3)" -gt "${MAX}" ]] && brightnessctl s "${MAX}" | |
;; | |
-dec) | |
notify $(( ( $(brightnessctl --machine-readable | cut -d ',' -f3) - ${DELTA} * ${STEP}) * 100 / "${MAX}" )) & | |
[[ "$(brightnessctl --machine-readable | cut -d ',' -f3)" -gt "${MAX}" ]] && brightnessctl s "${MAX}" | |
for i in $(seq "${STEP}"); do | |
brightnessctl s "${DELTA}-" > /dev/null | |
done | |
;; | |
*) | |
echo "Usage: backlit [-inc|-dec]" > /dev/stderr | |
exit 1 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment