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