1From 3b5f431a370054bfc090796e8d55de8c8cea46f4 Mon Sep 17 00:00:00 2001
2From: Martin Jansa <Martin.Jansa@gmail.com>
3Date: Wed, 11 Apr 2012 14:28:45 +0200
4Subject: [PATCH] add setdpi Xinit.d script
5
6Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com>
7
8---
9 X11/Xinit.d/50setdpi | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++
10 1 file changed, 92 insertions(+)
11 create mode 100644 X11/Xinit.d/50setdpi
12
13diff --git a/X11/Xinit.d/50setdpi b/X11/Xinit.d/50setdpi
14new file mode 100644
15index 0000000..04a2edd
16--- /dev/null
17+++ b/X11/Xinit.d/50setdpi
18@@ -0,0 +1,92 @@
19+#! /bin/sh
20+#
21+# Copyright Matthias Hentges <devel@hentges.net> (c) 2006
22+# License: GPL (see http://www.gnu.org/licenses/gpl.txt for a copy of the license)
23+#
24+# Filename: setDPI.sh
25+# Date: 09-Apr-06
26+
27+# This script configures Xft.dpi dependent on your screens DPI. This insures that the same font-size
28+# setting of 7 can be used on all machines.
29+
30+
31+XDEFAULTS="/etc/X11/Xdefaults"
32+
33+
34+
35+set_dpi() {
36+
37+	CURRENT_SETTING="`cat ${XDEFAULTS} | sed -n "/Xft.dpi\:/s/.*\:\(.*\)/\1/p" | sed -n "s/\ //p"`"
38+
39+	if test "$CURRENT_SETTING" != "$1"
40+	then
41+		echo "Using Xft.dpi of $SET_SCREEN_DPI for your $SCREEN_DPI DPI screen"
42+
43+		if grep -q "Xft.dpi" "$XDEFAULTS"
44+		then
45+			cat "${XDEFAULTS}" | sed "s/^Xft.dpi\:.*/Xft.dpi\: $SET_SCREEN_DPI/" > "${XDEFAULTS}_"
46+			mv "${XDEFAULTS}_" "${XDEFAULTS}"
47+		else
48+			echo -e "Xft.dpi: $SET_SCREEN_DPI\n" >> "$XDEFAULTS"
49+		fi
50+	else
51+		echo "Your $SCREEN_DPI DPI screen is already configured."
52+	fi
53+}
54+
55+set_rxvt_font() {
56+
57+	CURRENT_SETTING="`cat ${XDEFAULTS} | sed  -n "/Rxvt\*font/s/\(.*\pixelsize=\)\(.*\)/\2/p"`"
58+
59+	if test "$1" -gt 100
60+	then
61+
62+		# Configure the rxvt font-size for your screen here:
63+		test "$1" -gt 180 -a "$1" -lt "221" && RXVT_FONT_SIZE=16
64+
65+		if test -z "$RXVT_FONT_SIZE"
66+		then
67+			echo "WARNING: No rxvt font-size configured for a $SCREEN_DPI DPI screen!"
68+			echo "Defaulting to size 9"
69+			RXVT_FONT_SIZE=9
70+		fi
71+
72+		if test "$CURRENT_SETTING" != "$RXVT_FONT_SIZE"
73+		then
74+			echo "Using a rxvt font-size of $RXVT_FONT_SIZE"
75+			cat ${XDEFAULTS} | sed "/Rxvt\*font/s/\(.*\pixelsize\)\(=*.*\)/\1=$RXVT_FONT_SIZE/" > ${XDEFAULTS}_
76+			mv ${XDEFAULTS}_ ${XDEFAULTS}
77+		else
78+			echo "The rxvt font-size is already configured"
79+		fi
80+	fi
81+}
82+
83+if test -z "$DISPLAY"
84+then
85+	echo "DISPLAY is not set, aborting..."
86+	exit 0
87+fi
88+
89+SCREEN_DPI="`/usr/bin/xdpyinfo | grep "dots per inch" | awk '{print $2}'| sed -n "s/\(.*\)x\(.*\)/\2/p"`"
90+
91+if test -z "$SCREEN_DPI"
92+then
93+	echo "WARNING: Couldn't read your screens DPI, defaulting to 100"
94+	SCREEN_DPI=100
95+fi
96+
97+# Configure your screen here:
98+test "$SCREEN_DPI" -gt 180 -a "$SCREEN_DPI" -lt "221" && SET_SCREEN_DPI=160
99+test "$SCREEN_DPI" -gt 90 -a "$SCREEN_DPI" -lt "121" && SET_SCREEN_DPI=100
100+
101+
102+if test -z "$SET_SCREEN_DPI"
103+then
104+	echo "WARNING: No default configuration found for your $SCREEN_DPI DPI screen!"
105+	echo "Using 100 DPI"
106+	SET_SCREEN_DPI=100
107+fi
108+
109+set_dpi "$SET_SCREEN_DPI"
110+set_rxvt_font "$SCREEN_DPI"
111