summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@datawire.io>2019-05-17 14:29:41 -0400
committerLuke Shumaker <lukeshu@datawire.io>2019-05-17 14:29:41 -0400
commit8c94ca486138a5a07f67e0fa5c35073bc7f4ce3b (patch)
tree4e901cd80bea5f7deac38e35c06724fd3655aed4
parent7685c49b1fef4f5eb9beeca1bf0bfe8ab2888d3f (diff)
fix-dpi: Add a per-device DPI override
-rwxr-xr-x.local/bin/fix-dpi21
1 files changed, 20 insertions, 1 deletions
diff --git a/.local/bin/fix-dpi b/.local/bin/fix-dpi
index b700ea9..afcb4a1 100755
--- a/.local/bin/fix-dpi
+++ b/.local/bin/fix-dpi
@@ -45,14 +45,18 @@ usage() {
printf ' --render-dpi=<auto|auto-hwonly|DPI|XDPIxYDPI>\n'
printf ' Specify what DPI applications should render\n'
printf ' at (default: auto)\n'
+ printf ' --device-dpi=OUTPUT=<DPI|XDPIxYDPI>\n'
+ printf ' Override the hardware-reported DPI for'
+ printf ' the X11 output OUTPUT\n'
}
set -euE -o pipefail
-args=$(getopt -n "${0##*/}" -o 'hn' -l 'help,dry-run,render-dpi:' -- "$@") || errusage
+args=$(getopt -n "${0##*/}" -o 'hn' -l 'help,dry-run,render-dpi:,device-dpi:' -- "$@") || errusage
eval "set -- $args"
arg_dry_run=false
arg_render_dpi=auto
+declare -A arg_device_dpi
while (( $# > 0 )); do
case "$1" in
-h|--help)
@@ -77,6 +81,17 @@ while (( $# > 0 )); do
esac
shift 2
;;
+ --device-dpi)
+ if [[ "$2" != *=* ]]; then
+ errusage 'Invalid --device-dpi=%q' "$2"
+ fi
+ device=${2%=*}
+ dpi=${2##*=}
+ if ! arg_device_dpi["$device"]="$(sanitize "${dpi%%x*}" 2>/dev/null)x$(sanitize "${dpi#*x}" 2>/dev/null)"; then
+ errusage 'Invalid --device-dpi=%q' "$2"
+ fi
+ shift 2
+ ;;
--)
shift
break
@@ -96,6 +111,9 @@ if [[ $arg_render_dpi == auto ]] || [[ $arg_render_dpi == auto-hwonly ]]; then
if [[ $arg_render_dpi == auto-hwonly ]] && [[ $source != X11-RandR-hw ]]; then
continue
fi
+ if [[ $source == X11-RandR-hw ]]; then
+ dpi=${arg_device_dpi["$item"]:-"$dpi"}
+ fi
arg_render_xdpi=$(max "$(round "${dpi%%x*}")" "$arg_render_xdpi")
arg_render_ydpi=$(max "$(round "${dpi#*x}")" "$arg_render_ydpi")
done <<<"$dpis"
@@ -116,6 +134,7 @@ fi
if [[ $source != X11-RandR-hw ]]; then
continue
fi
+ dpi=${arg_device_dpi["$item"]:-"$dpi"}
hw_xdpi="$(sanitize "${dpi%%x*}")"
hw_ydpi="$(sanitize "${dpi#*x}")"