summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xdpi18
1 files changed, 11 insertions, 7 deletions
diff --git a/dpi b/dpi
index bd49dd4..04cee86 100755
--- a/dpi
+++ b/dpi
@@ -1,11 +1,15 @@
#!/usr/bin/env zsh
-res=$(xdpyinfo | grep 'dimensions:' | strips | cut -d" " -f 5)
+res=$(xrandr 2>/dev/null | grep "primary" | cut -d" " -f 4)
res_x=$(echo $res | cut -d"x" -f 1)
-res_y=$(echo $res | cut -d"x" -f 2)
-size_x=$(xrandr | grep " connected" | cut -d" " -f 13 | sed "s|mm||")
-size_y=$(xrandr | grep " connected" | cut -d" " -f 15 | sed "s|mm||")
-dpi=$(python -c "import math; print(round(math.sqrt($res_x**2 + $res_y**2) / math.sqrt(($size_x*0.0393701)**2 + ($size_y*0.0393701)**2)))")
-
+res_y=$(echo $res | cut -d"x" -f 2 | cut -d+ -f 1)
+size_x=$(xrandr 2>/dev/null | grep " primary" | cut -d" " -f 14 | sed "s|mm||")
+if [[ $size_x == "x" ]]; then
+ size_x=$(xrandr 2>/dev/null | grep " primary" | cut -d" " -f 13 | sed "s|mm||")
+fi
+size_y=$(xrandr 2>/dev/null | grep " primary" | cut -d" " -f 16 | sed "s|mm||")
+if [[ $size_y == "" ]]; then
+ size_y=$(xrandr 2>/dev/null | grep " primary" | cut -d" " -f 15 | sed "s|mm||")
+fi
+dpi=$(python3 -c "import math; print(round(math.sqrt($res_x**2 + $res_y**2) / math.sqrt(($size_x*0.0393701)**2 + ($size_y*0.0393701)**2)))")
echo $dpi
-