#! /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 split_xrandr_output "$(filter_size)" width=$GEOMETRY_X 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: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 )) ;; *) printf "Invalid option passed: %s\n" "$OPTARG" >&2 ;; esac done unset opt } get_primary_monitor_geometry() { 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" "$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 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() { cat <