Add sound function keys and clopper-ob-bash command

master
Hugo Thunnissen 6 years ago
parent 3d0ca07644
commit 27165fcac3

@ -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

@ -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 "$@"

@ -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

@ -203,6 +203,22 @@
<execute>brightness.bash -</execute>
</action>
</keybind>
<keybind key="XF86AudioRaiseVolume">
<action name="Execute">
<execute>sound.bash +</execute>
</action>
</keybind>
<keybind key="XF86AudioLowerVolume">
<action name="Execute">
<execute>sound.bash -</execute>
</action>
</keybind>
<keybind key="XF86AudioMute">
<action name="Execute">
<execute>sound.bash toggle</execute>
</action>
</keybind>
<!-- Keybindings for desktop switching -->
<keybind key="C-A-Left">

@ -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

@ -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
}

@ -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"

Loading…
Cancel
Save