diff --git a/bin/brightness.bash b/bin/brightness.bash index cd4ff19..4aa82ed 100755 --- a/bin/brightness.bash +++ b/bin/brightness.bash @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env clopper-ob-bash ## # Change brightness and show a notification @@ -11,18 +11,6 @@ current-brightness() { xrandr --current --verbose | grep -Pom 1 '(?<=Brightness: ).*' } -bar() { - declare -i count="$1" - [[ $count -eq 0 ]] && return 0 - printf '─' - ((count--)) - bar "$count" -} - -prefix-with-zero-point() { - echo "0.$1" -} - current-output() { xrandr --query | grep -Po '^.*(?= connected)' } @@ -33,13 +21,13 @@ set-brightness() { } notify-brightness() { - notify-send.sh -i '/usr/share/icons/Numix/48/notifications/notification-display-brightness.svg' \ + notify-send.sh -i "$(icon brightness)" \ --replace-file=$HOME/.cache/clopper-ob/brightness.id \ - " $(bar $((3 * $(multiply-by-10-and-strip-decimals $(current-brightness)))))" + " $(bar $((2 * $(multiply-by-10-and-strip-decimals $(current-brightness)))))" } increase-brightness() { - if [[ $(multiply-by-10-and-strip-decimals $(current-brightness)) -ge 10 ]]; then + if [[ $(multiply-by-10-and-strip-decimals $(current-brightness)) -ge 12 ]]; then return 0 fi diff --git a/bin/clopper-ob-bash b/bin/clopper-ob-bash new file mode 100755 index 0000000..917c2c2 --- /dev/null +++ b/bin/clopper-ob-bash @@ -0,0 +1,13 @@ +#!/bin/bash +## +# This is the code-clopper-opebox specific bash. It should be used to execute bash +# scripts that need some standard functions to be predefined. + +here() { + dirname "$(readlink -f "${BASH_SOURCE[0]}")" +} + +source "$(here)/../lib/common-functions.bash" + +# Source any script that is passed as parameter and pass it all other arguments. +source "$@" \ No newline at end of file diff --git a/bin/sound.bash b/bin/sound.bash new file mode 100755 index 0000000..d37c88a --- /dev/null +++ b/bin/sound.bash @@ -0,0 +1,67 @@ +#!/usr/bin/env clopper-ob-bash +## +# Sound controlls + +set -eo pipefail + +master-percentage() { + amixer -D pulse get Master | grep -Pom 1 '(?<=\[)[0-9]+(?=%\])' +} + +master-status() { + amixer -D pulse get Master | grep -Pom 1 '(?<=\[)(on|off)(?=\]$)' +} + +master-is-on() { + [[ $(master-status) == 'on' ]] +} + +increase-master() { + declare master_percentage='' + master_percentage="$(master-percentage)" + [[ $master_percentage -le 100 ]] || return 1 + amixer -D pulse set Master $((master_percentage + 8))'%' +} + +decrease-master() { + declare master_percentage='' + master_percentage="$(master-percentage)" + [[ $master_percentage -ge 0 ]] || return 1 + amixer -D pulse set Master $((master_percentage - 8))'%' +} + +disable-master() { + amixer -D pulse set Master off +} + +enable-master() { + amixer -D pulse set Master on +} + +notify-volume() { + notify-send.sh -i "$(icon sound-up)" \ + --replace-file="$HOME/.cache/clopper-ob/sound.id" \ + " $(bar $(($(master-percentage)/4)))" + play-sound volume-change +} + +case "$1" in + +) + increase-master + notify-volume + ;; + -) + decrease-master + notify-volume + ;; + toggle) + if master-is-on; then + disable-master + notify-send.sh -i "$(icon sound-off)" 'Muted' \ + --replace-file="$HOME/.cache/clopper-ob/sound.id" + else + enable-master + notify-volume + fi + ;; +esac diff --git a/config/openbox/rc.xml b/config/openbox/rc.xml index ce2f323..f6a7602 100644 --- a/config/openbox/rc.xml +++ b/config/openbox/rc.xml @@ -203,6 +203,22 @@ brightness.bash - + + + sound.bash + + + + + + sound.bash - + + + + + sound.bash toggle + + + diff --git a/developer_env.bash b/developer_env.bash new file mode 100644 index 0000000..e191639 --- /dev/null +++ b/developer_env.bash @@ -0,0 +1,5 @@ +## +# This file should be sourced when testing scripts locally in the project folder, otherwise +# the already installed clopper-ob-bash would be used and libraries wouldn't be refreshed. + +PATH="$(pwd)/bin:$PATH" /bin/bash -i diff --git a/lib/common-functions.bash b/lib/common-functions.bash new file mode 100644 index 0000000..2d1f2d1 --- /dev/null +++ b/lib/common-functions.bash @@ -0,0 +1,39 @@ +#!/bin/bash +## +# Some commonly used functions for clopper-ob + +here() { + dirname "$(readlink -f "${BASH_SOURCE[0]}")" +} + +bar() { + declare -i count="$1" + [[ $count -eq 0 ]] && return 0 + printf '─' + ((count--)) + bar "$count" +} + +icon() { + declare notif_icons='/usr/share/icons/Numix/48/notifications' + case "$1" in + brightness) + echo -n "$notif_icons/notification-display-brightness.svg" + ;; + sound-up) + echo -n "$notif_icons/notification-audio-volume-high.svg" + ;; + sound-off) + echo -n "$notif_icons/notification-audio-volume-muted.svg" + ;; + esac +} + +play-sound() { + declare sound_dir='/usr/share/sounds/freedesktop/stereo' + case "$1" in + volume-change) + ogg123 "$sound_dir/audio-volume-change.oga" + ;; + esac +} diff --git a/setup.bash b/setup.bash index 1ab4b2a..2c07efb 100755 --- a/setup.bash +++ b/setup.bash @@ -14,7 +14,15 @@ install-apt-dependencies() { echo "=> Installing apt dependencies" set -x sudo apt-get update && \ - sudo apt-get install xcompmgr openbox albert plank dunst numix-icon-theme-circle + sudo apt-get install \ + xcompmgr \ + openbox \ + albert \ + plank \ + dunst \ + numix-icon-theme-circle \ + vorbis-tools \ + sound-theme-freedesktop set +x } @@ -25,9 +33,13 @@ are-in-path() { are-in-path "$@" } +asset-dirs-exist() { + [[ -d /usr/share/icons/Numix-Circle ]] && [[ -d /usr/share/sounds/freedesktop ]] +} + install-dependencies() { echo "=> Checking dependencies" - if ! are-in-path xcompmgr openbox dunst || ! [[ -d /usr/share/icons/Numix-Circle ]]; then + if ! are-in-path xcompmgr openbox dunst ogg123 || ! asset-dirs-exist; then install-apt-dependencies fi @@ -114,17 +126,22 @@ create-local-dir() { mkdir -p "$(local-dir)" } -copy-bins() { +copy-bins-to-local-dir() { cp -r "$(here)/bin" "$(local-dir)/" } +copy-libs-to-local-dir() { + cp -r "$(here)/lib" "$(local-dir)/" +} + setup-openbox-for-user() { add-ppas install-dependencies copy-config create-cache-dir create-local-dir - copy-bins + copy-bins-to-local-dir + copy-libs-to-local-dir add-custom-startup echo "=> Finished"