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