From ebe34178fff63fc0611e26317fb7a867062daf64 Mon Sep 17 00:00:00 2001 From: Patrick Spek Date: Thu, 13 Feb 2020 14:31:01 +0100 Subject: Update glava wrapper --- .local/bin/glava | 60 ++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 48 insertions(+), 12 deletions(-) diff --git a/.local/bin/glava b/.local/bin/glava index 8979c71..c0fb164 100755 --- a/.local/bin/glava +++ b/.local/bin/glava @@ -23,9 +23,10 @@ main() [ "$OPT_HELP_ONLY" ] && usage && exit 0 # Get geometry - get_primary_monitor_geometry - width=${OPT_WIDTH:-$GEOMETRY_X} - height=${OPT_HEIGHT:-$GEOMETRY_Y} + split_xrandr_output "$(filter_size)" + + width=$GEOMETRY_X + height=$GEOMETRY_Y # Calculate dimensions glava_x=$(( ((GEOMETRY_X - width) / 2) + GEOMETRY_OFFSET_X )) @@ -44,14 +45,14 @@ opts() { OPTS=0 - while getopts ":b:hm:s:" opt + while getopts ":b:g:hm:" opt do case "$opt" in a) OPT_AUDIO=$OPTARG ; OPTS=$(( OPTS + 2 )) ;; b) OPT_BIN=$OPTARG ; OPTS=$(( OPTS + 1 )) ;; + g) OPT_GEOMETRY=$OPTARG ; OPTS=$(( OPTS + 2)) ;; h) OPT_HELP_ONLY=1 ;; m) OPT_MOD=$OPTARG ; OPTS=$(( OPTS + 2 )) ;; - s) OPT_WIDTH=${OPTARG%x*} ; OPT_HEIGHT=${OPTARG#*x} ; OPTS=$(( OPTS + 2)) ;; *) printf "Invalid option passed: %s\n" "$OPTARG" >&2 ;; @@ -63,14 +64,42 @@ opts() get_primary_monitor_geometry() { - xrandr_output=$(xrandr | grep 'connected primary' | awk '{ print $4 }' | sed 's/[x+]/ /g') + xrandr | grep 'connected primary' | awk '{ print $4 }' +} + +split_xrandr_output() +{ + fields=$(printf "%s" "$1" | sed 's/[x+]/ /g') + + if [ $(printf "%s" "$fields" | wc -w) -ne 4 ] + then + printf "Invalid size: $1\n" >&2 + exit 3 + fi - GEOMETRY_X=$(printf "%s" "$xrandr_output" | awk '{ print $1 }') - GEOMETRY_Y=$(printf "%s" "$xrandr_output" | awk '{ print $2 }') - GEOMETRY_OFFSET_X=$(printf "%s" "$xrandr_output" | awk '{ print $3 }') - GEOMETRY_OFFSET_Y=$(printf "%s" "$xrandr_output" | awk '{ print $4 }') + GEOMETRY_X=$(printf "%s" "$fields" | awk '{ print $1 }') + GEOMETRY_Y=$(printf "%s" "$fields" | awk '{ print $2 }') + GEOMETRY_OFFSET_X=$(printf "%s" "$fields" | awk '{ print $3 }') + GEOMETRY_OFFSET_Y=$(printf "%s" "$fields" | awk '{ print $4 }') - unset xrandr_output + unset fields +} + +filter_size() +{ + if [ "$OPT_GEOMETRY" ] + then + printf "%s" "$OPT_GEOMETRY" + return + fi + + if [ -f "$HOME/.local/etc/glava-xrandr-geometry" ] + then + head -n 1 "$HOME/.local/etc/glava-xrandr-geometry" + return + fi + + get_primary_monitor_geometry } usage() @@ -79,10 +108,17 @@ usage() Usage: ${0##*/} -h -Nondescript +Wrapper script for glava. Options: + -a Set audio source to visualize. Defaults to pulseaudio. + -b Set the original glava binary to wrap around. Defaults to + /usr/bin/glava. + -g Set the geometry of the visualization. This output can be retrieved + from xrandr. Defaults to using the full size of your primary + monitor. -h Show this help text and exit. + -m Set the module to use. Defaults to radial. EOF } -- cgit v1.1