#!/bin/ksh

#
# This file is a part of the NsCDE - Not so Common Desktop Environment
# Author: Hegel3DReloaded
# Licence: GPLv3
#

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8

ARG="$1"

function get_dpi
{
   type -p xdpyinfo > /dev/null 2>&1
   if (($? == 0)); then
      dpi1=$(xdpyinfo 2>/dev/null | egrep "resolution:.*dots per inch" | awk '{ print $2 }')
      DPI=${dpi1##*x}
      if [ "x$DPI" == "x" ]; then
         DPI=96
      fi
   else
      DPI=96
   fi
   
   if (($DPI <= 85)); then
      NSCDE_DPI=75
   elif (($DPI > 85 && $DPI < 108)); then
      NSCDE_DPI=96
   elif (($DPI >= 108 && $DPI < 132)); then
      NSCDE_DPI=120
   elif (($DPI >= 132)); then
      NSCDE_DPI=144
   fi

   echo $NSCDE_DPI
}

function get_font_dpi
{
   NSCDE_FONT_DPI=$(xrdb -q | sed -n "s/^Xft\\.dpi:\([\t ]\+\)\?//gp")

   if [ "x$NSCDE_FONT_DPI" != "x" ]; then
      echo $NSCDE_FONT_DPI
   else
      echo $NSCDE_DPI
   fi
}

if [ "$ARG" == "fontdpi" ]; then
   get_font_dpi
else
   get_dpi
fi

