From cdb603a3f2ac8cd24720245947749a863cb795ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=20Schr=C3=B6der?= Date: Sun, 31 Mar 2019 15:15:31 +0200 Subject: [PATCH] Automatically deduce DPI (#110) With this commit the DPI doesn't have to be listed in the ~/.Xresources and will be deduced automatically. --- betterlockscreen | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/betterlockscreen b/betterlockscreen index d58d8aa..8f98f7f 100755 --- a/betterlockscreen +++ b/betterlockscreen @@ -145,9 +145,11 @@ lockselect() { postlock } +# $1: number of pixels to convert +# $2: 1 for width. 2 for height logical_px() { # get dpi value from xrdb - local DPI=$(xrdb -query | awk '/Xft.dpi/ {print $2}') + local DPI=$(xdpyinfo | sed -En "s/\s*resolution:\s*([0-9]*)x([0-9]*)\s.*/\\$2/p" | head -n1) # return the default value if no DPI is set if [ -z "$DPI" ]; then @@ -175,9 +177,9 @@ update() { SR=$(xrandr --query | grep ' connected' | grep -o '[0-9][0-9]*x[0-9][0-9]*[^ ]*') for RES in $SR; do SRA=(${RES//[x+]/ }) - CX=$((${SRA[2]} + $(logical_px 25))) - CY=$((${SRA[1]} - $(logical_px 30))) - rectangles+="rectangle $CX,$CY $((CX+$(logical_px 300))),$((CY-$(logical_px 80))) " + CX=$((${SRA[2]} + $(logical_px 25 1))) + CY=$((${SRA[1]} - $(logical_px 30 2))) + rectangles+="rectangle $CX,$CY $((CX+$(logical_px 300 1))),$((CY-$(logical_px 80 2))) " done # User supplied Image