Big rewrite of grml-x: heavy use of evdev
[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
611         Load  "type1"     # font module
612         Load  "freetype"  # font 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  "ddc"       # ddc probing of monitor
618         # Load  "bitmap"    # bitmap fonts
619         # Load  "GLcore"    # render OpenGL in software
620         # Load  "i2c"       # I2C bus
621         # Load  "int10"     # initialize graphics cards via int10 call to the BIOS
622         # Load  "speedo"    # font module
623         # Load  "v4l"       # Video for Linux
624 # Valid entries - see /usr/lib/xorg/modules/[extensions/]
625 # afb bitmap cfb cfb16 cfb24 cfb32 cw damage dbe ddc dri drm extmod fb
626 # fbdevhw freetype GLcore glx i2c int10 int10 layer mfb pcidata rac ramdac
627 # record scanpci shadow shadowfb type1 vbe vgahw xaa xf1bpp xf24_32bpp xf4bpp
628 # xf8_16bpp xf8_32bpp xtrap
629 EndSection
630
631 # If you'd like to switch the positions of your capslock and control keys, use:
632 # Option "XkbOptions" "ctrl:swapcaps"
633 # Or if you just want both to be control, use:
634 # Option "XkbOptions" "ctrl:nocaps"
635 # More information: http://ftp.x.org/pub/X11R7.0/doc/html/XKB-Config.html
636 # Section "InputDevice"
637 #         Identifier  "Keyboard0"
638 #         Option      "CoreKeyboard"
639 #         $KEYBOARD
640 #         # Option      "XkbOptions" "ctrl:swapcaps,grp:alt_shift_toggle,grp_led:scroll,compose:menu"
641 # EndSection
642
643 # More information: http://ftp.x.org/pub/X11R7.0/doc/html/mouse.html
644 $USBMOUSEDETAIL
645 $PS2MOUSEDETAIL
646 $SERMOUSEDETAIL
647 $SYNMOUSEDETAIL
648 $EVDEV_MOUSE
649 Section "Monitor"
650         Identifier   "Monitor0"
651 #       ModelName    "Old Monitor (no DDC)"
652         $DPMS
653 #       HorizSync    28.0 - 78.0 # Warning: This may fry very old Monitors
654 #       HorizSync    28.0 - 96.0 # Warning: This may fry old Monitors
655 $HORIZSYNC
656 #       VertRefresh  50.0 - 76.0 # Very conservative. May flicker.
657 #       VertRefresh  50.0 - 60.0 # Extreme conservative. Will flicker. TFT default.
658 $VERTISYNC
659 # Need more information?
660 #  http://xtiming.sourceforge.net/cgi-bin/xtiming.pl
661 #  http://en.tldp.org/HOWTO/XFree86-Video-Timings-HOWTO/
662 EndSection
663
664 Section "Device"
665         ### Available Driver options are:
666         ## sw_cursor is needed for some ati and radeon cards
667         # Option     "sw_cursor"
668         # Option     "hw_cursor"
669         # Option     "NoAccel"
670         # Option     "ShowCache"
671         # Option     "ShadowFB"
672         # Option     "UseFBDev"
673         # Option     "Rotate"
674         ## xorg + nvidia:
675         # Option "RenderAccel" "true"
676         # Option "AllowGLXWithComposite" "true"
677         Identifier  "Card0"
678         # The following line is auto-generated by grml-x
679         Driver      "$MODULE"
680         VendorName  "All"
681         BoardName   "All"
682         ## Workaround for drivers (for example radeon) which might send output to wrong device:
683         # Option "MonitorLayout" "LVDS, AUTO"
684         # Option "MonitorLayout" "LVDS, CRT"
685         # Option "MonitorLayout" "NONE, STV"
686         # Option "MonitorLayout" "LVDS"
687         ## Specify BusID:
688         # BusID       "PCI:1:0:0"
689 EndSection
690
691 Section "Screen"
692         Identifier "Screen0"
693         Device     "Card0"
694         Monitor    "Monitor0"
695         DefaultColorDepth 16
696         SubSection "Display"
697                 Depth     1
698                 $MODES
699         EndSubSection
700         SubSection "Display"
701                 Depth     4
702                 $MODES
703         EndSubSection
704         SubSection "Display"
705                 Depth     8
706                 $MODES
707         EndSubSection
708         SubSection "Display"
709                 Depth     15
710                 $MODES
711         EndSubSection
712         SubSection "Display"
713                 Depth     16
714                 $MODES
715         EndSubSection
716         SubSection "Display"
717                 Depth     24
718                 $MODES
719         EndSubSection
720         SubSection "Display"
721                 Depth     32
722                 $MODES
723         EndSubSection
724 EndSection
725
726 # Make sure you have the relevant Debian packages on your system
727 # to be able to use DRI (libgl1-mesa-dri for example)
728 Section "DRI"
729         Mode 0666
730 EndSection
731
732 #Section "Extensions"
733 #    Option "Composite" "Enable"
734 #EndSection
735
736 ## END OF FILE #################################################################
737 EOX
738 }
739 # }}}
740
741 # writeit {{{
742 writeit() {
743     XCONFTMP="/tmp/xconfig.$$"
744     xconfig > $XCONFTMP
745     # we do not want to have two CorePointers, deactivate one therefore
746     if grep -Eq '^[[:space:]]+InputDevice[ ]+"USB Mouse"[ ]+"CorePointer"' $XCONFTMP ; then
747        if grep -Eq '^[[:space:]]+InputDevice[ ]+"PS/2 Mouse"[ ]+"CorePointer"' $XCONFTMP ; then
748           sed -i 's|InputDevice.*PS/2.*CorePointer|# & # deactivated to avoid two CorePointers|' $XCONFTMP
749        fi
750     fi
751     [ -f $XCONFIG ] && sudo mv -f $XCONFIG $XCONFIG.old
752     sudo mv $XCONFTMP $XCONFIG
753     sudo chown root.root $XCONFIG
754     sudo chmod 644 $XCONFIG
755 }
756 # }}}
757
758 # writeconfig {{{
759 function writeconfig
760 {
761   if [[ ! -f $XCONFIG ]] ; then
762     print -n "$bold_color$fg[blue]Creating $XCONFIG: $fg[red]"
763     writeit && print "$fg[green]done$reset_color"
764   else
765     if [ -z "$FORCE" -a -z "$FALLBACK" ] ; then
766        print "$bold_color$fg[blue]Notice: $XCONFIG exists already.
767 Use the force-option (-force) to force creation.
768 $fg[red]"
769     fi
770   fi
771   if [[ -n "$FORCE" ]] ; then
772     print "$bold_color$fg[blue]Force-switch or manual option(s) detected:"
773     print -n "\-> Moving eventual existing $XCONFIG to ${XCONFIG}.old: $fg[red]"
774     writeit && print "$fg[green]done$reset_color"
775   fi
776 }
777 # }}}
778
779 # runit {{{
780 function runit
781 {
782   writeconfig
783   if [ -z "$NOSTART" ] ; then
784     print "$reset_color"
785     if [ -x /etc/init.d/xorg-common ] ; then
786       sudo /etc/init.d/xorg-common start
787     else
788       if [ -x /etc/init.d/xfree86-common ] ; then
789         sudo /etc/init.d/xfree86-common start
790       fi
791     fi
792     print ""
793     if [ -z "$DISPLAY" ] ; then
794       print "$bold_color$fg[green]Now trying to run startx.$reset_color"
795       startx $XINITRC -- $XOPTS
796     else
797       print "$bold_color$fg[green]Now trying to run startx on display $DISPLAY.$reset_color"
798       startx $XINITRC -- :$DISPLAY $XOPTS
799     fi
800   else
801     print "$bold_color$fg[blue]Not running startx as requested via option.$reset_color"
802   fi
803   return 1
804 }
805 # }}}
806
807 # failed {{{
808 function failed
809 {
810   print "$fg[red]"
811   if [ -z "$ROOT" ] ; then
812     if [[ $(tty) == /dev/pts/* ]] ; then
813       print "It seems you are running $PROGRAMNAME from inside GNU screen.
814 Notice that this might fail if running as user grml!
815 Please exit screen and try to run $PROGRAMNAME again."
816     fi
817   fi
818   print "Run the following commands for getting information on your hardware:
819   hwinfo --gfxcard
820   discover -v --data-path=xfree86/server/device/driver display
821   xdebconfigurator -c -d -i -x
822   get-edid | parse-edid
823
824 Do you want to go the debian way of life? Run:
825   apt-get install x-window-system-core read-edid mdetect hwinfo xdebconfigurator
826   dpkg-reconfigure x-window-system-core (or xserver-xorg depending on your system)
827
828 Problems with the module used for X? Try to load another one or
829 fall back to module vesa:
830   $PROGRAMNAME -module radeon ...
831   $PROGRAMNAME -module vesa  ...
832
833 Do you want to deactivate a present synaptics touchpad? Run:
834   $PROGRAMNAME -nosynaptics ...
835
836 Your monitor is very old and/or does not support DDC-probing?
837   $PROGRAMNAME -noddc ...
838
839 Do you want to create a x configuration file but do not start X?
840   $PROGRAMNAME -nostart ...
841
842 Monitor frequency too high or too low? Just specify hsync/vsync manually:
843   $PROGRAMNAME -hsync 30-65 ...
844   $PROGRAMNAME -hsync 30-65 -vsync 50-60 ...
845
846 Want to adjust the resolution? Use the mode-switch:
847   $PROGRAMNAME -mode 1024x768 ...
848   $PROGRAMNAME -mode '1280x1024 1024x768' ...
849
850 Problems? Use vesa with resolution 1024x768:
851   $PROGRAMNAME -module vesa -mode 1024x768 ...
852
853 Still problems with X? Use the fallback option:
854   $PROGRAMNAME -fallback ...
855
856 To adjust resolution while running X execute:
857   xrandr -s '1024x768'
858
859 More information on grml-x can be found in the manual page: man grml-x
860
861 Report bugs, send wishes and feedback to the grml team:
862 http://grml.org/bugs/ - contact (at) grml.org
863 "
864 print -n "$reset_color"
865 }
866 # }}}
867
868 # cleanup {{{
869 cleanup()
870 {
871   rm -f $HWINFO_TMP
872   rm -f $MONITORINFO
873   rm -f $MOUSEINFO
874   rm -f $XCONFTMP
875 }
876 cleanup
877 # }}}
878
879 # xinitrc {{{
880   if ! [ -x "$(which $WINDOWMANAGER)" ] ; then
881      print "$bg[black]$fg[red]${bold_color}Fatal: windowmanager $fg[blue]$WINDOWMANAGER$fg[red] not executable, startx won' work.${reset_color}">&2
882      bailout
883   fi
884   if [ -w "$XINITRC" ] ; then
885     sed -i "s|^[^#]*exec.*|  exec $WINDOWMANAGER|g" $XINITRC
886     runit || failed
887   else
888     echo -e "#!/bin/sh\n  exec $WINDOWMANAGER" >> $XINITRC
889     runit || failed
890   fi
891 # }}}
892
893 ## END OF FILE #################################################################
894 # vim:foldmethod=marker