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