-
Notifications
You must be signed in to change notification settings - Fork 1
/
dattr
executable file
·63 lines (52 loc) · 1.43 KB
/
dattr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/sh
#
# Copyright (c) 2015 Laserswald, liscensed under the WTFPL
# Get the geometry of the given display.
# Global order of things.
order=""
## Function definitions.
usage () {
echo "usage: $(basename $0) [-axywh] DISPLAY"
exit 1
}
# Convert width and height coords to absolute coords
absolute () {
w=$(( $1 + $3 ))
h=$(( $2 + $4 ))
echo $w $h $3 $4
}
## Get the geometries of the connected monitors.
#
# @return a table of connected monitors, with the name of the monitor and then the XYWH of the monitor as fields.
function get_geos() {
echo "$(xrandr | grep -e " connected" | sed "s/ primary//g" | cut --delimiter=' ' --fields='1,3')"
}
function show_geo() { w=$1; h=$2; x=$3; y=$4;
for item in $order; do
case $item in
x) printf "$x " ;;
y) printf "$y " ;;
w) printf "$w " ;;
h) printf "$h " ;;
esac
done
printf "\n"
}
# Parse them options. Do it.
while getopts axywh flag; do
case $flag in
a) GIVE_ABS=1 ;;
x|y|w|h) order=$(echo $order $flag);; # crude queue
?) usage ;;
esac
done
shift $(( OPTIND - 1 ))
display=$1
# No given display? Ain't having that.
test -z $display && usage
# Default order
test $order || order='x y w h '
# Get the current display's geometry
geo=$(echo "$(get_geos)" | grep $display | cut -d' ' -f2 | tr '+x' ' ')
test $GIVE_ABS && geo=$(absolute $geo)
show_geo $geo