diff options
author | Jeff M. Hubbard <jeffmhubbard@users.noreply.github.com> | 2021-06-04 15:49:35 -0500 |
---|---|---|
committer | Sebastian Sellmeier <mail@sebastian-sellmeier.de> | 2021-07-21 01:03:46 +0200 |
commit | 66d975915922c462c86cce37818a4e4a567f9d26 (patch) | |
tree | 8611e81b53ca621d40c58f4b0a80e02d1377e98d | |
parent | c025de7b8f2707b553e0049408a96ce22aecf328 (diff) |
Get DPI from xrdb, fixes #236 (#237)
`multi-monitor` branch did not check for user set DPI in Xresources.
It does now. Also, rather than parsing .Xresources file, we instead
query xrdb to get the current value.
-rwxr-xr-x | betterlockscreen | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/betterlockscreen b/betterlockscreen index f908c82..568f94b 100755 --- a/betterlockscreen +++ b/betterlockscreen @@ -184,24 +184,30 @@ logical_px() { # $2: 1 for width. 2 for height local pixels="$1" local direction="$2" + local dpi - # get dpi value from xdpyinfo - local DPI - DPI=$(xdpyinfo | sed -En "s/\s*resolution:\s*([0-9]*)x([0-9]*)\s.*/\\$direction/p" | head -n1) + # use DPI set by user in .Xresources + dpi=$(xrdb -q | grep -oP '^\s*Xft.dpi:\s*\K\d+' | bc) - # return the default value if no DPI is set - if [ -z "$DPI" ]; then - echo "$pixels" - else - local SCALE - SCALE=$(echo "scale=2; $DPI / 96.0" | bc) + # or get dpi value from xdpyinfo + if [ -z "$dpi" ]; then + dpi=$(xdpyinfo | sed -En "s/\s*resolution:\s*([0-9]*)x([0-9]*)\s.*/\\$direction/p" | head -n1) + fi + + # adjust scaling + if [ -n "$dpi" ]; then + local scale + scale=$(echo "scale=2; $dpi / 96.0" | bc) # check if scaling the value is worthy - if [ "$(echo "$SCALE > 1.25" | bc -l)" -eq 0 ]; then + if [ "$(echo "$scale > 1.25" | bc -l)" -eq 0 ]; then echo "$pixels" else - echo "$SCALE * $pixels / 1" | bc + echo "$scale * $pixels / 1" | bc fi + else + # return the default value if no DPI is set + echo "$pixels" fi } |