From 7520bd4b96fe74c85b6ca1da8e1ddbc298143530 Mon Sep 17 00:00:00 2001 From: Patrick Spek Date: Thu, 13 Feb 2020 14:01:52 +0100 Subject: Include glava --- .local/bin/glava | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100755 .local/bin/glava (limited to '.local/bin') diff --git a/.local/bin/glava b/.local/bin/glava new file mode 100755 index 0000000..8979c71 --- /dev/null +++ b/.local/bin/glava @@ -0,0 +1,89 @@ +#! /usr/bin/env sh + +# This program is free software: you can redistribute it and/or modify it under +# the terms of the GNU Affero General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) any +# later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more +# details. + +readonly BIN=${OPT_BIN:-/usr/bin/glava} + +main() +{ + # Handle opts + opts "$@" + shift "$OPTS" + unset OPTS + + # Show help + [ "$OPT_HELP_ONLY" ] && usage && exit 0 + + # Get geometry + get_primary_monitor_geometry + width=${OPT_WIDTH:-$GEOMETRY_X} + height=${OPT_HEIGHT:-$GEOMETRY_Y} + + # Calculate dimensions + glava_x=$(( ((GEOMETRY_X - width) / 2) + GEOMETRY_OFFSET_X )) + glava_y=$(( ((GEOMETRY_Y - height) / 2) + GEOMETRY_OFFSET_Y )) + + # Run glava + "$BIN" \ + --force-mod="${OPT_MOD:-radial}" \ + --audio="${OPT_AUDIO:-pulseaudio}" \ + --request="setgeometry $glava_x $glava_y $width $height" \ + --desktop \ + "$@" +} + +opts() +{ + OPTS=0 + + while getopts ":b:hm:s:" opt + do + case "$opt" in + a) OPT_AUDIO=$OPTARG ; OPTS=$(( OPTS + 2 )) ;; + b) OPT_BIN=$OPTARG ; OPTS=$(( OPTS + 1 )) ;; + 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 + ;; + esac + done + + unset opt +} + +get_primary_monitor_geometry() +{ + xrandr_output=$(xrandr | grep 'connected primary' | awk '{ print $4 }' | sed 's/[x+]/ /g') + + 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 }') + + unset xrandr_output +} + +usage() +{ + cat <