aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xsetWindowSize.sh76
1 files changed, 54 insertions, 22 deletions
diff --git a/setWindowSize.sh b/setWindowSize.sh
index 8eabd83..522d5b4 100755
--- a/setWindowSize.sh
+++ b/setWindowSize.sh
@@ -2,9 +2,9 @@
# setWindowSize.sh: Sets the selected window size
#
-# Usage: template.sh [-ac] [-b OPTARG] FILE...
+# Usage: setWindowSize.sh [-p|-n]
-usageMessage="Usage: ${0} [-ac] [-b OPTARG] FILE..."
+usageMessage="Usage: ${0} [-p|-n]"
error() {
printf '%s error: %s\n' "$0" "$*" >&2
@@ -14,20 +14,28 @@ errorAndUsage() {
printf '%s error: %s\n%s\n' "$0" "$*" "$usageMessage" >&2
}
+resolutions='214 120
+427 240
+720 480
+800 600
+854 480
+1280 720
+1920 1080'
+
+prev=''
+next=''
+newResolution=''
+
# Process options
-while getopts ':ab:c' opt; do
+while getopts ':pn' opt; do
case $opt in
- 'a' )
- echo a
- ;;
-
- 'b' )
- echo b "$OPTARG"
+ 'p' )
+ prev='y'
;;
- 'c' )
- echo c
+ 'n' )
+ next='y'
;;
'?' )
@@ -38,15 +46,39 @@ while getopts ':ab:c' opt; do
done
shift $((OPTIND - 1))
-resolution="$(\
-printf \
-'214 120
-427 240
-854 480
-720 480
-800 600
-1280 720
-1920 1080' |
- dmenu -l 5 -p 'Resolution:')"
+windowId="$(xdotool getwindowfocus)"
+currentWidth="$(xwininfo -id "$windowId" | grep 'Width:' | awk '{print $2}')"
+currentHeight="$(xwininfo -id "$windowId" | grep 'Height:' | awk '{print $2}')"
+currentResolution="${currentWidth} ${currentHeight}"
+
+if [ -n "$prev" ] && [ -n "$next" ]; then
+
+ errorAndUsage '-p and -n can not be used together.'
+ exit 1
+
+elif [ -n "$next" ]; then
+
+ newResolution="$(printf '%s' "$resolutions" | grep -A 1 "^${currentResolution}$" | tail -n 1)"
+ # If resolution is the biggest, pick the smallest
+ if [ "$newResolution" = "$currentResolution" ]; then
+ newResolution="$(printf '%s' "$resolutions" | sed '1q')"
+ fi
+
+elif [ -n "$prev" ]; then
+
+ newResolution="$(printf '%s' "$resolutions" | grep -B 1 "^${currentResolution}$" | sed '1q')"
+ # If resolution is the smallest, pick the biggest
+ if [ "$newResolution" = "$currentResolution" ]; then
+ newResolution="$(printf '%s' "$resolutions" | tail -n 1)"
+ fi
+
+else
+
+ resolutionCount="$(printf '%s' "$resolutions" | wc -l)"
+ resolutionCount="$((resolutionCount + 1))"
+
+ newResolution="$(printf '%s' "$resolutions" | dmenu -l "$resolutionCount" -p 'Resolution:')"
+
+fi
-xdotool getwindowfocus -- windowsize $resolution
+xdotool getwindowfocus -- windowsize $newResolution