commit 067eefd65ea7fa41ed1a73ea689d770c09ba84ab
parent a7be7a84c9fcb126cdf249d112bc00114dc101c2
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date: Fri, 25 Sep 2020 12:33:18 +0200
add 'mon' script for controlling xrandr
Diffstat:
3 files changed, 86 insertions(+), 5 deletions(-)
diff --git a/.Xresources b/.Xresources
@@ -37,3 +37,10 @@ XTerm.termName: xterm-256color
XTerm.vt100.scrollBar: false
XTerm.vt100.bellIsUrgent: true
xterm*faceName: dina:pixelsize=12:antialias=false
+
+Xft.autohint: 0
+Xft.lcdfilter: lcddefault
+Xft.hintstyle: hintfull
+Xft.hinting: 0
+Xft.antialias: 0
+Xft.rgba: rgb
diff --git a/.local/bin/displayselect b/.local/bin/displayselect
@@ -1,10 +1,5 @@
#!/bin/sh
-# A UI for detecting and selecting all displays.
-# Probes xrandr for connected displays and lets user select one to use.
-# User may also select "manual selection" which opens arandr.
-# I plan on adding a routine from multi-monitor setups later.
-
twoscreen() { # If multi-monitor is selected and there are two screens.
mirror=$(printf "no\\nyes" | dmenu -i -p "Mirror displays?")
diff --git a/.local/bin/mon b/.local/bin/mon
@@ -0,0 +1,79 @@
+#!/bin/sh
+
+int=eDP-1
+int_dpi=315
+
+ext=HDMI-1
+
+res_from_xrandr() {
+ awk -v disp="$1" '
+ {
+ if (printline) { print $1; printline=0 }
+ if (match($0, disp)) { printline=1 }
+ }'
+}
+
+find_res() {
+ xrandr_q="$(xrandr -q)"
+ res_int="$(printf '%s' "$xrandr_q" | res_from_xrandr "$int")"
+ if printf '%s' "$xrandr_q" | grep -q "${ext} connected"; then
+ res_ext="$(printf '%s' "$xrandr_q" | res_from_xrandr "$ext")"
+ fi
+
+ res_int_x="${res_int%x*}"
+ res_int_y="${res_int#*x}"
+ if [ -n "$res_ext" ]; then
+ res_ext_x="${res_ext%x*}"
+ res_ext_y="${res_ext#*x}"
+ res_factor="$(printf '%d/%d\n' "${res_int_x}" "${res_ext_x}" | bc -l)"
+ fi
+}
+
+die() {
+ printf '%s: error: %s\n' "${0##*/}" "$1" >&2
+ exit 1
+}
+
+int() {
+ xrandr --dpi "$int_dpi" --fb "$res_int" \
+ --output "$int" --mode "$res_int" --scale 1x1 \
+ --output "$ext" --off
+}
+
+ext() {
+ xrandr --dpi "$int_dpi" --fb "$res_int" \
+ --output "$int" --off \
+ --output "$ext" --mode "${res_ext}" \
+ --scale "${res_factor}x${res_factor}" \
+ --panning "$res_int"
+}
+
+dual() {
+ xrandr --dpi "$int_dpi" \
+ --fb "$(printf '%d*2\n' "$res_int_x" | bc)x${res_int_y}" \
+ --output "$int" --mode "${res_int}" --scale 1x1 \
+ --output "$ext" --mode "${res_ext}" \
+ --scale "${res_factor}x${res_factor}" \
+ --right-of "$int"
+}
+
+mirror() {
+ xrandr --dpi "$int_dpi" \
+ --fb "$(printf '%d+%d\n' "$res_int_x" "$res_ext_x" | bc)x${res_int_y}" \
+ --output "$int" --auto --scale 1x1 \
+ --output "$ext" --mode "${res_ext}" \
+ --same-as "$int" --scale "${res_factor}x${res_factor}"
+}
+
+find_res
+if [ $# -eq 0 ] || [ -z "$res_ext" ]; then
+ int
+else
+ case "$1" in
+ int) int;;
+ ext) ext;;
+ dual) dual;;
+ mirror) mirror;;
+ *) die "unknown mode $1";;
+ esac
+fi