#!/bin/bash
if [ $# -lt 1 ]; then
    echo "Usage : ./dpi normal|med|high"
    echo -n "Trying magic : "
    xrandr --query | grep -q "DP1.*3840x2160"
    if [ $? -eq 0 ]; then
        target="high"
    else
        target="med"
    fi
    echo $1
else
    target=$1
fi
case $target in
    "normal")
        echo "normal"
        devPixel="1";
        DPI="96"
        Cursor="12"
       ;;
    "med")
        echo "med";
        devPixel="1.2";
        DPI="120";
        Cursor="16"
        ;;
    "high")
        echo "high";
        devPixel="2";
        DPI="165";
        Cursor="32"
        ;;
    *)
    echo "Usage : ./dpi normal|med|high"
    exit
esac
xfconf-query  -p /Xft/DPI  -c xsettings -s $DPI
xfconf-query  -p /Gtk/CursorThemeSize  -c xsettings -s $Cursor
sed -r -i "s/(user_pref\(\"layout.css.devPixelsPerPx\", \")[0-9.]+(\"\);)/\1$devPixel\2/" ~/.mozilla/firefox/default/prefs.js
sed -r -i "s/(user_pref\(\"layout.css.devPixelsPerPx\", \")[0-9.]+(\"\);)/\1$devPixel\2/" ~/.icedove/default/prefs.js
rm ~/.config/awesome/font.lua
ln -s "$HOME/.config/awesome/font-$target.lua" ~/.config/awesome/font.lua
