Added some more comments to the X modules
[grml-x.git] / grml-x
1 #!/bin/zsh
2 # Filename:      grml-x
3 # Purpose:       wrapper for startx on grml [providing new xconfiguration tool]
4 # Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
5 # Bug-Reports:   see http://grml.org/bugs/
6 # License:       This file is licensed under the GPL v2.
7 # Latest change: Mit Apr 04 16:26:39 CEST 2007 [mika]
8 ################################################################################
9
10 # debugging {{{
11 # usage: DEBUG=1 grml-x ..... 2>/tmp/grml-x-debug.log
12   if [[ $DEBUG -gt 0 ]]; then
13       setopt xtrace
14   fi
15 # }}}
16
17 # functions and color {{{
18   # use colors only if not booted with nocolor bootoption
19   if ! grep -q nocolor /proc/cmdline ; then
20      autoload colors ; colors
21      [ -r /etc/grml_colors ] && . /etc/grml_colors
22   fi
23
24   # some functions like getBootParam
25   if [ -r /etc/grml/script-functions -a -r /etc/grml/sh-lib ] ; then
26      source /etc/grml/script-functions
27      source /etc/grml/sh-lib
28   else
29     echo 'Error: sourcing function files failed. Exiting.'
30     exit 1
31   fi
32
33   check4root &>/dev/null && ROOT='1' || ROOT=''
34 # }}}
35
36 # set variables  {{{
37   PROGRAMNAME=${0##*/}
38   HWINFO='/usr/sbin/hwinfo'
39   DATE=$(date)
40   [ -n "$XINITRC" ] || XINITRC="$HOME/.xinitrc"
41
42   # temporary files
43   HWINFO_TMP="/tmp/hwinfo.$$"
44   MONITORINFO="/tmp/monitorinfo.$$"
45   MOUSEINFO="/tmp/mouse.$$"
46
47   if [ -r /etc/sysconfig/keyboard ] ; then
48     source /etc/sysconfig/keyboard
49   else
50     XKEYBOARD='us'
51   fi
52
53   XSERVER="Xorg"
54   XCONFIG='/etc/X11/xorg.conf'
55   KEYBOARD="# Driver      \"kbd\"
56 #         Option      \"XkbRules\"   \"xfree86\"
57 #         Option      \"XkbRules\"   \"xorg\"
58 #         Option      \"XkbModel\"   \"pc105\"
59 #         Option      \"XkbLayout\"  \"${XKEYBOARD},us\"
60 #         Option      \"XkbVariant\" \"nodeadkeys\""
61
62   # check for font path
63   if [ -d /usr/share/fonts/X11 ] ; then
64      XFONTS="        FontPath     \"/usr/share/fonts/X11/misc\"
65         FontPath     \"/usr/share/fonts/X11/100dpi/:unscaled\"
66         FontPath     \"/usr/share/fonts/X11/75dpi/:unscaled\"
67         FontPath     \"/usr/share/fonts/X11/Type1\"
68         FontPath     \"/usr/share/fonts/X11/100dpi\"
69         FontPath     \"/usr/share/fonts/X11/75dpi\""
70   fi
71   # /usr/X11R6/lib/X11/fonts exists nearly everywhere, assume
72   # /usr/X11R6/lib/X11/fonts as valid font path only if fonts.dir
73   # exists for "misc"
74   if [ -r /usr/X11R6/lib/X11/fonts/misc/fonts.dir ] ; then
75       XFONTS="$XFONTS
76         FontPath     \"/usr/X11R6/lib/X11/fonts/Type1\"
77         FontPath     \"/usr/X11R6/lib/X11/fonts/misc:unscaled\"
78         FontPath     \"/usr/X11R6/lib/X11/fonts/misc\"
79         FontPath     \"/usr/X11R6/lib/X11/fonts/75dpi:unscaled\"
80         FontPath     \"/usr/X11R6/lib/X11/fonts/75dpi\"
81         FontPath     \"/usr/X11R6/lib/X11/fonts/100dpi:unscaled\"
82         FontPath     \"/usr/X11R6/lib/X11/fonts/100dpi\""
83   fi
84 # }}}
85
86 # make sure we don't leave any temp files {{{
87 bailout() {
88   rm -f "$HWINFO_TMP" "$MONITORINFO" "$MOUSEINFO"
89   [ -n "$1" ] && EXIT="$1" || EXIT="1"
90   print "$bg[black]$fg[red]${bold_color}Exiting...${reset_color}">&2
91   exit "$EXIT"
92 }
93
94 trap bailout 1 2 3 15
95 # }}}
96
97 # warn if running as user root {{{
98   if [ -n "$ROOT" ] ; then
99      if [ -r /etc/grml_cd ] ; then
100         print "$bg[black]$fg[red]${bold_color}Warning: Please do not run grml-x as user root.${reset_color}"
101         print "$bg[black]$fg[red]${bold_color}Running grml-x as user root is *not* supported!${reset_color}"
102         print "$bg[black]$fg[red]${bold_color}Switch to user grml or run su - grml -c 'grml-x ...' instead.${reset_color}"
103         print ''
104      else
105         print "$bg[black]$fg[red]${bold_color}Warning: Please do not run X.org as user root!${reset_color}"
106         print "$bg[black]$fg[red]${bold_color}As soon as you have a working $XCONFIG please use startx instead of grml-x.${reset_color}"
107         print ''
108      fi
109   fi
110   fstabuser=$(grep ':x:1000:' /etc/passwd)
111   fstabuser=${fstabuser%%[:]*}
112 # }}}
113
114 # usage information {{{
115 usage()
116 {
117   if [[ $1 != '' ]] ; then echo 1>&2 "\n$1" ; fi
118   print "$bg[black]$fg[red]$bold_color"
119   print 1>&2 "
120 Usage: $PROGRAMNAME
121        $PROGRAMNAME [-options] windowmanager
122
123 Examples:
124   $PROGRAMNAME wmii
125   $PROGRAMNAME pekwm
126   $PROGRAMNAME fluxbox
127   $PROGRAMNAME -force -nostart fluxbox
128   $PROGRAMNAME -nosynaptics fluxbox
129   $PROGRAMNAME -nosync fluxbox
130   $PROGRAMNAME -noddc wmii
131   $PROGRAMNAME -module radeon -mode 1024x768 -vsync 60 wmi
132   XINITRC=~/.xinitrc $PROGRAMNAME ion
133   $PROGRAMNAME -display 8 wmii
134
135 More information on grml-x can be found in the manual page: man grml-x
136
137 Report bugs, send wishes and feedback to the grml team:
138 http://grml.org/bugs/ - contact (at) grml.org
139 "
140   print "${reset_color}"
141   exit 2
142 }
143 # }}}
144
145 # writehwinfo {{{
146 writehwinfo()
147 {
148    if [ -n "$ROOT" ] ; then
149      su - $fstabuser -c "$HWINFO > $HWINFO_TMP"
150    else
151      $HWINFO > $HWINFO_TMP
152    fi
153 }
154 # }}}
155
156 # monitor {{{
157 monitor()
158 {
159   sudo $HWINFO --monitor > $MONITORINFO
160 }
161 # }}}
162
163 # mode {{{
164 mode()
165 {
166    [ -r "$MONITORINFO" ] || monitor # get monitor settings
167    modes=$(perl -e 'while (<STDIN>) {if (/  Resolution:/) { s/.*\s+(\d+x\d+).*/$1/; print} }' < $MONITORINFO |
168 sort -nur | perl -ne 's/\s+/ /; s/(\d+x\d+)/"$1"/; print')
169    if [[ -n $NODDC ]] ; then
170      MODES='Modes "1024x768" "800x600" "640x480"  "1600x1200" "1280x1024" "1280x960"'
171    elif [[ "$modes" == "\"1024x768\" " || -z $modes ]] ; then
172      MODES='# Modes "1024x768" "800x600" "640x480"  "1600x1200" "1280x1024" "1280x960"'
173    else
174      MODES="# Modes $modes"
175    fi
176 }
177 # }}}
178
179 # sync - get hsync/vsync settings {{{
180 sync()
181 {
182    [ -r "$MONITORINFO" ] || monitor # get monitor settings
183    vsyncval=$(awk '/Vert. Sync Range:/{print $4}' $MONITORINFO | sed 's/-/.0 - / ; s/$/.0/' | head -1)
184    hsyncval=$(awk '/Hor. Sync Range:/{print $4}'  $MONITORINFO | sed 's/-/.0 - / ; s/$/.0/' | head -1)
185    if [ -z $vsyncval ] ; then
186      vsyncval='50.0 - 60.0'
187    fi
188    if [ -z $hsyncval ] ; then
189      hsyncval='28.0 - 96.0'
190    fi
191 }
192 # }}}
193
194 # mouse {{{
195 mouse()
196 {
197    sudo $HWINFO --mouse > $MOUSEINFO
198
199    # SynPS/2 Synaptics TouchPad
200    if grep -q 'Device:.*Synaptics' "$MOUSEINFO" ; then
201     if [[ "$SYNAPTICS" == "yes" ]] ; then # check for '-nosynaptics'-option
202      MOUSEDRIVER='synaptics'
203      SYNMOUSE='InputDevice    "Synaptics"  "AlwaysCore"'
204      SYNMOUSEDETAIL="
205 Section \"InputDevice\"
206   Driver        \"synaptics\"
207   Identifier    \"Synaptics\"
208   Option        \"Device\"        \"/dev/psaux\"
209   Option        \"Protocol\"      \"auto-dev\"
210   Option        \"LeftEdge\"      \"1700\"
211   Option        \"RightEdge\"     \"5300\"
212   Option        \"TopEdge\"       \"1700\"
213   Option        \"BottomEdge\"    \"4200\"
214   Option        \"FingerLow\"     \"25\"
215   Option        \"FingerHigh\"    \"30\"
216   Option        \"ZAxisMapping\"   \"4 5\"
217   Option        \"MaxTapTime\"    \"180\"
218   Option        \"MaxTapMove\"    \"220\"
219   Option        \"VertScrollDelta\" \"100\"
220   Option        \"MinSpeed\"      \"0.06\"
221   Option        \"MaxSpeed\"      \"0.12\"
222   Option        \"AccelFactor\" \"0.0010\"
223 #  Option       \"SHMConfig\"     \"on\"
224 #  Option       \"Repeater\"      \"/dev/ps2mouse\"
225 EndSection
226 "
227     else
228      MOUSEDRIVER='mouse'
229      SYNMOUSEDETAIL=""
230      SYNMOUSE='# No synaptics touchpad detected.'
231     fi
232    else
233
234     # AlpsPS/2 ALPS TouchPad (with Synapticsdriver)
235     if grep -q 'Device:.*ALPS' "$MOUSEINFO" ; then
236      if [[ "$SYNAPTICS" == "yes" ]] ; then # check for '-nosynaptics'-option
237       MOUSEDRIVER='synaptics'
238       SYNMOUSE='InputDevice    "Synaptics"  "AlwaysCore"'
239       SYNMOUSEDETAIL="
240 Section \"InputDevice\"
241   Driver        \"synaptics\"
242   Identifier    \"Synaptics\"
243   Option        \"Device\"        \"/dev/psaux\"
244   Option        \"Protocol\"      \"auto-dev\"
245   Option        \"LeftEdge\"      \"120\"
246   Option        \"RightEdge\"     \"850\"
247   Option        \"TopEdge\"       \"120\"
248   Option        \"BottomEdge\"    \"650\"
249   Option        \"FingerLow\"     \"14\"
250   Option        \"FingerHigh\"    \"15\"
251   Option        \"ZAxisMapping\"   \"4 5\"
252   Option        \"MaxTapTime\"    \"180\"
253   Option        \"MaxTapMove\"    \"50\"
254   Option        \"MaxDoubleTapTime\"    \"100\"
255   Option        \"VertScrollDelta\" \"20\"
256   Option        \"HorizScrollDelta\" \"20\"
257   Option        \"MinSpeed\"      \"0.3\"
258   Option        \"MaxSpeed\"      \"2.00\"
259   Option        \"AccelFactor\" \"0.030\"
260   Option        \"UpDownScrolling\" \"1\"
261   Option        \"EmulateMiddleButtonTime\" \"75\"
262   Option        \"CircularScrolling\" \"1\"
263   Option        \"CircScrollDelta\" \"0.1\"
264   Option        \"CircScrollTrigger\" \"8\"
265 #  Option       \"SHMConfig\"     \"on\"
266 #  Option       \"Repeater\"      \"/dev/ps2mouse\"
267 EndSection
268 "
269      else
270       MOUSEDRIVER='mouse'
271       SYNMOUSEDETAIL=""
272       SYNMOUSE='# No alps touchpad detected.'
273      fi
274     else
275       SYNMOUSE='# No synaptics/alps touchpad present.'
276     fi
277    fi
278
279    # USB-PS/2 Optical Mouse
280    if [ -n "$USE_USB" ] ; then
281      USBMOUSE='InputDevice    "USB Mouse"     "CorePointer"'
282      USBMOUSEDETAIL="
283 Section \"InputDevice\"
284         Identifier      \"USB Mouse\"
285         Driver          \"mouse\"
286         Option          \"Device\"                \"/dev/input/mice\"
287         Option          \"Protocol\"              \"auto\"
288         Option          \"ZAxisMapping\"          \"4 5\"
289         Option          \"Buttons\"               \"5\"
290         Option          \"SendCoreEvents\"        \"true\"
291 EndSection
292 "
293    else
294      USBMOUSE='# InputDevice    "USB Mouse"     "CorePointer"'
295      USBMOUSEDETAIL=''
296    fi
297
298    if grep -q 'Device:.*Serial' "$MOUSEINFO" ; then
299      SERIAL='yes'
300      SERMOUSE='InputDevice    "Serial Mouse"     "CorePointer"'
301      SERMOUSEDETAIL="Section \"InputDevice\"
302         Identifier  \"Serial Mouse\"
303         Driver      \"mouse\"
304         Option      \"Device\" \"/dev/ttyS0\"
305         Option      \"Protocol\" \"Microsoft\"
306         Option      \"Emulate3Buttons\" \"true\"
307         Option      \"Emulate3Timeout\" \"70\"
308         Option      \"SendCoreEvents\"  \"true\"
309 EndSection
310 "
311    else
312      SERMOUSE='# No serial mouse detected.'
313      SERMOUSEDETAIL=''
314    fi
315
316    # ImExPS/2 Logitech Explorer Mouse
317    # "PS2++ Logitech MX Mouse"
318    if [ -n "$USE_PS2" ] ; then
319       PS2='yes'
320       PS2MOUSE='InputDevice    "PS/2 Mouse"    "CorePointer"'
321       PS2MOUSEDETAIL="Section \"InputDevice\"
322         Identifier  \"PS/2 Mouse\"
323         Driver      \"mouse\"
324         Option      \"Device\" \"/dev/input/mice\"
325         # Option      \"Device\" \"/dev/psaux\"
326         Option      \"Protocol\" \"PS/2\"
327         Option      \"Emulate3Buttons\" \"true\"
328         Option      \"Emulate3Timeout\" \"70\"
329         Option      \"SendCoreEvents\"  \"true\"
330 EndSection
331 "
332      else
333       PS2MOUSE='# InputDevice    "PS/2 Mouse"    "CorePointer"'
334       PS2MOUSEDETAIL=''
335      fi
336
337      EVDEV_MOUSE="# Section \"InputDevice\"
338 #         Identifier      \"Generic Mouse\"
339 #         Driver          \"evdev\"
340 #         Option          \"Device\"                \"/dev/input/mice\"
341 #         Option          \"Protocol\"              \"auto\"
342 #         Option          \"ZAxisMapping\"          \"4 5\"
343 #         Option          \"Buttons\"               \"5\"
344 #         Option          \"SendCoreEvents\"        \"true\"
345 # EndSection
346 "
347
348    MOUSE="        $USBMOUSE
349         $PS2MOUSE
350         $SYNMOUSE
351         $SERMOUSE"
352 }
353 # }}}
354
355 # commandline parsing {{{
356 parse_options()
357 {
358    zparseopts -K -- module:=o_module help=o_help noddc=o_noddc nosync=o_nosync \
359                     vsync:=o_vsync hsync:=o_hsync mode:=o_mode force=o_force display:=o_display   \
360                     nostart=o_nostart nodpms=o_nodpms nosynaptics=o_nosynaptics nousb=o_nousb \
361                     nops2=o_nops2 genmouse=o_genmouse novref=o_novref nohsync=o_nohsync \
362                     fallback=o_fallback usb=o_usb ps2=o_ps2
363
364    if [[ $# == 0 || "$o_help" != "" || "$1" == '-h' || "$1" == '--help' ]]; then
365       usage
366    fi
367
368    if [[ "$o_force" != "" ]]; then
369       FORCE='yes'
370    fi
371
372    if [[ "$o_fallback" != "" ]]; then
373       FALLBACK="yes"
374       if [ -r /etc/X11/xorg.conf.example ] ; then
375          sudo cp /etc/X11/xorg.conf.example $XCONFIG
376          print "$bold_color$fg[blue]Copying /etc/X11/xorg.conf.example to $XCONFIG as requested via fallback option."
377       else
378          echo 'Error: /etc/X11/xorg.conf.example not readable, exiting.'
379          exit 1
380       fi
381    fi
382
383    if [[ "$o_nodpms" != "" ]]; then
384       DPMS='Option       "DPMS"      "false"'
385    else
386       DPMS='Option       "DPMS"      "true"'
387    fi
388
389    if [[ "$o_noddc" != "" ]]; then
390       NODDC="yes"
391    fi
392
393    if [[ "$o_vsync" != "" ]]; then
394       FORCE="yes"
395    fi
396
397    if [[ "$o_hsync" != "" ]]; then
398       FORCE="yes"
399    fi
400
401    if [[ "$o_nousb" != "" ]]; then
402       echo 'Warning: option -nousb is deprecated.'>&2
403    fi
404
405    if [[ "$o_usb" != "" ]]; then
406       USE_USB='yes'
407    fi
408
409    if [[ "$o_nops2" != "" ]]; then
410       echo 'Warning: optino -nops2 is deprecatedË™'>&2
411    fi
412
413    if [[ "$o_ps2" != "" ]]; then
414       USE_PS2='yes'
415    fi
416
417    if [[ "$o_genmouse" != "" ]]; then
418       GENERICMOUSE='yes'
419    fi
420
421    if [[ "$o_nosynaptics" != "" ]]; then
422       SYNAPTICS='no'
423    else
424       SYNAPTICS='yes'
425    fi
426
427    if [[ "$o_nostart" != "" ]]; then
428       NOSTART="yes"
429    fi
430
431    DISPLAY=$o_display[2]
432
433    eval WINDOWMANAGER=\${$#}
434
435    if [[ "$XKEYBOARD" == de ]] ; then
436       KEYBOARD="$KEYBOARD
437 #         Option      \"XkbVariant\" \"nodeadkeys\""
438    fi
439
440    if [ -n "$FORCE" -o ! -r "$XCONFIG" -a -z "$FALLBACK" ] ; then
441      print -n "$bold_color$fg[blue]Gathering hardware information...$fg[red]"
442
443      sync # get hsync/vsync
444
445      if [ -z "$o_hsync" ] ; then
446        o_hsync=(-hsync "$hsyncval")
447        HSYNC=$o_hsync[2]
448        HORIZSYNC="        HorizSync    $HSYNC"
449      else
450        o_hsync=(-hsync "$o_hsync[2]")
451        HSYNC=$o_hsync[2]
452        HORIZSYNC="        HorizSync    $HSYNC"
453      fi
454
455      if [ -z "$o_vsync" ] ; then
456        o_vsync=(-vsync "$vsyncval")
457        VSYNC=$o_vsync[2]
458        VERTISYNC="        VertRefresh  $VSYNC"
459      else
460        o_vsync=(-vsync "$o_vsync[2]")
461        VSYNC=$o_vsync[2]
462        VERTISYNC="        VertRefresh  $VSYNC"
463      fi
464
465      if [[ "$o_nosync" != "" ]]; then
466         HORIZSYNC="#       HorizSync   28.0 - 96.0  # deactivated via -nosync option of grml-x"
467         VERTISYNC="#       VertRefresh 50.0 - 60.0  # deactivated via -nosync option of grml-x"
468      fi
469
470      if [[ "$o_nohsync" != "" ]]; then
471         HORIZSYNC="#       HorizSync   28.0 - 96.0  # deactivated via -nohsync option of grml-x"
472      fi
473
474      if [[ "$o_novref" != "" ]]; then
475         VERTISYNC="#       VertRefresh 50.0 - 60.0  # deactivated via -novref option of grml-x"
476      fi
477
478      # write hwinfo stuff
479      writehwinfo
480
481      # monitor stuff
482      MONITOR=$(awk '/monitor.1:/{print $3}' $HWINFO_TMP)
483      [[ $MONITOR != 'ddc' ]] && NODDC=yes
484
485      # module handling
486      MODULE=$o_module[2]
487      if [ -z "$MODULE" ] ; then
488        MODULE="$(getBootParam xmodule 2>/dev/null)"
489        if [ -z "$MODULE" ] ; then
490          MODULE=$(grep 'XFree86 v4 Server Module:' "${HWINFO_TMP}" | head -1 | awk '{print $5}')
491          if [ -z "$MODULE" ] ; then
492            MODULE='vesa'
493          fi
494          # hwinfo >=13.28 reports driver 'intel' instead of i810
495          if [[ "$MODULE" == 'intel' ]] ; then
496             [ -r /usr/lib/xorg/modules/drivers/intel_drv.so ] || MODULE='i810'
497          fi
498        fi
499      else
500        FORCE="yes"
501      fi
502
503      mouse    # get mouse settings
504      VGA=$(lspci | grep VGA | sed 's/.*compatible controller: //' | head -1)
505
506      MODE=$o_mode[2]
507      if [ -z $MODE ] ; then
508        B_MODE="$(getBootParam xmode 2>/dev/null)"
509        if [ -n "$B_MODE" ] ; then
510          MODES="Modes \"$B_MODE\""
511          FORCE="yes"
512        fi
513        if [ -z "$MODES" ] ; then
514           mode # get available modes
515        fi
516      else
517        MODES="Modes \"$MODE\""
518        FORCE="yes"
519      fi
520
521      print "$fg[green]done$reset_color"
522      print "$bg[black]$fg[white]$bold_color"
523      print "$fg[green]Specified windowmanager is $fg[yellow]$WINDOWMANAGER"
524      print "$fg[green]Video is $fg[yellow]$VGA$fg[green] using $bg[black]$fg[yellow]${XSERVER}$fg[cyan](${MODULE})$fg[green] Server"
525      [[ -z $HSYNC ]] && [[ -z $VSYNC ]] && print "$fg[green]Monitor is $fg[yellow]$MONITOR"
526      [[ -z $HSYNC ]] && [[ -n $VSYNC ]] && print "$fg[green]Monitor is $fg[yellow]$MONITOR$fg[green], VSYNC: $fg[yellow]$VSYNC"
527      [[ -z $VSYNC ]] && [[ -n $HSYNC ]] && print "$fg[green]Monitor is $fg[yellow]$MONITOR$fg[green], HSYNC: $fg[yellow]$HSYNC"
528      [[ -n $VSYNC ]] && [[ -n $HSYNC ]] && print "$fg[green]Monitor is $fg[yellow]$MONITOR$fg[green], HSYNC: $fg[yellow]$HSYNC $fg[green]VSYNC: $fg[yellow]$VSYNC"
529      [[ -n $modes ]] && print "$fg[green]Using default X.org modes."
530      [[ -z $modes ]] && print "$fg[green]Using Mode: $fg[yellow]$MODE"
531      print "${reset_color}"
532    fi
533 }
534 parse_options $*
535 # }}}
536
537 # check for requirements {{{
538 requirements()
539 {
540 if ! [ -x $(which hwinfo) ] ; then
541   print "$bg[black]$fg[red]${bold_color}Error: hwinfo not found in path.${reset_color}
542 Note:  run 'apt-get install hwinfo' on systems running debian.
543 Exiting.${reset_color}"
544   exit -1
545 fi
546
547 if ! [[ -d /sys ]] ; then
548   print "$bg[black]$fg[red]${bold_color}Error: mounted /sys required (for hwinfo).${reset_color}
549 You may want to add the following line to your /etc/fstab:
550
551   sysfs /sys sysfs defaults 0 0
552
553 or just run 'mount /sys'. Exiting.${reset_color}"
554   exit -1
555 fi
556 }
557 requirements
558 # }}}
559
560 # xconfig {{{
561 xconfig() {
562 cat << EOX
563 ################################################################################
564 # Filename:      $XCONFIG
565 # Purpose:       config file for xserver - generated by grml-x
566 # Bug-Reports:   see http://grml.org/bugs/
567 # Latest change: ${DATE}
568 # See also:
569 #   /usr/share/doc/xserver-xorg/   and
570 #   http://wiki.x.org/wiki/Home    and
571 #   http://ftp.x.org/pub/X11R7.0/doc/html/index.html for information on Xorg
572 # Refer to the xorg.conf man page and to
573 # http://ftp.x.org/pub/X11R7.0/doc/html/xorg.conf.5.html
574 # for details about the format of this file.
575 #
576 # If you would like this file to be automatically reconfigured by debian,
577 # run the following command:
578 #   sudo dpkg-reconfigure -phigh xserver-xorg
579 ################################################################################
580
581 Section "ServerLayout"
582         Identifier     "XServer Configured"
583         Screen      0  "Screen0" 0 0
584         # InputDevice    "Keyboard0"     "CoreKeyboard"
585         # InputDevice    "Generic Mouse" "CorePointer"
586 $MOUSE
587 EndSection
588
589 Section "ServerFlags"
590         Option "AllowMouseOpenFail"  "true"  # allows the server to start up even if the mouse does not work
591         Option "DontVTSwitch"        "false" # allow switching between virtual terminal
592         # Option "DontZap"             "true"  # disable <Crtl><Alt><BS> (server abort)
593         # Option "DontZoom"            "true"  # disable <Crtl><Alt><KP_+>/<KP_-> (resolution switching)
594 EndSection
595
596 Section "Files"
597         # More information:  http://ftp.x.org/pub/X11R7.0/doc/html/fonts.html
598 $XFONTS
599         # FontPath     "/usr/share/fonts/ttf/western"
600         # FontPath     "/usr/share/fonts/ttf/decoratives"
601         FontPath     "/usr/share/fonts/truetype/ttf-bitstream-vera"
602         FontPath     "/usr/share/fonts/latex-ttf-fonts"
603         FontPath     "/var/lib/defoma/x-ttcidfont-conf.d/dirs/TrueType"
604 EndSection
605
606 # Modules - see /usr/X11R6/lib/modules/fonts and /usr/X11R6/lib/modules/extensions
607 Section "Module"
608         Load  "dbe"       # double buffer extension
609         Load  "dri"       # direct rendering
610         Load  "glx"       # 3D layer / GLX extension
611         Load  "type1"     # type1 font module
612         Load  "freetype"  # freetype fonts rendering
613         Load  "extmod"    # some commonly used server extensions (e.g. shape extension)
614         Load  "record"    # recording extension
615         Load  "evdev"     # generic input handling driver on Linux
616         # Load  "vbe"       # Vesa BIOS Extension
617         # Load  "i2c"       # I2C bus
618         # Load  "int10"     # initialize graphics cards via int10 call to the BIOS
619         # Load  "v4l"       # Video for Linux
620         ## Deprecated/unneeded modules with Xorg >=7.0:
621         # Load  "speedo"    # font module (does not exist anymore)
622         # Load  "ddc"       # ddc probing of monitor (automatically loaded)
623         # Load  "GLcore"    # render OpenGL in software (automatically loaded)
624         # Load  "bitmap"    # bitmap fonts (automatically loaded)
625 # Valid entries - see /usr/lib/xorg/modules/[extensions/]
626 # afb bitmap cfb cfb16 cfb24 cfb32 cw damage dbe ddc dri drm extmod fb
627 # fbdevhw freetype GLcore glx i2c int10 int10 layer mfb pcidata rac ramdac
628 # record scanpci shadow shadowfb type1 vbe vgahw xaa xf1bpp xf24_32bpp xf4bpp
629 # xf8_16bpp xf8_32bpp xtrap
630 EndSection
631
632 # If you'd like to switch the positions of your capslock and control keys, use:
633 # Option "XkbOptions" "ctrl:swapcaps"
634 # Or if you just want both to be control, use:
635 # Option "XkbOptions" "ctrl:nocaps"
636 # More information: http://ftp.x.org/pub/X11R7.0/doc/html/XKB-Config.html
637 # Section "InputDevice"
638 #         Identifier  "Keyboard0"
639 #         Option      "CoreKeyboard"
640 #         $KEYBOARD
641 #         # Option      "XkbOptions" "ctrl:swapcaps,grp:alt_shift_toggle,grp_led:scroll,compose:menu"
642 # EndSection
643
644 # More information: http://ftp.x.org/pub/X11R7.0/doc/html/mouse.html
645 $USBMOUSEDETAIL
646 $PS2MOUSEDETAIL
647 $SERMOUSEDETAIL
648 $SYNMOUSEDETAIL
649 $EVDEV_MOUSE
650 Section "Monitor"
651         Identifier   "Monitor0"
652 #       ModelName    "Old Monitor (no DDC)"
653         $DPMS
654 #       HorizSync    28.0 - 78.0 # Warning: This may fry very old Monitors
655 #       HorizSync    28.0 - 96.0 # Warning: This may fry old Monitors
656 $HORIZSYNC
657 #       VertRefresh  50.0 - 76.0 # Very conservative. May flicker.
658 #       VertRefresh  50.0 - 60.0 # Extreme conservative. Will flicker. TFT default.
659 $VERTISYNC
660 # Need more information?
661 #  http://xtiming.sourceforge.net/cgi-bin/xtiming.pl
662 #  http://en.tldp.org/HOWTO/XFree86-Video-Timings-HOWTO/
663 EndSection
664
665 Section "Device"
666         ### Available Driver options are:
667         ## sw_cursor is needed for some ati and radeon cards
668         # Option     "sw_cursor"
669         # Option     "hw_cursor"
670         # Option     "NoAccel"
671         # Option     "ShowCache"
672         # Option     "ShadowFB"
673         # Option     "UseFBDev"
674         # Option     "Rotate"
675         ## xorg + nvidia:
676         # Option "RenderAccel" "true"
677         # Option "AllowGLXWithComposite" "true"
678         Identifier  "Card0"
679         # The following line is auto-generated by grml-x
680         Driver      "$MODULE"
681         VendorName  "All"
682         BoardName   "All"
683         ## Workaround for drivers (for example radeon) which might send output to wrong device:
684         # Option "MonitorLayout" "LVDS, AUTO"
685         # Option "MonitorLayout" "LVDS, CRT"
686         # Option "MonitorLayout" "NONE, STV"
687         # Option "MonitorLayout" "LVDS"
688         ## Specify BusID:
689         # BusID       "PCI:1:0:0"
690 EndSection
691
692 Section "Screen"
693         Identifier "Screen0"
694         Device     "Card0"
695         Monitor    "Monitor0"
696         DefaultColorDepth 16
697         SubSection "Display"
698                 Depth     1
699                 $MODES
700         EndSubSection
701         SubSection "Display"
702                 Depth     4
703                 $MODES
704         EndSubSection
705         SubSection "Display"
706                 Depth     8
707                 $MODES
708         EndSubSection
709         SubSection "Display"
710                 Depth     15
711                 $MODES
712         EndSubSection
713         SubSection "Display"
714                 Depth     16
715                 $MODES
716         EndSubSection
717         SubSection "Display"
718                 Depth     24
719                 $MODES
720         EndSubSection
721         SubSection "Display"
722                 Depth     32
723                 $MODES
724         EndSubSection
725 EndSection
726
727 # Make sure you have the relevant Debian packages on your system
728 # to be able to use DRI (libgl1-mesa-dri for example)
729 Section "DRI"
730         Mode 0666
731 EndSection
732
733 #Section "Extensions"
734 #    Option "Composite" "Enable"
735 #EndSection
736
737 ## END OF FILE #################################################################
738 EOX
739 }
740 # }}}
741
742 # writeit {{{
743 writeit() {
744     XCONFTMP="/tmp/xconfig.$$"
745     xconfig > $XCONFTMP
746     # we do not want to have two CorePointers, deactivate one therefore
747     if grep -Eq '^[[:space:]]+InputDevice[ ]+"USB Mouse"[ ]+"CorePointer"' $XCONFTMP ; then
748        if grep -Eq '^[[:space:]]+InputDevice[ ]+"PS/2 Mouse"[ ]+"CorePointer"' $XCONFTMP ; then
749           sed -i 's|InputDevice.*PS/2.*CorePointer|# & # deactivated to avoid two CorePointers|' $XCONFTMP
750        fi
751     fi
752     [ -f $XCONFIG ] && sudo mv -f $XCONFIG $XCONFIG.old
753     sudo mv $XCONFTMP $XCONFIG
754     sudo chown root.root $XCONFIG
755     sudo chmod 644 $XCONFIG
756 }
757 # }}}
758
759 # writeconfig {{{
760 function writeconfig
761 {
762   if [[ ! -f $XCONFIG ]] ; then
763     print -n "$bold_color$fg[blue]Creating $XCONFIG: $fg[red]"
764     writeit && print "$fg[green]done$reset_color"
765   else
766     if [ -z "$FORCE" -a -z "$FALLBACK" ] ; then
767        print "$bold_color$fg[blue]Notice: $XCONFIG exists already.
768 Use the force-option (-force) to force creation.
769 $fg[red]"
770     fi
771   fi
772   if [[ -n "$FORCE" ]] ; then
773     print "$bold_color$fg[blue]Force-switch or manual option(s) detected:"
774     print -n "\-> Moving eventual existing $XCONFIG to ${XCONFIG}.old: $fg[red]"
775     writeit && print "$fg[green]done$reset_color"
776   fi
777 }
778 # }}}
779
780 # runit {{{
781 function runit
782 {
783   writeconfig
784   if [ -z "$NOSTART" ] ; then
785     print "$reset_color"
786     if [ -x /etc/init.d/xorg-common ] ; then
787       sudo /etc/init.d/xorg-common start
788     else
789       if [ -x /etc/init.d/xfree86-common ] ; then
790         sudo /etc/init.d/xfree86-common start
791       fi
792     fi
793     print ""
794     if [ -z "$DISPLAY" ] ; then
795       print "$bold_color$fg[green]Now trying to run startx.$reset_color"
796       startx $XINITRC -- $XOPTS
797     else
798       print "$bold_color$fg[green]Now trying to run startx on display $DISPLAY.$reset_color"
799       startx $XINITRC -- :$DISPLAY $XOPTS
800     fi
801   else
802     print "$bold_color$fg[blue]Not running startx as requested via option.$reset_color"
803   fi
804   return 1
805 }
806 # }}}
807
808 # failed {{{
809 function failed
810 {
811   print "$fg[red]"
812   if [ -z "$ROOT" ] ; then
813     if [[ $(tty) == /dev/pts/* ]] ; then
814       print "It seems you are running $PROGRAMNAME from inside GNU screen.
815 Notice that this might fail if running as user grml!
816 Please exit screen and try to run $PROGRAMNAME again."
817     fi
818   fi
819   print "Run the following commands for getting information on your hardware:
820   hwinfo --gfxcard
821   discover -v --data-path=xfree86/server/device/driver display
822   xdebconfigurator -c -d -i -x
823   get-edid | parse-edid
824
825 Do you want to go the debian way of life? Run:
826   apt-get install x-window-system-core read-edid mdetect hwinfo xdebconfigurator
827   dpkg-reconfigure x-window-system-core (or xserver-xorg depending on your system)
828
829 Problems with the module used for X? Try to load another one or
830 fall back to module vesa:
831   $PROGRAMNAME -module radeon ...
832   $PROGRAMNAME -module vesa  ...
833
834 Do you want to deactivate a present synaptics touchpad? Run:
835   $PROGRAMNAME -nosynaptics ...
836
837 Your monitor is very old and/or does not support DDC-probing?
838   $PROGRAMNAME -noddc ...
839
840 Do you want to create a x configuration file but do not start X?
841   $PROGRAMNAME -nostart ...
842
843 Monitor frequency too high or too low? Just specify hsync/vsync manually:
844   $PROGRAMNAME -hsync 30-65 ...
845   $PROGRAMNAME -hsync 30-65 -vsync 50-60 ...
846
847 Want to adjust the resolution? Use the mode-switch:
848   $PROGRAMNAME -mode 1024x768 ...
849   $PROGRAMNAME -mode '1280x1024 1024x768' ...
850
851 Problems? Use vesa with resolution 1024x768:
852   $PROGRAMNAME -module vesa -mode 1024x768 ...
853
854 Still problems with X? Use the fallback option:
855   $PROGRAMNAME -fallback ...
856
857 To adjust resolution while running X execute:
858   xrandr -s '1024x768'
859
860 More information on grml-x can be found in the manual page: man grml-x
861
862 Report bugs, send wishes and feedback to the grml team:
863 http://grml.org/bugs/ - contact (at) grml.org
864 "
865 print -n "$reset_color"
866 }
867 # }}}
868
869 # cleanup {{{
870 cleanup()
871 {
872   rm -f $HWINFO_TMP
873   rm -f $MONITORINFO
874   rm -f $MOUSEINFO
875   rm -f $XCONFTMP
876 }
877 cleanup
878 # }}}
879
880 # xinitrc {{{
881   if ! [ -x "$(which $WINDOWMANAGER)" ] ; then
882      print "$bg[black]$fg[red]${bold_color}Fatal: windowmanager $fg[blue]$WINDOWMANAGER$fg[red] not executable, startx won' work.${reset_color}">&2
883      bailout
884   fi
885   if [ -w "$XINITRC" ] ; then
886     sed -i "s|^[^#]*exec.*|  exec $WINDOWMANAGER|g" $XINITRC
887     runit || failed
888   else
889     echo -e "#!/bin/sh\n  exec $WINDOWMANAGER" >> $XINITRC
890     runit || failed
891   fi
892 # }}}
893
894 ## END OF FILE #################################################################
895 # vim:foldmethod=marker