aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Schröder <andre.schroedr@gmail.com>2019-03-31 15:15:31 +0200
committerPavan Jadhaw <pavanjadhaw96@gmail.com>2019-03-31 13:15:31 +0000
commitcdb603a3f2ac8cd24720245947749a863cb795ce (patch)
tree275f47b047cb52eb1db7ade5daa58fde020434c4
parentd022301c389e9c884fe18eea0c020dd575fd0543 (diff)
Automatically deduce DPI (#110)
With this commit the DPI doesn't have to be listed in the ~/.Xresources and will be deduced automatically.
-rwxr-xr-xbetterlockscreen10
1 files 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