+current_cfg_disper() {
+ $DISPER -p
+}
+
+common_cfg_xrandr() {
+ $XRANDR -q | awk '
+ # variables:
+ # output: current output
+ # outputlist: space sep list of all outputs
+ # outputarr: array of all connected outputs
+ # outputarrsize: number of connected outputs
+ # modelist[800x600]: space sep list of outputs supporting mode
+ # display is connected
+ /^[^ ]+ connected / {
+ output=$1;
+ outputlist=outputlist " " output
+ outputarr[outputarrsize++]=output
+ }
+ # disconnected or disabled displays
+ /^[^ ]+ disconnected / ||
+ /^[^ ]+ unknown connection / {
+ print "output " $1;
+ print "off";
+ }
+ # modes available on a screen
+ /^ [0-9]+x[0-9]+/ {
+ modelist[$1]=modelist[$1] " " output
+ }
+ END {
+ # find common mode with largest screen area
+ for (m in modelist) {
+ if (modelist[m] == outputlist) {
+ # calculate area of resolution
+ split(m, wh, "x");
+ if (wh[1]*wh[2] >= maxdim) {
+ maxdim=wh[1]*wh[2]
+ maxmode=m
+ }
+ }
+ }
+ if (maxmode) {
+ for (i in outputarr) {
+ print "output " outputarr[i];
+ print "mode " maxmode;
+ print "pos 0x0";
+ if (i > 0) {
+ print "same-as " outputarr[0]
+ }
+ }
+ }
+ }' \
+ | load_cfg_xrandr -
+}
+
+stack_cfg_xrandr() {
+ $XRANDR -q | awk -v stack="${STACK}" '
+ # variables:
+ # stack: "horizontal" (anything except vertical) or "vertical"
+ # output: current output
+ # firstmode: pick first mode after output
+ # posX,posY: position of the next output
+ BEGIN {
+ posX=posY=0
+ }
+ # display is connected
+ /^[^ ]+ connected / {
+ output=$1;
+ print "output " $1;
+ firstmode=1
+ }
+ # disconnected or disabled displays
+ /^[^ ]+ disconnected / ||
+ /^[^ ]+ unknown connection / {
+ print "output " $1;
+ print "off";
+ }
+ # modes available on a screen, but pick only the first
+ /^ [0-9]+x[0-9]+/ {
+ if (!firstmode) next;
+ firstmode=0
+ # output mode at current virtual desktop pos
+ print "mode " $1;
+ print "pos " posX "x" posY;
+ # calculate position of next output
+ split($1, wh, "x");
+ if (stack == "vertical")
+ posY += wh[2];
+ else
+ posX += wh[1];
+ }' \
+ | load_cfg_xrandr -
+}
+
+current_cfg() {
+ $CURRENT_CFG_METHOD;
+}
+