forked from l0b0/tilde
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonitor_resolutions.sh
executable file
·70 lines (66 loc) · 2.32 KB
/
monitor_resolutions.sh
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
63
64
65
66
67
68
69
70
#!/bin/sh
#
# NAME
# monitor_resolutions.sh - Variables for monitor resolutions
#
# SYNOPSIS
# eval `./monitor_resolutions.sh`
#
# DESCRIPTION
# Prints a set of `eval`-able variable assignments with monitor name,
# width and height for each monitor plus a monitor count.
#
# EXAMPLES
# eval `./monitor_resolutions.sh`
# Assign monitor1_name, monitor1_width, monitor1_height,
# monitor2_name, etc. and monitor_count variables.
#
# BUGS
# https://github.com/l0b0/tilde/issues
#
# COPYRIGHT
# Copyright (C) 2013 Victor Engmark
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
################################################################################
monitor_info() {
xrandr --query | tee ~/.xsession-xrandr-query
}
monitor_resolutions() {
# Input: XRandR monitor info
# Output: Lines with monitor name, width and height separated by spaces
while read -r word1 word2 _
do
if [ "${word2:-}" = 'connected' ]
then
IFS='x ' read -r width height _
printf '%s %d %d\n' "$word1" "$width" "$height"
fi
done
}
monitor_assignments() {
# Input: Lines with monitor name, width and height separated by spaces
# Output: eval-able variable assignments for each input value, including a final count
count=0
while read monitor width height
do
count=$(($count + 1))
printf "monitor%d_name='%s'\n" "$count" "$monitor"
printf "monitor%d_width='%s'\n" "$count" "$width"
printf "monitor%d_height='%s'\n" "$count" "$height"
done
printf "monitor_count='%s'\n" "$count"
}
monitor_info | monitor_resolutions | monitor_assignments