summaryrefslogtreecommitdiff
path: root/mdm/src/create-xorg-conf
blob: ebdb84ea80b750db0877893cd138efe0a26fa940 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
#!/bin/bash

# Copyright (C) 2004-2007 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.

# Ideally, this script should not exist.
# It would also be good if "X -configure" did a good job.
# But they are not enough, so we have to do this...
# I hope someday X will by default open multiple screens without xorg.conf

MDM_PREFIX=/
MDM_SCRIPTS=${MDM_PREFIX}/usr/sbin
MDM_INCLUDE=${MDM_SCRIPTS}/mdm-common
source $MDM_INCLUDE

function section_files () {
echo '
Section "Files"
        RgbPath      "/etc/X11/rgb"
        ModulePath   "/usr/lib/xorg/modules"
        FontPath     "/usr/share/fonts/X11/misc"
        FontPath     "/usr/share/fonts/X11/cyrillic"
        FontPath     "/usr/share/fonts/X11/100dpi/:unscaled"
        FontPath     "/usr/share/fonts/X11/75dpi/:unscaled"
        FontPath     "/usr/share/fonts/X11/Type1"
        FontPath     "/usr/share/fonts/X11/100dpi"
        FontPath     "/usr/share/fonts/X11/75dpi"
        FontPath     "/var/lib/defoma/x-ttcidfont-conf.d/dirs/TrueType"
EndSection' >> $MDM_XORG_CONF
}

function section_module () {
echo '
Section "Module"
        Load  "record"
        Load  "extmod"
        Load  "dbe"
        Load  "GLcore"
        Load  "glx"
        Load  "dri"
        Load  "xtrap"
EndSection' >> $MDM_XORG_CONF
}

function section_server_flags () {
echo '
Section "ServerFlags"
    Option    "DontVTSwitch"       "yes"
    Option    "DontZoom"           "yes"
    Option    "DontZap"            "yes"
    Option    "AllowMouseOpenFail" "yes"
    # Option    "BlankTime"    "0"
    # Option    "StandbyTime"  "0"
    # Option    "SuspendTime"  "0"
    # Option    "OffTime"      "0"
EndSection' >> $MDM_XORG_CONF
}

function section_dri () {
echo '
Section "DRI"
    Mode    0666
EndSection' >> $MDM_XORG_CONF
}

function input_devices_sections () {

if [ ! -z ${XKB_RULES[i]} ]; then
    MY_XKB_RULES=${XKB_RULES[i]}
else
    MY_XKB_RULES=$DEFAULT_XKB_RULES
fi
if [ ! -z ${XKB_MODEL[i]} ]; then
    MY_XKB_MODEL=${XKB_MODEL[i]}
else
    MY_XKB_MODEL=$DEFAULT_XKB_MODEL
fi
if [ ! -z ${XKB_LAYOUT[i]} ]; then
    MY_XKB_LAYOUT=${XKB_LAYOUT[i]}
else
    MY_XKB_LAYOUT=$DEFAULT_XKB_LAYOUT
fi

echo "
Section \"InputDevice\"
        Identifier  \"Keyboard\"
        Driver      \"kbd\"
	Option      \"CoreKeyboard\"
	#Option      \"XkbRules\"  \"$MY_XKB_RULES\"
	Option      \"XkbModel\"  \"$MY_XKB_MODEL\"
	Option      \"XkbLayout\" \"$MY_XKB_LAYOUT\"
EndSection " >> $MDM_XORG_CONF

echo '
Section "InputDevice"
        Identifier  "Mouse"
        Driver      "mouse"
	Option      "CorePointer"
        Option      "Protocol" "auto"
        Option      "Device" "/dev/input/mice"
        Option      "ZAxisMapping" "4 5 6 7"
EndSection' >> $MDM_XORG_CONF
}

function video_sections () {

# We're inside a loop 
i=$1

if [ ! -z ${MODE[i]} ]; then
    SCREEN_SIZE=${MODE[i]}
else
    SCREEN_SIZE=$DEFAULT_MODE
fi

# In case we're using one card with dual output, it is possible to make two
# heads on it. To do so, it is necessary to open a wider screen (for example,
# twice wider) to perform this action, we have the WIDTH_MULTIPLIER variable.

if [ -f "$XRANDR_INFO_FILE" ]; then
    WIDTH_MULTIPLIER=`grep -A1 ":0.$((i-1))" $XRANDR_INFO_FILE	|
                        tail -1 | cut -d'=' -f2`
    # If $WIDTH_MULTIPLIER=0, set it as 1 (for configuring at least one screen)
    WIDTH_MULTIPLIER=${WIDTH_MULTIPLIER/0/1}
fi

# The variable may be still unset, if so, set 1 as default
WIDTH_MULTIPLIER=${WIDTH_MULTIPLIER:=1}

VIRTUAL_X=$((`echo $SCREEN_SIZE | cut -d'x' -f1` * $WIDTH_MULTIPLIER))
VIRTUAL_Y=$(echo $SCREEN_SIZE | cut -d'x' -f2)

# HorizSync and VertRefresh: if 'none' specified, don't write in xorg.conf
if [ ! -z ${HORIZ_SYNC[i]} ]; then
    MONITOR_HORIZ=${HORIZ_SYNC[i]}
else
    MONITOR_HORIZ=$DEFAULT_HORIZ_SYNC
fi
if [ ! -z ${VERT_REFRESH[i]} ]; then
    MONITOR_VERT=${VERT_REFRESH[i]}
else
    MONITOR_VERT=$DEFAULT_VERT_REFRESH
fi

if [ "$MONITOR_HORIZ" = 'none' ]; then
	MONITOR_HORIZ=''
else
	MONITOR_HORIZ="HorizSync $MONITOR_HORIZ"
fi
if [ "$MONITOR_VERT" = 'none' ]; then
	MONITOR_VERT=''
else
	MONITOR_VERT="VertRefresh $MONITOR_VERT"
fi

echo "
Section \"Device\"
	Identifier	\"Video Card $i\"
	BusID		\"PCI:${BUS_IDS[i-1]}\"
	Driver		\"${DRIVERS[i-1]}\"
EndSection

Section \"Monitor\"
	Identifier	\"Monitor $i\"
	$MONITOR_HORIZ
	$MONITOR_VERT
	Option		\"DPMS\"
EndSection

Section \"Screen\"
	Identifier	\"Screen $i\"
	Device		\"Video Card $i\"
	Monitor		\"Monitor $i\"
	DefaultDepth	24
	SubSection	\"Display\"
		Depth	16
		Modes	\"${SCREEN_SIZE}\"
		Virtual	$VIRTUAL_X $VIRTUAL_Y
	EndSubSection
	SubSection	\"Display\"
		Depth	24
		Modes	\"${SCREEN_SIZE}\"
		Virtual	$VIRTUAL_X $VIRTUAL_Y
	EndSubSection
EndSection" >> $MDM_XORG_CONF
}

function section_server_layout () {
echo "
Section \"ServerLayout\"
	Identifier    \"X Configured\"
" >> $MDM_XORG_CONF

for (( i=1; i <= $N_CARDS; i++ )); do
	echo "	Screen $((i-1)) \"Screen $i\"" >> $MDM_XORG_CONF
done

echo '
	InputDevice    "Keyboard"
	InputDevice    "Mouse"
EndSection' >> $MDM_XORG_CONF
}

function generate_xrandr_info_file () {

    # We need X running to use xrandr, so:
    X -config $MDM_XORG_CONF -noreset &>/dev/null &
    local PID=$!
    sleep 5

    # This will create a file with xrandr useful information
    for (( i=0; i < "$N_CARDS"; i++ )); do
        export DISPLAY=:0.$i
        xrandr_append_info_file
    done

    # Killing X
    kill $PID
    sleep 5
}

function create_xorg_conf_file () {
    section_files
    section_module
    section_server_flags
    section_dri
    input_devices_sections
    for (( c = 1; c <= $N_CARDS; c++)); do
        video_sections $c
    done
    section_server_layout
}
#####

N_CARDS=$($DISCOVER_DEVICES driver | wc -l)
DRIVERS=($($DISCOVER_DEVICES driver | cut -f2))
BUS_IDS=($($DISCOVER_DEVICES bus | cut -f2))

# They called our script, so they DO want a new xorg.conf
rm -f $MDM_XORG_CONF
rm -f $XRANDR_INFO_FILE
create_xorg_conf_file

# After xorg.conf.mdm is ready, generate xrandr.info file
generate_xrandr_info_file

# And recreate xorg.conf, based on information given by xrandr.info file
rm -f $MDM_XORG_CONF
create_xorg_conf_file