diff --git a/packages/jelos/sources/scripts/brightness b/packages/jelos/sources/scripts/brightness index a5fd42b46..e6dae6608 100755 --- a/packages/jelos/sources/scripts/brightness +++ b/packages/jelos/sources/scripts/brightness @@ -2,6 +2,9 @@ # SPDX-License-Identifier: GPL-2.0-or-later # Copyright (C) 2020-present Fewtarius +## Load minimal distribution settings to improve +## performance. +. /etc/profile.d/02-distribution BRIGHTNESS_DEV="$(find /sys/class/backlight/*/ -name brightness -print -quit)" BRIGHTNESS_PATH="${BRIGHTNESS_DEV%/brightness}" @@ -10,12 +13,6 @@ MIN=0 MAX=$(<$(find /sys/class/backlight/*/ -name max_brightness -print -quit)) STEP="$(echo "scale=1; (${MAX} / 10)" | bc)" -# Ensure set_setting exists in all contexts -if ! type set_setting &>/dev/null -then - source /etc/profile -fi - if [ ! -f "${BRIGHTNESS_DEV}" ] then echo "ERROR: There is no BRIGHTNESS object to manage." diff --git a/packages/jelos/sources/scripts/volume b/packages/jelos/sources/scripts/volume new file mode 100644 index 000000000..500626f1e --- /dev/null +++ b/packages/jelos/sources/scripts/volume @@ -0,0 +1,38 @@ +#!/bin/sh + +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (C) 2023-present Fewtarius + + +# Source minimal predefined functions and variables +# to ensure as much performance as possible. +. /etc/profile.d/02-distribution + +VOLUME=$(get_setting "audio.volume") +MAX_VOLUME=100 +MIN_VOLUME=0 +STEP=10 + +case ${1} in + "+"|"up") + VOLUME=$(( ${VOLUME} + ${STEP} )) + ;; + "-"|"down") + VOLUME=$(( ${VOLUME} - ${STEP} )) + ;; + *) + VOLUME=${1} + ;; +esac + +if (( ${VOLUME} < ${MIN_VOLUME} )) +then + VOLUME=${MIN_VOLUME} +elif (( ${VOLUME} > ${MAX_VOLUME} )) +then + VOLUME=${MAX_VOLUME} +fi + +amixer set "${DEVICE_AUDIO_MIXER}" ${VOLUME}% +alsactl store -f /storage/.config/asound.state +set_setting "audio.volume" ${VOLUME} diff --git a/packages/sysutils/system-utils/sources/scripts/headphone_sense b/packages/sysutils/system-utils/sources/scripts/headphone_sense index b76c1eaa1..c8f5f6d80 100755 --- a/packages/sysutils/system-utils/sources/scripts/headphone_sense +++ b/packages/sysutils/system-utils/sources/scripts/headphone_sense @@ -13,7 +13,7 @@ GPIO=$(cat /sys/class/gpio/gpio${DEVICE_JACK}/value) if [ -e "/storage/.config/system/configs/system.cfg" ]; then /usr/bin/system_utils setaudio $(get_setting "audio.device") -/usr/bin/system_utils vol $(get_setting "audio.volume") +/usr/bin/volume $(get_setting "audio.volume") fi # Headphone sensing diff --git a/packages/sysutils/system-utils/sources/scripts/system_utils b/packages/sysutils/system-utils/sources/scripts/system_utils index 2daa54918..d43e1aae9 100755 --- a/packages/sysutils/system-utils/sources/scripts/system_utils +++ b/packages/sysutils/system-utils/sources/scripts/system_utils @@ -7,10 +7,6 @@ # Source predefined functions and variables . /etc/profile -round() { - awk -v val=$1 'BEGIN{print int((val+5/2)/5) * 5}' -} - if [ "${1}" == "toggleaudio" ];then # Toggle audio output CURRENTAUDIO=$(get_setting "audio.device") @@ -44,31 +40,3 @@ if [ "${1}" == "setaudio" ];then esac fi -if [ "${1}" == "vol" ];then - CURRENTVOL=$(get_setting "audio.volume") - MAXVOL=100 - MINVOL=0 - VOLSTEP=10 - - [ "$CURRENTVOL" -ge "$MAXVOL" ] && CURRENTVOL="$MAXVOL" - [ "$CURRENTVOL" -le "$MINVOL" ] && CURRENTVOL="$MINVOL" - - case ${2} in - "+") - STEPVOL=$(( $CURRENTVOL + $VOLSTEP )) - ;; - "-") - STEPVOL=$(( $CURRENTVOL - $VOLSTEP )) - ;; - *) - STEPVOL=${2} - ;; - esac - - [ "$STEPVOL" -ge "$MAXVOL" ] && STEPVOL="$MAXVOL" - [ "$STEPVOL" -le "$MINVOL" ] && STEPVOL="$MINVOL" - - amixer -M set "${DEVICE_AUDIO_MIXER}" ${STEPVOL}% - alsactl store -f /storage/.config/asound.state - set_setting "audio.volume" ${STEPVOL} -fi diff --git a/packages/sysutils/system-utils/sources/scripts/volume_sense b/packages/sysutils/system-utils/sources/scripts/volume_sense index 364cb92aa..dad18707c 100755 --- a/packages/sysutils/system-utils/sources/scripts/volume_sense +++ b/packages/sysutils/system-utils/sources/scripts/volume_sense @@ -148,7 +148,7 @@ mkcontroller 2>/dev/null ||: fi else # Default to 'volume' if Fn a or b is not pressed - COMMAND="/usr/bin/system_utils vol" + COMMAND="/usr/bin/volume" UP="+" DOWN="-" REPEAT_MOD=${VOLUME_REPEAT_MOD}