xserver: Branch 'pci-rework' - 148 commits

Ian Romanick idr at kemper.freedesktop.org
Wed Mar 28 18:13:35 EEST 2007


 GL/Makefile.am                                                                  |   12 
 GL/apple/Makefile.am                                                            |   15 
 GL/apple/indirect.c                                                             | 2136 +++++++---
 GL/glx/glxbyteorder.h                                                           |    5 
 GL/glx/glxcmdsswap.c                                                            |    4 
 GL/glx/glxdri.c                                                                 |    1 
 GL/mesa/main/Makefile.am                                                        |    1 
 GL/mesa/shader/Makefile.am                                                      |   13 
 GL/mesa/shader/slang/Makefile.am                                                |   22 
 GL/mesa/swrast/Makefile.am                                                      |    3 
 GL/mesa/tnl/Makefile.am                                                         |    1 
 Xext/appgroup.c                                                                 |   52 
 Xext/appgroup.h                                                                 |   22 
 Xext/panoramiX.c                                                                |   48 
 Xext/panoramiX.h                                                                |   12 
 Xext/panoramiXh.h                                                               |    5 
 Xext/panoramiXsrv.h                                                             |    3 
 Xext/saver.c                                                                    |    4 
 Xext/security.c                                                                 |    3 
 Xext/securitysrv.h                                                              |    9 
 Xext/shm.c                                                                      |   23 
 Xext/xace.c                                                                     |    4 
 Xext/xace.h                                                                     |   10 
 Xext/xevie.c                                                                    |    4 
 Xext/xtest.c                                                                    |    2 
 Xi/chgfctl.c                                                                    |  261 -
 Xi/chgfctl.h                                                                    |   42 
 Xi/chgptr.h                                                                     |    8 
 Xi/closedev.c                                                                   |   92 
 Xi/closedev.h                                                                   |   10 
 Xi/exevents.c                                                                   |   58 
 Xi/exglobals.h                                                                  |    2 
 Xi/extinit.c                                                                    |  384 -
 Xi/getdctl.c                                                                    |  213 
 Xi/getdctl.h                                                                    |   24 
 Xi/getfctl.c                                                                    |  198 
 Xi/getfctl.h                                                                    |   30 
 Xi/listdev.c                                                                    |  224 -
 Xi/listdev.h                                                                    |   38 
 afb/afb.h                                                                       |  124 
 afb/afbbitblt.c                                                                 |  146 
 afb/afbcmap.c                                                                   |   18 
 afb/afbgc.c                                                                     |  266 -
 afb/afbimage.c                                                                  |   31 
 afb/afbpixmap.c                                                                 |   14 
 afb/afbscrinit.c                                                                |   50 
 afb/afbsetsp.c                                                                  |   18 
 cfb/cfbpixmap.c                                                                 |    4 
 composite/compalloc.c                                                           |    2 
 composite/compext.c                                                             |   40 
 composite/compinit.c                                                            |    2 
 composite/compint.h                                                             |   15 
 config/config.c                                                                 |    6 
 configure.ac                                                                    |  220 -
 damageext/damageext.c                                                           |   18 
 damageext/damageextint.h                                                        |   14 
 dbe/dbe.c                                                                       |   31 
 dbe/dbestruct.h                                                                 |    5 
 dbe/midbe.c                                                                     |   25 
 dix/atom.c                                                                      |    8 
 dix/colormap.c                                                                  |   56 
 dix/cursor.c                                                                    |    8 
 dix/devices.c                                                                   |   86 
 dix/dispatch.c                                                                  |  305 -
 dix/dixfonts.c                                                                  |    7 
 dix/dixutils.c                                                                  |   16 
 dix/events.c                                                                    |  192 
 dix/extension.c                                                                 |   95 
 dix/gc.c                                                                        |   81 
 dix/getevents.c                                                                 |    2 
 dix/glyphcurs.c                                                                 |    8 
 dix/grabs.c                                                                     |    8 
 dix/main.c                                                                      |    6 
 dix/pixmap.c                                                                    |    4 
 dix/privates.c                                                                  |    8 
 dix/property.c                                                                  |    6 
 dix/resource.c                                                                  |   70 
 dix/swaprep.c                                                                   |  199 
 dix/swapreq.c                                                                   |  276 -
 dix/window.c                                                                    |  320 -
 doc/Makefile.am                                                                 |   16 
 doc/SecurityPolicy.man.pre                                                      |  258 +
 doc/Xserver.man.pre                                                             |  221 -
 exa/exa.c                                                                       |    4 
 fb/fbpixmap.c                                                                   |    4 
 hw/Makefile.am                                                                  |   13 
 hw/darwin/Makefile.am                                                           |  387 +
 hw/darwin/README.apple                                                          |   35 
 hw/darwin/apple/English.lproj/InfoPlist.strings                                 |binary
 hw/darwin/apple/English.lproj/main.nib/.svn/entries                             |   65 
 hw/darwin/apple/English.lproj/main.nib/.svn/format                              |    1 
 hw/darwin/apple/English.lproj/main.nib/.svn/prop-base/keyedobjects.nib.svn-base |    5 
 hw/darwin/apple/English.lproj/main.nib/.svn/text-base/classes.nib.svn-base      |  318 +
 hw/darwin/apple/English.lproj/main.nib/.svn/text-base/info.nib.svn-base         |   18 
 hw/darwin/apple/English.lproj/main.nib/.svn/text-base/keyedobjects.nib.svn-base |binary
 hw/darwin/apple/English.lproj/main.nib/classes.nib                              |  318 +
 hw/darwin/apple/English.lproj/main.nib/info.nib                                 |   18 
 hw/darwin/apple/English.lproj/main.nib/keyedobjects.nib                         |binary
 hw/darwin/apple/Info.plist                                                      |   71 
 hw/darwin/apple/X11.icns                                                        |binary
 hw/darwin/apple/X11.xcodeproj/project.pbxproj                                   |  320 +
 hw/darwin/apple/X11Application.h                                                |  104 
 hw/darwin/apple/X11Application.m                                                |  926 ++++
 hw/darwin/apple/X11Controller.h                                                 |   86 
 hw/darwin/apple/X11Controller.m                                                 |  752 +++
 hw/darwin/apple/Xquartz.man                                                     |  158 
 hw/darwin/apple/bundle-main.c                                                   |  912 ++++
 hw/darwin/bundle/Dutch.lproj/Makefile.am                                        |   35 
 hw/darwin/bundle/English.lproj/Makefile.am                                      |   35 
 hw/darwin/bundle/French.lproj/Makefile.am                                       |   38 
 hw/darwin/bundle/German.lproj/Makefile.am                                       |   36 
 hw/darwin/bundle/Info.plist                                                     |   66 
 hw/darwin/bundle/Japanese.lproj/Makefile.am                                     |   37 
 hw/darwin/bundle/Makefile.am                                                    |   38 
 hw/darwin/bundle/Portuguese.lproj/Makefile.am                                   |   36 
 hw/darwin/bundle/Spanish.lproj/Makefile.am                                      |   36 
 hw/darwin/bundle/Swedish.lproj/Makefile.am                                      |   36 
 hw/darwin/bundle/ko.lproj/Makefile.am                                           |   37 
 hw/darwin/darwin.c                                                              |   14 
 hw/darwin/darwin.h                                                              |    5 
 hw/darwin/darwinEvents.c                                                        |  352 -
 hw/darwin/darwinKeyboard.c                                                      |    2 
 hw/darwin/darwinKeyboard.h                                                      |    2 
 hw/darwin/iokit/Makefile.am                                                     |   17 
 hw/darwin/iokit/xfIOKit.c                                                       |    5 
 hw/darwin/iokit/xfIOKitCursor.c                                                 |    5 
 hw/darwin/iokit/xfIOKitStartup.c                                                |   11 
 hw/darwin/quartz/Makefile.am                                                    |   54 
 hw/darwin/quartz/Preferences.m                                                  |    6 
 hw/darwin/quartz/XDarwin.pbproj/project.pbxproj                                 |    2 
 hw/darwin/quartz/XDarwinStartup.c                                               |    4 
 hw/darwin/quartz/XServer.m                                                      |   18 
 hw/darwin/quartz/applewm.c                                                      |   27 
 hw/darwin/quartz/cr/XView.m                                                     |    4 
 hw/darwin/quartz/cr/crAppleWM.m                                                 |   14 
 hw/darwin/quartz/cr/crFrame.m                                                   |   10 
 hw/darwin/quartz/cr/crScreen.m                                                  |   18 
 hw/darwin/quartz/fullscreen/fullscreen.c                                        |   10 
 hw/darwin/quartz/fullscreen/quartzCursor.c                                      |    8 
 hw/darwin/quartz/pseudoramiX.c                                                  |    4 
 hw/darwin/quartz/quartz.c                                                       |   12 
 hw/darwin/quartz/quartzAudio.c                                                  |    5 
 hw/darwin/quartz/quartzCocoa.m                                                  |    3 
 hw/darwin/quartz/quartzCursor.c                                                 |    5 
 hw/darwin/quartz/quartzCursor.h                                                 |    1 
 hw/darwin/quartz/quartzKeyboard.c                                               |    5 
 hw/darwin/quartz/quartzPasteboard.c                                             |    3 
 hw/darwin/quartz/quartzStartup.c                                                |   87 
 hw/darwin/quartz/xpr/appledri.c                                                 |    3 
 hw/darwin/quartz/xpr/appledri.h                                                 |  107 
 hw/darwin/quartz/xpr/appledristr.h                                              |  176 
 hw/darwin/quartz/xpr/dri.c                                                      |    3 
 hw/darwin/quartz/xpr/x-hash.c                                                   |    4 
 hw/darwin/quartz/xpr/x-hook.c                                                   |    4 
 hw/darwin/quartz/xpr/x-list.c                                                   |    4 
 hw/darwin/quartz/xpr/xprAppleWM.c                                               |    7 
 hw/darwin/quartz/xpr/xprCursor.c                                                |    6 
 hw/darwin/quartz/xpr/xprFrame.c                                                 |    6 
 hw/darwin/quartz/xpr/xprScreen.c                                                |   27 
 hw/darwin/utils/Makefile.am                                                     |   11 
 hw/dmx/dmxclient.h                                                              |    4 
 hw/dmx/dmxpixmap.c                                                              |    4 
 hw/dmx/dmxscrinit.c                                                             |    6 
 hw/kdrive/ephyr/ephyr.c                                                         |    2 
 hw/kdrive/ephyr/ephyrinit.c                                                     |    2 
 hw/kdrive/ephyr/hostx.c                                                         |    6 
 hw/kdrive/ephyr/hostx.h                                                         |    2 
 hw/kdrive/src/kinput.c                                                          |   27 
 hw/xfree86/Makefile.am                                                          |   18 
 hw/xfree86/common/xf86Bus.c                                                     |   31 
 hw/xfree86/common/xf86Bus.h                                                     |    3 
 hw/xfree86/common/xf86Config.c                                                  |   30 
 hw/xfree86/common/xf86Config.h                                                  |    1 
 hw/xfree86/common/xf86Configure.c                                               |    2 
 hw/xfree86/common/xf86DGA.c                                                     |  180 
 hw/xfree86/common/xf86Events.c                                                  |    4 
 hw/xfree86/common/xf86Globals.c                                                 |    1 
 hw/xfree86/common/xf86Helper.c                                                  |   13 
 hw/xfree86/common/xf86Init.c                                                    |    1 
 hw/xfree86/common/xf86Mode.c                                                    |   10 
 hw/xfree86/common/xf86Priv.h                                                    |    2 
 hw/xfree86/common/xf86XKB.c                                                     |    2 
 hw/xfree86/common/xf86Xinput.c                                                  |   46 
 hw/xfree86/common/xf86Xinput.h                                                  |    8 
 hw/xfree86/common/xf86fbman.c                                                   |    2 
 hw/xfree86/common/xf86xv.c                                                      |    2 
 hw/xfree86/ddc/Makefile.am                                                      |    8 
 hw/xfree86/ddc/ddcProperty.c                                                    |    1 
 hw/xfree86/ddc/xf86DDC.c                                                        |   49 
 hw/xfree86/dixmods/Makefile.am                                                  |   19 
 hw/xfree86/dixmods/extmod/dgaproc.h                                             |    5 
 hw/xfree86/dixmods/glxmodule.c                                                  |    4 
 hw/xfree86/dixmods/xkbKillSrv.c                                                 |    2 
 hw/xfree86/dixmods/xkbPrivate.c                                                 |    2 
 hw/xfree86/dixmods/xkbVT.c                                                      |    2 
 hw/xfree86/doc/README.modes                                                     |  474 ++
 hw/xfree86/doc/man/xorg.conf.man.pre                                            |   79 
 hw/xfree86/dri/dri.c                                                            |  137 
 hw/xfree86/dri/dri.h                                                            |    5 
 hw/xfree86/dri/dristruct.h                                                      |    3 
 hw/xfree86/i2c/Makefile.am                                                      |    5 
 hw/xfree86/i2c/uda1380_module.c                                                 |    2 
 hw/xfree86/i2c/xf86i2cmodule.c                                                  |   36 
 hw/xfree86/loader/Makefile.am                                                   |    3 
 hw/xfree86/loader/dixsym.c                                                      |    4 
 hw/xfree86/loader/loader.c                                                      |  116 
 hw/xfree86/loader/loaderProcs.h                                                 |    4 
 hw/xfree86/loader/loadmod.c                                                     |  123 
 hw/xfree86/loader/misym.c                                                       |    3 
 hw/xfree86/loader/xf86sym.c                                                     |   94 
 hw/xfree86/modes/Makefile.am                                                    |   29 
 hw/xfree86/modes/xf86Crtc.c                                                     | 2040 +++++++++
 hw/xfree86/modes/xf86Crtc.h                                                     |  740 +++
 hw/xfree86/modes/xf86Cursors.c                                                  |  607 ++
 hw/xfree86/modes/xf86DiDGA.c                                                    |  286 +
 hw/xfree86/modes/xf86EdidModes.c                                                |  490 ++
 hw/xfree86/modes/xf86Modes.c                                                    |  664 +++
 hw/xfree86/modes/xf86Modes.h                                                    |   98 
 hw/xfree86/modes/xf86RandR12.c                                                  | 1088 +++++
 hw/xfree86/modes/xf86RandR12.h                                                  |   37 
 hw/xfree86/modes/xf86Rename.h                                                   |   84 
 hw/xfree86/modes/xf86Rotate.c                                                   |  464 ++
 hw/xfree86/modes/xf86cvt.c                                                      |  308 +
 hw/xfree86/os-support/bus/axpPci.c                                              |    5 
 hw/xfree86/os-support/shared/libc_wrapper.c                                     |    2 
 hw/xfree86/os-support/solaris/Makefile.am                                       |    4 
 hw/xfree86/os-support/solaris/sun_apm.c                                         |  232 +
 hw/xfree86/os-support/xf86_OSlib.h                                              |    2 
 hw/xfree86/parser/DRI.c                                                         |   31 
 hw/xfree86/parser/Flags.c                                                       |    9 
 hw/xfree86/parser/Layout.c                                                      |   38 
 hw/xfree86/parser/Makefile.am                                                   |    4 
 hw/xfree86/parser/Module.c                                                      |    2 
 hw/xfree86/parser/Monitor.c                                                     |   32 
 hw/xfree86/parser/Screen.c                                                      |    2 
 hw/xfree86/parser/Vendor.c                                                      |   15 
 hw/xfree86/parser/Video.c                                                       |   34 
 hw/xfree86/parser/configProcs.h                                                 |   16 
 hw/xfree86/parser/read.c                                                        |   38 
 hw/xfree86/parser/scan.c                                                        |   16 
 hw/xfree86/parser/xf86Parser.h                                                  |    1 
 hw/xfree86/ramdac/Makefile.am                                                   |    6 
 hw/xfree86/ramdac/xf86Cursor.c                                                  |    3 
 hw/xfree86/ramdac/xf86Cursor.h                                                  |    3 
 hw/xfree86/ramdac/xf86RamDacMod.c                                               |   46 
 hw/xfree86/x86emu/prim_ops.c                                                    |    4 
 hw/xfree86/xaa/Makefile.am                                                      |    1 
 hw/xfree86/xaa/xaaInit.c                                                        |    8 
 hw/xfree86/xf4bpp/Makefile.am                                                   |    1 
 hw/xfree86/xf4bpp/offscreen.c                                                   |   19 
 hw/xfree86/xf4bpp/ppcGC.c                                                       |    9 
 hw/xfree86/xf4bpp/ppcPixmap.c                                                   |    4 
 hw/xfree86/xf4bpp/ppcPolyRec.c                                                  |  130 
 hw/xfree86/xf4bpp/xf4bpp.h                                                      |    8 
 hw/xgl/egl/kinput.c                                                             |    2 
 hw/xgl/glx/xglx.c                                                               |    2 
 hw/xnest/Display.c                                                              |    2 
 hw/xnest/Keyboard.c                                                             |    2 
 hw/xnest/Pixmap.c                                                               |    6 
 hw/xnest/Screen.c                                                               |    6 
 hw/xnest/XNPixmap.h                                                             |    7 
 hw/xprint/config/C/print/models/CANONC3200-PS/fonts/Makefile.am                 |   10 
 hw/xprint/config/C/print/models/HPLJ4050-PS/fonts/Makefile.am                   |   10 
 hw/xprint/config/C/print/models/PSdefault/fonts/Makefile.am                     |    7 
 hw/xprint/config/C/print/models/SPSPARC2/fonts/Makefile.am                      |    2 
 hw/xwin/InitOutput.c                                                            |    2 
 hw/xwin/winconfig.c                                                             |    2 
 hw/xwin/winkeybd.c                                                              |    2 
 include/dix-config.h.in                                                         |   15 
 include/dix.h                                                                   |   75 
 include/exevents.h                                                              |   16 
 include/extinit.h                                                               |  119 
 include/extnsionst.h                                                            |   35 
 include/gc.h                                                                    |    5 
 include/globals.h                                                               |    4 
 include/inputstr.h                                                              |    2 
 include/os.h                                                                    |   14 
 include/pixmapstr.h                                                             |    2 
 include/screenint.h                                                             |    4 
 include/scrnintstr.h                                                            |    2 
 include/swaprep.h                                                               |   18 
 include/window.h                                                                |   19 
 include/windowstr.h                                                             |    6 
 include/xkbsrv.h                                                                | 1022 ++++
 include/xorg-server.h.in                                                        |   12 
 mfb/mfbpixmap.c                                                                 |    4 
 mi/mi.h                                                                         |   54 
 mi/miarc.c                                                                      |  113 
 mi/mibitblt.c                                                                   |   22 
 mi/mibstore.c                                                                   |   62 
 mi/micmap.c                                                                     |   18 
 mi/midash.c                                                                     |  193 
 mi/mieq.c                                                                       |   24 
 mi/miexpose.c                                                                   |   32 
 mi/mifillarc.c                                                                  |   70 
 mi/mifillarc.h                                                                  |   24 
 mi/mifillrct.c                                                                  |   20 
 mi/mifpolycon.c                                                                 |    8 
 mi/miglblt.c                                                                    |   20 
 mi/miinitext.c                                                                  |   27 
 mi/miline.h                                                                     |    2 
 mi/mioverlay.c                                                                  |   14 
 mi/mipointer.c                                                                  |   73 
 mi/mipointer.h                                                                  |   15 
 mi/mipoly.c                                                                     |    8 
 mi/mipoly.h                                                                     |    8 
 mi/mipolycon.c                                                                  |    8 
 mi/mipolygen.c                                                                  |   12 
 mi/mipolypnt.c                                                                  |    2 
 mi/mipolytext.c                                                                 |   51 
 mi/mipolyutil.c                                                                 |   52 
 mi/mipushpxl.c                                                                  |   10 
 mi/miregion.c                                                                   |  333 -
 mi/miscrinit.c                                                                  |   14 
 mi/mispans.c                                                                    |   82 
 mi/mispans.h                                                                    |   16 
 mi/misprite.c                                                                   |   10 
 mi/mivaltree.c                                                                  |   30 
 mi/miwideline.c                                                                 |  245 -
 mi/miwideline.h                                                                 |   42 
 mi/miwindow.c                                                                   |   48 
 mi/mizerarc.c                                                                   |   32 
 mi/mizerarc.h                                                                   |    6 
 miext/Makefile.am                                                               |    3 
 miext/cw/cw.c                                                                   |   24 
 miext/cw/cw.h                                                                   |    4 
 miext/damage/damage.c                                                           |   28 
 miext/damage/damagestr.h                                                        |    6 
 miext/rootless/Makefile.am                                                      |   29 
 miext/rootless/accel/Makefile.am                                                |   18 
 miext/rootless/accel/rlBlt.c                                                    |    1 
 miext/rootless/rootlessCommon.c                                                 |    3 
 miext/rootless/rootlessGC.c                                                     |    1 
 miext/rootless/rootlessValTree.c                                                |    1 
 miext/rootless/rootlessWindow.c                                                 |    6 
 miext/rootless/safeAlpha/Makefile.am                                            |   12 
 miext/rootless/safeAlpha/safeAlphaPicture.c                                     |    6 
 miext/rootless/safeAlpha/safeAlphaWindow.c                                      |    4 
 os/access.c                                                                     |    6 
 os/auth.c                                                                       |   20 
 os/connection.c                                                                 |   12 
 os/io.c                                                                         |   23 
 os/osdep.h                                                                      |   14 
 os/utils.c                                                                      |   15 
 os/xdmcp.c                                                                      |   72 
 randr/mirandr.c                                                                 |   28 
 randr/randr.c                                                                   |    2 
 randr/randrstr.h                                                                |   66 
 randr/rrcrtc.c                                                                  |  212 
 randr/rrdispatch.c                                                              |    7 
 randr/rrinfo.c                                                                  |   17 
 randr/rrmode.c                                                                  |  217 -
 randr/rroutput.c                                                                |  152 
 randr/rrpointer.c                                                               |    2 
 randr/rrproperty.c                                                              |  186 
 randr/rrscreen.c                                                                |   78 
 record/set.c                                                                    |    8 
 render/animcur.c                                                                |    4 
 render/glyph.c                                                                  |    6 
 render/glyphstr.h                                                               |    2 
 render/picture.c                                                                |    2 
 xfixes/cursor.c                                                                 |    3 
 xfixes/select.c                                                                 |    4 
 xfixes/xfixes.c                                                                 |    8 
 xfixes/xfixesint.h                                                              |    3 
 xkb/Makefile.am                                                                 |    3 
 xkb/XKBAlloc.c                                                                  |  157 
 xkb/XKBGAlloc.c                                                                 |    2 
 xkb/XKBMAlloc.c                                                                 |   82 
 xkb/XKBMisc.c                                                                   |  183 
 xkb/ddxBeep.c                                                                   |    2 
 xkb/ddxCtrls.c                                                                  |    2 
 xkb/ddxDevBtn.c                                                                 |    2 
 xkb/ddxFakeBtn.c                                                                |    2 
 xkb/ddxFakeMtn.c                                                                |    2 
 xkb/ddxInit.c                                                                   |    2 
 xkb/ddxKeyClick.c                                                               |    2 
 xkb/ddxKillSrv.c                                                                |    2 
 xkb/ddxLEDs.c                                                                   |    4 
 xkb/ddxList.c                                                                   |    2 
 xkb/ddxLoad.c                                                                   |    8 
 xkb/ddxPrivate.c                                                                |    2 
 xkb/ddxVT.c                                                                     |    2 
 xkb/maprules.c                                                                  |    2 
 xkb/xkb.c                                                                       |   63 
 xkb/xkb.h                                                                       |   42 
 xkb/xkbAccessX.c                                                                |    8 
 xkb/xkbActions.c                                                                |    8 
 xkb/xkbDflts.h                                                                  |   37 
 xkb/xkbEvents.c                                                                 |   46 
 xkb/xkbInit.c                                                                   |   26 
 xkb/xkbLEDs.c                                                                   |  453 --
 xkb/xkbPrKeyEv.c                                                                |    2 
 xkb/xkbSwap.c                                                                   |    2 
 xkb/xkbUtils.c                                                                  |   64 
 xkb/xkberrs.c                                                                   |   31 
 xkb/xkbfmisc.c                                                                  |  109 
 xkb/xkbout.c                                                                    |  126 
 xkb/xkbtext.c                                                                   |   96 
 xkb/xkmread.c                                                                   |   14 
 400 files changed, 20687 insertions(+), 8022 deletions(-)

New commits:
diff-tree 2c6d47108880584f1221ff86c6c8947627f9f607 (from parents)
Merge: c4fe1bcce1c1e4822e688959b331b47a051d6e0a 85220446359a75ea2c359b418b4051c04eea739c
Author: Ian Romanick <idr at us.ibm.com>
Date:   Wed Mar 28 08:08:04 2007 -0700

    Merge branch 'master' of git+ssh://git.freedesktop.org/git/xorg/xserver into pci-rework
    
    Conflicts:
    
    	hw/xfree86/Makefile.am
    	hw/xfree86/dri/dri.c

diff --cc configure.ac
index 42b88c7,fde6a89..0110df9
@@@ -1268,11 -1258,65 +1258,69 @@@
  	AC_CHECK_FUNC([dlopen], [], 
  		AC_CHECK_LIB([dl], [dlopen], XORG_LIBS="$XORG_LIBS -ldl"))
  
 +	PKG_CHECK_MODULES([PCIACCESS], [pciaccess >= 0.8.0])
 +	XSERVER_LIBS="$XSERVER_LIBS $PCIACCESS_LIBS"
 +	XORG_CFLAGS="$XORG_CFLAGS $PCIACCESS_CFLAGS"
 +
  	case $host_os in
+          darwin*)
+                XORG_OS="Darwin"
+                build_darwin=yes
+                if test "X$XQUARTZ" = Xauto; then
+                  AC_CACHE_CHECK([for Carbon framework],xorg_cv_Carbon_framework,[
+                  save_LDFLAGS=$LDFLAGS
+                  LDFLAGS="$LDFLAGS -framework Carbon"
+                  AC_LINK_IFELSE([char FSFindFolder();
+ int main() {
+ FSFindFolder();
+ return 0;}
+                  ],[xorg_cv_Carbon_framework=yes],
+                   [xorg_cv_Carbon_framework=no])
+                   LDFLAGS=$save_LDFLAGS])
+                  if test "X$xorg_cv_Carbon_framework" = Xyes; then
+                    AC_DEFINE([DARWIN_WITH_QUARTZ],[1],
+                          [Have Quartz])
+                    XQUARTZ=yes
+                  else
+                    XQUARTZ=no
+                  fi
+                fi
+ #	       glxAGL / glxCGL don't work yet
+ #               AC_CACHE_CHECK([for AGL framework],xorg_cv_AGL_framework,[
+ #               save_LDFLAGS=$LDFLAGS
+ #               LDFLAGS="$LDFLAGS -framework AGL"
+ #               AC_LINK_IFELSE([char aglEnable();
+ #int main() {
+ #aglEnable();
+ #return 0;}
+ #               ],[xorg_cv_AGL_framework=yes],
+ #               [xorg_cv_AGL_framework=no])
+ #               LDFLAGS=$save_LDFLAGS
+ #               ])
+                xorg_cv_AGL_framework=no
+ 	       DARWIN_LIBS="$FB_LIB $MI_LIB $FIXES_LIB $XEXT_LIB $DBE_LIB $XTRAP_LIB $RECORD_LIB $GLX_LIBS $RENDER_LIB $RANDR_LIB $DAMAGE_LIB $MIEXT_DAMAGE_LIB $MIEXT_SHADOW_LIB $XI_LIB $XKB_LIB $XKB_STUB_LIB $COMPOSITE_LIB $XPSTUBS_LIB $OS_LIB"
+ 	       AC_SUBST([DARWIN_LIBS])
+                AC_CHECK_LIB([Xplugin],[xp_init],[:])
+                AC_SUBST([APPLE_APPLICATIONS_DIR])
+                CFLAGS="${CFLAGS} -D__DARWIN__"
+                PLIST_VERSION_STRING=$VENDOR_VERSION_STRING
+                AC_SUBST([PLIST_VERSION_STRING])
+                PLIST_VENDOR_WEB=$VENDOR_WEB
+                AC_SUBST([PLIST_VENDOR_WEB])
+                # Not sure that we should be disabling all these...
+                if test "x$XF86MISC" = xyes || test "x$XF86MISC" = xauto; then
+                        AC_MSG_NOTICE([Disabling XF86Misc extension])
+                        XF86MISC=no
+                fi
+                if test "x$XF86VIDMODE" = xyes || test "x$XF86VIDMODE" = xauto; then
+                        AC_MSG_NOTICE([Disabling XF86VidMode extension])
+                        XF86VIDMODE=no
+                fi
+                if test "x$DGA" = xyes || test "x$DGA" = xauto; then
+                        AC_MSG_NOTICE([Disabling DGA extension])
+                        DGA=no
+                fi
+                ;;
  	  linux*)
  		if test "x$LNXAPM" = xyes; then
  			XORG_CFLAGS="$XORG_CFLAGS -DXF86PM"
diff --cc hw/xfree86/Makefile.am
index f0c9e56,50aa673..ec6a7ac
@@@ -11,13 -19,13 +19,13 @@@
  DOC_SUBDIR = doc
  
  SUBDIRS = common ddc dummylib i2c x86emu int10 fbdevhw os-support parser rac \
-           ramdac shadowfb vbe vgahw xaa xf1bpp xf4bpp xf8_16bpp \
- 	  xf8_32bpp loader dixmods exa \
+ 	  ramdac shadowfb vbe vgahw xaa $(MFB_SUBDIR) $(CFB_SUBDIR) \
 -	  loader scanpci dixmods exa modes \
++	  loader dixmods exa modes \
  	  $(DRI_SUBDIR) $(XF86UTILS_SUBDIR) $(DOC_SUBDIR)
  
  DIST_SUBDIRS = common ddc dummylib i2c x86emu int10 fbdevhw os-support \
                 parser rac ramdac shadowfb vbe vgahw xaa xf1bpp xf4bpp \
-                xf8_16bpp xf8_32bpp loader dixmods dri exa \
 -               xf8_16bpp xf8_32bpp loader scanpci dixmods dri exa modes \
++               xf8_16bpp xf8_32bpp loader dixmods dri exa modes \
  	       utils doc
  
  bin_PROGRAMS = Xorg
diff --cc hw/xfree86/common/xf86Priv.h
index 60fd31a,59ce8da..274f7e7
@@@ -102,8 -100,8 +102,7 @@@
  extern int xf86NumDrivers;
  extern Bool xf86Resetting;
  extern Bool xf86Initialising;
- extern Bool xf86ProbeFailed;
  extern int xf86NumScreens;
 -extern pciVideoPtr *xf86PciVideoInfo;
  extern xf86CurrentAccessRec xf86CurrentAccess;
  extern const char *xf86VisualNames[];
  extern int xf86Verbose;                 /* verbosity level */
diff-tree 85220446359a75ea2c359b418b4051c04eea739c (from 1af2ef0b25fd8017a3271e624a5f1548f02b09f9)
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Wed Mar 28 13:03:32 2007 +0300

    GL: Update for Mesa changes
    Added s_fragprog.c to fix the build.

diff --git a/GL/mesa/swrast/Makefile.am b/GL/mesa/swrast/Makefile.am
index 9a6aa92..bffb1e7 100644
--- a/GL/mesa/swrast/Makefile.am
+++ b/GL/mesa/swrast/Makefile.am
@@ -34,6 +34,7 @@ nodist_libswrast_la_SOURCES = s_aaline.c
                       s_drawpix.c \
                       s_feedback.c \
                       s_fog.c \
+		      s_fragprog.c \
                       s_imaging.c \
                       s_lines.c \
                       s_logic.c \
diff-tree 1af2ef0b25fd8017a3271e624a5f1548f02b09f9 (from 0bfc3cc22db94ec6867596606fe93228e315c847)
Author: Eric Anholt <eric at anholt.net>
Date:   Tue Mar 27 13:13:45 2007 -0700

    Enable Composite by default now that it disables itself in the known bad cases.

diff --git a/os/utils.c b/os/utils.c
index 2fc5cbb..e605a6c 100644
--- a/os/utils.c
+++ b/os/utils.c
@@ -136,10 +136,7 @@ _X_EXPORT Bool noTestExtensions;
 _X_EXPORT Bool noBigReqExtension = FALSE;
 #endif
 #ifdef COMPOSITE
- /* COMPOSITE is disabled by default for now until the
-  * interface is stable */
- #define COMPOSITE_DEFAULT FALSE
-_X_EXPORT Bool noCompositeExtension = !COMPOSITE_DEFAULT;
+_X_EXPORT Bool noCompositeExtension = FALSE;
 #endif
 
 #ifdef DAMAGE
diff-tree 0bfc3cc22db94ec6867596606fe93228e315c847 (from 5e7936371c9e1ac48e19bf1e9e3f71f037fd9b5d)
Author: Eric Anholt <eric at anholt.net>
Date:   Tue Mar 27 13:12:21 2007 -0700

    Disable composite when Xinerama is active.
    
    It will likely take a decent bit of work to make that work right.

diff --git a/composite/compext.c b/composite/compext.c
index af05b4a..ba37e7d 100644
--- a/composite/compext.c
+++ b/composite/compext.c
@@ -696,6 +696,11 @@ CompositeExtensionInit (void)
 	if (GetPictureScreenIfSet(pScreen) == NULL)
 	    return;
     }
+    /* Xinerama's rewriting of window drawing before Composite gets to it
+     * breaks Composite.
+     */
+    if (!noPanoramiXExtension)
+	return;
 
     CompositeClientWindowType = CreateNewResourceType (FreeCompositeClientWindow);
     if (!CompositeClientWindowType)
diff-tree 5e7936371c9e1ac48e19bf1e9e3f71f037fd9b5d (from 8afc7e2eb3ebec48d3879bf269143259c8bc18c8)
Author: Eric Anholt <eric at anholt.net>
Date:   Mon Mar 26 20:18:18 2007 -0700

    Disable Composite when the screen's visual is pseudocolor.
    
    Rendering fails badly in this case, and I don't care enough to fix it.

diff --git a/composite/compext.c b/composite/compext.c
index 3a9f896..af05b4a 100644
--- a/composite/compext.c
+++ b/composite/compext.c
@@ -678,9 +678,22 @@ CompositeExtensionInit (void)
     ExtensionEntry  *extEntry;
     int		    s;
 
-    /* Ensure that Render is initialized on all screens. */
     for (s = 0; s < screenInfo.numScreens; s++) {
-	if (GetPictureScreenIfSet(screenInfo.screens[s]) == NULL)
+	ScreenPtr pScreen = screenInfo.screens[s];
+	VisualPtr vis;
+
+	/* Composite on 8bpp pseudocolor root windows appears to fail, so
+	 * just disable it on anything pseudocolor for safety.
+	 */
+	for (vis = pScreen->visuals; vis->vid != pScreen->rootVisual; vis++)
+	    ;
+	if ((vis->class | DynamicClass) == PseudoColor)
+	    return;
+
+	/* Ensure that Render is initialized, which is required for automatic
+	 * compositing.
+	 */
+	if (GetPictureScreenIfSet(pScreen) == NULL)
 	    return;
     }
 
diff-tree 8afc7e2eb3ebec48d3879bf269143259c8bc18c8 (from 6ed08949af4f7ac09170d3d9581e4092b24a84ee)
Author: Eric Anholt <eric at anholt.net>
Date:   Mon Mar 26 15:55:38 2007 -0700

    Refuse to initialize Composite if Render is not present.
    
    Composite relies on the presence of Render, in particular for the automatic
    compositing.

diff --git a/composite/compext.c b/composite/compext.c
index 4c25cc7..3a9f896 100644
--- a/composite/compext.c
+++ b/composite/compext.c
@@ -678,6 +678,12 @@ CompositeExtensionInit (void)
     ExtensionEntry  *extEntry;
     int		    s;
 
+    /* Ensure that Render is initialized on all screens. */
+    for (s = 0; s < screenInfo.numScreens; s++) {
+	if (GetPictureScreenIfSet(screenInfo.screens[s]) == NULL)
+	    return;
+    }
+
     CompositeClientWindowType = CreateNewResourceType (FreeCompositeClientWindow);
     if (!CompositeClientWindowType)
 	return;
diff-tree 6ed08949af4f7ac09170d3d9581e4092b24a84ee (from e76b6349516d5d1c8f7167d6f5419e0d06a546c3)
Author: Eric Anholt <eric at anholt.net>
Date:   Tue Mar 27 17:31:28 2007 -0700

    Move libcw setup to the only renderer requiring it (XAA).
    
    Additionally, protect libcw setup behind checks for Render, to avoid
    segfaulting if Render isn't available (xnest).
    
    The previous setup was an ABI-preserving dance, which is better nuked now.
    Now, anything that needs libcw must explicitly initialize it, and
    miDisableCompositeWrapper (previously only called by EXA and presumably binary
    drivers) is gone.

diff --git a/configure.ac b/configure.ac
index 14c4ccb..fde6a89 100644
--- a/configure.ac
+++ b/configure.ac
@@ -853,10 +853,6 @@ AC_DEFINE(DAMAGE,1,[Support Damage exten
 DAMAGE_LIB='$(top_builddir)/damageext/libdamageext.la'
 DAMAGE_INC='-I$(top_srcdir)/damageext'
 MIEXT_DAMAGE_LIB='$(top_builddir)/miext/damage/libdamage.la'
-dnl damage (may) need the composite wrapper when composite is enabled
-if test "$COMPOSITE" = yes; then
-	MIEXT_DAMAGE_LIB="$MIEXT_DAMAGE_LIB "'$(top_builddir)/miext/cw/libcw.la'
-fi
 MIEXT_DAMAGE_INC='-I$(top_srcdir)/miext/damage'
 
 AC_DEFINE(XINPUT, 1, [Support X Input extension])
diff --git a/exa/exa.c b/exa/exa.c
index e9f42df..dd27d5e 100644
--- a/exa/exa.c
+++ b/exa/exa.c
@@ -668,10 +668,6 @@ exaDriverInit (ScreenPtr		pScreen,
     }
 #endif
 
-#ifdef COMPOSITE
-    miDisableCompositeWrapper(pScreen);
-#endif
-
 #ifdef MITSHM
     /* Re-register with the MI funcs, which don't allow shared pixmaps.
      * Shared pixmaps are almost always a performance loss for us, but this
diff --git a/hw/xfree86/loader/misym.c b/hw/xfree86/loader/misym.c
index 46d6a02..78ae10e 100644
--- a/hw/xfree86/loader/misym.c
+++ b/hw/xfree86/loader/misym.c
@@ -208,9 +208,6 @@ _X_HIDDEN void *miLookupTab[] = {
 #ifdef RENDER
     SYMFUNC(miGlyphExtents)
 #endif
-#ifdef COMPOSITE
-    SYMFUNC(miDisableCompositeWrapper)
-#endif
 #ifdef DAMAGE
     SYMFUNC(DamageDamageRegion)
 #endif
diff --git a/hw/xfree86/xaa/Makefile.am b/hw/xfree86/xaa/Makefile.am
index 5d529b1..6ed8303 100644
--- a/hw/xfree86/xaa/Makefile.am
+++ b/hw/xfree86/xaa/Makefile.am
@@ -9,6 +9,7 @@ MSB_3_FIXED = mf3-xaaBitmap.c mf3-xaaSti
 POLYSEG = s-xaaLine.c s-xaaDashLine.c
 
 libxaa_la_LDFLAGS = -avoid-version
+libxaa_la_LIBADD = $(top_builddir)/miext/cw/libcw.la
 
 module_LTLIBRARIES = libxaa.la
 libxaa_la_SOURCES = xaaInit.c xaaGC.c xaaInitAccel.c xaaFallback.c \
diff --git a/hw/xfree86/xaa/xaaInit.c b/hw/xfree86/xaa/xaaInit.c
index 1542fc2..79a0e4c 100644
--- a/hw/xfree86/xaa/xaaInit.c
+++ b/hw/xfree86/xaa/xaaInit.c
@@ -227,6 +227,14 @@ XAAInit(ScreenPtr pScreen, XAAInfoRecPtr
     if(infoRec->Flags & MICROSOFT_ZERO_LINE_BIAS)
 	miSetZeroLineBias(pScreen, OCTANT1 | OCTANT2 | OCTANT3 | OCTANT4);
 
+#ifdef COMPOSITE
+    /* Initialize the composite wrapper.  This needs to happen after the
+     * wrapping above (so it comes before us), but before all other extensions,
+     * so it doesn't confuse them. (particularly damage).
+     */
+    miInitializeCompositeWrapper(pScreen);
+#endif
+
     return TRUE;
 }
 
diff --git a/miext/cw/cw.c b/miext/cw/cw.c
index f60f8cf..6950271 100644
--- a/miext/cw/cw.c
+++ b/miext/cw/cw.c
@@ -50,7 +50,6 @@ int cwWindowIndex;
 #ifdef RENDER
 int cwPictureIndex;
 #endif
-static Bool cwDisabled[MAXSCREENS];
 static unsigned long cwGeneration = 0;
 extern GCOps cwGCOps;
 
@@ -619,9 +618,9 @@ void
 miInitializeCompositeWrapper(ScreenPtr pScreen)
 {
     cwScreenPtr pScreenPriv;
-
-    if (cwDisabled[pScreen->myNum])
-	return;
+#ifdef RENDER
+    Bool has_render = GetPictureScreenIfSet(pScreen) != NULL;
+#endif
 
     if (cwGeneration != serverGeneration)
     {
@@ -631,7 +630,8 @@ miInitializeCompositeWrapper(ScreenPtr p
 	cwGCIndex = AllocateGCPrivateIndex();
 	cwWindowIndex = AllocateWindowPrivateIndex();
 #ifdef RENDER
-	cwPictureIndex = AllocatePicturePrivateIndex();
+	if (has_render)
+	    cwPictureIndex = AllocatePicturePrivateIndex();
 #endif
 	cwGeneration = serverGeneration;
     }
@@ -640,8 +640,10 @@ miInitializeCompositeWrapper(ScreenPtr p
     if (!AllocateWindowPrivate(pScreen, cwWindowIndex, 0))
 	return;
 #ifdef RENDER
-    if (!AllocatePicturePrivate(pScreen, cwPictureIndex, 0))
-	return;
+    if (has_render) {
+	if (!AllocatePicturePrivate(pScreen, cwPictureIndex, 0))
+	    return;
+    }
 #endif
     pScreenPriv = (cwScreenPtr)xalloc(sizeof(cwScreenRec));
     if (!pScreenPriv)
@@ -661,17 +663,11 @@ miInitializeCompositeWrapper(ScreenPtr p
     SCREEN_EPILOGUE(pScreen, GetWindowPixmap, cwGetWindowPixmap);
 
 #ifdef RENDER
-    if (GetPictureScreen (pScreen))
+    if (has_render)
 	cwInitializeRender(pScreen);
 #endif
 }
 
-_X_EXPORT void
-miDisableCompositeWrapper(ScreenPtr pScreen)
-{
-    cwDisabled[pScreen->myNum] = TRUE;
-}
-
 static Bool
 cwCloseScreen (int i, ScreenPtr pScreen)
 {
diff --git a/miext/cw/cw.h b/miext/cw/cw.h
index 09cfc78..69abbbf 100644
--- a/miext/cw/cw.h
+++ b/miext/cw/cw.h
@@ -169,7 +169,3 @@ cwFiniRender (ScreenPtr pScreen);
 
 void
 miInitializeCompositeWrapper(ScreenPtr pScreen);
-
-/* Must be called before miInitializeCompositeWrapper */
-void
-miDisableCompositeWrapper(ScreenPtr pScreen);
diff --git a/miext/damage/damage.c b/miext/damage/damage.c
index 6f1ee28..d930747 100755
--- a/miext/damage/damage.c
+++ b/miext/damage/damage.c
@@ -1831,16 +1831,6 @@ DamageSetup (ScreenPtr pScreen)
     if (!pScrPriv)
 	return FALSE;
 
-#ifdef COMPOSITE
-    /* This is a kludge to ensure wrapping order with the composite wrapper.
-     * If it's done from compinit.c, then DamageSetup may be called before the
-     * extension init phase, so that cw will be higher in the wrapping chain and
-     * rewrite drawables before damage gets to it, causing confusion.
-     */
-    if (!noCompositeExtension)
-	miInitializeCompositeWrapper (pScreen);
-#endif
-	
     pScrPriv->internalLevel = 0;
     pScrPriv->pScreenDamage = 0;
 
diff-tree e76b6349516d5d1c8f7167d6f5419e0d06a546c3 (from 6a0bed16e80a91891cee6c7033c90875bc2af193)
Author: Eric Anholt <eric at anholt.net>
Date:   Mon Mar 26 16:04:50 2007 -0700

    Fix indentation of fakexa help text.

diff --git a/hw/kdrive/ephyr/ephyrinit.c b/hw/kdrive/ephyr/ephyrinit.c
index a77b87e..45e2d30 100644
--- a/hw/kdrive/ephyr/ephyrinit.c
+++ b/hw/kdrive/ephyr/ephyrinit.c
@@ -81,7 +81,7 @@ ddxUseMsg (void)
   ErrorF("-host-cursor  Re-use exisiting X host server cursor\n");
   ErrorF("-fullscreen   Attempt to run Xephyr fullscreen\n");
   ErrorF("-grayscale    Simulate 8bit grayscale\n");
-  ErrorF("-fakexa	Simulate acceleration using software rendering\n");
+  ErrorF("-fakexa       Simulate acceleration using software rendering\n");
   ErrorF("\n");
 
   exit(1);
diff-tree 6a0bed16e80a91891cee6c7033c90875bc2af193 (from b8f846a9dfc6697d59ad5482ba7c9d738875318e)
Author: Michel Dänzer <michel at tungstengraphics.com>
Date:   Tue Mar 27 16:51:12 2007 +0200

    Fix typo in GL/mesa/shader/slang/Makefile.am.

diff --git a/GL/mesa/shader/slang/Makefile.am b/GL/mesa/shader/slang/Makefile.am
index 4bd48e9..7f0cd64 100644
--- a/GL/mesa/shader/slang/Makefile.am
+++ b/GL/mesa/shader/slang/Makefile.am
@@ -37,4 +37,4 @@ nodist_libslang_la_SOURCES = slang_built
 		      slang_storage.c \
 		      slang_typeinfo.c \
 		      slang_utility.c \
-		      slang_variable.c
+		      slang_vartable.c
diff-tree b8f846a9dfc6697d59ad5482ba7c9d738875318e (from a63ee90bc2d490f6c5c1802c164391963cf6c1d9)
Author: Dave Airlie <airlied at linux.ie>
Date:   Tue Mar 27 14:17:40 2007 +1000

    gl: oops dodgy s appeared pointed out by jcristau on irc..

diff --git a/GL/mesa/shader/slang/Makefile.am b/GL/mesa/shader/slang/Makefile.am
index 479de63..4bd48e9 100644
--- a/GL/mesa/shader/slang/Makefile.am
+++ b/GL/mesa/shader/slang/Makefile.am
@@ -18,8 +18,7 @@ INCLUDES = -I at MESA_SOURCE@/include \
            -I../.. \
            -I$(top_srcdir)/hw/xfree86/os-support
 
-nodist_libslang_la_SOURCES = s
-		      slang_builtin.c \
+nodist_libslang_la_SOURCES = slang_builtin.c \
 		      slang_codegen.c \
 		      slang_compile.c \
 		      slang_compile_function.c \
diff-tree a63ee90bc2d490f6c5c1802c164391963cf6c1d9 (from d387a3ddf76716791e5e8b8f0954ca0df3c579d6)
Author: Dave Airlie <airlied at pegasus.(none)>
Date:   Tue Mar 27 11:05:52 2007 +1000

    gl: update for latest mesa glsl-compiler merge

diff --git a/GL/mesa/main/Makefile.am b/GL/mesa/main/Makefile.am
index 20b7935..2b838e9 100644
--- a/GL/mesa/main/Makefile.am
+++ b/GL/mesa/main/Makefile.am
@@ -68,6 +68,7 @@ nodist_libmain_la_SOURCES = accum.c \
                     rastpos.c \
                     rbadaptors.c \
                     renderbuffer.c \
+                    shaders.c \
                     state.c \
                     stencil.c \
                     texcompress.c \
diff --git a/GL/mesa/shader/Makefile.am b/GL/mesa/shader/Makefile.am
index 3519545..abde275 100644
--- a/GL/mesa/shader/Makefile.am
+++ b/GL/mesa/shader/Makefile.am
@@ -27,8 +27,13 @@ nodist_libshader_la_SOURCES = \
                       atifragshader.c \
                       nvfragparse.c \
                       nvprogram.c \
-                      nvvertexec.c \
-		      nvvertparse.c \
+                      nvvertparse.c \
+                      prog_debug.c \
+                      prog_execute.c \
+                      prog_instruction.c \
+                      prog_parameter.c \
+                      prog_print.c \
                       program.c \
-                      shaderobjects.c \
-		      shaderobjects_3dlabs.c
+                      programopt.c \
+                      prog_statevars.c \
+                      shader_api.c
diff --git a/GL/mesa/shader/slang/Makefile.am b/GL/mesa/shader/slang/Makefile.am
index 04001c4..479de63 100644
--- a/GL/mesa/shader/slang/Makefile.am
+++ b/GL/mesa/shader/slang/Makefile.am
@@ -18,23 +18,24 @@ INCLUDES = -I at MESA_SOURCE@/include \
            -I../.. \
            -I$(top_srcdir)/hw/xfree86/os-support
 
-nodist_libslang_la_SOURCES = slang_analyse.c \
-		      slang_assemble_assignment.c \
-		      slang_assemble.c \
-		      slang_assemble_conditional.c \
-		      slang_assemble_constructor.c \
-		      slang_assemble_typeinfo.c \
+nodist_libslang_la_SOURCES = s
+		      slang_builtin.c \
+		      slang_codegen.c \
 		      slang_compile.c \
 		      slang_compile_function.c \
 		      slang_compile_operation.c \
 		      slang_compile_struct.c \
 		      slang_compile_variable.c \
-		      slang_execute.c \
-		      slang_execute_x86.c \
-		      slang_export.c \
-		      slang_library_texsample.c \
+		      slang_emit.c \
+		      slang_ir.c \
+		      slang_label.c \
 		      slang_library_noise.c \
 		      slang_link.c \
+		      slang_log.c \
 		      slang_preprocess.c \
+		      slang_print.c \
+		      slang_simplify.c \
 		      slang_storage.c \
-		      slang_utility.c
+		      slang_typeinfo.c \
+		      slang_utility.c \
+		      slang_variable.c
diff --git a/GL/mesa/swrast/Makefile.am b/GL/mesa/swrast/Makefile.am
index 5ed6576..9a6aa92 100644
--- a/GL/mesa/swrast/Makefile.am
+++ b/GL/mesa/swrast/Makefile.am
@@ -23,7 +23,6 @@ nodist_libswrast_la_SOURCES = s_aaline.c
                       s_aatriangle.c \
                       s_accum.c \
                       s_alpha.c \
-                      s_arbshader.c \
                       s_atifragshader.c \
                       s_bitmap.c \
                       s_blend.c \
@@ -39,7 +38,6 @@ nodist_libswrast_la_SOURCES = s_aaline.c
                       s_lines.c \
                       s_logic.c \
                       s_masking.c \
-                      s_nvfragprog.c \
                       s_points.c \
                       s_readpix.c \
                       s_span.c \
diff --git a/GL/mesa/tnl/Makefile.am b/GL/mesa/tnl/Makefile.am
index 5d9bdb1..84301d3 100644
--- a/GL/mesa/tnl/Makefile.am
+++ b/GL/mesa/tnl/Makefile.am
@@ -23,7 +23,6 @@ nodist_libtnl_la_SOURCES = t_context.c \
                       t_pipeline.c \
                       t_vb_arbprogram.c \
                       t_vb_arbprogram_sse.c \
-                      t_vb_arbshader.c \
                       t_vb_cull.c \
                       t_vb_fog.c \
                       t_vb_light.c \
diff-tree d387a3ddf76716791e5e8b8f0954ca0df3c579d6 (from 92ba435bd9aa7b6eca9aef8e5193576ef62fc9db)
Author: Dave Airlie <airlied at pegasus.(none)>
Date:   Tue Mar 27 11:00:13 2007 +1000

    fix loading of GLcore after recent loading changes

diff --git a/hw/xfree86/dixmods/glxmodule.c b/hw/xfree86/dixmods/glxmodule.c
index 401707a..5384f43 100644
--- a/hw/xfree86/dixmods/glxmodule.c
+++ b/hw/xfree86/dixmods/glxmodule.c
@@ -95,8 +95,8 @@ __glXMesaProxyScreenProbe(ScreenPtr pScr
   static __GLXprovider *provider;
 
   if (provider == NULL) {
-    GLcore = LoadSubModuleLocal(glxModule, "GLcore", NULL, NULL, NULL, NULL, 
-				NULL, NULL);
+    GLcore = LoadSubModule(glxModule, "GLcore", NULL, NULL, NULL, NULL, 
+			   NULL, NULL);
     if (GLcore == NULL)
       return NULL;
 
diff-tree 92ba435bd9aa7b6eca9aef8e5193576ef62fc9db (from f7c5aa0dc0fa3569a2ee412c4f996960f936b6ed)
Author: Eric Anholt <eric at anholt.net>
Date:   Mon Mar 26 12:44:58 2007 -0700

    Update xorg.conf manpage for new RandR 1.2 monitor options.

diff --git a/hw/xfree86/doc/man/xorg.conf.man.pre b/hw/xfree86/doc/man/xorg.conf.man.pre
index bbba211..cc60d07 100644
--- a/hw/xfree86/doc/man/xorg.conf.man.pre
+++ b/hw/xfree86/doc/man/xorg.conf.man.pre
@@ -1004,12 +1004,22 @@ The
 .B Identifier
 entry specifies the unique name for this monitor.  The
 .B Monitor
-section provides information about the specifications of the monitor,
-monitor-specific
+section may be used to provide information about the specifications of the
+monitor, monitor-specific
 .BR Options ,
-and information about the video modes to use with the monitor.  Specifying
-video modes is optional because the server now has a built-in list of
-VESA standard modes.  When modes are specified explicitly in the
+and information about the video modes to use with the monitor.
+.PP
+With RandR 1.2-enabled drivers, monitor sections are tied to specific outputs 
+of the video card.  Each output has a name, and the server will look for a
+Monitor named
+.B \*qMonitor-outputname\*q
+for configuration of that output (for example, 
+.B \*qMonitor-VGA\*q
+for a VGA output)
+.PP
+Specifying video modes is optional because the server will use the DDC or other
+information provided by the monitor to automatically configure the list of
+modes available.  When modes are specified explicitly in the
 .B Monitor
 section (with the
 .BR Modes ,
@@ -1017,7 +1027,8 @@ section (with the
 or
 .B UseModes
 keywords), built-in modes with the same names are not included.  Built-in
-modes with different names are, however, still implicitly included.
+modes with different names are, however, still implicitly included, when they
+meet the requirements of the monitor.
 .PP
 The entries that may be used in
 .B Monitor
@@ -1214,6 +1225,62 @@ monitors do not require it.  The default
 This optional entry specifies the vertical refresh rate that the server
 should aim for when selecting video modes.  Without this option, the
 default is to prefer modes with higher refresh rates.
+.TP 7
+.BI "Option " "\*qPreferredMode\*q  " \*qstring\*q
+This optional entry specifies a mode to be marked as the preferred initial mode
+of the monitor.
+(RandR 1.2-supporting drivers only)
+.TP 7
+.BI "Option " "\*qPosition\*q  " "\*qx y\*q"
+This optional entry specifies the position of the monitor within the X
+screen.
+(RandR 1.2-supporting drivers only)
+.TP 7
+.BI "Option " "\*qLeftOf\*q  " \*qmonitor\*q
+This optional entry specifies that the monitor should be positioned to the
+left of the monitor of the given name.
+(RandR 1.2-supporting drivers only)
+.TP 7
+.BI "Option " "\*qRightOf\*q  " \*qmonitor\*q
+This optional entry specifies that the monitor should be positioned to the
+right of the monitor of the given name.
+(RandR 1.2-supporting drivers only)
+.TP 7
+.BI "Option " "\*qAbove\*q  " \*qmonitor\*q
+This optional entry specifies that the monitor should be positioned above the
+monitor of the given name.
+(RandR 1.2-supporting drivers only)
+.TP 7
+.BI "Option " "\*qBelow\*q  " \*qmonitor\*q
+This optional entry specifies that the monitor should be positioned below the
+monitor of the given name.
+(RandR 1.2-supporting drivers only)
+.TP 7
+.BI "Option " "\*qEnable\*q  " \*qbool\*q
+This optional entry specifies whether the monitor should be turned on
+at startup.  By default, the server will attempt to enable all connected
+monitors.
+(RandR 1.2-supporting drivers only)
+.TP 7
+.BI "Option " "\*qMinClock\*q  " \*qfrequency\*q
+This optional entry specifies the minimum dot clock, in kHz, that is supported
+by the monitor.
+.TP 7
+.BI "Option " "\*qMaxClock\*q  " \*qfrequency\*q
+This optional entry specifies the maximum dot clock, in kHz, that is supported
+by the monitor.
+.TP 7
+.BI "Option " "\*qIgnore\*q  " \*qbool\*q
+This optional entry specifies that the monitor should be ignored entirely,
+and not reported through RandR.  This is useful if the hardware reports the
+presence of outputs that don't exist.
+(RandR 1.2-supporting drivers only)
+.TP 7
+.BI "Option " "\*qRotate\*q  " \*qrotation\*q
+This optional entry specifies the initial rotation of the given monitor.
+Valid values for rotation are \*qnormal\*q, \*qleft\*q, \*qright\*q, and
+\*qinverted\*q.
+(RandR 1.2-supporting drivers only)
 
 .SH MODES SECTION
 The config file may have multiple
diff-tree f7c5aa0dc0fa3569a2ee412c4f996960f936b6ed (from 2e3cc861f90415f200826bc71dab6298d759c42b)
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Mar 26 10:21:44 2007 -0400

    Remove dead NEED_DBE_BUF_BITS code.

diff --git a/dbe/dbe.c b/dbe/dbe.c
index 862393b..d63620d 100644
--- a/dbe/dbe.c
+++ b/dbe/dbe.c
@@ -82,36 +82,6 @@ static Bool	firstRegistrationPass = TRUE
 
 /******************************************************************************
  *
- * DBE DIX Procedure: DbeValidateBuffer
- *
- * Description:
- *
- *     This function is called from VALIDATE_DRAWABLE_AND_GC and from
- *     various places in dispatch.c if the server has been compiled with
- *     the flags -DNEED_DBE_BUF_BITS and -DNEED_DBE_BUF_VALIDATE.  
- *     When pWin->dstBuffer changes, this function will be called with pWin
- *     as the first argument, the drawable ID that was specified as the
- *     second argument (could be a back buffer id), and True for the third
- *     argument.
- *     When pWin->srcBuffer changes, the third argument will be False, and
- *     the first two arguments are as described for dstBuffer.
- *
- *     This function should prepare the hardware to access the specified
- *     buffer for reads (if dstbuf is False) or writes (if dstbuf is True).
- *
- *****************************************************************************/
-
-void
-DbeValidateBuffer(WindowPtr pWin, XID drawID, Bool dstbuf)
-{
-    DbeScreenPrivPtr pDbeScreenPriv = DBE_SCREEN_PRIV_FROM_WINDOW(pWin);
-    if (pDbeScreenPriv->ValidateBuffer)
-	(*pDbeScreenPriv->ValidateBuffer)(pWin, drawID, dstbuf);
-}
-
-
-/******************************************************************************
- *
  * DBE DIX Procedure: DbeRegisterFunction
  *
  * Description:
@@ -317,7 +287,6 @@ DbeStubScreen(DbeScreenPrivPtr pDbeScree
     pDbeScreenPriv->EndIdiom            = NULL;
     pDbeScreenPriv->WinPrivDelete       = NULL;
     pDbeScreenPriv->ResetProc           = NULL;
-    pDbeScreenPriv->ValidateBuffer	= NULL;
 
     (*nStubbedScreens)++;
 
diff --git a/dbe/dbestruct.h b/dbe/dbestruct.h
index 460cc75..835074c 100644
--- a/dbe/dbestruct.h
+++ b/dbe/dbestruct.h
@@ -221,11 +221,6 @@ typedef struct _DbeScreenPrivRec
     void	(*ResetProc)(
 		ScreenPtr /*pScreen*/
 );
-    void	(*ValidateBuffer)(
-		WindowPtr /*pWin*/,
-		XID /*bufId*/,
-		Bool /*dstbuffer*/
-);
 
     /* Device-specific private information.
      */
diff --git a/dbe/midbe.c b/dbe/midbe.c
index 76f0577..014e365 100644
--- a/dbe/midbe.c
+++ b/dbe/midbe.c
@@ -759,11 +759,6 @@ miDbeResetProc(ScreenPtr pScreen)
 
 } /* miDbeResetProc() */
 
-static void
-miDbeNopValidateBuffer(WindowPtr pWin, XID bufId, Bool dstbuffer)
-{
-}
-
 
 /******************************************************************************
  *
@@ -821,9 +816,6 @@ miDbeInit(ScreenPtr pScreen, DbeScreenPr
     pDbeScreenPriv->ResetProc             = miDbeResetProc;
     pDbeScreenPriv->WinPrivDelete         = miDbeWinPrivDelete;
 
-    /* The mi implementation doesn't need buffer validation. */
-    pDbeScreenPriv->ValidateBuffer	  = miDbeNopValidateBuffer;
-
     return(TRUE);
 
 } /* miDbeInit() */
diff --git a/dix/dispatch.c b/dix/dispatch.c
index 3d8e71f..490b29c 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -1803,8 +1803,6 @@ ProcCopyArea(ClientPtr client)
     else
         pSrc = pDst;
 
-    SET_DBE_SRCBUF(pSrc, stuff->srcDrawable);
-
     pRgn = (*pGC->ops->CopyArea)(pSrc, pDst, pGC, stuff->srcX, stuff->srcY,
 				 stuff->width, stuff->height, 
 				 stuff->dstX, stuff->dstY);
@@ -1847,8 +1845,6 @@ ProcCopyPlane(ClientPtr client)
     else
         psrcDraw = pdstDraw;
 
-    SET_DBE_SRCBUF(psrcDraw, stuff->srcDrawable);
-
     /* Check to see if stuff->bitPlane has exactly ONE good bit set */
     if(stuff->bitPlane == 0 || (stuff->bitPlane & (stuff->bitPlane - 1)) ||
        (stuff->bitPlane > (1L << (psrcDraw->depth - 1))))
@@ -2208,8 +2204,6 @@ DoGetImage(ClientPtr client, int format,
 	xgi.visual = None;
     }
 
-    SET_DBE_SRCBUF(pDraw, drawable);
-
     xgi.type = X_Reply;
     xgi.sequenceNumber = client->sequence;
     xgi.depth = pDraw->depth;
diff --git a/dix/window.c b/dix/window.c
index 7d99477..96002eb 100644
--- a/dix/window.c
+++ b/dix/window.c
@@ -297,10 +297,6 @@ SetWindowToDefaults(WindowPtr pWin)
     pWin->deliverableEvents = 0;
     pWin->dontPropagate = 0;
     pWin->forcedBS = FALSE;
-#ifdef NEED_DBE_BUF_BITS
-    pWin->srcBuffer = DBE_FRONT_BUFFER;
-    pWin->dstBuffer = DBE_FRONT_BUFFER;
-#endif
 #ifdef COMPOSITE
     pWin->redirectDraw = 0;
 #endif
diff --git a/include/dix.h b/include/dix.h
index b412683..2d452d1 100644
--- a/include/dix.h
+++ b/include/dix.h
@@ -81,59 +81,6 @@ SOFTWARE.
         return(BadIDChoice);\
     }
 
-/*
- * We think that most hardware implementations of DBE will want
- * LookupID*(dbe_back_buffer_id) to return the window structure that the
- * id is a back buffer for.  Since both front and back buffers will
- * return the same structure, you need to be able to distinguish
- * somewhere what kind of buffer (front/back) was being asked for, so
- * that ddx can render to the right place.  That's the problem that the
- * following code solves.  Note: we couldn't embed this in the LookupID*
- * functions because the VALIDATE_DRAWABLE_AND_GC macro often circumvents
- * those functions by checking a one-element cache.  That's why we're
- * mucking with VALIDATE_DRAWABLE_AND_GC.
- * 
- * If you put -DNEED_DBE_BUF_BITS into PervasiveDBEDefines, the window
- * structure will have two additional bits defined, srcBuffer and
- * dstBuffer, and their values will be maintained via the macros
- * SET_DBE_DSTBUF and SET_DBE_SRCBUF (below).  If you also
- * put -DNEED_DBE_BUF_VALIDATE into PervasiveDBEDefines, the function
- * DbeValidateBuffer will be called any time the bits change to give you
- * a chance to do some setup.  See the DBE code for more details on this
- * function.  We put in these levels of conditionality so that you can do
- * just what you need to do, and no more.  If neither of these defines
- * are used, the bits won't be there, and VALIDATE_DRAWABLE_AND_GC will
- * be unchanged.	dpw
- */
-
-#if defined(NEED_DBE_BUF_BITS)
-#define SET_DBE_DSTBUF(_pDraw, _drawID) \
-        SET_DBE_BUF(_pDraw, _drawID, dstBuffer, TRUE)
-#define SET_DBE_SRCBUF(_pDraw, _drawID) \
-        SET_DBE_BUF(_pDraw, _drawID, srcBuffer, FALSE)
-#if defined (NEED_DBE_BUF_VALIDATE)
-#define SET_DBE_BUF(_pDraw, _drawID, _whichBuffer, _dstbuf) \
-    if (_pDraw->type == DRAWABLE_WINDOW)\
-    {\
-	int thisbuf = (_pDraw->id == _drawID);\
-	if (thisbuf != ((WindowPtr)_pDraw)->_whichBuffer)\
-	{\
-	     ((WindowPtr)_pDraw)->_whichBuffer = thisbuf;\
-	     DbeValidateBuffer((WindowPtr)_pDraw, _drawID, _dstbuf);\
-	}\
-     }
-#else /* want buffer bits, but don't need to call DbeValidateBuffer */
-#define SET_DBE_BUF(_pDraw, _drawID, _whichBuffer, _dstbuf) \
-    if (_pDraw->type == DRAWABLE_WINDOW)\
-    {\
-	((WindowPtr)_pDraw)->_whichBuffer = (_pDraw->id == _drawID);\
-    }
-#endif /* NEED_DBE_BUF_VALIDATE */
-#else /* don't want buffer bits in window */
-#define SET_DBE_DSTBUF(_pDraw, _drawID) /**/
-#define SET_DBE_SRCBUF(_pDraw, _drawID) /**/
-#endif /* NEED_DBE_BUF_BITS */
-
 #define VALIDATE_DRAWABLE_AND_GC(drawID, pDraw, pGC, client)\
     if ((stuff->gc == INVALID) || (client->lastGCID != stuff->gc) ||\
 	(client->lastDrawableID != drawID))\
@@ -158,7 +105,6 @@ SOFTWARE.
         pGC = client->lastGC;\
         pDraw = client->lastDrawable;\
     }\
-    SET_DBE_DSTBUF(pDraw, drawID);\
     if (pGC->serialNumber != pDraw->serialNumber)\
 	ValidateGC(pDraw, pGC);
 
diff --git a/include/windowstr.h b/include/windowstr.h
index a37dc6b..9fd6d76 100644
--- a/include/windowstr.h
+++ b/include/windowstr.h
@@ -129,12 +129,6 @@ typedef struct _Window {
     unsigned		viewable:1;	/* realized && InputOutput */
     unsigned		dontPropagate:3;/* index into DontPropagateMasks */
     unsigned		forcedBS:1;	/* system-supplied backingStore */
-#ifdef NEED_DBE_BUF_BITS
-#define DBE_FRONT_BUFFER 1
-#define DBE_BACK_BUFFER  0
-    unsigned		dstBuffer:1;	/* destination buffer for rendering */
-    unsigned		srcBuffer:1;	/* source buffer for rendering */
-#endif
 #ifdef COMPOSITE
     unsigned		redirectDraw:1;	/* rendering is redirected from here */
 #endif
diff-tree 2e3cc861f90415f200826bc71dab6298d759c42b (from e88fa75c9b468b88bb7b87b1da235c6eb2fe8164)
Author: Adam Jackson <ajax at benzedrine.nwnk.net>
Date:   Sun Mar 25 22:01:34 2007 -0400

    Since ddc, i2c, and ramdac are in core now, remove their ModuleData stubs.

diff --git a/hw/xfree86/ddc/xf86DDC.c b/hw/xfree86/ddc/xf86DDC.c
index 8080c8d..21984bc 100644
--- a/hw/xfree86/ddc/xf86DDC.c
+++ b/hw/xfree86/ddc/xf86DDC.c
@@ -15,52 +15,6 @@
 
 static const OptionInfoRec *DDCAvailableOptions(void *unused);
 
-#if DDC_MODULE
-
-static MODULESETUPPROTO(ddcSetup);
-
-static XF86ModuleVersionInfo ddcVersRec =
-{
-    "ddc",
-    MODULEVENDORSTRING,
-    MODINFOSTRING1,
-    MODINFOSTRING2,
-    XORG_VERSION_CURRENT,
-    1, 0, 0,
-    ABI_CLASS_VIDEODRV,		/* needs the video driver ABI */
-    ABI_VIDEODRV_VERSION,
-    MOD_CLASS_NONE,
-    {0,0,0,0}
-};
-
-_X_EXPORT XF86ModuleData ddcModuleData = { &ddcVersRec, ddcSetup, NULL };
-
-ModuleInfoRec DDC = {
-    1,
-    "DDC",
-    NULL,
-    0,
-    DDCAvailableOptions,
-};
-
-static pointer
-ddcSetup(pointer module, pointer opts, int *errmaj, int *errmin)
-{
-    static Bool setupDone = FALSE;
-
-    if (!setupDone) {
-	setupDone = TRUE;
-	xf86AddModuleInfo(&DDC, module);
-    } 
-    /*
-     * The return value must be non-NULL on success even though there
-     * is no TearDownProc.
-     */
-    return (pointer)1;
-}
-
-#endif
-
 #define RETRIES 4
 
 static unsigned char *EDIDRead_DDC1(
diff --git a/hw/xfree86/i2c/xf86i2cmodule.c b/hw/xfree86/i2c/xf86i2cmodule.c
deleted file mode 100644
index 3c6d313..0000000
--- a/hw/xfree86/i2c/xf86i2cmodule.c
+++ /dev/null
@@ -1,36 +0,0 @@
-/* (c) Itai Nahshon
- *
- * This code is derived from and inspired by the I2C driver
- * from the Linux kernel.
- *      (c) 1998 Gerd Knorr <kraxel at cs.tu-berlin.de>
- */
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include "xf86Module.h"
-
-static MODULESETUPPROTO(i2cSetup);
-
-static XF86ModuleVersionInfo i2cVersRec =
-{
-        "i2c",
-        MODULEVENDORSTRING,
-        MODINFOSTRING1,
-        MODINFOSTRING2,
-        XORG_VERSION_CURRENT,
-        1, 2, 0,
-        ABI_CLASS_VIDEODRV,		/* This needs the video driver ABI */
-        ABI_VIDEODRV_VERSION,
-        MOD_CLASS_NONE,
-        {0,0,0,0}
-};
-
-_X_EXPORT XF86ModuleData i2cModuleData = { &i2cVersRec, i2cSetup, NULL };
-
-static pointer
-i2cSetup(pointer module, pointer opts, int *errmaj, int *errmin) {
-/* ErrorF("i2cSetup\n"); */
-   return (pointer)1;
-}
diff --git a/hw/xfree86/ramdac/xf86RamDacMod.c b/hw/xfree86/ramdac/xf86RamDacMod.c
deleted file mode 100644
index b4187a9..0000000
--- a/hw/xfree86/ramdac/xf86RamDacMod.c
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright 1998 by Alan Hourihane, Wigan, England.
- *
- * Permission to use, copy, modify, distribute, and sell this software and its
- * documentation for any purpose is hereby granted without fee, provided that
- * the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of Alan Hourihane not be used in
- * advertising or publicity pertaining to distribution of the software without
- * specific, written prior permission.  Alan Hourihane makes no representations
- * about the suitability of this software for any purpose.  It is provided
- * "as is" without express or implied warranty.
- *
- * ALAN HOURIHANE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- * EVENT SHALL ALAN HOURIHANE BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- * PERFORMANCE OF THIS SOFTWARE.
- *
- * Authors:  Alan Hourihane, <alanh at fairlite.demon.co.uk>
- *
- * Generic RAMDAC module.
- */
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include "xf86Module.h"
-
-static XF86ModuleVersionInfo VersRec = {
-	"ramdac",
-	MODULEVENDORSTRING,
-	MODINFOSTRING1,
-	MODINFOSTRING2,
-	XORG_VERSION_CURRENT,
-	0, 1, 0,
-	ABI_CLASS_VIDEODRV,
-	ABI_VIDEODRV_VERSION,
-	MOD_CLASS_NONE,
-	{0, 0, 0, 0}
-};
-
-_X_EXPORT XF86ModuleData ramdacModuleData = { &VersRec, NULL, NULL };
diff-tree e88fa75c9b468b88bb7b87b1da235c6eb2fe8164 (from 4b5802ddbd45271be3cadeae0a83a6742df2515b)
Author: Adam Jackson <ajax at benzedrine.nwnk.net>
Date:   Sun Mar 18 17:39:08 2007 -0400

    Static cleanup on Xi/

diff --git a/Xi/chgfctl.c b/Xi/chgfctl.c
index d0acc59..82616c6 100644
--- a/Xi/chgfctl.c
+++ b/Xi/chgfctl.c
@@ -89,137 +89,13 @@ SProcXChangeFeedbackControl(register Cli
     return (ProcXChangeFeedbackControl(client));
 }
 
-/***********************************************************************
- *
- * Change the control attributes.
- *
- */
-
-int
-ProcXChangeFeedbackControl(ClientPtr client)
-{
-    unsigned len;
-    DeviceIntPtr dev;
-    KbdFeedbackPtr k;
-    PtrFeedbackPtr p;
-    IntegerFeedbackPtr i;
-    StringFeedbackPtr s;
-    BellFeedbackPtr b;
-    LedFeedbackPtr l;
-
-    REQUEST(xChangeFeedbackControlReq);
-    REQUEST_AT_LEAST_SIZE(xChangeFeedbackControlReq);
-
-    len = stuff->length - (sizeof(xChangeFeedbackControlReq) >> 2);
-    dev = LookupDeviceIntRec(stuff->deviceid);
-    if (dev == NULL) {
-	SendErrorToClient(client, IReqCode, X_ChangeFeedbackControl, 0,
-			  BadDevice);
-	return Success;
-    }
-
-    switch (stuff->feedbackid) {
-    case KbdFeedbackClass:
-	if (len != (sizeof(xKbdFeedbackCtl) >> 2)) {
-	    SendErrorToClient(client, IReqCode, X_ChangeFeedbackControl,
-			      0, BadLength);
-	    return Success;
-	}
-	for (k = dev->kbdfeed; k; k = k->next)
-	    if (k->ctrl.id == ((xKbdFeedbackCtl *) & stuff[1])->id) {
-		ChangeKbdFeedback(client, dev, stuff->mask, k,
-				  (xKbdFeedbackCtl *) & stuff[1]);
-		return Success;
-	    }
-	break;
-    case PtrFeedbackClass:
-	if (len != (sizeof(xPtrFeedbackCtl) >> 2)) {
-	    SendErrorToClient(client, IReqCode, X_ChangeFeedbackControl,
-			      0, BadLength);
-	    return Success;
-	}
-	for (p = dev->ptrfeed; p; p = p->next)
-	    if (p->ctrl.id == ((xPtrFeedbackCtl *) & stuff[1])->id) {
-		ChangePtrFeedback(client, dev, stuff->mask, p,
-				  (xPtrFeedbackCtl *) & stuff[1]);
-		return Success;
-	    }
-	break;
-    case StringFeedbackClass:
-    {
-	register char n;
-	xStringFeedbackCtl *f = ((xStringFeedbackCtl *) & stuff[1]);
-
-	if (client->swapped) {
-	    swaps(&f->num_keysyms, n);
-	}
-	if (len != ((sizeof(xStringFeedbackCtl) >> 2) + f->num_keysyms)) {
-	    SendErrorToClient(client, IReqCode, X_ChangeFeedbackControl,
-			      0, BadLength);
-	    return Success;
-	}
-	for (s = dev->stringfeed; s; s = s->next)
-	    if (s->ctrl.id == ((xStringFeedbackCtl *) & stuff[1])->id) {
-		ChangeStringFeedback(client, dev, stuff->mask, s,
-				     (xStringFeedbackCtl *) & stuff[1]);
-		return Success;
-	    }
-	break;
-    }
-    case IntegerFeedbackClass:
-	if (len != (sizeof(xIntegerFeedbackCtl) >> 2)) {
-	    SendErrorToClient(client, IReqCode, X_ChangeFeedbackControl,
-			      0, BadLength);
-	    return Success;
-	}
-	for (i = dev->intfeed; i; i = i->next)
-	    if (i->ctrl.id == ((xIntegerFeedbackCtl *) & stuff[1])->id) {
-		ChangeIntegerFeedback(client, dev, stuff->mask, i,
-				      (xIntegerFeedbackCtl *) & stuff[1]);
-		return Success;
-	    }
-	break;
-    case LedFeedbackClass:
-	if (len != (sizeof(xLedFeedbackCtl) >> 2)) {
-	    SendErrorToClient(client, IReqCode, X_ChangeFeedbackControl,
-			      0, BadLength);
-	    return Success;
-	}
-	for (l = dev->leds; l; l = l->next)
-	    if (l->ctrl.id == ((xLedFeedbackCtl *) & stuff[1])->id) {
-		ChangeLedFeedback(client, dev, stuff->mask, l,
-				  (xLedFeedbackCtl *) & stuff[1]);
-		return Success;
-	    }
-	break;
-    case BellFeedbackClass:
-	if (len != (sizeof(xBellFeedbackCtl) >> 2)) {
-	    SendErrorToClient(client, IReqCode, X_ChangeFeedbackControl,
-			      0, BadLength);
-	    return Success;
-	}
-	for (b = dev->bell; b; b = b->next)
-	    if (b->ctrl.id == ((xBellFeedbackCtl *) & stuff[1])->id) {
-		ChangeBellFeedback(client, dev, stuff->mask, b,
-				   (xBellFeedbackCtl *) & stuff[1]);
-		return Success;
-	    }
-	break;
-    default:
-	break;
-    }
-
-    SendErrorToClient(client, IReqCode, X_ChangeFeedbackControl, 0, BadMatch);
-    return Success;
-}
-
 /******************************************************************************
  *
  * This procedure changes KbdFeedbackClass data.
  *
  */
 
-int
+static int
 ChangeKbdFeedback(ClientPtr client, DeviceIntPtr dev, long unsigned int mask,
 		  KbdFeedbackPtr k, xKbdFeedbackCtl * f)
 {
@@ -351,7 +227,7 @@ ChangeKbdFeedback(ClientPtr client, Devi
  *
  */
 
-int
+static int
 ChangePtrFeedback(ClientPtr client, DeviceIntPtr dev, long unsigned int mask,
 		  PtrFeedbackPtr p, xPtrFeedbackCtl * f)
 {
@@ -422,7 +298,7 @@ ChangePtrFeedback(ClientPtr client, Devi
  *
  */
 
-int
+static int
 ChangeIntegerFeedback(ClientPtr client, DeviceIntPtr dev,
 		      long unsigned int mask, IntegerFeedbackPtr i,
 		      xIntegerFeedbackCtl * f)
@@ -445,7 +321,7 @@ ChangeIntegerFeedback(ClientPtr client, 
  *
  */
 
-int
+static int
 ChangeStringFeedback(ClientPtr client, DeviceIntPtr dev,
 		     long unsigned int mask, StringFeedbackPtr s,
 		     xStringFeedbackCtl * f)
@@ -495,7 +371,7 @@ ChangeStringFeedback(ClientPtr client, D
  *
  */
 
-int
+static int
 ChangeBellFeedback(ClientPtr client, DeviceIntPtr dev,
 		   long unsigned int mask, BellFeedbackPtr b,
 		   xBellFeedbackCtl * f)
@@ -560,7 +436,7 @@ ChangeBellFeedback(ClientPtr client, Dev
  *
  */
 
-int
+static int
 ChangeLedFeedback(ClientPtr client, DeviceIntPtr dev, long unsigned int mask,
 		  LedFeedbackPtr l, xLedFeedbackCtl * f)
 {
@@ -585,3 +461,128 @@ ChangeLedFeedback(ClientPtr client, Devi
 
     return Success;
 }
+
+/***********************************************************************
+ *
+ * Change the control attributes.
+ *
+ */
+
+int
+ProcXChangeFeedbackControl(ClientPtr client)
+{
+    unsigned len;
+    DeviceIntPtr dev;
+    KbdFeedbackPtr k;
+    PtrFeedbackPtr p;
+    IntegerFeedbackPtr i;
+    StringFeedbackPtr s;
+    BellFeedbackPtr b;
+    LedFeedbackPtr l;
+
+    REQUEST(xChangeFeedbackControlReq);
+    REQUEST_AT_LEAST_SIZE(xChangeFeedbackControlReq);
+
+    len = stuff->length - (sizeof(xChangeFeedbackControlReq) >> 2);
+    dev = LookupDeviceIntRec(stuff->deviceid);
+    if (dev == NULL) {
+	SendErrorToClient(client, IReqCode, X_ChangeFeedbackControl, 0,
+			  BadDevice);
+	return Success;
+    }
+
+    switch (stuff->feedbackid) {
+    case KbdFeedbackClass:
+	if (len != (sizeof(xKbdFeedbackCtl) >> 2)) {
+	    SendErrorToClient(client, IReqCode, X_ChangeFeedbackControl,
+			      0, BadLength);
+	    return Success;
+	}
+	for (k = dev->kbdfeed; k; k = k->next)
+	    if (k->ctrl.id == ((xKbdFeedbackCtl *) & stuff[1])->id) {
+		ChangeKbdFeedback(client, dev, stuff->mask, k,
+				  (xKbdFeedbackCtl *) & stuff[1]);
+		return Success;
+	    }
+	break;
+    case PtrFeedbackClass:
+	if (len != (sizeof(xPtrFeedbackCtl) >> 2)) {
+	    SendErrorToClient(client, IReqCode, X_ChangeFeedbackControl,
+			      0, BadLength);
+	    return Success;
+	}
+	for (p = dev->ptrfeed; p; p = p->next)
+	    if (p->ctrl.id == ((xPtrFeedbackCtl *) & stuff[1])->id) {
+		ChangePtrFeedback(client, dev, stuff->mask, p,
+				  (xPtrFeedbackCtl *) & stuff[1]);
+		return Success;
+	    }
+	break;
+    case StringFeedbackClass:
+    {
+	register char n;
+	xStringFeedbackCtl *f = ((xStringFeedbackCtl *) & stuff[1]);
+
+	if (client->swapped) {
+	    swaps(&f->num_keysyms, n);
+	}
+	if (len != ((sizeof(xStringFeedbackCtl) >> 2) + f->num_keysyms)) {
+	    SendErrorToClient(client, IReqCode, X_ChangeFeedbackControl,
+			      0, BadLength);
+	    return Success;
+	}
+	for (s = dev->stringfeed; s; s = s->next)
+	    if (s->ctrl.id == ((xStringFeedbackCtl *) & stuff[1])->id) {
+		ChangeStringFeedback(client, dev, stuff->mask, s,
+				     (xStringFeedbackCtl *) & stuff[1]);
+		return Success;
+	    }
+	break;
+    }
+    case IntegerFeedbackClass:
+	if (len != (sizeof(xIntegerFeedbackCtl) >> 2)) {
+	    SendErrorToClient(client, IReqCode, X_ChangeFeedbackControl,
+			      0, BadLength);
+	    return Success;
+	}
+	for (i = dev->intfeed; i; i = i->next)
+	    if (i->ctrl.id == ((xIntegerFeedbackCtl *) & stuff[1])->id) {
+		ChangeIntegerFeedback(client, dev, stuff->mask, i,
+				      (xIntegerFeedbackCtl *) & stuff[1]);
+		return Success;
+	    }
+	break;
+    case LedFeedbackClass:
+	if (len != (sizeof(xLedFeedbackCtl) >> 2)) {
+	    SendErrorToClient(client, IReqCode, X_ChangeFeedbackControl,
+			      0, BadLength);
+	    return Success;
+	}
+	for (l = dev->leds; l; l = l->next)
+	    if (l->ctrl.id == ((xLedFeedbackCtl *) & stuff[1])->id) {
+		ChangeLedFeedback(client, dev, stuff->mask, l,
+				  (xLedFeedbackCtl *) & stuff[1]);
+		return Success;
+	    }
+	break;
+    case BellFeedbackClass:
+	if (len != (sizeof(xBellFeedbackCtl) >> 2)) {
+	    SendErrorToClient(client, IReqCode, X_ChangeFeedbackControl,
+			      0, BadLength);
+	    return Success;
+	}
+	for (b = dev->bell; b; b = b->next)
+	    if (b->ctrl.id == ((xBellFeedbackCtl *) & stuff[1])->id) {
+		ChangeBellFeedback(client, dev, stuff->mask, b,
+				   (xBellFeedbackCtl *) & stuff[1]);
+		return Success;
+	    }
+	break;
+    default:
+	break;
+    }
+
+    SendErrorToClient(client, IReqCode, X_ChangeFeedbackControl, 0, BadMatch);
+    return Success;
+}
+
diff --git a/Xi/chgfctl.h b/Xi/chgfctl.h
index 81e1153..cfa9fc6 100644
--- a/Xi/chgfctl.h
+++ b/Xi/chgfctl.h
@@ -36,46 +36,4 @@ int SProcXChangeFeedbackControl(ClientPt
 int ProcXChangeFeedbackControl(ClientPtr	/* client */
     );
 
-int ChangeKbdFeedback(ClientPtr /* client */ ,
-		      DeviceIntPtr /* dev */ ,
-		      unsigned long /* mask */ ,
-		      KbdFeedbackPtr /* k */ ,
-		      xKbdFeedbackCtl *	/* f */
-    );
-
-int ChangePtrFeedback(ClientPtr /* client */ ,
-		      DeviceIntPtr /* dev */ ,
-		      unsigned long /* mask */ ,
-		      PtrFeedbackPtr /* p */ ,
-		      xPtrFeedbackCtl *	/* f */
-    );
-
-int ChangeIntegerFeedback(ClientPtr /* client */ ,
-			  DeviceIntPtr /* dev */ ,
-			  unsigned long /* mask */ ,
-			  IntegerFeedbackPtr /* i */ ,
-			  xIntegerFeedbackCtl *	/* f */
-    );
-
-int ChangeStringFeedback(ClientPtr /* client */ ,
-			 DeviceIntPtr /* dev */ ,
-			 unsigned long /* mask */ ,
-			 StringFeedbackPtr /* s */ ,
-			 xStringFeedbackCtl *	/* f */
-    );
-
-int ChangeBellFeedback(ClientPtr /* client */ ,
-		       DeviceIntPtr /* dev */ ,
-		       unsigned long /* mask */ ,
-		       BellFeedbackPtr /* b */ ,
-		       xBellFeedbackCtl *	/* f */
-    );
-
-int ChangeLedFeedback(ClientPtr /* client */ ,
-		      DeviceIntPtr /* dev */ ,
-		      unsigned long /* mask */ ,
-		      LedFeedbackPtr /* l */ ,
-		      xLedFeedbackCtl *	/* f */
-    );
-
 #endif /* CHGFCTL_H */
diff --git a/Xi/chgptr.h b/Xi/chgptr.h
index fb3b5cc..2d8ab66 100644
--- a/Xi/chgptr.h
+++ b/Xi/chgptr.h
@@ -45,12 +45,4 @@ void SendEventToAllWindows(DeviceIntPtr 
 			   int	/* count */
     );
 
-void FindInterestedChildren(	/* FIXME: could be static? */
-			       DeviceIntPtr /* dev */ ,
-			       WindowPtr /* p1 */ ,
-			       Mask /* mask */ ,
-			       xEvent * /* ev */ ,
-			       int	/* count */
-    );
-
 #endif /* CHGPTR_H */
diff --git a/Xi/closedev.c b/Xi/closedev.c
index cc83e6a..3d47b5f 100644
--- a/Xi/closedev.c
+++ b/Xi/closedev.c
@@ -89,42 +89,29 @@ SProcXCloseDevice(register ClientPtr cli
 
 /***********************************************************************
  *
- * This procedure closes an input device.
+ * Clear out event selections and passive grabs from a window for the
+ * specified device.
  *
  */
 
-int
-ProcXCloseDevice(register ClientPtr client)
+static void
+DeleteDeviceEvents(DeviceIntPtr dev, WindowPtr pWin, ClientPtr client)
 {
-    int i;
-    WindowPtr pWin, p1;
-    DeviceIntPtr d;
-
-    REQUEST(xCloseDeviceReq);
-    REQUEST_SIZE_MATCH(xCloseDeviceReq);
-
-    d = LookupDeviceIntRec(stuff->deviceid);
-    if (d == NULL) {
-	SendErrorToClient(client, IReqCode, X_CloseDevice, 0, BadDevice);
-	return Success;
-    }
-
-    if (d->grab && SameClient(d->grab, client))
-	(*d->DeactivateGrab) (d);	/* release active grab */
+    InputClientsPtr others;
+    OtherInputMasks *pOthers;
+    GrabPtr grab, next;
 
-    /* Remove event selections from all windows for events from this device 
-     * and selected by this client.
-     * Delete passive grabs from all windows for this device.      */
+    if ((pOthers = wOtherInputMasks(pWin)) != 0)
+	for (others = pOthers->inputClients; others; others = others->next)
+	    if (SameClient(others, client))
+		others->mask[dev->id] = NoEventMask;
 
-    for (i = 0; i < screenInfo.numScreens; i++) {
-	pWin = WindowTable[i];
-	DeleteDeviceEvents(d, pWin, client);
-	p1 = pWin->firstChild;
-	DeleteEventsFromChildren(d, p1, client);
+    for (grab = wPassiveGrabs(pWin); grab; grab = next) {
+	next = grab->next;
+	if ((grab->device == dev) &&
+	    (client->clientAsMask == CLIENT_BITS(grab->resource)))
+	    FreeResource(grab->resource, RT_NONE);
     }
-
-    CloseInputDevice(d, client);
-    return Success;
 }
 
 /***********************************************************************
@@ -134,7 +121,7 @@ ProcXCloseDevice(register ClientPtr clie
  *
  */
 
-void
+static void
 DeleteEventsFromChildren(DeviceIntPtr dev, WindowPtr p1, ClientPtr client)
 {
     WindowPtr p2;
@@ -149,27 +136,40 @@ DeleteEventsFromChildren(DeviceIntPtr de
 
 /***********************************************************************
  *
- * Clear out event selections and passive grabs from a window for the
- * specified device.
+ * This procedure closes an input device.
  *
  */
 
-void
-DeleteDeviceEvents(DeviceIntPtr dev, WindowPtr pWin, ClientPtr client)
+int
+ProcXCloseDevice(register ClientPtr client)
 {
-    InputClientsPtr others;
-    OtherInputMasks *pOthers;
-    GrabPtr grab, next;
+    int i;
+    WindowPtr pWin, p1;
+    DeviceIntPtr d;
 
-    if ((pOthers = wOtherInputMasks(pWin)) != 0)
-	for (others = pOthers->inputClients; others; others = others->next)
-	    if (SameClient(others, client))
-		others->mask[dev->id] = NoEventMask;
+    REQUEST(xCloseDeviceReq);
+    REQUEST_SIZE_MATCH(xCloseDeviceReq);
 
-    for (grab = wPassiveGrabs(pWin); grab; grab = next) {
-	next = grab->next;
-	if ((grab->device == dev) &&
-	    (client->clientAsMask == CLIENT_BITS(grab->resource)))
-	    FreeResource(grab->resource, RT_NONE);
+    d = LookupDeviceIntRec(stuff->deviceid);
+    if (d == NULL) {
+	SendErrorToClient(client, IReqCode, X_CloseDevice, 0, BadDevice);
+	return Success;
+    }
+
+    if (d->grab && SameClient(d->grab, client))
+	(*d->DeactivateGrab) (d);	/* release active grab */
+
+    /* Remove event selections from all windows for events from this device 
+     * and selected by this client.
+     * Delete passive grabs from all windows for this device.      */
+
+    for (i = 0; i < screenInfo.numScreens; i++) {
+	pWin = WindowTable[i];
+	DeleteDeviceEvents(d, pWin, client);
+	p1 = pWin->firstChild;
+	DeleteEventsFromChildren(d, p1, client);
     }
+
+    CloseInputDevice(d, client);
+    return Success;
 }
diff --git a/Xi/closedev.h b/Xi/closedev.h
index 6853d50..400aaa6 100644
--- a/Xi/closedev.h
+++ b/Xi/closedev.h
@@ -36,14 +36,4 @@ int SProcXCloseDevice(ClientPtr	/* clien
 int ProcXCloseDevice(ClientPtr	/* client */
     );
 
-void DeleteEventsFromChildren(DeviceIntPtr /* dev */ ,
-			      WindowPtr /* p1 */ ,
-			      ClientPtr	/* client */
-    );
-
-void DeleteDeviceEvents(DeviceIntPtr /* dev */ ,
-			WindowPtr /* pWin */ ,
-			ClientPtr	/* client */
-    );
-
 #endif /* CLOSEDEV_H */
diff --git a/Xi/exevents.c b/Xi/exevents.c
index b7645f4..164fce3 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -994,33 +994,7 @@ ChangeKeyMapping(ClientPtr client,
     return client->noClientException;
 }
 
-void
-DeleteWindowFromAnyExtEvents(WindowPtr pWin, Bool freeResources)
-{
-    int i;
-    DeviceIntPtr dev;
-    InputClientsPtr ic;
-    struct _OtherInputMasks *inputMasks;
-
-    for (dev = inputInfo.devices; dev; dev = dev->next) {
-	if (dev == inputInfo.pointer || dev == inputInfo.keyboard)
-	    continue;
-	DeleteDeviceFromAnyExtEvents(pWin, dev);
-    }
-
-    for (dev = inputInfo.off_devices; dev; dev = dev->next)
-	DeleteDeviceFromAnyExtEvents(pWin, dev);
-
-    if (freeResources)
-	while ((inputMasks = wOtherInputMasks(pWin)) != 0) {
-	    ic = inputMasks->inputClients;
-	    for (i = 0; i < EMASKSIZE; i++)
-		inputMasks->dontPropagateMask[i] = 0;
-	    FreeResource(ic->resource, RT_NONE);
-	}
-}
-
-void
+static void
 DeleteDeviceFromAnyExtEvents(WindowPtr pWin, DeviceIntPtr dev)
 {
     WindowPtr parent;
@@ -1085,6 +1059,32 @@ DeleteDeviceFromAnyExtEvents(WindowPtr p
 	    dev->valuator->motionHintWindow = NullWindow;
 }
 
+void
+DeleteWindowFromAnyExtEvents(WindowPtr pWin, Bool freeResources)
+{
+    int i;
+    DeviceIntPtr dev;
+    InputClientsPtr ic;
+    struct _OtherInputMasks *inputMasks;
+
+    for (dev = inputInfo.devices; dev; dev = dev->next) {
+	if (dev == inputInfo.pointer || dev == inputInfo.keyboard)
+	    continue;
+	DeleteDeviceFromAnyExtEvents(pWin, dev);
+    }
+
+    for (dev = inputInfo.off_devices; dev; dev = dev->next)
+	DeleteDeviceFromAnyExtEvents(pWin, dev);
+
+    if (freeResources)
+	while ((inputMasks = wOtherInputMasks(pWin)) != 0) {
+	    ic = inputMasks->inputClients;
+	    for (i = 0; i < EMASKSIZE; i++)
+		inputMasks->dontPropagateMask[i] = 0;
+	    FreeResource(ic->resource, RT_NONE);
+	}
+}
+
 int
 MaybeSendDeviceMotionNotifyHint(deviceKeyButtonPointer * pEvents, Mask mask)
 {
@@ -1138,7 +1138,7 @@ CheckDeviceGrabAndHintWindow(WindowPtr p
     }
 }
 
-Mask
+static Mask
 DeviceEventMaskForClient(DeviceIntPtr dev, WindowPtr pWin, ClientPtr client)
 {
     register InputClientsPtr other;
@@ -1223,7 +1223,7 @@ ShouldFreeInputMasks(WindowPtr pWin, Boo
  *
  */
 
-void
+static void
 FindInterestedChildren(DeviceIntPtr dev, WindowPtr p1, Mask mask,
                        xEvent * ev, int count)
 {
diff --git a/Xi/exglobals.h b/Xi/exglobals.h
index 61ebca8..50bb33f 100644
--- a/Xi/exglobals.h
+++ b/Xi/exglobals.h
@@ -45,7 +45,6 @@ extern Mask DevicePointerMotionMask;
 extern Mask DevicePointerMotionHintMask;
 extern Mask DeviceFocusChangeMask;
 extern Mask DeviceStateNotifyMask;
-extern Mask ChangeDeviceNotifyMask;
 extern Mask DeviceMappingNotifyMask;
 extern Mask DeviceOwnerGrabButtonMask;
 extern Mask DeviceButtonGrabMask;
diff --git a/Xi/extinit.c b/Xi/extinit.c
index d14e133..fed54ab 100644
--- a/Xi/extinit.c
+++ b/Xi/extinit.c
@@ -161,7 +161,7 @@ Mask DevicePointerMotionMask;
 Mask DevicePointerMotionHintMask;
 Mask DeviceFocusChangeMask;
 Mask DeviceStateNotifyMask;
-Mask ChangeDeviceNotifyMask;
+static Mask ChangeDeviceNotifyMask;
 Mask DeviceMappingNotifyMask;
 Mask DeviceOwnerGrabButtonMask;
 Mask DeviceButtonGrabMask;
@@ -208,51 +208,6 @@ static XExtensionVersion thisversion = {
     XI_Add_DevicePresenceNotify_Minor
 };
 
-/**********************************************************************
- *
- * IExtensionInit - initialize the input extension.
- *
- * Called from InitExtensions in main() or from QueryExtension() if the
- * extension is dynamically loaded.
- *
- * This extension has several events and errors.
- *
- */
-
-void
-XInputExtensionInit(void)
-{
-    ExtensionEntry *extEntry;
-
-    extEntry = AddExtension(INAME, IEVENTS, IERRORS, ProcIDispatch,
-			    SProcIDispatch, IResetProc, StandardMinorOpcode);
-    if (extEntry) {
-	IReqCode = extEntry->base;
-	AllExtensionVersions[IReqCode - 128] = thisversion;
-	MakeDeviceTypeAtoms();
-	RT_INPUTCLIENT = CreateNewResourceType((DeleteType) InputClientGone);
-	FixExtensionEvents(extEntry);
-	ReplySwapVector[IReqCode] = (ReplySwapPtr) SReplyIDispatch;
-	EventSwapVector[DeviceValuator] = SEventIDispatch;
-	EventSwapVector[DeviceKeyPress] = SEventIDispatch;
-	EventSwapVector[DeviceKeyRelease] = SEventIDispatch;
-	EventSwapVector[DeviceButtonPress] = SEventIDispatch;
-	EventSwapVector[DeviceButtonRelease] = SEventIDispatch;
-	EventSwapVector[DeviceMotionNotify] = SEventIDispatch;
-	EventSwapVector[DeviceFocusIn] = SEventIDispatch;
-	EventSwapVector[DeviceFocusOut] = SEventIDispatch;
-	EventSwapVector[ProximityIn] = SEventIDispatch;
-	EventSwapVector[ProximityOut] = SEventIDispatch;
-	EventSwapVector[DeviceStateNotify] = SEventIDispatch;
-	EventSwapVector[DeviceKeyStateNotify] = SEventIDispatch;
-	EventSwapVector[DeviceButtonStateNotify] = SEventIDispatch;
-	EventSwapVector[DeviceMappingNotify] = SEventIDispatch;
-	EventSwapVector[ChangeDeviceNotify] = SEventIDispatch;
-    } else {
-	FatalError("IExtensionInit: AddExtensions failed\n");
-    }
-}
-
 /*************************************************************************
  *
  * ProcIDispatch - main dispatch routine for requests to this extension.
@@ -260,7 +215,7 @@ XInputExtensionInit(void)
  *
  */
 
-int
+static int
 ProcIDispatch(register ClientPtr client)
 {
     REQUEST(xReq);
@@ -349,7 +304,7 @@ ProcIDispatch(register ClientPtr client)
  *
  */
 
-int
+static int
 SProcIDispatch(register ClientPtr client)
 {
     REQUEST(xReq);
@@ -441,7 +396,7 @@ SProcIDispatch(register ClientPtr client
     if (rep->RepType == X_##code) \
 	SRepX##code (client, len, (x##code##Reply *) rep)
 
-void
+static void
 SReplyIDispatch(ClientPtr client, int len, xGrabDeviceReply * rep)
 					/* All we look at is the type field */
 {	/* This is common to all replies    */
@@ -500,68 +455,13 @@ SReplyIDispatch(ClientPtr client, int le
     }
 }
 
-/*****************************************************************************
- *
- *	SEventIDispatch
- *
- *	Swap any events defined in this extension.
- */
-#define DO_SWAP(func,type) func ((type *)from, (type *)to)
-
-void
-SEventIDispatch(xEvent * from, xEvent * to)
-{
-    int type = from->u.u.type & 0177;
-
-    if (type == DeviceValuator)
-	DO_SWAP(SEventDeviceValuator, deviceValuator);
-    else if (type == DeviceKeyPress) {
-	SKeyButtonPtrEvent(from, to);
-	to->u.keyButtonPointer.pad1 = from->u.keyButtonPointer.pad1;
-    } else if (type == DeviceKeyRelease) {
-	SKeyButtonPtrEvent(from, to);
-	to->u.keyButtonPointer.pad1 = from->u.keyButtonPointer.pad1;
-    } else if (type == DeviceButtonPress) {
-	SKeyButtonPtrEvent(from, to);
-	to->u.keyButtonPointer.pad1 = from->u.keyButtonPointer.pad1;
-    } else if (type == DeviceButtonRelease) {
-	SKeyButtonPtrEvent(from, to);
-	to->u.keyButtonPointer.pad1 = from->u.keyButtonPointer.pad1;
-    } else if (type == DeviceMotionNotify) {
-	SKeyButtonPtrEvent(from, to);
-	to->u.keyButtonPointer.pad1 = from->u.keyButtonPointer.pad1;
-    } else if (type == DeviceFocusIn)
-	DO_SWAP(SEventFocus, deviceFocus);
-    else if (type == DeviceFocusOut)
-	DO_SWAP(SEventFocus, deviceFocus);
-    else if (type == ProximityIn) {
-	SKeyButtonPtrEvent(from, to);
-	to->u.keyButtonPointer.pad1 = from->u.keyButtonPointer.pad1;
-    } else if (type == ProximityOut) {
-	SKeyButtonPtrEvent(from, to);
-	to->u.keyButtonPointer.pad1 = from->u.keyButtonPointer.pad1;
-    } else if (type == DeviceStateNotify)
-	DO_SWAP(SDeviceStateNotifyEvent, deviceStateNotify);
-    else if (type == DeviceKeyStateNotify)
-	DO_SWAP(SDeviceKeyStateNotifyEvent, deviceKeyStateNotify);
-    else if (type == DeviceButtonStateNotify)
-	DO_SWAP(SDeviceButtonStateNotifyEvent, deviceButtonStateNotify);
-    else if (type == DeviceMappingNotify)
-	DO_SWAP(SDeviceMappingNotifyEvent, deviceMappingNotify);
-    else if (type == ChangeDeviceNotify)
-	DO_SWAP(SChangeDeviceNotifyEvent, changeDeviceNotify);
-    else {
-	FatalError("XInputExtension: Impossible event!\n");
-    }
-}
-
 /************************************************************************
  *
  * This function swaps the DeviceValuator event.
  *
  */
 
-void
+static void
 SEventDeviceValuator(deviceValuator * from, deviceValuator * to)
 {
     register char n;
@@ -577,7 +477,7 @@ SEventDeviceValuator(deviceValuator * fr
     }
 }
 
-void
+static void
 SEventFocus(deviceFocus * from, deviceFocus * to)
 {
     register char n;
@@ -588,7 +488,7 @@ SEventFocus(deviceFocus * from, deviceFo
     swapl(&to->window, n);
 }
 
-void
+static void
 SDeviceStateNotifyEvent(deviceStateNotify * from, deviceStateNotify * to)
 {
     register int i;
@@ -604,7 +504,7 @@ SDeviceStateNotifyEvent(deviceStateNotif
     }
 }
 
-void
+static void
 SDeviceKeyStateNotifyEvent(deviceKeyStateNotify * from,
 			   deviceKeyStateNotify * to)
 {
@@ -614,7 +514,7 @@ SDeviceKeyStateNotifyEvent(deviceKeyStat
     swaps(&to->sequenceNumber, n);
 }
 
-void
+static void
 SDeviceButtonStateNotifyEvent(deviceButtonStateNotify * from,
 			      deviceButtonStateNotify * to)
 {
@@ -624,7 +524,7 @@ SDeviceButtonStateNotifyEvent(deviceButt
     swaps(&to->sequenceNumber, n);
 }
 
-void
+static void
 SChangeDeviceNotifyEvent(changeDeviceNotify * from, changeDeviceNotify * to)
 {
     register char n;
@@ -634,7 +534,7 @@ SChangeDeviceNotifyEvent(changeDeviceNot
     swapl(&to->time, n);
 }
 
-void
+static void
 SDeviceMappingNotifyEvent(deviceMappingNotify * from, deviceMappingNotify * to)
 {
     register char n;
@@ -644,7 +544,7 @@ SDeviceMappingNotifyEvent(deviceMappingN
     swapl(&to->time, n);
 }
 
-void
+static void
 SDevicePresenceNotifyEvent (devicePresenceNotify *from, devicePresenceNotify *to)
 {
     register char n;
@@ -655,13 +555,106 @@ SDevicePresenceNotifyEvent (devicePresen
     swaps(&to->control, n);
 }
 
+/**************************************************************************
+ *
+ * Allow the specified event to have its propagation suppressed.
+ * The default is to not allow suppression of propagation.
+ *
+ */
+
+static void
+AllowPropagateSuppress(Mask mask)
+{
+    int i;
+
+    for (i = 0; i < MAX_DEVICES; i++)
+	PropagateMask[i] |= mask;
+}
+
+/**************************************************************************
+ *
+ * Return the next available extension event mask.
+ *
+ */
+
+static Mask
+GetNextExtEventMask(void)
+{
+    int i;
+    Mask mask = lastExtEventMask;
+
+    if (lastExtEventMask == 0) {
+	FatalError("GetNextExtEventMask: no more events are available.");
+    }
+    lastExtEventMask <<= 1;
+
+    for (i = 0; i < MAX_DEVICES; i++)
+	ExtValidMasks[i] |= mask;
+    return mask;
+}
+
+/**************************************************************************
+ *
+ * Record an event mask where there is no unique corresponding event type.
+ * We can't call SetMaskForEvent, since that would clobber the existing
+ * mask for that event.  MotionHint and ButtonMotion are examples.
+ *
+ * Since extension event types will never be less than 64, we can use
+ * 0-63 in the EventInfo array as the "type" to be used to look up this
+ * mask.  This means that the corresponding macros such as 
+ * DevicePointerMotionHint must have access to the same constants.
+ *
+ */
+
+static void
+SetEventInfo(Mask mask, int constant)
+{
+    EventInfo[ExtEventIndex].mask = mask;
+    EventInfo[ExtEventIndex++].type = constant;
+}
+
+/**************************************************************************
+ *
+ * Allow the specified event to be restricted to being selected by one
+ * client at a time.
+ * The default is to allow more than one client to select the event.
+ *
+ */
+
+static void
+SetExclusiveAccess(Mask mask)
+{
+    int i;
+
+    for (i = 0; i < MAX_DEVICES; i++)
+	ExtExclusiveMasks[i] |= mask;
+}
+
+/**************************************************************************
+ *
+ * Assign the specified mask to the specified event.
+ *
+ */
+
+static void
+SetMaskForExtEvent(Mask mask, int event)
+{
+
+    EventInfo[ExtEventIndex].mask = mask;
+    EventInfo[ExtEventIndex++].type = event;
+
+    if ((event < LASTEvent) || (event >= 128))
+	FatalError("MaskForExtensionEvent: bogus event number");
+    SetMaskForEvent(mask, event);
+}
+
 /************************************************************************
  *
  * This function sets up extension event types and masks.
  *
  */
 
-void
+static void
 FixExtensionEvents(ExtensionEntry * extEntry)
 {
     Mask mask;
@@ -767,7 +760,7 @@ FixExtensionEvents(ExtensionEntry * extE
  *
  */
 
-void
+static void
 RestoreExtensionEvents(void)
 {
     int i;
@@ -815,7 +808,7 @@ RestoreExtensionEvents(void)
  *
  */
 
-void
+static void
 IResetProc(ExtensionEntry * unused)
 {
 
@@ -859,7 +852,7 @@ AssignTypeAndName(DeviceIntPtr dev, Atom
  *
  */
 
-void
+static void
 MakeDeviceTypeAtoms(void)
 {
     int i;
@@ -892,95 +885,102 @@ LookupDeviceIntRec(CARD8 id)
     return NULL;
 }
 
-/**************************************************************************
- *
- * Allow the specified event to be restricted to being selected by one
- * client at a time.
- * The default is to allow more than one client to select the event.
- *
- */
-
-void
-SetExclusiveAccess(Mask mask)
-{
-    int i;
-
-    for (i = 0; i < MAX_DEVICES; i++)
-	ExtExclusiveMasks[i] |= mask;
-}
-
-/**************************************************************************
- *
- * Allow the specified event to have its propagation suppressed.
- * The default is to not allow suppression of propagation.
- *
- */
-
-void
-AllowPropagateSuppress(Mask mask)
-{
-    int i;
-
-    for (i = 0; i < MAX_DEVICES; i++)
-	PropagateMask[i] |= mask;
-}
-
-/**************************************************************************
+/*****************************************************************************
  *
- * Return the next available extension event mask.
+ *	SEventIDispatch
  *
+ *	Swap any events defined in this extension.
  */
+#define DO_SWAP(func,type) func ((type *)from, (type *)to)
 
-Mask
-GetNextExtEventMask(void)
+static void
+SEventIDispatch(xEvent * from, xEvent * to)
 {
-    int i;
-    Mask mask = lastExtEventMask;
+    int type = from->u.u.type & 0177;
 
-    if (lastExtEventMask == 0) {
-	FatalError("GetNextExtEventMask: no more events are available.");
+    if (type == DeviceValuator)
+	DO_SWAP(SEventDeviceValuator, deviceValuator);
+    else if (type == DeviceKeyPress) {
+	SKeyButtonPtrEvent(from, to);
+	to->u.keyButtonPointer.pad1 = from->u.keyButtonPointer.pad1;
+    } else if (type == DeviceKeyRelease) {
+	SKeyButtonPtrEvent(from, to);
+	to->u.keyButtonPointer.pad1 = from->u.keyButtonPointer.pad1;
+    } else if (type == DeviceButtonPress) {
+	SKeyButtonPtrEvent(from, to);
+	to->u.keyButtonPointer.pad1 = from->u.keyButtonPointer.pad1;
+    } else if (type == DeviceButtonRelease) {
+	SKeyButtonPtrEvent(from, to);
+	to->u.keyButtonPointer.pad1 = from->u.keyButtonPointer.pad1;
+    } else if (type == DeviceMotionNotify) {
+	SKeyButtonPtrEvent(from, to);
+	to->u.keyButtonPointer.pad1 = from->u.keyButtonPointer.pad1;
+    } else if (type == DeviceFocusIn)
+	DO_SWAP(SEventFocus, deviceFocus);
+    else if (type == DeviceFocusOut)
+	DO_SWAP(SEventFocus, deviceFocus);
+    else if (type == ProximityIn) {
+	SKeyButtonPtrEvent(from, to);
+	to->u.keyButtonPointer.pad1 = from->u.keyButtonPointer.pad1;
+    } else if (type == ProximityOut) {
+	SKeyButtonPtrEvent(from, to);
+	to->u.keyButtonPointer.pad1 = from->u.keyButtonPointer.pad1;
+    } else if (type == DeviceStateNotify)
+	DO_SWAP(SDeviceStateNotifyEvent, deviceStateNotify);
+    else if (type == DeviceKeyStateNotify)
+	DO_SWAP(SDeviceKeyStateNotifyEvent, deviceKeyStateNotify);
+    else if (type == DeviceButtonStateNotify)
+	DO_SWAP(SDeviceButtonStateNotifyEvent, deviceButtonStateNotify);
+    else if (type == DeviceMappingNotify)
+	DO_SWAP(SDeviceMappingNotifyEvent, deviceMappingNotify);
+    else if (type == ChangeDeviceNotify)
+	DO_SWAP(SChangeDeviceNotifyEvent, changeDeviceNotify);
+    else {
+	FatalError("XInputExtension: Impossible event!\n");
     }
-    lastExtEventMask <<= 1;
-
-    for (i = 0; i < MAX_DEVICES; i++)
-	ExtValidMasks[i] |= mask;
-    return mask;
 }
 
-/**************************************************************************
- *
- * Assign the specified mask to the specified event.
+/**********************************************************************
  *
- */
-
-void
-SetMaskForExtEvent(Mask mask, int event)
-{
-
-    EventInfo[ExtEventIndex].mask = mask;
-    EventInfo[ExtEventIndex++].type = event;
-
-    if ((event < LASTEvent) || (event >= 128))
-	FatalError("MaskForExtensionEvent: bogus event number");
-    SetMaskForEvent(mask, event);
-}
-
-/**************************************************************************
+ * IExtensionInit - initialize the input extension.
  *
- * Record an event mask where there is no unique corresponding event type.
- * We can't call SetMaskForEvent, since that would clobber the existing
- * mask for that event.  MotionHint and ButtonMotion are examples.
+ * Called from InitExtensions in main() or from QueryExtension() if the
+ * extension is dynamically loaded.
  *
- * Since extension event types will never be less than 64, we can use
- * 0-63 in the EventInfo array as the "type" to be used to look up this
- * mask.  This means that the corresponding macros such as 
- * DevicePointerMotionHint must have access to the same constants.
+ * This extension has several events and errors.
  *
  */
 
 void
-SetEventInfo(Mask mask, int constant)
+XInputExtensionInit(void)
 {
-    EventInfo[ExtEventIndex].mask = mask;
-    EventInfo[ExtEventIndex++].type = constant;
+    ExtensionEntry *extEntry;
+
+    extEntry = AddExtension(INAME, IEVENTS, IERRORS, ProcIDispatch,
+			    SProcIDispatch, IResetProc, StandardMinorOpcode);
+    if (extEntry) {
+	IReqCode = extEntry->base;
+	AllExtensionVersions[IReqCode - 128] = thisversion;
+	MakeDeviceTypeAtoms();
+	RT_INPUTCLIENT = CreateNewResourceType((DeleteType) InputClientGone);
+	FixExtensionEvents(extEntry);
+	ReplySwapVector[IReqCode] = (ReplySwapPtr) SReplyIDispatch;
+	EventSwapVector[DeviceValuator] = SEventIDispatch;
+	EventSwapVector[DeviceKeyPress] = SEventIDispatch;
+	EventSwapVector[DeviceKeyRelease] = SEventIDispatch;
+	EventSwapVector[DeviceButtonPress] = SEventIDispatch;
+	EventSwapVector[DeviceButtonRelease] = SEventIDispatch;
+	EventSwapVector[DeviceMotionNotify] = SEventIDispatch;
+	EventSwapVector[DeviceFocusIn] = SEventIDispatch;
+	EventSwapVector[DeviceFocusOut] = SEventIDispatch;
+	EventSwapVector[ProximityIn] = SEventIDispatch;
+	EventSwapVector[ProximityOut] = SEventIDispatch;
+	EventSwapVector[DeviceStateNotify] = SEventIDispatch;
+	EventSwapVector[DeviceKeyStateNotify] = SEventIDispatch;
+	EventSwapVector[DeviceButtonStateNotify] = SEventIDispatch;
+	EventSwapVector[DeviceMappingNotify] = SEventIDispatch;
+	EventSwapVector[ChangeDeviceNotify] = SEventIDispatch;
+    } else {
+	FatalError("IExtensionInit: AddExtensions failed\n");
+    }
 }
diff --git a/Xi/getdctl.c b/Xi/getdctl.c
index d738ef8..c264d4f 100644
--- a/Xi/getdctl.c
+++ b/Xi/getdctl.c
@@ -88,112 +88,11 @@ SProcXGetDeviceControl(register ClientPt
 
 /***********************************************************************
  *
- * Get the state of the specified device control.
- *
- */
-
-int
-ProcXGetDeviceControl(ClientPtr client)
-{
-    int total_length = 0;
-    char *buf, *savbuf;
-    register DeviceIntPtr dev;
-    xGetDeviceControlReply rep;
-
-    REQUEST(xGetDeviceControlReq);
-    REQUEST_SIZE_MATCH(xGetDeviceControlReq);
-
-    dev = LookupDeviceIntRec(stuff->deviceid);
-    if (dev == NULL) {
-	SendErrorToClient(client, IReqCode, X_GetDeviceControl, 0, BadDevice);
-	return Success;
-    }
-
-    rep.repType = X_Reply;
-    rep.RepType = X_GetDeviceControl;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-
-    switch (stuff->control) {
-    case DEVICE_RESOLUTION:
-	if (!dev->valuator) {
-	    SendErrorToClient(client, IReqCode, X_GetDeviceControl, 0,
-			      BadMatch);
-	    return Success;
-	}
-	total_length = sizeof(xDeviceResolutionState) +
-	    (3 * sizeof(int) * dev->valuator->numAxes);
-	break;
-    case DEVICE_ABS_CALIB:
-        if (!dev->absolute) {
-            SendErrorToClient(client, IReqCode, X_GetDeviceControl, 0,
-                              BadMatch);
-            return Success;
-        }
-
-        total_length = sizeof(xDeviceAbsCalibCtl);
-        break;
-    case DEVICE_ABS_AREA:
-        if (!dev->absolute) {
-            SendErrorToClient(client, IReqCode, X_GetDeviceControl, 0,
-                              BadMatch);
-            return Success;
-        }
-
-        total_length = sizeof(xDeviceAbsAreaCtl);
-        break;
-    case DEVICE_CORE:
-        total_length = sizeof(xDeviceCoreCtl);
-        break;
-    case DEVICE_ENABLE:
-        total_length = sizeof(xDeviceEnableCtl);
-        break;
-    default:
-	SendErrorToClient(client, IReqCode, X_GetDeviceControl, 0, BadValue);
-	return Success;
-    }
-
-    buf = (char *)xalloc(total_length);
-    if (!buf) {
-	SendErrorToClient(client, IReqCode, X_GetDeviceControl, 0, BadAlloc);
-	return Success;
-    }
-    savbuf = buf;
-
-    switch (stuff->control) {
-    case DEVICE_RESOLUTION:
-	CopySwapDeviceResolution(client, dev->valuator, buf, total_length);
-	break;
-    case DEVICE_ABS_CALIB:
-        CopySwapDeviceAbsCalib(client, dev->absolute, buf);
-        break;
-    case DEVICE_ABS_AREA:
-        CopySwapDeviceAbsArea(client, dev->absolute, buf);
-        break;
-    case DEVICE_CORE:
-        CopySwapDeviceCore(client, dev, buf);
-        break;
-    case DEVICE_ENABLE:
-        CopySwapDeviceEnable(client, dev, buf);
-        break;
-    default:
-	break;
-    }
-
-    rep.length = (total_length + 3) >> 2;
-    WriteReplyToClient(client, sizeof(xGetDeviceControlReply), &rep);
-    WriteToClient(client, total_length, savbuf);
-    xfree(savbuf);
-    return Success;
-}
-
-/***********************************************************************
- *
  * This procedure copies DeviceResolution data, swapping if necessary.
  *
  */
 
-void
+static void
 CopySwapDeviceResolution(ClientPtr client, ValuatorClassPtr v, char *buf,
 			 int length)
 {
@@ -225,7 +124,7 @@ CopySwapDeviceResolution(ClientPtr clien
     }
 }
 
-void CopySwapDeviceAbsCalib (ClientPtr client, AbsoluteClassPtr dts,
+static void CopySwapDeviceAbsCalib (ClientPtr client, AbsoluteClassPtr dts,
                                 char *buf)
 {
     register char n;
@@ -256,7 +155,7 @@ void CopySwapDeviceAbsCalib (ClientPtr c
     }
 }
 
-void CopySwapDeviceAbsArea (ClientPtr client, AbsoluteClassPtr dts,
+static void CopySwapDeviceAbsArea (ClientPtr client, AbsoluteClassPtr dts,
                                 char *buf)
 {
     register char n;
@@ -283,7 +182,7 @@ void CopySwapDeviceAbsArea (ClientPtr cl
     }
 }
 
-void CopySwapDeviceCore (ClientPtr client, DeviceIntPtr dev, char *buf)
+static void CopySwapDeviceCore (ClientPtr client, DeviceIntPtr dev, char *buf)
 {
     register char n;
     xDeviceCoreState *c = (xDeviceCoreState *) buf;
@@ -300,7 +199,7 @@ void CopySwapDeviceCore (ClientPtr clien
     }
 }
 
-void CopySwapDeviceEnable (ClientPtr client, DeviceIntPtr dev, char *buf)
+static void CopySwapDeviceEnable (ClientPtr client, DeviceIntPtr dev, char *buf)
 {
     register char n;
     xDeviceEnableState *e = (xDeviceEnableState *) buf;
@@ -316,7 +215,6 @@ void CopySwapDeviceEnable (ClientPtr cli
     }
 }
 
-
 /***********************************************************************
  *
  * This procedure writes the reply for the xGetDeviceControl function,
@@ -333,3 +231,104 @@ SRepXGetDeviceControl(ClientPtr client, 
     swapl(&rep->length, n);
     WriteToClient(client, size, (char *)rep);
 }
+
+/***********************************************************************
+ *
+ * Get the state of the specified device control.
+ *
+ */
+
+int
+ProcXGetDeviceControl(ClientPtr client)
+{
+    int total_length = 0;
+    char *buf, *savbuf;
+    register DeviceIntPtr dev;
+    xGetDeviceControlReply rep;
+
+    REQUEST(xGetDeviceControlReq);
+    REQUEST_SIZE_MATCH(xGetDeviceControlReq);
+
+    dev = LookupDeviceIntRec(stuff->deviceid);
+    if (dev == NULL) {
+	SendErrorToClient(client, IReqCode, X_GetDeviceControl, 0, BadDevice);
+	return Success;
+    }
+
+    rep.repType = X_Reply;
+    rep.RepType = X_GetDeviceControl;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+
+    switch (stuff->control) {
+    case DEVICE_RESOLUTION:
+	if (!dev->valuator) {
+	    SendErrorToClient(client, IReqCode, X_GetDeviceControl, 0,
+			      BadMatch);
+	    return Success;
+	}
+	total_length = sizeof(xDeviceResolutionState) +
+	    (3 * sizeof(int) * dev->valuator->numAxes);
+	break;
+    case DEVICE_ABS_CALIB:
+        if (!dev->absolute) {
+            SendErrorToClient(client, IReqCode, X_GetDeviceControl, 0,
+                              BadMatch);
+            return Success;
+        }
+
+        total_length = sizeof(xDeviceAbsCalibCtl);
+        break;
+    case DEVICE_ABS_AREA:
+        if (!dev->absolute) {
+            SendErrorToClient(client, IReqCode, X_GetDeviceControl, 0,
+                              BadMatch);
+            return Success;
+        }
+
+        total_length = sizeof(xDeviceAbsAreaCtl);
+        break;
+    case DEVICE_CORE:
+        total_length = sizeof(xDeviceCoreCtl);
+        break;
+    case DEVICE_ENABLE:
+        total_length = sizeof(xDeviceEnableCtl);
+        break;
+    default:
+	SendErrorToClient(client, IReqCode, X_GetDeviceControl, 0, BadValue);
+	return Success;
+    }
+
+    buf = (char *)xalloc(total_length);
+    if (!buf) {
+	SendErrorToClient(client, IReqCode, X_GetDeviceControl, 0, BadAlloc);
+	return Success;
+    }
+    savbuf = buf;
+
+    switch (stuff->control) {
+    case DEVICE_RESOLUTION:
+	CopySwapDeviceResolution(client, dev->valuator, buf, total_length);
+	break;
+    case DEVICE_ABS_CALIB:
+        CopySwapDeviceAbsCalib(client, dev->absolute, buf);
+        break;
+    case DEVICE_ABS_AREA:
+        CopySwapDeviceAbsArea(client, dev->absolute, buf);
+        break;
+    case DEVICE_CORE:
+        CopySwapDeviceCore(client, dev, buf);
+        break;
+    case DEVICE_ENABLE:
+        CopySwapDeviceEnable(client, dev, buf);
+        break;
+    default:
+	break;
+    }
+
+    rep.length = (total_length + 3) >> 2;
+    WriteReplyToClient(client, sizeof(xGetDeviceControlReply), &rep);
+    WriteToClient(client, total_length, savbuf);
+    xfree(savbuf);
+    return Success;
+}
diff --git a/Xi/getdctl.h b/Xi/getdctl.h
index 36868d8..19c189f 100644
--- a/Xi/getdctl.h
+++ b/Xi/getdctl.h
@@ -36,30 +36,6 @@ int SProcXGetDeviceControl(ClientPtr	/* 
 int ProcXGetDeviceControl(ClientPtr	/* client */
     );
 
-void CopySwapDeviceResolution(ClientPtr /* client */ ,
-			      ValuatorClassPtr /* v */ ,
-			      char * /* buf */ ,
-			      int	/* length */
-    );
-
-void CopySwapDeviceAbsCalib (ClientPtr client,
-                             AbsoluteClassPtr dts,
-                             char *buf);
-
-void CopySwapDeviceAbsArea (ClientPtr client,
-                            AbsoluteClassPtr dts,
-                            char *buf);
-
-void CopySwapDeviceCore(ClientPtr /* client */ ,
-                        DeviceIntPtr /* dev */ ,
-                        char * /* buf */
-    );
-
-void CopySwapDeviceEnable(ClientPtr /* client */ ,
-                          DeviceIntPtr /* dev */ ,
-                          char * /* buf */
-    );
-
 void SRepXGetDeviceControl(ClientPtr /* client */ ,
 			   int /* size */ ,
 			   xGetDeviceControlReply *	/* rep */
diff --git a/Xi/getfctl.c b/Xi/getfctl.c
index 870348f..28360ee 100644
--- a/Xi/getfctl.c
+++ b/Xi/getfctl.c
@@ -86,104 +86,11 @@ SProcXGetFeedbackControl(register Client
 
 /***********************************************************************
  *
- * Get the feedback control state.
- *
- */
-
-int
-ProcXGetFeedbackControl(ClientPtr client)
-{
-    int total_length = 0;
-    char *buf, *savbuf;
-    register DeviceIntPtr dev;
-    KbdFeedbackPtr k;
-    PtrFeedbackPtr p;
-    IntegerFeedbackPtr i;
-    StringFeedbackPtr s;
-    BellFeedbackPtr b;
-    LedFeedbackPtr l;
-    xGetFeedbackControlReply rep;
-
-    REQUEST(xGetFeedbackControlReq);
-    REQUEST_SIZE_MATCH(xGetFeedbackControlReq);
-
-    dev = LookupDeviceIntRec(stuff->deviceid);
-    if (dev == NULL) {
-	SendErrorToClient(client, IReqCode, X_GetFeedbackControl, 0, BadDevice);
-	return Success;
-    }
-
-    rep.repType = X_Reply;
-    rep.RepType = X_GetFeedbackControl;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.num_feedbacks = 0;
-
-    for (k = dev->kbdfeed; k; k = k->next) {
-	rep.num_feedbacks++;
-	total_length += sizeof(xKbdFeedbackState);
-    }
-    for (p = dev->ptrfeed; p; p = p->next) {
-	rep.num_feedbacks++;
-	total_length += sizeof(xPtrFeedbackState);
-    }
-    for (s = dev->stringfeed; s; s = s->next) {
-	rep.num_feedbacks++;
-	total_length += sizeof(xStringFeedbackState) +
-	    (s->ctrl.num_symbols_supported * sizeof(KeySym));
-    }
-    for (i = dev->intfeed; i; i = i->next) {
-	rep.num_feedbacks++;
-	total_length += sizeof(xIntegerFeedbackState);
-    }
-    for (l = dev->leds; l; l = l->next) {
-	rep.num_feedbacks++;
-	total_length += sizeof(xLedFeedbackState);
-    }
-    for (b = dev->bell; b; b = b->next) {
-	rep.num_feedbacks++;
-	total_length += sizeof(xBellFeedbackState);
-    }
-
-    if (total_length == 0) {
-	SendErrorToClient(client, IReqCode, X_GetFeedbackControl, 0, BadMatch);
-	return Success;
-    }
-
-    buf = (char *)xalloc(total_length);
-    if (!buf) {
-	SendErrorToClient(client, IReqCode, X_GetFeedbackControl, 0, BadAlloc);
-	return Success;
-    }
-    savbuf = buf;
-
-    for (k = dev->kbdfeed; k; k = k->next)
-	CopySwapKbdFeedback(client, k, &buf);
-    for (p = dev->ptrfeed; p; p = p->next)
-	CopySwapPtrFeedback(client, p, &buf);
-    for (s = dev->stringfeed; s; s = s->next)
-	CopySwapStringFeedback(client, s, &buf);
-    for (i = dev->intfeed; i; i = i->next)
-	CopySwapIntegerFeedback(client, i, &buf);
-    for (l = dev->leds; l; l = l->next)
-	CopySwapLedFeedback(client, l, &buf);
-    for (b = dev->bell; b; b = b->next)
-	CopySwapBellFeedback(client, b, &buf);
-
-    rep.length = (total_length + 3) >> 2;
-    WriteReplyToClient(client, sizeof(xGetFeedbackControlReply), &rep);
-    WriteToClient(client, total_length, savbuf);
-    xfree(savbuf);
-    return Success;
-}
-
-/***********************************************************************
- *
  * This procedure copies KbdFeedbackClass data, swapping if necessary.
  *
  */
 
-void
+static void
 CopySwapKbdFeedback(ClientPtr client, KbdFeedbackPtr k, char **buf)
 {
     int i;
@@ -218,7 +125,7 @@ CopySwapKbdFeedback(ClientPtr client, Kb
  *
  */
 
-void
+static void
 CopySwapPtrFeedback(ClientPtr client, PtrFeedbackPtr p, char **buf)
 {
     register char n;
@@ -246,7 +153,7 @@ CopySwapPtrFeedback(ClientPtr client, Pt
  *
  */
 
-void
+static void
 CopySwapIntegerFeedback(ClientPtr client, IntegerFeedbackPtr i, char **buf)
 {
     register char n;
@@ -274,7 +181,7 @@ CopySwapIntegerFeedback(ClientPtr client
  *
  */
 
-void
+static void
 CopySwapStringFeedback(ClientPtr client, StringFeedbackPtr s, char **buf)
 {
     int i;
@@ -311,7 +218,7 @@ CopySwapStringFeedback(ClientPtr client,
  *
  */
 
-void
+static void
 CopySwapLedFeedback(ClientPtr client, LedFeedbackPtr l, char **buf)
 {
     register char n;
@@ -337,7 +244,7 @@ CopySwapLedFeedback(ClientPtr client, Le
  *
  */
 
-void
+static void
 CopySwapBellFeedback(ClientPtr client, BellFeedbackPtr b, char **buf)
 {
     register char n;
@@ -376,3 +283,96 @@ SRepXGetFeedbackControl(ClientPtr client
     swaps(&rep->num_feedbacks, n);
     WriteToClient(client, size, (char *)rep);
 }
+
+/***********************************************************************
+ *
+ * Get the feedback control state.
+ *
+ */
+
+int
+ProcXGetFeedbackControl(ClientPtr client)
+{
+    int total_length = 0;
+    char *buf, *savbuf;
+    register DeviceIntPtr dev;
+    KbdFeedbackPtr k;
+    PtrFeedbackPtr p;
+    IntegerFeedbackPtr i;
+    StringFeedbackPtr s;
+    BellFeedbackPtr b;
+    LedFeedbackPtr l;
+    xGetFeedbackControlReply rep;
+
+    REQUEST(xGetFeedbackControlReq);
+    REQUEST_SIZE_MATCH(xGetFeedbackControlReq);
+
+    dev = LookupDeviceIntRec(stuff->deviceid);
+    if (dev == NULL) {
+	SendErrorToClient(client, IReqCode, X_GetFeedbackControl, 0, BadDevice);
+	return Success;
+    }
+
+    rep.repType = X_Reply;
+    rep.RepType = X_GetFeedbackControl;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+    rep.num_feedbacks = 0;
+
+    for (k = dev->kbdfeed; k; k = k->next) {
+	rep.num_feedbacks++;
+	total_length += sizeof(xKbdFeedbackState);
+    }
+    for (p = dev->ptrfeed; p; p = p->next) {
+	rep.num_feedbacks++;
+	total_length += sizeof(xPtrFeedbackState);
+    }
+    for (s = dev->stringfeed; s; s = s->next) {
+	rep.num_feedbacks++;
+	total_length += sizeof(xStringFeedbackState) +
+	    (s->ctrl.num_symbols_supported * sizeof(KeySym));
+    }
+    for (i = dev->intfeed; i; i = i->next) {
+	rep.num_feedbacks++;
+	total_length += sizeof(xIntegerFeedbackState);
+    }
+    for (l = dev->leds; l; l = l->next) {
+	rep.num_feedbacks++;
+	total_length += sizeof(xLedFeedbackState);
+    }
+    for (b = dev->bell; b; b = b->next) {
+	rep.num_feedbacks++;
+	total_length += sizeof(xBellFeedbackState);
+    }
+
+    if (total_length == 0) {
+	SendErrorToClient(client, IReqCode, X_GetFeedbackControl, 0, BadMatch);
+	return Success;
+    }
+
+    buf = (char *)xalloc(total_length);
+    if (!buf) {
+	SendErrorToClient(client, IReqCode, X_GetFeedbackControl, 0, BadAlloc);
+	return Success;
+    }
+    savbuf = buf;
+
+    for (k = dev->kbdfeed; k; k = k->next)
+	CopySwapKbdFeedback(client, k, &buf);
+    for (p = dev->ptrfeed; p; p = p->next)
+	CopySwapPtrFeedback(client, p, &buf);
+    for (s = dev->stringfeed; s; s = s->next)
+	CopySwapStringFeedback(client, s, &buf);
+    for (i = dev->intfeed; i; i = i->next)
+	CopySwapIntegerFeedback(client, i, &buf);
+    for (l = dev->leds; l; l = l->next)
+	CopySwapLedFeedback(client, l, &buf);
+    for (b = dev->bell; b; b = b->next)
+	CopySwapBellFeedback(client, b, &buf);
+
+    rep.length = (total_length + 3) >> 2;
+    WriteReplyToClient(client, sizeof(xGetFeedbackControlReply), &rep);
+    WriteToClient(client, total_length, savbuf);
+    xfree(savbuf);
+    return Success;
+}
diff --git a/Xi/getfctl.h b/Xi/getfctl.h
index 7d2d17a..0ad58aa 100644
--- a/Xi/getfctl.h
+++ b/Xi/getfctl.h
@@ -36,36 +36,6 @@ int SProcXGetFeedbackControl(ClientPtr	/
 int ProcXGetFeedbackControl(ClientPtr	/* client */
     );
 
-void CopySwapKbdFeedback(ClientPtr /* client */ ,
-			 KbdFeedbackPtr /* k */ ,
-			 char **	/* buf */
-    );
-
-void CopySwapPtrFeedback(ClientPtr /* client */ ,
-			 PtrFeedbackPtr /* p */ ,
-			 char **	/* buf */
-    );
-
-void CopySwapIntegerFeedback(ClientPtr /* client */ ,
-			     IntegerFeedbackPtr /* i */ ,
-			     char **	/* buf */
-    );
-
-void CopySwapStringFeedback(ClientPtr /* client */ ,
-			    StringFeedbackPtr /* s */ ,
-			    char **	/* buf */
-    );
-
-void CopySwapLedFeedback(ClientPtr /* client */ ,
-			 LedFeedbackPtr /* l */ ,
-			 char **	/* buf */
-    );
-
-void CopySwapBellFeedback(ClientPtr /* client */ ,
-			  BellFeedbackPtr /* b */ ,
-			  char **	/* buf */
-    );
-
 void SRepXGetFeedbackControl(ClientPtr /* client */ ,
 			     int /* size */ ,
 			     xGetFeedbackControlReply *	/* rep */
diff --git a/Xi/listdev.c b/Xi/listdev.c
index 02d55ad..257ee59 100644
--- a/Xi/listdev.c
+++ b/Xi/listdev.c
@@ -88,71 +88,12 @@ SProcXListInputDevices(register ClientPt
 
 /***********************************************************************
  *
- * This procedure lists the input devices available to the server.
- *
- */
-
-int
-ProcXListInputDevices(register ClientPtr client)
-{
-    xListInputDevicesReply rep;
-    int numdevs = 0;
-    int namesize = 1;	/* need 1 extra byte for strcpy */
-    int size = 0;
-    int total_length;
-    char *devbuf;
-    char *classbuf;
-    char *namebuf;
-    char *savbuf;
-    xDeviceInfo *dev;
-    DeviceIntPtr d;
-
-    REQUEST_SIZE_MATCH(xListInputDevicesReq);
-
-    rep.repType = X_Reply;
-    rep.RepType = X_ListInputDevices;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-
-    AddOtherInputDevices();
-
-    for (d = inputInfo.devices; d; d = d->next) {
-	SizeDeviceInfo(d, &namesize, &size);
-        numdevs++;
-    }
-    for (d = inputInfo.off_devices; d; d = d->next) {
-	SizeDeviceInfo(d, &namesize, &size);
-        numdevs++;
-    }
-
-    total_length = numdevs * sizeof(xDeviceInfo) + size + namesize;
-    devbuf = (char *)xalloc(total_length);
-    classbuf = devbuf + (numdevs * sizeof(xDeviceInfo));
-    namebuf = classbuf + size;
-    savbuf = devbuf;
-
-    dev = (xDeviceInfoPtr) devbuf;
-    for (d = inputInfo.devices; d; d = d->next, dev++)
-	ListDeviceInfo(client, d, dev, &devbuf, &classbuf, &namebuf);
-    for (d = inputInfo.off_devices; d; d = d->next, dev++)
-	ListDeviceInfo(client, d, dev, &devbuf, &classbuf, &namebuf);
-
-    rep.ndevices = numdevs;
-    rep.length = (total_length + 3) >> 2;
-    WriteReplyToClient(client, sizeof(xListInputDevicesReply), &rep);
-    WriteToClient(client, total_length, savbuf);
-    xfree(savbuf);
-    return Success;
-}
-
-/***********************************************************************
- *
  * This procedure calculates the size of the information to be returned
  * for an input device.
  *
  */
 
-void
+static void
 SizeDeviceInfo(DeviceIntPtr d, int *namesize, int *size)
 {
     int chunks;
@@ -173,32 +114,6 @@ SizeDeviceInfo(DeviceIntPtr d, int *name
 
 /***********************************************************************
  *
- * This procedure lists information to be returned for an input device.
- *
- */
-
-void
-ListDeviceInfo(ClientPtr client, DeviceIntPtr d, xDeviceInfoPtr dev,
-	       char **devbuf, char **classbuf, char **namebuf)
-{
-    CopyDeviceName(namebuf, d->name);
-    CopySwapDevice(client, d, 0, devbuf);
-    if (d->key != NULL) {
-	CopySwapKeyClass(client, d->key, classbuf);
-	dev->num_classes++;
-    }
-    if (d->button != NULL) {
-	CopySwapButtonClass(client, d->button, classbuf);
-	dev->num_classes++;
-    }
-    if (d->valuator != NULL) {
-	dev->num_classes +=
-	    CopySwapValuatorClass(client, d->valuator, classbuf);
-    }
-}
-
-/***********************************************************************
- *
  * This procedure copies data to the DeviceInfo struct, swapping if necessary.
  *
  * We need the extra byte in the allocated buffer, because the trailing null
@@ -207,7 +122,7 @@ ListDeviceInfo(ClientPtr client, DeviceI
  *
  */
 
-void
+static void
 CopyDeviceName(char **namebuf, char *name)
 {
     char *nameptr = (char *)*namebuf;
@@ -224,11 +139,33 @@ CopyDeviceName(char **namebuf, char *nam
 
 /***********************************************************************
  *
+ * This procedure copies ButtonClass information, swapping if necessary.
+ *
+ */
+
+static void
+CopySwapButtonClass(register ClientPtr client, ButtonClassPtr b, char **buf)
+{
+    register char n;
+    xButtonInfoPtr b2;
+
+    b2 = (xButtonInfoPtr) * buf;
+    b2->class = ButtonClass;
+    b2->length = sizeof(xButtonInfo);
+    b2->num_buttons = b->numButtons;
+    if (client->swapped) {
+	swaps(&b2->num_buttons, n);	/* macro - braces are required */
+    }
+    *buf += sizeof(xButtonInfo);
+}
+
+/***********************************************************************
+ *
  * This procedure copies data to the DeviceInfo struct, swapping if necessary.
  *
  */
 
-void
+static void
 CopySwapDevice(register ClientPtr client, DeviceIntPtr d, int num_classes,
 	       char **buf)
 {
@@ -262,7 +199,7 @@ CopySwapDevice(register ClientPtr client
  *
  */
 
-void
+static void
 CopySwapKeyClass(register ClientPtr client, KeyClassPtr k, char **buf)
 {
     register char n;
@@ -282,28 +219,6 @@ CopySwapKeyClass(register ClientPtr clie
 
 /***********************************************************************
  *
- * This procedure copies ButtonClass information, swapping if necessary.
- *
- */
-
-void
-CopySwapButtonClass(register ClientPtr client, ButtonClassPtr b, char **buf)
-{
-    register char n;
-    xButtonInfoPtr b2;
-
-    b2 = (xButtonInfoPtr) * buf;
-    b2->class = ButtonClass;
-    b2->length = sizeof(xButtonInfo);
-    b2->num_buttons = b->numButtons;
-    if (client->swapped) {
-	swaps(&b2->num_buttons, n);	/* macro - braces are required */
-    }
-    *buf += sizeof(xButtonInfo);
-}
-
-/***********************************************************************
- *
  * This procedure copies ValuatorClass information, swapping if necessary.
  *
  * Devices may have up to 255 valuators.  The length of a ValuatorClass is
@@ -314,7 +229,7 @@ CopySwapButtonClass(register ClientPtr c
  *
  */
 
-int
+static int
 CopySwapValuatorClass(register ClientPtr client, ValuatorClassPtr v, char **buf)
 {
     int i, j, axes, t_axes;
@@ -359,6 +274,91 @@ CopySwapValuatorClass(register ClientPtr
 
 /***********************************************************************
  *
+ * This procedure lists information to be returned for an input device.
+ *
+ */
+
+static void
+ListDeviceInfo(ClientPtr client, DeviceIntPtr d, xDeviceInfoPtr dev,
+	       char **devbuf, char **classbuf, char **namebuf)
+{
+    CopyDeviceName(namebuf, d->name);
+    CopySwapDevice(client, d, 0, devbuf);
+    if (d->key != NULL) {
+	CopySwapKeyClass(client, d->key, classbuf);
+	dev->num_classes++;
+    }
+    if (d->button != NULL) {
+	CopySwapButtonClass(client, d->button, classbuf);
+	dev->num_classes++;
+    }
+    if (d->valuator != NULL) {
+	dev->num_classes +=
+	    CopySwapValuatorClass(client, d->valuator, classbuf);
+    }
+}
+
+/***********************************************************************
+ *
+ * This procedure lists the input devices available to the server.
+ *
+ */
+
+int
+ProcXListInputDevices(register ClientPtr client)
+{
+    xListInputDevicesReply rep;
+    int numdevs = 0;
+    int namesize = 1;	/* need 1 extra byte for strcpy */
+    int size = 0;
+    int total_length;
+    char *devbuf;
+    char *classbuf;
+    char *namebuf;
+    char *savbuf;
+    xDeviceInfo *dev;
+    DeviceIntPtr d;
+
+    REQUEST_SIZE_MATCH(xListInputDevicesReq);
+
+    rep.repType = X_Reply;
+    rep.RepType = X_ListInputDevices;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+
+    AddOtherInputDevices();
+
+    for (d = inputInfo.devices; d; d = d->next) {
+	SizeDeviceInfo(d, &namesize, &size);
+        numdevs++;
+    }
+    for (d = inputInfo.off_devices; d; d = d->next) {
+	SizeDeviceInfo(d, &namesize, &size);
+        numdevs++;
+    }
+
+    total_length = numdevs * sizeof(xDeviceInfo) + size + namesize;
+    devbuf = (char *)xalloc(total_length);
+    classbuf = devbuf + (numdevs * sizeof(xDeviceInfo));
+    namebuf = classbuf + size;
+    savbuf = devbuf;
+
+    dev = (xDeviceInfoPtr) devbuf;
+    for (d = inputInfo.devices; d; d = d->next, dev++)
+	ListDeviceInfo(client, d, dev, &devbuf, &classbuf, &namebuf);
+    for (d = inputInfo.off_devices; d; d = d->next, dev++)
+	ListDeviceInfo(client, d, dev, &devbuf, &classbuf, &namebuf);
+
+    rep.ndevices = numdevs;
+    rep.length = (total_length + 3) >> 2;
+    WriteReplyToClient(client, sizeof(xListInputDevicesReply), &rep);
+    WriteToClient(client, total_length, savbuf);
+    xfree(savbuf);
+    return Success;
+}
+
+/***********************************************************************
+ *
  * This procedure writes the reply for the XListInputDevices function,
  * if the client and server have a different byte ordering.
  *
diff --git a/Xi/listdev.h b/Xi/listdev.h
index bdd67ce..db376de 100644
--- a/Xi/listdev.h
+++ b/Xi/listdev.h
@@ -36,44 +36,6 @@ int SProcXListInputDevices(ClientPtr	/* 
 int ProcXListInputDevices(ClientPtr	/* client */
     );
 
-void SizeDeviceInfo(DeviceIntPtr /* d */ ,
-		    int * /* namesize */ ,
-		    int *	/* size */
-    );
-
-void ListDeviceInfo(ClientPtr /* client */ ,
-		    DeviceIntPtr /* d */ ,
-		    xDeviceInfoPtr /* dev */ ,
-		    char ** /* devbuf */ ,
-		    char ** /* classbuf */ ,
-		    char **	/* namebuf */
-    );
-
-void CopyDeviceName(char ** /* namebuf */ ,
-		    char *	/* name */
-    );
-
-void CopySwapDevice(ClientPtr /* client */ ,
-		    DeviceIntPtr /* d */ ,
-		    int /* num_classes */ ,
-		    char **	/* buf */
-    );
-
-void CopySwapKeyClass(ClientPtr /* client */ ,
-		      KeyClassPtr /* k */ ,
-		      char **	/* buf */
-    );
-
-void CopySwapButtonClass(ClientPtr /* client */ ,
-			 ButtonClassPtr /* b */ ,
-			 char **	/* buf */
-    );
-
-int CopySwapValuatorClass(ClientPtr /* client */ ,
-			  ValuatorClassPtr /* v */ ,
-			  char **	/* buf */
-    );
-
 void SRepXListInputDevices(ClientPtr /* client */ ,
 			   int /* size */ ,
 			   xListInputDevicesReply *	/* rep */
diff --git a/include/exevents.h b/include/exevents.h
index 7fbaddb..69d4abc 100644
--- a/include/exevents.h
+++ b/include/exevents.h
@@ -148,10 +148,6 @@ extern void DeleteWindowFromAnyExtEvents
 	WindowPtr              /* pWin */,
 	Bool                   /* freeResources */);
 
-extern void DeleteDeviceFromAnyExtEvents(
-	WindowPtr              /* pWin */,
-	DeviceIntPtr           /* dev */);
-
 extern int MaybeSendDeviceMotionNotifyHint (
 	deviceKeyButtonPointer * /* pEvents */,
 	Mask                   /* mask */);
@@ -164,11 +160,6 @@ extern void CheckDeviceGrabAndHintWindow
 	ClientPtr              /* client */,
 	Mask                   /* deliveryMask */);
 
-extern Mask DeviceEventMaskForClient(
-	DeviceIntPtr           /* dev */,
-	WindowPtr              /* pWin */,
-	ClientPtr              /* client */);
-
 extern void MaybeStopDeviceHint(
 	DeviceIntPtr           /* dev */,
 	ClientPtr              /* client */);
@@ -179,13 +170,6 @@ extern int DeviceEventSuppressForWindow(
 	Mask                   /* mask */,
 	int                    /* maskndx */);
 
-void FindInterestedChildren(
-        DeviceIntPtr           /* dev */,
-        WindowPtr              /* p1 */,
-        Mask                   /* mask */,
-        xEvent *               /* ev */,
-        int                    /* count */);
-
 void SendEventToAllWindows(
         DeviceIntPtr           /* dev */,
         Mask                   /* mask */,
diff --git a/include/extinit.h b/include/extinit.h
index 2087d74..e616b6d 100644
--- a/include/extinit.h
+++ b/include/extinit.h
@@ -37,93 +37,6 @@ XInputExtensionInit(
 	void
 	);
 
-
-int
-ProcIDispatch (
-	ClientPtr              /* client */
-	);
-
-int
-SProcIDispatch(
-	ClientPtr              /* client */
-	);
-
-void
-SReplyIDispatch (
-	ClientPtr              /* client */,
-	int                    /* len */,
-	xGrabDeviceReply *     /* rep */
-	);
-
-void
-SEventIDispatch (
-	xEvent *               /* from */,
-	xEvent *               /* to */
-	);
-
-void
-SEventDeviceValuator (
-	deviceValuator *       /* from */,
-	deviceValuator *       /* to */
-	);
-
-void
-SEventFocus (
-	deviceFocus *          /* from */,
-	deviceFocus *          /* to */
-	);
-
-void
-SDeviceStateNotifyEvent (
-	deviceStateNotify *    /* from */,
-	deviceStateNotify *    /* to */
-	);
-
-void
-SDeviceKeyStateNotifyEvent (
-	deviceKeyStateNotify * /* from */,
-	deviceKeyStateNotify * /* to */
-	);
-
-void
-SDeviceButtonStateNotifyEvent (
-	deviceButtonStateNotify * /* from */,
-	deviceButtonStateNotify * /* to */
-	);
-
-void
-SChangeDeviceNotifyEvent (
-	changeDeviceNotify *   /* from */,
-	changeDeviceNotify *   /* to */
-	);
-
-void
-SDeviceMappingNotifyEvent (
-	deviceMappingNotify *  /* from */,
-	deviceMappingNotify *  /* to */
-	);
-
-void
-SDevicePresenceNotifyEvent (
-       devicePresenceNotify * /* from */,
-       devicePresenceNotify * /* to */
-       );
-
-void
-FixExtensionEvents (
-	ExtensionEntry 	*      /* extEntry */
-	);
-
-void
-RestoreExtensionEvents (
-	void
-	);
-
-void
-IResetProc(
-	ExtensionEntry *       /* unused */
-	);
-
 void
 AssignTypeAndName (
 	DeviceIntPtr           /* dev */,
@@ -131,41 +44,9 @@ AssignTypeAndName (
 	char *                 /* name */
 	);
 
-void
-MakeDeviceTypeAtoms (
-	void
-);
-
 DeviceIntPtr
 LookupDeviceIntRec (
 	CARD8                  /* id */
 	);
 
-void
-SetExclusiveAccess (
-	Mask                   /* mask */
-	);
-
-void
-AllowPropagateSuppress (
-	Mask                   /* mask */
-	);
-
-Mask
-GetNextExtEventMask (
-	void
-);
-
-void
-SetMaskForExtEvent(
-	Mask                   /* mask */,
-	int                    /* event */
-	);
-
-void
-SetEventInfo(
-	Mask                   /* mask */,
-	int                    /* constant */
-	);
-
 #endif /* EXTINIT_H */
diff-tree 4b5802ddbd45271be3cadeae0a83a6742df2515b (from 04b87d6dfae02e4ecdb5216d12c6cdafd1e8c2b4)
Author: Adam Jackson <ajax at benzedrine.nwnk.net>
Date:   Sun Mar 25 17:57:54 2007 -0400

    General DIX static and dead code cleanup.

diff --git a/dix/dispatch.c b/dix/dispatch.c
index 02665ed..3d8e71f 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -299,7 +299,6 @@ long	    SmartScheduleMaxSlice = SMART_S
 long	    SmartScheduleTime;
 static ClientPtr   SmartLastClient;
 static int	   SmartLastIndex[SMART_MAX_PRIORITY-SMART_MIN_PRIORITY+1];
-int         SmartScheduleClient(int *clientReady, int nready);
 
 #ifdef SMART_DEBUG
 long	    SmartLastPrint;
@@ -308,7 +307,7 @@ long	    SmartLastPrint;
 void        Dispatch(void);
 void        InitProcVectors(void);
 
-int
+static int
 SmartScheduleClient (int *clientReady, int nready)
 {
     ClientPtr	pClient;
@@ -834,7 +833,7 @@ ProcCirculateWindow(ClientPtr client)
     return(client->noClientException);
 }
 
-int
+static int
 GetGeometry(ClientPtr client, xGetGeometryReply *rep)
 {
     DrawablePtr pDraw;
@@ -2157,8 +2156,7 @@ ProcPutImage(ClientPtr client)
      return (client->noClientException);
 }
 
-
-int
+static int
 DoGetImage(ClientPtr client, int format, Drawable drawable, 
            int x, int y, int width, int height, 
            Mask planemask, xGetImageReply **im_return)
@@ -3383,6 +3381,28 @@ ProcChangeAccessControl(ClientPtr client
     return (result);
 }
 
+/*********************
+ * CloseDownRetainedResources
+ *
+ *    Find all clients that are gone and have terminated in RetainTemporary 
+ *    and destroy their resources.
+ *********************/
+
+static void
+CloseDownRetainedResources(void)
+{
+    int i;
+    ClientPtr client;
+
+    for (i=1; i<currentMaxClients; i++)
+    {
+        client = clients[i];
+        if (client && (client->closeDownMode == RetainTemporary)
+	    && (client->clientGone))
+	    CloseDownClient(client);
+    }
+}
+
 int
 ProcKillClient(ClientPtr client)
 {
@@ -3651,28 +3671,6 @@ KillAllClients()
         }
 }
 
-/*********************
- * CloseDownRetainedResources
- *
- *    Find all clients that are gone and have terminated in RetainTemporary 
- *    and  destroy their resources.
- *********************/
-
-void
-CloseDownRetainedResources()
-{
-    int i;
-    ClientPtr client;
-
-    for (i=1; i<currentMaxClients; i++)
-    {
-        client = clients[i];
-        if (client && (client->closeDownMode == RetainTemporary)
-	    && (client->clientGone))
-	    CloseDownClient(client);
-    }
-}
-
 extern int clientPrivateLen;
 extern unsigned *clientPrivateSizes;
 extern unsigned totalClientSize;
diff --git a/dix/dixutils.c b/dix/dixutils.c
index c0728da..44d82c9 100644
--- a/dix/dixutils.c
+++ b/dix/dixutils.c
@@ -882,9 +882,7 @@ static CallbackFuncsRec default_cbfuncs 
     _DeleteCallbackList
 };
 
-/* ===== Public Procedures ===== */
-
-Bool
+static Bool
 CreateCallbackList(CallbackListPtr *pcbl, CallbackFuncsPtr cbfuncs)
 {
     CallbackListPtr  cbl;
@@ -916,6 +914,8 @@ CreateCallbackList(CallbackListPtr *pcbl
     return TRUE;
 }
 
+/* ===== Public Procedures ===== */
+
 _X_EXPORT Bool 
 AddCallback(CallbackListPtr *pcbl, CallbackProcPtr callback, pointer data)
 {
diff --git a/dix/extension.c b/dix/extension.c
index fb4ee6b..88dff15 100644
--- a/dix/extension.c
+++ b/dix/extension.c
@@ -66,8 +66,6 @@ SOFTWARE.
 #define LAST_EVENT  128
 #define LAST_ERROR 255
 
-static ScreenProcEntry AuxillaryScreenProcs[MAXSCREENS];
-
 static ExtensionEntry **extensions = (ExtensionEntry **)NULL;
 
 int lastEvent = EXTENSION_EVENT_BASE;
@@ -298,21 +296,8 @@ CloseDownExtensions()
     extensions = (ExtensionEntry **)NULL;
     lastEvent = EXTENSION_EVENT_BASE;
     lastError = FirstExtensionError;
-    for (i=0; i<MAXSCREENS; i++)
-    {
-	ScreenProcEntry *spentry = &AuxillaryScreenProcs[i];
-
-	while (spentry->num)
-	{
-	    spentry->num--;
-	    xfree(spentry->procList[spentry->num].name);
-	}
-	xfree(spentry->procList);
-	spentry->procList = (ProcEntryPtr)NULL;
-    }
 }
 
-
 int
 ProcQueryExtension(ClientPtr client)
 {
@@ -406,72 +391,6 @@ ProcListExtensions(ClientPtr client)
     return(client->noClientException);
 }
 
-
-ExtensionLookupProc 
-LookupProc(char *name, GCPtr pGC)
-{
-    int i;
-    ScreenProcEntry *spentry;
-    spentry  = &AuxillaryScreenProcs[pGC->pScreen->myNum];
-    if (spentry->num)    
-    {
-        for (i = 0; i < spentry->num; i++)
-            if (strcmp(name, spentry->procList[i].name) == 0)
-                return(spentry->procList[i].proc);
-    }
-    return (ExtensionLookupProc)NULL;
-}
-
-Bool
-RegisterProc(char *name, GC *pGC, ExtensionLookupProc proc)
-{
-    return RegisterScreenProc(name, pGC->pScreen, proc);
-}
-
-Bool
-RegisterScreenProc(char *name, ScreenPtr pScreen, ExtensionLookupProc proc)
-{
-    ScreenProcEntry *spentry;
-    ProcEntryPtr procEntry = (ProcEntryPtr)NULL;
-    char *newname;
-    int i;
-
-    spentry = &AuxillaryScreenProcs[pScreen->myNum];
-    /* first replace duplicates */
-    if (spentry->num)
-    {
-        for (i = 0; i < spentry->num; i++)
-            if (strcmp(name, spentry->procList[i].name) == 0)
-	    {
-                procEntry = &spentry->procList[i];
-		break;
-	    }
-    }
-    if (procEntry)
-        procEntry->proc = proc;
-    else
-    {
-	newname = (char *)xalloc(strlen(name)+1);
-	if (!newname)
-	    return FALSE;
-	procEntry = (ProcEntryPtr)
-			    xrealloc(spentry->procList,
-				     sizeof(ProcEntryRec) * (spentry->num+1));
-	if (!procEntry)
-	{
-	    xfree(newname);
-	    return FALSE;
-	}
-	spentry->procList = procEntry;
-        procEntry += spentry->num;
-        procEntry->name = newname;
-        strcpy(newname, name);
-        procEntry->proc = proc;
-        spentry->num++;        
-    }
-    return TRUE;
-}
-
 #ifdef XSERVER_DTRACE
 void LoadExtensionNames(char **RequestNames) {
     int i;
diff --git a/dix/gc.c b/dix/gc.c
index 7b7953d..7a76dd9 100644
--- a/dix/gc.c
+++ b/dix/gc.c
@@ -907,17 +907,6 @@ FreeGC(pointer value, XID gid)
     return(Success);
 }
 
-void
-SetGCMask(GCPtr pGC, Mask selectMask, Mask newDataMask)
-{
-    pGC->stateChanges = (~selectMask & pGC->stateChanges) |
-		        (selectMask & newDataMask);
-    if (selectMask & newDataMask)
-        pGC->serialNumber |= GC_CHANGE_SERIAL_BIT;        
-}
-
-
-
 /* CreateScratchGC(pScreen, depth)
     like CreateGC, but doesn't do the default tile or stipple,
 since we can't create them without already having a GC.  any code
diff --git a/dix/swaprep.c b/dix/swaprep.c
index 6f4b277..7d3251a 100644
--- a/dix/swaprep.c
+++ b/dix/swaprep.c
@@ -317,7 +317,7 @@ SQueryPointerReply(ClientPtr pClient, in
     (void)WriteToClient(pClient, size, (char *) pRep);
 }
 
-void
+static void
 SwapTimecoord(xTimecoord* pCoord)
 {
     char n;
@@ -584,7 +584,7 @@ SAllocColorPlanesReply(ClientPtr pClient
     (void)WriteToClient(pClient, size, (char *) pRep);
 }
 
-void
+static void
 SwapRGB(xrgb *prgb)
 {
     char n;
@@ -1159,6 +1159,58 @@ SKeymapNotifyEvent(xEvent *from, xEvent 
     *to = *from;
 }
 
+static void
+SwapConnSetup(xConnSetup *pConnSetup, xConnSetup *pConnSetupT)
+{
+    cpswapl(pConnSetup->release, pConnSetupT->release);
+    cpswapl(pConnSetup->ridBase, pConnSetupT->ridBase);
+    cpswapl(pConnSetup->ridMask, pConnSetupT->ridMask);
+    cpswapl(pConnSetup->motionBufferSize, pConnSetupT->motionBufferSize);
+    cpswaps(pConnSetup->nbytesVendor, pConnSetupT->nbytesVendor);
+    cpswaps(pConnSetup->maxRequestSize, pConnSetupT->maxRequestSize);
+    pConnSetupT->minKeyCode = pConnSetup->minKeyCode;
+    pConnSetupT->maxKeyCode = pConnSetup->maxKeyCode;
+    pConnSetupT->numRoots = pConnSetup->numRoots;
+    pConnSetupT->numFormats = pConnSetup->numFormats;
+    pConnSetupT->imageByteOrder = pConnSetup->imageByteOrder;
+    pConnSetupT->bitmapBitOrder = pConnSetup->bitmapBitOrder;
+    pConnSetupT->bitmapScanlineUnit = pConnSetup->bitmapScanlineUnit;
+    pConnSetupT->bitmapScanlinePad = pConnSetup->bitmapScanlinePad;
+}
+
+static void
+SwapWinRoot(xWindowRoot *pRoot, xWindowRoot *pRootT)
+{
+    cpswapl(pRoot->windowId, pRootT->windowId);
+    cpswapl(pRoot->defaultColormap, pRootT->defaultColormap);
+    cpswapl(pRoot->whitePixel, pRootT->whitePixel);
+    cpswapl(pRoot->blackPixel, pRootT->blackPixel);
+    cpswapl(pRoot->currentInputMask, pRootT->currentInputMask);
+    cpswaps(pRoot->pixWidth, pRootT->pixWidth);
+    cpswaps(pRoot->pixHeight, pRootT->pixHeight);
+    cpswaps(pRoot->mmWidth, pRootT->mmWidth);
+    cpswaps(pRoot->mmHeight, pRootT->mmHeight);
+    cpswaps(pRoot->minInstalledMaps, pRootT->minInstalledMaps);
+    cpswaps(pRoot->maxInstalledMaps, pRootT->maxInstalledMaps);
+    cpswapl(pRoot->rootVisualID, pRootT->rootVisualID);
+    pRootT->backingStore = pRoot->backingStore;
+    pRootT->saveUnders = pRoot->saveUnders;
+    pRootT->rootDepth = pRoot->rootDepth;
+    pRootT->nDepths = pRoot->nDepths;
+}
+
+static void
+SwapVisual(xVisualType *pVis, xVisualType *pVisT)
+{
+    cpswapl(pVis->visualID, pVisT->visualID);
+    pVisT->class = pVis->class;
+    pVisT->bitsPerRGB = pVis->bitsPerRGB;
+    cpswaps(pVis->colormapEntries, pVisT->colormapEntries);
+    cpswapl(pVis->redMask, pVisT->redMask);
+    cpswapl(pVis->greenMask, pVisT->greenMask);
+    cpswapl(pVis->blueMask, pVisT->blueMask);
+}
+
 _X_EXPORT void
 SwapConnSetupInfo(
     char 	*pInfo,
@@ -1210,7 +1262,6 @@ SwapConnSetupInfo(
     }
 }
 
-
 void
 WriteSConnectionInfo(ClientPtr pClient, unsigned long size, char *pInfo)
 {
@@ -1227,58 +1278,6 @@ WriteSConnectionInfo(ClientPtr pClient, 
     DEALLOCATE_LOCAL(pInfoTBase);
 }
 
-void
-SwapConnSetup(xConnSetup *pConnSetup, xConnSetup *pConnSetupT)
-{
-    cpswapl(pConnSetup->release, pConnSetupT->release);
-    cpswapl(pConnSetup->ridBase, pConnSetupT->ridBase);
-    cpswapl(pConnSetup->ridMask, pConnSetupT->ridMask);
-    cpswapl(pConnSetup->motionBufferSize, pConnSetupT->motionBufferSize);
-    cpswaps(pConnSetup->nbytesVendor, pConnSetupT->nbytesVendor);
-    cpswaps(pConnSetup->maxRequestSize, pConnSetupT->maxRequestSize);
-    pConnSetupT->minKeyCode = pConnSetup->minKeyCode;
-    pConnSetupT->maxKeyCode = pConnSetup->maxKeyCode;
-    pConnSetupT->numRoots = pConnSetup->numRoots;
-    pConnSetupT->numFormats = pConnSetup->numFormats;
-    pConnSetupT->imageByteOrder = pConnSetup->imageByteOrder;
-    pConnSetupT->bitmapBitOrder = pConnSetup->bitmapBitOrder;
-    pConnSetupT->bitmapScanlineUnit = pConnSetup->bitmapScanlineUnit;
-    pConnSetupT->bitmapScanlinePad = pConnSetup->bitmapScanlinePad;
-}
-
-void
-SwapWinRoot(xWindowRoot *pRoot, xWindowRoot *pRootT)
-{
-    cpswapl(pRoot->windowId, pRootT->windowId);
-    cpswapl(pRoot->defaultColormap, pRootT->defaultColormap);
-    cpswapl(pRoot->whitePixel, pRootT->whitePixel);
-    cpswapl(pRoot->blackPixel, pRootT->blackPixel);
-    cpswapl(pRoot->currentInputMask, pRootT->currentInputMask);
-    cpswaps(pRoot->pixWidth, pRootT->pixWidth);
-    cpswaps(pRoot->pixHeight, pRootT->pixHeight);
-    cpswaps(pRoot->mmWidth, pRootT->mmWidth);
-    cpswaps(pRoot->mmHeight, pRootT->mmHeight);
-    cpswaps(pRoot->minInstalledMaps, pRootT->minInstalledMaps);
-    cpswaps(pRoot->maxInstalledMaps, pRootT->maxInstalledMaps);
-    cpswapl(pRoot->rootVisualID, pRootT->rootVisualID);
-    pRootT->backingStore = pRoot->backingStore;
-    pRootT->saveUnders = pRoot->saveUnders;
-    pRootT->rootDepth = pRoot->rootDepth;
-    pRootT->nDepths = pRoot->nDepths;
-}
-
-void
-SwapVisual(xVisualType *pVis, xVisualType *pVisT)
-{
-    cpswapl(pVis->visualID, pVisT->visualID);
-    pVisT->class = pVis->class;
-    pVisT->bitsPerRGB = pVis->bitsPerRGB;
-    cpswaps(pVis->colormapEntries, pVisT->colormapEntries);
-    cpswapl(pVis->redMask, pVisT->redMask);
-    cpswapl(pVis->greenMask, pVisT->greenMask);
-    cpswapl(pVis->blueMask, pVisT->blueMask);
-}
-
 _X_EXPORT void
 SwapConnSetupPrefix(xConnSetupPrefix *pcspFrom, xConnSetupPrefix *pcspTo)
 {
diff --git a/dix/window.c b/dix/window.c
index 2a82f2e..7d99477 100644
--- a/dix/window.c
+++ b/dix/window.c
@@ -539,7 +539,7 @@ InitRootWindow(WindowPtr pWin)
  * window from which the region came.
  */
 
-void
+static void
 ClippedRegionFromBox(WindowPtr pWin, RegionPtr Rgn,
                      int x, int y,
                      int w, int h)
@@ -836,6 +836,26 @@ CreateWindow(Window wid, WindowPtr pPare
 }
 
 static void
+DisposeWindowOptional (WindowPtr pWin)
+{
+    if (!pWin->optional)
+	return;
+    /*
+     * everything is peachy.  Delete the optional record
+     * and clean up
+     */
+    if (pWin->optional->cursor)
+    {
+	FreeCursor (pWin->optional->cursor, (Cursor)0);
+	pWin->cursorIsNone = FALSE;
+    }
+    else
+	pWin->cursorIsNone = TRUE;
+    xfree (pWin->optional);
+    pWin->optional = NULL;
+}
+
+static void
 FreeWindowResources(WindowPtr pWin)
 {
     ScreenPtr pScreen = pWin->drawable.pScreen;
@@ -2703,6 +2723,30 @@ RealizeTree(WindowPtr pWin)
     }
 }
 
+static WindowPtr windowDisableMapUnmapEvents;
+
+void
+DisableMapUnmapEvents(WindowPtr pWin)
+{
+    assert (windowDisableMapUnmapEvents == NULL);
+    
+    windowDisableMapUnmapEvents = pWin;
+}
+
+void
+EnableMapUnmapEvents(WindowPtr pWin)
+{
+    assert (windowDisableMapUnmapEvents != NULL);
+
+    windowDisableMapUnmapEvents = NULL;
+}
+
+static Bool
+MapUnmapEventsEnabled(WindowPtr pWin)
+{
+    return pWin != windowDisableMapUnmapEvents;
+}
+
 /*****
  * MapWindow
  *    If some other client has selected SubStructureReDirect on the parent
@@ -3203,21 +3247,6 @@ HandleSaveSet(ClientPtr client)
 
 /**
  *
- *  \param x,y  in root
- *  \param box  "return" value
- */
-Bool
-VisibleBoundingBoxFromPoint(WindowPtr pWin, int x, int y, BoxPtr box)
-{
-    if (!pWin->realized)
-	return (FALSE);
-    if (POINT_IN_REGION(pWin->drawable.pScreen, &pWin->clipList, x, y, box))
-	return(TRUE);
-    return(FALSE);
-}
-
-/**
- *
  * \param x,y  in root
  */
 Bool
@@ -3324,30 +3353,6 @@ SendVisibilityNotify(WindowPtr pWin)
     DeliverEvents(pWin, &event, 1, NullWindow);
 }
 
-static WindowPtr windowDisableMapUnmapEvents;
-
-void
-DisableMapUnmapEvents(WindowPtr pWin)
-{
-    assert (windowDisableMapUnmapEvents == NULL);
-    
-    windowDisableMapUnmapEvents = pWin;
-}
-
-void
-EnableMapUnmapEvents(WindowPtr pWin)
-{
-    assert (windowDisableMapUnmapEvents != NULL);
-
-    windowDisableMapUnmapEvents = NULL;
-}
-
-Bool
-MapUnmapEventsEnabled(WindowPtr pWin)
-{
-    return pWin != windowDisableMapUnmapEvents;
-}
-
 #define RANDOM_WIDTH 32
 
 #ifndef NOLOGOHACK
@@ -3700,41 +3705,6 @@ MakeWindowOptional (WindowPtr pWin)
     return TRUE;
 }
 
-void
-DisposeWindowOptional (WindowPtr pWin)
-{
-    if (!pWin->optional)
-	return;
-    /*
-     * everything is peachy.  Delete the optional record
-     * and clean up
-     */
-    /*
-     * TOG changed this code to:
-     *
-     *	    if (pWin->cursorIsNone == FALSE)
-     *		FreeCursor (pWin->optional->cursor, (Cursor)0);
-     *	    pWin->cursorIsNone = TRUE;
-     *
-     * This is blatently wrong; windows without optionals can have
-     * two different cursor values, either None or sharing their
-     * parents cursor.  This difference is controlled by the
-     * cursorIsNone value; when TRUE, the window has no cursor,
-     * when false, it shares its cursor with its parent; TOG
-     * made it impossible for a window to have a cursor without
-     * an optional record.
-     */
-    if (pWin->optional->cursor)
-    {
-	FreeCursor (pWin->optional->cursor, (Cursor)0);
-	pWin->cursorIsNone = FALSE;
-    }
-    else
-	pWin->cursorIsNone = TRUE;
-    xfree (pWin->optional);
-    pWin->optional = NULL;
-}
-
 #ifndef NOLOGOHACK
 static void
 DrawLogo(WindowPtr pWin)
diff --git a/include/dix.h b/include/dix.h
index 5c2c5b8..b412683 100644
--- a/include/dix.h
+++ b/include/dix.h
@@ -220,8 +220,6 @@ extern int dixDestroyPixmap(
     pointer /*value*/,
     XID /*pid*/);
 
-extern void CloseDownRetainedResources(void);
-
 extern void InitClient(
     ClientPtr /*client*/,
     int /*i*/,
@@ -243,25 +241,10 @@ extern void DeleteWindowFromAnySelection
 extern void MarkClientException(
     ClientPtr /*client*/);
 
-extern int GetGeometry(
-    ClientPtr /*client*/,
-    xGetGeometryReply* /* wa */);
-
 extern int SendConnSetup(
     ClientPtr /*client*/,
     char* /*reason*/);
 
-extern int DoGetImage(
-    ClientPtr	/*client*/,
-    int /*format*/,
-    Drawable /*drawable*/,
-    int /*x*/, 
-    int /*y*/, 
-    int /*width*/, 
-    int /*height*/,
-    Mask /*planemask*/,
-    xGetImageReply ** /*im_return*/);
-
 #if defined(DDXBEFORERESET)
 extern void ddxBeforeReset (void);
 #endif
@@ -632,10 +615,6 @@ typedef struct _CallbackProcs {
     DeleteCallbackListProcPtr	DeleteCallbackList;
 } CallbackFuncsRec, *CallbackFuncsPtr;
 
-extern Bool CreateCallbackList(
-    CallbackListPtr * /*pcbl*/,
-    CallbackFuncsPtr /*cbfuncs*/);
-
 extern Bool AddCallback(
     CallbackListPtr * /*pcbl*/,
     CallbackProcPtr /*callback*/,
diff --git a/include/extnsionst.h b/include/extnsionst.h
index 38d4bd7..28ae1d5 100644
--- a/include/extnsionst.h
+++ b/include/extnsionst.h
@@ -85,32 +85,11 @@ extern void NotImplemented (	/* FIXME: t
 	xEvent *,
 	xEvent *);
 
-typedef void (* ExtensionLookupProc)(
-#ifdef EXTENSION_PROC_ARGS
-    EXTENSION_PROC_ARGS
-#else
-    /* args no longer indeterminate */
-    char *name,
-    GCPtr pGC
-#endif
-);
-
-typedef struct _ProcEntry {
-    char *name;
-    ExtensionLookupProc proc;
-} ProcEntryRec, *ProcEntryPtr;
-
-typedef struct _ScreenProcEntry {
-    int num;
-    ProcEntryPtr procList;
-} ScreenProcEntry;
-
 #define    SetGCVector(pGC, VectorElement, NewRoutineAddress, Atom)    \
     pGC->VectorElement = NewRoutineAddress;
 
 #define    GetGCValue(pGC, GCElement)    (pGC->GCElement)
 
-
 extern ExtensionEntry *AddExtension(
     char* /*name*/,
     int /*NumEvents*/,
@@ -128,20 +107,6 @@ extern Bool AddExtensionAlias(
 extern ExtensionEntry *CheckExtension(const char *extname);
 extern ExtensionEntry *GetExtensionEntry(int major);
 
-extern ExtensionLookupProc LookupProc(
-    char* /*name*/,
-    GCPtr /*pGC*/);
-
-extern Bool RegisterProc(
-    char* /*name*/,
-    GCPtr /*pGC*/,
-    ExtensionLookupProc /*proc*/);
-
-extern Bool RegisterScreenProc(
-    char* /*name*/,
-    ScreenPtr /*pScreen*/,
-    ExtensionLookupProc /*proc*/);
-
 extern void DeclareExtensionSecurity(
     char * /*extname*/,
     Bool /*secure*/);
diff --git a/include/gc.h b/include/gc.h
index 6c7add6..3b7e38e 100644
--- a/include/gc.h
+++ b/include/gc.h
@@ -126,11 +126,6 @@ extern int FreeGC(
     pointer /*pGC*/,
     XID /*gid*/);
 
-extern void SetGCMask(
-    GCPtr /*pGC*/,
-    Mask /*selectMask*/,
-    Mask /*newDataMask*/);
-
 extern GCPtr CreateScratchGC(
     ScreenPtr /*pScreen*/,
     unsigned /*depth*/);
diff --git a/include/os.h b/include/os.h
index d4eed22..7399436 100644
--- a/include/os.h
+++ b/include/os.h
@@ -348,12 +348,6 @@ extern void InitAuthorization(char * /*f
 
 extern void RegisterAuthorizations(void);
 
-extern XID AuthorizationToID (
-	unsigned short	name_length,
-	char		*name,
-	unsigned short	data_length,
-	char		*data);
-
 extern int AuthorizationFromID (
 	XID 		id,
 	unsigned short	*name_lenp,
@@ -402,14 +396,6 @@ extern int ddxProcessArgument(int /*argc
 
 extern void ddxUseMsg(void);
 
-/*
- *  idiom processing stuff
- */
-
-extern xReqPtr PeekNextRequest(xReqPtr req, ClientPtr client, Bool readmore);
-
-extern void SkipRequests(xReqPtr req, ClientPtr client, int numskipped);
-
 /* int ReqLen(xReq *req, ClientPtr client)
  * Given a pointer to a *complete* request, return its length in bytes.
  * Note that if the request is a big request (as defined in the Big
diff --git a/include/swaprep.h b/include/swaprep.h
index 8a9dcf0..bebd3a8 100644
--- a/include/swaprep.h
+++ b/include/swaprep.h
@@ -91,9 +91,6 @@ extern void SQueryPointerReply(
     int /* size */,
     xQueryPointerReply * /* pRep */);
 
-extern void SwapTimecoord(
-    xTimecoord * /* pCoord */);
-
 extern void SwapTimeCoordWrite(
     ClientPtr /* pClient */,
     int /* size */,
@@ -174,9 +171,6 @@ extern void SAllocColorPlanesReply(
     int /* size */,
     xAllocColorPlanesReply * /* pRep */);
 
-extern void SwapRGB(
-    xrgb * /* prgb */);
-
 extern void SQColorsExtend(
     ClientPtr /* pClient */,
     int /* size */,
@@ -255,18 +249,6 @@ extern void WriteSConnectionInfo(
     unsigned long /* size */,
     char * /* pInfo */);
 
-extern void SwapConnSetup(
-    xConnSetup * /* pConnSetup */,
-    xConnSetup * /* pConnSetupT */);
-
-extern void SwapWinRoot(
-    xWindowRoot * /* pRoot */,
-    xWindowRoot * /* pRootT */);
-
-extern void SwapVisual(
-    xVisualType * /* pVis */,
-    xVisualType * /* pVisT */);
-
 extern void SwapConnSetupPrefix(
     xConnSetupPrefix * /* pcspFrom */,
     xConnSetupPrefix * /* pcspTo */);
diff --git a/include/window.h b/include/window.h
index bddeb25..cd8c5b2 100644
--- a/include/window.h
+++ b/include/window.h
@@ -93,14 +93,6 @@ extern Bool CreateRootWindow(
 extern void InitRootWindow(
     WindowPtr /*pWin*/);
 
-extern void ClippedRegionFromBox(
-    WindowPtr /*pWin*/,
-    RegionPtr /*Rgn*/,
-    int /*x*/,
-    int /*y*/,
-    int /*w*/,
-    int /*h*/);
-
 typedef WindowPtr (* RealChildHeadProc) (WindowPtr pWin);
 
 void RegisterRealChildHeadProc (RealChildHeadProc proc);
@@ -205,12 +197,6 @@ extern void UnmapSubwindows(
 extern void HandleSaveSet(
     ClientPtr /*client*/);
 
-extern Bool VisibleBoundingBoxFromPoint(
-    WindowPtr /*pWin*/,
-    int /*x*/,
-    int /*y*/,
-    BoxPtr /*box*/);
-
 extern Bool PointInWindowIsVisible(
     WindowPtr /*pWin*/,
     int /*x*/,
@@ -235,9 +221,6 @@ extern void CheckWindowOptionalNeed(
 extern Bool MakeWindowOptional(
     WindowPtr /*pWin*/);
 
-extern void DisposeWindowOptional(
-    WindowPtr /*pWin*/);
-
 extern WindowPtr MoveWindowInStack(
     WindowPtr /*pWin*/,
     WindowPtr /*pNextSib*/);
@@ -271,7 +254,5 @@ extern void DisableMapUnmapEvents(
     WindowPtr /* pWin */ );
 extern void EnableMapUnmapEvents(
     WindowPtr /* pWin */ );
-extern Bool MapUnmapEventsEnabled(
-    WindowPtr /* pWin */ );
 
 #endif /* WINDOW_H */
diff --git a/os/access.c b/os/access.c
index db5ca31..221b8cb 100644
--- a/os/access.c
+++ b/os/access.c
@@ -234,8 +234,8 @@ static Bool NewHost(int /*family*/,
 		    int /*len*/,
 		    int /* addingLocalHosts */);
 
-int LocalClientCredAndGroups(ClientPtr client, int *pUid, int *pGid, 
-                             int **pSuppGids, int *nSuppGids);
+static int LocalClientCredAndGroups(ClientPtr client, int *pUid, int *pGid, 
+				    int **pSuppGids, int *nSuppGids);
 
 
 /* XFree86 bug #156: To keep track of which hosts were explicitly requested in
@@ -1431,7 +1431,7 @@ LocalClientCred(ClientPtr client, int *p
  *
  * Used by localuser & localgroup ServerInterpreted access control forms below
  */
-int
+static int
 LocalClientCredAndGroups(ClientPtr client, int *pUid, int *pGid, 
 			 int **pSuppGids, int *nSuppGids)
 {
diff --git a/os/auth.c b/os/auth.c
index bf33b7e..b06333e 100644
--- a/os/auth.c
+++ b/os/auth.c
@@ -255,26 +255,6 @@ ResetAuthorization (void)
     ShouldLoadAuth = TRUE;
 }
 
-XID
-AuthorizationToID (
-	unsigned short	name_length,
-	char		*name,
-	unsigned short	data_length,
-	char		*data)
-{
-    int	i;
-
-    for (i = 0; i < NUM_AUTHORIZATION; i++) {
-    	if (protocols[i].name_length == name_length &&
-	    memcmp (protocols[i].name, name, (int) name_length) == 0 &&
-	    protocols[i].ToID)
-    	{
-	    return (*protocols[i].ToID) (data_length, data);
-    	}
-    }
-    return (XID) ~0L;
-}
-
 int
 AuthorizationFromID (
 	XID 		id,
diff --git a/os/io.c b/os/io.c
index 80a151f..4e83e68 100644
--- a/os/io.c
+++ b/os/io.c
@@ -90,6 +90,11 @@ SOFTWARE.
 _X_EXPORT CallbackListPtr       ReplyCallback;
 _X_EXPORT CallbackListPtr       FlushCallback;
 
+static ConnectionInputPtr AllocateInputBuffer(void);
+static ConnectionOutputPtr AllocateOutputBuffer(void);
+static xReqPtr PeekNextRequest(xReqPtr req, ClientPtr client, Bool readmore);
+static void SkipRequests(xReqPtr req, ClientPtr client, int numskipped);
+
 /* check for both EAGAIN and EWOULDBLOCK, because some supposedly POSIX
  * systems are broken and return EWOULDBLOCK when they should return EAGAIN
  */
@@ -635,7 +640,7 @@ ResetCurrentRequest(ClientPtr client)
  *
  **********************/
 
-xReqPtr
+static xReqPtr
 PeekNextRequest(
     xReqPtr req,	/* request we're starting from */
     ClientPtr client,	/* client whose requests we're skipping */
@@ -697,7 +702,7 @@ PeekNextRequest(
 
 _X_EXPORT CallbackListPtr SkippedRequestsCallback = NULL;
 
-void
+static void
 SkipRequests(
     xReqPtr req,	/* last request being skipped */
     ClientPtr client,   /* client whose requests we're skipping */
@@ -1165,7 +1170,7 @@ FlushClient(ClientPtr who, OsCommPtr oc,
     return extraCount; /* return only the amount explicitly requested */
 }
 
-ConnectionInputPtr
+static ConnectionInputPtr
 AllocateInputBuffer(void)
 {
     ConnectionInputPtr oci;
@@ -1186,7 +1191,7 @@ AllocateInputBuffer(void)
     return oci;
 }
 
-ConnectionOutputPtr
+static ConnectionOutputPtr
 AllocateOutputBuffer(void)
 {
     ConnectionOutputPtr oco;
diff --git a/os/osdep.h b/os/osdep.h
index 3d303f9..0984d51 100644
--- a/os/osdep.h
+++ b/os/osdep.h
@@ -210,10 +210,6 @@ extern void FreeOsBuffers(
 
 #include "dix.h"
 
-extern ConnectionInputPtr AllocateInputBuffer(void);
-
-extern ConnectionOutputPtr AllocateOutputBuffer(void);
-
 extern fd_set AllSockets;
 extern fd_set AllClients;
 extern fd_set LastSelectMask;
@@ -293,14 +289,12 @@ extern XID AuthSecurityCheck (AuthCheckA
 /* in xdmcp.c */
 extern void XdmcpUseMsg (void);
 extern int XdmcpOptions(int argc, char **argv, int i);
-extern void XdmcpSetAuthentication (ARRAY8Ptr name);
 extern void XdmcpRegisterConnection (
     int	    type,
     char    *address,
     int	    addrlen);
 extern void XdmcpRegisterAuthorizations (void);
 extern void XdmcpRegisterAuthorization (char *name, int namelen);
-extern void XdmcpRegisterDisplayClass (char *name, int length);
 extern void XdmcpInit (void);
 extern void XdmcpReset (void);
 extern void XdmcpOpenDisplay(int sock);
@@ -313,8 +307,6 @@ extern void XdmcpRegisterAuthentication 
     ValidatorFunc Validator,
     GeneratorFunc Generator,
     AddAuthorFunc AddAuth);
-extern int XdmcpCheckAuthentication (ARRAY8Ptr Name, ARRAY8Ptr Data, int packet_type);
-extern int XdmcpAddAuthorization (ARRAY8Ptr name, ARRAY8Ptr data);
 
 struct sockaddr_in;
 extern void XdmcpRegisterBroadcastAddress (struct sockaddr_in *addr);
diff --git a/os/xdmcp.c b/os/xdmcp.c
index cfc1005..310f33b 100644
--- a/os/xdmcp.c
+++ b/os/xdmcp.c
@@ -197,8 +197,6 @@ static void receive_packet(int /*socketf
 
 static void send_packet(void);
 
-extern void XdmcpDeadSession(char * /*reason*/);
-
 static void timeout(void);
 
 static void restart(void);
@@ -213,10 +211,23 @@ static void XdmcpWakeupHandler(
     int /*i*/,
     pointer /*LastSelectMask*/);
 
-void XdmcpRegisterManufacturerDisplayID(
-    char    * /*name*/,
-    int	    /*length*/);
+/*
+ * Register the Manufacturer display ID
+ */
+
+static ARRAY8 ManufacturerDisplayID;
+
+static void
+XdmcpRegisterManufacturerDisplayID (char *name, int length)
+{
+    int	    i;
 
+    XdmcpDisposeARRAY8 (&ManufacturerDisplayID);
+    if (!XdmcpAllocARRAY8 (&ManufacturerDisplayID, length))
+	return;
+    for (i = 0; i < length; i++)
+	ManufacturerDisplayID.data[i] = (CARD8) name[i];
+}
 
 static unsigned short	xdm_udp_port = XDM_UDP_PORT;
 static Bool	OneSession = FALSE;
@@ -417,7 +428,7 @@ static ARRAY8Ptr	AuthenticationName = &n
 static ARRAY8Ptr	AuthenticationData = &noAuthenticationData;
 static AuthenticationFuncsPtr	AuthenticationFuncs;
 
-void
+static void
 XdmcpSetAuthentication (ARRAY8Ptr name)
 {
     int	i;
@@ -549,7 +560,7 @@ XdmcpRegisterAuthorization (char *name, 
 
 static ARRAY8	DisplayClass;
 
-void
+static void
 XdmcpRegisterDisplayClass (char *name, int length)
 {
     int	    i;
@@ -561,24 +572,6 @@ XdmcpRegisterDisplayClass (char *name, i
 	DisplayClass.data[i] = (CARD8) name[i];
 }
 
-/*
- * Register the Manufacturer display ID
- */
-
-static ARRAY8 ManufacturerDisplayID;
-
-void
-XdmcpRegisterManufacturerDisplayID (char *name, int length)
-{
-    int	    i;
-
-    XdmcpDisposeARRAY8 (&ManufacturerDisplayID);
-    if (!XdmcpAllocARRAY8 (&ManufacturerDisplayID, length))
-	return;
-    for (i = 0; i < length; i++)
-	ManufacturerDisplayID.data[i] = (CARD8) name[i];
-}
-
 /* 
  * initialize XDMCP; create the socket, compute the display
  * number, set up the state machine
@@ -867,7 +860,7 @@ send_packet(void)
  * timeouts, or Keepalive failure.
  */
 
-void
+static void
 XdmcpDeadSession (char *reason)
 {
     ErrorF ("XDM: %s, declaring session dead\n", reason);
@@ -960,21 +953,16 @@ restart(void)
     send_packet();
 }
 
-int
-XdmcpCheckAuthentication (
-    ARRAY8Ptr	Name,
-    ARRAY8Ptr	Data,
-    int	packet_type)
+static int
+XdmcpCheckAuthentication (ARRAY8Ptr Name, ARRAY8Ptr Data, int packet_type)
 {
     return (XdmcpARRAY8Equal (Name, AuthenticationName) &&
 	    (AuthenticationName->length == 0 ||
 	     (*AuthenticationFuncs->Validator) (AuthenticationData, Data, packet_type)));
 }
 
-int
-XdmcpAddAuthorization (
-    ARRAY8Ptr	name,
-    ARRAY8Ptr	data)
+static int
+XdmcpAddAuthorization (ARRAY8Ptr name, ARRAY8Ptr data)
 {
     AddAuthorFunc AddAuth;
 
diff --git a/record/set.c b/record/set.c
index 0ebb088..07a3a63 100644
--- a/record/set.c
+++ b/record/set.c
@@ -164,10 +164,10 @@ BitVectorIterateSet(RecordSetPtr pSet, R
     return (RecordSetIteratePtr)(long)(pInterval->last + 1);
 }
 
-RecordSetOperations BitVectorSetOperations = {
+static RecordSetOperations BitVectorSetOperations = {
     BitVectorDestroySet, BitVectorIsMemberOfSet, BitVectorIterateSet };
 
-RecordSetOperations BitVectorNoFreeOperations = {
+static RecordSetOperations BitVectorNoFreeOperations = {
     NoopDestroySet, BitVectorIsMemberOfSet, BitVectorIterateSet };
 
 static int
@@ -277,10 +277,10 @@ IntervalListIterateSet(RecordSetPtr pSet
 	return (RecordSetIteratePtr)NULL;
 }
 
-RecordSetOperations IntervalListSetOperations = {
+static RecordSetOperations IntervalListSetOperations = {
     IntervalListDestroySet, IntervalListIsMemberOfSet, IntervalListIterateSet };
 
-RecordSetOperations IntervalListNoFreeOperations = {
+static RecordSetOperations IntervalListNoFreeOperations = {
     NoopDestroySet, IntervalListIsMemberOfSet, IntervalListIterateSet };
 
 static int
diff-tree 04b87d6dfae02e4ecdb5216d12c6cdafd1e8c2b4 (from af769892a91c9af59de53ca3bcd77fc4967daffb)
Author: Adam Jackson <ajax at benzedrine.nwnk.net>
Date:   Sun Mar 25 17:57:22 2007 -0400

    Static and dead code cleaup for Xext/

diff --git a/Xext/appgroup.c b/Xext/appgroup.c
index bb7a73c..7bd2055 100644
--- a/Xext/appgroup.c
+++ b/Xext/appgroup.c
@@ -116,8 +116,7 @@ int XagAppGroupFree(
     return Success;
 }
 
-/* static */
-void XagClientStateChange(
+static void XagClientStateChange(
     CallbackListPtr* pcbl,
     pointer nulldata,
     pointer calldata)
@@ -172,21 +171,6 @@ void XagClientStateChange(
     }
 }
 
-void
-XagExtensionInit(INITARGS)
-{
-    if (AddExtension (XAGNAME,
-		      0,
-		      XagNumberErrors,
-		      ProcXagDispatch,
-		      SProcXagDispatch,
-		      XagResetProc,
-		      StandardMinorOpcode)) {
-	RT_APPGROUP = CreateNewResourceType (XagAppGroupFree);
-	XaceRegisterCallback(XACE_AUTH_AVAIL, XagCallClientStateChange, NULL);
-    }
-}
-
 /*ARGSUSED*/
 static 
 void XagResetProc(
@@ -393,8 +377,7 @@ int AttrValidate(
     return client->noClientException;
 }
 
-/* static */
-int ProcXagCreate (
+static int ProcXagCreate (
     register ClientPtr client)
 {
     REQUEST (xXagCreateReq);
@@ -425,8 +408,7 @@ int ProcXagCreate (
     return client->noClientException;
 }
 
-/* static */
-int ProcXagDestroy(
+static int ProcXagDestroy(
     register ClientPtr client)
 {
     AppGroupPtr pAppGrp;
@@ -743,18 +725,7 @@ XID XagId(
     return (client->appgroup ? client->appgroup->appgroupId : 0);
 }
 
-void XagGetDeltaInfo(
-    ClientPtr client,
-    CARD32* buf)
-{
-    *buf++ = (CARD32) client->appgroup->default_root;
-    *buf++ = (CARD32) client->appgroup->root_visual;
-    *buf++ = (CARD32) client->appgroup->default_colormap;
-    *buf++ = (CARD32) client->appgroup->black_pixel;
-    *buf = (CARD32) client->appgroup->white_pixel;
-}
-
-void XagCallClientStateChange(
+static void XagCallClientStateChange(
     CallbackListPtr *pcbl,
     pointer nulldata,
     pointer calldata)
@@ -785,3 +756,18 @@ void XagCallClientStateChange(
 	XagClientStateChange (NULL, NULL, (pointer)&clientinfo);
     }
 }
+
+void
+XagExtensionInit(INITARGS)
+{
+    if (AddExtension (XAGNAME,
+		      0,
+		      XagNumberErrors,
+		      ProcXagDispatch,
+		      SProcXagDispatch,
+		      XagResetProc,
+		      StandardMinorOpcode)) {
+	RT_APPGROUP = CreateNewResourceType (XagAppGroupFree);
+	XaceRegisterCallback(XACE_AUTH_AVAIL, XagCallClientStateChange, NULL);
+    }
+}
diff --git a/Xext/appgroup.h b/Xext/appgroup.h
index a875068..778da5d 100644
--- a/Xext/appgroup.h
+++ b/Xext/appgroup.h
@@ -50,12 +50,6 @@ extern ClientPtr XagLeader(
     ClientPtr			/* client */
 );
 
-extern void XagCallClientStateChange(
-    CallbackListPtr *		/* pcbl */,
-    pointer 			/* nulldata */,
-    pointer 			/* calldata */
-);
-
 extern Bool XagIsControlledRoot (
     ClientPtr			/* client */,
     WindowPtr			/* pParent */
@@ -65,22 +59,6 @@ extern XID XagId (
     ClientPtr			/* client */
 );
 
-extern void XagGetDeltaInfo (
-    ClientPtr			/* client */,
-    CARD32*			/* buf */
-);
-
-extern void XagClientStateChange(
-    CallbackListPtr* pcbl,
-    pointer nulldata,
-    pointer calldata);
-
-extern int ProcXagCreate (
-    register ClientPtr client);
-
-extern int ProcXagDestroy(
-    register ClientPtr client);
-
 _XFUNCPROTOEND
 
 #endif /* _APPGROUP_SRV_H_ */
diff --git a/Xext/panoramiX.c b/Xext/panoramiX.c
index 85f5913..95df043 100644
--- a/Xext/panoramiX.c
+++ b/Xext/panoramiX.c
@@ -77,7 +77,7 @@ int 		PanoramiXPixHeight = 0;
 _X_EXPORT int 	PanoramiXNumScreens = 0;
 
 _X_EXPORT PanoramiXData *panoramiXdataPtr = NULL;
-RegionRec   		PanoramiXScreenRegion = {{0, 0, 0, 0}, NULL};
+static RegionRec   	PanoramiXScreenRegion = {{0, 0, 0, 0}, NULL};
 
 static int		PanoramiXNumDepths;
 static DepthPtr		PanoramiXDepths;
@@ -109,7 +109,6 @@ static void PanoramiXResetProc(Extension
 #include "panoramiXh.h"
 
 int (* SavedProcVector[256]) (ClientPtr client) = { NULL, };
-ScreenInfo *GlobalScrInfo = NULL;
 
 static int PanoramiXGCIndex = -1;
 static int PanoramiXScreenIndex = -1;
@@ -135,7 +134,7 @@ static void XineramaChangeClip(GCPtr, in
 static void XineramaDestroyClip(GCPtr);
 static void XineramaCopyClip(GCPtr, GCPtr);
 
-GCFuncs XineramaGCFuncs = {
+static GCFuncs XineramaGCFuncs = {
     XineramaValidateGC, XineramaChangeGC, XineramaCopyGC, XineramaDestroyGC,
     XineramaChangeClip, XineramaDestroyClip, XineramaCopyClip
 };
@@ -168,7 +167,7 @@ XineramaCloseScreen (int i, ScreenPtr pS
     return (*pScreen->CloseScreen) (i, pScreen);
 }
 
-Bool
+static Bool
 XineramaCreateGC(GCPtr pGC)
 {
     ScreenPtr pScreen = pGC->pScreen;
@@ -330,8 +329,6 @@ XineramaDestroyClip(GCPtr pGC)
     Xinerama_GC_FUNC_EPILOGUE (pGC);
 }
 
-
-
 _X_EXPORT int
 XineramaDeleteResource(pointer data, XID id)
 {
@@ -339,32 +336,11 @@ XineramaDeleteResource(pointer data, XID
     return 1;
 }
 
-
-static Bool 
-XineramaFindIDOnAnyScreen(pointer resource, XID id, pointer privdata)
-{
-    PanoramiXRes *res = (PanoramiXRes*)resource;
-    int j;
-
-    FOR_NSCREENS(j) 
-	if(res->info[j].id == *((XID*)privdata)) return TRUE;
-    
-    return FALSE;
-}
-
-PanoramiXRes *
-PanoramiXFindIDOnAnyScreen(RESTYPE type, XID id)
-{
-    return LookupClientResourceComplex(clients[CLIENT_ID(id)], type,
-		XineramaFindIDOnAnyScreen, &id);
-}
-
 typedef struct {
    int screen;
    int id;
 } PanoramiXSearchData; 
 
-
 static Bool 
 XineramaFindIDByScrnum(pointer resource, XID id, pointer privdata)
 {
@@ -389,23 +365,6 @@ PanoramiXFindIDByScrnum(RESTYPE type, XI
 		XineramaFindIDByScrnum, &data);
 }
 
-WindowPtr
-PanoramiXChangeWindow(int ScrnNum, WindowPtr pWin)
-{
-    int num = pWin->drawable.pScreen->myNum;
-
-    if(num != ScrnNum) {
-	PanoramiXRes	*win;
-
-	win = PanoramiXFindIDByScrnum(XRT_WINDOW, pWin->drawable.id, num);
-
-        if (win) 
-           pWin = (WindowPtr) LookupIDByType(win->info[ScrnNum].id, RT_WINDOW);
-    }
-  
-    return pWin;
-}
-
 typedef struct _connect_callback_list {
     void (*func)(void);
     struct _connect_callback_list *next;
@@ -496,7 +455,6 @@ void PanoramiXExtensionInit(int argc, ch
     if (noPanoramiXExtension) 
 	return;
 
-    GlobalScrInfo = &screenInfo;		/* For debug visibility */
     PanoramiXNumScreens = screenInfo.numScreens;
     if (PanoramiXNumScreens == 1) {		/* Only 1 screen 	*/
 	noPanoramiXExtension = TRUE;
diff --git a/Xext/panoramiX.h b/Xext/panoramiX.h
index 7b33392..3ad90fa 100644
--- a/Xext/panoramiX.h
+++ b/Xext/panoramiX.h
@@ -94,18 +94,6 @@ typedef struct {
     (a).root = WindowTable[0]->drawable.id;          \
 }
 
-#define FORCE_WIN(a) {                                  \
-    if ((win = PanoramiXFindIDOnAnyScreen(XRT_WINDOW, a))) { \
-        (a) = win->info[0].id; /* Real ID */       	   \
-    }                                                      \
-}
-
-#define FORCE_CMAP(a) {                                  \
-    if ((win = PanoramiXFindIDOnAnyScreen(XRT_COLORMAP, a))) { \
-        (a) = win->info[0].id; /* Real ID */       	   \
-    }                                                      \
-}
-
 #define IS_SHARED_PIXMAP(r) (((r)->type == XRT_PIXMAP) && (r)->u.pix.shared)
 
 #define SKIP_FAKE_WINDOW(a) if(!LookupIDByType(a, XRT_WINDOW)) return
diff --git a/Xext/panoramiXh.h b/Xext/panoramiXh.h
index 6cee650..1a76a45 100644
--- a/Xext/panoramiXh.h
+++ b/Xext/panoramiXh.h
@@ -19,10 +19,10 @@ extern int PanoramiXGetGeometry(ClientPt
 extern int PanoramiXTranslateCoords(ClientPtr client);	
 extern int PanoramiXCreatePixmap(ClientPtr client);
 extern int PanoramiXFreePixmap(ClientPtr client);
-extern int PanoramiXCreateGC(ClientPtr client);
 extern int PanoramiXChangeGC(ClientPtr client);
 extern int PanoramiXCopyGC(ClientPtr client);
 extern int PanoramiXCopyColormapAndFree(ClientPtr client);
+extern int PanoramiXCreateGC(ClientPtr client);
 extern int PanoramiXSetDashes(ClientPtr client);
 extern int PanoramiXSetClipRectangles(ClientPtr client);
 extern int PanoramiXFreeGC(ClientPtr client);
@@ -64,7 +64,6 @@ PROC_EXTERN(ProcPanoramiXGetScreenSize);
  
 PROC_EXTERN(ProcXineramaQueryScreens);
 PROC_EXTERN(ProcXineramaIsActive);
-extern Bool XineramaCreateGC(GCPtr pGC);
 
 extern int SProcPanoramiXDispatch(ClientPtr client);
 
@@ -72,6 +71,4 @@ extern char *ConnectionInfo;
 extern int connBlockScreenStart;
 extern xConnSetupPrefix connSetupPrefix;
 
-extern ScreenInfo *GlobalScrInfo;
 extern int (* SavedProcVector[256]) (ClientPtr client);
-
diff --git a/Xext/panoramiXsrv.h b/Xext/panoramiXsrv.h
index bb032cf..ae90244 100644
--- a/Xext/panoramiXsrv.h
+++ b/Xext/panoramiXsrv.h
@@ -12,14 +12,11 @@ extern int PanoramiXNumScreens;
 extern PanoramiXData *panoramiXdataPtr;
 extern int PanoramiXPixWidth;
 extern int PanoramiXPixHeight;
-extern RegionRec PanoramiXScreenRegion;
 extern XID *PanoramiXVisualTable;
 
 extern void PanoramiXConsolidate(void);
 extern Bool PanoramiXCreateConnectionBlock(void);
 extern PanoramiXRes * PanoramiXFindIDByScrnum(RESTYPE, XID, int);
-extern PanoramiXRes * PanoramiXFindIDOnAnyScreen(RESTYPE, XID);
-extern WindowPtr PanoramiXChangeWindow(int, WindowPtr);
 extern Bool XineramaRegisterConnectionBlockCallback(void (*func)(void));
 extern int XineramaDeleteResource(pointer, XID);
 
diff --git a/Xext/saver.c b/Xext/saver.c
index 7e3ebf4..a9f1dd3 100644
--- a/Xext/saver.c
+++ b/Xext/saver.c
@@ -66,7 +66,7 @@ static unsigned char ScreenSaverReqCode 
 #endif
 static int ScreenSaverEventBase = 0;
 
-extern DISPATCH_PROC(ProcScreenSaverQueryInfo);
+static DISPATCH_PROC(ProcScreenSaverQueryInfo);
 static DISPATCH_PROC(ProcScreenSaverDispatch);
 static DISPATCH_PROC(ProcScreenSaverQueryVersion);
 static DISPATCH_PROC(ProcScreenSaverSelectInput);
@@ -774,7 +774,7 @@ ProcScreenSaverQueryVersion (client)
     return (client->noClientException);
 }
 
-int
+static int
 ProcScreenSaverQueryInfo (client)
     register ClientPtr	client;
 {
diff --git a/Xext/security.c b/Xext/security.c
index 7202d39..c17a438 100644
--- a/Xext/security.c
+++ b/Xext/security.c
@@ -77,7 +77,7 @@ typedef struct {
 #define AUTHID(client) \
     (((SecurityClientStateRec*)STATEPTR(client))->authId)
 
-CallbackListPtr SecurityValidateGroupCallback = NULL;  /* see security.h */
+static CallbackListPtr SecurityValidateGroupCallback = NULL;
 
 RESTYPE SecurityAuthorizationResType; /* resource type for authorizations */
 
diff --git a/Xext/securitysrv.h b/Xext/securitysrv.h
index 7c6f432..67d864e 100644
--- a/Xext/securitysrv.h
+++ b/Xext/securitysrv.h
@@ -72,15 +72,6 @@ typedef struct {
     struct _OtherClients *eventClients; /* clients wanting events */
 } SecurityAuthorizationRec, *SecurityAuthorizationPtr;
 
-/* The following callback is called when a GenerateAuthorization request
- * is processed to sanity check the group argument.  The call data will
- * be a pointer to a SecurityValidateGroupInfoRec (below).  
- * Functions registered on this callback are expected to examine the
- * group and set the valid field to TRUE if they recognize the group as a
- * legitimate group.  If they don't recognize it, they should not change the
- * valid field.
- */
-extern CallbackListPtr SecurityValidateGroupCallback;
 typedef struct {
     XID group;	/* the group that was sent in GenerateAuthorization */
     Bool valid; /* did anyone recognize it? if so, set to TRUE */
diff --git a/Xext/xace.c b/Xext/xace.c
index 6fc5c12..6385631 100644
--- a/Xext/xace.c
+++ b/Xext/xace.c
@@ -37,10 +37,10 @@ CallbackListPtr XaceHooks[XACE_NUM_HOOKS
  * from guessing extension major opcodes and using the extension even though
  * the extension can't be listed or queried.
  */
-int (*UntrustedProcVector[256])(
+static int (*UntrustedProcVector[256])(
     ClientPtr /*client*/
 );
-int (*SwappedUntrustedProcVector[256])(
+static int (*SwappedUntrustedProcVector[256])(
     ClientPtr /*client*/
 );
 
diff --git a/Xext/xace.h b/Xext/xace.h
index 7231b04..4143cd4 100644
--- a/Xext/xace.h
+++ b/Xext/xace.h
@@ -82,16 +82,6 @@ extern int XaceHook(
 /* From the original Security extension...
  */
 
-/* Proc vectors for untrusted clients, swapped and unswapped versions.
- * These are the same as the normal proc vectors except that extensions
- * that haven't declared themselves secure will have ProcBadRequest plugged
- * in for their major opcode dispatcher.  This prevents untrusted clients
- * from guessing extension major opcodes and using the extension even though
- * the extension can't be listed or queried.
- */
-extern int (*UntrustedProcVector[256])(ClientPtr client);
-extern int (*SwappedUntrustedProcVector[256])(ClientPtr client);
-
 extern void XaceCensorImage(
     ClientPtr client,
     RegionPtr pVisibleRegion,
diff --git a/Xext/xevie.c b/Xext/xevie.c
index 2fd68f8..7922913 100644
--- a/Xext/xevie.c
+++ b/Xext/xevie.c
@@ -105,7 +105,7 @@ typedef struct {
 } xevieKeycQueueRec, *xevieKeycQueuePtr;
 
 #define KEYC_QUEUE_SIZE	    100
-xevieKeycQueueRec keycq[KEYC_QUEUE_SIZE] = {{0, NULL}};
+static xevieKeycQueueRec keycq[KEYC_QUEUE_SIZE] = {{0, NULL}};
 static int keycqHead = 0, keycqTail = 0;
 
 static int              ProcDispatch (ClientPtr), SProcDispatch (ClientPtr);
diff-tree af769892a91c9af59de53ca3bcd77fc4967daffb (from 62224e39727fd6f1cf11a461983662f615a9fea1)
Author: Adam Jackson <ajax at benzedrine.nwnk.net>
Date:   Sun Mar 25 17:56:32 2007 -0400

    Static and dead code cleanup from mi/

diff --git a/mi/mi.h b/mi/mi.h
index 53b5c44..c71c9b7 100644
--- a/mi/mi.h
+++ b/mi/mi.h
@@ -85,18 +85,6 @@ extern RegionPtr miCopyArea(
     int /*yOut*/
 );
 
-extern void miOpqStipDrawable(
-    DrawablePtr /*pDraw*/,
-    GCPtr /*pGC*/,
-    RegionPtr /*prgnSrc*/,
-    MiBits * /*pbits*/,
-    int /*srcx*/,
-    int /*w*/,
-    int /*h*/,
-    int /*dstx*/,
-    int /*dsty*/
-);
-
 extern RegionPtr miCopyPlane(
     DrawablePtr /*pSrcDrawable*/,
     DrawablePtr /*pDstDrawable*/,
@@ -144,15 +132,6 @@ extern void miRecolorCursor(
 
 /* midash.c */
 
-extern miDashPtr miDashLine(
-    int /*npt*/,
-    DDXPointPtr /*ppt*/,
-    unsigned int /*nDash*/,
-    unsigned char * /*pDash*/,
-    unsigned int /*offset*/,
-    int * /*pnseg*/
-);
-
 extern void miStepDash(
     int /*dist*/,
     int * /*pDashIndex*/,
@@ -326,16 +305,6 @@ extern void miPolySegment(
 
 /* mipolytext.c */
 
-extern int miPolyText(
-    DrawablePtr /*pDraw*/,
-    GCPtr /*pGC*/,
-    int /*x*/,
-    int /*y*/,
-    int /*count*/,
-    char * /*chars*/,
-    FontEncoding /*fontEncoding*/
-);
-
 extern int miPolyText8(
     DrawablePtr /*pDraw*/,
     GCPtr /*pGC*/,
@@ -354,16 +323,6 @@ extern int miPolyText16(
     unsigned short * /*chars*/
 );
 
-extern int miImageText(
-    DrawablePtr /*pDraw*/,
-    GCPtr /*pGC*/,
-    int /*x*/,
-    int /*y*/,
-    int /*count*/,
-    char * /*chars*/,
-    FontEncoding /*fontEncoding*/
-);
-
 extern void miImageText8(
     DrawablePtr /*pDraw*/,
     GCPtr /*pGC*/,
@@ -403,10 +362,6 @@ extern Bool miRectAlloc(
     int /*n*/
 );
 
-extern void miSetExtents(
-    RegionPtr /*pReg*/
-);
-
 extern int miFindMaxBand(
     RegionPtr /*prgn*/
 );
@@ -417,7 +372,6 @@ extern Bool miValidRegion(
 );
 #endif
 
-extern Bool miRegionDataCopy(RegionPtr dst, RegionPtr src);
 extern Bool miRegionBroken(RegionPtr pReg);
 
 /* miscrinit.c */
@@ -432,11 +386,6 @@ extern Bool miModifyPixmapHeader(
     pointer /*pPixData*/
 );
 
-extern Bool miCloseScreen(
-    int /*index*/,
-    ScreenPtr /*pScreen*/
-);
-
 extern Bool miCreateScreenResources(
     ScreenPtr /*pScreen*/
 );
diff --git a/mi/miarc.c b/mi/miarc.c
index 8b6d8c0..2bbbb0e 100644
--- a/mi/miarc.c
+++ b/mi/miarc.c
@@ -425,15 +425,8 @@ static unsigned long lrustamp;
 static arcCacheRec *lastCacheHit = &arcCache[0];
 static RESTYPE cacheType;
 
-/*
- * External so it can be called when low on memory.
- * Call with a zero ID in that case.
- */
-/*ARGSUSED*/
-int
-miFreeArcCache (data, id)
-    pointer data;
-    XID	    id;
+static int
+miFreeArcCache (pointer data, XID id)
 {
     int k;
     arcCacheRec *cent;
@@ -3136,8 +3129,8 @@ struct finalSpanChunk {
 
 static struct finalSpanChunk	*chunks;
 
-struct finalSpan *
-realAllocSpan ()
+static struct finalSpan *
+realAllocSpan (void)
 {
 	struct finalSpanChunk	*newChunk;
 	struct finalSpan	*span;
diff --git a/mi/mibitblt.c b/mi/mibitblt.c
index e4b1407..e61855a 100644
--- a/mi/mibitblt.c
+++ b/mi/mibitblt.c
@@ -400,13 +400,9 @@ miGetPlane(
  * Note how the clipped out bits of the bitmap are always the background
  * color so that the stipple never causes FillRect to draw them.
  */
-void
-miOpqStipDrawable(pDraw, pGC, prgnSrc, pbits, srcx, w, h, dstx, dsty)
-    DrawablePtr pDraw;
-    GCPtr	pGC;
-    RegionPtr	prgnSrc;
-    MiBits	*pbits;
-    int		srcx, w, h, dstx, dsty;
+static void
+miOpqStipDrawable(DrawablePtr pDraw, GCPtr pGC, RegionPtr prgnSrc,
+		  MiBits *pbits, int srcx, int w, int h, int dstx, int dsty)
 {
     int		oldfill, i;
     unsigned long oldfg;
diff --git a/mi/midash.c b/mi/midash.c
index 6dd161a..912fb03 100644
--- a/mi/midash.c
+++ b/mi/midash.c
@@ -54,196 +54,6 @@ SOFTWARE.
 
 static miDashPtr CheckDashStorage(miDashPtr *ppseg, int nseg, int *pnsegMax);
 
-/* return a list of DashRec.  there will be an extra
-entry at the end holding the last point of the polyline.
-   this means that the code that actually draws dashes can
-get a pair of points for every dash.  only the point in the last
-dash record is useful; the other fields are not used.
-   nseg is the number of segments, not the number of points.
-
-example:
-
-   dash1.start
-   dash2.start
-   dash3.start
-   last-point
-
-defines a list of segments
-   (dash1.pt, dash2.pt)
-   (dash2.pt, dash3.pt)
-   (dash3.pt, last-point)
-and nseg == 3.
-
-NOTE:
-    EVEN_DASH == ~ODD_DASH
-
-NOTE ALSO:
-    miDashLines may return 0 segments, going from pt[0] to pt[0] with one dash.
-*/
-
-miDashPtr
-miDashLine(npt, ppt, nDash, pDash, offset, pnseg)
-int npt;
-DDXPointPtr ppt;
-unsigned int nDash;
-unsigned char *pDash;
-unsigned int offset;
-int *pnseg;
-{
-    DDXPointRec pt1, pt2;
-    int lenCur;		/* npt used from this dash */
-    int lenMax;		/* npt in this dash */
-    int iDash = 0;	/* index of current dash */
-    int which;		/* EVEN_DASH or ODD_DASH */
-    miDashPtr pseg;	/* list of dash segments */
-    miDashPtr psegBase;	/* start of list */
-    int nseg = 0;	/* number of dashes so far */
-    int nsegMax = 0;	/* num segs we can fit in this list */
-
-    int x, y, len;
-    int adx, ady, signdx, signdy;
-    int du, dv, e1, e2, e, base_e = 0;
-
-    lenCur = offset;
-    which = EVEN_DASH;
-    while(lenCur >= pDash[iDash])
-    {
-	lenCur -= pDash[iDash];
-	iDash++;
-	if (iDash >= nDash)
-	    iDash = 0;
-	which = ~which;
-    }
-    lenMax = pDash[iDash];
-
-    psegBase = (miDashPtr)NULL;
-    pt2 = ppt[0];		/* just in case there is only one point */
-
-    while(--npt)
-    {
-	if (PtEqual(ppt[0], ppt[1]))
-	{
-	    ppt++;
-	    continue;		/* no duplicated points in polyline */
-	}
-	pt1 = *ppt++;
-	pt2 = *ppt;
-
-	adx = pt2.x - pt1.x;
-	ady = pt2.y - pt1.y;
-	signdx = sign(adx);
-	signdy = sign(ady);
-	adx = abs(adx);
-	ady = abs(ady);
-
-	if (adx > ady)
-	{
-	    du = adx;
-	    dv = ady;
-	    len = adx;
-	}
-	else
-	{
-	    du = ady;
-	    dv = adx;
-	    len = ady;
-	}
-
-	e1 = dv * 2;
-	e2 = e1 - 2*du;
-	e = e1 - du;
-	x = pt1.x;
-	y = pt1.y;
-
-	nseg++;
-	pseg = CheckDashStorage(&psegBase, nseg, &nsegMax);
-	if (!pseg)
-	    return (miDashPtr)NULL;
-	pseg->pt = pt1;
-	pseg->e1 = e1;
-	pseg->e2 = e2;
-	base_e = pseg->e = e;
-	pseg->which = which;
-	pseg->newLine = 1;
-
-	while (len--)
-	{
-	    if (adx > ady)
-	    {
-		/* X_AXIS */
-		if (((signdx > 0) && (e < 0)) ||
-		    ((signdx <=0) && (e <=0))
-		   )
-		{
-		    e += e1;
-		}
-		else
-		{
-		    y += signdy;
-		    e += e2;
-		}
-		x += signdx;
-	    }
-	    else
-	    {
-		/* Y_AXIS */
-		if (((signdx > 0) && (e < 0)) ||
-		    ((signdx <=0) && (e <=0))
-		   )
-		{
-		    e +=e1;
-		}
-		else
-		{
-		    x += signdx;
-		    e += e2;
-		}
-		y += signdy;
-	    }
-
-	    lenCur++;
-	    if (lenCur >= lenMax && (len || npt <= 1))
-	    {
-		nseg++;
-		pseg = CheckDashStorage(&psegBase, nseg, &nsegMax);
-		if (!pseg)
-		    return (miDashPtr)NULL;
-		pseg->pt.x = x;
-		pseg->pt.y = y;
-		pseg->e1 = e1;
-		pseg->e2 = e2;
-		pseg->e = e;
-		which = ~which;
-		pseg->which = which;
-		pseg->newLine = 0;
-
-		/* move on to next dash */
-		iDash++;
-		if (iDash >= nDash)
-		    iDash = 0;
-		lenMax = pDash[iDash];
-		lenCur = 0;
-	    }
-	} /* while len-- */
-    } /* while --npt */
-
-    if (lenCur == 0 && nseg != 0)
-    {
-	nseg--;
-	which = ~which;
-    }
-    *pnseg = nseg;
-    pseg = CheckDashStorage(&psegBase, nseg+1, &nsegMax);
-    if (!pseg)
-	return (miDashPtr)NULL;
-    pseg->pt = pt2;
-    pseg->e = base_e;
-    pseg->which = which;
-    pseg->newLine = 0;
-    return psegBase;
-} 
-
-
 #define NSEGDELTA 16
 
 /* returns a pointer to the pseg[nseg-1], growing the storage as
@@ -251,8 +61,7 @@ necessary.  this interface seems unneces
 
 */
 
-static
-miDashPtr
+static miDashPtr
 CheckDashStorage(
     miDashPtr *ppseg,		/* base pointer */
     int nseg,			/* number of segment we want to write to */
diff --git a/mi/mifillarc.c b/mi/mifillarc.c
index 46c0738..c561b1f 100644
--- a/mi/mifillarc.c
+++ b/mi/mifillarc.c
@@ -107,10 +107,8 @@ miFillArcSetup(arc, info)
     }
 }
 
-void
-miFillArcDSetup(arc, info)
-    xArc *arc;
-    miFillArcDRec *info;
+static void
+miFillArcDSetup(xArc *arc, miFillArcDRec *info)
 {
     /* h^2 * (2x - 2xorg)^2 = w^2 * h^2 - w^2 * (2y - 2yorg)^2 */
     /* even: xorg = yorg = 0   odd:  xorg = .5, yorg = -.5 */
@@ -188,15 +186,9 @@ miGetArcEdge(
     }
 }
 
-void
-miEllipseAngleToSlope (angle, width, height, dxp, dyp, d_dxp, d_dyp)
-    int	    angle;
-    int	    width;
-    int	    height;
-    int	    *dxp;
-    int	    *dyp;
-    double  *d_dxp;
-    double  *d_dyp;
+static void
+miEllipseAngleToSlope (int angle, int width, int height, int *dxp, int *dyp,
+		       double *d_dxp, double *d_dyp)
 {
     int	    dx, dy;
     double  d_dx, d_dy, scale;
diff --git a/mi/mifillarc.h b/mi/mifillarc.h
index 53f6f23..3e3bb98 100644
--- a/mi/mifillarc.h
+++ b/mi/mifillarc.h
@@ -176,35 +176,11 @@ typedef struct _miArcSlice {
 #define miFillInArcLower(slw) (((iny + dy) != 0) && \
 			       ((slw > 1) || (ine != inxk)))
 
-extern int miFreeArcCache(
-    pointer /*data*/,
-    XID /*id*/
-);
-
-extern struct finalSpan *realAllocSpan(
-    void
-);
-
 extern void miFillArcSetup(
     xArc * /*arc*/,
     miFillArcRec * /*info*/
 );
 
-extern void miFillArcDSetup(
-    xArc * /*arc*/,
-    miFillArcDRec * /*info*/
-);
-
-extern void miEllipseAngleToSlope(
-    int /*angle*/,
-    int /*width*/,
-    int /*height*/,
-    int * /*dxp*/,
-    int * /*dyp*/,
-    double * /*d_dxp*/,
-    double * /*d_dyp*/
-);
-
 extern void miFillArcSliceSetup(
     xArc * /*arc*/,
     miArcSliceRec * /*slice*/,
diff --git a/mi/mipointer.c b/mi/mipointer.c
index b94feaa..b86a26a 100644
--- a/mi/mipointer.c
+++ b/mi/mipointer.c
@@ -1,9 +1,4 @@
 /*
- * mipointer.c
- */
-
-
-/*
 
 Copyright 1989, 1998  The Open Group
 
@@ -409,6 +404,27 @@ miPointerAbsoluteCursor (int x, int y, u
     miPointerSetPosition(inputInfo.pointer, &x, &y, time);
 }
 
+/* Move the pointer on the current screen,  and update the sprite. */
+static void
+miPointerMoved (DeviceIntPtr pDev, ScreenPtr pScreen, int x, int y,
+                     unsigned long time)
+{
+    SetupScreen(pScreen);
+
+    if (pDev && (pDev->coreEvents || pDev == inputInfo.pointer) &&
+        !pScreenPriv->waitForUpdate && pScreen == miPointer.pSpriteScreen)
+    {
+	miPointer.devx = x;
+	miPointer.devy = y;
+	if(!miPointer.pCursor->bits->emptyMask)
+	    (*pScreenPriv->spriteFuncs->MoveCursor) (pScreen, x, y);
+    }
+
+    miPointer.x = x;
+    miPointer.y = y;
+    miPointer.pScreen = pScreen;
+}
+
 _X_EXPORT void
 miPointerSetPosition(DeviceIntPtr pDev, int *x, int *y, unsigned long time)
 {
@@ -499,24 +515,3 @@ miPointerMove (ScreenPtr pScreen, int x,
     for (i = 0; i < nevents; i++)
         mieqEnqueue(inputInfo.pointer, &events[i]);
 }
-
-/* Move the pointer on the current screen,  and update the sprite. */
-void
-miPointerMoved (DeviceIntPtr pDev, ScreenPtr pScreen, int x, int y,
-                     unsigned long time)
-{
-    SetupScreen(pScreen);
-
-    if (pDev && (pDev->coreEvents || pDev == inputInfo.pointer) &&
-        !pScreenPriv->waitForUpdate && pScreen == miPointer.pSpriteScreen)
-    {
-	miPointer.devx = x;
-	miPointer.devy = y;
-	if(!miPointer.pCursor->bits->emptyMask)
-	    (*pScreenPriv->spriteFuncs->MoveCursor) (pScreen, x, y);
-    }
-
-    miPointer.x = x;
-    miPointer.y = y;
-    miPointer.pScreen = pScreen;
-}
diff --git a/mi/mipointer.h b/mi/mipointer.h
index 30e8944..1bce42c 100644
--- a/mi/mipointer.h
+++ b/mi/mipointer.h
@@ -1,10 +1,4 @@
 /*
- * mipointer.h
- *
- */
-
-
-/*
 
 Copyright 1989, 1998  The Open Group
 
@@ -172,15 +166,6 @@ extern void miPointerSetPosition(
 extern void miPointerUpdateSprite(
     DeviceIntPtr pDev);
 
-/* Moves the sprite to x, y on the current screen, and updates the event
- * history. */
-extern void miPointerMoved(
-    DeviceIntPtr pDev,
-    ScreenPtr pScreen,
-    int x,
-    int y,
-    unsigned long time);
-
 extern int miPointerScreenIndex;
 
 #endif /* MIPOINTER_H */
diff --git a/mi/mipoly.h b/mi/mipoly.h
index 8e04f67..c1bab49 100644
--- a/mi/mipoly.h
+++ b/mi/mipoly.h
@@ -180,14 +180,6 @@ typedef struct _ScanLineListBlock {
 
 /* mipolyutil.c */
 
-extern Bool miInsertEdgeInET(
-    EdgeTable * /*ET*/,
-    EdgeTableEntry * /*ETE*/,
-    int /*scanline*/,
-    ScanLineListBlock ** /*SLLBlock*/,
-    int * /*iSLLBlock*/
-);
-
 extern Bool miCreateETandAET(
     int /*count*/,
     DDXPointPtr /*pts*/,
diff --git a/mi/mipolytext.c b/mi/mipolytext.c
index 6af02e0..82b16f7 100644
--- a/mi/mipolytext.c
+++ b/mi/mipolytext.c
@@ -66,30 +66,6 @@ SOFTWARE.
 #include	"dixfontstr.h"
 #include	"mi.h"
 
-int
-miPolyText(pDraw, pGC, x, y, count, chars, fontEncoding)
-    DrawablePtr pDraw;
-    GCPtr	pGC;
-    int		x, y;
-    int		count;
-    char 	*chars;
-    FontEncoding fontEncoding;
-{
-    unsigned long n, i;
-    int w;
-    CharInfoPtr charinfo[255];	/* encoding only has 1 byte for count */
-
-    GetGlyphs(pGC->font, (unsigned long)count, (unsigned char *)chars,
-	      fontEncoding, &n, charinfo);
-    w = 0;
-    for (i=0; i < n; i++) w += charinfo[i]->metrics.characterWidth;
-    if (n != 0)
-        (*pGC->ops->PolyGlyphBlt)(
-	    pDraw, pGC, x, y, n, charinfo, FONTGLYPHS(pGC->font));
-    return x+w;
-}
-
-
 _X_EXPORT int
 miPolyText8(pDraw, pGC, x, y, count, chars)
     DrawablePtr pDraw;
@@ -112,7 +88,6 @@ miPolyText8(pDraw, pGC, x, y, count, cha
     return x+w;
 }
 
-
 _X_EXPORT int
 miPolyText16(pDraw, pGC, x, y, count, chars)
     DrawablePtr pDraw;
@@ -136,31 +111,6 @@ miPolyText16(pDraw, pGC, x, y, count, ch
     return x+w;
 }
 
-
-int
-miImageText(pDraw, pGC, x, y, count, chars, fontEncoding)
-    DrawablePtr pDraw;
-    GCPtr	pGC;
-    int 	x, y;
-    int 	count;
-    char 	*chars;
-    FontEncoding fontEncoding;
-{
-    unsigned long n, i;
-    FontPtr font = pGC->font;
-    int w;
-    CharInfoPtr charinfo[255];
-
-    GetGlyphs(font, (unsigned long)count, (unsigned char *)chars,
-	      fontEncoding, &n, charinfo);
-    w = 0;
-    for (i=0; i < n; i++) w += charinfo[i]->metrics.characterWidth;
-    if (n !=0 )
-        (*pGC->ops->ImageGlyphBlt)(pDraw, pGC, x, y, n, charinfo, FONTGLYPHS(font));
-    return x+w;
-}
-
-
 _X_EXPORT void
 miImageText8(pDraw, pGC, x, y, count, chars)
     DrawablePtr pDraw;
@@ -179,7 +129,6 @@ miImageText8(pDraw, pGC, x, y, count, ch
         (*pGC->ops->ImageGlyphBlt)(pDraw, pGC, x, y, n, charinfo, FONTGLYPHS(font));
 }
 
-
 _X_EXPORT void
 miImageText16(pDraw, pGC, x, y, count, chars)
     DrawablePtr pDraw;
diff --git a/mi/mipolyutil.c b/mi/mipolyutil.c
index fe72e55..6ec860a 100644
--- a/mi/mipolyutil.c
+++ b/mi/mipolyutil.c
@@ -73,13 +73,9 @@ SOFTWARE.
  *     bucket.  Finally, we can insert it.
  *
  */
-Bool
-miInsertEdgeInET(ET, ETE, scanline, SLLBlock, iSLLBlock)
-    EdgeTable *ET;
-    EdgeTableEntry *ETE;
-    int scanline;
-    ScanLineListBlock **SLLBlock;
-    int *iSLLBlock;
+static Bool
+miInsertEdgeInET(EdgeTable *ET, EdgeTableEntry *ETE,  int scanline,
+		 ScanLineListBlock **SLLBlock, int *iSLLBlock)
 {
     EdgeTableEntry *start, *prev;
     ScanLineList *pSLL, *pPrevSLL;
diff --git a/mi/miregion.c b/mi/miregion.c
index 5422099..e980ad1 100644
--- a/mi/miregion.c
+++ b/mi/miregion.c
@@ -221,7 +221,7 @@ _X_EXPORT BoxRec miEmptyBox = {0, 0, 0, 
 _X_EXPORT RegDataRec miEmptyData = {0, 0};
 
 RegDataRec  miBrokenData = {0, 0};
-RegionRec   miBrokenRegion = { { 0, 0, 0, 0 }, &miBrokenData };
+static RegionRec   miBrokenRegion = { { 0, 0, 0, 0 }, &miBrokenData };
 
 _X_EXPORT void
 miPrintRegion(rgn)
@@ -913,7 +913,7 @@ miRegionOp(
  *
  *-----------------------------------------------------------------------
  */
-void
+static void
 miSetExtents (pReg)
     RegionPtr pReg;
 {
@@ -2182,35 +2182,6 @@ miTranslateRegion(pReg, x, y)
     }
 }
 
-Bool
-miRegionDataCopy(
-    RegionPtr dst,
-    RegionPtr src)
-{
-    good(dst);
-    good(src);
-    if (dst->data) 
-	return TRUE;
-    if (dst == src)
-	return TRUE;
-    if (!src->data || !src->data->size)
-    {
-	xfreeData(dst);
-	dst->data = (RegDataPtr)NULL;
-	return TRUE;
-    }
-    if (!dst->data || (dst->data->size < src->data->numRects))
-    {
-	xfreeData(dst);
-	dst->data = xallocData(src->data->numRects);
-	if (!dst->data)
-	    return miRegionBreak (dst);
-    }
-    dst->data->size = src->data->size;
-    dst->data->numRects = src->data->numRects;
-    return TRUE;
-}
-
 _X_EXPORT void
 miRegionReset(pReg, pBox)
     RegionPtr pReg;
diff --git a/mi/miscrinit.c b/mi/miscrinit.c
index 08cc3f6..cc40cbe 100644
--- a/mi/miscrinit.c
+++ b/mi/miscrinit.c
@@ -126,12 +126,8 @@ miModifyPixmapHeader(pPixmap, width, hei
     return TRUE;
 }
 
-
-/*ARGSUSED*/
-Bool
-miCloseScreen (iScreen, pScreen)
-    int		iScreen;
-    ScreenPtr	pScreen;
+static Bool
+miCloseScreen (int iScreen, ScreenPtr pScreen)
 {
     return ((*pScreen->DestroyPixmap)((PixmapPtr)pScreen->devPrivate));
 }
diff --git a/mi/mispans.c b/mi/mispans.c
index 61d72e4..530d9df 100644
--- a/mi/mispans.c
+++ b/mi/mispans.c
@@ -78,9 +78,7 @@ void miInitSpanGroup(spanGroup)
 #define YMIN(spans) (spans->points[0].y)
 #define YMAX(spans)  (spans->points[spans->count-1].y)
 
-void miSubtractSpans (spanGroup, sub)
-    SpanGroup	*spanGroup;
-    Spans	*sub;
+static void miSubtractSpans (SpanGroup *spanGroup, Spans *sub)
 {
     int		i, subCount, spansCount;
     int		ymin, ymax, xmin, xmax;
@@ -364,9 +362,8 @@ static int UniquifySpansX(
     return (newWidths - startNewWidths) + 1;
 } /* UniquifySpansX */
 
-void
-miDisposeSpanGroup (spanGroup)
-    SpanGroup	*spanGroup;
+static void
+miDisposeSpanGroup (SpanGroup *spanGroup)
 {
     int	    i;
     Spans   *spans;
@@ -538,24 +535,3 @@ void miFillUniqueSpanGroup(pDraw, pGC, s
     spanGroup->ymin = MAXSHORT;
     spanGroup->ymax = MINSHORT;
 }
-
-
-void miFillSpanGroup(pDraw, pGC, spanGroup)
-    DrawablePtr pDraw;
-    GCPtr	pGC;
-    SpanGroup   *spanGroup;
-{
-    int    i;
-    Spans  *spans;
-
-    for (i = 0, spans = spanGroup->group; i != spanGroup->count; i++, spans++) {
-	(*pGC->ops->FillSpans)
-	    (pDraw, pGC, spans->count, spans->points, spans->widths, TRUE);
-	xfree(spans->points);
-	xfree(spans->widths);
-    }
-
-    spanGroup->count = 0;
-    spanGroup->ymin = MAXSHORT;
-    spanGroup->ymax = MINSHORT;
-} /* FillSpanGroup */
diff --git a/mi/mispans.h b/mi/mispans.h
index 5b141af..258b292 100644
--- a/mi/mispans.h
+++ b/mi/mispans.h
@@ -71,13 +71,6 @@ extern void miAppendSpans(
     Spans * /*spans*/
 );
 
-/* Paint a span group, possibly with some overlap */
-extern void miFillSpanGroup(
-    DrawablePtr /*pDraw*/,
-    GCPtr /*pGC*/,
-    SpanGroup * /*spanGroup*/
-);
-
 /* Paint a span group, insuring that each pixel is painted at most once */
 extern void miFillUniqueSpanGroup(
     DrawablePtr /*pDraw*/,
@@ -90,15 +83,6 @@ extern void miFreeSpanGroup(
     SpanGroup * /*spanGroup*/
 );
 
-extern void miSubtractSpans(
-    SpanGroup * /*spanGroup*/,
-    Spans * /*sub*/
-);
-
-extern void miDisposeSpanGroup(
-    SpanGroup * /*spanGroup*/
-);
-
 extern int miClipSpans(
     RegionPtr /*prgnDst*/,
     DDXPointPtr /*ppt*/,
diff --git a/mi/miwideline.c b/mi/miwideline.c
index 7f99aca..08e4aa3 100644
--- a/mi/miwideline.c
+++ b/mi/miwideline.c
@@ -67,17 +67,11 @@ static void miLineArc(DrawablePtr pDraw,
  * spans-based polygon filler
  */
 
-void
-miFillPolyHelper (pDrawable, pGC, pixel, spanData, y, overall_height,
-		  left, right, left_count, right_count)
-    DrawablePtr	pDrawable;
-    GCPtr	pGC;
-    unsigned long   pixel;
-    SpanDataPtr	spanData;
-    int		y;			/* start y coordinate */
-    int		overall_height;		/* height of entire segment */
-    PolyEdgePtr	left, right;
-    int		left_count, right_count;
+static void
+miFillPolyHelper (DrawablePtr pDrawable, GCPtr pGC, unsigned long pixel,
+		  SpanDataPtr spanData, int y, int overall_height,
+		  PolyEdgePtr left, PolyEdgePtr right,
+		  int left_count, int right_count)
 {
     int left_x = 0, left_e = 0;
     int	left_stepx = 0;
@@ -873,11 +867,8 @@ miLineArcD (
     return (pts - points);
 }
 
-int
-miRoundJoinFace (face, edge, leftEdge)
-    LineFacePtr face;
-    PolyEdgePtr edge;
-    Bool	*leftEdge;
+static int
+miRoundJoinFace (LineFacePtr face, PolyEdgePtr edge, Bool *leftEdge)
 {
     int	    y;
     int	    dx, dy;
@@ -1114,16 +1105,10 @@ miLineArc (
     }
 }
 
-void
-miLineProjectingCap (pDrawable, pGC, pixel, spanData, face, isLeft, xorg, yorg, isInt)
-    DrawablePtr		pDrawable;
-    GCPtr  		pGC;
-    unsigned long	pixel;
-    SpanDataPtr		spanData;
-    LineFacePtr 	face;
-    Bool	    	isLeft;
-    double	    	xorg, yorg;
-    Bool	    	isInt;
+static void
+miLineProjectingCap (DrawablePtr pDrawable, GCPtr pGC, unsigned long pixel,
+		     SpanDataPtr spanData, LineFacePtr face, Bool isLeft,
+		     double xorg, double yorg, Bool isInt)
 {
     int	xorgi = 0, yorgi = 0;
     int	lw;
@@ -1506,11 +1491,8 @@ miWideSegment (
     }
 }
 
-SpanDataPtr
-miSetupSpanData (pGC, spanData, npt)
-    GCPtr pGC;
-    SpanDataPtr	spanData;
-    int		npt;
+static SpanDataPtr
+miSetupSpanData (GCPtr pGC, SpanDataPtr spanData, int npt)
 {
     if ((npt < 3 && pGC->capStyle != CapRound) || miSpansEasyRop(pGC->alu))
 	return (SpanDataPtr) NULL;
@@ -1520,11 +1502,8 @@ miSetupSpanData (pGC, spanData, npt)
     return spanData;
 }
 
-void
-miCleanupSpanData (pDrawable, pGC, spanData)
-    DrawablePtr	pDrawable;
-    GCPtr	pGC;
-    SpanDataPtr	spanData;
+static void
+miCleanupSpanData (DrawablePtr pDrawable, GCPtr pGC, SpanDataPtr spanData)
 {
     if (pGC->lineStyle == LineDoubleDash)
     {
diff --git a/mi/miwideline.h b/mi/miwideline.h
index 8cfa630..9d1aa03 100644
--- a/mi/miwideline.h
+++ b/mi/miwideline.h
@@ -153,24 +153,6 @@ typedef struct _LineFace {
     } \
 }
 
-extern void miFillPolyHelper(
-    DrawablePtr /*pDrawable*/,
-    GCPtr /*pGC*/,
-    unsigned long /*pixel*/,
-    SpanDataPtr /*spanData*/,
-    int /*y*/,
-    int /*overall_height*/,
-    PolyEdgePtr /*left*/,
-    PolyEdgePtr /*right*/,
-    int /*left_count*/,
-    int /*right_count*/
-);
-extern int miRoundJoinFace(
-    LineFacePtr /*face*/,
-    PolyEdgePtr /*edge*/,
-    Bool * /*leftEdge*/
-);
-
 extern void miRoundJoinClip(
     LineFacePtr /*pLeft*/,
     LineFacePtr /*pRight*/,
@@ -189,30 +171,6 @@ extern int miRoundCapClip(
     Bool * /*leftEdge*/
 );
 
-extern void miLineProjectingCap(
-    DrawablePtr /*pDrawable*/,
-    GCPtr /*pGC*/,
-    unsigned long /*pixel*/,
-    SpanDataPtr /*spanData*/,
-    LineFacePtr /*face*/,
-    Bool /*isLeft*/,
-    double /*xorg*/,
-    double /*yorg*/,
-    Bool /*isInt*/
-);
-
-extern SpanDataPtr miSetupSpanData(
-    GCPtr /*pGC*/,
-    SpanDataPtr /*spanData*/,
-    int /*npt*/
-);
-
-extern void miCleanupSpanData(
-    DrawablePtr /*pDrawable*/,
-    GCPtr /*pGC*/,
-    SpanDataPtr /*spanData*/
-);
-
 extern int miPolyBuildEdge(double x0, double y0, double k, int dx, int dy,
 				int xi, int yi, int left, PolyEdgePtr edge);
 extern int miPolyBuildPoly(PolyVertexPtr vertices, PolySlopePtr slopes,
diff --git a/mi/mizerarc.c b/mi/mizerarc.c
index f1adc9e..9d4715a 100644
--- a/mi/mizerarc.c
+++ b/mi/mizerarc.c
@@ -401,10 +401,8 @@ miZeroArcSetup(arc, info, ok360)
 
 #define DoPix(idx,xval,yval) if (mask & (1 << idx)) Pixelate(xval, yval);
 
-DDXPointPtr
-miZeroArcPts(arc, pts)
-    xArc *arc;
-    DDXPointPtr pts;
+static DDXPointPtr
+miZeroArcPts(xArc *arc, DDXPointPtr pts)
 {
     miZeroArcRec info;
     int x, y, a, b, d, mask;
diff --git a/mi/mizerarc.h b/mi/mizerarc.h
index 8119d88..28ebbe0 100644
--- a/mi/mizerarc.h
+++ b/mi/mizerarc.h
@@ -124,9 +124,3 @@ extern Bool miZeroArcSetup(
     miZeroArcRec * /*info*/,
     Bool /*ok360*/
 );
-
-extern DDXPointPtr miZeroArcPts(
-    xArc * /*arc*/,
-    DDXPointPtr /*pts*/
-);
-
diff-tree 62224e39727fd6f1cf11a461983662f615a9fea1 (from e8bc1988d9ff10b65717574175f70df3c4d6334d)
Author: Adam Jackson <ajax at benzedrine.nwnk.net>
Date:   Sun Mar 25 17:55:15 2007 -0400

    Static cleanup for xf86 ddx.

diff --git a/hw/xfree86/common/xf86Bus.c b/hw/xfree86/common/xf86Bus.c
index e1cbdbb..9740b07 100644
--- a/hw/xfree86/common/xf86Bus.c
+++ b/hw/xfree86/common/xf86Bus.c
@@ -1791,6 +1791,15 @@ convertRange2Host(int entityIndex, resRa
     }
 }
 
+static void
+xf86ConvertListToHost(int entityIndex, resPtr list)
+{
+    while (list) {
+	convertRange2Host(entityIndex, &list->val);
+	list = list->next;
+    }
+}
+
 /*
  * xf86RegisterResources() -- attempts to register listed resources.
  * If list is NULL it tries to obtain resources implicitly. Function
@@ -2836,17 +2845,6 @@ xf86IsSubsetOf(resRange range, resPtr li
     return ret;
 }
 
-Bool
-xf86IsListSubsetOf(resPtr list, resPtr BaseList)
-{
-    while (list) {
-	if (! xf86IsSubsetOf(list->val,BaseList))
-	    return FALSE;
-	list = list->next;
-    }
-    return TRUE;
-}
-
 static resPtr
 findIntersect(resRange Range, resPtr list)
 {
@@ -3071,15 +3069,6 @@ xf86NoSharedResources(int screenIndex,re
     return TRUE;
 }
 
-void
-xf86ConvertListToHost(int entityIndex, resPtr list)
-{
-    while (list) {
-	convertRange2Host(entityIndex, &list->val);
-	list = list->next;
-    }
-}
-
 _X_EXPORT void
 xf86RegisterStateChangeNotificationCallback(xf86StateChangeNotificationCallbackFunc func, pointer arg)
 {
diff --git a/hw/xfree86/common/xf86Bus.h b/hw/xfree86/common/xf86Bus.h
index 225a5c7..8d71959 100644
--- a/hw/xfree86/common/xf86Bus.h
+++ b/hw/xfree86/common/xf86Bus.h
@@ -141,11 +141,9 @@ int xf86AllocateEntity(void);
 BusType StringToBusType(const char* busID, const char **retID);
 memType ChkConflict(resRange *rgp, resPtr res, xf86State state);
 Bool xf86IsSubsetOf(resRange range, resPtr list);
-Bool xf86IsListSubsetOf(resPtr list, resPtr BaseList);
 resPtr xf86ExtractTypeFromList(resPtr list, unsigned long type);
 resPtr xf86FindIntersect(resRange Range, resPtr list);
 void RemoveOverlaps(resPtr target, resPtr list, Bool pow2Alignment,
 		    Bool useEstimated);
-void xf86ConvertListToHost(int entityIndex, resPtr list);
 
 #endif /* _XF86_BUS_H */
diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c
index 1bd3c62..4db844e 100644
--- a/hw/xfree86/common/xf86Config.c
+++ b/hw/xfree86/common/xf86Config.c
@@ -538,25 +538,6 @@ xf86DriverlistFromCompile(void)
     return driverlist;
 }
 
-
-char **
-xf86InputDriverlistFromCompile(void)
-{
-    static char **driverlist = NULL;
-    static Bool generated = FALSE;
-
-    /* This string is modified in-place */
-    static char drivernames[] = IDRIVERS;
-
-    if (!generated) {
-        generated = TRUE;
-	driverlist = GenerateDriverlist("input", drivernames);
-    }
-
-    return driverlist;
-}
-
-
 /*
  * xf86ConfigError --
  *      Print a READABLE ErrorMessage!!!  All information that is 
@@ -2504,17 +2485,8 @@ xf86HandleConfigFile(Bool autoconfig)
     return CONFIG_OK;
 }
 
-
-/* These make the equivalent parser functions visible to the common layer. */
-Bool
-xf86PathIsAbsolute(const char *path)
-{
-    return (xf86pathIsAbsolute(path) != 0);
-}
-
 Bool
 xf86PathIsSafe(const char *path)
 {
     return (xf86pathIsSafe(path) != 0);
 }
-
diff --git a/hw/xfree86/common/xf86Config.h b/hw/xfree86/common/xf86Config.h
index 0786ec6..3787ba2 100644
--- a/hw/xfree86/common/xf86Config.h
+++ b/hw/xfree86/common/xf86Config.h
@@ -53,7 +53,6 @@ char ** xf86ModulelistFromConfig(pointer
 char ** xf86DriverlistFromConfig(void);
 char ** xf86DriverlistFromCompile(void);
 char ** xf86InputDriverlistFromConfig(void);
-char ** xf86InputDriverlistFromCompile(void);
 Bool xf86BuiltinInputDriver(const char *);
 ConfigStatus xf86HandleConfigFile(Bool);
 
diff --git a/hw/xfree86/common/xf86Globals.c b/hw/xfree86/common/xf86Globals.c
index 9b23710..b41fe6e 100644
--- a/hw/xfree86/common/xf86Globals.c
+++ b/hw/xfree86/common/xf86Globals.c
@@ -146,7 +146,6 @@ _X_EXPORT confDRIRec xf86ConfigDRI = {0,
 XF86ConfigPtr xf86configptr = NULL;
 Bool xf86Resetting = FALSE;
 Bool xf86Initialising = FALSE;
-Bool xf86ProbeFailed = FALSE;
 Bool xf86DoProbe = FALSE;
 Bool xf86DoConfigure = FALSE;
 DriverPtr *xf86DriverList = NULL;
diff --git a/hw/xfree86/common/xf86Priv.h b/hw/xfree86/common/xf86Priv.h
index 9279dbd..59ce8da 100644
--- a/hw/xfree86/common/xf86Priv.h
+++ b/hw/xfree86/common/xf86Priv.h
@@ -100,7 +100,6 @@ extern int xf86NumModuleInfos;
 extern int xf86NumDrivers;
 extern Bool xf86Resetting;
 extern Bool xf86Initialising;
-extern Bool xf86ProbeFailed;
 extern int xf86NumScreens;
 extern pciVideoPtr *xf86PciVideoInfo;
 extern xf86CurrentAccessRec xf86CurrentAccess;
@@ -155,7 +154,6 @@ extern int pciTestMultiDeviceCard(int bu
 
 /* xf86Config.c */
 
-Bool xf86PathIsAbsolute(const char *path);
 Bool xf86PathIsSafe(const char *path);
 
 /* xf86DefaultModes */
diff --git a/hw/xfree86/os-support/shared/libc_wrapper.c b/hw/xfree86/os-support/shared/libc_wrapper.c
index 4c4af4c..a459d5d 100644
--- a/hw/xfree86/os-support/shared/libc_wrapper.c
+++ b/hw/xfree86/os-support/shared/libc_wrapper.c
@@ -628,7 +628,7 @@ typedef struct _xf86_file_ {
 	char*	fname;
 } XF86FILE_priv;
 
-XF86FILE_priv stdhnd[3] = {
+static XF86FILE_priv stdhnd[3] = {
 	{ 0, XF86FILE_magic, NULL, "$stdinp$" },
 	{ 0, XF86FILE_magic, NULL, "$stdout$" },
 	{ 0, XF86FILE_magic, NULL, "$stderr$" }
diff --git a/hw/xfree86/parser/Screen.c b/hw/xfree86/parser/Screen.c
index b7a64b0..79e1d24 100644
--- a/hw/xfree86/parser/Screen.c
+++ b/hw/xfree86/parser/Screen.c
@@ -83,7 +83,7 @@ static xf86ConfigSymTabRec DisplayTab[] 
 
 #define CLEANUP xf86freeDisplayList
 
-XF86ConfDisplayPtr
+static XF86ConfDisplayPtr
 xf86parseDisplaySubSection (void)
 {
 	int token;
diff --git a/hw/xfree86/parser/Vendor.c b/hw/xfree86/parser/Vendor.c
index 3e9358b..d1e6080 100644
--- a/hw/xfree86/parser/Vendor.c
+++ b/hw/xfree86/parser/Vendor.c
@@ -75,7 +75,7 @@ static xf86ConfigSymTabRec VendorSubTab[
 
 #define CLEANUP xf86freeVendorSubList
 
-XF86ConfVendSubPtr
+static XF86ConfVendSubPtr
 xf86parseVendorSubSection (void)
 {
 	int has_ident = FALSE;
@@ -242,16 +242,3 @@ xf86freeVendorSubList (XF86ConfVendSubPt
 		xf86conffree (prev);
 	}
 }
-
-XF86ConfVendorPtr
-xf86findVendor (const char *name, XF86ConfVendorPtr list)
-{
-	while (list)
-	{
-		if (xf86nameCompare (list->vnd_identifier, name) == 0)
-			return (list);
-		list = list->list.next;
-	}
-	return (NULL);
-}
-
diff --git a/hw/xfree86/parser/Video.c b/hw/xfree86/parser/Video.c
index fa0ff78..a8912cf 100644
--- a/hw/xfree86/parser/Video.c
+++ b/hw/xfree86/parser/Video.c
@@ -74,7 +74,23 @@ static xf86ConfigSymTabRec VideoPortTab[
 
 #define CLEANUP xf86freeVideoPortList
 
-XF86ConfVideoPortPtr
+static void
+xf86freeVideoPortList (XF86ConfVideoPortPtr ptr)
+{
+	XF86ConfVideoPortPtr prev;
+
+	while (ptr)
+	{
+		TestFree (ptr->vp_identifier);
+		TestFree (ptr->vp_comment);
+		xf86optionListFree (ptr->vp_option_lst);
+		prev = ptr;
+		ptr = ptr->list.next;
+		xf86conffree (prev);
+	}
+}
+
+static XF86ConfVideoPortPtr
 xf86parseVideoPortSubSection (void)
 {
 	int has_ident = FALSE;
@@ -266,22 +282,6 @@ xf86freeVideoAdaptorList (XF86ConfVideoA
 	}
 }
 
-void
-xf86freeVideoPortList (XF86ConfVideoPortPtr ptr)
-{
-	XF86ConfVideoPortPtr prev;
-
-	while (ptr)
-	{
-		TestFree (ptr->vp_identifier);
-		TestFree (ptr->vp_comment);
-		xf86optionListFree (ptr->vp_option_lst);
-		prev = ptr;
-		ptr = ptr->list.next;
-		xf86conffree (prev);
-	}
-}
-
 XF86ConfVideoAdaptorPtr
 xf86findVideoAdaptor (const char *ident, XF86ConfVideoAdaptorPtr p)
 {
diff --git a/hw/xfree86/parser/configProcs.h b/hw/xfree86/parser/configProcs.h
index e3961a9..3c9ce7a 100644
--- a/hw/xfree86/parser/configProcs.h
+++ b/hw/xfree86/parser/configProcs.h
@@ -66,7 +66,6 @@ int xf86validateMonitor(XF86ConfigPtr p,
 /* Pointer.c */
 XF86ConfInputPtr xf86parsePointerSection(void);
 /* Screen.c */
-XF86ConfDisplayPtr xf86parseDisplaySubSection(void);
 XF86ConfScreenPtr xf86parseScreenSection(void);
 void xf86printScreenSection(FILE *cf, XF86ConfScreenPtr ptr);
 void xf86freeScreenList(XF86ConfScreenPtr ptr);
@@ -76,16 +75,13 @@ void xf86freeModeList(XF86ModePtr ptr);
 int xf86validateScreen(XF86ConfigPtr p);
 /* Vendor.c */
 XF86ConfVendorPtr xf86parseVendorSection(void);
-XF86ConfVendSubPtr xf86parseVendorSubSection (void);
 void xf86freeVendorList(XF86ConfVendorPtr p);
 void xf86printVendorSection(FILE * cf, XF86ConfVendorPtr ptr);
 void xf86freeVendorSubList (XF86ConfVendSubPtr ptr);
 /* Video.c */
-XF86ConfVideoPortPtr xf86parseVideoPortSubSection(void);
 XF86ConfVideoAdaptorPtr xf86parseVideoAdaptorSection(void);
 void xf86printVideoAdaptorSection(FILE *cf, XF86ConfVideoAdaptorPtr ptr);
 void xf86freeVideoAdaptorList(XF86ConfVideoAdaptorPtr ptr);
-void xf86freeVideoPortList(XF86ConfVideoPortPtr ptr);
 /* scan.c */
 int xf86getToken(xf86ConfigSymTabRec *tab);
 int xf86getSubToken(char **comment);
diff --git a/hw/xfree86/parser/xf86Parser.h b/hw/xfree86/parser/xf86Parser.h
index a682927..89de97b 100644
--- a/hw/xfree86/parser/xf86Parser.h
+++ b/hw/xfree86/parser/xf86Parser.h
@@ -469,7 +469,6 @@ XF86ConfModeLinePtr xf86findModeLine(con
 XF86ConfScreenPtr xf86findScreen(const char *ident, XF86ConfScreenPtr p);
 XF86ConfInputPtr xf86findInput(const char *ident, XF86ConfInputPtr p);
 XF86ConfInputPtr xf86findInputByDriver(const char *driver, XF86ConfInputPtr p);
-XF86ConfVendorPtr xf86findVendor(const char *name, XF86ConfVendorPtr list);
 XF86ConfVideoAdaptorPtr xf86findVideoAdaptor(const char *ident,
 						XF86ConfVideoAdaptorPtr p);
 
diff-tree e8bc1988d9ff10b65717574175f70df3c4d6334d (from 70e493d223b1e943e652191150bd0b7e1a6ebcfb)
Author: Adam Jackson <ajax at benzedrine.nwnk.net>
Date:   Sun Mar 25 15:13:05 2007 -0400

    Un-staticise VTSwitchEnabled, since kbd wants it apparently.

diff --git a/hw/xfree86/common/xf86Events.c b/hw/xfree86/common/xf86Events.c
index eae6cb1..3610c17 100644
--- a/hw/xfree86/common/xf86Events.c
+++ b/hw/xfree86/common/xf86Events.c
@@ -128,7 +128,7 @@ extern Bool noXkbExtension;
 #ifdef USE_VT_SYSREQ
 static Bool VTSysreqToggle = FALSE;
 #endif /* !USE_VT_SYSREQ */
-static Bool VTSwitchEnabled = TRUE;	/* Allows run-time disabling for
+_X_EXPORT Bool VTSwitchEnabled = TRUE;	/* Allows run-time disabling for
                                          *BSD and for avoiding VT
                                          switches when using the DRI
                                          automatic full screen mode.*/
diff-tree 70e493d223b1e943e652191150bd0b7e1a6ebcfb (from f36bf1a3e4ce9465ea4a6159c209924a3cafbe58)
Author: Adam Jackson <ajax at benzedrine.nwnk.net>
Date:   Sun Mar 25 14:55:28 2007 -0400

    Static and dead code cleanup over afb/

diff --git a/afb/afb.h b/afb/afb.h
index c05cc55..5aa2b0c 100644
--- a/afb/afb.h
+++ b/afb/afb.h
@@ -78,27 +78,6 @@ extern void afbDoBitblt(
 	unsigned long /*planemask*/
 );
 
-extern RegionPtr afbBitBlt(
-	DrawablePtr /*pSrc*/,
-	DrawablePtr /*pDst*/,
-	GCPtr /*pGC*/,
-	int /*srcx*/,
-	int /*srcy*/,
-	int /*width*/,
-	int /*height*/,
-	int /*dstx*/,
-	int /*dsty*/,
-	void (*doBitBlt)(
-		DrawablePtr /*pSrc*/,
-		DrawablePtr /*pDst*/,
-		int /*alu*/,
-		RegionPtr /*prgnDst*/,
-		DDXPointPtr /*pptSrc*/,
-		unsigned long /*planemask*/
-        ),
-	unsigned long /*planemask*/
-);
-
 extern RegionPtr afbCopyArea(
 	DrawablePtr /*pSrcDrawable*/,
 	DrawablePtr /*pDstDrawable*/,
@@ -111,27 +90,6 @@ extern RegionPtr afbCopyArea(
 	int /*dsty*/
 );
 
-extern RegionPtr afbCopyPlane(
-	DrawablePtr /*pSrcDrawable*/,
-	DrawablePtr /*pDstDrawable*/,
-	GCPtr/*pGC*/,
-	int /*srcx*/,
-	int /*srcy*/,
-	int /*width*/,
-	int /*height*/,
-	int /*dstx*/,
-	int /*dsty*/,
-	unsigned long /*plane*/
-);
-
-extern void afbCopy1ToN(
-	DrawablePtr /*pSrc*/,
-	DrawablePtr /*pDst*/,
-	int /*alu*/,
-	RegionPtr /*prgnDst*/,
-	DDXPointPtr /*pptSrc*/,
-	unsigned long /*planemask*/
-);
 /* afbbltC.c */
 
 extern void afbDoBitbltCopy(
@@ -273,23 +231,6 @@ extern Bool afbInitializeColormap(
 	ColormapPtr /*pmap*/
 );
 
-extern int afbExpandDirectColors(
-	ColormapPtr /*pmap*/,
-	int /*ndefs*/,
-	xColorItem * /*indefs*/,
-	xColorItem * /*outdefs*/
-);
-
-extern Bool afbCreateDefColormap(
-	ScreenPtr /*pScreen*/
-);
-
-extern Bool afbSetVisualTypes(
-	int /*depth*/,
-	int /*visuals*/,
-	int /*bitsPerRGB*/
-);
-
 extern Bool afbInitVisuals(
 	VisualPtr * /*visualp*/,
 	DepthPtr * /*depthp*/,
@@ -410,16 +351,6 @@ extern Bool afbCreateGC(
 	GCPtr /*pGC*/
 );
 
-extern void afbValidateGC(
-	GCPtr /*pGC*/,
-	unsigned long /*changes*/,
-	DrawablePtr /*pDrawable*/
-);
-
-extern void afbDestroyGC(
-	GCPtr /*pGC*/
-);
-
 extern void afbReduceRop(
 	int /*alu*/,
 	Pixel /*src*/,
@@ -428,19 +359,6 @@ extern void afbReduceRop(
 	unsigned char * /*rrops*/
 );
 
-extern void afbReduceOpaqueStipple (
-	Pixel /*fg*/,
-	Pixel /*bg*/,
-	unsigned long /*planemask*/,
-	int /*depth*/,
-	unsigned char * /*rrops*/
-);
-
-extern void afbComputeCompositeClip(
-   GCPtr /*pGC*/,
-   DrawablePtr /*pDrawable*/
-);
-
 /* afbgetsp.c */
 
 extern void afbGetSpans(
@@ -588,14 +506,6 @@ extern Bool afbDestroyPixmap(
 	PixmapPtr /*pPixmap*/
 );
 
-extern PixmapPtr afbCopyPixmap(
-	PixmapPtr /*pSrc*/
-);
-
-extern void afbPadPixmap(
-	PixmapPtr /*pPixmap*/
-);
-
 extern void afbXRotatePixmap(
 	PixmapPtr /*pPix*/,
 	int /*rw*/
@@ -637,20 +547,9 @@ extern void afbPushPixels(
 	int /*xOrg*/,
 	int /*yOrg*/
 );
-/* afbscrclse.c */
 
-extern Bool afbCloseScreen(
-	int /*index*/,
-	ScreenPtr /*pScreen*/
-);
 /* afbscrinit.c */
 
-extern Bool afbAllocatePrivates(
-	ScreenPtr /*pScreen*/,
-	int * /*pWinIndex*/,
-	int * /*pGCIndex*/
-);
-
 extern Bool afbScreenInit(
 	ScreenPtr /*pScreen*/,
 	pointer /*pbits*/,
@@ -661,15 +560,6 @@ extern Bool afbScreenInit(
 	int /*width*/
 );
 
-extern PixmapPtr afbGetWindowPixmap(
-	WindowPtr /*pWin*/
-);
-
-extern void afbSetWindowPixmap(
-	WindowPtr /*pWin*/,
-	PixmapPtr /*pPix*/
-);
-
 /* afbseg.c */
 
 extern void afbSegmentSS(
@@ -687,20 +577,6 @@ extern void afbSegmentSD(
 );
 /* afbsetsp.c */
 
-extern void afbSetScanline(
-	int /*y*/,
-	int /*xOrigin*/,
-	int /*xStart*/,
-	int /*xEnd*/,
-	PixelType * /*psrc*/,
-	int /*alu*/,
-	PixelType * /*pdstBase*/,
-	int /*widthDst*/,
-	int /*sizeDst*/,
-	int /*depthDst*/,
-	int /*sizeSrc*/
-);
-
 extern void afbSetSpans(
 	DrawablePtr /*pDrawable*/,
 	GCPtr /*pGC*/,
diff --git a/afb/afbbitblt.c b/afb/afbbitblt.c
index 594e987..2e416e3 100644
--- a/afb/afbbitblt.c
+++ b/afb/afbbitblt.c
@@ -67,9 +67,6 @@ SOFTWARE.
 #include "afb.h"
 #include "maskbits.h"
 
-
-static unsigned char afbRropsOS[AFB_MAX_DEPTH];
-
 /* CopyArea and CopyPlane for a monchrome frame buffer
 
 
@@ -126,34 +123,7 @@ afbDoBitblt(DrawablePtr pSrc, DrawablePt
 typedef void (*afb_blit_func)
     (DrawablePtr, DrawablePtr, int, RegionPtr, DDXPointPtr, unsigned long);
 
-RegionPtr
-afbCopyArea(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable, GC *pGC, int srcx, int srcy, int width, int height, int dstx, int dsty)
-{
-	afb_blit_func doBitBlt;
-
-	switch (pGC->alu) {
-		case GXcopy:
-			doBitBlt = afbDoBitbltCopy;
-			break;
-		case GXxor:
-			doBitBlt = afbDoBitbltXor;
-			break;
-		case GXcopyInverted:
-			doBitBlt = afbDoBitbltCopyInverted;
-			break;
-		case GXor:
-			doBitBlt = afbDoBitbltOr;
-			break;
-		default:
-			doBitBlt = afbDoBitbltGeneral;
-			break;
-	}
-
-	return(afbBitBlt(pSrcDrawable, pDstDrawable, pGC, srcx, srcy,
-			 width, height, dstx, dsty, doBitBlt, pGC->planemask));
-}
-
-RegionPtr
+static RegionPtr
 afbBitBlt(register DrawablePtr pSrcDrawable, register DrawablePtr pDstDrawable, register GC *pGC, int srcx, int srcy, int width, int height, int dstx, int dsty, afb_blit_func doBitBlt, long unsigned int planemask)
 {
 	RegionPtr prgnSrcClip = NULL;		/* may be a new region, or just a copy */
@@ -346,102 +316,28 @@ afbBitBlt(register DrawablePtr pSrcDrawa
 }
 
 RegionPtr
-afbCopyPlane(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable, register GC *pGC, int srcx, int srcy, int width, int height, int dstx, int dsty, long unsigned int plane)
+afbCopyArea(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable, GC *pGC, int srcx, int srcy, int width, int height, int dstx, int dsty)
 {
-	int alu;
-	RegionPtr		prgnExposed = NULL;
-	unsigned long old_planemask;
-
-	if (pDstDrawable->depth == 1) {
-		old_planemask = pGC->planemask;
-		pGC->planemask = plane;
-		if ((pGC->fgPixel & 1) == 1 && (pGC->bgPixel & 1) == 0) {
-			prgnExposed = (*pGC->ops->CopyArea)(pSrcDrawable, pDstDrawable,
-							 pGC, srcx, srcy, width, height, dstx, dsty);
-		} else if ((pGC->fgPixel & 1) == (pGC->bgPixel & 1)) {
-			unsigned char rop;
-
-			afbReduceRop(pGC->alu, pGC->fgPixel, 1, 1, &rop);
-			alu = pGC->alu;
-			pGC->alu = rop;
-			prgnExposed = (*pGC->ops->CopyArea)(pSrcDrawable, pDstDrawable, pGC,
-															srcx, srcy, width, height, dstx,
-															dsty);
-			pGC->alu = alu;
-		} else { /* need to invert the src */
-			alu = pGC->alu;
-			pGC->alu = afbInverseAlu[alu];
-			prgnExposed = (*pGC->ops->CopyArea)(pSrcDrawable, pDstDrawable, pGC,
-															srcx, srcy, width, height, dstx,
-															dsty);
-			pGC->alu = alu;
-		}
-		pGC->planemask = old_planemask;
-	} else {
-		int free_pixmap = FALSE;
-		PixmapPtr pBitmap = (PixmapPtr)pSrcDrawable;
-		ScreenPtr pScreen = pSrcDrawable->pScreen;
-		GCPtr pGC1 = NULL;
-
-		if (pSrcDrawable == pDstDrawable ||
-			pSrcDrawable->type == DRAWABLE_WINDOW || pSrcDrawable->depth != 1) {
-			/* Copy a plane from source drawable to a tmp 1-bit deep pixmap */
-			/* XXX: Range check width and height */
-			pBitmap = (*pScreen->CreatePixmap)(pScreen, width, height, 1);
-
-			if (!pBitmap)
-				return(NULL);
-			pGC1 = GetScratchGC(1, pScreen);
-			if (!pGC1) {
-				(*pScreen->DestroyPixmap)(pBitmap);
-				return(NULL);
-			}
-			ValidateGC((DrawablePtr)pBitmap, pGC1);
-			(void)afbBitBlt(pSrcDrawable, (DrawablePtr)pBitmap, pGC1, srcx, srcy,
-								  width, height, 0, 0, afbDoBitbltCopy, plane);
-			free_pixmap = TRUE;
-		}
-#if 0
-		else {
-			/* XXX: could cope with N-deep pixmap source case without using tmp
-			 * src bitmap by setting up a scratch pixmap header and fiddle
-			 * around with the pbits pointer.
-			 */
-		}
-#endif
-		afbReduceOpaqueStipple(pGC->fgPixel, pGC->bgPixel, pGC->planemask,
-										pGC->depth, afbRropsOS);
-		(void)afbBitBlt((DrawablePtr)pBitmap, pDstDrawable, pGC, 0, 0, width,
-							  height, dstx, dsty, afbCopy1ToN, pGC->planemask);
-		if (free_pixmap) {
-			(*pScreen->DestroyPixmap)(pBitmap);
-			FreeScratchGC(pGC1);
-		}
+	afb_blit_func doBitBlt;
 
-		if (pGC->fExpose)
-			prgnExposed = miHandleExposures(pSrcDrawable, pDstDrawable, pGC, srcx,
-													  srcy, width, height, dstx, dsty,
-													  plane);
+	switch (pGC->alu) {
+		case GXcopy:
+			doBitBlt = afbDoBitbltCopy;
+			break;
+		case GXxor:
+			doBitBlt = afbDoBitbltXor;
+			break;
+		case GXcopyInverted:
+			doBitBlt = afbDoBitbltCopyInverted;
+			break;
+		case GXor:
+			doBitBlt = afbDoBitbltOr;
+			break;
+		default:
+			doBitBlt = afbDoBitbltGeneral;
+			break;
 	}
-	return prgnExposed;
-}
 
-void
-afbCopy1ToN(DrawablePtr pSrc, DrawablePtr pDst, int alu, RegionPtr prgnDst, DDXPointPtr pptSrc, long unsigned int planemask)
-{
-	int numRects = REGION_NUM_RECTS(prgnDst);
-	BoxPtr pbox = REGION_RECTS(prgnDst);
-	int r;
-
-	for (r = 0; r < numRects; r++, pbox++, pptSrc++) {
-		int dx = pptSrc->x;
-		int dy = pptSrc->y;
-
-		if (alu == GXcopy)
-			afbOpaqueStippleAreaCopy(pDst, 1, pbox, alu, (PixmapPtr)pSrc, dx, dy,
-											  afbRropsOS, planemask);
-		else
-			afbOpaqueStippleAreaGeneral(pDst, 1, pbox, alu, (PixmapPtr)pSrc, dx,
-												  dy, afbRropsOS, planemask);
-	}
+	return(afbBitBlt(pSrcDrawable, pDstDrawable, pGC, srcx, srcy,
+			 width, height, dstx, dsty, doBitBlt, pGC->planemask));
 }
diff --git a/afb/afbcmap.c b/afb/afbcmap.c
index e3b95fb..9608a36 100644
--- a/afb/afbcmap.c
+++ b/afb/afbcmap.c
@@ -70,24 +70,6 @@ afbInitializeColormap(register ColormapP
 	return miInitializeColormap(pmap);
 }
 
-int
-afbExpandDirectColors(ColormapPtr pmap, int ndef, xColorItem *indefs, xColorItem *outdefs)
-{
-	return miExpandDirectColors(pmap, ndef, indefs, outdefs);
-}
-
-Bool
-afbCreateDefColormap(ScreenPtr pScreen)
-{
-	return miCreateDefColormap(pScreen);
-}
-
-Bool
-afbSetVisualTypes(int depth, int visuals, int bitsPerRGB)
-{
-	return miSetVisualTypes(depth, visuals, bitsPerRGB, -1);
-}
-
 /*
  * Given a list of formats for a screen, create a list
  * of visuals and depths for the screen which correspond to
diff --git a/afb/afbgc.c b/afb/afbgc.c
index 03475dd..59c09e0 100644
--- a/afb/afbgc.c
+++ b/afb/afbgc.c
@@ -69,6 +69,9 @@ SOFTWARE.
 
 #include "maskbits.h"
 
+static void afbDestroyGC(GCPtr);
+static void afbValidateGC(GCPtr, unsigned long, DrawablePtr);
+
 static GCFuncs afbFuncs = {
 		afbValidateGC,
 		miChangeGC,
@@ -102,6 +105,33 @@ static GCOps afbGCOps = {
 		afbPushPixels
 };
 
+static void
+afbReduceOpaqueStipple(PixelType fg, PixelType bg, unsigned long planemask,
+		       int depth, unsigned char *rop)
+{
+	register int d;
+	register Pixel mask = 1;
+
+	bg ^= fg;
+
+	for (d = 0; d < depth; d++, mask <<= 1) {
+		if (!(planemask & mask))
+			rop[d] = RROP_NOP;
+		else if (!(bg & mask)) {
+			/* Both fg and bg have a 0 or 1 in this plane */
+			if (fg & mask)
+				rop[d] = RROP_WHITE;
+			else
+				rop[d] = RROP_BLACK;
+		} else {
+			/* Both fg and bg have different bits on this plane */
+			if (fg & mask)
+				rop[d] = RROP_COPY;
+			else
+				rop[d] = RROP_INVERT;
+		}
+	}
+}
 
 Bool
 afbCreateGC(pGC)
@@ -136,6 +166,95 @@ afbCreateGC(pGC)
 	return TRUE;
 }
 
+static void
+afbComputeCompositeClip(GCPtr pGC, DrawablePtr pDrawable)
+{
+	if (pDrawable->type == DRAWABLE_WINDOW) {
+		WindowPtr pWin = (WindowPtr) pDrawable;
+		RegionPtr pregWin;
+		Bool freeTmpClip, freeCompClip;
+
+	if (pGC->subWindowMode == IncludeInferiors) {
+		pregWin = NotClippedByChildren(pWin);
+		freeTmpClip = TRUE;
+	} else {
+		pregWin = &pWin->clipList;
+		freeTmpClip = FALSE;
+	}
+	freeCompClip = pGC->freeCompClip;
+
+	/*
+	 * if there is no client clip, we can get by with just keeping the
+	 * pointer we got, and remembering whether or not should destroy (or
+	 * maybe re-use) it later.  this way, we avoid unnecessary copying of
+	 * regions.  (this wins especially if many clients clip by children
+	 * and have no client clip.)
+	 */
+	if (pGC->clientClipType == CT_NONE) {
+		if (freeCompClip)
+			REGION_DESTROY(pGC->pScreen, pGC->pCompositeClip);
+			pGC->pCompositeClip = pregWin;
+			pGC->freeCompClip = freeTmpClip;
+		} else {
+			/*
+			 * we need one 'real' region to put into the composite clip. if
+			 * pregWin the current composite clip are real, we can get rid of
+			 * one. if pregWin is real and the current composite clip isn't,
+			 * use pregWin for the composite clip. if the current composite
+			 * clip is real and pregWin isn't, use the current composite
+			 * clip. if neither is real, create a new region.
+			 */
+
+			REGION_TRANSLATE(pGC->pScreen, pGC->clientClip,
+			pDrawable->x + pGC->clipOrg.x,
+			pDrawable->y + pGC->clipOrg.y);
+
+			if (freeCompClip) {
+				REGION_INTERSECT(pGC->pScreen, pGC->pCompositeClip, pregWin,
+									  pGC->clientClip);
+				if (freeTmpClip)
+					REGION_DESTROY(pGC->pScreen, pregWin);
+			} else if (freeTmpClip) {
+				REGION_INTERSECT(pGC->pScreen, pregWin, pregWin, pGC->clientClip);
+				pGC->pCompositeClip = pregWin;
+			} else {
+				pGC->pCompositeClip = REGION_CREATE(pGC->pScreen, NullBox, 0);
+				REGION_INTERSECT(pGC->pScreen, pGC->pCompositeClip,
+				pregWin, pGC->clientClip);
+			}
+			pGC->freeCompClip = TRUE;
+			REGION_TRANSLATE(pGC->pScreen, pGC->clientClip,
+			-(pDrawable->x + pGC->clipOrg.x),
+			-(pDrawable->y + pGC->clipOrg.y));
+		}
+	}	/* end of composite clip for a window */
+	else {
+		BoxRec pixbounds;
+
+		/* XXX should we translate by drawable.x/y here ? */
+		pixbounds.x1 = 0;
+		pixbounds.y1 = 0;
+		pixbounds.x2 = pDrawable->width;
+		pixbounds.y2 = pDrawable->height;
+
+		if (pGC->freeCompClip) {
+			REGION_RESET(pGC->pScreen, pGC->pCompositeClip, &pixbounds);
+		} else {
+			pGC->freeCompClip = TRUE;
+			pGC->pCompositeClip = REGION_CREATE(pGC->pScreen, &pixbounds, 1);
+		}
+
+		if (pGC->clientClipType == CT_REGION) {
+			REGION_TRANSLATE(pGC->pScreen, pGC->pCompositeClip, -pGC->clipOrg.x,
+								  -pGC->clipOrg.y);
+			REGION_INTERSECT(pGC->pScreen, pGC->pCompositeClip,
+								  pGC->pCompositeClip, pGC->clientClip);
+			REGION_TRANSLATE(pGC->pScreen, pGC->pCompositeClip, pGC->clipOrg.x,
+								  pGC->clipOrg.y);
+		}
+	}	/* end of composite clip for pixmap */
+} /* end afbComputeCompositeClip */
+
 /* Clipping conventions
 		if the drawable is a window
 			CT_REGION ==> pCompositeClip really is the composite
@@ -147,7 +266,7 @@ afbCreateGC(pGC)
 */
 
 /*ARGSUSED*/
-void
+static void
 afbValidateGC(pGC, changes, pDrawable)
 	register GCPtr 		pGC;
 	unsigned long		changes;
@@ -434,7 +553,7 @@ afbValidateGC(pGC, changes, pDrawable)
 	} /* end of new_fill */
 }
 
-void
+static void
 afbDestroyGC(pGC)
 	GCPtr pGC;
 {
@@ -445,58 +564,6 @@ afbDestroyGC(pGC)
 	miDestroyGCOps(pGC->ops);
 }
 
-/* table to map alu(src, dst) to alu(~src, dst) */
-int afbInverseAlu[16] = {
-		GXclear,
-		GXandInverted,
-		GXnor,
-		GXcopyInverted,
-		GXand,
-		GXnoop,
-		GXequiv,
-		GXorInverted,
-		GXandReverse,
-		GXxor,
-		GXinvert,
-		GXnand,
-		GXcopy,
-		GXor,
-		GXorReverse,
-		GXset
-};
-
-void
-afbReduceOpaqueStipple(fg, bg, planemask, depth, rop)
-register PixelType fg;
-register PixelType bg;
-register unsigned long planemask;
-int depth;
-register unsigned char *rop;
-{
-	register int d;
-	register Pixel mask = 1;
-
-	bg ^= fg;
-
-	for (d = 0; d < depth; d++, mask <<= 1) {
-		if (!(planemask & mask))
-			rop[d] = RROP_NOP;
-		else if (!(bg & mask)) {
-			/* Both fg and bg have a 0 or 1 in this plane */
-			if (fg & mask)
-				rop[d] = RROP_WHITE;
-			else
-				rop[d] = RROP_BLACK;
-		} else {
-			/* Both fg and bg have different bits on this plane */
-			if (fg & mask)
-				rop[d] = RROP_COPY;
-			else
-				rop[d] = RROP_INVERT;
-		}
-	}
-}
-
 void
 afbReduceRop(alu, src, planemask, depth, rop)
 	register int alu;
@@ -615,94 +682,3 @@ afbReduceRop(alu, src, planemask, depth,
 			}
 	}
 }
-
-void
-afbComputeCompositeClip(pGC, pDrawable)
-	GCPtr pGC;
-	DrawablePtr pDrawable;
-{
-	if (pDrawable->type == DRAWABLE_WINDOW) {
-		WindowPtr pWin = (WindowPtr) pDrawable;
-		RegionPtr pregWin;
-		Bool freeTmpClip, freeCompClip;
-
-	if (pGC->subWindowMode == IncludeInferiors) {
-		pregWin = NotClippedByChildren(pWin);
-		freeTmpClip = TRUE;
-	} else {
-		pregWin = &pWin->clipList;
-		freeTmpClip = FALSE;
-	}
-	freeCompClip = pGC->freeCompClip;
-
-	/*
-	 * if there is no client clip, we can get by with just keeping the
-	 * pointer we got, and remembering whether or not should destroy (or
-	 * maybe re-use) it later.  this way, we avoid unnecessary copying of
-	 * regions.  (this wins especially if many clients clip by children
-	 * and have no client clip.)
-	 */
-	if (pGC->clientClipType == CT_NONE) {
-		if (freeCompClip)
-			REGION_DESTROY(pGC->pScreen, pGC->pCompositeClip);
-			pGC->pCompositeClip = pregWin;
-			pGC->freeCompClip = freeTmpClip;
-		} else {
-			/*
-			 * we need one 'real' region to put into the composite clip. if
-			 * pregWin the current composite clip are real, we can get rid of
-			 * one. if pregWin is real and the current composite clip isn't,
-			 * use pregWin for the composite clip. if the current composite
-			 * clip is real and pregWin isn't, use the current composite
-			 * clip. if neither is real, create a new region.
-			 */
-
-			REGION_TRANSLATE(pGC->pScreen, pGC->clientClip,
-			pDrawable->x + pGC->clipOrg.x,
-			pDrawable->y + pGC->clipOrg.y);
-
-			if (freeCompClip) {
-				REGION_INTERSECT(pGC->pScreen, pGC->pCompositeClip, pregWin,
-									  pGC->clientClip);
-				if (freeTmpClip)
-					REGION_DESTROY(pGC->pScreen, pregWin);
-			} else if (freeTmpClip) {
-				REGION_INTERSECT(pGC->pScreen, pregWin, pregWin, pGC->clientClip);
-				pGC->pCompositeClip = pregWin;
-			} else {
-				pGC->pCompositeClip = REGION_CREATE(pGC->pScreen, NullBox, 0);
-				REGION_INTERSECT(pGC->pScreen, pGC->pCompositeClip,
-				pregWin, pGC->clientClip);
-			}
-			pGC->freeCompClip = TRUE;
-			REGION_TRANSLATE(pGC->pScreen, pGC->clientClip,
-			-(pDrawable->x + pGC->clipOrg.x),
-			-(pDrawable->y + pGC->clipOrg.y));
-		}
-	}	/* end of composite clip for a window */
-	else {
-		BoxRec pixbounds;
-
-		/* XXX should we translate by drawable.x/y here ? */
-		pixbounds.x1 = 0;
-		pixbounds.y1 = 0;
-		pixbounds.x2 = pDrawable->width;
-		pixbounds.y2 = pDrawable->height;
-
-		if (pGC->freeCompClip) {
-			REGION_RESET(pGC->pScreen, pGC->pCompositeClip, &pixbounds);
-		} else {
-			pGC->freeCompClip = TRUE;
-			pGC->pCompositeClip = REGION_CREATE(pGC->pScreen, &pixbounds, 1);
-		}
-
-		if (pGC->clientClipType == CT_REGION) {
-			REGION_TRANSLATE(pGC->pScreen, pGC->pCompositeClip, -pGC->clipOrg.x,
-								  -pGC->clipOrg.y);
-			REGION_INTERSECT(pGC->pScreen, pGC->pCompositeClip,
-								  pGC->pCompositeClip, pGC->clientClip);
-			REGION_TRANSLATE(pGC->pScreen, pGC->pCompositeClip, pGC->clipOrg.x,
-								  pGC->clipOrg.y);
-		}
-	}	/* end of composite clip for pixmap */
-} /* end afbComputeCompositeClip */
diff --git a/afb/afbimage.c b/afb/afbimage.c
index c82bb36..81f4973 100644
--- a/afb/afbimage.c
+++ b/afb/afbimage.c
@@ -42,39 +42,8 @@ afbPutImage(pDraw, pGC, depth, x, y, wid
 			(void)(*pGC->ops->CopyPlane)((DrawablePtr)pPixmap, pDraw, pGC, leftPad,
 												  0, width, height, x, y, 1);
 		else {
-#if 0
-			/* XXX: bit plane order wronge ! */
-			pPixmap->drawable.depth = 1;
-			pPixmap->drawable.bitsPerPixel = 1;
-
-			switch (pGC->alu) {
-				case GXcopy:
-					doBitBlt = afbDoBitbltCopy;
-					break;
-				case GXxor:
-					doBitBlt = afbDoBitbltXor;
-					break;
-				case GXcopyInverted:
-					doBitBlt = afbDoBitbltCopyInverted;
-					break;
-				case GXor:
-					doBitBlt = afbDoBitbltOr;
-					break;
-				default:
-					doBitBlt = afbDoBitbltGeneral;
-					break;
-			}
-
-			for (plane = (1L << (pPixmap->drawable.depth - 1)); plane;
-				  plane >>= 1) {
-				(void)afbBitBlt((DrawablePtr)pPixmap, pDraw, pGC, leftPad, 0,
-									  width, height, x, y, doBitBlt, plane);
-				/* pDraw->devKind += sizeDst; */
-			}
-#else
 			(void)(*pGC->ops->CopyArea)((DrawablePtr)pPixmap, pDraw, pGC, leftPad,
 												 0, width, height, x, y);
-#endif
 		}
 
 		pGC->fExpose = TRUE;
diff --git a/afb/afbpixmap.c b/afb/afbpixmap.c
index 6a3a485..77ba535 100644
--- a/afb/afbpixmap.c
+++ b/afb/afbpixmap.c
@@ -118,9 +118,8 @@ afbDestroyPixmap(pPixmap)
 }
 
 
-PixmapPtr
-afbCopyPixmap(pSrc)
-	register PixmapPtr pSrc;
+static PixmapPtr
+afbCopyPixmap(PixmapPtr pSrc)
 {
 	register PixmapPtr pDst;
 	int size;
@@ -148,9 +147,8 @@ afbCopyPixmap(pSrc)
 	  zero out area to be filled with replicate
 	  left shift and or in original as many times as needed
 */
-void
-afbPadPixmap(pPixmap)
-	PixmapPtr pPixmap;
+static void
+afbPadPixmap(PixmapPtr pPixmap)
 {
 	register int width = pPixmap->drawable.width;
 	register int h;
diff --git a/afb/afbscrinit.c b/afb/afbscrinit.c
index 2b0867f..7cb7423 100644
--- a/afb/afbscrinit.c
+++ b/afb/afbscrinit.c
@@ -77,7 +77,7 @@ int afbScreenPrivateIndex;
 
 static unsigned long afbGeneration = 0;
 
-BSFuncRec afbBSFuncRec = {
+static BSFuncRec afbBSFuncRec = {
 	afbSaveAreas,
 	afbRestoreAreas,
 	(BackingStoreSetClipmaskRgnProcPtr) 0,
@@ -85,7 +85,7 @@ BSFuncRec afbBSFuncRec = {
 	(BackingStoreGetSpansPixmapProcPtr) 0,
 };
 
-Bool
+static Bool
 afbCloseScreen(int index, ScreenPtr pScreen)
 {
 	int d;
@@ -119,7 +119,29 @@ afbCreateScreenResources(ScreenPtr pScre
 	return(retval);
 }
 
-Bool
+static PixmapPtr
+afbGetWindowPixmap(WindowPtr pWin)
+{
+#ifdef PIXMAP_PER_WINDOW
+    return (PixmapPtr)(pWin->devPrivates[frameWindowPrivateIndex].ptr);
+#else
+    ScreenPtr pScreen = pWin->drawable.pScreen;
+
+    return (* pScreen->GetScreenPixmap)(pScreen);
+#endif
+}
+
+static void
+afbSetWindowPixmap(WindowPtr pWin, PixmapPtr pPix)
+{
+#ifdef PIXMAP_PER_WINDOW
+    pWin->devPrivates[frameWindowPrivateIndex].ptr = (pointer)pPix;
+#else
+    (* pWin->drawable.pScreen->SetScreenPixmap)(pPix);
+#endif
+}
+
+static Bool
 afbAllocatePrivates(ScreenPtr pScreen, int *pWinIndex, int *pGCIndex)
 {
 	if (afbGeneration != serverGeneration) {
@@ -216,25 +238,3 @@ afbScreenInit(register ScreenPtr pScreen
 
 	return TRUE;
 }
-
-PixmapPtr
-afbGetWindowPixmap(WindowPtr pWin)
-{
-#ifdef PIXMAP_PER_WINDOW
-    return (PixmapPtr)(pWin->devPrivates[frameWindowPrivateIndex].ptr);
-#else
-    ScreenPtr pScreen = pWin->drawable.pScreen;
-
-    return (* pScreen->GetScreenPixmap)(pScreen);
-#endif
-}
-
-void
-afbSetWindowPixmap(WindowPtr pWin, PixmapPtr pPix)
-{
-#ifdef PIXMAP_PER_WINDOW
-    pWin->devPrivates[frameWindowPrivateIndex].ptr = (pointer)pPix;
-#else
-    (* pWin->drawable.pScreen->SetScreenPixmap)(pPix);
-#endif
-}
diff --git a/afb/afbsetsp.c b/afb/afbsetsp.c
index adc7266..cb36dba 100644
--- a/afb/afbsetsp.c
+++ b/afb/afbsetsp.c
@@ -73,20 +73,10 @@ SOFTWARE.
  * boxes, we may not want to start grabbing bits at psrc but at some offset
  * further on.)
  */
-void
-afbSetScanline(y, xOrigin, xStart, xEnd, psrc, alu, pdstBase, widthDst,
-					 sizeDst, depthDst, sizeSrc)
-	int y;
-	int xOrigin;					/* where this scanline starts */
-	int xStart;						/* first bit to use from scanline */
-	int xEnd;						/* last bit to use from scanline + 1 */
-	register PixelType *psrc;
-	register int alu;				/* raster op */
-	PixelType *pdstBase;			/* start of the drawable */
-	int widthDst;					/* width of drawable in words */
-	int sizeDst;
-	int depthDst;
-	int sizeSrc;
+static void
+afbSetScanline(int y, int xOrigin, int xStart, int xEnd, PixelType *psrc,
+	       int alu, PixelType *pdstBase, int widthDst, int sizeDst,
+	       int depthDst, int sizeSrc)
 {
 	int w;							/* width of scanline in bits */
 	register PixelType *pdst;	/* where to put the bits */
diff-tree f36bf1a3e4ce9465ea4a6159c209924a3cafbe58 (from 9a0f25de7ca3c68af867b38936103d17daa92ac6)
Author: Adam Jackson <ajax at benzedrine.nwnk.net>
Date:   Sun Mar 25 12:28:13 2007 -0400

    Delete a dead file.

diff --git a/hw/xfree86/xf4bpp/ppcPolyRec.c b/hw/xfree86/xf4bpp/ppcPolyRec.c
deleted file mode 100644
index d7f8662..0000000
--- a/hw/xfree86/xf4bpp/ppcPolyRec.c
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- * Copyright IBM Corporation 1987,1988,1989
- *
- * All Rights Reserved
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose and without fee is hereby granted,
- * provided that the above copyright notice appear in all copies and that 
- * both that copyright notice and this permission notice appear in
- * supporting documentation, and that the name of IBM not be
- * used in advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- *
- * IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
- * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
- * IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
- * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
- * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
- * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- *
-*/
-/***********************************************************
-
-Copyright (c) 1987  X Consortium
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
-X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
-AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-Except as contained in this notice, the name of the X Consortium shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from the X Consortium.
-
-
-Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
-
-                        All Rights Reserved
-
-Permission to use, copy, modify, and distribute this software and its 
-documentation for any purpose and without fee is hereby granted, 
-provided that the above copyright notice appear in all copies and that
-both that copyright notice and this permission notice appear in 
-supporting documentation, and that the name of Digital not be
-used in advertising or publicity pertaining to distribution of the
-software without specific, written prior permission.  
-
-DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
-ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
-DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
-ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
-WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
-ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
-SOFTWARE.
-
-******************************************************************/
-/* $XConsortium: ppcPolyRec.c /main/4 1996/02/21 17:58:11 kaleb $ */
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include "xf4bpp.h"
-
-void
-xf4bppPolyRectangle(pDraw, pGC, nrects, pRects)
-    DrawablePtr	pDraw;
-    GCPtr	pGC;
-    int		nrects;
-    xRectangle	*pRects;
-{
-    int i;
-    xRectangle *pR = pRects;
-    xRectangle *tmprects, *tmprectsinit;
-    int lw, fs, ss;
-
-    if ( ! ( tmprectsinit = tmprects = (xRectangle *)ALLOCATE_LOCAL( ( sizeof ( xRectangle ) * nrects ) << 2 ) ) )
-	return;
-
-    lw = pGC->lineWidth;
-    ss = lw >> 1;		/* skinny side of line */
-    fs = ( lw + 1 ) >> 1;	/* fat side of line */
-
-    for (i=0; i<nrects; i++)
-    {
-	tmprects->x = pR->x - ss;
-	tmprects->y = pR->y - ss;
-	tmprects->width = pR->width + lw;
-	tmprects->height = lw;
-	tmprects++;
-
-	tmprects->x = pR->x - ss;
-	tmprects->y = pR->y + fs;
-	tmprects->width = lw;
-	tmprects->height = pR->height - lw;
-	tmprects++;
-
-	tmprects->x = pR->x + pR->width - ss;
-	tmprects->y = pR->y + fs;
-	tmprects->width = lw;
-	tmprects->height = pR->height - lw;
-	tmprects++;
-
-	tmprects->x = pR->x - ss;
-	tmprects->y = pR->y + pR->height - ss;
-	tmprects->width = pR->width + lw;
-	tmprects->height = lw;
-	tmprects++;
-
-	pR++;
-    }
-
-    (* pGC->ops->PolyFillRect)( pDraw, pGC, nrects << 2, tmprectsinit );
-
-    DEALLOCATE_LOCAL( tmprectsinit );
-    return ;
-}
diff-tree 9a0f25de7ca3c68af867b38936103d17daa92ac6 (from ac2356843e38b3400142bc54b65393c12976fc07)
Author: Adam Jackson <ajax at benzedrine.nwnk.net>
Date:   Sun Mar 25 12:27:01 2007 -0400

    Static cleanups, dead code deletion.

diff --git a/Xi/exglobals.h b/Xi/exglobals.h
index 3afd1bb..61ebca8 100644
--- a/Xi/exglobals.h
+++ b/Xi/exglobals.h
@@ -37,7 +37,6 @@ OR IN CONNECTION WITH THE USE OR PERFORM
 
 extern int IReqCode;
 extern int BadDevice;
-extern int BadEvent;
 extern int BadMode;
 extern int DeviceBusy;
 extern int BadClass;
diff --git a/Xi/extinit.c b/Xi/extinit.c
index 4548837..d14e133 100644
--- a/Xi/extinit.c
+++ b/Xi/extinit.c
@@ -116,7 +116,7 @@ int ExtEventIndex;
 Mask ExtValidMasks[EMASKSIZE];
 Mask ExtExclusiveMasks[EMASKSIZE];
 
-struct dev_type
+static struct dev_type
 {
     Atom type;
     char *name;
@@ -152,7 +152,7 @@ XExtEventInfo EventInfo[32];
 
 int IReqCode = 0;
 int BadDevice = 0;
-int BadEvent = 1;
+static int BadEvent = 1;
 int BadMode = 2;
 int DeviceBusy = 3;
 int BadClass = 4;
diff --git a/composite/compalloc.c b/composite/compalloc.c
index 5bbf0a2..ce1ef7d 100644
--- a/composite/compalloc.c
+++ b/composite/compalloc.c
@@ -48,7 +48,7 @@
 
 #include "compint.h"
 
-void
+static void
 compReportDamage (DamagePtr pDamage, RegionPtr pRegion, void *closure)
 {
     WindowPtr	    pWin = (WindowPtr) closure;
diff --git a/composite/compext.c b/composite/compext.c
index 13936fa..4c25cc7 100644
--- a/composite/compext.c
+++ b/composite/compext.c
@@ -50,10 +50,10 @@
 #include "compint.h"
 
 static CARD8	CompositeReqCode;
-int		CompositeClientPrivateIndex;
+static int	CompositeClientPrivateIndex;
 RESTYPE		CompositeClientWindowType;
 RESTYPE		CompositeClientSubwindowsType;
-RESTYPE		CompositeClientOverlayType;
+static RESTYPE	CompositeClientOverlayType;
 
 static void deleteCompOverlayClient (CompOverlayClientPtr pOcToDel, 
 				     ScreenPtr pScreen);
@@ -423,7 +423,7 @@ createOverlayWindow (ScreenPtr pScreen)
     return pWin;
 }
 
-int
+static int
 ProcCompositeGetOverlayWindow (ClientPtr client)
 {
     REQUEST(xCompositeGetOverlayWindowReq); 
@@ -477,7 +477,7 @@ ProcCompositeGetOverlayWindow (ClientPtr
     return client->noClientException;
 }
 
-int
+static int
 ProcCompositeReleaseOverlayWindow (ClientPtr client)
 {
     REQUEST(xCompositeReleaseOverlayWindowReq); 
@@ -515,7 +515,7 @@ ProcCompositeReleaseOverlayWindow (Clien
     return client->noClientException;
 }
 
-int (*ProcCompositeVector[CompositeNumberRequests])(ClientPtr) = {
+static int (*ProcCompositeVector[CompositeNumberRequests])(ClientPtr) = {
     ProcCompositeQueryVersion,
     ProcCompositeRedirectWindow,
     ProcCompositeRedirectSubwindows,
@@ -625,7 +625,7 @@ SProcCompositeNameWindowPixmap (ClientPt
     return (*ProcCompositeVector[stuff->compositeReqType]) (client);
 }
 
-int
+static int
 SProcCompositeGetOverlayWindow (ClientPtr client)
 {
     int n;
@@ -637,7 +637,7 @@ SProcCompositeGetOverlayWindow (ClientPt
     return (*ProcCompositeVector[stuff->compositeReqType]) (client);
 }
 
-int
+static int
 SProcCompositeReleaseOverlayWindow (ClientPtr client)
 {
     int n;
@@ -649,7 +649,7 @@ SProcCompositeReleaseOverlayWindow (Clie
     return (*ProcCompositeVector[stuff->compositeReqType]) (client);
 }
 
-int (*SProcCompositeVector[CompositeNumberRequests])(ClientPtr) = {
+static int (*SProcCompositeVector[CompositeNumberRequests])(ClientPtr) = {
     SProcCompositeQueryVersion,
     SProcCompositeRedirectWindow,
     SProcCompositeRedirectSubwindows,
diff --git a/composite/compinit.c b/composite/compinit.c
index 1d5cc7b..27261dc 100644
--- a/composite/compinit.c
+++ b/composite/compinit.c
@@ -51,7 +51,7 @@
 int	CompScreenPrivateIndex;
 int	CompWindowPrivateIndex;
 int	CompSubwindowsPrivateIndex;
-int	CompGeneration;
+static int	CompGeneration;
 
 
 static Bool
diff --git a/composite/compint.h b/composite/compint.h
index 3958b3b..0bd55a9 100644
--- a/composite/compint.h
+++ b/composite/compint.h
@@ -171,9 +171,6 @@ extern RESTYPE		CompositeClientSubwindow
  * compalloc.c
  */
 
-void
-compReportDamage (DamagePtr pDamage, RegionPtr pRegion, void *closure);
-
 Bool
 compRedirectWindow (ClientPtr pClient, WindowPtr pWin, int update);
 
@@ -292,18 +289,6 @@ compWindowUpdate (WindowPtr pWin);
 void
 deleteCompOverlayClientsForScreen (ScreenPtr pScreen);
 
-int
-ProcCompositeGetOverlayWindow (ClientPtr client);
-
-int
-ProcCompositeReleaseOverlayWindow (ClientPtr client);
-
-int
-SProcCompositeGetOverlayWindow (ClientPtr client);
-
-int
-SProcCompositeReleaseOverlayWindow (ClientPtr client);
-
 WindowPtr
 CompositeRealChildHead (WindowPtr pWin);
 
diff --git a/damageext/damageext.c b/damageext/damageext.c
index 739d20f..57a7bce 100755
--- a/damageext/damageext.c
+++ b/damageext/damageext.c
@@ -28,12 +28,12 @@
 
 #include "damageextint.h"
 
-unsigned char	DamageReqCode;
-int		DamageEventBase;
-int		DamageErrorBase;
-int		DamageClientPrivateIndex;
-RESTYPE		DamageExtType;
-RESTYPE		DamageExtWinType;
+static unsigned char	DamageReqCode;
+static int		DamageEventBase;
+static int		DamageErrorBase;
+static int		DamageClientPrivateIndex;
+static RESTYPE		DamageExtType;
+static RESTYPE		DamageExtWinType;
 
 /* Version of the damage extension supported by the server, as opposed to the
  * DAMAGE_* defines from damageproto for what version the proto header
@@ -319,7 +319,7 @@ static const int version_requests[] = {
 
 #define NUM_VERSION_REQUESTS	(sizeof (version_requests) / sizeof (version_requests[0]))
     
-int	(*ProcDamageVector[XDamageNumberRequests])(ClientPtr) = {
+static int (*ProcDamageVector[XDamageNumberRequests])(ClientPtr) = {
 /*************** Version 1 ******************/
     ProcDamageQueryVersion,
     ProcDamageCreate,
@@ -408,7 +408,7 @@ SProcDamageAdd (ClientPtr client)
     return (*ProcDamageVector[stuff->damageReqType]) (client);
 }
 
-int	(*SProcDamageVector[XDamageNumberRequests])(ClientPtr) = {
+static int (*SProcDamageVector[XDamageNumberRequests])(ClientPtr) = {
 /*************** Version 1 ******************/
     SProcDamageQueryVersion,
     SProcDamageCreate,
@@ -478,7 +478,7 @@ FreeDamageExtWin (pointer value, XID wid
     return Success;
 }
 
-void
+static void
 SDamageNotifyEvent (xDamageNotifyEvent *from,
 		    xDamageNotifyEvent *to)
 {
diff --git a/damageext/damageextint.h b/damageext/damageextint.h
index 6f14e4e..1ed07de 100644
--- a/damageext/damageextint.h
+++ b/damageext/damageextint.h
@@ -44,13 +44,6 @@
 #include "damage.h" 
 #include "xfixes.h"
 
-extern unsigned char	DamageReqCode;
-extern int		DamageEventBase;
-extern int		DamageErrorBase;
-extern int		DamageClientPrivateIndex;
-extern RESTYPE		DamageExtType;
-extern RESTYPE		DamageExtWinType;
-
 typedef struct _DamageClient {
     CARD32	major_version;
     CARD32	minor_version;
@@ -67,9 +60,6 @@ typedef struct _DamageExt {
     XID			id;
 } DamageExtRec, *DamageExtPtr;
 
-extern int	(*ProcDamageVector[/*XDamageNumberRequests*/])(ClientPtr);
-extern int	(*SProcDamageVector[/*XDamageNumberRequests*/])(ClientPtr);
-
 #define VERIFY_DAMAGEEXT(pDamageExt, rid, client, mode) { \
     pDamageExt = SecurityLookupIDByType (client, rid, DamageExtType, mode); \
     if (!pDamageExt) { \
@@ -79,10 +69,6 @@ extern int	(*SProcDamageVector[/*XDamage
 }
 
 void
-SDamageNotifyEvent (xDamageNotifyEvent *from,
-		    xDamageNotifyEvent *to);
-
-void
 DamageExtSetCritical (ClientPtr pClient, Bool critical);
 
 #endif /* _DAMAGEEXTINT_H_ */
diff --git a/dbe/midbe.c b/dbe/midbe.c
index e687b98..76f0577 100644
--- a/dbe/midbe.c
+++ b/dbe/midbe.c
@@ -59,21 +59,12 @@
 
 #include <stdio.h>
 
-/* DEFINES */
-
-
-/* TYPEDEFS */
-
-
-/* GLOBALS */
-
 static int	miDbePrivPrivGeneration  =  0;
 static int	miDbeWindowPrivPrivIndex = -1;
-RESTYPE		dbeDrawableResType;
-RESTYPE		dbeWindowPrivResType;
-int		dbeScreenPrivIndex = -1;
-int		dbeWindowPrivIndex = -1;
-
+static RESTYPE	dbeDrawableResType;
+static RESTYPE	dbeWindowPrivResType;
+static int	dbeScreenPrivIndex = -1;
+static int	dbeWindowPrivIndex = -1;
 
 
 /******************************************************************************
diff --git a/dix/devices.c b/dix/devices.c
index 5996b75..f622be7 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -79,7 +79,8 @@ SOFTWARE.
 #include "exglobals.h"
 #include "exevents.h"
 
-int CoreDevicePrivatesIndex = 0, CoreDevicePrivatesGeneration = -1;
+int CoreDevicePrivatesIndex = 0;
+static int CoreDevicePrivatesGeneration = -1;
 
 DeviceIntPtr
 AddInputDevice(DeviceProc deviceProc, Bool autoStart)
@@ -926,16 +927,16 @@ InitPtrFeedbackClassDeviceStruct(DeviceI
 }
 
 
-LedCtrl defaultLedControl = {
+static LedCtrl defaultLedControl = {
 	DEFAULT_LEDS, DEFAULT_LEDS_MASK, 0};
 
-BellCtrl defaultBellControl = {
+static BellCtrl defaultBellControl = {
 	DEFAULT_BELL,
 	DEFAULT_BELL_PITCH,
 	DEFAULT_BELL_DURATION,
 	0};
 
-IntegerCtrl defaultIntegerControl = {
+static IntegerCtrl defaultIntegerControl = {
 	DEFAULT_INT_RESOLUTION,
 	DEFAULT_INT_MIN_VALUE,
 	DEFAULT_INT_MAX_VALUE,
diff --git a/dix/dispatch.c b/dix/dispatch.c
index 32f6788..02665ed 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -297,8 +297,8 @@ long	    SmartScheduleSlice = SMART_SCHE
 long	    SmartScheduleInterval = SMART_SCHEDULE_DEFAULT_INTERVAL;
 long	    SmartScheduleMaxSlice = SMART_SCHEDULE_MAX_SLICE;
 long	    SmartScheduleTime;
-ClientPtr   SmartLastClient;
-int	    SmartLastIndex[SMART_MAX_PRIORITY-SMART_MIN_PRIORITY+1];
+static ClientPtr   SmartLastClient;
+static int	   SmartLastIndex[SMART_MAX_PRIORITY-SMART_MIN_PRIORITY+1];
 int         SmartScheduleClient(int *clientReady, int nready);
 
 #ifdef SMART_DEBUG
diff --git a/dix/events.c b/dix/events.c
index 02598a3..e008e36 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -156,7 +156,7 @@ extern Mask      xevieFilters[128];
 extern int       xevieEventSent;
 extern int       xevieKBEventSent;
 int    xeviegrabState = 0;
-xEvent *xeviexE;
+static xEvent *xeviexE;
 #endif
 
 #include <X11/extensions/XIproto.h>
diff --git a/dix/extension.c b/dix/extension.c
index dc1a76f..fb4ee6b 100644
--- a/dix/extension.c
+++ b/dix/extension.c
@@ -66,7 +66,7 @@ SOFTWARE.
 #define LAST_EVENT  128
 #define LAST_ERROR 255
 
-ScreenProcEntry AuxillaryScreenProcs[MAXSCREENS];
+static ScreenProcEntry AuxillaryScreenProcs[MAXSCREENS];
 
 static ExtensionEntry **extensions = (ExtensionEntry **)NULL;
 
diff --git a/dix/gc.c b/dix/gc.c
index 89b246d..7b7953d 100644
--- a/dix/gc.c
+++ b/dix/gc.c
@@ -69,7 +69,7 @@ extern FontPtr defaultFont;
 
 static Bool CreateDefaultTile(GCPtr pGC);
 
-unsigned char DefaultDash[2] = {4, 4};
+static unsigned char DefaultDash[2] = {4, 4};
 
 _X_EXPORT void
 ValidateGC(DrawablePtr pDraw, GC *pGC)
diff --git a/dix/resource.c b/dix/resource.c
index 7092b2f..a5a7eed 100644
--- a/dix/resource.c
+++ b/dix/resource.c
@@ -246,7 +246,7 @@ CreateNewResourceClass()
     return next;
 }
 
-ClientResourceRec clientTable[MAXCLIENTS];
+static ClientResourceRec clientTable[MAXCLIENTS];
 
 /*****************
  * InitClientResources
diff --git a/hw/xfree86/common/xf86Bus.c b/hw/xfree86/common/xf86Bus.c
index 7617bf7..e1cbdbb 100644
--- a/hw/xfree86/common/xf86Bus.c
+++ b/hw/xfree86/common/xf86Bus.c
@@ -2847,7 +2847,7 @@ xf86IsListSubsetOf(resPtr list, resPtr B
     return TRUE;
 }
 
-resPtr
+static resPtr
 findIntersect(resRange Range, resPtr list)
 {
     resRange range;
diff --git a/hw/xfree86/common/xf86Bus.h b/hw/xfree86/common/xf86Bus.h
index b638e90..225a5c7 100644
--- a/hw/xfree86/common/xf86Bus.h
+++ b/hw/xfree86/common/xf86Bus.h
@@ -143,7 +143,6 @@ memType ChkConflict(resRange *rgp, resPt
 Bool xf86IsSubsetOf(resRange range, resPtr list);
 Bool xf86IsListSubsetOf(resPtr list, resPtr BaseList);
 resPtr xf86ExtractTypeFromList(resPtr list, unsigned long type);
-resPtr findIntersect(resRange Range, resPtr list);
 resPtr xf86FindIntersect(resRange Range, resPtr list);
 void RemoveOverlaps(resPtr target, resPtr list, Bool pow2Alignment,
 		    Bool useEstimated);
diff --git a/hw/xfree86/common/xf86Configure.c b/hw/xfree86/common/xf86Configure.c
index f71486c..4b482df 100644
--- a/hw/xfree86/common/xf86Configure.c
+++ b/hw/xfree86/common/xf86Configure.c
@@ -68,7 +68,7 @@ static int nDevToConfig = 0, CurrentDriv
 
 _X_EXPORT xf86MonPtr ConfiguredMonitor;
 Bool xf86DoConfigurePass1 = TRUE;
-Bool foundMouse = FALSE;
+static Bool foundMouse = FALSE;
 
 #if defined(__UNIXOS2__)
 #define DFLT_MOUSE_DEV "mouse$"
diff --git a/hw/xfree86/common/xf86Events.c b/hw/xfree86/common/xf86Events.c
index 05e62f1..eae6cb1 100644
--- a/hw/xfree86/common/xf86Events.c
+++ b/hw/xfree86/common/xf86Events.c
@@ -126,9 +126,9 @@ extern Bool noXkbExtension;
  */
 
 #ifdef USE_VT_SYSREQ
-Bool VTSysreqToggle = FALSE;
+static Bool VTSysreqToggle = FALSE;
 #endif /* !USE_VT_SYSREQ */
-Bool VTSwitchEnabled = TRUE;		/* Allows run-time disabling for
+static Bool VTSwitchEnabled = TRUE;	/* Allows run-time disabling for
                                          *BSD and for avoiding VT
                                          switches when using the DRI
                                          automatic full screen mode.*/
diff --git a/hw/xfree86/common/xf86xv.c b/hw/xfree86/common/xf86xv.c
index 3e908b8..2b097d2 100644
--- a/hw/xfree86/common/xf86xv.c
+++ b/hw/xfree86/common/xf86xv.c
@@ -110,7 +110,7 @@ static void xf86XVAdjustFrame(int index,
 static Bool xf86XVInitAdaptors(ScreenPtr, XF86VideoAdaptorPtr*, int);
 
 
-int XF86XVWindowIndex = -1;
+static int XF86XVWindowIndex = -1;
 int XF86XvScreenIndex = -1;
 static unsigned long XF86XVGeneration = 0;
 static unsigned long PortResource = 0;
diff --git a/hw/xfree86/loader/loader.c b/hw/xfree86/loader/loader.c
index ddd624c..774a4c4 100644
--- a/hw/xfree86/loader/loader.c
+++ b/hw/xfree86/loader/loader.c
@@ -189,101 +189,6 @@ _LoaderListPop(int handle)
     return 0;
 }
 
-/*
- * _LoaderHandleToName() will return the name of the first module with a
- * given handle. This requires getting the last module on the LIFO with
- * the given handle.
- */
-char *
-_LoaderHandleToName(int handle)
-{
-    loaderPtr item = listHead;
-    loaderPtr aritem = NULL;
-    loaderPtr lastitem = NULL;
-
-    if (handle < 0) {
-	return "(built-in)";
-    }
-    while (item) {
-	if (item->handle == handle) {
-	    if (strchr(item->name, ':') == NULL)
-		aritem = item;
-	    else
-		lastitem = item;
-	}
-	item = item->next;
-    }
-
-    if (aritem)
-	return aritem->name;
-
-    if (lastitem)
-	return lastitem->name;
-
-    return 0;
-}
-
-/*
- * _LoaderHandleToCanonicalName() will return the cname of the first module
- * with a given handle. This requires getting the last module on the LIFO with
- * the given handle.
- */
-char *
-_LoaderHandleToCanonicalName(int handle)
-{
-    loaderPtr item = listHead;
-    loaderPtr lastitem = NULL;
-
-    if (handle < 0) {
-	return "(built-in)";
-    }
-    while (item) {
-	if (item->handle == handle) {
-	    lastitem = item;
-	}
-	item = item->next;
-    }
-
-    if (lastitem)
-	return lastitem->cname;
-
-    return NULL;
-}
-
-/*
- * _LoaderModuleToName() will return the name of the first module with a
- * given handle. This requires getting the last module on the LIFO with
- * the given handle.
- */
-char *
-_LoaderModuleToName(int module)
-{
-    loaderPtr item = listHead;
-    loaderPtr aritem = NULL;
-    loaderPtr lastitem = NULL;
-
-    if (module < 0) {
-	return "(built-in)";
-    }
-    while (item) {
-	if (item->module == module) {
-	    if (strchr(item->name, ':') == NULL)
-		aritem = item;
-	    else
-		lastitem = item;
-	}
-	item = item->next;
-    }
-
-    if (aritem)
-	return aritem->name;
-
-    if (lastitem)
-	return lastitem->name;
-
-    return 0;
-}
-
 /* These four are just ABI stubs */
 _X_EXPORT void
 LoaderRefSymbols(const char *sym0, ...)
@@ -450,35 +355,14 @@ LoaderUnload(int handle)
     return 0;
 }
 
-void
-LoaderDuplicateSymbol(const char *symbol, const int handle)
-{
-    ErrorF("Duplicate symbol %s in %s\n", symbol,
-	   listHead ? listHead->name : "(built-in)");
-    ErrorF("Also defined in %s\n", _LoaderHandleToName(handle));
-    FatalError("Module load failure\n");
-}
-
 unsigned long LoaderOptions = 0;
 
 void
-LoaderResetOptions(void)
-{
-    LoaderOptions = 0;
-}
-
-void
 LoaderSetOptions(unsigned long opts)
 {
     LoaderOptions |= opts;
 }
 
-void
-LoaderClearOptions(unsigned long opts)
-{
-    LoaderOptions &= ~opts;
-}
-
 _X_EXPORT int
 LoaderGetABIVersion(const char *abiclass)
 {
diff --git a/hw/xfree86/loader/loaderProcs.h b/hw/xfree86/loader/loaderProcs.h
index ecbd676..b71ad45 100644
--- a/hw/xfree86/loader/loaderProcs.h
+++ b/hw/xfree86/loader/loaderProcs.h
@@ -97,9 +97,6 @@ void LoadFont(FontModule *);
 void UnloadModule(ModuleDescPtr);
 void UnloadSubModule(ModuleDescPtr);
 void UnloadDriver(ModuleDescPtr);
-void FreeModuleDesc(ModuleDescPtr mod);
-ModuleDescPtr NewModuleDesc(const char *);
-ModuleDescPtr AddSibling(ModuleDescPtr head, ModuleDescPtr new);
 void LoaderSetPath(const char *path);
 void LoaderSortExtensions(void);
 
@@ -108,7 +105,6 @@ unsigned long LoaderGetModuleVersion(Mod
 
 void LoaderResetOptions(void);
 void LoaderSetOptions(unsigned long);
-void LoaderClearOptions(unsigned long);
 
 /* Options for LoaderSetOptions */
 #define LDR_OPT_ABI_MISMATCH_NONFATAL		0x0001
diff --git a/hw/xfree86/loader/loadmod.c b/hw/xfree86/loader/loadmod.c
index a83b889..db12da4 100644
--- a/hw/xfree86/loader/loadmod.c
+++ b/hw/xfree86/loader/loadmod.c
@@ -745,6 +745,13 @@ CheckVersion(const char *module, XF86Mod
     return TRUE;
 }
 
+static ModuleDescPtr
+AddSibling(ModuleDescPtr head, ModuleDescPtr new)
+{
+    new->sib = head;
+    return (new);
+}
+
 _X_EXPORT ModuleDescPtr
 LoadSubModule(ModuleDescPtr parent, const char *module,
 	      const char **subdirlist, const char **patternlist,
@@ -775,35 +782,28 @@ LoadSubModule(ModuleDescPtr parent, cons
     return submod;
 }
 
-ModuleDescPtr
-LoadSubModuleLocal(ModuleDescPtr parent, const char *module,
-		   const char **subdirlist, const char **patternlist,
-		   pointer options, const XF86ModReqInfo * modreq,
-		   int *errmaj, int *errmin)
+static ModuleDescPtr
+NewModuleDesc(const char *name)
 {
-    ModuleDescPtr submod;
-
-    xf86MsgVerb(X_INFO, 3, "Loading local sub module \"%s\"\n", module);
+    ModuleDescPtr mdp = xalloc(sizeof(ModuleDesc));
 
-    if (PathIsAbsolute(module))
-    {
-	xf86Msg(X_ERROR,
-		"LoadSubModule: Absolute module path not permitted: \"%s\"\n",
-		module);
-	if (errmaj)
-	    *errmaj = LDR_BADUSAGE;
-	if (errmin)
-	    *errmin = 0;
-	return NULL;
+    if (mdp) {
+	mdp->child = NULL;
+	mdp->sib = NULL;
+	mdp->parent = NULL;
+	mdp->demand_next = NULL;
+	mdp->name = xstrdup(name);
+	mdp->filename = NULL;
+	mdp->identifier = NULL;
+	mdp->client_id = 0;
+	mdp->in_use = 0;
+	mdp->handle = -1;
+	mdp->SetupProc = NULL;
+	mdp->TearDownProc = NULL;
+	mdp->TearDownData = NULL;
     }
 
-    submod = doLoadModule(module, NULL, subdirlist, patternlist, options,
-			  modreq, errmaj, errmin, 0);
-    if (submod && submod != (ModuleDescPtr) 1) {
-	parent->child = AddSibling(parent->child, submod);
-	submod->parent = parent;
-    }
-    return submod;
+    return (mdp);
 }
 
 _X_EXPORT ModuleDescPtr
@@ -1099,26 +1099,12 @@ LoadModule(const char *module, const cha
 		      modreq, errmaj, errmin, LD_FLAG_GLOBAL);
 }
 
-ModuleDescPtr
-LoadDriver(const char *module, const char *path, int handle, pointer options,
-	   int *errmaj, int *errmin)
-{
-    return LoadModule(module, path, NULL, NULL, options, NULL, errmaj,
-		      errmin);
-}
-
 void
 UnloadModule(ModuleDescPtr mod)
 {
     UnloadModuleOrDriver(mod);
 }
 
-void
-UnloadDriver(ModuleDescPtr mod)
-{
-    UnloadModuleOrDriver(mod);
-}
-
 static void
 UnloadModuleOrDriver(ModuleDescPtr mod)
 {
@@ -1168,7 +1154,7 @@ UnloadSubModule(ModuleDescPtr mod)
     xfree(mod);
 }
 
-void
+static void
 FreeModuleDesc(ModuleDescPtr head)
 {
     ModuleDescPtr sibs, prev;
@@ -1177,7 +1163,7 @@ FreeModuleDesc(ModuleDescPtr head)
 	return;
     /*
      * only free it if it's not marked as in use. In use means that it may
-     * be unloaded someday, and UnloadModule or UnloadDriver will free it
+     * be unloaded someday, and UnloadModule will free it
      */
     if (head->in_use)
 	return;
@@ -1192,38 +1178,6 @@ FreeModuleDesc(ModuleDescPtr head)
     }
 }
 
-ModuleDescPtr
-NewModuleDesc(const char *name)
-{
-    ModuleDescPtr mdp = xalloc(sizeof(ModuleDesc));
-
-    if (mdp) {
-	mdp->child = NULL;
-	mdp->sib = NULL;
-	mdp->parent = NULL;
-	mdp->demand_next = NULL;
-	mdp->name = xstrdup(name);
-	mdp->filename = NULL;
-	mdp->identifier = NULL;
-	mdp->client_id = 0;
-	mdp->in_use = 0;
-	mdp->handle = -1;
-	mdp->SetupProc = NULL;
-	mdp->TearDownProc = NULL;
-	mdp->TearDownData = NULL;
-    }
-
-    return (mdp);
-}
-
-ModuleDescPtr
-AddSibling(ModuleDescPtr head, ModuleDescPtr new)
-{
-    new->sib = head;
-    return (new);
-
-}
-
 static void
 RemoveChild(ModuleDescPtr child)
 {
diff --git a/hw/xfree86/parser/DRI.c b/hw/xfree86/parser/DRI.c
index dc75cd2..18644bc 100644
--- a/hw/xfree86/parser/DRI.c
+++ b/hw/xfree86/parser/DRI.c
@@ -48,7 +48,21 @@ static xf86ConfigSymTabRec DRITab[] =
 
 #define CLEANUP xf86freeBuffersList
 
-XF86ConfBuffersPtr
+static void
+xf86freeBuffersList (XF86ConfBuffersPtr ptr)
+{
+    XF86ConfBuffersPtr prev;
+
+    while (ptr) {
+	TestFree (ptr->buf_flags);
+	TestFree (ptr->buf_comment);
+	prev = ptr;
+	ptr  = ptr->list.next;
+	xf86conffree (prev);
+    }
+}
+
+static XF86ConfBuffersPtr
 xf86parseBuffers (void)
 {
     int token;
@@ -169,18 +183,3 @@ xf86freeDRI (XF86ConfDRIPtr ptr)
     TestFree (ptr->dri_comment);
     xf86conffree (ptr);
 }
-
-void
-xf86freeBuffersList (XF86ConfBuffersPtr ptr)
-{
-    XF86ConfBuffersPtr prev;
-
-    while (ptr) {
-	TestFree (ptr->buf_flags);
-	TestFree (ptr->buf_comment);
-	prev = ptr;
-	ptr  = ptr->list.next;
-	xf86conffree (prev);
-    }
-}
-
diff --git a/hw/xfree86/parser/Flags.c b/hw/xfree86/parser/Flags.c
index 7ab70d1..4adea1a 100644
--- a/hw/xfree86/parser/Flags.c
+++ b/hw/xfree86/parser/Flags.c
@@ -441,15 +441,6 @@ xf86uLongToString(unsigned long i)
 	return s;
 }
 
-void
-xf86debugListOptions(XF86OptionPtr Options)
-{
-	while (Options) {
-		ErrorF("Option: %s Value: %s\n",Options->opt_name,Options->opt_val);
-		Options = Options->list.next;
-	}
-}
-
 XF86OptionPtr
 xf86parseOption(XF86OptionPtr head)
 {
diff --git a/hw/xfree86/parser/Layout.c b/hw/xfree86/parser/Layout.c
index b9f4e9e..5d1348a 100644
--- a/hw/xfree86/parser/Layout.c
+++ b/hw/xfree86/parser/Layout.c
@@ -382,24 +382,7 @@ xf86printLayoutSection (FILE * cf, XF86C
 	}
 }
 
-void
-xf86freeLayoutList (XF86ConfLayoutPtr ptr)
-{
-	XF86ConfLayoutPtr prev;
-
-	while (ptr)
-	{
-		TestFree (ptr->lay_identifier);
-		TestFree (ptr->lay_comment);
-		xf86freeAdjacencyList (ptr->lay_adjacency_lst);
-		xf86freeInputrefList (ptr->lay_input_lst);
-		prev = ptr;
-		ptr = ptr->list.next;
-		xf86conffree (prev);
-	}
-}
-
-void
+static void
 xf86freeAdjacencyList (XF86ConfAdjacencyPtr ptr)
 {
 	XF86ConfAdjacencyPtr prev;
@@ -419,7 +402,7 @@ xf86freeAdjacencyList (XF86ConfAdjacency
 
 }
 
-void
+static void
 xf86freeInputrefList (XF86ConfInputrefPtr ptr)
 {
 	XF86ConfInputrefPtr prev;
@@ -435,6 +418,23 @@ xf86freeInputrefList (XF86ConfInputrefPt
 
 }
 
+void
+xf86freeLayoutList (XF86ConfLayoutPtr ptr)
+{
+	XF86ConfLayoutPtr prev;
+
+	while (ptr)
+	{
+		TestFree (ptr->lay_identifier);
+		TestFree (ptr->lay_comment);
+		xf86freeAdjacencyList (ptr->lay_adjacency_lst);
+		xf86freeInputrefList (ptr->lay_input_lst);
+		prev = ptr;
+		ptr = ptr->list.next;
+		xf86conffree (prev);
+	}
+}
+
 #define CheckScreen(str, ptr)\
 if (str[0] != '\0') \
 { \
diff --git a/hw/xfree86/parser/Module.c b/hw/xfree86/parser/Module.c
index f3ed9d1..81eff18 100644
--- a/hw/xfree86/parser/Module.c
+++ b/hw/xfree86/parser/Module.c
@@ -83,7 +83,7 @@ static xf86ConfigSymTabRec ModuleTab[] =
 
 #define CLEANUP xf86freeModules
 
-XF86LoadPtr
+static XF86LoadPtr
 xf86parseModuleSubSection (XF86LoadPtr head, char *name)
 {
 	int token;
diff --git a/hw/xfree86/parser/Monitor.c b/hw/xfree86/parser/Monitor.c
index 9dd0b1b..4bff4b2 100644
--- a/hw/xfree86/parser/Monitor.c
+++ b/hw/xfree86/parser/Monitor.c
@@ -124,7 +124,21 @@ static xf86ConfigSymTabRec ModeTab[] =
 
 #define CLEANUP xf86freeModeLineList
 
-XF86ConfModeLinePtr
+static void
+xf86freeModeLineList (XF86ConfModeLinePtr ptr)
+{
+	XF86ConfModeLinePtr prev;
+	while (ptr)
+	{
+		TestFree (ptr->ml_identifier);
+		TestFree (ptr->ml_comment);
+		prev = ptr;
+		ptr = ptr->list.next;
+		xf86conffree (prev);
+	}
+}
+
+static XF86ConfModeLinePtr
 xf86parseModeLine (void)
 {
 	int token;
@@ -253,7 +267,7 @@ xf86parseModeLine (void)
 	return (ptr);
 }
 
-XF86ConfModeLinePtr
+static XF86ConfModeLinePtr
 xf86parseVerboseMode (void)
 {
 	int token, token2;
@@ -830,20 +844,6 @@ xf86freeModesList (XF86ConfModesPtr ptr)
 	}
 }
 
-void
-xf86freeModeLineList (XF86ConfModeLinePtr ptr)
-{
-	XF86ConfModeLinePtr prev;
-	while (ptr)
-	{
-		TestFree (ptr->ml_identifier);
-		TestFree (ptr->ml_comment);
-		prev = ptr;
-		ptr = ptr->list.next;
-		xf86conffree (prev);
-	}
-}
-
 XF86ConfMonitorPtr
 xf86findMonitor (const char *ident, XF86ConfMonitorPtr p)
 {
diff --git a/hw/xfree86/parser/configProcs.h b/hw/xfree86/parser/configProcs.h
index 0b98905..e3961a9 100644
--- a/hw/xfree86/parser/configProcs.h
+++ b/hw/xfree86/parser/configProcs.h
@@ -49,25 +49,19 @@ int xf86validateInput (XF86ConfigPtr p);
 XF86ConfLayoutPtr xf86parseLayoutSection(void);
 void xf86printLayoutSection(FILE *cf, XF86ConfLayoutPtr ptr);
 void xf86freeLayoutList(XF86ConfLayoutPtr ptr);
-void xf86freeAdjacencyList(XF86ConfAdjacencyPtr ptr);
-void xf86freeInputrefList(XF86ConfInputrefPtr ptr);
 int xf86validateLayout(XF86ConfigPtr p);
 /* Module.c */
-XF86LoadPtr xf86parseModuleSubSection(XF86LoadPtr head, char *name);
 XF86ConfModulePtr xf86parseModuleSection(void);
 void xf86printModuleSection(FILE *cf, XF86ConfModulePtr ptr);
 XF86LoadPtr xf86addNewLoadDirective(XF86LoadPtr head, char *name, int type, XF86OptionPtr opts);
 void xf86freeModules(XF86ConfModulePtr ptr);
 /* Monitor.c */
-XF86ConfModeLinePtr xf86parseModeLine(void);
-XF86ConfModeLinePtr xf86parseVerboseMode(void);
 XF86ConfMonitorPtr xf86parseMonitorSection(void);
 XF86ConfModesPtr xf86parseModesSection(void);
 void xf86printMonitorSection(FILE *cf, XF86ConfMonitorPtr ptr);
 void xf86printModesSection(FILE *cf, XF86ConfModesPtr ptr);
 void xf86freeMonitorList(XF86ConfMonitorPtr ptr);
 void xf86freeModesList(XF86ConfModesPtr ptr);
-void xf86freeModeLineList(XF86ConfModeLinePtr ptr);
 int xf86validateMonitor(XF86ConfigPtr p, XF86ConfScreenPtr screen);
 /* Pointer.c */
 XF86ConfInputPtr xf86parsePointerSection(void);
@@ -92,24 +86,18 @@ XF86ConfVideoAdaptorPtr xf86parseVideoAd
 void xf86printVideoAdaptorSection(FILE *cf, XF86ConfVideoAdaptorPtr ptr);
 void xf86freeVideoAdaptorList(XF86ConfVideoAdaptorPtr ptr);
 void xf86freeVideoPortList(XF86ConfVideoPortPtr ptr);
-/* read.c */
-int xf86validateConfig(XF86ConfigPtr p);
 /* scan.c */
-unsigned int xf86strToUL(char *str);
 int xf86getToken(xf86ConfigSymTabRec *tab);
 int xf86getSubToken(char **comment);
 int xf86getSubTokenWithTab(char **comment, xf86ConfigSymTabRec *tab);
 void xf86unGetToken(int token);
 char *xf86tokenString(void);
 void xf86parseError(char *format, ...);
-void xf86parseWarning(char *format, ...);
 void xf86validationError(char *format, ...);
 void xf86setSection(char *section);
 int xf86getStringToken(xf86ConfigSymTabRec *tab);
 /* write.c */
 /* DRI.c */
-XF86ConfBuffersPtr xf86parseBuffers (void);
-void xf86freeBuffersList (XF86ConfBuffersPtr ptr);
 XF86ConfDRIPtr xf86parseDRISection (void);
 void xf86printDRISection (FILE * cf, XF86ConfDRIPtr ptr);
 void xf86freeDRI (XF86ConfDRIPtr ptr);
diff --git a/hw/xfree86/parser/read.c b/hw/xfree86/parser/read.c
index b6b3bc3..9f79696 100644
--- a/hw/xfree86/parser/read.c
+++ b/hw/xfree86/parser/read.c
@@ -73,6 +73,25 @@ static xf86ConfigSymTabRec TopLevelTab[]
 
 #define CLEANUP xf86freeConfig
 
+/* 
+ * This function resolves name references and reports errors if the named
+ * objects cannot be found.
+ */
+static int
+xf86validateConfig (XF86ConfigPtr p)
+{
+	if (!xf86validateDevice (p))
+		return FALSE;
+	if (!xf86validateScreen (p))
+		return FALSE;
+	if (!xf86validateInput (p))
+		return FALSE;
+	if (!xf86validateLayout (p))
+		return FALSE;
+
+	return (TRUE);
+}
+
 XF86ConfigPtr
 xf86readConfigFile (void)
 {
@@ -219,25 +238,6 @@ xf86readConfigFile (void)
 #undef CLEANUP
 
 /* 
- * This function resolves name references and reports errors if the named
- * objects cannot be found.
- */
-int
-xf86validateConfig (XF86ConfigPtr p)
-{
-	if (!xf86validateDevice (p))
-		return FALSE;
-	if (!xf86validateScreen (p))
-		return FALSE;
-	if (!xf86validateInput (p))
-		return FALSE;
-	if (!xf86validateLayout (p))
-		return FALSE;
-
-	return (TRUE);
-}
-
-/* 
  * adds an item to the end of the linked list. Any record whose first field
  * is a GenericListRec can be cast to this type and used with this function.
  * A pointer to the head of the list is returned to handle the addition of
diff --git a/hw/xfree86/parser/scan.c b/hw/xfree86/parser/scan.c
index f81c45a..68e7ec6 100644
--- a/hw/xfree86/parser/scan.c
+++ b/hw/xfree86/parser/scan.c
@@ -116,7 +116,7 @@ extern char *__XOS2RedirRoot(char *path)
  *  A portable, but restricted, version of strtoul().  It only understands
  *  hex, octal, and decimal.  But it's good enough for our needs.
  */
-unsigned int
+static unsigned int
 xf86strToUL (char *str)
 {
 	int base = 10;
@@ -922,20 +922,6 @@ xf86parseError (char *format,...)
 }
 
 void
-xf86parseWarning (char *format,...)
-{
-	va_list ap;
-
-	ErrorF ("Parse warning on line %d of section %s in file %s\n\t",
-		 configLineNo, configSection, configPath);
-	va_start (ap, format);
-	VErrorF (format, ap);
-	va_end (ap);
-
-	ErrorF ("\n");
-}
-
-void
 xf86validationError (char *format,...)
 {
 	va_list ap;
diff --git a/hw/xfree86/xf4bpp/Makefile.am b/hw/xfree86/xf4bpp/Makefile.am
index 8fddb6b..5eab92f 100644
--- a/hw/xfree86/xf4bpp/Makefile.am
+++ b/hw/xfree86/xf4bpp/Makefile.am
@@ -20,7 +20,6 @@ libxf4bpp_la_SOURCES = \
         ppcPixmap.c \
         ppcPntWin.c \
         ppcPolyPnt.c \
-        ppcPolyRec.c \
         ppcQuery.c \
         ppcRslvC.c \
         ppcSetSp.c \
diff --git a/hw/xfree86/xf4bpp/offscreen.c b/hw/xfree86/xf4bpp/offscreen.c
index f35bde7..654be82 100644
--- a/hw/xfree86/xf4bpp/offscreen.c
+++ b/hw/xfree86/xf4bpp/offscreen.c
@@ -301,25 +301,6 @@ DoMono
 }
 
 void
-xf4bppOffDrawMonoImage( pWin, data, x, y, w, h, fg, alu, planes )
-WindowPtr pWin; /* GJA */
-unsigned char *data;
-int x, y, w, h ;
-unsigned long int fg ;
-int alu ;
-unsigned long int planes;
-{
-
-	if ( ( alu == GXnoop ) || !( planes &= VGA_ALLPLANES ) )
-		return ;
-
-	DoMono( pWin, w, x, y, (const unsigned char *) data, h,
-		      w, ( ( w + 31 ) & ~31 ) >> 3, h, 0, 0, alu,
-		      (int)planes, (int)fg) ;
-
-}
-
-void
 xf4bppOffFillStipple( pWin, pStipple, fg, alu, planes, x, y, w, h, xSrc, ySrc )
 WindowPtr pWin; /* GJA */
 register PixmapPtr const pStipple ;
diff --git a/hw/xfree86/xf4bpp/ppcGC.c b/hw/xfree86/xf4bpp/ppcGC.c
index 8153051..81441ef 100644
--- a/hw/xfree86/xf4bpp/ppcGC.c
+++ b/hw/xfree86/xf4bpp/ppcGC.c
@@ -90,10 +90,9 @@ SOFTWARE.
 | GCFunction | GCPlaneMask | GCFillStyle | GC_CALL_VALIDATE_BIT         \
 | GCClipXOrigin | GCClipYOrigin | GCClipMask | GCSubwindowMode )
 
+static void xf4bppValidateGC(GCPtr, unsigned long, DrawablePtr);
+static void xf4bppDestroyGC(GC *);
 
-/* GJA -- we modified the following function to get rid of
- * the records in file vgaData.c
- */
 static GCFuncs vgaGCFuncs = {
 	xf4bppValidateGC,
 	(void (*)(GCPtr, unsigned long))NoopDDA,
@@ -196,7 +195,7 @@ register GCPtr pGC ;
 	return TRUE ;
 }
 
-void
+static void
 xf4bppDestroyGC( pGC )
     register GC	*pGC ;
 
@@ -292,7 +291,7 @@ return 0 ;
 	    CT_other ==> pCompositeClip is the pixmap bounding box
 */
 
-void
+static void
 xf4bppValidateGC( pGC, changes, pDrawable )
     GCPtr         pGC;
     unsigned long changes;
diff --git a/hw/xfree86/xf4bpp/xf4bpp.h b/hw/xfree86/xf4bpp/xf4bpp.h
index 8d2da35..01512a8 100644
--- a/hw/xfree86/xf4bpp/xf4bpp.h
+++ b/hw/xfree86/xf4bpp/xf4bpp.h
@@ -149,14 +149,6 @@ void xf4bppTilePixmapFS(
 Bool xf4bppCreateGC(
     GCPtr
 );
-void xf4bppDestroyGC(
-    GC *
-);
-void xf4bppValidateGC(
-    GCPtr,
-    unsigned long,
-    DrawablePtr
-);
 
 /* ppcGetSp.c */
 void xf4bppGetSpans(
diff --git a/hw/xnest/Display.c b/hw/xnest/Display.c
index 57f3a68..1ec0609 100644
--- a/hw/xnest/Display.c
+++ b/hw/xnest/Display.c
@@ -39,7 +39,7 @@ XVisualInfo *xnestVisuals;
 int xnestNumVisuals;
 int xnestDefaultVisualIndex;
 Colormap *xnestDefaultColormaps;
-int xnestNumDefaultColormaps;
+static int xnestNumDefaultColormaps;
 int *xnestDepths;
 int xnestNumDepths;
 XPixmapFormatValues *xnestPixmapFormats;
diff --git a/hw/xnest/Screen.c b/hw/xnest/Screen.c
index e6870e7..e66b4f7 100644
--- a/hw/xnest/Screen.c
+++ b/hw/xnest/Screen.c
@@ -49,7 +49,7 @@ Window xnestScreenSaverWindows[MAXSCREEN
 extern void GlxWrapInitVisuals(miInitVisualsProcPtr *);
 #endif
 
-int xnestScreenGeneration = -1;
+static int xnestScreenGeneration = -1;
 
 ScreenPtr
 xnestScreen(Window window)
diff --git a/include/globals.h b/include/globals.h
index 821b12b..e23ce77 100644
--- a/include/globals.h
+++ b/include/globals.h
@@ -44,10 +44,6 @@ extern Bool DPMSCapableFlag;
 #endif
 
 #ifdef PANORAMIX
-extern Bool PanoramiXMapped;
-extern Bool PanoramiXVisibilityNotifySent;
-extern Bool PanoramiXWindowExposureSent;
-extern Bool PanoramiXOneExposeRequest;
 extern Bool PanoramiXExtensionDisabledHack;
 #endif
 
diff --git a/include/inputstr.h b/include/inputstr.h
index ada94e6..8f4e9b9 100644
--- a/include/inputstr.h
+++ b/include/inputstr.h
@@ -62,7 +62,7 @@ SOFTWARE.
 
 #define EMASKSIZE	MAX_DEVICES
 
-extern int CoreDevicePrivatesIndex, CoreDevicePrivatesGeneration;
+extern int CoreDevicePrivatesIndex;
 
 /* Kludge: OtherClients and InputClients must be compatible, see code */
 
diff --git a/mi/mioverlay.c b/mi/mioverlay.c
index 5724a6f..9701001 100644
--- a/mi/mioverlay.c
+++ b/mi/mioverlay.c
@@ -54,8 +54,8 @@ typedef struct {
 } miOverlayScreenRec, *miOverlayScreenPtr;
 
 static unsigned long miOverlayGeneration = 0;
-int miOverlayWindowIndex = -1;
-int miOverlayScreenIndex = -1;
+static int miOverlayWindowIndex = -1;
+static int miOverlayScreenIndex = -1;
 
 static void RebuildTree(WindowPtr);
 static Bool HasUnderlayChildren(WindowPtr);
diff --git a/mi/miscrinit.c b/mi/miscrinit.c
index 7922cb6..08cc3f6 100644
--- a/mi/miscrinit.c
+++ b/mi/miscrinit.c
@@ -312,7 +312,7 @@ miAllocateGCPrivateIndex()
 }
 
 _X_EXPORT int miZeroLineScreenIndex;
-unsigned int miZeroLineGeneration = 0;
+static unsigned int miZeroLineGeneration = 0;
 
 _X_EXPORT void
 miSetZeroLineBias(pScreen, bias)
diff --git a/miext/damage/damage.c b/miext/damage/damage.c
index cd66b54..6f1ee28 100755
--- a/miext/damage/damage.c
+++ b/miext/damage/damage.c
@@ -72,6 +72,12 @@
 
 #define pixmapDamage(pPixmap)		damagePixPriv(pPixmap)
 
+static int damageScrPrivateIndex;
+static int damagePixPrivateIndex;
+static int damageGCPrivateIndex;
+static int damageWinPrivateIndex;
+static int damageGeneration;
+
 static DamagePtr *
 getDrawableDamageRef (DrawablePtr pDrawable)
 {
@@ -368,12 +374,12 @@ static void damageChangeClip(GCPtr, int,
 static void damageDestroyClip(GCPtr);
 static void damageCopyClip(GCPtr, GCPtr);
 
-GCFuncs damageGCFuncs = {
+static GCFuncs damageGCFuncs = {
     damageValidateGC, damageChangeGC, damageCopyGC, damageDestroyGC,
     damageChangeClip, damageDestroyClip, damageCopyClip
 };
 
-extern GCOps damageGCOps;
+static GCOps damageGCOps;
 
 static Bool
 damageCreateGC(GCPtr pGC)
@@ -1686,7 +1692,7 @@ damageCopyWindow(WindowPtr	pWindow,
     wrap (pScrPriv, pScreen, CopyWindow, damageCopyWindow);
 }
 
-GCOps damageGCOps = {
+static GCOps damageGCOps = {
     damageFillSpans, damageSetSpans,
     damagePutImage, damageCopyArea,
     damageCopyPlane, damagePolyPoint,
@@ -1787,12 +1793,6 @@ damageCloseScreen (int i, ScreenPtr pScr
     return (*pScreen->CloseScreen) (i, pScreen);
 }
 
-int damageScrPrivateIndex;
-int damagePixPrivateIndex;
-int damageGCPrivateIndex;
-int damageWinPrivateIndex;
-int damageGeneration;
-
 Bool
 DamageSetup (ScreenPtr pScreen)
 {
diff --git a/miext/damage/damagestr.h b/miext/damage/damagestr.h
index 93e213f..83a202b 100755
--- a/miext/damage/damagestr.h
+++ b/miext/damage/damagestr.h
@@ -82,11 +82,7 @@ typedef struct _damageGCPriv {
     GCFuncs *funcs;
 } DamageGCPrivRec, *DamageGCPrivPtr;
 
-extern int damageScrPrivateIndex;
-extern int damagePixPrivateIndex;
-extern int damageGCPrivateIndex;
-extern int damageWinPrivateIndex;
-
+/* XXX should move these into damage.c, damageScrPrivateIndex is static */
 #define damageGetScrPriv(pScr) \
     ((DamageScrPrivPtr) (pScr)->devPrivates[damageScrPrivateIndex].ptr)
 
diff --git a/os/connection.c b/os/connection.c
index d0ffb81..cb3443c 100644
--- a/os/connection.c
+++ b/os/connection.c
@@ -175,7 +175,7 @@ typedef const char *string;
 # include <ucred.h>
 #endif
 
-int lastfdesc;			/* maximum file descriptor */
+static int lastfdesc;		/* maximum file descriptor */
 
 fd_set WellKnownConnections;	/* Listener mask */
 fd_set EnabledDevices;		/* mask for input devices that are on */
@@ -189,7 +189,7 @@ int MaxClients = 0;
 Bool NewOutputPending;		/* not yet attempted to write some new output */
 Bool AnyClientsWriteBlocked;	/* true if some client blocked on write */
 
-Bool RunFromSmartParent;	/* send SIGUSR1 to parent process */
+static Bool RunFromSmartParent;	/* send SIGUSR1 to parent process */
 Bool PartialNetwork;		/* continue even if unable to bind all addrs */
 static Pid_t ParentProcess;
 #ifdef __UNIXOS2__
@@ -298,9 +298,9 @@ void ClearConnectionTranslation(void)
 }
 #endif
 
-XtransConnInfo 	*ListenTransConns = NULL;
-int	       	*ListenTransFds = NULL;
-int		ListenTransCount;
+static XtransConnInfo 	*ListenTransConns = NULL;
+static int	       	*ListenTransFds = NULL;
+static int		ListenTransCount;
 
 static void ErrorConnMax(XtransConnInfo /* trans_conn */);
 
diff --git a/os/io.c b/os/io.c
index f6c666c..80a151f 100644
--- a/os/io.c
+++ b/os/io.c
@@ -111,11 +111,11 @@ _X_EXPORT CallbackListPtr       FlushCal
 #define ETEST(err) (err == EAGAIN || err == EWOULDBLOCK || err == ENOSPC)
 #endif
 
-Bool CriticalOutputPending;
-int timesThisConnection = 0;
-ConnectionInputPtr FreeInputs = (ConnectionInputPtr)NULL;
-ConnectionOutputPtr FreeOutputs = (ConnectionOutputPtr)NULL;
-OsCommPtr AvailableInput = (OsCommPtr)NULL;
+static Bool CriticalOutputPending;
+static int timesThisConnection = 0;
+static ConnectionInputPtr FreeInputs = (ConnectionInputPtr)NULL;
+static ConnectionOutputPtr FreeOutputs = (ConnectionOutputPtr)NULL;
+static OsCommPtr AvailableInput = (OsCommPtr)NULL;
 
 #define get_req_len(req,cli) ((cli)->swapped ? \
 			      lswaps((req)->length) : (req)->length)
diff --git a/os/osdep.h b/os/osdep.h
index 5fa1e39..3d303f9 100644
--- a/os/osdep.h
+++ b/os/osdep.h
@@ -234,12 +234,6 @@ extern void ClearConnectionTranslation()
  
 extern Bool NewOutputPending;
 extern Bool AnyClientsWriteBlocked;
-extern Bool CriticalOutputPending;
-
-extern int timesThisConnection;
-extern ConnectionInputPtr FreeInputs;
-extern ConnectionOutputPtr FreeOutputs;
-extern OsCommPtr AvailableInput;
 
 extern WorkQueuePtr workQueue;
 
diff --git a/os/utils.c b/os/utils.c
index 06c9b88..2fc5cbb 100644
--- a/os/utils.c
+++ b/os/utils.c
@@ -245,10 +245,6 @@ _X_EXPORT Bool noXvExtension = FALSE;
 Bool CoreDump;
 
 #ifdef PANORAMIX
-Bool PanoramiXVisibilityNotifySent = FALSE;
-Bool PanoramiXMapped = FALSE;
-Bool PanoramiXWindowExposureSent = FALSE;
-Bool PanoramiXOneExposeRequest = FALSE;
 Bool PanoramiXExtensionDisabledHack = FALSE;
 #endif
 
@@ -271,7 +267,7 @@ long Memory_fail = 0;
 #include <stdlib.h>  /* for random() */
 #endif
 
-char *dev_tty_from_init = NULL;		/* since we need to parse it anyway */
+static char *dev_tty_from_init = NULL;	/* since we need to parse it anyway */
 
 OsSigHandlerPtr
 OsSignal(sig, handler)
diff --git a/os/xdmcp.c b/os/xdmcp.c
index fd4be5e..cfc1005 100644
--- a/os/xdmcp.c
+++ b/os/xdmcp.c
@@ -411,11 +411,11 @@ XdmcpRegisterAuthentication (
  * set by the manager of the host to be connected to.
  */
 
-ARRAY8		noAuthenticationName = {(CARD16) 0, (CARD8Ptr) 0};
-ARRAY8		noAuthenticationData = {(CARD16) 0, (CARD8Ptr) 0};
-ARRAY8Ptr	AuthenticationName = &noAuthenticationName;
-ARRAY8Ptr	AuthenticationData = &noAuthenticationData;
-AuthenticationFuncsPtr	AuthenticationFuncs;
+static ARRAY8		noAuthenticationName = {(CARD16) 0, (CARD8Ptr) 0};
+static ARRAY8		noAuthenticationData = {(CARD16) 0, (CARD8Ptr) 0};
+static ARRAY8Ptr	AuthenticationName = &noAuthenticationName;
+static ARRAY8Ptr	AuthenticationData = &noAuthenticationData;
+static AuthenticationFuncsPtr	AuthenticationFuncs;
 
 void
 XdmcpSetAuthentication (ARRAY8Ptr name)
@@ -547,7 +547,7 @@ XdmcpRegisterAuthorization (char *name, 
  * Register the DisplayClass string
  */
 
-ARRAY8	DisplayClass;
+static ARRAY8	DisplayClass;
 
 void
 XdmcpRegisterDisplayClass (char *name, int length)
@@ -565,7 +565,7 @@ XdmcpRegisterDisplayClass (char *name, i
  * Register the Manufacturer display ID
  */
 
-ARRAY8 ManufacturerDisplayID;
+static ARRAY8 ManufacturerDisplayID;
 
 void
 XdmcpRegisterManufacturerDisplayID (char *name, int length)
@@ -776,7 +776,7 @@ XdmcpAddHost(
  * do the appropriate thing
  */
 
-ARRAY8	UnwillingMessage = { (CARD8) 14, (CARD8 *) "Host unwilling" };
+static ARRAY8	UnwillingMessage = { (CARD8) 14, (CARD8 *) "Host unwilling" };
 
 static void
 receive_packet(int socketfd)
diff --git a/render/animcur.c b/render/animcur.c
index 8e4f59d..1f25e79 100644
--- a/render/animcur.c
+++ b/render/animcur.c
@@ -87,8 +87,8 @@ static CursorBits   animCursorBits = {
     empty, empty, 2, 1, 1, 0, 0, 1
 };
 
-int	AnimCurScreenPrivateIndex = -1;
-int	AnimCurGeneration;
+static int AnimCurScreenPrivateIndex = -1;
+static int AnimCurGeneration;
 
 #define IsAnimCur(c)	    ((c)->bits == &animCursorBits)
 #define GetAnimCur(c)	    ((AnimCurPtr) ((c) + 1))
diff --git a/render/glyph.c b/render/glyph.c
index 6d09a0e..5987cbc 100644
--- a/render/glyph.c
+++ b/render/glyph.c
@@ -77,11 +77,11 @@ static GlyphHashSetRec glyphHashSets[] =
 
 #define NGLYPHHASHSETS	(sizeof(glyphHashSets)/sizeof(glyphHashSets[0]))
 
-const CARD8	glyphDepths[GlyphFormatNum] = { 1, 4, 8, 16, 32 };
+static const CARD8	glyphDepths[GlyphFormatNum] = { 1, 4, 8, 16, 32 };
 
-GlyphHashRec	globalGlyphs[GlyphFormatNum];
+static GlyphHashRec	globalGlyphs[GlyphFormatNum];
 
-int		globalTotalGlyphPrivateSize = 0;
+static int	globalTotalGlyphPrivateSize = 0;
 
 static int	glyphPrivateCount = 0;
 
diff --git a/render/glyphstr.h b/render/glyphstr.h
index 64cedfa..22150de 100644
--- a/render/glyphstr.h
+++ b/render/glyphstr.h
@@ -91,8 +91,6 @@ typedef struct _GlyphList {
     PictFormatPtr   format;
 } GlyphListRec, *GlyphListPtr;
 
-extern GlyphHashRec	globalGlyphs[GlyphFormatNum];
-
 GlyphHashSetPtr
 FindGlyphHashSet (CARD32 filled);
 
diff --git a/render/picture.c b/render/picture.c
index e7901e8..c30649c 100644
--- a/render/picture.c
+++ b/render/picture.c
@@ -43,7 +43,7 @@
 
 _X_EXPORT int	PictureScreenPrivateIndex = -1;
 int		PictureWindowPrivateIndex;
-int		PictureGeneration;
+static int	PictureGeneration;
 RESTYPE		PictureType;
 RESTYPE		PictFormatType;
 RESTYPE		GlyphSetType;
diff --git a/xfixes/xfixes.c b/xfixes/xfixes.c
index cee9e09..32dee8a 100755
--- a/xfixes/xfixes.c
+++ b/xfixes/xfixes.c
@@ -1,6 +1,4 @@
 /*
- * $Id$
- *
  * Copyright © 2006 Sun Microsystems
  *
  * Permission to use, copy, modify, distribute, and sell this software and its
@@ -55,10 +53,10 @@
 #define SERVER_XFIXES_MAJOR 4
 #define SERVER_XFIXES_MINOR 0
 
-unsigned char	XFixesReqCode;
+static unsigned char	XFixesReqCode;
 int		XFixesEventBase;
 int		XFixesErrorBase;
-int		XFixesClientPrivateIndex;
+static int	XFixesClientPrivateIndex;
 
 static int
 ProcXFixesQueryVersion(ClientPtr client)
@@ -169,7 +167,7 @@ SProcXFixesQueryVersion(ClientPtr client
     return (*ProcXFixesVector[stuff->xfixesReqType]) (client);
 }
 
-int	(*SProcXFixesVector[XFixesNumberRequests])(ClientPtr) = {
+static int (*SProcXFixesVector[XFixesNumberRequests])(ClientPtr) = {
 /*************** Version 1 ******************/
     SProcXFixesQueryVersion,
     SProcXFixesChangeSaveSet,
diff --git a/xfixes/xfixesint.h b/xfixes/xfixesint.h
index 5f08807..7f3b119 100755
--- a/xfixes/xfixesint.h
+++ b/xfixes/xfixesint.h
@@ -61,9 +61,7 @@
 #include "selection.h"
 #include "xfixes.h"
 
-extern unsigned char	XFixesReqCode;
 extern int		XFixesEventBase;
-extern int		XFixesClientPrivateIndex;
 
 typedef struct _XFixesClient {
     CARD32	major_version;
@@ -73,7 +71,6 @@ typedef struct _XFixesClient {
 #define GetXFixesClient(pClient)    ((XFixesClientPtr) (pClient)->devPrivates[XFixesClientPrivateIndex].ptr)
 
 extern int	(*ProcXFixesVector[XFixesNumberRequests])(ClientPtr);
-extern int	(*SProcXFixesVector[XFixesNumberRequests])(ClientPtr);
 
 /* Initialize extension at server startup time */
 
diff-tree ac2356843e38b3400142bc54b65393c12976fc07 (from 1072b88a8f352484e70bc749e300c936e5600480)
Author: Peter Hutterer <peter at cs.unisa.edu.au>
Date:   Sun Mar 25 09:41:33 2007 +0930

    dix: Increase allocation size for core keyboard keymap to avoid buffer overrun when copying keymap from extension devices.

diff --git a/dix/devices.c b/dix/devices.c
index f738419..5996b75 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -238,7 +238,7 @@ CoreKeyboardProc(DeviceIntPtr pDev, int 
         keySyms.mapWidth = 4;
         keySyms.map = (KeySym *)xcalloc(sizeof(KeySym),
                                         (keySyms.maxKeyCode -
-                                         keySyms.minKeyCode) *
+                                         keySyms.minKeyCode + 1) *
                                         keySyms.mapWidth);
         if (!keySyms.map) {
             ErrorF("Couldn't allocate core keymap\n");
diff-tree 1072b88a8f352484e70bc749e300c936e5600480 (from 804080a7096347d48c686f2c8fbfd06326bce400)
Author: Dave Airlie <airlied at linux.ie>
Date:   Sun Mar 25 10:06:00 2007 +1000

    loader: fix already built-in message

diff --git a/hw/xfree86/loader/loadmod.c b/hw/xfree86/loader/loadmod.c
index c220d8a..a83b889 100644
--- a/hw/xfree86/loader/loadmod.c
+++ b/hw/xfree86/loader/loadmod.c
@@ -869,7 +869,7 @@ doLoadModule(const char *module, const c
     for (cim = compiled_in_modules; *cim; cim++)
 	if (!strcmp (module, *cim))
 	{
-	    xf86MsgVerb(X_INFO, 3, "Module alread ybuilt-in");
+	    xf86MsgVerb(X_INFO, 3, "Module already built-in\n");
 	    return (ModuleDescPtr) 1;
 	}
 
diff-tree 804080a7096347d48c686f2c8fbfd06326bce400 (from 1f77120775dc05fc84a00dd55190af2fa50ae509)
Author: Keith Packard <keithp at neko.keithp.com>
Date:   Fri Mar 23 23:41:36 2007 -0700

    Make pending properties force mode set. And, remove AttachScreen calls.
    
    Yes, two changes in one commit. Sorry 'bout that.
    
    The first change ensures that when pending property values have been
    changed, a mode set to the current mode will actually do something, rather
    than being identified as a no-op. In addition, the driver no longer needs to
    manage the migration of pending to current values, that is handled both
    within the xf86 mode setting code (to deal with non-RandR changes) as well
    as within the RandR extension itself.
    
    The second change eliminates the two-call Create/AttachScreen stuff that was
    done in a failed attempt to create RandR resources before the screen
    structures were allocated. Merging these back into the Create function is
    cleaner.
    (cherry picked from commit 57e87e0d006cbf1f5b175fe02eeb981f741d92f0)
    
    Conflicts:
    
    	randr/randrstr.h
    	randr/rrcrtc.c
    
    I think master and server-1.3-branch are more in sync now.

diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c
index b9895d9..7d86b66 100644
--- a/hw/xfree86/modes/xf86Crtc.c
+++ b/hw/xfree86/modes/xf86Crtc.c
@@ -312,7 +312,13 @@ xf86CrtcSetMode (xf86CrtcPtr crtc, Displ
     {
 	xf86OutputPtr output = xf86_config->output[i];
 	if (output->crtc == crtc)
+	{
 	    output->funcs->commit(output);
+#ifdef RANDR_12_INTERFACE
+	    if (output->randr_output)
+		RRPostPendingProperties (output->randr_output);
+#endif
+	}
     }
 
     /* XXX free adjustedmode */
diff --git a/hw/xfree86/modes/xf86RandR12.c b/hw/xfree86/modes/xf86RandR12.c
index 4213fea..6f52ee2 100644
--- a/hw/xfree86/modes/xf86RandR12.c
+++ b/hw/xfree86/modes/xf86RandR12.c
@@ -1011,8 +1011,7 @@ xf86RandR12CreateObjects12 (ScreenPtr pS
     {
 	xf86CrtcPtr    crtc = config->crtc[c];
 	
-	crtc->randr_crtc = RRCrtcCreate (crtc);
-	RRCrtcAttachScreen (crtc->randr_crtc, pScreen);
+	crtc->randr_crtc = RRCrtcCreate (pScreen, crtc);
 	RRCrtcGammaSetSize (crtc->randr_crtc, 256);
     }
     /*
@@ -1022,13 +1021,13 @@ xf86RandR12CreateObjects12 (ScreenPtr pS
     {
 	xf86OutputPtr	output = config->output[o];
 
-	output->randr_output = RROutputCreate (output->name, 
+	output->randr_output = RROutputCreate (pScreen, output->name, 
 					       strlen (output->name),
 					       output);
-	RROutputAttachScreen (output->randr_output, pScreen);
 
 	if (output->funcs->create_resources != NULL)
 	    output->funcs->create_resources(output);
+	RRPostPendingProperties (output->randr_output);
     }
     return TRUE;
 }
diff --git a/randr/mirandr.c b/randr/mirandr.c
index 47136fb..3c4991e 100644
--- a/randr/mirandr.c
+++ b/randr/mirandr.c
@@ -133,20 +133,13 @@ miRandRInit (ScreenPtr pScreen)
     if (!mode)
 	return FALSE;
     
-    crtc = RRCrtcCreate (NULL);
+    crtc = RRCrtcCreate (pScreen, NULL);
     if (!crtc)
 	return FALSE;
-    if (!RRCrtcAttachScreen (crtc, pScreen))
-    {
-	RRCrtcDestroy (crtc);
-	return FALSE;
-    }
     
-    output = RROutputCreate ("screen", 6, NULL);
+    output = RROutputCreate (pScreen, "screen", 6, NULL);
     if (!output)
 	return FALSE;
-    if (!RROutputAttachScreen (output, pScreen))
-	return FALSE;
     if (!RROutputSetClones (output, NULL, 0))
 	return FALSE;
     if (!RROutputSetModes (output, &mode, 1, 0))
diff --git a/randr/randrstr.h b/randr/randrstr.h
index 9f039f7..4cc3a46 100644
--- a/randr/randrstr.h
+++ b/randr/randrstr.h
@@ -138,6 +138,7 @@ struct _rrOutput {
     RRModePtr	    *userModes;
     Bool	    changed;
     RRPropertyPtr   properties;
+    Bool	    pendingProperties;
     void	    *devPrivate;
 };
 
@@ -496,16 +497,14 @@ RRCrtcChanged (RRCrtcPtr crtc, Bool layo
  * Create a CRTC
  */
 RRCrtcPtr
-RRCrtcCreate (void	*devPrivate);
+RRCrtcCreate (ScreenPtr pScreen, void	*devPrivate);
 
 /*
- * Attach a CRTC to a screen. Once done, this cannot be
- * undone without destroying the CRTC; it is separate from Create
- * only to allow an xf86-based driver to create objects in preinit
+ * Set the allowed rotations on a CRTC
  */
-Bool
-RRCrtcAttachScreen (RRCrtcPtr crtc, ScreenPtr pScreen);
-    
+void
+RRCrtcSetRotations (RRCrtcPtr crtc, Rotation rotations);
+
 /*
  * Notify the extension that the Crtc has been reconfigured,
  * the driver calls this whenever it has updated the mode
@@ -562,13 +561,6 @@ RRCrtcGammaSetSize (RRCrtcPtr	crtc,
 		    int		size);
 
 /*
- * Set the allowable rotations of the CRTC.
- */
-Bool
-RRCrtcSetRotations (RRCrtcPtr crtc,
-		    Rotation rotations);
-
-/*
  * Return the area of the frame buffer scanned out by the crtc,
  * taking into account the current mode and rotation
  */
@@ -670,19 +662,12 @@ RROutputChanged (RROutputPtr output, Boo
  */
 
 RROutputPtr
-RROutputCreate (const char  *name,
+RROutputCreate (ScreenPtr   pScreen,
+		const char  *name,
 		int	    nameLength,
 		void	    *devPrivate);
 
 /*
- * Attach an output to a screen, again split from creation so
- * xf86 DDXen can create randr resources before the ScreenRec
- * exists
- */
-Bool
-RROutputAttachScreen (RROutputPtr output, ScreenPtr pScreen);
-
-/*
  * Notify extension that output parameters have been changed
  */
 Bool
@@ -762,7 +747,7 @@ void
 RRDeleteOutputProperty (RROutputPtr output, Atom property);
 
 Bool
-RRPostPendingProperty (RROutputPtr output, Atom property);
+RRPostPendingProperties (RROutputPtr output);
     
 int
 RRChangeOutputProperty (RROutputPtr output, Atom property, Atom type,
diff --git a/randr/rrcrtc.c b/randr/rrcrtc.c
index 7131dfb..1dfc3bb 100644
--- a/randr/rrcrtc.c
+++ b/randr/rrcrtc.c
@@ -51,17 +51,32 @@ RRCrtcChanged (RRCrtcPtr crtc, Bool layo
  * Create a CRTC
  */
 RRCrtcPtr
-RRCrtcCreate (void	*devPrivate)
+RRCrtcCreate (ScreenPtr pScreen, void *devPrivate)
 {
-    RRCrtcPtr	crtc;
-    
+    RRCrtcPtr	    crtc;
+    RRCrtcPtr	    *crtcs;
+    rrScrPrivPtr    pScrPriv;
+
     if (!RRInit())
 	return NULL;
+    
+    pScrPriv = rrGetScrPriv(pScreen);
+
+    /* make space for the crtc pointer */
+    if (pScrPriv->numCrtcs)
+	crtcs = xrealloc (pScrPriv->crtcs, 
+			  (pScrPriv->numCrtcs + 1) * sizeof (RRCrtcPtr));
+    else
+	crtcs = xalloc (sizeof (RRCrtcPtr));
+    if (!crtcs)
+	return FALSE;
+    pScrPriv->crtcs = crtcs;
+    
     crtc = xalloc (sizeof (RRCrtcRec));
     if (!crtc)
 	return NULL;
     crtc->id = FakeClientID (0);
-    crtc->pScreen = NULL;
+    crtc->pScreen = pScreen;
     crtc->mode = NULL;
     crtc->x = 0;
     crtc->y = 0;
@@ -77,37 +92,20 @@ RRCrtcCreate (void	*devPrivate)
     if (!AddResource (crtc->id, RRCrtcType, (pointer) crtc))
 	return NULL;
 
+    /* attach the screen and crtc together */
+    crtc->pScreen = pScreen;
+    pScrPriv->crtcs[pScrPriv->numCrtcs++] = crtc;
+    
     return crtc;
 }
 
 /*
- * Attach a Crtc to a screen. This is done as a separate step
- * so that an xf86-based driver can create CRTCs in PreInit
- * before the Screen has been created
+ * Set the allowed rotations on a CRTC
  */
-
-Bool
-RRCrtcAttachScreen (RRCrtcPtr crtc, ScreenPtr pScreen)
+void
+RRCrtcSetRotations (RRCrtcPtr crtc, Rotation rotations)
 {
-    rrScrPriv (pScreen);
-    RRCrtcPtr	*crtcs;
-
-    /* make space for the crtc pointer */
-    if (pScrPriv->numCrtcs)
-	crtcs = xrealloc (pScrPriv->crtcs, 
-			  (pScrPriv->numCrtcs + 1) * sizeof (RRCrtcPtr));
-    else
-	crtcs = xalloc (sizeof (RRCrtcPtr));
-    if (!crtcs)
-	return FALSE;
-    
-    /* attach the screen and crtc together */
-    crtc->pScreen = pScreen;
-    pScrPriv->crtcs = crtcs;
-    pScrPriv->crtcs[pScrPriv->numCrtcs++] = crtc;
-
-    RRCrtcChanged (crtc, TRUE);
-    return TRUE;
+    crtc->rotations = rotations;
 }
 
 /*
@@ -249,6 +247,22 @@ RRDeliverCrtcEvent (ClientPtr client, Wi
     WriteEventsToClient (client, 1, (xEvent *) &ce);
 }
 
+static Bool
+RRCrtcPendingProperties (RRCrtcPtr crtc)
+{
+    ScreenPtr	pScreen = crtc->pScreen;
+    rrScrPriv(pScreen);
+    int		o;
+
+    for (o = 0; o < pScrPriv->numOutputs; o++)
+    {
+	RROutputPtr output = pScrPriv->outputs[o];
+	if (output->crtc == crtc && output->pendingProperties)
+	    return TRUE;
+    }
+    return FALSE;
+}
+
 /*
  * Request that the Crtc be reconfigured
  */
@@ -271,7 +285,8 @@ RRCrtcSet (RRCrtcPtr    crtc,
 	crtc->y == y &&
 	crtc->rotation == rotation &&
 	crtc->numOutputs == numOutputs &&
-	!memcmp (crtc->outputs, outputs, numOutputs * sizeof (RROutputPtr)))
+	!memcmp (crtc->outputs, outputs, numOutputs * sizeof (RROutputPtr)) &&
+	!RRCrtcPendingProperties (crtc))
     {
 	ret = TRUE;
     }
@@ -328,7 +343,13 @@ RRCrtcSet (RRCrtcPtr    crtc,
 #endif
 	}
 	if (ret)
+	{
+	    int	o;
 	    RRTellChanged (pScreen);
+
+	    for (o = 0; o < numOutputs; o++)
+		RRPostPendingProperties (outputs[o]);
+	}
     }
     return ret;
 }
@@ -469,17 +490,6 @@ RRCrtcGammaSetSize (RRCrtcPtr	crtc,
 }
 
 /*
- * Set the allowable rotations of the CRTC.
- */
-Bool
-RRCrtcSetRotations (RRCrtcPtr crtc,
-		    Rotation rotations)
-{
-    crtc->rotations = rotations;
-    return TRUE;
-}
-
-/*
  * Initialize crtc type
  */
 Bool
diff --git a/randr/rrinfo.c b/randr/rrinfo.c
index 549d501..5ef1a6b 100644
--- a/randr/rrinfo.c
+++ b/randr/rrinfo.c
@@ -91,19 +91,12 @@ RRScanOldConfig (ScreenPtr pScreen, Rota
     if (pScrPriv->numOutputs == 0 &&
 	pScrPriv->numCrtcs == 0)
     {
-	crtc = RRCrtcCreate (NULL);
+	crtc = RRCrtcCreate (pScreen, NULL);
 	if (!crtc)
 	    return;
-	if (!RRCrtcAttachScreen (crtc, pScreen))
-	{
-	    RRCrtcDestroy (crtc);
-	    return;
-	}
-	output = RROutputCreate ("default", 7, NULL);
+	output = RROutputCreate (pScreen, "default", 7, NULL);
 	if (!output)
 	    return;
-	if (!RROutputAttachScreen (output, pScreen))
-	    return;
 	RROutputSetCrtcs (output, &crtc, 1);
 	RROutputSetCrtc (output, crtc);
 	RROutputSetConnection (output, RR_Connected);
diff --git a/randr/rroutput.c b/randr/rroutput.c
index 160071b..e001162 100644
--- a/randr/rroutput.c
+++ b/randr/rroutput.c
@@ -47,19 +47,35 @@ RROutputChanged (RROutputPtr output, Boo
  */
 
 RROutputPtr
-RROutputCreate (const char  *name,
+RROutputCreate (ScreenPtr   pScreen,
+		const char  *name,
 		int	    nameLength,
 		void	    *devPrivate)
 {
-    RROutputPtr	output;
+    RROutputPtr	    output;
+    RROutputPtr	    *outputs;
+    rrScrPrivPtr    pScrPriv;
 
     if (!RRInit())
 	return NULL;
+    
+    pScrPriv = rrGetScrPriv(pScreen);
+
+    if (pScrPriv->numOutputs)
+	outputs = xrealloc (pScrPriv->outputs, 
+			    (pScrPriv->numOutputs + 1) * sizeof (RROutputPtr));
+    else
+	outputs = xalloc (sizeof (RROutputPtr));
+    if (!outputs)
+	return FALSE;
+
+    pScrPriv->outputs = outputs;
+    
     output = xalloc (sizeof (RROutputRec) + nameLength + 1);
     if (!output)
 	return NULL;
     output->id = FakeClientID (0);
-    output->pScreen = NULL;
+    output->pScreen = pScreen;
     output->name = (char *) (output + 1);
     output->nameLength = nameLength;
     memcpy (output->name, name, nameLength);
@@ -85,36 +101,11 @@ RROutputCreate (const char  *name,
     if (!AddResource (output->id, RROutputType, (pointer) output))
 	return NULL;
 
+    pScrPriv->outputs[pScrPriv->numOutputs++] = output;
     return output;
 }
 
 /*
- * Attach an Output to a screen. This is done as a separate step
- * so that an xf86-based driver can create Outputs in PreInit
- * before the Screen has been created
- */
-
-Bool
-RROutputAttachScreen (RROutputPtr output, ScreenPtr pScreen)
-{
-    rrScrPriv (pScreen);
-    RROutputPtr	*outputs;
-    
-    if (pScrPriv->numOutputs)
-	outputs = xrealloc (pScrPriv->outputs, 
-			    (pScrPriv->numOutputs + 1) * sizeof (RROutputPtr));
-    else
-	outputs = xalloc (sizeof (RROutputPtr));
-    if (!outputs)
-	return FALSE;
-    output->pScreen = pScreen;
-    pScrPriv->outputs = outputs;
-    pScrPriv->outputs[pScrPriv->numOutputs++] = output;
-    RROutputChanged (output, FALSE);
-    return TRUE;
-}
-		      
-/*
  * Notify extension that output parameters have been changed
  */
 Bool
diff --git a/randr/rrproperty.c b/randr/rrproperty.c
index 148e4a2..5ac073f 100644
--- a/randr/rrproperty.c
+++ b/randr/rrproperty.c
@@ -27,7 +27,7 @@
 static void
 RRDeliverEvent (ScreenPtr pScreen, xEvent *event, CARD32 mask)
 {
-    
+
 }
 
 void
@@ -50,7 +50,7 @@ RRDeleteAllOutputProperties (RROutputPtr
 	    xfree(prop->current.data);
 	if (prop->pending.data)
 	    xfree(prop->pending.data);
-        xfree(prop);
+	xfree(prop);
     }
 }
 
@@ -67,7 +67,7 @@ static RRPropertyPtr
 RRCreateOutputProperty (Atom property)
 {
     RRPropertyPtr   prop;
-    
+
     prop = (RRPropertyPtr)xalloc(sizeof(RRPropertyRec));
     if (!prop)
 	return NULL;
@@ -139,7 +139,7 @@ RRChangeOutputProperty (RROutputPtr outp
     prop = RRQueryOutputProperty (output, property);
     if (!prop)   /* just add to list */
     {
-        prop = RRCreateOutputProperty (property);
+	prop = RRCreateOutputProperty (property);
 	if (!prop)
 	    return(BadAlloc);
 	add = TRUE;
@@ -149,11 +149,11 @@ RRChangeOutputProperty (RROutputPtr outp
 	prop_value = &prop->pending;
     else
 	prop_value = &prop->current;
-    
+
     /* To append or prepend to a property the request format and type
-	    must match those of the already defined property.  The
-	    existing format and type are irrelevant when using the mode
-	    "PropModeReplace" since they will be written over. */
+     must match those of the already defined property.  The
+     existing format and type are irrelevant when using the mode
+     "PropModeReplace" since they will be written over. */
 
     if ((format != prop_value->format) && (mode != PropModeReplace))
 	return(BadMatch);
@@ -167,8 +167,8 @@ RRChangeOutputProperty (RROutputPtr outp
 
     if (mode == PropModeReplace || len > 0)
     {
-	pointer	    new_data, old_data;
-	
+	pointer	    new_data = NULL, old_data = NULL;
+
 	total_size = total_len * size_in_bytes;
 	new_value.data = (pointer)xalloc (total_size);
 	if (!new_value.data && total_size)
@@ -197,11 +197,12 @@ RRChangeOutputProperty (RROutputPtr outp
 				  (prop_value->size * size_in_bytes));
 	    break;
 	}
-	memcpy ((char *) new_data, (char *) value, len * size_in_bytes);
+	if (new_data)
+	    memcpy ((char *) new_data, (char *) value, len * size_in_bytes);
 	if (old_data)
 	    memcpy ((char *) old_data, (char *) prop_value->data, 
 		    prop_value->size * size_in_bytes);
-	
+
 	if (pending && pScrPriv->rrOutputSetProperty &&
 	    !pScrPriv->rrOutputSetProperty(output->pScreen, output,
 					   prop->propertyName, &new_value))
@@ -214,18 +215,21 @@ RRChangeOutputProperty (RROutputPtr outp
 	    xfree (prop_value->data);
 	*prop_value = new_value;
     }
-    
+
     else if (len == 0)
     {
 	/* do nothing */
     }
-    
+
     if (add)
     {
 	prop->next = output->properties;
 	output->properties = prop;
     }
 
+    if (pending && prop->is_pending)
+	output->pendingProperties = TRUE;
+
     if (sendevent)
     {
 	event.type = RREventBase + RRNotify;
@@ -240,30 +244,45 @@ RRChangeOutputProperty (RROutputPtr outp
 }
 
 Bool
-RRPostPendingProperty (RROutputPtr output, Atom property)
+RRPostPendingProperties (RROutputPtr output)
 {
-    RRPropertyPtr		    prop = RRQueryOutputProperty (output, property);
-    RRPropertyValuePtr		    pending_value;
-    RRPropertyValuePtr		    current_value;
-    
-    if (!prop)
-	return FALSE;
-    if (!prop->is_pending)
-	return FALSE;
-    pending_value = &prop->pending;
-    current_value = &prop->current;
-
-    if (pending_value->type == current_value->type &&
-	pending_value->format == current_value->format &&
-	pending_value->size == current_value->size &&
-	!memcmp (pending_value->data, current_value->data, pending_value->size))
+    RRPropertyValuePtr	pending_value;
+    RRPropertyValuePtr	current_value;
+    RRPropertyPtr	property;
+    Bool		ret = TRUE;
+
+    if (!output->pendingProperties)
 	return TRUE;
     
-    if (RRChangeOutputProperty (output, property, 
-				pending_value->type, pending_value->format, PropModeReplace,
-				pending_value->size, pending_value->data, TRUE, FALSE) != Success)
-	return FALSE;
-    return TRUE;
+    output->pendingProperties = FALSE;
+    for (property = output->properties; property; property = property->next)
+    {
+	/* Skip non-pending properties */
+	if (!property->is_pending)
+	    continue;
+	
+	pending_value = &property->pending;
+	current_value = &property->current;
+
+	/*
+	 * If the pending and current values are equal, don't mark it
+	 * as changed (which would deliver an event)
+	 */
+	if (pending_value->type == current_value->type &&
+	    pending_value->format == current_value->format &&
+	    pending_value->size == current_value->size &&
+	    !memcmp (pending_value->data, current_value->data,
+		     pending_value->size))
+	    continue;
+
+	if (RRChangeOutputProperty (output, property->propertyName,
+				    pending_value->type, pending_value->format,
+				    PropModeReplace, pending_value->size,
+				    pending_value->data, TRUE,
+				    FALSE) != Success)
+	    ret = FALSE;
+    }
+    return ret;
 }
 
 RRPropertyPtr
diff-tree 1f77120775dc05fc84a00dd55190af2fa50ae509 (from 476f2b5aefa518262b69e487555e6094818d857a)
Author: Keith Packard <keithp at neko.keithp.com>
Date:   Fri Mar 23 14:39:10 2007 -0700

    Ensure that crtc desired values track most recent mode.
    
    desiredX and desiredY were not recorded during xf86InitialConfiguration.
    desiredX, desiredY and desiredRotation were not recorded during
    xf86SetSingleMode.
    (cherry picked from commit 36e5227215e0912ddf8a010db042467f00efe0fc)

diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c
index 2341715..b9895d9 100644
--- a/hw/xfree86/modes/xf86Crtc.c
+++ b/hw/xfree86/modes/xf86Crtc.c
@@ -1589,6 +1589,8 @@ xf86InitialConfiguration (ScrnInfoPtr sc
 	{
 	    crtc->desiredMode = *mode;
 	    crtc->desiredRotation = output->initial_rotation;
+	    crtc->desiredX = output->initial_x;
+	    crtc->desiredY = output->initial_y;
 	    crtc->enabled = TRUE;
 	    crtc->x = output->initial_x;
 	    crtc->y = output->initial_y;
@@ -1813,7 +1815,12 @@ xf86SetSingleMode (ScrnInfoPtr pScrn, Di
 	if (!xf86CrtcSetMode (crtc, crtc_mode, rotation, 0, 0))
 	    ok = FALSE;
 	else
+	{
 	    crtc->desiredMode = *crtc_mode;
+	    crtc->desiredRotation = rotation;
+	    crtc->desiredX = 0;
+	    crtc->desiredY = 0;
+	}
     }
     xf86DisableUnusedFunctions(pScrn);
     return ok;
diff-tree 476f2b5aefa518262b69e487555e6094818d857a (from 7093367c3976bef5b9d219d9f2a7dc7dd3eeb091)
Author: Keith Packard <keithp at guitar.keithp.com>
Date:   Fri Mar 23 01:17:14 2007 -0700

    Incorrect extra memory copy in RRChangeOutputProperty.
    
    Left over from previous version of the code, this memmove will break when
    the mode is not Replace.
    (cherry picked from commit 945aa0aa556429b50dea8e8ebc0008304b093eb7)

diff --git a/randr/rrproperty.c b/randr/rrproperty.c
index b0182da..148e4a2 100644
--- a/randr/rrproperty.c
+++ b/randr/rrproperty.c
@@ -177,8 +177,6 @@ RRChangeOutputProperty (RROutputPtr outp
 		RRDestroyOutputProperty (prop);
 	    return BadAlloc;
 	}
-	if (len)
-	    memmove((char *)new_value.data, (char *)value, total_size);
 	new_value.size = len;
 	new_value.type = type;
 	new_value.format = format;
diff-tree 7093367c3976bef5b9d219d9f2a7dc7dd3eeb091 (from 86d76390eb182f271f5fa5dc19205e97a867f7e7)
Author: Keith Packard <keithp at guitar.keithp.com>
Date:   Fri Mar 23 01:05:55 2007 -0700

    Fix Pending property API, adding RRPostPendingProperty.
    
    Pending Properties take effect when the driver says they do, so provide an
    API to tell DIX when a property effect is made. Also, allow driver
    to reject property values in RRChangeOutputProperty.
    (cherry picked from commit 8eb288fbd69e2ffd02521d2c6a964c8180d08ec8)

diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c
index fad0752..2341715 100644
--- a/hw/xfree86/modes/xf86Crtc.c
+++ b/hw/xfree86/modes/xf86Crtc.c
@@ -1923,7 +1923,7 @@ xf86OutputSetEDIDProperty (xf86OutputPtr
 
     if (data_len != 0) {
 	RRChangeOutputProperty(output->randr_output, edid_atom, XA_INTEGER, 8,
-			       PropModeReplace, data_len, data, FALSE);
+			       PropModeReplace, data_len, data, FALSE, TRUE);
     } else {
 	RRDeleteOutputProperty(output->randr_output, edid_atom);
     }
diff --git a/randr/randrstr.h b/randr/randrstr.h
index 0dee999..9f039f7 100644
--- a/randr/randrstr.h
+++ b/randr/randrstr.h
@@ -761,10 +761,13 @@ RRQueryOutputProperty (RROutputPtr outpu
 void
 RRDeleteOutputProperty (RROutputPtr output, Atom property);
 
+Bool
+RRPostPendingProperty (RROutputPtr output, Atom property);
+    
 int
 RRChangeOutputProperty (RROutputPtr output, Atom property, Atom type,
 			int format, int mode, unsigned long len,
-			pointer value, Bool sendevent);
+			pointer value, Bool sendevent, Bool pending);
 
 int
 RRConfigureOutputProperty (RROutputPtr output, Atom property,
diff --git a/randr/rrproperty.c b/randr/rrproperty.c
index edfed1f..b0182da 100644
--- a/randr/rrproperty.c
+++ b/randr/rrproperty.c
@@ -121,19 +121,19 @@ RRDeleteOutputProperty (RROutputPtr outp
 int
 RRChangeOutputProperty (RROutputPtr output, Atom property, Atom type,
 			int format, int mode, unsigned long len,
-			pointer value, Bool sendevent)
+			pointer value, Bool sendevent, Bool pending)
 {
     RRPropertyPtr		    prop;
     xRROutputPropertyNotifyEvent    event;
     rrScrPrivPtr		    pScrPriv = rrGetScrPriv(output->pScreen);
-    int				    sizeInBytes;
-    int				    totalSize;
-    pointer			    data;
+    int				    size_in_bytes;
+    int				    total_size;
+    unsigned long		    total_len;
     RRPropertyValuePtr		    prop_value;
+    RRPropertyValueRec		    new_value;
     Bool			    add = FALSE;
 
-    sizeInBytes = format >> 3;
-    totalSize = len * sizeInBytes;
+    size_in_bytes = format >> 3;
 
     /* first see if property already exists */
     prop = RRQueryOutputProperty (output, property);
@@ -145,7 +145,7 @@ RRChangeOutputProperty (RROutputPtr outp
 	add = TRUE;
 	mode = PropModeReplace;
     }
-    if (prop->is_pending)
+    if (pending && prop->is_pending)
 	prop_value = &prop->pending;
     else
 	prop_value = &prop->current;
@@ -159,68 +159,75 @@ RRChangeOutputProperty (RROutputPtr outp
 	return(BadMatch);
     if ((prop_value->type != type) && (mode != PropModeReplace))
 	return(BadMatch);
+    new_value = *prop_value;
     if (mode == PropModeReplace)
+	total_len = len;
+    else
+	total_len = prop_value->size + len;
+
+    if (mode == PropModeReplace || len > 0)
     {
-	if (totalSize != prop_value->size * (prop_value->format >> 3))
+	pointer	    new_data, old_data;
+	
+	total_size = total_len * size_in_bytes;
+	new_value.data = (pointer)xalloc (total_size);
+	if (!new_value.data && total_size)
 	{
-	    if (prop_value->data)
-		data = (pointer)xrealloc(prop_value->data, totalSize);
-	    else
-		data = (pointer)xalloc (totalSize);
-	    if (!data && len)
-	    {
-		if (add)
-		    RRDestroyOutputProperty (prop);
-		return(BadAlloc);
-	    }
-	    prop_value->data = data;
+	    if (add)
+		RRDestroyOutputProperty (prop);
+	    return BadAlloc;
 	}
 	if (len)
-	    memmove((char *)prop_value->data, (char *)value, totalSize);
-	prop_value->size = len;
-	prop_value->type = type;
-	prop_value->format = format;
+	    memmove((char *)new_value.data, (char *)value, total_size);
+	new_value.size = len;
+	new_value.type = type;
+	new_value.format = format;
+
+	switch (mode) {
+	case PropModeReplace:
+	    new_data = new_value.data;
+	    old_data = NULL;
+	    break;
+	case PropModeAppend:
+	    new_data = (pointer) (((char *) new_value.data) + 
+				  (prop_value->size * size_in_bytes));
+	    old_data = new_value.data;
+	    break;
+	case PropModePrepend:
+	    new_data = new_value.data;
+	    old_data = (pointer) (((char *) new_value.data) + 
+				  (prop_value->size * size_in_bytes));
+	    break;
+	}
+	memcpy ((char *) new_data, (char *) value, len * size_in_bytes);
+	if (old_data)
+	    memcpy ((char *) old_data, (char *) prop_value->data, 
+		    prop_value->size * size_in_bytes);
+	
+	if (pending && pScrPriv->rrOutputSetProperty &&
+	    !pScrPriv->rrOutputSetProperty(output->pScreen, output,
+					   prop->propertyName, &new_value))
+	{
+	    if (new_value.data)
+		xfree (new_value.data);
+	    return (BadValue);
+	}
+	if (prop_value->data)
+	    xfree (prop_value->data);
+	*prop_value = new_value;
     }
+    
     else if (len == 0)
     {
 	/* do nothing */
     }
-    else if (mode == PropModeAppend)
-    {
-	data = (pointer)xrealloc(prop_value->data,
-				 sizeInBytes * (len + prop_value->size));
-	if (!data)
-	    return(BadAlloc);
-	prop_value->data = data;
-	memmove(&((char *)data)[prop_value->size * sizeInBytes], 
-		(char *)value,
-	      totalSize);
-	prop_value->size += len;
-    }
-    else if (mode == PropModePrepend)
-    {
-	data = (pointer)xalloc(sizeInBytes * (len + prop_value->size));
-	if (!data)
-	    return(BadAlloc);
-	memmove(&((char *)data)[totalSize], (char *)prop_value->data, 
-	      (int)(prop_value->size * sizeInBytes));
-	memmove((char *)data, (char *)value, totalSize);
-	xfree(prop_value->data);
-	prop_value->data = data;
-	prop_value->size += len;
-    }
+    
     if (add)
     {
 	prop->next = output->properties;
 	output->properties = prop;
     }
 
-    if (!prop->is_pending) {
-	/* What should we do in case of failure? */
-	pScrPriv->rrOutputSetProperty(output->pScreen, output,
-				      prop->propertyName, prop_value);
-    }
-
     if (sendevent)
     {
 	event.type = RREventBase + RRNotify;
@@ -234,6 +241,33 @@ RRChangeOutputProperty (RROutputPtr outp
     return(Success);
 }
 
+Bool
+RRPostPendingProperty (RROutputPtr output, Atom property)
+{
+    RRPropertyPtr		    prop = RRQueryOutputProperty (output, property);
+    RRPropertyValuePtr		    pending_value;
+    RRPropertyValuePtr		    current_value;
+    
+    if (!prop)
+	return FALSE;
+    if (!prop->is_pending)
+	return FALSE;
+    pending_value = &prop->pending;
+    current_value = &prop->current;
+
+    if (pending_value->type == current_value->type &&
+	pending_value->format == current_value->format &&
+	pending_value->size == current_value->size &&
+	!memcmp (pending_value->data, current_value->data, pending_value->size))
+	return TRUE;
+    
+    if (RRChangeOutputProperty (output, property, 
+				pending_value->type, pending_value->format, PropModeReplace,
+				pending_value->size, pending_value->data, TRUE, FALSE) != Success)
+	return FALSE;
+    return TRUE;
+}
+
 RRPropertyPtr
 RRQueryOutputProperty (RROutputPtr output, Atom property)
 {
@@ -474,7 +508,7 @@ ProcRRChangeOutputProperty (ClientPtr cl
 
     err = RRChangeOutputProperty(output, stuff->property,
 				 stuff->type, (int)format,
-				 (int)mode, len, (pointer)&stuff[1], TRUE);
+				 (int)mode, len, (pointer)&stuff[1], TRUE, TRUE);
     if (err != Success)
 	return err;
     else
@@ -508,8 +542,8 @@ int
 ProcRRGetOutputProperty (ClientPtr client)
 {
     REQUEST(xRRGetOutputPropertyReq);
-    RRPropertyPtr			prop, *prev;
-    RRPropertyValuePtr			prop_value;
+    RRPropertyPtr		prop, *prev;
+    RRPropertyValuePtr		prop_value;
     unsigned long		n, len, ind;
     RROutputPtr			output;
     xRRGetOutputPropertyReply	reply;
@@ -600,7 +634,10 @@ ProcRRGetOutputProperty (ClientPtr clien
     reply.bytesAfter = n - (ind + len);
     reply.format = prop_value->format;
     reply.length = (len + 3) >> 2;
-    reply.nItems = len / (prop_value->format / 8 );
+    if (prop_value->format)
+	reply.nItems = len / (prop_value->format / 8);
+    else
+	reply.nItems = 0;
     reply.propertyType = prop_value->type;
 
     if (stuff->delete && (reply.bytesAfter == 0))
diff-tree 86d76390eb182f271f5fa5dc19205e97a867f7e7 (from 510eaa346e68fd82c852c7b41fb0e2c5be12da78)
Author: Keith Packard <keithp at guitar.keithp.com>
Date:   Fri Mar 23 01:03:40 2007 -0700

    Make sure RandR events are delivered from RRCrtcSet.
    
    Some paths were skipping the event delivery stage.
    (cherry picked from commit 9ca7ba5d6012295a77ed773c656e786440da973d)

diff --git a/randr/rrcrtc.c b/randr/rrcrtc.c
index ecf5bb2..7131dfb 100644
--- a/randr/rrcrtc.c
+++ b/randr/rrcrtc.c
@@ -262,6 +262,8 @@ RRCrtcSet (RRCrtcPtr    crtc,
 	   RROutputPtr  *outputs)
 {
     ScreenPtr	pScreen = crtc->pScreen;
+    Bool	ret = FALSE;
+    rrScrPriv(pScreen);
 
     /* See if nothing changed */
     if (crtc->mode == mode &&
@@ -271,61 +273,64 @@ RRCrtcSet (RRCrtcPtr    crtc,
 	crtc->numOutputs == numOutputs &&
 	!memcmp (crtc->outputs, outputs, numOutputs * sizeof (RROutputPtr)))
     {
-	return TRUE;
+	ret = TRUE;
     }
-    if (pScreen)
+    else
     {
 #if RANDR_12_INTERFACE
-	rrScrPriv(pScreen);
 	if (pScrPriv->rrCrtcSet)
 	{
-	    return (*pScrPriv->rrCrtcSet) (pScreen, crtc, mode, x, y, 
-					   rotation, numOutputs, outputs);
+	    ret = (*pScrPriv->rrCrtcSet) (pScreen, crtc, mode, x, y, 
+					  rotation, numOutputs, outputs);
 	}
+	else
 #endif
-#if RANDR_10_INTERFACE
-	if (pScrPriv->rrSetConfig)
 	{
-	    RRScreenSize	    size;
-	    RRScreenRate	    rate;
-	    Bool		    ret;
-
-	    if (!mode)
+#if RANDR_10_INTERFACE
+	    if (pScrPriv->rrSetConfig)
 	    {
-		RRCrtcNotify (crtc, NULL, x, y, rotation, 0, NULL);
-		return TRUE;
-	    }
+		RRScreenSize	    size;
+		RRScreenRate	    rate;
 
-	    size.width = mode->mode.width;
-	    size.height = mode->mode.height;
-	    if (outputs[0]->mmWidth && outputs[0]->mmHeight)
-	    {
-		size.mmWidth = outputs[0]->mmWidth;
-		size.mmHeight = outputs[0]->mmHeight;
+		if (!mode)
+		{
+		    RRCrtcNotify (crtc, NULL, x, y, rotation, 0, NULL);
+		    ret = TRUE;
+		}
+		else
+		{
+		    size.width = mode->mode.width;
+		    size.height = mode->mode.height;
+		    if (outputs[0]->mmWidth && outputs[0]->mmHeight)
+		    {
+			size.mmWidth = outputs[0]->mmWidth;
+			size.mmHeight = outputs[0]->mmHeight;
+		    }
+		    else
+		    {
+			size.mmWidth = pScreen->mmWidth;
+			size.mmHeight = pScreen->mmHeight;
+		    }
+		    size.nRates = 1;
+		    rate.rate = RRVerticalRefresh (&mode->mode);
+		    size.pRates = &rate;
+		    ret = (*pScrPriv->rrSetConfig) (pScreen, rotation, rate.rate, &size);
+		    /*
+		     * Old 1.0 interface tied screen size to mode size
+		     */
+		    if (ret)
+		    {
+			RRCrtcNotify (crtc, mode, x, y, rotation, 1, outputs);
+			RRScreenSizeNotify (pScreen);
+		    }
+		}
 	    }
-	    else
-	    {
-		size.mmWidth = pScreen->mmWidth;
-		size.mmHeight = pScreen->mmHeight;
-	    }
-	    size.nRates = 1;
-	    rate.rate = RRVerticalRefresh (&mode->mode);
-	    size.pRates = &rate;
-	    ret = (*pScrPriv->rrSetConfig) (pScreen, rotation, rate.rate, &size);
-	    /*
-	     * Old 1.0 interface tied screen size to mode size
-	     */
-	    if (ret)
-	    {
-		RRCrtcNotify (crtc, mode, x, y, rotation, 1, outputs);
-		RRScreenSizeNotify (pScreen);
-	    }
-	    return ret;
-	}
 #endif
-	RRTellChanged (pScreen);
+	}
+	if (ret)
+	    RRTellChanged (pScreen);
     }
-    return FALSE;
+    return ret;
 }
 
 /*
@@ -718,6 +723,7 @@ ProcRRSetCrtcConfig (ClientPtr client)
 	goto sendReply;
     }
     
+#if 0
     /*
      * if the client's config timestamp is not the same as the last config
      * timestamp, then the config information isn't up-to-date and
@@ -728,6 +734,7 @@ ProcRRSetCrtcConfig (ClientPtr client)
 	rep.status = RRSetConfigInvalidConfigTime;
 	goto sendReply;
     }
+#endif
     
     /*
      * Validate requested rotation
diff-tree 510eaa346e68fd82c852c7b41fb0e2c5be12da78 (from 479b2be4badab0a67b1f091feb83c1364e27d783)
Author: Keith Packard <keithp at guitar.keithp.com>
Date:   Fri Mar 23 00:59:11 2007 -0700

    Clean up xf86CrtcRec and xf86OutputRec objects at CloseScreen.
    
    Erase pointers to structures which are freed at server reset time.
    (cherry picked from commit 492c768065f49306a2194a88edf96b85de0ff4ff)

diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c
index a875cdf..fad0752 100644
--- a/hw/xfree86/modes/xf86Crtc.c
+++ b/hw/xfree86/modes/xf86Crtc.c
@@ -573,11 +573,25 @@ xf86CrtcCloseScreen (int index, ScreenPt
 {
     ScrnInfoPtr		scrn = xf86Screens[screen->myNum];
     xf86CrtcConfigPtr	config = XF86_CRTC_CONFIG_PTR(scrn);
+    int			o, c;
     
     screen->CloseScreen = config->CloseScreen;
 
     xf86RotateCloseScreen (screen);
 
+    for (o = 0; o < config->num_output; o++)
+    {
+	xf86OutputPtr	output = config->output[o];
+
+	output->crtc = NULL;
+	output->randr_output = NULL;
+    }
+    for (c = 0; c < config->num_crtc; c++)
+    {
+	xf86CrtcPtr	crtc = config->crtc[c];
+
+	crtc->randr_crtc = NULL;
+    }
     return screen->CloseScreen (index, screen);
 }
 
diff-tree 479b2be4badab0a67b1f091feb83c1364e27d783 (from b63e0d2545bb75e14d9de019a88f31e20a2f7377)
Author: Keith Packard <keithp at guitar.keithp.com>
Date:   Fri Mar 23 00:57:18 2007 -0700

    Clear allocated RandR screen private structure.
    
    Use xcalloc instead of xalloc when allocating this structure to ensure
    consistent contents at startup.
    (cherry picked from commit 16f4c0c1750824f2e5a001cef82a4122a7a2beb0)

diff --git a/randr/randr.c b/randr/randr.c
index 5fa9baf..4dd0ee5 100644
--- a/randr/randr.c
+++ b/randr/randr.c
@@ -230,7 +230,7 @@ Bool RRScreenInit(ScreenPtr pScreen)
 	RRScreenGeneration = serverGeneration;
     }
 
-    pScrPriv = (rrScrPrivPtr) xalloc (sizeof (rrScrPrivRec));
+    pScrPriv = (rrScrPrivPtr) xcalloc (1, sizeof (rrScrPrivRec));
     if (!pScrPriv)
 	return FALSE;
 
diff-tree b63e0d2545bb75e14d9de019a88f31e20a2f7377 (from 3e9f7a5504ab41d845e88f293d8498c963d8a7d8)
Author: Keith Packard <keithp at guitar.keithp.com>
Date:   Tue Mar 20 07:17:27 2007 -0700

    Clean up Rotate state on server reset.
    
    The rotation state is stored in the xf86_config structure which is not
    re-initialized at server reset time. Clean it up at CloseScreen time.
    (cherry picked from commit f8db7665dcd7af78ca4db2461e0bf787ec662cb1)

diff --git a/hw/xfree86/loader/xf86sym.c b/hw/xfree86/loader/xf86sym.c
index bc7c814..5175f01 100644
--- a/hw/xfree86/loader/xf86sym.c
+++ b/hw/xfree86/loader/xf86sym.c
@@ -1170,6 +1170,7 @@ _X_HIDDEN void *xfree86LookupTab[] = {
     SYMVAR(pciNumBuses)
 
     /* modes */
+    SYMVAR(xf86CrtcConfigPrivateIndex)
     SYMFUNC(xf86CrtcConfigInit)
     SYMFUNC(xf86CrtcConfigPrivateIndex)
     SYMFUNC(xf86CrtcCreate)
diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c
index 1a42920..a875cdf 100644
--- a/hw/xfree86/modes/xf86Crtc.c
+++ b/hw/xfree86/modes/xf86Crtc.c
@@ -566,6 +566,22 @@ xf86CrtcCreateScreenResources (ScreenPtr
 }
 
 /*
+ * Clean up config on server reset
+ */
+static Bool
+xf86CrtcCloseScreen (int index, ScreenPtr screen)
+{
+    ScrnInfoPtr		scrn = xf86Screens[screen->myNum];
+    xf86CrtcConfigPtr	config = XF86_CRTC_CONFIG_PTR(scrn);
+    
+    screen->CloseScreen = config->CloseScreen;
+
+    xf86RotateCloseScreen (screen);
+
+    return screen->CloseScreen (index, screen);
+}
+
+/*
  * Called at ScreenInit time to set up
  */
 Bool
@@ -596,6 +612,10 @@ xf86CrtcScreenInit (ScreenPtr screen)
     /* Wrap CreateScreenResources so we can initialize the RandR code */
     config->CreateScreenResources = screen->CreateScreenResources;
     screen->CreateScreenResources = xf86CrtcCreateScreenResources;
+
+    config->CloseScreen = screen->CloseScreen;
+    screen->CloseScreen = xf86CrtcCloseScreen;
+    
     return TRUE;
 }
 
diff --git a/hw/xfree86/modes/xf86Crtc.h b/hw/xfree86/modes/xf86Crtc.h
index b751592..42daf60 100644
--- a/hw/xfree86/modes/xf86Crtc.h
+++ b/hw/xfree86/modes/xf86Crtc.h
@@ -544,6 +544,8 @@ typedef struct _xf86CrtcConfig {
 
     CreateScreenResourcesProcPtr    CreateScreenResources;
 
+    CloseScreenProcPtr		    CloseScreen;
+
     /* Cursor information */
     xf86CursorInfoPtr	cursor_info;
     CursorPtr		cursor;
@@ -593,6 +595,12 @@ xf86CrtcSetMode (xf86CrtcPtr crtc, Displ
 Bool
 xf86CrtcRotate (xf86CrtcPtr crtc, DisplayModePtr mode, Rotation rotation);
 
+/*
+ * Clean up rotation during CloseScreen
+ */
+void
+xf86RotateCloseScreen (ScreenPtr pScreen);
+
 /**
  * Return whether any output is assigned to the crtc
  */
diff --git a/hw/xfree86/modes/xf86Rotate.c b/hw/xfree86/modes/xf86Rotate.c
index e82b69e..e8fafd0 100644
--- a/hw/xfree86/modes/xf86Rotate.c
+++ b/hw/xfree86/modes/xf86Rotate.c
@@ -321,36 +321,68 @@ xf86RotateWakeupHandler(pointer data, in
 {
 }
 
-Bool
-xf86CrtcRotate (xf86CrtcPtr crtc, DisplayModePtr mode, Rotation rotation)
+static void
+xf86RotateDestroy (xf86CrtcPtr crtc)
 {
     ScrnInfoPtr		pScrn = crtc->scrn;
-    xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
     ScreenPtr		pScreen = pScrn->pScreen;
+    xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
+    int			c;
     
-    if (rotation == RR_Rotate_0)
+    /* Free memory from rotation */
+    if (crtc->rotatedPixmap || crtc->rotatedData)
     {
-	/* Free memory from rotation */
+	crtc->funcs->shadow_destroy (crtc, crtc->rotatedPixmap, crtc->rotatedData);
+	crtc->rotatedPixmap = NULL;
+	crtc->rotatedData = NULL;
+    }
+
+    for (c = 0; c < xf86_config->num_crtc; c++)
 	if (crtc->rotatedPixmap || crtc->rotatedData)
-	{
-	    crtc->funcs->shadow_destroy (crtc, crtc->rotatedPixmap, crtc->rotatedData);
-	    crtc->rotatedPixmap = NULL;
-	    crtc->rotatedData = NULL;
-	}
+	    return;
 
-	if (xf86_config->rotation_damage)
+    /*
+     * Clean up damage structures when no crtcs are rotated
+     */
+    if (xf86_config->rotation_damage)
+    {
+	/* Free damage structure */
+	if (xf86_config->rotation_damage_registered)
 	{
-	    /* Free damage structure */
 	    DamageUnregister (&(*pScreen->GetScreenPixmap)(pScreen)->drawable,
 			      xf86_config->rotation_damage);
 	    xf86_config->rotation_damage_registered = FALSE;
-	    DamageDestroy (xf86_config->rotation_damage);
-	    xf86_config->rotation_damage = NULL;
-	    /* Free block/wakeup handler */
-	    RemoveBlockAndWakeupHandlers (xf86RotateBlockHandler,
-					  xf86RotateWakeupHandler,
-					  (pointer) pScreen);
 	}
+	DamageDestroy (xf86_config->rotation_damage);
+	xf86_config->rotation_damage = NULL;
+	/* Free block/wakeup handler */
+	RemoveBlockAndWakeupHandlers (xf86RotateBlockHandler,
+				      xf86RotateWakeupHandler,
+				      (pointer) pScreen);
+    }
+}
+
+void
+xf86RotateCloseScreen (ScreenPtr screen)
+{
+    ScrnInfoPtr		scrn = xf86Screens[screen->myNum];
+    xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+    int			c;
+
+    for (c = 0; c < xf86_config->num_crtc; c++)
+	xf86RotateDestroy (xf86_config->crtc[c]);
+}
+
+Bool
+xf86CrtcRotate (xf86CrtcPtr crtc, DisplayModePtr mode, Rotation rotation)
+{
+    ScrnInfoPtr		pScrn = crtc->scrn;
+    xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
+    ScreenPtr		pScreen = pScrn->pScreen;
+    
+    if (rotation == RR_Rotate_0)
+    {
+	xf86RotateDestroy (crtc);
     }
     else
     {
diff-tree 3e9f7a5504ab41d845e88f293d8498c963d8a7d8 (from f292de2ef13dc994a38029cee9e2642576893332)
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Wed Mar 21 02:35:31 2007 +0200

    XFree86 DGA: Guard against NULL pointer dereferences.
    Ass, u, me ...

diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c
index c9c8059..17ffed8 100644
--- a/hw/xfree86/common/xf86Xinput.c
+++ b/hw/xfree86/common/xf86Xinput.c
@@ -423,17 +423,19 @@ xf86PostMotionEvent(DeviceIntPtr	device,
 
 #if XFreeXDGA
     if (first_valuator == 0 && num_valuators >= 2) {
-        index = miPointerGetScreen(inputInfo.pointer)->myNum;
-        if (is_absolute) {
-            dx = valuators[0] - device->valuator->lastx;
-            dy = valuators[1] - device->valuator->lasty;
-        }
-        else {
-            dx = valuators[0];
-            dy = valuators[1];
+        if (miPointerGetScreen(inputInfo.pointer)) {
+            index = miPointerGetScreen(inputInfo.pointer)->myNum;
+            if (is_absolute) {
+                dx = valuators[0] - device->valuator->lastx;
+                dy = valuators[1] - device->valuator->lasty;
+            }
+            else {
+                dx = valuators[0];
+                dy = valuators[1];
+            }
+            if (DGAStealMotionEvent(index, dx, dy))
+                goto out;
         }
-        if (DGAStealMotionEvent(index, dx, dy))
-            goto out;
     }
 #endif
 
@@ -505,9 +507,11 @@ xf86PostButtonEvent(DeviceIntPtr	device,
     int index;
 
 #if XFreeXDGA
-    index = miPointerGetScreen(inputInfo.pointer)->myNum;
-    if (DGAStealButtonEvent(index, button, is_down))
-        return;
+    if (miPointerGetScreen(inputInfo.pointer)) {
+        index = miPointerGetScreen(inputInfo.pointer)->myNum;
+        if (DGAStealButtonEvent(index, button, is_down))
+            return;
+    }
 #endif
     
     valuators = xcalloc(sizeof(int), num_valuators);
@@ -588,9 +592,11 @@ xf86PostKeyboardEvent(DeviceIntPtr      
     int index;
 
 #if XFreeXDGA
-    index = miPointerGetScreen(inputInfo.pointer)->myNum;
-    if (DGAStealKeyEvent(index, key_code, is_down))
-        return;
+    if (miPointerGetScreen(inputInfo.pointer)) {
+        index = miPointerGetScreen(inputInfo.pointer)->myNum;
+        if (DGAStealKeyEvent(index, key_code, is_down))
+            return;
+    }
 #endif
 
     if (!xf86Events)
diff-tree f292de2ef13dc994a38029cee9e2642576893332 (from f34b9a20b0181d3c2641c305e91180711afbd4b9)
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Wed Mar 21 02:04:12 2007 +0200

    XKB: Fix size_syms calculation bug
    
    Apparently it needed to be nSyms*15/10, not *12/10; make it match the
    other allocation code.

diff --git a/xkb/XKBMAlloc.c b/xkb/XKBMAlloc.c
index 4b7428b..9feaf8e 100644
--- a/xkb/XKBMAlloc.c
+++ b/xkb/XKBMAlloc.c
@@ -399,7 +399,7 @@ KeyCode		matchingKeys[XkbMaxKeyCount],nM
 	}
 	if (nResize>0) {
 	    int nextMatch;
-	    xkb->map->size_syms= (nTotal*12)/10;
+	    xkb->map->size_syms= (nTotal*15)/10;
 	    newSyms = _XkbTypedCalloc(xkb->map->size_syms,KeySym);
 	    if (newSyms==NULL)
 		return BadAlloc;
diff-tree f34b9a20b0181d3c2641c305e91180711afbd4b9 (from 021fc5cb2cb4a7972b4a6fcb570c1da92787d68d)
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Wed Mar 21 02:03:37 2007 +0200

    XKB: Be a tiny bit more conservative with type allocation
    
    Make sure size_types will _always_ be 0 if we don't have any types.

diff --git a/xkb/xkbUtils.c b/xkb/xkbUtils.c
index 1d23667..bb6d8a0 100644
--- a/xkb/xkbUtils.c
+++ b/xkb/xkbUtils.c
@@ -1140,6 +1140,9 @@ XkbCopyKeymap(XkbDescPtr src, XkbDescPtr
                     dtype->preserve = NULL;
                 }
             }
+
+            dst->map->size_types = src->map->num_types;
+            dst->map->num_types = src->map->num_types;
         }
         else {
             if (dst->map->types) {
@@ -1155,9 +1158,9 @@ XkbCopyKeymap(XkbDescPtr src, XkbDescPtr
                 xfree(dst->map->types);
                 dst->map->types = NULL;
             }
+            dst->map->num_types = 0;
+            dst->map->size_types = 0;
         }
-        dst->map->size_types = src->map->num_types;
-        dst->map->num_types = src->map->num_types;
 
         if (src->map->modmap) {
             if (src->max_key_code != dst->max_key_code) {
diff-tree 021fc5cb2cb4a7972b4a6fcb570c1da92787d68d (from 9398d62f27ee1b287e4458fd8b011c10f7b59efd)
Author: Adam Jackson <ajax at benzedrine.nwnk.net>
Date:   Sun Mar 18 16:31:19 2007 -0400

    Static markup and dead code cull over xkb/.
    
    The former <X11/extensions/XKBsrv.h> has been pulled into the server now as
    include/xkbsrv.h, and the world updated to look for it in the new place,
    since it made no sense to define server API in an extension header.  Any
    further work along this line will need to do similar things with XKBgeom.h
    and friends.

diff --git a/Xext/xevie.c b/Xext/xevie.c
index e979e7e..2fd68f8 100644
--- a/Xext/xevie.c
+++ b/Xext/xevie.c
@@ -52,7 +52,7 @@ of the copyright holder.
 #include "inputstr.h"
 #include "windowstr.h"
 #include "cursorstr.h"
-#include <X11/extensions/XKBsrv.h>
+#include <xkbsrv.h>
 
 #include "../os/osdep.h"
 
diff --git a/dix/devices.c b/dix/devices.c
index 8eb54f7..f738419 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -67,7 +67,7 @@ SOFTWARE.
 #define	XKB_IN_SERVER
 #endif
 #ifdef XKB
-#include <X11/extensions/XKBsrv.h>
+#include <xkbsrv.h>
 #endif
 #include "xace.h"
 
diff --git a/dix/dispatch.c b/dix/dispatch.c
index b258aa6..32f6788 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -143,7 +143,7 @@ int ProcInitialConnection();
 #define XKB_IN_SERVER
 #endif
 #include "inputstr.h"
-#include <X11/extensions/XKBsrv.h>
+#include <xkbsrv.h>
 #endif
 
 #ifdef XSERVER_DTRACE
diff --git a/dix/events.c b/dix/events.c
index c0b62b8..02598a3 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -133,7 +133,7 @@ of the copyright holder.
 
 #ifdef XKB
 #include <X11/extensions/XKBproto.h>
-#include <X11/extensions/XKBsrv.h>
+#include <xkbsrv.h>
 extern Bool XkbFilterEvents(ClientPtr, int, xEvent *);
 #endif
 
diff --git a/dix/getevents.c b/dix/getevents.c
index 935112d..3f636bc 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -44,7 +44,7 @@
 
 #ifdef XKB
 #include <X11/extensions/XKBproto.h>
-#include <X11/extensions/XKBsrv.h>
+#include <xkbsrv.h>
 extern Bool XkbCopyKeymap(XkbDescPtr src, XkbDescPtr dst, Bool sendNotifies);
 #endif
 
diff --git a/hw/dmx/dmxclient.h b/hw/dmx/dmxclient.h
index 586b829..657a127 100644
--- a/hw/dmx/dmxclient.h
+++ b/hw/dmx/dmxclient.h
@@ -126,7 +126,7 @@ typedef XID           KeySym64;
 #undef KeySym
 #endif
 
-/* These are in exglobals.h, but that conflicts with X11/extensions/XKBsrv.h */
+/* These are in exglobals.h, but that conflicts with xkbsrv.h */
 extern int ProximityIn;
 extern int ProximityOut;
 extern int DeviceValuator;
@@ -144,7 +144,7 @@ extern int ChangeDeviceNotify;
 #ifndef XKB_IN_SERVER
 #define XKB_IN_SERVER
 #endif
-#include <X11/extensions/XKBsrv.h>
+#include <xkbsrv.h>
 #undef XPointer
 #endif
 #include <X11/extensions/XIproto.h>
diff --git a/hw/kdrive/src/kinput.c b/hw/kdrive/src/kinput.c
index 3bf6bad..857f04f 100644
--- a/hw/kdrive/src/kinput.c
+++ b/hw/kdrive/src/kinput.c
@@ -42,7 +42,7 @@
 #endif
 
 #ifdef XKB
-#include <X11/extensions/XKBsrv.h>
+#include <xkbsrv.h>
 #endif
 
 #include <X11/extensions/XI.h>
diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c
index c0e21dd..1bd3c62 100644
--- a/hw/xfree86/common/xf86Config.c
+++ b/hw/xfree86/common/xf86Config.c
@@ -75,7 +75,7 @@ extern DeviceAssocRec mouse_assoc;
 #ifdef XKB
 #undef XKB_IN_SERVER
 #define XKB_IN_SERVER
-#include <X11/extensions/XKBsrv.h>
+#include <xkbsrv.h>
 #endif
 
 #ifdef RENDER
diff --git a/hw/xfree86/common/xf86DGA.c b/hw/xfree86/common/xf86DGA.c
index 28058b5..43db1ee 100644
--- a/hw/xfree86/common/xf86DGA.c
+++ b/hw/xfree86/common/xf86DGA.c
@@ -43,7 +43,7 @@
 #include "servermd.h"
 #include "micmap.h"
 #ifdef XKB
-#include <X11/extensions/XKBsrv.h>
+#include <xkbsrv.h>
 #endif
 #include "xf86Xinput.h"
 
diff --git a/hw/xfree86/common/xf86XKB.c b/hw/xfree86/common/xf86XKB.c
index 399eb02..b805885 100644
--- a/hw/xfree86/common/xf86XKB.c
+++ b/hw/xfree86/common/xf86XKB.c
@@ -73,7 +73,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #define XF86_OS_PRIVS
 #include "xf86_OSlib.h"
 
-#include <X11/extensions/XKBsrv.h>
+#include <xkbsrv.h>
 
 void
 xf86InitXkb(void)
diff --git a/hw/xfree86/dixmods/xkbKillSrv.c b/hw/xfree86/dixmods/xkbKillSrv.c
index 415873a..b3399db 100644
--- a/hw/xfree86/dixmods/xkbKillSrv.c
+++ b/hw/xfree86/dixmods/xkbKillSrv.c
@@ -40,7 +40,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #include "inputstr.h"
 #include "scrnintstr.h"
 #include "windowstr.h"
-#include <X11/extensions/XKBsrv.h>
+#include <xkbsrv.h>
 #include <X11/extensions/XI.h>
 
 #include "xf86.h"
diff --git a/hw/xfree86/dixmods/xkbPrivate.c b/hw/xfree86/dixmods/xkbPrivate.c
index e6d4f0f..e0cd217 100644
--- a/hw/xfree86/dixmods/xkbPrivate.c
+++ b/hw/xfree86/dixmods/xkbPrivate.c
@@ -12,7 +12,7 @@
 #include <X11/X.h>
 #include "windowstr.h"
 #define XKBSRV_NEED_FILE_FUNCS
-#include <X11/extensions/XKBsrv.h>
+#include <xkbsrv.h>
 
 #include "xf86.h"
 
diff --git a/hw/xfree86/dixmods/xkbVT.c b/hw/xfree86/dixmods/xkbVT.c
index a1cdc70..e6d69e2 100644
--- a/hw/xfree86/dixmods/xkbVT.c
+++ b/hw/xfree86/dixmods/xkbVT.c
@@ -40,7 +40,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #include "inputstr.h"
 #include "scrnintstr.h"
 #include "windowstr.h"
-#include <X11/extensions/XKBsrv.h>
+#include <xkbsrv.h>
 #include <X11/extensions/XI.h>
 
 #include "xf86.h"
diff --git a/hw/xfree86/loader/dixsym.c b/hw/xfree86/loader/dixsym.c
index 594bf43..5d06b05 100644
--- a/hw/xfree86/loader/dixsym.c
+++ b/hw/xfree86/loader/dixsym.c
@@ -86,7 +86,7 @@
 #endif
 #include "selection.h"
 #ifdef XKB
-#include <X11/extensions/XKBsrv.h>
+#include <xkbsrv.h>
 extern int XkbDfltRepeatDelay, XkbDfltRepeatInterval;
 #endif
 
diff --git a/hw/xgl/egl/kinput.c b/hw/xgl/egl/kinput.c
index b374bf5..5fd23f5 100644
--- a/hw/xgl/egl/kinput.c
+++ b/hw/xgl/egl/kinput.c
@@ -41,7 +41,7 @@
 
 #ifdef XKB
 #define XKB_IN_SERVER
-#include <X11/extensions/XKBsrv.h>
+#include <xkbsrv.h>
 #endif
 
 static DeviceIntPtr	pKdKeyboard, pKdPointer;
diff --git a/hw/xgl/glx/xglx.c b/hw/xgl/glx/xglx.c
index 57cb847..92974f0 100644
--- a/hw/xgl/glx/xglx.c
+++ b/hw/xgl/glx/xglx.c
@@ -50,7 +50,7 @@
 
 #ifdef XKB
 #include <X11/extensions/XKB.h>
-#include <X11/extensions/XKBsrv.h>
+#include <xkbsrv.h>
 #include <X11/extensions/XKBconfig.h>
 
 extern Bool
diff --git a/hw/xnest/Keyboard.c b/hw/xnest/Keyboard.c
index 0dacae7..bb3cb13 100644
--- a/hw/xnest/Keyboard.c
+++ b/hw/xnest/Keyboard.c
@@ -36,7 +36,7 @@ is" without express or implied warranty.
 
 #ifdef XKB
 #include <X11/extensions/XKB.h>
-#include <X11/extensions/XKBsrv.h>
+#include <xkbsrv.h>
 #include <X11/extensions/XKBconfig.h>
 
 extern Bool
diff --git a/hw/xwin/InitOutput.c b/hw/xwin/InitOutput.c
index 39a5eda..9457c9c 100644
--- a/hw/xwin/InitOutput.c
+++ b/hw/xwin/InitOutput.c
@@ -44,7 +44,7 @@ from The Open Group.
 #include <mntent.h>
 #endif
 #if defined(XKB) && defined(WIN32)
-#include <X11/extensions/XKBsrv.h>
+#include <xkbsrv.h>
 #endif
 #ifdef RELOCATE_PROJECTROOT
 #include <shlobj.h>
diff --git a/hw/xwin/winconfig.c b/hw/xwin/winconfig.c
index e3d1808..2c18771 100644
--- a/hw/xwin/winconfig.c
+++ b/hw/xwin/winconfig.c
@@ -40,7 +40,7 @@
 #ifndef XKB_IN_SERVER
 #define XKB_IN_SERVER
 #endif
-#include <X11/extensions/XKBsrv.h>
+#include <xkbsrv.h>
 #endif
 
 #ifdef XWIN_XF86CONFIG
diff --git a/hw/xwin/winkeybd.c b/hw/xwin/winkeybd.c
index 164e391..d574f20 100644
--- a/hw/xwin/winkeybd.c
+++ b/hw/xwin/winkeybd.c
@@ -44,7 +44,7 @@
 #ifndef XKB_IN_SERVER
 #define XKB_IN_SERVER
 #endif
-#include <X11/extensions/XKBsrv.h>
+#include <xkbsrv.h>
 #endif
 
 static Bool g_winKeyState[NUM_KEYCODES];
diff --git a/include/xkbsrv.h b/include/xkbsrv.h
new file mode 100644
index 0000000..5edee53
--- /dev/null
+++ b/include/xkbsrv.h
@@ -0,0 +1,1022 @@
+/************************************************************
+Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
+
+Permission to use, copy, modify, and distribute this
+software and its documentation for any purpose and without
+fee is hereby granted, provided that the above copyright
+notice appear in all copies and that both that copyright
+notice and this permission notice appear in supporting
+documentation, and that the name of Silicon Graphics not be 
+used in advertising or publicity pertaining to distribution 
+of the software without specific prior written permission.
+Silicon Graphics makes no representation about the suitability 
+of this software for any purpose. It is provided "as is"
+without any express or implied warranty.
+
+SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 
+SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 
+AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
+GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 
+DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 
+DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 
+OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
+THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+********************************************************/
+
+#ifndef _XKBSRV_H_
+#define	_XKBSRV_H_
+
+#ifdef XKB_IN_SERVER
+#define XkbAllocClientMap		SrvXkbAllocClientMap
+#define XkbAllocServerMap		SrvXkbAllocServerMap
+#define XkbChangeTypesOfKey		SrvXkbChangeTypesOfKey
+#define XkbCopyKeyTypes			SrvXkbCopyKeyTypes
+#define XkbFreeClientMap		SrvXkbFreeClientMap
+#define XkbFreeServerMap		SrvXkbFreeServerMap
+#define	XkbKeyTypesForCoreSymbols	SrvXkbKeyTypesForCoreSymbols
+#define	XkbApplyCompatMapToKey		SrvXkbApplyCompatMapToKey
+#define XkbResizeKeyActions		SrvXkbResizeKeyActions
+#define XkbResizeKeySyms		SrvXkbResizeKeySyms
+#define XkbResizeKeyType		SrvXkbResizeKeyType
+#define XkbAllocCompatMap		SrvXkbAllocCompatMap
+#define XkbAllocControls		SrvXkbAllocControls
+#define XkbAllocIndicatorMaps		SrvXkbAllocIndicatorMaps
+#define XkbAllocKeyboard		SrvXkbAllocKeyboard
+#define XkbAllocNames			SrvXkbAllocNames
+#define XkbFreeCompatMap		SrvXkbFreeCompatMap
+#define XkbFreeKeyboard			SrvXkbFreeKeyboard
+#define XkbFreeNames			SrvXkbFreeNames
+#define XkbLatchModifiers		SrvXkbLatchModifiers
+#define XkbLatchGroup			SrvXkbLatchGroup
+#define XkbVirtualModsToReal		SrvXkbVirtualModsToReal
+#define	XkbChangeKeycodeRange		SrvXkbChangeKeycodeRange
+#define	XkbApplyVirtualModChanges	SrvXkbApplyVirtualModChanges
+#endif
+
+#include <X11/extensions/XKBstr.h>
+#include <X11/extensions/XKBproto.h>
+#include "inputstr.h"
+
+typedef struct _XkbInterest {
+	DeviceIntPtr		dev;
+	ClientPtr		client;
+	XID			resource;
+	struct _XkbInterest *	next;
+	CARD16			extDevNotifyMask;
+	CARD16			stateNotifyMask;
+	CARD16			namesNotifyMask;
+	CARD32 			ctrlsNotifyMask;
+	CARD8			compatNotifyMask;
+	BOOL			bellNotifyMask;
+	BOOL			actionMessageMask;
+	CARD16			accessXNotifyMask;
+	CARD32			iStateNotifyMask;
+	CARD32			iMapNotifyMask;
+	CARD16			altSymsNotifyMask;
+	CARD32			autoCtrls;
+	CARD32			autoCtrlValues;
+} XkbInterestRec,*XkbInterestPtr;
+
+typedef struct _XkbRadioGroup {
+	CARD8		flags;
+	CARD8		nMembers;
+	CARD8		dfltDown;
+	CARD8		currentDown;
+	CARD8		members[XkbRGMaxMembers];
+} XkbRadioGroupRec, *XkbRadioGroupPtr;
+
+typedef struct	_XkbEventCause {
+	CARD8		kc;
+	CARD8		event;
+	CARD8		mjr;
+	CARD8		mnr;
+	ClientPtr	client;
+} XkbEventCauseRec,*XkbEventCausePtr;
+#define	XkbSetCauseKey(c,k,e)	{ (c)->kc= (k),(c)->event= (e),\
+				  (c)->mjr= (c)->mnr= 0; \
+				  (c)->client= NULL; }
+#define	XkbSetCauseReq(c,j,n,cl) { (c)->kc= (c)->event= 0,\
+				  (c)->mjr= (j),(c)->mnr= (n);\
+				  (c)->client= (cl); }
+#define	XkbSetCauseCoreReq(c,e,cl) XkbSetCauseReq(c,e,0,cl)
+#define	XkbSetCauseXkbReq(c,e,cl)  XkbSetCauseReq(c,XkbReqCode,e,cl)
+#define	XkbSetCauseUnknown(c)	   XkbSetCauseKey(c,0,0)
+
+#define	_OFF_TIMER		0
+#define	_KRG_WARN_TIMER		1
+#define	_KRG_TIMER		2
+#define	_SK_TIMEOUT_TIMER	3
+#define	_ALL_TIMEOUT_TIMER	4
+
+#define	_BEEP_NONE		0
+#define	_BEEP_FEATURE_ON	1
+#define	_BEEP_FEATURE_OFF	2
+#define	_BEEP_FEATURE_CHANGE	3
+#define	_BEEP_SLOW_WARN		4
+#define	_BEEP_SLOW_PRESS	5
+#define	_BEEP_SLOW_ACCEPT	6
+#define	_BEEP_SLOW_REJECT	7
+#define	_BEEP_SLOW_RELEASE	8
+#define	_BEEP_STICKY_LATCH	9
+#define	_BEEP_STICKY_LOCK	10
+#define	_BEEP_STICKY_UNLOCK	11
+#define	_BEEP_LED_ON		12
+#define	_BEEP_LED_OFF		13
+#define	_BEEP_LED_CHANGE	14
+#define	_BEEP_BOUNCE_REJECT	15
+
+typedef struct _XkbSrvInfo {
+	XkbStateRec	 prev_state;
+	XkbStateRec	 state;
+	XkbDescPtr	 desc;
+
+	DeviceIntPtr	 device;
+	KbdCtrlProcPtr	 kbdProc;
+
+	XkbRadioGroupPtr radioGroups;
+	CARD8		 nRadioGroups;
+	CARD8		 clearMods;
+	CARD8		 setMods;
+	INT16		 groupChange;
+
+	CARD16		 dfltPtrDelta;
+
+	double		 mouseKeysCurve;
+	double		 mouseKeysCurveFactor;
+	INT16		 mouseKeysDX;
+	INT16		 mouseKeysDY;
+	CARD8		 mouseKeysFlags;
+	Bool		 mouseKeysAccel;
+	CARD8		 mouseKeysCounter;
+
+	CARD8		 lockedPtrButtons;
+	CARD8		 shiftKeyCount;
+	KeyCode		 mouseKey;
+	KeyCode		 inactiveKey;
+	KeyCode		 slowKey;
+	KeyCode		 repeatKey;
+	CARD8		 krgTimerActive;
+	CARD8		 beepType;
+	CARD8		 beepCount;
+
+	CARD32		 flags;
+	CARD32		 lastPtrEventTime;
+	CARD32		 lastShiftEventTime;
+	OsTimerPtr	 beepTimer;
+	OsTimerPtr	 mouseKeyTimer;
+	OsTimerPtr	 slowKeysTimer;
+	OsTimerPtr	 bounceKeysTimer;
+	OsTimerPtr	 repeatKeyTimer;
+	OsTimerPtr	 krgTimer;
+} XkbSrvInfoRec, *XkbSrvInfoPtr;
+
+#define	XkbSLI_IsDefault	(1L<<0)
+#define	XkbSLI_HasOwnState	(1L<<1)
+
+typedef struct	_XkbSrvLedInfo {
+	CARD16			flags;
+	CARD16			class;
+	CARD16			id;
+	union {
+	    KbdFeedbackPtr	kf;
+	    LedFeedbackPtr	lf;
+	} 			fb;
+
+	CARD32			physIndicators;
+	CARD32			autoState;
+	CARD32			explicitState;
+	CARD32			effectiveState;
+
+	CARD32			mapsPresent;
+	CARD32			namesPresent;
+	XkbIndicatorMapPtr	maps;
+	Atom *			names;
+
+	CARD32			usesBase;
+	CARD32			usesLatched;
+	CARD32			usesLocked;
+	CARD32			usesEffective;
+	CARD32			usesCompat;
+	CARD32			usesControls;
+
+	CARD32			usedComponents;
+} XkbSrvLedInfoRec, *XkbSrvLedInfoPtr;
+
+/*
+ * Settings for xkbClientFlags field (used by DIX)
+ * These flags _must_ not overlap with XkbPCF_*
+ */
+#define	_XkbClientInitialized		(1<<15)
+
+#define	_XkbWantsDetectableAutoRepeat(c)\
+	((c)->xkbClientFlags&XkbPCF_DetectableAutoRepeatMask)
+
+/*
+ * Settings for flags field
+ */
+#define	_XkbStateNotifyInProgress	(1<<0)
+
+typedef struct
+{
+    ProcessInputProc processInputProc;
+    ProcessInputProc realInputProc;
+    DeviceUnwrapProc unwrapProc;
+} xkbDeviceInfoRec, *xkbDeviceInfoPtr;
+
+#define WRAP_PROCESS_INPUT_PROC(device, oldprocs, proc, unwrapproc) \
+	device->public.processInputProc = proc; \
+	oldprocs->processInputProc = \
+	oldprocs->realInputProc = device->public.realInputProc; \
+	device->public.realInputProc = proc; \
+	oldprocs->unwrapProc = device->unwrapProc; \
+	device->unwrapProc = unwrapproc;
+
+#define COND_WRAP_PROCESS_INPUT_PROC(device, oldprocs, proc, unwrapproc) \
+	if (device->public.processInputProc == device->public.realInputProc)\
+	    device->public.processInputProc = proc; \
+	oldprocs->processInputProc = \
+	oldprocs->realInputProc = device->public.realInputProc; \
+	device->public.realInputProc = proc; \
+	oldprocs->unwrapProc = device->unwrapProc; \
+	device->unwrapProc = unwrapproc;
+
+#define UNWRAP_PROCESS_INPUT_PROC(device, oldprocs) \
+	device->public.processInputProc = oldprocs->processInputProc; \
+	device->public.realInputProc = oldprocs->realInputProc; \
+	device->unwrapProc = oldprocs->unwrapProc;
+
+#define XKBDEVICEINFO(dev) ((xkbDeviceInfoPtr) (dev)->devPrivates[xkbDevicePrivateIndex].ptr)
+
+/***====================================================================***/
+
+
+/***====================================================================***/
+
+#define XkbAX_KRGMask	 (XkbSlowKeysMask|XkbBounceKeysMask)
+#define	XkbAllFilteredEventsMask \
+	(XkbAccessXKeysMask|XkbRepeatKeysMask|XkbMouseKeysAccelMask|XkbAX_KRGMask)
+
+/***====================================================================***/
+
+extern int	XkbReqCode;
+extern int	XkbEventBase;
+extern int	XkbDisableLockActions;
+extern char *	XkbBaseDirectory;
+extern char *	XkbBinDirectory;
+extern char *	XkbInitialMap;
+extern unsigned	int XkbXIUnsupported;
+
+extern Bool	noXkbExtension;
+
+extern pointer	XkbLastRepeatEvent;
+
+extern CARD32	xkbDebugFlags;
+
+#define	_XkbAlloc(s)		xalloc((s))
+#define	_XkbCalloc(n,s)		Xcalloc((n)*(s))
+#define	_XkbRealloc(o,s)	Xrealloc((o),(s))
+#define	_XkbTypedAlloc(t)	((t *)xalloc(sizeof(t)))
+#define	_XkbTypedCalloc(n,t)	((t *)Xcalloc((n)*sizeof(t)))
+#define	_XkbTypedRealloc(o,n,t) \
+	((o)?(t *)Xrealloc((o),(n)*sizeof(t)):_XkbTypedCalloc(n,t))
+#define	_XkbClearElems(a,f,l,t)	bzero(&(a)[f],((l)-(f)+1)*sizeof(t))
+#define	_XkbFree(p)		Xfree(p)
+
+#define	_XkbLibError(c,l,d) \
+	{ _XkbErrCode= (c); _XkbErrLocation= (l); _XkbErrData= (d); }
+#define	_XkbErrCode2(a,b) ((XID)((((unsigned int)(a))<<24)|((b)&0xffffff)))
+#define	_XkbErrCode3(a,b,c)	_XkbErrCode2(a,(((unsigned int)(b))<<16)|(c))
+#define	_XkbErrCode4(a,b,c,d) _XkbErrCode3(a,b,((((unsigned int)(c))<<8)|(d)))
+
+extern	int	DeviceKeyPress,DeviceKeyRelease;
+extern	int	DeviceButtonPress,DeviceButtonRelease;
+
+#ifdef XINPUT
+#define	_XkbIsPressEvent(t)	(((t)==KeyPress)||((t)==DeviceKeyPress))
+#define	_XkbIsReleaseEvent(t)	(((t)==KeyRelease)||((t)==DeviceKeyRelease))
+#else
+#define	_XkbIsPressEvent(t)	((t)==KeyPress)
+#define	_XkbIsReleaseEvent(t)	((t)==KeyRelease)
+#endif
+
+#define	_XkbCoreKeycodeInRange(c,k)	(((k)>=(c)->curKeySyms.minKeyCode)&&\
+					 ((k)<=(c)->curKeySyms.maxKeyCode))
+#define	_XkbCoreNumKeys(c)	((c)->curKeySyms.maxKeyCode-\
+				 (c)->curKeySyms.minKeyCode+1)
+
+#define	XConvertCase(s,l,u)	XkbConvertCase(s,l,u)
+#undef	IsKeypadKey
+#define	IsKeypadKey(s)		XkbKSIsKeypad(s)
+
+#define	Status		int
+#define	XPointer	pointer
+#define	Display		struct _XDisplay
+
+#ifndef True
+#define	True	1
+#define	False	0
+#endif
+
+#ifndef PATH_MAX
+#ifdef MAXPATHLEN
+#define	PATH_MAX MAXPATHLEN
+#else
+#define	PATH_MAX 1024
+#endif
+#endif
+
+_XFUNCPROTOBEGIN
+
+extern void XkbUseMsg(
+    void
+);
+
+extern int XkbProcessArguments(
+    int				/* argc */,
+    char **			/* argv */,
+    int				/* i */
+);
+
+extern	void	XkbSetExtension(DeviceIntPtr device, ProcessInputProc proc);
+
+extern	void	XkbFreeCompatMap(
+    XkbDescPtr			/* xkb */,
+    unsigned int		/* which */,
+    Bool			/* freeMap */
+);
+
+extern	void XkbFreeNames(
+	XkbDescPtr		/* xkb */,
+	unsigned int		/* which */,
+	Bool			/* freeMap */
+);
+
+extern DeviceIntPtr _XkbLookupAnyDevice(
+    int			/* id */,
+    int *		/* why_rtrn */
+);
+
+extern DeviceIntPtr _XkbLookupKeyboard(
+    int			/* id */,
+    int *		/* why_rtrn */
+);
+
+extern DeviceIntPtr _XkbLookupBellDevice(
+    int			/* id */,
+    int *		/* why_rtrn */
+);
+
+extern DeviceIntPtr _XkbLookupLedDevice(
+    int			/* id */,
+    int *		/* why_rtrn */
+);
+
+extern DeviceIntPtr _XkbLookupButtonDevice(
+    int			/* id */,
+    int *		/* why_rtrn */
+);
+
+extern	XkbDescPtr XkbAllocKeyboard(
+	void
+);
+
+extern	Status XkbAllocClientMap(
+	XkbDescPtr		/* xkb */,
+	unsigned int		/* which */,
+	unsigned int		/* nTypes */
+);
+
+extern	Status XkbAllocServerMap(
+	XkbDescPtr		/* xkb */,
+	unsigned int		/* which */,
+	unsigned int		/* nNewActions */
+);
+
+extern	void	XkbFreeClientMap(
+    XkbDescPtr			/* xkb */,
+    unsigned int		/* what */,
+    Bool			/* freeMap */
+);
+
+extern	void	XkbFreeServerMap(
+    XkbDescPtr			/* xkb */,
+    unsigned int		/* what */,
+    Bool			/* freeMap */
+);
+
+extern	Status XkbAllocIndicatorMaps(
+	XkbDescPtr		/* xkb */
+);
+
+extern	Status	XkbAllocCompatMap(
+    XkbDescPtr			/* xkb */,
+    unsigned int		/* which */,
+    unsigned int		/* nInterpret */
+);
+
+extern	Status XkbAllocNames(
+	XkbDescPtr		/* xkb */,
+	unsigned int		/* which */,
+	int			/* nTotalRG */,
+	int			/* nTotalAliases */
+);
+
+extern	Status	XkbAllocControls(
+	XkbDescPtr		/* xkb */,
+	unsigned int		/* which*/
+);
+
+extern	Status	XkbCopyKeyTypes(
+    XkbKeyTypePtr		/* from */,
+    XkbKeyTypePtr		/* into */,
+    int				/* num_types */
+);
+
+extern	Status	XkbResizeKeyType(
+    XkbDescPtr		/* xkb */,
+    int			/* type_ndx */,
+    int			/* map_count */,
+    Bool		/* want_preserve */,
+    int			/* new_num_lvls */
+);
+
+extern	void	XkbFreeKeyboard(
+	XkbDescPtr		/* xkb */,
+	unsigned int		/* which */,
+	Bool			/* freeDesc */
+);
+
+extern  void XkbSetActionKeyMods(
+	XkbDescPtr		/* xkb */,
+	XkbAction *		/* act */,
+	unsigned int 		/* mods */
+);
+
+extern Bool XkbCheckActionVMods(
+	XkbDescPtr		/* xkb */,
+	XkbAction *		/* act */,
+	unsigned int 		/* changed */
+);
+
+extern	unsigned int XkbMaskForVMask(
+    XkbDescPtr		/* xkb */,
+    unsigned int	/* vmask */
+);
+
+extern Bool XkbVirtualModsToReal(
+	XkbDescPtr	/* xkb */,
+	unsigned int	/* virtua_mask */,
+	unsigned int *	/* mask_rtrn */
+);
+
+extern	unsigned int	XkbAdjustGroup(
+    int			/* group */,
+    XkbControlsPtr	/* ctrls */
+);
+
+extern KeySym *XkbResizeKeySyms(
+    XkbDescPtr		/* xkb */,
+    int 		/* key */,
+    int 		/* needed */
+);
+
+extern XkbAction *XkbResizeKeyActions(
+    XkbDescPtr		/* xkb */,
+    int 		/* key */,
+    int 		/* needed */
+);
+
+extern void XkbUpdateKeyTypesFromCore(
+    DeviceIntPtr	/* pXDev */,
+    KeyCode 		/* first */,
+    CARD8 		/* num */,
+    XkbChangesPtr	/* pChanges */
+);
+
+extern	void XkbUpdateDescActions(	
+    XkbDescPtr		/* xkb */,
+    KeyCode		/* first */,
+    CARD8		/* num */,
+    XkbChangesPtr	/* changes */
+);
+
+extern void XkbUpdateActions(
+    DeviceIntPtr	/* pXDev */,
+    KeyCode 		/* first */,
+    CARD8 		/* num */,
+    XkbChangesPtr  	/* pChanges */,
+    unsigned int *	/* needChecksRtrn */,
+    XkbEventCausePtr	/* cause */
+);
+
+extern void XkbUpdateCoreDescription(
+    DeviceIntPtr	/* keybd */,
+    Bool		/* resize */
+);
+
+extern void XkbApplyMappingChange(
+    DeviceIntPtr	/* pXDev */,
+    CARD8 		/* request */,
+    KeyCode 		/* firstKey */,
+    CARD8 		/* num */,
+    ClientPtr		/* client */
+);
+
+extern void XkbSetIndicators(
+    DeviceIntPtr		/* pXDev */,
+    CARD32			/* affect */,
+    CARD32			/* values */,
+    XkbEventCausePtr		/* cause */
+);
+
+extern void XkbUpdateIndicators(
+    DeviceIntPtr		/* keybd */,
+    CARD32		 	/* changed */,
+    Bool			/* check_edevs */,
+    XkbChangesPtr		/* pChanges */,
+    XkbEventCausePtr		/* cause */
+);
+
+extern XkbSrvLedInfoPtr XkbAllocSrvLedInfo(
+    DeviceIntPtr		/* dev */,
+    KbdFeedbackPtr		/* kf */,
+    LedFeedbackPtr		/* lf */,
+    unsigned int		/* needed_parts */
+);
+
+extern XkbSrvLedInfoPtr XkbFindSrvLedInfo(
+    DeviceIntPtr		/* dev */,
+    unsigned int		/* class */,
+    unsigned int		/* id */,
+    unsigned int		/* needed_parts */
+);
+
+extern void XkbApplyLedNameChanges(
+    DeviceIntPtr		/* dev */,
+    XkbSrvLedInfoPtr		/* sli */,
+    unsigned int		/* changed_names */,
+    xkbExtensionDeviceNotify *	/* ed */,
+    XkbChangesPtr		/* changes */,
+    XkbEventCausePtr		/* cause */
+);
+
+extern void XkbApplyLedMapChanges(
+    DeviceIntPtr		/* dev */,
+    XkbSrvLedInfoPtr		/* sli */,
+    unsigned int		/* changed_maps */,
+    xkbExtensionDeviceNotify *	/* ed */,
+    XkbChangesPtr		/* changes */,
+    XkbEventCausePtr		/* cause */
+);
+
+extern void XkbApplyLedStateChanges(
+    DeviceIntPtr		/* dev */,
+    XkbSrvLedInfoPtr		/* sli */,
+    unsigned int		/* changed_leds */,
+    xkbExtensionDeviceNotify *	/* ed */,
+    XkbChangesPtr		/* changes */,
+    XkbEventCausePtr		/* cause */
+);
+
+extern void XkbFlushLedEvents(	
+    DeviceIntPtr		/* dev */,
+    DeviceIntPtr		/* kbd */,
+    XkbSrvLedInfoPtr		/* sli */,
+    xkbExtensionDeviceNotify *	/* ed */,
+    XkbChangesPtr		/* changes */,
+    XkbEventCausePtr		/* cause */
+);
+
+extern unsigned int XkbIndicatorsToUpdate(
+    DeviceIntPtr		/* dev */,
+    unsigned long		/* state_changes */,
+    Bool			/* enabled_ctrl_changes */
+);
+
+extern void XkbComputeDerivedState(
+    XkbSrvInfoPtr		/* xkbi */
+);
+
+extern void XkbCheckSecondaryEffects(
+    XkbSrvInfoPtr		/* xkbi */,
+    unsigned int		/* which */,
+    XkbChangesPtr		/* changes */,
+    XkbEventCausePtr		/* cause */
+);
+
+extern void XkbCheckIndicatorMaps(
+    DeviceIntPtr		/* dev */,
+    XkbSrvLedInfoPtr		/* sli */,
+    unsigned int		/* which */
+);
+
+extern unsigned int XkbStateChangedFlags(
+    XkbStatePtr			/* old */,
+    XkbStatePtr			/* new */
+);
+
+extern	void XkbSendStateNotify(
+       DeviceIntPtr	/* kbd */,
+       xkbStateNotify *	/* pSN */
+);
+
+extern	void XkbSendMapNotify(
+       DeviceIntPtr	/* kbd */,
+       xkbMapNotify *	/* ev */
+);
+
+extern	int  XkbComputeControlsNotify(
+	DeviceIntPtr		/* kbd */,
+	XkbControlsPtr		/* old */,
+	XkbControlsPtr		/* new */,
+	xkbControlsNotify *	/* pCN */,
+	Bool			/* forceCtrlProc */
+);
+
+extern	void XkbSendControlsNotify(
+       DeviceIntPtr		/* kbd */,
+       xkbControlsNotify *	/* ev */
+);
+
+extern	void XkbSendCompatMapNotify(
+	DeviceIntPtr		/* kbd */,
+	xkbCompatMapNotify *	/* ev */
+);
+
+extern	void XkbHandleBell(
+       BOOL		/* force */,
+       BOOL		/* eventOnly */,
+       DeviceIntPtr	/* kbd */,
+       CARD8		/* percent */,
+       pointer 		/* ctrl */,
+       CARD8		/* class */,
+       Atom		/* name */,
+       WindowPtr	/* pWin */,
+       ClientPtr	/* pClient */
+);
+
+extern	void XkbSendAccessXNotify(
+       DeviceIntPtr		/* kbd */,
+       xkbAccessXNotify *	/* pEv */
+);
+
+extern	void XkbSendNamesNotify(
+       DeviceIntPtr	/* kbd */,
+       xkbNamesNotify *	/* ev */
+);
+
+extern	void XkbSendCompatNotify(
+       DeviceIntPtr		/* kbd */,
+       xkbCompatMapNotify *	/* ev */
+);
+
+extern	void XkbSendActionMessage(
+       DeviceIntPtr		/* kbd */,
+       xkbActionMessage *	/* ev */
+);
+
+extern	void XkbSendExtensionDeviceNotify(
+       DeviceIntPtr			/* kbd */,
+       ClientPtr			/* client */,
+       xkbExtensionDeviceNotify *	/* ev */
+);
+
+extern void XkbSendNotification(
+    DeviceIntPtr		/* kbd */,
+    XkbChangesPtr		/* pChanges */,
+    XkbEventCausePtr		/* cause */
+);
+
+extern void XkbProcessKeyboardEvent(
+    struct _xEvent * 		/* xE */,
+    DeviceIntPtr		/* keybd */,
+    int 			/* count */
+);
+
+extern void XkbHandleActions(
+    DeviceIntPtr		/* dev */,
+    DeviceIntPtr		/* kbd */,
+    struct _xEvent * 		/* xE */,
+    int 			/* count */
+);
+
+extern Bool XkbEnableDisableControls(
+    XkbSrvInfoPtr	/* xkbi */,
+    unsigned long	/* change */,
+    unsigned long	/* newValues */,
+    XkbChangesPtr	/* changes */,
+    XkbEventCausePtr	/* cause */
+);
+
+extern void AccessXInit(
+    DeviceIntPtr        /* dev */
+);
+
+extern Bool AccessXFilterPressEvent(
+    register struct _xEvent *	/* xE */,
+    register DeviceIntPtr	/* keybd */,
+    int				/* count */
+);
+
+extern Bool AccessXFilterReleaseEvent(
+    register struct _xEvent *	/* xE */,
+    register DeviceIntPtr	/* keybd */,
+    int				/* count */
+);
+
+extern void AccessXCancelRepeatKey(
+    XkbSrvInfoPtr	/* xkbi */,
+    KeyCode		/* key */
+);
+
+extern void AccessXComputeCurveFactor(
+    XkbSrvInfoPtr	/* xkbi */,
+    XkbControlsPtr	/* ctrls */
+);
+
+extern	XkbInterestPtr XkbFindClientResource(
+       DevicePtr	/* inDev */,
+       ClientPtr	/* client */
+);
+
+extern	XkbInterestPtr XkbAddClientResource(
+       DevicePtr	/* inDev */,
+       ClientPtr	/* client */,
+       XID		/* id */
+);
+
+extern	int XkbRemoveResourceClient(
+       DevicePtr	/* inDev */,
+       XID		/* id */
+);
+
+extern int XkbDDXInitDevice(
+    DeviceIntPtr        /* dev */
+);
+
+extern	int XkbDDXAccessXBeep(
+    DeviceIntPtr        /* dev */,
+    unsigned int	/* what */,
+    unsigned int	/* which */
+);
+
+extern	void XkbDDXKeyClick(
+    DeviceIntPtr	/* dev */,
+    int			/* keycode */,
+    int			/* synthetic */
+);
+
+extern 	int XkbDDXUsesSoftRepeat(
+    DeviceIntPtr	/* dev */
+);
+
+extern	void XkbDDXKeybdCtrlProc(
+	DeviceIntPtr	/* dev */,
+	KeybdCtrl *	/* ctrl */
+);
+
+extern void XkbDDXChangeControls(
+	DeviceIntPtr	/* dev */,
+	XkbControlsPtr 	/* old */,
+	XkbControlsPtr 	/* new */
+);
+
+extern void XkbDDXUpdateDeviceIndicators(
+	DeviceIntPtr		/* dev */,
+	XkbSrvLedInfoPtr	/* sli */,
+	CARD32			/* newState */
+);
+
+extern void XkbDDXFakePointerButton(
+	int 		/* event */,
+	int		/* button */
+);
+
+extern void XkbDDXFakePointerMotion(
+ 	unsigned int	/* flags */,
+	int		/* x */,
+	int		/* y */
+);
+
+extern void XkbDDXFakeDeviceButton(
+	DeviceIntPtr	/* dev */,
+	Bool		/* press */,
+	int		/* button */
+);
+
+extern int XkbDDXTerminateServer(
+	DeviceIntPtr	/* dev */,
+	KeyCode		/* key */,
+	XkbAction *	/* act */
+);
+
+extern int XkbDDXSwitchScreen(
+	DeviceIntPtr	/* dev */,
+	KeyCode		/* key */,
+	XkbAction *	/* act */
+);
+
+extern int XkbDDXPrivate(
+	DeviceIntPtr	/* dev */,
+	KeyCode		/* key */,
+	XkbAction *	/* act */
+);
+
+extern void XkbDisableComputedAutoRepeats(
+	DeviceIntPtr 	/* pXDev */,
+	unsigned int	/* key */
+);
+
+extern void XkbSetRepeatKeys(
+	DeviceIntPtr 	/* pXDev */,
+	int		/* key */,
+	int	 	/* onoff */
+);
+
+extern	int XkbLatchModifiers(
+	DeviceIntPtr 	/* pXDev */,
+	CARD8 		/* mask */,
+	CARD8 		/* latches */
+);
+
+extern	int XkbLatchGroup(
+	DeviceIntPtr  	/* pXDev */,
+	int	  	/* group */
+);
+
+extern	void XkbClearAllLatchesAndLocks(
+	DeviceIntPtr		/* dev */,
+	XkbSrvInfoPtr		/* xkbi */,
+	Bool			/* genEv */,
+	XkbEventCausePtr	/* cause */
+);
+
+extern	void	XkbSetRulesDflts(
+	char *			/* rulesFile */,
+	char *			/* model */,
+	char *			/* layout */,
+	char *			/* variant */,
+	char *			/* options */
+);
+
+extern	void	XkbInitDevice(
+	DeviceIntPtr 	/* pXDev */
+);
+
+extern	Bool	XkbInitKeyboardDeviceStruct(
+	DeviceIntPtr 		/* pXDev */,
+	XkbComponentNamesPtr	/* pNames */,
+	KeySymsPtr		/* pSyms */,
+	CARD8 			/* pMods */[],
+	BellProcPtr		/* bellProc */,
+	KbdCtrlProcPtr		/* ctrlProc */
+);
+
+extern	int SProcXkbDispatch(
+	ClientPtr		/* client */
+);
+
+extern XkbGeometryPtr XkbLookupNamedGeometry(
+	DeviceIntPtr		/* dev */,
+	Atom			/* name */,
+	Bool *			/* shouldFree */
+);
+
+extern char *	_XkbDupString(
+	char *			/* str */
+);
+
+extern void	XkbConvertCase(
+	KeySym 			/* sym */,
+	KeySym *		/* lower */,
+	KeySym *		/* upper */
+);
+
+extern	Status	 XkbChangeKeycodeRange(	
+	XkbDescPtr		/* xkb */,
+	int 			/* minKC */,
+	int 			/* maxKC */,
+	XkbChangesPtr		/* changes */
+);
+
+extern int XkbFinishDeviceInit(
+	DeviceIntPtr		/* pXDev */
+);
+
+extern void XkbFreeSrvLedInfo(
+	XkbSrvLedInfoPtr	/* sli */
+);
+
+extern void XkbFreeInfo(
+	XkbSrvInfoPtr		/* xkbi */
+);
+
+extern Status XkbChangeTypesOfKey(
+	XkbDescPtr		/* xkb */,
+	int			/* key */,
+	int			/* nGroups */,
+	unsigned int		/* groups */,
+	int *			/* newTypesIn */,
+	XkbMapChangesPtr	/* changes */
+);
+
+extern int XkbKeyTypesForCoreSymbols(
+	XkbDescPtr		/* xkb */,
+	int			/* map_width */,
+	KeySym *		/* core_syms */,
+	unsigned int		/* protected */,
+	int *			/* types_inout */,
+	KeySym *		/* xkb_syms_rtrn */
+);
+
+extern Bool XkbApplyCompatMapToKey(
+	XkbDescPtr		/* xkb */,
+	KeyCode			/* key */,
+	XkbChangesPtr		/* changes */
+);
+
+extern Bool XkbApplyVirtualModChanges(
+	XkbDescPtr		/* xkb */,
+	unsigned int		/* changed */,
+	XkbChangesPtr		/* changes */
+);
+
+extern void XkbSendNewKeyboardNotify(
+	DeviceIntPtr		/* kbd */,
+	xkbNewKeyboardNotify *	/* pNKN */
+);
+
+#ifdef XKBSRV_NEED_FILE_FUNCS
+
+#include <X11/extensions/XKMformat.h>
+#include <X11/extensions/XKBfile.h>
+#include <X11/extensions/XKBrules.h>
+
+#define	_XkbListKeymaps		0
+#define	_XkbListKeycodes	1
+#define	_XkbListTypes		2
+#define	_XkbListCompat		3
+#define	_XkbListSymbols		4
+#define	_XkbListGeometry	5
+#define	_XkbListNumComponents	6
+
+typedef struct _XkbSrvListInfo {
+	int		szPool;
+	int		nPool;
+	char *		pool;
+
+	int		maxRtrn;
+	int		nTotal;
+
+	char *		pattern[_XkbListNumComponents];
+	int		nFound[_XkbListNumComponents];
+} XkbSrvListInfoRec,*XkbSrvListInfoPtr;
+
+extern	Status	XkbDDXList(
+	DeviceIntPtr		/* dev */,
+	XkbSrvListInfoPtr	/* listing */,
+	ClientPtr		/* client */
+);
+
+extern	unsigned int XkbDDXLoadKeymapByNames(
+	DeviceIntPtr		/* keybd */,
+	XkbComponentNamesPtr	/* names */,
+	unsigned int		/* want */,
+	unsigned int		/* need */,
+	XkbFileInfoPtr		/* finfoRtrn */,
+	char *			/* keymapNameRtrn */,
+	int 			/* keymapNameRtrnLen */
+);
+
+extern	Bool XkbDDXNamesFromRules(
+	DeviceIntPtr		/* keybd */,
+	char *			/* rules */,
+	XkbRF_VarDefsPtr	/* defs */,
+	XkbComponentNamesPtr	/* names */
+);
+
+extern	Bool XkbDDXApplyConfig(
+	XPointer	/* cfg_in */,
+	XkbSrvInfoPtr	/* xkbi */
+);
+
+extern XPointer XkbDDXPreloadConfig(
+	char **			/* rulesFileRtrn */,
+	XkbRF_VarDefsPtr	/* defs */,
+	XkbComponentNamesPtr	/* names */,
+	DeviceIntPtr		/* dev */
+);
+
+extern	int _XkbStrCaseCmp(
+	char *			/* str1 */,
+	char *			/* str2 */
+);
+
+#endif /* XKBSRV_NEED_FILE_FUNCS */
+
+_XFUNCPROTOEND
+
+#define	XkbAtomGetString(d,s)	NameForAtom(s)
+
+#endif /* _XKBSRV_H_ */
diff --git a/os/utils.c b/os/utils.c
index 612c264..06c9b88 100644
--- a/os/utils.c
+++ b/os/utils.c
@@ -117,7 +117,7 @@ OR PERFORMANCE OF THIS SOFTWARE.
 #endif
 
 #ifdef XKB
-#include <X11/extensions/XKBsrv.h>
+#include <xkbsrv.h>
 #endif
 #ifdef XCSECURITY
 #include "securitysrv.h"
diff --git a/xkb/Makefile.am b/xkb/Makefile.am
index 996d527..78cdf71 100644
--- a/xkb/Makefile.am
+++ b/xkb/Makefile.am
@@ -41,7 +41,8 @@ X11_SRCS = \
         XKBGAlloc.c \
         XKBMAlloc.c
 
-XI_SRCS = xkbPrOtherEv.c
+# ends up unused...
+# XI_SRCS = xkbPrOtherEv.c
 
 libxkb_la_SOURCES = $(DDX_SRCS) $(DIX_SRCS) $(XI_SRCS) $(XKBFILE_SRCS) \
                     $(X11_SRCS)
diff --git a/xkb/XKBAlloc.c b/xkb/XKBAlloc.c
index c474733..f0a1f89 100644
--- a/xkb/XKBAlloc.c
+++ b/xkb/XKBAlloc.c
@@ -35,7 +35,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #include <X11/Xproto.h>
 #include "misc.h"
 #include "inputstr.h"
-#include <X11/extensions/XKBsrv.h>
+#include <xkbsrv.h>
 #include <X11/extensions/XKBgeom.h>
 
 /***===================================================================***/
@@ -259,7 +259,7 @@ XkbAllocControls(XkbDescPtr xkb,unsigned
 }
 
 /*ARGSUSED*/
-void
+static void
 XkbFreeControls(XkbDescPtr xkb,unsigned which,Bool freeMap)
 {
     if (freeMap && (xkb!=NULL) && (xkb->ctrls!=NULL)) {
@@ -284,7 +284,7 @@ XkbAllocIndicatorMaps(XkbDescPtr xkb)
     return Success;
 }
 
-void
+static void
 XkbFreeIndicatorMaps(XkbDescPtr xkb)
 {
     if ((xkb!=NULL)&&(xkb->indicators!=NULL)) {
@@ -335,154 +335,3 @@ XkbFreeKeyboard(XkbDescPtr xkb,unsigned 
 	_XkbFree(xkb);
     return;
 }
-
-/***====================================================================***/
-
-XkbDeviceLedInfoPtr
-XkbAddDeviceLedInfo(XkbDeviceInfoPtr devi,unsigned ledClass,unsigned ledId)
-{
-XkbDeviceLedInfoPtr	devli;
-register int		i;
-
-    if ((!devi)||(!XkbSingleXIClass(ledClass))||(!XkbSingleXIId(ledId)))
-	return NULL;
-    for (i=0,devli=devi->leds;i<devi->num_leds;i++,devli++) {
-	if ((devli->led_class==ledClass)&&(devli->led_id==ledId))
-	    return devli;
-    }
-    if (devi->num_leds>=devi->sz_leds) {
-	XkbDeviceLedInfoRec *prev_leds = devi->leds;
-	
-	if (devi->sz_leds>0)	devi->sz_leds*= 2;
-	else			devi->sz_leds= 1;
-	devi->leds= _XkbTypedRealloc(devi->leds,devi->sz_leds,
-							XkbDeviceLedInfoRec);
-	if (!devi->leds) {
-	    _XkbFree(prev_leds);
-	    devi->sz_leds= devi->num_leds= 0;
-	    return NULL;
-	}
-	i= devi->num_leds;
-	for (devli=&devi->leds[i];i<devi->sz_leds;i++,devli++) {
-	    bzero(devli,sizeof(XkbDeviceLedInfoRec));
-	    devli->led_class= XkbXINone;
-	    devli->led_id= XkbXINone;
-	}
-    }
-    devli= &devi->leds[devi->num_leds++];
-    bzero(devli,sizeof(XkbDeviceLedInfoRec));
-    devli->led_class= ledClass;
-    devli->led_id= ledId;
-    return devli;
-}
-
-Status
-XkbResizeDeviceButtonActions(XkbDeviceInfoPtr devi,unsigned newTotal)
-{
-    XkbAction *prev_btn_acts;
-
-    if ((!devi)||(newTotal>255))
-	return BadValue;
-    if ((devi->btn_acts!=NULL)&&(newTotal==devi->num_btns))
-	return Success;
-    if (newTotal==0) {
-	if (devi->btn_acts!=NULL) {
-	    _XkbFree(devi->btn_acts);
-	    devi->btn_acts= NULL;
-	}
-	devi->num_btns= 0;
-	return Success;
-    }
-    prev_btn_acts = devi->btn_acts;
-    devi->btn_acts= _XkbTypedRealloc(devi->btn_acts,newTotal,XkbAction);
-    if (devi->btn_acts==NULL) {
-	_XkbFree(prev_btn_acts);
-	devi->num_btns= 0;
-	return BadAlloc;
-    }
-    if (newTotal>devi->num_btns) {
-	XkbAction *act;
-	act= &devi->btn_acts[devi->num_btns];
-	bzero((char *)act,(newTotal-devi->num_btns)*sizeof(XkbAction));
-    }
-    devi->num_btns= newTotal;
-    return Success;
-}
-
-/*ARGSUSED*/
-XkbDeviceInfoPtr
-XkbAllocDeviceInfo(unsigned deviceSpec,unsigned nButtons,unsigned szLeds)
-{
-XkbDeviceInfoPtr	devi;
-
-    devi= _XkbTypedCalloc(1,XkbDeviceInfoRec);
-    if (devi!=NULL) {
-	devi->device_spec= deviceSpec;
-	devi->has_own_state= False;
-	devi->num_btns= 0;
-	devi->btn_acts= NULL;
-	if (nButtons>0) {
-	    devi->num_btns= nButtons;
-	    devi->btn_acts= _XkbTypedCalloc(nButtons,XkbAction);
-	    if (!devi->btn_acts) {
-		_XkbFree(devi);
-		return NULL;
-	    }
-	}
-	devi->dflt_kbd_fb= XkbXINone;
-	devi->dflt_led_fb= XkbXINone;
-	devi->num_leds= 0;
-	devi->sz_leds= 0;
-	devi->leds= NULL;
-	if (szLeds>0) {
-	    devi->sz_leds= szLeds;
-	    devi->leds= _XkbTypedCalloc(szLeds,XkbDeviceLedInfoRec);
-	    if (!devi->leds) {
-		if (devi->btn_acts)
-		    _XkbFree(devi->btn_acts);
-		_XkbFree(devi);
-		return NULL;
-	    }
-	}
-    }
-    return devi;
-}
-
-
-void 
-XkbFreeDeviceInfo(XkbDeviceInfoPtr devi,unsigned which,Bool freeDevI)
-{
-    if (devi) {
-	if (freeDevI) {
-	    which= XkbXI_AllDeviceFeaturesMask;
-	    if (devi->name) {
-		_XkbFree(devi->name);
-		devi->name= NULL;
-	    }
-	}
-	if ((which&XkbXI_ButtonActionsMask)&&(devi->btn_acts)) {
-	    _XkbFree(devi->btn_acts);
-	    devi->num_btns= 0;
-	    devi->btn_acts= NULL;
-	}
-	if ((which&XkbXI_IndicatorsMask)&&(devi->leds)) {
-	    register int i;
-	    if ((which&XkbXI_IndicatorsMask)==XkbXI_IndicatorsMask) {
-		_XkbFree(devi->leds);
-		devi->sz_leds= devi->num_leds= 0;
-		devi->leds= NULL;
-	    }
-	    else {
-		XkbDeviceLedInfoPtr	devli;
-		for (i=0,devli=devi->leds;i<devi->num_leds;i++,devli++) {
-		    if (which&XkbXI_IndicatorMapsMask)
-			 bzero((char *)&devli->maps[0],sizeof(devli->maps));
-		    else bzero((char *)&devli->names[0],sizeof(devli->names));
-		}
-	    }
-	}
-	if (freeDevI)
-	    _XkbFree(devi);
-    }
-    return;
-}
diff --git a/xkb/XKBGAlloc.c b/xkb/XKBGAlloc.c
index edaed10..815cc95 100644
--- a/xkb/XKBGAlloc.c
+++ b/xkb/XKBGAlloc.c
@@ -36,7 +36,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #include <X11/Xproto.h>
 #include "misc.h"
 #include "inputstr.h"
-#include <X11/extensions/XKBsrv.h>
+#include <xkbsrv.h>
 #include <X11/extensions/XKBgeom.h>
 
 #ifdef X_NOT_POSIX
diff --git a/xkb/XKBMAlloc.c b/xkb/XKBMAlloc.c
index ef4097d..4b7428b 100644
--- a/xkb/XKBMAlloc.c
+++ b/xkb/XKBMAlloc.c
@@ -39,7 +39,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #include "inputstr.h"
 #include <X11/keysym.h>
 #define	XKBSRV_NEED_FILE_FUNCS
-#include <X11/extensions/XKBsrv.h>
+#include <xkbsrv.h>
 
 /***====================================================================***/
 
@@ -220,7 +220,7 @@ XkbServerMapPtr map;
 
 /***====================================================================***/
 
-Status
+static Status
 XkbCopyKeyType(XkbKeyTypePtr from,XkbKeyTypePtr into)
 {
     if ((!from)||(!into))
@@ -275,82 +275,6 @@ register int i,rtrn;
     return Success;
 }
 
-XkbKeyTypePtr
-XkbAddKeyType(	XkbDescPtr	xkb,
-		Atom 		name,
-		int 		map_count,
-		Bool 		want_preserve,
-		int		num_lvls)
-{
-register int 	i;
-unsigned	tmp;
-XkbKeyTypePtr	type;
-XkbClientMapPtr	map;
-
-    if ((!xkb)||(num_lvls<1))
-	return NULL;
-    map= xkb->map;
-    if ((map)&&(map->types)) {
-	for (i=0;i<map->num_types;i++) {
-	    if (map->types[i].name==name) {
-		Status status;
-		status=XkbResizeKeyType(xkb,i,map_count,want_preserve,num_lvls);
-		return (status==Success?&map->types[i]:NULL);
-	    }
-	}
-    }
-    if ((!map)||(!map->types)||(!map->num_types<XkbNumRequiredTypes)) {
-	tmp= XkbNumRequiredTypes+1;
-	if (XkbAllocClientMap(xkb,XkbKeyTypesMask,tmp)!=Success)
-	    return NULL;
-        map = xkb->map;
-	tmp= 0;
-	if (map->num_types<=XkbKeypadIndex)
-	    tmp|= XkbKeypadMask;
-	if (map->num_types<=XkbAlphabeticIndex)
-	    tmp|= XkbAlphabeticMask;
-	if (map->num_types<=XkbTwoLevelIndex)
-	    tmp|= XkbTwoLevelMask;
-	if (map->num_types<=XkbOneLevelIndex)
-	    tmp|= XkbOneLevelMask;
-	if (XkbInitCanonicalKeyTypes(xkb,tmp,XkbNoModifier)==Success) {
-	    for (i=0;i<map->num_types;i++) {
-		Status status;
-		if (map->types[i].name!=name)
-		    continue;
-		status=XkbResizeKeyType(xkb,i,map_count,want_preserve,num_lvls);
-		return (status==Success?&map->types[i]:NULL);
-	    }
-	}
-    }
-    if ((map->num_types<=map->size_types)&&
-	(XkbAllocClientMap(xkb,XkbKeyTypesMask,map->num_types+1)!=Success)) {
-	return NULL;
-    }
-    type= &map->types[map->num_types];
-    map->num_types++;
-    bzero((char *)type,sizeof(XkbKeyTypeRec));
-    type->num_levels=	num_lvls;
-    type->map_count=	map_count;
-    type->name=		name;
-    if (map_count>0) {
-	type->map=	_XkbTypedCalloc(map_count,XkbKTMapEntryRec);
-	if (!type->map) {
-	    map->num_types--;
-	    return NULL;
-	}
-	if (want_preserve) {
-	    type->preserve=	_XkbTypedCalloc(map_count,XkbModsRec);
-	    if (!type->preserve) {
-		_XkbFree(type->map);
-		map->num_types--;
-		return NULL;
-	    }
-	}
-    }
-    return type;
-}
-
 Status
 XkbResizeKeyType(	XkbDescPtr	xkb,
 			int		type_ndx,
diff --git a/xkb/XKBMisc.c b/xkb/XKBMisc.c
index 7ed4769..0404108 100644
--- a/xkb/XKBMisc.c
+++ b/xkb/XKBMisc.c
@@ -39,102 +39,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #include "inputstr.h"
 #include <X11/keysym.h>
 #define	XKBSRV_NEED_FILE_FUNCS
-#include <X11/extensions/XKBsrv.h>
-
-/***====================================================================***/
-
-#define	mapSize(m)	(sizeof(m)/sizeof(XkbKTMapEntryRec))
-static  XkbKTMapEntryRec map2Level[]= { 
-  { True, ShiftMask, {1, ShiftMask, 0} }
-};
-
-static  XkbKTMapEntryRec mapAlpha[]= { 
-  { True, ShiftMask, { 1, ShiftMask, 0 } },
-  { True, LockMask,  { 0,  LockMask, 0 } }
-};
-
-static	XkbModsRec preAlpha[]= {
-	{        0,        0, 0 },
-	{ LockMask, LockMask, 0 }
-};
-
-#define	NL_VMOD_MASK	0
-static  XkbKTMapEntryRec mapKeypad[]= { 
-	{ True,	ShiftMask, { 1, ShiftMask,            0 } },
-	{ False,        0, { 1,         0, NL_VMOD_MASK } }
-};
-
-static	XkbKeyTypeRec	canonicalTypes[XkbNumRequiredTypes] = {
-	{ { 0, 0, 0 }, 
-	  1,	/* num_levels */
-	  0,	/* map_count */
-	  NULL,		NULL,
-	  None,		NULL
-	},
-	{ { ShiftMask, ShiftMask, 0 }, 
-	  2,	/* num_levels */
-	  mapSize(map2Level),	/* map_count */
-	  map2Level,	NULL,
-	  None,		NULL
-	},
-	{ { ShiftMask|LockMask, ShiftMask|LockMask, 0 }, 
-	  2,				/* num_levels */
-	  mapSize(mapAlpha),		/* map_count */
-	  mapAlpha,	preAlpha,
-	  None,		NULL
-	},
-	{ { ShiftMask, ShiftMask, NL_VMOD_MASK },
-	  2,				/* num_levels */
-	  mapSize(mapKeypad),		/* map_count */
-	  mapKeypad,	NULL,
-	  None,		NULL
-	}
-};
-
-Status
-XkbInitCanonicalKeyTypes(XkbDescPtr xkb,unsigned which,int keypadVMod)
-{
-XkbClientMapPtr	map;
-XkbKeyTypePtr	from,to;
-Status		rtrn;
-
-    if (!xkb)
-	return BadMatch;
-    rtrn= XkbAllocClientMap(xkb,XkbKeyTypesMask,XkbNumRequiredTypes);
-    if (rtrn!=Success)
-	return rtrn;
-    map= xkb->map;
-    if ((which&XkbAllRequiredTypes)==0)
-	return Success;
-    rtrn= Success;
-    from= canonicalTypes;
-    to= map->types;
-    if (which&XkbOneLevelMask)
-	rtrn= XkbCopyKeyType(&from[XkbOneLevelIndex],&to[XkbOneLevelIndex]);
-    if ((which&XkbTwoLevelMask)&&(rtrn==Success))
-	rtrn= XkbCopyKeyType(&from[XkbTwoLevelIndex],&to[XkbTwoLevelIndex]);
-    if ((which&XkbAlphabeticMask)&&(rtrn==Success))
-	rtrn= XkbCopyKeyType(&from[XkbAlphabeticIndex],&to[XkbAlphabeticIndex]);
-    if ((which&XkbKeypadMask)&&(rtrn==Success)) {
-	XkbKeyTypePtr type;
-	rtrn= XkbCopyKeyType(&from[XkbKeypadIndex],&to[XkbKeypadIndex]);
-	type= &to[XkbKeypadIndex];
-	if ((keypadVMod>=0)&&(keypadVMod<XkbNumVirtualMods)&&(rtrn==Success)) {
-	    type->mods.vmods= (1<<keypadVMod);
-	    type->map[0].active= True;
-	    type->map[0].mods.mask= ShiftMask;
-	    type->map[0].mods.real_mods= ShiftMask;
-	    type->map[0].mods.vmods= 0;
-	    type->map[0].level= 1;
-	    type->map[1].active= False;
-	    type->map[1].mods.mask= 0;
-	    type->map[1].mods.real_mods= 0;
-	    type->map[1].mods.vmods= (1<<keypadVMod);
-	    type->map[1].level= 1;
-	}
-    }
-    return Success;
-}
+#include <xkbsrv.h>
 
 /***====================================================================***/
 
@@ -558,88 +463,6 @@ unsigned		changed,tmp;
     return True;
 }
 
-Bool
-XkbUpdateMapFromCore(	XkbDescPtr	xkb,
-			KeyCode		first_key,
-			int		num_keys,
-			int		map_width,
-			KeySym *	core_keysyms,
-			XkbChangesPtr	changes)
-{
-register int	key,last_key;
-KeySym *	syms;
-
-    syms= &core_keysyms[(first_key-xkb->min_key_code)*map_width];
-    if (changes) {
-	if (changes->map.changed&XkbKeySymsMask) {
-	    _XkbAddKeyChange(&changes->map.first_key_sym,
-	    			&changes->map.num_key_syms,first_key);
-	    if (num_keys>1) {
-		_XkbAddKeyChange(&changes->map.first_key_sym,
-						&changes->map.num_key_syms,
-						first_key+num_keys-1);
-	    }
-	}
-	else {
-	    changes->map.changed|= XkbKeySymsMask;
-	    changes->map.first_key_sym= first_key;
-	    changes->map.num_key_syms= num_keys;
-	}
-    }
-    last_key= first_key+num_keys-1;
-    for (key=first_key;key<=last_key;key++,syms+= map_width) {
-	XkbMapChangesPtr	mc;
-	unsigned		explicit;
-	KeySym			tsyms[XkbMaxSymsPerKey];
-	int	 		types[XkbNumKbdGroups];
-	int			nG;
-
-	explicit= xkb->server->explicit[key]&XkbExplicitKeyTypesMask;
-	types[XkbGroup1Index]= XkbKeyKeyTypeIndex(xkb,key,XkbGroup1Index);
-	types[XkbGroup2Index]= XkbKeyKeyTypeIndex(xkb,key,XkbGroup2Index);
-	types[XkbGroup3Index]= XkbKeyKeyTypeIndex(xkb,key,XkbGroup3Index);
-	types[XkbGroup4Index]= XkbKeyKeyTypeIndex(xkb,key,XkbGroup4Index);
-	nG= XkbKeyTypesForCoreSymbols(xkb,map_width,syms,explicit,types,tsyms);
-	if (changes)
-	     mc= &changes->map;
-	else mc= NULL;
-	XkbChangeTypesOfKey(xkb,key,nG,XkbAllGroupsMask,types,mc);
-	memcpy((char *)XkbKeySymsPtr(xkb,key),(char *)tsyms,
-					XkbKeyNumSyms(xkb,key)*sizeof(KeySym));
-	XkbApplyCompatMapToKey(xkb,key,changes);
-    }
-
-    if ((xkb->server->vmods!=NULL)&&(xkb->map->modmap!=NULL)&&(changes)&&
-	(changes->map.changed&(XkbVirtualModMapMask|XkbModifierMapMask))) {
-	unsigned char		newVMods[XkbNumVirtualMods];
-	register  unsigned 	bit,i;
-	unsigned		present;
-
-	bzero(newVMods,XkbNumVirtualMods);
-	present= 0;
-	for (key=xkb->min_key_code;key<=xkb->max_key_code;key++) {
-	    if (xkb->server->vmodmap[key]==0)
-		continue;
-	    for (i=0,bit=1;i<XkbNumVirtualMods;i++,bit<<=1) {
-		if (bit&xkb->server->vmodmap[key]) {
-		    present|= bit;
-		    newVMods[i]|= xkb->map->modmap[key];
-		}
-	    }
-	}
-	for (i=0,bit=1;i<XkbNumVirtualMods;i++,bit<<=1) {
-	    if ((bit&present)&&(newVMods[i]!=xkb->server->vmods[i])) {
-		changes->map.changed|= XkbVirtualModsMask;
-		changes->map.vmods|= bit;
-		xkb->server->vmods[i]= newVMods[i];
-	    }
-	}
-    }
-    if (changes && (changes->map.changed&XkbVirtualModsMask))
-	XkbApplyVirtualModChanges(xkb,changes->map.vmods,changes);
-    return True;
-}
-
 Status
 XkbChangeTypesOfKey(	XkbDescPtr		 xkb,
 			int		 	 key,
@@ -788,7 +611,7 @@ register unsigned mask;
 
 /***====================================================================***/
 
-Bool
+static Bool
 XkbUpdateActionVirtualMods(XkbDescPtr xkb,XkbAction *act,unsigned changed)
 {
 unsigned int	tmp;
@@ -814,7 +637,7 @@ unsigned int	tmp;
     return False;
 }
 
-void
+static void
 XkbUpdateKeyTypeVirtualMods(	XkbDescPtr	xkb,
 				XkbKeyTypePtr	type,
 				unsigned int	changed,
diff --git a/xkb/ddxBeep.c b/xkb/ddxBeep.c
index 53f3a6f..331357d 100644
--- a/xkb/ddxBeep.c
+++ b/xkb/ddxBeep.c
@@ -36,7 +36,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #include "inputstr.h"
 #include "scrnintstr.h"
 #include "windowstr.h"
-#include <X11/extensions/XKBsrv.h>
+#include <xkbsrv.h>
 #include <X11/extensions/XI.h>
 
 /*#define FALLING_TONE	1*/
diff --git a/xkb/ddxCtrls.c b/xkb/ddxCtrls.c
index 5a9ad40..0f7f918 100644
--- a/xkb/ddxCtrls.c
+++ b/xkb/ddxCtrls.c
@@ -36,7 +36,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #include "inputstr.h"
 #include "scrnintstr.h"
 #include "windowstr.h"
-#include <X11/extensions/XKBsrv.h>
+#include <xkbsrv.h>
 #include <X11/extensions/XI.h>
 
 void
diff --git a/xkb/ddxDevBtn.c b/xkb/ddxDevBtn.c
index 3de8f87..7e27c51 100644
--- a/xkb/ddxDevBtn.c
+++ b/xkb/ddxDevBtn.c
@@ -36,7 +36,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #include "inputstr.h"
 #include "scrnintstr.h"
 #include "windowstr.h"
-#include <X11/extensions/XKBsrv.h>
+#include <xkbsrv.h>
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>
 
diff --git a/xkb/ddxFakeBtn.c b/xkb/ddxFakeBtn.c
index f7b746b..7722223 100644
--- a/xkb/ddxFakeBtn.c
+++ b/xkb/ddxFakeBtn.c
@@ -37,7 +37,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #include "inputstr.h"
 #include "scrnintstr.h"
 #include "windowstr.h"
-#include <X11/extensions/XKBsrv.h>
+#include <xkbsrv.h>
 #include <X11/extensions/XI.h>
 
 void
diff --git a/xkb/ddxFakeMtn.c b/xkb/ddxFakeMtn.c
index a19819f..1060afe 100644
--- a/xkb/ddxFakeMtn.c
+++ b/xkb/ddxFakeMtn.c
@@ -36,7 +36,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #include "inputstr.h"
 #include "scrnintstr.h"
 #include "windowstr.h"
-#include <X11/extensions/XKBsrv.h>
+#include <xkbsrv.h>
 #include <X11/extensions/XI.h>
 
 #ifdef PANORAMIX
diff --git a/xkb/ddxInit.c b/xkb/ddxInit.c
index 88c488c..3bcf9d6 100644
--- a/xkb/ddxInit.c
+++ b/xkb/ddxInit.c
@@ -37,7 +37,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #include "inputstr.h"
 #include "scrnintstr.h"
 #include "windowstr.h"
-#include <X11/extensions/XKBsrv.h>
+#include <xkbsrv.h>
 #include <X11/extensions/XI.h>
 
 int
diff --git a/xkb/ddxKeyClick.c b/xkb/ddxKeyClick.c
index 528b202..685ae1b 100644
--- a/xkb/ddxKeyClick.c
+++ b/xkb/ddxKeyClick.c
@@ -37,7 +37,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #include "inputstr.h"
 #include "scrnintstr.h"
 #include "windowstr.h"
-#include <X11/extensions/XKBsrv.h>
+#include <xkbsrv.h>
 #include <X11/extensions/XI.h>
 
 void
diff --git a/xkb/ddxKillSrv.c b/xkb/ddxKillSrv.c
index 95d7589..a573ecb 100644
--- a/xkb/ddxKillSrv.c
+++ b/xkb/ddxKillSrv.c
@@ -36,7 +36,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #include "inputstr.h"
 #include "scrnintstr.h"
 #include "windowstr.h"
-#include <X11/extensions/XKBsrv.h>
+#include <xkbsrv.h>
 
 int
 XkbDDXTerminateServer(DeviceIntPtr dev,KeyCode key,XkbAction *act)
diff --git a/xkb/ddxLEDs.c b/xkb/ddxLEDs.c
index fd01958..22899d7 100644
--- a/xkb/ddxLEDs.c
+++ b/xkb/ddxLEDs.c
@@ -37,10 +37,10 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #include "inputstr.h"
 #include "scrnintstr.h"
 #include "windowstr.h"
-#include <X11/extensions/XKBsrv.h>
+#include <xkbsrv.h>
 #include <X11/extensions/XI.h>
 
-void
+static void
 XkbDDXUpdateIndicators(DeviceIntPtr dev,CARD32 new)
 {
     dev->kbdfeed->ctrl.leds= new;
diff --git a/xkb/ddxList.c b/xkb/ddxList.c
index 034f694..a91a9ba 100644
--- a/xkb/ddxList.c
+++ b/xkb/ddxList.c
@@ -40,7 +40,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #include "scrnintstr.h"
 #include "windowstr.h"
 #define	XKBSRV_NEED_FILE_FUNCS
-#include <X11/extensions/XKBsrv.h>
+#include <xkbsrv.h>
 #include <X11/extensions/XI.h>
 
 #ifndef PATH_MAX
diff --git a/xkb/ddxLoad.c b/xkb/ddxLoad.c
index 6e8f892..c24c56c 100644
--- a/xkb/ddxLoad.c
+++ b/xkb/ddxLoad.c
@@ -44,7 +44,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #include "scrnintstr.h"
 #include "windowstr.h"
 #define	XKBSRV_NEED_FILE_FUNCS
-#include <X11/extensions/XKBsrv.h>
+#include <xkbsrv.h>
 #include <X11/extensions/XI.h>
 #include "xkb.h"
 
@@ -211,7 +211,7 @@ OutputDirectory(
     }
 }
 
-Bool
+static Bool
 XkbDDXCompileNamedKeymap(	XkbDescPtr		xkb,
 				XkbComponentNamesPtr	names,
 				char *			nameRtrn,
@@ -298,7 +298,7 @@ char 	*cmd = NULL,file[PATH_MAX],xkm_out
     return False;
 }
 
-Bool    	
+static Bool    	
 XkbDDXCompileKeymapByNames(	XkbDescPtr		xkb,
 				XkbComponentNamesPtr	names,
 				unsigned		want,
@@ -432,7 +432,7 @@ char tmpname[PATH_MAX];
     return False;
 }
 
-FILE *
+static FILE *
 XkbDDXOpenConfigFile(char *mapName,char *fileNameRtrn,int fileNameRtrnLen)
 {
 char	buf[PATH_MAX],xkm_output_dir[PATH_MAX];
diff --git a/xkb/ddxPrivate.c b/xkb/ddxPrivate.c
index 7450b47..f67e20c 100644
--- a/xkb/ddxPrivate.c
+++ b/xkb/ddxPrivate.c
@@ -6,7 +6,7 @@
 #define NEED_EVENTS
 #include <X11/X.h>
 #include "windowstr.h"
-#include <X11/extensions/XKBsrv.h>
+#include <xkbsrv.h>
 
 int
 XkbDDXPrivate(DeviceIntPtr dev,KeyCode key,XkbAction *act)
diff --git a/xkb/ddxVT.c b/xkb/ddxVT.c
index f56f079..55c82a8 100644
--- a/xkb/ddxVT.c
+++ b/xkb/ddxVT.c
@@ -36,7 +36,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #include "inputstr.h"
 #include "scrnintstr.h"
 #include "windowstr.h"
-#include <X11/extensions/XKBsrv.h>
+#include <xkbsrv.h>
 
 int
 XkbDDXSwitchScreen(DeviceIntPtr dev,KeyCode key,XkbAction *act)
diff --git a/xkb/maprules.c b/xkb/maprules.c
index b0a2225..0fa356e 100644
--- a/xkb/maprules.c
+++ b/xkb/maprules.c
@@ -48,7 +48,7 @@
 #include "dix.h"
 #include <X11/extensions/XKBstr.h>
 #define XKBSRV_NEED_FILE_FUNCS
-#include <X11/extensions/XKBsrv.h>
+#include <xkbsrv.h>
 
 #ifdef DEBUG
 #define PR_DEBUG(s)		fprintf(stderr,s)
diff --git a/xkb/xkb.c b/xkb/xkb.c
index 2c97e05..cf42430 100644
--- a/xkb/xkb.c
+++ b/xkb/xkb.c
@@ -36,23 +36,20 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #include "misc.h"
 #include "inputstr.h"
 #define	XKBSRV_NEED_FILE_FUNCS
-#include <X11/extensions/XKBsrv.h>
+#include <xkbsrv.h>
 #include "extnsionst.h"
 #include "xkb.h"
 
 #include <X11/extensions/XI.h>
 
 	int	XkbEventBase;
-	int	XkbErrorBase;
+static	int	XkbErrorBase;
 	int	XkbReqCode;
-	int	XkbKeyboardErrorCode;
-Atom	xkbONE_LEVEL;
-Atom	xkbTWO_LEVEL;
-Atom	xkbKEYPAD;
+static  int	XkbKeyboardErrorCode;
 CARD32	xkbDebugFlags = 0;
-CARD32	xkbDebugCtrls = 0;
+static CARD32	xkbDebugCtrls = 0;
 
-RESTYPE	RT_XKBCLIENT;
+static RESTYPE	RT_XKBCLIENT;
 
 /***====================================================================***/
 
@@ -895,52 +892,6 @@ ProcXkbSetControls(ClientPtr client)
     return client->noClientException;
 }
 
-/* FIXME: Needs to set rate on all core-sending devices. */
-int
-XkbSetRepeatRate(DeviceIntPtr dev,int timeout,int interval,int major,int minor)
-{
-int	changed= 0;
-XkbControlsRec old,*xkb;
-
-    if ((!dev)||(!dev->key)||(!dev->key->xkbInfo))
-	return 0;
-    xkb= dev->key->xkbInfo->desc->ctrls;
-    old= *xkb;
-    if ((timeout!=0) && (xkb->repeat_delay!=timeout)) {
-	xkb->repeat_delay= timeout;
-	changed++;
-    }
-    if ((interval!=0) && (xkb->repeat_interval!=interval)) {
-	xkb->repeat_interval= interval;
-	changed++;
-    }
-    if (changed) {
-	xkbControlsNotify	cn;
-	XkbDDXChangeControls(dev,&old,xkb);
-	if (XkbComputeControlsNotify(dev,&old,xkb,&cn,False)) {
-	    cn.keycode= 0;
-	    cn.eventType = 0;
-	    cn.requestMajor = major;
-	    cn.requestMinor = minor;
-	    XkbSendControlsNotify(dev,&cn);
-	}
-    }
-    return 1;
-}
-
-int
-XkbGetRepeatRate(DeviceIntPtr dev,int *timeout,int *interval)
-{
-XkbControlsPtr	xkb;
-
-    if ((!dev)||(!dev->key)||(!dev->key->xkbInfo))
-	return 0;
-    xkb= dev->key->xkbInfo->desc->ctrls;
-    if (timeout)	*timeout= xkb->repeat_delay;
-    if (interval)	*interval= xkb->repeat_interval;
-    return 1;
-}
-
 /***====================================================================***/
 
 static int
@@ -2820,7 +2771,7 @@ ProcXkbGetIndicatorState(ClientPtr clien
 
 /***====================================================================***/
 
-Status
+static Status
 XkbComputeGetIndicatorMapReplySize(
     XkbIndicatorPtr		indicators,
     xkbGetIndicatorMapReply	*rep)
@@ -2837,7 +2788,7 @@ int		nIndicators;
     return Success;
 }
 
-int
+static int
 XkbSendIndicatorMap(	ClientPtr			client,
 			XkbIndicatorPtr			indicators,
 			xkbGetIndicatorMapReply *	rep)
diff --git a/xkb/xkb.h b/xkb/xkb.h
index 2be4258..99b60bf 100644
--- a/xkb/xkb.h
+++ b/xkb/xkb.h
@@ -1,5 +1,3 @@
-/* $XFree86$ */
-
 /* #include "XKBfile.h" */
 
 extern int ProcXkbUseExtension(ClientPtr client);
@@ -29,50 +27,10 @@ extern int ProcXkbGetDeviceInfo(ClientPt
 extern int ProcXkbSetDeviceInfo(ClientPtr client);
 extern int ProcXkbSetDebuggingFlags(ClientPtr client);
 
-extern int XkbSetRepeatRate(DeviceIntPtr dev, int timeout, int interval, int major, int minor);
-extern int XkbGetRepeatRate(DeviceIntPtr dev, int *timeout, int *interval);
-
 extern void XkbExtensionInit(void);
 
-extern Status XkbComputeGetIndicatorMapReplySize(
-    XkbIndicatorPtr             indicators,
-    xkbGetIndicatorMapReply     *rep);
-extern int XkbSendIndicatorMap(
-    ClientPtr                   client,
-    XkbIndicatorPtr             indicators,
-    xkbGetIndicatorMapReply     *rep);
-
-extern void XkbComputeCompatState(XkbSrvInfoPtr xkbi);
-extern void XkbSetPhysicalLockingKey(DeviceIntPtr dev, unsigned key);
-
 extern Bool XkbFilterEvents(ClientPtr pClient, int nEvents, xEvent *xE);
 
-extern Bool XkbApplyLEDChangeToKeyboard(
-    XkbSrvInfoPtr           xkbi,
-    XkbIndicatorMapPtr      map,
-    Bool                    on,
-    XkbChangesPtr           change);
-
-extern Bool XkbWriteRulesProp(ClientPtr client, pointer closure);
-
-extern XkbAction XkbGetButtonAction(DeviceIntPtr kbd, DeviceIntPtr dev, int button);
-
-/* extern Status XkbMergeFile(XkbDescPtr xkb, XkbFileInfo finfo); */
-
-extern Bool XkbDDXCompileNamedKeymap(
-    XkbDescPtr              xkb,
-    XkbComponentNamesPtr    names,
-    char *                  nameRtrn,
-    int                     nameRtrnLen);
-
-extern Bool XkbDDXCompileKeymapByNames(
-    XkbDescPtr              xkb,
-    XkbComponentNamesPtr    names,
-    unsigned                want,
-    unsigned                need,
-    char *                  nameRtrn,
-    int                     nameRtrnLen);
-
 extern Bool XkbCopyKeymap(
     XkbDescPtr              src,
     XkbDescPtr              dst,
diff --git a/xkb/xkbAccessX.c b/xkb/xkbAccessX.c
index 0ab3dad..2954a0c 100644
--- a/xkb/xkbAccessX.c
+++ b/xkb/xkbAccessX.c
@@ -38,7 +38,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #include <X11/Xproto.h>
 #include <X11/keysym.h>
 #include "inputstr.h"
-#include <X11/extensions/XKBsrv.h>
+#include <xkbsrv.h>
 #if !defined(WIN32) && !defined(Lynx)
 #include <sys/time.h>
 #endif
@@ -52,9 +52,9 @@ pointer	XkbLastRepeatEvent=	NULL;
 
 unsigned short	XkbDfltAccessXTimeout= 	120;
 unsigned int	XkbDfltAccessXTimeoutMask= DFLT_TIMEOUT_CTRLS;
-unsigned int	XkbDfltAccessXTimeoutValues= 0;
-unsigned int	XkbDfltAccessXTimeoutOptionsMask= DFLT_TIMEOUT_OPTS;
-unsigned int	XkbDfltAccessXTimeoutOptionsValues= 0;
+static unsigned int XkbDfltAccessXTimeoutValues= 0;
+static unsigned int XkbDfltAccessXTimeoutOptionsMask= DFLT_TIMEOUT_OPTS;
+static unsigned int XkbDfltAccessXTimeoutOptionsValues= 0;
 unsigned int	XkbDfltAccessXFeedback= XkbAccessXFeedbackMask;
 unsigned short	XkbDfltAccessXOptions=  XkbAX_AllOptionsMask & ~(XkbAX_IndicatorFBMask|XkbAX_SKReleaseFBMask|XkbAX_SKRejectFBMask);
 
diff --git a/xkb/xkbActions.c b/xkb/xkbActions.c
index e0bf89c..2e0c89f 100644
--- a/xkb/xkbActions.c
+++ b/xkb/xkbActions.c
@@ -36,14 +36,14 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #include <X11/keysym.h>
 #include "misc.h"
 #include "inputstr.h"
-#include <X11/extensions/XKBsrv.h>
+#include <xkbsrv.h>
 #include "xkb.h"
 #include <ctype.h>
 
 static unsigned int _xkbServerGeneration;
-int xkbDevicePrivateIndex = -1;
+static int xkbDevicePrivateIndex = -1;
 
-void
+static void
 xkbUnwrapProc(DeviceIntPtr device, DeviceHandleProc proc,
                    pointer data)
 {
@@ -216,7 +216,7 @@ static XkbAction 	fake;
     return fake;
 }
 
-XkbAction
+static XkbAction
 XkbGetButtonAction(DeviceIntPtr kbd,DeviceIntPtr dev,int button)
 {
 XkbAction fake;
diff --git a/xkb/xkbDflts.h b/xkb/xkbDflts.h
index e31568a..5d86906 100644
--- a/xkb/xkbDflts.h
+++ b/xkb/xkbDflts.h
@@ -456,43 +456,6 @@ static XkbCompatMapRec compatMap= {
     num_dfltSI, num_dfltSI
 };
 
-static XkbIndicatorRec indicators= {
-    0x0,
-    {
-        { 0x80, 0, 0x00, XkbIM_UseEffective, { LockMask,  LockMask, 0 }, 0 },
-        { 0x80, 0, 0x00, XkbIM_UseEffective, { 0,  0, vmod_NumLockMask }, 0 },
-        { 0x80, 0, 0x00, XkbIM_UseLocked, { ShiftMask,  ShiftMask, 0 }, 0 },
-        { 0x80, 0, 0x00, 0, { 0,  0, 0 }, XkbMouseKeysMask },
-        { 0x80, 0, 0x00, XkbIM_UseLocked, { 0,  0, vmod_ScrollLockMask }, 0 },
-        { 0x80, XkbIM_UseEffective, 0xfe, 0, { 0,  0, 0 }, 0 },
-        { 0x00, 0, 0x00, 0, { 0,  0, 0 }, 0 },
-        { 0x00, 0, 0x00, 0, { 0,  0, 0 }, 0 },
-        { 0x00, 0, 0x00, 0, { 0,  0, 0 }, 0 },
-        { 0x00, 0, 0x00, 0, { 0,  0, 0 }, 0 },
-        { 0x00, 0, 0x00, 0, { 0,  0, 0 }, 0 },
-        { 0x00, 0, 0x00, 0, { 0,  0, 0 }, 0 },
-        { 0x00, 0, 0x00, 0, { 0,  0, 0 }, 0 },
-        { 0x00, 0, 0x00, 0, { 0,  0, 0 }, 0 },
-        { 0x00, 0, 0x00, 0, { 0,  0, 0 }, 0 },
-        { 0x00, 0, 0x00, 0, { 0,  0, 0 }, 0 },
-        { 0x00, 0, 0x00, 0, { 0,  0, 0 }, 0 },
-        { 0x00, 0, 0x00, 0, { 0,  0, 0 }, 0 },
-        { 0x00, 0, 0x00, 0, { 0,  0, 0 }, 0 },
-        { 0x00, 0, 0x00, 0, { 0,  0, 0 }, 0 },
-        { 0x00, 0, 0x00, 0, { 0,  0, 0 }, 0 },
-        { 0x00, 0, 0x00, 0, { 0,  0, 0 }, 0 },
-        { 0x00, 0, 0x00, 0, { 0,  0, 0 }, 0 },
-        { 0x00, 0, 0x00, 0, { 0,  0, 0 }, 0 },
-        { 0x00, 0, 0x00, 0, { 0,  0, 0 }, 0 },
-        { 0x00, 0, 0x00, 0, { 0,  0, 0 }, 0 },
-        { 0x00, 0, 0x00, 0, { 0,  0, 0 }, 0 },
-        { 0x00, 0, 0x00, 0, { 0,  0, 0 }, 0 },
-        { 0x00, 0, 0x00, 0, { 0,  0, 0 }, 0 },
-        { 0x00, 0, 0x00, 0, { 0,  0, 0 }, 0 },
-        { 0x00, 0, 0x00, 0, { 0,  0, 0 }, 0 },
-        { 0x00, 0, 0x00, 0, { 0,  0, 0 }, 0 }
-    }
-};
 static void
 initIndicatorNames(DPYTYPE dpy,XkbDescPtr xkb)
 {
diff --git a/xkb/xkbEvents.c b/xkb/xkbEvents.c
index 139221f..11dc17a 100644
--- a/xkb/xkbEvents.c
+++ b/xkb/xkbEvents.c
@@ -36,7 +36,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #include <X11/extensions/XI.h>
 #include "inputstr.h"
 #include "windowstr.h"
-#include <X11/extensions/XKBsrv.h>
+#include <xkbsrv.h>
 #include "xkb.h"
 
 /***====================================================================***/
@@ -331,7 +331,7 @@ Time 		 	time = 0;
     return;
 }
 
-void
+static void
 XkbSendIndicatorNotify(DeviceIntPtr kbd,int xkbType,xkbIndicatorNotify *pEv)
 {
 int		initialized;
@@ -972,48 +972,6 @@ XkbInterestPtr	interest;
 }
 
 int
-XkbRemoveClient(DevicePtr inDev,ClientPtr client)
-{
-XkbSrvInfoPtr	xkbi;
-DeviceIntPtr	dev = (DeviceIntPtr)inDev;
-XkbInterestPtr	interest;
-unsigned long	autoCtrls,autoValues;
-Bool		found;
-
-    found= False;
-    autoCtrls= autoValues= 0;
-    if ( dev->xkb_interest ) {
-	interest = dev->xkb_interest;
-	if (interest && (interest->client==client)){
-	    dev->xkb_interest = interest->next;
-	    autoCtrls= interest->autoCtrls;
-	    autoValues= interest->autoCtrlValues;
-	    _XkbFree(interest);
-	    found= True;
-	}
-	while ((!found)&&(interest->next)) {
-	    if (interest->next->client==client) {
-		XkbInterestPtr	victim = interest->next;
-		interest->next = victim->next;
-		autoCtrls= victim->autoCtrls;
-		autoValues= victim->autoCtrlValues;
-		_XkbFree(victim);
-		found= True;
-	    }
-	    interest = interest->next;
-	}
-    }
-    if (found && autoCtrls && dev->key && dev->key->xkbInfo ) {
-	XkbEventCauseRec cause;
-
-	xkbi= dev->key->xkbInfo;
-	XkbSetCauseXkbReq(&cause,X_kbPerClientFlags,client);
-	XkbEnableDisableControls(xkbi,autoCtrls,autoValues,NULL,&cause);
-    }
-    return found;
-}
-
-int
 XkbRemoveResourceClient(DevicePtr inDev,XID id) 
 {
 XkbSrvInfoPtr	xkbi;
diff --git a/xkb/xkbInit.c b/xkb/xkbInit.c
index 5aa121d..716bc26 100644
--- a/xkb/xkbInit.c
+++ b/xkb/xkbInit.c
@@ -47,7 +47,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #include "opaque.h"
 #include "property.h"
 #define	XKBSRV_NEED_FILE_FUNCS
-#include <X11/extensions/XKBsrv.h>
+#include <xkbsrv.h>
 #include <X11/extensions/XKBgeom.h>
 #include <X11/extensions/XKMformat.h>
 #include <X11/extensions/XKBfile.h>
@@ -124,7 +124,7 @@ typedef struct	_SrvXkmInfo {
 
 char	*		XkbBaseDirectory=	XKB_BASE_DIRECTORY;
 char	*		XkbBinDirectory=	XKB_BIN_DIRECTORY;
-int	 		XkbWantAccessX=		0;	
+static int	 	XkbWantAccessX=		0;	
 static XkbFileInfo *	_XkbInitFileInfo=	NULL;
 
 static Bool		rulesDefined=		False;
@@ -134,20 +134,17 @@ static char *		XkbLayoutDflt=		NULL;
 static char *		XkbVariantDflt=		NULL;
 static char *		XkbOptionsDflt=		NULL;
 
-char *			XkbModelUsed=	NULL;
-char *			XkbLayoutUsed=	NULL;
-char *			XkbVariantUsed=	NULL;
-char *			XkbOptionsUsed=	NULL;
-
-int			_XkbClientMajor=	XkbMajorVersion;
-int			_XkbClientMinor=	XkbMinorVersion;
+static char *		XkbModelUsed=	NULL;
+static char *		XkbLayoutUsed=	NULL;
+static char *		XkbVariantUsed=	NULL;
+static char *		XkbOptionsUsed=	NULL;
 
 _X_EXPORT Bool		noXkbExtension=		XKB_DFLT_DISABLED;
-Bool			XkbWantRulesProp=	XKB_DFLT_RULES_PROP;
+static Bool		XkbWantRulesProp=	XKB_DFLT_RULES_PROP;
 
 /***====================================================================***/
 
-char *
+static char *
 XkbGetRulesDflts(XkbRF_VarDefsPtr defs)
 {
     if (XkbModelDflt)	defs->model= XkbModelDflt;
@@ -161,7 +158,7 @@ XkbGetRulesDflts(XkbRF_VarDefsPtr defs)
     return (rulesDefined?XkbRulesFile:XKB_DFLT_RULES_FILE);
 }
 
-Bool
+static Bool
 XkbWriteRulesProp(ClientPtr client, pointer closure)
 {
 int 			len,out;
@@ -230,7 +227,7 @@ char *			pval;
     return True;
 }
 
-void
+static void
 XkbSetRulesUsed(XkbRF_VarDefsPtr defs)
 {
     if (XkbModelUsed)
@@ -289,9 +286,6 @@ XkbSetRulesDflts(char *rulesFile,char *m
 
 #include "xkbDflts.h"
 
-/* A dummy to keep the compiler quiet */
-pointer xkbBogus = &indicators;
-
 static Bool
 XkbInitKeyTypes(XkbDescPtr xkb,SrvXkmInfo *file)
 {
diff --git a/xkb/xkbLEDs.c b/xkb/xkbLEDs.c
index e94e0bf..d607d90 100644
--- a/xkb/xkbLEDs.c
+++ b/xkb/xkbLEDs.c
@@ -38,7 +38,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #include "inputstr.h"
 
 #include <X11/extensions/XI.h>
-#include <X11/extensions/XKBsrv.h>
+#include <xkbsrv.h>
 #include "xkb.h"
 
 /***====================================================================***/
@@ -82,7 +82,7 @@ XkbSrvLedInfoPtr	sli;
 
 	/*
 	 * Bool
-	 * XkbApplyLEDChangeToKeyboard(xkbi,map,on,change)
+	 *XkbApplyLEDChangeToKeyboard(xkbi,map,on,change)
 	 *
 	 * Some indicators "drive" the keyboard when their state is explicitly 
 	 * changed, as described in section 9.2.1 of the XKB protocol spec.
@@ -91,7 +91,7 @@ XkbSrvLedInfoPtr	sli;
 	 * when the indicator described by 'map' is turned on or off.  The
 	 * extent of the changes is reported in change, which must be defined.
 	 */
-Bool
+static Bool
 XkbApplyLEDChangeToKeyboard(	XkbSrvInfoPtr		xkbi,
 				XkbIndicatorMapPtr	map,
 				Bool			on,
@@ -166,6 +166,164 @@ XkbStatePtr	state;
     }
     return (stateChange || ctrlChange);
 }
+	
+	/*
+	 * Bool
+	 * ComputeAutoState(map,state,ctrls)
+	 *
+	 * This function reports the effect of applying the specified
+	 * indicator map given the specified state and controls, as
+	 * described in section 9.2 of the XKB protocol specification.
+	 */
+
+static Bool
+ComputeAutoState(	XkbIndicatorMapPtr	map,
+			XkbStatePtr 		state,
+			XkbControlsPtr 		ctrls)
+{
+Bool 			on;
+CARD8 			mods,group;
+
+    on= False;
+    mods= group= 0;
+    if (map->which_mods&XkbIM_UseAnyMods) {
+	if (map->which_mods&XkbIM_UseBase)
+	    mods|= state->base_mods;
+	if (map->which_mods&XkbIM_UseLatched)
+	    mods|= state->latched_mods;
+	if (map->which_mods&XkbIM_UseLocked)
+	    mods|= state->locked_mods;
+	if (map->which_mods&XkbIM_UseEffective)
+	    mods|= state->mods;
+	if (map->which_mods&XkbIM_UseCompat)
+	    mods|= state->compat_state;
+	on = ((map->mods.mask&mods)!=0);
+	on = on||((mods==0)&&(map->mods.mask==0)&&(map->mods.vmods==0));
+    }
+    if (map->which_groups&XkbIM_UseAnyGroup) {
+	if (map->which_groups&XkbIM_UseBase)
+	    group|= (1L << state->base_group);
+	if (map->which_groups&XkbIM_UseLatched)
+	    group|= (1L << state->latched_group);
+	if (map->which_groups&XkbIM_UseLocked)
+	    group|= (1L << state->locked_group);
+	if (map->which_groups&XkbIM_UseEffective)
+	    group|= (1L << state->group);
+	on = on||(((map->groups&group)!=0)||(map->groups==0));
+    }
+    if (map->ctrls)
+	on = on||(ctrls->enabled_ctrls&map->ctrls);
+    return on;
+}
+
+
+static void
+XkbUpdateLedAutoState(	DeviceIntPtr			dev,
+			XkbSrvLedInfoPtr		sli,
+			unsigned			maps_to_check,
+			xkbExtensionDeviceNotify *	ed,
+			XkbChangesPtr			changes,
+			XkbEventCausePtr		cause)
+{
+DeviceIntPtr			kbd;
+XkbStatePtr			state;
+XkbControlsPtr			ctrls;
+XkbChangesRec			my_changes;
+xkbExtensionDeviceNotify	my_ed;
+register unsigned		i,bit,affected;
+register XkbIndicatorMapPtr	map;
+unsigned			oldState;
+
+    if ((maps_to_check==0)||(sli->maps==NULL)||(sli->mapsPresent==0))
+	return;
+
+    if (dev->key && dev->key->xkbInfo)
+	 kbd= dev;
+    else kbd= (DeviceIntPtr)LookupKeyboardDevice();
+
+    state= &kbd->key->xkbInfo->state;
+    ctrls= kbd->key->xkbInfo->desc->ctrls;
+    affected= maps_to_check;
+    oldState= sli->effectiveState;
+    sli->autoState&= ~affected;
+    for (i=0,bit=1;(i<XkbNumIndicators)&&(affected);i++,bit<<=1) {
+	if ((affected&bit)==0)
+	    continue;
+	affected&= ~bit;
+	map= &sli->maps[i];
+	if((!(map->flags&XkbIM_NoAutomatic))&&ComputeAutoState(map,state,ctrls))
+	    sli->autoState|= bit;
+    }
+    sli->effectiveState= (sli->autoState|sli->explicitState);
+    affected= sli->effectiveState^oldState;
+    if (affected==0)
+	return;
+
+    if (ed==NULL) {
+	ed= &my_ed;
+	bzero((char *)ed,sizeof(xkbExtensionDeviceNotify));
+    }
+    else if ((ed->reason&XkbXI_IndicatorsMask)&&
+	     ((ed->ledClass!=sli->class)||(ed->ledID!=sli->id))) {
+	XkbFlushLedEvents(dev,kbd,sli,ed,changes,cause);
+    }
+
+    if ((kbd==dev)&&(sli->flags&XkbSLI_IsDefault)) {
+	if (changes==NULL) {
+	    changes= &my_changes;
+	    bzero((char *)changes,sizeof(XkbChangesRec));
+	}
+	changes->indicators.state_changes|= affected;
+    }
+
+    ed->reason|=	XkbXI_IndicatorStateMask;
+    ed->ledClass= 	sli->class;
+    ed->ledID=		sli->id;
+    ed->ledsDefined=	sli->namesPresent|sli->mapsPresent;
+    ed->ledState=	sli->effectiveState;
+    ed->unsupported|=	XkbXI_IndicatorStateMask;
+    ed->supported=	XkbXI_AllFeaturesMask;
+
+    if (changes!=&my_changes)	changes= NULL;
+    if (ed!=&my_ed)		ed= NULL;
+    if (changes || ed)
+	XkbFlushLedEvents(dev,kbd,sli,ed,changes,cause);
+    return;
+}
+
+static void
+XkbUpdateAllDeviceIndicators(XkbChangesPtr changes,XkbEventCausePtr cause)
+{
+DeviceIntPtr		edev;
+XkbSrvLedInfoPtr	sli;
+
+    for (edev=inputInfo.devices;edev!=NULL;edev=edev->next) {
+	if (edev->kbdfeed) {
+	    KbdFeedbackPtr	kf;
+	    for (kf=edev->kbdfeed;kf!=NULL;kf=kf->next) {
+		if ((kf->xkb_sli==NULL)||(kf->xkb_sli->maps==NULL))
+		    continue;
+		sli= kf->xkb_sli;
+		XkbUpdateLedAutoState(edev,sli,sli->mapsPresent,NULL,
+								changes,cause);
+			
+	    }
+	}
+	if (edev->leds) {
+	    LedFeedbackPtr	lf;
+	    for (lf=edev->leds;lf!=NULL;lf=lf->next) {
+		if ((lf->xkb_sli==NULL)||(lf->xkb_sli->maps==NULL))
+		    continue;
+		sli= lf->xkb_sli;
+		XkbUpdateLedAutoState(edev,sli,sli->mapsPresent,NULL,
+								changes,cause);
+			
+	    }
+	}
+    }
+    return;
+}
+
 
 /***====================================================================***/
 
@@ -228,55 +386,6 @@ unsigned 			side_affected;
 
 /***====================================================================***/
 
-	/*
-	 * Bool
-	 * ComputeAutoState(map,state,ctrls)
-	 *
-	 * This function reports the effect of applying the specified
-	 * indicator map given the specified state and controls, as
-	 * described in section 9.2 of the XKB protocol specification.
-	 */
-
-static Bool
-ComputeAutoState(	XkbIndicatorMapPtr	map,
-			XkbStatePtr 		state,
-			XkbControlsPtr 		ctrls)
-{
-Bool 			on;
-CARD8 			mods,group;
-
-    on= False;
-    mods= group= 0;
-    if (map->which_mods&XkbIM_UseAnyMods) {
-	if (map->which_mods&XkbIM_UseBase)
-	    mods|= state->base_mods;
-	if (map->which_mods&XkbIM_UseLatched)
-	    mods|= state->latched_mods;
-	if (map->which_mods&XkbIM_UseLocked)
-	    mods|= state->locked_mods;
-	if (map->which_mods&XkbIM_UseEffective)
-	    mods|= state->mods;
-	if (map->which_mods&XkbIM_UseCompat)
-	    mods|= state->compat_state;
-	on = ((map->mods.mask&mods)!=0);
-	on = on||((mods==0)&&(map->mods.mask==0)&&(map->mods.vmods==0));
-    }
-    if (map->which_groups&XkbIM_UseAnyGroup) {
-	if (map->which_groups&XkbIM_UseBase)
-	    group|= (1L << state->base_group);
-	if (map->which_groups&XkbIM_UseLatched)
-	    group|= (1L << state->latched_group);
-	if (map->which_groups&XkbIM_UseLocked)
-	    group|= (1L << state->locked_group);
-	if (map->which_groups&XkbIM_UseEffective)
-	    group|= (1L << state->group);
-	on = on||(((map->groups&group)!=0)||(map->groups==0));
-    }
-    if (map->ctrls)
-	on = on||(ctrls->enabled_ctrls&map->ctrls);
-    return on;
-}
-
 /***====================================================================***/
 
 	/*
@@ -314,39 +423,6 @@ XkbSrvLedInfoPtr	sli;
 
 /***====================================================================***/
 
-void
-XkbUpdateAllDeviceIndicators(XkbChangesPtr changes,XkbEventCausePtr cause)
-{
-DeviceIntPtr		edev;
-XkbSrvLedInfoPtr	sli;
-
-    for (edev=inputInfo.devices;edev!=NULL;edev=edev->next) {
-	if (edev->kbdfeed) {
-	    KbdFeedbackPtr	kf;
-	    for (kf=edev->kbdfeed;kf!=NULL;kf=kf->next) {
-		if ((kf->xkb_sli==NULL)||(kf->xkb_sli->maps==NULL))
-		    continue;
-		sli= kf->xkb_sli;
-		XkbUpdateLedAutoState(edev,sli,sli->mapsPresent,NULL,
-								changes,cause);
-			
-	    }
-	}
-	if (edev->leds) {
-	    LedFeedbackPtr	lf;
-	    for (lf=edev->leds;lf!=NULL;lf=lf->next) {
-		if ((lf->xkb_sli==NULL)||(lf->xkb_sli->maps==NULL))
-		    continue;
-		sli= lf->xkb_sli;
-		XkbUpdateLedAutoState(edev,sli,sli->mapsPresent,NULL,
-								changes,cause);
-			
-	    }
-	}
-    }
-    return;
-}
-
 /***====================================================================***/
 
 	/*
@@ -856,210 +932,3 @@ Bool				kb_changed;
 	XkbUpdateAllDeviceIndicators(NULL,cause);
     return;
 }
-
-/***====================================================================***/
-
-void
-XkbUpdateLedAutoState(	DeviceIntPtr			dev,
-			XkbSrvLedInfoPtr		sli,
-			unsigned			maps_to_check,
-			xkbExtensionDeviceNotify *	ed,
-			XkbChangesPtr			changes,
-			XkbEventCausePtr		cause)
-{
-DeviceIntPtr			kbd;
-XkbStatePtr			state;
-XkbControlsPtr			ctrls;
-XkbChangesRec			my_changes;
-xkbExtensionDeviceNotify	my_ed;
-register unsigned		i,bit,affected;
-register XkbIndicatorMapPtr	map;
-unsigned			oldState;
-
-    if ((maps_to_check==0)||(sli->maps==NULL)||(sli->mapsPresent==0))
-	return;
-
-    if (dev->key && dev->key->xkbInfo)
-	 kbd= dev;
-    else kbd= (DeviceIntPtr)LookupKeyboardDevice();
-
-    state= &kbd->key->xkbInfo->state;
-    ctrls= kbd->key->xkbInfo->desc->ctrls;
-    affected= maps_to_check;
-    oldState= sli->effectiveState;
-    sli->autoState&= ~affected;
-    for (i=0,bit=1;(i<XkbNumIndicators)&&(affected);i++,bit<<=1) {
-	if ((affected&bit)==0)
-	    continue;
-	affected&= ~bit;
-	map= &sli->maps[i];
-	if((!(map->flags&XkbIM_NoAutomatic))&&ComputeAutoState(map,state,ctrls))
-	    sli->autoState|= bit;
-    }
-    sli->effectiveState= (sli->autoState|sli->explicitState);
-    affected= sli->effectiveState^oldState;
-    if (affected==0)
-	return;
-
-    if (ed==NULL) {
-	ed= &my_ed;
-	bzero((char *)ed,sizeof(xkbExtensionDeviceNotify));
-    }
-    else if ((ed->reason&XkbXI_IndicatorsMask)&&
-	     ((ed->ledClass!=sli->class)||(ed->ledID!=sli->id))) {
-	XkbFlushLedEvents(dev,kbd,sli,ed,changes,cause);
-    }
-
-    if ((kbd==dev)&&(sli->flags&XkbSLI_IsDefault)) {
-	if (changes==NULL) {
-	    changes= &my_changes;
-	    bzero((char *)changes,sizeof(XkbChangesRec));
-	}
-	changes->indicators.state_changes|= affected;
-    }
-
-    ed->reason|=	XkbXI_IndicatorStateMask;
-    ed->ledClass= 	sli->class;
-    ed->ledID=		sli->id;
-    ed->ledsDefined=	sli->namesPresent|sli->mapsPresent;
-    ed->ledState=	sli->effectiveState;
-    ed->unsupported|=	XkbXI_IndicatorStateMask;
-    ed->supported=	XkbXI_AllFeaturesMask;
-
-    if (changes!=&my_changes)	changes= NULL;
-    if (ed!=&my_ed)		ed= NULL;
-    if (changes || ed)
-	XkbFlushLedEvents(dev,kbd,sli,ed,changes,cause);
-    return;
-}
-
-/***====================================================================***/
-
-static void
-_UpdateButtonVMods(	XkbDescPtr			xkb,
-			unsigned			num_btns,
-			XkbAction *			acts,
-			unsigned			changed,
-			xkbExtensionDeviceNotify *	ed_inout)
-{
-register int i;
-
-    for (i=0;i<num_btns;i++,acts++) {
-	if ((acts->any.type!=XkbSA_NoAction)&&
-				XkbUpdateActionVirtualMods(xkb,acts,changed)) {
-	    if ((ed_inout->reason&XkbXI_ButtonActionsMask)==0) {
-		ed_inout->reason|= XkbXI_ButtonActionsMask;
-		ed_inout->firstBtn= i;
-		ed_inout->nBtns= 1;
-	    }
-	    else {
-		ed_inout->nBtns= (i-ed_inout->firstBtn)+1;
-	    }
-	}
-    }
-    return;
-}
-
-static void
-_UpdateMapVMods(	XkbDescPtr	xkb,
-			register	XkbIndicatorMapPtr map,
-			unsigned	changed_vmods,
-			unsigned *	changed_maps_rtrn)
-{
-register int i;
-
-    *changed_maps_rtrn= 0;
-    for (i=0;i<XkbNumIndicators;i++,map++) {
-	if (map->mods.vmods&changed_vmods) {
-	    map->mods.mask= map->mods.real_mods;
-	    map->mods.mask|= XkbMaskForVMask(xkb,map->mods.vmods);
-	    *changed_maps_rtrn|= (1L<<i);
-	}	
-    }
-    return;
-}
-
-static void
-_UpdateDeviceVMods(	DeviceIntPtr		dev,
-			XkbDescPtr		xkb,
-			unsigned		changed,
-			XkbEventCausePtr	cause)
-{
-xkbExtensionDeviceNotify	ed;
-XkbSrvLedInfoPtr		sli;
-unsigned			changed_maps;
-
-    bzero((char *)&ed,sizeof(xkbExtensionDeviceNotify));
-    ed.deviceID= dev->id;
-    if ((dev->button)&&(dev->button->xkb_acts)) {
-	_UpdateButtonVMods(xkb,dev->button->numButtons,
-					dev->button->xkb_acts,changed,&ed);
-    }
-    if (dev->kbdfeed) {
-	KbdFeedbackPtr	kf;
-	for (kf=dev->kbdfeed;kf!=NULL;kf=kf->next) {
-	    if ((kf->xkb_sli==NULL)||(kf->xkb_sli->maps==NULL))
-		continue;
-	    sli= kf->xkb_sli;
-	    _UpdateMapVMods(xkb,sli->maps,changed,&changed_maps);
-	    if (changed_maps) {
-		if (ed.reason&XkbXI_IndicatorsMask) {
-		    XkbSendExtensionDeviceNotify(dev,NULL,&ed);
-		    ed.reason= 0;
-		    ed.firstBtn= ed.nBtns;
-		}
-		ed.ledClass= 	sli->class;
-		ed.ledID=	sli->id;
-		ed.ledsDefined= sli->namesPresent|sli->mapsPresent;
-		ed.reason|= 	XkbXI_IndicatorMapsMask;
-		XkbUpdateLedAutoState(dev,sli,changed_maps,&ed,NULL,cause);
-	    }
-	}
-    }
-    if (dev->leds) {
-	LedFeedbackPtr	lf;
-	for (lf=dev->leds;lf!=NULL;lf=lf->next) {
-	    if ((lf->xkb_sli==NULL)||(lf->xkb_sli->maps==NULL))
-		continue;
-	    sli= lf->xkb_sli;
-	    _UpdateMapVMods(xkb,sli->maps,changed,&changed_maps);
-	    if (changed_maps) {
-		if (ed.reason&XkbXI_IndicatorsMask) {
-		    XkbSendExtensionDeviceNotify(dev,NULL,&ed);
-		    ed.reason= 0;
-		    ed.firstBtn= ed.nBtns;
-		}
-		ed.ledClass= 	sli->class;
-		ed.ledID=	sli->id;
-		ed.ledsDefined= sli->namesPresent|sli->mapsPresent;
-		ed.reason|= 	XkbXI_IndicatorMapsMask;
-		XkbUpdateLedAutoState(dev,sli,changed_maps,&ed,NULL,cause);
-	    }
-	}
-    }
-    if (ed.reason!=0)
-	XkbSendExtensionDeviceNotify(dev,NULL,&ed);
-    return;
-}
-
-void
-XkbApplyVModChangesToAllDevices(	DeviceIntPtr		dev,
-					XkbDescPtr 		xkb,
-					unsigned 		changed,
-					XkbEventCausePtr	cause)
-{
-DeviceIntPtr			edev;
-    if (dev!=(DeviceIntPtr)LookupKeyboardDevice())
-	return;
-    for (edev=inputInfo.devices;edev!=NULL;edev=edev->next) {
-	if (edev->key)
-	    continue;
-	_UpdateDeviceVMods(edev,xkb,changed,cause);
-    }
-    for (edev=inputInfo.off_devices;edev!=NULL;edev=edev->next) {
-	if (edev->key)
-	    continue;
-	_UpdateDeviceVMods(edev,xkb,changed,cause);
-    }
-    return;
-}
diff --git a/xkb/xkbPrKeyEv.c b/xkb/xkbPrKeyEv.c
index 9944c88..81124bc 100644
--- a/xkb/xkbPrKeyEv.c
+++ b/xkb/xkbPrKeyEv.c
@@ -36,7 +36,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #include <X11/keysym.h>
 #include "misc.h"
 #include "inputstr.h"
-#include <X11/extensions/XKBsrv.h>
+#include <xkbsrv.h>
 #include <ctype.h>
 
 
diff --git a/xkb/xkbSwap.c b/xkb/xkbSwap.c
index 9a04b77..da4c905 100644
--- a/xkb/xkbSwap.c
+++ b/xkb/xkbSwap.c
@@ -35,7 +35,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #include <X11/Xproto.h>
 #include "misc.h"
 #include "inputstr.h"
-#include <X11/extensions/XKBsrv.h>
+#include <xkbsrv.h>
 #include <X11/extensions/XKBstr.h>
 #include "extnsionst.h"
 #include "xkb.h"
diff --git a/xkb/xkbUtils.c b/xkb/xkbUtils.c
index 062159e..1d23667 100644
--- a/xkb/xkbUtils.c
+++ b/xkb/xkbUtils.c
@@ -41,7 +41,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #include "inputstr.h"
 
 #define	XKBSRV_NEED_FILE_FUNCS
-#include <X11/extensions/XKBsrv.h>
+#include <xkbsrv.h>
 #include <X11/extensions/XKBgeom.h>
 #include "xkb.h"
 
@@ -172,44 +172,6 @@ register unsigned mask;
     return mask;
 }
 
-
-Bool
-XkbApplyVModChanges(	XkbSrvInfoPtr		xkbi,
-			unsigned		changed,
-			XkbChangesPtr		changes,
-			unsigned *		needChecksRtrn,
-			XkbEventCausePtr	cause)
-{
-XkbDescPtr		xkb;
-Bool			check;
-
-    xkb= xkbi->desc;
-#ifdef DEBUG
-{
-register unsigned i,bit;
-    for (i=0,bit=1;i<XkbNumVirtualMods;i++,bit<<=1) {
-	if ((changed&bit)==0)
-	    continue;
-	if (xkbDebugFlags)
-	    ErrorF("Should be applying: change vmod %d to 0x%x\n",i,
-					xkb->server->vmods[i]);
-    }
-}
-#endif
-    check= XkbApplyVirtualModChanges(xkb,changed,changes);
-    XkbApplyVModChangesToAllDevices(xkbi->device,xkb,changed,cause);
-
-    if (needChecksRtrn!=NULL)  {
-	if (check)
-	     *needChecksRtrn= XkbStateNotifyMask|XkbIndicatorStateNotifyMask;
-	else *needChecksRtrn= 0;
-    }
-    else if (check) {
-	/* 7/12/95 (ef) -- XXX check compatibility and/or indicator state */
-    }
-    return 1;
-}
-
 /***====================================================================***/
 
 void
@@ -658,7 +620,7 @@ int		changed;
     return changed;
 }
 
-void
+static void
 XkbComputeCompatState(XkbSrvInfoPtr xkbi)
 {
 CARD16 		grp_mask;
@@ -772,21 +734,6 @@ XkbCheckSecondaryEffects(	XkbSrvInfoPtr	
 
 /***====================================================================***/
 
-void
-XkbSetPhysicalLockingKey(DeviceIntPtr dev,unsigned key)
-{
-XkbDescPtr	xkb;
-
-    xkb= dev->key->xkbInfo->desc;
-    if ((key>=xkb->min_key_code) && (key<=xkb->max_key_code)) {
-	xkb->server->behaviors[key].type= XkbKB_Lock|XkbKB_Permanent;
-    }
-    else ErrorF("Internal Error!  Bad XKB info in SetPhysicalLockingKey\n");
-    return;
-}
-
-/***====================================================================***/
-
 Bool
 XkbEnableDisableControls(	XkbSrvInfoPtr		xkbi,
 				unsigned long		change,
diff --git a/xkb/xkberrs.c b/xkb/xkberrs.c
index 095d573..3534356 100644
--- a/xkb/xkberrs.c
+++ b/xkb/xkberrs.c
@@ -32,37 +32,6 @@
 #include <ctype.h>
 #include <stdlib.h>
 
-char *		_XkbErrMessages[] = {
-	"success",				/* _XkbSuccess		     */
-	"key names not defined",		/* _XkbErrMissingNames	     */
-	"key types not defined",		/* _XkbErrMissingTypes	     */
-	"required key types not present",	/* _XkbErrMissingReqTypes    */
-	"symbols not defined",			/* _XkbErrMissingSymbols     */
-	"virtual modifier bindings not defined",/* _XkbErrMissingVMods	     */
-	"indicators not defined",		/* _XkbErrMissingIndicators  */
-	"compatibility map not defined",	/* _XkbErrMissingCompatMap   */
-	"symbol interpretations not defined",	/* _XkbErrMissingSymInterps  */
-	"geometry not defined",			/* _XkbErrMissingGeometry    */
-	"illegal doodad type",			/* _XkbErrIllegalDoodad	     */
-	"illegal TOC type",			/* _XkbErrIllegalTOCType     */
-	"illegal contents",			/* _XkbErrIllegalContents    */
-	"empty file",				/* _XkbErrEmptyFile	     */
-	"file not found",			/* _XkbErrFileNotFound       */
-	"cannot open",				/* _XkbErrFileCannotOpen     */
-	"bad value",				/* _XkbErrBadValue           */
-	"bad match",				/* _XkbErrBadMatch           */
-	"illegal name for type",		/* _XkbErrBadTypeName        */
-	"illegal width for type",		/* _XkbErrBadTypeWidth       */
-	"bad file type",			/* _XkbErrBadFileType        */
-	"bad file version",			/* _XkbErrBadFileVersion     */
-	"error in Xkm file",			/* _XkbErrBadFileFormat      */
-	"allocation failed",			/* _XkbErrBadAlloc           */
-	"bad length",                           /* _XkbErrBadLength          */
-	"X request failed",			/* _XkbErrXReqFailure        */
-	"not implemented"                       /* _XkbErrBadImplementation  */
-};
-
 unsigned	_XkbErrCode;
 char *		_XkbErrLocation= NULL;
 unsigned	_XkbErrData;
-
diff --git a/xkb/xkbfmisc.c b/xkb/xkbfmisc.c
index 4130bd9..05344b4 100644
--- a/xkb/xkbfmisc.c
+++ b/xkb/xkbfmisc.c
@@ -44,7 +44,7 @@
 #include "dix.h"
 #include <X11/extensions/XKBstr.h>
 #define XKBSRV_NEED_FILE_FUNCS	1
-#include <X11/extensions/XKBsrv.h>
+#include <xkbsrv.h>
 #include <X11/extensions/XKBgeom.h>
 #include "xkb.h"
 
@@ -133,76 +133,6 @@ unsigned	set,rtrn;
 
 /***===================================================================***/
 
-Bool
-XkbLookupGroupAndLevel(	XkbDescPtr 	xkb,
-			int 		key,
-			int *		mods_inout,
-			int *		grp_inout,
-			int *		lvl_rtrn)
-{
-int		nG,eG;
-
-    if ((!xkb)||(!XkbKeycodeInRange(xkb,key))||(!grp_inout))
-	return False;
-
-    nG= XkbKeyNumGroups(xkb,key);
-    eG= *grp_inout;
-
-    if ( nG==0 ) {
-	*grp_inout= 0;
-	if (lvl_rtrn!=NULL)
-	    *lvl_rtrn= 0;
-	return False;
-    }
-    else if ( nG==1 ) {
-	eG= 0;
-    }
-    else if ( eG>=nG ) {
-	unsigned gI= XkbKeyGroupInfo(xkb,key);
-	switch (XkbOutOfRangeGroupAction(gI)) {
-	    default:
-		eG %= nG;
-		break;
-	    case XkbClampIntoRange:
-		eG = nG-1;
-		break;
-	    case XkbRedirectIntoRange:
-		eG = XkbOutOfRangeGroupNumber(gI);
-		if (eG>=nG)
-		    eG= 0;
-		break;
-	}
-    }
-    *grp_inout= eG;
-    if (mods_inout!=NULL) {
-	XkbKeyTypePtr	type;
-	int		preserve;
-
-	type = XkbKeyKeyType(xkb,key,eG);
-	if (lvl_rtrn!=NULL)
-	    *lvl_rtrn= 0;
-	preserve= 0;
-	if (type->map) { /* find the shift level */
-	    register int i;
-	    register XkbKTMapEntryPtr entry;
-	    for (i=0,entry=type->map;i<type->map_count;i++,entry++) {
-		if ((entry->active)&&
-			(((*mods_inout)&type->mods.mask)==entry->mods.mask)){
-		    if (lvl_rtrn!=NULL)
-			*lvl_rtrn= entry->level;
-		    if (type->preserve)
-			preserve= type->preserve[i].mask;
-		    break;
-		}
-	    }
-	}
-	(*mods_inout)&= ~(type->mods.mask&(~preserve));
-    }
-    return True;
-}
-
-/***===================================================================***/
-
 static Bool
 XkbWriteSectionFromName(FILE *file,char *sectionName,char *name)
 {
@@ -416,15 +346,6 @@ XkbFileInfo	finfo;
 
 /***====================================================================***/
 
-/*ARGSUSED*/
-Status
-XkbMergeFile(XkbDescPtr xkb,XkbFileInfo finfo)
-{
-    return BadImplementation;
-}
-
-/***====================================================================***/
-
 int
 XkbFindKeycodeByName(XkbDescPtr xkb,char *name,Bool use_aliases)
 {
@@ -484,34 +405,6 @@ unsigned	rtrn;
     return rtrn;
 }
 
-unsigned
-XkbConvertXkbComponents(Bool toXkm,unsigned orig)
-{
-unsigned	rtrn;
-
-    rtrn= 0;
-    if (toXkm) {
-	if (orig&XkbClientMapMask)	rtrn|= XkmTypesMask|XkmSymbolsMask;
-	if (orig&XkbServerMapMask)	rtrn|= XkmTypesMask|XkmSymbolsMask;
-	if (orig&XkbCompatMapMask)	rtrn|= XkmCompatMapMask;
-	if (orig&XkbIndicatorMapMask)	rtrn|= XkmIndicatorsMask;
-	if (orig&XkbNamesMask)		rtrn|= XkmKeyNamesMask;
-	if (orig&XkbGeometryMask)	rtrn|= XkmGeometryMask;
-    }
-    else {
-	if (orig!=0)			rtrn|= XkbNamesMask;
-	if (orig&XkmTypesMask)		rtrn|= XkbClientMapMask;
-	if (orig&XkmCompatMapMask)
-		rtrn|= XkbCompatMapMask|XkbIndicatorMapMask;
-	if (orig&XkmSymbolsMask)	rtrn|=XkbClientMapMask|XkbServerMapMask;
-	if (orig&XkmIndicatorsMask)	rtrn|= XkbIndicatorMapMask;
-	if (orig&XkmKeyNamesMask)	
-		rtrn|= XkbNamesMask|XkbIndicatorMapMask;
-	if (orig&XkmGeometryMask)	rtrn|= XkbGeometryMask;
-    }
-    return rtrn;
-}
-
 Bool
 XkbDetermineFileType(XkbFileInfoPtr finfo,int format,int *opts_missing)
 {
diff --git a/xkb/xkbout.c b/xkb/xkbout.c
index 31cd4fa..bdec8e7 100644
--- a/xkb/xkbout.c
+++ b/xkb/xkbout.c
@@ -44,7 +44,7 @@
 #include "dix.h"
 #include <X11/extensions/XKBstr.h>
 #define XKBSRV_NEED_FILE_FUNCS	1
-#include <X11/extensions/XKBsrv.h>
+#include <xkbsrv.h>
 
 #include <X11/extensions/XKBgeom.h>
 #include <X11/extensions/XKBfile.h>
@@ -925,127 +925,3 @@ XkbGeometryPtr		geom;
     fprintf(file,"};\n\n");
     return True;
 }
-
-/*ARGSUSED*/
-Bool
-XkbWriteXKBSemantics(	FILE *			file,
-			XkbFileInfo *		result,
-			Bool			topLevel,
-			Bool			showImplicit,
-			XkbFileAddOnFunc	addOn,
-			void *			priv)
-{
-Bool		ok;
-
-    fprintf(file,"xkb_semantics {\n");
-    ok= XkbWriteXKBKeyTypes(file,result,False,False,addOn,priv);
-    ok= ok&&XkbWriteXKBCompatMap(file,result,False,False,addOn,priv);
-    fprintf(file,"};\n");
-    return ok;
-}
-
-/*ARGSUSED*/
-Bool
-XkbWriteXKBLayout(	FILE *			file,
-			XkbFileInfo *		result,
-			Bool			topLevel,
-			Bool			showImplicit,
-			XkbFileAddOnFunc	addOn,
-			void *			priv)
-{
-Bool		ok;
-XkbDescPtr	xkb;
-
-    xkb= result->xkb;
-    fprintf(file,"xkb_layout {\n");
-    ok= XkbWriteXKBKeycodes(file,result,False,showImplicit,addOn,priv);
-    ok= ok&&XkbWriteXKBKeyTypes(file,result,False,showImplicit,addOn,priv);
-    ok= ok&&XkbWriteXKBSymbols(file,result,False,showImplicit,addOn,priv);
-    if (xkb->geom)
-	ok= ok&&XkbWriteXKBGeometry(file,result,False,showImplicit,addOn,priv);
-    fprintf(file,"};\n");
-    return ok;
-}
-
-/*ARGSUSED*/
-Bool
-XkbWriteXKBKeymap(	FILE *			file,
-			XkbFileInfo *		result,
-			Bool			topLevel,
-			Bool			showImplicit,
-			XkbFileAddOnFunc	addOn,
-			void *			priv)
-{
-Bool		ok;
-XkbDescPtr	xkb;
-
-    xkb= result->xkb;
-    fprintf(file,"xkb_keymap {\n");
-    ok= XkbWriteXKBKeycodes(file,result,False,showImplicit,addOn,priv);
-    ok= ok&&XkbWriteXKBKeyTypes(file,result,False,showImplicit,addOn,priv);
-    ok= ok&&XkbWriteXKBCompatMap(file,result,False,showImplicit,addOn,priv);
-    ok= ok&&XkbWriteXKBSymbols(file,result,False,showImplicit,addOn,priv);
-    if (xkb->geom)
-	ok= ok&&XkbWriteXKBGeometry(file,result,False,showImplicit,addOn,priv);
-    fprintf(file,"};\n");
-    return ok;
-}
-
-Bool
-XkbWriteXKBFile(	FILE *			out,
-			XkbFileInfo *		result,
-			Bool			showImplicit,
-			XkbFileAddOnFunc	addOn,
-			void *			priv)
-{
-Bool	 		ok = False;
-Bool			(*func)(
-    FILE *		/* file */,
-    XkbFileInfo *	/* result */,
-    Bool		/* topLevel */,
-    Bool		/* showImplicit */,
-    XkbFileAddOnFunc	/* addOn */,
-    void *		/* priv */
-) = NULL;
-
-    switch (result->type) {
-	case XkmSemanticsFile:
-	    func= XkbWriteXKBSemantics;
-	    break;
-	case XkmLayoutFile:
-	    func= XkbWriteXKBLayout;
-	    break;
-	case XkmKeymapFile:
-	    func= XkbWriteXKBKeymap;
-	    break;
-	case XkmTypesIndex:
-	    func= XkbWriteXKBKeyTypes;
-	    break;
-	case XkmCompatMapIndex:
-	    func= XkbWriteXKBCompatMap;
-	    break;
-	case XkmSymbolsIndex:
-	    func= XkbWriteXKBSymbols;
-	    break;
-	case XkmKeyNamesIndex:
-	    func= XkbWriteXKBKeycodes;
-	    break;
-	case XkmGeometryFile:
-	case XkmGeometryIndex:
-	    func= XkbWriteXKBGeometry;
-	    break;
-	case XkmVirtualModsIndex:
-	case XkmIndicatorsIndex:
-	    _XkbLibError(_XkbErrBadImplementation,
-	    		XkbConfigText(result->type,XkbMessage),0);
-	    return False;
-    }
-    if (out==NULL) {
-	_XkbLibError(_XkbErrFileCannotOpen,"XkbWriteXkbFile",0);
-	ok= False;
-    }
-    else if (func) {
-	ok= (*func)(out,result,True,showImplicit,addOn,priv);
-    }
-    return ok;
-}
diff --git a/xkb/xkbtext.c b/xkb/xkbtext.c
index defd45a..3a50371 100644
--- a/xkb/xkbtext.c
+++ b/xkb/xkbtext.c
@@ -44,7 +44,7 @@
 #include "dix.h"
 #include <X11/extensions/XKBstr.h>
 #define XKBSRV_NEED_FILE_FUNCS	1
-#include <X11/extensions/XKBsrv.h>
+#include <xkbsrv.h>
 #include <X11/extensions/XKBgeom.h>
 
 /***====================================================================***/
@@ -448,100 +448,6 @@ char *		buf;
     return buf;
 }
 
-char *
-XkbAccessXDetailText(unsigned state,unsigned format)
-{
-char *buf,*prefix;
-
-    buf= tbGetBuffer(32);
-    if (format==XkbMessage)	prefix= "";
-    else			prefix= "XkbAXN_";
-    switch (state){
-	case XkbAXN_SKPress:	sprintf(buf,"%sSKPress",prefix); break;
-	case XkbAXN_SKAccept:	sprintf(buf,"%sSKAccept",prefix); break;
-	case XkbAXN_SKRelease:	sprintf(buf,"%sSKRelease",prefix); break;
-	case XkbAXN_SKReject:	sprintf(buf,"%sSKReject",prefix); break;
-	case XkbAXN_BKAccept:	sprintf(buf,"%sBKAccept",prefix); break;
-	case XkbAXN_BKReject:	sprintf(buf,"%sBKReject",prefix); break;
-	case XkbAXN_AXKWarning:	sprintf(buf,"%sAXKWarning",prefix); break;
-	default:		sprintf(buf,"ILLEGAL"); break;
-    }
-    return buf;
-}
-
-static char *nknNames[] = {
-	"keycodes", "geometry", "deviceID"
-};
-#define	NUM_NKN	(sizeof(nknNames)/sizeof(char *))
-
-char *
-XkbNKNDetailMaskText(unsigned detail,unsigned format)
-{
-char *buf,*prefix,*suffix;
-register int 		i;
-register unsigned	bit;
-int			len,plen,slen;
-
-
-    if ((detail&XkbAllNewKeyboardEventsMask)==0) {
-	char *tmp = "";
-	if (format==XkbCFile)			tmp= "0";
-	else if (format==XkbMessage)		tmp= "none";
-	buf=  tbGetBuffer(strlen(tmp)+1);
-	strcpy(buf,tmp);
-	return buf;
-    }
-    else if ((detail&XkbAllNewKeyboardEventsMask)==XkbAllNewKeyboardEventsMask){
-	char *	tmp;
-	if (format==XkbCFile)		tmp= "XkbAllNewKeyboardEventsMask";
-	else 				tmp= "all";
-	buf=  tbGetBuffer(strlen(tmp)+1);
-	strcpy(buf,tmp);
-	return buf;
-    }
-    if (format==XkbMessage) {
-	prefix= "";
-	suffix= "";
-	slen= plen= 0;
-    }
-    else {
-	prefix= "XkbNKN_";
-	plen= 7;
-	if (format==XkbCFile)
-	     suffix= "Mask";
-	else suffix= "";
-	slen= strlen(suffix);
-    }
-    for (len=0,i=0,bit=1;i<NUM_NKN;i++,bit<<=1) {
-	if (detail&bit) {
-	    if (len!=0)	len+= 1;	/* room for '+' or '|' */
-	    len+= plen+slen+strlen(nknNames[i]);
-	}
-    }
-    buf= tbGetBuffer(len+1);
-    buf[0]= '\0';
-    for (len=0,i=0,bit=1;i<NUM_NKN;i++,bit<<=1) {
-	if (detail&bit) {
-	    if (len!=0) {
-		if (format==XkbCFile)	buf[len++]= '|';
-		else			buf[len++]= '+';
-	    }
-	    if (plen) {
-		strcpy(&buf[len],prefix);
-		len+= plen;
-	    }
-	    strcpy(&buf[len],nknNames[i]);
-	    len+= strlen(nknNames[i]);
-	    if (slen) {
-		strcpy(&buf[len],suffix);
-		len+= slen;
-	    }
-	}
-    }
-    buf[len++]= '\0';
-    return buf;
-}
-
 static char *ctrlNames[] = {
 	"repeatKeys",
 	"slowKeys",
diff --git a/xkb/xkmread.c b/xkb/xkmread.c
index fec8687..c6c1842 100644
--- a/xkb/xkmread.c
+++ b/xkb/xkmread.c
@@ -41,7 +41,7 @@
 #include "inputstr.h"
 #include <X11/extensions/XKBstr.h>
 #define	 XKBSRV_NEED_FILE_FUNCS
-#include <X11/extensions/XKBsrv.h>
+#include <xkbsrv.h>
 #include <X11/extensions/XKBgeom.h>
 
 Atom
@@ -1098,18 +1098,6 @@ unsigned i,size_toc;
     return 1;
 }
 
-xkmSectionInfo *
-XkmFindTOCEntry(xkmFileInfo *finfo,xkmSectionInfo *toc,unsigned type)
-{
-register int i;
-
-    for (i=0;i<finfo->num_toc;i++) {
-	if (toc[i].type==type)
-	    return &toc[i];
-    }
-    return NULL;
-}
-
 Bool
 XkmReadFileSection(	FILE *			file,
 			xkmSectionInfo *	toc,
diff-tree 9398d62f27ee1b287e4458fd8b011c10f7b59efd (from 0f75c47e0c5f4b2778930a6fabf894fc1dffd9d3)
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Wed Mar 21 00:18:24 2007 +0200

    XFree86 input: Add backwards compatibility for motion history
    Add the old motion history API back, as a shim around the new mi API.

diff --git a/hw/xfree86/common/xf86Helper.c b/hw/xfree86/common/xf86Helper.c
index 93c89fd..913735b 100644
--- a/hw/xfree86/common/xf86Helper.c
+++ b/hw/xfree86/common/xf86Helper.c
@@ -2981,3 +2981,16 @@ xf86IsUnblank(int mode)
 	return TRUE;
     }
 }
+
+_X_EXPORT void
+xf86MotionHistoryAllocate(LocalDevicePtr local)
+{
+    AllocateMotionHistory(local->dev);
+}
+
+_X_EXPORT int
+xf86GetMotionEvents(DeviceIntPtr pDev, xTimecoord *buff, unsigned long start,
+                    unsigned long stop, ScreenPtr pScreen)
+{
+    return GetMotionHistory(pDev, buff, start, stop, pScreen);
+}
diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c
index b8f4b69..c9c8059 100644
--- a/hw/xfree86/common/xf86Xinput.c
+++ b/hw/xfree86/common/xf86Xinput.c
@@ -132,6 +132,9 @@ xf86ProcessCommonOptions(LocalDevicePtr 
     } else {
         xf86Msg(X_CONFIG, "%s: doesn't report drag events\n", local->name);
     }
+
+    /* Backwards compatibility. */
+    local->history_size = GetMotionHistorySize();
 }
 
 /***********************************************************************
diff --git a/hw/xfree86/common/xf86Xinput.h b/hw/xfree86/common/xf86Xinput.h
index 47dbc70..b2bc8de 100644
--- a/hw/xfree86/common/xf86Xinput.h
+++ b/hw/xfree86/common/xf86Xinput.h
@@ -86,6 +86,9 @@
 #define XI_PRIVATE(dev) \
 	(((LocalDevicePtr)((dev)->public.devicePrivate))->private)
 
+/* Stupid API backwards-compatibility. */
+#define TS_Raw 60
+#define TS_Scaled 61
 
 #ifdef XINPUT
 /* This holds the input driver entry and module information. */
@@ -144,6 +147,7 @@ typedef struct _LocalDeviceRec {
     InputDriverPtr	    drv;
     pointer		    module;
     pointer		    options;
+    unsigned int            history_size;
 } LocalDeviceRec, *LocalDevicePtr, InputInfoRec, *InputInfoPtr;
 
 typedef struct _DeviceAssocRec 
diff-tree 0f75c47e0c5f4b2778930a6fabf894fc1dffd9d3 (from 80d29475b9a2ebbb303a8e324e09a15c528d5556)
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Wed Mar 21 00:12:02 2007 +0200

    xfree86 input: Re-enable DGA support
    Re-enable DGA support for relative mouse motion.

diff --git a/hw/xfree86/common/xf86DGA.c b/hw/xfree86/common/xf86DGA.c
index 204457f..28058b5 100644
--- a/hw/xfree86/common/xf86DGA.c
+++ b/hw/xfree86/common/xf86DGA.c
@@ -51,11 +51,14 @@
 
 static unsigned long DGAGeneration = 0;
 static int DGAScreenIndex = -1;
+static int mieq_installed = 0;
 
 static Bool DGACloseScreen(int i, ScreenPtr pScreen);
 static void DGADestroyColormap(ColormapPtr pmap);
 static void DGAInstallColormap(ColormapPtr pmap);
 static void DGAUninstallColormap(ColormapPtr pmap);
+static void DGAHandleEvent(int screen_num, xEvent *event,
+                           DeviceIntPtr device, int nevents);
 
 static void
 DGACopyModeInfo(
@@ -96,7 +99,6 @@ typedef struct {
    Bool			grabKeyboard;
 } DGAScreenRec, *DGAScreenPtr;
 
-
 _X_EXPORT Bool
 DGAInit(
    ScreenPtr pScreen,
@@ -146,7 +148,6 @@ DGAInit(
 	    modes[i].flags &= ~DGA_PIXMAP_AVAILABLE;
 #endif
 
-
     pScreen->devPrivates[DGAScreenIndex].ptr = (pointer)pScreenPriv;
     pScreenPriv->CloseScreen = pScreen->CloseScreen;
     pScreen->CloseScreen = DGACloseScreen;
@@ -157,11 +158,6 @@ DGAInit(
     pScreenPriv->UninstallColormap = pScreen->UninstallColormap;
     pScreen->UninstallColormap = DGAUninstallColormap;
 
-    /*
-     * This is now set in InitOutput().
-     *
-    pScrn->SetDGAMode = xf86SetDGAMode;
-     */
 
     return TRUE;
 }
@@ -247,12 +243,22 @@ FreeMarkedVisuals(ScreenPtr pScreen)
     }
 }
 
-
 static Bool 
 DGACloseScreen(int i, ScreenPtr pScreen)
 {
    DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen);
 
+   if (XDGAEventBase) {
+       OsBlockSignals();
+       ProcessInputEvents();
+       mieqSetHandler(*XDGAEventBase + MotionNotify, NULL);
+       mieqSetHandler(*XDGAEventBase + ButtonPress, NULL);
+       mieqSetHandler(*XDGAEventBase + ButtonRelease, NULL);
+       mieqSetHandler(*XDGAEventBase + KeyPress, NULL);
+       mieqSetHandler(*XDGAEventBase + KeyRelease, NULL);
+       OsReleaseSignals();
+    }
+
    FreeMarkedVisuals(pScreen);
 
    pScreen->CloseScreen = pScreenPriv->CloseScreen;
@@ -462,6 +468,15 @@ DGASetInputMode(int index, Bool keyboard
    {
       pScreenPriv->grabMouse = mouse;
       pScreenPriv->grabKeyboard = keyboard;
+
+      if (!mieq_installed) {
+          mieqSetHandler(*XDGAEventBase + MotionNotify, DGAHandleEvent);
+          mieqSetHandler(*XDGAEventBase + ButtonPress, DGAHandleEvent);
+          mieqSetHandler(*XDGAEventBase + ButtonRelease, DGAHandleEvent);
+          mieqSetHandler(*XDGAEventBase + KeyPress, DGAHandleEvent);
+          mieqSetHandler(*XDGAEventBase + KeyRelease, DGAHandleEvent);
+          mieq_installed = 1;
+      }
    }
 }
 
@@ -903,21 +918,93 @@ DGAVTSwitch(void)
    return TRUE;
 }
 
+Bool
+DGAStealKeyEvent(int index, int key_code, int is_down)
+{
+   DGAScreenPtr pScreenPriv;
+   dgaEvent    de;
+    
+   if(DGAScreenIndex < 0) /* no DGA */
+        return FALSE;
+
+   pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]);
 
-/* We have the power to steal or modify events that are about to get queued */
+   if(!pScreenPriv || !pScreenPriv->grabKeyboard) /* no direct mode */
+        return FALSE; 
+
+    de.u.u.type = *XDGAEventBase + (is_down ? KeyPress : KeyRelease);
+    de.u.u.detail = key_code;
+    de.u.event.time = GetTimeInMillis();
+    mieqEnqueue (inputInfo.keyboard, (xEvent *) &de);
+
+   return TRUE;
+}  
+
+static int  DGAMouseX, DGAMouseY;
 
 Bool
-DGAStealKeyEvent(int index, xEvent *e)
+DGAStealMotionEvent(int index, int dx, int dy)
 {
-}
+   DGAScreenPtr pScreenPriv;
+    dgaEvent    de;
 
-static int  DGAMouseX, DGAMouseY;
+   if(DGAScreenIndex < 0) /* no DGA */
+        return FALSE;
+    
+   pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]);
+
+   if(!pScreenPriv || !pScreenPriv->grabMouse) /* no direct mode */
+        return FALSE;
+
+    DGAMouseX += dx;
+    if (DGAMouseX < 0)
+        DGAMouseX = 0;
+    else if (DGAMouseX > screenInfo.screens[index]->width)
+        DGAMouseX = screenInfo.screens[index]->width;
+    DGAMouseY += dy;
+    if (DGAMouseY < 0)
+        DGAMouseY = 0;
+    else if (DGAMouseY > screenInfo.screens[index]->height)
+        DGAMouseY = screenInfo.screens[index]->height;
+    de.u.u.type = *XDGAEventBase + MotionNotify;
+    de.u.u.detail = 0;
+    de.u.event.time = GetTimeInMillis();
+    de.u.event.dx = dx;
+    de.u.event.dy = dy;
+    de.u.event.pad1 = DGAMouseX;
+    de.u.event.pad2 = DGAMouseY;
+    mieqEnqueue (inputInfo.pointer, (xEvent *) &de);
+    return TRUE;
+}
 
 Bool
-DGAStealMouseEvent(int index, xEvent *e, int dx, int dy)
+DGAStealButtonEvent(int index, int button, int is_down)
 {
+    DGAScreenPtr pScreenPriv;
+    dgaEvent de;
+
+    if (DGAScreenIndex < 0)
+        return FALSE;
+    
+    pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]);
+
+    if (!pScreenPriv || !pScreenPriv->grabMouse)
+        return FALSE;
+
+    de.u.u.type = *XDGAEventBase + (is_down ? ButtonPress : ButtonRelease);
+    de.u.u.detail = button;
+    de.u.event.time = GetTimeInMillis();
+    de.u.event.dx = 0;
+    de.u.event.dy = 0;
+    de.u.event.pad1 = DGAMouseX;
+    de.u.event.pad2 = DGAMouseY;
+    mieqEnqueue (inputInfo.pointer, (xEvent *) &de);
+
+    return TRUE;
 }
 
+/* We have the power to steal or modify events that are about to get queued */
+
 Bool
 DGAIsDgaEvent (xEvent *e)
 {
@@ -1124,39 +1211,6 @@ DGAProcessPointerEvent (ScreenPtr pScree
     }
 }
 
-Bool
-DGADeliverEvent (ScreenPtr pScreen, xEvent *e)
-{
-    dgaEvent	    *de = (dgaEvent *) e;
-    DGAScreenPtr    pScreenPriv;
-    int		    coreEquiv;
-
-    /* no DGA */
-    if (DGAScreenIndex < 0 || XDGAEventBase == 0)
-	return FALSE;
-    pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen);
-    
-    /* DGA not initialized on this screen */
-    if (!pScreenPriv)
-	return FALSE;
-    
-    coreEquiv = de->u.u.type - *XDGAEventBase;
-    /* Not a DGA event */
-    if (coreEquiv < KeyPress || coreEquiv > MotionNotify)
-	return FALSE;
-    
-    switch (coreEquiv) {
-    case KeyPress:
-    case KeyRelease:
-	DGAProcessKeyboardEvent (pScreen, de, inputInfo.keyboard);
-	break;
-    default:
-	DGAProcessPointerEvent (pScreen, de, inputInfo.pointer);
-	break;
-    }
-    return TRUE;
-}
-
 _X_EXPORT Bool 
 DGAOpenFramebuffer(
    int index,
@@ -1215,3 +1269,35 @@ DGAGetOldDGAMode(int index)
    return 0;
 }
 
+static void
+DGAHandleEvent(int screen_num, xEvent *event, DeviceIntPtr device, int nevents)
+{
+    dgaEvent	    *de = (dgaEvent *) event;
+    ScreenPtr       pScreen = screenInfo.screens[screen_num];
+    DGAScreenPtr    pScreenPriv;
+    int		    coreEquiv;
+
+    /* no DGA */
+    if (DGAScreenIndex < 0 || XDGAEventBase == 0)
+	return;
+    pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen);
+    
+    /* DGA not initialized on this screen */
+    if (!pScreenPriv)
+	return;
+    
+    coreEquiv = de->u.u.type - *XDGAEventBase;
+    /* Not a DGA event; shouldn't happen, but you never know. */
+    if (coreEquiv < KeyPress || coreEquiv > MotionNotify)
+	return;
+    
+    switch (coreEquiv) {
+    case KeyPress:
+    case KeyRelease:
+	DGAProcessKeyboardEvent (pScreen, de, inputInfo.keyboard);
+	break;
+    default:
+	DGAProcessPointerEvent (pScreen, de, inputInfo.pointer);
+	break;
+    }
+}
diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c
index 16e330d..b8f4b69 100644
--- a/hw/xfree86/common/xf86Xinput.c
+++ b/hw/xfree86/common/xf86Xinput.c
@@ -90,6 +90,10 @@
 
 #include "mi.h"
 
+#ifdef XFreeXDGA
+#include "dgaproc.h"
+#endif
+
 xEvent *xf86Events = NULL;
 
 static Bool
@@ -395,10 +399,12 @@ xf86PostMotionEvent(DeviceIntPtr	device,
 {
     va_list var;
     int i = 0, nevents = 0;
+    int dx, dy;
     Bool drag = xf86SendDragEvents(device);
     int *valuators = NULL;
     int flags = 0;
     xEvent *xE = NULL;
+    int index;
 
     if (is_absolute)
         flags = POINTER_ABSOLUTE;
@@ -412,6 +418,22 @@ xf86PostMotionEvent(DeviceIntPtr	device,
         valuators[i] = va_arg(var, int);
     va_end(var);
 
+#if XFreeXDGA
+    if (first_valuator == 0 && num_valuators >= 2) {
+        index = miPointerGetScreen(inputInfo.pointer)->myNum;
+        if (is_absolute) {
+            dx = valuators[0] - device->valuator->lastx;
+            dy = valuators[1] - device->valuator->lasty;
+        }
+        else {
+            dx = valuators[0];
+            dy = valuators[1];
+        }
+        if (DGAStealMotionEvent(index, dx, dy))
+            goto out;
+    }
+#endif
+
     if (!xf86Events)
         xf86Events = (xEvent *)xcalloc(sizeof(xEvent), GetMaximumEventsNum());
     if (!xf86Events)
@@ -430,6 +452,7 @@ xf86PostMotionEvent(DeviceIntPtr	device,
         }
     }
 
+out:
     xfree(valuators);
 }
 
@@ -476,6 +499,13 @@ xf86PostButtonEvent(DeviceIntPtr	device,
     va_list var;
     int *valuators = NULL;
     int i = 0, nevents = 0;
+    int index;
+
+#if XFreeXDGA
+    index = miPointerGetScreen(inputInfo.pointer)->myNum;
+    if (DGAStealButtonEvent(index, button, is_down))
+        return;
+#endif
     
     valuators = xcalloc(sizeof(int), num_valuators);
 
@@ -552,6 +582,13 @@ xf86PostKeyboardEvent(DeviceIntPtr      
                       int               is_down)
 {
     int nevents = 0, i = 0;
+    int index;
+
+#if XFreeXDGA
+    index = miPointerGetScreen(inputInfo.pointer)->myNum;
+    if (DGAStealKeyEvent(index, key_code, is_down))
+        return;
+#endif
 
     if (!xf86Events)
         xf86Events = (xEvent *)xcalloc(sizeof(xEvent), GetMaximumEventsNum());
diff --git a/hw/xfree86/common/xf86Xinput.h b/hw/xfree86/common/xf86Xinput.h
index fe65643..47dbc70 100644
--- a/hw/xfree86/common/xf86Xinput.h
+++ b/hw/xfree86/common/xf86Xinput.h
@@ -191,6 +191,10 @@ InputInfoPtr xf86AllocateInput(InputDriv
 InputDriverPtr xf86LookupInputDriver(const char *name);
 InputInfoPtr xf86LookupInput(const char *name);
 void xf86DeleteInput(InputInfoPtr pInp, int flags);
+void xf86MotionHistoryAllocate(LocalDevicePtr local);
+int xf86GetMotionEvents(DeviceIntPtr dev, xTimecoord *buff,
+                        unsigned long start, unsigned long stop,
+                        ScreenPtr pScreen);
 
 /* xf86Option.c */
 void xf86CollectInputOptions(InputInfoPtr pInfo, const char **defaultOpts,
diff --git a/hw/xfree86/dixmods/extmod/dgaproc.h b/hw/xfree86/dixmods/extmod/dgaproc.h
index 5e424af..aaea4e2 100644
--- a/hw/xfree86/dixmods/extmod/dgaproc.h
+++ b/hw/xfree86/dixmods/extmod/dgaproc.h
@@ -120,8 +120,9 @@ int DGAGetOldDGAMode(int Index);
 int DGAGetModeInfo(int Index, XDGAModePtr mode, int num);
 
 Bool DGAVTSwitch(void);
-Bool DGAStealMouseEvent(int Index, xEvent *e, int dx, int dy);
-Bool DGAStealKeyEvent(int Index, xEvent *e);
+Bool DGAStealButtonEvent(int Index, int button, int is_down);
+Bool DGAStealMotionEvent(int Index, int dx, int dy);
+Bool DGAStealKeyEvent(int Index, int key_code, int is_down);
 Bool DGAIsDgaEvent (xEvent *e);
 
 Bool DGADeliverEvent (ScreenPtr pScreen, xEvent *e);
diff-tree 80d29475b9a2ebbb303a8e324e09a15c528d5556 (from b8df961843a95b29258ae9c5d46ccfc620d8de1c)
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Wed Mar 21 00:10:38 2007 +0200

    mieq: Allow event handlers for arbitrary events to be set
    Allow arbitrary events to use mieq by letting custom handlers be set.

diff --git a/mi/mi.h b/mi/mi.h
index 8d9d120..53b5c44 100644
--- a/mi/mi.h
+++ b/mi/mi.h
@@ -186,6 +186,9 @@ extern void mieqProcessInputEvents(
     void
 );
 
+typedef void (*mieqHandler)(int, xEventPtr, DeviceIntPtr, int);
+void mieqSetHandler(int event, mieqHandler handler);
+
 /* miexpose.c */
 
 extern RegionPtr miHandleExposures(
diff --git a/mi/mieq.c b/mi/mieq.c
index 507cdd3..5bd87eb 100644
--- a/mi/mieq.c
+++ b/mi/mieq.c
@@ -74,6 +74,7 @@ typedef struct _EventQueue {
     EventRec         events[QUEUE_SIZE]; /* static allocation for signals */
     ScreenPtr        pEnqueueScreen;     /* screen events are being delivered to */
     ScreenPtr        pDequeueScreen;     /* screen events are being dispatched to */
+    mieqHandler      handlers[128];      /* custom event handler */
 } EventQueueRec, *EventQueuePtr;
 
 static EventQueueRec miEventQueue;
@@ -81,11 +82,15 @@ static EventQueueRec miEventQueue;
 Bool
 mieqInit()
 {
+    int i;
+
     miEventQueue.head = miEventQueue.tail = 0;
     miEventQueue.lastEventTime = GetTimeInMillis ();
     miEventQueue.lastMotion = FALSE;
     miEventQueue.pEnqueueScreen = screenInfo.screens[0];
     miEventQueue.pDequeueScreen = miEventQueue.pEnqueueScreen;
+    for (i = 0; i < 128; i++)
+        miEventQueue.handlers[i] = NULL;
     SetInputCheck(&miEventQueue.head, &miEventQueue.tail);
     return TRUE;
 }
@@ -178,6 +183,16 @@ mieqSwitchScreen(ScreenPtr pScreen, Bool
 	miEventQueue.pDequeueScreen = pScreen;
 }
 
+void
+mieqSetHandler(int event, mieqHandler handler)
+{
+    if (handler && miEventQueue.handlers[event])
+        ErrorF("mieq: warning: overriding existing handler %p with %p for "
+               "event %d\n", miEventQueue.handlers[event], handler, event);
+
+    miEventQueue.handlers[event] = handler;
+}
+
 /* Call this from ProcessInputEvents(). */
 void
 mieqProcessInputEvents()
@@ -215,6 +230,15 @@ mieqProcessInputEvents()
             else
                 ++miEventQueue.head;
 
+            /* If someone's registered a custom event handler, let them
+             * steal it. */
+            if (miEventQueue.handlers[e->event->u.u.type]) {
+                miEventQueue.handlers[e->event->u.u.type](miEventQueue.pDequeueScreen->myNum,
+                                                          e->event, dev,
+                                                          e->nevents);
+                return;
+            }
+
             /* If this is a core event, make sure our keymap, et al, is
              * changed to suit. */
             if (e->event[0].u.u.type == KeyPress ||
diff-tree b8df961843a95b29258ae9c5d46ccfc620d8de1c (from 720f302d241e88e6e9f2962207da1aa9a79728b7)
Author: Alan Coopersmith <alan.coopersmith at sun.com>
Date:   Mon Mar 19 18:03:26 2007 -0700

    Define XF86PM on Solaris x86 builds now that we have sun_apm.c

diff --git a/configure.ac b/configure.ac
index fe77709..14c4ccb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1413,6 +1413,8 @@ return 0;}
 			fi
 			if test "${OS_MINOR}" -lt 8 ; then
 				solaris_usl_console="yes"
+			else
+				XORG_CFLAGS="$XORG_CFLAGS -DXF86PM"
 			fi
 			;;
 		  *)
diff-tree 720f302d241e88e6e9f2962207da1aa9a79728b7 (from b5a8a71e64c76b8dd42962cbd7984215c6ce4aa8)
Author: Keith Packard <keithp at neko.keithp.com>
Date:   Sat Mar 17 20:14:05 2007 -0700

    Slow down DDC I2C bus using a RiseFallTime of 20us for old monitors.
    
    This time value makes the bus run slowly enough for even the least reliable
    of monitors. Thanks to Pavel Troller for finding the necessary change.

diff --git a/hw/xfree86/ddc/xf86DDC.c b/hw/xfree86/ddc/xf86DDC.c
index 0f24c52..8080c8d 100644
--- a/hw/xfree86/ddc/xf86DDC.c
+++ b/hw/xfree86/ddc/xf86DDC.c
@@ -337,6 +337,12 @@ DDCRead_DDC2(int scrnIndex, I2CBusPtr pB
     unsigned char *R_Buffer;
     int i;
     
+    /*
+     * Slow down the bus so that older monitors don't 
+     * miss things.
+     */
+    pBus->RiseFallTime = 20;
+    
     if (!(dev = xf86I2CFindDev(pBus, 0x00A0))) {
 	dev = xf86CreateI2CDevRec();
 	dev->DevName = "ddc2";
diff-tree b5a8a71e64c76b8dd42962cbd7984215c6ce4aa8 (from 2489dae9f7def788910eee5733931392df83a0d6)
Author: Keith Packard <keithp at neko.keithp.com>
Date:   Sat Mar 17 17:26:11 2007 -0700

    Remove extra (and wrong) I2C ByteTimeout setting in DDC code.
    
    The DDC code sets the I2C timeouts to VESA standards, except that it had an
    extra setting of the ByteTimeout value which was wrong (off by a factor of
    50). Removing this should help DDC work on many more monitors. Note that the
    Intel driver duplicated these settings, along with the error. Yay for cult
    and paste coding.

diff --git a/hw/xfree86/ddc/xf86DDC.c b/hw/xfree86/ddc/xf86DDC.c
index 4ce585c..0f24c52 100644
--- a/hw/xfree86/ddc/xf86DDC.c
+++ b/hw/xfree86/ddc/xf86DDC.c
@@ -344,7 +344,6 @@ DDCRead_DDC2(int scrnIndex, I2CBusPtr pB
 	dev->ByteTimeout = 2200; /* VESA DDC spec 3 p. 43 (+10 %) */
 	dev->StartTimeout = 550;
 	dev->BitTimeout = 40;
-	dev->ByteTimeout = 40;
 	dev->AcknTimeout = 40;
 
 	dev->pI2CBus = pBus;
diff-tree 2489dae9f7def788910eee5733931392df83a0d6 (from 9d0c3b52f25df89738fb1a62ccffda8c8cbb4689)
Author: Keith Packard <keithp at guitar.keithp.com>
Date:   Thu Mar 15 20:26:07 2007 -0700

    Correct ref counting of RRMode structures
    
    RRModes are referenced by the resource db, RROutput and RRCrtc structures.
    Ensure that the mode reference count is decremented each time a reference is
    lost from one of these sources. The missing destroys were in
    RRCrtcDestroyResource and RROutputDestroyResource, which only happen at
    server reset time, so modes would be unavailable in subsequent server
    generations.

diff --git a/randr/rrcrtc.c b/randr/rrcrtc.c
index 315dd6c..ecf5bb2 100644
--- a/randr/rrcrtc.c
+++ b/randr/rrcrtc.c
@@ -361,6 +361,8 @@ RRCrtcDestroyResource (pointer value, XI
     }
     if (crtc->gammaRed)
 	xfree (crtc->gammaRed);
+    if (crtc->mode)
+	RRModeDestroy (crtc->mode);
     xfree (crtc);
     return 1;
 }
diff --git a/randr/rroutput.c b/randr/rroutput.c
index 6e95c95..160071b 100644
--- a/randr/rroutput.c
+++ b/randr/rroutput.c
@@ -406,9 +406,12 @@ RROutputDestroyResource (pointer value, 
 	    }
 	}
     }
-    /* XXX destroy all modes? */
     if (output->modes)
+    {
+	for (m = 0; m < output->numModes; m++)
+	    RRModeDestroy (output->modes[m]);
 	xfree (output->modes);
+    }
     
     for (m = 0; m < output->numUserModes; m++)
 	RRModeDestroy (output->userModes[m]);
diff-tree 9d0c3b52f25df89738fb1a62ccffda8c8cbb4689 (from 2c93083edd29a65e73bb2e8eff9d353e92845c9b)
Author: Keith Packard <keithp at guitar.keithp.com>
Date:   Tue Feb 20 23:04:26 2007 -0800

    Eliminate RRModeRec devPrivate field.
    
    The xf86 mode setting code was mis-using this field to try and store a
    pointer to a DisplayModeRec, however, each output has its own copy of every
    DisplayModeRec leaving the one in in the RRModeRec devPrivate field pointing
    at a random DisplayModeRec.
    
    Instead of attempting to rectify this, eliminating the devPrivate entirely
    turned out to be very easy; the DDX code now accepts an arbitrary RRModeRec
    structure and set that to the hardware, converting it on the fly to a
    DisplayModeRec as needed.
    (cherry picked from commit 3506b9376c2b0db09bfff58d64e07af88a6e8195)

diff --git a/hw/xfree86/modes/xf86RandR12.c b/hw/xfree86/modes/xf86RandR12.c
index 73647a6..4213fea 100644
--- a/hw/xfree86/modes/xf86RandR12.c
+++ b/hw/xfree86/modes/xf86RandR12.c
@@ -556,6 +556,56 @@ xf86RandR12GetOriginalVirtualSize(ScrnIn
 }
 
 #if RANDR_12_INTERFACE
+
+#define FLAG_BITS (RR_HSyncPositive | \
+		   RR_HSyncNegative | \
+		   RR_VSyncPositive | \
+		   RR_VSyncNegative | \
+		   RR_Interlace | \
+		   RR_DoubleScan | \
+		   RR_CSync | \
+		   RR_CSyncPositive | \
+		   RR_CSyncNegative | \
+		   RR_HSkewPresent | \
+		   RR_BCast | \
+		   RR_PixelMultiplex | \
+		   RR_DoubleClock | \
+		   RR_ClockDivideBy2)
+
+static Bool
+xf86RandRModeMatches (RRModePtr		randr_mode,
+		      DisplayModePtr	mode)
+{
+#if 0
+    if (match_name)
+    {
+	/* check for same name */
+	int	len = strlen (mode->name);
+	if (randr_mode->mode.nameLength != len)			return FALSE;
+	if (memcmp (randr_mode->name, mode->name, len) != 0)	return FALSE;
+    }
+#endif
+    
+    /* check for same timings */
+    if (randr_mode->mode.dotClock / 1000 != mode->Clock)    return FALSE;
+    if (randr_mode->mode.width        != mode->HDisplay)    return FALSE;
+    if (randr_mode->mode.hSyncStart   != mode->HSyncStart)  return FALSE;
+    if (randr_mode->mode.hSyncEnd     != mode->HSyncEnd)    return FALSE;
+    if (randr_mode->mode.hTotal       != mode->HTotal)	    return FALSE;
+    if (randr_mode->mode.hSkew        != mode->HSkew)	    return FALSE;
+    if (randr_mode->mode.height       != mode->VDisplay)    return FALSE;
+    if (randr_mode->mode.vSyncStart   != mode->VSyncStart)  return FALSE;
+    if (randr_mode->mode.vSyncEnd     != mode->VSyncEnd)    return FALSE;
+    if (randr_mode->mode.vTotal       != mode->VTotal)	    return FALSE;
+    
+    /* check for same flags (using only the XF86 valid flag bits) */
+    if ((randr_mode->mode.modeFlags & FLAG_BITS) != (mode->Flags & FLAG_BITS))
+	return FALSE;
+    
+    /* everything matches */
+    return TRUE;
+}
+
 static Bool
 xf86RandR12CrtcNotify (RRCrtcPtr	randr_crtc)
 {
@@ -594,12 +644,15 @@ xf86RandR12CrtcNotify (RRCrtcPtr	randr_c
 	     * We make copies of modes, so pointer equality 
 	     * isn't sufficient
 	     */
-	    for (j = 0; j < randr_output->numModes; j++)
+	    for (j = 0; j < randr_output->numModes + randr_output->numUserModes; j++)
 	    {
-		DisplayModePtr	outMode = randr_output->modes[j]->devPrivate;
-		if (xf86ModesEqual(mode, outMode))
+		RRModePtr   m = (j < randr_output->numModes ?
+				 randr_output->modes[j] :
+				 randr_output->userModes[j-randr_output->numModes]);
+					 
+		if (xf86RandRModeMatches (m, mode))
 		{
-		    randr_mode = randr_output->modes[j];
+		    randr_mode = m;
 		    break;
 		}
 	    }
@@ -611,6 +664,39 @@ xf86RandR12CrtcNotify (RRCrtcPtr	randr_c
     return ret;
 }
 
+/*
+ * Convert a RandR mode to a DisplayMode
+ */
+static void
+xf86RandRModeConvert (ScrnInfoPtr	scrn,
+		      RRModePtr		randr_mode,
+		      DisplayModePtr	mode)
+{
+    mode->prev = NULL;
+    mode->next = NULL;
+    mode->name = NULL;
+    mode->status = MODE_OK;
+    mode->type = 0;
+
+    mode->Clock = randr_mode->mode.dotClock / 1000;
+    
+    mode->HDisplay = randr_mode->mode.width;
+    mode->HSyncStart = randr_mode->mode.hSyncStart;
+    mode->HSyncEnd = randr_mode->mode.hSyncEnd;
+    mode->HTotal = randr_mode->mode.hTotal;
+    mode->HSkew = randr_mode->mode.hSkew;
+    
+    mode->VDisplay = randr_mode->mode.height;
+    mode->VSyncStart = randr_mode->mode.vSyncStart;
+    mode->VSyncEnd = randr_mode->mode.vSyncEnd;
+    mode->VTotal = randr_mode->mode.vTotal;
+    mode->VScan = 0;
+
+    mode->Flags = randr_mode->mode.modeFlags & FLAG_BITS;
+
+    xf86SetModeCrtc (mode, scrn->adjustFlags);
+}
+
 static Bool
 xf86RandR12CrtcSet (ScreenPtr	pScreen,
 		  RRCrtcPtr	randr_crtc,
@@ -624,16 +710,15 @@ xf86RandR12CrtcSet (ScreenPtr	pScreen,
     ScrnInfoPtr		pScrn = xf86Screens[pScreen->myNum];
     xf86CrtcConfigPtr   config = XF86_CRTC_CONFIG_PTR(pScrn);
     xf86CrtcPtr		crtc = randr_crtc->devPrivate;
-    DisplayModePtr	mode = randr_mode ? randr_mode->devPrivate : NULL;
     Bool		changed = FALSE;
     int			o, ro;
     xf86CrtcPtr		*save_crtcs;
     Bool		save_enabled = crtc->enabled;
 
     save_crtcs = ALLOCATE_LOCAL(config->num_crtc * sizeof (xf86CrtcPtr));
-    if ((mode != NULL) != crtc->enabled)
+    if ((randr_mode != NULL) != crtc->enabled)
 	changed = TRUE;
-    else if (mode && !xf86ModesEqual (&crtc->mode, mode))
+    else if (randr_mode && !xf86RandRModeMatches (randr_mode, &crtc->mode))
 	changed = TRUE;
     
     if (rotation != crtc->rotation)
@@ -667,11 +752,14 @@ xf86RandR12CrtcSet (ScreenPtr	pScreen,
     /* XXX need device-independent mode setting code through an API */
     if (changed)
     {
-	crtc->enabled = mode != NULL;
+	crtc->enabled = randr_mode != NULL;
 
-	if (mode)
+	if (randr_mode)
 	{
-	    if (!xf86CrtcSetMode (crtc, mode, rotation, x, y))
+	    DisplayModeRec  mode;
+
+	    xf86RandRModeConvert (pScrn, randr_mode, &mode);
+	    if (!xf86CrtcSetMode (crtc, &mode, rotation, x, y))
 	    {
 		crtc->enabled = save_enabled;
 		for (o = 0; o < config->num_output; o++)
@@ -685,7 +773,7 @@ xf86RandR12CrtcSet (ScreenPtr	pScreen,
 	    /*
 	     * Save the last successful setting for EnterVT
 	     */
-	    crtc->desiredMode = *mode;
+	    crtc->desiredMode = mode;
 	    crtc->desiredRotation = rotation;
 	    crtc->desiredX = x;
 	    crtc->desiredY = y;
@@ -733,33 +821,12 @@ xf86RandR12OutputValidateMode (ScreenPtr
 			       RROutputPtr  randr_output,
 			       RRModePtr    randr_mode)
 {
+    ScrnInfoPtr	    pScrn = xf86Screens[pScreen->myNum];
     xf86OutputPtr   output = randr_output->devPrivate;
-    DisplayModePtr  mode = randr_mode->devPrivate;
+    DisplayModeRec  mode;
 
-    if (!mode)
-    {
-	mode = xalloc (sizeof (DisplayModeRec) + randr_mode->mode.nameLength + 1);
-	if (!mode)
-	    return FALSE;
-	mode->name = (char *) mode + 1;
-	memcpy (mode->name, randr_mode->name, randr_mode->mode.nameLength);
-	mode->name[randr_mode->mode.nameLength] = '\0';
-	mode->Clock = randr_mode->mode.dotClock / 1000;
-	mode->HDisplay = randr_mode->mode.width;
-	mode->HSyncStart = randr_mode->mode.hSyncStart;
-	mode->HSyncEnd = randr_mode->mode.hSyncEnd;
-	mode->HTotal = randr_mode->mode.hTotal;
-	mode->HSkew = randr_mode->mode.hSkew;
-	
-	mode->VDisplay = randr_mode->mode.height;
-	mode->VSyncStart = randr_mode->mode.vSyncStart;
-	mode->VSyncEnd = randr_mode->mode.vSyncEnd;
-	mode->VTotal = randr_mode->mode.vTotal;
-    
-	mode->Flags = randr_mode->mode.modeFlags;
-	randr_mode->devPrivate = mode;
-    }
-    if (!output->funcs->mode_valid (output, mode))
+    xf86RandRModeConvert (pScrn, randr_mode, &mode);
+    if (output->funcs->mode_valid (output, &mode) != MODE_OK)
 	return FALSE;
     return TRUE;
 }
@@ -767,13 +834,6 @@ xf86RandR12OutputValidateMode (ScreenPtr
 static void
 xf86RandR12ModeDestroy (ScreenPtr pScreen, RRModePtr randr_mode)
 {
-    DisplayModePtr  mode = randr_mode->devPrivate;
-
-    if (mode)
-    {
-	xfree (mode);
-	randr_mode->devPrivate = NULL;
-    }
 }
 
 /**
@@ -822,7 +882,6 @@ xf86RROutputSetModes (RROutputPtr randr_
 
 		    rrmode = RRModeGet (&modeInfo, mode->name);
 		    if (rrmode) {
-			rrmode->devPrivate = mode;
 			rrmodes[nmode++] = rrmode;
 			npreferred += pref;
 		    }
diff --git a/randr/randrstr.h b/randr/randrstr.h
index f6d35cf..0dee999 100644
--- a/randr/randrstr.h
+++ b/randr/randrstr.h
@@ -79,7 +79,6 @@ struct _rrMode {
     int		    refcnt;
     xRRModeInfo	    mode;
     char	    *name;
-    void	    *devPrivate;
     ScreenPtr	    userScreen;
 };
 
diff-tree 2c93083edd29a65e73bb2e8eff9d353e92845c9b (from 3bffb281260476d2f74f0bf451d85d2f7cacd6c4)
Author: Keith Packard <keithp at guitar.keithp.com>
Date:   Sun Feb 18 23:49:38 2007 -0800

    Add support for user-defined modelines in RandR.
    
    The RandR protocol spec has several requests in support of user-defined
    modes, but the implementation was stubbed out inside the X server. Fill out
    the DIX portion and start on the xf86 DDX portion. It might be necessary to
    add more code to the DDX to insert the user-defined modes into the output
    mode list.
    (cherry picked from commit 63cc2a51ef87130c632a874672a8c9167f14314e)
    
    Conflicts:
    
    	randr/randrstr.h
    
    Updated code to work in master with recent security API changes.

diff --git a/hw/xfree86/modes/xf86RandR12.c b/hw/xfree86/modes/xf86RandR12.c
index ce780b6..73647a6 100644
--- a/hw/xfree86/modes/xf86RandR12.c
+++ b/hw/xfree86/modes/xf86RandR12.c
@@ -728,6 +728,54 @@ xf86RandR12OutputSetProperty (ScreenPtr 
     return output->funcs->set_property(output, property, value);
 }
 
+static Bool
+xf86RandR12OutputValidateMode (ScreenPtr    pScreen,
+			       RROutputPtr  randr_output,
+			       RRModePtr    randr_mode)
+{
+    xf86OutputPtr   output = randr_output->devPrivate;
+    DisplayModePtr  mode = randr_mode->devPrivate;
+
+    if (!mode)
+    {
+	mode = xalloc (sizeof (DisplayModeRec) + randr_mode->mode.nameLength + 1);
+	if (!mode)
+	    return FALSE;
+	mode->name = (char *) mode + 1;
+	memcpy (mode->name, randr_mode->name, randr_mode->mode.nameLength);
+	mode->name[randr_mode->mode.nameLength] = '\0';
+	mode->Clock = randr_mode->mode.dotClock / 1000;
+	mode->HDisplay = randr_mode->mode.width;
+	mode->HSyncStart = randr_mode->mode.hSyncStart;
+	mode->HSyncEnd = randr_mode->mode.hSyncEnd;
+	mode->HTotal = randr_mode->mode.hTotal;
+	mode->HSkew = randr_mode->mode.hSkew;
+	
+	mode->VDisplay = randr_mode->mode.height;
+	mode->VSyncStart = randr_mode->mode.vSyncStart;
+	mode->VSyncEnd = randr_mode->mode.vSyncEnd;
+	mode->VTotal = randr_mode->mode.vTotal;
+    
+	mode->Flags = randr_mode->mode.modeFlags;
+	randr_mode->devPrivate = mode;
+    }
+    if (!output->funcs->mode_valid (output, mode))
+	return FALSE;
+    return TRUE;
+}
+
+static void
+xf86RandR12ModeDestroy (ScreenPtr pScreen, RRModePtr randr_mode)
+{
+    DisplayModePtr  mode = randr_mode->devPrivate;
+
+    if (mode)
+    {
+	xfree (mode);
+	randr_mode->devPrivate = NULL;
+    }
+}
+
 /**
  * Given a list of xf86 modes and a RandR Output object, construct
  * RandR modes and assign them to the output
@@ -958,6 +1006,8 @@ xf86RandR12Init12 (ScreenPtr pScreen)
     rp->rrCrtcSet = xf86RandR12CrtcSet;
     rp->rrCrtcSetGamma = xf86RandR12CrtcSetGamma;
     rp->rrOutputSetProperty = xf86RandR12OutputSetProperty;
+    rp->rrOutputValidateMode = xf86RandR12OutputValidateMode;
+    rp->rrModeDestroy = xf86RandR12ModeDestroy;
     rp->rrSetConfig = NULL;
     pScrn->PointerMoved = xf86RandR12PointerMoved;
     if (!xf86RandR12CreateObjects12 (pScreen))
diff --git a/randr/mirandr.c b/randr/mirandr.c
index 0b763e1..47136fb 100644
--- a/randr/mirandr.c
+++ b/randr/mirandr.c
@@ -73,6 +73,20 @@ miRROutputSetProperty (ScreenPtr	    pSc
     return TRUE;
 }
 
+Bool
+miRROutputValidateMode (ScreenPtr	    pScreen,
+			RROutputPtr	    output,
+			RRModePtr	    mode)
+{
+    return FALSE;
+}
+
+void
+miRRModeDestroy (ScreenPtr  pScreen,
+		 RRModePtr  mode)
+{
+}
+
 /*
  * This function assumes that only a single depth can be
  * displayed at a time, but that all visuals of that depth
@@ -102,7 +116,8 @@ miRandRInit (ScreenPtr pScreen)
     pScrPriv->rrCrtcSet = miRRCrtcSet;
     pScrPriv->rrCrtcSetGamma = miRRCrtcSetGamma;
     pScrPriv->rrOutputSetProperty = miRROutputSetProperty;
-    
+    pScrPriv->rrOutputValidateMode = miRROutputValidateMode;
+    pScrPriv->rrModeDestroy = miRRModeDestroy;
     
     RRScreenSetSizeRange (pScreen,
 			  pScreen->width, pScreen->height,
diff --git a/randr/randrstr.h b/randr/randrstr.h
index 5058212..f6d35cf 100644
--- a/randr/randrstr.h
+++ b/randr/randrstr.h
@@ -80,7 +80,7 @@ struct _rrMode {
     xRRModeInfo	    mode;
     char	    *name;
     void	    *devPrivate;
-    Bool	    userDefined;
+    ScreenPtr	    userScreen;
 };
 
 struct _rrPropertyValue {
@@ -135,6 +135,8 @@ struct _rrOutput {
     int		    numModes;
     int		    numPreferred;
     RRModePtr	    *modes;
+    int		    numUserModes;
+    RRModePtr	    *userModes;
     Bool	    changed;
     RRPropertyPtr   properties;
     void	    *devPrivate;
@@ -164,6 +166,13 @@ typedef Bool (*RROutputSetPropertyProcPt
 					    Atom		property,
 					    RRPropertyValuePtr	value);
 
+typedef Bool (*RROutputValidateModeProcPtr) (ScreenPtr		pScreen,
+					     RROutputPtr	output,
+					     RRModePtr		mode);
+
+typedef void (*RRModeDestroyProcPtr) (ScreenPtr	    pScreen,
+				      RRModePtr	    mode);
+
 #endif
 
 typedef Bool (*RRGetInfoProcPtr) (ScreenPtr pScreen, Rotation *rotations);
@@ -208,6 +217,8 @@ typedef struct _rrScrPriv {
     RRCrtcSetProcPtr	    rrCrtcSet;
     RRCrtcSetGammaProcPtr   rrCrtcSetGamma;
     RROutputSetPropertyProcPtr	rrOutputSetProperty;
+    RROutputValidateModeProcPtr	rrOutputValidateMode;
+    RRModeDestroyProcPtr	rrModeDestroy;
 #endif
     
     /*
@@ -394,6 +405,15 @@ miRROutputSetProperty (ScreenPtr	    pSc
 		       Atom		    property,
 		       RRPropertyValuePtr   value);
 
+Bool
+miRROutputValidateMode (ScreenPtr	    pScreen,
+			RROutputPtr	    output,
+			RRModePtr	    mode);
+
+void
+miRRModeDestroy (ScreenPtr  pScreen,
+		 RRModePtr  mode);
+
 /* randr.c */
 /*
  * Send all pending events
@@ -549,6 +569,11 @@ Bool
 RRCrtcSetRotations (RRCrtcPtr crtc,
 		    Rotation rotations);
 
+/*
+ * Return the area of the frame buffer scanned out by the crtc,
+ * taking into account the current mode and rotation
+ */
+
 void
 RRCrtcGetScanoutSize(RRCrtcPtr crtc, int *width, int *height);
 
@@ -672,6 +697,14 @@ RROutputSetModes (RROutputPtr	output,
 		  int		numModes,
 		  int		numPreferred);
 
+int
+RROutputAddUserMode (RROutputPtr    output,
+		     RRModePtr	    mode);
+
+int
+RROutputDeleteUserMode (RROutputPtr output,
+			RRModePtr   mode);
+
 Bool
 RROutputSetCrtcs (RROutputPtr	output,
 		  RRCrtcPtr	*crtcs,
diff --git a/randr/rrcrtc.c b/randr/rrcrtc.c
index db506f4..315dd6c 100644
--- a/randr/rrcrtc.c
+++ b/randr/rrcrtc.c
@@ -666,10 +666,15 @@ ProcRRSetCrtcConfig (ClientPtr client)
 	    return BadMatch;
 	}
 	/* validate mode for this output */
-	for (j = 0; j < outputs[i]->numModes; j++)
-	    if (outputs[i]->modes[j] == mode)
+	for (j = 0; j < outputs[i]->numModes + outputs[i]->numUserModes; j++)
+	{
+	    RRModePtr	m = (j < outputs[i]->numModes ? 
+			     outputs[i]->modes[j] :
+			     outputs[i]->userModes[j - outputs[i]->numModes]);
+	    if (m == mode)
 		break;
-	if (j == outputs[i]->numModes)
+	}
+	if (j == outputs[i]->numModes + outputs[i]->numUserModes)
 	{
 	    if (outputs)
 		xfree (outputs);
diff --git a/randr/rrinfo.c b/randr/rrinfo.c
index 797cdb1..549d501 100644
--- a/randr/rrinfo.c
+++ b/randr/rrinfo.c
@@ -157,9 +157,11 @@ RRScanOldConfig (ScreenPtr pScreen, Rota
     pScrPriv->nSizes = 0;
 	    
     /* find size bounds */
-    for (i = 0; i < output->numModes; i++) 
+    for (i = 0; i < output->numModes + output->numUserModes; i++) 
     {
-	RRModePtr   mode = output->modes[i];
+	RRModePtr   mode = (i < output->numModes ? 
+			    output->modes[i] : 
+			    output->userModes[i-output->numModes]);
         CARD16	    width = mode->mode.width;
         CARD16	    height = mode->mode.height;
 	
diff --git a/randr/rrmode.c b/randr/rrmode.c
index 261e1b7..1117581 100644
--- a/randr/rrmode.c
+++ b/randr/rrmode.c
@@ -48,25 +48,13 @@ RRModeEqual (xRRModeInfo *a, xRRModeInfo
 static int	    num_modes;
 static RRModePtr    *modes;
 
-RRModePtr
-RRModeGet (xRRModeInfo	*modeInfo,
-	   const char	*name)
+static RRModePtr
+RRModeCreate (xRRModeInfo   *modeInfo,
+	      const char    *name,
+	      ScreenPtr	    userScreen)
 {
-    int	i;
-    RRModePtr	mode;
-    RRModePtr	*newModes;
-
-    for (i = 0; i < num_modes; i++)
-    {
-	mode = modes[i];
-	if (RRModeEqual (&mode->mode, modeInfo) &&
-	    !memcmp (name, mode->name, modeInfo->nameLength))
-	{
-	    ++mode->refcnt;
-	    return mode;
-	}
-    }
-
+    RRModePtr	mode, *newModes;
+    
     if (!RRInit ())
 	return NULL;
 
@@ -78,7 +66,7 @@ RRModeGet (xRRModeInfo	*modeInfo,
     mode->name = (char *) (mode + 1);
     memcpy (mode->name, name, modeInfo->nameLength);
     mode->name[modeInfo->nameLength] = '\0';
-    mode->userDefined = FALSE;
+    mode->userScreen = userScreen;
 
     if (num_modes)
 	newModes = xrealloc (modes, (num_modes + 1) * sizeof (RRModePtr));
@@ -104,11 +92,75 @@ RRModeGet (xRRModeInfo	*modeInfo,
     return mode;
 }
 
+static RRModePtr
+RRModeFindByName (const char	*name,
+		  CARD16    	nameLength)
+{
+    int		i;
+    RRModePtr	mode;
+
+    for (i = 0; i < num_modes; i++)
+    {
+	mode = modes[i];
+	if (mode->mode.nameLength == nameLength &&
+	    !memcmp (name, mode->name, nameLength))
+	{
+	    return mode;
+	}
+    }
+    return NULL;
+}
+
+RRModePtr
+RRModeGet (xRRModeInfo	*modeInfo,
+	   const char	*name)
+{
+    int	i;
+
+    for (i = 0; i < num_modes; i++)
+    {
+	RRModePtr   mode = modes[i];
+	if (RRModeEqual (&mode->mode, modeInfo) &&
+	    !memcmp (name, mode->name, modeInfo->nameLength))
+	{
+	    ++mode->refcnt;
+	    return mode;
+	}
+    }
+
+    return RRModeCreate (modeInfo, name, NULL);
+}
+
+static RRModePtr
+RRModeCreateUser (ScreenPtr	pScreen,
+		  xRRModeInfo	*modeInfo,
+		  const char	*name,
+		  int		*error)
+{
+    RRModePtr	mode;
+
+    mode = RRModeFindByName (name, modeInfo->nameLength);
+    if (mode)
+    {
+	*error = BadName;
+	return NULL;
+    }
+    
+    mode = RRModeCreate (modeInfo, name, pScreen);
+    if (!mode)
+    {
+	*error = BadAlloc;
+	return NULL;
+    }
+    *error = Success;
+    return mode;
+}
+
 RRModePtr *
 RRModesForScreen (ScreenPtr pScreen, int *num_ret)
 {
     rrScrPriv(pScreen);
-    int	o, c;
+    int		o, c, m;
     RRModePtr	*screen_modes;
     int		num_screen_modes = 0;
 
@@ -122,9 +174,11 @@ RRModesForScreen (ScreenPtr pScreen, int
 	RROutputPtr	output = pScrPriv->outputs[o];
 	int		m, n;
 
-	for (m = 0; m < output->numModes; m++)
+	for (m = 0; m < output->numModes + output->numUserModes; m++)
 	{
-	    RRModePtr	mode = output->modes[m];
+	    RRModePtr   mode = (m < output->numModes ? 
+				output->modes[m] : 
+				output->userModes[m-output->numModes]);
 	    for (n = 0; n < num_screen_modes; n++)
 		if (screen_modes[n] == mode)
 		    break;
@@ -150,6 +204,23 @@ RRModesForScreen (ScreenPtr pScreen, int
 	if (n == num_screen_modes)
 	    screen_modes[num_screen_modes++] = mode;
     }
+    /*
+     * Add all user modes for this screen
+     */
+    for (m = 0; m < num_modes; m++)
+    {
+	RRModePtr	mode = modes[m];
+	int		n;
+
+	if (mode->userScreen != pScreen)
+	    continue;
+	for (n = 0; n < num_screen_modes; n++)
+	    if (screen_modes[n] == mode)
+		break;
+	if (n == num_screen_modes)
+	    screen_modes[num_screen_modes++] = mode;
+    }
+    
     *num_ret = num_screen_modes;
     return screen_modes;
 }
@@ -205,38 +276,122 @@ int
 ProcRRCreateMode (ClientPtr client)
 {
     REQUEST(xRRCreateModeReq);
+    xRRCreateModeReply	rep;
+    WindowPtr		pWin;
+    ScreenPtr		pScreen;
+    rrScrPrivPtr	pScrPriv;
+    xRRModeInfo		*modeInfo;
+    long		units_after;
+    char		*name;
+    int			error, rc;
+    RRModePtr		mode;
+    
+    REQUEST_AT_LEAST_SIZE (xRRCreateModeReq);
+    rc = dixLookupWindow(&pWin, stuff->window, client, DixReadAccess);
+    if (rc != Success)
+	return rc;
+
+    pScreen = pWin->drawable.pScreen;
+    pScrPriv = rrGetScrPriv(pScreen);
+    
+    modeInfo = &stuff->modeInfo;
+    name = (char *) (stuff + 1);
+    units_after = (stuff->length - (sizeof (xRRCreateModeReq) >> 2));
+
+    /* check to make sure requested name fits within the data provided */
+    if ((int) (modeInfo->nameLength + 3) >> 2 > units_after)
+	return BadLength;
+
+    mode = RRModeCreateUser (pScreen, modeInfo, name, &error);
+    if (!mode)
+	return error;
+
+    rep.type = X_Reply;
+    rep.pad0 = 0;
+    rep.sequenceNumber = client->sequence;
+    rep.length = 0;
+    rep.mode = mode->mode.id;
+    if (client->swapped)
+    {
+	int n;
+    	swaps(&rep.sequenceNumber, n);
+    	swapl(&rep.length, n);
+	swapl(&rep.mode, n);
+    }
+    WriteToClient(client, sizeof(xRRCreateModeReply), (char *)&rep);
     
-    REQUEST_SIZE_MATCH(xRRCreateModeReq);
-    (void) stuff;
-    return BadImplementation; 
+    return client->noClientException;
 }
 
 int
 ProcRRDestroyMode (ClientPtr client)
 {
     REQUEST(xRRDestroyModeReq);
+    RRModePtr	mode;
     
     REQUEST_SIZE_MATCH(xRRDestroyModeReq);
-    (void) stuff;
-    return BadImplementation; 
+    mode = LookupIDByType (stuff->mode, RRModeType);
+    if (!mode)
+    {
+	client->errorValue = stuff->mode;
+	return RRErrorBase + BadRRMode;
+    }
+    if (!mode->userScreen)
+	return BadMatch;
+    if (mode->refcnt > 1)
+	return BadAccess;
+    FreeResource (stuff->mode, 0);
+    return Success;
 }
 
 int
 ProcRRAddOutputMode (ClientPtr client)
 {
     REQUEST(xRRAddOutputModeReq);
+    RRModePtr	mode;
+    RROutputPtr	output;
     
     REQUEST_SIZE_MATCH(xRRAddOutputModeReq);
-    (void) stuff;
-    return BadImplementation; 
+    output = LookupOutput(client, stuff->output, DixReadAccess);
+
+    if (!output)
+    {
+	client->errorValue = stuff->output;
+	return RRErrorBase + BadRROutput;
+    }
+    
+    mode = LookupIDByType (stuff->mode, RRModeType);
+    if (!mode)
+    {
+	client->errorValue = stuff->mode;
+	return RRErrorBase + BadRRMode;
+    }
+    
+    return RROutputAddUserMode (output, mode);
 }
 
 int
 ProcRRDeleteOutputMode (ClientPtr client)
 {
     REQUEST(xRRDeleteOutputModeReq);
+    RRModePtr	mode;
+    RROutputPtr	output;
     
     REQUEST_SIZE_MATCH(xRRDeleteOutputModeReq);
-    (void) stuff;
-    return BadImplementation; 
+    output = LookupOutput(client, stuff->output, DixReadAccess);
+
+    if (!output)
+    {
+	client->errorValue = stuff->output;
+	return RRErrorBase + BadRROutput;
+    }
+    
+    mode = LookupIDByType (stuff->mode, RRModeType);
+    if (!mode)
+    {
+	client->errorValue = stuff->mode;
+	return RRErrorBase + BadRRMode;
+    }
+    
+    return RROutputDeleteUserMode (output, mode);
 }
diff --git a/randr/rroutput.c b/randr/rroutput.c
index df1741f..6e95c95 100644
--- a/randr/rroutput.c
+++ b/randr/rroutput.c
@@ -76,6 +76,8 @@ RROutputCreate (const char  *name,
     output->numModes = 0;
     output->numPreferred = 0;
     output->modes = NULL;
+    output->numUserModes = 0;
+    output->userModes = NULL;
     output->properties = NULL;
     output->changed = FALSE;
     output->devPrivate = devPrivate;
@@ -192,6 +194,74 @@ RROutputSetModes (RROutputPtr	output,
     return TRUE;
 }
 
+int
+RROutputAddUserMode (RROutputPtr    output,
+		     RRModePtr	    mode)
+{
+    int		m;
+    ScreenPtr	pScreen = output->pScreen;
+    rrScrPriv(pScreen);
+    RRModePtr	*newModes;
+
+    /* Check to see if this mode is already listed for this output */
+    for (m = 0; m < output->numModes + output->numUserModes; m++)
+    {
+	RRModePtr   e = (m < output->numModes ?
+			 output->modes[m] :
+			 output->userModes[m - output->numModes]);
+	if (mode == e)
+	    return Success;
+    }
+
+    /* Check with the DDX to see if this mode is OK */
+    if (pScrPriv->rrOutputValidateMode)
+	if (!pScrPriv->rrOutputValidateMode (pScreen, output, mode))
+	    return BadMatch;
+
+    if (output->userModes)
+	newModes = xrealloc (output->userModes,
+			     (output->numUserModes + 1) * sizeof (RRModePtr));
+    else
+	newModes = xalloc (sizeof (RRModePtr));
+    if (!newModes)
+	return BadAlloc;
+
+    output->userModes = newModes;
+    output->userModes[output->numUserModes++] = mode;
+    ++mode->refcnt;
+    RROutputChanged (output, TRUE);
+    RRTellChanged (pScreen);
+    return Success;
+}
+
+int
+RROutputDeleteUserMode (RROutputPtr output,
+			RRModePtr   mode)
+{
+    int		m;
+    
+    /* Find this mode in the user mode list */
+    for (m = 0; m < output->numUserModes; m++)
+    {
+	RRModePtr   e = output->userModes[m];
+
+	if (mode == e)
+	    break;
+    }
+    /* Not there, access error */
+    if (m == output->numUserModes)
+	return BadAccess;
+
+    /* make sure the mode isn't active for this output */
+    if (output->crtc && output->crtc->mode == mode)
+	return BadMatch;
+
+    memmove (output->userModes + m, output->userModes + m + 1,
+	     (output->numUserModes - m - 1) * sizeof (RRModePtr));
+    RRModeDestroy (mode);
+    return Success;
+}
+
 Bool
 RROutputSetCrtcs (RROutputPtr	output,
 		  RRCrtcPtr	*crtcs,
@@ -308,9 +378,9 @@ RRDeliverOutputEvent(ClientPtr client, W
  * Destroy a Output at shutdown
  */
 void
-RROutputDestroy (RROutputPtr crtc)
+RROutputDestroy (RROutputPtr output)
 {
-    FreeResource (crtc->id, 0);
+    FreeResource (output->id, 0);
 }
 
 static int
@@ -318,6 +388,7 @@ RROutputDestroyResource (pointer value, 
 {
     RROutputPtr	output = (RROutputPtr) value;
     ScreenPtr	pScreen = output->pScreen;
+    int		m;
 
     if (pScreen)
     {
@@ -335,8 +406,15 @@ RROutputDestroyResource (pointer value, 
 	    }
 	}
     }
+    /* XXX destroy all modes? */
     if (output->modes)
 	xfree (output->modes);
+    
+    for (m = 0; m < output->numUserModes; m++)
+	RRModeDestroy (output->userModes[m]);
+    if (output->userModes)
+	xfree (output->userModes);
+
     if (output->crtcs)
 	xfree (output->crtcs);
     if (output->clones)
@@ -383,7 +461,10 @@ ProcRRGetOutputInfo (ClientPtr client)
     output = LookupOutput(client, stuff->output, DixReadAccess);
 
     if (!output)
+    {
+	client->errorValue = stuff->output;
 	return RRErrorBase + BadRROutput;
+    }
 
     pScreen = output->pScreen;
     pScrPriv = rrGetScrPriv(pScreen);
@@ -398,13 +479,13 @@ ProcRRGetOutputInfo (ClientPtr client)
     rep.connection = output->connection;
     rep.subpixelOrder = output->subpixelOrder;
     rep.nCrtcs = output->numCrtcs;
-    rep.nModes = output->numModes;
+    rep.nModes = output->numModes + output->numUserModes;
     rep.nPreferred = output->numPreferred;
     rep.nClones = output->numClones;
     rep.nameLength = output->nameLength;
     
     extraLen = ((output->numCrtcs + 
-		 output->numModes + 
+		 output->numModes + output->numUserModes +
 		 output->numClones +
 		 ((rep.nameLength + 3) >> 2)) << 2);
 
@@ -420,7 +501,7 @@ ProcRRGetOutputInfo (ClientPtr client)
 
     crtcs = (RRCrtc *) extra;
     modes = (RRMode *) (crtcs + output->numCrtcs);
-    clones = (RROutput *) (modes + output->numModes);
+    clones = (RROutput *) (modes + output->numModes + output->numUserModes);
     name = (char *) (clones + output->numClones);
     
     for (i = 0; i < output->numCrtcs; i++)
@@ -429,9 +510,12 @@ ProcRRGetOutputInfo (ClientPtr client)
 	if (client->swapped)
 	    swapl (&crtcs[i], n);
     }
-    for (i = 0; i < output->numModes; i++)
+    for (i = 0; i < output->numModes + output->numUserModes; i++)
     {
-	modes[i] = output->modes[i]->mode.id;
+	if (i < output->numModes)
+	    modes[i] = output->modes[i]->mode.id;
+	else
+	    modes[i] = output->userModes[i - output->numModes]->mode.id;
 	if (client->swapped)
 	    swapl (&modes[i], n);
     }
diff --git a/randr/rrscreen.c b/randr/rrscreen.c
index 1680003..ad74ac3 100644
--- a/randr/rrscreen.c
+++ b/randr/rrscreen.c
@@ -473,7 +473,7 @@ RR10GetData (ScreenPtr pScreen, RROutput
 {
     RR10DataPtr	    data;
     RRScreenSizePtr size;
-    int		    nmode = output->numModes;
+    int		    nmode = output->numModes + output->numUserModes;
     int		    o, os, l, r;
     RRScreenRatePtr refresh;
     CARD16	    vRefresh;
@@ -500,11 +500,14 @@ RR10GetData (ScreenPtr pScreen, RROutput
     /*
      * find modes not yet listed
      */
-    for (o = 0; o < output->numModes; o++)
+    for (o = 0; o < output->numModes + output->numUserModes; o++)
     {
 	if (used[o]) continue;
 	
-	mode = output->modes[o];
+	if (o < output->numModes)
+	    mode = output->modes[o];
+	else
+	    mode = output->userModes[o - output->numModes];
 	
 	l = data->nsize;
 	size[l].id = data->nsize;
@@ -524,9 +527,12 @@ RR10GetData (ScreenPtr pScreen, RROutput
 	/*
 	 * Find all modes with matching size
 	 */
-	for (os = o; os < output->numModes; os++)
+	for (os = o; os < output->numModes + output->numUserModes; os++)
 	{
-	    mode = output->modes[os];
+	    if (os < output->numModes)
+		mode = output->modes[os];
+	    else
+		mode = output->userModes[os - output->numModes];
 	    if (mode->mode.width == size[l].width &&
 		mode->mode.height == size[l].height)
 	    {
diff-tree 3bffb281260476d2f74f0bf451d85d2f7cacd6c4 (from 9562b6abe1da566cf73a08c4f4c4339fb67fbc71)
Author: Keith Packard <keithp at neko.keithp.com>
Date:   Thu Mar 15 16:16:16 2007 -0700

    Don't wedge when rotating more than one CRTC.
    
    Rotation block handler was re-registering the rotation damage structure,
    creating an infinite loop in the damage code. Track registration of the
    damage structure to avoid this.
    (cherry picked from commit b14f003b0ed1252766c9e3b1c086ea2809521047)

diff --git a/hw/xfree86/modes/xf86Crtc.h b/hw/xfree86/modes/xf86Crtc.h
index df8a8aa..b751592 100644
--- a/hw/xfree86/modes/xf86Crtc.h
+++ b/hw/xfree86/modes/xf86Crtc.h
@@ -529,7 +529,8 @@ typedef struct _xf86CrtcConfig {
     int			maxWidth, maxHeight;
     
     /* For crtc-based rotation */
-    DamagePtr   rotationDamage;
+    DamagePtr		rotation_damage;
+    Bool		rotation_damage_registered;
 
     /* DGA */
     unsigned int	dga_flags;
diff --git a/hw/xfree86/modes/xf86Rotate.c b/hw/xfree86/modes/xf86Rotate.c
index 6826b62..e82b69e 100644
--- a/hw/xfree86/modes/xf86Rotate.c
+++ b/hw/xfree86/modes/xf86Rotate.c
@@ -251,9 +251,13 @@ xf86RotatePrepare (ScreenPtr pScreen)
 							     crtc->rotatedData,
 							     crtc->mode.HDisplay,
 							     crtc->mode.VDisplay);
-	    /* Hook damage to screen pixmap */
-	    DamageRegister (&(*pScreen->GetScreenPixmap)(pScreen)->drawable,
-			    xf86_config->rotationDamage);
+	    if (!xf86_config->rotation_damage_registered)
+	    {
+		/* Hook damage to screen pixmap */
+		DamageRegister (&(*pScreen->GetScreenPixmap)(pScreen)->drawable,
+				xf86_config->rotation_damage);
+		xf86_config->rotation_damage_registered = TRUE;
+	    }
 	    
 	    xf86CrtcDamageShadow (crtc);
 	}
@@ -265,7 +269,7 @@ xf86RotateRedisplay(ScreenPtr pScreen)
 {
     ScrnInfoPtr		pScrn = xf86Screens[pScreen->myNum];
     xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
-    DamagePtr		damage = xf86_config->rotationDamage;
+    DamagePtr		damage = xf86_config->rotation_damage;
     RegionPtr		region;
 
     if (!damage)
@@ -334,13 +338,14 @@ xf86CrtcRotate (xf86CrtcPtr crtc, Displa
 	    crtc->rotatedData = NULL;
 	}
 
-	if (xf86_config->rotationDamage)
+	if (xf86_config->rotation_damage)
 	{
 	    /* Free damage structure */
 	    DamageUnregister (&(*pScreen->GetScreenPixmap)(pScreen)->drawable,
-			      xf86_config->rotationDamage);
-	    DamageDestroy (xf86_config->rotationDamage);
-	    xf86_config->rotationDamage = NULL;
+			      xf86_config->rotation_damage);
+	    xf86_config->rotation_damage_registered = FALSE;
+	    DamageDestroy (xf86_config->rotation_damage);
+	    xf86_config->rotation_damage = NULL;
 	    /* Free block/wakeup handler */
 	    RemoveBlockAndWakeupHandlers (xf86RotateBlockHandler,
 					  xf86RotateWakeupHandler,
@@ -382,13 +387,13 @@ xf86CrtcRotate (xf86CrtcPtr crtc, Displa
 	    xf86CrtcDamageShadow (crtc);
 	}
 	
-	if (!xf86_config->rotationDamage)
+	if (!xf86_config->rotation_damage)
 	{
 	    /* Create damage structure */
-	    xf86_config->rotationDamage = DamageCreate (NULL, NULL,
+	    xf86_config->rotation_damage = DamageCreate (NULL, NULL,
 						DamageReportNone,
 						TRUE, pScreen, pScreen);
-	    if (!xf86_config->rotationDamage)
+	    if (!xf86_config->rotation_damage)
 		goto bail2;
 	    
 	    /* Assign block/wakeup handler */
@@ -402,8 +407,8 @@ xf86CrtcRotate (xf86CrtcPtr crtc, Displa
 	if (0)
 	{
 bail3:
-	    DamageDestroy (xf86_config->rotationDamage);
-	    xf86_config->rotationDamage = NULL;
+	    DamageDestroy (xf86_config->rotation_damage);
+	    xf86_config->rotation_damage = NULL;
 	    
 bail2:
 	    if (shadow || shadowData)
diff-tree 9562b6abe1da566cf73a08c4f4c4339fb67fbc71 (from 3b71b0f89f1db837da91650baa0ef4bb7ef2e98f)
Author: Keith Packard <keithp at neko.keithp.com>
Date:   Thu Mar 15 10:50:45 2007 -0700

    Allow xf86_reload_cursors during server init.
    
    xf86_reload_cursors is supposed to be called from the crtc mode setting
    commit hook; as that happens during server initialization, check for this
    case.
    (cherry picked from commit 5b77bf2d020b1ee56c1c5f2db089a8f7f64a76a6)

diff --git a/hw/xfree86/modes/xf86Cursors.c b/hw/xfree86/modes/xf86Cursors.c
index 095df48..009cccf 100644
--- a/hw/xfree86/modes/xf86Cursors.c
+++ b/hw/xfree86/modes/xf86Cursors.c
@@ -548,12 +548,24 @@ xf86_cursors_init (ScreenPtr screen, int
 void
 xf86_reload_cursors (ScreenPtr screen)
 {
-    ScrnInfoPtr		scrn = xf86Screens[screen->myNum];
-    xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
-    xf86CursorInfoPtr	cursor_info = xf86_config->cursor_info;
-    CursorPtr		cursor = xf86_config->cursor;
+    ScrnInfoPtr		scrn;
+    xf86CrtcConfigPtr   xf86_config;
+    xf86CursorInfoPtr   cursor_info;
+    CursorPtr		cursor;
     int			x, y;
     
+    /* initial mode setting will not have set a screen yet */
+    if (!screen)
+	return;
+    scrn = xf86Screens[screen->myNum];
+    xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+
+    /* make sure the cursor code has been initialized */
+    cursor_info = xf86_config->cursor_info;
+    if (!cursor_info)
+	return;
+    
+    cursor = xf86_config->cursor;
     GetSpritePosition (&x, &y);
     if (!(cursor_info->Flags & HARDWARE_CURSOR_UPDATE_UNHIDDEN))
 	(*cursor_info->HideCursor)(scrn);
diff-tree 3b71b0f89f1db837da91650baa0ef4bb7ef2e98f (from 2fe74ef339c3a4902ae8214f5a0454662895422c)
Author: Eric Anholt <eric at anholt.net>
Date:   Thu Mar 15 13:21:00 2007 -0700

    Set the RandR version returned, rather than just passing the proto's version.

diff --git a/randr/rrdispatch.c b/randr/rrdispatch.c
index 7f98965..5525427 100644
--- a/randr/rrdispatch.c
+++ b/randr/rrdispatch.c
@@ -22,6 +22,9 @@
 
 #include "randrstr.h"
 
+#define SERVER_RANDR_MAJOR	1
+#define SERVER_RANDR_MINOR	2
+
 Bool
 RRClientKnowsRates (ClientPtr	pClient)
 {
@@ -49,8 +52,8 @@ ProcRRQueryVersion (ClientPtr client)
      * Report the current version; the current
      * spec says they're all compatible after 1.0
      */
-    rep.majorVersion = RANDR_MAJOR;
-    rep.minorVersion = RANDR_MINOR;
+    rep.majorVersion = SERVER_RANDR_MAJOR;
+    rep.minorVersion = SERVER_RANDR_MINOR;
     if (client->swapped) {
     	swaps(&rep.sequenceNumber, n);
     	swapl(&rep.length, n);
diff-tree 2fe74ef339c3a4902ae8214f5a0454662895422c (from ae75019ccf1edac9e8be31b6a96293624f672ccb)
Author: Matthias Hopf <mhopf at suse.de>
Date:   Thu Mar 15 16:56:01 2007 +0100

    Fix calculations in x86 emulator for the long long case (Andreas Schwab).

diff --git a/hw/xfree86/x86emu/prim_ops.c b/hw/xfree86/x86emu/prim_ops.c
index 461e09e..b9e7257 100644
--- a/hw/xfree86/x86emu/prim_ops.c
+++ b/hw/xfree86/x86emu/prim_ops.c
@@ -2082,7 +2082,7 @@ Implements the IMUL instruction and side
 void imul_long_direct(u32 *res_lo, u32* res_hi,u32 d, u32 s)
 {
 #ifdef	__HAS_LONG_LONG__
-	s64 res = (s32)d * (s32)s;
+	s64 res = (s64)(s32)d * (s32)s;
 
 	*res_lo = (u32)res;
 	*res_hi = (u32)(res >> 32);
@@ -2174,7 +2174,7 @@ Implements the MUL instruction and side 
 void mul_long(u32 s)
 {
 #ifdef	__HAS_LONG_LONG__
-	u64 res = (u32)M.x86.R_EAX * (u32)s;
+	u64 res = (u64)M.x86.R_EAX * s;
 
 	M.x86.R_EAX = (u32)res;
 	M.x86.R_EDX = (u32)(res >> 32);
diff-tree ae75019ccf1edac9e8be31b6a96293624f672ccb (from 4bf1b280f7cb676ec2b172f26dd2ad9bac2eb2ca)
Author: Keith Packard <keithp at guitar.keithp.com>
Date:   Wed Mar 14 23:59:29 2007 -0700

    Create driver-independent CRTC-based cursor layer.
    
    This moves most of the cursor management code out of the intel driver and
    into the general server code. Of course, the hope is that this code will be
    useful for other driver writers as well.
    
    Check out xf86Crtc.h for the usage information, making sure you add the
    needed hooks to the crtc funcs structure for your driver.
    (cherry picked from commit 4d81c99a4660a0bf9014f789de55edabd185bd14)

diff --git a/hw/xfree86/Makefile.am b/hw/xfree86/Makefile.am
index b669063..50aa673 100644
--- a/hw/xfree86/Makefile.am
+++ b/hw/xfree86/Makefile.am
@@ -56,6 +56,7 @@ XORG_LIBS = \
             parser/libxf86config.a \
 	    dixmods/libdixmods.la \
 	    modes/libxf86modes.a \
+	    ramdac/libramdac.a \
 	    ddc/libddc.a \
 	    i2c/libi2c.a \
             @XORG_LIBS@
diff --git a/hw/xfree86/loader/Makefile.am b/hw/xfree86/loader/Makefile.am
index ceb66a2..ef9ab9a 100644
--- a/hw/xfree86/loader/Makefile.am
+++ b/hw/xfree86/loader/Makefile.am
@@ -2,7 +2,8 @@ noinst_LIBRARIES = libloader.a
 
 INCLUDES = $(XORG_INCS) -I$(srcdir)/../parser -I$(srcdir)/../dixmods/extmod \
 	   -I$(srcdir)/../vbe -I$(top_srcdir)/miext/cw -I$(srcdir)/../int10 \
-	   -I$(srcdir)/../ddc -I$(srcdir)/../i2c -I$(srcdir)/../modes
+	   -I$(srcdir)/../ddc -I$(srcdir)/../i2c -I$(srcdir)/../modes \
+	   -I$(srcdir)/../ramdac
 
 #AM_LDFLAGS = -r
 AM_CFLAGS = -DIN_LOADER $(DIX_CFLAGS) $(XORG_CFLAGS)
diff --git a/hw/xfree86/loader/loadmod.c b/hw/xfree86/loader/loadmod.c
index e489212..c220d8a 100644
--- a/hw/xfree86/loader/loadmod.c
+++ b/hw/xfree86/loader/loadmod.c
@@ -841,6 +841,7 @@ DuplicateModule(ModuleDescPtr mod, Modul
 static const char *compiled_in_modules[] = {
     "ddc",
     "i2c",
+    "ramdac",
     NULL
 };
 
@@ -861,7 +862,7 @@ doLoadModule(const char *module, const c
     PatternPtr patterns = NULL;
     int noncanonical = 0;
     char *m = NULL;
-    char **cim;
+    const char **cim;
 
     xf86MsgVerb(X_INFO, 3, "LoadModule: \"%s\"", module);
 
diff --git a/hw/xfree86/loader/xf86sym.c b/hw/xfree86/loader/xf86sym.c
index 6337265..bc7c814 100644
--- a/hw/xfree86/loader/xf86sym.c
+++ b/hw/xfree86/loader/xf86sym.c
@@ -1220,6 +1220,11 @@ _X_HIDDEN void *xfree86LookupTab[] = {
     SYMFUNC(xf86RandR12SetConfig)
     SYMFUNC(xf86RandR12SetRotations)
 #endif
+    SYMFUNC(xf86_cursors_init)
+    SYMFUNC(xf86_reload_cursors)
+    SYMFUNC(xf86_show_cursors)
+    SYMFUNC(xf86_hide_cursors)
+    SYMFUNC(xf86_cursors_fini)
 
     SYMFUNC(xf86DoEDID_DDC1)
     SYMFUNC(xf86DoEDID_DDC2)
diff --git a/hw/xfree86/modes/Makefile.am b/hw/xfree86/modes/Makefile.am
index e0b6136..1f82068 100644
--- a/hw/xfree86/modes/Makefile.am
+++ b/hw/xfree86/modes/Makefile.am
@@ -3,6 +3,7 @@ noinst_LIBRARIES = libxf86modes.a
 libxf86modes_a_SOURCES = \
 	xf86Crtc.c \
 	xf86Crtc.h \
+	xf86Cursors.c \
 	xf86cvt.c \
 	xf86DiDGA.c \
 	xf86EdidModes.c \
@@ -16,7 +17,8 @@ libxf86modes_a_SOURCES = \
 INCLUDES = $(XORG_INCS) -I$(srcdir)/../ddc -I$(srcdir)/../i2c \
 	   -I$(srcdir)/../loader -I$(srcdir)/../rac -I$(srcdir)/../parser \
            -I$(srcdir)/../scanpci -I$(srcdir)/../vbe -I$(srcdir)/../int10 \
-	   -I$(srcdir)/../vgahw -I$(srcdir)/../dixmods/extmod
+	   -I$(srcdir)/../vgahw -I$(srcdir)/../ramdac \
+	   -I$(srcdir)/../dixmods/extmod
 
 sdk_HEADERS = \
 	xf86Crtc.h \
diff --git a/hw/xfree86/modes/xf86Crtc.h b/hw/xfree86/modes/xf86Crtc.h
index 6152ae4..df8a8aa 100644
--- a/hw/xfree86/modes/xf86Crtc.h
+++ b/hw/xfree86/modes/xf86Crtc.h
@@ -28,6 +28,7 @@
 #include "xf86Rename.h"
 #endif
 #include "xf86Modes.h"
+#include "xf86Cursor.h"
 #include "damage.h"
 
 /* Compat definitions for older X Servers. */
@@ -37,6 +38,9 @@
 #ifndef M_T_DRIVER
 #define M_T_DRIVER	0x40
 #endif
+#ifndef HARDWARE_CURSOR_ARGB
+#define HARDWARE_CURSOR_ARGB				0x00004000
+#endif
 
 typedef struct _xf86Crtc xf86CrtcRec, *xf86CrtcPtr;
 typedef struct _xf86Output xf86OutputRec, *xf86OutputPtr;
@@ -155,6 +159,42 @@ typedef struct _xf86CrtcFuncs {
     (*shadow_destroy) (xf86CrtcPtr crtc, PixmapPtr pPixmap, void *data);
 
     /**
+     * Set cursor colors
+     */
+    void
+    (*set_cursor_colors) (xf86CrtcPtr crtc, int bg, int fg);
+
+    /**
+     * Set cursor position
+     */
+    void
+    (*set_cursor_position) (xf86CrtcPtr crtc, int x, int y);
+
+    /**
+     * Show cursor
+     */
+    void
+    (*show_cursor) (xf86CrtcPtr crtc);
+
+    /**
+     * Hide cursor
+     */
+    void
+    (*hide_cursor) (xf86CrtcPtr crtc);
+
+    /**
+     * Load monochrome image
+     */
+    void
+    (*load_cursor_image) (xf86CrtcPtr crtc, CARD8 *image);
+
+    /**
+     * Load ARGB image
+     */
+     void
+     (*load_cursor_argb) (xf86CrtcPtr crtc, CARD32 *image);
+     
+    /**
      * Clean up driver-specific bits of the crtc
      */
     void
@@ -174,12 +214,6 @@ struct _xf86Crtc {
      */
     Bool	    enabled;
     
-    /** Track whether cursor is within CRTC range  */
-    Bool	    cursorInRange;
-    
-    /** Track state of cursor associated with this CRTC */
-    Bool	    cursorShown;
-    
     /**
      * Active mode
      *
@@ -232,6 +266,19 @@ struct _xf86Crtc {
 #else
     void	    *randr_crtc;
 #endif
+
+    /**
+     * Current cursor is ARGB
+     */
+    Bool	    cursor_argb;
+    /**
+     * Track whether cursor is within CRTC range 
+     */
+    Bool	    cursor_in_range;
+    /**
+     * Track state of cursor associated with this CRTC
+     */
+    Bool	    cursor_shown;
 };
 
 typedef struct _xf86OutputFuncs {
@@ -495,6 +542,13 @@ typedef struct _xf86CrtcConfig {
     const xf86CrtcConfigFuncsRec *funcs;
 
     CreateScreenResourcesProcPtr    CreateScreenResources;
+
+    /* Cursor information */
+    xf86CursorInfoPtr	cursor_info;
+    CursorPtr		cursor;
+    CARD8		*cursor_image;
+    Bool		cursor_on;
+    CARD32		cursor_fg, cursor_bg;
 } xf86CrtcConfigRec, *xf86CrtcConfigPtr;
 
 extern int xf86CrtcConfigPrivateIndex;
@@ -637,4 +691,41 @@ xf86ConnectorGetName(xf86ConnectorType c
 Bool
 xf86SetDesiredModes (ScrnInfoPtr pScrn);
 
+/**
+ * Initialize the CRTC-based cursor code. CRTC function vectors must
+ * contain relevant cursor setting functions.
+ *
+ * Driver should call this from ScreenInit function
+ */
+Bool
+xf86_cursors_init (ScreenPtr screen, int max_width, int max_height, int flags);
+
+/**
+ * Called when anything on the screen is reconfigured.
+ *
+ * Reloads cursor images as needed, then adjusts cursor positions.
+ * 
+ * Driver should call this from crtc commit function.
+ */
+void
+xf86_reload_cursors (ScreenPtr screen);
+
+/**
+ * Called from EnterVT to turn the cursors back on
+ */
+void
+xf86_show_cursors (ScrnInfoPtr scrn);
+
+/**
+ * Called by the driver to turn cursors off
+ */
+void
+xf86_hide_cursors (ScrnInfoPtr scrn);
+
+/**
+ * Clean up CRTC-based cursor code. Driver must call this at CloseScreen time.
+ */
+void
+xf86_cursors_fini (ScreenPtr screen);
+    
 #endif /* _XF86CRTC_H_ */
diff --git a/hw/xfree86/modes/xf86Cursors.c b/hw/xfree86/modes/xf86Cursors.c
new file mode 100644
index 0000000..095df48
--- /dev/null
+++ b/hw/xfree86/modes/xf86Cursors.c
@@ -0,0 +1,595 @@
+/*
+ * Copyright © 2007 Keith Packard
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission.  The copyright holders make no representations
+ * about the suitability of this software for any purpose.  It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#else
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#endif
+
+#include <stddef.h>
+#include <string.h>
+#include <stdio.h>
+
+#include "xf86.h"
+#include "xf86DDC.h"
+#include "xf86Crtc.h"
+#include "xf86Modes.h"
+#include "xf86RandR12.h"
+#include "X11/extensions/render.h"
+#define DPMS_SERVER
+#include "X11/extensions/dpms.h"
+#include "X11/Xatom.h"
+#ifdef RENDER
+#include "picturestr.h"
+#endif
+#include "cursorstr.h"
+
+/*
+ * Given a screen coordinate, rotate back to a cursor source coordinate
+ */
+static void
+xf86_crtc_rotate_coord (Rotation    rotation,
+			int	    width,
+			int	    height,
+			int	    x_dst,
+			int	    y_dst,
+			int	    *x_src,
+			int	    *y_src)
+{
+    if (rotation & RR_Reflect_X)
+	x_dst = width - x_dst - 1;
+    if (rotation & RR_Reflect_Y)
+	y_dst = height - y_dst - 1;
+    
+    switch (rotation & 0xf) {
+    case RR_Rotate_0:
+	*x_src = x_dst;
+	*y_src = y_dst;
+	break;
+    case RR_Rotate_90:
+	*x_src = height - y_dst - 1;
+	*y_src = x_dst;
+	break;
+    case RR_Rotate_180:
+	*x_src = width - x_dst - 1;
+	*y_src = height - y_dst - 1;
+	break;
+    case RR_Rotate_270:
+	*x_src = y_dst;
+	*y_src = width - x_dst - 1;
+	break;
+    }
+}
+
+/*
+ * Convert an x coordinate to a position within the cursor bitmap
+ */
+static int
+cursor_bitpos (int flags, int x, Bool mask)
+{
+    if (flags & HARDWARE_CURSOR_SWAP_SOURCE_AND_MASK)
+	mask = !mask;
+    if (flags & HARDWARE_CURSOR_NIBBLE_SWAPPED)
+	x = (x & ~3) | (3 - (x & 3));
+    if (flags & HARDWARE_CURSOR_BIT_ORDER_MSBFIRST)
+	x = (x & ~7) | (7 - (x & 7));
+    if (flags & HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_1)
+	x = (x << 1) + mask;
+    else if (flags & HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_8)
+	x = ((x & ~7) << 1) | (mask << 3) | (x & 7);
+    else if (flags & HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_16)
+	x = ((x & ~15) << 1) | (mask << 4) | (x & 15);
+    else if (flags & HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_32)
+	x = ((x & ~31) << 1) | (mask << 5) | (x & 31);
+    else if (flags & HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_64)
+	x = ((x & ~63) << 1) | (mask << 6) | (x & 63);
+    return x;
+}
+
+/*
+ * Fetch one bit from a cursor bitmap
+ */
+static CARD8
+get_bit (CARD8 *image, int stride, int flags, int x, int y, Bool mask)
+{
+    x = cursor_bitpos (flags, x, mask);
+    image += y * stride;
+    return (image[(x >> 3)] >> (x & 7)) & 1;
+}
+
+/*
+ * Set one bit in a cursor bitmap
+ */
+static void
+set_bit (CARD8 *image, int stride, int flags, int x, int y, Bool mask)
+{
+    x = cursor_bitpos (flags, x, mask);
+    image += y * stride;
+    image[(x >> 3)] |= 1 << (x & 7);
+}
+    
+/*
+ * Load a two color cursor into a driver that supports only ARGB cursors
+ */
+static void
+xf86_crtc_convert_cursor_to_argb (xf86CrtcPtr crtc, unsigned char *src)
+{
+    ScrnInfoPtr		scrn = crtc->scrn;
+    xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+    xf86CursorInfoPtr	cursor_info = xf86_config->cursor_info;
+    CARD32		*cursor_image = (CARD32 *) xf86_config->cursor_image;
+    int			x, y;
+    int			xin, yin;
+    int			stride = cursor_info->MaxWidth >> 2;
+    int			flags = cursor_info->Flags;
+    CARD32		bits;
+
+#ifdef ARGB_CURSOR
+    crtc->cursor_argb = FALSE;
+#endif
+
+    for (y = 0; y < cursor_info->MaxHeight; y++)
+	for (x = 0; x < cursor_info->MaxWidth; x++) 
+	{
+	    xf86_crtc_rotate_coord (crtc->rotation,
+				    cursor_info->MaxWidth,
+				    cursor_info->MaxHeight,
+				    x, y, &xin, &yin);
+	    if (get_bit (src, stride, flags, xin, yin, TRUE) ==
+		((flags & HARDWARE_CURSOR_INVERT_MASK) == 0))
+	    {
+		if (get_bit (src, stride, flags, xin, yin, FALSE))
+		    bits = xf86_config->cursor_fg;
+		else
+		    bits = xf86_config->cursor_bg;
+	    }
+	    else
+		bits = 0;
+	    cursor_image[y * cursor_info->MaxWidth + x] = bits;
+	}
+    crtc->funcs->load_cursor_argb (crtc, cursor_image);
+}
+
+/*
+ * Set the colors for a two-color cursor (ignore for ARGB cursors)
+ */
+static void
+xf86_set_cursor_colors (ScrnInfoPtr scrn, int bg, int fg)
+{
+    ScreenPtr		screen = scrn->pScreen;
+    xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+    CursorPtr		cursor = xf86_config->cursor;
+    int			c;
+    CARD8		*bits = cursor ? cursor->devPriv[screen->myNum] : NULL;
+
+    /* Save ARGB versions of these colors */
+    xf86_config->cursor_fg = (CARD32) fg | 0xff000000;
+    xf86_config->cursor_bg = (CARD32) bg | 0xff000000;
+    
+    for (c = 0; c < xf86_config->num_crtc; c++)
+    {
+	xf86CrtcPtr crtc = xf86_config->crtc[c];
+
+	if (crtc->enabled && !crtc->cursor_argb)
+	{
+	    if (crtc->funcs->load_cursor_image)
+		crtc->funcs->set_cursor_colors (crtc, bg, fg);
+	    else if (bits)
+		xf86_crtc_convert_cursor_to_argb (crtc, bits);
+	}
+    }
+}
+
+static void
+xf86_crtc_hide_cursor (xf86CrtcPtr crtc)
+{
+    if (crtc->cursor_shown)
+    {
+	crtc->funcs->hide_cursor (crtc);
+	crtc->cursor_shown = FALSE;
+    }
+}
+
+void
+xf86_hide_cursors (ScrnInfoPtr scrn)
+{
+    xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+    int			c;
+
+    xf86_config->cursor_on = FALSE;
+    for (c = 0; c < xf86_config->num_crtc; c++)
+    {
+	xf86CrtcPtr crtc = xf86_config->crtc[c];
+
+	if (crtc->enabled)
+	    xf86_crtc_hide_cursor (crtc);
+    }
+}
+    
+static void
+xf86_crtc_show_cursor (xf86CrtcPtr crtc)
+{
+    if (!crtc->cursor_shown && crtc->cursor_in_range)
+    {
+	crtc->funcs->show_cursor (crtc);
+	crtc->cursor_shown = TRUE;
+    }
+}
+
+void
+xf86_show_cursors (ScrnInfoPtr scrn)
+{
+    xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+    int			c;
+
+    xf86_config->cursor_on = TRUE;
+    for (c = 0; c < xf86_config->num_crtc; c++)
+    {
+	xf86CrtcPtr crtc = xf86_config->crtc[c];
+
+	if (crtc->enabled)
+	    xf86_crtc_show_cursor (crtc);
+    }
+}
+    
+static void
+xf86_crtc_set_cursor_position (xf86CrtcPtr crtc, int x, int y)
+{
+    ScrnInfoPtr		scrn = crtc->scrn;
+    xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+    xf86CursorInfoPtr	cursor_info = xf86_config->cursor_info;
+    DisplayModePtr	mode = &crtc->mode;
+    int			x_temp;
+    int			y_temp;
+    Bool		in_range;
+
+    /* 
+     * Move to crtc coordinate space
+     */
+    x -= crtc->x;
+    y -= crtc->y;
+    
+    /*
+     * Rotate
+     */
+    switch ((crtc->rotation) & 0xf) {
+    case RR_Rotate_0:
+	break;
+    case RR_Rotate_90:
+	x_temp = y;
+	y_temp = mode->VDisplay - cursor_info->MaxWidth - x;
+	x = x_temp;
+	y = y_temp;
+	break;
+    case RR_Rotate_180:
+	x_temp = mode->HDisplay - cursor_info->MaxWidth - x;
+	y_temp = mode->VDisplay - cursor_info->MaxHeight - y;
+	x = x_temp;
+	y = y_temp;
+	break;
+    case RR_Rotate_270:
+	x_temp = mode->HDisplay - cursor_info->MaxHeight -  y;
+	y_temp = x;
+	x = x_temp;
+	y = y_temp;
+	break;
+    }
+    
+    /*
+     * Reflect
+     */
+    if (crtc->rotation & RR_Reflect_X)
+	x = mode->HDisplay - cursor_info->MaxWidth - x;
+    if (crtc->rotation & RR_Reflect_Y)
+	y = mode->VDisplay - cursor_info->MaxHeight - y;
+
+    /*
+     * Disable the cursor when it is outside the viewport
+     */
+    in_range = TRUE;
+    if (x >= mode->HDisplay || y >= mode->VDisplay ||
+	x <= -cursor_info->MaxWidth || y <= -cursor_info->MaxHeight) 
+    {
+	in_range = FALSE;
+	x = 0;
+	y = 0;
+    }
+
+    crtc->cursor_in_range = in_range;
+    
+    if (in_range)
+    {
+	crtc->funcs->set_cursor_position (crtc, x, y);
+	xf86_crtc_show_cursor (crtc);
+    }
+    else
+	xf86_crtc_hide_cursor (crtc);
+}
+
+static void
+xf86_set_cursor_position (ScrnInfoPtr scrn, int x, int y)
+{
+    xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+    int			c;
+
+    /* undo what xf86HWCurs did to the coordinates */
+    x += scrn->frameX0;
+    y += scrn->frameY0;
+    for (c = 0; c < xf86_config->num_crtc; c++)
+    {
+	xf86CrtcPtr crtc = xf86_config->crtc[c];
+
+	if (crtc->enabled)
+	    xf86_crtc_set_cursor_position (crtc, x, y);
+    }
+}
+    
+/*
+ * Load a two-color cursor into a crtc, performing rotation as needed
+ */
+static void
+xf86_crtc_load_cursor_image (xf86CrtcPtr crtc, CARD8 *src)
+{
+    ScrnInfoPtr		scrn = crtc->scrn;
+    xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+    xf86CursorInfoPtr	cursor_info = xf86_config->cursor_info;
+    CARD8		*cursor_image;
+
+#ifdef ARGB_CURSOR
+    crtc->cursor_argb = FALSE;
+#endif
+
+    if (crtc->rotation == RR_Rotate_0)
+	cursor_image = src;
+    else
+    {
+        int x, y;
+    	int xin, yin;
+	int stride = cursor_info->MaxWidth >> 2;
+	int flags = cursor_info->Flags;
+	
+	cursor_image = xf86_config->cursor_image;
+	memset(cursor_image, 0, cursor_info->MaxWidth * stride);
+	
+        for (y = 0; y < cursor_info->MaxHeight; y++)
+	    for (x = 0; x < cursor_info->MaxWidth; x++) 
+	    {
+		xf86_crtc_rotate_coord (crtc->rotation,
+					cursor_info->MaxWidth,
+					cursor_info->MaxHeight,
+					x, y, &xin, &yin);
+		if (get_bit(src, stride, flags, xin, yin, FALSE))
+		    set_bit(cursor_image, stride, flags, x, y, FALSE);
+		if (get_bit(src, stride, flags, xin, yin, TRUE))
+		    set_bit(cursor_image, stride, flags, x, y, TRUE);
+	    }
+    }
+    crtc->funcs->load_cursor_image (crtc, cursor_image);
+}
+    
+/*
+ * Load a cursor image into all active CRTCs
+ */
+static void
+xf86_load_cursor_image (ScrnInfoPtr scrn, unsigned char *src)
+{
+    xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+    int			c;
+
+    for (c = 0; c < xf86_config->num_crtc; c++)
+    {
+	xf86CrtcPtr crtc = xf86_config->crtc[c];
+
+	if (crtc->enabled)
+	{
+	    if (crtc->funcs->load_cursor_image)
+		xf86_crtc_load_cursor_image (crtc, src);
+	    else if (crtc->funcs->load_cursor_argb)
+		xf86_crtc_convert_cursor_to_argb (crtc, src);
+	}
+    }
+}
+
+static Bool
+xf86_use_hw_cursor (ScreenPtr screen, CursorPtr cursor)
+{
+    ScrnInfoPtr		scrn = xf86Screens[screen->myNum];
+    xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+    xf86CursorInfoPtr	cursor_info = xf86_config->cursor_info;
+
+    xf86_config->cursor = cursor;
+    
+    if (cursor->bits->width > cursor_info->MaxWidth ||
+	cursor->bits->height> cursor_info->MaxHeight)
+	return FALSE;
+
+    return TRUE;
+}
+
+static Bool
+xf86_use_hw_cursor_argb (ScreenPtr screen, CursorPtr cursor)
+{
+    ScrnInfoPtr		scrn = xf86Screens[screen->myNum];
+    xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+    xf86CursorInfoPtr	cursor_info = xf86_config->cursor_info;
+    
+    xf86_config->cursor = cursor;
+    
+    /* Make sure ARGB support is available */
+    if ((cursor_info->Flags & HARDWARE_CURSOR_ARGB) == 0)
+	return FALSE;
+    
+    if (cursor->bits->width > cursor_info->MaxWidth ||
+	cursor->bits->height> cursor_info->MaxHeight)
+	return FALSE;
+
+    return TRUE;
+}
+
+static void
+xf86_crtc_load_cursor_argb (xf86CrtcPtr crtc, CursorPtr cursor)
+{
+    ScrnInfoPtr		scrn = crtc->scrn;
+    xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+    xf86CursorInfoPtr	cursor_info = xf86_config->cursor_info;
+    CARD32		*cursor_image = (CARD32 *) xf86_config->cursor_image;
+    CARD32		*cursor_source = (CARD32 *) cursor->bits->argb;
+    int			x, y;
+    int			xin, yin;
+    CARD32		bits;
+    int			source_width = cursor->bits->width;
+    int			source_height = cursor->bits->height;
+    int			image_width = cursor_info->MaxWidth;
+    int			image_height = cursor_info->MaxHeight;
+    
+    for (y = 0; y < image_height; y++)
+	for (x = 0; x < image_width; x++)
+	{
+	    xf86_crtc_rotate_coord (crtc->rotation, image_width, image_height,
+				    x, y, &xin, &yin);
+	    if (xin < source_width && yin < source_height)
+		bits = cursor_source[yin * source_width + xin];
+	    else
+		bits = 0;
+	    cursor_image[y * image_width + x] = bits;
+	}
+    
+    crtc->funcs->load_cursor_argb (crtc, cursor_image);
+}
+
+static void
+xf86_load_cursor_argb (ScrnInfoPtr scrn, CursorPtr cursor)
+{
+    xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+    int			c;
+
+    for (c = 0; c < xf86_config->num_crtc; c++)
+    {
+	xf86CrtcPtr crtc = xf86_config->crtc[c];
+
+	if (crtc->enabled)
+	    xf86_crtc_load_cursor_argb (crtc, cursor);
+    }
+}
+
+Bool
+xf86_cursors_init (ScreenPtr screen, int max_width, int max_height, int flags)
+{
+    ScrnInfoPtr		scrn = xf86Screens[screen->myNum];
+    xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+    xf86CursorInfoPtr	cursor_info;
+
+    cursor_info = xf86CreateCursorInfoRec();
+    if (!cursor_info)
+	return FALSE;
+
+    xf86_config->cursor_image = xalloc (max_width * max_height * 4);
+
+    if (!xf86_config->cursor_image)
+    {
+	xf86DestroyCursorInfoRec (cursor_info);
+	return FALSE;
+    }
+	
+    xf86_config->cursor_info = cursor_info;
+
+    cursor_info->MaxWidth = max_width;
+    cursor_info->MaxHeight = max_height;
+    cursor_info->Flags = flags;
+
+    cursor_info->SetCursorColors = xf86_set_cursor_colors;
+    cursor_info->SetCursorPosition = xf86_set_cursor_position;
+    cursor_info->LoadCursorImage = xf86_load_cursor_image;
+    cursor_info->HideCursor = xf86_hide_cursors;
+    cursor_info->ShowCursor = xf86_show_cursors;
+    cursor_info->UseHWCursor = xf86_use_hw_cursor;
+#ifdef ARGB_CURSOR
+    if (flags & HARDWARE_CURSOR_ARGB)
+    {
+	cursor_info->UseHWCursorARGB = xf86_use_hw_cursor_argb;
+	cursor_info->LoadCursorARGB = xf86_load_cursor_argb;
+    }
+#endif
+    
+    xf86_config->cursor = NULL;
+    xf86_hide_cursors (scrn);
+    
+    return xf86InitCursor (screen, cursor_info);
+}
+
+/**
+ * Called when anything on the screen is reconfigured.
+ *
+ * Reloads cursor images as needed, then adjusts cursor positions
+ */
+
+void
+xf86_reload_cursors (ScreenPtr screen)
+{
+    ScrnInfoPtr		scrn = xf86Screens[screen->myNum];
+    xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+    xf86CursorInfoPtr	cursor_info = xf86_config->cursor_info;
+    CursorPtr		cursor = xf86_config->cursor;
+    int			x, y;
+    
+    GetSpritePosition (&x, &y);
+    if (!(cursor_info->Flags & HARDWARE_CURSOR_UPDATE_UNHIDDEN))
+	(*cursor_info->HideCursor)(scrn);
+
+    if (cursor)
+    {
+#ifdef ARGB_CURSOR
+	if (cursor->bits->argb && cursor_info->LoadCursorARGB)
+	    (*cursor_info->LoadCursorARGB) (scrn, cursor);
+	else
+#endif
+	    (*cursor_info->LoadCursorImage)(cursor_info->pScrn,
+					    cursor->devPriv[screen->myNum]);
+
+	(*cursor_info->SetCursorPosition)(cursor_info->pScrn, x, y);
+	(*cursor_info->ShowCursor)(cursor_info->pScrn);
+    }
+}
+
+/**
+ * Clean up CRTC-based cursor code
+ */
+void
+xf86_cursors_fini (ScreenPtr screen)
+{
+    ScrnInfoPtr		scrn = xf86Screens[screen->myNum];
+    xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+    
+    if (xf86_config->cursor_info)
+    {
+	xf86DestroyCursorInfoRec (xf86_config->cursor_info);
+	xf86_config->cursor_info = NULL;
+    }
+    if (xf86_config->cursor_image)
+    {
+	xfree (xf86_config->cursor_image);
+	xf86_config->cursor_image = NULL;
+    }
+}
diff --git a/hw/xfree86/ramdac/Makefile.am b/hw/xfree86/ramdac/Makefile.am
index 8d94445..2b84cb4 100644
--- a/hw/xfree86/ramdac/Makefile.am
+++ b/hw/xfree86/ramdac/Makefile.am
@@ -1,8 +1,6 @@
-module_LTLIBRARIES = libramdac.la
+noinst_LIBRARIES = libramdac.a
 
-libramdac_la_LDFLAGS = -avoid-version
-
-libramdac_la_SOURCES = xf86RamDacMod.c xf86RamDac.c xf86RamDacCmap.c \
+libramdac_a_SOURCES = xf86RamDac.c xf86RamDacCmap.c \
                       xf86Cursor.c xf86HWCurs.c IBM.c BT.c TI.c \
 		      xf86BitOrder.c
 
diff --git a/hw/xfree86/ramdac/xf86Cursor.h b/hw/xfree86/ramdac/xf86Cursor.h
index 08cca6b..469f48f 100644
--- a/hw/xfree86/ramdac/xf86Cursor.h
+++ b/hw/xfree86/ramdac/xf86Cursor.h
@@ -44,5 +44,8 @@ void xf86ForceHWCursor (ScreenPtr pScree
 #define HARDWARE_CURSOR_NIBBLE_SWAPPED			0x00000800
 #define HARDWARE_CURSOR_SHOW_TRANSPARENT		0x00001000
 #define HARDWARE_CURSOR_UPDATE_UNHIDDEN			0x00002000
+#ifdef ARGB_CURSOR
+#define HARDWARE_CURSOR_ARGB				0x00004000
+#endif
 
 #endif /* _XF86CURSOR_H */
diff-tree 4bf1b280f7cb676ec2b172f26dd2ad9bac2eb2ca (from c366b82bd50066019cf82b3464445d5bc27d6f9f)
Author: Alan Hourihane <alanh at fairlite.demon.co.uk>
Date:   Fri Mar 9 14:18:14 2007 +0000

    Set pScreen on context

diff --git a/GL/glx/glxdri.c b/GL/glx/glxdri.c
index e035704..5e683a8 100644
--- a/GL/glx/glxdri.c
+++ b/GL/glx/glxdri.c
@@ -495,6 +495,7 @@ __glXDRIscreenCreateContext(__GLXscreen 
     context->base.loseCurrent       = __glXDRIcontextLoseCurrent;
     context->base.copy              = __glXDRIcontextCopy;
     context->base.forceCurrent      = __glXDRIcontextForceCurrent;
+    context->base.pScreen           = screen->base.pScreen;
 
     context->base.textureFromPixmap = &__glXDRItextureFromPixmap;
 
diff-tree c366b82bd50066019cf82b3464445d5bc27d6f9f (from 405483496538f1c82cbd7fe1e76c5d94e1a90525)
Author: Jay Estabrook <Jay.Estabrook at hp.com>
Date:   Fri Mar 9 12:26:55 2007 +0000

    Ensure domain is stripped from the bus ID.

diff --git a/hw/xfree86/dri/dri.c b/hw/xfree86/dri/dri.c
index c183e2a..7bd07c0 100644
--- a/hw/xfree86/dri/dri.c
+++ b/hw/xfree86/dri/dri.c
@@ -71,6 +71,8 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN
 #include "mipointer.h"
 #include "xf86_OSproc.h"
 
+#define PCI_BUS_NO_DOMAIN(bus) ((bus) & 0xffu)
+
 #if !defined(PANORAMIX)
 extern Bool noPanoramiXExtension;
 #endif
@@ -2202,8 +2204,8 @@ DRICreatePCIBusID(pciVideoPtr PciInfo)
 
     tag = pciTag(PciInfo->bus, PciInfo->device, PciInfo->func);
     domain = xf86GetPciDomain(tag);
-    snprintf(busID, 20, "pci:%04x:%02x:%02x.%d", domain, PciInfo->bus,
-	PciInfo->device, PciInfo->func);
+    snprintf(busID, 20, "pci:%04x:%02x:%02x.%d", domain,
+	PCI_BUS_NO_DOMAIN(PciInfo->bus), PciInfo->device, PciInfo->func);
     return busID;
 }
 
diff-tree 405483496538f1c82cbd7fe1e76c5d94e1a90525 (from 63169ce52d354b4345dcfc46b89f0ea88379718f)
Author: Peter Hutterer <peter at cs.unisa.edu.au>
Date:   Fri Mar 9 14:16:23 2007 +1030

    mi: remove 'register' keywords.

diff --git a/mi/miarc.c b/mi/miarc.c
index 2b3a0cb..8b6d8c0 100644
--- a/mi/miarc.c
+++ b/mi/miarc.c
@@ -246,7 +246,7 @@ typedef struct _miPolyArc {
 static CARD32 gcvals[6];
 
 static void fillSpans(DrawablePtr pDrawable, GCPtr pGC);
-static void newFinalSpan(int y, register int xmin, register int xmax);
+static void newFinalSpan(int y, int xmin, int xmax);
 static void drawArc(xArc *tarc, int l, int a0, int a1, miArcFacePtr right,
 		    miArcFacePtr left);
 static void drawZeroArc(DrawablePtr pDraw, GCPtr pGC, xArc *tarc, int lw,
@@ -284,7 +284,7 @@ miArcSegment(
 {
     int l = pGC->lineWidth;
     int a0, a1, startAngle, endAngle;
-    miArcFacePtr	temp;
+    miArcFacePtr temp;
 
     if (!l)
 	l = 1;
@@ -432,8 +432,8 @@ static RESTYPE cacheType;
 /*ARGSUSED*/
 int
 miFreeArcCache (data, id)
-    pointer	    data;
-    XID		    id;
+    pointer data;
+    XID	    id;
 {
     int k;
     arcCacheRec *cent;
@@ -461,11 +461,11 @@ miComputeCircleSpans(
     xArc *parc,
     miArcSpanData *spdata)
 {
-    register miArcSpan *span;
+    miArcSpan *span;
     int doinner;
-    register int x, y, e;
+    int x, y, e;
     int xk, yk, xm, ym, dx, dy;
-    register int slw, inslw;
+    int slw, inslw;
     int inx = 0, iny, ine = 0;
     int inxk = 0, inyk = 0, inxm = 0, inym = 0;
 
@@ -529,7 +529,7 @@ miComputeEllipseSpans(
     xArc *parc,
     miArcSpanData *spdata)
 {
-    register miArcSpan *span;
+    miArcSpan *span;
     double w, h, r, xorg;
     double Hs, Hf, WH, K, Vk, Nk, Fk, Vr, N, Nc, Z, rs;
     double A, T, b, d, x, y, t, inx, outx = 0.0, hepp, hepm;
@@ -859,13 +859,13 @@ tailX(
 
 static miArcSpanData *
 miComputeWideEllipse(
-    int		   lw,
-    register xArc *parc,
-    Bool	  *mustFree)
-{
-    register miArcSpanData *spdata;
-    register arcCacheRec *cent, *lruent;
-    register int k;
+    int  lw,
+    xArc *parc,
+    Bool *mustFree)
+{
+    miArcSpanData *spdata;
+    arcCacheRec *cent, *lruent;
+    int k;
     arcCacheRec fakeent;
 
     if (!lw)
@@ -943,14 +943,14 @@ miFillWideEllipse(
     xArc	*parc)
 {
     DDXPointPtr points;
-    register DDXPointPtr pts;
+    DDXPointPtr pts;
     int *widths;
-    register int *wids;
+    int *wids;
     miArcSpanData *spdata;
     Bool mustFree;
-    register miArcSpan *span;
-    register int xorg, yorgu, yorgl;
-    register int n;
+    miArcSpan *span;
+    int xorg, yorgu, yorgl;
+    int n;
 
     yorgu = parc->height + pGC->lineWidth;
     n = (sizeof(int) * 2) * yorgu;
@@ -1077,20 +1077,20 @@ miPolyArc(pDraw, pGC, narcs, parcs)
     int		narcs;
     xArc	*parcs;
 {
-    register int		i;
-    xArc			*parc;
-    int				xMin, xMax, yMin, yMax;
-    int				pixmapWidth = 0, pixmapHeight = 0;
-    int				xOrg = 0, yOrg = 0;
-    int				width;
-    Bool			fTricky;
-    DrawablePtr			pDrawTo;
-    CARD32			fg, bg;
-    GCPtr			pGCTo;
-    miPolyArcPtr		polyArcs;
-    int				cap[2], join[2];
-    int				iphase;
-    int				halfWidth;
+    int		i;
+    xArc	*parc;
+    int		xMin, xMax, yMin, yMax;
+    int		pixmapWidth = 0, pixmapHeight = 0;
+    int		xOrg = 0, yOrg = 0;
+    int		width;
+    Bool	fTricky;
+    DrawablePtr	pDrawTo;
+    CARD32	fg, bg;
+    GCPtr	pGCTo;
+    miPolyArcPtr polyArcs;
+    int		cap[2], join[2];
+    int		iphase;
+    int		halfWidth;
 
     width = pGC->lineWidth;
     if(width == 0 && pGC->lineStyle == LineSolid)
@@ -3139,9 +3139,9 @@ static struct finalSpanChunk	*chunks;
 struct finalSpan *
 realAllocSpan ()
 {
-	register struct finalSpanChunk	*newChunk;
-	register struct finalSpan	*span;
-	register int			i;
+	struct finalSpanChunk	*newChunk;
+	struct finalSpan	*span;
+	int			i;
 
 	newChunk = (struct finalSpanChunk *) xalloc (sizeof (struct finalSpanChunk));
 	if (!newChunk)
@@ -3179,14 +3179,14 @@ fillSpans (
     DrawablePtr	pDrawable,
     GCPtr	pGC)
 {
-	register struct finalSpan	*span;
-	register DDXPointPtr		xSpan;
-	register int			*xWidth;
-	register int			i;
-	register struct finalSpan	**f;
-	register int			spany;
-	DDXPointPtr			xSpans;
-	int				*xWidths;
+	struct finalSpan	*span;
+	DDXPointPtr		xSpan;
+	int			*xWidth;
+	int			i;
+	struct finalSpan	**f;
+	int			spany;
+	DDXPointPtr		xSpans;
+	int			*xWidths;
 
 	if (nspans == 0)
 		return;
@@ -3280,13 +3280,13 @@ realFindSpan (int y)
 static void
 newFinalSpan (
     int		y,
-    register int	xmin,
-    register int	xmax)
+    int	xmin,
+    int	xmax)
 {
-	register struct finalSpan	*x;
-	register struct finalSpan	**f;
-	struct finalSpan		*oldx;
-	struct finalSpan		*prev;
+	struct finalSpan	*x;
+	struct finalSpan	**f;
+	struct finalSpan	*oldx;
+	struct finalSpan	*prev;
 
 	f = findSpan (y);
 	if (!f)
diff --git a/mi/mibitblt.c b/mi/mibitblt.c
index bf0e29a..e4b1407 100644
--- a/mi/mibitblt.c
+++ b/mi/mibitblt.c
@@ -76,12 +76,12 @@ extern int ffs(int);
 _X_EXPORT RegionPtr
 miCopyArea(pSrcDrawable, pDstDrawable,
 	    pGC, xIn, yIn, widthSrc, heightSrc, xOut, yOut)
-    register DrawablePtr 	pSrcDrawable;
-    register DrawablePtr 	pDstDrawable;
-    GCPtr 			pGC;
-    int 			xIn, yIn;
-    int 			widthSrc, heightSrc;
-    int 			xOut, yOut;
+    DrawablePtr 	pSrcDrawable;
+    DrawablePtr 	pDstDrawable;
+    GCPtr 		pGC;
+    int 		xIn, yIn;
+    int 		widthSrc, heightSrc;
+    int 		xOut, yOut;
 {
     DDXPointPtr		ppt, pptFirst;
     unsigned int	*pwidthFirst, *pwidth, *pbits;
diff --git a/mi/mibstore.c b/mi/mibstore.c
index 6653c23..70839ce 100644
--- a/mi/mibstore.c
+++ b/mi/mibstore.c
@@ -152,11 +152,11 @@ static void	    miBSClearBackingRegion(W
 
 #define copyData(src,dst,n,morecopy) \
 { \
-    register short *srcCopy = (short *)(src); \
-    register short *dstCopy = (short *)(dst); \
-    register int i; \
-    register int bsx = pBackingStore->x; \
-    register int bsy = pBackingStore->y; \
+    short *srcCopy = (short *)(src); \
+    short *dstCopy = (short *)(dst); \
+    int i; \
+    int bsx = pBackingStore->x; \
+    int bsy = pBackingStore->y; \
     for (i = n; --i >= 0; ) \
     { \
 	*dstCopy++ = *srcCopy++ - bsx; \
@@ -1010,7 +1010,7 @@ miBSSetSpans(pDrawable, pGC, psrc, ppt, 
     DrawablePtr		pDrawable;
     GCPtr		pGC;
     char		*psrc;
-    register DDXPointPtr ppt;
+    DDXPointPtr 	ppt;
     int			*pwidth;
     int			nspans;
     int			fSorted;
@@ -1150,8 +1150,8 @@ miBSDoCopy(
     }	    	  	*boxes;	    /* Array of box/drawable pairs covering
 				     * source box. */
     int  	  	*sequence;  /* Sequence of boxes to move */
-    register int  	i, j, k, l, y;
-    register BoxPtr	pBox;
+    int  		i, j, k, l, y;
+    BoxPtr		pBox;
     int	    	  	dx, dy, nrects;
     Bool    	  	graphicsExposures;
     CopyPlaneProcPtr  	pixCopyProc;
@@ -1591,7 +1591,7 @@ static RegionPtr
 miBSCopyPlane (pSrc, pDst, pGC, srcx, srcy, w, h, dstx, dsty, plane)
     DrawablePtr	  pSrc;
     DrawablePtr	  pDst;
-    register GC   *pGC;
+    GC  	 *pGC;
     int     	  srcx,
 		  srcy;
     int     	  w,
@@ -1901,9 +1901,9 @@ miBSPolyArc(pDrawable, pGC, narcs, parcs
 static void
 miBSFillPolygon(pDrawable, pGC, shape, mode, count, pPts)
     DrawablePtr		pDrawable;
-    register GCPtr	pGC;
+    GCPtr		pGC;
     int			shape, mode;
-    register int	count;
+    int			count;
     DDXPointPtr		pPts;
 {
     DDXPointPtr	pPtsCopy;
@@ -2546,8 +2546,8 @@ static void
 miBSAllocate(pWin)
     WindowPtr 	  pWin;
 {
-    register miBSWindowPtr  pBackingStore;
-    register ScreenPtr 	    pScreen;
+    miBSWindowPtr  	pBackingStore;
+    ScreenPtr 	   	pScreen;
 	
     if (pWin->drawable.pScreen->backingStoreSupport == NotUseful)
 	return;
@@ -2648,7 +2648,7 @@ miBSFree(pWin)
     WindowPtr pWin;
 {
     miBSWindowPtr 	pBackingStore;
-    register ScreenPtr	pScreen;
+    ScreenPtr		pScreen;
 
     pScreen = pWin->drawable.pScreen;
 
@@ -2792,9 +2792,9 @@ miResizeBackingStore(
  */
 static void
 miBSSaveDoomedAreas(pWin, pObscured, dx, dy)
-    register WindowPtr pWin;
-    RegionPtr 	       pObscured;
-    int		       dx, dy;
+    WindowPtr		pWin;
+    RegionPtr		pObscured;
+    int			dx, dy;
 {
     miBSWindowPtr 	pBackingStore;
     ScreenPtr	  	pScreen;
@@ -2899,14 +2899,14 @@ miBSSaveDoomedAreas(pWin, pObscured, dx,
  */
 static RegionPtr
 miBSRestoreAreas(pWin, prgnExposed)
-    register WindowPtr pWin;
+    WindowPtr pWin;
     RegionPtr prgnExposed;
 {
     PixmapPtr pBackingPixmap;
     miBSWindowPtr pBackingStore;
     RegionPtr prgnSaved;
     RegionPtr prgnRestored;
-    register ScreenPtr pScreen;
+    ScreenPtr pScreen;
     RegionPtr exposures = prgnExposed;
 
     pScreen = pWin->drawable.pScreen;
@@ -3097,15 +3097,15 @@ miBSTranslateBackingStore(pWin, windx, w
     int     	  oldx;		/* old window position */
     int     	  oldy;
 {
-    register miBSWindowPtr 	pBackingStore;
-    register RegionPtr 	    	pSavedRegion;
-    register RegionPtr 	    	newSaved, doomed;
-    register ScreenPtr		pScreen;
-    BoxRec			extents;
-    int     	  scrdx;	/* bit translation distance on screen */
-    int     	  scrdy;
-    int		  dx;		/* distance window moved  on screen */
-    int		  dy;
+    miBSWindowPtr 	pBackingStore;
+    RegionPtr 	    	pSavedRegion;
+    RegionPtr 	    	newSaved, doomed;
+    ScreenPtr		pScreen;
+    BoxRec		extents;
+    int 		scrdx;	/* bit translation distance on screen */
+    int     	  	scrdy;
+    int			dx;		/* distance window moved  on screen */
+    int			dy;
 
     pScreen = pWin->drawable.pScreen;
     pBackingStore = (miBSWindowPtr)(pWin->backStorage);
@@ -3815,9 +3815,9 @@ miBSExposeCopy (pSrc, pDst, pGC, prgnExp
     miBSWindowPtr	pBackingStore;
     CopyPlaneProcPtr 	copyProc;
     GCPtr		pScratchGC;
-    register BoxPtr	pBox;
-    register int  	i;
-    register int  	dx, dy;
+    BoxPtr		pBox;
+    int  		i;
+    int  		dx, dy;
     BITS32		gcMask;
 
     if (!REGION_NOTEMPTY(pGC->pScreen, prgnExposed))
diff --git a/mi/micmap.c b/mi/micmap.c
index 987affe..977c587 100644
--- a/mi/micmap.c
+++ b/mi/micmap.c
@@ -125,8 +125,8 @@ miResolveColor(unsigned short *pred, uns
 _X_EXPORT Bool
 miInitializeColormap(ColormapPtr pmap)
 {
-    register unsigned i;
-    register VisualPtr pVisual;
+    unsigned i;
+    VisualPtr pVisual;
     unsigned lim, maxent, shift;
 
     pVisual = pmap->pVisual;
@@ -211,13 +211,13 @@ _X_EXPORT int
 miExpandDirectColors(ColormapPtr pmap, int ndef, xColorItem *indefs,
 			xColorItem *outdefs)
 {
-    register int    red, green, blue;
-    int		    maxred, maxgreen, maxblue;
-    int		    stepred, stepgreen, stepblue;
-    VisualPtr	    pVisual;
-    register int    pixel;
-    register int    nresult;
-    register int    i;
+    int	        red, green, blue;
+    int	        maxred, maxgreen, maxblue;
+    int	        stepred, stepgreen, stepblue;
+    VisualPtr   pVisual;
+    int         pixel;
+    int         nresult;
+    int         i;
 
     pVisual = pmap->pVisual;
 
diff --git a/mi/miexpose.c b/mi/miexpose.c
index 1ca5fc9..df04bd2 100644
--- a/mi/miexpose.c
+++ b/mi/miexpose.c
@@ -130,15 +130,15 @@ exposing is done by the backing store's 
 _X_EXPORT RegionPtr
 miHandleExposures(pSrcDrawable, pDstDrawable,
 		  pGC, srcx, srcy, width, height, dstx, dsty, plane)
-    register DrawablePtr	pSrcDrawable;
-    register DrawablePtr	pDstDrawable;
+    DrawablePtr			pSrcDrawable;
+    DrawablePtr			pDstDrawable;
     GCPtr 			pGC;
     int 			srcx, srcy;
     int 			width, height;
     int 			dstx, dsty;
     unsigned long		plane;
 {
-    register ScreenPtr pscr;
+    ScreenPtr pscr;
     RegionPtr prgnSrcClip;	/* drawable-relative source clip */
     RegionRec rgnSrcRec;
     RegionPtr prgnDstClip;	/* drawable-relative dest clip */
@@ -387,9 +387,9 @@ miSendGraphicsExpose (client, pRgn, draw
     if (pRgn && !REGION_NIL(pRgn))
     {
         xEvent *pEvent;
-	register xEvent *pe;
-	register BoxPtr pBox;
-	register int i;
+	xEvent *pe;
+	BoxPtr pBox;
+	int i;
 	int numRects;
 
 	numRects = REGION_NUM_RECTS(pRgn);
@@ -431,12 +431,12 @@ void
 miSendExposures(pWin, pRgn, dx, dy)
     WindowPtr pWin;
     RegionPtr pRgn;
-    register int dx, dy;
+    int dx, dy;
 {
-    register BoxPtr pBox;
+    BoxPtr pBox;
     int numRects;
-    register xEvent *pEvent, *pe;
-    register int i;
+    xEvent *pEvent, *pe;
+    int i;
 
     pBox = REGION_RECTS(pRgn);
     numRects = REGION_NUM_RECTS(pRgn);
@@ -493,7 +493,7 @@ miSendExposures(pWin, pRgn, dx, dy)
 _X_EXPORT void 
 miWindowExposures(pWin, prgn, other_exposed)
     WindowPtr pWin;
-    register RegionPtr prgn, other_exposed;
+    RegionPtr prgn, other_exposed;
 {
     RegionPtr   exposures = prgn;
     if (pWin->backStorage && prgn)
@@ -629,7 +629,7 @@ tossGC (
 
 _X_EXPORT void
 miPaintWindow(pWin, prgn, what)
-register WindowPtr pWin;
+WindowPtr pWin;
 RegionPtr prgn;
 int what;
 {
@@ -657,10 +657,10 @@ int what;
     BoxRec box;
     WindowPtr	pBgWin;
     GCPtr pGC;
-    register int i;
-    register BoxPtr pbox;
-    register ScreenPtr pScreen = pWin->drawable.pScreen;
-    register xRectangle *prect;
+    int i;
+    BoxPtr pbox;
+    ScreenPtr pScreen = pWin->drawable.pScreen;
+    xRectangle *prect;
     int numRects;
 
     gcmask = 0;
diff --git a/mi/mifillarc.c b/mi/mifillarc.c
index 6606316..46c0738 100644
--- a/mi/mifillarc.c
+++ b/mi/mifillarc.c
@@ -54,8 +54,8 @@ Author:  Bob Scheifler, MIT X Consortium
 
 _X_EXPORT void
 miFillArcSetup(arc, info)
-    register xArc *arc;
-    register miFillArcRec *info;
+    xArc *arc;
+    miFillArcRec *info;
 {
     info->y = arc->height >> 1;
     info->dy = arc->height & 1;
@@ -109,8 +109,8 @@ miFillArcSetup(arc, info)
 
 void
 miFillArcDSetup(arc, info)
-    register xArc *arc;
-    register miFillArcDRec *info;
+    xArc *arc;
+    miFillArcDRec *info;
 {
     /* h^2 * (2x - 2xorg)^2 = w^2 * h^2 - w^2 * (2y - 2yorg)^2 */
     /* even: xorg = yorg = 0   odd:  xorg = .5, yorg = -.5 */
@@ -141,13 +141,13 @@ miFillArcDSetup(arc, info)
 
 static void
 miGetArcEdge(
-	     register xArc *arc,
-	     register miSliceEdgePtr edge,
+	     xArc *arc,
+	     miSliceEdgePtr edge,
 	     int k,
 	     Bool top, 
 	     Bool left )
 {
-    register int xady, y;
+    int xady, y;
 
     y = arc->height >> 1;
     if (!(arc->width & 1))
@@ -271,13 +271,13 @@ miEllipseAngleToSlope (angle, width, hei
 
 static void
 miGetPieEdge(
-	     register xArc *arc,
-	     register int angle,
-	     register miSliceEdgePtr edge,
+	     xArc *arc,
+	     int angle,
+	     miSliceEdgePtr edge,
 	     Bool top, 
 	     Bool left )
 {
-    register int k;
+    int k;
     int	dx, dy;
 
     miEllipseAngleToSlope (angle, arc->width, arc->height, &dx, &dy, 0, 0);
@@ -316,11 +316,11 @@ miGetPieEdge(
 
 _X_EXPORT void
 miFillArcSliceSetup(arc, slice, pGC)
-    register xArc *arc;
-    register miArcSliceRec *slice;
+    xArc *arc;
+    miArcSliceRec *slice;
     GCPtr pGC;
 {
-    register int angle1, angle2;
+    int angle1, angle2;
 
     angle1 = arc->angle1;
     if (arc->angle2 < 0)
@@ -550,14 +550,14 @@ miFillEllipseI(
 	       GCPtr pGC,
 	       xArc *arc )
 {
-    register int x, y, e;
+    int x, y, e;
     int yk, xk, ym, xm, dx, dy, xorg, yorg;
     int slw;
     miFillArcRec info;
     DDXPointPtr points;
-    register DDXPointPtr pts;
+    DDXPointPtr pts;
     int *widths;
-    register int *wids;
+    int *wids;
 
     points = (DDXPointPtr)ALLOCATE_LOCAL(sizeof(DDXPointRec) * arc->height);
     if (!points)
@@ -593,14 +593,14 @@ miFillEllipseD(
 	       GCPtr pGC,
 	       xArc *arc )
 {
-    register int x, y;
+    int x, y;
     int xorg, yorg, dx, dy, slw;
     double e, yk, xk, ym, xm;
     miFillArcDRec info;
     DDXPointPtr points;
-    register DDXPointPtr pts;
+    DDXPointPtr pts;
     int *widths;
-    register int *wids;
+    int *wids;
 
     points = (DDXPointPtr)ALLOCATE_LOCAL(sizeof(DDXPointRec) * arc->height);
     if (!points)
@@ -659,14 +659,14 @@ miFillArcSliceI(
 		xArc *arc )
 {
     int yk, xk, ym, xm, dx, dy, xorg, yorg, slw;
-    register int x, y, e;
+    int x, y, e;
     miFillArcRec info;
     miArcSliceRec slice;
     int ya, xl, xr, xc;
     DDXPointPtr points;
-    register DDXPointPtr pts;
+    DDXPointPtr pts;
     int *widths;
-    register int *wids;
+    int *wids;
 
     miFillArcSetup(arc, &info);
     miFillArcSliceSetup(arc, &slice, pGC);
@@ -721,16 +721,16 @@ miFillArcSliceD(
 		GCPtr pGC,
 		xArc *arc )
 {
-    register int x, y;
+    int x, y;
     int dx, dy, xorg, yorg, slw;
     double e, yk, xk, ym, xm;
     miFillArcDRec info;
     miArcSliceRec slice;
     int ya, xl, xr, xc;
     DDXPointPtr points;
-    register DDXPointPtr pts;
+    DDXPointPtr pts;
     int *widths;
-    register int *wids;
+    int *wids;
 
     miFillArcDSetup(arc, &info);
     miFillArcSliceSetup(arc, &slice, pGC);
@@ -790,8 +790,8 @@ miPolyFillArc(pDraw, pGC, narcs, parcs)
     int		narcs;
     xArc	*parcs;
 {
-    register int i;
-    register xArc *arc;
+    int i;
+    xArc *arc;
 
     for(i = narcs, arc = parcs; --i >= 0; arc++)
     {
diff --git a/mi/mifillrct.c b/mi/mifillrct.c
index 78e89d6..ca7e864 100644
--- a/mi/mifillrct.c
+++ b/mi/mifillrct.c
@@ -74,16 +74,16 @@ miPolyFillRect(pDrawable, pGC, nrectFill
     xRectangle	*prectInit;  	/* Pointer to first rectangle to fill */
 {
     int i;
-    register int	height;
-    register int	width;
-    register xRectangle *prect; 
-    int			xorg;
-    register int	yorg;
-    int			maxheight;
-    DDXPointPtr		pptFirst;
-    register DDXPointPtr ppt;
-    int			*pwFirst;
-    register int 	*pw;
+    int	height;
+    int	width;
+    xRectangle *prect; 
+    int	xorg;
+    int	yorg;
+    int	maxheight;
+    DDXPointPtr	pptFirst;
+    DDXPointPtr ppt;
+    int	*pwFirst;
+    int *pw;
 
     if (pGC->miTranslate)
     {
diff --git a/mi/mifpolycon.c b/mi/mifpolycon.c
index 57229f6..7bc1bb2 100644
--- a/mi/mifpolycon.c
+++ b/mi/mifpolycon.c
@@ -55,7 +55,7 @@ SOFTWARE.
 #include "pixmapstr.h"
 #include "mifpoly.h"
 
-static int GetFPolyYBounds(register SppPointPtr pts, int n, double yFtrans,
+static int GetFPolyYBounds(SppPointPtr pts, int n, double yFtrans,
 			   int *by, int *ty);
 
 #ifdef ICEILTEMPDECL
@@ -101,7 +101,7 @@ miFillSppPoly(dst, pgc, count, ptsIn, xT
     			*width,
     			*FirstWidth,    /* output buffer */
     	 		*Marked;	/* set if this vertex has been used */
-    register int	left, right,	/* indices to first endpoints */
+    int			left, right,	/* indices to first endpoints */
     			nextleft,
                  	nextright;	/* indices to second endpoints */
     DDXPointPtr 	ptsOut,
@@ -251,13 +251,13 @@ miFillSppPoly(dst, pgc, count, ptsIn, xT
 static
 int
 GetFPolyYBounds(
-    register SppPointPtr	pts,
+    SppPointPtr			pts,
     int 			n,
     double			yFtrans,
     int 			*by,
     int				*ty)
 {
-    register SppPointPtr	ptMin;
+    SppPointPtr			ptMin;
     double 			ymin, ymax;
     SppPointPtr			ptsStart = pts;
 
diff --git a/mi/miglblt.c b/mi/miglblt.c
index db299a8..4db3eb6 100644
--- a/mi/miglblt.c
+++ b/mi/miglblt.c
@@ -92,18 +92,18 @@ miPolyGlyphBlt(pDrawable, pGC, x, y, ngl
 {
     int width, height;
     PixmapPtr pPixmap;
-    int nbyLine;			/* bytes per line of padded pixmap */
+    int nbyLine;		/* bytes per line of padded pixmap */
     FontPtr pfont;
     GCPtr pGCtmp;
-    register int i;
-    register int j;
-    unsigned char *pbits;		/* buffer for PutImage */
-    register unsigned char *pb;		/* temp pointer into buffer */
-    register CharInfoPtr pci;		/* currect char info */
-    register unsigned char *pglyph;	/* pointer bits in glyph */
-    int gWidth, gHeight;		/* width and height of glyph */
-    register int nbyGlyphWidth;		/* bytes per scanline of glyph */
-    int nbyPadGlyph;			/* server padded line of glyph */
+    int i;
+    int j;
+    unsigned char *pbits;	/* buffer for PutImage */
+    unsigned char *pb;		/* temp pointer into buffer */
+    CharInfoPtr pci;		/* currect char info */
+    unsigned char *pglyph;	/* pointer bits in glyph */
+    int gWidth, gHeight;	/* width and height of glyph */
+    int nbyGlyphWidth;		/* bytes per scanline of glyph */
+    int nbyPadGlyph;		/* server padded line of glyph */
 
     XID gcvals[3];
 
diff --git a/mi/miline.h b/mi/miline.h
index 7028485..b97b8cf 100644
--- a/mi/miline.h
+++ b/mi/miline.h
@@ -109,7 +109,7 @@ extern void miSetZeroLineBias(
 }
   
 #define SWAPINT(i, j) \
-{  register int _t = i;  i = j;  j = _t; }
+{  int _t = i;  i = j;  j = _t; }
 
 #define SWAPPT(i, j) \
 {  DDXPointRec _t; _t = i;  i = j; j = _t; }
diff --git a/mi/mioverlay.c b/mi/mioverlay.c
index c02ea2d..5724a6f 100644
--- a/mi/mioverlay.c
+++ b/mi/mioverlay.c
@@ -1019,7 +1019,7 @@ miOverlayMoveWindow(
 static void 
 miOverlayWindowExposures(
     WindowPtr pWin,
-    register RegionPtr prgn,
+    RegionPtr prgn,
     RegionPtr other_exposed
 ){
     RegionPtr   exposures = prgn;
@@ -1106,7 +1106,7 @@ miOverlayRecomputeExposures (
     WindowPtr	pWin,
     pointer	value 
 ){
-    register ScreenPtr pScreen;
+    ScreenPtr pScreen;
     miOverlayTwoRegions	*pValid = (miOverlayTwoRegions*)value;
     miOverlayTreePtr pTree = MIOVERLAY_GET_WINDOW_TREE(pWin);
 
@@ -1161,10 +1161,10 @@ miOverlayResizeWindow(
     DDXPointRec oldpt;
     RegionPtr oldRegion = NULL, oldRegion2 = NULL;
     WindowPtr pFirstChange;
-    register WindowPtr pChild;
+    WindowPtr pChild;
     RegionPtr	gravitate[StaticGravity + 1];
     RegionPtr	gravitate2[StaticGravity + 1];
-    register unsigned g;
+    unsigned 	g;
     int		nx, ny;		/* destination x,y */
     int		newx, newy;	/* new inner window position */
     RegionPtr	pRegion = NULL;
@@ -1669,7 +1669,7 @@ miOverlayChangeBorderWidth(
     unsigned int width
 ){
     int oldwidth;
-    register ScreenPtr pScreen;
+    ScreenPtr pScreen;
     Bool WasViewable = (Bool)(pWin->viewable);
     Bool HadBorder;
 #ifdef DO_SAVE_UNDERS
diff --git a/mi/mipoly.c b/mi/mipoly.c
index b514b5e..ea0406f 100644
--- a/mi/mipoly.c
+++ b/mi/mipoly.c
@@ -70,14 +70,14 @@ SOFTWARE.
 _X_EXPORT void
 miFillPolygon(dst, pgc, shape, mode, count, pPts)
     DrawablePtr		dst;
-    register GCPtr	pgc;
+    GCPtr		pgc;
     int			shape, mode;
-    register int	count;
+    int			count;
     DDXPointPtr		pPts;
 {
     int			i;
-    register int	xorg, yorg;
-    register DDXPointPtr ppt;
+    int			xorg, yorg;
+    DDXPointPtr 	ppt;
 
     if (count == 0)
 	return;
diff --git a/mi/mipolycon.c b/mi/mipolycon.c
index b5ab893..e2d666e 100644
--- a/mi/mipolycon.c
+++ b/mi/mipolycon.c
@@ -78,9 +78,9 @@ miFillConvexPoly(dst, pgc, count, ptsIn)
     int		count;                /* number of points        */
     DDXPointPtr ptsIn;                /* the points              */
 {
-    register int xl = 0, xr = 0; /* x vals of left and right edges */
-    register int dl = 0, dr = 0; /* decision variables             */
-    register int ml = 0, m1l = 0;/* left edge slope and slope+1    */
+    int xl = 0, xr = 0; /* x vals of left and right edges */
+    int dl = 0, dr = 0; /* decision variables             */
+    int ml = 0, m1l = 0;/* left edge slope and slope+1    */
     int mr = 0, m1r = 0;         /* right edge slope and slope+1   */
     int incr1l = 0, incr2l = 0;  /* left edge error increments     */
     int incr1r = 0, incr2r = 0;  /* right edge error increments    */
@@ -221,7 +221,7 @@ miFillConvexPoly(dst, pgc, count, ptsIn)
 static int
 getPolyYBounds(DDXPointPtr pts, int n, int *by, int *ty)
 {
-    register DDXPointPtr ptMin;
+    DDXPointPtr ptMin;
     int ymin, ymax;
     DDXPointPtr ptsStart = pts;
 
diff --git a/mi/mipolygen.c b/mi/mipolygen.c
index 34da21f..0d2ecc4 100644
--- a/mi/mipolygen.c
+++ b/mi/mipolygen.c
@@ -72,12 +72,12 @@ miFillGeneralPoly(dst, pgc, count, ptsIn
     int		count;              /* number of points        */
     DDXPointPtr ptsIn;              /* the points              */
 {
-    register EdgeTableEntry *pAET;  /* the Active Edge Table   */
-    register int y;                 /* the current scanline    */
-    register int nPts = 0;          /* number of pts in buffer */
-    register EdgeTableEntry *pWETE; /* Winding Edge Table      */
-    register ScanLineList *pSLL;    /* Current ScanLineList    */
-    register DDXPointPtr ptsOut;      /* ptr to output buffers   */
+    EdgeTableEntry *pAET;  /* the Active Edge Table   */
+    int y;                 /* the current scanline    */
+    int nPts = 0;          /* number of pts in buffer */
+    EdgeTableEntry *pWETE; /* Winding Edge Table      */
+    ScanLineList *pSLL;    /* Current ScanLineList    */
+    DDXPointPtr ptsOut;      /* ptr to output buffers   */
     int *width;
     DDXPointRec FirstPoint[NUMPTSTOBUFFER]; /* the output buffers */
     int FirstWidth[NUMPTSTOBUFFER];
diff --git a/mi/mipolypnt.c b/mi/mipolypnt.c
index 245bda3..afe3f72 100644
--- a/mi/mipolypnt.c
+++ b/mi/mipolypnt.c
@@ -70,7 +70,7 @@ miPolyPoint(pDrawable, pGC, mode, npt, p
     XID			fsOld, fsNew;
     int			*pwidthInit, *pwidth;
     int			i;
-    register xPoint 	*ppt;
+    xPoint 		*ppt;
 
     /* make pointlist origin relative */
     if (mode == CoordModePrevious)
diff --git a/mi/mipolyutil.c b/mi/mipolyutil.c
index 5443ba5..fe72e55 100644
--- a/mi/mipolyutil.c
+++ b/mi/mipolyutil.c
@@ -81,8 +81,8 @@ miInsertEdgeInET(ET, ETE, scanline, SLLB
     ScanLineListBlock **SLLBlock;
     int *iSLLBlock;
 {
-    register EdgeTableEntry *start, *prev;
-    register ScanLineList *pSLL, *pPrevSLL;
+    EdgeTableEntry *start, *prev;
+    ScanLineList *pSLL, *pPrevSLL;
     ScanLineListBlock *tmpSLLBlock;
 
     /*
@@ -166,15 +166,15 @@ miInsertEdgeInET(ET, ETE, scanline, SLLB
 
 Bool
 miCreateETandAET(count, pts, ET, AET, pETEs, pSLLBlock)
-    register int count;
-    register DDXPointPtr pts;
+    int count;
+    DDXPointPtr pts;
     EdgeTable *ET;
     EdgeTableEntry *AET;
-    register EdgeTableEntry *pETEs;
+    EdgeTableEntry *pETEs;
     ScanLineListBlock   *pSLLBlock;
 {
-    register DDXPointPtr top, bottom;
-    register DDXPointPtr PrevPt, CurrPt;
+    DDXPointPtr top, bottom;
+    DDXPointPtr PrevPt, CurrPt;
     int iSLLBlock = 0;
 
     int dy;
@@ -262,10 +262,10 @@ miCreateETandAET(count, pts, ET, AET, pE
 
 void
 miloadAET(AET, ETEs)
-    register EdgeTableEntry *AET, *ETEs;
+    EdgeTableEntry *AET, *ETEs;
 {
-    register EdgeTableEntry *pPrevAET;
-    register EdgeTableEntry *tmp;
+    EdgeTableEntry *pPrevAET;
+    EdgeTableEntry *tmp;
 
     pPrevAET = AET;
     AET = AET->next;
@@ -310,11 +310,11 @@ miloadAET(AET, ETEs)
  */
 void
 micomputeWAET(AET)
-    register EdgeTableEntry *AET;
+    EdgeTableEntry *AET;
 {
-    register EdgeTableEntry *pWETE;
-    register int inside = 1;
-    register int isInside = 0;
+    EdgeTableEntry *pWETE;
+    int inside = 1;
+    int isInside = 0;
 
     AET->nextWETE = (EdgeTableEntry *)NULL;
     pWETE = AET;
@@ -349,12 +349,12 @@ micomputeWAET(AET)
 
 int
 miInsertionSort(AET)
-    register EdgeTableEntry *AET;
+    EdgeTableEntry *AET;
 {
-    register EdgeTableEntry *pETEchase;
-    register EdgeTableEntry *pETEinsert;
-    register EdgeTableEntry *pETEchaseBackTMP;
-    register int changed = 0;
+    EdgeTableEntry *pETEchase;
+    EdgeTableEntry *pETEinsert;
+    EdgeTableEntry *pETEchaseBackTMP;
+    int changed = 0;
 
     AET = AET->next;
     while (AET) 
@@ -386,9 +386,9 @@ miInsertionSort(AET)
  */
 void
 miFreeStorage(pSLLBlock)
-    register ScanLineListBlock   *pSLLBlock;
+    ScanLineListBlock   *pSLLBlock;
 {
-    register ScanLineListBlock   *tmpSLLBlock;
+    ScanLineListBlock   *tmpSLLBlock;
 
     while (pSLLBlock) 
     {
diff --git a/mi/mipushpxl.c b/mi/mipushpxl.c
index 6526aa0..3695f30 100644
--- a/mi/mipushpxl.c
+++ b/mi/mipushpxl.c
@@ -85,11 +85,11 @@ miPushPixels(pGC, pBitMap, pDrawable, dx
     int		dx, dy, xOrg, yOrg;
 {
     int		h, dxDivPPW, ibEnd;
-    MiBits *pwLineStart;
-    register MiBits	*pw, *pwEnd;
-    register MiBits msk;
-    register int ib, w;
-    register int ipt;		/* index into above arrays */
+    MiBits 	*pwLineStart;
+    MiBits	*pw, *pwEnd;
+    MiBits 	msk;
+    int 	ib, w;
+    int 	ipt;		/* index into above arrays */
     Bool 	fInBox;
     DDXPointRec	pt[NPT], ptThisLine;
     int		width[NPT];
diff --git a/mi/miregion.c b/mi/miregion.c
index 0db46dc..5422099 100644
--- a/mi/miregion.c
+++ b/mi/miregion.c
@@ -228,7 +228,7 @@ miPrintRegion(rgn)
     RegionPtr rgn;
 {
     int num, size;
-    register int i;
+    int i;
     BoxPtr rects;
 
     num = REGION_NUM_RECTS(rgn);
@@ -275,7 +275,7 @@ Bool
 miValidRegion(reg)
     RegionPtr reg;
 {
-    register int i, numRects;
+    int i, numRects;
 
     if ((reg->extents.x1 > reg->extents.x2) ||
 	(reg->extents.y1 > reg->extents.y2))
@@ -289,7 +289,7 @@ miValidRegion(reg)
 	return (!reg->data);
     else
     {
-	register BoxPtr pboxP, pboxN;
+	BoxPtr pboxP, pboxN;
 	BoxRec box;
 
 	pboxP = REGION_RECTS(reg);
@@ -331,7 +331,7 @@ miRegionCreate(rect, size)
     BoxPtr rect;
     int size;
 {
-    register RegionPtr pReg;
+    RegionPtr pReg;
    
     pReg = (RegionPtr)xalloc(sizeof(RegionRec));
     if (!pReg)
@@ -414,7 +414,7 @@ miRegionBreak (pReg)
 
 _X_EXPORT Bool
 miRectAlloc(
-    register RegionPtr pRgn,
+    RegionPtr pRgn,
     int n)
 {
     RegDataPtr	data;
@@ -455,8 +455,8 @@ miRectAlloc(
 
 _X_EXPORT Bool
 miRegionCopy(dst, src)
-    register RegionPtr dst;
-    register RegionPtr src;
+    RegionPtr dst;
+    RegionPtr src;
 {
     good(dst);
     good(src);
@@ -508,14 +508,14 @@ miRegionCopy(dst, src)
  */
 INLINE static int
 miCoalesce (
-    register RegionPtr	pReg,	    	/* Region to coalesce		     */
+    RegionPtr	pReg,	    	/* Region to coalesce		     */
     int	    	  	prevStart,  	/* Index of start of previous band   */
     int	    	  	curStart)   	/* Index of start of current band    */
 {
-    register BoxPtr	pPrevBox;   	/* Current box in previous band	     */
-    register BoxPtr	pCurBox;    	/* Current box in current band       */
-    register int  	numRects;	/* Number rectangles in both bands   */
-    register int	y2;		/* Bottom of current band	     */
+    BoxPtr	pPrevBox;   	/* Current box in previous band	     */
+    BoxPtr	pCurBox;    	/* Current box in current band       */
+    int  	numRects;	/* Number rectangles in both bands   */
+    int		y2;		/* Bottom of current band	     */
     /*
      * Figure out how many rectangles are in the band.
      */
@@ -592,14 +592,14 @@ miCoalesce (
 
 INLINE static Bool
 miAppendNonO (
-    register RegionPtr	pReg,
-    register BoxPtr	r,
-    BoxPtr  	  	rEnd,
-    register int  	y1,
-    register int  	y2)
+    RegionPtr	pReg,
+    BoxPtr	r,
+    BoxPtr  	rEnd,
+    int  	y1,
+    int  	y2)
 {
-    register BoxPtr	pNextRect;
-    register int	newRects;
+    BoxPtr	pNextRect;
+    int		newRects;
 
     newRects = rEnd - r;
 
@@ -691,25 +691,25 @@ miRegionOp(
 					    /* in region 2 ? */
     Bool	    *pOverlap)
 {
-    register BoxPtr r1;			    /* Pointer into first region     */
-    register BoxPtr r2;			    /* Pointer into 2d region	     */
-    BoxPtr	    r1End;		    /* End of 1st region	     */
-    BoxPtr	    r2End;		    /* End of 2d region		     */
-    short	    ybot;		    /* Bottom of intersection	     */
-    short	    ytop;		    /* Top of intersection	     */
-    RegDataPtr	    oldData;		    /* Old data for newReg	     */
-    int		    prevBand;		    /* Index of start of
-					     * previous band in newReg       */
-    int		    curBand;		    /* Index of start of current
-					     * band in newReg		     */
-    register BoxPtr r1BandEnd;		    /* End of current band in r1     */
-    register BoxPtr r2BandEnd;		    /* End of current band in r2     */
-    short	    top;		    /* Top of non-overlapping band   */
-    short	    bot;		    /* Bottom of non-overlapping band*/
-    register int    r1y1;		    /* Temps for r1->y1 and r2->y1   */
-    register int    r2y1;
-    int		    newSize;
-    int		    numRects;
+    BoxPtr 	r1;		    /* Pointer into first region     */
+    BoxPtr 	r2;		    /* Pointer into 2d region	     */
+    BoxPtr	r1End;		    /* End of 1st region	     */
+    BoxPtr	r2End;		    /* End of 2d region		     */
+    short	ybot;		    /* Bottom of intersection	     */
+    short	ytop;		    /* Top of intersection	     */
+    RegDataPtr	oldData;	    /* Old data for newReg	     */
+    int		prevBand;	    /* Index of start of
+				     * previous band in newReg       */
+    int		curBand;	    /* Index of start of current
+				     * band in newReg		     */
+    BoxPtr  	r1BandEnd;	    /* End of current band in r1     */
+    BoxPtr  	r2BandEnd;	    /* End of current band in r2     */
+    short   	top;		    /* Top of non-overlapping band   */
+    short   	bot;	    	    /* Bottom of non-overlapping band*/
+    int     	r1y1;	    	    /* Temps for r1->y1 and r2->y1   */
+    int     	r2y1;
+    int	    	newSize;
+    int	    	numRects;
 
     /*
      * Break any region computed from a broken region
@@ -915,9 +915,9 @@ miRegionOp(
  */
 void
 miSetExtents (pReg)
-    register RegionPtr pReg;
+    RegionPtr pReg;
 {
-    register BoxPtr pBox, pBoxEnd;
+    BoxPtr pBox, pBoxEnd;
 
     if (!pReg->data)
 	return;
@@ -974,18 +974,18 @@ miSetExtents (pReg)
 /*ARGSUSED*/
 static Bool
 miIntersectO (
-    register RegionPtr	pReg,
-    register BoxPtr	r1,
+    RegionPtr	pReg,
+    BoxPtr	r1,
     BoxPtr  	  	r1End,
-    register BoxPtr	r2,
+    BoxPtr	r2,
     BoxPtr  	  	r2End,
     short    	  	y1,
     short    	  	y2,
     Bool		*pOverlap)
 {
-    register int  	x1;
-    register int  	x2;
-    register BoxPtr	pNextRect;
+    int  	x1;
+    int  	x2;
+    BoxPtr	pNextRect;
 
     pNextRect = REGION_TOP(pReg);
 
@@ -1022,9 +1022,9 @@ miIntersectO (
 
 _X_EXPORT Bool
 miIntersect(newReg, reg1, reg2)
-    register RegionPtr 	newReg;     /* destination Region */
-    register RegionPtr 	reg1;
-    register RegionPtr	reg2;       /* source regions     */
+    RegionPtr 	newReg;     /* destination Region */
+    RegionPtr 	reg1;
+    RegionPtr	reg2;       /* source regions     */
 {
     good(reg1);
     good(reg2);
@@ -1117,18 +1117,18 @@ miIntersect(newReg, reg1, reg2)
  */
 static Bool
 miUnionO (
-    register RegionPtr	pReg,
-    register BoxPtr	r1,
-	     BoxPtr  	r1End,
-    register BoxPtr	r2,
-	     BoxPtr  	r2End,
-	     short	y1,
-	     short	y2,
-	     Bool	*pOverlap)
-{
-    register BoxPtr     pNextRect;
-    register int        x1;     /* left and right side of current union */
-    register int        x2;
+    RegionPtr	pReg,
+    BoxPtr	r1,
+    BoxPtr  	r1End,
+    BoxPtr	r2,
+    BoxPtr  	r2End,
+    short	y1,
+    short	y2,
+    Bool	*pOverlap)
+{
+    BoxPtr     pNextRect;
+    int        x1;     /* left and right side of current union */
+    int        x2;
 
     assert (y1 < y2);
     assert(r1 != r1End && r2 != r2End);
@@ -1178,8 +1178,8 @@ miUnionO (
 _X_EXPORT Bool 
 miUnion(newReg, reg1, reg2)
     RegionPtr		newReg;                  /* destination Region */
-    register RegionPtr 	reg1;
-    register RegionPtr	reg2;             /* source regions     */
+    RegionPtr 	reg1;
+    RegionPtr	reg2;             /* source regions     */
 {
     Bool overlap; /* result ignored */
 
@@ -1276,8 +1276,8 @@ miUnion(newReg, reg1, reg2)
  */
 _X_EXPORT Bool
 miRegionAppend(dstrgn, rgn)
-    register RegionPtr dstrgn;
-    register RegionPtr rgn;
+    RegionPtr dstrgn;
+    RegionPtr rgn;
 {
     int numRects, dnumRects, size;
     BoxPtr new, old;
@@ -1307,7 +1307,7 @@ miRegionAppend(dstrgn, rgn)
 	dstrgn->extents = rgn->extents;
     else if (dstrgn->extents.x2 > dstrgn->extents.x1)
     {
-	register BoxPtr first, last;
+	BoxPtr first, last;
 
 	first = old;
 	last = REGION_BOXPTR(dstrgn) + (dnumRects - 1);
@@ -1371,13 +1371,13 @@ miRegionAppend(dstrgn, rgn)
 
 static void
 QuickSortRects(
-    register BoxRec     rects[],
-    register int        numRects)
+    BoxRec     rects[],
+    int        numRects)
 {
-    register int	y1;
-    register int	x1;
-    register int        i, j;
-    register BoxPtr     r;
+    int	y1;
+    int	x1;
+    int        i, j;
+    BoxPtr     r;
 
     /* Always called with numRects > 1 */
 
@@ -1472,17 +1472,17 @@ miRegionValidate(badreg, pOverlap)
 	int	    curBand;
     } RegionInfo;
 
-	     int	numRects;   /* Original numRects for badreg	    */
-	     RegionInfo *ri;	    /* Array of current regions		    */
-    	     int	numRI;      /* Number of entries used in ri	    */
-	     int	sizeRI;	    /* Number of entries available in ri    */
-	     int	i;	    /* Index into rects			    */
-    register int	j;	    /* Index into ri			    */
-    register RegionInfo *rit;       /* &ri[j]				    */
-    register RegionPtr  reg;        /* ri[j].reg			    */
-    register BoxPtr	box;	    /* Current box in rects		    */
-    register BoxPtr	riBox;      /* Last box in ri[j].reg		    */
-    register RegionPtr  hreg;       /* ri[j_half].reg			    */
+    int	numRects;   /* Original numRects for badreg	    */
+    RegionInfo *ri;	    /* Array of current regions		    */
+    int	numRI;      /* Number of entries used in ri	    */
+    int	sizeRI;	    /* Number of entries available in ri    */
+    int	i;	    /* Index into rects			    */
+    int	j;	    /* Index into ri			    */
+    RegionInfo *rit;       /* &ri[j]				    */
+    RegionPtr  reg;        /* ri[j].reg			    */
+    BoxPtr	box;	    /* Current box in rects		    */
+    BoxPtr	riBox;      /* Last box in ri[j].reg		    */
+    RegionPtr  hreg;       /* ri[j_half].reg			    */
     Bool		ret = TRUE;
 
     *pOverlap = FALSE;
@@ -1654,13 +1654,13 @@ bail:
 _X_EXPORT RegionPtr
 miRectsToRegion(nrects, prect, ctype)
     int			nrects;
-    register xRectangle	*prect;
+    xRectangle		*prect;
     int			ctype;
 {
-    register RegionPtr	pRgn;
-    register RegDataPtr	pData;
-    register BoxPtr	pBox;
-    register int        i;
+    RegionPtr		pRgn;
+    RegDataPtr		pData;
+    BoxPtr		pBox;
+    int        		i;
     int			x1, y1, x2, y2;
 
     pRgn = miRegionCreate(NullBox, 0);
@@ -1754,17 +1754,17 @@ miRectsToRegion(nrects, prect, ctype)
 /*ARGSUSED*/
 static Bool
 miSubtractO (
-    register RegionPtr	pReg,
-    register BoxPtr	r1,
-    BoxPtr  	  	r1End,
-    register BoxPtr	r2,
-    BoxPtr  	  	r2End,
-    register short  	y1,
-             short  	y2,
-    Bool		*pOverlap)
+    RegionPtr	pReg,
+    BoxPtr	r1,
+    BoxPtr  	r1End,
+    BoxPtr	r2,
+    BoxPtr  	r2End,
+    short  	y1,
+    short  	y2,
+    Bool	*pOverlap)
 {
-    register BoxPtr	pNextRect;
-    register int  	x1;
+    BoxPtr	pNextRect;
+    int  	x1;
 
     x1 = r1->x1;
     
@@ -1878,9 +1878,9 @@ miSubtractO (
  */
 _X_EXPORT Bool
 miSubtract(regD, regM, regS)
-    register RegionPtr	regD;               
-    register RegionPtr 	regM;
-    register RegionPtr	regS;          
+    RegionPtr	regD;               
+    RegionPtr 	regM;
+    RegionPtr	regS;          
 {
     Bool overlap; /* result ignored */
 
@@ -2003,15 +2003,15 @@ miInverse(newReg, reg1, invRect)
 
 _X_EXPORT int
 miRectIn(region, prect)
-    register RegionPtr  region;
-    register BoxPtr     prect;
+    RegionPtr  region;
+    BoxPtr     prect;
 {
-    register int	x;
-    register int	y;
-    register BoxPtr     pbox;
-    register BoxPtr     pboxEnd;
-    int			partIn, partOut;
-    int			numRects;
+    int		x;
+    int		y;
+    BoxPtr	pbox;
+    BoxPtr	pboxEnd;
+    int		partIn, partOut;
+    int		numRects;
 
     good(region);
     numRects = REGION_NUM_RECTS(region);
@@ -2099,13 +2099,13 @@ miRectIn(region, prect)
 
 _X_EXPORT void
 miTranslateRegion(pReg, x, y)
-    register RegionPtr pReg;
-    register int x;
-    register int y;
+    RegionPtr pReg;
+    int x;
+    int y;
 {
     int x1, x2, y1, y2;
-    register int nbox;
-    register BoxPtr pbox;
+    int nbox;
+    BoxPtr pbox;
 
     good(pReg);
     pReg->extents.x1 = x1 = pReg->extents.x1 + x;
@@ -2144,7 +2144,7 @@ miTranslateRegion(pReg, x, y)
 	pReg->extents.y2 = MAXSHORT;
     if (pReg->data && (nbox = pReg->data->numRects))
     {
-	register BoxPtr pboxout;
+	BoxPtr pboxout;
 
 	for (pboxout = pbox = REGION_BOXPTR(pReg); nbox--; pbox++)
 	{
@@ -2184,8 +2184,8 @@ miTranslateRegion(pReg, x, y)
 
 Bool
 miRegionDataCopy(
-    register RegionPtr dst,
-    register RegionPtr src)
+    RegionPtr dst,
+    RegionPtr src)
 {
     good(dst);
     good(src);
@@ -2226,11 +2226,11 @@ miRegionReset(pReg, pBox)
 
 _X_EXPORT Bool
 miPointInRegion(pReg, x, y, box)
-    register RegionPtr pReg;
-    register int x, y;
+    RegionPtr pReg;
+    int x, y;
     BoxPtr box;     /* "return" value */
 {
-    register BoxPtr pbox, pboxEnd;
+    BoxPtr pbox, pboxEnd;
     int numRects;
 
     good(pReg);
@@ -2294,8 +2294,8 @@ miRegionExtents(pReg)
 
 #define ExchangeSpans(a, b)				    \
 {							    \
-    DDXPointRec     tpt;				    \
-    register int    tw;					    \
+    DDXPointRec	tpt;				    	    \
+    int    	tw;					    \
 							    \
     tpt = spans[a]; spans[a] = spans[b]; spans[b] = tpt;    \
     tw = widths[a]; widths[a] = widths[b]; widths[b] = tw;  \
@@ -2307,13 +2307,13 @@ miRegionExtents(pReg)
 */
 
 static void QuickSortSpans(
-    register DDXPointRec    spans[],
-    register int	    widths[],
-    register int	    numSpans)
-{
-    register int	    y;
-    register int	    i, j, m;
-    register DDXPointPtr    r;
+    DDXPointRec spans[],
+    int	    	widths[],
+    int	    	numSpans)
+{
+    int	    y;
+    int	    i, j, m;
+    DDXPointPtr    r;
 
     /* Always called with numSpans > 1 */
     /* Sorts only by y, doesn't bother to sort by x */
@@ -2323,7 +2323,7 @@ static void QuickSortSpans(
 	if (numSpans < 9)
 	{
 	    /* Do insertion sort */
-	    register int yprev;
+	    int yprev;
 
 	    yprev = spans[0].y;
 	    i = 1;
@@ -2412,18 +2412,18 @@ static void QuickSortSpans(
 
 _X_EXPORT int
 miClipSpans(
-    RegionPtr		    prgnDst,
-    register DDXPointPtr    ppt,
-    register int	    *pwidth,
-    int			    nspans,
-    register DDXPointPtr    pptNew,
-    int			    *pwidthNew,
-    int			    fSorted)
-{
-    register DDXPointPtr pptLast;
-    int			*pwidthNewStart;	/* the vengeance of Xerox! */
-    register int	y, x1, x2;
-    register int	numRects;
+    RegionPtr	prgnDst,
+    DDXPointPtr ppt,
+    int	    	*pwidth,
+    int		nspans,
+    DDXPointPtr	pptNew,
+    int		*pwidthNew,
+    int		fSorted)
+{
+    DDXPointPtr pptLast;
+    int	*pwidthNewStart;	/* the vengeance of Xerox! */
+    int	y, x1, x2;
+    int	numRects;
 
     good(prgnDst);
     pptLast = ppt + nspans;
@@ -2435,7 +2435,7 @@ miClipSpans(
 	/* It doesn't pay much to make use of fSorted in this case, 
 	   so we lump everything together. */
 
-	register    int clipx1, clipx2, clipy1, clipy2;
+	int clipx1, clipx2, clipy1, clipy2;
 
 	clipx1 = prgnDst->extents.x1;
 	clipy1 = prgnDst->extents.y1;
@@ -2467,10 +2467,10 @@ miClipSpans(
     else if ((numRects = prgnDst->data->numRects))
     {
 	/* Have to clip against many boxes */
-	BoxPtr		pboxBandStart, pboxBandEnd;
-	register BoxPtr pbox;
-	register BoxPtr pboxLast;
-	register int	clipy1, clipy2;
+	BoxPtr pboxBandStart, pboxBandEnd;
+	BoxPtr pbox;
+	BoxPtr pboxLast;
+	int clipy1, clipy2;
 
 	/* In this case, taking advantage of sorted spans gains more than
 	   the sorting costs. */
@@ -2493,7 +2493,7 @@ miClipSpans(
 		x2 = x1 + *pwidth;
 		do
 		{ /* For each box in band */
-		    register int    newx1, newx2;
+		    int newx1, newx2;
 
 		    newx1 = x1;
 		    newx2 = x2;
@@ -2531,10 +2531,10 @@ _X_EXPORT int
 miFindMaxBand(prgn)
     RegionPtr prgn;
 {
-    register int nbox;
-    register BoxPtr pbox;
-    register int nThisBand;
-    register int nMaxBand = 0;
+    int nbox;
+    BoxPtr pbox;
+    int nThisBand;
+    int nMaxBand = 0;
     short yThisBand;
 
     good(prgn);
diff --git a/mi/miscrinit.c b/mi/miscrinit.c
index ac1b823..7922cb6 100644
--- a/mi/miscrinit.c
+++ b/mi/miscrinit.c
@@ -185,7 +185,7 @@ miCreateScreenResources(pScreen)
 
 Bool
 miScreenDevPrivateInit(pScreen, width, pbits)
-    register ScreenPtr pScreen;
+    ScreenPtr pScreen;
     int width;
     pointer pbits;
 {
@@ -207,7 +207,7 @@ miScreenDevPrivateInit(pScreen, width, p
 _X_EXPORT Bool
 miScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy, width,
 	     rootDepth, numDepths, depths, rootVisual, numVisuals, visuals)
-    register ScreenPtr pScreen;
+    ScreenPtr pScreen;
     pointer pbits;		/* pointer to screen bits */
     int xsize, ysize;		/* in pixels */
     int dpix, dpiy;		/* dots per inch */
diff --git a/mi/mispans.c b/mi/mispans.c
index 4c8b6d6..61d72e4 100644
--- a/mi/mispans.c
+++ b/mi/mispans.c
@@ -188,8 +188,8 @@ void miAppendSpans(spanGroup, otherGroup
     SpanGroup	*otherGroup;
     Spans       *spans;
 {
-    register    int ymin, ymax;
-    register    int spansCount;
+    int ymin, ymax;
+    int spansCount;
 
     spansCount = spans->count;
     if (spansCount > 0) {
@@ -226,21 +226,21 @@ void miFreeSpanGroup(spanGroup)
 }
 
 static void QuickSortSpansX(
-    register DDXPointRec    points[],
-    register int	    widths[],
-    register int	    numSpans )
+    DDXPointRec points[],
+    int		widths[],
+    int		numSpans )
 {
-    register int	    x;
-    register int	    i, j, m;
-    register DDXPointPtr    r;
+    int	    		x;
+    int	    		i, j, m;
+    DDXPointPtr 	r;
 
 /* Always called with numSpans > 1 */
 /* Sorts only by x, as all y should be the same */
 
 #define ExchangeSpans(a, b)				    \
 {							    \
-    DDXPointRec     tpt;				    \
-    register int    tw;					    \
+    DDXPointRec 	tpt;				    \
+    int    		tw;				    \
 							    \
     tpt = points[a]; points[a] = points[b]; points[b] = tpt;    \
     tw = widths[a]; widths[a] = widths[b]; widths[b] = tw;  \
@@ -249,7 +249,7 @@ static void QuickSortSpansX(
     do {
 	if (numSpans < 9) {
 	    /* Do insertion sort */
-	    register int xprev;
+	    int xprev;
 
 	    xprev = points[0].x;
 	    i = 1;
@@ -313,14 +313,14 @@ static void QuickSortSpansX(
 
 
 static int UniquifySpansX(
-    Spans		    *spans,
-    register DDXPointRec    *newPoints,
-    register int	    *newWidths )
+    Spans	    	*spans,
+    DDXPointRec    	*newPoints,
+    int	    		*newWidths )
 {
-    register int newx1, newx2, oldpt, i, y;
-    register DDXPointRec    *oldPoints;
-    register int	    *oldWidths;
-    int			    *startNewWidths;
+    int 		newx1, newx2, oldpt, i, y;
+    DDXPointRec		*oldPoints;
+    int	    		*oldWidths;
+    int			*startNewWidths;
 
 /* Always called with numSpans > 1 */
 /* Uniquify the spans, and stash them into newPoints and newWidths.  Return the
@@ -384,16 +384,16 @@ void miFillUniqueSpanGroup(pDraw, pGC, s
     GCPtr	pGC;
     SpanGroup   *spanGroup;
 {
-    register int    i;
-    register Spans  *spans;
-    register Spans  *yspans;
-    register int    *ysizes;
-    register int    ymin, ylength;
+    int    		i;
+    Spans  		*spans;
+    Spans  		*yspans;
+    int    		*ysizes;
+    int    		ymin, ylength;
 
     /* Outgoing spans for one big call to FillSpans */
-    register DDXPointPtr    points;
-    register int	    *widths;
-    register int	    count;
+    DDXPointPtr    	points;
+    int	    		*widths;
+    int	    		count;
 
     if (spanGroup->count == 0) return;
 
@@ -545,8 +545,8 @@ void miFillSpanGroup(pDraw, pGC, spanGro
     GCPtr	pGC;
     SpanGroup   *spanGroup;
 {
-    register int    i;
-    register Spans  *spans;
+    int    i;
+    Spans  *spans;
 
     for (i = 0, spans = spanGroup->group; i != spanGroup->count; i++, spans++) {
 	(*pGC->ops->FillSpans)
diff --git a/mi/misprite.c b/mi/misprite.c
index 286c755..c0560a4 100644
--- a/mi/misprite.c
+++ b/mi/misprite.c
@@ -320,11 +320,11 @@ miSpriteGetSpans (pDrawable, wMax, ppt, 
 
     if (pDrawable->type == DRAWABLE_WINDOW && pScreenPriv->isUp)
     {
-	register DDXPointPtr    pts;
-	register int    	*widths;
-	register int    	nPts;
-	register int    	xorg,
-				yorg;
+	DDXPointPtr    	pts;
+	int    		*widths;
+	int    		nPts;
+	int    		xorg,
+			yorg;
 
 	xorg = pDrawable->x;
 	yorg = pDrawable->y;
diff --git a/mi/mivaltree.c b/mi/mivaltree.c
index 0e5ed61..92ea0a8 100644
--- a/mi/mivaltree.c
+++ b/mi/mivaltree.c
@@ -112,13 +112,13 @@ miShapedWindowIn (pScreen, universe, bou
     ScreenPtr	pScreen;
     RegionPtr	universe, bounding;
     BoxPtr	rect;
-    register int x, y;
+    int 	x, y;
 {
-    BoxRec  box;
-    register BoxPtr  boundBox;
-    int	    nbox;
-    Bool    someIn, someOut;
-    register int t, x1, y1, x2, y2;
+    BoxRec  	box;
+    BoxPtr	boundBox;
+    int		nbox;
+    Bool	someIn, someOut;
+    int 	t, x1, y1, x2, y2;
 
     nbox = REGION_NUM_RECTS (bounding);
     boundBox = REGION_RECTS (bounding);
@@ -202,16 +202,16 @@ miRegisterRedirectBorderClipProc (SetRed
  */
 static void
 miComputeClips (
-    register WindowPtr	pParent,
-    register ScreenPtr	pScreen,
-    register RegionPtr	universe,
+    WindowPtr	pParent,
+    ScreenPtr	pScreen,
+    RegionPtr	universe,
     VTKind		kind,
     RegionPtr		exposed ) /* for intermediate calculations */
 {
     int			dx,
 			dy;
     RegionRec		childUniverse;
-    register WindowPtr	pChild;
+    WindowPtr		pChild;
     int     	  	oldVis, newVis;
     BoxRec		borderSize;
     RegionRec		childUnion;
@@ -535,10 +535,10 @@ miComputeClips (
 
 static void
 miTreeObscured(
-    register WindowPtr pParent )
+    WindowPtr pParent )
 {
-    register WindowPtr pChild;
-    register int    oldVis;
+    WindowPtr 	pChild;
+    int    	oldVis;
 
     pChild = pParent;
     while (1)
@@ -609,8 +609,8 @@ miValidateTree (pParent, pChild, kind)
     RegionRec		childUnion; /* the space covered by borderSize for
 				     * all marked children */
     RegionRec		exposed;    /* For intermediate calculations */
-    register ScreenPtr	pScreen;
-    register WindowPtr	pWin;
+    ScreenPtr		pScreen;
+    WindowPtr		pWin;
     Bool		overlap;
     int			viewvals;
     Bool		forward;
diff --git a/mi/miwideline.c b/mi/miwideline.c
index d57c2ea..7f99aca 100644
--- a/mi/miwideline.c
+++ b/mi/miwideline.c
@@ -56,10 +56,10 @@ from The Open Group.
 ICEILTEMPDECL
 #endif
 
-static void miLineArc(DrawablePtr pDraw, register GCPtr pGC,
+static void miLineArc(DrawablePtr pDraw, GCPtr pGC,
 		      unsigned long pixel, SpanDataPtr spanData,
-		      register LineFacePtr leftFace,
-		      register LineFacePtr rightFace,
+		      LineFacePtr leftFace,
+		      LineFacePtr rightFace,
 		      double xorg, double yorg, Bool isInt);
 
 
@@ -79,12 +79,12 @@ miFillPolyHelper (pDrawable, pGC, pixel,
     PolyEdgePtr	left, right;
     int		left_count, right_count;
 {
-    register int left_x = 0, left_e = 0;
+    int left_x = 0, left_e = 0;
     int	left_stepx = 0;
     int	left_signdx = 0;
     int	left_dy = 0, left_dx = 0;
 
-    register int right_x = 0, right_e = 0;
+    int right_x = 0, right_e = 0;
     int	right_stepx = 0;
     int	right_signdx = 0;
     int	right_dy = 0, right_dx = 0;
@@ -92,10 +92,10 @@ miFillPolyHelper (pDrawable, pGC, pixel,
     int	height = 0;
     int	left_height = 0, right_height = 0;
 
-    register DDXPointPtr ppt;
+    DDXPointPtr ppt;
     DDXPointPtr pptInit = NULL;
-    register int *pwidth;
-    int *pwidthInit = NULL;
+    int 	*pwidth;
+    int 	*pwidthInit = NULL;
     XID		oldPixel;
     int		xorg;
     Spans	spanRec;
@@ -203,8 +203,8 @@ miFillRectPolyHelper (
     int		w,
     int		h)
 {
-    register DDXPointPtr ppt;
-    register int *pwidth;
+    DDXPointPtr ppt;
+    int 	*pwidth;
     XID		oldPixel;
     Spans	spanRec;
     xRectangle  rect;
@@ -265,10 +265,10 @@ _X_EXPORT /* static */ int
 miPolyBuildEdge (x0, y0, k, dx, dy, xi, yi, left, edge)
     double	x0, y0;
     double	k;  /* x0 * dy - y0 * dx */
-    register int dx, dy;
+    int 	dx, dy;
     int		xi, yi;
     int		left;
-    register PolyEdgePtr edge;
+    PolyEdgePtr edge;
 {
     int	    x, y, e;
     int	    xady;
@@ -322,23 +322,23 @@ miPolyBuildEdge (x0, y0, k, dx, dy, xi, 
 
 _X_EXPORT /* static */ int
 miPolyBuildPoly (vertices, slopes, count, xi, yi, left, right, pnleft, pnright, h)
-    register PolyVertexPtr vertices;
-    register PolySlopePtr  slopes;
-    int		    count;
-    int		    xi, yi;
-    PolyEdgePtr	    left, right;
-    int		    *pnleft, *pnright;
-    int		    *h;
+    PolyVertexPtr 	vertices;
+    PolySlopePtr	slopes;
+    int			count;
+    int		   	xi, yi;
+    PolyEdgePtr	    	left, right;
+    int		    	*pnleft, *pnright;
+    int		    	*h;
 {
-    int	    top, bottom;
-    double  miny, maxy;
-    register int i;
-    int	    j;
-    int	    clockwise;
-    int	    slopeoff;
-    register int s;
-    register int nright, nleft;
-    int	    y, lasty = 0, bottomy, topy = 0;
+    int 	top, bottom;
+    double 	miny, maxy;
+    int 	i;
+    int		j;
+    int		clockwise;
+    int		slopeoff;
+    int 	s;
+    int 	nright, nleft;
+    int	   	y, lasty = 0, bottomy, topy = 0;
 
     /* find the top of the polygon */
     maxy = miny = vertices[0].y;
@@ -467,12 +467,12 @@ miLineOnePoint (
 
 static void
 miLineJoin (
-    DrawablePtr	    pDrawable,
-    GCPtr	    pGC,
-    unsigned long   pixel,
-    SpanDataPtr	    spanData,
-    register LineFacePtr pLeft,
-    register LineFacePtr pRight)
+    DrawablePtr 	pDrawable,
+    GCPtr		pGC,
+    unsigned long	pixel,
+    SpanDataPtr		spanData,
+    LineFacePtr		pLeft,
+    LineFacePtr 	pRight)
 {
     double	    mx = 0, my = 0;
     double	    denom = 0.0;
@@ -624,9 +624,9 @@ miLineArcI (
     DDXPointPtr	    points,
     int		    *widths)
 {
-    register DDXPointPtr tpts, bpts;
-    register int *twids, *bwids;
-    register int x, y, e, ex, slw;
+    DDXPointPtr tpts, bpts;
+    int *twids, *bwids;
+    int x, y, e, ex, slw;
 
     tpts = points;
     twids = widths;
@@ -717,8 +717,8 @@ miLineArcD (
     int		    edgey2,
     Bool	    edgeleft2)
 {
-    register DDXPointPtr pts;
-    register int *wids;
+    DDXPointPtr pts;
+    int *wids;
     double radius, x0, y0, el, er, yk, xlk, xrk, k;
     int xbase, ybase, y, boty, xl, xr, xcl, xcr;
     int ymin, ymax;
@@ -875,8 +875,8 @@ miLineArcD (
 
 int
 miRoundJoinFace (face, edge, leftEdge)
-    register LineFacePtr face;
-    register PolyEdgePtr edge;
+    LineFacePtr face;
+    PolyEdgePtr edge;
     Bool	*leftEdge;
 {
     int	    y;
@@ -924,7 +924,7 @@ miRoundJoinFace (face, edge, leftEdge)
 
 _X_EXPORT void
 miRoundJoinClip (pLeft, pRight, edge1, edge2, y1, y2, left1, left2)
-    register LineFacePtr pLeft, pRight;
+    LineFacePtr pLeft, pRight;
     PolyEdgePtr	edge1, edge2;
     int		*y1, *y2;
     Bool	*left1, *left2;
@@ -949,14 +949,14 @@ miRoundJoinClip (pLeft, pRight, edge1, e
 
 _X_EXPORT int
 miRoundCapClip (face, isInt, edge, leftEdge)
-    register LineFacePtr face;
+    LineFacePtr face;
     Bool	isInt;
-    register PolyEdgePtr edge;
+    PolyEdgePtr edge;
     Bool	*leftEdge;
 {
-    int	    y;
-    register int dx, dy;
-    double  xa, ya, k;
+    int		y;
+    int 	dx, dy;
+    double	xa, ya, k;
     Bool	left;
 
     dx = -face->dy;
@@ -999,15 +999,15 @@ miRoundCapClip (face, isInt, edge, leftE
 
 static void
 miLineArc (
-    DrawablePtr	    pDraw,
-    register GCPtr  pGC,
-    unsigned long   pixel,
-    SpanDataPtr	    spanData,
-    register LineFacePtr leftFace,
-    register LineFacePtr rightFace,
-    double	    xorg,
-    double          yorg,
-    Bool	    isInt)
+    DrawablePtr		pDraw,
+    GCPtr  		pGC,
+    unsigned long	pixel,
+    SpanDataPtr		spanData,
+    LineFacePtr		leftFace,
+    LineFacePtr 	rightFace,
+    double	    	xorg,
+    double          	yorg,
+    Bool	    	isInt)
 {
     DDXPointPtr points;
     int *widths;
@@ -1116,14 +1116,14 @@ miLineArc (
 
 void
 miLineProjectingCap (pDrawable, pGC, pixel, spanData, face, isLeft, xorg, yorg, isInt)
-    DrawablePtr	    pDrawable;
-    register GCPtr  pGC;
-    unsigned long   pixel;
-    SpanDataPtr	    spanData;
-    register LineFacePtr face;
-    Bool	    isLeft;
-    double	    xorg, yorg;
-    Bool	    isInt;
+    DrawablePtr		pDrawable;
+    GCPtr  		pGC;
+    unsigned long	pixel;
+    SpanDataPtr		spanData;
+    LineFacePtr 	face;
+    Bool	    	isLeft;
+    double	    	xorg, yorg;
+    Bool	    	isInt;
 {
     int	xorgi = 0, yorgi = 0;
     int	lw;
@@ -1286,18 +1286,18 @@ miLineProjectingCap (pDrawable, pGC, pix
 
 static void
 miWideSegment (
-    DrawablePtr	    pDrawable,
-    GCPtr	    pGC,
-    unsigned long   pixel,
-    SpanDataPtr	    spanData,
-    register int    x1,
-    register int    y1,
-    register int    x2,
-    register int    y2,
-    Bool	    projectLeft,
-    Bool	    projectRight,
-    register LineFacePtr leftFace,
-    register LineFacePtr rightFace)
+    DrawablePtr		pDrawable,
+    GCPtr		pGC,
+    unsigned long	pixel,
+    SpanDataPtr		spanData,
+    int    		x1,
+    int    		y1,
+    int    		x2,
+    int    		y2,
+    Bool		projectLeft,
+    Bool		projectRight,
+    LineFacePtr 	leftFace,
+    LineFacePtr 	rightFace)
 {
     double	l, L, r;
     double	xa, ya;
@@ -1508,7 +1508,7 @@ miWideSegment (
 
 SpanDataPtr
 miSetupSpanData (pGC, spanData, npt)
-    register GCPtr pGC;
+    GCPtr pGC;
     SpanDataPtr	spanData;
     int		npt;
 {
@@ -1552,21 +1552,21 @@ miCleanupSpanData (pDrawable, pGC, spanD
 _X_EXPORT void
 miWideLine (pDrawable, pGC, mode, npt, pPts)
     DrawablePtr	pDrawable;
-    register GCPtr pGC;
+    GCPtr 	pGC;
     int		mode;
-    register int npt;
-    register DDXPointPtr pPts;
+    int 	npt;
+    DDXPointPtr pPts;
 {
-    int		    x1, y1, x2, y2;
-    SpanDataRec	    spanDataRec;
-    SpanDataPtr	    spanData;
-    unsigned long   pixel;
-    Bool	    projectLeft, projectRight;
-    LineFaceRec	    leftFace, rightFace, prevRightFace;
-    LineFaceRec	    firstFace;
-    register int    first;
-    Bool	    somethingDrawn = FALSE;
-    Bool	    selfJoin;
+    int		x1, y1, x2, y2;
+    SpanDataRec	spanDataRec;
+    SpanDataPtr	spanData;
+    long   	pixel;
+    Bool	projectLeft, projectRight;
+    LineFaceRec	leftFace, rightFace, prevRightFace;
+    LineFaceRec	firstFace;
+    int		first;
+    Bool	somethingDrawn = FALSE;
+    Bool	selfJoin;
 
     spanData = miSetupSpanData (pGC, &spanDataRec, npt);
     pixel = pGC->fgPixel;
@@ -1693,7 +1693,7 @@ miWideLine (pDrawable, pGC, mode, npt, p
 static void
 miWideDashSegment (
     DrawablePtr	    pDrawable,
-    register GCPtr  pGC,
+    GCPtr  	    pGC,
     SpanDataPtr	    spanData,
     int		    *pDashOffset,
     int		    *pDashIndex,
@@ -2050,25 +2050,25 @@ miWideDashSegment (
 _X_EXPORT void
 miWideDash (pDrawable, pGC, mode, npt, pPts)
     DrawablePtr	pDrawable;
-    register GCPtr pGC;
+    GCPtr 	pGC;
     int		mode;
-    register int npt;
-    register DDXPointPtr pPts;
+    int 	npt;
+    DDXPointPtr pPts;
 {
-    int		    x1, y1, x2, y2;
-    unsigned long   pixel;
-    Bool	    projectLeft, projectRight;
-    LineFaceRec	    leftFace, rightFace, prevRightFace;
-    LineFaceRec	    firstFace;
-    int		    first;
-    int		    dashIndex, dashOffset;
-    register int    prevDashIndex;
-    SpanDataRec	    spanDataRec;
-    SpanDataPtr	    spanData;
-    Bool	    somethingDrawn = FALSE;
-    Bool	    selfJoin;
-    Bool	    endIsFg = FALSE, startIsFg = FALSE;
-    Bool            firstIsFg = FALSE, prevIsFg = FALSE;
+    int			x1, y1, x2, y2;
+    unsigned long	pixel;
+    Bool		projectLeft, projectRight;
+    LineFaceRec		leftFace, rightFace, prevRightFace;
+    LineFaceRec		firstFace;
+    int			first;
+    int			dashIndex, dashOffset;
+    int			prevDashIndex;
+    SpanDataRec		spanDataRec;
+    SpanDataPtr		spanData;
+    Bool		somethingDrawn = FALSE;
+    Bool		selfJoin;
+    Bool		endIsFg = FALSE, startIsFg = FALSE;
+    Bool		firstIsFg = FALSE, prevIsFg = FALSE;
 
 #if 0
     /* XXX backward compatibility */
diff --git a/mi/miwindow.c b/mi/miwindow.c
index cd6bb8d..6ca2e1e 100644
--- a/mi/miwindow.c
+++ b/mi/miwindow.c
@@ -160,12 +160,12 @@ miClearToBackground(pWin, x, y, w, h, ge
  */
 static Bool
 miCheckSubSaveUnder(
-    register WindowPtr	pParent,	/* Parent to check */
+    WindowPtr		pParent,	/* Parent to check */
     WindowPtr		pFirst,		/* first reconfigured window */
     RegionPtr		pRegion)	/* Initial area obscured by saveUnder */
 {
-    register WindowPtr	pChild;		/* Current child */
-    register ScreenPtr	pScreen;	/* Screen to use */
+    WindowPtr		pChild;		/* Current child */
+    ScreenPtr		pScreen;	/* Screen to use */
     RegionRec		SubRegion;	/* Area of children obscured */
     Bool		res = FALSE;	/* result */
     Bool		subInited=FALSE;/* SubRegion initialized */
@@ -268,12 +268,12 @@ miCheckSubSaveUnder(
  */
 Bool
 miChangeSaveUnder(pWin, first)
-    register WindowPtr	pWin;
+    WindowPtr		pWin;
     WindowPtr		first;		/* First window to check.
 					 * Used when pWin was restacked */
 {
     RegionRec	rgn;	/* Area obscured by saveUnder windows */
-    register ScreenPtr pScreen;
+    ScreenPtr 	pScreen;
     Bool	res;
 
     if (!deltaSaveUndersViewable && !numSaveUndersViewable)
@@ -309,7 +309,7 @@ miPostChangeSaveUnder(pWin, pFirst)
     WindowPtr		pWin;
     WindowPtr		pFirst;
 {
-    register WindowPtr pParent, pChild;
+    WindowPtr pParent, pChild;
     ChangeWindowAttributesProcPtr ChangeWindowAttributes;
 
     if (!(pParent = pWin->parent))
@@ -342,9 +342,9 @@ miPostChangeSaveUnder(pWin, pFirst)
 
 void
 miMarkWindow(pWin)
-    register WindowPtr pWin;
+    WindowPtr pWin;
 {
-    register ValidatePtr val;
+    ValidatePtr val;
 
     if (pWin->valdata)
 	return;
@@ -362,8 +362,8 @@ miMarkOverlappedWindows(pWin, pFirst, pp
     WindowPtr pFirst;
     WindowPtr *ppLayerWin;
 {
-    register BoxPtr box;
-    register WindowPtr pChild, pLast;
+    BoxPtr box;
+    WindowPtr pChild, pLast;
     Bool anyMarked = FALSE;
     MarkWindowProcPtr MarkWindow = pWin->drawable.pScreen->MarkWindow;
     ScreenPtr pScreen;
@@ -449,8 +449,8 @@ _X_EXPORT void
 miHandleValidateExposures(pWin)
     WindowPtr pWin;
 {
-    register WindowPtr pChild;
-    register ValidatePtr val;
+    WindowPtr pChild;
+    ValidatePtr val;
     ScreenPtr pScreen;
     WindowExposuresProcPtr WindowExposures;
 
@@ -487,7 +487,7 @@ miHandleValidateExposures(pWin)
 
 void
 miMoveWindow(pWin, x, y, pNextSib, kind)
-    register WindowPtr pWin;
+    WindowPtr pWin;
     int x,y;
     WindowPtr pNextSib;
     VTKind kind;
@@ -498,7 +498,7 @@ miMoveWindow(pWin, x, y, pNextSib, kind)
     RegionPtr oldRegion = NULL;
     DDXPointRec oldpt;
     Bool anyMarked = FALSE;
-    register ScreenPtr pScreen;
+    ScreenPtr pScreen;
     WindowPtr windowToValidate;
 #ifdef DO_SAVE_UNDERS
     Bool dosave = FALSE;
@@ -576,10 +576,10 @@ miMoveWindow(pWin, x, y, pNextSib, kind)
 
 static int
 miRecomputeExposures (
-    register WindowPtr	pWin,
+    WindowPtr	pWin,
     pointer		value) /* must conform to VisitWindowProcPtr */
 {
-    register ScreenPtr	pScreen;
+    ScreenPtr	pScreen;
     RegionPtr	pValid = (RegionPtr)value;
 
     if (pWin->valdata)
@@ -604,7 +604,7 @@ miRecomputeExposures (
 
 void
 miSlideAndSizeWindow(pWin, x, y, w, h, pSib)
-    register WindowPtr pWin;
+    WindowPtr pWin;
     int x,y;
     unsigned int w, h;
     WindowPtr pSib;
@@ -620,11 +620,11 @@ miSlideAndSizeWindow(pWin, x, y, w, h, p
     DDXPointRec oldpt;
     RegionPtr oldRegion = NULL;
     Bool anyMarked = FALSE;
-    register ScreenPtr pScreen;
+    ScreenPtr pScreen;
     WindowPtr pFirstChange;
-    register WindowPtr pChild;
+    WindowPtr pChild;
     RegionPtr	gravitate[StaticGravity + 1];
-    register unsigned g;
+    unsigned g;
     int		nx, ny;		/* destination x,y */
     int		newx, newy;	/* new inner window position */
     RegionPtr	pRegion = NULL;
@@ -981,10 +981,10 @@ miGetLayerWindow(pWin)
 
 _X_EXPORT void
 miSetShape(pWin)
-    register WindowPtr	pWin;
+    WindowPtr	pWin;
 {
     Bool	WasViewable = (Bool)(pWin->viewable);
-    register ScreenPtr pScreen = pWin->drawable.pScreen;
+    ScreenPtr 	pScreen = pWin->drawable.pScreen;
     Bool	anyMarked = FALSE;
     RegionPtr	pOldClip = NULL, bsExposed;
 #ifdef DO_SAVE_UNDERS
@@ -1081,12 +1081,12 @@ miSetShape(pWin)
 
 _X_EXPORT void
 miChangeBorderWidth(pWin, width)
-    register WindowPtr pWin;
+    WindowPtr pWin;
     unsigned int width;
 {
     int oldwidth;
     Bool anyMarked = FALSE;
-    register ScreenPtr pScreen;
+    ScreenPtr pScreen;
     Bool WasViewable = (Bool)(pWin->viewable);
     Bool HadBorder;
 #ifdef DO_SAVE_UNDERS
diff --git a/mi/mizerarc.c b/mi/mizerarc.c
index 33e1acc..f1adc9e 100644
--- a/mi/mizerarc.c
+++ b/mi/mizerarc.c
@@ -97,8 +97,8 @@ static miZeroArcPtRec oob = {65536, 6553
 
 _X_EXPORT Bool
 miZeroArcSetup(arc, info, ok360)
-    register xArc *arc;
-    register miZeroArcRec *info;
+    xArc *arc;
+    miZeroArcRec *info;
     Bool ok360;
 {
     int l;
@@ -404,11 +404,11 @@ miZeroArcSetup(arc, info, ok360)
 DDXPointPtr
 miZeroArcPts(arc, pts)
     xArc *arc;
-    register DDXPointPtr pts;
+    DDXPointPtr pts;
 {
     miZeroArcRec info;
-    register int x, y, a, b, d, mask;
-    register int k1, k3, dx, dy;
+    int x, y, a, b, d, mask;
+    int k1, k3, dx, dy;
     Bool do360;
 
     do360 = miZeroArcSetup(arc, &info, TRUE);
@@ -509,14 +509,14 @@ miZeroArcDashPts(
     GCPtr pGC,
     xArc *arc,
     DashInfo *dinfo,
-    register DDXPointPtr points,
+    DDXPointPtr points,
     int maxPts,
-    register DDXPointPtr *evenPts, 
-    register DDXPointPtr *oddPts )
+    DDXPointPtr *evenPts, 
+    DDXPointPtr *oddPts )
 {
     miZeroArcRec info;
-    register int x, y, a, b, d, mask;
-    register int k1, k3, dx, dy;
+    int x, y, a, b, d, mask;
+    int k1, k3, dx, dy;
     int dashRemaining;
     DDXPointPtr arcPts[4];
     DDXPointPtr startPts[5], endPts[5];
@@ -715,11 +715,11 @@ miZeroPolyArc(pDraw, pGC, narcs, parcs)
     xArc	*parcs;
 {
     int maxPts = 0;
-    register int n, maxw = 0;
-    register xArc *arc;
-    register int i;
+    int n, maxw = 0;
+    xArc *arc;
+    int i;
     DDXPointPtr points, pts, oddPts;
-    register DDXPointPtr pt;
+    DDXPointPtr pt;
     int numPts;
     Bool dospans;
     int *widths = NULL;
diff-tree 63169ce52d354b4345dcfc46b89f0ea88379718f (from 40ae4f246d8818410490236ab183204a84765629)
Author: Peter Hutterer <peter at cs.unisa.edu.au>
Date:   Thu Mar 8 17:50:19 2007 +1030

    dix: remove 'register' keyword for all variables.

diff --git a/dix/atom.c b/dix/atom.c
index d9d74f1..bd3223c 100644
--- a/dix/atom.c
+++ b/dix/atom.c
@@ -77,10 +77,10 @@ void FreeAtom(NodePtr patom);
 _X_EXPORT Atom 
 MakeAtom(char *string, unsigned len, Bool makeit)
 {
-    register    NodePtr * np;
+    NodePtr * np;
     unsigned i;
-    int     comp;
-    register unsigned int   fp = 0;
+    int comp;
+    unsigned int fp = 0;
 
     np = &atomRoot;
     for (i = 0; i < (len+1)/2; i++)
@@ -107,7 +107,7 @@ MakeAtom(char *string, unsigned len, Boo
     }
     if (makeit)
     {
-	register NodePtr nd;
+	NodePtr nd;
 
 	nd = (NodePtr) xalloc(sizeof(NodeRec));
 	if (!nd)
diff --git a/dix/colormap.c b/dix/colormap.c
index a74cb39..73b6669 100644
--- a/dix/colormap.c
+++ b/dix/colormap.c
@@ -95,8 +95,8 @@ static int BlueComp(
 );
 
 static void FreePixels(
-    register ColormapPtr /*pmap*/,
-    register int /*client*/
+    ColormapPtr /*pmap*/,
+    int /*client*/
 );
 
 static void CopyFree(
@@ -259,9 +259,9 @@ CreateColormap (Colormap mid, ScreenPtr 
     int		class, size;
     unsigned long sizebytes;
     ColormapPtr	pmap;
-    register	EntryPtr	pent;
+    EntryPtr	pent;
     int		i;
-    register	Pixel	*ppix, **pptr;
+    Pixel	*ppix, **pptr;
 
     class = pVisual->class;
     if(!(class & DynamicClass) && (alloc != AllocNone) && (client != SERVER_ID))
@@ -428,8 +428,8 @@ CreateColormap (Colormap mid, ScreenPtr 
 int
 FreeColormap (pointer value, XID mid)
 {
-    int		i;
-    register EntryPtr pent;
+    int	i;
+    EntryPtr pent;
     ColormapPtr	pmap = (ColormapPtr)value;
 
     if(CLIENT_ID(mid) != SERVER_ID)
@@ -744,9 +744,9 @@ static void
 UpdateColors (ColormapPtr pmap)
 {
     xColorItem		*defs;
-    register xColorItem *pdef;
-    register EntryPtr 	pent;
-    register VisualPtr	pVisual;
+    xColorItem *pdef;
+    EntryPtr 	pent;
+    VisualPtr	pVisual;
     int			i, n, size;
 
     pVisual = pmap->pVisual;
@@ -993,14 +993,14 @@ AllocColor (ColormapPtr pmap, 
  */
 
 _X_EXPORT void
-FakeAllocColor (register ColormapPtr pmap, register xColorItem *item)
+FakeAllocColor (ColormapPtr pmap, xColorItem *item)
 {
-    Pixel	pixR, pixG, pixB;
-    Pixel	temp;
-    int		entries;
-    xrgb	rgb;
-    int		class;
-    register VisualPtr	pVisual;
+    Pixel pixR, pixG, pixB;
+    Pixel temp;
+    int	entries;
+    xrgb rgb;
+    int	class;
+    VisualPtr pVisual;
 
     pVisual = pmap->pVisual;
     rgb.red = item->red;
@@ -1059,9 +1059,9 @@ FakeAllocColor (register ColormapPtr pma
 
 /* free a pixel value obtained from FakeAllocColor */
 _X_EXPORT void
-FakeFreeColor(register ColormapPtr pmap, Pixel pixel)
+FakeFreeColor(ColormapPtr pmap, Pixel pixel)
 {
-    register VisualPtr pVisual;
+    VisualPtr pVisual;
     Pixel pixR, pixG, pixB;
 
     switch (pmap->class) {
@@ -1507,11 +1507,11 @@ QueryColors (ColormapPtr pmap, int count
 }
 
 static void
-FreePixels(register ColormapPtr pmap, register int client)
+FreePixels(ColormapPtr pmap, int client)
 {
-    register Pixel		*ppix, *ppixStart;
-    register int 		n;
-    int				class;
+    Pixel *ppix, *ppixStart;
+    int n;
+    int	class;
 
     class = pmap->class;
     ppixStart = pmap->clientPixelsRed[client];
@@ -1646,8 +1646,8 @@ AllocColorPlanes (int client, ColormapPt
 {
     int		ok;
     Pixel	mask, *ppixFirst;
-    register Pixel shift;
-    register int i;
+    Pixel shift;
+    int i;
     int		class;
     int		oldcount;
     colorResource *pcr = (colorResource *)NULL;
@@ -2409,10 +2409,10 @@ FreeCo (ColormapPtr pmap, int client, in
 _X_EXPORT int
 StoreColors (ColormapPtr pmap, int count, xColorItem *defs)
 {
-    register Pixel 	pix;
-    register xColorItem *pdef;
-    register EntryPtr 	pent, pentT, pentLast;
-    register VisualPtr	pVisual;
+    Pixel 	pix;
+    xColorItem *pdef;
+    EntryPtr 	pent, pentT, pentLast;
+    VisualPtr	pVisual;
     SHAREDCOLOR		*pred, *pgreen, *pblue;
     int			n, ChgRed, ChgGreen, ChgBlue, idef;
     int			class, errVal = Success;
diff --git a/dix/cursor.c b/dix/cursor.c
index 7071d83..5ab562e 100644
--- a/dix/cursor.c
+++ b/dix/cursor.c
@@ -86,7 +86,7 @@ FreeCursorBits(CursorBitsPtr bits)
 #endif
     if (bits->refcnt == 0)
     {
-	register GlyphSharePtr *prev, this;
+	GlyphSharePtr *prev, this;
 
 	for (prev = &sharedGlyphs;
 	     (this = *prev) && (this->bits != bits);
@@ -135,7 +135,7 @@ FreeCursor(pointer value, XID cid)
 static void
 CheckForEmptyMask(CursorBitsPtr bits)
 {
-    register unsigned char *msk = bits->mask;
+    unsigned char *msk = bits->mask;
     int n = BitmapBytePad(bits->width) * bits->height;
 
     bits->emptyMask = FALSE;
@@ -305,8 +305,8 @@ AllocGlyphCursor(Font source, unsigned s
 	}
 	if (!maskfont)
 	{
-	    register long n;
-	    register unsigned char *mskptr;
+	    long n;
+	    unsigned char *mskptr;
 
 	    n = BitmapBytePad(cm.width)*(long)cm.height;
 	    mskptr = mskbits = (unsigned char *)xalloc(n);
diff --git a/dix/devices.c b/dix/devices.c
index d5acb2d..8eb54f7 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -84,7 +84,7 @@ int CoreDevicePrivatesIndex = 0, CoreDev
 DeviceIntPtr
 AddInputDevice(DeviceProc deviceProc, Bool autoStart)
 {
-    register DeviceIntPtr dev, *prev; /* not a typo */
+    DeviceIntPtr dev, *prev; /* not a typo */
 
     if (inputInfo.numDevices >= MAX_DEVICES)
 	return (DeviceIntPtr)NULL;
@@ -140,9 +140,9 @@ AddInputDevice(DeviceProc deviceProc, Bo
 }
 
 Bool
-EnableDevice(register DeviceIntPtr dev)
+EnableDevice(DeviceIntPtr dev)
 {
-    register DeviceIntPtr *prev;
+    DeviceIntPtr *prev;
     int ret;
 
     for (prev = &inputInfo.off_devices;
@@ -166,9 +166,9 @@ EnableDevice(register DeviceIntPtr dev)
 }
 
 Bool
-DisableDevice(register DeviceIntPtr dev)
+DisableDevice(DeviceIntPtr dev)
 {
-    register DeviceIntPtr *prev;
+    DeviceIntPtr *prev;
 
     for (prev = &inputInfo.devices;
 	 *prev && (*prev != dev);
@@ -315,7 +315,7 @@ CorePointerProc(DeviceIntPtr pDev, int w
 void
 InitCoreDevices()
 {
-    register DeviceIntPtr dev;
+    DeviceIntPtr dev;
 
     if (CoreDevicePrivatesGeneration != serverGeneration) {
         CoreDevicePrivatesIndex = AllocateDevicePrivateIndex();
@@ -374,7 +374,7 @@ InitCoreDevices()
 int
 InitAndStartDevices()
 {
-    register DeviceIntPtr dev, next;
+    DeviceIntPtr dev, next;
 
     for (dev = inputInfo.off_devices; dev; dev = dev->next) {
         DebugF("(dix) initialising device %d\n", dev->id);
@@ -406,7 +406,7 @@ InitAndStartDevices()
 }
 
 static void
-CloseDevice(register DeviceIntPtr dev)
+CloseDevice(DeviceIntPtr dev)
 {
     KbdFeedbackPtr k, knext;
     PtrFeedbackPtr p, pnext;
@@ -504,7 +504,7 @@ CloseDevice(register DeviceIntPtr dev)
 void
 CloseDownDevices()
 {
-    register DeviceIntPtr dev, next;
+    DeviceIntPtr dev, next;
 
     for (dev = inputInfo.devices; dev; dev = next)
     {
@@ -634,7 +634,7 @@ QueryMinMaxKeyCodes(KeyCode *minCode, Ke
 }
 
 Bool
-SetKeySymsMap(register KeySymsPtr dst, register KeySymsPtr src)
+SetKeySymsMap(KeySymsPtr dst, KeySymsPtr src)
 {
     int i, j;
     int rowDif = src->minKeyCode - dst->minKeyCode;
@@ -683,7 +683,7 @@ SetKeySymsMap(register KeySymsPtr dst, r
 }
 
 static Bool
-InitModMap(register KeyClassPtr keyc)
+InitModMap(KeyClassPtr keyc)
 {
     int i, j;
     CARD8 keysPerModifier[8];
@@ -728,7 +728,7 @@ _X_EXPORT Bool
 InitKeyClassDeviceStruct(DeviceIntPtr dev, KeySymsPtr pKeySyms, CARD8 pModifiers[])
 {
     int i;
-    register KeyClassPtr keyc;
+    KeyClassPtr keyc;
     
     keyc = (KeyClassPtr)xalloc(sizeof(KeyClassRec));
     if (!keyc)
@@ -763,10 +763,10 @@ InitKeyClassDeviceStruct(DeviceIntPtr de
 }
 
 _X_EXPORT Bool
-InitButtonClassDeviceStruct(register DeviceIntPtr dev, int numButtons, 
+InitButtonClassDeviceStruct(DeviceIntPtr dev, int numButtons, 
                             CARD8 *map)
 {
-    register ButtonClassPtr butc;
+    ButtonClassPtr butc;
     int i;
 
     butc = (ButtonClassPtr)xalloc(sizeof(ButtonClassRec));
@@ -792,7 +792,7 @@ InitValuatorClassDeviceStruct(DeviceIntP
                               int numMotionEvents, int mode)
 {
     int i;
-    register ValuatorClassPtr valc;
+    ValuatorClassPtr valc;
 
     if (!dev)
         return FALSE;
@@ -834,7 +834,7 @@ InitValuatorClassDeviceStruct(DeviceIntP
 _X_EXPORT Bool
 InitAbsoluteClassDeviceStruct(DeviceIntPtr dev)
 {
-    register AbsoluteClassPtr abs;
+    AbsoluteClassPtr abs;
 
     abs = (AbsoluteClassPtr)xalloc(sizeof(AbsoluteClassRec));
     if (!abs)
@@ -864,7 +864,7 @@ InitAbsoluteClassDeviceStruct(DeviceIntP
 _X_EXPORT Bool
 InitFocusClassDeviceStruct(DeviceIntPtr dev)
 {
-    register FocusClassPtr focc;
+    FocusClassPtr focc;
 
     focc = (FocusClassPtr)xalloc(sizeof(FocusClassRec));
     if (!focc)
@@ -883,7 +883,7 @@ _X_EXPORT Bool
 InitKbdFeedbackClassDeviceStruct(DeviceIntPtr dev, BellProcPtr bellProc, 
                                  KbdCtrlProcPtr controlProc)
 {
-    register KbdFeedbackPtr feedc;
+    KbdFeedbackPtr feedc;
 
     feedc = (KbdFeedbackPtr)xalloc(sizeof(KbdFeedbackClassRec));
     if (!feedc)
@@ -910,7 +910,7 @@ InitKbdFeedbackClassDeviceStruct(DeviceI
 _X_EXPORT Bool
 InitPtrFeedbackClassDeviceStruct(DeviceIntPtr dev, PtrCtrlProcPtr controlProc)
 {
-    register PtrFeedbackPtr feedc;
+    PtrFeedbackPtr feedc;
 
     feedc = (PtrFeedbackPtr)xalloc(sizeof(PtrFeedbackClassRec));
     if (!feedc)
@@ -948,7 +948,7 @@ InitStringFeedbackClassDeviceStruct (
       int max_symbols, int num_symbols_supported, KeySym *symbols)
 {
     int i;
-    register StringFeedbackPtr feedc;
+    StringFeedbackPtr feedc;
 
     feedc = (StringFeedbackPtr)xalloc(sizeof(StringFeedbackClassRec));
     if (!feedc)
@@ -986,7 +986,7 @@ _X_EXPORT Bool
 InitBellFeedbackClassDeviceStruct (DeviceIntPtr dev, BellProcPtr bellProc, 
                                    BellCtrlProcPtr controlProc)
 {
-    register BellFeedbackPtr feedc;
+    BellFeedbackPtr feedc;
 
     feedc = (BellFeedbackPtr)xalloc(sizeof(BellFeedbackClassRec));
     if (!feedc)
@@ -1005,7 +1005,7 @@ InitBellFeedbackClassDeviceStruct (Devic
 _X_EXPORT Bool
 InitLedFeedbackClassDeviceStruct (DeviceIntPtr dev, LedCtrlProcPtr controlProc)
 {
-    register LedFeedbackPtr feedc;
+    LedFeedbackPtr feedc;
 
     feedc = (LedFeedbackPtr)xalloc(sizeof(LedFeedbackClassRec));
     if (!feedc)
@@ -1026,7 +1026,7 @@ InitLedFeedbackClassDeviceStruct (Device
 _X_EXPORT Bool
 InitIntegerFeedbackClassDeviceStruct (DeviceIntPtr dev, IntegerCtrlProcPtr controlProc)
 {
-    register IntegerFeedbackPtr feedc;
+    IntegerFeedbackPtr feedc;
 
     feedc = (IntegerFeedbackPtr)xalloc(sizeof(IntegerFeedbackClassRec));
     if (!feedc)
@@ -1112,9 +1112,9 @@ SendMappingNotify(unsigned request, unsi
  * sort it to do the checking. How often is it called? Just being lazy?
  */
 Bool
-BadDeviceMap(register BYTE *buff, int length, unsigned low, unsigned high, XID *errval)
+BadDeviceMap(BYTE *buff, int length, unsigned low, unsigned high, XID *errval)
 {
-    register int     i, j;
+    int i, j;
 
     for (i = 0; i < length; i++)
 	if (buff[i])		       /* only check non-zero elements */
@@ -1136,12 +1136,12 @@ BadDeviceMap(register BYTE *buff, int le
 
 Bool
 AllModifierKeysAreUp(dev, map1, per1, map2, per2)
-    register DeviceIntPtr dev;
-    register CARD8 *map1, *map2;
+    DeviceIntPtr dev;
+    CARD8 *map1, *map2;
     int per1, per2;
 {
-    register int i, j, k;
-    register CARD8 *down = dev->key->down;
+    int i, j, k;
+    CARD8 *down = dev->key->down;
 
     for (i = 8; --i >= 0; map2 += per2)
     {
@@ -1258,7 +1258,7 @@ int
 ProcGetModifierMapping(ClientPtr client)
 {
     xGetModifierMappingReply rep;
-    register KeyClassPtr keyc = inputInfo.keyboard->key;
+    KeyClassPtr keyc = inputInfo.keyboard->key;
 
     REQUEST_SIZE_MATCH(xReq);
     rep.type = X_Reply;
@@ -1459,7 +1459,7 @@ NoteLedState(DeviceIntPtr keybd, int led
 _X_EXPORT int
 Ones(unsigned long mask)             /* HACKMEM 169 */
 {
-    register unsigned long y;
+    unsigned long y;
 
     y = (mask >> 1) &033333333333;
     y = mask - y - ((y >>1) & 033333333333);
@@ -1676,7 +1676,7 @@ int
 ProcGetKeyboardControl (ClientPtr client)
 {
     int i;
-    register KeybdCtrl *ctrl = &inputInfo.keyboard->kbdfeed->ctrl;
+    KeybdCtrl *ctrl = &inputInfo.keyboard->kbdfeed->ctrl;
     xGetKeyboardControlReply rep;
 
     REQUEST_SIZE_MATCH(xReq);
@@ -1698,7 +1698,7 @@ ProcGetKeyboardControl (ClientPtr client
 int
 ProcBell(ClientPtr client)
 {
-    register DeviceIntPtr keybd = inputInfo.keyboard;
+    DeviceIntPtr keybd = inputInfo.keyboard;
     int base = keybd->kbdfeed->ctrl.bell;
     int newpercent;
     REQUEST(xBellReq);
@@ -1807,7 +1807,7 @@ ProcChangePointerControl(ClientPtr clien
 int
 ProcGetPointerControl(ClientPtr client)
 {
-    register PtrCtrl *ctrl = &inputInfo.pointer->ptrfeed->ctrl;
+    PtrCtrl *ctrl = &inputInfo.pointer->ptrfeed->ctrl;
     xGetPointerControlReply rep;
 
     REQUEST_SIZE_MATCH(xReq);
@@ -1822,7 +1822,7 @@ ProcGetPointerControl(ClientPtr client)
 }
 
 void
-MaybeStopHint(register DeviceIntPtr dev, ClientPtr client)
+MaybeStopHint(DeviceIntPtr dev, ClientPtr client)
 {
     GrabPtr grab = dev->grab;
 
diff --git a/dix/dispatch.c b/dix/dispatch.c
index d44687e..b258aa6 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -262,7 +262,7 @@ void 
 FlushClientCaches(XID id)
 {
     int i;
-    register ClientPtr client;
+    ClientPtr client;
 
     client = clients[CLIENT_ID(id)];
     if (client == NullClient)
@@ -394,11 +394,11 @@ SmartScheduleClient (int *clientReady, i
 void
 Dispatch(void)
 {
-    register int        *clientReady;     /* array of request ready clients */
-    register int	result;
-    register ClientPtr	client;
-    register int	nready;
-    register HWEventQueuePtr* icheck = checkForInput;
+    int        *clientReady;     /* array of request ready clients */
+    int	result;
+    ClientPtr	client;
+    int	nready;
+    HWEventQueuePtr* icheck = checkForInput;
 #ifdef SMART_SCHEDULE
     long			start_tick;
 #endif
@@ -594,11 +594,11 @@ ProcCreateWindow(ClientPtr client)
 }
 
 int
-ProcChangeWindowAttributes(register ClientPtr client)
+ProcChangeWindowAttributes(ClientPtr client)
 {
     WindowPtr pWin;
     REQUEST(xChangeWindowAttributesReq);
-    register int result;
+    int result;
     int len, rc;
 
     REQUEST_AT_LEAST_SIZE(xChangeWindowAttributesReq);
@@ -619,7 +619,7 @@ ProcChangeWindowAttributes(register Clie
 }
 
 int
-ProcGetWindowAttributes(register ClientPtr client)
+ProcGetWindowAttributes(ClientPtr client)
 {
     WindowPtr pWin;
     REQUEST(xResourceReq);
@@ -636,7 +636,7 @@ ProcGetWindowAttributes(register ClientP
 }
 
 int
-ProcDestroyWindow(register ClientPtr client)
+ProcDestroyWindow(ClientPtr client)
 {
     WindowPtr pWin;
     REQUEST(xResourceReq);
@@ -652,7 +652,7 @@ ProcDestroyWindow(register ClientPtr cli
 }
 
 int
-ProcDestroySubwindows(register ClientPtr client)
+ProcDestroySubwindows(ClientPtr client)
 {
     WindowPtr pWin;
     REQUEST(xResourceReq);
@@ -667,11 +667,11 @@ ProcDestroySubwindows(register ClientPtr
 }
 
 int
-ProcChangeSaveSet(register ClientPtr client)
+ProcChangeSaveSet(ClientPtr client)
 {
     WindowPtr pWin;
     REQUEST(xChangeSaveSetReq);
-    register int result, rc;
+    int result, rc;
 		  
     REQUEST_SIZE_MATCH(xChangeSaveSetReq);
     rc = dixLookupWindow(&pWin, stuff->window, client, DixReadAccess);
@@ -695,11 +695,11 @@ ProcChangeSaveSet(register ClientPtr cli
 }
 
 int
-ProcReparentWindow(register ClientPtr client)
+ProcReparentWindow(ClientPtr client)
 {
     WindowPtr pWin, pParent;
     REQUEST(xReparentWindowReq);
-    register int result, rc;
+    int result, rc;
 
     REQUEST_SIZE_MATCH(xReparentWindowReq);
     rc = dixLookupWindow(&pWin, stuff->window, client, DixWriteAccess);
@@ -728,7 +728,7 @@ ProcReparentWindow(register ClientPtr cl
 }
 
 int
-ProcMapWindow(register ClientPtr client)
+ProcMapWindow(ClientPtr client)
 {
     WindowPtr pWin;
     REQUEST(xResourceReq);
@@ -744,7 +744,7 @@ ProcMapWindow(register ClientPtr client)
 }
 
 int
-ProcMapSubwindows(register ClientPtr client)
+ProcMapSubwindows(ClientPtr client)
 {
     WindowPtr pWin;
     REQUEST(xResourceReq);
@@ -760,7 +760,7 @@ ProcMapSubwindows(register ClientPtr cli
 }
 
 int
-ProcUnmapWindow(register ClientPtr client)
+ProcUnmapWindow(ClientPtr client)
 {
     WindowPtr pWin;
     REQUEST(xResourceReq);
@@ -776,7 +776,7 @@ ProcUnmapWindow(register ClientPtr clien
 }
 
 int
-ProcUnmapSubwindows(register ClientPtr client)
+ProcUnmapSubwindows(ClientPtr client)
 {
     WindowPtr pWin;
     REQUEST(xResourceReq);
@@ -791,11 +791,11 @@ ProcUnmapSubwindows(register ClientPtr c
 }
 
 int
-ProcConfigureWindow(register ClientPtr client)
+ProcConfigureWindow(ClientPtr client)
 {
     WindowPtr pWin;
     REQUEST(xConfigureWindowReq);
-    register int result;
+    int result;
     int len, rc;
 
     REQUEST_AT_LEAST_SIZE(xConfigureWindowReq);
@@ -814,7 +814,7 @@ ProcConfigureWindow(register ClientPtr c
 }
 
 int
-ProcCirculateWindow(register ClientPtr client)
+ProcCirculateWindow(ClientPtr client)
 {
     WindowPtr pWin;
     REQUEST(xCirculateWindowReq);
@@ -835,7 +835,7 @@ ProcCirculateWindow(register ClientPtr c
 }
 
 int
-GetGeometry(register ClientPtr client, xGetGeometryReply *rep)
+GetGeometry(ClientPtr client, xGetGeometryReply *rep)
 {
     DrawablePtr pDraw;
     int rc;
@@ -865,7 +865,7 @@ GetGeometry(register ClientPtr client, x
     if ((pDraw->type == UNDRAWABLE_WINDOW) ||
         ((pDraw->type == DRAWABLE_WINDOW) && (stuff->id == pDraw->id)))
     {
-        register WindowPtr pWin = (WindowPtr)pDraw;
+        WindowPtr pWin = (WindowPtr)pDraw;
 	rep->x = pWin->origin.x - wBorderWidth (pWin);
 	rep->y = pWin->origin.y - wBorderWidth (pWin);
 	rep->borderWidth = pWin->borderWidth;
@@ -880,7 +880,7 @@ GetGeometry(register ClientPtr client, x
 
 
 int
-ProcGetGeometry(register ClientPtr client)
+ProcGetGeometry(ClientPtr client)
 {
     xGetGeometryReply rep;
     int status;
@@ -894,7 +894,7 @@ ProcGetGeometry(register ClientPtr clien
 
 
 int
-ProcQueryTree(register ClientPtr client)
+ProcQueryTree(ClientPtr client)
 {
     xQueryTreeReply reply;
     int rc, numChildren = 0;
@@ -942,7 +942,7 @@ ProcQueryTree(register ClientPtr client)
 }
 
 int
-ProcInternAtom(register ClientPtr client)
+ProcInternAtom(ClientPtr client)
 {
     Atom atom;
     char *tchar;
@@ -971,7 +971,7 @@ ProcInternAtom(register ClientPtr client
 }
 
 int
-ProcGetAtomName(register ClientPtr client)
+ProcGetAtomName(ClientPtr client)
 {
     char *str;
     xGetAtomNameReply reply;
@@ -1002,7 +1002,7 @@ extern int k5_bad();
 #endif
 
 int
-ProcSetSelectionOwner(register ClientPtr client)
+ProcSetSelectionOwner(ClientPtr client)
 {
     WindowPtr pWin;
     TimeStamp time;
@@ -1097,7 +1097,7 @@ ProcSetSelectionOwner(register ClientPtr
 }
 
 int
-ProcGetSelectionOwner(register ClientPtr client)
+ProcGetSelectionOwner(ClientPtr client)
 {
     REQUEST(xResourceReq);
 
@@ -1128,7 +1128,7 @@ ProcGetSelectionOwner(register ClientPtr
 }
 
 int
-ProcConvertSelection(register ClientPtr client)
+ProcConvertSelection(ClientPtr client)
 {
     Bool paramsOkay;
     xEvent event;
@@ -1188,7 +1188,7 @@ ProcConvertSelection(register ClientPtr 
 }
 
 int
-ProcGrabServer(register ClientPtr client)
+ProcGrabServer(ClientPtr client)
 {
     REQUEST_SIZE_MATCH(xReq);
     if (grabState != GrabNone && client != grabClient)
@@ -1242,7 +1242,7 @@ UngrabServer(ClientPtr client)
 }
 
 int
-ProcUngrabServer(register ClientPtr client)
+ProcUngrabServer(ClientPtr client)
 {
     REQUEST_SIZE_MATCH(xReq);
     UngrabServer(client);
@@ -1250,7 +1250,7 @@ ProcUngrabServer(register ClientPtr clie
 }
 
 int
-ProcTranslateCoords(register ClientPtr client)
+ProcTranslateCoords(ClientPtr client)
 {
     REQUEST(xTranslateCoordsReq);
 
@@ -1327,7 +1327,7 @@ ProcTranslateCoords(register ClientPtr c
 }
 
 int
-ProcOpenFont(register ClientPtr client)
+ProcOpenFont(ClientPtr client)
 {
     int	err;
     REQUEST(xOpenFontReq);
@@ -1346,7 +1346,7 @@ ProcOpenFont(register ClientPtr client)
 }
 
 int
-ProcCloseFont(register ClientPtr client)
+ProcCloseFont(ClientPtr client)
 {
     FontPtr pFont;
     REQUEST(xResourceReq);
@@ -1367,11 +1367,11 @@ ProcCloseFont(register ClientPtr client)
 }
 
 int
-ProcQueryFont(register ClientPtr client)
+ProcQueryFont(ClientPtr client)
 {
     xQueryFontReply	*reply;
     FontPtr pFont;
-    register GC *pGC;
+    GC *pGC;
     REQUEST(xResourceReq);
 
     REQUEST_SIZE_MATCH(xResourceReq);
@@ -1425,7 +1425,7 @@ ProcQueryFont(register ClientPtr client)
 }
 
 int
-ProcQueryTextExtents(register ClientPtr client)
+ProcQueryTextExtents(ClientPtr client)
 {
     REQUEST(xQueryTextExtentsReq);
     xQueryTextExtentsReply reply;
@@ -1475,7 +1475,7 @@ ProcQueryTextExtents(register ClientPtr 
 }
 
 int
-ProcListFonts(register ClientPtr client)
+ProcListFonts(ClientPtr client)
 {
     REQUEST(xListFontsReq);
 
@@ -1486,7 +1486,7 @@ ProcListFonts(register ClientPtr client)
 }
 
 int
-ProcListFontsWithInfo(register ClientPtr client)
+ProcListFontsWithInfo(ClientPtr client)
 {
     REQUEST(xListFontsWithInfoReq);
 
@@ -1508,13 +1508,13 @@ dixDestroyPixmap(pointer value, XID pid)
 }
 
 int
-ProcCreatePixmap(register ClientPtr client)
+ProcCreatePixmap(ClientPtr client)
 {
     PixmapPtr pMap;
     DrawablePtr pDraw;
     REQUEST(xCreatePixmapReq);
     DepthPtr pDepth;
-    register int i, rc;
+    int i, rc;
 
     REQUEST_SIZE_MATCH(xCreatePixmapReq);
     client->errorValue = stuff->pid;
@@ -1571,7 +1571,7 @@ CreatePmap:
 }
 
 int
-ProcFreePixmap(register ClientPtr client)
+ProcFreePixmap(ClientPtr client)
 {
     PixmapPtr pMap;
 
@@ -1593,7 +1593,7 @@ ProcFreePixmap(register ClientPtr client
 }
 
 int
-ProcCreateGC(register ClientPtr client)
+ProcCreateGC(ClientPtr client)
 {
     int error, rc;
     GC *pGC;
@@ -1621,7 +1621,7 @@ ProcCreateGC(register ClientPtr client)
 }
 
 int
-ProcChangeGC(register ClientPtr client)
+ProcChangeGC(ClientPtr client)
 {
     GC *pGC;
     int result;
@@ -1648,7 +1648,7 @@ ProcChangeGC(register ClientPtr client)
 }
 
 int
-ProcCopyGC(register ClientPtr client)
+ProcCopyGC(ClientPtr client)
 {
     GC *dstGC;
     GC *pGC;
@@ -1675,7 +1675,7 @@ ProcCopyGC(register ClientPtr client)
 }
 
 int
-ProcSetDashes(register ClientPtr client)
+ProcSetDashes(ClientPtr client)
 {
     GC *pGC;
     int result;
@@ -1704,7 +1704,7 @@ ProcSetDashes(register ClientPtr client)
 }
 
 int
-ProcSetClipRectangles(register ClientPtr client)
+ProcSetClipRectangles(ClientPtr client)
 {
     int	nr, result;
     GC *pGC;
@@ -1734,7 +1734,7 @@ ProcSetClipRectangles(register ClientPtr
 }
 
 int
-ProcFreeGC(register ClientPtr client)
+ProcFreeGC(ClientPtr client)
 {
     GC *pGC;
     int rc;
@@ -1750,7 +1750,7 @@ ProcFreeGC(register ClientPtr client)
 }
 
 int
-ProcClearToBackground(register ClientPtr client)
+ProcClearToBackground(ClientPtr client)
 {
     REQUEST(xClearAreaReq);
     WindowPtr pWin;
@@ -1777,7 +1777,7 @@ ProcClearToBackground(register ClientPtr
 }
 
 int
-ProcCopyArea(register ClientPtr client)
+ProcCopyArea(ClientPtr client)
 {
     DrawablePtr pDst;
     DrawablePtr pSrc;
@@ -1821,7 +1821,7 @@ ProcCopyArea(register ClientPtr client)
 }
 
 int
-ProcCopyPlane(register ClientPtr client)
+ProcCopyPlane(ClientPtr client)
 {
     DrawablePtr psrcDraw, pdstDraw;
     GC *pGC;
@@ -1872,7 +1872,7 @@ ProcCopyPlane(register ClientPtr client)
 }
 
 int
-ProcPolyPoint(register ClientPtr client)
+ProcPolyPoint(ClientPtr client)
 {
     int npoint;
     GC *pGC;
@@ -1895,7 +1895,7 @@ ProcPolyPoint(register ClientPtr client)
 }
 
 int
-ProcPolyLine(register ClientPtr client)
+ProcPolyLine(ClientPtr client)
 {
     int npoint;
     GC *pGC;
@@ -1918,7 +1918,7 @@ ProcPolyLine(register ClientPtr client)
 }
 
 int
-ProcPolySegment(register ClientPtr client)
+ProcPolySegment(ClientPtr client)
 {
     int nsegs;
     GC *pGC;
@@ -1937,7 +1937,7 @@ ProcPolySegment(register ClientPtr clien
 }
 
 int
-ProcPolyRectangle (register ClientPtr client)
+ProcPolyRectangle (ClientPtr client)
 {
     int nrects;
     GC *pGC;
@@ -1957,7 +1957,7 @@ ProcPolyRectangle (register ClientPtr cl
 }
 
 int
-ProcPolyArc(register ClientPtr client)
+ProcPolyArc(ClientPtr client)
 {
     int		narcs;
     GC *pGC;
@@ -1976,7 +1976,7 @@ ProcPolyArc(register ClientPtr client)
 }
 
 int
-ProcFillPoly(register ClientPtr client)
+ProcFillPoly(ClientPtr client)
 {
     int          things;
     GC *pGC;
@@ -2007,7 +2007,7 @@ ProcFillPoly(register ClientPtr client)
 }
 
 int
-ProcPolyFillRectangle(register ClientPtr client)
+ProcPolyFillRectangle(ClientPtr client)
 {
     int             things;
     GC *pGC;
@@ -2028,7 +2028,7 @@ ProcPolyFillRectangle(register ClientPtr
 }
 
 int
-ProcPolyFillArc(register ClientPtr client)
+ProcPolyFillArc(ClientPtr client)
 {
     int		narcs;
     GC *pGC;
@@ -2101,7 +2101,7 @@ ReformatImage (char *base, int nbytes, i
  * boundary, even if the scanlines are padded to our satisfaction.
  */
 int
-ProcPutImage(register ClientPtr client)
+ProcPutImage(ClientPtr client)
 {
     GC *pGC;
     DrawablePtr pDraw;
@@ -2159,13 +2159,13 @@ ProcPutImage(register ClientPtr client)
 
 
 int
-DoGetImage(register ClientPtr client, int format, Drawable drawable, 
+DoGetImage(ClientPtr client, int format, Drawable drawable, 
            int x, int y, int width, int height, 
            Mask planemask, xGetImageReply **im_return)
 {
     DrawablePtr		pDraw;
     int			nlines, linesPerBuf, rc;
-    register int	linesDone;
+    int	linesDone;
     long		widthBytesLine, length;
     Mask		plane = 0;
     char		*pBuf;
@@ -2379,7 +2379,7 @@ DoGetImage(register ClientPtr client, in
 }
 
 int
-ProcGetImage(register ClientPtr client)
+ProcGetImage(ClientPtr client)
 {
     REQUEST(xGetImageReq);
 
@@ -2392,7 +2392,7 @@ ProcGetImage(register ClientPtr client)
 }
 
 int
-ProcPolyText(register ClientPtr client)
+ProcPolyText(ClientPtr client)
 {
     int	err;
     REQUEST(xPolyTextReq);
@@ -2421,7 +2421,7 @@ ProcPolyText(register ClientPtr client)
 }
 
 int
-ProcImageText8(register ClientPtr client)
+ProcImageText8(ClientPtr client)
 {
     int	err;
     DrawablePtr pDraw;
@@ -2451,7 +2451,7 @@ ProcImageText8(register ClientPtr client
 }
 
 int
-ProcImageText16(register ClientPtr client)
+ProcImageText16(ClientPtr client)
 {
     int	err;
     DrawablePtr pDraw;
@@ -2482,7 +2482,7 @@ ProcImageText16(register ClientPtr clien
 
 
 int
-ProcCreateColormap(register ClientPtr client)
+ProcCreateColormap(ClientPtr client)
 {
     VisualPtr	pVisual;
     ColormapPtr	pmap;
@@ -2524,7 +2524,7 @@ ProcCreateColormap(register ClientPtr cl
 }
 
 int
-ProcFreeColormap(register ClientPtr client)
+ProcFreeColormap(ClientPtr client)
 {
     ColormapPtr pmap;
     REQUEST(xResourceReq);
@@ -2548,7 +2548,7 @@ ProcFreeColormap(register ClientPtr clie
 
 
 int
-ProcCopyColormapAndFree(register ClientPtr client)
+ProcCopyColormapAndFree(ClientPtr client)
 {
     Colormap	mid;
     ColormapPtr	pSrcMap;
@@ -2575,7 +2575,7 @@ ProcCopyColormapAndFree(register ClientP
 }
 
 int
-ProcInstallColormap(register ClientPtr client)
+ProcInstallColormap(ClientPtr client)
 {
     ColormapPtr pcmp;
     REQUEST(xResourceReq);
@@ -2596,7 +2596,7 @@ ProcInstallColormap(register ClientPtr c
 }
 
 int
-ProcUninstallColormap(register ClientPtr client)
+ProcUninstallColormap(ClientPtr client)
 {
     ColormapPtr pcmp;
     REQUEST(xResourceReq);
@@ -2618,7 +2618,7 @@ ProcUninstallColormap(register ClientPtr
 }
 
 int
-ProcListInstalledColormaps(register ClientPtr client)
+ProcListInstalledColormaps(ClientPtr client)
 {
     xListInstalledColormapsReply *preply; 
     int nummaps, rc;
@@ -2651,7 +2651,7 @@ ProcListInstalledColormaps(register Clie
 }
 
 int
-ProcAllocColor (register ClientPtr client)
+ProcAllocColor (ClientPtr client)
 {
     ColormapPtr pmap;
     int	retval;
@@ -2693,7 +2693,7 @@ ProcAllocColor (register ClientPtr clien
 }
 
 int
-ProcAllocNamedColor (register ClientPtr client)
+ProcAllocNamedColor (ClientPtr client)
 {
     ColormapPtr pcmp;
     REQUEST(xAllocNamedColorReq);
@@ -2745,7 +2745,7 @@ ProcAllocNamedColor (register ClientPtr 
 }
 
 int
-ProcAllocColorCells (register ClientPtr client)
+ProcAllocColorCells (ClientPtr client)
 {
     ColormapPtr pcmp;
     REQUEST(xAllocColorCellsReq);
@@ -2811,7 +2811,7 @@ ProcAllocColorCells (register ClientPtr 
 }
 
 int
-ProcAllocColorPlanes(register ClientPtr client)
+ProcAllocColorPlanes(ClientPtr client)
 {
     ColormapPtr pcmp;
     REQUEST(xAllocColorPlanesReq);
@@ -2875,7 +2875,7 @@ ProcAllocColorPlanes(register ClientPtr 
 }
 
 int
-ProcFreeColors(register ClientPtr client)
+ProcFreeColors(ClientPtr client)
 {
     ColormapPtr pcmp;
     REQUEST(xFreeColorsReq);
@@ -2944,7 +2944,7 @@ ProcStoreColors (ClientPtr client)
 }
 
 int
-ProcStoreNamedColor (register ClientPtr client)
+ProcStoreNamedColor (ClientPtr client)
 {
     ColormapPtr pcmp;
     REQUEST(xStoreNamedColorReq);
@@ -2978,7 +2978,7 @@ ProcStoreNamedColor (register ClientPtr 
 }
 
 int
-ProcQueryColors(register ClientPtr client)
+ProcQueryColors(ClientPtr client)
 {
     ColormapPtr pcmp;
     REQUEST(xQueryColorsReq);
@@ -3029,7 +3029,7 @@ ProcQueryColors(register ClientPtr clien
 } 
 
 int
-ProcLookupColor(register ClientPtr client)
+ProcLookupColor(ClientPtr client)
 {
     ColormapPtr pcmp;
     REQUEST(xLookupColorReq);
@@ -3067,17 +3067,16 @@ ProcLookupColor(register ClientPtr clien
 }
 
 int
-ProcCreateCursor (register ClientPtr client)
+ProcCreateCursor (ClientPtr client)
 {
-    CursorPtr	pCursor;
-
-    register PixmapPtr 	src;
-    register PixmapPtr 	msk;
+    CursorPtr		pCursor;
+    PixmapPtr 		src;
+    PixmapPtr 		msk;
     unsigned char *	srcbits;
     unsigned char *	mskbits;
     unsigned short	width, height;
     long		n;
-    CursorMetricRec cm;
+    CursorMetricRec 	cm;
 
 
     REQUEST(xCreateCursorReq);
@@ -3132,7 +3131,7 @@ ProcCreateCursor (register ClientPtr cli
 					 XYPixmap, 1, (pointer)srcbits);
     if ( msk == (PixmapPtr)NULL)
     {
-	register unsigned char *bits = mskbits;
+	unsigned char *bits = mskbits;
 	while (--n >= 0)
 	    *bits++ = ~0;
     }
@@ -3157,7 +3156,7 @@ ProcCreateCursor (register ClientPtr cli
 }
 
 int
-ProcCreateGlyphCursor (register ClientPtr client)
+ProcCreateGlyphCursor (ClientPtr client)
 {
     CursorPtr pCursor;
     int res;
@@ -3181,7 +3180,7 @@ ProcCreateGlyphCursor (register ClientPt
 
 
 int
-ProcFreeCursor (register ClientPtr client)
+ProcFreeCursor (ClientPtr client)
 {
     CursorPtr pCursor;
     REQUEST(xResourceReq);
@@ -3202,7 +3201,7 @@ ProcFreeCursor (register ClientPtr clien
 }
 
 int
-ProcQueryBestSize (register ClientPtr client)
+ProcQueryBestSize (ClientPtr client)
 {
     xQueryBestSizeReply	reply;
     DrawablePtr pDraw;
@@ -3239,7 +3238,7 @@ ProcQueryBestSize (register ClientPtr cl
 
 
 int
-ProcSetScreenSaver (register ClientPtr client)
+ProcSetScreenSaver (ClientPtr client)
 {
     int blankingOption, exposureOption;
     REQUEST(xSetScreenSaverReq);
@@ -3295,7 +3294,7 @@ ProcSetScreenSaver (register ClientPtr c
 }
 
 int
-ProcGetScreenSaver(register ClientPtr client)
+ProcGetScreenSaver(ClientPtr client)
 {
     xGetScreenSaverReply rep;
 
@@ -3312,7 +3311,7 @@ ProcGetScreenSaver(register ClientPtr cl
 }
 
 int
-ProcChangeHosts(register ClientPtr client)
+ProcChangeHosts(ClientPtr client)
 {
     REQUEST(xChangeHostsReq);
     int result;
@@ -3336,7 +3335,7 @@ ProcChangeHosts(register ClientPtr clien
 }
 
 int
-ProcListHosts(register ClientPtr client)
+ProcListHosts(ClientPtr client)
 {
     xListHostsReply reply;
     int	len, nHosts, result;
@@ -3367,7 +3366,7 @@ ProcListHosts(register ClientPtr client)
 }
 
 int
-ProcChangeAccessControl(register ClientPtr client)
+ProcChangeAccessControl(ClientPtr client)
 {
     int result;
     REQUEST(xSetAccessControlReq);
@@ -3385,7 +3384,7 @@ ProcChangeAccessControl(register ClientP
 }
 
 int
-ProcKillClient(register ClientPtr client)
+ProcKillClient(ClientPtr client)
 {
     REQUEST(xResourceReq);
     ClientPtr killclient;
@@ -3417,7 +3416,7 @@ ProcKillClient(register ClientPtr client
 }
 
 int
-ProcSetFontPath(register ClientPtr client)
+ProcSetFontPath(ClientPtr client)
 {
     unsigned char *ptr;
     unsigned long nbytes, total;
@@ -3452,7 +3451,7 @@ ProcSetFontPath(register ClientPtr clien
 }
 
 int
-ProcGetFontPath(register ClientPtr client)
+ProcGetFontPath(ClientPtr client)
 {
     xGetFontPathReply reply;
     int stringLens, numpaths;
@@ -3474,7 +3473,7 @@ ProcGetFontPath(register ClientPtr clien
 }
 
 int
-ProcChangeCloseDownMode(register ClientPtr client)
+ProcChangeCloseDownMode(ClientPtr client)
 {
     REQUEST(xSetCloseDownModeReq);
 
@@ -3493,7 +3492,7 @@ ProcChangeCloseDownMode(register ClientP
     }
 }
 
-int ProcForceScreenSaver(register ClientPtr client)
+int ProcForceScreenSaver(ClientPtr client)
 {    
     REQUEST(xForceScreenSaverReq);
 
@@ -3509,7 +3508,7 @@ int ProcForceScreenSaver(register Client
     return client->noClientException;
 }
 
-int ProcNoOperation(register ClientPtr client)
+int ProcNoOperation(ClientPtr client)
 {
     REQUEST_AT_LEAST_SIZE(xReq);
     
@@ -3552,7 +3551,7 @@ InitProcVectors(void)
 char dispatchExceptionAtReset = DE_RESET;
 
 void
-CloseDownClient(register ClientPtr client)
+CloseDownClient(ClientPtr client)
 {
     Bool really_close_down = client->clientGone ||
 			     client->closeDownMode == DestroyAll;
@@ -3662,8 +3661,8 @@ KillAllClients()
 void
 CloseDownRetainedResources()
 {
-    register int i;
-    register ClientPtr client;
+    int i;
+    ClientPtr client;
 
     for (i=1; i<currentMaxClients; i++)
     {
@@ -3733,11 +3732,11 @@ void InitClient(ClientPtr client, int i,
 int
 InitClientPrivates(ClientPtr client)
 {
-    register char *ptr;
+    char *ptr;
     DevUnion *ppriv;
-    register unsigned *sizes;
-    register unsigned size;
-    register int i;
+    unsigned *sizes;
+    unsigned size;
+    int i;
 
     if (totalClientSize == sizeof(ClientRec))
 	ppriv = (DevUnion *)NULL;
@@ -3787,8 +3786,8 @@ InitClientPrivates(ClientPtr client)
 
 ClientPtr NextAvailableClient(pointer ospriv)
 {
-    register int i;
-    register ClientPtr client;
+    int i;
+    ClientPtr client;
     xReq data;
 
     i = nextFreeClientID;
@@ -3829,10 +3828,10 @@ ClientPtr NextAvailableClient(pointer os
 }
 
 int
-ProcInitialConnection(register ClientPtr client)
+ProcInitialConnection(ClientPtr client)
 {
     REQUEST(xReq);
-    register xConnClientPrefix *prefix;
+    xConnClientPrefix *prefix;
     int whichbyte = 1;
 
     prefix = (xConnClientPrefix *)((char *)stuff + sz_xReq);
@@ -3856,10 +3855,10 @@ ProcInitialConnection(register ClientPtr
 }
 
 int
-SendConnSetup(register ClientPtr client, char *reason)
+SendConnSetup(ClientPtr client, char *reason)
 {
-    register xWindowRoot *root;
-    register int i;
+    xWindowRoot *root;
+    int i;
     int numScreens;
     char* lConnectionInfo;
     xConnSetupPrefix* lconnSetupPrefix;
@@ -3914,8 +3913,8 @@ SendConnSetup(register ClientPtr client,
 
     for (i=0; i<numScreens; i++) 
     {
-	register unsigned int j;
-	register xDepth *pDepth;
+	unsigned int j;
+	xDepth *pDepth;
 
         root->currentInputMask = WindowTable[i]->eventMask |
 			         wOtherEventMasks (WindowTable[i]);
@@ -3956,10 +3955,10 @@ SendConnSetup(register ClientPtr client,
 }
 
 int
-ProcEstablishConnection(register ClientPtr client)
+ProcEstablishConnection(ClientPtr client)
 {
     char *reason, *auth_proto, *auth_string;
-    register xConnClientPrefix *prefix;
+    xConnClientPrefix *prefix;
     REQUEST(xReq);
 
     prefix = (xConnClientPrefix *)((char *)stuff + sz_xReq);
@@ -4008,7 +4007,7 @@ SendErrorToClient(ClientPtr client, unsi
 void
 DeleteWindowFromAnySelections(WindowPtr pWin)
 {
-    register int i;
+    int i;
 
     for (i = 0; i< NumCurrentSelections; i++)
         if (CurrentSelections[i].pWin == pWin)
@@ -4030,7 +4029,7 @@ DeleteWindowFromAnySelections(WindowPtr 
 static void
 DeleteClientFromAnySelections(ClientPtr client)
 {
-    register int i;
+    int i;
 
     for (i = 0; i< NumCurrentSelections; i++)
         if (CurrentSelections[i].client == client)
diff --git a/dix/dixfonts.c b/dix/dixfonts.c
index 5f087a3..62ad575 100644
--- a/dix/dixfonts.c
+++ b/dix/dixfonts.c
@@ -1145,9 +1145,9 @@ static XID clearGC[] = { CT_NONE };
 #define clearGCmask (GCClipMask)
 
 int
-doPolyText(ClientPtr client, register PTclosurePtr c)
+doPolyText(ClientPtr client, PTclosurePtr c)
 {
-    register FontPtr pFont = c->pGC->font, oldpFont;
+    FontPtr pFont = c->pGC->font, oldpFont;
     Font	fid, oldfid;
     int err = Success, lgerr;	/* err is in X error, not font error, space */
     enum { NEVER_SLEPT, START_SLEEP, SLEEPING } client_state = NEVER_SLEPT;
@@ -1447,7 +1447,7 @@ PolyText(ClientPtr client, DrawablePtr p
 #undef FontShiftSize
 
 int
-doImageText(ClientPtr client, register ITclosurePtr c)
+doImageText(ClientPtr client, ITclosurePtr c)
 {
     int err = Success, lgerr;	/* err is in X error, not font error, space */
     FontPathElementPtr fpe;
diff --git a/dix/dixutils.c b/dix/dixutils.c
index e530360..c0728da 100644
--- a/dix/dixutils.c
+++ b/dix/dixutils.c
@@ -168,7 +168,7 @@ ISOLatin1ToLower (unsigned char source)
 _X_EXPORT void
 CopyISOLatin1Lowered(unsigned char *dest, unsigned char *source, int length)
 {
-    register int i;
+    int i;
 
     for (i = 0; i < length; i++, source++, dest++)
 	*dest = ISOLatin1ToLower (*source);
@@ -392,8 +392,8 @@ AlterSaveSetForClient(ClientPtr client, 
 void
 DeleteWindowFromAnySaveSet(WindowPtr pWin)
 {
-    register int i;
-    register ClientPtr client;
+    int i;
+    ClientPtr client;
     
     for (i = 0; i< currentMaxClients; i++)
     {    
@@ -434,7 +434,7 @@ static Bool		handlerDeleted;
 void
 BlockHandler(pointer pTimeout, pointer pReadmask)
 {
-    register int i, j;
+    int i, j;
     
     ++inHandler;
     for (i = 0; i < screenInfo.numScreens; i++)
@@ -468,7 +468,7 @@ BlockHandler(pointer pTimeout, pointer p
 void
 WakeupHandler(int result, pointer pReadmask)
 {
-    register int i, j;
+    int i, j;
 
     ++inHandler;
     for (i = numHandlers - 1; i >= 0; i--)
diff --git a/dix/events.c b/dix/events.c
index 0053f42..c0b62b8 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -761,8 +761,8 @@ CheckPhysLimits(
 
 static void
 CheckVirtualMotion(
-    register QdEventPtr qe,
-    register WindowPtr pWin)
+    QdEventPtr qe,
+    WindowPtr pWin)
 {
 #ifdef PANORAMIX
     if(!noPanoramiXExtension) {
@@ -875,7 +875,7 @@ ChangeToCursor(CursorPtr cursor)
 
 /* returns true if b is a descendent of a */
 Bool
-IsParent(register WindowPtr a, register WindowPtr b)
+IsParent(WindowPtr a, WindowPtr b)
 {
     for (b = b->parent; b; b = b->parent)
 	if (b == a) return TRUE;
@@ -885,8 +885,8 @@ IsParent(register WindowPtr a, register 
 static void
 PostNewCursor(void)
 {
-    register    WindowPtr win;
-    register    GrabPtr grab = inputInfo.pointer->grab;
+    WindowPtr win;
+    GrabPtr grab = inputInfo.pointer->grab;
 
     if (syncEvents.playingEvents)
 	return;
@@ -952,7 +952,7 @@ XineramaGetCursorScreen()
 #define TIMESLOP (5 * 60 * 1000) /* 5 minutes */
 
 static void
-MonthChangedOrBadTime(register xEvent *xE)
+MonthChangedOrBadTime(xEvent *xE)
 {
     /* If the ddx/OS is careless about not processing timestamped events from
      * different sources in sorted order, then it's possible for time to go
@@ -971,7 +971,7 @@ MonthChangedOrBadTime(register xEvent *x
     lastDeviceEventTime = currentTime; }
 
 void
-NoticeEventTime(register xEvent *xE)
+NoticeEventTime(xEvent *xE)
 {
     if (!syncEvents.playingEvents)
 	NoticeTime(xE);
@@ -984,8 +984,8 @@ NoticeEventTime(register xEvent *xE)
 void
 EnqueueEvent(xEvent *xE, DeviceIntPtr device, int count)
 {
-    register QdEventPtr tail = *syncEvents.pendtail;
-    register QdEventPtr qe;
+    QdEventPtr tail = *syncEvents.pendtail;
+    QdEventPtr qe;
     xEvent		*qxE;
 
     NoticeTime(xE);
@@ -1059,8 +1059,8 @@ EnqueueEvent(xEvent *xE, DeviceIntPtr de
 static void
 PlayReleasedEvents(void)
 {
-    register QdEventPtr *prev, qe;
-    register DeviceIntPtr dev;
+    QdEventPtr *prev, qe;
+    DeviceIntPtr dev;
 
     prev = &syncEvents.pending;
     while ( (qe = *prev) )
@@ -1104,7 +1104,7 @@ PlayReleasedEvents(void)
 }
 
 static void
-FreezeThaw(register DeviceIntPtr dev, Bool frozen)
+FreezeThaw(DeviceIntPtr dev, Bool frozen)
 {
     dev->sync.frozen = frozen;
     if (frozen)
@@ -1116,13 +1116,13 @@ FreezeThaw(register DeviceIntPtr dev, Bo
 void
 ComputeFreezes()
 {
-    register DeviceIntPtr replayDev = syncEvents.replayDev;
-    register int i;
+    DeviceIntPtr replayDev = syncEvents.replayDev;
+    int i;
     WindowPtr w;
-    register xEvent *xE;
+    xEvent *xE;
     int count;
     GrabPtr grab;
-    register DeviceIntPtr dev;
+    DeviceIntPtr dev;
 
     for (dev = inputInfo.devices; dev; dev = dev->next)
 	FreezeThaw(dev, dev->sync.other || (dev->sync.state >= FROZEN));
@@ -1198,10 +1198,10 @@ ScreenRestructured (ScreenPtr pScreen)
 #endif
 
 void
-CheckGrabForSyncs(register DeviceIntPtr thisDev, Bool thisMode, Bool otherMode)
+CheckGrabForSyncs(DeviceIntPtr thisDev, Bool thisMode, Bool otherMode)
 {
-    register GrabPtr grab = thisDev->grab;
-    register DeviceIntPtr dev;
+    GrabPtr grab = thisDev->grab;
+    DeviceIntPtr dev;
 
     if (thisMode == GrabModeSync)
 	thisDev->sync.state = FROZEN_NO_EVENT;
@@ -1232,7 +1232,7 @@ CheckGrabForSyncs(register DeviceIntPtr 
 }
 
 void
-ActivatePointerGrab(register DeviceIntPtr mouse, register GrabPtr grab, 
+ActivatePointerGrab(DeviceIntPtr mouse, GrabPtr grab, 
                     TimeStamp time, Bool autoGrab)
 {
     WindowPtr oldWin = (mouse->grab) ? mouse->grab->window
@@ -1260,10 +1260,10 @@ ActivatePointerGrab(register DeviceIntPt
 }
 
 void
-DeactivatePointerGrab(register DeviceIntPtr mouse)
+DeactivatePointerGrab(DeviceIntPtr mouse)
 {
-    register GrabPtr grab = mouse->grab;
-    register DeviceIntPtr dev;
+    GrabPtr grab = mouse->grab;
+    DeviceIntPtr dev;
 
     mouse->valuator->motionHintWindow = NullWindow;
     mouse->grab = NullGrab;
@@ -1284,7 +1284,7 @@ DeactivatePointerGrab(register DeviceInt
 }
 
 void
-ActivateKeyboardGrab(register DeviceIntPtr keybd, GrabPtr grab, TimeStamp time, Bool passive)
+ActivateKeyboardGrab(DeviceIntPtr keybd, GrabPtr grab, TimeStamp time, Bool passive)
 {
     WindowPtr oldWin;
 
@@ -1310,11 +1310,11 @@ ActivateKeyboardGrab(register DeviceIntP
 }
 
 void
-DeactivateKeyboardGrab(register DeviceIntPtr keybd)
+DeactivateKeyboardGrab(DeviceIntPtr keybd)
 {
-    register GrabPtr grab = keybd->grab;
-    register DeviceIntPtr dev;
-    register WindowPtr focusWin = keybd->focus ? keybd->focus->win
+    GrabPtr grab = keybd->grab;
+    DeviceIntPtr dev;
+    WindowPtr focusWin = keybd->focus ? keybd->focus->win
 					       : sprite.win;
 
     if (focusWin == FollowKeyboardWin)
@@ -1338,7 +1338,7 @@ AllowSome(ClientPtr client, TimeStamp ti
 {
     Bool thisGrabbed, otherGrabbed, othersFrozen, thisSynced;
     TimeStamp grabTime;
-    register DeviceIntPtr dev;
+    DeviceIntPtr dev;
 
     thisGrabbed = thisDev->grab && SameClient(thisDev->grab, client);
     thisSynced = FALSE;
@@ -1442,7 +1442,7 @@ AllowSome(ClientPtr client, TimeStamp ti
 }
 
 int
-ProcAllowEvents(register ClientPtr client)
+ProcAllowEvents(ClientPtr client)
 {
     TimeStamp		time;
     DeviceIntPtr	mouse = inputInfo.pointer;
@@ -1487,7 +1487,7 @@ ProcAllowEvents(register ClientPtr clien
 void
 ReleaseActiveGrabs(ClientPtr client)
 {
-    register DeviceIntPtr dev;
+    DeviceIntPtr dev;
     Bool    done;
 
     /* XXX CloseDownClient should remove passive grabs before
@@ -1589,12 +1589,12 @@ TryClientEvents (ClientPtr client, xEven
 }
 
 int
-DeliverEventsToWindow(register WindowPtr pWin, xEvent *pEvents, int count, 
+DeliverEventsToWindow(WindowPtr pWin, xEvent *pEvents, int count, 
                       Mask filter, GrabPtr grab, int mskidx)
 {
     int deliveries = 0, nondeliveries = 0;
     int attempt;
-    register InputClients *other;
+    InputClients *other;
     ClientPtr client = NullClient;
     Mask deliveryMask = 0; /* If a grab occurs due to a button press, then
 		              this mask is the mask of the grab. */
@@ -1708,10 +1708,10 @@ XineramaTryClientEventsResult(
 #endif
 
 int
-MaybeDeliverEventsToClient(register WindowPtr pWin, xEvent *pEvents, 
+MaybeDeliverEventsToClient(WindowPtr pWin, xEvent *pEvents, 
                            int count, Mask filter, ClientPtr dontClient)
 {
-    register OtherClients *other;
+    OtherClients *other;
 
 
     if (pWin->eventMask & filter)
@@ -1799,8 +1799,8 @@ FixUpEventFromWindow(
 }
 
 int
-DeliverDeviceEvents(register WindowPtr pWin, register xEvent *xE, GrabPtr grab, 
-                    register WindowPtr stopAt, DeviceIntPtr dev, int count)
+DeliverDeviceEvents(WindowPtr pWin, xEvent *xE, GrabPtr grab, 
+                    WindowPtr stopAt, DeviceIntPtr dev, int count)
 {
     Window child = None;
     int type = xE->u.u.type;
@@ -1809,7 +1809,7 @@ DeliverDeviceEvents(register WindowPtr p
 
     if (type & EXTENSION_EVENT_BASE)
     {
-	register OtherInputMasks *inputMasks;
+	OtherInputMasks *inputMasks;
 	int mskidx = dev->id;
 
 	inputMasks = wOtherInputMasks(pWin);
@@ -1863,8 +1863,8 @@ DeliverDeviceEvents(register WindowPtr p
 
 /* not useful for events that propagate up the tree or extension events */
 _X_EXPORT int
-DeliverEvents(register WindowPtr pWin, register xEvent *xE, int count, 
-              register WindowPtr otherParent)
+DeliverEvents(WindowPtr pWin, xEvent *xE, int count, 
+              WindowPtr otherParent)
 {
     Mask filter;
     int     deliveries;
@@ -1929,7 +1929,7 @@ PointInBorderSize(WindowPtr pWin, int x,
 static WindowPtr 
 XYToWindow(int x, int y)
 {
-    register WindowPtr  pWin;
+    WindowPtr  pWin;
     BoxRec		box;
 
     spriteTraceGood = 1;	/* root window still there */
@@ -2092,9 +2092,9 @@ void ReinitializeRootWindow(WindowPtr wi
 #endif
 
 void
-DefineInitialRootWindow(register WindowPtr win)
+DefineInitialRootWindow(WindowPtr win)
 {
-    register ScreenPtr pScreen = win->drawable.pScreen;
+    ScreenPtr pScreen = win->drawable.pScreen;
 
     sprite.hotPhys.pScreen = pScreen;
     sprite.hotPhys.x = pScreen->width / 2;
@@ -2411,13 +2411,13 @@ BorderSizeNotEmpty(WindowPtr pWin)
 static Bool
 CheckPassiveGrabsOnWindow(
     WindowPtr pWin,
-    register DeviceIntPtr device,
-    register xEvent *xE,
+    DeviceIntPtr device,
+    xEvent *xE,
     int count)
 {
-    register GrabPtr grab = wPassiveGrabs(pWin);
+    GrabPtr grab = wPassiveGrabs(pWin);
     GrabRec tempGrab;
-    register xEvent *dxE;
+    xEvent *dxE;
 
     if (!grab)
 	return FALSE;
@@ -2513,12 +2513,12 @@ tried. PRH
 */
 
 Bool
-CheckDeviceGrabs(register DeviceIntPtr device, register xEvent *xE, 
+CheckDeviceGrabs(DeviceIntPtr device, xEvent *xE, 
                  int checkFirst, int count)
 {
-    register int i;
-    register WindowPtr pWin = NULL;
-    register FocusClassPtr focus = device->focus;
+    int i;
+    WindowPtr pWin = NULL;
+    FocusClassPtr focus = device->focus;
 
     if (((xE->u.u.type == ButtonPress)
 #if defined(XINPUT) && defined(XKB)
@@ -2585,13 +2585,13 @@ DeliverFocusedEvent(DeviceIntPtr keybd, 
 }
 
 void
-DeliverGrabbedEvent(register xEvent *xE, register DeviceIntPtr thisDev, 
+DeliverGrabbedEvent(xEvent *xE, DeviceIntPtr thisDev, 
                     Bool deactivateGrab, int count)
 {
-    register GrabPtr grab = thisDev->grab;
+    GrabPtr grab = thisDev->grab;
     int deliveries = 0;
-    register DeviceIntPtr dev;
-    register xEvent *dxE;
+    DeviceIntPtr dev;
+    xEvent *dxE;
 
     if (grab->ownerEvents)
     {
@@ -2668,19 +2668,19 @@ DeliverGrabbedEvent(register xEvent *xE,
 
 void
 #ifdef XKB
-CoreProcessKeyboardEvent (register xEvent *xE, register DeviceIntPtr keybd, int count)
+CoreProcessKeyboardEvent (xEvent *xE, DeviceIntPtr keybd, int count)
 #else
-ProcessKeyboardEvent (register xEvent *xE, register DeviceIntPtr keybd, int count)
+ProcessKeyboardEvent (xEvent *xE, DeviceIntPtr keybd, int count)
 #endif
 {
     int             key, bit;
-    register BYTE   *kptr;
-    register int    i;
-    register CARD8  modifiers;
-    register CARD16 mask;
+    BYTE   *kptr;
+    int    i;
+    CARD8  modifiers;
+    CARD16 mask;
     GrabPtr         grab = keybd->grab;
     Bool            deactivateGrab = FALSE;
-    register KeyClassPtr keyc = keybd->key;
+    KeyClassPtr keyc = keybd->key;
 #ifdef XEVIE
     static Window           rootWin = 0;
 
@@ -2832,11 +2832,11 @@ drawable.id:0;
    CoreProcessKeyEvent to be called, as in for example Mouse Keys.
 */
 void
-FixKeyState (register xEvent *xE, register DeviceIntPtr keybd)
+FixKeyState (xEvent *xE, DeviceIntPtr keybd)
 {
     int             key, bit;
-    register BYTE   *kptr;
-    register KeyClassPtr keyc = keybd->key;
+    BYTE   *kptr;
+    KeyClassPtr keyc = keybd->key;
 
     key = xE->u.u.detail;
     kptr = &keyc->down[key >> 3];
@@ -2863,14 +2863,14 @@ FixKeyState (register xEvent *xE, regist
 
 void
 #ifdef XKB
-CoreProcessPointerEvent (register xEvent *xE, register DeviceIntPtr mouse, int count)
+CoreProcessPointerEvent (xEvent *xE, DeviceIntPtr mouse, int count)
 #else
-ProcessPointerEvent (register xEvent *xE, register DeviceIntPtr mouse, int count)
+ProcessPointerEvent (xEvent *xE, DeviceIntPtr mouse, int count)
 #endif
 {
-    register GrabPtr	grab = mouse->grab;
+    GrabPtr	grab = mouse->grab;
     Bool                deactivateGrab = FALSE;
-    register ButtonClassPtr butc = mouse->button;
+    ButtonClassPtr butc = mouse->button;
 #ifdef XKB
     XkbSrvInfoPtr xkbi= inputInfo.keyboard->key->xkbInfo;
 #endif
@@ -2914,8 +2914,8 @@ ProcessPointerEvent (register xEvent *xE
     }
     if (xE->u.u.type != MotionNotify)
     {
-	register int  key;
-	register BYTE *kptr;
+	int  key;
+	BYTE *kptr;
 	int           bit;
 
 	XE_KBPTR.rootX = sprite.hot.x;
@@ -2976,10 +2976,10 @@ ProcessPointerEvent (register xEvent *xE
 
 void
 RecalculateDeliverableEvents(pWin)
-    register WindowPtr pWin;
+    WindowPtr pWin;
 {
-    register OtherClients *others;
-    register WindowPtr pChild;
+    OtherClients *others;
+    WindowPtr pChild;
 
     pChild = pWin;
     while (1)
@@ -3018,8 +3018,8 @@ RecalculateDeliverableEvents(pWin)
 int
 OtherClientGone(pointer value, XID id)
 {
-    register OtherClientsPtr other, prev;
-    register WindowPtr pWin = (WindowPtr)value;
+    OtherClientsPtr other, prev;
+    WindowPtr pWin = (WindowPtr)value;
 
     prev = 0;
     for (other = wOtherClients(pWin); other; other = other->next)
@@ -3045,7 +3045,7 @@ OtherClientGone(pointer value, XID id)
 }
 
 int
-EventSelectForWindow(register WindowPtr pWin, register ClientPtr client, Mask mask)
+EventSelectForWindow(WindowPtr pWin, ClientPtr client, Mask mask)
 {
     Mask check;
     OtherClients * others;
@@ -3117,10 +3117,10 @@ maskSet: 
 }
 
 int
-EventSuppressForWindow(register WindowPtr pWin, register ClientPtr client, 
+EventSuppressForWindow(WindowPtr pWin, ClientPtr client, 
                        Mask mask, Bool *checkOptional)
 {
-    register int i, free;
+    int i, free;
 
     if (mask & ~PropagateMask)
     {
@@ -3174,8 +3174,8 @@ EventSuppressForWindow(register WindowPt
 
 static WindowPtr 
 CommonAncestor(
-    register WindowPtr a,
-    register WindowPtr b)
+    WindowPtr a,
+    WindowPtr b)
 {
     for (b = b->parent; b; b = b->parent)
 	if (IsParent(b, a)) return b;
@@ -3187,14 +3187,14 @@ EnterLeaveEvent(
     int type,
     int mode,
     int detail,
-    register WindowPtr pWin,
+    WindowPtr pWin,
     Window child)
 {
     xEvent		event;
-    register DeviceIntPtr keybd = inputInfo.keyboard;
+    DeviceIntPtr keybd = inputInfo.keyboard;
     WindowPtr		focus;
-    register DeviceIntPtr mouse = inputInfo.pointer;
-    register GrabPtr	grab = mouse->grab;
+    DeviceIntPtr mouse = inputInfo.pointer;
+    GrabPtr	grab = mouse->grab;
     Mask		mask;
 
     if ((pWin == mouse->valuator->motionHintWindow) &&
@@ -3278,7 +3278,7 @@ EnterNotifies(WindowPtr ancestor, Window
 static void
 LeaveNotifies(WindowPtr child, WindowPtr ancestor, int mode, int detail)
 {
-    register WindowPtr  pWin;
+    WindowPtr  pWin;
 
     if (ancestor == child)
 	return;
@@ -3318,7 +3318,7 @@ DoEnterLeaveEvents(WindowPtr fromWin, Wi
 }
 
 static void
-FocusEvent(DeviceIntPtr dev, int type, int mode, int detail, register WindowPtr pWin)
+FocusEvent(DeviceIntPtr dev, int type, int mode, int detail, WindowPtr pWin)
 {
     xEvent event;
 
@@ -3388,7 +3388,7 @@ FocusOutEvents(
     int mode, int detail,
     Bool doAncestor)
 {
-    register WindowPtr  pWin;
+    WindowPtr  pWin;
 
     for (pWin = child; pWin != ancestor; pWin = pWin->parent)
 	FocusEvent(dev, FocusOut, mode, detail, pWin);
@@ -3531,7 +3531,7 @@ SetInputFocus(
     Time ctime,
     Bool followOK)
 {
-    register FocusClassPtr focus;
+    FocusClassPtr focus;
     WindowPtr focusWin;
     int mode, rc;
     TimeStamp time;
@@ -3579,7 +3579,7 @@ SetInputFocus(
     else
     {
         int depth = 0;
-	register WindowPtr pWin;
+	WindowPtr pWin;
 
         for (pWin = focusWin; pWin; pWin = pWin->parent) depth++;
         if (depth > focus->traceSize)
@@ -3745,7 +3745,7 @@ int
 ProcChangeActivePointerGrab(ClientPtr client)
 {
     DeviceIntPtr device = inputInfo.pointer;
-    register GrabPtr grab = device->grab;
+    GrabPtr grab = device->grab;
     CursorPtr newCursor, oldCursor;
     REQUEST(xChangeActivePointerGrabReq);
     TimeStamp time;
@@ -3807,12 +3807,12 @@ ProcUngrabPointer(ClientPtr client)
 }
 
 int
-GrabDevice(register ClientPtr client, register DeviceIntPtr dev, 
+GrabDevice(ClientPtr client, DeviceIntPtr dev, 
            unsigned this_mode, unsigned other_mode, Window grabWindow, 
            unsigned ownerEvents, Time ctime, Mask mask, CARD8 *status)
 {
     WindowPtr pWin;
-    register GrabPtr grab;
+    GrabPtr grab;
     TimeStamp time;
     int rc;
 
@@ -4433,7 +4433,7 @@ CheckCursorConfinement(WindowPtr pWin)
 Mask
 EventMaskForClient(WindowPtr pWin, ClientPtr client)
 {
-    register OtherClientsPtr	other;
+    OtherClientsPtr	other;
 
     if (wClient (pWin) == client)
 	return pWin->eventMask;
diff --git a/dix/extension.c b/dix/extension.c
index 29cae86..dc1a76f 100644
--- a/dix/extension.c
+++ b/dix/extension.c
@@ -81,11 +81,11 @@ extern unsigned totalExtensionSize;
 static void
 InitExtensionPrivates(ExtensionEntry *ext)
 {
-    register char *ptr;
+    char *ptr;
     DevUnion *ppriv;
-    register unsigned *sizes;
-    register unsigned size;
-    register int i;
+    unsigned *sizes;
+    unsigned size;
+    int i;
 
     if (totalExtensionSize == sizeof(ExtensionEntry))
 	ppriv = (DevUnion *)NULL;
@@ -115,7 +115,7 @@ AddExtension(char *name, int NumEvents, 
 	     unsigned short (*MinorOpcodeProc)(ClientPtr c3))
 {
     int i;
-    register ExtensionEntry *ext, **newexts;
+    ExtensionEntry *ext, **newexts;
 
     if (!MainProc || !SwappedMainProc || !CloseDownProc || !MinorOpcodeProc)
         return((ExtensionEntry *) NULL);
@@ -282,7 +282,7 @@ MinorOpcodeOfRequest(ClientPtr client)
 void
 CloseDownExtensions()
 {
-    register int i,j;
+    int i,j;
 
     for (i = NumExtensions - 1; i >= 0; i--)
     {
@@ -300,7 +300,7 @@ CloseDownExtensions()
     lastError = FirstExtensionError;
     for (i=0; i<MAXSCREENS; i++)
     {
-	register ScreenProcEntry *spentry = &AuxillaryScreenProcs[i];
+	ScreenProcEntry *spentry = &AuxillaryScreenProcs[i];
 
 	while (spentry->num)
 	{
@@ -363,7 +363,7 @@ ProcListExtensions(ClientPtr client)
 
     if ( NumExtensions )
     {
-        register int i, j;
+        int i, j;
 
         for (i=0;  i<NumExtensions; i++)
 	{
@@ -410,8 +410,8 @@ ProcListExtensions(ClientPtr client)
 ExtensionLookupProc 
 LookupProc(char *name, GCPtr pGC)
 {
-    register int i;
-    register ScreenProcEntry *spentry;
+    int i;
+    ScreenProcEntry *spentry;
     spentry  = &AuxillaryScreenProcs[pGC->pScreen->myNum];
     if (spentry->num)    
     {
@@ -431,8 +431,8 @@ RegisterProc(char *name, GC *pGC, Extens
 Bool
 RegisterScreenProc(char *name, ScreenPtr pScreen, ExtensionLookupProc proc)
 {
-    register ScreenProcEntry *spentry;
-    register ProcEntryPtr procEntry = (ProcEntryPtr)NULL;
+    ScreenProcEntry *spentry;
+    ProcEntryPtr procEntry = (ProcEntryPtr)NULL;
     char *newname;
     int i;
 
diff --git a/dix/gc.c b/dix/gc.c
index 5106fcd..89b246d 100644
--- a/dix/gc.c
+++ b/dix/gc.c
@@ -144,12 +144,12 @@ ValidateGC(DrawablePtr pDraw, GC *pGC)
     assert(pUnion); _var = (_type)pUnion->ptr; pUnion++; }
 
 _X_EXPORT int
-dixChangeGC(ClientPtr client, register GC *pGC, register BITS32 mask, CARD32 *pC32, ChangeGCValPtr pUnion)
+dixChangeGC(ClientPtr client, GC *pGC, BITS32 mask, CARD32 *pC32, ChangeGCValPtr pUnion)
 {
-    register BITS32 	index2;
-    register int 	error = 0;
-    PixmapPtr 		pPixmap;
-    BITS32		maskQ;
+    BITS32 	index2;
+    int 	error = 0;
+    PixmapPtr 	pPixmap;
+    BITS32	maskQ;
 
     assert( (pC32 && !pUnion) || (!pC32 && pUnion) );
     pGC->serialNumber |= GC_CHANGE_SERIAL_BIT;
@@ -522,7 +522,7 @@ dixChangeGC(ClientPtr client, register G
 /* Publically defined entry to ChangeGC.  Just calls dixChangeGC and tells
  * it that all of the entries are constants or IDs */
 _X_EXPORT int
-ChangeGC(register GC *pGC, register BITS32 mask, XID *pval)
+ChangeGC(GC *pGC, BITS32 mask, XID *pval)
 {
     return (dixChangeGC(NullClient, pGC, mask, pval, NULL));
 }
@@ -548,7 +548,7 @@ NOTE:
 32 bits long
 */
 _X_EXPORT int
-DoChangeGC(register GC *pGC, register BITS32 mask, XID *pval, int fPointer)
+DoChangeGC(GC *pGC, BITS32 mask, XID *pval, int fPointer)
 {
     if (fPointer)
     /* XXX might be a problem on 64 bit big-endian servers */
@@ -572,11 +572,11 @@ static GCPtr
 AllocateGC(ScreenPtr pScreen)
 {
     GCPtr pGC;
-    register char *ptr;
-    register DevUnion *ppriv;
-    register unsigned *sizes;
-    register unsigned size;
-    register int i;
+    char *ptr;
+    DevUnion *ppriv;
+    unsigned *sizes;
+    unsigned size;
+    int i;
 
     pGC = (GCPtr)xalloc(pScreen->totalGCSize);
     if (pGC)
@@ -602,7 +602,7 @@ AllocateGC(ScreenPtr pScreen)
 _X_EXPORT GCPtr
 CreateGC(DrawablePtr pDrawable, BITS32 mask, XID *pval, int *pStatus)
 {
-    register GCPtr pGC;
+    GCPtr pGC;
 
     pGC = AllocateGC(pDrawable->pScreen);
     if (!pGC)
@@ -724,11 +724,11 @@ CreateDefaultTile (GCPtr pGC)
 }
 
 _X_EXPORT int
-CopyGC(register GC *pgcSrc, register GC *pgcDst, register BITS32 mask)
+CopyGC(GC *pgcSrc, GC *pgcDst, BITS32 mask)
 {
-    register BITS32	index2;
-    BITS32		maskQ;
-    int 		error = 0;
+    BITS32	index2;
+    BITS32	maskQ;
+    int 	error = 0;
 
     if (pgcSrc == pgcDst)
 	return Success;
@@ -934,7 +934,7 @@ go with CreateGC() or ChangeGC().)
 _X_EXPORT GCPtr
 CreateScratchGC(ScreenPtr pScreen, unsigned depth)
 {
-    register GCPtr pGC;
+    GCPtr pGC;
 
     pGC = AllocateGC(pScreen);
     if (!pGC)
@@ -986,8 +986,8 @@ CreateScratchGC(ScreenPtr pScreen, unsig
 void
 FreeGCperDepth(int screenNum)
 {
-    register int i;
-    register ScreenPtr pScreen;
+    int i;
+    ScreenPtr pScreen;
     GCPtr *ppGC;
 
     pScreen = screenInfo.screens[screenNum];
@@ -1002,8 +1002,8 @@ FreeGCperDepth(int screenNum)
 Bool
 CreateGCperDepth(int screenNum)
 {
-    register int i;
-    register ScreenPtr pScreen;
+    int i;
+    ScreenPtr pScreen;
     DepthPtr pDepth;
     GCPtr *ppGC;
 
@@ -1035,7 +1035,7 @@ CreateGCperDepth(int screenNum)
 Bool
 CreateDefaultStipple(int screenNum)
 {
-    register ScreenPtr pScreen;
+    ScreenPtr pScreen;
     XID tmpval[3];
     xRectangle rect;
     CARD16 w, h;
@@ -1077,10 +1077,10 @@ FreeDefaultStipple(int screenNum)
 }
 
 _X_EXPORT int
-SetDashes(register GCPtr pGC, unsigned offset, unsigned ndash, unsigned char *pdash)
+SetDashes(GCPtr pGC, unsigned offset, unsigned ndash, unsigned char *pdash)
 {
-    register long i;
-    register unsigned char *p, *indash;
+    long i;
+    unsigned char *p, *indash;
     BITS32 maskQ = 0;
 
     i = ndash;
@@ -1135,8 +1135,8 @@ SetDashes(register GCPtr pGC, unsigned o
 _X_EXPORT int
 VerifyRectOrder(int nrects, xRectangle *prects, int ordering)
 {
-    register xRectangle	*prectP, *prectN;
-    register int	i;
+    xRectangle	*prectP, *prectN;
+    int	i;
 
     switch(ordering)
     {
@@ -1220,10 +1220,10 @@ SetClipRects(GCPtr pGC, int xOrigin, int
    you use it often enough it will become real.)
 */
 _X_EXPORT GCPtr
-GetScratchGC(register unsigned depth, register ScreenPtr pScreen)
+GetScratchGC(unsigned depth, ScreenPtr pScreen)
 {
-    register int i;
-    register GCPtr pGC;
+    int i;
+    GCPtr pGC;
 
     for (i=0; i<=pScreen->numDepths; i++)
         if ( pScreen->GCperDepth[i]->depth == depth &&
@@ -1269,10 +1269,10 @@ mark it as available.
    if not, free it for real
 */
 _X_EXPORT void
-FreeScratchGC(register GCPtr pGC)
+FreeScratchGC(GCPtr pGC)
 {
-    register ScreenPtr pScreen = pGC->pScreen;
-    register int i;
+    ScreenPtr pScreen = pGC->pScreen;
+    int i;
 
     for (i=0; i<=pScreen->numDepths; i++)
     {
diff --git a/dix/glyphcurs.c b/dix/glyphcurs.c
index c1c545f..70b1ff8 100644
--- a/dix/glyphcurs.c
+++ b/dix/glyphcurs.c
@@ -74,10 +74,10 @@ cursor metrics.
 */
 
 int
-ServerBitsFromGlyph(FontPtr pfont, unsigned ch, register CursorMetricPtr cm, unsigned char **ppbits)
+ServerBitsFromGlyph(FontPtr pfont, unsigned ch, CursorMetricPtr cm, unsigned char **ppbits)
 {
-    register ScreenPtr pScreen;
-    register GCPtr pGC;
+    ScreenPtr pScreen;
+    GCPtr pGC;
     xRectangle rect;
     PixmapPtr ppix;
     long nby;
@@ -140,7 +140,7 @@ ServerBitsFromGlyph(FontPtr pfont, unsig
 
 
 Bool
-CursorMetricsFromGlyph(register FontPtr pfont, unsigned ch, register CursorMetricPtr cm)
+CursorMetricsFromGlyph(FontPtr pfont, unsigned ch, CursorMetricPtr cm)
 {
     CharInfoPtr 	pci;
     unsigned long	nglyphs;
diff --git a/dix/grabs.c b/dix/grabs.c
index 0c2b05e..714fea3 100644
--- a/dix/grabs.c
+++ b/dix/grabs.c
@@ -128,7 +128,7 @@ FreeGrab(GrabPtr pGrab)
 int
 DeletePassiveGrab(pointer value, XID id)
 {
-    register GrabPtr g, prev;
+    GrabPtr g, prev;
     GrabPtr pGrab = (GrabPtr)value;
 
     /* it is OK if the grab isn't found */
@@ -153,8 +153,8 @@ DeletePassiveGrab(pointer value, XID id)
 static Mask *
 DeleteDetailFromMask(Mask *pDetailMask, unsigned short detail)
 {
-    register Mask *mask;
-    register int i;
+    Mask *mask;
+    int i;
 
     mask = (Mask *)xalloc(sizeof(Mask) * MasksPerDetailMask);
     if (mask)
@@ -305,7 +305,7 @@ AddPassiveGrabToList(GrabPtr pGrab)
 Bool
 DeletePassiveGrabFromList(GrabPtr pMinuendGrab)
 {
-    register GrabPtr grab;
+    GrabPtr grab;
     GrabPtr *deletes, *adds;
     Mask ***updates, **details;
     int i, ndels, nadds, nups;
diff --git a/dix/privates.c b/dix/privates.c
index a61c3cb..a66fc3d 100644
--- a/dix/privates.c
+++ b/dix/privates.c
@@ -225,7 +225,7 @@ AllocateWindowPrivateIndex()
 }
 
 _X_EXPORT Bool
-AllocateWindowPrivate(register ScreenPtr pScreen, int index2, unsigned amount)
+AllocateWindowPrivate(ScreenPtr pScreen, int index2, unsigned amount)
 {
     unsigned oldamount;
 
@@ -275,7 +275,7 @@ AllocateGCPrivateIndex()
 }
 
 _X_EXPORT Bool
-AllocateGCPrivate(register ScreenPtr pScreen, int index2, unsigned amount)
+AllocateGCPrivate(ScreenPtr pScreen, int index2, unsigned amount)
 {
     unsigned oldamount;
 
@@ -324,7 +324,7 @@ AllocatePixmapPrivateIndex()
 }
 
 _X_EXPORT Bool
-AllocatePixmapPrivate(register ScreenPtr pScreen, int index2, unsigned amount)
+AllocatePixmapPrivate(ScreenPtr pScreen, int index2, unsigned amount)
 {
     unsigned oldamount;
 
diff --git a/dix/property.c b/dix/property.c
index d402849..034d86f 100644
--- a/dix/property.c
+++ b/dix/property.c
@@ -76,7 +76,7 @@ static void
 PrintPropertys(WindowPtr pWin)
 {
     PropertyPtr pProp;
-    register int j;
+    int j;
 
     pProp = pWin->userProps;
     while (pProp)
@@ -97,7 +97,7 @@ ProcRotateProperties(ClientPtr client)
     int     i, j, delta, rc;
     REQUEST(xRotatePropertiesReq);
     WindowPtr pWin;
-    register    Atom * atoms;
+    Atom * atoms;
     PropertyPtr * props;               /* array of pointer */
     PropertyPtr pProp;
     xEvent event;
@@ -622,7 +622,7 @@ ProcListProperties(ClientPtr client)
 }
 
 int 
-ProcDeleteProperty(register ClientPtr client)
+ProcDeleteProperty(ClientPtr client)
 {
     WindowPtr pWin;
     REQUEST(xDeletePropertyReq);
diff --git a/dix/resource.c b/dix/resource.c
index 4468f45..7092b2f 100644
--- a/dix/resource.c
+++ b/dix/resource.c
@@ -257,7 +257,7 @@ ClientResourceRec clientTable[MAXCLIENTS
 Bool
 InitClientResources(ClientPtr client)
 {
-    register int i, j;
+    int i, j;
  
     if (client == serverClient)
     {
@@ -314,7 +314,7 @@ InitClientResources(ClientPtr client)
 
 
 static int
-Hash(int client, register XID id)
+Hash(int client, XID id)
 {
     id &= RESOURCE_ID_MASK;
     switch (clientTable[client].hashsize)
@@ -337,12 +337,12 @@ Hash(int client, register XID id)
 
 static XID
 AvailableID(
-    register int client,
-    register XID id,
-    register XID maxid,
-    register XID goodid)
+    int client,
+    XID id,
+    XID maxid,
+    XID goodid)
 {
-    register ResourcePtr res;
+    ResourcePtr res;
 
     if ((goodid >= id) && (goodid <= maxid))
 	return goodid;
@@ -360,10 +360,10 @@ AvailableID(
 _X_EXPORT void
 GetXIDRange(int client, Bool server, XID *minp, XID *maxp)
 {
-    register XID id, maxid;
-    register ResourcePtr *resp;
-    register ResourcePtr res;
-    register int i;
+    XID id, maxid;
+    ResourcePtr *resp;
+    ResourcePtr res;
+    int i;
     XID goodid;
 
     id = (Mask)client << CLIENTOFFSET;
@@ -436,7 +436,7 @@ GetXIDList(ClientPtr pClient, unsigned c
  */
 
 _X_EXPORT XID
-FakeClientID(register int client)
+FakeClientID(int client)
 {
     XID id, maxid;
 
@@ -460,8 +460,8 @@ _X_EXPORT Bool
 AddResource(XID id, RESTYPE type, pointer value)
 {
     int client;
-    register ClientResourceRec *rrec;
-    register ResourcePtr res, *head;
+    ClientResourceRec *rrec;
+    ResourcePtr res, *head;
     	
 #ifdef XSERVER_DTRACE
     XSERVER_RESOURCE_ALLOC(id, type, value, TypeNameString(type));
@@ -498,10 +498,10 @@ AddResource(XID id, RESTYPE type, pointe
 static void
 RebuildTable(int client)
 {
-    register int j;
-    register ResourcePtr res, next;
+    int j;
+    ResourcePtr res, next;
     ResourcePtr **tails, *resources;
-    register ResourcePtr **tptr, *rptr;
+    ResourcePtr **tptr, *rptr;
 
     /*
      * For now, preserve insertion order, since some ddx layers depend
@@ -548,9 +548,9 @@ _X_EXPORT void
 FreeResource(XID id, RESTYPE skipDeleteFuncType)
 {
     int		cid;
-    register    ResourcePtr res;
-    register	ResourcePtr *prev, *head;
-    register	int *eltptr;
+    ResourcePtr res;
+    ResourcePtr *prev, *head;
+    int *eltptr;
     int		elements;
     Bool	gotOne = FALSE;
 
@@ -600,8 +600,8 @@ _X_EXPORT void
 FreeResourceByType(XID id, RESTYPE type, Bool skipFree)
 {
     int		cid;
-    register    ResourcePtr res;
-    register	ResourcePtr *prev, *head;
+    ResourcePtr res;
+    ResourcePtr *prev, *head;
     if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && clientTable[cid].buckets)
     {
 	head = &clientTable[cid].resources[Hash(cid, id)];
@@ -644,7 +644,7 @@ _X_EXPORT Bool
 ChangeResourceValue (XID id, RESTYPE rtype, pointer value)
 {
     int    cid;
-    register    ResourcePtr res;
+    ResourcePtr res;
 
     if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && clientTable[cid].buckets)
     {
@@ -675,10 +675,10 @@ FindClientResourcesByType(
     FindResType func,
     pointer cdata
 ){
-    register ResourcePtr *resources;
-    register ResourcePtr this, next;
+    ResourcePtr *resources;
+    ResourcePtr this, next;
     int i, elements;
-    register int *eltptr;
+    int *eltptr;
 
     if (!client)
 	client = serverClient;
@@ -706,10 +706,10 @@ FindAllClientResources(
     FindAllRes func,
     pointer cdata
 ){
-    register ResourcePtr *resources;
-    register ResourcePtr this, next;
+    ResourcePtr *resources;
+    ResourcePtr this, next;
     int i, elements;
-    register int *eltptr;
+    int *eltptr;
 
     if (!client)
         client = serverClient;
@@ -796,8 +796,8 @@ FreeClientNeverRetainResources(ClientPtr
 void
 FreeClientResources(ClientPtr client)
 {
-    register ResourcePtr *resources;
-    register ResourcePtr this;
+    ResourcePtr *resources;
+    ResourcePtr this;
     int j;
 
     /* This routine shouldn't be called with a null client, but just in
@@ -856,7 +856,7 @@ FreeAllResources()
 }
 
 _X_EXPORT Bool
-LegalNewID(XID id, register ClientPtr client)
+LegalNewID(XID id, ClientPtr client)
 {
 
 #ifdef PANORAMIX
@@ -887,7 +887,7 @@ _X_EXPORT pointer
 SecurityLookupIDByType(ClientPtr client, XID id, RESTYPE rtype, Mask mode)
 {
     int    cid;
-    register    ResourcePtr res;
+    ResourcePtr res;
     pointer retval = NULL;
 
     if (((cid = CLIENT_ID(id)) < MAXCLIENTS) &&
@@ -914,7 +914,7 @@ _X_EXPORT pointer
 SecurityLookupIDByClass(ClientPtr client, XID id, RESTYPE classes, Mask mode)
 {
     int    cid;
-    register ResourcePtr res = NULL;
+    ResourcePtr res = NULL;
     pointer retval = NULL;
 
     if (((cid = CLIENT_ID(id)) < MAXCLIENTS) &&
diff --git a/dix/swaprep.c b/dix/swaprep.c
index 08ae6eb..6f4b277 100644
--- a/dix/swaprep.c
+++ b/dix/swaprep.c
@@ -73,10 +73,10 @@ static void SwapFont(xQueryFontReply *pr
  *  \param size size in bytes
  */
 _X_EXPORT void
-Swap32Write(ClientPtr pClient, int size, register CARD32 *pbuf)
+Swap32Write(ClientPtr pClient, int size, CARD32 *pbuf)
 {
-    register int i;
-    register char n;
+    int i;
+    char n;
 
     size >>= 2;
     for(i = 0; i < size; i++)
@@ -97,7 +97,7 @@ CopySwap32Write(ClientPtr pClient, int s
 {
     int bufsize = size;
     CARD32 *pbufT;
-    register CARD32 *from, *to, *fromLast, *toLast;
+    CARD32 *from, *to, *fromLast, *toLast;
     CARD32 tmpbuf[1];
     
     /* Allocate as big a buffer as we can... */
@@ -145,7 +145,7 @@ CopySwap16Write(ClientPtr pClient, int s
 {
     int bufsize = size;
     short *pbufT;
-    register short *from, *to, *fromLast, *toLast;
+    short *from, *to, *fromLast, *toLast;
     short tmpbuf[2];
     
     /* Allocate as big a buffer as we can... */
@@ -189,7 +189,7 @@ CopySwap16Write(ClientPtr pClient, int s
 void
 SGenericReply(ClientPtr pClient, int size, xGenericReply *pRep)
 {
-    register char n;
+    char n;
 
     swaps(&pRep->sequenceNumber, n);
     (void)WriteToClient(pClient, size, (char *) pRep);
@@ -200,7 +200,7 @@ void
 SGetWindowAttributesReply(ClientPtr pClient, int size,
                           xGetWindowAttributesReply *pRep)
 {
-    register char n;
+    char n;
 
     swaps(&pRep->sequenceNumber, n);
     swapl(&pRep->length, n);
@@ -218,7 +218,7 @@ SGetWindowAttributesReply(ClientPtr pCli
 void
 SGetGeometryReply(ClientPtr pClient, int size, xGetGeometryReply *pRep)
 {
-    register char n;
+    char n;
 
     swaps(&pRep->sequenceNumber, n);
     swapl(&pRep->root, n);
@@ -233,7 +233,7 @@ SGetGeometryReply(ClientPtr pClient, int
 void
 SQueryTreeReply(ClientPtr pClient, int size, xQueryTreeReply *pRep)
 {
-    register char n;
+    char n;
 
     swaps(&pRep->sequenceNumber, n);
     swapl(&pRep->length, n);
@@ -246,7 +246,7 @@ SQueryTreeReply(ClientPtr pClient, int s
 void
 SInternAtomReply(ClientPtr pClient, int size, xInternAtomReply *pRep)
 {
-    register char n;
+    char n;
 
     swaps(&pRep->sequenceNumber, n);
     swapl(&pRep->atom, n);
@@ -256,7 +256,7 @@ SInternAtomReply(ClientPtr pClient, int 
 void
 SGetAtomNameReply(ClientPtr pClient, int size, xGetAtomNameReply *pRep)
 {
-    register char n;
+    char n;
 
     swaps(&pRep->sequenceNumber, n);
     swapl(&pRep->length, n);
@@ -268,7 +268,7 @@ SGetAtomNameReply(ClientPtr pClient, int
 void
 SGetPropertyReply(ClientPtr pClient, int size, xGetPropertyReply *pRep)
 {
-    register char n;
+    char n;
 
     swaps(&pRep->sequenceNumber, n);
     swapl(&pRep->length, n);
@@ -281,7 +281,7 @@ SGetPropertyReply(ClientPtr pClient, int
 void
 SListPropertiesReply(ClientPtr pClient, int size, xListPropertiesReply *pRep)
 {
-    register char n;
+    char n;
 
     swaps(&pRep->sequenceNumber, n);
     swapl(&pRep->length, n);
@@ -293,7 +293,7 @@ void
 SGetSelectionOwnerReply(ClientPtr pClient, int size,
                         xGetSelectionOwnerReply *pRep)
 {
-    register char n;
+    char n;
 
     swaps(&pRep->sequenceNumber, n);
     swapl(&pRep->owner, n);
@@ -304,7 +304,7 @@ SGetSelectionOwnerReply(ClientPtr pClien
 void
 SQueryPointerReply(ClientPtr pClient, int size, xQueryPointerReply *pRep)
 {
-    register char n;
+    char n;
 
     swaps(&pRep->sequenceNumber, n);
     swapl(&pRep->root, n);
@@ -320,7 +320,7 @@ SQueryPointerReply(ClientPtr pClient, in
 void
 SwapTimecoord(xTimecoord* pCoord)
 {
-    register char n;
+    char n;
 
     swapl(&pCoord->time, n);
     swaps(&pCoord->x, n);
@@ -346,7 +346,7 @@ SwapTimeCoordWrite(ClientPtr pClient, in
 void
 SGetMotionEventsReply(ClientPtr pClient, int size, xGetMotionEventsReply *pRep)
 {
-    register char n;
+    char n;
 
     swaps(&pRep->sequenceNumber, n);
     swapl(&pRep->length, n);
@@ -357,7 +357,7 @@ SGetMotionEventsReply(ClientPtr pClient,
 void
 STranslateCoordsReply(ClientPtr pClient, int size, xTranslateCoordsReply *pRep)
 {
-    register char n;
+    char n;
 
     swaps(&pRep->sequenceNumber, n);
     swapl(&pRep->child, n);
@@ -369,7 +369,7 @@ STranslateCoordsReply(ClientPtr pClient,
 void
 SGetInputFocusReply(ClientPtr pClient, int size, xGetInputFocusReply *pRep)
 {
-    register char n;
+    char n;
 
     swaps(&pRep->sequenceNumber, n);
     swapl(&pRep->focus, n);
@@ -380,7 +380,7 @@ SGetInputFocusReply(ClientPtr pClient, i
 void
 SQueryKeymapReply(ClientPtr pClient, int size, xQueryKeymapReply *pRep)
 {
-    register char n;
+    char n;
 
     swaps(&pRep->sequenceNumber, n);
     swapl(&pRep->length, n);
@@ -390,7 +390,7 @@ SQueryKeymapReply(ClientPtr pClient, int
 static void
 SwapCharInfo(xCharInfo *pInfo)
 {
-    register char n;
+    char n;
 
     swaps(&pInfo->leftSideBearing, n);
     swaps(&pInfo->rightSideBearing, n);
@@ -403,7 +403,7 @@ SwapCharInfo(xCharInfo *pInfo)
 static void
 SwapFontInfo(xQueryFontReply *pr)
 {
-    register char		n;
+    char n;
 
     swaps(&pr->minCharOrByte2, n);
     swaps(&pr->maxCharOrByte2, n);
@@ -423,7 +423,7 @@ SwapFont(xQueryFontReply *pr, Bool hasGl
     xCharInfo *	pxci;
     unsigned	nchars, nprops;
     char	*pby;
-    register char n;
+    char n;
 
     swaps(&pr->sequenceNumber, n);
     swapl(&pr->length, n);
@@ -458,7 +458,7 @@ SQueryFontReply(ClientPtr pClient, int s
 void
 SQueryTextExtentsReply(ClientPtr pClient, int size, xQueryTextExtentsReply *pRep)
 {
-    register char n;
+    char n;
 
     swaps(&pRep->sequenceNumber, n);
     swaps(&pRep->fontAscent, n);
@@ -474,7 +474,7 @@ SQueryTextExtentsReply(ClientPtr pClient
 void
 SListFontsReply(ClientPtr pClient, int size, xListFontsReply *pRep)
 {
-    register char n;
+    char n;
 
     swaps(&pRep->sequenceNumber, n);
     swapl(&pRep->length, n);
@@ -493,7 +493,7 @@ SListFontsWithInfoReply(ClientPtr pClien
 void
 SGetFontPathReply(ClientPtr pClient, int size, xGetFontPathReply *pRep)
 {
-    register char n;
+    char n;
 
     swaps(&pRep->sequenceNumber, n);
     swapl(&pRep->length, n);
@@ -504,7 +504,7 @@ SGetFontPathReply(ClientPtr pClient, int
 void
 SGetImageReply(ClientPtr pClient, int size, xGetImageReply *pRep)
 {
-    register char n;
+    char n;
 
     swaps(&pRep->sequenceNumber, n);
     swapl(&pRep->length, n);
@@ -517,7 +517,7 @@ void
 SListInstalledColormapsReply(ClientPtr pClient, int size,
                              xListInstalledColormapsReply *pRep)
 {
-    register char n;
+    char n;
 
     swaps(&pRep->sequenceNumber, n);
     swapl(&pRep->length, n);
@@ -531,7 +531,7 @@ SAllocColorReply(pClient, size, pRep)
     int			size;
     xAllocColorReply	*pRep;
 {
-    register char n;
+    char n;
 
     swaps(&pRep->sequenceNumber, n);
     swaps(&pRep->red, n);
@@ -544,7 +544,7 @@ SAllocColorReply(pClient, size, pRep)
 void
 SAllocNamedColorReply(ClientPtr pClient, int size, xAllocNamedColorReply *pRep)
 {
-    register char n;
+    char n;
 
     swaps(&pRep->sequenceNumber, n);
     swapl(&pRep->pixel, n);
@@ -560,7 +560,7 @@ SAllocNamedColorReply(ClientPtr pClient,
 void
 SAllocColorCellsReply(ClientPtr pClient, int size, xAllocColorCellsReply *pRep)
 {
-    register char n;
+    char n;
 
     swaps(&pRep->sequenceNumber, n);
     swapl(&pRep->length, n);
@@ -573,7 +573,7 @@ SAllocColorCellsReply(ClientPtr pClient,
 void
 SAllocColorPlanesReply(ClientPtr pClient, int size, xAllocColorPlanesReply *pRep)
 {
-    register char n;
+    char n;
 
     swaps(&pRep->sequenceNumber, n);
     swapl(&pRep->length, n);
@@ -587,7 +587,7 @@ SAllocColorPlanesReply(ClientPtr pClient
 void
 SwapRGB(xrgb *prgb)
 {
-    register char n;
+    char n;
 
     swaps(&prgb->red, n);
     swaps(&prgb->green, n);
@@ -613,7 +613,7 @@ SQColorsExtend(ClientPtr pClient, int si
 void
 SQueryColorsReply(ClientPtr pClient, int size, xQueryColorsReply* pRep)
 {
-    register char n;
+    char n;
 
     swaps(&pRep->sequenceNumber, n);
     swapl(&pRep->length, n);
@@ -624,7 +624,7 @@ SQueryColorsReply(ClientPtr pClient, int
 void
 SLookupColorReply(ClientPtr pClient, int size, xLookupColorReply *pRep)
 {
-    register char n;
+    char n;
 
     swaps(&pRep->sequenceNumber, n);
     swaps(&pRep->exactRed, n);
@@ -639,7 +639,7 @@ SLookupColorReply(ClientPtr pClient, int
 void
 SQueryBestSizeReply(ClientPtr pClient, int size, xQueryBestSizeReply *pRep)
 {
-    register char n;
+    char n;
 
     swaps(&pRep->sequenceNumber, n);
     swaps(&pRep->width, n);
@@ -650,7 +650,7 @@ SQueryBestSizeReply(ClientPtr pClient, i
 void
 SListExtensionsReply(ClientPtr pClient, int size, xListExtensionsReply *pRep)
 {
-    register char n;
+    char n;
 
     swaps(&pRep->sequenceNumber, n);
     swapl(&pRep->length, n);
@@ -661,7 +661,7 @@ void
 SGetKeyboardMappingReply(ClientPtr pClient, int size,
                          xGetKeyboardMappingReply *pRep)
 {
-    register char n;
+    char n;
 
     swaps(&pRep->sequenceNumber, n);
     swapl(&pRep->length, n);
@@ -672,7 +672,7 @@ void
 SGetPointerMappingReply(ClientPtr pClient, int size,
                         xGetPointerMappingReply *pRep)
 {
-    register char n;
+    char n;
 
     swaps(&pRep->sequenceNumber, n);
     swapl(&pRep->length, n);
@@ -683,7 +683,7 @@ void
 SGetModifierMappingReply(ClientPtr pClient, int size,
                          xGetModifierMappingReply *pRep)
 {
-    register char n;
+    char n;
 
     swaps(&pRep->sequenceNumber, n);
     swapl(&pRep->length, n);
@@ -693,7 +693,7 @@ SGetModifierMappingReply(ClientPtr pClie
 void
 SGetKeyboardControlReply(ClientPtr pClient, int size, xGetKeyboardControlReply *pRep)
 {
-    register char n;
+    char n;
 
     swaps(&pRep->sequenceNumber, n);
     swapl(&pRep->length, n);
@@ -706,7 +706,7 @@ SGetKeyboardControlReply(ClientPtr pClie
 void
 SGetPointerControlReply(ClientPtr pClient, int size, xGetPointerControlReply *pRep)
 {
-    register char n;
+    char n;
 
     swaps(&pRep->sequenceNumber, n);
     swaps(&pRep->accelNumerator, n);
@@ -718,7 +718,7 @@ SGetPointerControlReply(ClientPtr pClien
 void
 SGetScreenSaverReply(ClientPtr pClient, int size, xGetScreenSaverReply *pRep)
 {
-    register char n;
+    char n;
 
     swaps(&pRep->sequenceNumber, n);
     swaps(&pRep->timeout, n);
@@ -734,7 +734,7 @@ SLHostsExtend(ClientPtr pClient, int siz
     while (bufT < endbuf) {
 	xHostEntry *host = (xHostEntry *) bufT;
 	int len = host->length;
-        register char n;
+        char n;
 	swaps (&host->length, n);
 	bufT += sizeof (xHostEntry) + (((len + 3) >> 2) << 2);
 	}
@@ -744,7 +744,7 @@ SLHostsExtend(ClientPtr pClient, int siz
 void
 SListHostsReply(ClientPtr pClient, int size, xListHostsReply *pRep)
 {
-    register char n;
+    char n;
 
     swaps(&pRep->sequenceNumber, n);
     swapl(&pRep->length, n);
diff --git a/dix/swapreq.c b/dix/swapreq.c
index a6a2115..ad60d17 100644
--- a/dix/swapreq.c
+++ b/dix/swapreq.c
@@ -63,9 +63,9 @@ SOFTWARE.
 
 /* Byte swap a list of longs */
 _X_EXPORT void
-SwapLongs (register CARD32 *list, register unsigned long count)
+SwapLongs (CARD32 *list, unsigned long count)
 {
-	register char n;
+	char n;
 
 	while (count >= 8) {
 	    swapl(list+0, n);
@@ -89,9 +89,9 @@ SwapLongs (register CARD32 *list, regist
 
 /* Byte swap a list of shorts */
 _X_EXPORT void
-SwapShorts (register short *list, register unsigned long count)
+SwapShorts (short *list, unsigned long count)
 {
-	register char n;
+	char n;
 
 	while (count >= 16) {
 	    swaps(list+0, n);
@@ -124,9 +124,9 @@ SwapShorts (register short *list, regist
 /* The following is used for all requests that have
    no fields to be swapped (except "length") */
 int
-SProcSimpleReq(register ClientPtr client)
+SProcSimpleReq(ClientPtr client)
 {
-    register char n;
+    char n;
 
     REQUEST(xReq);
     swaps(&stuff->length, n);
@@ -137,9 +137,9 @@ SProcSimpleReq(register ClientPtr client
    only a single 32-bit field to be swapped, coming
    right after the "length" field */
 int
-SProcResourceReq(register ClientPtr client)
+SProcResourceReq(ClientPtr client)
 {
-    register char n;
+    char n;
 
     REQUEST(xResourceReq);
     swaps(&stuff->length, n);
@@ -149,9 +149,9 @@ SProcResourceReq(register ClientPtr clie
 }
 
 int
-SProcCreateWindow(register ClientPtr client)
+SProcCreateWindow(ClientPtr client)
 {
-    register char n;
+    char n;
 
     REQUEST(xCreateWindowReq);
     swaps(&stuff->length, n);
@@ -171,9 +171,9 @@ SProcCreateWindow(register ClientPtr cli
 }
 
 int
-SProcChangeWindowAttributes(register ClientPtr client)
+SProcChangeWindowAttributes(ClientPtr client)
 {
-    register char n;
+    char n;
 
     REQUEST(xChangeWindowAttributesReq);
     swaps(&stuff->length, n);
@@ -185,9 +185,9 @@ SProcChangeWindowAttributes(register Cli
 }
 
 int
-SProcReparentWindow(register ClientPtr client)
+SProcReparentWindow(ClientPtr client)
 {
-    register char n;
+    char n;
     REQUEST(xReparentWindowReq);
     swaps(&stuff->length, n);
     REQUEST_SIZE_MATCH(xReparentWindowReq);
@@ -199,9 +199,9 @@ SProcReparentWindow(register ClientPtr c
 }
 
 int
-SProcConfigureWindow(register ClientPtr client)
+SProcConfigureWindow(ClientPtr client)
 {
-    register char n;
+    char n;
     REQUEST(xConfigureWindowReq);
     swaps(&stuff->length, n);
     REQUEST_AT_LEAST_SIZE(xConfigureWindowReq);
@@ -214,9 +214,9 @@ SProcConfigureWindow(register ClientPtr 
 
 
 int
-SProcInternAtom(register ClientPtr client)
+SProcInternAtom(ClientPtr client)
 {
-    register char n;
+    char n;
     REQUEST(xInternAtomReq);
     swaps(&stuff->length, n);
     REQUEST_AT_LEAST_SIZE(xInternAtomReq);
@@ -225,9 +225,9 @@ SProcInternAtom(register ClientPtr clien
 }
 
 int
-SProcChangeProperty(register ClientPtr client)
+SProcChangeProperty(ClientPtr client)
 {
-    register char n;
+    char n;
     REQUEST(xChangePropertyReq);
     swaps(&stuff->length, n);
     REQUEST_AT_LEAST_SIZE(xChangePropertyReq);
@@ -249,9 +249,9 @@ SProcChangeProperty(register ClientPtr c
 }
 
 int 
-SProcDeleteProperty(register ClientPtr client)
+SProcDeleteProperty(ClientPtr client)
 {
-    register char n;
+    char n;
     REQUEST(xDeletePropertyReq);
     swaps(&stuff->length, n);
     REQUEST_SIZE_MATCH(xDeletePropertyReq);
@@ -262,9 +262,9 @@ SProcDeleteProperty(register ClientPtr c
 }
 
 int 
-SProcGetProperty(register ClientPtr client)
+SProcGetProperty(ClientPtr client)
 {
-    register char n;
+    char n;
     REQUEST(xGetPropertyReq);
     swaps(&stuff->length, n);
     REQUEST_SIZE_MATCH(xGetPropertyReq);
@@ -277,9 +277,9 @@ SProcGetProperty(register ClientPtr clie
 }
 
 int
-SProcSetSelectionOwner(register ClientPtr client)
+SProcSetSelectionOwner(ClientPtr client)
 {
-    register char n;
+    char n;
     REQUEST(xSetSelectionOwnerReq);
     swaps(&stuff->length, n);
     REQUEST_SIZE_MATCH(xSetSelectionOwnerReq);
@@ -290,9 +290,9 @@ SProcSetSelectionOwner(register ClientPt
 }
 
 int
-SProcConvertSelection(register ClientPtr client)
+SProcConvertSelection(ClientPtr client)
 {
-    register char n;
+    char n;
     REQUEST(xConvertSelectionReq);
     swaps(&stuff->length, n);
     REQUEST_SIZE_MATCH(xConvertSelectionReq);
@@ -305,9 +305,9 @@ SProcConvertSelection(register ClientPtr
 }
 
 int
-SProcSendEvent(register ClientPtr client)
+SProcSendEvent(ClientPtr client)
 {
-    register char n;
+    char n;
     xEvent eventT;
     EventSwapPtr proc;
     REQUEST(xSendEventReq);
@@ -327,9 +327,9 @@ SProcSendEvent(register ClientPtr client
 }
 
 int
-SProcGrabPointer(register ClientPtr client)
+SProcGrabPointer(ClientPtr client)
 {
-    register char n;
+    char n;
     REQUEST(xGrabPointerReq);
     swaps(&stuff->length, n);
     REQUEST_SIZE_MATCH(xGrabPointerReq);
@@ -342,9 +342,9 @@ SProcGrabPointer(register ClientPtr clie
 }
 
 int
-SProcGrabButton(register ClientPtr client)
+SProcGrabButton(ClientPtr client)
 {
-    register char n;
+    char n;
     REQUEST(xGrabButtonReq);
     swaps(&stuff->length, n);
     REQUEST_SIZE_MATCH(xGrabButtonReq);
@@ -357,9 +357,9 @@ SProcGrabButton(register ClientPtr clien
 }
 
 int
-SProcUngrabButton(register ClientPtr client)
+SProcUngrabButton(ClientPtr client)
 {
-    register char n;
+    char n;
     REQUEST(xUngrabButtonReq);
     swaps(&stuff->length, n);
     REQUEST_SIZE_MATCH(xUngrabButtonReq);
@@ -369,9 +369,9 @@ SProcUngrabButton(register ClientPtr cli
 }
 
 int
-SProcChangeActivePointerGrab(register ClientPtr client)
+SProcChangeActivePointerGrab(ClientPtr client)
 {
-    register char n;
+    char n;
     REQUEST(xChangeActivePointerGrabReq);
     swaps(&stuff->length, n);
     REQUEST_SIZE_MATCH(xChangeActivePointerGrabReq);
@@ -382,9 +382,9 @@ SProcChangeActivePointerGrab(register Cl
 }
 
 int
-SProcGrabKeyboard(register ClientPtr client)
+SProcGrabKeyboard(ClientPtr client)
 {
-    register char n;
+    char n;
     REQUEST(xGrabKeyboardReq);
     swaps(&stuff->length, n);
     REQUEST_SIZE_MATCH(xGrabKeyboardReq);
@@ -394,9 +394,9 @@ SProcGrabKeyboard(register ClientPtr cli
 }
 
 int
-SProcGrabKey(register ClientPtr client)
+SProcGrabKey(ClientPtr client)
 {
-    register char n;
+    char n;
     REQUEST(xGrabKeyReq);
     swaps(&stuff->length, n);
     REQUEST_SIZE_MATCH(xGrabKeyReq);
@@ -406,9 +406,9 @@ SProcGrabKey(register ClientPtr client)
 }
 
 int
-SProcUngrabKey(register ClientPtr client)
+SProcUngrabKey(ClientPtr client)
 {
-    register char n;
+    char n;
     REQUEST(xUngrabKeyReq);
     swaps(&stuff->length, n);
     REQUEST_SIZE_MATCH(xUngrabKeyReq);
@@ -418,9 +418,9 @@ SProcUngrabKey(register ClientPtr client
 }
 
 int
-SProcGetMotionEvents(register ClientPtr client)
+SProcGetMotionEvents(ClientPtr client)
 {
-    register char n;
+    char n;
     REQUEST(xGetMotionEventsReq);
     swaps(&stuff->length, n);
     REQUEST_SIZE_MATCH(xGetMotionEventsReq);
@@ -431,9 +431,9 @@ SProcGetMotionEvents(register ClientPtr 
 }
 
 int
-SProcTranslateCoords(register ClientPtr client)
+SProcTranslateCoords(ClientPtr client)
 {
-    register char n;
+    char n;
     REQUEST(xTranslateCoordsReq);
     swaps(&stuff->length, n);
     REQUEST_SIZE_MATCH(xTranslateCoordsReq);
@@ -445,9 +445,9 @@ SProcTranslateCoords(register ClientPtr 
 }
 
 int
-SProcWarpPointer(register ClientPtr client)
+SProcWarpPointer(ClientPtr client)
 {
-    register char n;
+    char n;
     REQUEST(xWarpPointerReq);
     swaps(&stuff->length, n);
     REQUEST_SIZE_MATCH(xWarpPointerReq);
@@ -463,9 +463,9 @@ SProcWarpPointer(register ClientPtr clie
 }
 
 int
-SProcSetInputFocus(register ClientPtr client)
+SProcSetInputFocus(ClientPtr client)
 {
-    register char n;
+    char n;
     REQUEST(xSetInputFocusReq);
     swaps(&stuff->length, n);
     REQUEST_SIZE_MATCH(xSetInputFocusReq);
@@ -475,9 +475,9 @@ SProcSetInputFocus(register ClientPtr cl
 }
 
 int
-SProcOpenFont(register ClientPtr client)
+SProcOpenFont(ClientPtr client)
 {
-    register char n;
+    char n;
     REQUEST(xOpenFontReq);
     swaps(&stuff->length, n);
     REQUEST_AT_LEAST_SIZE(xOpenFontReq);
@@ -487,9 +487,9 @@ SProcOpenFont(register ClientPtr client)
 }
 
 int
-SProcListFonts(register ClientPtr client)
+SProcListFonts(ClientPtr client)
 {
-    register char n;
+    char n;
     REQUEST(xListFontsReq);
     swaps(&stuff->length, n);
     REQUEST_AT_LEAST_SIZE(xListFontsReq);
@@ -499,9 +499,9 @@ SProcListFonts(register ClientPtr client
 }
 
 int
-SProcListFontsWithInfo(register ClientPtr client)
+SProcListFontsWithInfo(ClientPtr client)
 {
-    register char n;
+    char n;
     REQUEST(xListFontsWithInfoReq);
     swaps(&stuff->length, n);
     REQUEST_AT_LEAST_SIZE(xListFontsWithInfoReq);
@@ -511,9 +511,9 @@ SProcListFontsWithInfo(register ClientPt
 }
 
 int
-SProcSetFontPath(register ClientPtr client)
+SProcSetFontPath(ClientPtr client)
 {
-    register char n;
+    char n;
     REQUEST(xSetFontPathReq);
     swaps(&stuff->length, n);
     REQUEST_AT_LEAST_SIZE(xSetFontPathReq);
@@ -522,9 +522,9 @@ SProcSetFontPath(register ClientPtr clie
 }
 
 int
-SProcCreatePixmap(register ClientPtr client)
+SProcCreatePixmap(ClientPtr client)
 {
-    register char n;
+    char n;
     REQUEST(xCreatePixmapReq);
 
     swaps(&stuff->length, n);
@@ -537,9 +537,9 @@ SProcCreatePixmap(register ClientPtr cli
 }
 
 int
-SProcCreateGC(register ClientPtr client)
+SProcCreateGC(ClientPtr client)
 {
-    register char n;
+    char n;
     REQUEST(xCreateGCReq);
     swaps(&stuff->length, n);
     REQUEST_AT_LEAST_SIZE(xCreateGCReq);
@@ -551,9 +551,9 @@ SProcCreateGC(register ClientPtr client)
 }
 
 int
-SProcChangeGC(register ClientPtr client)
+SProcChangeGC(ClientPtr client)
 {
-    register char n;
+    char n;
     REQUEST(xChangeGCReq);
     swaps(&stuff->length, n);
     REQUEST_AT_LEAST_SIZE(xChangeGCReq);
@@ -564,9 +564,9 @@ SProcChangeGC(register ClientPtr client)
 }
 
 int
-SProcCopyGC(register ClientPtr client)
+SProcCopyGC(ClientPtr client)
 {
-    register char n;
+    char n;
     REQUEST(xCopyGCReq);
     swaps(&stuff->length, n);
     REQUEST_SIZE_MATCH(xCopyGCReq);
@@ -577,9 +577,9 @@ SProcCopyGC(register ClientPtr client)
 }
 
 int
-SProcSetDashes(register ClientPtr client)
+SProcSetDashes(ClientPtr client)
 {
-    register char n;
+    char n;
     REQUEST(xSetDashesReq);
     swaps(&stuff->length, n);
     REQUEST_AT_LEAST_SIZE(xSetDashesReq);
@@ -591,9 +591,9 @@ SProcSetDashes(register ClientPtr client
 }
 
 int
-SProcSetClipRectangles(register ClientPtr client)
+SProcSetClipRectangles(ClientPtr client)
 {
-    register char n;
+    char n;
     REQUEST(xSetClipRectanglesReq);
     swaps(&stuff->length, n);
     REQUEST_AT_LEAST_SIZE(xSetClipRectanglesReq);
@@ -605,9 +605,9 @@ SProcSetClipRectangles(register ClientPt
 }
 
 int
-SProcClearToBackground(register ClientPtr client)
+SProcClearToBackground(ClientPtr client)
 {
-    register char n;
+    char n;
     REQUEST(xClearAreaReq);
     swaps(&stuff->length, n);
     REQUEST_SIZE_MATCH(xClearAreaReq);
@@ -620,9 +620,9 @@ SProcClearToBackground(register ClientPt
 }
 
 int
-SProcCopyArea(register ClientPtr client)
+SProcCopyArea(ClientPtr client)
 {
-    register char n;
+    char n;
     REQUEST(xCopyAreaReq);
     swaps(&stuff->length, n);
     REQUEST_SIZE_MATCH(xCopyAreaReq);
@@ -639,9 +639,9 @@ SProcCopyArea(register ClientPtr client)
 }
 
 int
-SProcCopyPlane(register ClientPtr client)
+SProcCopyPlane(ClientPtr client)
 {
-    register char n;
+    char n;
     REQUEST(xCopyPlaneReq);
     swaps(&stuff->length, n);
     REQUEST_SIZE_MATCH(xCopyPlaneReq);
@@ -661,9 +661,9 @@ SProcCopyPlane(register ClientPtr client
 /* The following routine is used for all Poly drawing requests
    (except FillPoly, which uses a different request format) */
 int
-SProcPoly(register ClientPtr client)
+SProcPoly(ClientPtr client)
 {
-    register char n;
+    char n;
 
     REQUEST(xPolyPointReq);
     swaps(&stuff->length, n);
@@ -678,9 +678,9 @@ SProcPoly(register ClientPtr client)
    is longer than xPolyPointReq, and we don't want to swap
    the difference as shorts! */
 int
-SProcFillPoly(register ClientPtr client)
+SProcFillPoly(ClientPtr client)
 {
-    register char n;
+    char n;
 
     REQUEST(xFillPolyReq);
     swaps(&stuff->length, n);
@@ -692,9 +692,9 @@ SProcFillPoly(register ClientPtr client)
 }
 
 int
-SProcPutImage(register ClientPtr client)
+SProcPutImage(ClientPtr client)
 {
-    register char n;
+    char n;
     REQUEST(xPutImageReq);
     swaps(&stuff->length, n);
     REQUEST_AT_LEAST_SIZE(xPutImageReq);
@@ -710,9 +710,9 @@ SProcPutImage(register ClientPtr client)
 }
 
 int
-SProcGetImage(register ClientPtr client)
+SProcGetImage(ClientPtr client)
 {
-    register char n;
+    char n;
     REQUEST(xGetImageReq);
     swaps(&stuff->length, n);
     REQUEST_SIZE_MATCH(xGetImageReq);
@@ -728,9 +728,9 @@ SProcGetImage(register ClientPtr client)
 /* ProcPolyText used for both PolyText8 and PolyText16 */
 
 int
-SProcPolyText(register ClientPtr client)
+SProcPolyText(ClientPtr client)
 {
-    register char n;
+    char n;
     REQUEST(xPolyTextReq);
     swaps(&stuff->length, n);
     REQUEST_AT_LEAST_SIZE(xPolyTextReq);
@@ -744,9 +744,9 @@ SProcPolyText(register ClientPtr client)
 /* ProcImageText used for both ImageText8 and ImageText16 */
 
 int
-SProcImageText(register ClientPtr client)
+SProcImageText(ClientPtr client)
 {
-    register char n;
+    char n;
     REQUEST(xImageTextReq);
     swaps(&stuff->length, n);
     REQUEST_AT_LEAST_SIZE(xImageTextReq);
@@ -758,9 +758,9 @@ SProcImageText(register ClientPtr client
 }
 
 int
-SProcCreateColormap(register ClientPtr client)
+SProcCreateColormap(ClientPtr client)
 {
-    register char n;
+    char n;
     REQUEST(xCreateColormapReq);
     swaps(&stuff->length, n);
     REQUEST_SIZE_MATCH(xCreateColormapReq);
@@ -772,9 +772,9 @@ SProcCreateColormap(register ClientPtr c
 
 
 int
-SProcCopyColormapAndFree(register ClientPtr client)
+SProcCopyColormapAndFree(ClientPtr client)
 {
-    register char n;
+    char n;
     REQUEST(xCopyColormapAndFreeReq);
     swaps(&stuff->length, n);
     REQUEST_SIZE_MATCH(xCopyColormapAndFreeReq);
@@ -785,9 +785,9 @@ SProcCopyColormapAndFree(register Client
 }
 
 int
-SProcAllocColor(register ClientPtr client)
+SProcAllocColor(ClientPtr client)
 {
-    register char n;
+    char n;
     REQUEST(xAllocColorReq);
     swaps(&stuff->length, n);
     REQUEST_SIZE_MATCH(xAllocColorReq);
@@ -799,9 +799,9 @@ SProcAllocColor(register ClientPtr clien
 }
 
 int
-SProcAllocNamedColor(register ClientPtr client)
+SProcAllocNamedColor(ClientPtr client)
 {
-    register char n;
+    char n;
 
     REQUEST(xAllocNamedColorReq);
     swaps(&stuff->length, n);
@@ -812,9 +812,9 @@ SProcAllocNamedColor(register ClientPtr 
 }
 
 int
-SProcAllocColorCells(register ClientPtr client)
+SProcAllocColorCells(ClientPtr client)
 {
-    register char n;
+    char n;
     REQUEST(xAllocColorCellsReq);
     swaps(&stuff->length, n);
     REQUEST_SIZE_MATCH(xAllocColorCellsReq);
@@ -825,9 +825,9 @@ SProcAllocColorCells(register ClientPtr 
 }
 
 int
-SProcAllocColorPlanes(register ClientPtr client)
+SProcAllocColorPlanes(ClientPtr client)
 {
-    register char n;
+    char n;
     REQUEST(xAllocColorPlanesReq);
     swaps(&stuff->length, n);
     REQUEST_SIZE_MATCH(xAllocColorPlanesReq);
@@ -840,9 +840,9 @@ SProcAllocColorPlanes(register ClientPtr
 }
 
 int
-SProcFreeColors(register ClientPtr client)
+SProcFreeColors(ClientPtr client)
 {
-    register char n;
+    char n;
     REQUEST(xFreeColorsReq);
     swaps(&stuff->length, n);
     REQUEST_AT_LEAST_SIZE(xFreeColorsReq);
@@ -856,7 +856,7 @@ SProcFreeColors(register ClientPtr clien
 _X_EXPORT void
 SwapColorItem(xColorItem *pItem)
 {
-    register char n;
+    char n;
 
     swapl(&pItem->pixel, n);
     swaps(&pItem->red, n);
@@ -865,9 +865,9 @@ SwapColorItem(xColorItem *pItem)
 }
 
 int
-SProcStoreColors(register ClientPtr client)
+SProcStoreColors(ClientPtr client)
 {
-    register char n;
+    char n;
     long count;
     xColorItem 	*pItem;
 
@@ -882,9 +882,9 @@ SProcStoreColors(register ClientPtr clie
 }
 
 int
-SProcStoreNamedColor (register ClientPtr client)
+SProcStoreNamedColor (ClientPtr client)
 {
-    register char n;
+    char n;
     REQUEST(xStoreNamedColorReq);
     swaps(&stuff->length, n);
     REQUEST_AT_LEAST_SIZE(xStoreNamedColorReq);
@@ -895,9 +895,9 @@ SProcStoreNamedColor (register ClientPtr
 }
 
 int
-SProcQueryColors (register ClientPtr client)
+SProcQueryColors (ClientPtr client)
 {
-    register char n;
+    char n;
     REQUEST(xQueryColorsReq);
     swaps(&stuff->length, n);
     REQUEST_AT_LEAST_SIZE(xQueryColorsReq);
@@ -907,9 +907,9 @@ SProcQueryColors (register ClientPtr cli
 } 
 
 int
-SProcLookupColor (register ClientPtr client)
+SProcLookupColor (ClientPtr client)
 {
-    register char n;
+    char n;
     REQUEST(xLookupColorReq);
     swaps(&stuff->length, n);
     REQUEST_AT_LEAST_SIZE(xLookupColorReq);
@@ -919,9 +919,9 @@ SProcLookupColor (register ClientPtr cli
 }
 
 int
-SProcCreateCursor (register ClientPtr client)
+SProcCreateCursor (ClientPtr client)
 {
-    register char n;
+    char n;
     REQUEST(xCreateCursorReq);
     swaps(&stuff->length, n);
     REQUEST_SIZE_MATCH(xCreateCursorReq);
@@ -940,9 +940,9 @@ SProcCreateCursor (register ClientPtr cl
 }
 
 int
-SProcCreateGlyphCursor (register ClientPtr client)
+SProcCreateGlyphCursor (ClientPtr client)
 {
-    register char n;
+    char n;
     REQUEST(xCreateGlyphCursorReq);
     swaps(&stuff->length, n);
     REQUEST_SIZE_MATCH(xCreateGlyphCursorReq);
@@ -962,9 +962,9 @@ SProcCreateGlyphCursor (register ClientP
 
 
 int
-SProcRecolorCursor (register ClientPtr client)
+SProcRecolorCursor (ClientPtr client)
 {
-    register char n;
+    char n;
     REQUEST(xRecolorCursorReq);
     swaps(&stuff->length, n);
     REQUEST_SIZE_MATCH(xRecolorCursorReq);
@@ -979,9 +979,9 @@ SProcRecolorCursor (register ClientPtr c
 }
 
 int
-SProcQueryBestSize (register ClientPtr client)
+SProcQueryBestSize (ClientPtr client)
 {
-    register char n;
+    char n;
     REQUEST(xQueryBestSizeReq);
     swaps(&stuff->length, n);
     REQUEST_SIZE_MATCH(xQueryBestSizeReq);
@@ -993,9 +993,9 @@ SProcQueryBestSize (register ClientPtr c
 }
 
 int
-SProcQueryExtension (register ClientPtr client)
+SProcQueryExtension (ClientPtr client)
 {
-    register char n;
+    char n;
     REQUEST(xQueryExtensionReq);
     swaps(&stuff->length, n);
     REQUEST_AT_LEAST_SIZE(xQueryExtensionReq);
@@ -1004,9 +1004,9 @@ SProcQueryExtension (register ClientPtr 
 }
 
 int
-SProcChangeKeyboardMapping (register ClientPtr client)
+SProcChangeKeyboardMapping (ClientPtr client)
 {
-    register char n;
+    char n;
     REQUEST(xChangeKeyboardMappingReq);
     swaps(&stuff->length, n);
     REQUEST_AT_LEAST_SIZE(xChangeKeyboardMappingReq);
@@ -1016,9 +1016,9 @@ SProcChangeKeyboardMapping (register Cli
 
 
 int
-SProcChangeKeyboardControl (register ClientPtr client)
+SProcChangeKeyboardControl (ClientPtr client)
 {
-    register char n;
+    char n;
     REQUEST(xChangeKeyboardControlReq);
     swaps(&stuff->length, n);
     REQUEST_AT_LEAST_SIZE(xChangeKeyboardControlReq);
@@ -1028,9 +1028,9 @@ SProcChangeKeyboardControl (register Cli
 }
 
 int
-SProcChangePointerControl (register ClientPtr client)
+SProcChangePointerControl (ClientPtr client)
 {
-    register char n;
+    char n;
     REQUEST(xChangePointerControlReq);
     swaps(&stuff->length, n);
     REQUEST_SIZE_MATCH(xChangePointerControlReq);
@@ -1042,9 +1042,9 @@ SProcChangePointerControl (register Clie
 
 
 int
-SProcSetScreenSaver (register ClientPtr client)
+SProcSetScreenSaver (ClientPtr client)
 {
-    register char n;
+    char n;
     REQUEST(xSetScreenSaverReq);
     swaps(&stuff->length, n);
     REQUEST_SIZE_MATCH(xSetScreenSaverReq);
@@ -1054,9 +1054,9 @@ SProcSetScreenSaver (register ClientPtr 
 }
 
 int
-SProcChangeHosts (register ClientPtr client)
+SProcChangeHosts (ClientPtr client)
 {
-    register char n;
+    char n;
 
     REQUEST(xChangeHostsReq);
     swaps(&stuff->length, n);
@@ -1066,9 +1066,9 @@ SProcChangeHosts (register ClientPtr cli
 
 }
 
-int SProcRotateProperties (register ClientPtr client)
+int SProcRotateProperties (ClientPtr client)
 {
-    register char n;
+    char n;
     REQUEST(xRotatePropertiesReq);
     swaps(&stuff->length, n);
     REQUEST_AT_LEAST_SIZE(xRotatePropertiesReq);
@@ -1080,9 +1080,9 @@ int SProcRotateProperties (register Clie
 }
 
 int
-SProcNoOperation(register ClientPtr client)
+SProcNoOperation(ClientPtr client)
 {
-    register char n;
+    char n;
     REQUEST(xReq);
     swaps(&stuff->length, n);
     return ((* ProcVector[X_NoOperation])(client));
@@ -1091,7 +1091,7 @@ SProcNoOperation(register ClientPtr clie
 void
 SwapConnClientPrefix(xConnClientPrefix *pCCP)
 {
-    register char n;
+    char n;
 
     swaps(&pCCP->majorVersion, n);
     swaps(&pCCP->minorVersion, n);
diff --git a/dix/window.c b/dix/window.c
index e33140d..2a82f2e 100644
--- a/dix/window.c
+++ b/dix/window.c
@@ -220,10 +220,10 @@ PrintWindowTree(void)
 #endif
 
 _X_EXPORT int
-TraverseTree(register WindowPtr pWin, VisitWindowProcPtr func, pointer data)
+TraverseTree(WindowPtr pWin, VisitWindowProcPtr func, pointer data)
 {
-    register int result;
-    register WindowPtr pChild;
+    int result;
+    WindowPtr pChild;
 
     if (!(pChild = pWin))
        return(WT_NOMATCH);
@@ -269,7 +269,7 @@ Bool	enableBackingStore = FALSE;
 Bool	disableSaveUnders = FALSE;
 
 static void
-SetWindowToDefaults(register WindowPtr pWin)
+SetWindowToDefaults(WindowPtr pWin)
 {
     pWin->prevSib = NullWindow;
     pWin->firstChild = NullWindow;
@@ -313,8 +313,8 @@ MakeRootTile(WindowPtr pWin)
     GCPtr pGC;
     unsigned char back[128];
     int len = BitmapBytePad(sizeof(long));
-    register unsigned char *from, *to;
-    register int i, j;
+    unsigned char *from, *to;
+    int i, j;
 
     pWin->background.pixmap = (*pScreen->CreatePixmap)(pScreen, 4, 4,
 						    pScreen->rootDepth);
@@ -353,11 +353,11 @@ WindowPtr
 AllocateWindow(ScreenPtr pScreen)
 {
     WindowPtr pWin;
-    register char *ptr;
-    register DevUnion *ppriv;
-    register unsigned *sizes;
-    register unsigned size;
-    register int i;
+    char *ptr;
+    DevUnion *ppriv;
+    unsigned *sizes;
+    unsigned size;
+    int i;
 
     pWin = (WindowPtr)xalloc(pScreen->totalWindowSize);
     if (pWin)
@@ -540,9 +540,9 @@ InitRootWindow(WindowPtr pWin)
  */
 
 void
-ClippedRegionFromBox(register WindowPtr pWin, RegionPtr Rgn,
-                     register int x, register int y,
-                     register int w, register int h)
+ClippedRegionFromBox(WindowPtr pWin, RegionPtr Rgn,
+                     int x, int y,
+                     int w, int h)
 {
     ScreenPtr pScreen;
     BoxRec box;
@@ -579,7 +579,7 @@ RegisterRealChildHeadProc (RealChildHead
 
 
 WindowPtr
-RealChildHead(register WindowPtr pWin)
+RealChildHead(WindowPtr pWin)
 {
     if (realChildHeadProc) {
 	return realChildHeadProc (pWin);
@@ -599,19 +599,19 @@ RealChildHead(register WindowPtr pWin)
  *****/
 
 _X_EXPORT WindowPtr
-CreateWindow(Window wid, register WindowPtr pParent, int x, int y, unsigned w,
-             unsigned h, unsigned bw, unsigned class, register Mask vmask, XID *vlist,
+CreateWindow(Window wid, WindowPtr pParent, int x, int y, unsigned w,
+             unsigned h, unsigned bw, unsigned class, Mask vmask, XID *vlist,
              int depth, ClientPtr client, VisualID visual, int *error)
 {
-    register WindowPtr pWin;
+    WindowPtr pWin;
     WindowPtr pHead;
-    register ScreenPtr pScreen;
+    ScreenPtr pScreen;
     xEvent event;
     int idepth, ivisual;
     Bool fOK;
     DepthPtr pDepth;
     PixmapFormatRec *format;
-    register WindowOptPtr ancwopt;
+    WindowOptPtr ancwopt;
 
     if (class == CopyFromParent)
 	class = pParent->drawable.class;
@@ -836,9 +836,9 @@ CreateWindow(Window wid, register Window
 }
 
 static void
-FreeWindowResources(register WindowPtr pWin)
+FreeWindowResources(WindowPtr pWin)
 {
-    register ScreenPtr pScreen = pWin->drawable.pScreen;
+    ScreenPtr pScreen = pWin->drawable.pScreen;
 
     DeleteWindowFromAnySaveSet(pWin);
     DeleteWindowFromAnySelections(pWin);
@@ -869,7 +869,7 @@ FreeWindowResources(register WindowPtr p
 static void
 CrushTree(WindowPtr pWin)
 {
-    register WindowPtr pChild, pSib, pParent;
+    WindowPtr pChild, pSib, pParent;
     UnrealizeWindowProcPtr UnrealizeWindow;
     xEvent event;
 
@@ -926,8 +926,8 @@ CrushTree(WindowPtr pWin)
 int
 DeleteWindow(pointer value, XID wid)
  {
-    register WindowPtr pParent;
-    register WindowPtr pWin = (WindowPtr)value;
+    WindowPtr pParent;
+    WindowPtr pWin = (WindowPtr)value;
     xEvent event;
 
     UnmapWindow(pWin, FALSE);
@@ -959,7 +959,7 @@ DeleteWindow(pointer value, XID wid)
 }
 
 void
-DestroySubwindows(register WindowPtr pWin, ClientPtr client)
+DestroySubwindows(WindowPtr pWin, ClientPtr client)
 {
     /* XXX
      * The protocol is quite clear that each window should be
@@ -986,10 +986,10 @@ DestroySubwindows(register WindowPtr pWi
  *****/
  
 _X_EXPORT int
-ChangeWindowAttributes(register WindowPtr pWin, Mask vmask, XID *vlist, ClientPtr client)
+ChangeWindowAttributes(WindowPtr pWin, Mask vmask, XID *vlist, ClientPtr client)
 {
-    register Mask index2;
-    register XID *pVlist;
+    Mask index2;
+    XID *pVlist;
     PixmapPtr pPixmap;
     Pixmap pixID;
     CursorPtr pCursor, pOldCursor;
@@ -999,9 +999,9 @@ ChangeWindowAttributes(register WindowPt
     ColormapPtr	pCmap;
     xEvent xE;
     int result;
-    register ScreenPtr pScreen;
+    ScreenPtr pScreen;
     Mask vmaskCopy = 0;
-    register Mask tmask;
+    Mask tmask;
     unsigned int val;
     int error;
     Bool checkOptional = FALSE;
@@ -1520,7 +1520,7 @@ PatchUp:
  *****/
 
 void
-GetWindowAttributes(register WindowPtr pWin, ClientPtr client, xGetWindowAttributesReply *wa)
+GetWindowAttributes(WindowPtr pWin, ClientPtr client, xGetWindowAttributesReply *wa)
 {
     wa->type = X_Reply;
     wa->bitGravity = pWin->bitGravity;
@@ -1556,9 +1556,9 @@ GetWindowAttributes(register WindowPtr p
 
 
 _X_EXPORT WindowPtr
-MoveWindowInStack(register WindowPtr pWin, register WindowPtr pNextSib)
+MoveWindowInStack(WindowPtr pWin, WindowPtr pNextSib)
 {
-    register WindowPtr pParent = pWin->parent;
+    WindowPtr pParent = pWin->parent;
     WindowPtr pFirstChange = pWin; /* highest window where list changes */
 
     if (pWin->nextSib != pNextSib)
@@ -1640,7 +1640,7 @@ MoveWindowInStack(register WindowPtr pWi
 }
 
 _X_EXPORT RegionPtr
-CreateUnclippedWinSize (register WindowPtr pWin)
+CreateUnclippedWinSize (WindowPtr pWin)
 {
     RegionPtr	pRgn;
     BoxRec	box;
@@ -1668,7 +1668,7 @@ CreateUnclippedWinSize (register WindowP
 }
 
 _X_EXPORT void
-SetWinSize (register WindowPtr pWin)
+SetWinSize (WindowPtr pWin)
 {
 #ifdef COMPOSITE
     if (pWin->redirectDraw)
@@ -1707,7 +1707,7 @@ SetWinSize (register WindowPtr pWin)
 }
 
 _X_EXPORT void
-SetBorderSize (register WindowPtr pWin)
+SetBorderSize (WindowPtr pWin)
 {
     int	bw;
 
@@ -1759,9 +1759,9 @@ SetBorderSize (register WindowPtr pWin)
  */
 
 _X_EXPORT void
-GravityTranslate (register int x, register int y, int oldx, int oldy,
+GravityTranslate (int x, int y, int oldx, int oldy,
                   int dw, int dh, unsigned gravity,
-                  register int *destx, register int *desty)
+                  int *destx, int *desty)
 {
     switch (gravity) {
     case NorthGravity:
@@ -1809,10 +1809,10 @@ GravityTranslate (register int x, regist
 
 /* XXX need to retile border on each window with ParentRelative origin */
 _X_EXPORT void
-ResizeChildrenWinSize(register WindowPtr pWin, int dx, int dy, int dw, int dh)
+ResizeChildrenWinSize(WindowPtr pWin, int dx, int dy, int dw, int dh)
 {
-    register ScreenPtr pScreen;
-    register WindowPtr pSib, pChild;
+    ScreenPtr pScreen;
+    WindowPtr pSib, pChild;
     Bool resized = (dw || dh);
 
     pScreen = pWin->drawable.pScreen;
@@ -1904,10 +1904,10 @@ ResizeChildrenWinSize(register WindowPtr
 
 static int
 IsSiblingAboveMe(
-    register WindowPtr pMe,
-    register WindowPtr pSib)
+    WindowPtr pMe,
+    WindowPtr pSib)
 {
-    register WindowPtr pWin;
+    WindowPtr pWin;
 
     pWin = pMe->parent->firstChild;
     while (pWin)
@@ -1923,8 +1923,8 @@ IsSiblingAboveMe(
 
 static BoxPtr
 WindowExtents(
-    register WindowPtr pWin,
-    register BoxPtr pBox)
+    WindowPtr pWin,
+    BoxPtr pBox)
 {
     pBox->x1 = pWin->drawable.x - wBorderWidth (pWin);
     pBox->y1 = pWin->drawable.y - wBorderWidth (pWin);
@@ -1940,7 +1940,7 @@ WindowExtents(
 
 static RegionPtr
 MakeBoundingRegion (
-    register WindowPtr	pWin,
+    WindowPtr	pWin,
     BoxPtr	pBox)
 {
     RegionPtr	pRgn;
@@ -1966,7 +1966,7 @@ ShapeOverlap (
     BoxPtr	pSibBox)
 {
     RegionPtr	pWinRgn, pSibRgn;
-    register ScreenPtr	pScreen;
+    ScreenPtr	pScreen;
     Bool	ret;
 
     if (!IS_SHAPED(pWin) && !IS_SHAPED(pSib))
@@ -1986,11 +1986,11 @@ static Bool
 AnyWindowOverlapsMe(
     WindowPtr pWin,
     WindowPtr pHead,
-    register BoxPtr box)
+    BoxPtr box)
 {
-    register WindowPtr pSib;
+    WindowPtr pSib;
     BoxRec sboxrec;
-    register BoxPtr sbox;
+    BoxPtr sbox;
 
     for (pSib = pWin->prevSib; pSib != pHead; pSib = pSib->prevSib)
     {
@@ -2011,11 +2011,11 @@ AnyWindowOverlapsMe(
 static Bool
 IOverlapAnyWindow(
     WindowPtr pWin,
-    register BoxPtr box)
+    BoxPtr box)
 {
-    register WindowPtr pSib;
+    WindowPtr pSib;
     BoxRec sboxrec;
-    register BoxPtr sbox;
+    BoxPtr sbox;
 
     for (pSib = pWin->nextSib; pSib; pSib = pSib->nextSib)
     {
@@ -2063,8 +2063,8 @@ IOverlapAnyWindow(
 
 static WindowPtr
 WhereDoIGoInTheStack(
-    register WindowPtr pWin,
-    register WindowPtr pSib,
+    WindowPtr pWin,
+    WindowPtr pSib,
     short x,
     short y,
     unsigned short w,
@@ -2072,7 +2072,7 @@ WhereDoIGoInTheStack(
     int smode)
 {
     BoxRec box;
-    register ScreenPtr pScreen;
+    ScreenPtr pScreen;
     WindowPtr pHead, pFirst;
 
     if ((pWin == pWin->parent->firstChild) &&
@@ -2169,8 +2169,8 @@ WhereDoIGoInTheStack(
 
 static void
 ReflectStackChange(
-    register WindowPtr pWin,
-    register WindowPtr pSib,
+    WindowPtr pWin,
+    WindowPtr pSib,
     VTKind  kind)
 {
 /* Note that pSib might be NULL */
@@ -2222,17 +2222,17 @@ ReflectStackChange(
  *****/
 
 int
-ConfigureWindow(register WindowPtr pWin, register Mask mask, XID *vlist, ClientPtr client)
+ConfigureWindow(WindowPtr pWin, Mask mask, XID *vlist, ClientPtr client)
 {
 #define RESTACK_WIN    0
 #define MOVE_WIN       1
 #define RESIZE_WIN     2
 #define REBORDER_WIN   3
-    register WindowPtr pSib = NullWindow;
-    register WindowPtr pParent = pWin->parent;
+    WindowPtr pSib = NullWindow;
+    WindowPtr pParent = pWin->parent;
     Window sibwid = 0;
     Mask index2, tmask;
-    register XID *pVlist;
+    XID *pVlist;
     short x,   y, beforeX, beforeY;
     unsigned short w = pWin->drawable.width,
 		   h = pWin->drawable.height,
@@ -2509,7 +2509,7 @@ ActuallyDoSomething:
 int
 CirculateWindow(WindowPtr pParent, int direction, ClientPtr client)
 {
-    register WindowPtr pWin, pHead, pFirst;
+    WindowPtr pWin, pHead, pFirst;
     xEvent event;
     BoxRec box;
 
@@ -2579,14 +2579,14 @@ CompareWIDs(
  *****/
 
 int
-ReparentWindow(register WindowPtr pWin, register WindowPtr pParent,
+ReparentWindow(WindowPtr pWin, WindowPtr pParent,
                int x, int y, ClientPtr client)
 {
     WindowPtr pPrev, pPriorParent;
     Bool WasMapped = (Bool)(pWin->mapped);
     xEvent event;
     int bw = wBorderWidth (pWin);
-    register ScreenPtr pScreen;
+    ScreenPtr pScreen;
 
     pScreen = pWin->drawable.pScreen;
     if (TraverseTree(pWin, CompareWIDs, (pointer)&pParent->drawable.id) == WT_STOPWALKING)
@@ -2673,7 +2673,7 @@ ReparentWindow(register WindowPtr pWin, 
 static void
 RealizeTree(WindowPtr pWin)
 {
-    register WindowPtr pChild;
+    WindowPtr pChild;
     RealizeWindowProcPtr Realize;
 
     Realize = pWin->drawable.pScreen->RealizeWindow;
@@ -2712,11 +2712,11 @@ RealizeTree(WindowPtr pWin)
  *****/
 
 _X_EXPORT int
-MapWindow(register WindowPtr pWin, ClientPtr client)
+MapWindow(WindowPtr pWin, ClientPtr client)
 {
-    register ScreenPtr pScreen;
+    ScreenPtr pScreen;
 
-    register WindowPtr pParent;
+    WindowPtr pParent;
 #ifdef DO_SAVE_UNDERS
     Bool	dosave = FALSE;
 #endif
@@ -2832,18 +2832,18 @@ MapWindow(register WindowPtr pWin, Clien
  *****/
 
 void
-MapSubwindows(register WindowPtr pParent, ClientPtr client)
+MapSubwindows(WindowPtr pParent, ClientPtr client)
 {
-    register WindowPtr	pWin;
-    WindowPtr		pFirstMapped = NullWindow;
+    WindowPtr	pWin;
+    WindowPtr	pFirstMapped = NullWindow;
 #ifdef DO_SAVE_UNDERS
-    WindowPtr		pFirstSaveUndered = NullWindow;
+    WindowPtr	pFirstSaveUndered = NullWindow;
 #endif
-    register ScreenPtr	pScreen;
-    register Mask	parentRedirect;
-    register Mask	parentNotify;
-    xEvent		event;
-    Bool		anyMarked;
+    ScreenPtr	pScreen;
+    Mask	parentRedirect;
+    Mask	parentNotify;
+    xEvent	event;
+    Bool	anyMarked;
 #ifdef DO_SAVE_UNDERS
     Bool	dosave = FALSE;
 #endif
@@ -2952,7 +2952,7 @@ UnrealizeTree(
     WindowPtr pWin,
     Bool fromConfigure)
 {
-    register WindowPtr pChild;
+    WindowPtr pChild;
     UnrealizeWindowProcPtr Unrealize;
     MarkUnrealizedWindowProcPtr MarkUnrealizedWindow;
 
@@ -3011,9 +3011,9 @@ UnrealizeTree(
  *****/
 
 _X_EXPORT int
-UnmapWindow(register WindowPtr pWin, Bool fromConfigure)
+UnmapWindow(WindowPtr pWin, Bool fromConfigure)
 {
-    register WindowPtr pParent;
+    WindowPtr pParent;
     xEvent event;
     Bool wasRealized = (Bool)pWin->realized;
     Bool wasViewable = (Bool)pWin->viewable;
@@ -3070,9 +3070,9 @@ UnmapWindow(register WindowPtr pWin, Boo
  *****/
 
 void
-UnmapSubwindows(register WindowPtr pWin)
+UnmapSubwindows(WindowPtr pWin)
 {
-    register WindowPtr pChild, pHead;
+    WindowPtr pChild, pHead;
     xEvent event;
     Bool wasRealized = (Bool)pWin->realized;
     Bool wasViewable = (Bool)pWin->viewable;
@@ -3161,10 +3161,10 @@ UnmapSubwindows(register WindowPtr pWin)
 
 
 void
-HandleSaveSet(register ClientPtr client)
+HandleSaveSet(ClientPtr client)
 {
-    register WindowPtr pParent, pWin;
-    register int j;
+    WindowPtr pParent, pWin;
+    int j;
 
     for (j=0; j<client->numSaved; j++)
     {
@@ -3207,7 +3207,7 @@ HandleSaveSet(register ClientPtr client)
  *  \param box  "return" value
  */
 Bool
-VisibleBoundingBoxFromPoint(register WindowPtr pWin, int x, int y, BoxPtr box)
+VisibleBoundingBoxFromPoint(WindowPtr pWin, int x, int y, BoxPtr box)
 {
     if (!pWin->realized)
 	return (FALSE);
@@ -3221,7 +3221,7 @@ VisibleBoundingBoxFromPoint(register Win
  * \param x,y  in root
  */
 Bool
-PointInWindowIsVisible(register WindowPtr pWin, int x, int y)
+PointInWindowIsVisible(WindowPtr pWin, int x, int y)
 {
     BoxRec box;
 
@@ -3240,9 +3240,9 @@ PointInWindowIsVisible(register WindowPt
 
 
 _X_EXPORT RegionPtr
-NotClippedByChildren(register WindowPtr pWin)
+NotClippedByChildren(WindowPtr pWin)
 {
-    register ScreenPtr pScreen;
+    ScreenPtr pScreen;
     RegionPtr pReg;
 
     pScreen = pWin->drawable.pScreen;
@@ -3588,7 +3588,7 @@ TileScreenSaver(int i, int kind)
  */
 
 _X_EXPORT WindowPtr
-FindWindowWithOptional (register WindowPtr w)
+FindWindowWithOptional (WindowPtr w)
 {
     do
 	w = w->parent;
@@ -3605,10 +3605,10 @@ FindWindowWithOptional (register WindowP
  */
 
 _X_EXPORT void
-CheckWindowOptionalNeed (register WindowPtr w)
+CheckWindowOptionalNeed (WindowPtr w)
 {
-    register WindowOptPtr optional;
-    register WindowOptPtr parentOptional;
+    WindowOptPtr optional;
+    WindowOptPtr parentOptional;
 
     if (!w->parent)
 	return;
@@ -3659,10 +3659,10 @@ CheckWindowOptionalNeed (register Window
  */
 
 _X_EXPORT Bool
-MakeWindowOptional (register WindowPtr pWin)
+MakeWindowOptional (WindowPtr pWin)
 {
-    register WindowOptPtr optional;
-    register WindowOptPtr parentOptional;
+    WindowOptPtr optional;
+    WindowOptPtr parentOptional;
 
     if (pWin->optional)
 	return TRUE;
@@ -3701,7 +3701,7 @@ MakeWindowOptional (register WindowPtr p
 }
 
 void
-DisposeWindowOptional (register WindowPtr pWin)
+DisposeWindowOptional (WindowPtr pWin)
 {
     if (!pWin->optional)
 	return;
diff-tree 40ae4f246d8818410490236ab183204a84765629 (from b5fde366e2e21234ac0b81222fd5c42ca3e49cba)
Author: Keith Packard <keithp at guitar.keithp.com>
Date:   Wed Mar 7 20:52:31 2007 -0800

    Remove stale monitor data when output becomes disconnected.
    
    Remove parsed EDID and EDID property from disconnected outputs.
    (cherry picked from commit ae9d5aa479dd50cc81b755079fcf96a0d02f135a)

diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c
index 2794496..1a42920 100644
--- a/hw/xfree86/modes/xf86Crtc.c
+++ b/hw/xfree86/modes/xf86Crtc.c
@@ -1158,7 +1158,10 @@ xf86ProbeOutputModes (ScrnInfoPtr scrn, 
 	output->status = (*output->funcs->detect)(output);
 
 	if (output->status == XF86OutputStatusDisconnected)
+	{
+	    xf86OutputSetEDID (output, NULL);
 	    continue;
+	}
 
 	memset (&mon_rec, '\0', sizeof (mon_rec));
 	
diff-tree b5fde366e2e21234ac0b81222fd5c42ca3e49cba (from a3d2c5d622d9ca36d6fa2966aff09524e3ea39ac)
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Wed Mar 7 12:29:55 2007 -0500

    Properly free device devPrivates - memory leak fix.

diff --git a/dix/devices.c b/dix/devices.c
index 9f42184..d5acb2d 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -494,6 +494,9 @@ CloseDevice(register DeviceIntPtr dev)
 	XkbRemoveResourceClient((DevicePtr)dev,dev->xkb_interest->resource);
 #endif
 
+    if (dev->devPrivates)
+	xfree(dev->devPrivates);
+
     xfree(dev->sync.event);
     xfree(dev);
 }
diff-tree a3d2c5d622d9ca36d6fa2966aff09524e3ea39ac (from e9bfb2b3d7dfaafd90d2ad0fa3d0e1acced4380b)
Author: Adam Jackson <ajax at benzedrine.nwnk.net>
Date:   Wed Mar 7 11:02:47 2007 -0500

    XORG_VERSION_CURRENT, not XF86_VERSION_CURRENT.
    
    If only this was the least wrong thing in this code.

diff --git a/hw/xfree86/i2c/uda1380_module.c b/hw/xfree86/i2c/uda1380_module.c
index 3844583..895f8c6 100644
--- a/hw/xfree86/i2c/uda1380_module.c
+++ b/hw/xfree86/i2c/uda1380_module.c
@@ -12,7 +12,7 @@ static XF86ModuleVersionInfo uda1380Vers
         MODULEVENDORSTRING,
         MODINFOSTRING1,
         MODINFOSTRING2,
-        XF86_VERSION_CURRENT,
+        XORG_VERSION_CURRENT,
         1, 0, 0,
         ABI_CLASS_VIDEODRV,             /* This needs the video driver ABI */
         ABI_VIDEODRV_VERSION,
diff-tree e9bfb2b3d7dfaafd90d2ad0fa3d0e1acced4380b (from 72a23d88d73a8c72ed18847b004db05092d3e7be)
Author: Keith Packard <keithp at neko.keithp.com>
Date:   Tue Mar 6 23:19:30 2007 -0800

    Add hw/xfree86/docs/README.modes, documenting new mode setting APIs.
    
    This document covers both API and xorg.conf usage of the new mode setting
    APIs.
    (cherry picked from commit a59c31b0f7b94ed1f395c7586c37ef5fe7ba2a25)

diff --git a/hw/xfree86/doc/README.modes b/hw/xfree86/doc/README.modes
new file mode 100644
index 0000000..894e213
--- /dev/null
+++ b/hw/xfree86/doc/README.modes
@@ -0,0 +1,474 @@
+		    Multi-monitor Mode Setting APIs
+	           Keith Packard, <keithp at keithp.com
+		   	   6 March 2007
+
+1. Introduction
+
+This document describes a set of mode setting APIs added in X server version
+1.3 that support multiple monitors per card. These interfaces expose the
+underlying hardware CRTC and output concepts to the xf86 DDX layer so that
+the implementation of initial server setup and mode changes through
+extensions can be shared across drivers. In addition, these new interfaces
+support a new configuration mechanism as well which allows each monitor to
+be customized separately providing a consistent cross-driver configuration
+mechanism that supports the full range of output features.
+
+All of the code implementing this interface can be found in hw/xfree86/modes
+in the X server sources.
+
+2. Overview
+
+This document describes both the driver API and the configuration data
+placed in xorg.conf; these are entirely separate as the driver has no
+interaction with the configuration information at all. Much of the structure
+here is cloned from the RandR extension version 1.2 additions which deal
+with the same kinds of information.
+
+2.1 API overview
+
+The mode setting API is expressed through two new driver-visible objects,
+the 'CRTC' (xf86CrtcRec) and the 'Output' (xf86OutputRec). A CRTC refers to
+hardware within the video system that can scan a subset of the framebuffer
+and generate a video signal. An Output receives that signal and transmits it
+to a monitor, projector or other device.
+
+The xf86CrtcRec and xf86OutputRec contain a small amount of state data
+related to the object along with a pointer to a set of functions provided by
+the driver that manipulate the object in fairly simple ways.
+
+To emulate older behaviour, one of the outputs is picked as the 'compat'
+output; this output changes over time as outputs are detected and used, the
+goal is to always have one 'special' output which is used for operations
+which need a single defined monitor (like XFree86-VidModeExtension mode
+setting, RandR 1.1 mode setting, DDC property setting, etc.).
+
+2.1.1 Output overview 
+
+As outputs are connected to monitors, they hold a list of modes supported by
+the monitor. If the monitor and output support DDC, then the list of modes
+generally comes from the EDID data in the monitor. Otherwise, the server
+uses the standard VESA modes, pruned by monitor timing. If the configuration
+file doesn't contain monitor timing data, the server uses default timing
+information which supports 640x480, 800x600 and 1024x768 all with a 60Hz
+refresh rate.
+
+As hardware often limits possible configuration combinations, each output
+knows the set of CRTCs that it can be connected to as well as the set of
+other outputs which can be simutaneously connected to a CRTC.
+
+2.1.2 CRTC overview
+
+CRTCs serve only to stream frame buffer data to outputs using a mode line.
+Ideally, they would not be presented to the user at all, and in fact the
+configuration file doesn't expose them. The RandR 1.2 protocol does, but the
+hope there is that client-side applications will hide them carefully away.
+
+Each crtc has an associated cursor, along with the current configuration.
+All of the data needed to determine valid configurations is contained within
+the Outputs.
+
+2.2 Configuration overview
+
+As outputs drive monitors, the "Monitor" section has been repurposed to
+define their configuration. This provides for a bit more syntax than
+the large list of driver-specific options that were used in the past for
+similar configuration.
+
+However, the existing "Monitor" section referenced by the active "Screen"
+section no longer has any use at all; some sensible meaning for this
+parameter is needed now that a Screen can have multiple Monitors.
+
+3. Public Functions
+
+3.1 PreInit functions
+
+These functions should be used during the driver PreInit phase, they are
+arranged in the order they should be invoked.
+
+    void
+    xf86CrtcConfigInit (ScrnInfoPtr			scrn
+			const xf86CrtcConfigFuncsRec	*funcs)
+
+This function allocates and initializes structures needed to track CRTC and
+Output state.
+
+    void
+    xf86CrtcSetSizeRange (ScrnInfoPtr scrn,
+			  int minWidth, int minHeight,
+			  int maxWidth, int maxHeight)
+
+This sets the range of screen sizes supported by the driver.
+
+    xf86CrtcPtr
+    xf86CrtcCreate (ScrnInfoPtr             scrn,
+		    const xf86CrtcFuncsRec  *funcs)
+    
+Create one CRTC object. See the discussion below for a description of the
+contents of the xf86CrtcFuncsRec. Note that this is done in PreInit, so it
+should not be re-invoked at each server generation. Create one of these for
+each CRTC present in the hardware.
+    
+    xf86OutputPtr
+    xf86OutputCreate (ScrnInfoPtr              scrn,
+		      const xf86OutputFuncsRec *funcs,
+		      const char	       *name)
+
+Create one Output object. See the discussion below for a description of the
+contents of the xf86OutputFuncsRec. This is also called from PreInit and
+need not be re-invoked at each ScreenInit time. An Output should be created
+for every Output present in the hardware, not just for outputs which have
+detected monitors.
+    
+    Bool
+    xf86OutputRename (xf86OutputPtr output, const char *name)
+
+If necessary, the name of an output can be changed after it is created using
+this function.
+    
+    Bool
+    xf86InitialConfiguration (ScrnInfoPtr scrn, Bool canGrow)
+
+Using the resources provided, and the configuration specified by the user,
+this function computes an initial configuration for the server. It tries to
+enable as much hardware as possible using some fairly simple heuristics. 
+
+The 'canGrow' parameter indicates that the frame buffer does not have a fixed
+size (fixed size frame buffers are required by XAA). When the frame buffer
+has a fixed size, the configuration selects a 'reasonablely large' frame
+buffer so that common reconfiguration options are possible. For resizable
+frame buffers, the frame buffer is set to the smallest size that encloses
+the desired configuration.
+    
+3.2 ScreenInit functions
+
+These functions should be used during the driver ScreenInit phase.
+
+    Bool
+    xf86DiDGAInit (ScreenPtr screen, unsigned long dga_address)
+
+This function provides driver-independent accelerated DGA support for some
+of the DGA operations; using this, the driver can avoid needing to implement
+any of the rest of DGA.
+
+    Bool
+    xf86SaveScreen(ScreenPtr pScreen, int mode)
+
+Stick this in pScreen->SaveScreen and the core X screen saver will be
+implemented by disabling outputs and crtcs using their dpms functions.
+
+    void
+    xf86DPMSSet(ScrnInfoPtr scrn, int mode, int flags)
+
+Pass this function to xf86DPMSInit and all DPMS mode switching will be
+managed by using the dpms functions provided by the Outputs and CRTCs.
+
+    Bool
+    xf86CrtcScreenInit (ScreenPtr screen)
+
+This function completes the screen initialization process for the crtc and
+output objects. Call it near the end of the ScreenInit function, after the
+frame buffer and acceleration layers have been added.
+
+3.3 EnterVT functions
+
+Functions used during EnterVT, or whenever the current configuration needs
+to be applied to the hardware.
+
+    Bool
+    xf86SetDesiredModes (ScrnInfoPtr scrn)
+
+xf86InitialConfiguration selects the desired configuration at PreInit time;
+when the server finally hits ScreenInit, xf86SetDesiredModes is used by the
+driver to take that configuration and apply it to the hardware. In addition,
+successful mode selection at other times updates the configuration that will
+be used by this function, so LeaveVT/EnterVT pairs can simply invoke this
+and return to the previous configuration.
+
+3.4 SwitchMode functions
+
+Functions called from the pScrn->SwitchMode hook, which is used by the
+XFree86-VidModeExtension and the keypad mode switch commands.
+
+    Bool
+    xf86SetSingleMode (ScrnInfoPtr	scrn, 
+		       DisplayModePtr   desired,
+		       Rotation		rotation)
+
+This function applies the specified mode to all active outputs. Which is to
+say, it picks reasonable modes for all active outputs, attempting to get the
+screen to the specified size while not breaking anything that is currently
+working.
+
+3.7 get_modes functions
+
+Functions called during output->get_modes to help build lists of modes
+
+    xf86MonPtr
+    xf86OutputGetEDID (xf86OutputPtr output, I2CBusPtr pDDCBus)
+
+This returns the EDID data structure for the 'output' using the I2C bus
+'pDDCBus'. This has no effect on 'output' itself.
+
+    void
+    xf86OutputSetEDID (xf86OutputPtr output, xf86MonPtr edid_mon)
+
+Once the EDID data has been fetched, this call applies the EDID data to the
+output object, setting the physical size and also various properties, like
+the DDC root window property (when output is the 'compat' output), and the
+RandR 1.2 EDID output properties.
+
+    DisplayModePtr
+    xf86OutputGetEDIDModes (xf86OutputPtr output)
+
+Given an EDID data structure, this function computes a list of suitable
+modes. This function also applies a sequence of 'quirks' during this process
+so that the returned modes may not actually match the mode data present in
+the EDID data.
+
+3.6 Other functions
+
+These remaining functions in the API can be used by the driver as needed.
+
+    Bool
+    xf86CrtcSetMode (xf86CrtcPtr crtc, DisplayModePtr mode, Rotation rotation,
+		     int x, int y)
+
+Applies a mode to a CRTC. All of the outputs which are currently using the
+specified CRTC are included in the mode setting process. 'x' and 'y' are the
+offset within the frame buffer that the crtc is placed at. No checking is
+done in this function to ensure that the mode is usable by the active
+outputs.
+    
+    void
+    xf86ProbeOutputModes (ScrnInfoPtr pScrn, int maxX, int maxY)
+
+This discards the mode lists for all outputs, re-detects monitor presence
+and then acquires new mode lists for all monitors which are not disconnected.
+Monitor configuration data is used to modify the mode lists returned by the
+outputs. 'maxX' and 'maxY' limit the maximum size modes that will be
+returned.
+    
+    void
+    xf86SetScrnInfoModes (ScrnInfoPtr pScrn)
+
+This copies the 'compat' output mode list into the pScrn modes list which is
+used by the XFree86-VidModeExtension and the keypad mode switching
+operations. The current 'desired' mode for the CRTC associated with the
+'compat' output is placed first in this list to indicate the current mode.
+Usually, the driver won't need to call this function as
+xf86InitialConfiguration will do so automatically, as well as any RandR
+functions which reprobe for modes. However, if the driver reprobes for modes
+at other times using xf86ProbeOutputModes, this function needs to be called.
+    
+    Bool
+    xf86DiDGAReInit (ScreenPtr pScreen)
+
+This is similar to xf86SetScrnInfoModes, but it applies the 'compat' output
+mode list to the set of modes advertised by the DGA extension; it needs to
+be called whenever xf86ProbeOutputModes is invoked.
+
+    void
+    xf86DisableUnusedFunctions(ScrnInfoPtr pScrn)
+
+After any sequence of calls using xf86CrtcSetMode, this function cleans up
+any leftover Output and CRTC objects by disabling them, saving power. It is
+safe to call this whenever the server is running as it only disables objects
+which are not currently in use.
+    
+4. CRTC operations
+
+4.1 CRTC functions
+
+These functions provide an abstract interface for the CRTC object; most
+manipulation of the CRTC object is done through these functions.
+
+    void
+    crtc->funcs->dpms (xf86CrtcPtr crtc, int mode)
+
+Where 'mode' is one of DPMSModeOff, DPMSModeSuspend, DPMSModeStandby or
+DPMSModeOn. This requests that the crtc go to the specified power state.
+When changing power states, the output dpms functions are invoked before the
+crtc dpms functions.
+
+    void
+    crtc->funcs->save (xf86CrtcPtr crtc)
+	
+    void
+    crtc->funcs->restore (xf86CrtcPtr crtc)
+
+Preserve/restore any register contents related to the CRTC. These are
+strictly a convenience for the driver writer; if the existing driver has
+fully operation save/restore functions, you need not place any additional
+code here. In particular, the server itself never uses this function.
+
+    Bool
+    crtc->funcs->lock (xf86CrtcPtr crtc)
+	
+    void
+    crtc->funcs->unlock (xf86CrtcPtr crtc)
+
+These functions are invoked around mode setting operations; the intent is
+that DRI locking be done here to prevent DRI applications from manipulating
+the hardware while the server is busy changing the output configuration. If
+the lock function returns FALSE, the unlock function will not be invoked.
+
+    Bool
+    crtc->funcs->mode_fixup (xf86CrtcPtr crtc, 
+			     DisplayModePtr mode,
+			     DisplayModePtr adjusted_mode)
+
+This call gives the CRTC a chance to see what mode will be set and to
+comment on the mode by changing 'adjusted_mode' as needed. This function
+shall not modify the state of the crtc hardware at all. If the CRTC cannot
+accept this mode, this function may return FALSE.
+
+    void
+    crtc->funcs->prepare (xf86CrtcPtr crtc)
+
+This call is made just before the mode is set to make the hardware ready for
+the operation. A usual function to perform here is to disable the crtc so
+that mode setting can occur with clocks turned off and outputs deactivated.
+
+    void
+    crtc->funcs->mode_set (xf86CrtcPtr crtc,
+			   DisplayModePtr mode,
+			   DisplayModePtr adjusted_mode)
+
+This function applies the specified mode (possibly adjusted by the CRTC
+and/or Outputs).
+
+    void
+    crtc->funcs->commit (xf86CrtcPtr crtc)
+
+Once the mode has been applied to the CRTC and Outputs, this function is
+invoked to let the hardware turn things back on.
+
+    void
+    crtc->funcs->gamma_set (xf86CrtcPtr crtc, CARD16 *red,
+			    CARD16 *green, CARD16 *blue, int size)
+
+This function adjusts the gamma ramps for the specified crtc.
+
+    void *
+    crtc->funcs->shadow_allocate (xf86CrtcPtr crtc, int width, int height)
+
+This function allocates frame buffer space for a shadow frame buffer. When
+allocated, the crtc must scan from the shadow instead of the main frame
+buffer. This is used for rotation. The address returned is passed to the
+shadow_create function. This function should return NULL on failure.
+
+    PixmapPtr
+    crtc->funcs->shadow_create (xf86CrtcPtr crtc, void *data,
+				int width, int height)
+
+This function creates a pixmap object that will be used as a shadow of the
+main frame buffer for CRTCs which are rotated or reflected. 'data' is the
+value returned by shadow_allocate.
+
+    void
+    crtc->funcs->shadow_destroy (xf86CrtcPtr crtc, PixmapPtr pPixmap,
+				 void *data)
+
+Destroys any associated shadow objects. If pPixmap is NULL, then a pixmap
+was not created, but 'data' may still be non-NULL indicating that the shadow
+had been allocated.
+
+    void
+    crtc->funcs->destroy (xf86CrtcPtr crtc)
+
+When a CRTC is destroyed (which only happens in error cases), this function
+can clean up any driver-specific data.
+
+4.2 CRTC fields
+
+The CRTC object is not opaque; there are several fields of interest to the
+driver writer.
+
+    struct _xf86Crtc {
+	/**
+	 * Associated ScrnInfo
+	 */
+	ScrnInfoPtr     scrn;
+    
+	/**
+	 * Active state of this CRTC
+	 *
+	 * Set when this CRTC is driving one or more outputs
+	 */
+	Bool            enabled;
+    
+	/** Track whether cursor is within CRTC range  */
+	Bool            cursorInRange;
+    
+	/** Track state of cursor associated with this CRTC */
+	Bool            cursorShown;
+    
+	/**
+	 * Active mode
+	 *
+	 * This reflects the mode as set in the CRTC currently
+	 * It will be cleared when the VT is not active or
+	 * during server startup
+	 */
+	DisplayModeRec  mode;
+	Rotation        rotation;
+	PixmapPtr       rotatedPixmap;
+	void            *rotatedData;
+    
+	/**
+	 * Position on screen
+	 *
+	 * Locates this CRTC within the frame buffer
+	 */
+	int             x, y;
+    
+	/**
+	 * Desired mode
+	 *
+	 * This is set to the requested mode, independent of
+	 * whether the VT is active. In particular, it receives
+	 * the startup configured mode and saves the active mode
+	 * on VT switch.
+	 */
+	DisplayModeRec  desiredMode;
+	Rotation        desiredRotation;
+	int             desiredX, desiredY;
+    
+	/** crtc-specific functions */
+	const xf86CrtcFuncsRec *funcs;
+    
+	/**
+	 * Driver private
+	 *
+	 * Holds driver-private information
+	 */
+	void            *driver_private;
+    #ifdef RANDR_12_INTERFACE
+	/**
+	 * RandR crtc
+	 *
+	 * When RandR 1.2 is available, this
+	 * points at the associated crtc object
+	 */
+	RRCrtcPtr       randr_crtc;
+    #else
+	void            *randr_crtc;
+    #endif
+    };
+
+    
+5. Output functions.
+
+6. Configuration
+
+Because the configuration file syntax is fixed,
+this was done by creating new "Driver" section options that hook specific
+outputs to specific "Monitor" sections in the file. The option:
+section of the form:
+
+	Option	"monitor-VGA" "My VGA Monitor"
+
+connects the VGA output of this driver to the "Monitor" section with
+Identifier "My VGA Monitor". All of the usual monitor options can now be
+placed in that "Monitor" section and will be applied to the VGA output
+configuration.
diff-tree 72a23d88d73a8c72ed18847b004db05092d3e7be (from 81526232bc0119d2ec7b8590be4f78cf066ae359)
Author: Keith Packard <keithp at guitar.keithp.com>
Date:   Tue Mar 6 23:15:34 2007 -0800

    Add xf86CrtcScreenInit to share initialization across drivers.
    
    xf86CrtcScreenInit performs initialization that needs to happen at
    ScreenInit time.
    (cherry picked from commit 558a4f5588ad2ec11254e0b5d6ce9515b137369e)

diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c
index 46515fd..2794496 100644
--- a/hw/xfree86/modes/xf86Crtc.c
+++ b/hw/xfree86/modes/xf86Crtc.c
@@ -545,6 +545,60 @@ xf86OutputDestroy (xf86OutputPtr output)
     xfree (output);
 }
 
+/*
+ * Called during CreateScreenResources to hook up RandR
+ */
+static Bool
+xf86CrtcCreateScreenResources (ScreenPtr screen)
+{
+    ScrnInfoPtr		scrn = xf86Screens[screen->myNum];
+    xf86CrtcConfigPtr	config = XF86_CRTC_CONFIG_PTR(scrn);
+
+    screen->CreateScreenResources = config->CreateScreenResources;
+    
+    if (!(*screen->CreateScreenResources)(screen))
+	return FALSE;
+
+    if (!xf86RandR12CreateScreenResources (screen))
+	return FALSE;
+
+    return TRUE;
+}
+
+/*
+ * Called at ScreenInit time to set up
+ */
+Bool
+xf86CrtcScreenInit (ScreenPtr screen)
+{
+    ScrnInfoPtr		scrn = xf86Screens[screen->myNum];
+    xf86CrtcConfigPtr	config = XF86_CRTC_CONFIG_PTR(scrn);
+    int			c;
+
+    /* Rotation */
+    xf86DrvMsg(scrn->scrnIndex, X_INFO, "RandR 1.2 enabled, ignore the following RandR disabled message.\n");
+    xf86DisableRandR(); /* Disable old RandR extension support */
+    xf86RandR12Init (screen);
+
+    /* support all rotations if every crtc has the shadow alloc funcs */
+    for (c = 0; c < config->num_crtc; c++)
+    {
+	xf86CrtcPtr crtc = config->crtc[c];
+	if (!crtc->funcs->shadow_allocate || !crtc->funcs->shadow_create)
+	    break;
+    }
+    if (c == config->num_crtc)
+	xf86RandR12SetRotations (screen, RR_Rotate_0 | RR_Rotate_90 |
+				 RR_Rotate_180 | RR_Rotate_270);
+    else
+	xf86RandR12SetRotations (screen, RR_Rotate_0);
+    
+    /* Wrap CreateScreenResources so we can initialize the RandR code */
+    config->CreateScreenResources = screen->CreateScreenResources;
+    screen->CreateScreenResources = xf86CrtcCreateScreenResources;
+    return TRUE;
+}
+
 static DisplayModePtr
 xf86DefaultMode (xf86OutputPtr output, int width, int height)
 {
diff --git a/hw/xfree86/modes/xf86Crtc.h b/hw/xfree86/modes/xf86Crtc.h
index 062a2db..6152ae4 100644
--- a/hw/xfree86/modes/xf86Crtc.h
+++ b/hw/xfree86/modes/xf86Crtc.h
@@ -494,6 +494,7 @@ typedef struct _xf86CrtcConfig {
 
     const xf86CrtcConfigFuncsRec *funcs;
 
+    CreateScreenResourcesProcPtr    CreateScreenResources;
 } xf86CrtcConfigRec, *xf86CrtcConfigPtr;
 
 extern int xf86CrtcConfigPrivateIndex;
@@ -525,25 +526,6 @@ xf86CrtcDestroy (xf86CrtcPtr		crtc);
 
 
 /**
- * Allocate a crtc for the specified output
- *
- * Find a currently unused CRTC which is suitable for
- * the specified output
- */
-
-xf86CrtcPtr 
-xf86AllocCrtc (xf86OutputPtr		output);
-
-/**
- * Free a crtc
- *
- * Mark the crtc as unused by any outputs
- */
-
-void
-xf86FreeCrtc (xf86CrtcPtr		crtc);
-
-/**
  * Sets the given video mode on the given crtc
  */
 Bool
@@ -583,6 +565,9 @@ void
 xf86SetScrnInfoModes (ScrnInfoPtr pScrn);
 
 Bool
+xf86CrtcScreenInit (ScreenPtr pScreen);
+
+Bool
 xf86InitialConfiguration (ScrnInfoPtr pScrn, Bool canGrow);
 
 void
diff --git a/hw/xfree86/modes/xf86Rename.h b/hw/xfree86/modes/xf86Rename.h
index eae6d64..9dcfef5 100644
--- a/hw/xfree86/modes/xf86Rename.h
+++ b/hw/xfree86/modes/xf86Rename.h
@@ -31,6 +31,7 @@
 #define xf86CrtcDestroy XF86NAME(xf86CrtcDestroy)
 #define xf86CrtcInUse XF86NAME(xf86CrtcInUse)
 #define xf86CrtcRotate XF86NAME(xf86CrtcRotate)
+#define xf86CrtcScreenInit XF86NAME(xf86CrtcScreenInit)
 #define xf86CrtcSetMode XF86NAME(xf86CrtcSetMode)
 #define xf86CrtcSetSizeRange XF86NAME(xf86CrtcSetSizeRange)
 #define xf86CVTMode XF86NAME(xf86CVTMode)
diff-tree 81526232bc0119d2ec7b8590be4f78cf066ae359 (from a7cd53deb99957dec27a55ffd75e548b322ae0ce)
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Mar 6 17:19:11 2007 -0500

    remove PIXPRIV check as this flag is always set.

diff --git a/dix/pixmap.c b/dix/pixmap.c
index a5b7b06..c280a3b 100644
--- a/dix/pixmap.c
+++ b/dix/pixmap.c
@@ -109,7 +109,6 @@ _X_EXPORT PixmapPtr
 AllocatePixmap(ScreenPtr pScreen, int pixDataSize)
 {
     PixmapPtr pPixmap;
-#ifdef PIXPRIV
     char *ptr;
     DevUnion *ppriv;
     unsigned *sizes;
@@ -136,9 +135,6 @@ AllocatePixmap(ScreenPtr pScreen, int pi
         else
 	    ppriv->ptr = (pointer)NULL;
     }
-#else
-    pPixmap = (PixmapPtr)xalloc(sizeof(PixmapRec) + pixDataSize);
-#endif
 
 #ifdef _XSERVER64
     if (pPixmap) {
diff-tree a7cd53deb99957dec27a55ffd75e548b322ae0ce (from 024bbc7cbb924daaf3e305ddfc8e74509acd1e15)
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Mar 6 15:32:13 2007 -0500

    remove PIXPRIV checks as this flag is always set.

diff --git a/Xext/shm.c b/Xext/shm.c
index 7cfaa68..ac587be 100644
--- a/Xext/shm.c
+++ b/Xext/shm.c
@@ -119,9 +119,7 @@ static int pixmapFormat;
 static int shmPixFormat[MAXSCREENS];
 static ShmFuncsPtr shmFuncs[MAXSCREENS];
 static DestroyPixmapProcPtr destroyPixmap[MAXSCREENS];
-#ifdef PIXPRIV
 static int  shmPixmapPrivate;
-#endif
 static ShmFuncs miFuncs = {NULL, miShmPutImage};
 static ShmFuncs fbFuncs = {fbShmCreatePixmap, fbShmPutImage};
 
@@ -237,7 +235,6 @@ ShmExtensionInit(INITARGS)
 	    destroyPixmap[i] = screenInfo.screens[i]->DestroyPixmap;
 	    screenInfo.screens[i]->DestroyPixmap = ShmDestroyPixmap;
 	}
-#ifdef PIXPRIV
 	shmPixmapPrivate = AllocatePixmapPrivateIndex();
 	for (i = 0; i < screenInfo.numScreens; i++)
 	{
@@ -245,7 +242,6 @@ ShmExtensionInit(INITARGS)
 				       shmPixmapPrivate, 0))
 		return;
 	}
-#endif
       }
     }
     ShmSegType = CreateNewResourceType(ShmDetachSegment);
@@ -299,22 +295,7 @@ ShmDestroyPixmap (PixmapPtr pPixmap)
     if (pPixmap->refcnt == 1)
     {
 	ShmDescPtr  shmdesc;
-#ifdef PIXPRIV
 	shmdesc = (ShmDescPtr) pPixmap->devPrivates[shmPixmapPrivate].ptr;
-#else
-	char	*base = (char *) pPixmap->devPrivate.ptr;
-	
-	if (base != (pointer) (pPixmap + 1))
-	{
-	    for (shmdesc = Shmsegs; shmdesc; shmdesc = shmdesc->next)
-	    {
-		if (shmdesc->addr <= base && base <= shmdesc->addr + shmdesc->size)
-		    break;
-	    }
-	}
-	else
-	    shmdesc = 0;
-#endif
 	if (shmdesc)
 	    ShmDetachSegment ((pointer) shmdesc, pPixmap->drawable.id);
     }
@@ -781,9 +762,7 @@ CreatePmap:
 				shmdesc->addr + stuff->offset);
 
 	if (pMap) {
-#ifdef PIXPRIV
             pMap->devPrivates[shmPixmapPrivate].ptr = (pointer) shmdesc;
-#endif
             shmdesc->refcnt++;
 	    pMap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
 	    pMap->drawable.id = newPix->info[j].id;
@@ -1097,9 +1076,7 @@ CreatePmap:
 			    shmdesc->addr + stuff->offset);
     if (pMap)
     {
-#ifdef PIXPRIV
 	pMap->devPrivates[shmPixmapPrivate].ptr = (pointer) shmdesc;
-#endif
 	shmdesc->refcnt++;
 	pMap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
 	pMap->drawable.id = stuff->pid;
diff --git a/afb/afbpixmap.c b/afb/afbpixmap.c
index 6801960..6a3a485 100644
--- a/afb/afbpixmap.c
+++ b/afb/afbpixmap.c
@@ -102,12 +102,8 @@ afbCreatePixmap(pScreen, width, height, 
 	pPixmap->drawable.height = height;
 	pPixmap->devKind = paddedWidth;
 	pPixmap->refcnt = 1;
-#ifdef PIXPRIV
 	pPixmap->devPrivate.ptr =  datasize ?
 				(pointer)((char *)pPixmap + pScreen->totalPixmapSize) : NULL;
-#else
-	pPixmap->devPrivate.ptr = (pointer)(pPixmap + 1);
-#endif
 	return(pPixmap);
 }
 
diff --git a/cfb/cfbpixmap.c b/cfb/cfbpixmap.c
index d51c518..6fdf3ea 100644
--- a/cfb/cfbpixmap.c
+++ b/cfb/cfbpixmap.c
@@ -96,12 +96,8 @@ cfbCreatePixmap (pScreen, width, height,
     pPixmap->drawable.height = height;
     pPixmap->devKind = paddedWidth;
     pPixmap->refcnt = 1;
-#ifdef PIXPRIV
     pPixmap->devPrivate.ptr = datasize ?
 		(pointer)((char *)pPixmap + pScreen->totalPixmapSize) : NULL;
-#else
-    pPixmap->devPrivate.ptr = (pointer)(pPixmap + 1);
-#endif
     return pPixmap;
 }
 
diff --git a/dix/main.c b/dix/main.c
index 3a77533..92c30b6 100644
--- a/dix/main.c
+++ b/dix/main.c
@@ -361,9 +361,7 @@ main(int argc, char *argv[], char *envp[
 	ResetScreenPrivates();
 	ResetWindowPrivates();
 	ResetGCPrivates();
-#ifdef PIXPRIV
 	ResetPixmapPrivates();
-#endif
 	ResetColormapPrivates();
 	ResetFontPrivateIndex();
 	ResetDevicePrivateIndex();
@@ -731,11 +729,9 @@ AddScreen(
     pScreen->GCPrivateSizes = (unsigned *)NULL;
     pScreen->totalGCSize =
         ((sizeof(GC) + sizeof(long) - 1) / sizeof(long)) * sizeof(long);
-#ifdef PIXPRIV
     pScreen->PixmapPrivateLen = 0;
     pScreen->PixmapPrivateSizes = (unsigned *)NULL;
     pScreen->totalPixmapSize = BitmapBytePad(sizeof(PixmapRec)*8);
-#endif
     pScreen->ClipNotify = 0;	/* for R4 ddx compatibility */
     pScreen->CreateScreenResources = 0;
     
@@ -799,9 +795,7 @@ FreeScreen(ScreenPtr pScreen)
 {
     xfree(pScreen->WindowPrivateSizes);
     xfree(pScreen->GCPrivateSizes);
-#ifdef PIXPRIV
     xfree(pScreen->PixmapPrivateSizes);
-#endif
     xfree(pScreen->devPrivates);
     xfree(pScreen);
 }
diff --git a/dix/privates.c b/dix/privates.c
index b20a1db..a61c3cb 100644
--- a/dix/privates.c
+++ b/dix/privates.c
@@ -309,7 +309,6 @@ AllocateGCPrivate(register ScreenPtr pSc
 /*
  *  pixmap private machinery
  */
-#ifdef PIXPRIV
 static int  pixmapPrivateCount;
 
 void
@@ -355,7 +354,6 @@ AllocatePixmapPrivate(register ScreenPtr
     pScreen->totalPixmapSize = BitmapBytePad(pScreen->totalPixmapSize * 8);
     return TRUE;
 }
-#endif
 
 
 /*
diff --git a/fb/fbpixmap.c b/fb/fbpixmap.c
index c2ddcb0..18c1204 100644
--- a/fb/fbpixmap.c
+++ b/fb/fbpixmap.c
@@ -43,11 +43,7 @@ fbCreatePixmapBpp (ScreenPtr pScreen, in
     if (paddedWidth / 4 > 32767 || height > 32767)
 	return NullPixmap;
     datasize = height * paddedWidth;
-#ifdef PIXPRIV
     base = pScreen->totalPixmapSize;
-#else
-    base = sizeof (PixmapRec);
-#endif
     adjust = 0;
     if (base & 7)
 	adjust = 8 - (base & 7);
diff --git a/hw/dmx/dmxpixmap.c b/hw/dmx/dmxpixmap.c
index 4a669fd..9340606 100644
--- a/hw/dmx/dmxpixmap.c
+++ b/hw/dmx/dmxpixmap.c
@@ -49,15 +49,11 @@
 /** Initialize a private area in \a pScreen for pixmap information. */
 Bool dmxInitPixmap(ScreenPtr pScreen)
 {
-#ifdef PIXPRIV
     if (!AllocatePixmapPrivate(pScreen, dmxPixPrivateIndex,
 			       sizeof(dmxPixPrivRec)))
 	return FALSE;
 
     return TRUE;
-#else
-#error Must define PIXPRIV to compile DMX X server
-#endif
 }
 
 /** Create a pixmap on the back-end server. */
diff --git a/hw/dmx/dmxscrinit.c b/hw/dmx/dmxscrinit.c
index 5bfb4df..7c315d8 100644
--- a/hw/dmx/dmxscrinit.c
+++ b/hw/dmx/dmxscrinit.c
@@ -70,9 +70,7 @@ static unsigned long *dmxCursorGeneratio
 
 int dmxGCPrivateIndex;          /**< Private index for GCs       */
 int dmxWinPrivateIndex;         /**< Private index for Windows   */
-#ifdef PIXPRIV
 int dmxPixPrivateIndex;         /**< Private index for Pixmaps   */
-#endif
 int dmxFontPrivateIndex;        /**< Private index for Fonts     */
 int dmxScreenPrivateIndex;      /**< Private index for Screens   */
 int dmxColormapPrivateIndex;    /**< Private index for Colormaps */
@@ -233,14 +231,10 @@ Bool dmxScreenInit(int idx, ScreenPtr pS
 	if (dmxWinPrivateIndex == -1)
 	    return FALSE;
 
-#ifdef PIXPRIV
 	/* Allocate pixmap private index */
 	dmxPixPrivateIndex = AllocatePixmapPrivateIndex();
 	if (dmxPixPrivateIndex == -1)
 	    return FALSE;
-#else
-#error Must define PIXPRIV to compile DMX X server
-#endif
 
 	/* Allocate font private index */
 	dmxFontPrivateIndex = AllocateFontPrivateIndex();
diff --git a/hw/xfree86/loader/dixsym.c b/hw/xfree86/loader/dixsym.c
index 32e0e4f..594bf43 100644
--- a/hw/xfree86/loader/dixsym.c
+++ b/hw/xfree86/loader/dixsym.c
@@ -271,10 +271,8 @@ _X_HIDDEN void *dixLookupTab[] = {
     SYMFUNC(AllocateColormapPrivateIndex)
     SYMFUNC(AllocateDevicePrivateIndex)
     SYMFUNC(AllocateDevicePrivate)
-#ifdef PIXPRIV
     SYMFUNC(AllocatePixmapPrivateIndex)
     SYMFUNC(AllocatePixmapPrivate)
-#endif
     /* resource.c */
     SYMFUNC(AddResource)
     SYMFUNC(ChangeResourceValue)
diff --git a/hw/xfree86/xf4bpp/ppcPixmap.c b/hw/xfree86/xf4bpp/ppcPixmap.c
index 9f4cdc9..9b2defd 100644
--- a/hw/xfree86/xf4bpp/ppcPixmap.c
+++ b/hw/xfree86/xf4bpp/ppcPixmap.c
@@ -120,12 +120,8 @@ xf4bppCreatePixmap( pScreen, width, heig
     pPixmap->devKind = size;
     pPixmap->refcnt = 1 ;
     size = height * pPixmap->devKind ;
-#ifdef PIXPRIV
     pPixmap->devPrivate.ptr = (pointer) (((CARD8*)pPixmap)
 					 + pScreen->totalPixmapSize);
-#else
-    pPixmap->devPrivate.ptr = (pointer) (pPixmap + 1);
-#endif
     bzero( (char *) pPixmap->devPrivate.ptr, size ) ;
     return pPixmap ;
 }
diff --git a/hw/xnest/Pixmap.c b/hw/xnest/Pixmap.c
index aa8bed9..612df8d 100644
--- a/hw/xnest/Pixmap.c
+++ b/hw/xnest/Pixmap.c
@@ -32,9 +32,7 @@ is" without express or implied warranty.
 #include "Screen.h"
 #include "XNPixmap.h"
 
-#ifdef PIXPRIV
 int xnestPixmapPrivateIndex;	    
-#endif
 
 PixmapPtr
 xnestCreatePixmap(ScreenPtr pScreen, int width, int height, int depth)
@@ -57,12 +55,8 @@ xnestCreatePixmap(ScreenPtr pScreen, int
   pPixmap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
   pPixmap->refcnt = 1;
   pPixmap->devKind = PixmapBytePad(width, depth);
-#ifdef PIXPRIV
   pPixmap->devPrivates[xnestPixmapPrivateIndex].ptr =
       (pointer)((char *)pPixmap + pScreen->totalPixmapSize);
-#else
-  pPixmap->devPrivate.ptr = (pointer)(pPixmap + 1);
-#endif
   if (width && height)
       xnestPixmapPriv(pPixmap)->pixmap = 
 	  XCreatePixmap(xnestDisplay, 
diff --git a/hw/xnest/Screen.c b/hw/xnest/Screen.c
index 8e86efb..e6870e7 100644
--- a/hw/xnest/Screen.c
+++ b/hw/xnest/Screen.c
@@ -49,9 +49,7 @@ Window xnestScreenSaverWindows[MAXSCREEN
 extern void GlxWrapInitVisuals(miInitVisualsProcPtr *);
 #endif
 
-#ifdef PIXPRIV
 int xnestScreenGeneration = -1;
-#endif
 
 ScreenPtr
 xnestScreen(Window window)
@@ -154,7 +152,6 @@ xnestOpenScreen(int index, ScreenPtr pSc
 			    sizeof(xnestPrivGC)))) 
     return False;
 
-#ifdef PIXPRIV
   if (xnestScreenGeneration != serverGeneration) {
       if ((xnestPixmapPrivateIndex = AllocatePixmapPrivateIndex()) < 0)
 	  return False;
@@ -164,7 +161,6 @@ xnestOpenScreen(int index, ScreenPtr pSc
   if (!AllocatePixmapPrivate(pScreen,xnestPixmapPrivateIndex,
 			     sizeof (xnestPrivPixmap)))
       return False;
-#endif
   visuals = (VisualPtr)xalloc(xnestNumVisuals * sizeof(VisualRec));
   numVisuals = 0;
 
diff --git a/hw/xnest/XNPixmap.h b/hw/xnest/XNPixmap.h
index 77cba24..6971b11 100644
--- a/hw/xnest/XNPixmap.h
+++ b/hw/xnest/XNPixmap.h
@@ -15,21 +15,14 @@ is" without express or implied warranty.
 #ifndef XNESTPIXMAP_H
 #define XNESTPIXMAP_H
 
-#ifdef PIXPRIV
 extern int xnestPixmapPrivateIndex;
-#endif
 
 typedef struct {
   Pixmap pixmap;
 } xnestPrivPixmap;
 
-#ifdef PIXPRIV
 #define xnestPixmapPriv(pPixmap) \
   ((xnestPrivPixmap *)((pPixmap)->devPrivates[xnestPixmapPrivateIndex].ptr))
-#else
-#define xnestPixmapPriv(pPixmap) \
-  ((xnestPrivPixmap *)((pPixmap)->devPrivate.ptr))
-#endif
 
 #define xnestPixmap(pPixmap) (xnestPixmapPriv(pPixmap)->pixmap)
 
diff --git a/include/pixmapstr.h b/include/pixmapstr.h
index 628465b..93bd45d 100644
--- a/include/pixmapstr.h
+++ b/include/pixmapstr.h
@@ -86,9 +86,7 @@ typedef struct _Pixmap {
     int			refcnt;
     int			devKind;
     DevUnion		devPrivate;
-#ifdef PIXPRIV
     DevUnion		*devPrivates; /* real devPrivates like gcs & windows */
-#endif
 #ifdef COMPOSITE
     short		screen_x;
     short		screen_y;
diff --git a/include/screenint.h b/include/screenint.h
index e60c248..1f1434a 100644
--- a/include/screenint.h
+++ b/include/screenint.h
@@ -86,8 +86,6 @@ extern int AddScreen(
     int /*argc*/,
     char** /*argv*/);
 
-#ifdef PIXPRIV
-
 extern void ResetPixmapPrivates(void);
 
 extern int AllocatePixmapPrivateIndex(void);
@@ -97,8 +95,6 @@ extern Bool AllocatePixmapPrivate(
     int /* index */,
     unsigned /* amount */);
 
-#endif /* PIXPRIV */
-
 extern void ResetColormapPrivates(void);
 
 
diff --git a/include/scrnintstr.h b/include/scrnintstr.h
index 3613515..110f4dc 100644
--- a/include/scrnintstr.h
+++ b/include/scrnintstr.h
@@ -558,11 +558,9 @@ typedef struct _Screen {
 
     PixmapPtr pScratchPixmap;		/* scratch pixmap "pool" */
 
-#ifdef PIXPRIV
     int			PixmapPrivateLen;
     unsigned int		*PixmapPrivateSizes;
     unsigned int		totalPixmapSize;
-#endif
 
     MarkWindowProcPtr		MarkWindow;
     MarkOverlappedWindowsProcPtr MarkOverlappedWindows;
diff --git a/mfb/mfbpixmap.c b/mfb/mfbpixmap.c
index 5ec8502..e349724 100644
--- a/mfb/mfbpixmap.c
+++ b/mfb/mfbpixmap.c
@@ -101,12 +101,8 @@ mfbCreatePixmap (pScreen, width, height,
     pPixmap->drawable.height = height;
     pPixmap->devKind = paddedWidth;
     pPixmap->refcnt = 1;
-#ifdef PIXPRIV
     pPixmap->devPrivate.ptr =  datasize ?
 		(pointer)((char *)pPixmap + pScreen->totalPixmapSize) : NULL;
-#else
-    pPixmap->devPrivate.ptr = (pointer)(pPixmap + 1);
-#endif
     return pPixmap;
 }
 
diff-tree 024bbc7cbb924daaf3e305ddfc8e74509acd1e15 (from 9d94c137596d3f9d9118ec70455b7a30b3582046)
Author: Eric Anholt <eric at anholt.net>
Date:   Tue Mar 6 16:18:59 2007 -0800

    Bug #9931: Fix linear allocations with a non-1-byte granularity.
    
    This was introduced in 83080809f9a1c1d24b0318e54632f25f5940da25.  Instead of
    aligning the offset, it doubled it.  Results were appropriately spectacular.

diff --git a/hw/xfree86/common/xf86fbman.c b/hw/xfree86/common/xf86fbman.c
index d64cfae..537d53d 100644
--- a/hw/xfree86/common/xf86fbman.c
+++ b/hw/xfree86/common/xf86fbman.c
@@ -968,7 +968,7 @@ localAllocateOffscreenLinear(
 	linear->size = h * w;
 	linear->offset = (pitch * area->box.y1) + area->box.x1;
 	if (gran > 1)
-            linear->offset += ((linear->offset + gran - 1) / gran) * gran;
+            linear->offset = ((linear->offset + gran - 1) / gran) * gran;
 	linear->granularity = gran;
 	linear->MoveLinearCallback = moveCB;
 	linear->RemoveLinearCallback = removeCB;
diff-tree 9d94c137596d3f9d9118ec70455b7a30b3582046 (from 81d581e655fc989da3be4256b83849a63b8607b7)
Author: Ben Byer <bbyer at apple.com>
Date:   Tue Mar 6 11:09:30 2007 -0800

    updated todo list

diff --git a/hw/darwin/README.apple b/hw/darwin/README.apple
index 68bc692..229ab17 100644
--- a/hw/darwin/README.apple
+++ b/hw/darwin/README.apple
@@ -22,20 +22,14 @@ The server builds 4 targets:
 Known issues:
 
 * AGL and CGL support for 3D indirect acceleration does not work;
-  indirect.c needs to be rewritten.
+  indirect.c has been rewritten, but not yet integrated into this source tree.
 
 * Fullscreen mode does not work; I don't know why.
 
-* The keyboard and mouse do not work at all; they worked in X11R7.1,
-  and I believe that they were broken by the events changes in dix/.
-
 * Some features in X11.app are not yet implemented; these are marked
   with #ifdef DARWIN_DDX_MISSING in the code.
 
 * The build system code could probably be cleaned up slightly.
 
-* Most testing of this code has occurred under 10.5, but it should
-  also work under 10.4.
-
 Any patches or code contributions would be most welcome and may be
 sent to me at bbyer at apple.com.
diff-tree 81d581e655fc989da3be4256b83849a63b8607b7 (from parents)
Merge: a05ffca8dd0da9bdb5c1bf4c481028aeabf21e34 d5aba03feff41722c72b4c6193f09d141cbf1678
Author: Ben Byer <bbyer at bbyer.(none)>
Date:   Tue Mar 6 10:37:29 2007 -0800

    Merge branch 'master' of git+ssh://bbyer@git.freedesktop.org/git/xorg/xserver

diff-tree a05ffca8dd0da9bdb5c1bf4c481028aeabf21e34 (from 3206e9225897989638ad553e1f392b918ac4d21f)
Author: Ben Byer <bbyer at bbyer.(none)>
Date:   Tue Mar 6 10:36:51 2007 -0800

    rewrote event handling, Xquartz now has working mouse and keyboard. use it\!

diff --git a/hw/darwin/apple/X11Application.m b/hw/darwin/apple/X11Application.m
index 34c0307..57795f4 100644
--- a/hw/darwin/apple/X11Application.m
+++ b/hw/darwin/apple/X11Application.m
@@ -919,11 +919,7 @@ static void send_nsevent (NSEventType ty
       break;
 
     case NSFlagsChanged:
-      bzero(&xe, sizeof(xe));
-      xe.u.u.type = kXDarwinUpdateModifiers;
-      xe.u.clientMessage.u.l.longs0 = [e modifierFlags];
-      DarwinEQEnqueue (&xe);
-      DarwinPokeEQ();
+      DarwinUpdateModKeys([e modifierFlags]);
       break;
     default: break; /* for gcc */
     }	
diff --git a/hw/darwin/darwinEvents.c b/hw/darwin/darwinEvents.c
index cb30a90..3d7f268 100644
--- a/hw/darwin/darwinEvents.c
+++ b/hw/darwin/darwinEvents.c
@@ -63,6 +63,8 @@ typedef struct _Event {
 
 int input_check_zero, input_check_flag;
 
+static int old_flags = 0;  // last known modifier state
+
 typedef struct _EventQueue {
     HWEventQueueType    head, tail; /* long for SetInputCheck */
     CARD32      lastEventTime;      /* to avoid time running backwards */
@@ -81,18 +83,15 @@ xEvent *darwinEvents;
  *  Press or release the given modifier key, specified by its mask.
  */
 static void DarwinPressModifierMask(
-    xEvent *xe,     // must already have type, time and mouse location
+    int pressed,				    
     int mask)       // one of NX_*MASK constants
 {
     int key = DarwinModifierNXMaskToNXKey(mask);
 
     if (key != -1) {
         int keycode = DarwinModifierNXKeyToNXKeycode(key, 0);
-        if (keycode != 0) {
-            xe->u.u.detail = keycode + MIN_KEYCODE;
-            (*darwinEventQueue.pKbd->processInputProc)(xe,
-                            (DeviceIntPtr)darwinEventQueue.pKbd, 1);
-        }
+        if (keycode != 0)
+	  DarwinSendKeyboardEvents(pressed, keycode);
     }
 }
 
@@ -125,28 +124,26 @@ static void DarwinPressModifierMask(
  *  Send events to update the modifier state.
  */
 static void DarwinUpdateModifiers(
-    xEvent *xe,         // event template with time and mouse position set
     int pressed,        // KeyPress or KeyRelease
     int flags )         // modifier flags that have changed
 {
-    xe->u.u.type = pressed;
     if (flags & NX_ALPHASHIFTMASK) {
-        DarwinPressModifierMask(xe, NX_ALPHASHIFTMASK);
+        DarwinPressModifierMask(pressed, NX_ALPHASHIFTMASK);
     }
     if (flags & NX_COMMANDMASK) {
-        DarwinPressModifierMask(xe, COMMAND_MASK(flags));
+        DarwinPressModifierMask(pressed, COMMAND_MASK(flags));
     }
     if (flags & NX_CONTROLMASK) {
-        DarwinPressModifierMask(xe, CONTROL_MASK(flags));
+        DarwinPressModifierMask(pressed, CONTROL_MASK(flags));
     }
     if (flags & NX_ALTERNATEMASK) {
-        DarwinPressModifierMask(xe, ALTERNATE_MASK(flags));
+        DarwinPressModifierMask(pressed, ALTERNATE_MASK(flags));
     }
     if (flags & NX_SHIFTMASK) {
-        DarwinPressModifierMask(xe, SHIFT_MASK(flags));
+        DarwinPressModifierMask(pressed, SHIFT_MASK(flags));
     }
     if (flags & NX_SECONDARYFNMASK) {
-        DarwinPressModifierMask(xe, NX_SECONDARYFNMASK);
+        DarwinPressModifierMask(pressed, NX_SECONDARYFNMASK);
     }
 }
 
@@ -163,19 +160,20 @@ static void DarwinUpdateModifiers(
  *  simulate a button 2 press instead of Command-button 2.
  */
 static void DarwinSimulateMouseClick(
-    xEvent *xe,         // event template with time and
-                        // mouse position filled in
+    int pointer_x,
+    int pointer_y,
     int whichButton,    // mouse button to be pressed
     int modifierMask)   // modifiers used for the fake click
 {
     // first fool X into forgetting about the keys
-    DarwinUpdateModifiers(xe, KeyRelease, modifierMask);
+    DarwinUpdateModifiers(KeyRelease, modifierMask);
 
     // push the mouse button
-    xe->u.u.type = ButtonPress;
-    xe->u.u.detail = whichButton;
-    (*darwinEventQueue.pPtr->processInputProc)
-            (xe, (DeviceIntPtr)darwinEventQueue.pPtr, 1);
+    DarwinSendPointerEvents(ButtonPress, whichButton, pointer_x, pointer_y);
+    DarwinSendPointerEvents(ButtonRelease, whichButton, pointer_x, pointer_y);
+
+    // restore old modifiers
+    DarwinUpdateModifiers(KeyPress, modifierMask);
 }
 
 
@@ -234,7 +232,7 @@ void DarwinEQEnqueue(const xEvent *e) {
     darwinEventQueue.tail = newtail;
 
     // Signal there is an event ready to handle
-    write(darwinEventWriteFD, &byte, 1);
+    DarwinPokeEQ();
 }
 
 
@@ -265,8 +263,6 @@ void ProcessInputEvents(void) {
     xEvent  xe;
     static int  old_flags = 0;  // last known modifier state
     // button number and modifier mask of currently pressed fake button
-    static int darwinFakeMouseButtonDown = 0;
-    static int darwinFakeMouseButtonMask = 0;
     input_check_flag=0;
 
     //    ErrorF("calling mieqProcessInputEvents\n");
@@ -318,155 +314,35 @@ void ProcessInputEvents(void) {
                 darwinEventQueue.head = 0;
             else
                 ++darwinEventQueue.head;
-            switch (xe.u.u.type)
-            {
+            switch (xe.u.u.type) {
             case KeyPress:
-                if (old_flags == 0
-                    && darwinSyncKeymap && darwinKeymapFile == NULL)
-                {
-                    /* See if keymap has changed. */
-
-                    static unsigned int last_seed;
-                    unsigned int this_seed;
-
-                    this_seed = DarwinModeSystemKeymapSeed();
-                    if (this_seed != last_seed)
-                    {
-                        last_seed = this_seed;
-                        DarwinKeyboardReload(darwinKeyboard);
-                    }
-                }
-                /* fall through */
-
             case KeyRelease:
-                xe.u.u.detail += MIN_KEYCODE;
-                (*darwinEventQueue.pKbd->processInputProc)
-                    (&xe, (DeviceIntPtr)darwinEventQueue.pKbd, 1);
-                break;
+	      ErrorF("Unexpected Keyboard event in DarwinProcessInputEvents\n");
+	      break;
 
             case ButtonPress:
-                miPointerAbsoluteCursor(xe.u.keyButtonPointer.rootX,
-                                        xe.u.keyButtonPointer.rootY,
-                                        xe.u.keyButtonPointer.time);
-                if (darwinFakeButtons && xe.u.u.detail == 1) {
-                    // Mimic multi-button mouse with modifier-clicks
-                    // If both sets of modifiers are pressed,
-                    // button 2 is clicked.
-                    if ((old_flags & darwinFakeMouse2Mask) ==
-                        darwinFakeMouse2Mask)
-                    {
-                        DarwinSimulateMouseClick(&xe, 2, darwinFakeMouse2Mask);
-                        darwinFakeMouseButtonDown = 2;
-                        darwinFakeMouseButtonMask = darwinFakeMouse2Mask;
-                        break;
-                    }
-                    else if ((old_flags & darwinFakeMouse3Mask) ==
-                             darwinFakeMouse3Mask)
-                    {
-                        DarwinSimulateMouseClick(&xe, 3, darwinFakeMouse3Mask);
-                        darwinFakeMouseButtonDown = 3;
-                        darwinFakeMouseButtonMask = darwinFakeMouse3Mask;
-                        break;
-                    }
-                }
-                (*darwinEventQueue.pPtr->processInputProc)
-                        (&xe, (DeviceIntPtr)darwinEventQueue.pPtr, 1);
+	      ErrorF("Unexpected ButtonPress event in DarwinProcessInputEvents\n");
                 break;
 
             case ButtonRelease:
-                miPointerAbsoluteCursor(xe.u.keyButtonPointer.rootX,
-                                        xe.u.keyButtonPointer.rootY,
-                                        xe.u.keyButtonPointer.time);
-                if (darwinFakeButtons && xe.u.u.detail == 1 &&
-                    darwinFakeMouseButtonDown)
-                {
-                    // If last mousedown was a fake click, don't check for
-                    // mouse modifiers here. The user may have released the
-                    // modifiers before the mouse button.
-                    xe.u.u.detail = darwinFakeMouseButtonDown;
-                    darwinFakeMouseButtonDown = 0;
-                    (*darwinEventQueue.pPtr->processInputProc)
-                            (&xe, (DeviceIntPtr)darwinEventQueue.pPtr, 1);
-
-                    // Bring modifiers back up to date
-                    DarwinUpdateModifiers(&xe, KeyPress,
-                            darwinFakeMouseButtonMask & old_flags);
-                    darwinFakeMouseButtonMask = 0;
-                } else {
-                    (*darwinEventQueue.pPtr->processInputProc)
-                            (&xe, (DeviceIntPtr)darwinEventQueue.pPtr, 1);
-                }
+	      ErrorF("Unexpected ButtonRelease event in DarwinProcessInputEvents\n");
                 break;
 
             case MotionNotify:
-                miPointerAbsoluteCursor(xe.u.keyButtonPointer.rootX,
-                                        xe.u.keyButtonPointer.rootY,
-                                        xe.u.keyButtonPointer.time);
+	      ErrorF("Unexpected ButtonRelease event in DarwinProcessInputEvents\n");
                 break;
 
             case kXDarwinUpdateModifiers:
-            {
-                // Update modifier state.
-                // Any amount of modifiers may have changed.
-                int flags = xe.u.clientMessage.u.l.longs0;
-                DarwinUpdateModifiers(&xe, KeyRelease,
-                                      old_flags & ~flags);
-                DarwinUpdateModifiers(&xe, KeyPress,
-                                      ~old_flags & flags);
-                old_flags = flags;
-                break;
-            }
+	      ErrorF("Unexpected ButtonRelease event in DarwinProcessInputEvents\n");
+	      break;
 
             case kXDarwinUpdateButtons:
-            {
-                long hwDelta = xe.u.clientMessage.u.l.longs0;
-                long hwButtons = xe.u.clientMessage.u.l.longs1;
-                int i;
-
-                for (i = 1; i < 5; i++) {
-                    if (hwDelta & (1 << i)) {
-                        // IOKit and X have different numbering for the
-                        // middle and right mouse buttons.
-                        if (i == 1) {
-                            xe.u.u.detail = 3;
-                        } else if (i == 2) {
-                            xe.u.u.detail = 2;
-                        } else {
-                            xe.u.u.detail = i + 1;
-                        }
-                        if (hwButtons & (1 << i)) {
-                            xe.u.u.type = ButtonPress;
-                        } else {
-                            xe.u.u.type = ButtonRelease;
-                        }
-                        (*darwinEventQueue.pPtr->processInputProc)
-                    (&xe, (DeviceIntPtr)darwinEventQueue.pPtr, 1);
-                    }
-                }
-                break;
-            }
+	      ErrorF("Unexpected XDarwinScrollWheel event in DarwinProcessInputEvents\n");
+	      break;
 
-            case kXDarwinScrollWheel:
-            {
-                short count = xe.u.clientMessage.u.s.shorts0;
-
-                if (count > 0) {
-                    xe.u.u.detail = SCROLLWHEELUPFAKE;
-                } else {
-                    xe.u.u.detail = SCROLLWHEELDOWNFAKE;
-                    count = -count;
-                }
-
-                for (; count; --count) {
-                    xe.u.u.type = ButtonPress;
-                    (*darwinEventQueue.pPtr->processInputProc)
-                            (&xe, (DeviceIntPtr)darwinEventQueue.pPtr, 1);
-                    xe.u.u.type = ButtonRelease;
-                    (*darwinEventQueue.pPtr->processInputProc)
-                            (&xe, (DeviceIntPtr)darwinEventQueue.pPtr, 1);
-                }
-                break;
-            }
+            case kXDarwinScrollWheel: 
+	      ErrorF("Unexpected XDarwinScrollWheel event in DarwinProcessInputEvents\n");
+	      break;
 
             default:
                 // Check for mode specific event
@@ -475,7 +351,7 @@ void ProcessInputEvents(void) {
         }
     }
 
-    miPointerUpdate();
+    //    miPointerUpdate();
 }
 
 /* Sends a null byte down darwinEventWriteFD, which will cause the
@@ -488,18 +364,58 @@ void DarwinPokeEQ(void) {
 }
 
 void DarwinSendPointerEvents(int ev_type, int ev_button, int pointer_x, int pointer_y) {
-  int i;
+  static int darwinFakeMouseButtonDown = 0;
+  static int darwinFakeMouseButtonMask = 0;
+  int i, num_events;
   int valuators[2] = {pointer_x, pointer_y};
-  int num_events = GetPointerEvents(darwinEvents, darwinPointer, ev_type, ev_button, 
-				    POINTER_ABSOLUTE, 0, 2, valuators);
+  if (ev_type == ButtonPress && darwinFakeButtons && ev_button == 1) {
+    // Mimic multi-button mouse with modifier-clicks
+    // If both sets of modifiers are pressed,
+    // button 2 is clicked.
+    if ((old_flags & darwinFakeMouse2Mask) == darwinFakeMouse2Mask) {
+      DarwinSimulateMouseClick(pointer_x, pointer_y, 2, darwinFakeMouse2Mask);
+      darwinFakeMouseButtonDown = 2;
+      darwinFakeMouseButtonMask = darwinFakeMouse2Mask;
+    } else if ((old_flags & darwinFakeMouse3Mask) == darwinFakeMouse3Mask) {
+      DarwinSimulateMouseClick(pointer_x, pointer_y, 3, darwinFakeMouse3Mask);
+      darwinFakeMouseButtonDown = 3;
+      darwinFakeMouseButtonMask = darwinFakeMouse3Mask;
+    }
+  }
+  if (ev_type == ButtonRelease && darwinFakeButtons && darwinFakeMouseButtonDown) {
+    // If last mousedown was a fake click, don't check for
+    // mouse modifiers here. The user may have released the
+    // modifiers before the mouse button.
+    ev_button = darwinFakeMouseButtonDown;
+    darwinFakeMouseButtonDown = 0;
+    // Bring modifiers back up to date
+    DarwinUpdateModifiers(KeyPress, darwinFakeMouseButtonMask & old_flags);
+    darwinFakeMouseButtonMask = 0;
+  } 
+
+  num_events = GetPointerEvents(darwinEvents, darwinPointer, ev_type, ev_button, 
+				POINTER_ABSOLUTE, 0, 2, valuators);
       
   for(i=0; i<num_events; i++) mieqEnqueue (darwinPointer,&darwinEvents[i]);
   DarwinPokeEQ();
 }
 
 void DarwinSendKeyboardEvents(int ev_type, int keycode) {
-  int i;
-  int num_events = GetKeyboardEvents(darwinEvents, darwinKeyboard, ev_type, keycode + MIN_KEYCODE);
+  int i, num_events;
+  if (old_flags == 0 && darwinSyncKeymap && darwinKeymapFile == NULL) {
+    /* See if keymap has changed. */
+
+    static unsigned int last_seed;
+    unsigned int this_seed;
+
+    this_seed = DarwinModeSystemKeymapSeed();
+    if (this_seed != last_seed) {
+      last_seed = this_seed;
+      DarwinKeyboardReload(darwinKeyboard);
+    }
+  }
+
+  num_events = GetKeyboardEvents(darwinEvents, darwinKeyboard, ev_type, keycode + MIN_KEYCODE);
   for(i=0; i<num_events; i++) mieqEnqueue(darwinKeyboard,&darwinEvents[i]);
   DarwinPokeEQ();
 }
@@ -520,3 +436,11 @@ void DarwinSendScrollEvents(float count,
   }
   DarwinPokeEQ();
 }
+
+/* Send the appropriate KeyPress/KeyRelease events to GetKeyboardEvents to
+   reflect changing modifier flags (alt, control, meta, etc) */
+void DarwinUpdateModKeys(int flags) {
+  DarwinUpdateModifiers(KeyRelease, old_flags & ~flags);
+  DarwinUpdateModifiers(KeyPress, ~old_flags & flags);
+  old_flags = flags;
+}
diff-tree d5aba03feff41722c72b4c6193f09d141cbf1678 (from 0ccd1443fd6db397b42e5b99ce733ce1316c785e)
Author: Drew Parsons <dparsons at debian.org>
Date:   Tue Mar 6 23:53:23 2007 +1100

    Xprint: shorten font filename to fit in tar length limit
    
    The length of the Xprint font file NewCenturySchlbk-BoldItalic.pmf
    pushes the full path over the traditional 100 character limit for
    tarballs (when module version number is included).  Shorten it to
    NewCentSchlbk-BoldItal.pmf to get back below the limit and rename
    other font files in that family to match.

diff --git a/hw/xprint/config/C/print/models/CANONC3200-PS/fonts/Makefile.am b/hw/xprint/config/C/print/models/CANONC3200-PS/fonts/Makefile.am
index c574c5c..7a7ecc3 100644
--- a/hw/xprint/config/C/print/models/CANONC3200-PS/fonts/Makefile.am
+++ b/hw/xprint/config/C/print/models/CANONC3200-PS/fonts/Makefile.am
@@ -19,10 +19,10 @@ XPFONTS = \
         LubalinGraph-BookOblique.pmf \
         LubalinGraph-Demi.pmf \
         LubalinGraph-DemiOblique.pmf \
-        NewCenturySchlbk-Bold.pmf \
-        NewCenturySchlbk-BoldItalic.pmf \
-        NewCenturySchlbk-Italic.pmf \
-        NewCenturySchlbk-Roman.pmf \
+        NewCentSchlbk-Bold.pmf \
+        NewCentSchlbk-BoldItal.pmf \
+        NewCentSchlbk-Ital.pmf \
+        NewCentSchlbk-Roman.pmf \
         Souvenir-Demi.pmf \
         Souvenir-DemiItalic.pmf \
         Souvenir-Light.pmf \
diff --git a/hw/xprint/config/C/print/models/HPLJ4050-PS/fonts/Makefile.am b/hw/xprint/config/C/print/models/HPLJ4050-PS/fonts/Makefile.am
index 634db1f..f4f4243 100644
--- a/hw/xprint/config/C/print/models/HPLJ4050-PS/fonts/Makefile.am
+++ b/hw/xprint/config/C/print/models/HPLJ4050-PS/fonts/Makefile.am
@@ -19,10 +19,10 @@ XPFONTS = \
         LubalinGraph-BookOblique.pmf \
         LubalinGraph-Demi.pmf \
         LubalinGraph-DemiOblique.pmf \
-        NewCenturySchlbk-Bold.pmf \
-        NewCenturySchlbk-BoldItalic.pmf \
-        NewCenturySchlbk-Italic.pmf \
-        NewCenturySchlbk-Roman.pmf \
+        NewCentSchlbk-Bold.pmf \
+        NewCentSchlbk-BoldItal.pmf \
+        NewCentSchlbk-Ital.pmf \
+        NewCentSchlbk-Roman.pmf \
         Souvenir-Demi.pmf \
         Souvenir-DemiItalic.pmf \
         Souvenir-Light.pmf \
diff --git a/hw/xprint/config/C/print/models/PSdefault/fonts/Makefile.am b/hw/xprint/config/C/print/models/PSdefault/fonts/Makefile.am
index 1e8c8a7..40f1e3d 100644
--- a/hw/xprint/config/C/print/models/PSdefault/fonts/Makefile.am
+++ b/hw/xprint/config/C/print/models/PSdefault/fonts/Makefile.am
@@ -17,10 +17,10 @@ dist_xpc_DATA =				\
 	LubalinGraph-Book.pmf		\
 	LubalinGraph-DemiOblique.pmf	\
 	LubalinGraph-Demi.pmf		\
-	NewCenturySchlbk-Bold.pmf	\
-	NewCenturySchlbk-BoldItalic.pmf \
-	NewCenturySchlbk-Italic.pmf	\
-	NewCenturySchlbk-Roman.pmf	\
+	NewCentSchlbk-Bold.pmf		\
+	NewCentSchlbk-BoldItal.pmf 	\
+	NewCentSchlbk-Ital.pmf		\
+	NewCentSchlbk-Roman.pmf		\
 	Souvenir-DemiItalic.pmf		\
 	Souvenir-Demi.pmf		\
 	Souvenir-LightItalic.pmf	\
diff --git a/hw/xprint/config/C/print/models/PSdefault/fonts/NewCentSchlbk-Bold.pmf b/hw/xprint/config/C/print/models/PSdefault/fonts/NewCentSchlbk-Bold.pmf
new file mode 100644
index 0000000..ab22aab
Binary files /dev/null and b/hw/xprint/config/C/print/models/PSdefault/fonts/NewCentSchlbk-Bold.pmf differ
diff --git a/hw/xprint/config/C/print/models/PSdefault/fonts/NewCentSchlbk-BoldItal.pmf b/hw/xprint/config/C/print/models/PSdefault/fonts/NewCentSchlbk-BoldItal.pmf
new file mode 100644
index 0000000..e68811e
Binary files /dev/null and b/hw/xprint/config/C/print/models/PSdefault/fonts/NewCentSchlbk-BoldItal.pmf differ
diff --git a/hw/xprint/config/C/print/models/PSdefault/fonts/NewCentSchlbk-Ital.pmf b/hw/xprint/config/C/print/models/PSdefault/fonts/NewCentSchlbk-Ital.pmf
new file mode 100644
index 0000000..390f223
Binary files /dev/null and b/hw/xprint/config/C/print/models/PSdefault/fonts/NewCentSchlbk-Ital.pmf differ
diff --git a/hw/xprint/config/C/print/models/PSdefault/fonts/NewCentSchlbk-Roman.pmf b/hw/xprint/config/C/print/models/PSdefault/fonts/NewCentSchlbk-Roman.pmf
new file mode 100644
index 0000000..655b9b6
Binary files /dev/null and b/hw/xprint/config/C/print/models/PSdefault/fonts/NewCentSchlbk-Roman.pmf differ
diff --git a/hw/xprint/config/C/print/models/PSdefault/fonts/NewCenturySchlbk-Bold.pmf b/hw/xprint/config/C/print/models/PSdefault/fonts/NewCenturySchlbk-Bold.pmf
deleted file mode 100644
index ab22aab..0000000
Binary files a/hw/xprint/config/C/print/models/PSdefault/fonts/NewCenturySchlbk-Bold.pmf and /dev/null differ
diff --git a/hw/xprint/config/C/print/models/PSdefault/fonts/NewCenturySchlbk-BoldItalic.pmf b/hw/xprint/config/C/print/models/PSdefault/fonts/NewCenturySchlbk-BoldItalic.pmf
deleted file mode 100644
index e68811e..0000000
Binary files a/hw/xprint/config/C/print/models/PSdefault/fonts/NewCenturySchlbk-BoldItalic.pmf and /dev/null differ
diff --git a/hw/xprint/config/C/print/models/PSdefault/fonts/NewCenturySchlbk-Italic.pmf b/hw/xprint/config/C/print/models/PSdefault/fonts/NewCenturySchlbk-Italic.pmf
deleted file mode 100644
index 390f223..0000000
Binary files a/hw/xprint/config/C/print/models/PSdefault/fonts/NewCenturySchlbk-Italic.pmf and /dev/null differ
diff --git a/hw/xprint/config/C/print/models/PSdefault/fonts/NewCenturySchlbk-Roman.pmf b/hw/xprint/config/C/print/models/PSdefault/fonts/NewCenturySchlbk-Roman.pmf
deleted file mode 100644
index 655b9b6..0000000
Binary files a/hw/xprint/config/C/print/models/PSdefault/fonts/NewCenturySchlbk-Roman.pmf and /dev/null differ
diff-tree 3206e9225897989638ad553e1f392b918ac4d21f (from 0ccd1443fd6db397b42e5b99ce733ce1316c785e)
Author: Ben Byer <bbyer at bbyer.(none)>
Date:   Tue Mar 6 02:31:59 2007 -0800

    moved new event-handling code from X11Application.m to darwinEvents.c in preparation for making all Darwin servers use it

diff --git a/hw/darwin/apple/X11Application.m b/hw/darwin/apple/X11Application.m
index cfc9750..34c0307 100644
--- a/hw/darwin/apple/X11Application.m
+++ b/hw/darwin/apple/X11Application.m
@@ -855,48 +855,6 @@ convert_flags (unsigned int nsflags) {
     return xflags;
 }
 
-/* Sends a null byte down darwinEventWriteFD, which will cause the
-   Dispatch() event loop to check out event queue */
-void DarwinPokeEQ(void) {
-  char nullbyte=0;
-  input_check_flag++;
-  //  <daniels> bushing: oh, i ... er ... christ.
-  write(darwinEventWriteFD, &nullbyte, 1);
-}
-
-void DarwinSendPointerEvents(int ev_type, int ev_button, int pointer_x, int pointer_y) {
-  int i;
-  int valuators[2] = {pointer_x, pointer_y};
-  int num_events = GetPointerEvents(darwinEvents, darwinPointer, ev_type, ev_button, 
-				    POINTER_ABSOLUTE, 0, 2, valuators);
-      
-  for(i=0; i<num_events; i++) mieqEnqueue (darwinPointer,&darwinEvents[i]);
-  DarwinPokeEQ();
-}
-
-void DarwinSendKeyboardEvents(int ev_type, int keycode) {
-  int i;
-  int num_events = GetKeyboardEvents(darwinEvents, darwinKeyboard, ev_type, keycode + MIN_KEYCODE);
-  for(i=0; i<num_events; i++) mieqEnqueue(darwinKeyboard,&darwinEvents[i]);
-  DarwinPokeEQ();
-}
-
-/* Send the appropriate number of button 4 / 5 clicks to emulate scroll wheel */
-void DarwinSendScrollEvents(float count, int pointer_x, int pointer_y) {
-  int i;
-  int ev_button = count > 0.0f ? 4 : 5;
-  int valuators[2] = {pointer_x, pointer_y};
-
-  for (count = fabs(count); count > 0.0; count = count - 1.0f) {
-    int num_events = GetPointerEvents(darwinEvents, darwinPointer, ButtonPress, ev_button, 
-				      POINTER_ABSOLUTE, 0, 2, valuators);
-    for(i=0; i<num_events; i++) mieqEnqueue(darwinPointer,&darwinEvents[i]);
-    num_events = GetPointerEvents(darwinEvents, darwinPointer, ButtonRelease, ev_button, 
-				      POINTER_ABSOLUTE, 0, 2, valuators);
-    for(i=0; i<num_events; i++) mieqEnqueue(darwinPointer,&darwinEvents[i]);
-  }
-  DarwinPokeEQ();
-}
 
 // This code should probably be merged with that in XDarwin's XServer.m - BB
 static void send_nsevent (NSEventType type, NSEvent *e) {
diff --git a/hw/darwin/darwinEvents.c b/hw/darwin/darwinEvents.c
index ac03e5a..cb30a90 100644
--- a/hw/darwin/darwinEvents.c
+++ b/hw/darwin/darwinEvents.c
@@ -477,3 +477,46 @@ void ProcessInputEvents(void) {
 
     miPointerUpdate();
 }
+
+/* Sends a null byte down darwinEventWriteFD, which will cause the
+   Dispatch() event loop to check out event queue */
+void DarwinPokeEQ(void) {
+  char nullbyte=0;
+  input_check_flag++;
+  //  <daniels> bushing: oh, i ... er ... christ.
+  write(darwinEventWriteFD, &nullbyte, 1);
+}
+
+void DarwinSendPointerEvents(int ev_type, int ev_button, int pointer_x, int pointer_y) {
+  int i;
+  int valuators[2] = {pointer_x, pointer_y};
+  int num_events = GetPointerEvents(darwinEvents, darwinPointer, ev_type, ev_button, 
+				    POINTER_ABSOLUTE, 0, 2, valuators);
+      
+  for(i=0; i<num_events; i++) mieqEnqueue (darwinPointer,&darwinEvents[i]);
+  DarwinPokeEQ();
+}
+
+void DarwinSendKeyboardEvents(int ev_type, int keycode) {
+  int i;
+  int num_events = GetKeyboardEvents(darwinEvents, darwinKeyboard, ev_type, keycode + MIN_KEYCODE);
+  for(i=0; i<num_events; i++) mieqEnqueue(darwinKeyboard,&darwinEvents[i]);
+  DarwinPokeEQ();
+}
+
+/* Send the appropriate number of button 4 / 5 clicks to emulate scroll wheel */
+void DarwinSendScrollEvents(float count, int pointer_x, int pointer_y) {
+  int i;
+  int ev_button = count > 0.0f ? 4 : 5;
+  int valuators[2] = {pointer_x, pointer_y};
+
+  for (count = fabs(count); count > 0.0; count = count - 1.0f) {
+    int num_events = GetPointerEvents(darwinEvents, darwinPointer, ButtonPress, ev_button, 
+				      POINTER_ABSOLUTE, 0, 2, valuators);
+    for(i=0; i<num_events; i++) mieqEnqueue(darwinPointer,&darwinEvents[i]);
+    num_events = GetPointerEvents(darwinEvents, darwinPointer, ButtonRelease, ev_button, 
+				      POINTER_ABSOLUTE, 0, 2, valuators);
+    for(i=0; i<num_events; i++) mieqEnqueue(darwinPointer,&darwinEvents[i]);
+  }
+  DarwinPokeEQ();
+}
diff-tree 0ccd1443fd6db397b42e5b99ce733ce1316c785e (from parents)
Merge: ec1ef8a56d6217ca2b04899043874ce0bcad9784 9b6bb06f13a71f6078f762b4a78fa516faccb638
Author: Ben Byer <bbyer at bbyer.(none)>
Date:   Tue Mar 6 01:04:50 2007 -0800

    Merge branch 'master' of git+ssh://bbyer@git.freedesktop.org/git/xorg/xserver

diff-tree ec1ef8a56d6217ca2b04899043874ce0bcad9784 (from 33d2cf93fb50464941e74efe246b10aee212223a)
Author: Ben Byer <bbyer at bbyer.(none)>
Date:   Tue Mar 6 00:57:23 2007 -0800

    Fixed Darwin's Makefile.am to fix a problem building X11.app

diff --git a/hw/darwin/Makefile.am b/hw/darwin/Makefile.am
index 75d028e..3e28d32 100644
--- a/hw/darwin/Makefile.am
+++ b/hw/darwin/Makefile.am
@@ -112,7 +112,7 @@ macos_PROGRAMS = XDarwinApp
 macos_SCRIPTS = x11app
 
 x11app:
-	cd apple && xcodebuild
+	cd apple && xcodebuild CFLAGS="$(XSERVERCFLAGS_CFLAGS)" LDFLAGS="$(XSERVERCFLAGS_LIBS)"
 
 XDarwinApp_SOURCES = \
                 $(top_srcdir)/fb/fbcmap.c \
@@ -275,7 +275,7 @@ install-data-hook: $(HOOK_TARGETS)
 
 xquartz-install-hook:
 	mv $(DESTDIR)$(macosdir)/XDarwinApp $(DESTDIR)$(macosdir)/XDarwin
-        cd apple && xcodebuild CFLAGS="$(XSERVERCFLAGS_CFLAGS)" LDFLAGS="$(XSERVERCFLAGS_LIBS)"
+	cd apple && xcodebuild install
 
 EXTRA_DIST = \
 	darwin.c \
diff-tree 9b6bb06f13a71f6078f762b4a78fa516faccb638 (from bed76caa6caaea6a6598755b82a54425a9d9f73e)
Author: Keith Packard <keithp at guitar.keithp.com>
Date:   Mon Mar 5 23:49:35 2007 -0800

    Allow relative positions to use output names or monitor identifiers.
    
    Previous version used monitor identifiers if present, otherwise output
    names. That caused existing working configurations to break when additional
    information was added to the configuration file.
    (cherry picked from commit 3f5cedf00a82f08a433c95ffbb7f8ac69dcf6a50)

diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c
index c38da62..46515fd 100644
--- a/hw/xfree86/modes/xf86Crtc.c
+++ b/hw/xfree86/modes/xf86Crtc.c
@@ -879,13 +879,17 @@ xf86InitialOutputPositions (ScrnInfoPtr 
 		{
 		    xf86OutputPtr	out_rel = config->output[or];
 		    XF86ConfMonitorPtr	rel_mon = out_rel->conf_monitor;
-		    char		*name;
 
 		    if (rel_mon)
-			name = rel_mon->mon_identifier;
-		    else
-			name = out_rel->name;
-		    if (!strcmp (relative_name, name))
+		    {
+			if (xf86nameCompare (rel_mon->mon_identifier,
+					      relative_name) == 0)
+			{
+			    relative = config->output[or];
+			    break;
+			}
+		    }
+		    if (strcmp (out_rel->name, relative_name) == 0)
 		    {
 			relative = config->output[or];
 			break;
diff-tree bed76caa6caaea6a6598755b82a54425a9d9f73e (from 47f8361c3a64834587e54507653d8d5b258c2530)
Author: Keith Packard <keithp at guitar.keithp.com>
Date:   Mon Mar 5 23:36:00 2007 -0800

    Use EDID data to set screen physical size at server startup.
    
    Screen physical size is set to a random value before the RandR code gets
    control, override that and reset it to a value based on the compat_output
    physical size (if available). If that output has no physical size, just use
    96dpi as the default resolution and set the physical size as appropriate.
    (cherry picked from commit 843077f23a1b49bd712d931421753e3a09d4008c)

diff --git a/hw/xfree86/modes/xf86RandR12.c b/hw/xfree86/modes/xf86RandR12.c
index 052d12a..ce780b6 100644
--- a/hw/xfree86/modes/xf86RandR12.c
+++ b/hw/xfree86/modes/xf86RandR12.c
@@ -422,8 +422,28 @@ xf86RandR12CreateScreenResources (Screen
 	}
 	else
 	{
-	    mmWidth = pScreen->mmWidth;
-	    mmHeight = pScreen->mmHeight;
+	    xf86OutputPtr   output = config->output[config->compat_output];
+	    xf86CrtcPtr	    crtc = output->crtc;
+
+	    if (crtc && crtc->mode.HDisplay &&
+		output->mm_width && output->mm_height)
+	    {
+		/*
+		 * If the output has a mode and a declared size, use that
+		 * to scale the screen size
+		 */
+		DisplayModePtr	mode = &crtc->mode;
+		mmWidth = output->mm_width * width / mode->HDisplay;
+		mmHeight = output->mm_height * height / mode->VDisplay;
+	    }
+	    else
+	    {
+		/*
+		 * Otherwise, just set the screen to 96dpi
+		 */
+		mmWidth = width * 25.4 / 96;
+		mmHeight = height * 25.4 / 96;
+	    }
 	}
 	xf86DrvMsg(pScrn->scrnIndex, X_INFO,
 		   "Setting screen physical size to %d x %d\n",
diff-tree 47f8361c3a64834587e54507653d8d5b258c2530 (from 33d2cf93fb50464941e74efe246b10aee212223a)
Author: Keith Packard <keithp at guitar.keithp.com>
Date:   Mon Mar 5 22:07:01 2007 -0800

    Add xf86SetDesiredModes to apply desired modes to crtcs.
    
    xf86SetDesiredModes applies the desired modes to each crtc (as selected by
    xf86InitialConfiguration initially and modified by successful mode settings
    afterwards). For crtcs without a desired mode, pScrn->currentMode is used to
    select something workable.
    (cherry picked from commit bcade98ccaa18298d844a606cb44271f0254c185)

diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c
index 3d28293..c38da62 100644
--- a/hw/xfree86/modes/xf86Crtc.c
+++ b/hw/xfree86/modes/xf86Crtc.c
@@ -1542,6 +1542,63 @@ xf86InitialConfiguration (ScrnInfoPtr sc
     return TRUE;
 }
 
+/*
+ * Using the desired mode information in each crtc, set
+ * modes (used in EnterVT functions, or at server startup)
+ */
+
+Bool
+xf86SetDesiredModes (ScrnInfoPtr scrn)
+{
+    xf86CrtcConfigPtr   config = XF86_CRTC_CONFIG_PTR(scrn);
+    int			c;
+
+    for (c = 0; c < config->num_crtc; c++)
+    {
+	xf86CrtcPtr	crtc = config->crtc[c];
+	xf86OutputPtr	output = NULL;
+	int		o;
+
+	if (config->output[config->compat_output]->crtc == crtc)
+	    output = config->output[config->compat_output];
+	else
+	{
+	    for (o = 0; o < config->num_output; o++)
+		if (config->output[o]->crtc == crtc)
+		{
+		    output = config->output[o];
+		    break;
+		}
+	}
+	/*
+	 * Skip disabled crtcs
+	 */
+	if (!output)
+	    continue;
+
+	/* Mark that we'll need to re-set the mode for sure */
+	memset(&crtc->mode, 0, sizeof(crtc->mode));
+	if (!crtc->desiredMode.CrtcHDisplay)
+	{
+	    DisplayModePtr  mode = xf86OutputFindClosestMode (output, scrn->currentMode);
+
+	    if (!mode)
+		return FALSE;
+	    crtc->desiredMode = *mode;
+	    crtc->desiredRotation = RR_Rotate_0;
+	    crtc->desiredX = 0;
+	    crtc->desiredY = 0;
+	}
+
+	if (!xf86CrtcSetMode (crtc, &crtc->desiredMode, crtc->desiredRotation,
+			      crtc->desiredX, crtc->desiredY))
+	    return FALSE;
+    }
+
+    xf86DisableUnusedFunctions(scrn);
+    return TRUE;
+}
+
 /**
  * In the current world order, there are lists of modes per output, which may
  * or may not include the mode that was asked to be set by XFree86's mode
diff --git a/hw/xfree86/modes/xf86Crtc.h b/hw/xfree86/modes/xf86Crtc.h
index 56c7769..062a2db 100644
--- a/hw/xfree86/modes/xf86Crtc.h
+++ b/hw/xfree86/modes/xf86Crtc.h
@@ -644,4 +644,12 @@ xf86CrtcSetScreenSubpixelOrder (ScreenPt
 char *
 xf86ConnectorGetName(xf86ConnectorType connector);
 
+/*
+ * Using the desired mode information in each crtc, set
+ * modes (used in EnterVT functions, or at server startup)
+ */
+
+Bool
+xf86SetDesiredModes (ScrnInfoPtr pScrn);
+
 #endif /* _XF86CRTC_H_ */
diff --git a/hw/xfree86/modes/xf86Rename.h b/hw/xfree86/modes/xf86Rename.h
index 6cfa5ca..eae6d64 100644
--- a/hw/xfree86/modes/xf86Rename.h
+++ b/hw/xfree86/modes/xf86Rename.h
@@ -76,5 +76,8 @@
 #define xf86CrtcSetScreenSubpixelOrder XF86NAME(xf86CrtcSetScreenSubpixelOrder)
 #define xf86ModeWidth XF86NAME(xf86ModeWidth)
 #define xf86ModeHeight XF86NAME(xf86ModeHeight)
+#define xf86OutputFindClosestMode XF86NAME(xf86OutputFindClosestMode)
+#define xf86SetSingleMode XF86NAME(xf86SetSingleMode)
+#define xf86SetDesiredModes XF86NAME(xf86SetDesiredModes)
 
 #endif /* _XF86RENAME_H_ */
diff-tree 33d2cf93fb50464941e74efe246b10aee212223a (from 689d52b6242434507a64a8fff27b01607628c393)
Author: Keith Packard <keithp at neko.keithp.com>
Date:   Sat Mar 3 23:10:31 2007 -0800

    Move xf86SetSingleMode into X server from intel driver.
    
    This function applies a single mode to the screen (as from RandR 1.1,
    XFree86-VidModeExtension or XFree86-DGA) using a policy that selects one
    output to reconfigure to the requested mode and then makes all other outputs
    fit within that size.
    (cherry picked from commit 5a595c1f767a8d666348b845d18934aee0cfe38f)

diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c
index 2ffa956..3d28293 100644
--- a/hw/xfree86/modes/xf86Crtc.c
+++ b/hw/xfree86/modes/xf86Crtc.c
@@ -1543,6 +1543,132 @@ xf86InitialConfiguration (ScrnInfoPtr sc
 }
 
 /**
+ * In the current world order, there are lists of modes per output, which may
+ * or may not include the mode that was asked to be set by XFree86's mode
+ * selection.  Find the closest one, in the following preference order:
+ *
+ * - Equality
+ * - Closer in size to the requested mode, but no larger
+ * - Closer in refresh rate to the requested mode.
+ */
+
+DisplayModePtr
+xf86OutputFindClosestMode (xf86OutputPtr output, DisplayModePtr desired)
+{
+    DisplayModePtr	best = NULL, scan = NULL;
+
+    for (scan = output->probed_modes; scan != NULL; scan = scan->next) 
+    {
+	/* If there's an exact match, we're done. */
+	if (xf86ModesEqual(scan, desired)) {
+	    best = desired;
+	    break;
+	}
+
+	/* Reject if it's larger than the desired mode. */
+	if (scan->HDisplay > desired->HDisplay || 
+	    scan->VDisplay > desired->VDisplay)
+	{
+	    continue;
+	}
+
+	/*
+	 * If we haven't picked a best mode yet, use the first
+	 * one in the size range
+	 */
+	if (best == NULL) 
+	{
+	    best = scan;
+	    continue;
+	}
+
+	/* Find if it's closer to the right size than the current best
+	 * option.
+	 */
+	if ((scan->HDisplay > best->HDisplay &&
+	     scan->VDisplay >= best->VDisplay) ||
+	    (scan->HDisplay >= best->HDisplay &&
+	     scan->VDisplay > best->VDisplay))
+	{
+	    best = scan;
+	    continue;
+	}
+
+	/* Find if it's still closer to the right refresh than the current
+	 * best resolution.
+	 */
+	if (scan->HDisplay == best->HDisplay &&
+	    scan->VDisplay == best->VDisplay &&
+	    (fabs(scan->VRefresh - desired->VRefresh) <
+	     fabs(best->VRefresh - desired->VRefresh))) {
+	    best = scan;
+	}
+    }
+    return best;
+}
+
+/**
+ * When setting a mode through XFree86-VidModeExtension or XFree86-DGA,
+ * take the specified mode and apply it to the crtc connected to the compat
+ * output. Then, find similar modes for the other outputs, as with the
+ * InitialConfiguration code above. The goal is to clone the desired
+ * mode across all outputs that are currently active.
+ */
+
+Bool
+xf86SetSingleMode (ScrnInfoPtr pScrn, DisplayModePtr desired, Rotation rotation)
+{
+    xf86CrtcConfigPtr	config = XF86_CRTC_CONFIG_PTR(pScrn);
+    Bool		ok = TRUE;
+    xf86OutputPtr	compat_output = config->output[config->compat_output];
+    DisplayModePtr	compat_mode;
+    int			c;
+
+    /*
+     * Let the compat output drive the final mode selection
+     */
+    compat_mode = xf86OutputFindClosestMode (compat_output, desired);
+    if (compat_mode)
+	desired = compat_mode;
+    
+    for (c = 0; c < config->num_crtc; c++)
+    {
+	xf86CrtcPtr	crtc = config->crtc[c];
+	DisplayModePtr	crtc_mode = NULL;
+	int		o;
+
+	if (!crtc->enabled)
+	    continue;
+	
+	for (o = 0; o < config->num_output; o++)
+	{
+	    xf86OutputPtr   output = config->output[o];
+	    DisplayModePtr  output_mode;
+
+	    /* skip outputs not on this crtc */
+	    if (output->crtc != crtc)
+		continue;
+	    
+	    if (crtc_mode)
+	    {
+		output_mode = xf86OutputFindClosestMode (output, crtc_mode);
+		if (output_mode != crtc_mode)
+		    output->crtc = NULL;
+	    }
+	    else
+		crtc_mode = xf86OutputFindClosestMode (output, desired);
+	}
+	if (!xf86CrtcSetMode (crtc, crtc_mode, rotation, 0, 0))
+	    ok = FALSE;
+	else
+	    crtc->desiredMode = *crtc_mode;
+    }
+    xf86DisableUnusedFunctions(pScrn);
+    return ok;
+}
+
+
+/**
  * Set the DPMS power mode of all outputs and CRTCs.
  *
  * If the new mode is off, it will turn off outputs and then CRTCs.
diff --git a/hw/xfree86/modes/xf86Crtc.h b/hw/xfree86/modes/xf86Crtc.h
index 537df3a..56c7769 100644
--- a/hw/xfree86/modes/xf86Crtc.h
+++ b/hw/xfree86/modes/xf86Crtc.h
@@ -594,6 +594,12 @@ xf86SaveScreen(ScreenPtr pScreen, int mo
 void
 xf86DisableUnusedFunctions(ScrnInfoPtr pScrn);
 
+DisplayModePtr
+xf86OutputFindClosestMode (xf86OutputPtr output, DisplayModePtr desired);
+    
+Bool
+xf86SetSingleMode (ScrnInfoPtr pScrn, DisplayModePtr desired, Rotation rotation);
+
 /**
  * Set the EDID information for the specified output
  */
diff-tree 689d52b6242434507a64a8fff27b01607628c393 (from fe7b8f4237874e3e45fe25a6bf06faddfa1ab8e1)
Author: Jens Granseuer <jensgr at gmx.net>
Date:   Mon Mar 5 15:31:44 2007 -0800

    Bugzilla #7145: fix build with gcc 2.95
    
    Bugzilla #7145: <http://bugs.freedesktop.org/show_bug.cgi?id=7145>
    Patch #8987: <http://bugs.freedesktop.org/attachment.cgi?id=8987>

diff --git a/GL/glx/glxcmdsswap.c b/GL/glx/glxcmdsswap.c
index d59dfdb..1857bc1 100644
--- a/GL/glx/glxcmdsswap.c
+++ b/GL/glx/glxcmdsswap.c
@@ -496,11 +496,11 @@ int __glXDispSwap_CopySubBufferMESA(__GL
     GLXDrawable		 *drawId;
     int			 *buffer;
 
+    __GLX_DECLARE_SWAP_VARIABLES;
+
     (void) drawId;
     (void) buffer;
 
-    __GLX_DECLARE_SWAP_VARIABLES;
-
     pc += __GLX_VENDPRIV_HDR_SIZE;
 
     __GLX_SWAP_SHORT(&req->length);
diff --git a/randr/rrcrtc.c b/randr/rrcrtc.c
index 1f7462f..db506f4 100644
--- a/randr/rrcrtc.c
+++ b/randr/rrcrtc.c
@@ -490,7 +490,7 @@ RRCrtcInit (void)
 int
 ProcRRGetCrtcInfo (ClientPtr client)
 {
-    REQUEST(xRRGetCrtcInfoReq);;
+    REQUEST(xRRGetCrtcInfoReq);
     xRRGetCrtcInfoReply	rep;
     RRCrtcPtr			crtc;
     CARD8			*extra;
diff --git a/randr/rroutput.c b/randr/rroutput.c
index a664330..df1741f 100644
--- a/randr/rroutput.c
+++ b/randr/rroutput.c
@@ -366,7 +366,7 @@ RROutputInit (void)
 int
 ProcRRGetOutputInfo (ClientPtr client)
 {
-    REQUEST(xRRGetOutputInfoReq);;
+    REQUEST(xRRGetOutputInfoReq);
     xRRGetOutputInfoReply	rep;
     RROutputPtr			output;
     CARD8			*extra;
diff --git a/randr/rrpointer.c b/randr/rrpointer.c
index 802dcb2..c88a0f8 100644
--- a/randr/rrpointer.c
+++ b/randr/rrpointer.c
@@ -103,7 +103,7 @@ void
 RRPointerMoved (ScreenPtr pScreen, int x, int y)
 {
     rrScrPriv (pScreen);
-    RRCrtcPtr	pointerCrtc = pScrPriv->pointerCrtc;;
+    RRCrtcPtr	pointerCrtc = pScrPriv->pointerCrtc;
     int	c;
 
     /* Check last known CRTC */
diff-tree fe7b8f4237874e3e45fe25a6bf06faddfa1ab8e1 (from 537dc5ecde46d0525c503d1d2b39b6eb89a1298e)
Author: Ben Byer <bbyer at bbyer.(none)>
Date:   Mon Mar 5 03:48:27 2007 -0800

    began to factor out code to move to darwinEvents.c

diff --git a/hw/darwin/apple/X11Application.m b/hw/darwin/apple/X11Application.m
index c50f704..cfc9750 100644
--- a/hw/darwin/apple/X11Application.m
+++ b/hw/darwin/apple/X11Application.m
@@ -855,21 +855,58 @@ convert_flags (unsigned int nsflags) {
     return xflags;
 }
 
+/* Sends a null byte down darwinEventWriteFD, which will cause the
+   Dispatch() event loop to check out event queue */
+void DarwinPokeEQ(void) {
+  char nullbyte=0;
+  input_check_flag++;
+  //  <daniels> bushing: oh, i ... er ... christ.
+  write(darwinEventWriteFD, &nullbyte, 1);
+}
+
+void DarwinSendPointerEvents(int ev_type, int ev_button, int pointer_x, int pointer_y) {
+  int i;
+  int valuators[2] = {pointer_x, pointer_y};
+  int num_events = GetPointerEvents(darwinEvents, darwinPointer, ev_type, ev_button, 
+				    POINTER_ABSOLUTE, 0, 2, valuators);
+      
+  for(i=0; i<num_events; i++) mieqEnqueue (darwinPointer,&darwinEvents[i]);
+  DarwinPokeEQ();
+}
+
+void DarwinSendKeyboardEvents(int ev_type, int keycode) {
+  int i;
+  int num_events = GetKeyboardEvents(darwinEvents, darwinKeyboard, ev_type, keycode + MIN_KEYCODE);
+  for(i=0; i<num_events; i++) mieqEnqueue(darwinKeyboard,&darwinEvents[i]);
+  DarwinPokeEQ();
+}
+
+/* Send the appropriate number of button 4 / 5 clicks to emulate scroll wheel */
+void DarwinSendScrollEvents(float count, int pointer_x, int pointer_y) {
+  int i;
+  int ev_button = count > 0.0f ? 4 : 5;
+  int valuators[2] = {pointer_x, pointer_y};
+
+  for (count = fabs(count); count > 0.0; count = count - 1.0f) {
+    int num_events = GetPointerEvents(darwinEvents, darwinPointer, ButtonPress, ev_button, 
+				      POINTER_ABSOLUTE, 0, 2, valuators);
+    for(i=0; i<num_events; i++) mieqEnqueue(darwinPointer,&darwinEvents[i]);
+    num_events = GetPointerEvents(darwinEvents, darwinPointer, ButtonRelease, ev_button, 
+				      POINTER_ABSOLUTE, 0, 2, valuators);
+    for(i=0; i<num_events; i++) mieqEnqueue(darwinPointer,&darwinEvents[i]);
+  }
+  DarwinPokeEQ();
+}
+
 // This code should probably be merged with that in XDarwin's XServer.m - BB
 static void send_nsevent (NSEventType type, NSEvent *e) {
-    static unsigned int button_state = 0;
+  //    static unsigned int button_state = 0;
     NSRect screen;
     NSPoint location;
     NSWindow *window;
     int pointer_x, pointer_y, ev_button, ev_type; 
-    int num_events=0, i=0, state;
-    int valuators[2];
-    float count;
+    //    int num_events=0, i=0, state;
     xEvent xe;
-    char nullbyte=0;
-
-    bzero(&xe, sizeof(xe));
-    input_check_flag++;
 	
     /* convert location to global top-left coordinates */
     location = [e locationInWindow];
@@ -886,11 +923,8 @@ static void send_nsevent (NSEventType ty
       pointer_y = (screen.origin.y + screen.size.height) - location.y;
     }
     
-//    ErrorF("send_nsevent: type=%d pointer=(%d,%d)\n", type, pointer_x, pointer_y);
-    
-    valuators[0] = pointer_x;
-    valuators[1] = pointer_y - aquaMenuBarHeight;
-    state = convert_flags ([e modifierFlags]);
+    pointer_y -= aquaMenuBarHeight;
+    //    state = convert_flags ([e modifierFlags]);
     
     switch (type) {
     case NSLeftMouseDown:    ev_button=1; ev_type=ButtonPress; goto handle_mouse;
@@ -905,50 +939,34 @@ static void send_nsevent (NSEventType ty
     case NSMouseMoved: ev_button=0; ev_type=MotionNotify; goto handle_mouse;
     handle_mouse:
       
-      if(ev_type==ButtonPress) {
+      /* I'm not sure the below code is necessary or useful (-bb)
+	if(ev_type==ButtonPress) {
 	if (!quartzProcs->IsX11Window([e window], [e windowNumber])) {
 	  fprintf(stderr, "Dropping event because it's not a window\n");
 	  break;
 	}
 	button_state |= (1 << ev_button);
+	DarwinSendPointerEvents(ev_type, ev_button, pointer_x, pointer_y);
       } else if (ev_type==ButtonRelease && (button_state & (1 << ev_button)) == 0) break;
-      
-      num_events = GetPointerEvents(darwinEvents, darwinPointer, ev_type, ev_button, 
-				    POINTER_ABSOLUTE, 0, 2, valuators);
-      
-      for(i=0; i<num_events; i++)
-	mieqEnqueue (darwinPointer,&darwinEvents[i]);
+      */
+      DarwinSendPointerEvents(ev_type, ev_button, pointer_x, pointer_y);
       break;
     case NSScrollWheel: 
-      count = [e deltaY];
-      ev_button = count > 0.0f ? 4 : 5;
-      for (count = fabs(count); count > 0.0; count = count - 1.0f) {
-	num_events = GetPointerEvents(darwinEvents, darwinPointer, ButtonPress, ev_button, 
-				      POINTER_ABSOLUTE, 0, 2, valuators);
-	for(i=0; i<num_events; i++) 
-	  mieqEnqueue(darwinPointer,&darwinEvents[i]);
-	num_events = GetPointerEvents(darwinEvents, darwinPointer, ButtonRelease, ev_button, 
-				      POINTER_ABSOLUTE, 0, 2, valuators);
-	for(i=0; i<num_events; i++)
-	  mieqEnqueue(darwinPointer,&darwinEvents[i]);
-      }
+      DarwinSendScrollEvents([e deltaY], pointer_x, pointer_y);
       break;
       
     case NSKeyDown:  // do we need to translate these keyCodes?
     case NSKeyUp:
-      num_events = GetKeyboardEvents(darwinEvents, darwinKeyboard, 
-				     (type == NSKeyDown)?KeyPress:KeyRelease, [e keyCode]);
-      for(i=0; i<num_events; i++) 
-	mieqEnqueue(darwinKeyboard,&darwinEvents[i]);
+      DarwinSendKeyboardEvents((type == NSKeyDown)?KeyPress:KeyRelease, [e keyCode]);
       break;
 
     case NSFlagsChanged:
+      bzero(&xe, sizeof(xe));
       xe.u.u.type = kXDarwinUpdateModifiers;
       xe.u.clientMessage.u.l.longs0 = [e modifierFlags];
       DarwinEQEnqueue (&xe);
+      DarwinPokeEQ();
       break;
     default: break; /* for gcc */
     }	
-    //  <daniels> bushing: oh, i ... er ... christ.
-    write(darwinEventWriteFD, &nullbyte, 1);
 }
diff --git a/hw/darwin/darwin.h b/hw/darwin/darwin.h
index 48a2224..fc4a58a 100644
--- a/hw/darwin/darwin.h
+++ b/hw/darwin/darwin.h
@@ -58,6 +58,10 @@ Bool DarwinEQInit(DevicePtr pKbd, Device
 void DarwinEQEnqueue(const xEvent *e);
 void DarwinEQPointerPost(xEvent *e);
 void DarwinEQSwitchScreen(ScreenPtr pScreen, Bool fromDIX);
+void DarwinPokeEQ(void);
+void DarwinSendPointerEvents(int ev_type, int ev_button, int pointer_x, int pointer_y);
+void DarwinSendKeyboardEvents(int ev_type, int keycode);
+void DarwinSendScrollEvents(float count, int pointer_x, int pointer_y);
 
 // From darwinKeyboard.c
 int DarwinModifierNXKeyToNXKeycode(int key, int side);
diff --git a/hw/darwin/darwinEvents.c b/hw/darwin/darwinEvents.c
index 1eb2336..ac03e5a 100644
--- a/hw/darwin/darwinEvents.c
+++ b/hw/darwin/darwinEvents.c
@@ -269,7 +269,7 @@ void ProcessInputEvents(void) {
     static int darwinFakeMouseButtonMask = 0;
     input_check_flag=0;
 
-    ErrorF("calling mieqProcessInputEvents\n");
+    //    ErrorF("calling mieqProcessInputEvents\n");
     mieqProcessInputEvents();
 
     // Empty the signaling pipe
@@ -292,12 +292,12 @@ void ProcessInputEvents(void) {
         xe.u.keyButtonPointer.rootY -= darwinMainScreenY +
                 dixScreenOrigins[miPointerCurrentScreen()->myNum].y;
 	
-	ErrorF("old rootX = (%d,%d) darwinMainScreen = (%d,%d) dixScreenOrigins[%d]=(%d,%d)\n",
+	/*	ErrorF("old rootX = (%d,%d) darwinMainScreen = (%d,%d) dixScreenOrigins[%d]=(%d,%d)\n",
 	       xe.u.keyButtonPointer.rootX, xe.u.keyButtonPointer.rootY,
 	       darwinMainScreenX, darwinMainScreenY,
 	       miPointerCurrentScreen()->myNum,
 	       dixScreenOrigins[miPointerCurrentScreen()->myNum].x,
-	       dixScreenOrigins[miPointerCurrentScreen()->myNum].y);
+	       dixScreenOrigins[miPointerCurrentScreen()->myNum].y); */
 
 	//Assumption - screen switching can only occur on motion events
 
diff-tree 537dc5ecde46d0525c503d1d2b39b6eb89a1298e (from 8ba5e8d82014b774a52f3e050ddbbb8bde4e0933)
Author: Ben Byer <bbyer at bbyer.(none)>
Date:   Mon Mar 5 02:30:56 2007 -0800

    started moving new input code into darwinEvents.c so that it may be shared by the three servers

diff --git a/hw/darwin/apple/X11Application.m b/hw/darwin/apple/X11Application.m
index 0be1e40..c50f704 100644
--- a/hw/darwin/apple/X11Application.m
+++ b/hw/darwin/apple/X11Application.m
@@ -56,7 +56,7 @@ extern int darwinFakeButtons, input_chec
 // extern Bool enable_stereo; 
 Bool enable_stereo;  //<-- this needs to go back to being an extern once glxCGL is fixed
 
-static xEvent *quartzEvents;
+extern xEvent *darwinEvents;
 
 X11Application *X11App;
 
@@ -805,7 +805,6 @@ void X11ApplicationMain (int argc, const
     pool = [[NSAutoreleasePool alloc] init];
 	
     X11App = (X11Application *) [X11Application sharedApplication];
-    quartzEvents = (xEvent *)malloc(sizeof(xEvent) * GetMaximumEventsNum());
 
     init_ports ();
 	
@@ -914,33 +913,33 @@ static void send_nsevent (NSEventType ty
 	button_state |= (1 << ev_button);
       } else if (ev_type==ButtonRelease && (button_state & (1 << ev_button)) == 0) break;
       
-      num_events = GetPointerEvents(quartzEvents, darwinPointer, ev_type, ev_button, 
+      num_events = GetPointerEvents(darwinEvents, darwinPointer, ev_type, ev_button, 
 				    POINTER_ABSOLUTE, 0, 2, valuators);
       
       for(i=0; i<num_events; i++)
-	mieqEnqueue (darwinPointer,&quartzEvents[i]);
+	mieqEnqueue (darwinPointer,&darwinEvents[i]);
       break;
     case NSScrollWheel: 
       count = [e deltaY];
       ev_button = count > 0.0f ? 4 : 5;
       for (count = fabs(count); count > 0.0; count = count - 1.0f) {
-	num_events = GetPointerEvents(quartzEvents, darwinPointer, ButtonPress, ev_button, 
+	num_events = GetPointerEvents(darwinEvents, darwinPointer, ButtonPress, ev_button, 
 				      POINTER_ABSOLUTE, 0, 2, valuators);
 	for(i=0; i<num_events; i++) 
-	  mieqEnqueue(darwinPointer,&quartzEvents[i]);
-	num_events = GetPointerEvents(quartzEvents, darwinPointer, ButtonRelease, ev_button, 
+	  mieqEnqueue(darwinPointer,&darwinEvents[i]);
+	num_events = GetPointerEvents(darwinEvents, darwinPointer, ButtonRelease, ev_button, 
 				      POINTER_ABSOLUTE, 0, 2, valuators);
 	for(i=0; i<num_events; i++)
-	  mieqEnqueue(darwinPointer,&quartzEvents[i]);
+	  mieqEnqueue(darwinPointer,&darwinEvents[i]);
       }
       break;
       
     case NSKeyDown:  // do we need to translate these keyCodes?
     case NSKeyUp:
-      num_events = GetKeyboardEvents(quartzEvents, darwinKeyboard, 
+      num_events = GetKeyboardEvents(darwinEvents, darwinKeyboard, 
 				     (type == NSKeyDown)?KeyPress:KeyRelease, [e keyCode]);
       for(i=0; i<num_events; i++) 
-	mieqEnqueue(darwinKeyboard,&quartzEvents[i]);
+	mieqEnqueue(darwinKeyboard,&darwinEvents[i]);
       break;
 
     case NSFlagsChanged:
diff --git a/hw/darwin/darwinEvents.c b/hw/darwin/darwinEvents.c
index 2a27ac4..1eb2336 100644
--- a/hw/darwin/darwinEvents.c
+++ b/hw/darwin/darwinEvents.c
@@ -74,6 +74,7 @@ typedef struct _EventQueue {
 } EventQueueRec, *EventQueuePtr;
 
 static EventQueueRec darwinEventQueue;
+xEvent *darwinEvents;
 
 /*
  * DarwinPressModifierMask
@@ -179,6 +180,7 @@ static void DarwinSimulateMouseClick(
 
 
 Bool DarwinEQInit(DevicePtr pKbd, DevicePtr pPtr) { 
+    darwinEvents = (xEvent *)malloc(sizeof(xEvent) * GetMaximumEventsNum());
     mieqInit();
     darwinEventQueue.head = darwinEventQueue.tail = 0;
     darwinEventQueue.lastEventTime = GetTimeInMillis ();
diff-tree 8ba5e8d82014b774a52f3e050ddbbb8bde4e0933 (from 2e31872e05c2408d53ba0182bcddc5dabb3615fe)
Author: Dave Airlie <airlied at linux.ie>
Date:   Mon Mar 5 13:46:41 2007 +1100

    add a standard connector type and name for us as an output property

diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c
index 8b13e2b..2ffa956 100644
--- a/hw/xfree86/modes/xf86Crtc.c
+++ b/hw/xfree86/modes/xf86Crtc.c
@@ -1738,3 +1738,12 @@ xf86OutputGetEDID (xf86OutputPtr output,
 
     return xf86DoEDID_DDC2 (scrn->scrnIndex, pDDCBus);
 }
+
+static char *_xf86ConnectorNames[] = { "None", "VGA", "DVI-I", "DVI-D",
+				      "DVI-A", "Composite", "S-Video",
+				      "Component", "LFP", "Proprietary" };
+char *
+xf86ConnectorGetName(xf86ConnectorType connector)
+{
+    return _xf86ConnectorNames[connector];
+}
diff --git a/hw/xfree86/modes/xf86Crtc.h b/hw/xfree86/modes/xf86Crtc.h
index c8aafc1..537df3a 100644
--- a/hw/xfree86/modes/xf86Crtc.h
+++ b/hw/xfree86/modes/xf86Crtc.h
@@ -41,6 +41,20 @@
 typedef struct _xf86Crtc xf86CrtcRec, *xf86CrtcPtr;
 typedef struct _xf86Output xf86OutputRec, *xf86OutputPtr;
 
+/* define a standard for connector types */
+typedef enum _xf86ConnectorType {
+   XF86ConnectorNone,
+   XF86ConnectorVGA,
+   XF86ConnectorDVI_I,
+   XF86ConnectorDVI_D,
+   XF86ConnectorDVI_A,
+   XF86ConnectorComposite,
+   XF86ConnectorSvideo,
+   XF86ConnectorComponent,
+   XF86ConnectorLFP,
+   XF86ConnectorProprietary,
+} xf86ConnectorType;
+
 typedef enum _xf86OutputStatus {
    XF86OutputStatusConnected,
    XF86OutputStatusDisconnected,
@@ -618,4 +632,10 @@ xf86DiDGAReInit (ScreenPtr pScreen);
 void
 xf86CrtcSetScreenSubpixelOrder (ScreenPtr pScreen);
 
+/*
+ * Get a standard string name for a connector type 
+ */
+char *
+xf86ConnectorGetName(xf86ConnectorType connector);
+
 #endif /* _XF86CRTC_H_ */
diff-tree 2e31872e05c2408d53ba0182bcddc5dabb3615fe (from 06b01186f6ae17aafdd1f628c306466ddea9e065)
Author: Dave Airlie <airlied at linux.ie>
Date:   Mon Feb 26 09:40:00 2007 +1100

    modes: add commit/prepare hooks

diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c
index c53d2a8..8b13e2b 100644
--- a/hw/xfree86/modes/xf86Crtc.c
+++ b/hw/xfree86/modes/xf86Crtc.c
@@ -282,7 +282,7 @@ xf86CrtcSetMode (xf86CrtcPtr crtc, Displ
 	goto done;
     }
 
-    /* Disable the outputs and CRTCs before setting the mode. */
+    /* Prepare the outputs and CRTCs before setting the mode. */
     for (i = 0; i < xf86_config->num_output; i++) {
 	xf86OutputPtr output = xf86_config->output[i];
 
@@ -290,10 +290,10 @@ xf86CrtcSetMode (xf86CrtcPtr crtc, Displ
 	    continue;
 
 	/* Disable the output as the first thing we do. */
-	output->funcs->dpms(output, DPMSModeOff);
+	output->funcs->prepare(output);
     }
 
-    crtc->funcs->dpms(crtc, DPMSModeOff);
+    crtc->funcs->prepare(crtc);
 
     /* Set up the DPLL and any output state that needs to adjust or depend
      * on the DPLL.
@@ -307,12 +307,12 @@ xf86CrtcSetMode (xf86CrtcPtr crtc, Displ
     }
 
     /* Now, enable the clocks, plane, pipe, and outputs that we set up. */
-    crtc->funcs->dpms(crtc, DPMSModeOn);
+    crtc->funcs->commit(crtc);
     for (i = 0; i < xf86_config->num_output; i++) 
     {
 	xf86OutputPtr output = xf86_config->output[i];
 	if (output->crtc == crtc)
-	    output->funcs->dpms(output, DPMSModeOn);
+	    output->funcs->commit(output);
     }
 
     /* XXX free adjustedmode */
diff --git a/hw/xfree86/modes/xf86Crtc.h b/hw/xfree86/modes/xf86Crtc.h
index b04f7f3..c8aafc1 100644
--- a/hw/xfree86/modes/xf86Crtc.h
+++ b/hw/xfree86/modes/xf86Crtc.h
@@ -97,6 +97,12 @@ typedef struct _xf86CrtcFuncs {
 		  DisplayModePtr adjusted_mode);
 
     /**
+     * Prepare CRTC for an upcoming mode set.
+     */
+    void
+    (*prepare)(xf86CrtcPtr crtc);
+
+    /**
      * Callback for setting up a video mode after fixups have been made.
      */
     void
@@ -105,6 +111,12 @@ typedef struct _xf86CrtcFuncs {
 		DisplayModePtr adjusted_mode,
 		int x, int y);
 
+    /**
+     * Commit mode changes to a CRTC
+     */
+    void
+    (*commit)(xf86CrtcPtr crtc);
+
     /* Set the color ramps for the CRTC to the given values. */
     void
     (*gamma_set)(xf86CrtcPtr crtc, CARD16 *red, CARD16 *green, CARD16 *blue,
@@ -264,6 +276,18 @@ typedef struct _xf86OutputFuncs {
 		  DisplayModePtr adjusted_mode);
 
     /**
+     * Callback for preparing mode changes on an output
+     */
+    void
+    (*prepare)(xf86OutputPtr output);
+
+    /**
+     * Callback for committing mode changes on an output
+     */
+    void
+    (*commit)(xf86OutputPtr output);
+
+    /**
      * Callback for setting up a video mode after fixups have been made.
      *
      * This is only called while the output is disabled.  The dpms callback
diff-tree 06b01186f6ae17aafdd1f628c306466ddea9e065 (from c14507b6837387d867792a24778786311b2b38d5)
Author: Keith Packard <keithp at neko.keithp.com>
Date:   Sun Mar 4 17:15:24 2007 -0800

    Remove debugging ErrorF from rotation code.
    (cherry picked from commit e6af7569f201842b4754aec6e72b30dc2daefdfb)

diff --git a/hw/xfree86/modes/xf86Rotate.c b/hw/xfree86/modes/xf86Rotate.c
index ef637ee..6826b62 100644
--- a/hw/xfree86/modes/xf86Rotate.c
+++ b/hw/xfree86/modes/xf86Rotate.c
@@ -143,10 +143,9 @@ xf86RotateCrtcRedisplay (xf86CrtcPtr crt
 			 &include_inferiors,
 			 serverClient,
 			 &error);
-    if (!src) {
-	ErrorF("couldn't create src pict\n");
+    if (!src)
 	return;
-    }
+
     dst = CreatePicture (None,
 			 &dst_pixmap->drawable,
 			 format,
@@ -154,10 +153,8 @@ xf86RotateCrtcRedisplay (xf86CrtcPtr crt
 			 NULL,
 			 serverClient,
 			 &error);
-    if (!dst) {
-	ErrorF("couldn't create src pict\n");
+    if (!dst)
 	return;
-    }
 
     memset (&transform, '\0', sizeof (transform));
     transform.matrix[2][2] = IntToxFixed(1);
@@ -198,17 +195,13 @@ xf86RotateCrtcRedisplay (xf86CrtcPtr crt
     }
 
     error = SetPictureTransform (src, &transform);
-    if (error) {
-	ErrorF("Couldn't set transform\n");
+    if (error)
 	return;
-    }
 
     while (n--)
     {
 	BoxRec	dst_box;
 
-	ErrorF ("painting %d,%d - %d,%d\n",
-		b->x1, b->y1, b->x2, b->y2);
 	xf86TransformBox (&dst_box, b, crtc->rotation,
 			  crtc->x, crtc->y,
 			  crtc->mode.HDisplay, crtc->mode.VDisplay);
@@ -235,8 +228,6 @@ xf86CrtcDamageShadow (xf86CrtcPtr crtc)
     damage_box.x2 = crtc->x + xf86ModeWidth (&crtc->mode, crtc->rotation);
     damage_box.y1 = crtc->y;
     damage_box.y2 = crtc->y + xf86ModeHeight (&crtc->mode, crtc->rotation);
-    ErrorF ("damaged %d,%d - %d,%d\n",
-	    damage_box.x1, damage_box.y1, damage_box.x2, damage_box.y2);
     REGION_INIT (pScreen, &damage_region, &damage_box, 1);
     DamageDamageRegion (&(*pScreen->GetScreenPixmap)(pScreen)->drawable,
 			&damage_region);
diff-tree c14507b6837387d867792a24778786311b2b38d5 (from 97978b515b7af5fbaaa32b1729e835f3bfb9f5c6)
Author: Keith Packard <keithp at neko.keithp.com>
Date:   Sun Mar 4 17:06:37 2007 -0800

    Handle non-zero origin rotated crtc. Damage crtc area on re-rotate.
    
    Box transformation from source to dest area was broken, leaving the wrong
    areas painted when the crtc origin was non-zero.
    
    When rotating from left to right, the pixmap doesn't get reallocated, and so
    no damage was left in the pixmap from xf86RotatePrepare. Separately damage
    the whole crtc area when this occurs to repaint the area.
    (cherry picked from commit 2a50ca2160bc05af1c24421ec079e902ff730277)

diff --git a/hw/xfree86/modes/xf86Rotate.c b/hw/xfree86/modes/xf86Rotate.c
index 7b20498..ef637ee 100644
--- a/hw/xfree86/modes/xf86Rotate.c
+++ b/hw/xfree86/modes/xf86Rotate.c
@@ -69,31 +69,44 @@ compWindowFormat (WindowPtr pWin)
 }
 
 static void
-xf86RotateBox (BoxPtr dst, BoxPtr src, Rotation rotation,
-	       int dest_width, int dest_height)
+xf86TranslateBox (BoxPtr b, int dx, int dy)
 {
+    b->x1 += dx;
+    b->y1 += dy;
+    b->x2 += dx;
+    b->y2 += dy;
+}
+
+static void
+xf86TransformBox (BoxPtr dst, BoxPtr src, Rotation rotation,
+		  int xoff, int yoff,
+		  int dest_width, int dest_height)
+{
+    BoxRec  stmp = *src;
+    
+    xf86TranslateBox (&stmp, -xoff, -yoff);
     switch (rotation & 0xf) {
     default:
     case RR_Rotate_0:
-	*dst = *src;
+	*dst = stmp;
 	break;
     case RR_Rotate_90:
-	dst->x1 = src->y1;
-	dst->y1 = dest_height - src->x2;
-	dst->x2 = src->y2;
-	dst->y2 = dest_height - src->x1;
+	dst->x1 = stmp.y1;
+	dst->y1 = dest_height - stmp.x2;
+	dst->x2 = stmp.y2;
+	dst->y2 = dest_height - stmp.x1;
 	break;
     case RR_Rotate_180:
-	dst->x1 = dest_width - src->x2;
-	dst->y1 = dest_height - src->y2;
-	dst->x2 = dest_width - src->x1;
-	dst->y2 = dest_height - src->y1;
+	dst->x1 = dest_width - stmp.x2;
+	dst->y1 = dest_height - stmp.y2;
+	dst->x2 = dest_width - stmp.x1;
+	dst->y2 = dest_height - stmp.y1;
 	break;
     case RR_Rotate_270:
-	dst->x1 = dest_width - src->y2;
-	dst->y1 = src->x1;
-	dst->y2 = src->x2;
-	dst->x2 = dest_width - src->y1;
+	dst->x1 = dest_width - stmp.y2;
+	dst->y1 = stmp.x1;
+	dst->y2 = stmp.x2;
+	dst->x2 = dest_width - stmp.y1;
 	break;
     }
     if (rotation & RR_Reflect_X) {
@@ -194,8 +207,11 @@ xf86RotateCrtcRedisplay (xf86CrtcPtr crt
     {
 	BoxRec	dst_box;
 
-	xf86RotateBox (&dst_box, b, crtc->rotation,
-		       crtc->mode.HDisplay, crtc->mode.VDisplay);
+	ErrorF ("painting %d,%d - %d,%d\n",
+		b->x1, b->y1, b->x2, b->y2);
+	xf86TransformBox (&dst_box, b, crtc->rotation,
+			  crtc->x, crtc->y,
+			  crtc->mode.HDisplay, crtc->mode.VDisplay);
 	CompositePicture (PictOpSrc,
 			  src, NULL, dst,
 			  dst_box.x1, dst_box.y1, 0, 0, dst_box.x1, dst_box.y1,
@@ -208,6 +224,26 @@ xf86RotateCrtcRedisplay (xf86CrtcPtr crt
 }
 
 static void
+xf86CrtcDamageShadow (xf86CrtcPtr crtc)
+{
+    ScrnInfoPtr	pScrn = crtc->scrn;
+    BoxRec	damage_box;
+    RegionRec   damage_region;
+    ScreenPtr	pScreen = pScrn->pScreen;
+
+    damage_box.x1 = crtc->x;
+    damage_box.x2 = crtc->x + xf86ModeWidth (&crtc->mode, crtc->rotation);
+    damage_box.y1 = crtc->y;
+    damage_box.y2 = crtc->y + xf86ModeHeight (&crtc->mode, crtc->rotation);
+    ErrorF ("damaged %d,%d - %d,%d\n",
+	    damage_box.x1, damage_box.y1, damage_box.x2, damage_box.y2);
+    REGION_INIT (pScreen, &damage_region, &damage_box, 1);
+    DamageDamageRegion (&(*pScreen->GetScreenPixmap)(pScreen)->drawable,
+			&damage_region);
+    REGION_UNINIT (pScreen, &damage_region);
+}
+
+static void
 xf86RotatePrepare (ScreenPtr pScreen)
 {
     ScrnInfoPtr		pScrn = xf86Screens[pScreen->myNum];
@@ -220,9 +256,6 @@ xf86RotatePrepare (ScreenPtr pScreen)
 	
 	if (crtc->rotatedData && !crtc->rotatedPixmap)
 	{
-	    BoxRec	    damage_box;
-	    RegionRec   damage_region;
-
 	    crtc->rotatedPixmap = crtc->funcs->shadow_create (crtc,
 							     crtc->rotatedData,
 							     crtc->mode.HDisplay,
@@ -231,14 +264,7 @@ xf86RotatePrepare (ScreenPtr pScreen)
 	    DamageRegister (&(*pScreen->GetScreenPixmap)(pScreen)->drawable,
 			    xf86_config->rotationDamage);
 	    
-	    damage_box.x1 = 0;
-	    damage_box.y1 = 0;
-	    damage_box.x2 = xf86ModeWidth (&crtc->mode, crtc->rotation);
-	    damage_box.y2 = xf86ModeHeight (&crtc->mode, crtc->rotation);
-	    REGION_INIT (pScreen, &damage_region, &damage_box, 1);
-	    DamageDamageRegion (&(*pScreen->GetScreenPixmap)(pScreen)->drawable,
-				&damage_region);
-	    REGION_UNINIT (pScreen, &damage_region);
+	    xf86CrtcDamageShadow (crtc);
 	}
     }
 }
@@ -357,6 +383,12 @@ xf86CrtcRotate (xf86CrtcPtr crtc, Displa
 	    if (!shadowData)
 		goto bail1;
 	    crtc->rotatedData = shadowData;
+	    /* shadow will be damaged in xf86RotatePrepare */
+	}
+	else
+	{
+	    /* mark shadowed area as damaged so it will be repainted */
+	    xf86CrtcDamageShadow (crtc);
 	}
 	
 	if (!xf86_config->rotationDamage)
diff-tree 97978b515b7af5fbaaa32b1729e835f3bfb9f5c6 (from 215e3691b76a63e6af19865790193b20b105ec5a)
Author: Drew Parsons <drew at pug.localdomain>
Date:   Sun Mar 4 16:28:54 2007 +1100

    Xprint: fix font symlinks
    
    Change symlinks to Xprint base fonts in model/PSdefault using local
    relative links.  This facilitates moving the Xprint config files, for
    instance for FHS compliance placing data files in /usr/share rather
    than /usr/lib.  Also ensures NewCenturySchlbk-BoldItalic.pmf is
    installed.

diff --git a/hw/xprint/config/C/print/models/CANONC3200-PS/fonts/Makefile.am b/hw/xprint/config/C/print/models/CANONC3200-PS/fonts/Makefile.am
index 5be5419..c574c5c 100644
--- a/hw/xprint/config/C/print/models/CANONC3200-PS/fonts/Makefile.am
+++ b/hw/xprint/config/C/print/models/CANONC3200-PS/fonts/Makefile.am
@@ -1,6 +1,6 @@
 xpcdir = @xpconfigdir@/C/print/models/CANONC3200-PS/fonts
 
-parentdir = @xpconfigdir@/C/print/models/PSdefault/fonts
+parentdir = ../../PSdefault/fonts
 
 XPFONTS = \
         AvantGarde-Book.pmf \
diff --git a/hw/xprint/config/C/print/models/HPLJ4050-PS/fonts/Makefile.am b/hw/xprint/config/C/print/models/HPLJ4050-PS/fonts/Makefile.am
index 2ff9ab7..634db1f 100644
--- a/hw/xprint/config/C/print/models/HPLJ4050-PS/fonts/Makefile.am
+++ b/hw/xprint/config/C/print/models/HPLJ4050-PS/fonts/Makefile.am
@@ -1,6 +1,6 @@
 xpcdir = @xpconfigdir@/C/print/models/HPLJ4050-PS/fonts
 
-parentdir = @xpconfigdir@/C/print/models/PSdefault/fonts
+parentdir = ../../PSdefault/fonts
 
 XPFONTS = \
         AvantGarde-Book.pmf \
diff --git a/hw/xprint/config/C/print/models/PSdefault/fonts/Makefile.am b/hw/xprint/config/C/print/models/PSdefault/fonts/Makefile.am
index e7ddb6c..1e8c8a7 100644
--- a/hw/xprint/config/C/print/models/PSdefault/fonts/Makefile.am
+++ b/hw/xprint/config/C/print/models/PSdefault/fonts/Makefile.am
@@ -18,6 +18,7 @@ dist_xpc_DATA =				\
 	LubalinGraph-DemiOblique.pmf	\
 	LubalinGraph-Demi.pmf		\
 	NewCenturySchlbk-Bold.pmf	\
+	NewCenturySchlbk-BoldItalic.pmf \
 	NewCenturySchlbk-Italic.pmf	\
 	NewCenturySchlbk-Roman.pmf	\
 	Souvenir-DemiItalic.pmf		\
diff --git a/hw/xprint/config/C/print/models/SPSPARC2/fonts/Makefile.am b/hw/xprint/config/C/print/models/SPSPARC2/fonts/Makefile.am
index 8cc2694..d1ee6cf 100644
--- a/hw/xprint/config/C/print/models/SPSPARC2/fonts/Makefile.am
+++ b/hw/xprint/config/C/print/models/SPSPARC2/fonts/Makefile.am
@@ -1,6 +1,6 @@
 xpcdir = @xpconfigdir@/C/print/models/SPSPARC2/fonts
 
-parentdir = @xpconfigdir@/C/print/models/PSdefault/fonts
+parentdir = ../../PSdefault/fonts
 
 XPFONTS = \
         Courier-Bold.pmf \
diff-tree 215e3691b76a63e6af19865790193b20b105ec5a (from ea8dcc458ea8870126cf8d3e21cab9d63d094c5e)
Author: Ben Byer <bbyer at xyzzy.local>
Date:   Sat Mar 3 21:52:56 2007 -0800

    stopped using XTrans internals in X11.app because they're apparently no longer public

diff --git a/hw/darwin/apple/bundle-main.c b/hw/darwin/apple/bundle-main.c
index 12fb1bf..a35e1e3 100644
--- a/hw/darwin/apple/bundle-main.c
+++ b/hw/darwin/apple/bundle-main.c
@@ -601,10 +601,10 @@ display_exists_p (int number)
     int idisplay, iscreen;
     char *conn_auth_name, *conn_auth_data;
     int conn_auth_namelen, conn_auth_datalen;
-	
+#ifdef USE_XTRANS_INTERNALS	
     extern void *_X11TransConnectDisplay ();
     extern void _XDisconnectDisplay ();
-	
+#endif	
     /* Since connecting to the display waits for a few seconds if the
 	 display doesn't exist, check for trivial non-existence - if the
 	 socket in /tmp exists or not.. (note: if the socket exists, the
@@ -613,7 +613,7 @@ display_exists_p (int number)
     sprintf (buf, "/tmp/.X11-unix/X%d", number);
     if (access (buf, F_OK) != 0)
 		return FALSE;
-	
+#ifdef USE_XTRANS_INTERNALS	
     /* This is a private function that we shouldn't really be calling,
 	 but it's the best way to see if the server exists (without
 	 needing to hold the necessary authentication to use it) */
@@ -626,6 +626,7 @@ display_exists_p (int number)
 		return FALSE;
 	
     _XDisconnectDisplay (conn);
+#endif
     return TRUE;
 }
 
diff-tree ea8dcc458ea8870126cf8d3e21cab9d63d094c5e (from 18508212599bf0964c450c69b9790208e5d428be)
Author: Ben Byer <bbyer at xyzzy.local>
Date:   Sat Mar 3 21:51:20 2007 -0800

    Makefile fix for X11.app

diff --git a/hw/darwin/Makefile.am b/hw/darwin/Makefile.am
index 46642cd..75d028e 100644
--- a/hw/darwin/Makefile.am
+++ b/hw/darwin/Makefile.am
@@ -275,7 +275,7 @@ install-data-hook: $(HOOK_TARGETS)
 
 xquartz-install-hook:
 	mv $(DESTDIR)$(macosdir)/XDarwinApp $(DESTDIR)$(macosdir)/XDarwin
-	cd apple && xcodebuild install
+        cd apple && xcodebuild CFLAGS="$(XSERVERCFLAGS_CFLAGS)" LDFLAGS="$(XSERVERCFLAGS_LIBS)"
 
 EXTRA_DIST = \
 	darwin.c \
diff-tree 18508212599bf0964c450c69b9790208e5d428be (from 7f2b9f3790456044d01bf8e6404f9a1239b41da6)
Author: Ben Byer <bbyer at xyzzy.local>
Date:   Sat Mar 3 21:41:33 2007 -0800

    fixed X11.xcodeproj to get CFLAGS and LDFLAGS from autoconf script

diff --git a/hw/darwin/apple/X11.xcodeproj/project.pbxproj b/hw/darwin/apple/X11.xcodeproj/project.pbxproj
index 7ca75d4..2fef99b 100644
--- a/hw/darwin/apple/X11.xcodeproj/project.pbxproj
+++ b/hw/darwin/apple/X11.xcodeproj/project.pbxproj
@@ -224,15 +224,12 @@
 				DSTROOT = "$(DSTROOT)";
 				FRAMEWORK_SEARCH_PATHS = "";
 				GCC_SYMBOLS_PRIVATE_EXTERN = NO;
-				HEADER_SEARCH_PATHS = /usr/X11/include;
+				HEADER_SEARCH_PATHS = "";
 				INFOPLIST_FILE = Info.plist;
 				INSTALL_PATH = $DSTROOT/Applications/Utilties;
-				LIBRARY_SEARCH_PATHS = /usr/X11/lib;
-				OTHER_CFLAGS = "";
-				OTHER_LDFLAGS = (
-					"-lXau",
-					"-lX11",
-				);
+				LIBRARY_SEARCH_PATHS = "";
+				OTHER_CFLAGS = "$(CFLAGS)";
+				OTHER_LDFLAGS = "$(LDFLAGS)";
 				OTHER_REZFLAGS = "";
 				PRODUCT_NAME = X11;
 				SECTORDER_FLAGS = "";
@@ -252,15 +249,12 @@
 				DSTROOT = "$(DSTROOT)";
 				FRAMEWORK_SEARCH_PATHS = "";
 				GCC_SYMBOLS_PRIVATE_EXTERN = NO;
-				HEADER_SEARCH_PATHS = /usr/X11/include;
+				HEADER_SEARCH_PATHS = "";
 				INFOPLIST_FILE = Info.plist;
 				INSTALL_PATH = $DSTROOT/Applications/Utilties;
-				LIBRARY_SEARCH_PATHS = /usr/X11/lib;
-				OTHER_CFLAGS = "";
-				OTHER_LDFLAGS = (
-					"-lXau",
-					"-lX11",
-				);
+				LIBRARY_SEARCH_PATHS = "";
+				OTHER_CFLAGS = "$(CFLAGS)";
+				OTHER_LDFLAGS = "$(LDFLAGS)";
 				OTHER_REZFLAGS = "";
 				PRODUCT_NAME = X11;
 				SECTORDER_FLAGS = "";
@@ -279,15 +273,12 @@
 				DSTROOT = "$(DSTROOT)";
 				FRAMEWORK_SEARCH_PATHS = "";
 				GCC_SYMBOLS_PRIVATE_EXTERN = NO;
-				HEADER_SEARCH_PATHS = /usr/X11/include;
+				HEADER_SEARCH_PATHS = "";
 				INFOPLIST_FILE = Info.plist;
 				INSTALL_PATH = $DSTROOT/Applications/Utilties;
-				LIBRARY_SEARCH_PATHS = /usr/X11/lib;
-				OTHER_CFLAGS = "";
-				OTHER_LDFLAGS = (
-					"-lXau",
-					"-lX11",
-				);
+				LIBRARY_SEARCH_PATHS = "";
+				OTHER_CFLAGS = "$(CFLAGS)";
+				OTHER_LDFLAGS = "$(LDFLAGS)";
 				OTHER_REZFLAGS = "";
 				PRODUCT_NAME = X11;
 				SECTORDER_FLAGS = "";
diff-tree 7f2b9f3790456044d01bf8e6404f9a1239b41da6 (from ea1a72946d1aa4c256e6afb9d834c582ba4ac3a1)
Author: Ben Byer <bbyer at xyzzy.local>
Date:   Sat Mar 3 19:27:53 2007 -0800

    autoconf fixes for XDarwin (created DARWIN_LIBS)

diff --git a/configure.ac b/configure.ac
index 9386d87..fe77709 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1298,6 +1298,8 @@ return 0;}
 #               LDFLAGS=$save_LDFLAGS
 #               ])
                xorg_cv_AGL_framework=no
+	       DARWIN_LIBS="$FB_LIB $MI_LIB $FIXES_LIB $XEXT_LIB $DBE_LIB $XTRAP_LIB $RECORD_LIB $GLX_LIBS $RENDER_LIB $RANDR_LIB $DAMAGE_LIB $MIEXT_DAMAGE_LIB $MIEXT_SHADOW_LIB $XI_LIB $XKB_LIB $XKB_STUB_LIB $COMPOSITE_LIB $XPSTUBS_LIB $OS_LIB"
+	       AC_SUBST([DARWIN_LIBS])
                AC_CHECK_LIB([Xplugin],[xp_init],[:])
                AC_SUBST([APPLE_APPLICATIONS_DIR])
                CFLAGS="${CFLAGS} -D__DARWIN__"
diff --git a/hw/darwin/Makefile.am b/hw/darwin/Makefile.am
index 9b4628e..46642cd 100644
--- a/hw/darwin/Makefile.am
+++ b/hw/darwin/Makefile.am
@@ -17,7 +17,6 @@ SUBDIRS = \
 	  utils \
 	  .
 
-
 darwinappdir = @APPLE_APPLICATIONS_DIR@/XDarwin.app
 
 libdarwinShared_a_SOURCES = darwin.c \
@@ -62,25 +61,11 @@ XDarwin_LDADD = \
 		$(top_builddir)/dix/dixfonts.lo \
 		$(top_builddir)/dix/libdix.la \
 		$(top_builddir)/config/libconfig.a \
-		$(top_builddir)/os/libos.la \
 		./libdarwinShared.a \
 		./iokit/libiokit.a \
-		$(top_builddir)/dix/libxpstubs.la \
 		$(top_builddir)/miext/shadow/libshadow.la \
-		$(top_builddir)/fb/libfb.la \
-		$(top_builddir)/composite/libcomposite.la \
-		$(top_builddir)/damageext/libdamageext.la \
-		$(top_builddir)/miext/damage/libdamage.la \
-		$(top_builddir)/xfixes/libxfixes.la \
 		$(top_builddir)/miext/cw/libcw.la \
-		$(top_builddir)/Xext/libXext.la \
-		$(top_builddir)/xkb/libxkb.la \
-		$(top_builddir)/xkb/libxkbstubs.la \
-		$(top_builddir)/Xi/libXi.la \
-		$(top_builddir)/dbe/libdbe.la \
-		$(top_builddir)/record/librecord.la \
-		$(top_builddir)/XTrap/libxtrap.la \
-		$(XGLX_LIBS) \
+		$(DARWIN_LIBS) \
 		$(top_builddir)/miext/rootless/librootless.la \
 		$(top_builddir)/miext/rootless/safeAlpha/libsafeAlpha.la \
 		$(top_builddir)/miext/rootless/accel/librlAccel.la \
@@ -91,23 +76,10 @@ Xquartz_LDADD = \
 		$(top_builddir)/dix/dixfonts.lo \
 		$(top_builddir)/dix/libdix.la \
 		$(top_builddir)/config/libconfig.a \
-		$(top_builddir)/os/libos.la \
 		./libdarwinShared.a \
-		$(top_builddir)/dix/libxpstubs.la \
 		$(top_builddir)/miext/shadow/libshadow.la \
-		$(top_builddir)/fb/libfb.la \
-		$(top_builddir)/composite/libcomposite.la \
-		$(top_builddir)/damageext/libdamageext.la \
-		$(top_builddir)/miext/damage/libdamage.la \
-		$(top_builddir)/xfixes/libxfixes.la \
 		$(top_builddir)/miext/cw/libcw.la \
-		$(top_builddir)/Xext/libXext.la \
-		$(top_builddir)/xkb/libxkb.la \
-		$(top_builddir)/xkb/libxkbstubs.la \
-		$(top_builddir)/Xi/libXi.la \
-		$(top_builddir)/dbe/libdbe.la \
-		$(top_builddir)/record/librecord.la \
-		$(top_builddir)/XTrap/libxtrap.la \
+		$(DARWIN_LIBS) \
 		$(top_builddir)/miext/rootless/librootless.la \
 		$(top_builddir)/miext/rootless/safeAlpha/libsafeAlpha.la \
 		$(top_builddir)/miext/rootless/accel/librlAccel.la \
@@ -155,28 +127,14 @@ XDarwinApp_LDADD = \
 		./quartz/XApplication.o \
 		./libdarwinShared.a \
 		./quartz/libXQuartz.a \
-		$(top_builddir)/dix/libxpstubs.la \
 		 $(top_builddir)/miext/shadow/libshadow.la \
-		 $(top_builddir)/fb/libfb.la \
-		 $(top_builddir)/composite/libcomposite.la \
-		 $(top_builddir)/damageext/libdamageext.la \
-		 $(top_builddir)/miext/damage/libdamage.la \
-		 $(top_builddir)/xfixes/libxfixes.la \
 		 $(top_builddir)/miext/cw/libcw.la \
-		 $(top_builddir)/Xext/libXext.la \
-		 $(top_builddir)/xkb/libxkb.la \
-		 $(top_builddir)/xkb/libxkbstubs.la \
-		 $(top_builddir)/Xi/libXi.la \
-		 $(top_builddir)/dbe/libdbe.la \
-		 $(top_builddir)/record/librecord.la \
-		 $(top_builddir)/XTrap/libxtrap.la \
-		 $(XGLX_LIBS) \
+		 $(DARWIN_LIBS) \
 		 $(top_builddir)/miext/rootless/librootless.la \
 		 $(top_builddir)/miext/rootless/safeAlpha/libsafeAlpha.la \
 		 $(top_builddir)/miext/rootless/accel/librlAccel.la \
 		 @XORG_LIBS@ \
-		 $(XSERVER_LIBS) \
-		 $(top_builddir)/fb/libfb.la 
+		 $(XSERVER_LIBS)
 
 XDarwinApp_LDFLAGS =  \
 		 -XCClinker -Objc \
diff-tree ea1a72946d1aa4c256e6afb9d834c582ba4ac3a1 (from 04d15da95d608766c7832a7aa881be499c1395ba)
Author: Aaron Plattner <aplattner at nvidia.com>
Date:   Wed Feb 28 14:26:47 2007 -0800

    Add a canGrow argument to xf86InitialConfiguration.
    
    canGrow indicates to the DDX that the driver can enlarge the desktop via the
    xf86_config->funcs->resize hook.  If so, xf86InitialConfiguration will set
    virtual[XY] to match the configuration it chooses and will leave the crtc config
    size ranges alone.  If FALSE, it will bloat the screen to fit the largest probed
    mode and also set the crtc config max size to limit the desktop to the initial
    virtual[XY] size.

diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c
index ebc0f8f..c53d2a8 100644
--- a/hw/xfree86/modes/xf86Crtc.c
+++ b/hw/xfree86/modes/xf86Crtc.c
@@ -734,12 +734,16 @@ xf86PickCrtcs (ScrnInfoPtr	scrn,
 
 /*
  * Compute the virtual size necessary to place all of the available
- * crtcs in the specified configuration and also large enough to
- * resize any crtc to the largest available mode
+ * crtcs in the specified configuration.
+ *
+ * canGrow indicates that the driver can make the screen larger than its initial
+ * configuration.  If FALSE, this function will enlarge the screen to include
+ * the largest available mode.
  */
 
 static void
-xf86DefaultScreenLimits (ScrnInfoPtr scrn, int *widthp, int *heightp)
+xf86DefaultScreenLimits (ScrnInfoPtr scrn, int *widthp, int *heightp,
+			 Bool canGrow)
 {
     xf86CrtcConfigPtr	config = XF86_CRTC_CONFIG_PTR(scrn);
     int	    width = 0, height = 0;
@@ -757,26 +761,28 @@ xf86DefaultScreenLimits (ScrnInfoPtr scr
 	    crtc_width = crtc->x + xf86ModeWidth (&crtc->desiredMode, crtc->desiredRotation);
 	    crtc_height = crtc->y + xf86ModeHeight (&crtc->desiredMode, crtc->desiredRotation);
 	}
-	for (o = 0; o < config->num_output; o++) 
-	{
-	    xf86OutputPtr   output = config->output[o];
+	if (!canGrow) {
+	    for (o = 0; o < config->num_output; o++)
+	    {
+		xf86OutputPtr   output = config->output[o];
 
-	    for (s = 0; s < config->num_crtc; s++)
-		if (output->possible_crtcs & (1 << s))
-		{
-		    DisplayModePtr  mode;
-		    for (mode = output->probed_modes; mode; mode = mode->next)
+		for (s = 0; s < config->num_crtc; s++)
+		    if (output->possible_crtcs & (1 << s))
 		    {
-			if (mode->HDisplay > crtc_width)
-			    crtc_width = mode->HDisplay;
-			if (mode->VDisplay > crtc_width)
-			    crtc_width = mode->VDisplay;
-			if (mode->VDisplay > crtc_height)
-			    crtc_height = mode->VDisplay;
-			if (mode->HDisplay > crtc_height)
-			    crtc_height = mode->HDisplay;
+			DisplayModePtr  mode;
+			for (mode = output->probed_modes; mode; mode = mode->next)
+			{
+			    if (mode->HDisplay > crtc_width)
+				crtc_width = mode->HDisplay;
+			    if (mode->VDisplay > crtc_width)
+				crtc_width = mode->VDisplay;
+			    if (mode->VDisplay > crtc_height)
+				crtc_height = mode->VDisplay;
+			    if (mode->HDisplay > crtc_height)
+				crtc_height = mode->HDisplay;
+			}
 		    }
-		}
+	    }
 	}
 	if (crtc_width > width)
 	    width = crtc_width;
@@ -1350,10 +1356,17 @@ xf86SetScrnInfoModes (ScrnInfoPtr scrn)
  *
  * Given auto-detected (and, eventually, configured) values,
  * construct a usable configuration for the system
+ *
+ * canGrow indicates that the driver can resize the screen to larger than its
+ * initially configured size via the config->funcs->resize hook.  If TRUE, this
+ * function will set virtualX and virtualY to match the initial configuration
+ * and leave config->max{Width,Height} alone.  If FALSE, it will bloat
+ * virtual[XY] to include the largest modes and set config->max{Width,Height}
+ * accordingly.
  */
 
 Bool
-xf86InitialConfiguration (ScrnInfoPtr	    scrn)
+xf86InitialConfiguration (ScrnInfoPtr scrn, Bool canGrow)
 {
     xf86CrtcConfigPtr	config = XF86_CRTC_CONFIG_PTR(scrn);
     int			o, c;
@@ -1491,9 +1504,10 @@ xf86InitialConfiguration (ScrnInfoPtr	  
     if (scrn->display->virtualX == 0)
     {
 	/*
-	 * Expand virtual size to cover potential mode switches
+	 * Expand virtual size to cover the current config and potential mode
+	 * switches, if the driver can't enlarge the screen later.
 	 */
-	xf86DefaultScreenLimits (scrn, &width, &height);
+	xf86DefaultScreenLimits (scrn, &width, &height, canGrow);
     
 	scrn->display->virtualX = width;
 	scrn->display->virtualY = height;
@@ -1503,7 +1517,23 @@ xf86InitialConfiguration (ScrnInfoPtr	  
 	scrn->virtualX = width;
     if (height > scrn->virtualY)
 	scrn->virtualY = height;
-    
+
+    /*
+     * Make sure the configuration isn't too small.
+     */
+    if (width < config->minWidth || height < config->minHeight)
+	return FALSE;
+
+    /*
+     * Limit the crtc config to virtual[XY] if the driver can't grow the
+     * desktop.
+     */
+    if (!canGrow)
+    {
+	xf86CrtcSetSizeRange (scrn, config->minWidth, config->minHeight,
+			      width, height);
+    }
+
     /* Mirror output modes to scrn mode list */
     xf86SetScrnInfoModes (scrn);
     
diff --git a/hw/xfree86/modes/xf86Crtc.h b/hw/xfree86/modes/xf86Crtc.h
index 345332b..b04f7f3 100644
--- a/hw/xfree86/modes/xf86Crtc.h
+++ b/hw/xfree86/modes/xf86Crtc.h
@@ -545,7 +545,7 @@ void
 xf86SetScrnInfoModes (ScrnInfoPtr pScrn);
 
 Bool
-xf86InitialConfiguration (ScrnInfoPtr pScrn);
+xf86InitialConfiguration (ScrnInfoPtr pScrn, Bool canGrow);
 
 void
 xf86DPMSSet(ScrnInfoPtr pScrn, int PowerManagementMode, int flags);
diff-tree 04d15da95d608766c7832a7aa881be499c1395ba (from b11dfac287d65de7b83f63749087cba4e8ddaf4a)
Author: Aaron Plattner <aplattner at nvidia.com>
Date:   Wed Feb 28 13:36:58 2007 -0800

    Add a screen resize hook to xf86CrtcConfigRec.
    
    This hook is called when the DDX needs to resize the screen.  The driver is
    responsible for changing virtualX and virtualY, along with any other related
    screen properties (devPrivate.ptr, devKind, displayWidth, etc.).
    
    Use the size range from the crtc config instead of randrp->virtual[XY] when
    reporting the min and max screen sizes to the DDX.

diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c
index 29042a0..ebc0f8f 100644
--- a/hw/xfree86/modes/xf86Crtc.c
+++ b/hw/xfree86/modes/xf86Crtc.c
@@ -52,13 +52,17 @@
 int xf86CrtcConfigPrivateIndex = -1;
 
 void
-xf86CrtcConfigInit (ScrnInfoPtr scrn)
+xf86CrtcConfigInit (ScrnInfoPtr scrn,
+		    const xf86CrtcConfigFuncsRec *funcs)
 {
     xf86CrtcConfigPtr	config;
     
     if (xf86CrtcConfigPrivateIndex == -1)
 	xf86CrtcConfigPrivateIndex = xf86AllocateScrnInfoPrivateIndex();
     config = xnfcalloc (1, sizeof (xf86CrtcConfigRec));
+
+    config->funcs = funcs;
+
     scrn->privates[xf86CrtcConfigPrivateIndex].ptr = config;
 }
  
diff --git a/hw/xfree86/modes/xf86Crtc.h b/hw/xfree86/modes/xf86Crtc.h
index 756730e..345332b 100644
--- a/hw/xfree86/modes/xf86Crtc.h
+++ b/hw/xfree86/modes/xf86Crtc.h
@@ -407,6 +407,25 @@ struct _xf86Output {
 #endif
 };
 
+typedef struct _xf86CrtcConfigFuncs {
+    /**
+     * Requests that the driver resize the screen.
+     *
+     * The driver is responsible for updating scrn->virtualX and scrn->virtualY.
+     * If the requested size cannot be set, the driver should leave those values
+     * alone and return FALSE.
+     *
+     * A naive driver that cannot reallocate the screen may simply change
+     * virtual[XY].  A more advanced driver will want to also change the
+     * devPrivate.ptr and devKind of the screen pixmap, update any offscreen
+     * pixmaps it may have moved, and change pScrn->displayWidth.
+     */
+    Bool
+    (*resize)(ScrnInfoPtr	scrn,
+	      int		width,
+	      int		height);
+} xf86CrtcConfigFuncsRec, *xf86CrtcConfigFuncsPtr;
+
 typedef struct _xf86CrtcConfig {
     int			num_output;
     xf86OutputPtr	*output;
@@ -435,6 +454,8 @@ typedef struct _xf86CrtcConfig {
     int			dga_width, dga_height, dga_stride;
     DisplayModePtr	dga_save_mode;
 
+    const xf86CrtcConfigFuncsRec *funcs;
+
 } xf86CrtcConfigRec, *xf86CrtcConfigPtr;
 
 extern int xf86CrtcConfigPrivateIndex;
@@ -446,7 +467,8 @@ extern int xf86CrtcConfigPrivateIndex;
  */
 
 void
-xf86CrtcConfigInit (ScrnInfoPtr		scrn);
+xf86CrtcConfigInit (ScrnInfoPtr				scrn,
+		    const xf86CrtcConfigFuncsRec	*funcs);
 
 void
 xf86CrtcSetSizeRange (ScrnInfoPtr scrn,
diff --git a/hw/xfree86/modes/xf86RandR12.c b/hw/xfree86/modes/xf86RandR12.c
index abdf92e..052d12a 100644
--- a/hw/xfree86/modes/xf86RandR12.c
+++ b/hw/xfree86/modes/xf86RandR12.c
@@ -335,8 +335,9 @@ xf86RandR12ScreenSetSize (ScreenPtr	pScr
 {
     XF86RandRInfoPtr	randrp = XF86RANDRINFO(pScreen);
     ScrnInfoPtr		pScrn = XF86SCRNINFO(pScreen);
+    xf86CrtcConfigPtr	config = XF86_CRTC_CONFIG_PTR(pScrn);
     WindowPtr		pRoot = WindowTable[pScreen->myNum];
-    Bool 		ret = TRUE;
+    Bool		ret = FALSE;
 
     if (randrp->virtualX == -1 || randrp->virtualY == -1)
     {
@@ -345,20 +346,26 @@ xf86RandR12ScreenSetSize (ScreenPtr	pScr
     }
     if (pRoot)
 	(*pScrn->EnableDisableFBAccess) (pScreen->myNum, FALSE);
-    pScrn->virtualX = width;
-    pScrn->virtualY = height;
 
-    pScreen->width = pScrn->virtualX;
-    pScreen->height = pScrn->virtualY;
+    /* Let the driver update virtualX and virtualY */
+    if (!(*config->funcs->resize)(pScrn, width, height))
+	goto finish;
+
+    ret = TRUE;
+
+    pScreen->width = width;
+    pScreen->height = height;
     pScreen->mmWidth = mmWidth;
     pScreen->mmHeight = mmHeight;
 
     xf86SetViewport (pScreen, pScreen->width-1, pScreen->height-1);
     xf86SetViewport (pScreen, 0, 0);
+
+finish:
     if (pRoot)
 	(*pScrn->EnableDisableFBAccess) (pScreen->myNum, TRUE);
 #if RANDR_12_INTERFACE
-    if (WindowTable[pScreen->myNum])
+    if (WindowTable[pScreen->myNum] && ret)
 	RRScreenSizeNotify (pScreen);
 #endif
     return ret;
@@ -904,15 +911,14 @@ xf86RandR12CreateScreenResources12 (Scre
 {
     int			c;
     ScrnInfoPtr		pScrn = xf86Screens[pScreen->myNum];
-    XF86RandRInfoPtr	randrp = XF86RANDRINFO(pScreen);
     xf86CrtcConfigPtr   config = XF86_CRTC_CONFIG_PTR(pScrn);
 
     for (c = 0; c < config->num_crtc; c++)
 	xf86RandR12CrtcNotify (config->crtc[c]->randr_crtc);
     
     
-    RRScreenSetSizeRange (pScreen, 320, 240,
-			  randrp->virtualX, randrp->virtualY);
+    RRScreenSetSizeRange (pScreen, config->minWidth, config->minHeight,
+			  config->maxWidth, config->maxHeight);
     return TRUE;
 }
 
diff-tree b11dfac287d65de7b83f63749087cba4e8ddaf4a (from 2dafc46e3d814e02b25e5a2fa2e931f0257402a8)
Author: Matthias Hopf <mhopf at suse.de>
Date:   Fri Mar 2 12:30:26 2007 +0100

    Legacy framebuffer support wasn't compiled if Xorg wasn't explicitly enabled.

diff --git a/configure.ac b/configure.ac
index 9cefc2a..9386d87 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1570,6 +1570,9 @@ AM_CONDITIONAL([XQUARTZ],[test "X$XQUART
 AM_CONDITIONAL(DGA, [test "x$DGA" = xyes])
 
 dnl legacy fb support
+test "x$MFB" = xauto && MFB="$XORG"
+test "x$CFB" = xauto && CFB="$XORG"
+test "x$AFB" = xauto && AFB="$XORG"
 AM_CONDITIONAL(MFB, [test "x$MFB" = xyes])
 AM_CONDITIONAL(CFB, [test "x$CFB" = xyes])
 AM_CONDITIONAL(AFB, [test "x$AFB" = xyes])
diff-tree 2dafc46e3d814e02b25e5a2fa2e931f0257402a8 (from 39ecd6fff4f946deebe310b4b26b171c842db223)
Author: Ben Byer <bbyer at bbyer.apple.com>
Date:   Thu Mar 1 17:44:39 2007 -0800

    Fixed pointer events in Xquartz -- Keyboard events work, but
    the keycodes are incorrect.

diff --git a/hw/darwin/apple/X11Application.m b/hw/darwin/apple/X11Application.m
index 3982d97..0be1e40 100644
--- a/hw/darwin/apple/X11Application.m
+++ b/hw/darwin/apple/X11Application.m
@@ -867,7 +867,8 @@ static void send_nsevent (NSEventType ty
     int valuators[2];
     float count;
     xEvent xe;
-    
+    char nullbyte=0;
+
     bzero(&xe, sizeof(xe));
     input_check_flag++;
 	
@@ -886,10 +887,10 @@ static void send_nsevent (NSEventType ty
       pointer_y = (screen.origin.y + screen.size.height) - location.y;
     }
     
-    ErrorF("send_nsevent: type=%d pointer=(%d,%d)\n", type, pointer_x, pointer_y);
+//    ErrorF("send_nsevent: type=%d pointer=(%d,%d)\n", type, pointer_x, pointer_y);
     
     valuators[0] = pointer_x;
-    valuators[1] = pointer_y;
+    valuators[1] = pointer_y - aquaMenuBarHeight;
     state = convert_flags ([e modifierFlags]);
     
     switch (type) {
@@ -916,12 +917,8 @@ static void send_nsevent (NSEventType ty
       num_events = GetPointerEvents(quartzEvents, darwinPointer, ev_type, ev_button, 
 				    POINTER_ABSOLUTE, 0, 2, valuators);
       
-      ErrorF("GetPointerEvents returned %d events\n", num_events);
-      for(i=0; i<num_events; i++) {
-	ErrorF("qe[%d].u.u.type=%d\n", i, quartzEvents[i].u.u.type);
-//				quartzEvents[i].u.keyButtonPointer.state = state;
+      for(i=0; i<num_events; i++)
 	mieqEnqueue (darwinPointer,&quartzEvents[i]);
-      }
       break;
     case NSScrollWheel: 
       count = [e deltaY];
@@ -929,28 +926,23 @@ static void send_nsevent (NSEventType ty
       for (count = fabs(count); count > 0.0; count = count - 1.0f) {
 	num_events = GetPointerEvents(quartzEvents, darwinPointer, ButtonPress, ev_button, 
 				      POINTER_ABSOLUTE, 0, 2, valuators);
-	for(i=0; i<num_events; i++) {
-//						quartzEvents[i].u.keyButtonPointer.state = state;
+	for(i=0; i<num_events; i++) 
 	  mieqEnqueue(darwinPointer,&quartzEvents[i]);
-	}
 	num_events = GetPointerEvents(quartzEvents, darwinPointer, ButtonRelease, ev_button, 
 				      POINTER_ABSOLUTE, 0, 2, valuators);
-	for(i=0; i<num_events; i++) {
-//						quartzEvents[i].u.keyButtonPointer.state = state;
+	for(i=0; i<num_events; i++)
 	  mieqEnqueue(darwinPointer,&quartzEvents[i]);
-	}
       }
       break;
       
-    case NSKeyDown:
+    case NSKeyDown:  // do we need to translate these keyCodes?
     case NSKeyUp:
       num_events = GetKeyboardEvents(quartzEvents, darwinKeyboard, 
 				     (type == NSKeyDown)?KeyPress:KeyRelease, [e keyCode]);
-      for(i=0; i<num_events; i++) {
-//				quartzEvents[i].u.keyButtonPointer.state = state;
+      for(i=0; i<num_events; i++) 
 	mieqEnqueue(darwinKeyboard,&quartzEvents[i]);
-      }
       break;
+
     case NSFlagsChanged:
       xe.u.u.type = kXDarwinUpdateModifiers;
       xe.u.clientMessage.u.l.longs0 = [e modifierFlags];
@@ -958,5 +950,6 @@ static void send_nsevent (NSEventType ty
       break;
     default: break; /* for gcc */
     }	
-    //	UpdateCurrentTime();
+    //  <daniels> bushing: oh, i ... er ... christ.
+    write(darwinEventWriteFD, &nullbyte, 1);
 }
diff --git a/hw/darwin/quartz/applewm.c b/hw/darwin/quartz/applewm.c
index 869f7a9..cc11cfa 100644
--- a/hw/darwin/quartz/applewm.c
+++ b/hw/darwin/quartz/applewm.c
@@ -446,7 +446,11 @@ ProcAppleWMSetWindowMenu(
         }
     }
 
+#ifdef INXQUARTZ
+    X11ApplicationSetWindowMenu (nitems, items, shortcuts);
+#else
     QuartzSetWindowMenu (nitems, items, shortcuts);
+#endif
 
     free(items);
     free(shortcuts);
@@ -462,10 +466,12 @@ ProcAppleWMSetWindowMenuCheck(
     REQUEST(xAppleWMSetWindowMenuCheckReq);
 
     REQUEST_SIZE_MATCH(xAppleWMSetWindowMenuCheckReq);
-
+#ifdef INXQUARTZ
+    X11ApplicationSetWindowMenuCheck(stuff->index);
+#else
     QuartzMessageMainThread(kQuartzSetWindowMenuCheck, &stuff->index,
                             sizeof(stuff->index));
-
+#endif
     return (client->noClientException);
 }
 
@@ -475,9 +481,11 @@ ProcAppleWMSetFrontProcess(
 )
 {
     REQUEST_SIZE_MATCH(xAppleWMSetFrontProcessReq);
-
+#ifdef INXQUARTZ
+    X11ApplicationSetFrontProcess();
+#else
     QuartzMessageMainThread(kQuartzSetFrontProcess, NULL, 0);
-
+#endif
     return (client->noClientException);
 }
 
@@ -516,9 +524,12 @@ ProcAppleWMSetCanQuit(
     REQUEST(xAppleWMSetCanQuitReq);
 
     REQUEST_SIZE_MATCH(xAppleWMSetCanQuitReq);
-
+#ifdef INXQUARTZ
+    X11ApplicationSetCanQuit(stuff->state);
+#else
     QuartzMessageMainThread(kQuartzSetCanQuit, &stuff->state,
                             sizeof(stuff->state));
+#endif
 
     return (client->noClientException);
 }
diff --git a/hw/darwin/quartz/quartz.c b/hw/darwin/quartz/quartz.c
index 913ea72..038b21e 100644
--- a/hw/darwin/quartz/quartz.c
+++ b/hw/darwin/quartz/quartz.c
@@ -160,7 +160,11 @@ void DarwinModeInitInput(
     int argc,
     char **argv )
 {
+#ifdef INXQUARTZ
+  X11ApplicationServerReady();
+#else
     QuartzMessageMainThread(kQuartzServerStarted, NULL, 0);
+#endif
 
     // Do final display mode specific initialization before handling events
     if (quartzProcs->InitInput)
@@ -274,7 +278,9 @@ static void QuartzHide(void)
         }
     }
     quartzServerVisible = FALSE;
+#ifndef INXQUARTZ
     QuartzMessageMainThread(kQuartzServerHidden, NULL, 0);
+#endif
 }
 
 
diff --git a/hw/darwin/quartz/quartzCursor.c b/hw/darwin/quartz/quartzCursor.c
index 1e618e3..6ed6a76 100644
--- a/hw/darwin/quartz/quartzCursor.c
+++ b/hw/darwin/quartz/quartzCursor.c
@@ -93,7 +93,9 @@ static pthread_cond_t cursorCondition;
         /* Acquire lock and tell the main thread to change cursor */    \
         pthread_mutex_lock(&cursorMutex);                               \
         currentCursor = (CCrsrHandle) (cursorH);                        \
+#ifndef INXQUARTZ
         QuartzMessageMainThread(kQuartzCursorUpdate, NULL, 0);          \
+#endif
                                                                         \
         /* Wait for the main thread to change the cursor */             \
         pthread_cond_wait(&cursorCondition, &cursorMutex);              \
diff-tree 39ecd6fff4f946deebe310b4b26b171c842db223 (from ed7ccc481ad1caaa518cafe944c2327a5d0b6c65)
Author: Ben Byer <bbyer at bbyer.(none)>
Date:   Thu Mar 1 01:45:19 2007 -0800

    Rewrote parts of the Xquartz event-handling code (thanks daniels and whot!)
    It should still be considered a work in progress, but mouse events almost work.

diff --git a/hw/darwin/apple/X11Application.m b/hw/darwin/apple/X11Application.m
index 5da0574..3982d97 100644
--- a/hw/darwin/apple/X11Application.m
+++ b/hw/darwin/apple/X11Application.m
@@ -1,7 +1,6 @@
 /* X11Application.m -- subclass of NSApplication to multiplex events
- $Id: X11Application.m,v 1.59 2006/09/06 21:19:32 jharper Exp $
  
- Copyright (c) 2002-2007 Apple Inc. All rights reserved.
+ Copyright (c) 2002-2007 Apple Inc.
  
  Permission is hereby granted, free of charge, to any person
  obtaining a copy of this software and associated documentation files
@@ -35,12 +34,10 @@
 
 /* ouch! */
 #define BOOL X_BOOL
-//# include "Xproto.h"
 # include "darwin.h"
 # include "../quartz/quartz.h"
 # define _APPLEWM_SERVER_
 # include "X11/extensions/applewm.h"
-//# include "X.h"
 # include "micmap.h"
 #undef BOOL
 
@@ -55,15 +52,15 @@
 int X11EnableKeyEquivalents = TRUE;
 int quartzHasRoot = FALSE, quartzEnableRootless = TRUE;
 
-extern int darwinFakeButtons;
+extern int darwinFakeButtons, input_check_flag;
 // extern Bool enable_stereo; 
 Bool enable_stereo;  //<-- this needs to go back to being an extern once glxCGL is fixed
 
+static xEvent *quartzEvents;
 
 X11Application *X11App;
 
-#define ALL_KEY_MASKS (NSShiftKeyMask | NSControlKeyMask \
-| NSAlternateKeyMask | NSCommandKeyMask)
+#define ALL_KEY_MASKS (NSShiftKeyMask | NSControlKeyMask | NSAlternateKeyMask | NSCommandKeyMask)
 
 @implementation X11Application
 
@@ -82,27 +79,21 @@ static void send_nsevent (NSEventType ty
  but is statically linked into this X server. */
 extern Bool QuartzModeBundleInit(void);
 
-static void
-init_ports (void)
-{
+static void init_ports (void) {
     kern_return_t r;
     NSPort *p;
 	
-    if (_port != MACH_PORT_NULL)
-		return;
+    if (_port != MACH_PORT_NULL) return;
 	
     r = mach_port_allocate (mach_task_self (), MACH_PORT_RIGHT_RECEIVE, &_port);
-    if (r != KERN_SUCCESS)
-		return;
+    if (r != KERN_SUCCESS) return;
 	
     p = [NSMachPort portWithMachPort:_port];
     [p setDelegate:NSApp];
     [p scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
 }
 
-static void
-message_kit_thread (SEL selector, NSObject *arg)
-{
+static void message_kit_thread (SEL selector, NSObject *arg) {
     message msg;
     kern_return_t r;
 	
@@ -117,29 +108,24 @@ message_kit_thread (SEL selector, NSObje
     msg.arg = [arg retain];
 	
     r = mach_msg (&msg.hdr, MACH_SEND_MSG, msg.hdr.msgh_size,
-				  0, MACH_PORT_NULL, 0, MACH_PORT_NULL);
+		  0, MACH_PORT_NULL, 0, MACH_PORT_NULL);
     if (r != KERN_SUCCESS)
-		fprintf (stderr, "%s: mach_msg failed: %x\n", __FUNCTION__, r);
+		ErrorF("%s: mach_msg failed: %x\n", __FUNCTION__, r);
 }
 
-- (void) handleMachMessage:(void *)_msg
-{
+- (void) handleMachMessage:(void *)_msg {
     message *msg = _msg;
 	
     [self performSelector:msg->selector withObject:msg->arg];
     [msg->arg release];
 }
 
-- (void) set_controller:obj
-{
-    if (_controller == nil)
-		_controller = [obj retain];
+- (void) set_controller:obj {
+    if (_controller == nil) _controller = [obj retain];
 }
 
-- (void) dealloc
-{
-    if (_controller != nil)
-		[_controller release];
+- (void) dealloc {
+    if (_controller != nil) [_controller release];
 	
     if (_port != MACH_PORT_NULL)
 		mach_port_deallocate (mach_task_self (), _port);
@@ -147,8 +133,7 @@ message_kit_thread (SEL selector, NSObje
     [super dealloc];
 }
 
-- (void) orderFrontStandardAboutPanel: (id) sender
-{
+- (void) orderFrontStandardAboutPanel: (id) sender {
     NSMutableDictionary *dict;
     NSDictionary *infoDict;
     NSString *tem;
@@ -161,57 +146,45 @@ message_kit_thread (SEL selector, NSObje
 	
     tem = [infoDict objectForKey:@"CFBundleShortVersionString"];
 	
-    [dict setObject:[NSString stringWithFormat:@"X11.app %@ - X.org X11R7.1",
-					 tem] forKey:@"ApplicationVersion"];
+    [dict setObject:[NSString stringWithFormat:@"X11.app %@ - X.org X11R7.3", tem] 
+	  forKey:@"ApplicationVersion"];
 	
     [self orderFrontStandardAboutPanelWithOptions: dict];
 }
 
-- (void) activateX:(BOOL)state
-{
+- (void) activateX:(BOOL)state {
     /* Create a TSM document that supports full Unicode input, and
 	 have it activated while X is active (unless using the old
 	 keymapping files) */
     static TSMDocumentID x11_document;
 	
-    if (state)
-    {
-		QuartzMessageServerThread (kXDarwinActivate, 0);
-		
-		if (!_x_active)
-		{
-			if (x11_document == 0 && darwinKeymapFile == NULL)
-			{
-				OSType types[1];
-				types[0] = kUnicodeDocument;
-				NewTSMDocument (1, types, &x11_document, 0);
-			}
-			
-			if (x11_document != 0)
-				ActivateTSMDocument (x11_document);
-		}
-    }
-    else
-    {
-		QuartzMessageServerThread (kXDarwinDeactivate, 0);
-		
-		if (_x_active)
-		{
-			if (x11_document != 0)
-				DeactivateTSMDocument (x11_document);
-		}
-    }
+    if (state) {
+      QuartzMessageServerThread (kXDarwinActivate, 0);
+      
+      if (!_x_active) {
+	if (x11_document == 0 && darwinKeymapFile == NULL) {
+	  OSType types[1];
+	  types[0] = kUnicodeDocument;
+	  NewTSMDocument (1, types, &x11_document, 0);
+	}
 	
+	if (x11_document != 0)	ActivateTSMDocument (x11_document);
+      }
+    } else {
+      QuartzMessageServerThread (kXDarwinDeactivate, 0);
+      
+      if (_x_active && x11_document != 0)
+	DeactivateTSMDocument (x11_document);
+    }
+    
     _x_active = state;
 }
 
-- (void) became_key:(NSWindow *)win
-{
+- (void) became_key:(NSWindow *)win {
     [self activateX:NO];
 }
 
-- (void) sendEvent:(NSEvent *)e
-{
+- (void) sendEvent:(NSEvent *)e {
     NSEventType type;
     BOOL for_appkit, for_x;
 	
@@ -221,178 +194,140 @@ message_kit_thread (SEL selector, NSObje
     for_appkit = YES;
     for_x = YES;
 	
-    switch (type)
-    {
+    switch (type) {
     case NSLeftMouseDown: case NSRightMouseDown: case NSOtherMouseDown:
     case NSLeftMouseUp: case NSRightMouseUp: case NSOtherMouseUp:
-		if ([e window] != nil)
-		{
-			/* Pointer event has a window. Probably something for the kit. */
-			
-			for_x = NO;
-			
-			if (_x_active)
-				[self activateX:NO];
-		}
-		else if ([self modalWindow] == nil)
-		{
-			/* Must be an X window. Tell appkit it doesn't have focus. */
-			
-			for_appkit = NO;
-			
-			if ([self isActive])
-			{
-				[self deactivate];
-				
-				if (!_x_active && quartzProcs->IsX11Window([e window],
-														   [e windowNumber]))
-				[self activateX:YES];
-			}
-		}
-		break;
-		
+      if ([e window] != nil) {
+	/* Pointer event has a window. Probably something for the kit. */
+	
+	for_x = NO;
+	
+	if (_x_active) [self activateX:NO];
+      } else if ([self modalWindow] == nil) {
+	/* Must be an X window. Tell appkit it doesn't have focus. */
+			
+	for_appkit = NO;
+	
+	if ([self isActive]) {
+	  [self deactivate];
+	  
+	  if (!_x_active && quartzProcs->IsX11Window([e window], [e windowNumber]))
+	    [self activateX:YES];
+	}
+      }
+      break;
+      
     case NSKeyDown: case NSKeyUp:
-		if (_x_active)
-		{
-			static int swallow_up;
-			
-			/* No kit window is focused, so send it to X. */
-			
-			for_appkit = NO;
-			
-			if (type == NSKeyDown)
-			{
-				/* Before that though, see if there are any global
-				 shortcuts bound to it. */
-				
-				if (X11EnableKeyEquivalents
-					&& [[self mainMenu] performKeyEquivalent:e])
-				{
-					swallow_up = [e keyCode];
-					for_x = NO;
-				}
-				else if (!quartzEnableRootless
-						 && ([e modifierFlags] & ALL_KEY_MASKS)
-						 == (NSCommandKeyMask | NSAlternateKeyMask)
-						 && ([e keyCode] == 0 /*a*/
-							 || [e keyCode] == 53 /*Esc*/))
-				{
-					swallow_up = 0;
-					for_x = NO;
+      if (_x_active) {
+	static int swallow_up;
+	
+	/* No kit window is focused, so send it to X. */
+	
+	for_appkit = NO;
+	
+	if (type == NSKeyDown) {
+	  /* Before that though, see if there are any global
+	     shortcuts bound to it. */
+	  
+	  if (X11EnableKeyEquivalents
+	      && [[self mainMenu] performKeyEquivalent:e]) {
+	    swallow_up = [e keyCode];
+	    for_x = NO;
+	  } else if (!quartzEnableRootless
+		   && ([e modifierFlags] & ALL_KEY_MASKS)
+		   == (NSCommandKeyMask | NSAlternateKeyMask)
+		   && ([e keyCode] == 0 /*a*/
+		       || [e keyCode] == 53 /*Esc*/)) {
+	    swallow_up = 0;
+	    for_x = NO;
 #ifdef DARWIN_DDX_MISSING
-					QuartzMessageServerThread (kXDarwinToggleFullscreen, 0);
+	    QuartzMessageServerThread (kXDarwinToggleFullscreen, 0);
 #endif
-				}
-			}
-			else
-			{
-				/* If we saw a key equivalent on the down, don't pass
-				 the up through to X. */
-				
-				if (swallow_up != 0 && [e keyCode] == swallow_up)
-				{
-					swallow_up = 0;
-					for_x = NO;
-				}
-			}
-		}
-		else
-		{
-			for_x = NO;
-		}
-		break;
+	  }
+	} else {
+	  /* If we saw a key equivalent on the down, don't pass
+	     the up through to X. */
+	  
+	  if (swallow_up != 0 && [e keyCode] == swallow_up) {
+	    swallow_up = 0;
+	    for_x = NO;
+	  }
+	}
+      }
+      else for_x = NO;
+      break;
 		
     case NSFlagsChanged:
-		/* For the l33t X users who remap modifier keys to normal keysyms. */
-		if (!_x_active)
-			for_x = NO;
-		break;
+      /* For the l33t X users who remap modifier keys to normal keysyms. */
+      if (!_x_active)
+	for_x = NO;
+      break;
 		
     case NSAppKitDefined:
-		switch ([e subtype])
-		{
-		case NSApplicationActivatedEventType:
-			for_x = NO;
-			if ([self modalWindow] == nil)
-			{
-				for_appkit = NO;
-				
-				/* FIXME: hack to avoid having to pass the event to appkit,
-				 which would cause it to raise one of its windows. */
-				_appFlags._active = YES;
-				
-				[self activateX:YES];
+      switch ([e subtype]) {
+      case NSApplicationActivatedEventType:
+	for_x = NO;
+	if ([self modalWindow] == nil) {
+	  for_appkit = NO;
+	  
+	  /* FIXME: hack to avoid having to pass the event to appkit,
+	     which would cause it to raise one of its windows. */
+	  _appFlags._active = YES;
+	  
+	  [self activateX:YES];
 #ifdef DARWIN_DDX_MISSING
-				if ([e data2] & 0x10) QuartzMessageServerThread (kXDarwinBringAllToFront, 0);
+	  if ([e data2] & 0x10) QuartzMessageServerThread (kXDarwinBringAllToFront, 0);
 #endif
-			}
-			break;
-			
-		case 18: /* ApplicationDidReactivate */
-			if (quartzHasRoot)
-				for_appkit = NO;
-			break;
+	}
+	break;
 			
-		case NSApplicationDeactivatedEventType:
-			for_x = NO;
-			[self activateX:NO];
-			break;
-		}
-		break;
-		
+      case 18: /* ApplicationDidReactivate */
+	if (quartzHasRoot) for_appkit = NO;
+	break;
+			
+      case NSApplicationDeactivatedEventType:
+	for_x = NO;
+	[self activateX:NO];
+	break;
+      }
+      break;
+      
     default: break; /* for gcc */
     }
 	
-    if (for_appkit)
-    {
-		[super sendEvent:e];
-    }
-	
-    if (for_x)
-    {
-		send_nsevent (type, e);
-    }
+    if (for_appkit) [super sendEvent:e];
+    if (for_x) send_nsevent (type, e);
 }
 
-- (void) set_window_menu:(NSArray *)list
-{
+- (void) set_window_menu:(NSArray *)list {
     [_controller set_window_menu:list];
 }
 
-- (void) set_window_menu_check:(NSNumber *)n
-{
+- (void) set_window_menu_check:(NSNumber *)n {
     [_controller set_window_menu_check:n];
 }
 
-- (void) set_apps_menu:(NSArray *)list
-{
+- (void) set_apps_menu:(NSArray *)list {
     [_controller set_apps_menu:list];
 }
 
-- (void) set_front_process:unused
-{
+- (void) set_front_process:unused {
     [NSApp activateIgnoringOtherApps:YES];
 	
-    if ([self modalWindow] == nil)
-		[self activateX:YES];
+    if ([self modalWindow] == nil) [self activateX:YES];
 }
 
-- (void) set_can_quit:(NSNumber *)state
-{
+- (void) set_can_quit:(NSNumber *)state {
     [_controller set_can_quit:[state boolValue]];
 }
 
-- (void) server_ready:unused
-{
+- (void) server_ready:unused {
     [_controller server_ready];
 }
 
-- (void) show_hide_menubar:(NSNumber *)state
-{
-    if ([state boolValue])
-		ShowMenuBar ();
-    else
-		HideMenuBar ();
+- (void) show_hide_menubar:(NSNumber *)state {
+    if ([state boolValue]) ShowMenuBar ();
+    else HideMenuBar ();
 }
 
 
@@ -404,12 +339,12 @@ message_kit_thread (SEL selector, NSObje
 static const void *cfretain (CFAllocatorRef a, const void *b) {
     return CFRetain (b);
 }
+
 static void cfrelease (CFAllocatorRef a, const void *b) {
     CFRelease (b);
 }
-static CFMutableArrayRef
-nsarray_to_cfarray (NSArray *in)
-{
+
+static CFMutableArrayRef nsarray_to_cfarray (NSArray *in) {
     CFMutableArrayRef out;
     CFArrayCallBacks cb;
     NSObject *ns;
@@ -424,24 +359,22 @@ nsarray_to_cfarray (NSArray *in)
     count = [in count];
     out = CFArrayCreateMutable (NULL, count, &cb);
 	
-    for (i = 0; i < count; i++)
-    {
-		ns = [in objectAtIndex:i];
-		
-		if ([ns isKindOfClass:[NSArray class]])
-			cf = (CFTypeRef) nsarray_to_cfarray ((NSArray *) ns);
-		else
-			cf = CFRetain ((CFTypeRef) ns);
-		
-		CFArrayAppendValue (out, cf);
-		CFRelease (cf);
+    for (i = 0; i < count; i++) {
+      ns = [in objectAtIndex:i];
+      
+      if ([ns isKindOfClass:[NSArray class]])
+	cf = (CFTypeRef) nsarray_to_cfarray ((NSArray *) ns);
+      else
+	cf = CFRetain ((CFTypeRef) ns);
+      
+      CFArrayAppendValue (out, cf);
+      CFRelease (cf);
     }
-	
+    
     return out;
 }
-static NSMutableArray *
-cfarray_to_nsarray (CFArrayRef in)
-{
+
+static NSMutableArray * cfarray_to_nsarray (CFArrayRef in) {
     NSMutableArray *out;
     const CFTypeRef *cf;
     NSObject *ns;
@@ -450,320 +383,277 @@ cfarray_to_nsarray (CFArrayRef in)
     count = CFArrayGetCount (in);
     out = [[NSMutableArray alloc] initWithCapacity:count];
 	
-    for (i = 0; i < count; i++)
-    {
-		cf = CFArrayGetValueAtIndex (in, i);
-		
-		if (CFGetTypeID (cf) == CFArrayGetTypeID ())
-			ns = cfarray_to_nsarray ((CFArrayRef) cf);
-		else
-			ns = [(id)cf retain];
+    for (i = 0; i < count; i++) {
+      cf = CFArrayGetValueAtIndex (in, i);
 		
-		[out addObject:ns];
-		[ns release];
+      if (CFGetTypeID (cf) == CFArrayGetTypeID ())
+	ns = cfarray_to_nsarray ((CFArrayRef) cf);
+      else
+	ns = [(id)cf retain];
+      
+      [out addObject:ns];
+      [ns release];
     }
-	
+    
     return out;
 }
 
-- (CFPropertyListRef) prefs_get:(NSString *)key
-{
+- (CFPropertyListRef) prefs_get:(NSString *)key {
     CFPropertyListRef value;
 	
     value = CFPreferencesCopyAppValue ((CFStringRef) key, CFSTR (APP_PREFS));
 	
-    if (value == NULL)
-    {
-		static CFDictionaryRef defaults;
-		
-		if (defaults == NULL)
-		{
-			CFStringRef error = NULL;
-			CFDataRef data;
-			CFURLRef url;
-			SInt32 error_code;
-			
-			url = (CFURLCreateFromFileSystemRepresentation
-				   (NULL, (unsigned char *)DEFAULTS_FILE, strlen (DEFAULTS_FILE), false));
-			if (CFURLCreateDataAndPropertiesFromResource (NULL, url, &data,
-														  NULL, NULL,
-														  &error_code))
-			{
-				defaults = (CFPropertyListCreateFromXMLData
-							(NULL, data, kCFPropertyListMutableContainersAndLeaves, &error));
-				if (error != NULL)
-					CFRelease (error);
-				CFRelease (data);
-			}
-			CFRelease (url);
+    if (value == NULL) {
+      static CFDictionaryRef defaults;
+      
+      if (defaults == NULL) {
+	CFStringRef error = NULL;
+	CFDataRef data;
+	CFURLRef url;
+	SInt32 error_code;
+	
+	url = (CFURLCreateFromFileSystemRepresentation
+	       (NULL, (unsigned char *)DEFAULTS_FILE, strlen (DEFAULTS_FILE), false));
+	if (CFURLCreateDataAndPropertiesFromResource (NULL, url, &data,
+						      NULL, NULL, &error_code)) {
+	  defaults = (CFPropertyListCreateFromXMLData
+		      (NULL, data, kCFPropertyListMutableContainersAndLeaves, &error));
+	  if (error != NULL) CFRelease (error);
+	  CFRelease (data);
+	}
+	CFRelease (url);
 			
-			if (defaults != NULL)
-			{
-				NSMutableArray *apps, *elt;
-				int count, i;
-				NSString *name, *nname;
-				
-				/* Localize the names in the default apps menu. */
-				
-				apps = [(NSDictionary *)defaults objectForKey:@PREFS_APPSMENU];
-				if (apps != nil)
-				{
-					count = [apps count];
-					for (i = 0; i < count; i++)
-					{
-						elt = [apps objectAtIndex:i];
-						if (elt != nil && [elt isKindOfClass:[NSArray class]])
-						{
-							name = [elt objectAtIndex:0];
-							if (name != nil)
-							{
-								nname = NSLocalizedString (name, nil);
-								if (nname != nil && nname != name)
-									[elt replaceObjectAtIndex:0 withObject:nname];
-							}
-						}
-					}
-				}
-			}
-		}
-		
-		if (defaults != NULL)
-			value = CFDictionaryGetValue (defaults, key);
+	if (defaults != NULL) {
+	  NSMutableArray *apps, *elt;
+	  int count, i;
+	  NSString *name, *nname;
+	  
+	  /* Localize the names in the default apps menu. */
+	  
+	  apps = [(NSDictionary *)defaults objectForKey:@PREFS_APPSMENU];
+	  if (apps != nil) {
+	    count = [apps count];
+	    for (i = 0; i < count; i++)	{
+	      elt = [apps objectAtIndex:i];
+	      if (elt != nil && [elt isKindOfClass:[NSArray class]]) {
+		name = [elt objectAtIndex:0];
+		if (name != nil) {
+		  nname = NSLocalizedString (name, nil);
+		  if (nname != nil && nname != name)
+		    [elt replaceObjectAtIndex:0 withObject:nname];
+		}
+	      }
+	    }
+	  }
+	}
+      }
 		
-		if (value != NULL)
-			CFRetain (value);
+      if (defaults != NULL) value = CFDictionaryGetValue (defaults, key);
+      if (value != NULL) CFRetain (value);
     }
 	
     return value;
 }
 
-- (int) prefs_get_integer:(NSString *)key default:(int)def
-{
-    CFPropertyListRef value;
-    int ret;
-	
-    value = [self prefs_get:key];
-	
-    if (value != NULL && CFGetTypeID (value) == CFNumberGetTypeID ())
-		CFNumberGetValue (value, kCFNumberIntType, &ret);
-    else if (value != NULL && CFGetTypeID (value) == CFStringGetTypeID ())
-		ret = CFStringGetIntValue (value);
-    else
-		ret = def;
-	
-    if (value != NULL)
-		CFRelease (value);
-	
-    return ret;
-}
-
-- (const char *) prefs_get_string:(NSString *)key default:(const char *)def
-{
-    CFPropertyListRef value;
-    const char *ret = NULL;
-	
-    value = [self prefs_get:key];
-	
-    if (value != NULL && CFGetTypeID (value) == CFStringGetTypeID ())
-    {
-		NSString *s = (NSString *) value;
-		
-		ret = [s UTF8String];
-    }
-	
-    if (value != NULL)
-		CFRelease (value);
-	
-    return ret != NULL ? ret : def;
-}
-
-- (float) prefs_get_float:(NSString *)key default:(float)def
-{
-    CFPropertyListRef value;
-    float ret = def;
-	
-    value = [self prefs_get:key];
-	
-    if (value != NULL
-		&& CFGetTypeID (value) == CFNumberGetTypeID ()
-		&& CFNumberIsFloatType (value))
-    {
-		CFNumberGetValue (value, kCFNumberFloatType, &ret);
-    }
-    else if (value != NULL && CFGetTypeID (value) == CFStringGetTypeID ())
-    {
-		ret = CFStringGetDoubleValue (value);
-    }
-	
-    if (value != NULL)
-		CFRelease (value);
-	
-    return ret;
-}
-
-- (int) prefs_get_boolean:(NSString *)key default:(int)def
-{
-    CFPropertyListRef value;
-    int ret = def;
-	
-    value = [self prefs_get:key];
-	
-    if (value != NULL)
-    {
-		if (CFGetTypeID (value) == CFNumberGetTypeID ())
-			CFNumberGetValue (value, kCFNumberIntType, &ret);
-		else if (CFGetTypeID (value) == CFBooleanGetTypeID ())
-			ret = CFBooleanGetValue (value);
-		else if (CFGetTypeID (value) == CFStringGetTypeID ())
-		{
-			const char *tem = [(NSString *) value lossyCString];
-			if (strcasecmp (tem, "true") == 0 || strcasecmp (tem, "yes") == 0)
-				ret = YES;
-			else
-				ret = NO;
-		}
-		
-		CFRelease (value);
+- (int) prefs_get_integer:(NSString *)key default:(int)def {
+  CFPropertyListRef value;
+  int ret;
+  
+  value = [self prefs_get:key];
+  
+  if (value != NULL && CFGetTypeID (value) == CFNumberGetTypeID ())
+    CFNumberGetValue (value, kCFNumberIntType, &ret);
+  else if (value != NULL && CFGetTypeID (value) == CFStringGetTypeID ())
+    ret = CFStringGetIntValue (value);
+  else
+    ret = def;
+  
+  if (value != NULL) CFRelease (value);
+  
+  return ret;
+}
+
+- (const char *) prefs_get_string:(NSString *)key default:(const char *)def {
+  CFPropertyListRef value;
+  const char *ret = NULL;
+  
+  value = [self prefs_get:key];
+  
+  if (value != NULL && CFGetTypeID (value) == CFStringGetTypeID ()) {
+    NSString *s = (NSString *) value;
+    
+    ret = [s UTF8String];
+  }
+  
+  if (value != NULL) CFRelease (value);
+  
+  return ret != NULL ? ret : def;
+}
+
+- (float) prefs_get_float:(NSString *)key default:(float)def {
+  CFPropertyListRef value;
+  float ret = def;
+  
+  value = [self prefs_get:key];
+  
+  if (value != NULL
+      && CFGetTypeID (value) == CFNumberGetTypeID ()
+      && CFNumberIsFloatType (value)) 
+    CFNumberGetValue (value, kCFNumberFloatType, &ret);
+  else if (value != NULL && CFGetTypeID (value) == CFStringGetTypeID ())
+    ret = CFStringGetDoubleValue (value);
+	
+  if (value != NULL) CFRelease (value);
+  
+  return ret;
+}
+
+- (int) prefs_get_boolean:(NSString *)key default:(int)def {
+  CFPropertyListRef value;
+  int ret = def;
+  
+  value = [self prefs_get:key];
+  
+  if (value != NULL) {
+    if (CFGetTypeID (value) == CFNumberGetTypeID ())
+      CFNumberGetValue (value, kCFNumberIntType, &ret);
+    else if (CFGetTypeID (value) == CFBooleanGetTypeID ())
+      ret = CFBooleanGetValue (value);
+    else if (CFGetTypeID (value) == CFStringGetTypeID ()) {
+      const char *tem = [(NSString *) value lossyCString];
+      if (strcasecmp (tem, "true") == 0 || strcasecmp (tem, "yes") == 0)
+	ret = YES;
+      else
+	ret = NO;
     }
-	
-    return ret;
+    
+    CFRelease (value);
+  }
+  return ret;
 }
 
-- (NSArray *) prefs_get_array:(NSString *)key
-{
-    NSArray *ret = nil;
-    CFPropertyListRef value;
-	
-    value = [self prefs_get:key];
-	
-    if (value != NULL)
-    {
-		if (CFGetTypeID (value) == CFArrayGetTypeID ())
-			ret = [cfarray_to_nsarray (value) autorelease];
-		
-		CFRelease (value);
-    }
-	
-    return ret;
+- (NSArray *) prefs_get_array:(NSString *)key {
+  NSArray *ret = nil;
+  CFPropertyListRef value;
+  
+  value = [self prefs_get:key];
+  
+  if (value != NULL) {
+    if (CFGetTypeID (value) == CFArrayGetTypeID ())
+      ret = [cfarray_to_nsarray (value) autorelease];
+    
+    CFRelease (value);
+  }
+  
+  return ret;
 }
 
-- (void) prefs_set_integer:(NSString *)key value:(int)value
-{
+- (void) prefs_set_integer:(NSString *)key value:(int)value {
     CFNumberRef x;
 	
     x = CFNumberCreate (NULL, kCFNumberIntType, &value);
 	
     CFPreferencesSetValue ((CFStringRef) key, (CFTypeRef) x, CFSTR (APP_PREFS),
-						   kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
+			   kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
 	
     CFRelease (x);
 }
 
-- (void) prefs_set_float:(NSString *)key value:(float)value
-{
+- (void) prefs_set_float:(NSString *)key value:(float)value {
     CFNumberRef x;
 	
     x = CFNumberCreate (NULL, kCFNumberFloatType, &value);
 	
     CFPreferencesSetValue ((CFStringRef) key, (CFTypeRef) x, CFSTR (APP_PREFS),
-						   kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
+			   kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
 	
     CFRelease (x);
 }
 
-- (void) prefs_set_boolean:(NSString *)key value:(int)value
-{
-    CFPreferencesSetValue ((CFStringRef) key,
-						   (CFTypeRef) value ? kCFBooleanTrue
-						   : kCFBooleanFalse, CFSTR (APP_PREFS),
-						   kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
-	
-}
-
-- (void) prefs_set_array:(NSString *)key value:(NSArray *)value
-{
-    CFArrayRef cfarray;
-	
-    cfarray = nsarray_to_cfarray (value);
-    CFPreferencesSetValue ((CFStringRef) key,
-						   (CFTypeRef) cfarray,
-						   CFSTR (APP_PREFS),
-						   kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
-    CFRelease (cfarray);
-}
-
-- (void) prefs_set_string:(NSString *)key value:(NSString *)value
-{
-    CFPreferencesSetValue ((CFStringRef) key, (CFTypeRef) value,
-						   CFSTR (APP_PREFS), kCFPreferencesCurrentUser,
-						   kCFPreferencesAnyHost);
+- (void) prefs_set_boolean:(NSString *)key value:(int)value {
+  CFPreferencesSetValue ((CFStringRef) key,
+			 (CFTypeRef) value ? kCFBooleanTrue
+			 : kCFBooleanFalse, CFSTR (APP_PREFS),
+			 kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
+  
+}
+
+- (void) prefs_set_array:(NSString *)key value:(NSArray *)value {
+  CFArrayRef cfarray;
+  
+  cfarray = nsarray_to_cfarray (value);
+  CFPreferencesSetValue ((CFStringRef) key,
+			 (CFTypeRef) cfarray,
+			 CFSTR (APP_PREFS),
+			 kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
+  CFRelease (cfarray);
+}
+
+- (void) prefs_set_string:(NSString *)key value:(NSString *)value {
+  CFPreferencesSetValue ((CFStringRef) key, (CFTypeRef) value,
+			 CFSTR (APP_PREFS), kCFPreferencesCurrentUser,
+			 kCFPreferencesAnyHost);
 }
 
-- (void) prefs_synchronize
-{
+- (void) prefs_synchronize {
     CFPreferencesAppSynchronize (kCFPreferencesCurrentApplication);
 }
 
-- (void) read_defaults
-{
-    const char *tem;
-	
-    quartzUseSysBeep = [self prefs_get_boolean:@PREFS_SYSBEEP
-									   default:quartzUseSysBeep];
-    quartzEnableRootless = [self prefs_get_boolean:@PREFS_ROOTLESS
-										   default:quartzEnableRootless];
+- (void) read_defaults {
+  const char *tem;
+  
+  quartzUseSysBeep = [self prefs_get_boolean:@PREFS_SYSBEEP
+			   default:quartzUseSysBeep];
+  quartzEnableRootless = [self prefs_get_boolean:@PREFS_ROOTLESS
+			       default:quartzEnableRootless];
 #ifdef DARWIN_DDX_MISSING
-    quartzFullscreenDisableHotkeys = ![self prefs_get_boolean:
-									   @PREFS_FULLSCREEN_HOTKEYS default:
-									   !quartzFullscreenDisableHotkeys];
-    quartzXpluginOptions = [self prefs_get_integer:@PREFS_XP_OPTIONS
-										   default:quartzXpluginOptions];
+  quartzFullscreenDisableHotkeys = ![self prefs_get_boolean:
+					    @PREFS_FULLSCREEN_HOTKEYS default:
+					    !quartzFullscreenDisableHotkeys];
+  quartzXpluginOptions = [self prefs_get_integer:@PREFS_XP_OPTIONS
+			       default:quartzXpluginOptions];
 #endif
-	
-    darwinSwapAltMeta = [self prefs_get_boolean:@PREFS_SWAP_ALT_META
-										default:darwinSwapAltMeta];
-    darwinFakeButtons = [self prefs_get_boolean:@PREFS_FAKEBUTTONS
-										default:darwinFakeButtons];
-    if (darwinFakeButtons)
-    {
-        const char *fake2, *fake3;
-		
-        fake2 = [self prefs_get_string:@PREFS_FAKE_BUTTON2 default:NULL];
-        fake3 = [self prefs_get_string:@PREFS_FAKE_BUTTON3 default:NULL];
-		
-		if (fake2 != NULL) darwinFakeMouse2Mask = DarwinParseModifierList(fake2);
-		if (fake3 != NULL) darwinFakeMouse3Mask = DarwinParseModifierList(fake3);
+  
+  darwinSwapAltMeta = [self prefs_get_boolean:@PREFS_SWAP_ALT_META
+			    default:darwinSwapAltMeta];
+  darwinFakeButtons = [self prefs_get_boolean:@PREFS_FAKEBUTTONS
+			    default:darwinFakeButtons];
+  if (darwinFakeButtons) {
+    const char *fake2, *fake3;
+    
+    fake2 = [self prefs_get_string:@PREFS_FAKE_BUTTON2 default:NULL];
+    fake3 = [self prefs_get_string:@PREFS_FAKE_BUTTON3 default:NULL];
+													      
+     if (fake2 != NULL) darwinFakeMouse2Mask = DarwinParseModifierList(fake2);
+     if (fake3 != NULL) darwinFakeMouse3Mask = DarwinParseModifierList(fake3);
 		
-    }
+  }
 	
-    X11EnableKeyEquivalents = [self prefs_get_boolean:@PREFS_KEYEQUIVS
-											  default:X11EnableKeyEquivalents];
+  X11EnableKeyEquivalents = [self prefs_get_boolean:@PREFS_KEYEQUIVS
+				  default:X11EnableKeyEquivalents];
 	
-    darwinSyncKeymap = [self prefs_get_boolean:@PREFS_SYNC_KEYMAP
-									   default:darwinSyncKeymap];
+  darwinSyncKeymap = [self prefs_get_boolean:@PREFS_SYNC_KEYMAP
+			   default:darwinSyncKeymap];
 	
-    tem = [self prefs_get_string:@PREFS_KEYMAP_FILE default:NULL];
-    if (tem != NULL)
-		darwinKeymapFile = strdup (tem);
-    else
-        darwinKeymapFile = NULL;
+  tem = [self prefs_get_string:@PREFS_KEYMAP_FILE default:NULL];
+
+  if (tem != NULL) darwinKeymapFile = strdup (tem);
+  else darwinKeymapFile = NULL;
 	
-    darwinDesiredDepth = [self prefs_get_integer:@PREFS_DEPTH
-										 default:darwinDesiredDepth];
+  darwinDesiredDepth = [self prefs_get_integer:@PREFS_DEPTH
+			     default:darwinDesiredDepth];
 	
-    enable_stereo = [self prefs_get_boolean:@PREFS_ENABLE_STEREO
-									default:false];
+  enable_stereo = [self prefs_get_boolean:@PREFS_ENABLE_STEREO
+			default:false];
 }
 
 /* This will end up at the end of the responder chain. */
-- (void) copy:sender
-{
-    QuartzMessageServerThread (kXDarwinPasteboardNotify, 1,
-							   AppleWMCopyToPasteboard);
+- (void) copy:sender {
+  QuartzMessageServerThread (kXDarwinPasteboardNotify, 1,
+			     AppleWMCopyToPasteboard);
 }
 
-- (BOOL) x_active
-{
+- (BOOL) x_active {
     return _x_active;
 }
 
@@ -771,75 +661,62 @@ cfarray_to_nsarray (CFArrayRef in)
 
 static NSArray *
 array_with_strings_and_numbers (int nitems, const char **items,
-								const char *numbers)
-{
-    NSMutableArray *array, *subarray;
-    NSString *string;
-    NSString *number;
-    int i;
-	
-    /* (Can't autorelease on the X server thread) */
-	
-    array = [[NSMutableArray alloc] initWithCapacity:nitems];
-	
-    for (i = 0; i < nitems; i++)
-    {
-		subarray = [[NSMutableArray alloc] initWithCapacity:2];
-		
-		string = [[NSString alloc] initWithUTF8String:items[i]];
-		[subarray addObject:string];
-		[string release];
-		
-		if (numbers[i] != 0)
-		{
-			number = [[NSString alloc] initWithFormat:@"%d", numbers[i]];
-			[subarray addObject:number];
-			[number release];
-		}
-		else
-			[subarray addObject:@""];
-		
-		[array addObject:subarray];
-		[subarray release];
-    }
-	
-    return array;
-}
-
-void
-X11ApplicationSetWindowMenu (int nitems, const char **items,
-							 const char *shortcuts)
-{
-    NSArray *array;
-    array = array_with_strings_and_numbers (nitems, items, shortcuts);
-	
-    /* Send the array of strings over to the appkit thread */
-	
-    message_kit_thread (@selector (set_window_menu:), array);
-    [array release];
-}
-
-void
-X11ApplicationSetWindowMenuCheck (int idx)
-{
-    NSNumber *n;
-	
-    n = [[NSNumber alloc] initWithInt:idx];
-	
-    message_kit_thread (@selector (set_window_menu_check:), n);
-	
-    [n release];
+				const char *numbers) {
+  NSMutableArray *array, *subarray;
+  NSString *string, *number;
+  int i;
+	
+  /* (Can't autorelease on the X server thread) */
+  
+  array = [[NSMutableArray alloc] initWithCapacity:nitems];
+  
+  for (i = 0; i < nitems; i++) {
+    subarray = [[NSMutableArray alloc] initWithCapacity:2];
+    
+    string = [[NSString alloc] initWithUTF8String:items[i]];
+    [subarray addObject:string];
+    [string release];
+    
+    if (numbers[i] != 0) {
+      number = [[NSString alloc] initWithFormat:@"%d", numbers[i]];
+      [subarray addObject:number];
+      [number release];
+    } else
+      [subarray addObject:@""];
+    
+    [array addObject:subarray];
+    [subarray release];
+  }
+  
+  return array;
+}
+
+void X11ApplicationSetWindowMenu (int nitems, const char **items,
+				  const char *shortcuts) {
+  NSArray *array;
+  array = array_with_strings_and_numbers (nitems, items, shortcuts);
+  
+  /* Send the array of strings over to the appkit thread */
+  
+  message_kit_thread (@selector (set_window_menu:), array);
+  [array release];
+}
+
+void X11ApplicationSetWindowMenuCheck (int idx) {
+  NSNumber *n;
+  
+  n = [[NSNumber alloc] initWithInt:idx];
+  
+  message_kit_thread (@selector (set_window_menu_check:), n);
+  
+  [n release];
 }
 
-void
-X11ApplicationSetFrontProcess (void)
-{
+void X11ApplicationSetFrontProcess (void) {
     message_kit_thread (@selector (set_front_process:), nil);
 }
 
-void
-X11ApplicationSetCanQuit (int state)
-{
+void X11ApplicationSetCanQuit (int state) {
     NSNumber *n;
 	
     n = [[NSNumber alloc] initWithBool:state];
@@ -849,15 +726,11 @@ X11ApplicationSetCanQuit (int state)
     [n release];
 }
 
-void
-X11ApplicationServerReady (void)
-{
+void X11ApplicationServerReady (void) {
     message_kit_thread (@selector (server_ready:), nil);
 }
 
-void
-X11ApplicationShowHideMenubar (int state)
-{
+void X11ApplicationShowHideMenubar (int state) {
     NSNumber *n;
 	
     n = [[NSNumber alloc] initWithBool:state];
@@ -867,27 +740,20 @@ X11ApplicationShowHideMenubar (int state
     [n release];
 }
 
-static void *
-create_thread (void *func, void *arg)
-{
+static void * create_thread (void *func, void *arg) {
     pthread_attr_t attr;
     pthread_t tid;
 	
     pthread_attr_init (&attr);
-	
     pthread_attr_setscope (&attr, PTHREAD_SCOPE_SYSTEM);
     pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
-	
     pthread_create (&tid, &attr, func, arg);
-	
     pthread_attr_destroy (&attr);
 	
     return (void *) tid;
 }
 
-static void
-check_xinitrc (void)
-{
+static void check_xinitrc (void) {
     char *tem, buf[1024];
     NSString *msg;
 	
@@ -895,8 +761,7 @@ check_xinitrc (void)
 		return;
 	
     tem = getenv ("HOME");
-    if (tem == NULL)
-		goto done;
+    if (tem == NULL) goto done;
 	
     snprintf (buf, sizeof (buf), "%s/.xinitrc", tem);
     if (access (buf, F_OK) != 0)
@@ -904,48 +769,44 @@ check_xinitrc (void)
 	
     /* FIXME: put localized strings into Resources/English.lproj */
 	
-    msg = NSLocalizedString (
-							 @"You have an existing ~/.xinitrc file.\n\n\
-							 Windows displayed by X11 applications may not have titlebars, or may look \
-							 different to windows displayed by native applications.\n\n\
-							 Would you like to move aside the existing file and use the standard X11 \
-							 environment?", @"Startup xinitrc dialog");
+    msg = NSLocalizedString (@"You have an existing ~/.xinitrc file.\n\n\
+Windows displayed by X11 applications may not have titlebars, or may look \
+different to windows displayed by native applications.\n\n\
+Would you like to move aside the existing file and use the standard X11 \
+environment?", @"Startup xinitrc dialog");
 	
     if (NSRunAlertPanel (nil, msg, NSLocalizedString (@"Yes", @""),
-						 NSLocalizedString (@"No", @""), nil)
-		== NSAlertDefaultReturn)
-    {
-		char buf2[1024];
-		int i = -1;
-		
-		snprintf (buf2, sizeof (buf2), "%s.old", buf);
-		
-		for (i = 1; access (buf2, F_OK) == 0; i++)
-			snprintf (buf2, sizeof (buf2), "%s.old.%d", buf, i);
-		
-		rename (buf, buf2);
+			 NSLocalizedString (@"No", @""), nil)
+	== NSAlertDefaultReturn) {
+      char buf2[1024];
+      int i = -1;
+      
+      snprintf (buf2, sizeof (buf2), "%s.old", buf);
+      
+      for (i = 1; access (buf2, F_OK) == 0; i++)
+	snprintf (buf2, sizeof (buf2), "%s.old.%d", buf, i);
+      
+      rename (buf, buf2);
     }
     
-	done:
+ done:
     [X11App prefs_set_boolean:@PREFS_DONE_XINIT_CHECK value:YES];
     [X11App prefs_synchronize];
 }
 
-void
-X11ApplicationMain (int argc, const char *argv[],
-					void (*server_thread) (void *), void *server_arg)
-{
+void X11ApplicationMain (int argc, const char *argv[],
+			 void (*server_thread) (void *), void *server_arg) {
     NSAutoreleasePool *pool;
 	
 #ifdef DEBUG
-    while (access ("/tmp/x11-block", F_OK) == 0)
-		sleep (1);
+    while (access ("/tmp/x11-block", F_OK) == 0) sleep (1);
 #endif
 	
     pool = [[NSAutoreleasePool alloc] init];
 	
     X11App = (X11Application *) [X11Application sharedApplication];
-	
+    quartzEvents = (xEvent *)malloc(sizeof(xEvent) * GetMaximumEventsNum());
+
     init_ports ();
 	
     [NSApp read_defaults];
@@ -953,8 +814,8 @@ X11ApplicationMain (int argc, const char
     [NSBundle loadNibNamed:@"main" owner:NSApp];
 	
     [[NSNotificationCenter defaultCenter] addObserver:NSApp
-											 selector:@selector (became_key:)
-												 name:NSWindowDidBecomeKeyNotification object:nil];
+					  selector:@selector (became_key:)
+					  name:NSWindowDidBecomeKeyNotification object:nil];
 	
     check_xinitrc ();
 	
@@ -966,173 +827,136 @@ X11ApplicationMain (int argc, const char
 	
     /* Calculate the height of the menubar so we can avoid it. */
     aquaMenuBarHeight = NSHeight([[NSScreen mainScreen] frame]) -
-	NSMaxY([[NSScreen mainScreen] visibleFrame]) - 1;
+      NSMaxY([[NSScreen mainScreen] visibleFrame]) - 1;
 	
-    if (!create_thread (server_thread, server_arg))
-    {
-		fprintf (stderr, "can't create secondary thread\n");
-		exit (1);
+    if (!create_thread (server_thread, server_arg)) {
+      ErrorF("can't create secondary thread\n");
+      exit(1);
     }
 	
     [NSApp run];
-	
-    /* not reached */
 }
 
 
 /* event conversion */
 
 static inline unsigned short
-convert_flags (unsigned int nsflags)
-{
-    unsigned int xflags;
+convert_flags (unsigned int nsflags) {
+    unsigned int xflags = 0;
 	
     if (nsflags == ~0) return 0xffff;
 	
-    xflags = 0;
-	
     if (nsflags & NSAlphaShiftKeyMask)	xflags |= LockMask;
-    if (nsflags & NSShiftKeyMask)		xflags |= ShiftMask;
-    if (nsflags & NSControlKeyMask)		xflags |= ControlMask;
+    if (nsflags & NSShiftKeyMask)	xflags |= ShiftMask;
+    if (nsflags & NSControlKeyMask)	xflags |= ControlMask;
     if (nsflags & NSAlternateKeyMask)	xflags |= Mod1Mask;
-    if (nsflags & NSCommandKeyMask)		xflags |= Mod2Mask;
+    if (nsflags & NSCommandKeyMask)	xflags |= Mod2Mask;
     /* FIXME: secondaryfn? */
 	
     return xflags;
 }
 
-static void
-send_nsevent (NSEventType type, NSEvent *e)
-{
+// This code should probably be merged with that in XDarwin's XServer.m - BB
+static void send_nsevent (NSEventType type, NSEvent *e) {
     static unsigned int button_state = 0;
     NSRect screen;
     NSPoint location;
     NSWindow *window;
-    int pointer_x, pointer_y;
+    int pointer_x, pointer_y, ev_button, ev_type; 
+    int num_events=0, i=0, state;
+    int valuators[2];
+    float count;
     xEvent xe;
+    
+    bzero(&xe, sizeof(xe));
+    input_check_flag++;
 	
-    memset (&xe, 0, sizeof (xe));
-	
-    /* This field should be filled in for every event */
-    xe.u.keyButtonPointer.time = GetTimeInMillis();
-
-	/* convert location to global top-left coordinates */
-	location = [e locationInWindow];
-	window = [e window];
-	screen = [[[NSScreen screens] objectAtIndex:0] frame];
-		
-	if (window != nil)	{
-		NSRect frame = [window frame];
-		pointer_x = location.x + frame.origin.x;
-		pointer_y = (((screen.origin.y + screen.size.height)
-					  - location.y) - frame.origin.y);
-	} else {
-		pointer_x = location.x;
-		pointer_y = (screen.origin.y + screen.size.height) - location.y;
+    /* convert location to global top-left coordinates */
+    location = [e locationInWindow];
+    window = [e window];
+    screen = [[[NSScreen screens] objectAtIndex:0] frame];
+		
+    if (window != nil)	{
+      NSRect frame = [window frame];
+      pointer_x = location.x + frame.origin.x;
+      pointer_y = (((screen.origin.y + screen.size.height)
+		    - location.y) - frame.origin.y);
+    } else {
+      pointer_x = location.x;
+      pointer_y = (screen.origin.y + screen.size.height) - location.y;
+    }
+    
+    ErrorF("send_nsevent: type=%d pointer=(%d,%d)\n", type, pointer_x, pointer_y);
+    
+    valuators[0] = pointer_x;
+    valuators[1] = pointer_y;
+    state = convert_flags ([e modifierFlags]);
+    
+    switch (type) {
+    case NSLeftMouseDown:    ev_button=1; ev_type=ButtonPress; goto handle_mouse;
+    case NSOtherMouseDown:   ev_button=2; ev_type=ButtonPress; goto handle_mouse;
+    case NSRightMouseDown:   ev_button=3; ev_type=ButtonPress; goto handle_mouse;
+    case NSLeftMouseUp:      ev_button=1; ev_type=ButtonRelease; goto handle_mouse;
+    case NSOtherMouseUp:     ev_button=2; ev_type=ButtonRelease; goto handle_mouse;
+    case NSRightMouseUp:     ev_button=3; ev_type=ButtonRelease; goto handle_mouse;
+    case NSLeftMouseDragged:  ev_button=1; ev_type=MotionNotify; goto handle_mouse;
+    case NSOtherMouseDragged: ev_button=2; ev_type=MotionNotify; goto handle_mouse;
+    case NSRightMouseDragged: ev_button=3; ev_type=MotionNotify; goto handle_mouse;
+    case NSMouseMoved: ev_button=0; ev_type=MotionNotify; goto handle_mouse;
+    handle_mouse:
+      
+      if(ev_type==ButtonPress) {
+	if (!quartzProcs->IsX11Window([e window], [e windowNumber])) {
+	  fprintf(stderr, "Dropping event because it's not a window\n");
+	  break;
 	}
-		
-	xe.u.keyButtonPointer.rootX = pointer_x;
-	xe.u.keyButtonPointer.rootY = pointer_y;
-	
-	switch (type) {
-		float count;
-		
-    case NSLeftMouseDown:
-		xe.u.u.type = ButtonPress;
-		xe.u.u.detail = 1;
-		goto do_press_event;
-		
-    case NSRightMouseDown:
-		xe.u.u.type = ButtonPress;
-		xe.u.u.detail = 3;
-		goto do_press_event;
-		
-    case NSOtherMouseDown:
-		xe.u.u.type = ButtonPress;
-		xe.u.u.detail = 2; /* FIXME? */
-		goto do_press_event;
-		
-do_press_event:
-		if (!quartzProcs->IsX11Window([e window], [e windowNumber])) {
-			/* X server doesn't grok this window, drop the event.
-			 
-			 Note: theoretically this isn't necessary, but if I click
-			 on the menubar, we get sent a LeftMouseDown when the
-			 release happens, but no LeftMouseUp is ever seen! */
-			
-			break;
-		}
-		goto do_event;
-		
-    case NSLeftMouseUp:
-		xe.u.u.type = ButtonRelease;
-		xe.u.u.detail = 1;
-		goto do_release_event;
-		
-    case NSRightMouseUp:
-		xe.u.u.type = ButtonRelease;
-		xe.u.u.detail = 3;
-		goto do_release_event;
-		
-    case NSOtherMouseUp:
-		xe.u.u.type = ButtonRelease;
-		xe.u.u.detail = 2; /* FIXME? */
-		goto do_release_event;
-		
-do_release_event:
-		if ((button_state & (1 << xe.u.u.detail)) == 0)
-		{
-			/* X didn't see the button press for this release, so skip it */
-			break;
-		}
-		goto do_event;
-		
-    case NSMouseMoved:
-    case NSLeftMouseDragged:
-    case NSRightMouseDragged:
-    case NSOtherMouseDragged:
-		xe.u.u.type = MotionNotify;
-		goto do_event;
-		
+	button_state |= (1 << ev_button);
+      } else if (ev_type==ButtonRelease && (button_state & (1 << ev_button)) == 0) break;
+      
+      num_events = GetPointerEvents(quartzEvents, darwinPointer, ev_type, ev_button, 
+				    POINTER_ABSOLUTE, 0, 2, valuators);
+      
+      ErrorF("GetPointerEvents returned %d events\n", num_events);
+      for(i=0; i<num_events; i++) {
+	ErrorF("qe[%d].u.u.type=%d\n", i, quartzEvents[i].u.u.type);
+//				quartzEvents[i].u.keyButtonPointer.state = state;
+	mieqEnqueue (darwinPointer,&quartzEvents[i]);
+      }
+      break;
+    case NSScrollWheel: 
+      count = [e deltaY];
+      ev_button = count > 0.0f ? 4 : 5;
+      for (count = fabs(count); count > 0.0; count = count - 1.0f) {
+	num_events = GetPointerEvents(quartzEvents, darwinPointer, ButtonPress, ev_button, 
+				      POINTER_ABSOLUTE, 0, 2, valuators);
+	for(i=0; i<num_events; i++) {
+//						quartzEvents[i].u.keyButtonPointer.state = state;
+	  mieqEnqueue(darwinPointer,&quartzEvents[i]);
+	}
+	num_events = GetPointerEvents(quartzEvents, darwinPointer, ButtonRelease, ev_button, 
+				      POINTER_ABSOLUTE, 0, 2, valuators);
+	for(i=0; i<num_events; i++) {
+//						quartzEvents[i].u.keyButtonPointer.state = state;
+	  mieqEnqueue(darwinPointer,&quartzEvents[i]);
+	}
+      }
+      break;
+      
     case NSKeyDown:
-		xe.u.u.type = KeyPress;
-		xe.u.u.detail = [e keyCode];
-		goto do_event;
-		
     case NSKeyUp:
-		xe.u.u.type = KeyRelease;
-		xe.u.u.detail = [e keyCode];
-		goto do_event;
-		
-    case NSScrollWheel:
-		xe.u.keyButtonPointer.state = convert_flags ([e modifierFlags]);
-		count = [e deltaY];
-		xe.u.u.detail = count > 0.0f ? 4 : 5;
-		for (count = fabs(count); count > 0.0; count = count - 1.0f) {
-			xe.u.u.type = ButtonPress;
-			DarwinEQEnqueue(&xe);
-			xe.u.u.type = ButtonRelease;
-			DarwinEQEnqueue(&xe);
-		}
-		xe.u.u.type = 0;
-		break;
-		
+      num_events = GetKeyboardEvents(quartzEvents, darwinKeyboard, 
+				     (type == NSKeyDown)?KeyPress:KeyRelease, [e keyCode]);
+      for(i=0; i<num_events; i++) {
+//				quartzEvents[i].u.keyButtonPointer.state = state;
+	mieqEnqueue(darwinKeyboard,&quartzEvents[i]);
+      }
+      break;
     case NSFlagsChanged:
-        xe.u.u.type = kXDarwinUpdateModifiers;
-        xe.u.clientMessage.u.l.longs0 = [e modifierFlags];
-        DarwinEQEnqueue (&xe);
-        break;
-		
-do_event:
-		//	xe.u.keyButtonPointer.state = convert_flags ([e modifierFlags]);
-		DarwinEQEnqueue (&xe);
-		break;
-		
+      xe.u.u.type = kXDarwinUpdateModifiers;
+      xe.u.clientMessage.u.l.longs0 = [e modifierFlags];
+      DarwinEQEnqueue (&xe);
+      break;
     default: break; /* for gcc */
-    }
-	
-    if (xe.u.u.type == ButtonPress)
-		button_state |= (1 << xe.u.u.detail);
-    else if (xe.u.u.type == ButtonRelease)
-		button_state &= ~(1 << xe.u.u.detail);
+    }	
+    //	UpdateCurrentTime();
 }
diff --git a/hw/darwin/darwinEvents.c b/hw/darwin/darwinEvents.c
index 6b902df..2a27ac4 100644
--- a/hw/darwin/darwinEvents.c
+++ b/hw/darwin/darwinEvents.c
@@ -1,9 +1,9 @@
 /*
- * Darwin event queue and event handling
- */
-/*
-Copyright (c) 2002-2004 Torrey T. Lyons. All Rights Reserved.
+Darwin event queue and event handling
+
+Copyright 2007 Apple Inc.
 Copyright 2004 Kaleb S. KEITHLEY. All Rights Reserved.
+Copyright (c) 2002-2004 Torrey T. Lyons. All Rights Reserved.
 
 This file is based on mieq.c by Keith Packard,
 which contains the following copyright:
@@ -61,6 +61,8 @@ typedef struct _Event {
     ScreenPtr   pScreen;
 } EventRec, *EventPtr;
 
+int input_check_zero, input_check_flag;
+
 typedef struct _EventQueue {
     HWEventQueueType    head, tail; /* long for SetInputCheck */
     CARD32      lastEventTime;      /* to avoid time running backwards */
@@ -73,7 +75,6 @@ typedef struct _EventQueue {
 
 static EventQueueRec darwinEventQueue;
 
-
 /*
  * DarwinPressModifierMask
  *  Press or release the given modifier key, specified by its mask.
@@ -177,18 +178,15 @@ static void DarwinSimulateMouseClick(
 }
 
 
-Bool
-DarwinEQInit(
-    DevicePtr pKbd,
-    DevicePtr pPtr)
-{
+Bool DarwinEQInit(DevicePtr pKbd, DevicePtr pPtr) { 
+    mieqInit();
     darwinEventQueue.head = darwinEventQueue.tail = 0;
     darwinEventQueue.lastEventTime = GetTimeInMillis ();
     darwinEventQueue.pKbd = pKbd;
     darwinEventQueue.pPtr = pPtr;
     darwinEventQueue.pEnqueueScreen = screenInfo.screens[0];
     darwinEventQueue.pDequeueScreen = darwinEventQueue.pEnqueueScreen;
-    SetInputCheck (&darwinEventQueue.head, &darwinEventQueue.tail);
+    SetInputCheck(&input_check_zero, &input_check_flag);
     return TRUE;
 }
 
@@ -199,11 +197,10 @@ DarwinEQInit(
  *    DarwinEQEnqueue    - called from event gathering thread
  *    ProcessInputEvents - called from X server thread
  *  DarwinEQEnqueue should never be called from more than one thread.
+ * 
+ * This should be deprecated in favor of miEQEnqueue -- BB
  */
-void
-DarwinEQEnqueue(
-    const xEvent *e)
-{
+void DarwinEQEnqueue(const xEvent *e) {
     HWEventQueueType oldtail, newtail;
     char byte = 0;
 
@@ -213,13 +210,12 @@ DarwinEQEnqueue(
     // This is difficult to do in a thread-safe way and rarely useful.
 
     newtail = oldtail + 1;
-    if (newtail == QUEUE_SIZE)
-        newtail = 0;
+    if (newtail == QUEUE_SIZE) newtail = 0;
     /* Toss events which come in late */
-    if (newtail == darwinEventQueue.head)
-        return;
+    if (newtail == darwinEventQueue.head) return;
 
     darwinEventQueue.events[oldtail].event = *e;
+
     /*
      * Make sure that event times don't go backwards - this
      * is "unnecessary", but very useful
@@ -244,20 +240,13 @@ DarwinEQEnqueue(
  * DarwinEQPointerPost
  *  Post a pointer event. Used by the mipointer.c routines.
  */
-void
-DarwinEQPointerPost(
-    xEvent *e)
-{
+void DarwinEQPointerPost(xEvent *e) {
     (*darwinEventQueue.pPtr->processInputProc)
             (e, (DeviceIntPtr)darwinEventQueue.pPtr, 1);
 }
 
 
-void
-DarwinEQSwitchScreen(
-    ScreenPtr   pScreen,
-    Bool        fromDIX)
-{
+void DarwinEQSwitchScreen(ScreenPtr pScreen, Bool fromDIX) {
     darwinEventQueue.pEnqueueScreen = pScreen;
     if (fromDIX)
         darwinEventQueue.pDequeueScreen = pScreen;
@@ -268,8 +257,7 @@ DarwinEQSwitchScreen(
  * ProcessInputEvents
  *  Read and process events from the event queue until it is empty.
  */
-void ProcessInputEvents(void)
-{
+void ProcessInputEvents(void) {
     EventRec *e;
     int     x, y;
     xEvent  xe;
@@ -277,12 +265,15 @@ void ProcessInputEvents(void)
     // button number and modifier mask of currently pressed fake button
     static int darwinFakeMouseButtonDown = 0;
     static int darwinFakeMouseButtonMask = 0;
+    input_check_flag=0;
+
+    ErrorF("calling mieqProcessInputEvents\n");
+    mieqProcessInputEvents();
 
     // Empty the signaling pipe
     x = sizeof(xe);
-    while (x == sizeof(xe)) {
+    while (x == sizeof(xe)) 
         x = read(darwinEventReadFD, &xe, sizeof(xe));
-    }
 
     while (darwinEventQueue.head != darwinEventQueue.tail)
     {
@@ -298,10 +289,16 @@ void ProcessInputEvents(void)
                 dixScreenOrigins[miPointerCurrentScreen()->myNum].x;
         xe.u.keyButtonPointer.rootY -= darwinMainScreenY +
                 dixScreenOrigins[miPointerCurrentScreen()->myNum].y;
+	
+	ErrorF("old rootX = (%d,%d) darwinMainScreen = (%d,%d) dixScreenOrigins[%d]=(%d,%d)\n",
+	       xe.u.keyButtonPointer.rootX, xe.u.keyButtonPointer.rootY,
+	       darwinMainScreenX, darwinMainScreenY,
+	       miPointerCurrentScreen()->myNum,
+	       dixScreenOrigins[miPointerCurrentScreen()->myNum].x,
+	       dixScreenOrigins[miPointerCurrentScreen()->myNum].y);
+
+	//Assumption - screen switching can only occur on motion events
 
-        /*
-         * Assumption - screen switching can only occur on motion events
-         */
         if (e->pScreen != darwinEventQueue.pDequeueScreen)
         {
             darwinEventQueue.pDequeueScreen = e->pScreen;
diff-tree ed7ccc481ad1caaa518cafe944c2327a5d0b6c65 (from 90ca76ba28fcd8bed945e33cf9674784fa2eb533)
Author: Ben Byer <bbyer at bbyer.(none)>
Date:   Thu Mar 1 00:51:10 2007 -0800

    AIGLX support for Darwin -- works well enough to run
    glxgears and glxinfo, but still needs more testing.

diff --git a/GL/apple/indirect.c b/GL/apple/indirect.c
index 8cba1c6..ba54186 100644
--- a/GL/apple/indirect.c
+++ b/GL/apple/indirect.c
@@ -1,11 +1,10 @@
 /*
  * GLX implementation that uses Apple's OpenGL.framework
  * (Indirect rendering path)
- */
-/*
- * Copyright (c) 2002 Greg Parker. All Rights Reserved.
- * Copyright (c) 2002 Apple Computer, Inc.
+ *
+ * Copyright (c) 2007 Apple Inc.
  * Copyright (c) 2004 Torrey T. Lyons. All Rights Reserved.
+ * Copyright (c) 2002 Greg Parker. All Rights Reserved.
  *
  * Portions of this file are copied from Mesa's xf86glx.c,
  * which contains the following copyright:
@@ -39,11 +38,12 @@
 #include "dri.h"
 #include "quartz.h"
 
-#include <CoreGraphics/CoreGraphics.h>
+//#include <CoreGraphics/CoreGraphics.h>
 #include <OpenGL/OpenGL.h>
 #include <OpenGL/CGLContext.h>
 
 // X11 and X11's glx
+#include <GL/gl.h>
 #include <miscstruct.h>
 #include <windowstr.h>
 #include <resource.h>
@@ -61,11 +61,16 @@
 #include "x-hash.h"
 #include "x-list.h"
 
+#include <dispatch.h>
+
 #include "glcontextmodes.h"
+#include <glapi.h>
+#include <glapitable.h>
 
 // ggs: needed to call back to glx with visual configs
 extern void GlxSetVisualConfigs(int nconfigs, __GLXvisualConfig *configs, void **configprivs);
 
+#define GLAQUA_DEBUG 1
 
 // Write debugging output, or not
 #ifdef GLAQUA_DEBUG
@@ -74,182 +79,163 @@ extern void GlxSetVisualConfigs(int ncon
 #define GLAQUA_DEBUG_MSG(a, ...)
 #endif
 
-
-// The following GL functions don't have an EXT suffix in OpenGL.framework.
-GLboolean glAreTexturesResidentEXT(GLsizei a, const GLuint *b, GLboolean *c) {
-    return glAreTexturesResident(a, b, c);
-}
-void glDeleteTexturesEXT(GLsizei d, const GLuint *e) {
-    glDeleteTextures(d, e);
-}
-void glGenTexturesEXT(GLsizei f, GLuint *g) {
-    glGenTextures(f, g);
-}
-GLboolean glIsTextureEXT(GLuint h) {
-    return glIsTexture(h);
-}
+static void setup_dispatch_table(void);
 
 // some prototypes
-static Bool glAquaScreenProbe(int screen);
+static __GLXscreen * __glXAquaScreenProbe(ScreenPtr pScreen);
 static Bool glAquaInitVisuals(VisualPtr *visualp, DepthPtr *depthp,
                               int *nvisualp, int *ndepthp,
                               int *rootDepthp, VisualID *defaultVisp,
                               unsigned long sizes, int bitsPerRGB);
 static void glAquaSetVisualConfigs(int nconfigs, __GLXvisualConfig *configs,
                                    void **privates);
+
 static __GLinterface *glAquaCreateContext(__GLimports *imports,
                                           __GLcontextModes *mode,
                                           __GLinterface *shareGC);
-static void glAquaCreateBuffer(__GLXdrawablePrivate *glxPriv);
 static void glAquaResetExtension(void);
-
-/*
- * This structure is statically allocated in the __glXScreens[]
- * structure.  This struct is not used anywhere other than in
- * __glXScreenInit to initialize each of the active screens
- * (__glXActiveScreens[]).  Several of the fields must be initialized by
- * the screenProbe routine before they are copied to the active screens
- * struct.  In particular, the contextCreate, modes, numVisuals,
- * and numUsableVisuals fields must be initialized.
- */
-static __GLXscreenInfo __glDDXScreenInfo = {
-    glAquaScreenProbe,   /* Must be generic and handle all screens */
-    glAquaCreateContext, /* Substitute screen's createContext routine */
-    glAquaCreateBuffer,  /* Substitute screen's createBuffer routine */
-    NULL,                 /* Set up modes in probe */
-    NULL,                 /* Set up pVisualPriv in probe */
-    0,                    /* Set up numVisuals in probe */
-    0,                    /* Set up numUsableVisuals in probe */
-    "Vendor String",      /* GLXvendor is overwritten by __glXScreenInit */
-    "Version String",     /* GLXversion is overwritten by __glXScreenInit */
-    "Extensions String",  /* GLXextensions is overwritten by __glXScreenInit */
-    NULL                  /* WrappedPositionWindow is overwritten */
-};
-
-void *__glXglDDXScreenInfo(void) {
-    return &__glDDXScreenInfo;
-}
-
-static __GLXextensionInfo __glDDXExtensionInfo = {
-    GL_CORE_APPLE,
-    glAquaResetExtension,
-    glAquaInitVisuals,
-    glAquaSetVisualConfigs
+static void __glXAquaContextDestroy(__GLXcontext *baseContext);
+static int __glXAquaContextMakeCurrent(__GLXcontext *baseContext);
+static int __glXAquaContextLoseCurrent(__GLXcontext *baseContext);
+static int __glXAquaContextForceCurrent(__GLXcontext *baseContext);
+static int __glXAquaContextCopy(__GLXcontext *baseDst, __GLXcontext *baseSrc, unsigned long mask);
+static __GLXdrawable * __glXAquaContextCreateDrawable(__GLXcontext *context, DrawablePtr pDraw, XID drawId);
+
+static CGLPixelFormatObj makeFormat(__GLcontextModes *mode);
+
+__GLXprovider __glXMesaProvider = {
+  __glXAquaScreenProbe,
+  "Core OpenGL",
+    NULL
 };
 
-void *__glXglDDXExtensionInfo(void) {
-    return &__glDDXExtensionInfo;
+__GLXprovider *
+GlxGetMesaProvider (void)
+{
+  ErrorF("GlxGetMesaProvider\n");
+  return &__glXMesaProvider;
 }
 
-// prototypes
-
-static GLboolean glAquaDestroyContext(__GLcontext *gc);
-static GLboolean glAquaLoseCurrent(__GLcontext *gc);
-static GLboolean glAquaMakeCurrent(__GLcontext *gc);
-static GLboolean glAquaShareContext(__GLcontext *gc, __GLcontext *gcShare);
-static GLboolean glAquaCopyContext(__GLcontext *dst, const __GLcontext *src,
-                                    GLuint mask);
-static GLboolean glAquaForceCurrent(__GLcontext *gc);
-
-/* Drawing surface notification callbacks */
-static GLboolean glAquaNotifyResize(__GLcontext *gc);
-static void glAquaNotifyDestroy(__GLcontext *gc);
-static void glAquaNotifySwapBuffers(__GLcontext *gc);
-
-/* Dispatch table override control for external agents like libGLS */
-static struct __GLdispatchStateRec* glAquaDispatchExec(__GLcontext *gc);
-static void glAquaBeginDispatchOverride(__GLcontext *gc);
-static void glAquaEndDispatchOverride(__GLcontext *gc);
-
-static __GLexports glAquaExports = {
-    glAquaDestroyContext,
-    glAquaLoseCurrent,
-    glAquaMakeCurrent,
-    glAquaShareContext,
-    glAquaCopyContext,
-    glAquaForceCurrent,
-
-    glAquaNotifyResize,
-    glAquaNotifyDestroy,
-    glAquaNotifySwapBuffers,
-
-    glAquaDispatchExec,
-    glAquaBeginDispatchOverride,
-    glAquaEndDispatchOverride
-};
+typedef struct __GLXAquaScreen   __GLXAquaScreen;
+typedef struct __GLXAquaContext  __GLXAquaContext;
+typedef struct __GLXAquaDrawable __GLXAquaDrawable;
 
-typedef struct {
+struct __GLXAquaScreen {
+  __GLXscreen   base;
+  int           index;
     int num_vis;
     __GLcontextModes *modes;
-    void **priv;
+};
 
-    // wrapped screen functions
-    RealizeWindowProcPtr RealizeWindow;
-    UnrealizeWindowProcPtr UnrealizeWindow;
-} glAquaScreenRec;
+static __GLXAquaScreen glAquaScreens[MAXSCREENS];
 
-static glAquaScreenRec glAquaScreens[MAXSCREENS];
+struct __GLXAquaContext {
+  __GLXcontext base;
+  CGLContextObj ctx;
+  CGLPixelFormatObj pixelFormat;
+  xp_surface_id sid;
+  unsigned isAttached :1;
+};
 
-// __GLdrawablePrivate->private
-typedef struct {
+struct __GLXAquaDrawable {
+  __GLXdrawable base;
     DrawablePtr pDraw;
     xp_surface_id sid;
-} GLAquaDrawableRec;
-
-struct __GLcontextRec {
-    struct __GLinterfaceRec interface; // required to be first
+};
 
-    CGLContextObj ctx;
-    CGLPixelFormatObj pixelFormat;
+static __GLXcontext *
+__glXAquaScreenCreateContext(__GLXscreen *screen,
+			     __GLcontextModes *modes,
+			     __GLXcontext *baseShareContext)
+{
+  __GLXAquaContext *context;
+  __GLXAquaContext *shareContext = (__GLXAquaContext *) baseShareContext;
+  CGLError gl_err;
+  
+  GLAQUA_DEBUG_MSG("glXAquaScreenCreateContext\n");
+
+  context = malloc (sizeof (__GLXAquaContext));
+  if (context == NULL) return NULL;
+
+  memset(context, 0, sizeof *context);
+
+  context->base.pGlxScreen = screen;
+  context->base.modes      = modes;
+
+  context->base.destroy        = __glXAquaContextDestroy;
+  context->base.makeCurrent    = __glXAquaContextMakeCurrent;
+  context->base.loseCurrent    = __glXAquaContextLoseCurrent;
+  context->base.copy           = __glXAquaContextCopy;
+  context->base.forceCurrent   = __glXAquaContextForceCurrent;
+  context->base.createDrawable = __glXAquaContextCreateDrawable;
+
+  context->pixelFormat = makeFormat(modes);
+  if (!context->pixelFormat) {
+        free(context);
+        return NULL;
+  }
 
-    /* set when attached */
-    xp_surface_id sid;
+  context->ctx = NULL;
+  gl_err = CGLCreateContext(context->pixelFormat,
+                            shareContext ? shareContext->ctx : NULL,
+                            &context->ctx);
+
+  if (gl_err != 0) {
+      ErrorF("CGLCreateContext error: %s\n", CGLErrorString(gl_err));
+      CGLDestroyPixelFormat(context->pixelFormat);
+      free(context);
+      return NULL;
+    }
+	setup_dispatch_table();
+    GLAQUA_DEBUG_MSG("glAquaCreateContext done\n");
+  return &context->base;
+}
 
-    unsigned isAttached :1;
+static __GLXextensionInfo __glDDXExtensionInfo = {
+    GL_CORE_APPLE,
+    glAquaResetExtension,
+    glAquaInitVisuals,
+    glAquaSetVisualConfigs
 };
 
+void *__glXglDDXExtensionInfo(void) {
+  GLAQUA_DEBUG_MSG("glXAglDDXExtensionInfo\n");
+    return &__glDDXExtensionInfo;
+}
+
 /* maps from surface id -> list of __GLcontext */
 static x_hash_table *surface_hash;
 
-
-// Context manipulation; return GL_FALSE on failure
-static GLboolean glAquaDestroyContext(__GLcontext *gc)
-{
+static void __glXAquaContextDestroy(__GLXcontext *baseContext) {
     x_list *lst;
 
-    GLAQUA_DEBUG_MSG("glAquaDestroyContext (ctx 0x%x)\n",
-                     (unsigned int) gc->ctx);
-
-    if (gc != NULL)
-    {
-        if (gc->sid != 0 && surface_hash != NULL)
-        {
-            lst = x_hash_table_lookup(surface_hash, (void *) gc->sid, NULL);
-            lst = x_list_remove(lst, gc);
-            x_hash_table_insert(surface_hash, (void *) gc->sid, lst);
-        }
+    __GLXAquaContext *context = (__GLXAquaContext *) baseContext;
 
-        if (gc->ctx != NULL)
-            CGLDestroyContext(gc->ctx);
+    GLAQUA_DEBUG_MSG("glAquaContextDestroy (ctx 0x%x)\n",
+                     (unsigned int) baseContext);
+    if (context != NULL) {
+      if (context->sid != 0 && surface_hash != NULL) {
+		lst = x_hash_table_lookup(surface_hash, (void *) context->sid, NULL);
+		lst = x_list_remove(lst, context);
+		x_hash_table_insert(surface_hash, (void *) context->sid, lst);
+      }
 
-        if (gc->pixelFormat != NULL)
-            CGLDestroyPixelFormat(gc->pixelFormat);
+      if (context->ctx != NULL) CGLDestroyContext(context->ctx);
 
-        free(gc);
+      if (context->pixelFormat != NULL)	CGLDestroyPixelFormat(context->pixelFormat);
+      
+      free(context);
     }
-
-    return GL_TRUE;
 }
 
-static GLboolean glAquaLoseCurrent(__GLcontext *gc)
-{
+static int __glXAquaContextLoseCurrent(__GLXcontext *baseContext) {
     CGLError gl_err;
 
-    GLAQUA_DEBUG_MSG("glAquaLoseCurrent (ctx 0x%x)\n", (unsigned int) gc->ctx);
+    GLAQUA_DEBUG_MSG("glAquaLoseCurrent (ctx 0x%p)\n", baseContext);
 
     gl_err = CGLSetCurrentContext(NULL);
     if (gl_err != 0)
-        ErrorF("CGLSetCurrentContext error: %s\n", CGLErrorString(gl_err));
+      ErrorF("CGLSetCurrentContext error: %s\n", CGLErrorString(gl_err));
 
     __glXLastContext = NULL; // Mesa does this; why?
 
@@ -258,141 +244,139 @@ static GLboolean glAquaLoseCurrent(__GLc
 
 /* Called when a surface is destroyed as a side effect of destroying
    the window it's attached to. */
-static void surface_notify(void *_arg, void *data)
-{
-    DRISurfaceNotifyArg *arg = _arg;
-    GLAquaDrawableRec *aquaPriv = data;
-    __GLcontext *gc;
+static void surface_notify(void *_arg, void *data) {
+    DRISurfaceNotifyArg *arg = (DRISurfaceNotifyArg *)_arg;
+    __GLXAquaDrawable *draw = (__GLXAquaDrawable *)data;
+    __GLXAquaContext *context;
     x_list *lst;
-
-    switch (arg->kind)
-    {
+	if(_arg == NULL || data == NULL) {
+		ErrorF("surface_notify called with bad params");
+		return;
+	}
+	
+    GLAQUA_DEBUG_MSG("surface_notify(%p, %p)\n", _arg, data);
+    switch (arg->kind) {
     case AppleDRISurfaceNotifyDestroyed:
         if (surface_hash != NULL)
             x_hash_table_remove(surface_hash, (void *) arg->id);
-
-        aquaPriv->pDraw = NULL;
-        aquaPriv->sid = 0;
+	        draw->base->pDraw = NULL;
+			draw->sid = 0;
         break;
 
     case AppleDRISurfaceNotifyChanged:
-        if (surface_hash != NULL)
-        {
+        if (surface_hash != NULL) {
             lst = x_hash_table_lookup(surface_hash, (void *) arg->id, NULL);
             for (; lst != NULL; lst = lst->next)
             {
-                gc = lst->data;
-                xp_update_gl_context(gc->ctx);
+                context = lst->data;
+                xp_update_gl_context(context->ctx);
             }
         }
         break;
+	default:
+		ErrorF("surface_notify: unknown kind %d\n", arg->kind);
+		break;
     }
 }
 
-static void unattach(__GLcontext *gc)
-{
-    x_list *lst;
-
-    if (gc->isAttached)
-    {
-        GLAQUA_DEBUG_MSG("unattaching\n");
-
-        if (surface_hash != NULL)
-        {
-            lst = x_hash_table_lookup(surface_hash, (void *) gc->sid, NULL);
-            lst = x_list_remove(lst, gc);
-            x_hash_table_insert(surface_hash, (void *) gc->sid, lst);
-        }
-
-        CGLClearDrawable(gc->ctx);
-        gc->isAttached = FALSE;
-        gc->sid = 0;
-    }
-}
-
-static void attach(__GLcontext *gc, __GLdrawablePrivate *glPriv)
-{
-    __GLXdrawablePrivate *glxPriv;
-    GLAquaDrawableRec *aquaPriv;
+static void attach(__GLXAquaContext *context, __GLXAquaDrawable *draw) {
     DrawablePtr pDraw;
+	GLAQUA_DEBUG_MSG("attach(%p, %p)\n", context, draw);
+    pDraw = draw->base.pDraw;
 
-    glxPriv = (__GLXdrawablePrivate *)glPriv->other;
-    aquaPriv = (GLAquaDrawableRec *)glPriv->private;
-    pDraw = glxPriv->pDraw;
-
-    if (aquaPriv->sid == 0)
-    {
-        if (!quartzProcs->CreateSurface(pDraw->pScreen, pDraw->id, pDraw,
-                                        0, &aquaPriv->sid, NULL,
-                                        surface_notify, aquaPriv))
-        {
+    if (draw->sid == 0) {
+//        if (!quartzProcs->CreateSurface(pDraw->pScreen, pDraw->id, pDraw,
+        if (!DRICreateSurface(pDraw->pScreen, pDraw->id, pDraw,
+                                        0, &draw->sid, NULL,
+                                        surface_notify, draw))
             return;
-        }
-        aquaPriv->pDraw = pDraw;
-    }
+        draw->pDraw = pDraw;
+	} 
 
-    if (!gc->isAttached || gc->sid != aquaPriv->sid)
-    {
+    if (!context->isAttached || context->sid != draw->sid) {
         x_list *lst;
 
-        if (xp_attach_gl_context(gc->ctx, aquaPriv->sid) != Success)
-        {
-            quartzProcs->DestroySurface(pDraw->pScreen, pDraw->id, pDraw,
-                                        surface_notify, aquaPriv);
+        if (xp_attach_gl_context(context->ctx, draw->sid) != Success) {
+//            quartzProcs->DestroySurface(pDraw->pScreen, pDraw->id, pDraw,
+            DRIDestroySurface(pDraw->pScreen, pDraw->id, pDraw,
+								surface_notify, draw);
             if (surface_hash != NULL)
-                x_hash_table_remove(surface_hash, (void *) aquaPriv->sid);
+                x_hash_table_remove(surface_hash, (void *) draw->sid);
 
-            aquaPriv->sid = 0;
+            draw->sid = 0;
             return;
         }
 
-        gc->isAttached = TRUE;
-        gc->sid = aquaPriv->sid;
+        context->isAttached = TRUE;
+        context->sid = draw->sid;
 
         if (surface_hash == NULL)
             surface_hash = x_hash_table_new(NULL, NULL, NULL, NULL);
 
-        lst = x_hash_table_lookup(surface_hash, (void *) gc->sid, NULL);
-        if (x_list_find(lst, gc) == NULL)
-        {
-            lst = x_list_prepend(lst, gc);
-            x_hash_table_insert(surface_hash, (void *) gc->sid, lst);
+        lst = x_hash_table_lookup(surface_hash, (void *) context->sid, NULL);
+        if (x_list_find(lst, context) == NULL) {
+            lst = x_list_prepend(lst, context);
+            x_hash_table_insert(surface_hash, (void *) context->sid, lst);
         }
 
         GLAQUA_DEBUG_MSG("attached 0x%x to 0x%x\n", (unsigned int) pDraw->id,
-                         (unsigned int) aquaPriv->sid);
+                         (unsigned int) draw->sid);
+    } 
+}
+
+static void unattach(__GLXAquaContext *context) {
+	x_list *lst;
+	GLAQUA_DEBUG_MSG("unattach\n");
+	if (context == NULL) {
+		ErrorF("Tried to unattach a null context\n");
+		return;
+	}
+    if (context->isAttached) {
+        GLAQUA_DEBUG_MSG("unattaching\n");
+
+        if (surface_hash != NULL) {
+            lst = x_hash_table_lookup(surface_hash, (void *) context->sid, NULL);
+            lst = x_list_remove(lst, context);
+            x_hash_table_insert(surface_hash, (void *) context->sid, lst);
+        }
+
+        CGLClearDrawable(context->ctx);
+        context->isAttached = FALSE;
+        context->sid = 0;
     }
 }
 
-static GLboolean glAquaMakeCurrent(__GLcontext *gc)
-{
-    __GLdrawablePrivate *glPriv = gc->interface.imports.getDrawablePrivate(gc);
+static int __glXAquaContextMakeCurrent(__GLXcontext *baseContext) {
     CGLError gl_err;
+    __GLXAquaContext *context = (__GLXAquaContext *) baseContext;
+	__GLXAquaDrawable *drawPriv = (__GLXAquaDrawable *) context->base.drawPriv;
+    __GLXAquaDrawable *readPriv = (__GLXAquaDrawable *) context->base.readPriv;
 
-    GLAQUA_DEBUG_MSG("glAquaMakeCurrent (ctx 0x%x)\n", (unsigned int) gc->ctx);
-
-    attach(gc, glPriv);
+    GLAQUA_DEBUG_MSG("glAquaMakeCurrent (ctx 0x%p)\n", baseContext);
+    
+    attach(context, drawPriv);
 
-    gl_err = CGLSetCurrentContext(gc->ctx);
+    gl_err = CGLSetCurrentContext(context->ctx);
     if (gl_err != 0)
         ErrorF("CGLSetCurrentContext error: %s\n", CGLErrorString(gl_err));
-
+    
     return gl_err == 0;
 }
 
 static GLboolean glAquaShareContext(__GLcontext *gc, __GLcontext *gcShare)
 {
   GLAQUA_DEBUG_MSG("glAquaShareContext unimplemented\n");
-
   return GL_TRUE;
 }
 
-static GLboolean glAquaCopyContext(__GLcontext *dst, const __GLcontext *src,
-                                   GLuint mask)
+static int __glXAquaContextCopy(__GLXcontext *baseDst, __GLXcontext *baseSrc, unsigned long mask)
 {
     CGLError gl_err;
 
-    GLAQUA_DEBUG_MSG("glAquaCopyContext\n");
+    __GLXAquaContext *dst = (__GLXAquaContext *) baseDst;
+    __GLXAquaContext *src = (__GLXAquaContext *) baseSrc;
+
+    GLAQUA_DEBUG_MSG("GLXAquaContextCopy\n");
 
     gl_err = CGLCopyContext(src->ctx, dst->ctx, mask);
     if (gl_err != 0)
@@ -401,14 +385,13 @@ static GLboolean glAquaCopyContext(__GLc
     return gl_err == 0;
 }
 
-static GLboolean glAquaForceCurrent(__GLcontext *gc)
+static int __glXAquaContextForceCurrent(__GLXcontext *baseContext)
 {
     CGLError gl_err;
+    __GLXAquaContext *context = (__GLXAquaContext *) baseContext;
+    GLAQUA_DEBUG_MSG("glAquaForceCurrent (ctx %p)\n", context->ctx);
 
-    GLAQUA_DEBUG_MSG("glAquaForceCurrent (ctx 0x%x)\n",
-                     (unsigned int) gc->ctx);
-
-    gl_err = CGLSetCurrentContext(gc->ctx);
+    gl_err = CGLSetCurrentContext(context->ctx);
     if (gl_err != 0)
         ErrorF("CGLSetCurrentContext error: %s\n", CGLErrorString(gl_err));
 
@@ -417,45 +400,41 @@ static GLboolean glAquaForceCurrent(__GL
 
 /* Drawing surface notification callbacks */
 
-static GLboolean glAquaNotifyResize(__GLcontext *gc)
-{
-    GLAQUA_DEBUG_MSG("unimplemented glAquaNotifyResize");
+static GLboolean __glXAquaDrawableResize(__GLXdrawable *base)  {
+    GLAQUA_DEBUG_MSG("unimplemented glAquaDrawableResize\n");
     return GL_TRUE;
 }
 
-static void glAquaNotifyDestroy(__GLcontext *gc)
-{
+static void glAquaNotifyDestroy(__GLcontext *gc) {
     GLAQUA_DEBUG_MSG("unimplemented glAquaNotifyDestroy");
 }
 
-static void glAquaNotifySwapBuffers(__GLcontext *gc)
-{
-    GLAQUA_DEBUG_MSG("unimplemented glAquaNotifySwapBuffers");
-}
-
-/* Dispatch table override control for external agents like libGLS */
-static struct __GLdispatchStateRec* glAquaDispatchExec(__GLcontext *gc)
-{
-    GLAQUA_DEBUG_MSG("unimplemented glAquaDispatchExec");
-    return NULL;
-}
+static GLboolean __glXAquaDrawableSwapBuffers(__GLXdrawable *base) {
+    __GLXAquaDrawable *glxPriv = (__GLXAquaDrawable *) base;
+    CGLError gl_err;
+	__GLXAquaContext * drawableCtx;
+//    GLAQUA_DEBUG_MSG("glAquaDrawableSwapBuffers(%p)\n",base);
+	
+	if(!base) {
+		ErrorF("glXAquaDrawbleSwapBuffers passed NULL\n");
+	    return GL_FALSE;
+	}
 
-static void glAquaBeginDispatchOverride(__GLcontext *gc)
-{
-    GLAQUA_DEBUG_MSG("unimplemented glAquaBeginDispatchOverride");
-}
+    drawableCtx = (__GLXAquaContext *)base->drawGlxc;
 
-static void glAquaEndDispatchOverride(__GLcontext *gc)
-{
-    GLAQUA_DEBUG_MSG("unimplemented glAquaEndDispatchOverride");
+    if (drawableCtx != NULL && drawableCtx->ctx != NULL) {
+        gl_err = CGLFlushDrawable(drawableCtx->ctx);
+        if (gl_err != 0)
+            ErrorF("CGLFlushDrawable error: %s\n", CGLErrorString(gl_err));
+    }
+    return GL_TRUE;
 }
 
-static CGLPixelFormatObj makeFormat(__GLcontextModes *mode)
-{
+static CGLPixelFormatObj makeFormat(__GLcontextModes *mode) {
     int i;
     CGLPixelFormatAttribute attr[64]; // currently uses max of 30
     CGLPixelFormatObj result;
-    long n_formats;
+    GLint n_formats;
     CGLError gl_err;
     
     GLAQUA_DEBUG_MSG("makeFormat\n");
@@ -491,10 +470,12 @@ static CGLPixelFormatObj makeFormat(__GL
         attr[i++] = mode->accumRedBits + mode->accumGreenBits
                     + mode->accumBlueBits + mode->accumAlphaBits;
     }
+	
     if (mode->haveDepthBuffer) {
         attr[i++] = kCGLPFADepthSize;
         attr[i++] = mode->depthBits;
     }
+	
     if (mode->haveStencilBuffer) {
         attr[i++] = kCGLPFAStencilSize;
         attr[i++] = mode->stencilBits;
@@ -521,129 +502,6 @@ static CGLPixelFormatObj makeFormat(__GL
     return result;
 }
 
-static __GLinterface *glAquaCreateContext(__GLimports *imports,
-                                          __GLcontextModes *mode,
-                                          __GLinterface *shareGC)
-{
-    __GLcontext *result;
-    __GLcontext *sharectx = (__GLcontext *)shareGC;
-    CGLError gl_err;
-
-    GLAQUA_DEBUG_MSG("glAquaCreateContext\n");
-
-    result = (__GLcontext *)calloc(1, sizeof(__GLcontext));
-    if (!result) return NULL;
-
-    result->interface.imports = *imports;
-    result->interface.exports = glAquaExports;
-
-    result->pixelFormat = makeFormat(mode);
-    if (!result->pixelFormat) {
-        free(result);
-        return NULL;
-    }
-
-    result->ctx = NULL;
-    gl_err = CGLCreateContext(result->pixelFormat,
-                              sharectx ? sharectx->ctx : NULL,
-                              &result->ctx);
-
-    if (gl_err != 0) {
-        ErrorF("CGLCreateContext error: %s\n", CGLErrorString(gl_err));
-        CGLDestroyPixelFormat(result->pixelFormat);
-        free(result);
-        return NULL;
-    }
-
-    GLAQUA_DEBUG_MSG("glAquaCreateContext done\n");
-    return (__GLinterface *)result;
-}
-
-Bool
-glAquaRealizeWindow(WindowPtr pWin)
-{
-    // If this window has GL contexts, tell them to reattach
-    Bool result;
-    ScreenPtr pScreen = pWin->drawable.pScreen;
-    glAquaScreenRec *screenPriv = &glAquaScreens[pScreen->myNum];
-    __GLXdrawablePrivate *glxPriv;
-
-    GLAQUA_DEBUG_MSG("glAquaRealizeWindow\n");
-
-    // Allow the window to be created (RootlessRealizeWindow is inside our wrap)
-    pScreen->RealizeWindow = screenPriv->RealizeWindow;
-    result = pScreen->RealizeWindow(pWin);
-    pScreen->RealizeWindow = glAquaRealizeWindow;
-
-    // The Aqua window will already have been created (windows are
-    // realized from top down)
-
-    // Re-attach this window's GL contexts, if any.
-    glxPriv = __glXFindDrawablePrivate(pWin->drawable.id);
-    if (glxPriv) {
-        __GLXcontext *gx;
-        __GLcontext *gc;
-        __GLdrawablePrivate *glPriv = &glxPriv->glPriv;
-        GLAQUA_DEBUG_MSG("glAquaRealizeWindow is GL drawable!\n");
-
-        // GL contexts bound to this window for drawing
-        for (gx = glxPriv->drawGlxc; gx != NULL; gx = gx->next) {
-            gc = (__GLcontext *)gx->gc;
-            attach(gc, glPriv);
-        }
-
-        // GL contexts bound to this window for reading
-        for (gx = glxPriv->readGlxc; gx != NULL; gx = gx->next) {
-            gc = (__GLcontext *)gx->gc;
-            attach(gc, glPriv);
-        }
-    }
-
-    return result;
-}
-
-Bool
-glAquaUnrealizeWindow(WindowPtr pWin)
-{
-    // If this window has GL contexts, tell them to unattach
-    Bool result;
-    ScreenPtr pScreen = pWin->drawable.pScreen;
-    glAquaScreenRec *screenPriv = &glAquaScreens[pScreen->myNum];
-    __GLXdrawablePrivate *glxPriv;
-
-    GLAQUA_DEBUG_MSG("glAquaUnrealizeWindow\n");
-
-    // The Aqua window may have already been destroyed (windows
-    // are unrealized from top down)
-
-    // Unattach this window's GL contexts, if any.
-    glxPriv = __glXFindDrawablePrivate(pWin->drawable.id);
-    if (glxPriv) {
-        __GLXcontext *gx;
-        __GLcontext *gc;
-        GLAQUA_DEBUG_MSG("glAquaUnealizeWindow is GL drawable!\n");
-
-        // GL contexts bound to this window for drawing
-        for (gx = glxPriv->drawGlxc; gx != NULL; gx = gx->next) {
-            gc = (__GLcontext *)gx->gc;
-            unattach(gc);
-        }
-
-        // GL contexts bound to this window for reading
-        for (gx = glxPriv->readGlxc; gx != NULL; gx = gx->next) {
-            gc = (__GLcontext *)gx->gc;
-            unattach(gc);
-        }
-    }
-
-    pScreen->UnrealizeWindow = screenPriv->UnrealizeWindow;
-    result = pScreen->UnrealizeWindow(pWin);
-    pScreen->UnrealizeWindow = glAquaUnrealizeWindow;
-
-    return result;
-}
-
-
 // Originally copied from Mesa
 
 static int                 numConfigs     = 0;
@@ -821,15 +679,15 @@ static Bool init_visuals(int *nvisualp, 
 
     /* Alloc space for the list of new GLX visuals */
     pNewVisualConfigs = (__GLXvisualConfig *)
-                     __glXMalloc(numNewConfigs * sizeof(__GLXvisualConfig));
+                     malloc(numNewConfigs * sizeof(__GLXvisualConfig));
     if (!pNewVisualConfigs) {
         return FALSE;
     }
 
     /* Alloc space for the list of new GLX visual privates */
-    pNewVisualPriv = (void **) __glXMalloc(numNewConfigs * sizeof(void *));
+    pNewVisualPriv = (void **) malloc(numNewConfigs * sizeof(void *));
     if (!pNewVisualPriv) {
-        __glXFree(pNewVisualConfigs);
+        free(pNewVisualConfigs);
         return FALSE;
     }
 
@@ -879,40 +737,40 @@ static Bool init_visuals(int *nvisualp, 
     numConfigs = 0;
 
     /* Alloc temp space for the list of orig VisualIDs for each new visual */
-    orig_vid = (VisualID *)__glXMalloc(numNewVisuals * sizeof(VisualID));
+    orig_vid = (VisualID *)malloc(numNewVisuals * sizeof(VisualID));
     if (!orig_vid) {
-        __glXFree(pNewVisualPriv);
-        __glXFree(pNewVisualConfigs);
+        free(pNewVisualPriv);
+        free(pNewVisualConfigs);
         return FALSE;
     }
 
     /* Alloc space for the list of glXVisuals */
     modes = _gl_context_modes_create(numNewVisuals, sizeof(__GLcontextModes));
     if (modes == NULL) {
-        __glXFree(orig_vid);
-        __glXFree(pNewVisualPriv);
-        __glXFree(pNewVisualConfigs);
+        free(orig_vid);
+        free(pNewVisualPriv);
+        free(pNewVisualConfigs);
         return FALSE;
     }
 
     /* Alloc space for the list of glXVisualPrivates */
-    glXVisualPriv = (void **)__glXMalloc(numNewVisuals * sizeof(void *));
+    glXVisualPriv = (void **)malloc(numNewVisuals * sizeof(void *));
     if (!glXVisualPriv) {
         _gl_context_modes_destroy( modes );
-        __glXFree(orig_vid);
-        __glXFree(pNewVisualPriv);
-        __glXFree(pNewVisualConfigs);
+        free(orig_vid);
+        free(pNewVisualPriv);
+        free(pNewVisualConfigs);
         return FALSE;
     }
 
     /* Alloc space for the new list of the X server's visuals */
-    pVisualNew = (VisualPtr)__glXMalloc(numNewVisuals * sizeof(VisualRec));
+    pVisualNew = (VisualPtr)malloc(numNewVisuals * sizeof(VisualRec));
     if (!pVisualNew) {
-        __glXFree(glXVisualPriv);
+        free(glXVisualPriv);
         _gl_context_modes_destroy( modes );
-        __glXFree(orig_vid);
-        __glXFree(pNewVisualPriv);
-        __glXFree(pNewVisualConfigs);
+        free(orig_vid);
+        free(pNewVisualPriv);
+        free(pNewVisualConfigs);
         return FALSE;
     }
 
@@ -1007,7 +865,7 @@ static Bool init_visuals(int *nvisualp, 
 
     /* Save the GLX visuals in the screen structure */
     glAquaScreens[screenInfo.numScreens-1].num_vis = numNewVisuals;
-    glAquaScreens[screenInfo.numScreens-1].priv = glXVisualPriv;
+    //    glAquaScreens[screenInfo.numScreens-1].priv = glXVisualPriv;
 
     /* Set up depth's VisualIDs */
     for (i = 0; i < ndepth; i++) {
@@ -1022,7 +880,7 @@ static Bool init_visuals(int *nvisualp, 
                 numVids++;
 
         /* Allocate a new list of VisualIDs for this depth */
-        pVids = (VisualID *)__glXMalloc(numVids * sizeof(VisualID));
+        pVids = (VisualID *)malloc(numVids * sizeof(VisualID));
 
         /* Initialize the new list of VisualIDs for this depth */
         for (j = 0; j < pdepth[i].numVids; j++)
@@ -1031,7 +889,7 @@ static Bool init_visuals(int *nvisualp, 
                 pVids[n++] = pVisualNew[k].vid;
 
         /* Update this depth's list of VisualIDs */
-        __glXFree(pdepth[i].vids);
+        free(pdepth[i].vids);
         pdepth[i].vids = pVids;
         pdepth[i].numVids = numVids;
     }
@@ -1041,21 +899,22 @@ static Bool init_visuals(int *nvisualp, 
     *visualp = pVisualNew;
 
     /* Free the old list of the X server's visuals */
-    __glXFree(pVisual);
+    free(pVisual);
 
     /* Clean up temporary allocations */
-    __glXFree(orig_vid);
-    __glXFree(pNewVisualPriv);
-    __glXFree(pNewVisualConfigs);
+    free(orig_vid);
+    free(pNewVisualPriv);
+    free(pNewVisualConfigs);
 
     /* Free the private list created by DDX HW driver */
     if (visualPrivates)
-        xfree(visualPrivates);
+        free(visualPrivates);
     visualPrivates = NULL;
 
     return TRUE;
 }
 
+Bool enable_stereo = FALSE;
 /* based on code in i830_dri.c
    This ends calling glAquaSetVisualConfigs to set the static
    numconfigs, etc. */
@@ -1066,20 +925,22 @@ glAquaInitVisualConfigs(void)
     __GLXvisualConfig  *lclVisualConfigs  = NULL;
     void              **lclVisualPrivates = NULL;
 
-    int depth, aux, buffers, stencil, accum;
+    int stereo, depth, aux, buffers, stencil, accum;
     int i = 0;
 
     GLAQUA_DEBUG_MSG("glAquaInitVisualConfigs ");
         
     /* count num configs:
+        2 stereo (on, off) (optional)
         2 Z buffer (0, 24 bit)
         2 AUX buffer (0, 2)
         2 buffers (single, double)
         2 stencil (0, 8 bit)
         2 accum (0, 64 bit)
-        = 32 configs */
+        = 64 configs with stereo, or 32 without */
 
-    lclNumConfigs = 2 * 2 * 2 * 2 * 2; /* 32 */
+    if (enable_stereo) lclNumConfigs = 2 * 2 * 2 * 2 * 2 * 2; /* 64 */
+    else               lclNumConfigs = 2 * 2 * 2 * 2 * 2; /* 32 */
 
     /* alloc */
     lclVisualConfigs = xcalloc(sizeof(__GLXvisualConfig), lclNumConfigs);
@@ -1088,54 +949,55 @@ glAquaInitVisualConfigs(void)
     /* fill in configs */
     if (NULL != lclVisualConfigs) {
         i = 0; /* current buffer */
-        for (depth = 0; depth < 2; depth++) {
+        for (stereo = 0; stereo < (enable_stereo ? 2 : 1); stereo++) {
+	  for (depth = 0; depth < 2; depth++) {
             for (aux = 0; aux < 2; aux++) {
-                for (buffers = 0; buffers < 2; buffers++) {
-                    for (stencil = 0; stencil < 2; stencil++) {
-                        for (accum = 0; accum < 2; accum++) {
-                            lclVisualConfigs[i].vid = -1;
-                            lclVisualConfigs[i].class = -1;
-                            lclVisualConfigs[i].rgba = TRUE;
-                            lclVisualConfigs[i].redSize = -1;
-                            lclVisualConfigs[i].greenSize = -1;
-                            lclVisualConfigs[i].blueSize = -1;
-                            lclVisualConfigs[i].redMask = -1;
-                            lclVisualConfigs[i].greenMask = -1;
-                            lclVisualConfigs[i].blueMask = -1;
-                            lclVisualConfigs[i].alphaMask = 0;
-                            if (accum) {
-                                lclVisualConfigs[i].accumRedSize = 16;
-                                lclVisualConfigs[i].accumGreenSize = 16;
-                                lclVisualConfigs[i].accumBlueSize = 16;
-                                lclVisualConfigs[i].accumAlphaSize = 16;
-                            }
-                            else {
-                                lclVisualConfigs[i].accumRedSize = 0;
-                                lclVisualConfigs[i].accumGreenSize = 0;
-                                lclVisualConfigs[i].accumBlueSize = 0;
-                                lclVisualConfigs[i].accumAlphaSize = 0;
-                            }
-                            lclVisualConfigs[i].doubleBuffer = buffers ? TRUE : FALSE;
-                            lclVisualConfigs[i].stereo = FALSE;
-                            lclVisualConfigs[i].bufferSize = -1;
-
-                            lclVisualConfigs[i].depthSize = depth? 24 : 0;
-                            lclVisualConfigs[i].stencilSize = stencil ? 8 : 0;
-                            lclVisualConfigs[i].auxBuffers = aux ? 2 : 0;
-                            lclVisualConfigs[i].level = 0;
-                            lclVisualConfigs[i].visualRating = GLX_NONE_EXT;
-                            lclVisualConfigs[i].transparentPixel = 0;
-                            lclVisualConfigs[i].transparentRed = 0;
-                            lclVisualConfigs[i].transparentGreen = 0;
-                            lclVisualConfigs[i].transparentBlue = 0;
-                            lclVisualConfigs[i].transparentAlpha = 0;
-                            lclVisualConfigs[i].transparentIndex = 0;
-                            i++;
-                        }
-                    }
-                }
+	      for (buffers = 0; buffers < 2; buffers++) {
+		for (stencil = 0; stencil < 2; stencil++) {
+		  for (accum = 0; accum < 2; accum++) {
+		    lclVisualConfigs[i].vid = -1;
+		    lclVisualConfigs[i].class = -1;
+		    lclVisualConfigs[i].rgba = TRUE;
+		    lclVisualConfigs[i].redSize = -1;
+		    lclVisualConfigs[i].greenSize = -1;
+		    lclVisualConfigs[i].blueSize = -1;
+		    lclVisualConfigs[i].redMask = -1;
+		    lclVisualConfigs[i].greenMask = -1;
+		    lclVisualConfigs[i].blueMask = -1;
+		    lclVisualConfigs[i].alphaMask = 0;
+		    if (accum) {
+		      lclVisualConfigs[i].accumRedSize = 16;
+		      lclVisualConfigs[i].accumGreenSize = 16;
+		      lclVisualConfigs[i].accumBlueSize = 16;
+		      lclVisualConfigs[i].accumAlphaSize = 16;
+		    } else {
+		      lclVisualConfigs[i].accumRedSize = 0;
+		      lclVisualConfigs[i].accumGreenSize = 0;
+		      lclVisualConfigs[i].accumBlueSize = 0;
+		      lclVisualConfigs[i].accumAlphaSize = 0;
+		    }
+		    lclVisualConfigs[i].doubleBuffer = buffers ? TRUE : FALSE;
+		    lclVisualConfigs[i].stereo = stereo ? TRUE : FALSE;
+		    lclVisualConfigs[i].bufferSize = -1;
+		    
+		    lclVisualConfigs[i].depthSize = depth? 24 : 0;
+		    lclVisualConfigs[i].stencilSize = stencil ? 8 : 0;
+		    lclVisualConfigs[i].auxBuffers = aux ? 2 : 0;
+		    lclVisualConfigs[i].level = 0;
+		    lclVisualConfigs[i].visualRating = GLX_NONE_EXT;
+		    lclVisualConfigs[i].transparentPixel = 0;
+		    lclVisualConfigs[i].transparentRed = 0;
+		    lclVisualConfigs[i].transparentGreen = 0;
+		    lclVisualConfigs[i].transparentBlue = 0;
+		    lclVisualConfigs[i].transparentAlpha = 0;
+		    lclVisualConfigs[i].transparentIndex = 0;
+		    i++;
+		  }
+		}
+	      }
             }
-        }
+	  }
+	}
     }
     if (i != lclNumConfigs)
         GLAQUA_DEBUG_MSG("glAquaInitVisualConfigs failed to alloc visual configs");
@@ -1171,7 +1033,7 @@ static Bool glAquaInitVisuals(VisualPtr 
                         *ndepthp, *depthp, *rootDepthp);
 }
 
-
+#if 0
 static void fixup_visuals(int screen)
 {
     ScreenPtr pScreen = screenInfo.screens[screen];
@@ -1204,27 +1066,35 @@ static void fixup_visuals(int screen)
         }
     }
 }
+#endif
+static void __glXAquaScreenDestroy(__GLXscreen *screen) {
 
-static void init_screen_visuals(int screen)
-{
-    ScreenPtr pScreen = screenInfo.screens[screen];
-    __GLcontextModes *modes;
-    int *used;
-    int i, j;
+	GLAQUA_DEBUG_MSG("glXAquaScreenDestroy(%p)\n", screen);
+  __glXScreenDestroy(screen);
+
+  free(screen);
+}
 
+static void init_screen_visuals(__GLXAquaScreen *screen) {
+  ScreenPtr pScreen = screen->base.pScreen;
+  
+  __GLcontextModes *modes;
+  int *used;
+  int i, j;
+  
     GLAQUA_DEBUG_MSG("init_screen_visuals\n");
 
     /* FIXME: Change 'used' to be a array of bits (rather than of ints),
      * FIXME: create a stack array of 8 or 16 bytes.  If 'numVisuals' is less
      * FIXME: than 64 or 128 the stack array can be used instead of calling
-     * FIXME: __glXMalloc / __glXFree.  If nothing else, convert 'used' to
+     * FIXME: malloc / free.  If nothing else, convert 'used' to
      * FIXME: array of bytes instead of ints!
      */
-    used = (int *)__glXMalloc(pScreen->numVisuals * sizeof(int));
-    __glXMemset(used, 0, pScreen->numVisuals * sizeof(int));
+    used = (int *)malloc(pScreen->numVisuals * sizeof(int));
+    memset(used, 0, pScreen->numVisuals * sizeof(int));
 
     i = 0;
-    for ( modes = glAquaScreens[screen].modes 
+    for ( modes = screen -> base.modes
           ; modes != NULL
           ; modes = modes->next ) {
         const int vis_class = _gl_convert_to_x_visual_type( modes->visualType );
@@ -1261,102 +1131,70 @@ static void init_screen_visuals(int scre
         i++;
     }
 
-    __glXFree(used);
+    free(used);
 }
 
-static Bool glAquaScreenProbe(int screen)
-{
-    ScreenPtr pScreen;
-    glAquaScreenRec *screenPriv;
-
-    GLAQUA_DEBUG_MSG("glAquaScreenProbe\n");
-
-    /*
-     * Set up the current screen's visuals.
-     */
-    __glDDXScreenInfo.modes = glAquaScreens[screen].modes;
-    __glDDXScreenInfo.pVisualPriv = glAquaScreens[screen].priv;
-    __glDDXScreenInfo.numVisuals =
-        __glDDXScreenInfo.numUsableVisuals = glAquaScreens[screen].num_vis;
-
-    /*
-     * Set the current screen's createContext routine.  This could be
-     * wrapped by a DDX GLX context creation routine.
-     */
-    __glDDXScreenInfo.createContext = glAquaCreateContext;
-
-    /*
-     * The ordering of the rgb compenents might have been changed by the
-     * driver after mi initialized them.
-     */
-    fixup_visuals(screen);
-
-    /*
-     * Find the GLX visuals that are supported by this screen and create
-     * XMesa's visuals.
-     */
-    init_screen_visuals(screen);
-
-    /*
-     * Wrap RealizeWindow and UnrealizeWindow on this screen
-     */
-    pScreen = screenInfo.screens[screen];
-    screenPriv = &glAquaScreens[screen];
-    screenPriv->RealizeWindow = pScreen->RealizeWindow;
-    pScreen->RealizeWindow = glAquaRealizeWindow;
-    screenPriv->UnrealizeWindow = pScreen->UnrealizeWindow;
-    pScreen->UnrealizeWindow = glAquaUnrealizeWindow;
+static __GLXscreen * __glXAquaScreenProbe(ScreenPtr pScreen) {
+  __GLXAquaScreen *screen;
+  GLAQUA_DEBUG_MSG("glXAquaScreenProbe\n");
+  if (screen == NULL) return NULL;
 
-    return TRUE;
-}
+  screen = malloc(sizeof *screen);
 
-static GLboolean glAquaSwapBuffers(__GLXdrawablePrivate *glxPriv)
-{
-    // swap buffers on only *one* of the contexts
-    // (e.g. the last one for drawing)
-    __GLcontext *gc = (__GLcontext *)glxPriv->drawGlxc->gc;
-    CGLError gl_err;
+  __glXScreenInit(&screen->base, pScreen);
 
-    GLAQUA_DEBUG_MSG("glAquaSwapBuffers\n");
+  screen->base.destroy       = __glXAquaScreenDestroy;
+  screen->base.createContext = __glXAquaScreenCreateContext;
+  screen->base.pScreen       = pScreen;
 
-    if (gc != NULL && gc->ctx != NULL)
-    {
-        gl_err = CGLFlushDrawable(gc->ctx);
-        if (gl_err != 0)
-            ErrorF("CGLFlushDrawable error: %s\n", CGLErrorString(gl_err));
-    }
+  init_screen_visuals(screen);
 
-    return GL_TRUE;
+  return &screen->base;
 }
 
-static void glAquaDestroyDrawablePrivate(__GLdrawablePrivate *glPriv)
-{
+static void __glXAquaDrawableDestroy(__GLXdrawable *base) {
     GLAQUA_DEBUG_MSG("glAquaDestroyDrawablePrivate\n");
 
     /* It doesn't work to call DRIDestroySurface here, the drawable's
        already gone.. But dri.c notices the window destruction and
        frees the surface itself. */
 
-    free(glPriv->private);
-    glPriv->private = NULL;
+    free(base);
 }
 
-static void glAquaCreateBuffer(__GLXdrawablePrivate *glxPriv)
+static __GLXdrawable *
+__glXAquaContextCreateDrawable(__GLXcontext *context,
+			       DrawablePtr pDraw,
+			       XID drawId)
 {
-    GLAquaDrawableRec *aquaPriv = malloc(sizeof(GLAquaDrawableRec));
-    __GLdrawablePrivate *glPriv = &glxPriv->glPriv;
+  __GLXAquaDrawable *glxPriv;
+  __GLXscreen *pGlxScreen;
+
+  GLAQUA_DEBUG_MSG("glAquaContextCreateDrawable(%p,%p,%d)\n", context, pDraw, drawId);
+  if (glxPriv == NULL) return NULL;
+  glxPriv = xalloc(sizeof *glxPriv);
+
+  memset(glxPriv, 0, sizeof *glxPriv);
+
+  if (!__glXDrawableInit(&glxPriv->base, context, pDraw, drawId)) {
+    xfree(glxPriv);
+    return NULL;
+  }
+
+  glxPriv->base.destroy       = __glXAquaDrawableDestroy;
+  glxPriv->base.resize        = __glXAquaDrawableResize;
+  glxPriv->base.swapBuffers   = __glXAquaDrawableSwapBuffers;
 
-    aquaPriv->sid = 0;
-    aquaPriv->pDraw = NULL;
+  pGlxScreen = __glXActiveScreens[pDraw->pScreen->myNum];
 
-    GLAQUA_DEBUG_MSG("glAquaCreateBuffer\n");
+  if (glxPriv->base.type == DRAWABLE_WINDOW) {
+    VisualID vid = wVisual((WindowPtr)pDraw);
 
-    // replace swapBuffers (original is never called)
-    glxPriv->swapBuffers = glAquaSwapBuffers;
+    glxPriv->base.modes = _gl_context_modes_find_visual(pGlxScreen->modes, vid);
+  } else 
+    glxPriv->base.modes = glxPriv->base.pGlxPixmap->modes;
 
-    // stash private data
-    glPriv->private = aquaPriv;
-    glPriv->freePrivate = glAquaDestroyDrawablePrivate;
+    return &glxPriv->base;
 }
 
 static void glAquaResetExtension(void)
@@ -1377,3 +1215,1239 @@ GLuint __glFloorLog2(GLuint val)
     }
     return c;
 }
+
+static void setup_dispatch_table(void) {
+	struct _glapi_table *disp=_glapi_get_dispatch();
+
+ SET_NewList(disp, glNewList);
+ SET_EndList(disp, glEndList);
+ SET_CallList(disp, glCallList);
+ SET_CallLists(disp, glCallLists);
+ SET_DeleteLists(disp, glDeleteLists);
+ SET_GenLists(disp, glGenLists);
+ SET_ListBase(disp, glListBase);
+ SET_Begin(disp, glBegin);
+ SET_Bitmap(disp, glBitmap);
+ SET_Color3b(disp, glColor3b);
+ SET_Color3bv(disp, glColor3bv);
+ SET_Color3d(disp, glColor3d);
+ SET_Color3dv(disp, glColor3dv);
+ SET_Color3f(disp, glColor3f);
+ SET_Color3fv(disp, glColor3fv);
+ SET_Color3i(disp, glColor3i);
+ SET_Color3iv(disp, glColor3iv);
+ SET_Color3s(disp, glColor3s);
+ SET_Color3sv(disp, glColor3sv);
+ SET_Color3ub(disp, glColor3ub);
+ SET_Color3ubv(disp, glColor3ubv);
+ SET_Color3ui(disp, glColor3ui);
+ SET_Color3uiv(disp, glColor3uiv);
+ SET_Color3us(disp, glColor3us);
+ SET_Color3usv(disp, glColor3usv);
+ SET_Color4b(disp, glColor4b);
+ SET_Color4bv(disp, glColor4bv);
+ SET_Color4d(disp, glColor4d);
+ SET_Color4dv(disp, glColor4dv);
+ SET_Color4f(disp, glColor4f);
+ SET_Color4fv(disp, glColor4fv);
+ SET_Color4i(disp, glColor4i);
+ SET_Color4iv(disp, glColor4iv);
+ SET_Color4s(disp, glColor4s);
+ SET_Color4sv(disp, glColor4sv);
+ SET_Color4ub(disp, glColor4ub);
+ SET_Color4ubv(disp, glColor4ubv);
+ SET_Color4ui(disp, glColor4ui);
+ SET_Color4uiv(disp, glColor4uiv);
+ SET_Color4us(disp, glColor4us);
+ SET_Color4usv(disp, glColor4usv);
+ SET_EdgeFlag(disp, glEdgeFlag);
+ SET_EdgeFlagv(disp, glEdgeFlagv);
+ SET_End(disp, glEnd);
+ SET_Indexd(disp, glIndexd);
+ SET_Indexdv(disp, glIndexdv);
+ SET_Indexf(disp, glIndexf);
+ SET_Indexfv(disp, glIndexfv);
+ SET_Indexi(disp, glIndexi);
+ SET_Indexiv(disp, glIndexiv);
+ SET_Indexs(disp, glIndexs);
+ SET_Indexsv(disp, glIndexsv);
+ SET_Normal3b(disp, glNormal3b);
+ SET_Normal3bv(disp, glNormal3bv);
+ SET_Normal3d(disp, glNormal3d);
+ SET_Normal3dv(disp, glNormal3dv);
+ SET_Normal3f(disp, glNormal3f);
+ SET_Normal3fv(disp, glNormal3fv);
+ SET_Normal3i(disp, glNormal3i);
+ SET_Normal3iv(disp, glNormal3iv);
+ SET_Normal3s(disp, glNormal3s);
+ SET_Normal3sv(disp, glNormal3sv);
+ SET_RasterPos2d(disp, glRasterPos2d);
+ SET_RasterPos2dv(disp, glRasterPos2dv);
+ SET_RasterPos2f(disp, glRasterPos2f);
+ SET_RasterPos2fv(disp, glRasterPos2fv);
+ SET_RasterPos2i(disp, glRasterPos2i);
+ SET_RasterPos2iv(disp, glRasterPos2iv);
+ SET_RasterPos2s(disp, glRasterPos2s);
+ SET_RasterPos2sv(disp, glRasterPos2sv);
+ SET_RasterPos3d(disp, glRasterPos3d);
+ SET_RasterPos3dv(disp, glRasterPos3dv);
+ SET_RasterPos3f(disp, glRasterPos3f);
+ SET_RasterPos3fv(disp, glRasterPos3fv);
+ SET_RasterPos3i(disp, glRasterPos3i);
+ SET_RasterPos3iv(disp, glRasterPos3iv);
+ SET_RasterPos3s(disp, glRasterPos3s);
+ SET_RasterPos3sv(disp, glRasterPos3sv);
+ SET_RasterPos4d(disp, glRasterPos4d);
+ SET_RasterPos4dv(disp, glRasterPos4dv);
+ SET_RasterPos4f(disp, glRasterPos4f);
+ SET_RasterPos4fv(disp, glRasterPos4fv);
+ SET_RasterPos4i(disp, glRasterPos4i);
+ SET_RasterPos4iv(disp, glRasterPos4iv);
+ SET_RasterPos4s(disp, glRasterPos4s);
+ SET_RasterPos4sv(disp, glRasterPos4sv);
+ SET_Rectd(disp, glRectd);
+ SET_Rectdv(disp, glRectdv);
+ SET_Rectf(disp, glRectf);
+ SET_Rectfv(disp, glRectfv);
+ SET_Recti(disp, glRecti);
+ SET_Rectiv(disp, glRectiv);
+ SET_Rects(disp, glRects);
+ SET_Rectsv(disp, glRectsv);
+ SET_TexCoord1d(disp, glTexCoord1d);
+ SET_TexCoord1dv(disp, glTexCoord1dv);
+ SET_TexCoord1f(disp, glTexCoord1f);
+ SET_TexCoord1fv(disp, glTexCoord1fv);
+ SET_TexCoord1i(disp, glTexCoord1i);
+ SET_TexCoord1iv(disp, glTexCoord1iv);
+ SET_TexCoord1s(disp, glTexCoord1s);
+ SET_TexCoord1sv(disp, glTexCoord1sv);
+ SET_TexCoord2d(disp, glTexCoord2d);
+ SET_TexCoord2dv(disp, glTexCoord2dv);
+ SET_TexCoord2f(disp, glTexCoord2f);
+ SET_TexCoord2fv(disp, glTexCoord2fv);
+ SET_TexCoord2i(disp, glTexCoord2i);
+ SET_TexCoord2iv(disp, glTexCoord2iv);
+ SET_TexCoord2s(disp, glTexCoord2s);
+ SET_TexCoord2sv(disp, glTexCoord2sv);
+ SET_TexCoord3d(disp, glTexCoord3d);
+ SET_TexCoord3dv(disp, glTexCoord3dv);
+ SET_TexCoord3f(disp, glTexCoord3f);
+ SET_TexCoord3fv(disp, glTexCoord3fv);
+ SET_TexCoord3i(disp, glTexCoord3i);
+ SET_TexCoord3iv(disp, glTexCoord3iv);
+ SET_TexCoord3s(disp, glTexCoord3s);
+ SET_TexCoord3sv(disp, glTexCoord3sv);
+ SET_TexCoord4d(disp, glTexCoord4d);
+ SET_TexCoord4dv(disp, glTexCoord4dv);
+ SET_TexCoord4f(disp, glTexCoord4f);
+ SET_TexCoord4fv(disp, glTexCoord4fv);
+ SET_TexCoord4i(disp, glTexCoord4i);
+ SET_TexCoord4iv(disp, glTexCoord4iv);
+ SET_TexCoord4s(disp, glTexCoord4s);
+ SET_TexCoord4sv(disp, glTexCoord4sv);
+ SET_Vertex2d(disp, glVertex2d);
+ SET_Vertex2dv(disp, glVertex2dv);
+ SET_Vertex2f(disp, glVertex2f);
+ SET_Vertex2fv(disp, glVertex2fv);
+ SET_Vertex2i(disp, glVertex2i);
+ SET_Vertex2iv(disp, glVertex2iv);
+ SET_Vertex2s(disp, glVertex2s);
+ SET_Vertex2sv(disp, glVertex2sv);
+ SET_Vertex3d(disp, glVertex3d);
+ SET_Vertex3dv(disp, glVertex3dv);
+ SET_Vertex3f(disp, glVertex3f);
+ SET_Vertex3fv(disp, glVertex3fv);
+ SET_Vertex3i(disp, glVertex3i);
+ SET_Vertex3iv(disp, glVertex3iv);
+ SET_Vertex3s(disp, glVertex3s);
+ SET_Vertex3sv(disp, glVertex3sv);
+ SET_Vertex4d(disp, glVertex4d);
+ SET_Vertex4dv(disp, glVertex4dv);
+ SET_Vertex4f(disp, glVertex4f);
+ SET_Vertex4fv(disp, glVertex4fv);
+ SET_Vertex4i(disp, glVertex4i);
+ SET_Vertex4iv(disp, glVertex4iv);
+ SET_Vertex4s(disp, glVertex4s);
+ SET_Vertex4sv(disp, glVertex4sv);
+ SET_ClipPlane(disp, glClipPlane);
+ SET_ColorMaterial(disp, glColorMaterial);
+ SET_CullFace(disp, glCullFace);
+ SET_Fogf(disp, glFogf);
+ SET_Fogfv(disp, glFogfv);
+ SET_Fogi(disp, glFogi);
+ SET_Fogiv(disp, glFogiv);
+ SET_FrontFace(disp, glFrontFace);
+ SET_Hint(disp, glHint);
+ SET_Lightf(disp, glLightf);
+ SET_Lightfv(disp, glLightfv);
+ SET_Lighti(disp, glLighti);
+ SET_Lightiv(disp, glLightiv);
+ SET_LightModelf(disp, glLightModelf);
+ SET_LightModelfv(disp, glLightModelfv);
+ SET_LightModeli(disp, glLightModeli);
+ SET_LightModeliv(disp, glLightModeliv);
+ SET_LineStipple(disp, glLineStipple);
+ SET_LineWidth(disp, glLineWidth);
+ SET_Materialf(disp, glMaterialf);
+ SET_Materialfv(disp, glMaterialfv);
+ SET_Materiali(disp, glMateriali);
+ SET_Materialiv(disp, glMaterialiv);
+ SET_PointSize(disp, glPointSize);
+ SET_PolygonMode(disp, glPolygonMode);
+ SET_PolygonStipple(disp, glPolygonStipple);
+ SET_Scissor(disp, glScissor);
+ SET_ShadeModel(disp, glShadeModel);
+ SET_TexParameterf(disp, glTexParameterf);
+ SET_TexParameterfv(disp, glTexParameterfv);
+ SET_TexParameteri(disp, glTexParameteri);
+ SET_TexParameteriv(disp, glTexParameteriv);
+ SET_TexImage1D(disp, glTexImage1D);
+ SET_TexImage2D(disp, glTexImage2D);
+ SET_TexEnvf(disp, glTexEnvf);
+ SET_TexEnvfv(disp, glTexEnvfv);
+ SET_TexEnvi(disp, glTexEnvi);
+ SET_TexEnviv(disp, glTexEnviv);
+ SET_TexGend(disp, glTexGend);
+ SET_TexGendv(disp, glTexGendv);
+ SET_TexGenf(disp, glTexGenf);
+ SET_TexGenfv(disp, glTexGenfv);
+ SET_TexGeni(disp, glTexGeni);
+ SET_TexGeniv(disp, glTexGeniv);
+ SET_FeedbackBuffer(disp, glFeedbackBuffer);
+ SET_SelectBuffer(disp, glSelectBuffer);
+ SET_RenderMode(disp, glRenderMode);
+ SET_InitNames(disp, glInitNames);
+ SET_LoadName(disp, glLoadName);
+ SET_PassThrough(disp, glPassThrough);
+ SET_PopName(disp, glPopName);
+ SET_PushName(disp, glPushName);
+ SET_DrawBuffer(disp, glDrawBuffer);
+ SET_Clear(disp, glClear);
+ SET_ClearAccum(disp, glClearAccum);
+ SET_ClearIndex(disp, glClearIndex);
+ SET_ClearColor(disp, glClearColor);
+ SET_ClearStencil(disp, glClearStencil);
+ SET_ClearDepth(disp, glClearDepth);
+ SET_StencilMask(disp, glStencilMask);
+ SET_ColorMask(disp, glColorMask);
+ SET_DepthMask(disp, glDepthMask);
+ SET_IndexMask(disp, glIndexMask);
+ SET_Accum(disp, glAccum);
+ SET_Disable(disp, glDisable);
+ SET_Enable(disp, glEnable);
+ SET_Finish(disp, glFinish);
+ SET_Flush(disp, glFlush);
+ SET_PopAttrib(disp, glPopAttrib);
+ SET_PushAttrib(disp, glPushAttrib);
+ SET_Map1d(disp, glMap1d);
+ SET_Map1f(disp, glMap1f);
+ SET_Map2d(disp, glMap2d);
+ SET_Map2f(disp, glMap2f);
+ SET_MapGrid1d(disp, glMapGrid1d);
+ SET_MapGrid1f(disp, glMapGrid1f);
+ SET_MapGrid2d(disp, glMapGrid2d);
+ SET_MapGrid2f(disp, glMapGrid2f);
+ SET_EvalCoord1d(disp, glEvalCoord1d);
+ SET_EvalCoord1dv(disp, glEvalCoord1dv);
+ SET_EvalCoord1f(disp, glEvalCoord1f);
+ SET_EvalCoord1fv(disp, glEvalCoord1fv);
+ SET_EvalCoord2d(disp, glEvalCoord2d);
+ SET_EvalCoord2dv(disp, glEvalCoord2dv);
+ SET_EvalCoord2f(disp, glEvalCoord2f);
+ SET_EvalCoord2fv(disp, glEvalCoord2fv);
+ SET_EvalMesh1(disp, glEvalMesh1);
+ SET_EvalPoint1(disp, glEvalPoint1);
+ SET_EvalMesh2(disp, glEvalMesh2);
+ SET_EvalPoint2(disp, glEvalPoint2);
+ SET_AlphaFunc(disp, glAlphaFunc);
+ SET_BlendFunc(disp, glBlendFunc);
+ SET_LogicOp(disp, glLogicOp);
+ SET_StencilFunc(disp, glStencilFunc);
+ SET_StencilOp(disp, glStencilOp);
+ SET_DepthFunc(disp, glDepthFunc);
+ SET_PixelZoom(disp, glPixelZoom);
+ SET_PixelTransferf(disp, glPixelTransferf);
+ SET_PixelTransferi(disp, glPixelTransferi);
+ SET_PixelStoref(disp, glPixelStoref);
+ SET_PixelStorei(disp, glPixelStorei);
+ SET_PixelMapfv(disp, glPixelMapfv);
+ SET_PixelMapuiv(disp, glPixelMapuiv);
+ SET_PixelMapusv(disp, glPixelMapusv);
+ SET_ReadBuffer(disp, glReadBuffer);
+ SET_CopyPixels(disp, glCopyPixels);
+ SET_ReadPixels(disp, glReadPixels);
+ SET_DrawPixels(disp, glDrawPixels);
+ SET_GetBooleanv(disp, glGetBooleanv);
+ SET_GetClipPlane(disp, glGetClipPlane);
+ SET_GetDoublev(disp, glGetDoublev);
+ SET_GetError(disp, glGetError);
+ SET_GetFloatv(disp, glGetFloatv);
+ SET_GetIntegerv(disp, glGetIntegerv);
+ SET_GetLightfv(disp, glGetLightfv);
+ SET_GetLightiv(disp, glGetLightiv);
+ SET_GetMapdv(disp, glGetMapdv);
+ SET_GetMapfv(disp, glGetMapfv);
+ SET_GetMapiv(disp, glGetMapiv);
+ SET_GetMaterialfv(disp, glGetMaterialfv);
+ SET_GetMaterialiv(disp, glGetMaterialiv);
+ SET_GetPixelMapfv(disp, glGetPixelMapfv);
+ SET_GetPixelMapuiv(disp, glGetPixelMapuiv);
+ SET_GetPixelMapusv(disp, glGetPixelMapusv);
+ SET_GetPolygonStipple(disp, glGetPolygonStipple);
+ SET_GetString(disp, glGetString);
+ SET_GetTexEnvfv(disp, glGetTexEnvfv);
+ SET_GetTexEnviv(disp, glGetTexEnviv);
+ SET_GetTexGendv(disp, glGetTexGendv);
+ SET_GetTexGenfv(disp, glGetTexGenfv);
+ SET_GetTexGeniv(disp, glGetTexGeniv);
+ SET_GetTexImage(disp, glGetTexImage);
+ SET_GetTexParameterfv(disp, glGetTexParameterfv);
+ SET_GetTexParameteriv(disp, glGetTexParameteriv);
+ SET_GetTexLevelParameterfv(disp, glGetTexLevelParameterfv);
+ SET_GetTexLevelParameteriv(disp, glGetTexLevelParameteriv);
+ SET_IsEnabled(disp, glIsEnabled);
+ SET_IsList(disp, glIsList);
+ SET_DepthRange(disp, glDepthRange);
+ SET_Frustum(disp, glFrustum);
+ SET_LoadIdentity(disp, glLoadIdentity);
+ SET_LoadMatrixf(disp, glLoadMatrixf);
+ SET_LoadMatrixd(disp, glLoadMatrixd);
+ SET_MatrixMode(disp, glMatrixMode);
+ SET_MultMatrixf(disp, glMultMatrixf);
+ SET_MultMatrixd(disp, glMultMatrixd);
+ SET_Ortho(disp, glOrtho);
+ SET_PopMatrix(disp, glPopMatrix);
+ SET_PushMatrix(disp, glPushMatrix);
+ SET_Rotated(disp, glRotated);
+ SET_Rotatef(disp, glRotatef);
+ SET_Scaled(disp, glScaled);
+ SET_Scalef(disp, glScalef);
+ SET_Translated(disp, glTranslated);
+ SET_Translatef(disp, glTranslatef);
+ SET_Viewport(disp, glViewport);
+ SET_ArrayElement(disp, glArrayElement);
+ SET_BindTexture(disp, glBindTexture);
+ SET_ColorPointer(disp, glColorPointer);
+ SET_DisableClientState(disp, glDisableClientState);
+ SET_DrawArrays(disp, glDrawArrays);
+ SET_DrawElements(disp, glDrawElements);
+ SET_EdgeFlagPointer(disp, glEdgeFlagPointer);
+ SET_EnableClientState(disp, glEnableClientState);
+ SET_IndexPointer(disp, glIndexPointer);
+ SET_Indexub(disp, glIndexub);
+ SET_Indexubv(disp, glIndexubv);
+ SET_InterleavedArrays(disp, glInterleavedArrays);
+ SET_NormalPointer(disp, glNormalPointer);
+ SET_PolygonOffset(disp, glPolygonOffset);
+ SET_TexCoordPointer(disp, glTexCoordPointer);
+ SET_VertexPointer(disp, glVertexPointer);
+ SET_AreTexturesResident(disp, glAreTexturesResident); 
+ SET_CopyTexImage1D(disp, glCopyTexImage1D);
+ SET_CopyTexImage2D(disp, glCopyTexImage2D);
+ SET_CopyTexSubImage1D(disp, glCopyTexSubImage1D);
+ SET_CopyTexSubImage2D(disp, glCopyTexSubImage2D);
+ SET_DeleteTextures(disp, glDeleteTextures);
+ SET_GenTextures(disp, glGenTextures);
+ SET_GetPointerv(disp, glGetPointerv);
+ SET_IsTexture(disp, glIsTexture);
+ SET_PrioritizeTextures(disp, glPrioritizeTextures);
+ SET_TexSubImage1D(disp, glTexSubImage1D);
+ SET_TexSubImage2D(disp, glTexSubImage2D);
+ SET_PopClientAttrib(disp, glPopClientAttrib);
+ SET_PushClientAttrib(disp, glPushClientAttrib);
+ SET_BlendColor(disp, glBlendColor);
+ SET_BlendEquation(disp, glBlendEquation);
+ SET_DrawRangeElements(disp, glDrawRangeElements);
+ SET_ColorTable(disp, glColorTable);
+ SET_ColorTableParameterfv(disp, glColorTableParameterfv);
+ SET_ColorTableParameteriv(disp, glColorTableParameteriv);
+ SET_CopyColorTable(disp, glCopyColorTable);
+ SET_GetColorTable(disp, glGetColorTable);
+ SET_GetColorTableParameterfv(disp, glGetColorTableParameterfv);
+ SET_GetColorTableParameteriv(disp, glGetColorTableParameteriv);
+ SET_ColorSubTable(disp, glColorSubTable);
+ SET_CopyColorSubTable(disp, glCopyColorSubTable);
+ SET_ConvolutionFilter1D(disp, glConvolutionFilter1D);
+ SET_ConvolutionFilter2D(disp, glConvolutionFilter2D);
+ SET_ConvolutionParameterf(disp, glConvolutionParameterf);
+ SET_ConvolutionParameterfv(disp, glConvolutionParameterfv);
+ SET_ConvolutionParameteri(disp, glConvolutionParameteri);
+ SET_ConvolutionParameteriv(disp, glConvolutionParameteriv);
+ SET_CopyConvolutionFilter1D(disp, glCopyConvolutionFilter1D);
+ SET_CopyConvolutionFilter2D(disp, glCopyConvolutionFilter2D);
+ SET_GetConvolutionFilter(disp, glGetConvolutionFilter);
+ SET_GetConvolutionParameterfv(disp, glGetConvolutionParameterfv);
+ SET_GetConvolutionParameteriv(disp, glGetConvolutionParameteriv);
+ SET_GetSeparableFilter(disp, glGetSeparableFilter);
+ SET_SeparableFilter2D(disp, glSeparableFilter2D);
+ SET_GetHistogram(disp, glGetHistogram);
+ SET_GetHistogramParameterfv(disp, glGetHistogramParameterfv);
+ SET_GetHistogramParameteriv(disp, glGetHistogramParameteriv);
+ SET_GetMinmax(disp, glGetMinmax);
+ SET_GetMinmaxParameterfv(disp, glGetMinmaxParameterfv);
+ SET_GetMinmaxParameteriv(disp, glGetMinmaxParameteriv);
+ SET_Histogram(disp, glHistogram);
+ SET_Minmax(disp, glMinmax);
+ SET_ResetHistogram(disp, glResetHistogram);
+ SET_ResetMinmax(disp, glResetMinmax);
+ SET_TexImage3D(disp, glTexImage3D);
+ SET_TexSubImage3D(disp, glTexSubImage3D);
+ SET_CopyTexSubImage3D(disp, glCopyTexSubImage3D);
+ SET_ActiveTextureARB(disp, glActiveTextureARB);
+ SET_ClientActiveTextureARB(disp, glClientActiveTextureARB);
+ SET_MultiTexCoord1dARB(disp, glMultiTexCoord1dARB);
+ SET_MultiTexCoord1dvARB(disp, glMultiTexCoord1dvARB);
+ SET_MultiTexCoord1fARB(disp, glMultiTexCoord1fARB);
+ SET_MultiTexCoord1fvARB(disp, glMultiTexCoord1fvARB);
+ SET_MultiTexCoord1iARB(disp, glMultiTexCoord1iARB);
+ SET_MultiTexCoord1ivARB(disp, glMultiTexCoord1ivARB);
+ SET_MultiTexCoord1sARB(disp, glMultiTexCoord1sARB);
+ SET_MultiTexCoord1svARB(disp, glMultiTexCoord1svARB);
+ SET_MultiTexCoord2dARB(disp, glMultiTexCoord2dARB);
+ SET_MultiTexCoord2dvARB(disp, glMultiTexCoord2dvARB);
+ SET_MultiTexCoord2fARB(disp, glMultiTexCoord2fARB);
+ SET_MultiTexCoord2fvARB(disp, glMultiTexCoord2fvARB);
+ SET_MultiTexCoord2iARB(disp, glMultiTexCoord2iARB);
+ SET_MultiTexCoord2ivARB(disp, glMultiTexCoord2ivARB);
+ SET_MultiTexCoord2sARB(disp, glMultiTexCoord2sARB);
+ SET_MultiTexCoord2svARB(disp, glMultiTexCoord2svARB);
+ SET_MultiTexCoord3dARB(disp, glMultiTexCoord3dARB);
+ SET_MultiTexCoord3dvARB(disp, glMultiTexCoord3dvARB);
+ SET_MultiTexCoord3fARB(disp, glMultiTexCoord3fARB);
+ SET_MultiTexCoord3fvARB(disp, glMultiTexCoord3fvARB);
+ SET_MultiTexCoord3iARB(disp, glMultiTexCoord3iARB);
+ SET_MultiTexCoord3ivARB(disp, glMultiTexCoord3ivARB);
+ SET_MultiTexCoord3sARB(disp, glMultiTexCoord3sARB);
+ SET_MultiTexCoord3svARB(disp, glMultiTexCoord3svARB);
+ SET_MultiTexCoord4dARB(disp, glMultiTexCoord4dARB);
+ SET_MultiTexCoord4dvARB(disp, glMultiTexCoord4dvARB);
+ SET_MultiTexCoord4fARB(disp, glMultiTexCoord4fARB);
+ SET_MultiTexCoord4fvARB(disp, glMultiTexCoord4fvARB);
+ SET_MultiTexCoord4iARB(disp, glMultiTexCoord4iARB);
+ SET_MultiTexCoord4ivARB(disp, glMultiTexCoord4ivARB);
+ SET_MultiTexCoord4sARB(disp, glMultiTexCoord4sARB);
+ SET_MultiTexCoord4svARB(disp, glMultiTexCoord4svARB);
+ SET_LoadTransposeMatrixfARB(disp, glLoadTransposeMatrixfARB);
+ SET_LoadTransposeMatrixdARB(disp, glLoadTransposeMatrixdARB);
+ SET_MultTransposeMatrixfARB(disp, glMultTransposeMatrixfARB);
+ SET_MultTransposeMatrixdARB(disp, glMultTransposeMatrixdARB);
+ SET_SampleCoverageARB(disp, glSampleCoverageARB);
+ SET_DrawBuffersARB(disp, glDrawBuffersARB);
+/* SET_PolygonOffsetEXT(disp, glPolygonOffsetEXT);
+ SET_GetTexFilterFuncSGIS(disp, glGetTexFilterFuncSGIS);
+ SET_TexFilterFuncSGIS(disp, glTexFilterFuncSGIS);
+ SET_GetHistogramEXT(disp, glGetHistogramEXT);
+ SET_GetHistogramParameterfvEXT(disp, glGetHistogramParameterfvEXT);
+ SET_GetHistogramParameterivEXT(disp, glGetHistogramParameterivEXT);
+ SET_GetMinmaxEXT(disp, glGetMinmaxEXT);
+ SET_GetMinmaxParameterfvEXT(disp, glGetMinmaxParameterfvEXT);
+ SET_GetMinmaxParameterivEXT(disp, glGetMinmaxParameterivEXT);
+ SET_GetConvolutionFilterEXT(disp, glGetConvolutionFilterEXT);
+ SET_GetConvolutionParameterfvEXT(disp, glGetConvolutionParameterfvEXT);
+ SET_GetConvolutionParameterivEXT(disp, glGetConvolutionParameterivEXT);
+ SET_GetSeparableFilterEXT(disp, glGetSeparableFilterEXT);
+ SET_GetColorTableSGI(disp, glGetColorTableSGI);
+ SET_GetColorTableParameterfvSGI(disp, glGetColorTableParameterfvSGI);
+ SET_GetColorTableParameterivSGI(disp, glGetColorTableParameterivSGI);
+ SET_PixelTexGenSGIX(disp, glPixelTexGenSGIX);
+ SET_PixelTexGenParameteriSGIS(disp, glPixelTexGenParameteriSGIS);
+ SET_PixelTexGenParameterivSGIS(disp, glPixelTexGenParameterivSGIS);
+ SET_PixelTexGenParameterfSGIS(disp, glPixelTexGenParameterfSGIS);
+ SET_PixelTexGenParameterfvSGIS(disp, glPixelTexGenParameterfvSGIS);
+ SET_GetPixelTexGenParameterivSGIS(disp, glGetPixelTexGenParameterivSGIS);
+ SET_GetPixelTexGenParameterfvSGIS(disp, glGetPixelTexGenParameterfvSGIS);
+ SET_TexImage4DSGIS(disp, glTexImage4DSGIS);
+ SET_TexSubImage4DSGIS(disp, glTexSubImage4DSGIS); */
+ SET_AreTexturesResidentEXT(disp, glAreTexturesResident);
+ SET_GenTexturesEXT(disp, glGenTextures);
+ SET_IsTextureEXT(disp, glIsTexture);
+/* SET_DetailTexFuncSGIS(disp, glDetailTexFuncSGIS);
+ SET_GetDetailTexFuncSGIS(disp, glGetDetailTexFuncSGIS);
+ SET_SharpenTexFuncSGIS(disp, glSharpenTexFuncSGIS);
+ SET_GetSharpenTexFuncSGIS(disp, glGetSharpenTexFuncSGIS);
+ SET_SampleMaskSGIS(disp, glSampleMaskSGIS);
+ SET_SamplePatternSGIS(disp, glSamplePatternSGIS);
+ SET_ColorPointerEXT(disp, glColorPointerEXT);
+ SET_EdgeFlagPointerEXT(disp, glEdgeFlagPointerEXT);
+ SET_IndexPointerEXT(disp, glIndexPointerEXT);
+ SET_NormalPointerEXT(disp, glNormalPointerEXT);
+ SET_TexCoordPointerEXT(disp, glTexCoordPointerEXT);
+ SET_VertexPointerEXT(disp, glVertexPointerEXT);
+ SET_SpriteParameterfSGIX(disp, glSpriteParameterfSGIX);
+ SET_SpriteParameterfvSGIX(disp, glSpriteParameterfvSGIX);
+ SET_SpriteParameteriSGIX(disp, glSpriteParameteriSGIX);
+ SET_SpriteParameterivSGIX(disp, glSpriteParameterivSGIX);
+ SET_PointParameterfEXT(disp, glPointParameterfEXT);
+ SET_PointParameterfvEXT(disp, glPointParameterfvEXT);
+ SET_GetInstrumentsSGIX(disp, glGetInstrumentsSGIX);
+ SET_InstrumentsBufferSGIX(disp, glInstrumentsBufferSGIX);
+ SET_PollInstrumentsSGIX(disp, glPollInstrumentsSGIX);
+ SET_ReadInstrumentsSGIX(disp, glReadInstrumentsSGIX);
+ SET_StartInstrumentsSGIX(disp, glStartInstrumentsSGIX);
+ SET_StopInstrumentsSGIX(disp, glStopInstrumentsSGIX);
+ SET_FrameZoomSGIX(disp, glFrameZoomSGIX);
+ SET_TagSampleBufferSGIX(disp, glTagSampleBufferSGIX);
+ SET_ReferencePlaneSGIX(disp, glReferencePlaneSGIX);
+ SET_FlushRasterSGIX(disp, glFlushRasterSGIX);
+ SET_GetListParameterfvSGIX(disp, glGetListParameterfvSGIX);
+ SET_GetListParameterivSGIX(disp, glGetListParameterivSGIX);
+ SET_ListParameterfSGIX(disp, glListParameterfSGIX);
+ SET_ListParameterfvSGIX(disp, glListParameterfvSGIX);
+ SET_ListParameteriSGIX(disp, glListParameteriSGIX);
+ SET_ListParameterivSGIX(disp, glListParameterivSGIX);
+ SET_FragmentColorMaterialSGIX(disp, glFragmentColorMaterialSGIX);
+ SET_FragmentLightfSGIX(disp, glFragmentLightfSGIX);
+ SET_FragmentLightfvSGIX(disp, glFragmentLightfvSGIX);
+ SET_FragmentLightiSGIX(disp, glFragmentLightiSGIX);
+ SET_FragmentLightivSGIX(disp, glFragmentLightivSGIX);
+ SET_FragmentLightModelfSGIX(disp, glFragmentLightModelfSGIX);
+ SET_FragmentLightModelfvSGIX(disp, glFragmentLightModelfvSGIX);
+ SET_FragmentLightModeliSGIX(disp, glFragmentLightModeliSGIX);
+ SET_FragmentLightModelivSGIX(disp, glFragmentLightModelivSGIX);
+ SET_FragmentMaterialfSGIX(disp, glFragmentMaterialfSGIX);
+ SET_FragmentMaterialfvSGIX(disp, glFragmentMaterialfvSGIX);
+ SET_FragmentMaterialiSGIX(disp, glFragmentMaterialiSGIX);
+ SET_FragmentMaterialivSGIX(disp, glFragmentMaterialivSGIX);
+ SET_GetFragmentLightfvSGIX(disp, glGetFragmentLightfvSGIX);
+ SET_GetFragmentLightivSGIX(disp, glGetFragmentLightivSGIX);
+ SET_GetFragmentMaterialfvSGIX(disp, glGetFragmentMaterialfvSGIX);
+ SET_GetFragmentMaterialivSGIX(disp, glGetFragmentMaterialivSGIX);
+ SET_LightEnviSGIX(disp, glLightEnviSGIX); 
+ SET_VertexWeightfEXT(disp, glVertexWeightfEXT);
+ SET_VertexWeightfvEXT(disp, glVertexWeightfvEXT);
+ SET_VertexWeightPointerEXT(disp, glVertexWeightPointerEXT);
+ SET_FlushVertexArrayRangeNV(disp, glFlushVertexArrayRangeNV);
+ SET_VertexArrayRangeNV(disp, glVertexArrayRangeNV);
+ SET_CombinerParameterfvNV(disp, glCombinerParameterfvNV);
+ SET_CombinerParameterfNV(disp, glCombinerParameterfNV);
+ SET_CombinerParameterivNV(disp, glCombinerParameterivNV);
+ SET_CombinerParameteriNV(disp, glCombinerParameteriNV);
+ SET_CombinerInputNV(disp, glCombinerInputNV);
+ SET_CombinerOutputNV(disp, glCombinerOutputNV);
+ SET_FinalCombinerInputNV(disp, glFinalCombinerInputNV);
+ SET_GetCombinerInputParameterfvNV(disp, glGetCombinerInputParameterfvNV);
+ SET_GetCombinerInputParameterivNV(disp, glGetCombinerInputParameterivNV);
+ SET_GetCombinerOutputParameterfvNV(disp, glGetCombinerOutputParameterfvNV);
+ SET_GetCombinerOutputParameterivNV(disp, glGetCombinerOutputParameterivNV);
+ SET_GetFinalCombinerInputParameterfvNV(disp, glGetFinalCombinerInputParameterfvNV);
+ SET_GetFinalCombinerInputParameterivNV(disp, glGetFinalCombinerInputParameterivNV);
+ SET_ResizeBuffersMESA(disp, glResizeBuffersMESA);
+ SET_WindowPos2dMESA(disp, glWindowPos2dMESA);
+ SET_WindowPos2dvMESA(disp, glWindowPos2dvMESA);
+ SET_WindowPos2fMESA(disp, glWindowPos2fMESA);
+ SET_WindowPos2fvMESA(disp, glWindowPos2fvMESA);
+ SET_WindowPos2iMESA(disp, glWindowPos2iMESA);
+ SET_WindowPos2ivMESA(disp, glWindowPos2ivMESA);
+ SET_WindowPos2sMESA(disp, glWindowPos2sMESA);
+ SET_WindowPos2svMESA(disp, glWindowPos2svMESA);
+ SET_WindowPos3dMESA(disp, glWindowPos3dMESA);
+ SET_WindowPos3dvMESA(disp, glWindowPos3dvMESA);
+ SET_WindowPos3fMESA(disp, glWindowPos3fMESA);
+ SET_WindowPos3fvMESA(disp, glWindowPos3fvMESA);
+ SET_WindowPos3iMESA(disp, glWindowPos3iMESA);
+ SET_WindowPos3ivMESA(disp, glWindowPos3ivMESA);
+ SET_WindowPos3sMESA(disp, glWindowPos3sMESA);
+ SET_WindowPos3svMESA(disp, glWindowPos3svMESA);
+ SET_WindowPos4dMESA(disp, glWindowPos4dMESA);
+ SET_WindowPos4dvMESA(disp, glWindowPos4dvMESA);
+ SET_WindowPos4fMESA(disp, glWindowPos4fMESA);
+ SET_WindowPos4fvMESA(disp, glWindowPos4fvMESA);
+ SET_WindowPos4iMESA(disp, glWindowPos4iMESA);
+ SET_WindowPos4ivMESA(disp, glWindowPos4ivMESA);
+ SET_WindowPos4sMESA(disp, glWindowPos4sMESA);
+ SET_WindowPos4svMESA(disp, glWindowPos4svMESA);
+ SET_BlendFuncSeparateEXT(disp, glBlendFuncSeparateEXT);
+ SET_IndexMaterialEXT(disp, glIndexMaterialEXT);
+ SET_IndexFuncEXT(disp, glIndexFuncEXT);
+ SET_LockArraysEXT(disp, glLockArraysEXT);
+ SET_UnlockArraysEXT(disp, glUnlockArraysEXT);
+ SET_CullParameterdvEXT(disp, glCullParameterdvEXT);
+ SET_CullParameterfvEXT(disp, glCullParameterfvEXT);
+ SET_HintPGI(disp, glHintPGI);
+ SET_FogCoordfEXT(disp, glFogCoordfEXT);
+ SET_FogCoordfvEXT(disp, glFogCoordfvEXT);
+ SET_FogCoorddEXT(disp, glFogCoorddEXT);
+ SET_FogCoorddvEXT(disp, glFogCoorddvEXT);
+ SET_FogCoordPointerEXT(disp, glFogCoordPointerEXT);
+ SET_GetColorTableEXT(disp, glGetColorTableEXT);
+ SET_GetColorTableParameterivEXT(disp, glGetColorTableParameterivEXT);
+ SET_GetColorTableParameterfvEXT(disp, glGetColorTableParameterfvEXT);
+ SET_TbufferMask3DFX(disp, glTbufferMask3DFX);
+ SET_CompressedTexImage3DARB(disp, glCompressedTexImage3DARB);
+ SET_CompressedTexImage2DARB(disp, glCompressedTexImage2DARB);
+ SET_CompressedTexImage1DARB(disp, glCompressedTexImage1DARB);
+ SET_CompressedTexSubImage3DARB(disp, glCompressedTexSubImage3DARB);
+ SET_CompressedTexSubImage2DARB(disp, glCompressedTexSubImage2DARB);
+ SET_CompressedTexSubImage1DARB(disp, glCompressedTexSubImage1DARB);
+ SET_GetCompressedTexImageARB(disp, glGetCompressedTexImageARB);
+ SET_SecondaryColor3bEXT(disp, glSecondaryColor3bEXT);
+ SET_SecondaryColor3bvEXT(disp, glSecondaryColor3bvEXT);
+ SET_SecondaryColor3dEXT(disp, glSecondaryColor3dEXT);
+ SET_SecondaryColor3dvEXT(disp, glSecondaryColor3dvEXT);
+ SET_SecondaryColor3fEXT(disp, glSecondaryColor3fEXT);
+ SET_SecondaryColor3fvEXT(disp, glSecondaryColor3fvEXT);
+ SET_SecondaryColor3iEXT(disp, glSecondaryColor3iEXT);
+ SET_SecondaryColor3ivEXT(disp, glSecondaryColor3ivEXT);
+ SET_SecondaryColor3sEXT(disp, glSecondaryColor3sEXT);
+ SET_SecondaryColor3svEXT(disp, glSecondaryColor3svEXT);
+ SET_SecondaryColor3ubEXT(disp, glSecondaryColor3ubEXT);
+ SET_SecondaryColor3ubvEXT(disp, glSecondaryColor3ubvEXT);
+ SET_SecondaryColor3uiEXT(disp, glSecondaryColor3uiEXT);
+ SET_SecondaryColor3uivEXT(disp, glSecondaryColor3uivEXT);
+ SET_SecondaryColor3usEXT(disp, glSecondaryColor3usEXT);
+ SET_SecondaryColor3usvEXT(disp, glSecondaryColor3usvEXT);
+ SET_SecondaryColorPointerEXT(disp, glSecondaryColorPointerEXT);
+ SET_AreProgramsResidentNV(disp, glAreProgramsResidentNV);
+ SET_BindProgramNV(disp, glBindProgramNV);
+ SET_DeleteProgramsNV(disp, glDeleteProgramsNV);
+ SET_ExecuteProgramNV(disp, glExecuteProgramNV);
+ SET_GenProgramsNV(disp, glGenProgramsNV);
+ SET_GetProgramParameterdvNV(disp, glGetProgramParameterdvNV);
+ SET_GetProgramParameterfvNV(disp, glGetProgramParameterfvNV);
+ SET_GetProgramivNV(disp, glGetProgramivNV);
+ SET_GetProgramStringNV(disp, glGetProgramStringNV);
+ SET_GetTrackMatrixivNV(disp, glGetTrackMatrixivNV);
+ SET_GetVertexAttribdvARB(disp, glGetVertexAttribdvARB);
+ SET_GetVertexAttribfvARB(disp, glGetVertexAttribfvARB);
+ SET_GetVertexAttribivARB(disp, glGetVertexAttribivARB);
+ SET_GetVertexAttribPointervNV(disp, glGetVertexAttribPointervNV);
+ SET_IsProgramNV(disp, glIsProgramNV);
+ SET_LoadProgramNV(disp, glLoadProgramNV);
+ SET_ProgramParameter4dNV(disp, glProgramParameter4dNV);
+ SET_ProgramParameter4dvNV(disp, glProgramParameter4dvNV);
+ SET_ProgramParameter4fNV(disp, glProgramParameter4fNV);
+ SET_ProgramParameter4fvNV(disp, glProgramParameter4fvNV);
+ SET_ProgramParameters4dvNV(disp, glProgramParameters4dvNV);
+ SET_ProgramParameters4fvNV(disp, glProgramParameters4fvNV);
+ SET_RequestResidentProgramsNV(disp, glRequestResidentProgramsNV);
+ SET_TrackMatrixNV(disp, glTrackMatrixNV);
+ SET_VertexAttribPointerNV(disp, glVertexAttribPointerNV);
+ SET_VertexAttrib1dARB(disp, glVertexAttrib1dARB);
+ SET_VertexAttrib1dvARB(disp, glVertexAttrib1dvARB);
+ SET_VertexAttrib1fARB(disp, glVertexAttrib1fARB);
+ SET_VertexAttrib1fvARB(disp, glVertexAttrib1fvARB);
+ SET_VertexAttrib1sARB(disp, glVertexAttrib1sARB);
+ SET_VertexAttrib1svARB(disp, glVertexAttrib1svARB);
+ SET_VertexAttrib2dARB(disp, glVertexAttrib2dARB);
+ SET_VertexAttrib2dvARB(disp, glVertexAttrib2dvARB);
+ SET_VertexAttrib2fARB(disp, glVertexAttrib2fARB);
+ SET_VertexAttrib2fvARB(disp, glVertexAttrib2fvARB);
+ SET_VertexAttrib2sARB(disp, glVertexAttrib2sARB);
+ SET_VertexAttrib2svARB(disp, glVertexAttrib2svARB);
+ SET_VertexAttrib3dARB(disp, glVertexAttrib3dARB);
+ SET_VertexAttrib3dvARB(disp, glVertexAttrib3dvARB);
+ SET_VertexAttrib3fARB(disp, glVertexAttrib3fARB);
+ SET_VertexAttrib3fvARB(disp, glVertexAttrib3fvARB);
+ SET_VertexAttrib3sARB(disp, glVertexAttrib3sARB);
+ SET_VertexAttrib3svARB(disp, glVertexAttrib3svARB);
+ SET_VertexAttrib4dARB(disp, glVertexAttrib4dARB);
+ SET_VertexAttrib4dvARB(disp, glVertexAttrib4dvARB);
+ SET_VertexAttrib4fARB(disp, glVertexAttrib4fARB);
+ SET_VertexAttrib4fvARB(disp, glVertexAttrib4fvARB);
+ SET_VertexAttrib4sARB(disp, glVertexAttrib4sARB);
+ SET_VertexAttrib4svARB(disp, glVertexAttrib4svARB);
+ SET_VertexAttrib4NubARB(disp, glVertexAttrib4NubARB);
+ SET_VertexAttrib4NubvARB(disp, glVertexAttrib4NubvARB);
+ SET_VertexAttribs1dvNV(disp, glVertexAttribs1dvNV);
+ SET_VertexAttribs1fvNV(disp, glVertexAttribs1fvNV);
+ SET_VertexAttribs1svNV(disp, glVertexAttribs1svNV);
+ SET_VertexAttribs2dvNV(disp, glVertexAttribs2dvNV);
+ SET_VertexAttribs2fvNV(disp, glVertexAttribs2fvNV);
+ SET_VertexAttribs2svNV(disp, glVertexAttribs2svNV);
+ SET_VertexAttribs3dvNV(disp, glVertexAttribs3dvNV);
+ SET_VertexAttribs3fvNV(disp, glVertexAttribs3fvNV);
+ SET_VertexAttribs3svNV(disp, glVertexAttribs3svNV);
+ SET_VertexAttribs4dvNV(disp, glVertexAttribs4dvNV);
+ SET_VertexAttribs4fvNV(disp, glVertexAttribs4fvNV);
+ SET_VertexAttribs4svNV(disp, glVertexAttribs4svNV);
+ SET_VertexAttribs4ubvNV(disp, glVertexAttribs4ubvNV);
+ SET_PointParameteriNV(disp, glPointParameteriNV);
+ SET_PointParameterivNV(disp, glPointParameterivNV);
+ SET_MultiDrawArraysEXT(disp, glMultiDrawArraysEXT);
+ SET_MultiDrawElementsEXT(disp, glMultiDrawElementsEXT);
+ SET_ActiveStencilFaceEXT(disp, glActiveStencilFaceEXT);
+ SET_DeleteFencesNV(disp, glDeleteFencesNV);
+ SET_GenFencesNV(disp, glGenFencesNV);
+ SET_IsFenceNV(disp, glIsFenceNV);
+ SET_TestFenceNV(disp, glTestFenceNV);
+ SET_GetFenceivNV(disp, glGetFenceivNV);
+ SET_FinishFenceNV(disp, glFinishFenceNV);
+ SET_SetFenceNV(disp, glSetFenceNV);
+ SET_VertexAttrib4bvARB(disp, glVertexAttrib4bvARB);
+ SET_VertexAttrib4ivARB(disp, glVertexAttrib4ivARB);
+ SET_VertexAttrib4ubvARB(disp, glVertexAttrib4ubvARB);
+ SET_VertexAttrib4usvARB(disp, glVertexAttrib4usvARB);
+ SET_VertexAttrib4uivARB(disp, glVertexAttrib4uivARB);
+ SET_VertexAttrib4NbvARB(disp, glVertexAttrib4NbvARB);
+ SET_VertexAttrib4NsvARB(disp, glVertexAttrib4NsvARB);
+ SET_VertexAttrib4NivARB(disp, glVertexAttrib4NivARB);
+ SET_VertexAttrib4NusvARB(disp, glVertexAttrib4NusvARB);
+ SET_VertexAttrib4NuivARB(disp, glVertexAttrib4NuivARB);
+ SET_VertexAttribPointerARB(disp, glVertexAttribPointerARB);
+ SET_EnableVertexAttribArrayARB(disp, glEnableVertexAttribArrayARB);
+ SET_DisableVertexAttribArrayARB(disp, glDisableVertexAttribArrayARB);
+ SET_ProgramStringARB(disp, glProgramStringARB);
+ SET_ProgramEnvParameter4dARB(disp, glProgramEnvParameter4dARB);
+ SET_ProgramEnvParameter4dvARB(disp, glProgramEnvParameter4dvARB);
+ SET_ProgramEnvParameter4fARB(disp, glProgramEnvParameter4fARB);
+ SET_ProgramEnvParameter4fvARB(disp, glProgramEnvParameter4fvARB);
+ SET_ProgramLocalParameter4dARB(disp, glProgramLocalParameter4dARB);
+ SET_ProgramLocalParameter4dvARB(disp, glProgramLocalParameter4dvARB);
+ SET_ProgramLocalParameter4fARB(disp, glProgramLocalParameter4fARB);
+ SET_ProgramLocalParameter4fvARB(disp, glProgramLocalParameter4fvARB);
+ SET_GetProgramEnvParameterdvARB(disp, glGetProgramEnvParameterdvARB);
+ SET_GetProgramEnvParameterfvARB(disp, glGetProgramEnvParameterfvARB);
+ SET_GetProgramLocalParameterdvARB(disp, glGetProgramLocalParameterdvARB);
+ SET_GetProgramLocalParameterfvARB(disp, glGetProgramLocalParameterfvARB);
+ SET_GetProgramivARB(disp, glGetProgramivARB);
+ SET_GetProgramStringARB(disp, glGetProgramStringARB);
+ SET_ProgramNamedParameter4fNV(disp, glProgramNamedParameter4fNV);
+ SET_ProgramNamedParameter4dNV(disp, glProgramNamedParameter4dNV);
+ SET_ProgramNamedParameter4fvNV(disp, glProgramNamedParameter4fvNV);
+ SET_ProgramNamedParameter4dvNV(disp, glProgramNamedParameter4dvNV);
+ SET_GetProgramNamedParameterfvNV(disp, glGetProgramNamedParameterfvNV);
+ SET_GetProgramNamedParameterdvNV(disp, glGetProgramNamedParameterdvNV);
+ SET_BindBufferARB(disp, glBindBufferARB);
+ SET_BufferDataARB(disp, glBufferDataARB);
+ SET_BufferSubDataARB(disp, glBufferSubDataARB);
+ SET_DeleteBuffersARB(disp, glDeleteBuffersARB);
+ SET_GenBuffersARB(disp, glGenBuffersARB);
+ SET_GetBufferParameterivARB(disp, glGetBufferParameterivARB);
+ SET_GetBufferPointervARB(disp, glGetBufferPointervARB);
+ SET_GetBufferSubDataARB(disp, glGetBufferSubDataARB);
+ SET_IsBufferARB(disp, glIsBufferARB);
+ SET_MapBufferARB(disp, glMapBufferARB);
+ SET_UnmapBufferARB(disp, glUnmapBufferARB);
+ SET_DepthBoundsEXT(disp, glDepthBoundsEXT);
+ SET_GenQueriesARB(disp, glGenQueriesARB);
+ SET_DeleteQueriesARB(disp, glDeleteQueriesARB);
+ SET_IsQueryARB(disp, glIsQueryARB);
+ SET_BeginQueryARB(disp, glBeginQueryARB);
+ SET_EndQueryARB(disp, glEndQueryARB);
+ SET_GetQueryivARB(disp, glGetQueryivARB);
+ SET_GetQueryObjectivARB(disp, glGetQueryObjectivARB);
+ SET_GetQueryObjectuivARB(disp, glGetQueryObjectuivARB);
+ SET_MultiModeDrawArraysIBM(disp, glMultiModeDrawArraysIBM);
+ SET_MultiModeDrawElementsIBM(disp, glMultiModeDrawElementsIBM);
+ SET_BlendEquationSeparateEXT(disp, glBlendEquationSeparateEXT);
+ SET_DeleteObjectARB(disp, glDeleteObjectARB);
+ SET_GetHandleARB(disp, glGetHandleARB);
+ SET_DetachObjectARB(disp, glDetachObjectARB);
+ SET_CreateShaderObjectARB(disp, glCreateShaderObjectARB);
+ SET_ShaderSourceARB(disp, glShaderSourceARB);
+ SET_CompileShaderARB(disp, glCompileShaderARB);
+ SET_CreateProgramObjectARB(disp, glCreateProgramObjectARB);
+ SET_AttachObjectARB(disp, glAttachObjectARB);
+ SET_LinkProgramARB(disp, glLinkProgramARB);
+ SET_UseProgramObjectARB(disp, glUseProgramObjectARB);
+ SET_ValidateProgramARB(disp, glValidateProgramARB);
+ SET_Uniform1fARB(disp, glUniform1fARB);
+ SET_Uniform2fARB(disp, glUniform2fARB);
+ SET_Uniform3fARB(disp, glUniform3fARB);
+ SET_Uniform4fARB(disp, glUniform4fARB);
+ SET_Uniform1iARB(disp, glUniform1iARB);
+ SET_Uniform2iARB(disp, glUniform2iARB);
+ SET_Uniform3iARB(disp, glUniform3iARB);
+ SET_Uniform4iARB(disp, glUniform4iARB);
+ SET_Uniform1fvARB(disp, glUniform1fvARB);
+ SET_Uniform2fvARB(disp, glUniform2fvARB);
+ SET_Uniform3fvARB(disp, glUniform3fvARB);
+ SET_Uniform4fvARB(disp, glUniform4fvARB);
+ SET_Uniform1ivARB(disp, glUniform1ivARB);
+ SET_Uniform2ivARB(disp, glUniform2ivARB);
+ SET_Uniform3ivARB(disp, glUniform3ivARB);
+ SET_Uniform4ivARB(disp, glUniform4ivARB);
+ SET_UniformMatrix2fvARB(disp, glUniformMatrix2fvARB);
+ SET_UniformMatrix3fvARB(disp, glUniformMatrix3fvARB);
+ SET_UniformMatrix4fvARB(disp, glUniformMatrix4fvARB);
+ SET_GetObjectParameterfvARB(disp, glGetObjectParameterfvARB);
+ SET_GetObjectParameterivARB(disp, glGetObjectParameterivARB);
+ SET_GetInfoLogARB(disp, glGetInfoLogARB);
+ SET_GetAttachedObjectsARB(disp, glGetAttachedObjectsARB);
+ SET_GetUniformLocationARB(disp, glGetUniformLocationARB);
+ SET_GetActiveUniformARB(disp, glGetActiveUniformARB);
+ SET_GetUniformfvARB(disp, glGetUniformfvARB);
+ SET_GetUniformivARB(disp, glGetUniformivARB);
+ SET_GetShaderSourceARB(disp, glGetShaderSourceARB);
+ SET_BindAttribLocationARB(disp, glBindAttribLocationARB);
+ SET_GetActiveAttribARB(disp, glGetActiveAttribARB);
+ SET_GetAttribLocationARB(disp, glGetAttribLocationARB);
+ SET_GetVertexAttribdvNV(disp, glGetVertexAttribdvNV);
+ SET_GetVertexAttribfvNV(disp, glGetVertexAttribfvNV);
+ SET_GetVertexAttribivNV(disp, glGetVertexAttribivNV);
+ SET_VertexAttrib1dNV(disp, glVertexAttrib1dNV);
+ SET_VertexAttrib1dvNV(disp, glVertexAttrib1dvNV);
+ SET_VertexAttrib1fNV(disp, glVertexAttrib1fNV);
+ SET_VertexAttrib1fvNV(disp, glVertexAttrib1fvNV);
+ SET_VertexAttrib1sNV(disp, glVertexAttrib1sNV);
+ SET_VertexAttrib1svNV(disp, glVertexAttrib1svNV);
+ SET_VertexAttrib2dNV(disp, glVertexAttrib2dNV);
+ SET_VertexAttrib2dvNV(disp, glVertexAttrib2dvNV);
+ SET_VertexAttrib2fNV(disp, glVertexAttrib2fNV);
+ SET_VertexAttrib2fvNV(disp, glVertexAttrib2fvNV);
+ SET_VertexAttrib2sNV(disp, glVertexAttrib2sNV);
+ SET_VertexAttrib2svNV(disp, glVertexAttrib2svNV);
+ SET_VertexAttrib3dNV(disp, glVertexAttrib3dNV);
+ SET_VertexAttrib3dvNV(disp, glVertexAttrib3dvNV);
+ SET_VertexAttrib3fNV(disp, glVertexAttrib3fNV);
+ SET_VertexAttrib3fvNV(disp, glVertexAttrib3fvNV);
+ SET_VertexAttrib3sNV(disp, glVertexAttrib3sNV);
+ SET_VertexAttrib3svNV(disp, glVertexAttrib3svNV);
+ SET_VertexAttrib4dNV(disp, glVertexAttrib4dNV);
+ SET_VertexAttrib4dvNV(disp, glVertexAttrib4dvNV);
+ SET_VertexAttrib4fNV(disp, glVertexAttrib4fNV);
+ SET_VertexAttrib4fvNV(disp, glVertexAttrib4fvNV);
+ SET_VertexAttrib4sNV(disp, glVertexAttrib4sNV);
+ SET_VertexAttrib4svNV(disp, glVertexAttrib4svNV);
+ SET_VertexAttrib4ubNV(disp, glVertexAttrib4ubNV);
+ SET_VertexAttrib4ubvNV(disp, glVertexAttrib4ubvNV);
+ SET_GenFragmentShadersATI(disp, glGenFragmentShadersATI);
+ SET_BindFragmentShaderATI(disp, glBindFragmentShaderATI);
+ SET_DeleteFragmentShaderATI(disp, glDeleteFragmentShaderATI);
+ SET_BeginFragmentShaderATI(disp, glBeginFragmentShaderATI);
+ SET_EndFragmentShaderATI(disp, glEndFragmentShaderATI);
+ SET_PassTexCoordATI(disp, glPassTexCoordATI);
+ SET_SampleMapATI(disp, glSampleMapATI);
+ SET_ColorFragmentOp1ATI(disp, glColorFragmentOp1ATI);
+ SET_ColorFragmentOp2ATI(disp, glColorFragmentOp2ATI);
+ SET_ColorFragmentOp3ATI(disp, glColorFragmentOp3ATI);
+ SET_AlphaFragmentOp1ATI(disp, glAlphaFragmentOp1ATI);
+ SET_AlphaFragmentOp2ATI(disp, glAlphaFragmentOp2ATI);
+ SET_AlphaFragmentOp3ATI(disp, glAlphaFragmentOp3ATI);
+ SET_SetFragmentShaderConstantATI(disp, glSetFragmentShaderConstantATI);
+ SET_IsRenderbufferEXT(disp, glIsRenderbufferEXT);
+ SET_BindRenderbufferEXT(disp, glBindRenderbufferEXT);
+ SET_DeleteRenderbuffersEXT(disp, glDeleteRenderbuffersEXT);
+ SET_GenRenderbuffersEXT(disp, glGenRenderbuffersEXT);
+ SET_RenderbufferStorageEXT(disp, glRenderbufferStorageEXT);
+ SET_GetRenderbufferParameterivEXT(disp, glGetRenderbufferParameterivEXT);
+ SET_IsFramebufferEXT(disp, glIsFramebufferEXT);
+ SET_BindFramebufferEXT(disp, glBindFramebufferEXT);
+ SET_DeleteFramebuffersEXT(disp, glDeleteFramebuffersEXT);
+ SET_GenFramebuffersEXT(disp, glGenFramebuffersEXT);
+ SET_CheckFramebufferStatusEXT(disp, glCheckFramebufferStatusEXT);
+ SET_FramebufferTexture1DEXT(disp, glFramebufferTexture1DEXT);
+ SET_FramebufferTexture2DEXT(disp, glFramebufferTexture2DEXT);
+ SET_FramebufferTexture3DEXT(disp, glFramebufferTexture3DEXT);
+ SET_FramebufferRenderbufferEXT(disp, glFramebufferRenderbufferEXT);
+ SET_GetFramebufferAttachmentParameterivEXT(disp, glGetFramebufferAttachmentParameterivEXT);
+ SET_GenerateMipmapEXT(disp, glGenerateMipmapEXT);
+ SET_StencilFuncSeparate(disp, glStencilFuncSeparate);
+ SET_StencilOpSeparate(disp, glStencilOpSeparate);
+ SET_StencilMaskSeparate(disp, glStencilMaskSeparate);
+ SET_GetQueryObjecti64vEXT(disp, glGetQueryObjecti64vEXT);
+ SET_GetQueryObjectui64vEXT(disp, glGetQueryObjectui64vEXT);
+ SET_BlitFramebufferEXT(disp, glBlitFramebufferEXT);
+ SET_LoadTransposeMatrixfARB(disp, glLoadTransposeMatrixfARB);
+ SET_LoadTransposeMatrixdARB(disp, glLoadTransposeMatrixdARB);
+ SET_MultTransposeMatrixfARB(disp, glMultTransposeMatrixfARB);
+ SET_MultTransposeMatrixdARB(disp, glMultTransposeMatrixdARB);
+ SET_SampleCoverageARB(disp, glSampleCoverageARB);
+ SET_DrawBuffersARB(disp, glDrawBuffersARB);
+ SET_PolygonOffsetEXT(disp, glPolygonOffsetEXT);
+ SET_GetTexFilterFuncSGIS(disp, glGetTexFilterFuncSGIS);
+ SET_TexFilterFuncSGIS(disp, glTexFilterFuncSGIS);
+ SET_GetHistogramEXT(disp, glGetHistogramEXT);
+ SET_GetHistogramParameterfvEXT(disp, glGetHistogramParameterfvEXT);
+ SET_GetHistogramParameterivEXT(disp, glGetHistogramParameterivEXT);
+ SET_GetMinmaxEXT(disp, glGetMinmaxEXT);
+ SET_GetMinmaxParameterfvEXT(disp, glGetMinmaxParameterfvEXT);
+ SET_GetMinmaxParameterivEXT(disp, glGetMinmaxParameterivEXT);
+ SET_GetConvolutionFilterEXT(disp, glGetConvolutionFilterEXT);
+ SET_GetConvolutionParameterfvEXT(disp, glGetConvolutionParameterfvEXT);
+ SET_GetConvolutionParameterivEXT(disp, glGetConvolutionParameterivEXT);
+ SET_GetSeparableFilterEXT(disp, glGetSeparableFilterEXT);
+ SET_GetColorTableSGI(disp, glGetColorTableSGI);
+ SET_GetColorTableParameterfvSGI(disp, glGetColorTableParameterfvSGI);
+ SET_GetColorTableParameterivSGI(disp, glGetColorTableParameterivSGI);
+ SET_PixelTexGenSGIX(disp, glPixelTexGenSGIX);
+ SET_PixelTexGenParameteriSGIS(disp, glPixelTexGenParameteriSGIS);
+ SET_PixelTexGenParameterivSGIS(disp, glPixelTexGenParameterivSGIS);
+ SET_PixelTexGenParameterfSGIS(disp, glPixelTexGenParameterfSGIS);
+ SET_PixelTexGenParameterfvSGIS(disp, glPixelTexGenParameterfvSGIS);
+ SET_GetPixelTexGenParameterivSGIS(disp, glGetPixelTexGenParameterivSGIS);
+ SET_GetPixelTexGenParameterfvSGIS(disp, glGetPixelTexGenParameterfvSGIS);
+ SET_TexImage4DSGIS(disp, glTexImage4DSGIS);
+ SET_TexSubImage4DSGIS(disp, glTexSubImage4DSGIS);
+ SET_AreTexturesResidentEXT(disp, glAreTexturesResidentEXT);
+ SET_GenTexturesEXT(disp, glGenTexturesEXT);
+ SET_IsTextureEXT(disp, glIsTextureEXT);
+ SET_DetailTexFuncSGIS(disp, glDetailTexFuncSGIS);
+ SET_GetDetailTexFuncSGIS(disp, glGetDetailTexFuncSGIS);
+ SET_SharpenTexFuncSGIS(disp, glSharpenTexFuncSGIS);
+ SET_GetSharpenTexFuncSGIS(disp, glGetSharpenTexFuncSGIS);
+ SET_SampleMaskSGIS(disp, glSampleMaskSGIS);
+ SET_SamplePatternSGIS(disp, glSamplePatternSGIS);
+ SET_ColorPointerEXT(disp, glColorPointerEXT);
+ SET_EdgeFlagPointerEXT(disp, glEdgeFlagPointerEXT);
+ SET_IndexPointerEXT(disp, glIndexPointerEXT);
+ SET_NormalPointerEXT(disp, glNormalPointerEXT);
+ SET_TexCoordPointerEXT(disp, glTexCoordPointerEXT);
+ SET_VertexPointerEXT(disp, glVertexPointerEXT);
+ SET_SpriteParameterfSGIX(disp, glSpriteParameterfSGIX);
+ SET_SpriteParameterfvSGIX(disp, glSpriteParameterfvSGIX);
+ SET_SpriteParameteriSGIX(disp, glSpriteParameteriSGIX);
+ SET_SpriteParameterivSGIX(disp, glSpriteParameterivSGIX);
+ SET_PointParameterfEXT(disp, glPointParameterfEXT);
+ SET_PointParameterfvEXT(disp, glPointParameterfvEXT);
+ SET_GetInstrumentsSGIX(disp, glGetInstrumentsSGIX);
+ SET_InstrumentsBufferSGIX(disp, glInstrumentsBufferSGIX);
+ SET_PollInstrumentsSGIX(disp, glPollInstrumentsSGIX);
+ SET_ReadInstrumentsSGIX(disp, glReadInstrumentsSGIX);
+ SET_StartInstrumentsSGIX(disp, glStartInstrumentsSGIX);
+ SET_StopInstrumentsSGIX(disp, glStopInstrumentsSGIX);
+ SET_FrameZoomSGIX(disp, glFrameZoomSGIX);
+ SET_TagSampleBufferSGIX(disp, glTagSampleBufferSGIX);
+ SET_ReferencePlaneSGIX(disp, glReferencePlaneSGIX);
+ SET_FlushRasterSGIX(disp, glFlushRasterSGIX);
+ SET_GetListParameterfvSGIX(disp, glGetListParameterfvSGIX);
+ SET_GetListParameterivSGIX(disp, glGetListParameterivSGIX);
+ SET_ListParameterfSGIX(disp, glListParameterfSGIX);
+ SET_ListParameterfvSGIX(disp, glListParameterfvSGIX);
+ SET_ListParameteriSGIX(disp, glListParameteriSGIX);
+ SET_ListParameterivSGIX(disp, glListParameterivSGIX);
+ SET_FragmentColorMaterialSGIX(disp, glFragmentColorMaterialSGIX);
+ SET_FragmentLightfSGIX(disp, glFragmentLightfSGIX);
+ SET_FragmentLightfvSGIX(disp, glFragmentLightfvSGIX);
+ SET_FragmentLightiSGIX(disp, glFragmentLightiSGIX);
+ SET_FragmentLightivSGIX(disp, glFragmentLightivSGIX);
+ SET_FragmentLightModelfSGIX(disp, glFragmentLightModelfSGIX);
+ SET_FragmentLightModelfvSGIX(disp, glFragmentLightModelfvSGIX);
+ SET_FragmentLightModeliSGIX(disp, glFragmentLightModeliSGIX);
+ SET_FragmentLightModelivSGIX(disp, glFragmentLightModelivSGIX);
+ SET_FragmentMaterialfSGIX(disp, glFragmentMaterialfSGIX);
+ SET_FragmentMaterialfvSGIX(disp, glFragmentMaterialfvSGIX);
+ SET_FragmentMaterialiSGIX(disp, glFragmentMaterialiSGIX);
+ SET_FragmentMaterialivSGIX(disp, glFragmentMaterialivSGIX);
+ SET_GetFragmentLightfvSGIX(disp, glGetFragmentLightfvSGIX);
+ SET_GetFragmentLightivSGIX(disp, glGetFragmentLightivSGIX);
+ SET_GetFragmentMaterialfvSGIX(disp, glGetFragmentMaterialfvSGIX);
+ SET_GetFragmentMaterialivSGIX(disp, glGetFragmentMaterialivSGIX);
+ SET_LightEnviSGIX(disp, glLightEnviSGIX);
+ SET_VertexWeightfEXT(disp, glVertexWeightfEXT);
+ SET_VertexWeightfvEXT(disp, glVertexWeightfvEXT);
+ SET_VertexWeightPointerEXT(disp, glVertexWeightPointerEXT);
+ SET_FlushVertexArrayRangeNV(disp, glFlushVertexArrayRangeNV);
+ SET_VertexArrayRangeNV(disp, glVertexArrayRangeNV);
+ SET_CombinerParameterfvNV(disp, glCombinerParameterfvNV);
+ SET_CombinerParameterfNV(disp, glCombinerParameterfNV);
+ SET_CombinerParameterivNV(disp, glCombinerParameterivNV);
+ SET_CombinerParameteriNV(disp, glCombinerParameteriNV);
+ SET_CombinerInputNV(disp, glCombinerInputNV);
+ SET_CombinerOutputNV(disp, glCombinerOutputNV);
+ SET_FinalCombinerInputNV(disp, glFinalCombinerInputNV);
+ SET_GetCombinerInputParameterfvNV(disp, glGetCombinerInputParameterfvNV);
+ SET_GetCombinerInputParameterivNV(disp, glGetCombinerInputParameterivNV);
+ SET_GetCombinerOutputParameterfvNV(disp, glGetCombinerOutputParameterfvNV);
+ SET_GetCombinerOutputParameterivNV(disp, glGetCombinerOutputParameterivNV);
+ SET_GetFinalCombinerInputParameterfvNV(disp, glGetFinalCombinerInputParameterfvNV);
+ SET_GetFinalCombinerInputParameterivNV(disp, glGetFinalCombinerInputParameterivNV);
+ SET_ResizeBuffersMESA(disp, glResizeBuffersMESA);
+ SET_WindowPos2dMESA(disp, glWindowPos2dMESA);
+ SET_WindowPos2dvMESA(disp, glWindowPos2dvMESA);
+ SET_WindowPos2fMESA(disp, glWindowPos2fMESA);
+ SET_WindowPos2fvMESA(disp, glWindowPos2fvMESA);
+ SET_WindowPos2iMESA(disp, glWindowPos2iMESA);
+ SET_WindowPos2ivMESA(disp, glWindowPos2ivMESA);
+ SET_WindowPos2sMESA(disp, glWindowPos2sMESA);
+ SET_WindowPos2svMESA(disp, glWindowPos2svMESA);
+ SET_WindowPos3dMESA(disp, glWindowPos3dMESA);
+ SET_WindowPos3dvMESA(disp, glWindowPos3dvMESA);
+ SET_WindowPos3fMESA(disp, glWindowPos3fMESA);
+ SET_WindowPos3fvMESA(disp, glWindowPos3fvMESA);
+ SET_WindowPos3iMESA(disp, glWindowPos3iMESA);
+ SET_WindowPos3ivMESA(disp, glWindowPos3ivMESA);
+ SET_WindowPos3sMESA(disp, glWindowPos3sMESA);
+ SET_WindowPos3svMESA(disp, glWindowPos3svMESA);
+ SET_WindowPos4dMESA(disp, glWindowPos4dMESA);
+ SET_WindowPos4dvMESA(disp, glWindowPos4dvMESA);
+ SET_WindowPos4fMESA(disp, glWindowPos4fMESA);
+ SET_WindowPos4fvMESA(disp, glWindowPos4fvMESA);
+ SET_WindowPos4iMESA(disp, glWindowPos4iMESA);
+ SET_WindowPos4ivMESA(disp, glWindowPos4ivMESA);
+ SET_WindowPos4sMESA(disp, glWindowPos4sMESA);
+ SET_WindowPos4svMESA(disp, glWindowPos4svMESA);
+ SET_BlendFuncSeparateEXT(disp, glBlendFuncSeparateEXT);
+ SET_IndexMaterialEXT(disp, glIndexMaterialEXT);
+ SET_IndexFuncEXT(disp, glIndexFuncEXT);
+ SET_LockArraysEXT(disp, glLockArraysEXT);
+ SET_UnlockArraysEXT(disp, glUnlockArraysEXT);
+ SET_CullParameterdvEXT(disp, glCullParameterdvEXT);
+ SET_CullParameterfvEXT(disp, glCullParameterfvEXT);
+ SET_HintPGI(disp, glHintPGI);
+ SET_FogCoordfEXT(disp, glFogCoordfEXT);
+ SET_FogCoordfvEXT(disp, glFogCoordfvEXT);
+ SET_FogCoorddEXT(disp, glFogCoorddEXT);
+ SET_FogCoorddvEXT(disp, glFogCoorddvEXT);
+ SET_FogCoordPointerEXT(disp, glFogCoordPointerEXT);
+ SET_GetColorTableEXT(disp, glGetColorTableEXT);
+ SET_GetColorTableParameterivEXT(disp, glGetColorTableParameterivEXT);
+ SET_GetColorTableParameterfvEXT(disp, glGetColorTableParameterfvEXT);
+ SET_TbufferMask3DFX(disp, glTbufferMask3DFX);
+ SET_CompressedTexImage3DARB(disp, glCompressedTexImage3DARB);
+ SET_CompressedTexImage2DARB(disp, glCompressedTexImage2DARB);
+ SET_CompressedTexImage1DARB(disp, glCompressedTexImage1DARB);
+ SET_CompressedTexSubImage3DARB(disp, glCompressedTexSubImage3DARB);
+ SET_CompressedTexSubImage2DARB(disp, glCompressedTexSubImage2DARB);
+ SET_CompressedTexSubImage1DARB(disp, glCompressedTexSubImage1DARB);
+ SET_GetCompressedTexImageARB(disp, glGetCompressedTexImageARB);
+ SET_SecondaryColor3bEXT(disp, glSecondaryColor3bEXT);
+ SET_SecondaryColor3bvEXT(disp, glSecondaryColor3bvEXT);
+ SET_SecondaryColor3dEXT(disp, glSecondaryColor3dEXT);
+ SET_SecondaryColor3dvEXT(disp, glSecondaryColor3dvEXT);
+ SET_SecondaryColor3fEXT(disp, glSecondaryColor3fEXT);
+ SET_SecondaryColor3fvEXT(disp, glSecondaryColor3fvEXT);
+ SET_SecondaryColor3iEXT(disp, glSecondaryColor3iEXT);
+ SET_SecondaryColor3ivEXT(disp, glSecondaryColor3ivEXT);
+ SET_SecondaryColor3sEXT(disp, glSecondaryColor3sEXT);
+ SET_SecondaryColor3svEXT(disp, glSecondaryColor3svEXT);
+ SET_SecondaryColor3ubEXT(disp, glSecondaryColor3ubEXT);
+ SET_SecondaryColor3ubvEXT(disp, glSecondaryColor3ubvEXT);
+ SET_SecondaryColor3uiEXT(disp, glSecondaryColor3uiEXT);
+ SET_SecondaryColor3uivEXT(disp, glSecondaryColor3uivEXT);
+ SET_SecondaryColor3usEXT(disp, glSecondaryColor3usEXT);
+ SET_SecondaryColor3usvEXT(disp, glSecondaryColor3usvEXT);
+ SET_SecondaryColorPointerEXT(disp, glSecondaryColorPointerEXT);
+ SET_AreProgramsResidentNV(disp, glAreProgramsResidentNV);
+ SET_BindProgramNV(disp, glBindProgramNV);
+ SET_DeleteProgramsNV(disp, glDeleteProgramsNV);
+ SET_ExecuteProgramNV(disp, glExecuteProgramNV);
+ SET_GenProgramsNV(disp, glGenProgramsNV);
+ SET_GetProgramParameterdvNV(disp, glGetProgramParameterdvNV);
+ SET_GetProgramParameterfvNV(disp, glGetProgramParameterfvNV);
+ SET_GetProgramivNV(disp, glGetProgramivNV);
+ SET_GetProgramStringNV(disp, glGetProgramStringNV);
+ SET_GetTrackMatrixivNV(disp, glGetTrackMatrixivNV);
+ SET_GetVertexAttribdvARB(disp, glGetVertexAttribdvARB);
+ SET_GetVertexAttribfvARB(disp, glGetVertexAttribfvARB);
+ SET_GetVertexAttribivARB(disp, glGetVertexAttribivARB);
+ SET_GetVertexAttribPointervNV(disp, glGetVertexAttribPointervNV);
+ SET_IsProgramNV(disp, glIsProgramNV);
+ SET_LoadProgramNV(disp, glLoadProgramNV);
+ SET_ProgramParameter4dNV(disp, glProgramParameter4dNV);
+ SET_ProgramParameter4dvNV(disp, glProgramParameter4dvNV);
+ SET_ProgramParameter4fNV(disp, glProgramParameter4fNV);
+ SET_ProgramParameter4fvNV(disp, glProgramParameter4fvNV);
+ SET_ProgramParameters4dvNV(disp, glProgramParameters4dvNV);
+ SET_ProgramParameters4fvNV(disp, glProgramParameters4fvNV);
+ SET_RequestResidentProgramsNV(disp, glRequestResidentProgramsNV);
+ SET_TrackMatrixNV(disp, glTrackMatrixNV);
+ SET_VertexAttribPointerNV(disp, glVertexAttribPointerNV);
+ SET_VertexAttrib1dARB(disp, glVertexAttrib1dARB);
+ SET_VertexAttrib1dvARB(disp, glVertexAttrib1dvARB);
+ SET_VertexAttrib1fARB(disp, glVertexAttrib1fARB);
+ SET_VertexAttrib1fvARB(disp, glVertexAttrib1fvARB);
+ SET_VertexAttrib1sARB(disp, glVertexAttrib1sARB);
+ SET_VertexAttrib1svARB(disp, glVertexAttrib1svARB);
+ SET_VertexAttrib2dARB(disp, glVertexAttrib2dARB);
+ SET_VertexAttrib2dvARB(disp, glVertexAttrib2dvARB);
+ SET_VertexAttrib2fARB(disp, glVertexAttrib2fARB);
+ SET_VertexAttrib2fvARB(disp, glVertexAttrib2fvARB);
+ SET_VertexAttrib2sARB(disp, glVertexAttrib2sARB);
+ SET_VertexAttrib2svARB(disp, glVertexAttrib2svARB);
+ SET_VertexAttrib3dARB(disp, glVertexAttrib3dARB);
+ SET_VertexAttrib3dvARB(disp, glVertexAttrib3dvARB);
+ SET_VertexAttrib3fARB(disp, glVertexAttrib3fARB);
+ SET_VertexAttrib3fvARB(disp, glVertexAttrib3fvARB);
+ SET_VertexAttrib3sARB(disp, glVertexAttrib3sARB);
+ SET_VertexAttrib3svARB(disp, glVertexAttrib3svARB);
+ SET_VertexAttrib4dARB(disp, glVertexAttrib4dARB);
+ SET_VertexAttrib4dvARB(disp, glVertexAttrib4dvARB);
+ SET_VertexAttrib4fARB(disp, glVertexAttrib4fARB);
+ SET_VertexAttrib4fvARB(disp, glVertexAttrib4fvARB);
+ SET_VertexAttrib4sARB(disp, glVertexAttrib4sARB);
+ SET_VertexAttrib4svARB(disp, glVertexAttrib4svARB);
+ SET_VertexAttrib4NubARB(disp, glVertexAttrib4NubARB);
+ SET_VertexAttrib4NubvARB(disp, glVertexAttrib4NubvARB);
+ SET_VertexAttribs1dvNV(disp, glVertexAttribs1dvNV);
+ SET_VertexAttribs1fvNV(disp, glVertexAttribs1fvNV);
+ SET_VertexAttribs1svNV(disp, glVertexAttribs1svNV);
+ SET_VertexAttribs2dvNV(disp, glVertexAttribs2dvNV);
+ SET_VertexAttribs2fvNV(disp, glVertexAttribs2fvNV);
+ SET_VertexAttribs2svNV(disp, glVertexAttribs2svNV);
+ SET_VertexAttribs3dvNV(disp, glVertexAttribs3dvNV);
+ SET_VertexAttribs3fvNV(disp, glVertexAttribs3fvNV);
+ SET_VertexAttribs3svNV(disp, glVertexAttribs3svNV);
+ SET_VertexAttribs4dvNV(disp, glVertexAttribs4dvNV);
+ SET_VertexAttribs4fvNV(disp, glVertexAttribs4fvNV);
+ SET_VertexAttribs4svNV(disp, glVertexAttribs4svNV);
+ SET_VertexAttribs4ubvNV(disp, glVertexAttribs4ubvNV);
+ SET_PointParameteriNV(disp, glPointParameteriNV);
+ SET_PointParameterivNV(disp, glPointParameterivNV);
+ SET_MultiDrawArraysEXT(disp, glMultiDrawArraysEXT);
+ SET_MultiDrawElementsEXT(disp, glMultiDrawElementsEXT);
+ SET_ActiveStencilFaceEXT(disp, glActiveStencilFaceEXT);
+ SET_DeleteFencesNV(disp, glDeleteFencesNV);
+ SET_GenFencesNV(disp, glGenFencesNV);
+ SET_IsFenceNV(disp, glIsFenceNV);
+ SET_TestFenceNV(disp, glTestFenceNV);
+ SET_GetFenceivNV(disp, glGetFenceivNV);
+ SET_FinishFenceNV(disp, glFinishFenceNV);
+ SET_SetFenceNV(disp, glSetFenceNV);
+ SET_VertexAttrib4bvARB(disp, glVertexAttrib4bvARB);
+ SET_VertexAttrib4ivARB(disp, glVertexAttrib4ivARB);
+ SET_VertexAttrib4ubvARB(disp, glVertexAttrib4ubvARB);
+ SET_VertexAttrib4usvARB(disp, glVertexAttrib4usvARB);
+ SET_VertexAttrib4uivARB(disp, glVertexAttrib4uivARB);
+ SET_VertexAttrib4NbvARB(disp, glVertexAttrib4NbvARB);
+ SET_VertexAttrib4NsvARB(disp, glVertexAttrib4NsvARB);
+ SET_VertexAttrib4NivARB(disp, glVertexAttrib4NivARB);
+ SET_VertexAttrib4NusvARB(disp, glVertexAttrib4NusvARB);
+ SET_VertexAttrib4NuivARB(disp, glVertexAttrib4NuivARB);
+ SET_VertexAttribPointerARB(disp, glVertexAttribPointerARB);
+ SET_EnableVertexAttribArrayARB(disp, glEnableVertexAttribArrayARB);
+ SET_DisableVertexAttribArrayARB(disp, glDisableVertexAttribArrayARB);
+ SET_ProgramStringARB(disp, glProgramStringARB);
+ SET_ProgramEnvParameter4dARB(disp, glProgramEnvParameter4dARB);
+ SET_ProgramEnvParameter4dvARB(disp, glProgramEnvParameter4dvARB);
+ SET_ProgramEnvParameter4fARB(disp, glProgramEnvParameter4fARB);
+ SET_ProgramEnvParameter4fvARB(disp, glProgramEnvParameter4fvARB);
+ SET_ProgramLocalParameter4dARB(disp, glProgramLocalParameter4dARB);
+ SET_ProgramLocalParameter4dvARB(disp, glProgramLocalParameter4dvARB);
+ SET_ProgramLocalParameter4fARB(disp, glProgramLocalParameter4fARB);
+ SET_ProgramLocalParameter4fvARB(disp, glProgramLocalParameter4fvARB);
+ SET_GetProgramEnvParameterdvARB(disp, glGetProgramEnvParameterdvARB);
+ SET_GetProgramEnvParameterfvARB(disp, glGetProgramEnvParameterfvARB);
+ SET_GetProgramLocalParameterdvARB(disp, glGetProgramLocalParameterdvARB);
+ SET_GetProgramLocalParameterfvARB(disp, glGetProgramLocalParameterfvARB);
+ SET_GetProgramivARB(disp, glGetProgramivARB);
+ SET_GetProgramStringARB(disp, glGetProgramStringARB);
+ SET_ProgramNamedParameter4fNV(disp, glProgramNamedParameter4fNV);
+ SET_ProgramNamedParameter4dNV(disp, glProgramNamedParameter4dNV);
+ SET_ProgramNamedParameter4fvNV(disp, glProgramNamedParameter4fvNV);
+ SET_ProgramNamedParameter4dvNV(disp, glProgramNamedParameter4dvNV);
+ SET_GetProgramNamedParameterfvNV(disp, glGetProgramNamedParameterfvNV);
+ SET_GetProgramNamedParameterdvNV(disp, glGetProgramNamedParameterdvNV);
+ SET_BindBufferARB(disp, glBindBufferARB);
+ SET_BufferDataARB(disp, glBufferDataARB);
+ SET_BufferSubDataARB(disp, glBufferSubDataARB);
+ SET_DeleteBuffersARB(disp, glDeleteBuffersARB);
+ SET_GenBuffersARB(disp, glGenBuffersARB);
+ SET_GetBufferParameterivARB(disp, glGetBufferParameterivARB);
+ SET_GetBufferPointervARB(disp, glGetBufferPointervARB);
+ SET_GetBufferSubDataARB(disp, glGetBufferSubDataARB);
+ SET_IsBufferARB(disp, glIsBufferARB);
+ SET_MapBufferARB(disp, glMapBufferARB);
+ SET_UnmapBufferARB(disp, glUnmapBufferARB);
+ SET_DepthBoundsEXT(disp, glDepthBoundsEXT);
+ SET_GenQueriesARB(disp, glGenQueriesARB);
+ SET_DeleteQueriesARB(disp, glDeleteQueriesARB);
+ SET_IsQueryARB(disp, glIsQueryARB);
+ SET_BeginQueryARB(disp, glBeginQueryARB);
+ SET_EndQueryARB(disp, glEndQueryARB);
+ SET_GetQueryivARB(disp, glGetQueryivARB);
+ SET_GetQueryObjectivARB(disp, glGetQueryObjectivARB);
+ SET_GetQueryObjectuivARB(disp, glGetQueryObjectuivARB);
+ SET_MultiModeDrawArraysIBM(disp, glMultiModeDrawArraysIBM);
+ SET_MultiModeDrawElementsIBM(disp, glMultiModeDrawElementsIBM);
+ SET_BlendEquationSeparateEXT(disp, glBlendEquationSeparateEXT);
+ SET_DeleteObjectARB(disp, glDeleteObjectARB);
+ SET_GetHandleARB(disp, glGetHandleARB);
+ SET_DetachObjectARB(disp, glDetachObjectARB);
+ SET_CreateShaderObjectARB(disp, glCreateShaderObjectARB);
+ SET_ShaderSourceARB(disp, glShaderSourceARB);
+ SET_CompileShaderARB(disp, glCompileShaderARB);
+ SET_CreateProgramObjectARB(disp, glCreateProgramObjectARB);
+ SET_AttachObjectARB(disp, glAttachObjectARB);
+ SET_LinkProgramARB(disp, glLinkProgramARB);
+ SET_UseProgramObjectARB(disp, glUseProgramObjectARB);
+ SET_ValidateProgramARB(disp, glValidateProgramARB);
+ SET_Uniform1fARB(disp, glUniform1fARB);
+ SET_Uniform2fARB(disp, glUniform2fARB);
+ SET_Uniform3fARB(disp, glUniform3fARB);
+ SET_Uniform4fARB(disp, glUniform4fARB);
+ SET_Uniform1iARB(disp, glUniform1iARB);
+ SET_Uniform2iARB(disp, glUniform2iARB);
+ SET_Uniform3iARB(disp, glUniform3iARB);
+ SET_Uniform4iARB(disp, glUniform4iARB);
+ SET_Uniform1fvARB(disp, glUniform1fvARB);
+ SET_Uniform2fvARB(disp, glUniform2fvARB);
+ SET_Uniform3fvARB(disp, glUniform3fvARB);
+ SET_Uniform4fvARB(disp, glUniform4fvARB);
+ SET_Uniform1ivARB(disp, glUniform1ivARB);
+ SET_Uniform2ivARB(disp, glUniform2ivARB);
+ SET_Uniform3ivARB(disp, glUniform3ivARB);
+ SET_Uniform4ivARB(disp, glUniform4ivARB);
+ SET_UniformMatrix2fvARB(disp, glUniformMatrix2fvARB);
+ SET_UniformMatrix3fvARB(disp, glUniformMatrix3fvARB);
+ SET_UniformMatrix4fvARB(disp, glUniformMatrix4fvARB);
+ SET_GetObjectParameterfvARB(disp, glGetObjectParameterfvARB);
+ SET_GetObjectParameterivARB(disp, glGetObjectParameterivARB);
+ SET_GetInfoLogARB(disp, glGetInfoLogARB);
+ SET_GetAttachedObjectsARB(disp, glGetAttachedObjectsARB);
+ SET_GetUniformLocationARB(disp, glGetUniformLocationARB);
+ SET_GetActiveUniformARB(disp, glGetActiveUniformARB);
+ SET_GetUniformfvARB(disp, glGetUniformfvARB);
+ SET_GetUniformivARB(disp, glGetUniformivARB);
+ SET_GetShaderSourceARB(disp, glGetShaderSourceARB);
+ SET_BindAttribLocationARB(disp, glBindAttribLocationARB);
+ SET_GetActiveAttribARB(disp, glGetActiveAttribARB);
+ SET_GetAttribLocationARB(disp, glGetAttribLocationARB);
+ SET_GetVertexAttribdvNV(disp, glGetVertexAttribdvNV);
+ SET_GetVertexAttribfvNV(disp, glGetVertexAttribfvNV);
+ SET_GetVertexAttribivNV(disp, glGetVertexAttribivNV);
+ SET_VertexAttrib1dNV(disp, glVertexAttrib1dNV);
+ SET_VertexAttrib1dvNV(disp, glVertexAttrib1dvNV);
+ SET_VertexAttrib1fNV(disp, glVertexAttrib1fNV);
+ SET_VertexAttrib1fvNV(disp, glVertexAttrib1fvNV);
+ SET_VertexAttrib1sNV(disp, glVertexAttrib1sNV);
+ SET_VertexAttrib1svNV(disp, glVertexAttrib1svNV);
+ SET_VertexAttrib2dNV(disp, glVertexAttrib2dNV);
+ SET_VertexAttrib2dvNV(disp, glVertexAttrib2dvNV);
+ SET_VertexAttrib2fNV(disp, glVertexAttrib2fNV);
+ SET_VertexAttrib2fvNV(disp, glVertexAttrib2fvNV);
+ SET_VertexAttrib2sNV(disp, glVertexAttrib2sNV);
+ SET_VertexAttrib2svNV(disp, glVertexAttrib2svNV);
+ SET_VertexAttrib3dNV(disp, glVertexAttrib3dNV);
+ SET_VertexAttrib3dvNV(disp, glVertexAttrib3dvNV);
+ SET_VertexAttrib3fNV(disp, glVertexAttrib3fNV);
+ SET_VertexAttrib3fvNV(disp, glVertexAttrib3fvNV);
+ SET_VertexAttrib3sNV(disp, glVertexAttrib3sNV);
+ SET_VertexAttrib3svNV(disp, glVertexAttrib3svNV);
+ SET_VertexAttrib4dNV(disp, glVertexAttrib4dNV);
+ SET_VertexAttrib4dvNV(disp, glVertexAttrib4dvNV);
+ SET_VertexAttrib4fNV(disp, glVertexAttrib4fNV);
+ SET_VertexAttrib4fvNV(disp, glVertexAttrib4fvNV);
+ SET_VertexAttrib4sNV(disp, glVertexAttrib4sNV);
+ SET_VertexAttrib4svNV(disp, glVertexAttrib4svNV);
+ SET_VertexAttrib4ubNV(disp, glVertexAttrib4ubNV);
+ SET_VertexAttrib4ubvNV(disp, glVertexAttrib4ubvNV);
+ SET_GenFragmentShadersATI(disp, glGenFragmentShadersATI);
+ SET_BindFragmentShaderATI(disp, glBindFragmentShaderATI);
+ SET_DeleteFragmentShaderATI(disp, glDeleteFragmentShaderATI);
+ SET_BeginFragmentShaderATI(disp, glBeginFragmentShaderATI);
+ SET_EndFragmentShaderATI(disp, glEndFragmentShaderATI);
+ SET_PassTexCoordATI(disp, glPassTexCoordATI);
+ SET_SampleMapATI(disp, glSampleMapATI);
+ SET_ColorFragmentOp1ATI(disp, glColorFragmentOp1ATI);
+ SET_ColorFragmentOp2ATI(disp, glColorFragmentOp2ATI);
+ SET_ColorFragmentOp3ATI(disp, glColorFragmentOp3ATI);
+ SET_AlphaFragmentOp1ATI(disp, glAlphaFragmentOp1ATI);
+ SET_AlphaFragmentOp2ATI(disp, glAlphaFragmentOp2ATI);
+ SET_AlphaFragmentOp3ATI(disp, glAlphaFragmentOp3ATI);
+ SET_SetFragmentShaderConstantATI(disp, glSetFragmentShaderConstantATI);
+ SET_IsRenderbufferEXT(disp, glIsRenderbufferEXT);
+ SET_BindRenderbufferEXT(disp, glBindRenderbufferEXT);
+ SET_DeleteRenderbuffersEXT(disp, glDeleteRenderbuffersEXT);
+ SET_GenRenderbuffersEXT(disp, glGenRenderbuffersEXT);
+ SET_RenderbufferStorageEXT(disp, glRenderbufferStorageEXT);
+ SET_GetRenderbufferParameterivEXT(disp, glGetRenderbufferParameterivEXT);
+ SET_IsFramebufferEXT(disp, glIsFramebufferEXT);
+ SET_BindFramebufferEXT(disp, glBindFramebufferEXT);
+ SET_DeleteFramebuffersEXT(disp, glDeleteFramebuffersEXT);
+ SET_GenFramebuffersEXT(disp, glGenFramebuffersEXT);
+ SET_CheckFramebufferStatusEXT(disp, glCheckFramebufferStatusEXT);
+ SET_FramebufferTexture1DEXT(disp, glFramebufferTexture1DEXT);
+ SET_FramebufferTexture2DEXT(disp, glFramebufferTexture2DEXT);
+ SET_FramebufferTexture3DEXT(disp, glFramebufferTexture3DEXT);
+ SET_FramebufferRenderbufferEXT(disp, glFramebufferRenderbufferEXT);
+ SET_GetFramebufferAttachmentParameterivEXT(disp, glGetFramebufferAttachmentParameterivEXT);
+ SET_GenerateMipmapEXT(disp, glGenerateMipmapEXT);
+ SET_StencilFuncSeparate(disp, glStencilFuncSeparate);
+ SET_StencilOpSeparate(disp, glStencilOpSeparate);
+ SET_StencilMaskSeparate(disp, glStencilMaskSeparate);
+ SET_GetQueryObjecti64vEXT(disp, glGetQueryObjecti64vEXT);
+ SET_GetQueryObjectui64vEXT(disp, glGetQueryObjectui64vEXT);
+ SET_BlitFramebufferEXT(disp, glBlitFramebufferEXT); */
+
+}
diff-tree 90ca76ba28fcd8bed945e33cf9674784fa2eb533 (from 06c3021aec720837bef432656e88ae9b4e35101d)
Author: Jay Cotton <jay.cotton at sun.com>
Date:   Wed Feb 28 17:40:58 2007 -0800

    Add sun_apm.c for Suspend-and-Resume support on Solaris
    
    <http://bugs.opensolaris.org/bugdatabase/view_bug.do?bug_id=6205248>

diff --git a/hw/xfree86/os-support/solaris/Makefile.am b/hw/xfree86/os-support/solaris/Makefile.am
index 57ec89e..d01e2e6 100644
--- a/hw/xfree86/os-support/solaris/Makefile.am
+++ b/hw/xfree86/os-support/solaris/Makefile.am
@@ -19,9 +19,9 @@ solaris-$(SOLARIS_INOUT_ARCH).il: solari
 
 noinst_LTLIBRARIES = libsolaris.la
 libsolaris_la_SOURCES = sun_bios.c sun_init.c \
-	sun_mouse.c sun_vid.c sun_bell.c $(AGP_SRC) \
+	sun_mouse.c sun_vid.c sun_bell.c $(AGP_SRC) sun_apm.c \
 	$(srcdir)/../shared/libc_wrapper.c \
-	$(srcdir)/../shared/kmod_noop.c $(srcdir)/../shared/pm_noop.c \
+	$(srcdir)/../shared/kmod_noop.c \
 	$(srcdir)/../shared/posix_tty.c $(srcdir)/../shared/sigiostubs.c \
 	$(srcdir)/../shared/stdPci.c $(srcdir)/../shared/stdResource.c \
 	$(VTSW_SRC)
diff --git a/hw/xfree86/os-support/solaris/sun_apm.c b/hw/xfree86/os-support/solaris/sun_apm.c
new file mode 100644
index 0000000..a9657fd
--- /dev/null
+++ b/hw/xfree86/os-support/solaris/sun_apm.c
@@ -0,0 +1,232 @@
+/* Based on hw/xfree86/os-support/bsd/bsd_apm.c which bore no explicit
+ * copyright notice, so is covered by the following notice:
+ *
+ * Copyright (C) 1994-2003 The XFree86 Project, Inc.  All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE XFREE86 PROJECT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of the XFree86 Project shall
+ * not be used in advertising or otherwise to promote the sale, use or other
+ * dealings in this Software without prior written authorization from the
+ * XFree86 Project.
+ */
+
+/* Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, and/or sell copies of the Software, and to permit persons
+ * to whom the Software is furnished to do so, provided that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the Software and that both the above copyright notice(s) and this
+ * permission notice appear in supporting documentation.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
+ * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
+ * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Except as contained in this notice, the name of a copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include "os.h"
+#include "xf86.h"
+#include "xf86Priv.h"
+#define XF86_OS_PRIVS
+#include "xf86_OSproc.h"
+#include "xf86_OSlib.h"
+
+#ifndef PLEASE_FIX_THIS
+#define APM_STANDBY_REQ 0xa01
+#define APM_SUSPEND_REQ 0xa02
+#define APM_NORMAL_RESUME 0xa03
+#define APM_CRIT_RESUME 0xa04
+#define APM_BATTERY_LOW 0xa05
+#define APM_POWER_CHANGE 0xa06
+#define APM_UPDATE_TIME 0xa07
+#define APM_CRIT_SUSPEND_REQ 0xa08
+#define APM_USER_STANDBY_REQ 0xa09
+#define APM_USER_SUSPEND_REQ 0xa0a
+#define APM_SYS_STANDBY_RESUME 0xa0b
+#define APM_IOC_NEXTEVENT 0xa0c
+#define APM_IOC_RESUME 0xa0d
+#define APM_IOC_SUSPEND 0xa0e
+#define APM_IOC_STANDBY 0xa0f
+#endif
+
+typedef struct apm_event_info 
+{
+	int	type;
+} apm_event_info;
+
+/*
+ This may be replaced with a better device name
+ very soon...
+*/
+#define APM_DEVICE "/dev/srn"
+#define APM_DEVICE1 "/dev/apm"
+
+static pointer APMihPtr = NULL;
+static void sunCloseAPM(void);
+
+static struct {
+    u_int apmBsd;
+    pmEvent xf86;
+} sunToXF86Array [] = {
+    { APM_STANDBY_REQ, XF86_APM_SYS_STANDBY },
+    { APM_SUSPEND_REQ, XF86_APM_SYS_SUSPEND },
+    { APM_NORMAL_RESUME, XF86_APM_NORMAL_RESUME },
+    { APM_CRIT_RESUME, XF86_APM_CRITICAL_RESUME },
+    { APM_BATTERY_LOW, XF86_APM_LOW_BATTERY },
+    { APM_POWER_CHANGE, XF86_APM_POWER_STATUS_CHANGE },
+    { APM_UPDATE_TIME, XF86_APM_UPDATE_TIME },
+    { APM_CRIT_SUSPEND_REQ, XF86_APM_CRITICAL_SUSPEND },
+    { APM_USER_STANDBY_REQ, XF86_APM_USER_STANDBY },
+    { APM_USER_SUSPEND_REQ, XF86_APM_USER_SUSPEND },
+    { APM_SYS_STANDBY_RESUME, XF86_APM_STANDBY_RESUME },
+#ifdef APM_CAPABILITY_CHANGE
+    { APM_CAPABILITY_CHANGE, XF86_APM_CAPABILITY_CHANGED },
+#endif
+};
+
+#define numApmEvents (sizeof(sunToXF86Array) / sizeof(sunToXF86Array[0]))
+
+static pmEvent
+sunToXF86(int type)
+{
+    int i;
+
+    for (i = 0; i < numApmEvents; i++) {
+	if (type == sunToXF86Array[i].apmBsd) {
+	    return sunToXF86Array[i].xf86;
+	}
+    }
+    return XF86_APM_UNKNOWN;
+}
+
+/*
+ * APM events can be requested direclty from /dev/apm 
+ */
+static int 
+sunPMGetEventFromOS(int fd, pmEvent *events, int num)
+{
+    struct apm_event_info sunEvent;
+    int i;
+
+    for (i = 0; i < num; i++) {
+	
+	if (ioctl(fd, APM_IOC_NEXTEVENT, &sunEvent) < 0) {
+	    if (errno != EAGAIN) {
+		xf86Msg(X_WARNING, "sunPMGetEventFromOS: APM_IOC_NEXTEVENT"
+			" errno = %d\n", errno);
+	    }
+	    break;
+	}
+	events[i] = sunToXF86(sunEvent.type);
+    }
+    xf86Msg(X_WARNING, "Got some events\n");
+    return i;
+}
+
+static pmWait
+sunPMConfirmEventToOs(int fd, pmEvent event)
+{
+    switch (event) {
+/* XXX: NOT CURRENTLY RETURNED FROM OS */
+      case XF86_APM_SYS_STANDBY:
+      case XF86_APM_USER_STANDBY:
+        if (ioctl( fd, APM_IOC_STANDBY, NULL ) == 0)
+            return PM_WAIT;  /* should we stop the Xserver in standby, too? */
+        else
+            return PM_NONE;
+      case XF86_APM_SYS_SUSPEND:
+      case XF86_APM_CRITICAL_SUSPEND:
+      case XF86_APM_USER_SUSPEND:
+	    xf86Msg(X_WARNING, "Got SUSPENDED\n");
+        if (ioctl( fd, APM_IOC_SUSPEND, NULL ) == 0)
+            return PM_CONTINUE;
+        else {
+	    xf86Msg(X_WARNING, "sunPMConfirmEventToOs: APM_IOC_SUSPEND"
+		" errno = %d\n", errno);
+            return PM_FAILED;
+	}
+      case XF86_APM_STANDBY_RESUME:
+      case XF86_APM_NORMAL_RESUME:
+      case XF86_APM_CRITICAL_RESUME:
+      case XF86_APM_STANDBY_FAILED:
+      case XF86_APM_SUSPEND_FAILED:
+	    xf86Msg(X_WARNING, "Got RESUME\n");
+        if (ioctl( fd, APM_IOC_RESUME, NULL ) == 0)
+            return PM_CONTINUE;
+        else {
+	    xf86Msg(X_WARNING, "sunPMConfirmEventToOs: APM_IOC_RESUME"
+		" errno = %d\n", errno);
+            return PM_FAILED;
+	}
+      default:
+	return PM_NONE;
+    }
+}
+
+PMClose
+xf86OSPMOpen(void)
+{
+    int fd;
+
+    if (APMihPtr || !xf86Info.pmFlag) {
+	return NULL;
+    }
+
+    if ((fd = open(APM_DEVICE, O_RDWR)) == -1) {
+    	if ((fd = open(APM_DEVICE1, O_RDWR)) == -1) {
+		return NULL;
+	}
+    }
+    xf86PMGetEventFromOs = sunPMGetEventFromOS;
+    xf86PMConfirmEventToOs = sunPMConfirmEventToOs;
+    APMihPtr = xf86AddInputHandler(fd, xf86HandlePMEvents, NULL);
+    return sunCloseAPM;
+}
+
+static void
+sunCloseAPM(void)
+{
+    int fd;
+
+    if (APMihPtr) {
+	fd = xf86RemoveInputHandler(APMihPtr);
+	close(fd);
+	APMihPtr = NULL;
+    }
+}
diff-tree 06c3021aec720837bef432656e88ae9b4e35101d (from 68c64ad7b1eea79c786b5a7f3459076780163a47)
Author: Aaron Plattner <aplattner at nvidia.com>
Date:   Wed Feb 28 16:09:11 2007 -0800

    Don't crash setting a NULL mode with a randr classic DDX. Also remember to update the screen size during modesets.

diff --git a/randr/rrcrtc.c b/randr/rrcrtc.c
index 474c946..1f7462f 100644
--- a/randr/rrcrtc.c
+++ b/randr/rrcrtc.c
@@ -290,6 +290,12 @@ RRCrtcSet (RRCrtcPtr    crtc,
 	    RRScreenRate	    rate;
 	    Bool		    ret;
 
+	    if (!mode)
+	    {
+		RRCrtcNotify (crtc, NULL, x, y, rotation, 0, NULL);
+		return TRUE;
+	    }
+
 	    size.width = mode->mode.width;
 	    size.height = mode->mode.height;
 	    if (outputs[0]->mmWidth && outputs[0]->mmHeight)
@@ -310,7 +316,10 @@ RRCrtcSet (RRCrtcPtr    crtc,
 	     * Old 1.0 interface tied screen size to mode size
 	     */
 	    if (ret)
+	    {
 		RRCrtcNotify (crtc, mode, x, y, rotation, 1, outputs);
+		RRScreenSizeNotify (pScreen);
+	    }
 	    return ret;
 	}
 #endif
diff-tree 68c64ad7b1eea79c786b5a7f3459076780163a47 (from 8b245758845523d5f8f017bb9d0e9aa57b616c28)
Author: Peter Hutterer <peter at cs.unisa.edu.au>
Date:   Thu Mar 1 09:51:20 2007 +1030

    Xext: Update device's lastx/lasty when sending a motion event with XTest.

diff --git a/Xext/xtest.c b/Xext/xtest.c
index c9b511e..94d8974 100644
--- a/Xext/xtest.c
+++ b/Xext/xtest.c
@@ -441,6 +441,8 @@ ProcXTestFakeInput(client)
 	    (root->drawable.pScreen,
 	     ev->u.keyButtonPointer.rootX,
 	     ev->u.keyButtonPointer.rootY, FALSE);
+        dev->valuator->lastx = ev->u.keyButtonPointer.rootX;
+        dev->valuator->lasty = ev->u.keyButtonPointer.rootY;
 	break;
     case ButtonPress:
     case ButtonRelease:
diff-tree 8b245758845523d5f8f017bb9d0e9aa57b616c28 (from d9bcb22d199e8444b9762a35754e04d327dd5915)
Author: Aaron Plattner <aplattner at nvidia.com>
Date:   Mon Feb 26 17:45:40 2007 -0800

    Return BadMatch if a client tries to clone non-cloneable outputs.

diff --git a/randr/rrcrtc.c b/randr/rrcrtc.c
index fdd1d42..474c946 100644
--- a/randr/rrcrtc.c
+++ b/randr/rrcrtc.c
@@ -667,6 +667,27 @@ ProcRRSetCrtcConfig (ClientPtr client)
 	    return BadMatch;
 	}
     }
+    /* validate clones */
+    for (i = 0; i < numOutputs; i++)
+    {
+	for (j = 0; j < numOutputs; j++)
+	{
+	    int k;
+	    if (i == j)
+		continue;
+	    for (k = 0; k < outputs[i]->numClones; k++)
+	    {
+		if (outputs[i]->clones[k] == outputs[j])
+		    break;
+	    }
+	    if (k == outputs[i]->numClones)
+	    {
+		if (outputs)
+		    xfree (outputs);
+		return BadMatch;
+	    }
+	}
+    }
 
     pScreen = crtc->pScreen;
     pScrPriv = rrGetScrPriv(pScreen);
diff-tree d9bcb22d199e8444b9762a35754e04d327dd5915 (from parents)
Merge: 272d9341d0f7c3e9e0c9b9a8c0d4d8779cdcc5cf c16343ac2ca18391b21022b2edd02ad9f413d2b3
Author: Ben Byer <bbyer at bbyer.apple.com>
Date:   Tue Feb 27 16:28:20 2007 -0800

    Merge branch 'master' of git+ssh://bbyer@git.freedesktop.org/git/xorg/xserver

diff-tree 272d9341d0f7c3e9e0c9b9a8c0d4d8779cdcc5cf (from ab0fc8c1ad7ea2dc3389a4a4bb1c45bbded5e7ad)
Author: Ben Byer <bbyer at bbyer.apple.com>
Date:   Tue Feb 27 16:27:26 2007 -0800

    fix for hw/darwin/Makefile.am to properly use XSERVER_LIBS

diff --git a/hw/darwin/Makefile.am b/hw/darwin/Makefile.am
index 22b396e..9b4628e 100644
--- a/hw/darwin/Makefile.am
+++ b/hw/darwin/Makefile.am
@@ -85,7 +85,7 @@ XDarwin_LDADD = \
 		$(top_builddir)/miext/rootless/safeAlpha/libsafeAlpha.la \
 		$(top_builddir)/miext/rootless/accel/librlAccel.la \
 		@XORG_LIBS@ \
-		-lXau -lXdmcp -lXfont -lfreetype
+		$(XSERVER_LIBS)
 
 Xquartz_LDADD = \
 		$(top_builddir)/dix/dixfonts.lo \
@@ -112,7 +112,7 @@ Xquartz_LDADD = \
 		$(top_builddir)/miext/rootless/safeAlpha/libsafeAlpha.la \
 		$(top_builddir)/miext/rootless/accel/librlAccel.la \
 		@XORG_LIBS@ \
-		-lXau -lXdmcp -lXfont -lfreetype -lXplugin
+		$(XSERVER_LIBS) -lXplugin
 
 XDarwin_LDFLAGS =  \
                  -XCClinker -Objc \
@@ -175,7 +175,7 @@ XDarwinApp_LDADD = \
 		 $(top_builddir)/miext/rootless/safeAlpha/libsafeAlpha.la \
 		 $(top_builddir)/miext/rootless/accel/librlAccel.la \
 		 @XORG_LIBS@ \
-		 -lXau -lXdmcp -lXfont -lfreetype \
+		 $(XSERVER_LIBS) \
 		 $(top_builddir)/fb/libfb.la 
 
 XDarwinApp_LDFLAGS =  \
diff-tree c16343ac2ca18391b21022b2edd02ad9f413d2b3 (from 5680efc0d2baf0a9451e82e490e3690fc23dda0f)
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Feb 27 14:14:47 2007 -0500

    Make mfb, cfb, and afb support configurable at build-time.

diff --git a/configure.ac b/configure.ac
index 3260855..9cefc2a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -540,6 +540,10 @@ AC_ARG_ENABLE(xprint,         AS_HELP_ST
 AC_ARG_ENABLE(xgl,            AS_HELP_STRING([--enable-xgl], [Build Xgl server (default: no)]), [XGL=$enableval], [XGL=no])
 AC_ARG_ENABLE(xglx,           AS_HELP_STRING([--enable-xglx], [Build Xglx xgl module (default: no)]), [XGLX=$enableval], [XGLX=no])
 AC_ARG_ENABLE(xegl,           AS_HELP_STRING([--enable-xegl], [Build Xegl xgl module (default: no)]), [XEGL=$enableval], [XEGL=no])
+dnl legacy fb support
+AC_ARG_ENABLE(mfb,            AS_HELP_STRING([--enable-mfb], [Build legacy mono framebuffer support (default: enabled)]), [MFB=$enableval], [MFB=$XORG])
+AC_ARG_ENABLE(cfb,            AS_HELP_STRING([--enable-cfb], [Build legacy color framebuffer support (default: enabled)]), [CFB=$enableval], [CFB=$XORG])
+AC_ARG_ENABLE(afb,            AS_HELP_STRING([--enable-afb], [Build legacy advanced framebuffer support (default: enabled)]), [AFB=$enableval], [AFB=$XORG])
 dnl kdrive and its subsystems
 AC_ARG_ENABLE(kdrive,         AS_HELP_STRING([--enable-kdrive], [Build kdrive servers (default: no)]), [KDRIVE=$enableval], [KDRIVE=no])
 AC_ARG_ENABLE(xephyr,         AS_HELP_STRING([--enable-xephyr], [Build the kdrive Xephyr server (default: auto)]), [XEPHYR=$enableval], [XEPHYR=auto])
@@ -1561,13 +1565,20 @@ AM_CONDITIONAL([LINUX_ALPHA], [test "x$l
 AM_CONDITIONAL([LNXACPI], [test "x$linux_acpi" = xyes])
 AM_CONDITIONAL([SOLARIS_USL_CONSOLE], [test "x$solaris_usl_console" = xyes])
 AM_CONDITIONAL([SOLARIS_ASM_INLINE], [test "x$solaris_asm_inline" = xyes])
-AM_CONDITIONAL(MFB, [test "x$XORG" = xyes])
-AM_CONDITIONAL(CFB, [test "x$XORG" = xyes])
-AM_CONDITIONAL(AFB, [test "x$XORG" = xyes])
 AM_CONDITIONAL([BUILD_DARWIN],[test "X$build_darwin" = Xyes])
 AM_CONDITIONAL([XQUARTZ],[test "X$XQUARTZ" = Xyes])
 AM_CONDITIONAL(DGA, [test "x$DGA" = xyes])
 
+dnl legacy fb support
+AM_CONDITIONAL(MFB, [test "x$MFB" = xyes])
+AM_CONDITIONAL(CFB, [test "x$CFB" = xyes])
+AM_CONDITIONAL(AFB, [test "x$AFB" = xyes])
+if test "x$MFB" = xyes -o "x$CFB" = xyes -o "x$AFB" = xyes; then
+	if test "x$XORG" != xyes; then
+		AC_MSG_ERROR([legacy fb support requires the Xorg server])
+	fi
+fi
+
 dnl Xprint DDX
 
 AC_MSG_CHECKING([whether to build Xprint DDX])
diff --git a/hw/xfree86/Makefile.am b/hw/xfree86/Makefile.am
index 1a286d6..b669063 100644
--- a/hw/xfree86/Makefile.am
+++ b/hw/xfree86/Makefile.am
@@ -8,11 +8,19 @@ if XF86UTILS
 XF86UTILS_SUBDIR = utils
 endif
 
+if MFB
+MFB_SUBDIR = xf1bpp xf4bpp
+endif
+
+if CFB
+CFB_SUBDIR = xf8_16bpp xf8_32bpp
+endif
+
 DOC_SUBDIR = doc
 
 SUBDIRS = common ddc dummylib i2c x86emu int10 fbdevhw os-support parser rac \
-          ramdac shadowfb vbe vgahw xaa xf1bpp xf4bpp xf8_16bpp \
-	  xf8_32bpp loader scanpci dixmods exa modes \
+	  ramdac shadowfb vbe vgahw xaa $(MFB_SUBDIR) $(CFB_SUBDIR) \
+	  loader scanpci dixmods exa modes \
 	  $(DRI_SUBDIR) $(XF86UTILS_SUBDIR) $(DOC_SUBDIR)
 
 DIST_SUBDIRS = common ddc dummylib i2c x86emu int10 fbdevhw os-support \
diff --git a/hw/xfree86/dixmods/Makefile.am b/hw/xfree86/dixmods/Makefile.am
index c34ddd6..58099bc 100644
--- a/hw/xfree86/dixmods/Makefile.am
+++ b/hw/xfree86/dixmods/Makefile.am
@@ -14,12 +14,23 @@ if DBE
 DBEMOD = libdbe.la
 endif
 
-module_LTLIBRARIES = libafb.la \
-                     libcfb.la \
-                     libcfb32.la \
+if AFB
+AFBMOD = libafb.la
+endif
+
+if CFB
+CFBMOD = libcfb.la libcfb32.la
+endif
+
+if MFB
+MFBMOD = libmfb.la
+endif
+
+module_LTLIBRARIES = $(AFBMOD) \
+                     $(CFBMOD) \
                      libfb.la \
                      libwfb.la \
-                     libmfb.la \
+                     $(MFBMOD) \
                      libshadow.la
 
 extsmoduledir = $(moduledir)/extensions
diff-tree 5680efc0d2baf0a9451e82e490e3690fc23dda0f (from ab0fc8c1ad7ea2dc3389a4a4bb1c45bbded5e7ad)
Author: Alan Coopersmith <alan.coopersmith at sun.com>
Date:   Tue Feb 27 09:55:48 2007 -0800

    Sun bug 6529003: Xorg should not be including <sys/immu.h> on Solaris
    
    <sys/immu.h> was removed from the latest Solaris Nevada build, but it's
    been useless to Xorg for a long time (it only declared a couple of kernel
    variables)
    <http://bugs.opensolaris.org/view_bug.do?bug_id=6529003>

diff --git a/hw/xfree86/os-support/xf86_OSlib.h b/hw/xfree86/os-support/xf86_OSlib.h
index 97f8723..27f766d 100644
--- a/hw/xfree86/os-support/xf86_OSlib.h
+++ b/hw/xfree86/os-support/xf86_OSlib.h
@@ -130,8 +130,8 @@ typedef signed long xf86ssize_t;
 # include <errno.h>
 
 # if defined(_NEED_SYSI86)
-#  include <sys/immu.h>
 #  if !(defined (sun) && defined (SVR4))
+#    include <sys/immu.h>
 #    include <sys/region.h>
 #  endif
 #  include <sys/proc.h>
diff-tree ab0fc8c1ad7ea2dc3389a4a4bb1c45bbded5e7ad (from cdd4c84572cc3bdd004f8dca6d8b64e710344ac0)
Author: Ben Byer <bbyer at bbyer.(none)>
Date:   Tue Feb 27 00:14:35 2007 -0800

    verbiage corrected per daniels

diff --git a/hw/darwin/README.apple b/hw/darwin/README.apple
index 0977ce9..68bc692 100644
--- a/hw/darwin/README.apple
+++ b/hw/darwin/README.apple
@@ -1,5 +1,5 @@
-This repository contains patches to the modular X.org server code to allow
-it to be compiled on Darwin/OS X; this would not have been possible
+This directory contains a port of the XDarwin code to the modular X.org
+codebase to be compiled on Darwin/OS X; this would not have been possible
 without the help of Torrey Lyons and Peter O'Gorman, to whom I am
 grateful for their patches, time and moral support.
 
diff-tree cdd4c84572cc3bdd004f8dca6d8b64e710344ac0 (from 776d4d6587c57f94bca8732f915d07a0d4e137c8)
Author: Ben Byer <bbyer at bbyer.(none)>
Date:   Mon Feb 26 23:57:02 2007 -0800

    added hw/darwin/README.apple file with some todo items and props.

diff --git a/hw/darwin/README.apple b/hw/darwin/README.apple
new file mode 100644
index 0000000..0977ce9
--- /dev/null
+++ b/hw/darwin/README.apple
@@ -0,0 +1,41 @@
+This repository contains patches to the modular X.org server code to allow
+it to be compiled on Darwin/OS X; this would not have been possible
+without the help of Torrey Lyons and Peter O'Gorman, to whom I am
+grateful for their patches, time and moral support.
+
+The server builds 4 targets:
+
+* XDarwin: this server runs on Darwin systems without Quartz
+  (i.e. non-OS X); it has not been well-tested.
+
+* XDarwinApp: this builds XDarwin.app, which is a full X server using
+  Quartz.  It has loadable module support for AGL and CGL, and well as
+  fullscreen and rootless support.
+
+* Xquartz: this server runs on Quartz-based systems, and is meant to
+  work with X11.app
+
+* x11app: this builds a version of Apple's X11.app using patches by
+  Torrey Lyons; most, but not all, functionality of Apple's original
+  X11.app is present in this release.
+
+Known issues:
+
+* AGL and CGL support for 3D indirect acceleration does not work;
+  indirect.c needs to be rewritten.
+
+* Fullscreen mode does not work; I don't know why.
+
+* The keyboard and mouse do not work at all; they worked in X11R7.1,
+  and I believe that they were broken by the events changes in dix/.
+
+* Some features in X11.app are not yet implemented; these are marked
+  with #ifdef DARWIN_DDX_MISSING in the code.
+
+* The build system code could probably be cleaned up slightly.
+
+* Most testing of this code has occurred under 10.5, but it should
+  also work under 10.4.
+
+Any patches or code contributions would be most welcome and may be
+sent to me at bbyer at apple.com.
diff-tree 776d4d6587c57f94bca8732f915d07a0d4e137c8 (from 154d2c13f4ec22b7e6332808bbcd049d63784891)
Author: Ben Byer <bbyer at bbyer.(none)>
Date:   Mon Feb 26 23:40:00 2007 -0800

    X11.app now builds correctly

diff --git a/hw/darwin/Makefile.am b/hw/darwin/Makefile.am
index 3133eaa..22b396e 100644
--- a/hw/darwin/Makefile.am
+++ b/hw/darwin/Makefile.am
@@ -37,7 +37,7 @@ Xquartz_SOURCES = \
                   $(top_srcdir)/Xi/stubs.c \
                   apple/X11Application.m \
                   apple/X11Controller.m \
-                  quartz/XServer.m \
+                  quartz/Xserver.m \
                   quartz/Preferences.m \
                   quartz/applewm.c \
                   quartz/keysym2ucs.c \
@@ -90,6 +90,7 @@ XDarwin_LDADD = \
 Xquartz_LDADD = \
 		$(top_builddir)/dix/dixfonts.lo \
 		$(top_builddir)/dix/libdix.la \
+		$(top_builddir)/config/libconfig.a \
 		$(top_builddir)/os/libos.la \
 		./libdarwinShared.a \
 		$(top_builddir)/dix/libxpstubs.la \
@@ -122,7 +123,7 @@ Xquartz_LDFLAGS =  \
                  -XCClinker -Objc \
                  -Wl,-u,_miDCInitialize \
                  -Wl,-framework,Carbon \
-                 -Wl,-framework,ApplicationServices \
+                 -Wl,-framework,OpenGL \
                  -Wl,-framework,Cocoa \
                  -Wl,-framework,CoreAudio \
                  -Wl,-framework,IOKit
diff --git a/hw/darwin/quartz/quartzStartup.c b/hw/darwin/quartz/quartzStartup.c
index ae156f8..76392e4 100644
--- a/hw/darwin/quartz/quartzStartup.c
+++ b/hw/darwin/quartz/quartzStartup.c
@@ -42,10 +42,12 @@
 char **envpGlobal;      // argcGlobal and argvGlobal
                         // are from dix/globals.c
 
-#ifdef INX11APP
+#ifdef INXQUARTZ
 void X11ControllerMain(int argc, char *argv[], void (*server_thread) (void *), void *server_arg);
+# ifdef GLXEXT
 void GlxExtensionInit(void);
 void GlxWrapInitVisuals(miInitVisualsProcPtr *);
+# endif
 
 static void server_thread (void *arg) {
   extern int main (int argc, char **argv, char **envp);
@@ -53,19 +55,18 @@ static void server_thread (void *arg) {
 }
 #else
 int NSApplicationMain(int argc, char *argv[]);
+typedef Bool (*QuartzModeBundleInitPtr)(void);
 
+# ifdef GLXEXT
 // GLX bundle function pointers
 typedef void (*GlxExtensionInitPtr)(void); 
 static GlxExtensionInitPtr GlxExtensionInit = NULL;
-
 typedef void (*GlxWrapInitVisualsPtr)(miInitVisualsProcPtr *);
 static GlxWrapInitVisualsPtr GlxWrapInitVisuals = NULL;
-
-typedef Bool (*QuartzModeBundleInitPtr)(void);
-
 void * __DarwinglXMesaProvider = NULL;
 typedef void (*GlxPushProviderPtr)(void *);
 GlxPushProviderPtr GlxPushProvider = NULL;
+# endif
 #endif
 
 /*
@@ -123,7 +124,7 @@ void DarwinHandleGUI(
         }
     }
 
-#ifdef INX11APP
+#ifdef INXQUARTZ
     /* Initially I ran the X server on the main thread, and received
        events on the second thread. But now we may be using Carbon,
        that needs to run on the main thread. (Otherwise, when it's
@@ -143,7 +144,7 @@ void DarwinHandleGUI(
     exit(main_exit);
 }
 
-#ifndef INX11APP
+#ifndef INXQUARTZ
 /*
  * QuartzLoadDisplayBundle
  *  Try to load the appropriate bundle containing the back end display code.
@@ -201,7 +202,7 @@ Bool QuartzLoadDisplayBundle(
     return TRUE;
 }
 
-
+#ifdef GLXEXT
 /*
  * LoadGlxBundle
  *  The Quartz mode X server needs to dynamically load the appropriate
@@ -268,7 +269,7 @@ static void LoadGlxBundle(void)
     CFRelease(bundleName);
     CFRelease(bundleURL);
 }
-
+# endif
 #else
 
 Bool QuartzLoadDisplayBundle(const char *dpyBundleName)
@@ -278,9 +279,10 @@ Bool QuartzLoadDisplayBundle(const char 
 
 #endif
 
+#ifdef GLXEXT
 void DarwinGlxPushProvider(void *impl)
 {
-#ifndef INX11APP
+#ifndef INXQUARTZ
     if (!GlxExtensionInit)
         LoadGlxBundle();
 #endif
@@ -294,7 +296,7 @@ void DarwinGlxPushProvider(void *impl)
  */
 void DarwinGlxExtensionInit(void)
 {
-#ifndef INX11APP
+#ifndef INXQUARTZ
     if (!GlxExtensionInit)
         LoadGlxBundle();
 #endif
@@ -308,13 +310,13 @@ void DarwinGlxExtensionInit(void)
 void DarwinGlxWrapInitVisuals(
     miInitVisualsProcPtr *procPtr)
 {
-#ifndef INX11APP
+#ifndef INXQUARTZ
     if (!GlxWrapInitVisuals)
         LoadGlxBundle();
 #endif
     GlxWrapInitVisuals(procPtr);
 }
-
+#endif
 
 int DarwinModeProcessArgument( int argc, char *argv[], int i )
 {
diff-tree 154d2c13f4ec22b7e6332808bbcd049d63784891 (from fa06e11f972e2a75c84b2f1586997ffc1239cbd9)
Author: Ben Byer <bbyer at bbyer.apple.com>
Date:   Mon Feb 26 19:39:26 2007 -0800

    more changes for X11.app

diff --git a/hw/darwin/Makefile.am b/hw/darwin/Makefile.am
index ebbfb61..3133eaa 100644
--- a/hw/darwin/Makefile.am
+++ b/hw/darwin/Makefile.am
@@ -25,11 +25,39 @@ libdarwinShared_a_SOURCES = darwin.c \
 			  darwinKeyboard.c \
 			  $(darwin_XINPUT_SRCS) 
 
-bin_PROGRAMS = XDarwin
+bin_PROGRAMS = XDarwin Xquartz
 XDarwin_SOURCES = \
                   $(top_srcdir)/fb/fbcmap.c \
                   $(top_srcdir)/mi/miinitext.c \
                   $(top_srcdir)/Xi/stubs.c
+
+Xquartz_SOURCES = \
+                  $(top_srcdir)/fb/fbcmap.c \
+                  $(top_srcdir)/mi/miinitext.c \
+                  $(top_srcdir)/Xi/stubs.c \
+                  apple/X11Application.m \
+                  apple/X11Controller.m \
+                  quartz/XServer.m \
+                  quartz/Preferences.m \
+                  quartz/applewm.c \
+                  quartz/keysym2ucs.c \
+                  quartz/pseudoramiX.c \
+                  quartz/quartz.c \
+                  quartz/quartzAudio.c \
+                  quartz/quartzCocoa.m \
+                  quartz/quartzKeyboard.c \
+                  quartz/quartzPasteboard.c \
+                  quartz/quartzStartup.c \
+                  quartz/xpr/appledri.c \
+                  quartz/xpr/dri.c \
+                  quartz/xpr/xprAppleWM.c \
+                  quartz/xpr/xprCursor.c \
+                  quartz/xpr/xprFrame.c \
+                  quartz/xpr/xprScreen.c \
+                  quartz/xpr/x-hash.c \
+                  quartz/xpr/x-hook.c \
+                  quartz/xpr/x-list.c
+
 XDarwin_LDADD = \
 		$(top_builddir)/dix/dixfonts.lo \
 		$(top_builddir)/dix/libdix.la \
@@ -59,12 +87,48 @@ XDarwin_LDADD = \
 		@XORG_LIBS@ \
 		-lXau -lXdmcp -lXfont -lfreetype
 
+Xquartz_LDADD = \
+		$(top_builddir)/dix/dixfonts.lo \
+		$(top_builddir)/dix/libdix.la \
+		$(top_builddir)/os/libos.la \
+		./libdarwinShared.a \
+		$(top_builddir)/dix/libxpstubs.la \
+		$(top_builddir)/miext/shadow/libshadow.la \
+		$(top_builddir)/fb/libfb.la \
+		$(top_builddir)/composite/libcomposite.la \
+		$(top_builddir)/damageext/libdamageext.la \
+		$(top_builddir)/miext/damage/libdamage.la \
+		$(top_builddir)/xfixes/libxfixes.la \
+		$(top_builddir)/miext/cw/libcw.la \
+		$(top_builddir)/Xext/libXext.la \
+		$(top_builddir)/xkb/libxkb.la \
+		$(top_builddir)/xkb/libxkbstubs.la \
+		$(top_builddir)/Xi/libXi.la \
+		$(top_builddir)/dbe/libdbe.la \
+		$(top_builddir)/record/librecord.la \
+		$(top_builddir)/XTrap/libxtrap.la \
+		$(top_builddir)/miext/rootless/librootless.la \
+		$(top_builddir)/miext/rootless/safeAlpha/libsafeAlpha.la \
+		$(top_builddir)/miext/rootless/accel/librlAccel.la \
+		@XORG_LIBS@ \
+		-lXau -lXdmcp -lXfont -lfreetype -lXplugin
+
 XDarwin_LDFLAGS =  \
-		 -XCClinker -Objc \
-		 -Wl,-u,_miDCInitialize \
-		 -Wl,-framework,IOKit
+                 -XCClinker -Objc \
+                 -Wl,-u,_miDCInitialize \
+                 -Wl,-framework,IOKit
+
+Xquartz_LDFLAGS =  \
+                 -XCClinker -Objc \
+                 -Wl,-u,_miDCInitialize \
+                 -Wl,-framework,Carbon \
+                 -Wl,-framework,ApplicationServices \
+                 -Wl,-framework,Cocoa \
+                 -Wl,-framework,CoreAudio \
+                 -Wl,-framework,IOKit
 
 XDarwin_CFLAGS = -DINXDARWIN
+Xquartz_CFLAGS = -DINXQUARTZ -DHAS_CG_MACH_PORT -DHAS_KL_API  -DHAVE_XORG_CONFIG_H
 
 if XQUARTZ
 macosdir = $(darwinappdir)/Contents/MacOS
@@ -72,6 +136,10 @@ macosdir = $(darwinappdir)/Contents/MacO
 DEFS += -DDARWIN_WITH_QUARTZ -DXFree86Server
 
 macos_PROGRAMS = XDarwinApp
+macos_SCRIPTS = x11app
+
+x11app:
+	cd apple && xcodebuild
 
 XDarwinApp_SOURCES = \
                 $(top_srcdir)/fb/fbcmap.c \
@@ -248,6 +316,7 @@ install-data-hook: $(HOOK_TARGETS)
 
 xquartz-install-hook:
 	mv $(DESTDIR)$(macosdir)/XDarwinApp $(DESTDIR)$(macosdir)/XDarwin
+	cd apple && xcodebuild install
 
 EXTRA_DIST = \
 	darwin.c \
diff --git a/hw/darwin/quartz/quartzStartup.c b/hw/darwin/quartz/quartzStartup.c
index 38fde3c..ae156f8 100644
--- a/hw/darwin/quartz/quartzStartup.c
+++ b/hw/darwin/quartz/quartzStartup.c
@@ -38,11 +38,22 @@
 #include "opaque.h"
 #include "micmap.h"
 #include <assert.h>
-int NSApplicationMain(int argc, char *argv[]);
 
 char **envpGlobal;      // argcGlobal and argvGlobal
                         // are from dix/globals.c
 
+#ifdef INX11APP
+void X11ControllerMain(int argc, char *argv[], void (*server_thread) (void *), void *server_arg);
+void GlxExtensionInit(void);
+void GlxWrapInitVisuals(miInitVisualsProcPtr *);
+
+static void server_thread (void *arg) {
+  extern int main (int argc, char **argv, char **envp);
+  exit (main (argcGlobal, argvGlobal, envpGlobal));
+}
+#else
+int NSApplicationMain(int argc, char *argv[]);
+
 // GLX bundle function pointers
 typedef void (*GlxExtensionInitPtr)(void); 
 static GlxExtensionInitPtr GlxExtensionInit = NULL;
@@ -55,6 +66,7 @@ typedef Bool (*QuartzModeBundleInitPtr)(
 void * __DarwinglXMesaProvider = NULL;
 typedef void (*GlxPushProviderPtr)(void *);
 GlxPushProviderPtr GlxPushProvider = NULL;
+#endif
 
 /*
  * DarwinHandleGUI
@@ -74,7 +86,9 @@ void DarwinHandleGUI(
     int         fd[2];
 
     if (been_here) {
+#ifdef INXDARWINAPP
         QuartzReadPreferences();
+#endif
         return;
     }
     been_here = TRUE;
@@ -109,11 +123,27 @@ void DarwinHandleGUI(
         }
     }
 
+#ifdef INX11APP
+    /* Initially I ran the X server on the main thread, and received
+       events on the second thread. But now we may be using Carbon,
+       that needs to run on the main thread. (Otherwise, when it's
+       prebound, it will initialize itself on the wrong thread)
+       
+       grr.. but doing that means that if the X thread gets scheduled
+       before the main thread when we're _not_ prebound, things fail,
+       so initialize by hand. */
+    extern void _InitHLTB(void);
+    
+    _InitHLTB();
+    
+    X11ControllerMain(argc, argv, server_thread, NULL);
+#else
     main_exit = NSApplicationMain(argc, argv);
+#endif
     exit(main_exit);
 }
 
-
+#ifndef INX11APP
 /*
  * QuartzLoadDisplayBundle
  *  Try to load the appropriate bundle containing the back end display code.
@@ -239,15 +269,21 @@ static void LoadGlxBundle(void)
     CFRelease(bundleURL);
 }
 
+#else
+
+Bool QuartzLoadDisplayBundle(const char *dpyBundleName)
+{
+      return TRUE;
+  }
+
+#endif
 
-/*
- * DarwinGlxExtensionInit
- *  Initialize the GLX extension.
- */
 void DarwinGlxPushProvider(void *impl)
 {
+#ifndef INX11APP
     if (!GlxExtensionInit)
         LoadGlxBundle();
+#endif
 	
     GlxPushProvider(impl);
 }
@@ -258,9 +294,10 @@ void DarwinGlxPushProvider(void *impl)
  */
 void DarwinGlxExtensionInit(void)
 {
+#ifndef INX11APP
     if (!GlxExtensionInit)
         LoadGlxBundle();
-
+#endif
     GlxExtensionInit();
 }
 
@@ -271,9 +308,10 @@ void DarwinGlxExtensionInit(void)
 void DarwinGlxWrapInitVisuals(
     miInitVisualsProcPtr *procPtr)
 {
+#ifndef INX11APP
     if (!GlxWrapInitVisuals)
         LoadGlxBundle();
-
+#endif
     GlxWrapInitVisuals(procPtr);
 }
 
diff-tree fa06e11f972e2a75c84b2f1586997ffc1239cbd9 (from a16360733ea393ec1fc267e88fc604d9d7534484)
Author: Ben Byer <bbyer at bbyer.apple.com>
Date:   Mon Feb 26 17:06:53 2007 -0800

    added hw/darwin/apple directory, which contains source and data files to build
    a version of the X11.app shipped with Mac OS X, using the X.org server.

diff --git a/hw/darwin/apple/English.lproj/InfoPlist.strings b/hw/darwin/apple/English.lproj/InfoPlist.strings
new file mode 100644
index 0000000..88e1f04
Binary files /dev/null and b/hw/darwin/apple/English.lproj/InfoPlist.strings differ
diff --git a/hw/darwin/apple/English.lproj/main.nib/.svn/entries b/hw/darwin/apple/English.lproj/main.nib/.svn/entries
new file mode 100644
index 0000000..95a15f2
--- /dev/null
+++ b/hw/darwin/apple/English.lproj/main.nib/.svn/entries
@@ -0,0 +1,65 @@
+8
+
+dir
+29110
+svn+ssh://src.apple.com/svn/BSD/X11server/trunk/darwin/apple/English.lproj/main.nib
+svn+ssh://src.apple.com/svn/BSD
+
+
+
+2007-02-03T03:06:20.842932Z
+28761
+bbyer
+
+
+svn:special svn:externals svn:needs-lock
+
+
+
+
+
+
+
+
+
+
+
+e92bca22-270c-0410-9cea-e3f1106b6a1c
+
+info.nib
+file
+
+
+
+
+2007-02-27T01:00:07.000000Z
+456347804c516786b1d1339ce2ef50a2
+2007-02-03T03:06:20.842932Z
+28761
+bbyer
+
+keyedobjects.nib
+file
+
+
+
+
+2007-02-27T01:00:07.000000Z
+eb3010372b09768c846df0d996cfdd8d
+2007-02-03T03:06:20.842932Z
+28761
+bbyer
+has-props
+
+classes.nib
+file
+
+
+
+
+2007-02-27T01:00:07.000000Z
+0ae2660c3afabbd5aa02fc34712c96e6
+2007-02-03T03:06:20.842932Z
+28761
+bbyer
+
diff --git a/hw/darwin/apple/English.lproj/main.nib/.svn/format b/hw/darwin/apple/English.lproj/main.nib/.svn/format
new file mode 100644
index 0000000..45a4fb7
--- /dev/null
+++ b/hw/darwin/apple/English.lproj/main.nib/.svn/format
@@ -0,0 +1 @@
+8
diff --git a/hw/darwin/apple/English.lproj/main.nib/.svn/prop-base/keyedobjects.nib.svn-base b/hw/darwin/apple/English.lproj/main.nib/.svn/prop-base/keyedobjects.nib.svn-base
new file mode 100644
index 0000000..5e9587e
--- /dev/null
+++ b/hw/darwin/apple/English.lproj/main.nib/.svn/prop-base/keyedobjects.nib.svn-base
@@ -0,0 +1,5 @@
+K 13
+svn:mime-type
+V 24
+application/octet-stream
+END
diff --git a/hw/darwin/apple/English.lproj/main.nib/.svn/text-base/classes.nib.svn-base b/hw/darwin/apple/English.lproj/main.nib/.svn/text-base/classes.nib.svn-base
new file mode 100644
index 0000000..a82159b
--- /dev/null
+++ b/hw/darwin/apple/English.lproj/main.nib/.svn/text-base/classes.nib.svn-base
@@ -0,0 +1,318 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+	<key>IBClasses</key>
+	<array>
+		<dict>
+			<key>CLASS</key>
+			<string>IBLibraryObjectTemplate</string>
+			<key>LANGUAGE</key>
+			<string>ObjC</string>
+			<key>OUTLETS</key>
+			<dict>
+				<key>draggedView</key>
+				<string>NSView</string>
+				<key>representedObject</key>
+				<string>NSObject</string>
+			</dict>
+			<key>SUPERCLASS</key>
+			<string>NSView</string>
+		</dict>
+		<dict>
+			<key>CLASS</key>
+			<string>IBInspector</string>
+			<key>LANGUAGE</key>
+			<string>ObjC</string>
+			<key>OUTLETS</key>
+			<dict>
+				<key>inspectorView</key>
+				<string>NSView</string>
+			</dict>
+			<key>SUPERCLASS</key>
+			<string>NSObject</string>
+		</dict>
+		<dict>
+			<key>CLASS</key>
+			<string>NSDateFormatter</string>
+			<key>LANGUAGE</key>
+			<string>ObjC</string>
+			<key>SUPERCLASS</key>
+			<string>NSFormatter</string>
+		</dict>
+		<dict>
+			<key>ACTIONS</key>
+			<dict>
+				<key>apps_table_cancel</key>
+				<string>id</string>
+				<key>apps_table_delete</key>
+				<string>id</string>
+				<key>apps_table_done</key>
+				<string>id</string>
+				<key>apps_table_duplicate</key>
+				<string>id</string>
+				<key>apps_table_new</key>
+				<string>id</string>
+				<key>apps_table_show</key>
+				<string>id</string>
+				<key>bring_to_front</key>
+				<string>id</string>
+				<key>close_window</key>
+				<string>id</string>
+				<key>enable_fullscreen_changed</key>
+				<string>id</string>
+				<key>minimize_window</key>
+				<string>id</string>
+				<key>next_window</key>
+				<string>id</string>
+				<key>prefs_changed</key>
+				<string>id</string>
+				<key>prefs_show</key>
+				<string>id</string>
+				<key>previous_window</key>
+				<string>id</string>
+				<key>toggle_fullscreen</key>
+				<string>id</string>
+				<key>x11_help</key>
+				<string>id</string>
+				<key>zoom_window</key>
+				<string>id</string>
+			</dict>
+			<key>CLASS</key>
+			<string>X11Controller</string>
+			<key>LANGUAGE</key>
+			<string>ObjC</string>
+			<key>OUTLETS</key>
+			<dict>
+				<key>apps_separator</key>
+				<string>id</string>
+				<key>apps_table</key>
+				<string>id</string>
+				<key>depth</key>
+				<string>id</string>
+				<key>dock_apps_menu</key>
+				<string>id</string>
+				<key>dock_menu</key>
+				<string>id</string>
+				<key>dock_window_separator</key>
+				<string>id</string>
+				<key>enable_auth</key>
+				<string>id</string>
+				<key>enable_fullscreen</key>
+				<string>id</string>
+				<key>enable_keyequivs</key>
+				<string>id</string>
+				<key>enable_tcp</key>
+				<string>id</string>
+				<key>fake_buttons</key>
+				<string>id</string>
+				<key>prefs_panel</key>
+				<string>id</string>
+				<key>sync_keymap</key>
+				<string>id</string>
+				<key>toggle_fullscreen_item</key>
+				<string>id</string>
+				<key>use_sysbeep</key>
+				<string>id</string>
+				<key>window_separator</key>
+				<string>id</string>
+				<key>x11_about_item</key>
+				<string>id</string>
+			</dict>
+			<key>SUPERCLASS</key>
+			<string>NSObject</string>
+		</dict>
+		<dict>
+			<key>CLASS</key>
+			<string>NSNumberFormatter</string>
+			<key>LANGUAGE</key>
+			<string>ObjC</string>
+			<key>SUPERCLASS</key>
+			<string>NSFormatter</string>
+		</dict>
+		<dict>
+			<key>CLASS</key>
+			<string>NSFormatter</string>
+			<key>LANGUAGE</key>
+			<string>ObjC</string>
+			<key>SUPERCLASS</key>
+			<string>NSObject</string>
+		</dict>
+		<dict>
+			<key>ACTIONS</key>
+			<dict>
+				<key>alignCenter:</key>
+				<string>id</string>
+				<key>alignJustified:</key>
+				<string>id</string>
+				<key>alignLeft:</key>
+				<string>id</string>
+				<key>alignRight:</key>
+				<string>id</string>
+				<key>arrangeInFront:</key>
+				<string>id</string>
+				<key>centerSelectionInVisibleArea:</key>
+				<string>id</string>
+				<key>changeFont:</key>
+				<string>id</string>
+				<key>checkSpelling:</key>
+				<string>id</string>
+				<key>clear:</key>
+				<string>id</string>
+				<key>clearRecentDocuments:</key>
+				<string>id</string>
+				<key>complete:</key>
+				<string>id</string>
+				<key>copy:</key>
+				<string>id</string>
+				<key>copyFont:</key>
+				<string>id</string>
+				<key>copyRuler:</key>
+				<string>id</string>
+				<key>cut:</key>
+				<string>id</string>
+				<key>delete:</key>
+				<string>id</string>
+				<key>deminiaturize:</key>
+				<string>id</string>
+				<key>fax:</key>
+				<string>id</string>
+				<key>hide:</key>
+				<string>id</string>
+				<key>hideOtherApplications:</key>
+				<string>id</string>
+				<key>loosenKerning:</key>
+				<string>id</string>
+				<key>lowerBaseline:</key>
+				<string>id</string>
+				<key>makeKeyAndOrderFront:</key>
+				<string>id</string>
+				<key>miniaturize:</key>
+				<string>id</string>
+				<key>newDocument:</key>
+				<string>id</string>
+				<key>openDocument:</key>
+				<string>id</string>
+				<key>orderBack:</key>
+				<string>id</string>
+				<key>orderFront:</key>
+				<string>id</string>
+				<key>orderFrontColorPanel:</key>
+				<string>id</string>
+				<key>orderFrontHelpPanel:</key>
+				<string>id</string>
+				<key>orderOut:</key>
+				<string>id</string>
+				<key>outline:</key>
+				<string>id</string>
+				<key>paste:</key>
+				<string>id</string>
+				<key>pasteAsPlainText:</key>
+				<string>id</string>
+				<key>pasteAsRichText:</key>
+				<string>id</string>
+				<key>pasteFont:</key>
+				<string>id</string>
+				<key>pasteRuler:</key>
+				<string>id</string>
+				<key>pause:</key>
+				<string>id</string>
+				<key>performClose:</key>
+				<string>id</string>
+				<key>performFindPanelAction:</key>
+				<string>id</string>
+				<key>performMiniaturize:</key>
+				<string>id</string>
+				<key>performZoom:</key>
+				<string>id</string>
+				<key>play:</key>
+				<string>id</string>
+				<key>print:</key>
+				<string>id</string>
+				<key>printDocument:</key>
+				<string>id</string>
+				<key>raiseBaseline:</key>
+				<string>id</string>
+				<key>record:</key>
+				<string>id</string>
+				<key>redo:</key>
+				<string>id</string>
+				<key>resume:</key>
+				<string>id</string>
+				<key>revertDocumentToSaved:</key>
+				<string>id</string>
+				<key>run:</key>
+				<string>id</string>
+				<key>runPageLayout:</key>
+				<string>id</string>
+				<key>runToolbarCustomizationPalette:</key>
+				<string>id</string>
+				<key>saveAllDocuments:</key>
+				<string>id</string>
+				<key>saveDocument:</key>
+				<string>id</string>
+				<key>saveDocumentAs:</key>
+				<string>id</string>
+				<key>saveDocumentTo:</key>
+				<string>id</string>
+				<key>selectAll:</key>
+				<string>id</string>
+				<key>selectText:</key>
+				<string>id</string>
+				<key>showGuessPanel:</key>
+				<string>id</string>
+				<key>showHelp:</key>
+				<string>id</string>
+				<key>start:</key>
+				<string>id</string>
+				<key>startSpeaking:</key>
+				<string>id</string>
+				<key>stop:</key>
+				<string>id</string>
+				<key>stopSpeaking:</key>
+				<string>id</string>
+				<key>subscript:</key>
+				<string>id</string>
+				<key>superscript:</key>
+				<string>id</string>
+				<key>terminate:</key>
+				<string>id</string>
+				<key>tightenKerning:</key>
+				<string>id</string>
+				<key>toggleContinuousSpellChecking:</key>
+				<string>id</string>
+				<key>toggleRuler:</key>
+				<string>id</string>
+				<key>toggleToolbarShown:</key>
+				<string>id</string>
+				<key>turnOffKerning:</key>
+				<string>id</string>
+				<key>turnOffLigatures:</key>
+				<string>id</string>
+				<key>underline:</key>
+				<string>id</string>
+				<key>undo:</key>
+				<string>id</string>
+				<key>unhideAllApplications:</key>
+				<string>id</string>
+				<key>unscript:</key>
+				<string>id</string>
+				<key>useAllLigatures:</key>
+				<string>id</string>
+				<key>useStandardKerning:</key>
+				<string>id</string>
+				<key>useStandardLigatures:</key>
+				<string>id</string>
+			</dict>
+			<key>CLASS</key>
+			<string>FirstResponder</string>
+			<key>LANGUAGE</key>
+			<string>ObjC</string>
+			<key>SUPERCLASS</key>
+			<string>NSObject</string>
+		</dict>
+	</array>
+	<key>IBVersion</key>
+	<integer>1</integer>
+</dict>
+</plist>
diff --git a/hw/darwin/apple/English.lproj/main.nib/.svn/text-base/info.nib.svn-base b/hw/darwin/apple/English.lproj/main.nib/.svn/text-base/info.nib.svn-base
new file mode 100644
index 0000000..88bc626
--- /dev/null
+++ b/hw/darwin/apple/English.lproj/main.nib/.svn/text-base/info.nib.svn-base
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+	<key>IBFramework Version</key>
+	<string>588</string>
+	<key>IBOpenObjects</key>
+	<array>
+		<integer>244</integer>
+		<integer>29</integer>
+		<integer>423</integer>
+	</array>
+	<key>IBSystem Version</key>
+	<string>9A356</string>
+	<key>targetFramework</key>
+	<string>IBCocoaFramework</string>
+</dict>
+</plist>
diff --git a/hw/darwin/apple/English.lproj/main.nib/.svn/text-base/keyedobjects.nib.svn-base b/hw/darwin/apple/English.lproj/main.nib/.svn/text-base/keyedobjects.nib.svn-base
new file mode 100644
index 0000000..8b31450
Binary files /dev/null and b/hw/darwin/apple/English.lproj/main.nib/.svn/text-base/keyedobjects.nib.svn-base differ
diff --git a/hw/darwin/apple/English.lproj/main.nib/classes.nib b/hw/darwin/apple/English.lproj/main.nib/classes.nib
new file mode 100644
index 0000000..a82159b
--- /dev/null
+++ b/hw/darwin/apple/English.lproj/main.nib/classes.nib
@@ -0,0 +1,318 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+	<key>IBClasses</key>
+	<array>
+		<dict>
+			<key>CLASS</key>
+			<string>IBLibraryObjectTemplate</string>
+			<key>LANGUAGE</key>
+			<string>ObjC</string>
+			<key>OUTLETS</key>
+			<dict>
+				<key>draggedView</key>
+				<string>NSView</string>
+				<key>representedObject</key>
+				<string>NSObject</string>
+			</dict>
+			<key>SUPERCLASS</key>
+			<string>NSView</string>
+		</dict>
+		<dict>
+			<key>CLASS</key>
+			<string>IBInspector</string>
+			<key>LANGUAGE</key>
+			<string>ObjC</string>
+			<key>OUTLETS</key>
+			<dict>
+				<key>inspectorView</key>
+				<string>NSView</string>
+			</dict>
+			<key>SUPERCLASS</key>
+			<string>NSObject</string>
+		</dict>
+		<dict>
+			<key>CLASS</key>
+			<string>NSDateFormatter</string>
+			<key>LANGUAGE</key>
+			<string>ObjC</string>
+			<key>SUPERCLASS</key>
+			<string>NSFormatter</string>
+		</dict>
+		<dict>
+			<key>ACTIONS</key>
+			<dict>
+				<key>apps_table_cancel</key>
+				<string>id</string>
+				<key>apps_table_delete</key>
+				<string>id</string>
+				<key>apps_table_done</key>
+				<string>id</string>
+				<key>apps_table_duplicate</key>
+				<string>id</string>
+				<key>apps_table_new</key>
+				<string>id</string>
+				<key>apps_table_show</key>
+				<string>id</string>
+				<key>bring_to_front</key>
+				<string>id</string>
+				<key>close_window</key>
+				<string>id</string>
+				<key>enable_fullscreen_changed</key>
+				<string>id</string>
+				<key>minimize_window</key>
+				<string>id</string>
+				<key>next_window</key>
+				<string>id</string>
+				<key>prefs_changed</key>
+				<string>id</string>
+				<key>prefs_show</key>
+				<string>id</string>
+				<key>previous_window</key>
+				<string>id</string>
+				<key>toggle_fullscreen</key>
+				<string>id</string>
+				<key>x11_help</key>
+				<string>id</string>
+				<key>zoom_window</key>
+				<string>id</string>
+			</dict>
+			<key>CLASS</key>
+			<string>X11Controller</string>
+			<key>LANGUAGE</key>
+			<string>ObjC</string>
+			<key>OUTLETS</key>
+			<dict>
+				<key>apps_separator</key>
+				<string>id</string>
+				<key>apps_table</key>
+				<string>id</string>
+				<key>depth</key>
+				<string>id</string>
+				<key>dock_apps_menu</key>
+				<string>id</string>
+				<key>dock_menu</key>
+				<string>id</string>
+				<key>dock_window_separator</key>
+				<string>id</string>
+				<key>enable_auth</key>
+				<string>id</string>
+				<key>enable_fullscreen</key>
+				<string>id</string>
+				<key>enable_keyequivs</key>
+				<string>id</string>
+				<key>enable_tcp</key>
+				<string>id</string>
+				<key>fake_buttons</key>
+				<string>id</string>
+				<key>prefs_panel</key>
+				<string>id</string>
+				<key>sync_keymap</key>
+				<string>id</string>
+				<key>toggle_fullscreen_item</key>
+				<string>id</string>
+				<key>use_sysbeep</key>
+				<string>id</string>
+				<key>window_separator</key>
+				<string>id</string>
+				<key>x11_about_item</key>
+				<string>id</string>
+			</dict>
+			<key>SUPERCLASS</key>
+			<string>NSObject</string>
+		</dict>
+		<dict>
+			<key>CLASS</key>
+			<string>NSNumberFormatter</string>
+			<key>LANGUAGE</key>
+			<string>ObjC</string>
+			<key>SUPERCLASS</key>
+			<string>NSFormatter</string>
+		</dict>
+		<dict>
+			<key>CLASS</key>
+			<string>NSFormatter</string>
+			<key>LANGUAGE</key>
+			<string>ObjC</string>
+			<key>SUPERCLASS</key>
+			<string>NSObject</string>
+		</dict>
+		<dict>
+			<key>ACTIONS</key>
+			<dict>
+				<key>alignCenter:</key>
+				<string>id</string>
+				<key>alignJustified:</key>
+				<string>id</string>
+				<key>alignLeft:</key>
+				<string>id</string>
+				<key>alignRight:</key>
+				<string>id</string>
+				<key>arrangeInFront:</key>
+				<string>id</string>
+				<key>centerSelectionInVisibleArea:</key>
+				<string>id</string>
+				<key>changeFont:</key>
+				<string>id</string>
+				<key>checkSpelling:</key>
+				<string>id</string>
+				<key>clear:</key>
+				<string>id</string>
+				<key>clearRecentDocuments:</key>
+				<string>id</string>
+				<key>complete:</key>
+				<string>id</string>
+				<key>copy:</key>
+				<string>id</string>
+				<key>copyFont:</key>
+				<string>id</string>
+				<key>copyRuler:</key>
+				<string>id</string>
+				<key>cut:</key>
+				<string>id</string>
+				<key>delete:</key>
+				<string>id</string>
+				<key>deminiaturize:</key>
+				<string>id</string>
+				<key>fax:</key>
+				<string>id</string>
+				<key>hide:</key>
+				<string>id</string>
+				<key>hideOtherApplications:</key>
+				<string>id</string>
+				<key>loosenKerning:</key>
+				<string>id</string>
+				<key>lowerBaseline:</key>
+				<string>id</string>
+				<key>makeKeyAndOrderFront:</key>
+				<string>id</string>
+				<key>miniaturize:</key>
+				<string>id</string>
+				<key>newDocument:</key>
+				<string>id</string>
+				<key>openDocument:</key>
+				<string>id</string>
+				<key>orderBack:</key>
+				<string>id</string>
+				<key>orderFront:</key>
+				<string>id</string>
+				<key>orderFrontColorPanel:</key>
+				<string>id</string>
+				<key>orderFrontHelpPanel:</key>
+				<string>id</string>
+				<key>orderOut:</key>
+				<string>id</string>
+				<key>outline:</key>
+				<string>id</string>
+				<key>paste:</key>
+				<string>id</string>
+				<key>pasteAsPlainText:</key>
+				<string>id</string>
+				<key>pasteAsRichText:</key>
+				<string>id</string>
+				<key>pasteFont:</key>
+				<string>id</string>
+				<key>pasteRuler:</key>
+				<string>id</string>
+				<key>pause:</key>
+				<string>id</string>
+				<key>performClose:</key>
+				<string>id</string>
+				<key>performFindPanelAction:</key>
+				<string>id</string>
+				<key>performMiniaturize:</key>
+				<string>id</string>
+				<key>performZoom:</key>
+				<string>id</string>
+				<key>play:</key>
+				<string>id</string>
+				<key>print:</key>
+				<string>id</string>
+				<key>printDocument:</key>
+				<string>id</string>
+				<key>raiseBaseline:</key>
+				<string>id</string>
+				<key>record:</key>
+				<string>id</string>
+				<key>redo:</key>
+				<string>id</string>
+				<key>resume:</key>
+				<string>id</string>
+				<key>revertDocumentToSaved:</key>
+				<string>id</string>
+				<key>run:</key>
+				<string>id</string>
+				<key>runPageLayout:</key>
+				<string>id</string>
+				<key>runToolbarCustomizationPalette:</key>
+				<string>id</string>
+				<key>saveAllDocuments:</key>
+				<string>id</string>
+				<key>saveDocument:</key>
+				<string>id</string>
+				<key>saveDocumentAs:</key>
+				<string>id</string>
+				<key>saveDocumentTo:</key>
+				<string>id</string>
+				<key>selectAll:</key>
+				<string>id</string>
+				<key>selectText:</key>
+				<string>id</string>
+				<key>showGuessPanel:</key>
+				<string>id</string>
+				<key>showHelp:</key>
+				<string>id</string>
+				<key>start:</key>
+				<string>id</string>
+				<key>startSpeaking:</key>
+				<string>id</string>
+				<key>stop:</key>
+				<string>id</string>
+				<key>stopSpeaking:</key>
+				<string>id</string>
+				<key>subscript:</key>
+				<string>id</string>
+				<key>superscript:</key>
+				<string>id</string>
+				<key>terminate:</key>
+				<string>id</string>
+				<key>tightenKerning:</key>
+				<string>id</string>
+				<key>toggleContinuousSpellChecking:</key>
+				<string>id</string>
+				<key>toggleRuler:</key>
+				<string>id</string>
+				<key>toggleToolbarShown:</key>
+				<string>id</string>
+				<key>turnOffKerning:</key>
+				<string>id</string>
+				<key>turnOffLigatures:</key>
+				<string>id</string>
+				<key>underline:</key>
+				<string>id</string>
+				<key>undo:</key>
+				<string>id</string>
+				<key>unhideAllApplications:</key>
+				<string>id</string>
+				<key>unscript:</key>
+				<string>id</string>
+				<key>useAllLigatures:</key>
+				<string>id</string>
+				<key>useStandardKerning:</key>
+				<string>id</string>
+				<key>useStandardLigatures:</key>
+				<string>id</string>
+			</dict>
+			<key>CLASS</key>
+			<string>FirstResponder</string>
+			<key>LANGUAGE</key>
+			<string>ObjC</string>
+			<key>SUPERCLASS</key>
+			<string>NSObject</string>
+		</dict>
+	</array>
+	<key>IBVersion</key>
+	<integer>1</integer>
+</dict>
+</plist>
diff --git a/hw/darwin/apple/English.lproj/main.nib/info.nib b/hw/darwin/apple/English.lproj/main.nib/info.nib
new file mode 100644
index 0000000..88bc626
--- /dev/null
+++ b/hw/darwin/apple/English.lproj/main.nib/info.nib
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+	<key>IBFramework Version</key>
+	<string>588</string>
+	<key>IBOpenObjects</key>
+	<array>
+		<integer>244</integer>
+		<integer>29</integer>
+		<integer>423</integer>
+	</array>
+	<key>IBSystem Version</key>
+	<string>9A356</string>
+	<key>targetFramework</key>
+	<string>IBCocoaFramework</string>
+</dict>
+</plist>
diff --git a/hw/darwin/apple/English.lproj/main.nib/keyedobjects.nib b/hw/darwin/apple/English.lproj/main.nib/keyedobjects.nib
new file mode 100644
index 0000000..8b31450
Binary files /dev/null and b/hw/darwin/apple/English.lproj/main.nib/keyedobjects.nib differ
diff --git a/hw/darwin/apple/Info.plist b/hw/darwin/apple/Info.plist
new file mode 100644
index 0000000..ae47e95
--- /dev/null
+++ b/hw/darwin/apple/Info.plist
@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+	<key>CFBundleDevelopmentRegion</key>
+	<string>English</string>
+	<key>CFBundleDocumentTypes</key>
+	<array>
+		<dict>
+			<key>CFBundleTypeExtensions</key>
+			<array>
+				<string>x11app</string>
+			</array>
+			<key>CFBundleTypeIconFile</key>
+			<string>X11.icns</string>
+			<key>CFBundleTypeName</key>
+			<string>X11 Application</string>
+			<key>CFBundleTypeOSTypes</key>
+			<array>
+				<string>****</string>
+			</array>
+			<key>CFBundleTypeRole</key>
+			<string>Viewer</string>
+			<key>LSIsAppleDefaultForType</key>
+			<true/>
+		</dict>
+		<dict>
+			<key>CFBundleTypeExtensions</key>
+			<array>
+				<string>tool</string>
+				<string>*</string>
+			</array>
+			<key>CFBundleTypeName</key>
+			<string>UNIX Application</string>
+			<key>CFBundleTypeOSTypes</key>
+			<array>
+				<string>****</string>
+			</array>
+			<key>CFBundleTypeRole</key>
+			<string>Viewer</string>
+		</dict>
+	</array>
+	<key>CFBundleExecutable</key>
+	<string>X11</string>
+	<key>CFBundleGetInfoString</key>
+	<string>X11</string>
+	<key>CFBundleIconFile</key>
+	<string>X11.icns</string>
+	<key>CFBundleIdentifier</key>
+	<string>org.x.X11</string>
+	<key>CFBundleInfoDictionaryVersion</key>
+	<string>6.0</string>
+	<key>CFBundleName</key>
+	<string>X11</string>
+	<key>CFBundlePackageType</key>
+	<string>APPL</string>
+	<key>CFBundleShortVersionString</key>
+	<string>2.0</string>
+	<key>CFBundleSignature</key>
+	<string>????</string>
+	<key>CSResourcesFileMapped</key>
+	<true/>
+	<key>NSHumanReadableCopyright</key>
+	<string>Copyright © 2003-2007, Apple Inc.
+Copyright © 2003, XFree86 Project, Inc.</string>
+	<key>NSMainNibFile</key>
+	<string>main</string>
+	<key>NSPrincipalClass</key>
+	<string>X11Application</string>
+</dict>
+</plist>
diff --git a/hw/darwin/apple/X11.icns b/hw/darwin/apple/X11.icns
new file mode 100644
index 0000000..4c47177
Binary files /dev/null and b/hw/darwin/apple/X11.icns differ
diff --git a/hw/darwin/apple/X11.xcodeproj/project.pbxproj b/hw/darwin/apple/X11.xcodeproj/project.pbxproj
new file mode 100644
index 0000000..7ca75d4
--- /dev/null
+++ b/hw/darwin/apple/X11.xcodeproj/project.pbxproj
@@ -0,0 +1,329 @@
+// !$*UTF8*$!
+{
+	archiveVersion = 1;
+	classes = {
+	};
+	objectVersion = 42;
+	objects = {
+
+/* Begin PBXBuildFile section */
+		527F24190B5D938C007840A7 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 0867D6AAFE840B52C02AAC07 /* InfoPlist.strings */; };
+		527F241A0B5D938C007840A7 /* main.nib in Resources */ = {isa = PBXBuildFile; fileRef = 02345980000FD03B11CA0E72 /* main.nib */; };
+		527F241B0B5D938C007840A7 /* X11.icns in Resources */ = {isa = PBXBuildFile; fileRef = 50459C5F038587C60ECA21EC /* X11.icns */; };
+		527F241D0B5D938C007840A7 /* bundle-main.c in Sources */ = {isa = PBXBuildFile; fileRef = 50EE2AB703849F0B0ECA21EC /* bundle-main.c */; };
+		527F241F0B5D938C007840A7 /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 50F4F0A7039D6ACA0E82C0CB /* CoreFoundation.framework */; };
+		527F24200B5D938C007840A7 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 570C5748047186C400ACF82F /* SystemConfiguration.framework */; };
+		527F24370B5D9D89007840A7 /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 527F24260B5D938C007840A7 /* Info.plist */; };
+/* End PBXBuildFile section */
+
+/* Begin PBXFileReference section */
+		0867D6ABFE840B52C02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = "<group>"; };
+		1870340FFE93FCAF11CA0CD7 /* English */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = English; path = English.lproj/main.nib; sourceTree = "<group>"; };
+		50459C5F038587C60ECA21EC /* X11.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = X11.icns; sourceTree = "<group>"; };
+		50EE2AB703849F0B0ECA21EC /* bundle-main.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; path = "bundle-main.c"; sourceTree = "<group>"; };
+		50F4F0A7039D6ACA0E82C0CB /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = /System/Library/Frameworks/CoreFoundation.framework; sourceTree = "<absolute>"; };
+		527F24260B5D938C007840A7 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = Info.plist; sourceTree = "<group>"; };
+		527F24270B5D938C007840A7 /* X11.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = X11.app; sourceTree = BUILT_PRODUCTS_DIR; };
+		570C5748047186C400ACF82F /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = /System/Library/Frameworks/SystemConfiguration.framework; sourceTree = "<absolute>"; };
+/* End PBXFileReference section */
+
+/* Begin PBXFrameworksBuildPhase section */
+		527F241E0B5D938C007840A7 /* Frameworks */ = {
+			isa = PBXFrameworksBuildPhase;
+			buildActionMask = 2147483647;
+			files = (
+				527F241F0B5D938C007840A7 /* CoreFoundation.framework in Frameworks */,
+				527F24200B5D938C007840A7 /* SystemConfiguration.framework in Frameworks */,
+			);
+			runOnlyForDeploymentPostprocessing = 0;
+		};
+/* End PBXFrameworksBuildPhase section */
+
+/* Begin PBXGroup section */
+		195DF8CFFE9D517E11CA2CBB /* Products */ = {
+			isa = PBXGroup;
+			children = (
+				527F24270B5D938C007840A7 /* X11.app */,
+			);
+			name = Products;
+			sourceTree = "<group>";
+		};
+		20286C29FDCF999611CA2CEA /* X11 */ = {
+			isa = PBXGroup;
+			children = (
+				20286C2AFDCF999611CA2CEA /* Sources */,
+				20286C2CFDCF999611CA2CEA /* Resources */,
+				20286C32FDCF999611CA2CEA /* External Frameworks and Libraries */,
+				195DF8CFFE9D517E11CA2CBB /* Products */,
+				527F24260B5D938C007840A7 /* Info.plist */,
+			);
+			name = X11;
+			sourceTree = "<group>";
+		};
+		20286C2AFDCF999611CA2CEA /* Sources */ = {
+			isa = PBXGroup;
+			children = (
+				50EE2AB703849F0B0ECA21EC /* bundle-main.c */,
+			);
+			name = Sources;
+			sourceTree = "<group>";
+		};
+		20286C2CFDCF999611CA2CEA /* Resources */ = {
+			isa = PBXGroup;
+			children = (
+				50459C5F038587C60ECA21EC /* X11.icns */,
+				0867D6AAFE840B52C02AAC07 /* InfoPlist.strings */,
+				02345980000FD03B11CA0E72 /* main.nib */,
+			);
+			name = Resources;
+			sourceTree = "<group>";
+		};
+		20286C32FDCF999611CA2CEA /* External Frameworks and Libraries */ = {
+			isa = PBXGroup;
+			children = (
+				50F4F0A7039D6ACA0E82C0CB /* CoreFoundation.framework */,
+				570C5748047186C400ACF82F /* SystemConfiguration.framework */,
+			);
+			name = "External Frameworks and Libraries";
+			sourceTree = "<group>";
+		};
+/* End PBXGroup section */
+
+/* Begin PBXHeadersBuildPhase section */
+		527F24170B5D938C007840A7 /* Headers */ = {
+			isa = PBXHeadersBuildPhase;
+			buildActionMask = 2147483647;
+			files = (
+			);
+			runOnlyForDeploymentPostprocessing = 0;
+		};
+/* End PBXHeadersBuildPhase section */
+
+/* Begin PBXNativeTarget section */
+		527F24160B5D938C007840A7 /* X11 */ = {
+			isa = PBXNativeTarget;
+			buildConfigurationList = 527F24220B5D938C007840A7 /* Build configuration list for PBXNativeTarget "X11" */;
+			buildPhases = (
+				527F24170B5D938C007840A7 /* Headers */,
+				527F24180B5D938C007840A7 /* Resources */,
+				527F241C0B5D938C007840A7 /* Sources */,
+				527F241E0B5D938C007840A7 /* Frameworks */,
+				527F24210B5D938C007840A7 /* Rez */,
+			);
+			buildRules = (
+			);
+			dependencies = (
+			);
+			name = X11;
+			productName = X11;
+			productReference = 527F24270B5D938C007840A7 /* X11.app */;
+			productType = "com.apple.product-type.application";
+		};
+/* End PBXNativeTarget section */
+
+/* Begin PBXProject section */
+		20286C28FDCF999611CA2CEA /* Project object */ = {
+			isa = PBXProject;
+			buildConfigurationList = 527F24080B5D8FFC007840A7 /* Build configuration list for PBXProject "X11" */;
+			compatibilityVersion = "Xcode 2.4";
+			hasScannedForEncodings = 1;
+			mainGroup = 20286C29FDCF999611CA2CEA /* X11 */;
+			projectDirPath = "";
+			projectRoot = "";
+			shouldCheckCompatibility = 1;
+			targets = (
+				527F24160B5D938C007840A7 /* X11 */,
+			);
+		};
+/* End PBXProject section */
+
+/* Begin PBXResourcesBuildPhase section */
+		527F24180B5D938C007840A7 /* Resources */ = {
+			isa = PBXResourcesBuildPhase;
+			buildActionMask = 2147483647;
+			files = (
+				527F24370B5D9D89007840A7 /* Info.plist in Resources */,
+				527F24190B5D938C007840A7 /* InfoPlist.strings in Resources */,
+				527F241A0B5D938C007840A7 /* main.nib in Resources */,
+				527F241B0B5D938C007840A7 /* X11.icns in Resources */,
+			);
+			runOnlyForDeploymentPostprocessing = 0;
+		};
+/* End PBXResourcesBuildPhase section */
+
+/* Begin PBXRezBuildPhase section */
+		527F24210B5D938C007840A7 /* Rez */ = {
+			isa = PBXRezBuildPhase;
+			buildActionMask = 2147483647;
+			files = (
+			);
+			runOnlyForDeploymentPostprocessing = 0;
+		};
+/* End PBXRezBuildPhase section */
+
+/* Begin PBXSourcesBuildPhase section */
+		527F241C0B5D938C007840A7 /* Sources */ = {
+			isa = PBXSourcesBuildPhase;
+			buildActionMask = 2147483647;
+			files = (
+				527F241D0B5D938C007840A7 /* bundle-main.c in Sources */,
+			);
+			runOnlyForDeploymentPostprocessing = 0;
+		};
+/* End PBXSourcesBuildPhase section */
+
+/* Begin PBXVariantGroup section */
+		02345980000FD03B11CA0E72 /* main.nib */ = {
+			isa = PBXVariantGroup;
+			children = (
+				1870340FFE93FCAF11CA0CD7 /* English */,
+			);
+			name = main.nib;
+			sourceTree = "<group>";
+		};
+		0867D6AAFE840B52C02AAC07 /* InfoPlist.strings */ = {
+			isa = PBXVariantGroup;
+			children = (
+				0867D6ABFE840B52C02AAC07 /* English */,
+			);
+			name = InfoPlist.strings;
+			sourceTree = "<group>";
+		};
+/* End PBXVariantGroup section */
+
+/* Begin XCBuildConfiguration section */
+		527F24090B5D8FFC007840A7 /* Development */ = {
+			isa = XCBuildConfiguration;
+			buildSettings = {
+				DSTROOT = "$(DSTROOT)";
+				SKIP_INSTALL = YES;
+			};
+			name = Development;
+		};
+		527F240A0B5D8FFC007840A7 /* Deployment */ = {
+			isa = XCBuildConfiguration;
+			buildSettings = {
+				DSTROOT = "$(DSTROOT)";
+				SKIP_INSTALL = YES;
+			};
+			name = Deployment;
+		};
+		527F240B0B5D8FFC007840A7 /* Default */ = {
+			isa = XCBuildConfiguration;
+			buildSettings = {
+				DSTROOT = "$(DSTROOT)";
+				SKIP_INSTALL = YES;
+			};
+			name = Default;
+		};
+		527F24230B5D938C007840A7 /* Development */ = {
+			isa = XCBuildConfiguration;
+			buildSettings = {
+				ARCHS = "$(NATIVE_ARCH_32_BIT)";
+				COPY_PHASE_STRIP = NO;
+				DSTROOT = "$(DSTROOT)";
+				FRAMEWORK_SEARCH_PATHS = "";
+				GCC_SYMBOLS_PRIVATE_EXTERN = NO;
+				HEADER_SEARCH_PATHS = /usr/X11/include;
+				INFOPLIST_FILE = Info.plist;
+				INSTALL_PATH = $DSTROOT/Applications/Utilties;
+				LIBRARY_SEARCH_PATHS = /usr/X11/lib;
+				OTHER_CFLAGS = "";
+				OTHER_LDFLAGS = (
+					"-lXau",
+					"-lX11",
+				);
+				OTHER_REZFLAGS = "";
+				PRODUCT_NAME = X11;
+				SECTORDER_FLAGS = "";
+				WARNING_CFLAGS = (
+					"-Wmost",
+					"-Wno-four-char-constants",
+					"-Wno-unknown-pragmas",
+				);
+				WRAPPER_EXTENSION = app;
+			};
+			name = Development;
+		};
+		527F24240B5D938C007840A7 /* Deployment */ = {
+			isa = XCBuildConfiguration;
+			buildSettings = {
+				COPY_PHASE_STRIP = YES;
+				DSTROOT = "$(DSTROOT)";
+				FRAMEWORK_SEARCH_PATHS = "";
+				GCC_SYMBOLS_PRIVATE_EXTERN = NO;
+				HEADER_SEARCH_PATHS = /usr/X11/include;
+				INFOPLIST_FILE = Info.plist;
+				INSTALL_PATH = $DSTROOT/Applications/Utilties;
+				LIBRARY_SEARCH_PATHS = /usr/X11/lib;
+				OTHER_CFLAGS = "";
+				OTHER_LDFLAGS = (
+					"-lXau",
+					"-lX11",
+				);
+				OTHER_REZFLAGS = "";
+				PRODUCT_NAME = X11;
+				SECTORDER_FLAGS = "";
+				WARNING_CFLAGS = (
+					"-Wmost",
+					"-Wno-four-char-constants",
+					"-Wno-unknown-pragmas",
+				);
+				WRAPPER_EXTENSION = app;
+			};
+			name = Deployment;
+		};
+		527F24250B5D938C007840A7 /* Default */ = {
+			isa = XCBuildConfiguration;
+			buildSettings = {
+				DSTROOT = "$(DSTROOT)";
+				FRAMEWORK_SEARCH_PATHS = "";
+				GCC_SYMBOLS_PRIVATE_EXTERN = NO;
+				HEADER_SEARCH_PATHS = /usr/X11/include;
+				INFOPLIST_FILE = Info.plist;
+				INSTALL_PATH = $DSTROOT/Applications/Utilties;
+				LIBRARY_SEARCH_PATHS = /usr/X11/lib;
+				OTHER_CFLAGS = "";
+				OTHER_LDFLAGS = (
+					"-lXau",
+					"-lX11",
+				);
+				OTHER_REZFLAGS = "";
+				PRODUCT_NAME = X11;
+				SECTORDER_FLAGS = "";
+				WARNING_CFLAGS = (
+					"-Wmost",
+					"-Wno-four-char-constants",
+					"-Wno-unknown-pragmas",
+				);
+				WRAPPER_EXTENSION = app;
+			};
+			name = Default;
+		};
+/* End XCBuildConfiguration section */
+
+/* Begin XCConfigurationList section */
+		527F24080B5D8FFC007840A7 /* Build configuration list for PBXProject "X11" */ = {
+			isa = XCConfigurationList;
+			buildConfigurations = (
+				527F24090B5D8FFC007840A7 /* Development */,
+				527F240A0B5D8FFC007840A7 /* Deployment */,
+				527F240B0B5D8FFC007840A7 /* Default */,
+			);
+			defaultConfigurationIsVisible = 0;
+			defaultConfigurationName = Default;
+		};
+		527F24220B5D938C007840A7 /* Build configuration list for PBXNativeTarget "X11" */ = {
+			isa = XCConfigurationList;
+			buildConfigurations = (
+				527F24230B5D938C007840A7 /* Development */,
+				527F24240B5D938C007840A7 /* Deployment */,
+				527F24250B5D938C007840A7 /* Default */,
+			);
+			defaultConfigurationIsVisible = 0;
+			defaultConfigurationName = Default;
+		};
+/* End XCConfigurationList section */
+	};
+	rootObject = 20286C28FDCF999611CA2CEA /* Project object */;
+}
diff --git a/hw/darwin/apple/X11Application.h b/hw/darwin/apple/X11Application.h
new file mode 100644
index 0000000..b9d2af8
--- /dev/null
+++ b/hw/darwin/apple/X11Application.h
@@ -0,0 +1,104 @@
+/* X11Application.h -- subclass of NSApplication to multiplex events
+   $Id: X11Application.h,v 1.26 2003/08/08 19:16:13 jharper Exp $
+
+   Copyright (c) 2002-2007 Apple Inc. All rights reserved.
+
+   Permission is hereby granted, free of charge, to any person
+   obtaining a copy of this software and associated documentation files
+   (the "Software"), to deal in the Software without restriction,
+   including without limitation the rights to use, copy, modify, merge,
+   publish, distribute, sublicense, and/or sell copies of the Software,
+   and to permit persons to whom the Software is furnished to do so,
+   subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be
+   included in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+   NONINFRINGEMENT.  IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT
+   HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+
+   Except as contained in this notice, the name(s) of the above
+   copyright holders shall not be used in advertising or otherwise to
+   promote the sale, use or other dealings in this Software without
+   prior written authorization. */
+
+#ifndef X11APPLICATION_H
+#define X11APPLICATION_H 1
+
+#if __OBJC__
+
+#import <Cocoa/Cocoa.h>
+#import "X11Controller.h"
+
+ at interface X11Application : NSApplication {
+    X11Controller *_controller;
+
+    unsigned int _x_active :1;
+}
+
+- (void) set_controller:controller;
+- (void) set_window_menu:(NSArray *)list;
+
+- (int) prefs_get_integer:(NSString *)key default:(int)def;
+- (const char *) prefs_get_string:(NSString *)key default:(const char *)def;
+- (float) prefs_get_float:(NSString *)key default:(float)def;
+- (int) prefs_get_boolean:(NSString *)key default:(int)def;
+- (NSArray *) prefs_get_array:(NSString *)key;
+- (void) prefs_set_integer:(NSString *)key value:(int)value;
+- (void) prefs_set_float:(NSString *)key value:(float)value;
+- (void) prefs_set_boolean:(NSString *)key value:(int)value;
+- (void) prefs_set_array:(NSString *)key value:(NSArray *)value;
+- (void) prefs_set_string:(NSString *)key value:(NSString *)value;
+- (void) prefs_synchronize;
+
+- (BOOL) x_active;
+
+ at end
+
+extern X11Application *X11App;
+
+#endif /* __OBJC__ */
+
+extern void X11ApplicationSetWindowMenu (int nitems, const char **items,
+					 const char *shortcuts);
+extern void X11ApplicationSetWindowMenuCheck (int idx);
+extern void X11ApplicationSetFrontProcess (void);
+extern void X11ApplicationSetCanQuit (int state);
+extern void X11ApplicationServerReady (void);
+extern void X11ApplicationShowHideMenubar (int state);
+
+extern void X11ApplicationMain (int argc, const char *argv[],
+				void (*server_thread) (void *),
+				void *server_arg);
+
+extern int X11EnableKeyEquivalents;
+extern int quartzHasRoot, quartzEnableRootless;
+
+#define APP_PREFS "com.apple.x11"
+
+#define PREFS_APPSMENU		"apps_menu"
+#define PREFS_FAKEBUTTONS	"enable_fake_buttons"
+#define PREFS_SYSBEEP		"enable_system_beep"
+#define PREFS_KEYEQUIVS		"enable_key_equivalents"
+#define PREFS_KEYMAP_FILE	"keymap_file"
+#define PREFS_SYNC_KEYMAP	"sync_keymap"
+#define PREFS_DEPTH		"depth"
+#define PREFS_NO_AUTH		"no_auth"
+#define PREFS_NO_TCP		"nolisten_tcp"
+#define PREFS_DONE_XINIT_CHECK	"done_xinit_check"
+#define PREFS_NO_QUIT_ALERT	"no_quit_alert"
+#define PREFS_FAKE_BUTTON2	"fake_button2"
+#define PREFS_FAKE_BUTTON3	"fake_button3"
+#define PREFS_ROOTLESS		"rootless"
+#define PREFS_FULLSCREEN_HOTKEYS "fullscreen_hotkeys"
+#define PREFS_SWAP_ALT_META	"swap_alt_meta"
+#define PREFS_XP_OPTIONS	"xp_options"
+#define PREFS_ENABLE_STEREO	"enable_stereo"
+
+#endif /* X11APPLICATION_H */
diff --git a/hw/darwin/apple/X11Application.m b/hw/darwin/apple/X11Application.m
new file mode 100644
index 0000000..5da0574
--- /dev/null
+++ b/hw/darwin/apple/X11Application.m
@@ -0,0 +1,1138 @@
+/* X11Application.m -- subclass of NSApplication to multiplex events
+ $Id: X11Application.m,v 1.59 2006/09/06 21:19:32 jharper Exp $
+ 
+ Copyright (c) 2002-2007 Apple Inc. All rights reserved.
+ 
+ Permission is hereby granted, free of charge, to any person
+ obtaining a copy of this software and associated documentation files
+ (the "Software"), to deal in the Software without restriction,
+ including without limitation the rights to use, copy, modify, merge,
+ publish, distribute, sublicense, and/or sell copies of the Software,
+ and to permit persons to whom the Software is furnished to do so,
+ subject to the following conditions:
+ 
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+ 
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT.  IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT
+ HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ DEALINGS IN THE SOFTWARE.
+ 
+ Except as contained in this notice, the name(s) of the above
+ copyright holders shall not be used in advertising or otherwise to
+ promote the sale, use or other dealings in this Software without
+ prior written authorization. */
+
+#include "../quartz/quartzCommon.h"
+
+#import "X11Application.h"
+#include <Carbon/Carbon.h>
+
+/* ouch! */
+#define BOOL X_BOOL
+//# include "Xproto.h"
+# include "darwin.h"
+# include "../quartz/quartz.h"
+# define _APPLEWM_SERVER_
+# include "X11/extensions/applewm.h"
+//# include "X.h"
+# include "micmap.h"
+#undef BOOL
+
+#include "xf86Version.h"
+
+#include <mach/mach.h>
+#include <unistd.h>
+#include <pthread.h>
+
+#define DEFAULTS_FILE "/etc/X11/xserver/Xquartz.plist"
+
+int X11EnableKeyEquivalents = TRUE;
+int quartzHasRoot = FALSE, quartzEnableRootless = TRUE;
+
+extern int darwinFakeButtons;
+// extern Bool enable_stereo; 
+Bool enable_stereo;  //<-- this needs to go back to being an extern once glxCGL is fixed
+
+
+X11Application *X11App;
+
+#define ALL_KEY_MASKS (NSShiftKeyMask | NSControlKeyMask \
+| NSAlternateKeyMask | NSCommandKeyMask)
+
+ at implementation X11Application
+
+typedef struct message_struct message;
+struct message_struct {
+    mach_msg_header_t hdr;
+    SEL selector;
+    NSObject *arg;
+};
+
+static mach_port_t _port;
+
+static void send_nsevent (NSEventType type, NSEvent *e);
+
+/* Quartz mode initialization routine. This is often dynamically loaded
+ but is statically linked into this X server. */
+extern Bool QuartzModeBundleInit(void);
+
+static void
+init_ports (void)
+{
+    kern_return_t r;
+    NSPort *p;
+	
+    if (_port != MACH_PORT_NULL)
+		return;
+	
+    r = mach_port_allocate (mach_task_self (), MACH_PORT_RIGHT_RECEIVE, &_port);
+    if (r != KERN_SUCCESS)
+		return;
+	
+    p = [NSMachPort portWithMachPort:_port];
+    [p setDelegate:NSApp];
+    [p scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
+}
+
+static void
+message_kit_thread (SEL selector, NSObject *arg)
+{
+    message msg;
+    kern_return_t r;
+	
+    msg.hdr.msgh_bits = MACH_MSGH_BITS (MACH_MSG_TYPE_MAKE_SEND, 0);
+    msg.hdr.msgh_size = sizeof (msg);
+    msg.hdr.msgh_remote_port = _port;
+    msg.hdr.msgh_local_port = MACH_PORT_NULL;
+    msg.hdr.msgh_reserved = 0;
+    msg.hdr.msgh_id = 0;
+	
+    msg.selector = selector;
+    msg.arg = [arg retain];
+	
+    r = mach_msg (&msg.hdr, MACH_SEND_MSG, msg.hdr.msgh_size,
+				  0, MACH_PORT_NULL, 0, MACH_PORT_NULL);
+    if (r != KERN_SUCCESS)
+		fprintf (stderr, "%s: mach_msg failed: %x\n", __FUNCTION__, r);
+}
+
+- (void) handleMachMessage:(void *)_msg
+{
+    message *msg = _msg;
+	
+    [self performSelector:msg->selector withObject:msg->arg];
+    [msg->arg release];
+}
+
+- (void) set_controller:obj
+{
+    if (_controller == nil)
+		_controller = [obj retain];
+}
+
+- (void) dealloc
+{
+    if (_controller != nil)
+		[_controller release];
+	
+    if (_port != MACH_PORT_NULL)
+		mach_port_deallocate (mach_task_self (), _port);
+	
+    [super dealloc];
+}
+
+- (void) orderFrontStandardAboutPanel: (id) sender
+{
+    NSMutableDictionary *dict;
+    NSDictionary *infoDict;
+    NSString *tem;
+	
+    dict = [NSMutableDictionary dictionaryWithCapacity:2];
+    infoDict = [[NSBundle mainBundle] infoDictionary];
+	
+    [dict setObject: NSLocalizedString (@"The X Window System", @"About panel")
+			 forKey:@"ApplicationName"];
+	
+    tem = [infoDict objectForKey:@"CFBundleShortVersionString"];
+	
+    [dict setObject:[NSString stringWithFormat:@"X11.app %@ - X.org X11R7.1",
+					 tem] forKey:@"ApplicationVersion"];
+	
+    [self orderFrontStandardAboutPanelWithOptions: dict];
+}
+
+- (void) activateX:(BOOL)state
+{
+    /* Create a TSM document that supports full Unicode input, and
+	 have it activated while X is active (unless using the old
+	 keymapping files) */
+    static TSMDocumentID x11_document;
+	
+    if (state)
+    {
+		QuartzMessageServerThread (kXDarwinActivate, 0);
+		
+		if (!_x_active)
+		{
+			if (x11_document == 0 && darwinKeymapFile == NULL)
+			{
+				OSType types[1];
+				types[0] = kUnicodeDocument;
+				NewTSMDocument (1, types, &x11_document, 0);
+			}
+			
+			if (x11_document != 0)
+				ActivateTSMDocument (x11_document);
+		}
+    }
+    else
+    {
+		QuartzMessageServerThread (kXDarwinDeactivate, 0);
+		
+		if (_x_active)
+		{
+			if (x11_document != 0)
+				DeactivateTSMDocument (x11_document);
+		}
+    }
+	
+    _x_active = state;
+}
+
+- (void) became_key:(NSWindow *)win
+{
+    [self activateX:NO];
+}
+
+- (void) sendEvent:(NSEvent *)e
+{
+    NSEventType type;
+    BOOL for_appkit, for_x;
+	
+    type = [e type];
+	
+    /* By default pass down the responder chain and to X. */
+    for_appkit = YES;
+    for_x = YES;
+	
+    switch (type)
+    {
+    case NSLeftMouseDown: case NSRightMouseDown: case NSOtherMouseDown:
+    case NSLeftMouseUp: case NSRightMouseUp: case NSOtherMouseUp:
+		if ([e window] != nil)
+		{
+			/* Pointer event has a window. Probably something for the kit. */
+			
+			for_x = NO;
+			
+			if (_x_active)
+				[self activateX:NO];
+		}
+		else if ([self modalWindow] == nil)
+		{
+			/* Must be an X window. Tell appkit it doesn't have focus. */
+			
+			for_appkit = NO;
+			
+			if ([self isActive])
+			{
+				[self deactivate];
+				
+				if (!_x_active && quartzProcs->IsX11Window([e window],
+														   [e windowNumber]))
+				[self activateX:YES];
+			}
+		}
+		break;
+		
+    case NSKeyDown: case NSKeyUp:
+		if (_x_active)
+		{
+			static int swallow_up;
+			
+			/* No kit window is focused, so send it to X. */
+			
+			for_appkit = NO;
+			
+			if (type == NSKeyDown)
+			{
+				/* Before that though, see if there are any global
+				 shortcuts bound to it. */
+				
+				if (X11EnableKeyEquivalents
+					&& [[self mainMenu] performKeyEquivalent:e])
+				{
+					swallow_up = [e keyCode];
+					for_x = NO;
+				}
+				else if (!quartzEnableRootless
+						 && ([e modifierFlags] & ALL_KEY_MASKS)
+						 == (NSCommandKeyMask | NSAlternateKeyMask)
+						 && ([e keyCode] == 0 /*a*/
+							 || [e keyCode] == 53 /*Esc*/))
+				{
+					swallow_up = 0;
+					for_x = NO;
+#ifdef DARWIN_DDX_MISSING
+					QuartzMessageServerThread (kXDarwinToggleFullscreen, 0);
+#endif
+				}
+			}
+			else
+			{
+				/* If we saw a key equivalent on the down, don't pass
+				 the up through to X. */
+				
+				if (swallow_up != 0 && [e keyCode] == swallow_up)
+				{
+					swallow_up = 0;
+					for_x = NO;
+				}
+			}
+		}
+		else
+		{
+			for_x = NO;
+		}
+		break;
+		
+    case NSFlagsChanged:
+		/* For the l33t X users who remap modifier keys to normal keysyms. */
+		if (!_x_active)
+			for_x = NO;
+		break;
+		
+    case NSAppKitDefined:
+		switch ([e subtype])
+		{
+		case NSApplicationActivatedEventType:
+			for_x = NO;
+			if ([self modalWindow] == nil)
+			{
+				for_appkit = NO;
+				
+				/* FIXME: hack to avoid having to pass the event to appkit,
+				 which would cause it to raise one of its windows. */
+				_appFlags._active = YES;
+				
+				[self activateX:YES];
+#ifdef DARWIN_DDX_MISSING
+				if ([e data2] & 0x10) QuartzMessageServerThread (kXDarwinBringAllToFront, 0);
+#endif
+			}
+			break;
+			
+		case 18: /* ApplicationDidReactivate */
+			if (quartzHasRoot)
+				for_appkit = NO;
+			break;
+			
+		case NSApplicationDeactivatedEventType:
+			for_x = NO;
+			[self activateX:NO];
+			break;
+		}
+		break;
+		
+    default: break; /* for gcc */
+    }
+	
+    if (for_appkit)
+    {
+		[super sendEvent:e];
+    }
+	
+    if (for_x)
+    {
+		send_nsevent (type, e);
+    }
+}
+
+- (void) set_window_menu:(NSArray *)list
+{
+    [_controller set_window_menu:list];
+}
+
+- (void) set_window_menu_check:(NSNumber *)n
+{
+    [_controller set_window_menu_check:n];
+}
+
+- (void) set_apps_menu:(NSArray *)list
+{
+    [_controller set_apps_menu:list];
+}
+
+- (void) set_front_process:unused
+{
+    [NSApp activateIgnoringOtherApps:YES];
+	
+    if ([self modalWindow] == nil)
+		[self activateX:YES];
+}
+
+- (void) set_can_quit:(NSNumber *)state
+{
+    [_controller set_can_quit:[state boolValue]];
+}
+
+- (void) server_ready:unused
+{
+    [_controller server_ready];
+}
+
+- (void) show_hide_menubar:(NSNumber *)state
+{
+    if ([state boolValue])
+		ShowMenuBar ();
+    else
+		HideMenuBar ();
+}
+
+
+/* user preferences */
+
+/* Note that these functions only work for arrays whose elements
+ can be toll-free-bridged between NS and CF worlds. */
+
+static const void *cfretain (CFAllocatorRef a, const void *b) {
+    return CFRetain (b);
+}
+static void cfrelease (CFAllocatorRef a, const void *b) {
+    CFRelease (b);
+}
+static CFMutableArrayRef
+nsarray_to_cfarray (NSArray *in)
+{
+    CFMutableArrayRef out;
+    CFArrayCallBacks cb;
+    NSObject *ns;
+    const CFTypeRef *cf;
+    int i, count;
+	
+    memset (&cb, 0, sizeof (cb));
+    cb.version = 0;
+    cb.retain = cfretain;
+    cb.release = cfrelease;
+	
+    count = [in count];
+    out = CFArrayCreateMutable (NULL, count, &cb);
+	
+    for (i = 0; i < count; i++)
+    {
+		ns = [in objectAtIndex:i];
+		
+		if ([ns isKindOfClass:[NSArray class]])
+			cf = (CFTypeRef) nsarray_to_cfarray ((NSArray *) ns);
+		else
+			cf = CFRetain ((CFTypeRef) ns);
+		
+		CFArrayAppendValue (out, cf);
+		CFRelease (cf);
+    }
+	
+    return out;
+}
+static NSMutableArray *
+cfarray_to_nsarray (CFArrayRef in)
+{
+    NSMutableArray *out;
+    const CFTypeRef *cf;
+    NSObject *ns;
+    int i, count;
+	
+    count = CFArrayGetCount (in);
+    out = [[NSMutableArray alloc] initWithCapacity:count];
+	
+    for (i = 0; i < count; i++)
+    {
+		cf = CFArrayGetValueAtIndex (in, i);
+		
+		if (CFGetTypeID (cf) == CFArrayGetTypeID ())
+			ns = cfarray_to_nsarray ((CFArrayRef) cf);
+		else
+			ns = [(id)cf retain];
+		
+		[out addObject:ns];
+		[ns release];
+    }
+	
+    return out;
+}
+
+- (CFPropertyListRef) prefs_get:(NSString *)key
+{
+    CFPropertyListRef value;
+	
+    value = CFPreferencesCopyAppValue ((CFStringRef) key, CFSTR (APP_PREFS));
+	
+    if (value == NULL)
+    {
+		static CFDictionaryRef defaults;
+		
+		if (defaults == NULL)
+		{
+			CFStringRef error = NULL;
+			CFDataRef data;
+			CFURLRef url;
+			SInt32 error_code;
+			
+			url = (CFURLCreateFromFileSystemRepresentation
+				   (NULL, (unsigned char *)DEFAULTS_FILE, strlen (DEFAULTS_FILE), false));
+			if (CFURLCreateDataAndPropertiesFromResource (NULL, url, &data,
+														  NULL, NULL,
+														  &error_code))
+			{
+				defaults = (CFPropertyListCreateFromXMLData
+							(NULL, data, kCFPropertyListMutableContainersAndLeaves, &error));
+				if (error != NULL)
+					CFRelease (error);
+				CFRelease (data);
+			}
+			CFRelease (url);
+			
+			if (defaults != NULL)
+			{
+				NSMutableArray *apps, *elt;
+				int count, i;
+				NSString *name, *nname;
+				
+				/* Localize the names in the default apps menu. */
+				
+				apps = [(NSDictionary *)defaults objectForKey:@PREFS_APPSMENU];
+				if (apps != nil)
+				{
+					count = [apps count];
+					for (i = 0; i < count; i++)
+					{
+						elt = [apps objectAtIndex:i];
+						if (elt != nil && [elt isKindOfClass:[NSArray class]])
+						{
+							name = [elt objectAtIndex:0];
+							if (name != nil)
+							{
+								nname = NSLocalizedString (name, nil);
+								if (nname != nil && nname != name)
+									[elt replaceObjectAtIndex:0 withObject:nname];
+							}
+						}
+					}
+				}
+			}
+		}
+		
+		if (defaults != NULL)
+			value = CFDictionaryGetValue (defaults, key);
+		
+		if (value != NULL)
+			CFRetain (value);
+    }
+	
+    return value;
+}
+
+- (int) prefs_get_integer:(NSString *)key default:(int)def
+{
+    CFPropertyListRef value;
+    int ret;
+	
+    value = [self prefs_get:key];
+	
+    if (value != NULL && CFGetTypeID (value) == CFNumberGetTypeID ())
+		CFNumberGetValue (value, kCFNumberIntType, &ret);
+    else if (value != NULL && CFGetTypeID (value) == CFStringGetTypeID ())
+		ret = CFStringGetIntValue (value);
+    else
+		ret = def;
+	
+    if (value != NULL)
+		CFRelease (value);
+	
+    return ret;
+}
+
+- (const char *) prefs_get_string:(NSString *)key default:(const char *)def
+{
+    CFPropertyListRef value;
+    const char *ret = NULL;
+	
+    value = [self prefs_get:key];
+	
+    if (value != NULL && CFGetTypeID (value) == CFStringGetTypeID ())
+    {
+		NSString *s = (NSString *) value;
+		
+		ret = [s UTF8String];
+    }
+	
+    if (value != NULL)
+		CFRelease (value);
+	
+    return ret != NULL ? ret : def;
+}
+
+- (float) prefs_get_float:(NSString *)key default:(float)def
+{
+    CFPropertyListRef value;
+    float ret = def;
+	
+    value = [self prefs_get:key];
+	
+    if (value != NULL
+		&& CFGetTypeID (value) == CFNumberGetTypeID ()
+		&& CFNumberIsFloatType (value))
+    {
+		CFNumberGetValue (value, kCFNumberFloatType, &ret);
+    }
+    else if (value != NULL && CFGetTypeID (value) == CFStringGetTypeID ())
+    {
+		ret = CFStringGetDoubleValue (value);
+    }
+	
+    if (value != NULL)
+		CFRelease (value);
+	
+    return ret;
+}
+
+- (int) prefs_get_boolean:(NSString *)key default:(int)def
+{
+    CFPropertyListRef value;
+    int ret = def;
+	
+    value = [self prefs_get:key];
+	
+    if (value != NULL)
+    {
+		if (CFGetTypeID (value) == CFNumberGetTypeID ())
+			CFNumberGetValue (value, kCFNumberIntType, &ret);
+		else if (CFGetTypeID (value) == CFBooleanGetTypeID ())
+			ret = CFBooleanGetValue (value);
+		else if (CFGetTypeID (value) == CFStringGetTypeID ())
+		{
+			const char *tem = [(NSString *) value lossyCString];
+			if (strcasecmp (tem, "true") == 0 || strcasecmp (tem, "yes") == 0)
+				ret = YES;
+			else
+				ret = NO;
+		}
+		
+		CFRelease (value);
+    }
+	
+    return ret;
+}
+
+- (NSArray *) prefs_get_array:(NSString *)key
+{
+    NSArray *ret = nil;
+    CFPropertyListRef value;
+	
+    value = [self prefs_get:key];
+	
+    if (value != NULL)
+    {
+		if (CFGetTypeID (value) == CFArrayGetTypeID ())
+			ret = [cfarray_to_nsarray (value) autorelease];
+		
+		CFRelease (value);
+    }
+	
+    return ret;
+}
+
+- (void) prefs_set_integer:(NSString *)key value:(int)value
+{
+    CFNumberRef x;
+	
+    x = CFNumberCreate (NULL, kCFNumberIntType, &value);
+	
+    CFPreferencesSetValue ((CFStringRef) key, (CFTypeRef) x, CFSTR (APP_PREFS),
+						   kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
+	
+    CFRelease (x);
+}
+
+- (void) prefs_set_float:(NSString *)key value:(float)value
+{
+    CFNumberRef x;
+	
+    x = CFNumberCreate (NULL, kCFNumberFloatType, &value);
+	
+    CFPreferencesSetValue ((CFStringRef) key, (CFTypeRef) x, CFSTR (APP_PREFS),
+						   kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
+	
+    CFRelease (x);
+}
+
+- (void) prefs_set_boolean:(NSString *)key value:(int)value
+{
+    CFPreferencesSetValue ((CFStringRef) key,
+						   (CFTypeRef) value ? kCFBooleanTrue
+						   : kCFBooleanFalse, CFSTR (APP_PREFS),
+						   kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
+	
+}
+
+- (void) prefs_set_array:(NSString *)key value:(NSArray *)value
+{
+    CFArrayRef cfarray;
+	
+    cfarray = nsarray_to_cfarray (value);
+    CFPreferencesSetValue ((CFStringRef) key,
+						   (CFTypeRef) cfarray,
+						   CFSTR (APP_PREFS),
+						   kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
+    CFRelease (cfarray);
+}
+
+- (void) prefs_set_string:(NSString *)key value:(NSString *)value
+{
+    CFPreferencesSetValue ((CFStringRef) key, (CFTypeRef) value,
+						   CFSTR (APP_PREFS), kCFPreferencesCurrentUser,
+						   kCFPreferencesAnyHost);
+}
+
+- (void) prefs_synchronize
+{
+    CFPreferencesAppSynchronize (kCFPreferencesCurrentApplication);
+}
+
+- (void) read_defaults
+{
+    const char *tem;
+	
+    quartzUseSysBeep = [self prefs_get_boolean:@PREFS_SYSBEEP
+									   default:quartzUseSysBeep];
+    quartzEnableRootless = [self prefs_get_boolean:@PREFS_ROOTLESS
+										   default:quartzEnableRootless];
+#ifdef DARWIN_DDX_MISSING
+    quartzFullscreenDisableHotkeys = ![self prefs_get_boolean:
+									   @PREFS_FULLSCREEN_HOTKEYS default:
+									   !quartzFullscreenDisableHotkeys];
+    quartzXpluginOptions = [self prefs_get_integer:@PREFS_XP_OPTIONS
+										   default:quartzXpluginOptions];
+#endif
+	
+    darwinSwapAltMeta = [self prefs_get_boolean:@PREFS_SWAP_ALT_META
+										default:darwinSwapAltMeta];
+    darwinFakeButtons = [self prefs_get_boolean:@PREFS_FAKEBUTTONS
+										default:darwinFakeButtons];
+    if (darwinFakeButtons)
+    {
+        const char *fake2, *fake3;
+		
+        fake2 = [self prefs_get_string:@PREFS_FAKE_BUTTON2 default:NULL];
+        fake3 = [self prefs_get_string:@PREFS_FAKE_BUTTON3 default:NULL];
+		
+		if (fake2 != NULL) darwinFakeMouse2Mask = DarwinParseModifierList(fake2);
+		if (fake3 != NULL) darwinFakeMouse3Mask = DarwinParseModifierList(fake3);
+		
+    }
+	
+    X11EnableKeyEquivalents = [self prefs_get_boolean:@PREFS_KEYEQUIVS
+											  default:X11EnableKeyEquivalents];
+	
+    darwinSyncKeymap = [self prefs_get_boolean:@PREFS_SYNC_KEYMAP
+									   default:darwinSyncKeymap];
+	
+    tem = [self prefs_get_string:@PREFS_KEYMAP_FILE default:NULL];
+    if (tem != NULL)
+		darwinKeymapFile = strdup (tem);
+    else
+        darwinKeymapFile = NULL;
+	
+    darwinDesiredDepth = [self prefs_get_integer:@PREFS_DEPTH
+										 default:darwinDesiredDepth];
+	
+    enable_stereo = [self prefs_get_boolean:@PREFS_ENABLE_STEREO
+									default:false];
+}
+
+/* This will end up at the end of the responder chain. */
+- (void) copy:sender
+{
+    QuartzMessageServerThread (kXDarwinPasteboardNotify, 1,
+							   AppleWMCopyToPasteboard);
+}
+
+- (BOOL) x_active
+{
+    return _x_active;
+}
+
+ at end
+
+static NSArray *
+array_with_strings_and_numbers (int nitems, const char **items,
+								const char *numbers)
+{
+    NSMutableArray *array, *subarray;
+    NSString *string;
+    NSString *number;
+    int i;
+	
+    /* (Can't autorelease on the X server thread) */
+	
+    array = [[NSMutableArray alloc] initWithCapacity:nitems];
+	
+    for (i = 0; i < nitems; i++)
+    {
+		subarray = [[NSMutableArray alloc] initWithCapacity:2];
+		
+		string = [[NSString alloc] initWithUTF8String:items[i]];
+		[subarray addObject:string];
+		[string release];
+		
+		if (numbers[i] != 0)
+		{
+			number = [[NSString alloc] initWithFormat:@"%d", numbers[i]];
+			[subarray addObject:number];
+			[number release];
+		}
+		else
+			[subarray addObject:@""];
+		
+		[array addObject:subarray];
+		[subarray release];
+    }
+	
+    return array;
+}
+
+void
+X11ApplicationSetWindowMenu (int nitems, const char **items,
+							 const char *shortcuts)
+{
+    NSArray *array;
+    array = array_with_strings_and_numbers (nitems, items, shortcuts);
+	
+    /* Send the array of strings over to the appkit thread */
+	
+    message_kit_thread (@selector (set_window_menu:), array);
+    [array release];
+}
+
+void
+X11ApplicationSetWindowMenuCheck (int idx)
+{
+    NSNumber *n;
+	
+    n = [[NSNumber alloc] initWithInt:idx];
+	
+    message_kit_thread (@selector (set_window_menu_check:), n);
+	
+    [n release];
+}
+
+void
+X11ApplicationSetFrontProcess (void)
+{
+    message_kit_thread (@selector (set_front_process:), nil);
+}
+
+void
+X11ApplicationSetCanQuit (int state)
+{
+    NSNumber *n;
+	
+    n = [[NSNumber alloc] initWithBool:state];
+	
+    message_kit_thread (@selector (set_can_quit:), n);
+	
+    [n release];
+}
+
+void
+X11ApplicationServerReady (void)
+{
+    message_kit_thread (@selector (server_ready:), nil);
+}
+
+void
+X11ApplicationShowHideMenubar (int state)
+{
+    NSNumber *n;
+	
+    n = [[NSNumber alloc] initWithBool:state];
+	
+    message_kit_thread (@selector (show_hide_menubar:), n);
+	
+    [n release];
+}
+
+static void *
+create_thread (void *func, void *arg)
+{
+    pthread_attr_t attr;
+    pthread_t tid;
+	
+    pthread_attr_init (&attr);
+	
+    pthread_attr_setscope (&attr, PTHREAD_SCOPE_SYSTEM);
+    pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
+	
+    pthread_create (&tid, &attr, func, arg);
+	
+    pthread_attr_destroy (&attr);
+	
+    return (void *) tid;
+}
+
+static void
+check_xinitrc (void)
+{
+    char *tem, buf[1024];
+    NSString *msg;
+	
+    if ([X11App prefs_get_boolean:@PREFS_DONE_XINIT_CHECK default:NO])
+		return;
+	
+    tem = getenv ("HOME");
+    if (tem == NULL)
+		goto done;
+	
+    snprintf (buf, sizeof (buf), "%s/.xinitrc", tem);
+    if (access (buf, F_OK) != 0)
+		goto done;
+	
+    /* FIXME: put localized strings into Resources/English.lproj */
+	
+    msg = NSLocalizedString (
+							 @"You have an existing ~/.xinitrc file.\n\n\
+							 Windows displayed by X11 applications may not have titlebars, or may look \
+							 different to windows displayed by native applications.\n\n\
+							 Would you like to move aside the existing file and use the standard X11 \
+							 environment?", @"Startup xinitrc dialog");
+	
+    if (NSRunAlertPanel (nil, msg, NSLocalizedString (@"Yes", @""),
+						 NSLocalizedString (@"No", @""), nil)
+		== NSAlertDefaultReturn)
+    {
+		char buf2[1024];
+		int i = -1;
+		
+		snprintf (buf2, sizeof (buf2), "%s.old", buf);
+		
+		for (i = 1; access (buf2, F_OK) == 0; i++)
+			snprintf (buf2, sizeof (buf2), "%s.old.%d", buf, i);
+		
+		rename (buf, buf2);
+    }
+    
+	done:
+    [X11App prefs_set_boolean:@PREFS_DONE_XINIT_CHECK value:YES];
+    [X11App prefs_synchronize];
+}
+
+void
+X11ApplicationMain (int argc, const char *argv[],
+					void (*server_thread) (void *), void *server_arg)
+{
+    NSAutoreleasePool *pool;
+	
+#ifdef DEBUG
+    while (access ("/tmp/x11-block", F_OK) == 0)
+		sleep (1);
+#endif
+	
+    pool = [[NSAutoreleasePool alloc] init];
+	
+    X11App = (X11Application *) [X11Application sharedApplication];
+	
+    init_ports ();
+	
+    [NSApp read_defaults];
+	
+    [NSBundle loadNibNamed:@"main" owner:NSApp];
+	
+    [[NSNotificationCenter defaultCenter] addObserver:NSApp
+											 selector:@selector (became_key:)
+												 name:NSWindowDidBecomeKeyNotification object:nil];
+	
+    check_xinitrc ();
+	
+    /*
+     * The xpr Quartz mode is statically linked into this server.
+     * Initialize all the Quartz functions.
+     */
+    QuartzModeBundleInit();
+	
+    /* Calculate the height of the menubar so we can avoid it. */
+    aquaMenuBarHeight = NSHeight([[NSScreen mainScreen] frame]) -
+	NSMaxY([[NSScreen mainScreen] visibleFrame]) - 1;
+	
+    if (!create_thread (server_thread, server_arg))
+    {
+		fprintf (stderr, "can't create secondary thread\n");
+		exit (1);
+    }
+	
+    [NSApp run];
+	
+    /* not reached */
+}
+
+
+/* event conversion */
+
+static inline unsigned short
+convert_flags (unsigned int nsflags)
+{
+    unsigned int xflags;
+	
+    if (nsflags == ~0) return 0xffff;
+	
+    xflags = 0;
+	
+    if (nsflags & NSAlphaShiftKeyMask)	xflags |= LockMask;
+    if (nsflags & NSShiftKeyMask)		xflags |= ShiftMask;
+    if (nsflags & NSControlKeyMask)		xflags |= ControlMask;
+    if (nsflags & NSAlternateKeyMask)	xflags |= Mod1Mask;
+    if (nsflags & NSCommandKeyMask)		xflags |= Mod2Mask;
+    /* FIXME: secondaryfn? */
+	
+    return xflags;
+}
+
+static void
+send_nsevent (NSEventType type, NSEvent *e)
+{
+    static unsigned int button_state = 0;
+    NSRect screen;
+    NSPoint location;
+    NSWindow *window;
+    int pointer_x, pointer_y;
+    xEvent xe;
+	
+    memset (&xe, 0, sizeof (xe));
+	
+    /* This field should be filled in for every event */
+    xe.u.keyButtonPointer.time = GetTimeInMillis();
+
+	/* convert location to global top-left coordinates */
+	location = [e locationInWindow];
+	window = [e window];
+	screen = [[[NSScreen screens] objectAtIndex:0] frame];
+		
+	if (window != nil)	{
+		NSRect frame = [window frame];
+		pointer_x = location.x + frame.origin.x;
+		pointer_y = (((screen.origin.y + screen.size.height)
+					  - location.y) - frame.origin.y);
+	} else {
+		pointer_x = location.x;
+		pointer_y = (screen.origin.y + screen.size.height) - location.y;
+	}
+		
+	xe.u.keyButtonPointer.rootX = pointer_x;
+	xe.u.keyButtonPointer.rootY = pointer_y;
+	
+	switch (type) {
+		float count;
+		
+    case NSLeftMouseDown:
+		xe.u.u.type = ButtonPress;
+		xe.u.u.detail = 1;
+		goto do_press_event;
+		
+    case NSRightMouseDown:
+		xe.u.u.type = ButtonPress;
+		xe.u.u.detail = 3;
+		goto do_press_event;
+		
+    case NSOtherMouseDown:
+		xe.u.u.type = ButtonPress;
+		xe.u.u.detail = 2; /* FIXME? */
+		goto do_press_event;
+		
+do_press_event:
+		if (!quartzProcs->IsX11Window([e window], [e windowNumber])) {
+			/* X server doesn't grok this window, drop the event.
+			 
+			 Note: theoretically this isn't necessary, but if I click
+			 on the menubar, we get sent a LeftMouseDown when the
+			 release happens, but no LeftMouseUp is ever seen! */
+			
+			break;
+		}
+		goto do_event;
+		
+    case NSLeftMouseUp:
+		xe.u.u.type = ButtonRelease;
+		xe.u.u.detail = 1;
+		goto do_release_event;
+		
+    case NSRightMouseUp:
+		xe.u.u.type = ButtonRelease;
+		xe.u.u.detail = 3;
+		goto do_release_event;
+		
+    case NSOtherMouseUp:
+		xe.u.u.type = ButtonRelease;
+		xe.u.u.detail = 2; /* FIXME? */
+		goto do_release_event;
+		
+do_release_event:
+		if ((button_state & (1 << xe.u.u.detail)) == 0)
+		{
+			/* X didn't see the button press for this release, so skip it */
+			break;
+		}
+		goto do_event;
+		
+    case NSMouseMoved:
+    case NSLeftMouseDragged:
+    case NSRightMouseDragged:
+    case NSOtherMouseDragged:
+		xe.u.u.type = MotionNotify;
+		goto do_event;
+		
+    case NSKeyDown:
+		xe.u.u.type = KeyPress;
+		xe.u.u.detail = [e keyCode];
+		goto do_event;
+		
+    case NSKeyUp:
+		xe.u.u.type = KeyRelease;
+		xe.u.u.detail = [e keyCode];
+		goto do_event;
+		
+    case NSScrollWheel:
+		xe.u.keyButtonPointer.state = convert_flags ([e modifierFlags]);
+		count = [e deltaY];
+		xe.u.u.detail = count > 0.0f ? 4 : 5;
+		for (count = fabs(count); count > 0.0; count = count - 1.0f) {
+			xe.u.u.type = ButtonPress;
+			DarwinEQEnqueue(&xe);
+			xe.u.u.type = ButtonRelease;
+			DarwinEQEnqueue(&xe);
+		}
+		xe.u.u.type = 0;
+		break;
+		
+    case NSFlagsChanged:
+        xe.u.u.type = kXDarwinUpdateModifiers;
+        xe.u.clientMessage.u.l.longs0 = [e modifierFlags];
+        DarwinEQEnqueue (&xe);
+        break;
+		
+do_event:
+		//	xe.u.keyButtonPointer.state = convert_flags ([e modifierFlags]);
+		DarwinEQEnqueue (&xe);
+		break;
+		
+    default: break; /* for gcc */
+    }
+	
+    if (xe.u.u.type == ButtonPress)
+		button_state |= (1 << xe.u.u.detail);
+    else if (xe.u.u.type == ButtonRelease)
+		button_state &= ~(1 << xe.u.u.detail);
+}
diff --git a/hw/darwin/apple/X11Controller.h b/hw/darwin/apple/X11Controller.h
new file mode 100644
index 0000000..954d0ab
--- /dev/null
+++ b/hw/darwin/apple/X11Controller.h
@@ -0,0 +1,86 @@
+/* X11Controller.h -- connect the IB ui
+   $Id: X11Controller.h,v 1.21 2003/07/24 17:52:29 jharper Exp $
+
+   Copyright (c) 2002 Apple Computer, Inc. All rights reserved.
+
+   Permission is hereby granted, free of charge, to any person
+   obtaining a copy of this software and associated documentation files
+   (the "Software"), to deal in the Software without restriction,
+   including without limitation the rights to use, copy, modify, merge,
+   publish, distribute, sublicense, and/or sell copies of the Software,
+   and to permit persons to whom the Software is furnished to do so,
+   subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be
+   included in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+   NONINFRINGEMENT.  IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT
+   HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+
+   Except as contained in this notice, the name(s) of the above
+   copyright holders shall not be used in advertising or otherwise to
+   promote the sale, use or other dealings in this Software without
+   prior written authorization. */
+
+#ifndef X11CONTROLLER_H
+#define X11CONTROLLER_H 1
+
+#if __OBJC__
+
+#import <Cocoa/Cocoa.h>
+#include "../quartz/xpr/x-list.h"
+
+ at interface X11Controller : NSObject
+{
+    NSPanel *prefs_panel;
+
+    NSButton *fake_buttons;
+    NSButton *enable_fullscreen;
+    NSButton *use_sysbeep;
+    NSButton *enable_keyequivs;
+    NSButton *sync_keymap;
+    NSButton *enable_auth;
+    NSButton *enable_tcp;
+    NSPopUpButton *depth;
+
+    NSMenuItem *x11_about_item;
+    NSMenuItem *window_separator;
+    NSMenuItem *dock_window_separator;
+    NSMenuItem *apps_separator;
+    NSMenuItem *toggle_fullscreen_item;
+    NSMenu *dock_apps_menu;
+    NSTableView *apps_table;
+
+    NSArray *apps;
+    NSMutableArray *table_apps;
+
+    NSMenu *dock_menu;
+
+    int checked_window_item;
+    x_list *pending_apps;
+
+    BOOL finished_launching;
+    BOOL can_quit;
+}
+
+- (void) set_window_menu:(NSArray *)list;
+- (void) set_window_menu_check:(NSNumber *)n;
+- (void) set_apps_menu:(NSArray *)list;
+- (void) set_can_quit:(BOOL)state;
+- (void) server_ready;
+
+ at end
+
+#endif /* __OBJC__ */
+
+extern void X11ControllerMain (int argc, const char *argv[],
+			       void (*server_thread) (void *),
+			       void *server_arg);
+
+#endif /* X11CONTROLLER_H */
diff --git a/hw/darwin/apple/X11Controller.m b/hw/darwin/apple/X11Controller.m
new file mode 100644
index 0000000..3dc965b
--- /dev/null
+++ b/hw/darwin/apple/X11Controller.m
@@ -0,0 +1,752 @@
+/* X11Controller.m -- connect the IB ui, also the NSApp delegate
+   $Id: X11Controller.m,v 1.40 2006/09/06 21:19:32 jharper Exp $
+ 
+   Copyright (c) 2002-2007 Apple Inc. All rights reserved.
+ 
+   Permission is hereby granted, free of charge, to any person
+   obtaining a copy of this software and associated documentation files
+   (the "Software"), to deal in the Software without restriction,
+   including without limitation the rights to use, copy, modify, merge,
+   publish, distribute, sublicense, and/or sell copies of the Software,
+   and to permit persons to whom the Software is furnished to do so,
+   subject to the following conditions:
+ 
+   The above copyright notice and this permission notice shall be
+   included in all copies or substantial portions of the Software.
+ 
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+   NONINFRINGEMENT.  IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT
+   HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+ 
+   Except as contained in this notice, the name(s) of the above
+   copyright holders shall not be used in advertising or otherwise to
+   promote the sale, use or other dealings in this Software without
+   prior written authorization. */
+
+#define DEFAULT_PATH "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/X11/bin"
+
+#include "../quartz/quartzCommon.h"
+
+#import "X11Controller.h"
+#import "X11Application.h"
+#import <Carbon/Carbon.h>
+
+/* ouch! */
+#define BOOL X_BOOL
+//# include "Xproto.h"
+#include "opaque.h"
+# include "darwin.h"
+# include "../quartz/quartz.h"
+# define _APPLEWM_SERVER_
+# include "X11/extensions/applewm.h"
+# include "../quartz/applewmExt.h"
+//# include "X.h"
+#undef BOOL
+
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#define TRACE() fprintf (stderr, "%s\n", __FUNCTION__)
+
+ at implementation X11Controller
+
+- (void) awakeFromNib
+{
+  X11Application *xapp = NSApp;
+  NSArray *array;
+	
+  /* Point X11Application at ourself. */
+  [xapp set_controller:self];
+	
+  array = [xapp prefs_get_array:@PREFS_APPSMENU];
+  if (array != nil)
+    {
+      int count;
+		
+      /* convert from [TITLE1 COMMAND1 TITLE2 COMMAND2 ...]
+	 to [[TITLE1 COMMAND1] [TITLE2 COMMAND2] ...] format. */
+		
+      count = [array count];
+      if (count > 0
+	  && ![[array objectAtIndex:0] isKindOfClass:[NSArray class]])
+	{
+	  int i;
+	  NSMutableArray *copy, *sub;
+			
+	  copy = [NSMutableArray arrayWithCapacity:(count / 2)];
+			
+	  for (i = 0; i < count / 2; i++)
+	    {
+	      sub = [[NSMutableArray alloc] initWithCapacity:3];
+	      [sub addObject:[array objectAtIndex:i*2]];
+	      [sub addObject:[array objectAtIndex:i*2+1]];
+	      [sub addObject:@""];
+	      [copy addObject:sub];
+	      [sub release];
+	    }
+			
+	  array = copy;
+	}
+		
+      [self set_apps_menu:array];
+    }
+}
+
+- (void) item_selected:sender
+{
+  [NSApp activateIgnoringOtherApps:YES];
+	
+  QuartzMessageServerThread (kXDarwinControllerNotify, 2,
+			     AppleWMWindowMenuItem, [sender tag]);
+}
+
+- (void) remove_window_menu
+{
+  NSMenu *menu;
+  int first, count, i;
+	
+  /* Work backwards so we don't mess up the indices */
+  menu = [window_separator menu];
+  first = [menu indexOfItem:window_separator] + 1;
+  count = [menu numberOfItems];
+  for (i = count - 1; i >= first; i--)
+    [menu removeItemAtIndex:i];
+	
+  menu = [dock_window_separator menu];
+  count = [menu indexOfItem:dock_window_separator];
+  for (i = 0; i < count; i++)
+    [dock_menu removeItemAtIndex:0];
+}
+
+- (void) install_window_menu:(NSArray *)list
+{
+  NSMenu *menu;
+  NSMenuItem *item;
+  int first, count, i;
+	
+  menu = [window_separator menu];
+  first = [menu indexOfItem:window_separator] + 1;
+  count = [list count];
+  for (i = 0; i < count; i++)
+    {
+      NSString *name, *shortcut;
+		
+      name = [[list objectAtIndex:i] objectAtIndex:0];
+      shortcut = [[list objectAtIndex:i] objectAtIndex:1];
+		
+      item = (NSMenuItem *) [menu addItemWithTitle:name action:@selector
+				  (item_selected:) keyEquivalent:shortcut];
+      [item setTarget:self];
+      [item setTag:i];
+      [item setEnabled:YES];
+		
+      item = (NSMenuItem *) [dock_menu insertItemWithTitle:name
+				       action:@selector
+				       (item_selected:) keyEquivalent:shortcut
+				       atIndex:i];
+      [item setTarget:self];
+      [item setTag:i];
+      [item setEnabled:YES];
+    }
+	
+  if (checked_window_item >= 0 && checked_window_item < count)
+    {
+      item = (NSMenuItem *) [menu itemAtIndex:first + checked_window_item];
+      [item setState:NSOnState];
+      item = (NSMenuItem *) [dock_menu itemAtIndex:checked_window_item];
+      [item setState:NSOnState];
+    }
+}
+
+- (void) remove_apps_menu
+{
+  NSMenu *menu;
+  NSMenuItem *item;
+  int i;
+	
+  if (apps == nil || apps_separator == nil) return;
+	
+  menu = [apps_separator menu];
+	
+  if (menu != nil)
+    {
+      for (i = [menu numberOfItems] - 1; i >= 0; i--)
+	{
+	  item = (NSMenuItem *) [menu itemAtIndex:i];
+	  if ([item tag] != 0)
+	    [menu removeItemAtIndex:i];
+	}
+    }
+    
+  if (dock_apps_menu != nil)
+    {
+      for (i = [dock_apps_menu numberOfItems] - 1; i >= 0; i--)
+	{
+	  item = (NSMenuItem *) [dock_apps_menu itemAtIndex:i];
+	  if ([item tag] != 0)
+	    [dock_apps_menu removeItemAtIndex:i];
+	}
+    }
+    
+  [apps release];
+  apps = nil;
+}
+
+- (void) prepend_apps_item:(NSArray *)list index:(int)i menu:(NSMenu *)menu
+{
+  NSString *title, *shortcut = @"";
+  NSArray *group;
+  NSMenuItem *item;
+	
+  group = [list objectAtIndex:i];
+  title = [group objectAtIndex:0];
+  if ([group count] >= 3)
+    shortcut = [group objectAtIndex:2];
+	
+  if ([title length] != 0)
+    {
+      item = (NSMenuItem *) [menu insertItemWithTitle:title
+				  action:@selector (app_selected:)
+				  keyEquivalent:shortcut atIndex:0];
+      [item setTarget:self];
+      [item setEnabled:YES];
+    }
+  else
+    {
+      item = (NSMenuItem *) [NSMenuItem separatorItem];
+      [menu insertItem:item atIndex:0];
+    }
+	
+  [item setTag:i+1];			/* can't be zero, so add one */
+}
+
+- (void) install_apps_menu:(NSArray *)list
+{
+  NSMenu *menu;
+  int i, count;
+	
+  count = [list count];
+	
+  if (count == 0 || apps_separator == nil) return;
+	
+  menu = [apps_separator menu];
+	
+  for (i = count - 1; i >= 0; i--)
+    {
+      if (menu != nil)
+	[self prepend_apps_item:list index:i menu:menu];
+      if (dock_apps_menu != nil)
+	[self prepend_apps_item:list index:i menu:dock_apps_menu];
+    }
+	
+  apps = [list retain];
+}
+
+- (void) set_window_menu:(NSArray *)list
+{
+  [self remove_window_menu];
+  [self install_window_menu:list];
+	
+  QuartzMessageServerThread (kXDarwinControllerNotify, 1,
+			     AppleWMWindowMenuNotify);
+}
+
+- (void) set_window_menu_check:(NSNumber *)nn
+{
+  NSMenu *menu;
+  NSMenuItem *item;
+  int first, count;
+  int n = [nn intValue];
+
+  menu = [window_separator menu];
+  first = [menu indexOfItem:window_separator] + 1;
+  count = [menu numberOfItems] - first;
+	
+  if (checked_window_item >= 0 && checked_window_item < count)
+    {
+      item = (NSMenuItem *) [menu itemAtIndex:first + checked_window_item];
+      [item setState:NSOffState];
+      item = (NSMenuItem *) [dock_menu itemAtIndex:checked_window_item];
+      [item setState:NSOffState];
+    }
+  if (n >= 0 && n < count)
+    {
+      item = (NSMenuItem *) [menu itemAtIndex:first + n];
+      [item setState:NSOnState];
+      item = (NSMenuItem *) [dock_menu itemAtIndex:n];
+      [item setState:NSOnState];
+    }
+  checked_window_item = n;
+}
+
+- (void) set_apps_menu:(NSArray *)list
+{
+  [self remove_apps_menu];
+  [self install_apps_menu:list];
+}
+
+- (void) launch_client:(NSString *)filename
+{
+  const char *command = [filename UTF8String];
+  const char *shell;
+  const char *argv[5];
+  int child1, child2 = 0;
+  int status;
+	
+  shell = getenv("SHELL");
+  if (shell == NULL) shell = "/bin/bash";
+    
+  argv[0] = shell;
+  argv[1] = "-l";
+  argv[2] = "-c";
+  argv[3] = command;
+  argv[4] = NULL;
+    
+  /* Do the fork-twice trick to avoid having to reap zombies */
+    
+  child1 = fork();
+    
+  switch (child1) {
+  case -1:                                /* error */
+    break;
+      
+  case 0:                                 /* child1 */
+    child2 = fork();
+      
+    switch (child2) {
+      int max_files, i;
+      char buf[1024], *temp;
+	
+    case -1:                            /* error */
+      _exit(1);
+	
+    case 0:                             /* child2 */
+      /* close all open files except for standard streams */
+      max_files = sysconf(_SC_OPEN_MAX);
+      for (i = 3; i < max_files; i++)	close(i);
+	
+      /* ensure stdin is on /dev/null */
+      close(0);
+      open("/dev/null", O_RDONLY);
+	
+      /* Setup environment */
+      temp = getenv("DISPLAY");
+      if (temp == NULL || temp[0] == 0) {
+	snprintf(buf, sizeof(buf), ":%s", display);
+	setenv("DISPLAY", buf, TRUE);
+      }
+	
+      temp = getenv("PATH");
+      if (temp == NULL || temp[0] == 0) 
+	setenv ("PATH", DEFAULT_PATH, TRUE);
+      else if (strnstr(temp, "/usr/X11/bin", sizeof(temp)) == NULL) {
+	snprintf(buf, sizeof(buf), "%s:/usr/X11/bin", temp);            
+	setenv("PATH", buf, TRUE);      
+      }
+      /* cd $HOME */
+      temp = getenv("HOME");
+      if (temp != NULL && temp[0]!=0) chdir(temp);
+	
+      execvp(argv[0], (char **const) argv);
+	
+      _exit(2);
+	
+    default:                            /* parent (child1) */
+      _exit(0);
+    }
+    break;
+      
+  default:                                /* parent */
+    waitpid(child1, &status, 0);
+  }
+}
+
+- (void) app_selected:sender
+{
+  int tag;
+  NSString *item;
+  
+  tag = [sender tag] - 1;
+  if (apps == nil || tag < 0 || tag >= [apps count])
+    return;
+  
+  item = [[apps objectAtIndex:tag] objectAtIndex:1];
+  
+  [self launch_client:item];
+}
+
+- (IBAction) apps_table_show:sender
+{
+  NSArray *columns;
+	
+  if (table_apps == nil) {
+    table_apps = [[NSMutableArray alloc] initWithCapacity:1];
+      
+    if (apps != nil)[table_apps addObjectsFromArray:apps];
+  }
+	
+  columns = [apps_table tableColumns];
+  [[columns objectAtIndex:0] setIdentifier:@"0"];
+  [[columns objectAtIndex:1] setIdentifier:@"1"];
+  [[columns objectAtIndex:2] setIdentifier:@"2"];
+	
+  [apps_table setDataSource:self];
+  [apps_table selectRow:0 byExtendingSelection:NO];
+	
+  [[apps_table window] makeKeyAndOrderFront:sender];
+}
+
+- (IBAction) apps_table_cancel:sender
+{
+  [[apps_table window] orderOut:sender];
+  [apps_table reloadData];
+	
+  [table_apps release];
+  table_apps = nil;
+}
+
+- (IBAction) apps_table_done:sender
+{
+  [apps_table deselectAll:sender];	/* flush edits? */
+	
+  [self remove_apps_menu];
+  [self install_apps_menu:table_apps];
+	
+  [NSApp prefs_set_array:@PREFS_APPSMENU value:table_apps];
+  [NSApp prefs_synchronize];
+	
+  [[apps_table window] orderOut:sender];
+	
+  [table_apps release];
+  table_apps = nil;
+}
+
+- (IBAction) apps_table_new:sender
+{
+  NSMutableArray *item;
+	
+  int row = [apps_table selectedRow], i;
+	
+  if (row < 0) row = 0;
+  else row = row + 1;
+	
+  i = row;
+  if (i > [table_apps count])
+    return;				/* avoid exceptions */
+	
+  [apps_table deselectAll:sender];
+	
+  item = [[NSMutableArray alloc] initWithCapacity:3];
+  [item addObject:@""];
+  [item addObject:@""];
+  [item addObject:@""];
+	
+  [table_apps insertObject:item atIndex:i];
+  [item release];
+	
+  [apps_table reloadData];
+  [apps_table selectRow:row byExtendingSelection:NO];
+}
+
+- (IBAction) apps_table_duplicate:sender
+{
+  int row = [apps_table selectedRow], i;
+  NSObject *item;
+	
+  if (row < 0) {
+    [self apps_table_new:sender];
+    return;
+  }
+	
+  i = row;
+  if (i > [table_apps count] - 1) return;				/* avoid exceptions */
+    
+  [apps_table deselectAll:sender];
+	
+  item = [[table_apps objectAtIndex:i] mutableCopy];
+  [table_apps insertObject:item atIndex:i];
+  [item release];
+	
+  [apps_table reloadData];
+  [apps_table selectRow:row+1 byExtendingSelection:NO];
+}
+
+- (IBAction) apps_table_delete:sender
+{
+  int row = [apps_table selectedRow];
+	
+  if (row >= 0)
+    {
+      int i = row;
+      
+      if (i > [table_apps count] - 1) return;			/* avoid exceptions */
+      
+      [apps_table deselectAll:sender];
+      
+      [table_apps removeObjectAtIndex:i];
+    }
+	
+  [apps_table reloadData];
+	
+  row = MIN (row, [table_apps count] - 1);
+  if (row >= 0)
+    [apps_table selectRow:row byExtendingSelection:NO];
+}
+
+- (int) numberOfRowsInTableView:(NSTableView *)tableView
+{
+  if (table_apps == nil) return 0;
+  
+  return [table_apps count];
+}
+
+- (id) tableView:(NSTableView *)tableView
+objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row
+{
+  NSArray *item;
+  int col;
+	
+  if (table_apps == nil) return nil;
+	
+  col = [[tableColumn identifier] intValue];
+	
+  item = [table_apps objectAtIndex:row];
+  if ([item count] > col)
+    return [item objectAtIndex:col];
+  else
+    return @"";
+}
+
+- (void) tableView:(NSTableView *)tableView setObjectValue:(id)object
+    forTableColumn:(NSTableColumn *)tableColumn row:(int)row
+{
+  NSMutableArray *item;
+  int col;
+	
+  if (table_apps == nil) return;
+	
+  col = [[tableColumn identifier] intValue];
+	
+  item = [table_apps objectAtIndex:row];
+  [item replaceObjectAtIndex:col withObject:object];
+}
+
+- (void) hide_window:sender
+{
+  if ([X11App x_active])
+    QuartzMessageServerThread (kXDarwinControllerNotify, 1, AppleWMHideWindow);
+  else
+    NSBeep ();			/* FIXME: something here */
+}
+
+- (IBAction)bring_to_front:sender
+{
+  QuartzMessageServerThread(kXDarwinControllerNotify, 1, AppleWMBringAllToFront);
+}
+
+- (IBAction)close_window:sender
+{
+  if ([X11App x_active])
+    QuartzMessageServerThread (kXDarwinControllerNotify, 1, AppleWMCloseWindow);
+  else
+    [[NSApp keyWindow] performClose:sender];
+}
+
+- (IBAction)minimize_window:sender
+{
+  if ([X11App x_active])
+    QuartzMessageServerThread (kXDarwinControllerNotify, 1, AppleWMMinimizeWindow);
+  else
+    [[NSApp keyWindow] performMiniaturize:sender];
+}
+
+- (IBAction)zoom_window:sender
+{
+  if ([X11App x_active])
+    QuartzMessageServerThread (kXDarwinControllerNotify, 1, AppleWMZoomWindow);
+  else
+    [[NSApp keyWindow] performZoom:sender];
+}
+
+- (IBAction) next_window:sender
+{
+  QuartzMessageServerThread (kXDarwinControllerNotify, 1, AppleWMNextWindow);
+}
+
+- (IBAction) previous_window:sender
+{
+  QuartzMessageServerThread (kXDarwinControllerNotify, 1, AppleWMPreviousWindow);
+}
+
+- (IBAction) enable_fullscreen_changed:sender
+{
+  int value = ![enable_fullscreen intValue];
+	
+#ifdef DARWIN_DDX_MISSING
+  QuartzMessageServerThread (kXDarwinSetRootless, 1, value);
+#endif
+	
+  [NSApp prefs_set_boolean:@PREFS_ROOTLESS value:value];
+  [NSApp prefs_synchronize];
+}
+
+- (IBAction) toggle_fullscreen:sender
+{
+#ifdef DARWIN_DDX_MISSING
+  QuartzMessageServerThread (kXDarwinToggleFullscreen, 0);
+#endif
+}
+
+- (void) set_can_quit:(BOOL)state
+{
+  can_quit = state;
+}
+
+- (IBAction)prefs_changed:sender
+{
+  darwinFakeButtons = [fake_buttons intValue];
+  quartzUseSysBeep = [use_sysbeep intValue];
+  X11EnableKeyEquivalents = [enable_keyequivs intValue];
+  darwinSyncKeymap = [sync_keymap intValue];
+	
+  /* after adding prefs here, also add to [X11Application read_defaults]
+     and below */
+	
+  [NSApp prefs_set_boolean:@PREFS_FAKEBUTTONS value:darwinFakeButtons];
+  [NSApp prefs_set_boolean:@PREFS_SYSBEEP value:quartzUseSysBeep];
+  [NSApp prefs_set_boolean:@PREFS_KEYEQUIVS value:X11EnableKeyEquivalents];
+  [NSApp prefs_set_boolean:@PREFS_SYNC_KEYMAP value:darwinSyncKeymap];
+  [NSApp prefs_set_boolean:@PREFS_NO_AUTH value:![enable_auth intValue]];
+  [NSApp prefs_set_boolean:@PREFS_NO_TCP value:![enable_tcp intValue]];
+  [NSApp prefs_set_integer:@PREFS_DEPTH value:[depth selectedTag]];
+	
+  [NSApp prefs_synchronize];
+}
+
+- (IBAction) prefs_show:sender
+{
+  [fake_buttons setIntValue:darwinFakeButtons];
+  [use_sysbeep setIntValue:quartzUseSysBeep];
+  [enable_keyequivs setIntValue:X11EnableKeyEquivalents];
+  [sync_keymap setIntValue:darwinSyncKeymap];
+  [sync_keymap setEnabled:darwinKeymapFile == NULL];
+	
+  [enable_auth setIntValue:![NSApp prefs_get_boolean:@PREFS_NO_AUTH default:NO]];
+  [enable_tcp setIntValue:![NSApp prefs_get_boolean:@PREFS_NO_TCP default:NO]];
+  [depth selectItemAtIndex:[depth indexOfItemWithTag:[NSApp prefs_get_integer:@PREFS_DEPTH default:-1]]];
+	
+  [enable_fullscreen setIntValue:!quartzEnableRootless];
+	
+  [prefs_panel makeKeyAndOrderFront:sender];
+}
+
+- (IBAction) quit:sender
+{
+  QuartzMessageServerThread (kXDarwinQuit, 0);
+}
+
+- (IBAction) x11_help:sender
+{
+  AHLookupAnchor (CFSTR ("Mac Help"), CFSTR ("mchlp2276"));
+}
+
+- (BOOL) validateMenuItem:(NSMenuItem *)item
+{
+  NSMenu *menu = [item menu];
+	
+  if (item == toggle_fullscreen_item)
+    return !quartzEnableRootless;
+  else if (menu == [window_separator menu] || menu == dock_menu
+	   || (menu == [x11_about_item menu] && [item tag] == 42))
+    return (AppleWMSelectedEvents () & AppleWMControllerNotifyMask) != 0;
+  else
+    return TRUE;
+}
+
+- (void) applicationDidHide:(NSNotification *)notify
+{
+  QuartzMessageServerThread (kXDarwinControllerNotify, 1, AppleWMHideAll);
+}
+
+- (void) applicationDidUnhide:(NSNotification *)notify
+{
+  QuartzMessageServerThread (kXDarwinControllerNotify, 1, AppleWMShowAll);
+}
+
+- (NSApplicationTerminateReply) applicationShouldTerminate:sender
+{
+  NSString *msg;
+	
+  if (can_quit || [X11App prefs_get_boolean:@PREFS_NO_QUIT_ALERT default:NO])
+    return NSTerminateNow;
+	
+  /* Make sure we're frontmost. */
+  [NSApp activateIgnoringOtherApps:YES];
+	
+  msg = NSLocalizedString (@"Are you sure you want to quit X11?\n\nIf you quit X11, any X11 applications you are running will stop immediately and you will lose any changes you have not saved.", @"Dialog when quitting");
+	
+  /* FIXME: safe to run the alert in here? Or should we return Later
+     and then run the alert on a timer? It seems to work here, so.. */
+	
+  return (NSRunAlertPanel (nil, msg, NSLocalizedString (@"Quit", @""),
+			   NSLocalizedString (@"Cancel", @""), nil)
+	  == NSAlertDefaultReturn) ? NSTerminateNow : NSTerminateCancel;
+}
+
+- (void) applicationWillTerminate:(NSNotification *)aNotification
+{
+  [X11App prefs_synchronize];
+	
+  /* shutdown the X server, it will exit () for us. */
+  QuartzMessageServerThread (kXDarwinQuit, 0);
+	
+  /* In case it doesn't, exit anyway after a while. */
+  while (sleep (10) != 0) ;
+  exit (1);
+}
+
+- (void) server_ready
+{
+  x_list *node;
+	
+  finished_launching = YES;
+	
+  for (node = pending_apps; node != NULL; node = node->next)
+    {
+      NSString *filename = node->data;
+      [self launch_client:filename];
+      [filename release];
+    }
+	
+  x_list_free (pending_apps);
+  pending_apps = NULL;
+}
+
+- (BOOL) application:(NSApplication *)app openFile:(NSString *)filename
+{
+  const char *name = [filename UTF8String];
+	
+  if (finished_launching)
+    [self launch_client:filename];
+  else if (name[0] != ':')		/* ignore display names */
+    pending_apps = x_list_prepend (pending_apps, [filename retain]);
+	
+  /* FIXME: report failures. */
+  return YES;
+}
+
+ at end
+
+void X11ControllerMain (int argc, const char *argv[],
+			void (*server_thread) (void *), void *server_arg)
+{
+  X11ApplicationMain (argc, argv, server_thread, server_arg);
+}
diff --git a/hw/darwin/apple/Xquartz.man b/hw/darwin/apple/Xquartz.man
new file mode 100644
index 0000000..edac30e
--- /dev/null
+++ b/hw/darwin/apple/Xquartz.man
@@ -0,0 +1,158 @@
+.\" $XFree86: xc/programs/Xserver/hw/darwin/XDarwin.man,v 1.4 2002/01/09 18:01:58 torrey Exp $
+.\"
+.TH XQUARTZ 1 __vendorversion__
+.SH NAME
+Xquartz \- X window system server for Quartz operating system
+.SH SYNOPSIS
+.B Xquartz
+[ options ] ...
+.SH DESCRIPTION
+.I Xquartz
+is the X window server for Mac OS X provided by Apple.
+.I Xquartz
+runs in parallel with Aqua in rootless mode. In rootless mode, the X
+window system and Mac OS X share your display.  The root window of the
+X11 display is the size of the screen and contains all the other
+windows. The X11 root window is not displayed in rootless mode as Mac
+OS X handles the desktop background.
+.SH OPTIONS
+.PP
+In addition to the normal server options described in the \fIXserver(1)\fP
+manual page, \fIXquartz\fP accepts the following command line switches:
+.TP 8
+.B \-fakebuttons
+Emulates a 3 button mouse using modifier keys. By default, the Command modifier
+is used to emulate button 2 and Option is used for button 3. Thus, clicking the
+first mouse button while holding down Command will act like clicking
+button 2. Holding down Option will simulate button 3.
+.TP 8
+.B \-nofakebuttons
+Do not emulate a 3 button mouse. This is the default.
+.TP 8
+.B "\-fakemouse2 \fImodifiers\fP"
+Change the modifier keys used to emulate the second mouse button. By default,
+Command is used to emulate the second button. Any combination of the following
+modifier names may be used: Shift, Option, Control, Command, Fn. For example,
+.B \-fakemouse2 """Option,Shift""
+will set holding Option, Shift and clicking on button one as equivalent to
+clicking the second mouse button.
+.TP 8
+.B "\-fakemouse3 \fImodifiers\fP"
+Change the modifier keys used to emulate the third mouse button. By default,
+Option is used to emulate the third button. Any combination of the following
+modifier names may be used: Shift, Option, Control, Command, Fn. For example,
+.B \-fakemouse3 """Control,Shift""
+will set holding Control, Shift and clicking on button one as equivalent to
+clicking the third mouse button.
+.TP 8
+.B "\-swapAltMeta"
+Swaps the meaning of the Alt and Meta modifier keys.
+.TP 8
+.B "\-keymap \fIfile\fP"
+On startup \fIXquartz\fP translates a Darwin keymapping into an X keymap.
+The default is to read this keymapping from USA.keymapping. With this option
+the keymapping will be read from \fIfile\fP instead. If the file's path is
+not specified, it will be searched for in Library/Keyboards/ underneath the
+following directories (in order): ~, /, /Network, /System.
+.TP 8
+.B \-nokeymap
+On startup \fIXquartz\fP translates a Darwin keymapping into an X keymap.
+With this option \fIXquartz\fP queries the kernel for the current keymapping
+instead of reading it from a file. This will often fail on newer kernels.
+.TP 8
+.B "\-depth \fIdepth\fP"
+Specifies the color bit depth to use. Currently only 15, and 24 color
+bits per pixel are supported. If not specified, defaults to the depth
+of the main display.
+.SH CUSTOMIZATION
+\fIXquartz\fP can also be customized using the defaults(1) command. The available options are:
+.TP 8
+.B defaults write com.apple.x11 enable_fake_buttons -boolean true
+Equivalent to the \fB-fakebuttons\fP command line option.
+.TP 8
+.B defaults write com.apple.x11 fake_button2 \fImodifiers\fP
+Equivalent to the \fB-fakemouse2\fP option.
+.TP 8
+.B defaults write com.apple.x11 fake_button3 \fImodifiers\fP
+Equivalent to the \fB-fakemouse3\fP option.
+.TP 8
+.B defaults write com.apple.x11 swap_alt_meta -boolean true
+Equivalent to the \fB-swapAltMeta\fP option.
+.TP 8
+.B defaults write com.apple.x11 keymap_file \fIfilename\fP
+Equivalent to the \fB-keymap\fP option.
+.TP 8
+.B defaults write com.apple.x11 no_quit_alert -boolean true
+Disables the alert dialog displayed when attempting to quit X11.
+.TP 8
+.B defaults write com.apple.x11 no_auth -boolean true
+Stops the X server requiring that clients authenticate themselves when
+connecting. See Xsecurity(__miscmansuffix__).
+.TP 8
+.B defaults write com.apple.x11 nolisten_tcp -boolean true
+Prevents the X server accepting remote connections.
+.TP 8
+.B defaults write com.apple.x11 xinit_kills_server -boolean false
+Stops the X server exiting when the xinitrc script terminates.
+.TP 8
+.B defaults write com.apple.x11 fullscreen_hotkeys -boolean false
+Allows system hotkeys to be handled while in X11 fullscreen mode.
+.TP 8
+.B defaults write com.apple.x11 enable_system_beep -boolean false
+Don't use the standard system beep effect for X11 alerts.
+.TP 8
+.B defaults write com.apple.x11 enable_key_equivalents -boolean false
+Disable menu keyboard equivalents while X11 windows are focused.
+.TP 8
+.B defaults write com.apple.x11 depth \fIdepth\fP
+Equivalent to the \fB-depth\fP option.
+.SH "SEE ALSO"
+.PP
+X(__miscmansuffix__), XFree86(1), Xserver(1), xdm(1), xinit(1)
+.PP
+.SH AUTHORS
+XFree86 was originally ported to Mac OS X Server by John Carmack. Dave
+Zarzycki used this as the basis of his port of XFree86 4.0 to Darwin 1.0.
+Torrey T. Lyons improved and integrated this code into the XFree86
+Project's mainline for the 4.0.2 release.
+.PP
+The following members of the XonX Team contributed to the following
+releases (in alphabetical order):
+.TP 4
+XFree86 4.1.0:
+.br
+Rob Braun - Darwin x86 support
+.br
+Torrey T. Lyons - Project Lead
+.br
+Andreas Monitzer - Cocoa version of XDarwin front end
+.br
+Gregory Robert Parker - Original Quartz implementation
+.br
+Christoph Pfisterer - Dynamic shared X libraries
+.br
+Toshimitsu Tanaka - Japanese localization
+.TP 4
+XFree86 4.2.0:
+.br
+Rob Braun - Darwin x86 support
+.br
+Pablo Di Noto - Spanish localization
+.br
+Paul Edens - Dutch localization
+.br
+Kyunghwan Kim - Korean localization
+.br
+Mario Klebsch - Non-US keyboard support
+.br
+Torrey T. Lyons - Project Lead
+.br
+Andreas Monitzer - German localization
+.br
+Patrik Montgomery - Swedish localization
+.br
+Greg Parker - Rootless support
+.br
+Toshimitsu Tanaka - Japanese localization
+.br
+Olivier Verdier - French localization
diff --git a/hw/darwin/apple/bundle-main.c b/hw/darwin/apple/bundle-main.c
new file mode 100644
index 0000000..12fb1bf
--- /dev/null
+++ b/hw/darwin/apple/bundle-main.c
@@ -0,0 +1,911 @@
+/* bundle-main.c -- X server launcher
+ $Id: bundle-main.c,v 1.17 2003/09/11 00:17:10 jharper Exp $
+ 
+ Copyright (c) 2002-2007 Apple Inc. All rights reserved.
+ 
+ Permission is hereby granted, free of charge, to any person
+ obtaining a copy of this software and associated documentation files
+ (the "Software"), to deal in the Software without restriction,
+ including without limitation the rights to use, copy, modify, merge,
+ publish, distribute, sublicense, and/or sell copies of the Software,
+ and to permit persons to whom the Software is furnished to do so,
+ subject to the following conditions:
+ 
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+ 
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT.  IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT
+ HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ DEALINGS IN THE SOFTWARE.
+ 
+ Except as contained in this notice, the name(s) of the above
+ copyright holders shall not be used in advertising or otherwise to
+ promote the sale, use or other dealings in this Software without
+ prior written authorization.
+ 
+ Parts of this file are derived from xdm, which has this copyright:
+ 
+ Copyright 1988, 1998  The Open Group
+ 
+ Permission to use, copy, modify, distribute, and sell this software
+ and its documentation for any purpose is hereby granted without fee,
+ provided that the above copyright notice appear in all copies and
+ that both that copyright notice and this permission notice appear in
+ supporting documentation.
+ 
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+ 
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ 
+ Except as contained in this notice, the name of The Open Group shall
+ not be used in advertising or otherwise to promote the sale, use or
+ other dealings in this Software without prior written authorization
+ from The Open Group. */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <sys/socket.h>
+#include <sys/utsname.h>
+#include <ifaddrs.h>
+#include <netdb.h>
+#include <netinet/in.h>
+#include <time.h>
+#include <sys/wait.h>
+#include <setjmp.h>
+#include <sys/ioctl.h>
+
+#include <X11/Xlib.h>
+#include <X11/Xauth.h>
+
+#include <CoreFoundation/CoreFoundation.h>
+#include <SystemConfiguration/SystemConfiguration.h>
+
+#define X_SERVER "/usr/X11/bin/Xquartz"
+#define XTERM_PATH "/usr/X11/bin/xterm"
+#define WM_PATH "/usr/X11/bin/quartz-wm"
+#define DEFAULT_XINITRC "/etc/X11/xinit/xinitrc"
+#define DEFAULT_PATH "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/X11/bin"
+
+/* what xinit does */
+#ifndef SHELL
+# define SHELL "sh"
+#endif
+
+#undef FALSE
+#define FALSE 0
+#undef TRUE
+#define TRUE 1
+
+#define MAX_DISPLAYS 64
+
+static int server_pid = -1, client_pid = -1;
+static int xinit_kills_server = FALSE;
+static jmp_buf exit_continuation;
+static const char *server_name = NULL;
+static Display *server_dpy;
+
+static char *auth_file;
+
+typedef struct addr_list_struct addr_list;
+
+struct addr_list_struct {
+    addr_list *next;
+    Xauth auth;
+};
+
+static addr_list *addresses;
+
+
+/* Utility functions. */
+
+/* Return the current host name. Matches what Xlib does. */
+static char *
+host_name (void)
+{
+#ifdef NEED_UTSNAME
+    static struct utsname name;
+	
+    uname(&name);
+	
+    return name.nodename;
+#else
+    static char buf[100];
+	
+    gethostname(buf, sizeof(buf));
+	
+    return buf;
+#endif
+}
+
+static int
+read_boolean_pref (CFStringRef name, int default_)
+{
+    int value;
+    Boolean ok;
+	
+    value = CFPreferencesGetAppBooleanValue (name,
+											 CFSTR ("com.apple.x11"), &ok);
+    return ok ? value : default_;
+}
+
+static inline int
+binary_equal (const void *a, const void *b, int length)
+{
+    return memcmp (a, b, length) == 0;
+}
+
+static inline void *
+binary_dup (const void *a, int length)
+{
+    void *b = malloc (length);
+    if (b != NULL)
+		memcpy (b, a, length);
+    return b;
+}
+
+static inline void
+binary_free (void *data, int length)
+{
+    if (data != NULL)
+		free (data);
+}
+
+
+/* Functions for managing the authentication entries. */
+
+/* Returns true if something matching AUTH is in our list of auth items */
+static int
+check_auth_item (Xauth *auth)
+{
+    addr_list *a;
+	
+    for (a = addresses; a != NULL; a = a->next)
+    {
+		if (a->auth.family == auth->family
+			&& a->auth.address_length == auth->address_length
+			&& binary_equal (a->auth.address, auth->address, auth->address_length)
+			&& a->auth.number_length == auth->number_length
+			&& binary_equal (a->auth.number, auth->number, auth->number_length)
+			&& a->auth.name_length == auth->name_length
+			&& binary_equal (a->auth.name, auth->name, auth->name_length))
+		{
+			return TRUE;
+		}
+    }
+	
+    return FALSE;
+}
+
+/* Add one item to our list of auth items. */
+static void
+add_auth_item (Xauth *auth)
+{
+    addr_list *a = malloc (sizeof (addr_list));
+	
+    a->auth.family = auth->family;
+    a->auth.address_length = auth->address_length;
+    a->auth.address = binary_dup (auth->address, auth->address_length);
+    a->auth.number_length = auth->number_length;
+    a->auth.number = binary_dup (auth->number, auth->number_length);
+    a->auth.name_length = auth->name_length;
+    a->auth.name = binary_dup (auth->name, auth->name_length);
+    a->auth.data_length = auth->data_length;
+    a->auth.data = binary_dup (auth->data, auth->data_length);
+	
+    a->next = addresses;
+    addresses = a;
+}
+
+/* Free all allocated auth items. */
+static void
+free_auth_items (void)
+{
+    addr_list *a;
+	
+    while ((a = addresses) != NULL)
+    {
+		addresses = a->next;
+		
+		binary_free (a->auth.address, a->auth.address_length);
+		binary_free (a->auth.number, a->auth.number_length);
+		binary_free (a->auth.name, a->auth.name_length);
+		binary_free (a->auth.data, a->auth.data_length);
+		free (a);
+    }
+}
+
+/* Add the unix domain auth item. */
+static void
+define_local (Xauth *auth)
+{
+    char *host = host_name ();
+	
+#ifdef DEBUG
+    fprintf (stderr, "x11: hostname is %s\n", host);
+#endif
+	
+    auth->family = FamilyLocal;
+    auth->address_length = strlen (host);
+    auth->address = host;
+	
+    add_auth_item (auth);
+}
+
+/* Add the tcp auth item. */
+static void
+define_named (Xauth *auth, const char *name)
+{
+    struct ifaddrs *addrs, *ptr;
+	
+    if (getifaddrs (&addrs) != 0)
+		return;
+	
+    for (ptr = addrs; ptr != NULL; ptr = ptr->ifa_next)
+    {
+		if (ptr->ifa_addr->sa_family != AF_INET)
+			continue;
+		
+		auth->family = FamilyInternet;
+		auth->address_length = sizeof (struct in_addr);
+		auth->address = (char *) &(((struct sockaddr_in *) ptr->ifa_addr)->sin_addr);
+		
+#ifdef DEBUG
+		fprintf (stderr, "x11: ipaddr is %d.%d.%d.%d\n",
+				 (unsigned char) auth->address[0],
+				 (unsigned char) auth->address[1],
+				 (unsigned char) auth->address[2],
+				 (unsigned char) auth->address[3]);
+#endif
+		
+		add_auth_item (auth);
+    }
+	
+    freeifaddrs (addrs);
+}
+
+/* Parse the display number from NAME and add it to AUTH. */
+static void
+set_auth_number (Xauth *auth, const char *name)
+{
+    char *colon;
+    char *dot, *number;
+	
+    colon = strrchr(name, ':');
+    if (colon != NULL)
+    {
+		colon++;
+		dot = strchr(colon, '.');
+		
+		if (dot != NULL)
+			auth->number_length = dot - colon;
+		else
+			auth->number_length = strlen (colon);
+		
+		number = malloc (auth->number_length + 1);
+		if (number != NULL)
+		{
+			strncpy (number, colon, auth->number_length);
+			number[auth->number_length] = '\0';
+		}
+		else
+		{
+			auth->number_length = 0;
+		}
+		
+		auth->number = number;
+    }
+}
+
+/* Put 128 bits of random data into DATA. If possible, it will be "high
+ quality" */
+static int
+generate_mit_magic_cookie (char data[16])
+{
+    int fd, ret, i;
+    long *ldata = (long *) data;
+	
+    fd = open ("/dev/random", O_RDONLY);
+    if (fd > 0) {
+		ret = read (fd, data, 16);
+		close (fd);
+		if (ret == 16) return TRUE;
+    }
+	
+    /* fall back to the usual crappy rng */
+	
+    srand48 (getpid () ^ time (NULL));
+	
+    for (i = 0; i < 4; i++)
+		ldata[i] = lrand48 ();
+	
+    return TRUE;
+}
+
+/* Create the keys we'll be using for the display named NAME. */
+static int
+make_auth_keys (const char *name)
+{
+    Xauth auth;
+    char key[16];
+	
+    if (auth_file == NULL)
+		return FALSE;
+	
+    auth.name = "MIT-MAGIC-COOKIE-1";
+    auth.name_length = strlen (auth.name);
+	
+    if (!generate_mit_magic_cookie (key))
+    {
+		auth_file = NULL;
+		return FALSE;
+    }
+	
+    auth.data = key;
+    auth.data_length = 16;
+	
+    set_auth_number (&auth, name);
+	
+    define_named (&auth, host_name ());
+    define_local (&auth);
+	
+    free (auth.number);
+	
+    return TRUE;
+}
+
+/* If ADD-ENTRIES is true, merge our auth entries into the existing
+ Xauthority file. If ADD-ENTRIES is false, remove our entries. */
+static int
+write_auth_file (int add_entries)
+{
+    char *home, newname[1024];
+    int fd, ret;
+    FILE *new_fh, *old_fh;
+    addr_list *addr;
+    Xauth *auth;
+	
+    if (auth_file == NULL)
+		return FALSE;
+	
+    home = getenv ("HOME");
+    if (home == NULL)
+    {
+		auth_file = NULL;
+		return FALSE;
+    }
+	
+    snprintf (newname, sizeof (newname), "%s/.XauthorityXXXXXX", home);
+    mktemp (newname);
+	
+    if (XauLockAuth (auth_file, 1, 2, 10) != LOCK_SUCCESS)
+    {
+		/* FIXME: do something here? */
+		
+		auth_file = NULL;
+		return FALSE;
+    }
+	
+    fd = open (newname, O_WRONLY | O_CREAT | O_TRUNC, 0600);
+    if (fd >= 0)
+    {
+		new_fh = fdopen (fd, "w");
+		if (new_fh != NULL)
+		{
+			if (add_entries)
+			{
+				for (addr = addresses; addr != NULL; addr = addr->next)
+				{
+					XauWriteAuth (new_fh, &addr->auth);
+				}
+			}
+			
+			old_fh = fopen (auth_file, "r");
+			if (old_fh != NULL)
+			{
+				while ((auth = XauReadAuth (old_fh)) != NULL)
+				{
+					if (!check_auth_item (auth))
+						XauWriteAuth (new_fh, auth);
+					XauDisposeAuth (auth);
+				}
+				fclose (old_fh);
+			}
+			
+			fclose (new_fh);
+			unlink (auth_file);
+			
+			ret = rename (newname, auth_file);
+			
+			if (ret != 0)
+				auth_file = NULL;
+			
+			XauUnlockAuth (auth_file);
+			return ret == 0;
+		}
+		
+		close (fd);
+    }
+	
+    XauUnlockAuth (auth_file);
+    auth_file = NULL;
+    return FALSE;
+}
+
+
+/* Subprocess management functions. */
+
+static int
+start_server (char **xargv)
+{
+    int child;
+	
+    child = fork ();
+	
+    switch (child)
+    {
+    case -1:				/* error */
+		perror ("fork");
+		return FALSE;
+		
+    case 0:				/* child */
+		execv (X_SERVER, xargv);
+		perror ("Couldn't exec " X_SERVER);
+		_exit (1);
+		
+    default:				/* parent */
+		server_pid = child;
+		return TRUE;
+    }
+}
+
+static int
+wait_for_server (void)
+{
+    int count = 100;
+	
+    while (count-- > 0)
+    {
+		int status;
+		
+		server_dpy = XOpenDisplay (server_name);
+		if (server_dpy != NULL)
+			return TRUE;
+		
+		if (waitpid (server_pid, &status, WNOHANG) == server_pid)
+			return FALSE;
+		
+		sleep (1);
+    }
+	
+    return FALSE;
+}
+
+static int
+start_client (void)
+{
+    int child;
+	
+    child = fork();
+	
+    switch (child) {
+		char *temp, buf[1024];		
+
+	case -1:				/* error */
+		perror("fork");
+		return FALSE;
+
+	case 0:					/* child */
+		/* Setup environment */
+		temp = getenv("DISPLAY");
+		if (temp != NULL && temp[0] != 0)
+			setenv("DISPLAY", server_name, TRUE);
+
+		temp = getenv("PATH");
+		if (temp == NULL || temp[0] == 0) 
+			setenv ("PATH", DEFAULT_PATH, TRUE);
+		else if (strnstr(temp, "/usr/X11/bin", sizeof(temp)) == NULL) {
+			snprintf(buf, sizeof(buf), "%s:/usr/X11/bin", temp);		
+			setenv("PATH", buf, TRUE);	
+		}
+		
+		/* First try value of $XINITRC, if set. */
+		temp = getenv("XINITRC");
+		if (temp != NULL && temp[0] != 0 && access(temp, R_OK) == 0)
+			execlp (SHELL, SHELL, temp, NULL);
+
+		/* Then look for .xinitrc in user's home directory. */
+		temp = getenv("HOME");
+		if (temp != NULL && temp[0] != 0) {
+			chdir(temp);
+			snprintf (buf, sizeof (buf), "%s/.xinitrc", temp);
+			if (access(buf, R_OK) == 0)
+				execlp(SHELL, SHELL, buf, NULL);
+		}
+		
+		/* Then try the default xinitrc in the lib directory. */
+		
+		if (access(DEFAULT_XINITRC, R_OK) == 0)
+			execlp(SHELL, SHELL, DEFAULT_XINITRC, NULL);
+		
+		/* Then fallback to hardcoding an xterm and the window manager. */
+		
+		//		system(XTERM_PATH " &");
+		execl(WM_PATH, WM_PATH, NULL);
+		
+		perror("exec");
+		_exit(1);
+		
+    default:				/* parent */
+		client_pid = child;
+		return TRUE;
+    }
+}
+
+static void
+sigchld_handler (int sig)
+{
+    int pid, status;
+	
+	again:
+    pid = waitpid (WAIT_ANY, &status, WNOHANG);
+	
+    if (pid > 0)
+    {
+		if (pid == server_pid)
+		{
+			server_pid = -1;
+			
+			if (client_pid >= 0)
+				kill (client_pid, SIGTERM);
+		}
+		else if (pid == client_pid)
+		{
+			client_pid = -1;
+			
+			if (server_pid >= 0 && xinit_kills_server)
+				kill (server_pid, SIGTERM);
+		}
+		goto again;
+    }
+	
+    if (server_pid == -1 && client_pid == -1)
+		longjmp (exit_continuation, 1);
+	
+    signal (SIGCHLD, sigchld_handler);
+}
+
+
+/* Server utilities. */
+
+static Boolean
+display_exists_p (int number)
+{
+    char buf[64];
+    void *conn;
+    char *fullname = NULL;
+    int idisplay, iscreen;
+    char *conn_auth_name, *conn_auth_data;
+    int conn_auth_namelen, conn_auth_datalen;
+	
+    extern void *_X11TransConnectDisplay ();
+    extern void _XDisconnectDisplay ();
+	
+    /* Since connecting to the display waits for a few seconds if the
+	 display doesn't exist, check for trivial non-existence - if the
+	 socket in /tmp exists or not.. (note: if the socket exists, the
+	 server may still not, so we need to try to connect in that case..) */
+	
+    sprintf (buf, "/tmp/.X11-unix/X%d", number);
+    if (access (buf, F_OK) != 0)
+		return FALSE;
+	
+    /* This is a private function that we shouldn't really be calling,
+	 but it's the best way to see if the server exists (without
+	 needing to hold the necessary authentication to use it) */
+	
+    sprintf (buf, ":%d", number);
+    conn = _X11TransConnectDisplay (buf, &fullname, &idisplay, &iscreen,
+									&conn_auth_name, &conn_auth_namelen,
+									&conn_auth_data, &conn_auth_datalen);
+    if (conn == NULL)
+		return FALSE;
+	
+    _XDisconnectDisplay (conn);
+    return TRUE;
+}
+
+
+/* Monitoring when the system's ip addresses change. */
+
+static Boolean pending_timer;
+
+static void
+timer_callback (CFRunLoopTimerRef timer, void *info)
+{
+    pending_timer = FALSE;
+	
+    /* Update authentication names. Need to write .Xauthority file first
+	 without the existing entries, then again with the new entries.. */
+	
+    write_auth_file (FALSE);
+	
+    free_auth_items ();
+    make_auth_keys (server_name);
+	
+    write_auth_file (TRUE);
+}
+
+/* This function is called when the system's ip addresses may have changed. */
+static void
+ipaddr_callback (SCDynamicStoreRef store, CFArrayRef changed_keys, void *info)
+{
+#if DEBUG
+    if (changed_keys != NULL) {
+		fprintf (stderr, "x11: changed sc keys: ");
+		CFShow (changed_keys);
+    }
+#endif
+
+    if (auth_file != NULL && !pending_timer)
+    {
+		CFRunLoopTimerRef timer;
+		
+		timer = CFRunLoopTimerCreate (NULL, CFAbsoluteTimeGetCurrent () + 1.0,
+									  0.0, 0, 0, timer_callback, NULL);
+		CFRunLoopAddTimer (CFRunLoopGetCurrent (), timer,
+						   kCFRunLoopDefaultMode);
+		CFRelease (timer);
+		
+		pending_timer = TRUE;
+    }
+}
+
+/* This code adapted from "Living in a Dynamic TCP/IP Environment" technote. */
+static Boolean
+install_ipaddr_source (void)
+{
+    CFRunLoopSourceRef source = NULL;
+	
+    SCDynamicStoreContext context = {0};
+    SCDynamicStoreRef ref;
+	
+    ref = SCDynamicStoreCreate (NULL,
+								CFSTR ("AddIPAddressListChangeCallbackSCF"),
+								ipaddr_callback, &context);
+	
+    if (ref != NULL)
+    {
+		const void *keys[4], *patterns[2];
+		int i;
+		
+		keys[0] = SCDynamicStoreKeyCreateNetworkGlobalEntity (NULL, kSCDynamicStoreDomainState, kSCEntNetIPv4);
+		keys[1] = SCDynamicStoreKeyCreateNetworkGlobalEntity (NULL, kSCDynamicStoreDomainState, kSCEntNetIPv6);
+		keys[2] = SCDynamicStoreKeyCreateComputerName (NULL);
+		keys[3] = SCDynamicStoreKeyCreateHostNames (NULL);
+		
+		patterns[0] = SCDynamicStoreKeyCreateNetworkInterfaceEntity (NULL, kSCDynamicStoreDomainState, kSCCompAnyRegex, kSCEntNetIPv4);
+		patterns[1] = SCDynamicStoreKeyCreateNetworkInterfaceEntity (NULL, kSCDynamicStoreDomainState, kSCCompAnyRegex, kSCEntNetIPv6);
+		
+		if (keys[0] != NULL && keys[1] != NULL && keys[2] != NULL
+			&& keys[3] != NULL && patterns[0] != NULL && patterns[1] != NULL)
+		{
+			CFArrayRef key_array, pattern_array;
+			
+			key_array = CFArrayCreate (NULL, keys, 4, &kCFTypeArrayCallBacks);
+			pattern_array = CFArrayCreate (NULL, patterns, 2, &kCFTypeArrayCallBacks);
+			
+			if (key_array != NULL || pattern_array != NULL)
+			{
+				SCDynamicStoreSetNotificationKeys (ref, key_array, pattern_array);
+				source = SCDynamicStoreCreateRunLoopSource (NULL, ref, 0);
+			}
+			
+			if (key_array != NULL)
+				CFRelease (key_array);
+			if (pattern_array != NULL)
+				CFRelease (pattern_array);
+		}
+		
+		
+		for (i = 0; i < 4; i++)
+			if (keys[i] != NULL)
+			CFRelease (keys[i]);
+		for (i = 0; i < 2; i++)
+			if (patterns[i] != NULL)
+			CFRelease (patterns[i]);
+		
+		CFRelease (ref); 
+    }
+	
+    if (source != NULL)
+    {
+		CFRunLoopAddSource (CFRunLoopGetCurrent (),
+							source, kCFRunLoopDefaultMode);
+		CFRelease (source);
+    }
+	
+    return source != NULL;
+}
+
+
+/* Entrypoint. */
+
+void
+termination_signal_handler (int unused_sig)
+{
+    signal (SIGTERM, SIG_DFL);
+    signal (SIGHUP, SIG_DFL);
+    signal (SIGINT, SIG_DFL);
+    signal (SIGQUIT, SIG_DFL);
+
+    longjmp (exit_continuation, 1);
+}
+
+int
+main (int argc, char **argv)
+{
+    char **xargv;
+    int i, j;
+    int fd;
+	
+    xargv = alloca (sizeof (char *) * (argc + 32));
+	
+    if (!read_boolean_pref (CFSTR ("no_auth"), FALSE))
+		auth_file = XauFileName ();
+	
+    /* The standard X11 behaviour is for the server to quit when the first
+	 client exits. But it can be useful for debugging (and to mimic our
+	 behaviour in the beta releases) to not do that. */
+	
+    xinit_kills_server = read_boolean_pref (CFSTR ("xinit_kills_server"), TRUE);
+	
+    for (i = 1; i < argc; i++)
+    {
+		if (argv[i][0] == ':')
+			server_name = argv[i];
+    }
+	
+    if (server_name == NULL)
+    {
+		static char name[8];
+		
+		/* No display number specified, so search for the first unused.
+		 
+		 There's a big old race condition here if two servers start at
+		 the same time, but that's fairly unlikely. We could create
+		 lockfiles or something, but that's seems more likely to cause
+		 problems than the race condition itself.. */
+		
+		for (i = 0; i < MAX_DISPLAYS; i++)
+		{
+			if (!display_exists_p (i))
+				break;
+		}
+		
+		if (i == MAX_DISPLAYS)
+		{
+			fprintf (stderr, "%s: couldn't allocate a display number", argv[0]);
+			exit (1);
+		}
+		
+		sprintf (name, ":%d", i);
+		server_name = name;
+    }
+	
+    if (auth_file != NULL)
+    {
+		/* Create new Xauth keys and add them to the .Xauthority file */
+		
+		make_auth_keys (server_name);
+		write_auth_file (TRUE);
+    }
+	
+    /* Construct our new argv */
+	
+    i = j = 0;
+	
+    xargv[i++] = argv[j++];
+	
+    if (auth_file != NULL)
+    {
+		xargv[i++] = "-auth";
+		xargv[i++] = auth_file;
+    }
+	
+    /* By default, don't listen on tcp sockets if Xauth is disabled. */
+	
+    if (read_boolean_pref (CFSTR ("nolisten_tcp"), auth_file == NULL))
+    {
+		xargv[i++] = "-nolisten";
+		xargv[i++] = "tcp";
+    }
+	
+    while (j < argc)
+    {
+		if (argv[j++][0] != ':')
+			xargv[i++] = argv[j-1];
+    }
+	
+    xargv[i++] = (char *) server_name;
+    xargv[i++] = NULL;
+	
+    /* Detach from any controlling terminal and connect stdin to /dev/null */
+	
+#ifdef TIOCNOTTY
+    fd = open ("/dev/tty", O_RDONLY);
+    if (fd != -1)
+    {
+		ioctl (fd, TIOCNOTTY, 0);
+		close (fd);
+    }
+#endif
+	
+    fd = open ("/dev/null", O_RDWR, 0);
+    if (fd >= 0)
+    {
+		dup2 (fd, 0);
+		if (fd > 0)
+			close (fd);
+    }
+	
+    if (!start_server (xargv))
+		return 1;
+	
+    if (!wait_for_server ())
+    {
+		kill (server_pid, SIGTERM);
+		return 1;
+    }
+	
+    if (!start_client ())
+    {
+		kill (server_pid, SIGTERM);
+		return 1;
+    }
+	
+    signal (SIGCHLD, sigchld_handler);
+	
+    signal (SIGTERM, termination_signal_handler);
+    signal (SIGHUP, termination_signal_handler);
+    signal (SIGINT, termination_signal_handler);
+    signal (SIGQUIT, termination_signal_handler);
+
+    if (setjmp (exit_continuation) == 0)
+    {
+		if (install_ipaddr_source ())
+			CFRunLoopRun ();
+		else
+			while (1) pause ();
+    }
+	
+    signal (SIGCHLD, SIG_IGN);
+
+    if (client_pid >= 0) kill (client_pid, SIGTERM);
+    if (server_pid >= 0) kill (server_pid, SIGTERM);
+	
+    if (auth_file != NULL)
+    {
+		/* Remove our Xauth keys */
+		
+		write_auth_file (FALSE);
+    }
+	
+    free_auth_items ();
+	
+    return 0;
+}
diff-tree a16360733ea393ec1fc267e88fc604d9d7534484 (from 566610680c4e1cab3e7fc7146adbeaba52fdd0ad)
Author: Jay Estabrook <Jay.Estabrook at hp.com>
Date:   Sun Feb 25 19:58:26 2007 +0000

    Fix root bus/domain selection on alpha

diff --git a/hw/xfree86/os-support/bus/axpPci.c b/hw/xfree86/os-support/bus/axpPci.c
index 9acc4ab..fc16a51 100644
--- a/hw/xfree86/os-support/bus/axpPci.c
+++ b/hw/xfree86/os-support/bus/axpPci.c
@@ -217,7 +217,8 @@ axpPciInit()
 	 * only set up the root bus for each domain (hose) and the bridged 
 	 * buses will be set up as they are found.
 	 */
-	bus = PCI_MAKE_BUS(domain, 0);
+	/* make a bus with both the domain and the root bus in it */
+	bus = PCI_MAKE_BUS(domain, pDomain->root_bus);
 	pciBusInfo[bus] = xnfalloc(sizeof(pciBusInfo_t));
 	(void)memset(pciBusInfo[bus], 0, sizeof(pciBusInfo_t));
 
@@ -249,7 +250,7 @@ axpPciBusFromTag(PCITAG tag)
 	|| !(pDomain = pBusInfo->pciBusPriv)
 	|| (pDomain->domain != PCI_DOM_FROM_TAG(tag))) return -1;
 
-    bus = PCI_BUS_NO_DOMAIN(bus) + pDomain->root_bus;
+    bus = PCI_BUS_NO_DOMAIN(bus); /* should just be root_bus */
     dfn = PCI_DFN_FROM_TAG(tag);
     if (_iobase(IOBASE_HOSE, -1, bus, dfn) != pDomain->hose) return -1;
 
diff-tree 566610680c4e1cab3e7fc7146adbeaba52fdd0ad (from af550ea91c451cf4f831c2413266a19d1f211d0e)
Author: Adam Jackson <ajax at benzedrine.nwnk.net>
Date:   Fri Feb 23 15:20:35 2007 -0500

    Don't install libi2c.a

diff --git a/hw/xfree86/i2c/Makefile.am b/hw/xfree86/i2c/Makefile.am
index 70a9ace..a16d880 100644
--- a/hw/xfree86/i2c/Makefile.am
+++ b/hw/xfree86/i2c/Makefile.am
@@ -1,4 +1,4 @@
-module_LIBRARIES = libi2c.a
+noinst_LIBRARIES = libi2c.a
 
 multimediadir = $(moduledir)/multimedia
 multimedia_LTLIBRARIES =	\
diff-tree af550ea91c451cf4f831c2413266a19d1f211d0e (from b1142cdbce76fed8cb22ba6d7ac027751dd56a76)
Author: Alan Coopersmith <alan.coopersmith at sun.com>
Date:   Thu Feb 22 14:38:40 2007 -0800

    Move SecurityPolicy file format from Xserver(1) to it's own man page
    
    Don't make users looking for Xserver information page through pages of
    details only interesting to the handful of people writing security policies.

diff --git a/doc/Makefile.am b/doc/Makefile.am
index 0ac533e..ce1979d 100644
--- a/doc/Makefile.am
+++ b/doc/Makefile.am
@@ -1,25 +1,35 @@
 appmandir = $(APP_MAN_DIR)
+filemandir = $(FILE_MAN_DIR)
 
 # Xserver.man covers options generic to all X servers built in this tree
+# (i.e. those handled in the os/utils.c options processing instead of in
+#  the DDX-level options processing)
 appman_PRE = Xserver.man.pre
+fileman_PRE = SecurityPolicy.man.pre
 
 appman_PROCESSED = $(appman_PRE:man.pre=man)
+fileman_PROCESSED = $(fileman_PRE:man.pre=man)
 
 appman_DATA = $(appman_PRE:man.pre=@APP_MAN_SUFFIX@)
+fileman_DATA = $(fileman_PRE:man.pre=@FILE_MAN_SUFFIX@)
 
-BUILT_SOURCES = $(appman_PROCESSED)
+BUILT_SOURCES = $(appman_PROCESSED) $(fileman_PROCESSED)
 
-CLEANFILES = $(appman_PROCESSED) $(appman_DATA)
+CLEANFILES = $(appman_PROCESSED) $(appman_DATA) \
+		$(fileman_PROCESSED) $(fileman_DATA)
 
 include $(top_srcdir)/cpprules.in
 
 .man.$(APP_MAN_SUFFIX):
 	cp $< $@
 
+.man.$(FILE_MAN_SUFFIX):
+	cp $< $@
+
 EXTRAMANDEFS = -D__default_font_path__="`echo $(COMPILEDDEFAULTFONTPATH) | sed -e 's/,/, /g'`"
 
 # Docs about X server internals that we ship with source but don't install
 DEVEL_DOCS = smartsched
 
 
-EXTRA_DIST = $(DEVEL_DOCS) $(appman_PRE)
+EXTRA_DIST = $(DEVEL_DOCS) $(appman_PRE) $(fileman_PRE)
diff --git a/doc/SecurityPolicy.man.pre b/doc/SecurityPolicy.man.pre
new file mode 100644
index 0000000..f5aff0c
--- /dev/null
+++ b/doc/SecurityPolicy.man.pre
@@ -0,0 +1,258 @@
+.\" Split out of Xserver.man, which was covered by this notice:
+.\" Copyright 1984 - 1991, 1993, 1994, 1998  The Open Group
+.\"
+.\" Permission to use, copy, modify, distribute, and sell this software and its
+.\" documentation for any purpose is hereby granted without fee, provided that
+.\" the above copyright notice appear in all copies and that both that
+.\" copyright notice and this permission notice appear in supporting
+.\" documentation.
+.\"
+.\" The above copyright notice and this permission notice shall be included
+.\" in all copies or substantial portions of the Software.
+.\"
+.\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+.\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+.\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+.\" IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
+.\" OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+.\" ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+.\" OTHER DEALINGS IN THE SOFTWARE.
+.\"
+.\" Except as contained in this notice, the name of The Open Group shall
+.\" not be used in advertising or otherwise to promote the sale, use or
+.\" other dealings in this Software without prior written authorization
+.\" from The Open Group.
+.\" $XFree86: xc/programs/Xserver/Xserver.man,v 3.31 2004/01/10 22:27:46 dawes Exp $
+.\" shorthand for double quote that works everywhere.
+.ds q \N'34'
+.TH SecurityPolicy __filemansuffix__ __xorgversion__
+.SH NAME
+SecurityPolicy \- X Window System SECURITY Extension Policy file format
+.SH DESCRIPTION
+The SECURITY extension to the X Window System uses a policy file to determine
+which operations should be allowed or denied.   The default location for this
+file is
+.IR __projectroot__/lib/xserver/SecurityPolicy .
+.PP
+The syntax of the security policy file is as follows.
+Notation: "*" means zero or more occurrences of the preceding element,
+and "+" means one or more occurrences.  To interpret <foo/bar>, ignore
+the text after the /; it is used to distinguish between instances of
+<foo> in the next section.
+.PP
+.nf
+<policy file> ::= <version line> <other line>*
+
+<version line> ::= <string/v> '\en'
+
+<other line > ::= <comment> | <access rule> | <site policy> | <blank line>
+
+<comment> ::= # <not newline>* '\en'
+
+<blank line> ::= <space> '\en'
+
+<site policy> ::= sitepolicy <string/sp> '\en'
+
+<access rule> ::= property <property/ar> <window> <perms> '\en'
+
+<property> ::= <string>
+
+<window> ::= any | root | <required property>
+
+<required property> ::= <property/rp> | <property with value>
+
+<property with value> ::= <property/rpv> = <string/rv>
+
+<perms> ::= [ <operation> | <action> | <space> ]*
+
+<operation> ::= r | w | d
+
+<action> ::= a | i | e
+
+<string> ::= <dbl quoted string> | <single quoted string> | <unquoted string>
+
+<dbl quoted string> ::= <space> " <not dquote>* " <space>
+
+<single quoted string> ::= <space> ' <not squote>* ' <space>
+
+<unquoted string> ::= <space> <not space>+ <space>
+
+<space> ::= [ ' ' | '\et' ]*
+
+Character sets:
+
+<not newline> ::= any character except '\en'
+<not dquote>  ::= any character except "
+<not squote>  ::= any character except '
+<not space>   ::= any character except those in <space>
+.fi
+.PP
+The semantics associated with the above syntax are as follows.
+.PP
+<version line>, the first line in the file, specifies the file format
+version.  If the server does not recognize the version <string/v>, it
+ignores the rest of the file.  The version string for the file format
+described here is "version-1" .
+.PP
+Once past the <version line>, lines that do not match the above syntax
+are ignored.
+.PP
+<comment> lines are ignored.
+.PP
+<sitepolicy> lines are currently ignored.  They are intended to
+specify the site policies used by the XC-QUERY-SECURITY-1
+authorization method.
+.PP
+<access rule> lines specify how the server should react to untrusted
+client requests that affect the X Window property named <property/ar>.
+The rest of this section describes the interpretation of an
+<access rule>.
+.PP
+For an <access rule> to apply to a given instance of <property/ar>,
+<property/ar> must be on a window that is in the set of windows
+specified by <window>.  If <window> is any, the rule applies to
+<property/ar> on any window.  If <window> is root, the rule applies to
+<property/ar> only on root windows.
+.PP
+If <window> is <required property>, the following apply.  If <required
+property> is a <property/rp>, the rule applies when the window also
+has that <property/rp>, regardless of its value.  If <required
+property> is a <property with value>, <property/rpv> must also have
+the value specified by <string/rv>.  In this case, the property must
+have type STRING and format 8, and should contain one or more
+null-terminated strings.  If any of the strings match <string/rv>, the
+rule applies.
+.PP
+The definition of string matching is simple case-sensitive string
+comparison with one elaboration: the occurrence of the character '*' in
+<string/rv> is a wildcard meaning "any string."  A <string/rv> can
+contain multiple wildcards anywhere in the string.  For example, "x*"
+matches strings that begin with x, "*x" matches strings that end with
+x, "*x*" matches strings containing x, and "x*y*" matches strings that
+start with x and subsequently contain y.
+.PP
+There may be multiple <access rule> lines for a given <property/ar>.
+The rules are tested in the order that they appear in the file.  The
+first rule that applies is used.
+.PP
+<perms> specify operations that untrusted clients may attempt, and
+the actions that the server should take in response to those operations.
+.PP
+<operation> can be r (read), w (write), or d (delete).  The following
+table shows how X Protocol property requests map to these operations
+in the X.Org server implementation.
+.PP
+.nf
+GetProperty	r, or r and d if delete = True
+ChangeProperty	w
+RotateProperties	r and w
+DeleteProperty	d
+ListProperties	none, untrusted clients can always list all properties
+.fi
+.PP
+<action> can be a (allow), i (ignore), or e (error).  Allow means
+execute the request as if it had been issued by a trusted client.
+Ignore means treat the request as a no-op.  In the case of
+GetProperty, ignore means return an empty property value if the
+property exists, regardless of its actual value.  Error means do not
+execute the request and return a BadAtom error with the atom set to
+the property name.  Error is the default action for all properties,
+including those not listed in the security policy file.
+.PP
+An <action> applies to all <operation>s that follow it, until the next
+<action> is encountered.  Thus, irwad  means ignore read and write,
+allow delete.
+.PP
+GetProperty and RotateProperties may do multiple operations (r and d,
+or r and w).  If different actions apply to the operations, the most
+severe action is applied to the whole request; there is no partial
+request execution.  The severity ordering is: allow < ignore < error.
+Thus, if the <perms> for a property are ired (ignore read, error
+delete), and an untrusted client attempts GetProperty on that property
+with delete = True, an error is returned, but the property value is
+not.  Similarly, if any of the properties in a RotateProperties do not
+allow both read and write, an error is returned without changing any
+property values.
+.PP
+Here is an example security policy file.
+.PP
+.ta 3i 4i
+.nf
+version-1
+
+XCOMM Allow reading of application resources, but not writing.
+property RESOURCE_MANAGER	root	ar iw
+property SCREEN_RESOURCES	root	ar iw
+
+XCOMM Ignore attempts to use cut buffers.  Giving errors causes apps to crash,
+XCOMM and allowing access may give away too much information.
+property CUT_BUFFER0	root	irw
+property CUT_BUFFER1	root	irw
+property CUT_BUFFER2	root	irw
+property CUT_BUFFER3	root	irw
+property CUT_BUFFER4	root	irw
+property CUT_BUFFER5	root	irw
+property CUT_BUFFER6	root	irw
+property CUT_BUFFER7	root	irw
+
+XCOMM If you are using Motif, you probably want these.
+property _MOTIF_DEFAULT_BINDINGS	root	ar iw
+property _MOTIF_DRAG_WINDOW	root	ar iw
+property _MOTIF_DRAG_TARGETS	any 	ar iw
+property _MOTIF_DRAG_ATOMS	any 	ar iw
+property _MOTIF_DRAG_ATOM_PAIRS	any 	ar iw
+
+XCOMM The next two rules let xwininfo -tree work when untrusted.
+property WM_NAME	any	ar
+
+XCOMM Allow read of WM_CLASS, but only for windows with WM_NAME.
+XCOMM This might be more restrictive than necessary, but demonstrates
+XCOMM the <required property> facility, and is also an attempt to
+XCOMM say "top level windows only."
+property WM_CLASS	WM_NAME	ar
+
+XCOMM These next three let xlsclients work untrusted.  Think carefully
+XCOMM before including these; giving away the client machine name and command
+XCOMM may be exposing too much.
+property WM_STATE	WM_NAME	ar
+property WM_CLIENT_MACHINE	WM_NAME	ar
+property WM_COMMAND	WM_NAME	ar
+
+XCOMM To let untrusted clients use the standard colormaps created by
+XCOMM xstdcmap, include these lines.
+property RGB_DEFAULT_MAP	root	ar
+property RGB_BEST_MAP	root	ar
+property RGB_RED_MAP	root	ar
+property RGB_GREEN_MAP	root	ar
+property RGB_BLUE_MAP	root	ar
+property RGB_GRAY_MAP	root	ar
+
+XCOMM To let untrusted clients use the color management database created
+XCOMM by xcmsdb, include these lines.
+property XDCCC_LINEAR_RGB_CORRECTION	root	ar
+property XDCCC_LINEAR_RGB_MATRICES	root	ar
+property XDCCC_GRAY_SCREENWHITEPOINT	root	ar
+property XDCCC_GRAY_CORRECTION	root	ar
+
+XCOMM To let untrusted clients use the overlay visuals that many vendors
+XCOMM support, include this line.
+property SERVER_OVERLAY_VISUALS	root	ar
+
+XCOMM Dumb examples to show other capabilities.
+
+XCOMM oddball property names and explicit specification of error conditions
+property "property with spaces"	'property with "'	aw er ed
+
+XCOMM Allow deletion of Woo-Hoo if window also has property OhBoy with value
+XCOMM ending in "son".  Reads and writes will cause an error.
+property Woo-Hoo	OhBoy = "*son"	ad
+
+.fi
+.SH FILES
+.TP 30
+.I __projectroot__/lib/xserver/SecurityPolicy
+Default X server security policy
+.SH "SEE ALSO"
+.PP
+\fIXserver\fp(__appmansuffix__),
+.I "Security Extension Specification"
diff --git a/doc/Xserver.man.pre b/doc/Xserver.man.pre
index cca58b1..aac3b51 100644
--- a/doc/Xserver.man.pre
+++ b/doc/Xserver.man.pre
@@ -414,221 +414,8 @@ X servers that support the SECURITY exte
 causes the server to attempt to read and interpret filename as a security
 policy file with the format described below.  The file is read at server
 startup and reread at each server reset.
-.PP
-The syntax of the security policy file is as follows.
-Notation: "*" means zero or more occurrences of the preceding element,
-and "+" means one or more occurrences.  To interpret <foo/bar>, ignore
-the text after the /; it is used to distinguish between instances of
-<foo> in the next section.
-.PP
-.nf
-<policy file> ::= <version line> <other line>*
-
-<version line> ::= <string/v> '\en'
-
-<other line > ::= <comment> | <access rule> | <site policy> | <blank line>
-
-<comment> ::= # <not newline>* '\en'
-
-<blank line> ::= <space> '\en'
-
-<site policy> ::= sitepolicy <string/sp> '\en'
-
-<access rule> ::= property <property/ar> <window> <perms> '\en'
-
-<property> ::= <string>
-
-<window> ::= any | root | <required property>
-
-<required property> ::= <property/rp> | <property with value>
-
-<property with value> ::= <property/rpv> = <string/rv>
-
-<perms> ::= [ <operation> | <action> | <space> ]*
-
-<operation> ::= r | w | d
-
-<action> ::= a | i | e
-
-<string> ::= <dbl quoted string> | <single quoted string> | <unquoted string>
-
-<dbl quoted string> ::= <space> " <not dquote>* " <space>
-
-<single quoted string> ::= <space> ' <not squote>* ' <space>
-
-<unquoted string> ::= <space> <not space>+ <space>
-
-<space> ::= [ ' ' | '\et' ]*
-
-Character sets:
-
-<not newline> ::= any character except '\en'
-<not dquote>  ::= any character except "
-<not squote>  ::= any character except '
-<not space>   ::= any character except those in <space>
-.fi
-.PP
-The semantics associated with the above syntax are as follows.
-.PP
-<version line>, the first line in the file, specifies the file format
-version.  If the server does not recognize the version <string/v>, it
-ignores the rest of the file.  The version string for the file format
-described here is "version-1" .
-.PP
-Once past the <version line>, lines that do not match the above syntax
-are ignored.
-.PP
-<comment> lines are ignored.
-.PP
-<sitepolicy> lines are currently ignored.  They are intended to
-specify the site policies used by the XC-QUERY-SECURITY-1
-authorization method.
-.PP
-<access rule> lines specify how the server should react to untrusted
-client requests that affect the X Window property named <property/ar>.
-The rest of this section describes the interpretation of an
-<access rule>.
-.PP
-For an <access rule> to apply to a given instance of <property/ar>,
-<property/ar> must be on a window that is in the set of windows
-specified by <window>.  If <window> is any, the rule applies to
-<property/ar> on any window.  If <window> is root, the rule applies to
-<property/ar> only on root windows.
-.PP
-If <window> is <required property>, the following apply.  If <required
-property> is a <property/rp>, the rule applies when the window also
-has that <property/rp>, regardless of its value.  If <required
-property> is a <property with value>, <property/rpv> must also have
-the value specified by <string/rv>.  In this case, the property must
-have type STRING and format 8, and should contain one or more
-null-terminated strings.  If any of the strings match <string/rv>, the
-rule applies.
-.PP
-The definition of string matching is simple case-sensitive string
-comparison with one elaboration: the occurrence of the character '*' in
-<string/rv> is a wildcard meaning "any string."  A <string/rv> can
-contain multiple wildcards anywhere in the string.  For example, "x*"
-matches strings that begin with x, "*x" matches strings that end with
-x, "*x*" matches strings containing x, and "x*y*" matches strings that
-start with x and subsequently contain y.
-.PP
-There may be multiple <access rule> lines for a given <property/ar>.
-The rules are tested in the order that they appear in the file.  The
-first rule that applies is used.
-.PP
-<perms> specify operations that untrusted clients may attempt, and
-the actions that the server should take in response to those operations.
-.PP
-<operation> can be r (read), w (write), or d (delete).  The following
-table shows how X Protocol property requests map to these operations
-in The Open Group server implementation.
-.PP
-.nf
-GetProperty	r, or r and d if delete = True
-ChangeProperty	w
-RotateProperties	r and w
-DeleteProperty	d
-ListProperties	none, untrusted clients can always list all properties
-.fi
-.PP
-<action> can be a (allow), i (ignore), or e (error).  Allow means
-execute the request as if it had been issued by a trusted client.
-Ignore means treat the request as a no-op.  In the case of
-GetProperty, ignore means return an empty property value if the
-property exists, regardless of its actual value.  Error means do not
-execute the request and return a BadAtom error with the atom set to
-the property name.  Error is the default action for all properties,
-including those not listed in the security policy file.
-.PP
-An <action> applies to all <operation>s that follow it, until the next
-<action> is encountered.  Thus, irwad  means ignore read and write,
-allow delete.
-.PP
-GetProperty and RotateProperties may do multiple operations (r and d,
-or r and w).  If different actions apply to the operations, the most
-severe action is applied to the whole request; there is no partial
-request execution.  The severity ordering is: allow < ignore < error.
-Thus, if the <perms> for a property are ired (ignore read, error
-delete), and an untrusted client attempts GetProperty on that property
-with delete = True, an error is returned, but the property value is
-not.  Similarly, if any of the properties in a RotateProperties do not
-allow both read and write, an error is returned without changing any
-property values.
-.PP
-Here is an example security policy file.
-.PP
-.ta 3i 4i
-.nf
-version-1
-
-XCOMM Allow reading of application resources, but not writing.
-property RESOURCE_MANAGER	root	ar iw
-property SCREEN_RESOURCES	root	ar iw
-
-XCOMM Ignore attempts to use cut buffers.  Giving errors causes apps to crash,
-XCOMM and allowing access may give away too much information.
-property CUT_BUFFER0	root	irw
-property CUT_BUFFER1	root	irw
-property CUT_BUFFER2	root	irw
-property CUT_BUFFER3	root	irw
-property CUT_BUFFER4	root	irw
-property CUT_BUFFER5	root	irw
-property CUT_BUFFER6	root	irw
-property CUT_BUFFER7	root	irw
-
-XCOMM If you are using Motif, you probably want these.
-property _MOTIF_DEFAULT_BINDINGS	root	ar iw
-property _MOTIF_DRAG_WINDOW	root	ar iw
-property _MOTIF_DRAG_TARGETS	any 	ar iw
-property _MOTIF_DRAG_ATOMS	any 	ar iw
-property _MOTIF_DRAG_ATOM_PAIRS	any 	ar iw
-
-XCOMM The next two rules let xwininfo -tree work when untrusted.
-property WM_NAME	any	ar
-
-XCOMM Allow read of WM_CLASS, but only for windows with WM_NAME.
-XCOMM This might be more restrictive than necessary, but demonstrates
-XCOMM the <required property> facility, and is also an attempt to
-XCOMM say "top level windows only."
-property WM_CLASS	WM_NAME	ar
-
-XCOMM These next three let xlsclients work untrusted.  Think carefully
-XCOMM before including these; giving away the client machine name and command
-XCOMM may be exposing too much.
-property WM_STATE	WM_NAME	ar
-property WM_CLIENT_MACHINE	WM_NAME	ar
-property WM_COMMAND	WM_NAME	ar
-
-XCOMM To let untrusted clients use the standard colormaps created by
-XCOMM xstdcmap, include these lines.
-property RGB_DEFAULT_MAP	root	ar
-property RGB_BEST_MAP	root	ar
-property RGB_RED_MAP	root	ar
-property RGB_GREEN_MAP	root	ar
-property RGB_BLUE_MAP	root	ar
-property RGB_GRAY_MAP	root	ar
-
-XCOMM To let untrusted clients use the color management database created
-XCOMM by xcmsdb, include these lines.
-property XDCCC_LINEAR_RGB_CORRECTION	root	ar
-property XDCCC_LINEAR_RGB_MATRICES	root	ar
-property XDCCC_GRAY_SCREENWHITEPOINT	root	ar
-property XDCCC_GRAY_CORRECTION	root	ar
-
-XCOMM To let untrusted clients use the overlay visuals that many vendors
-XCOMM support, include this line.
-property SERVER_OVERLAY_VISUALS	root	ar
-
-XCOMM Dumb examples to show other capabilities.
-
-XCOMM oddball property names and explicit specification of error conditions
-property "property with spaces"	'property with "'	aw er ed
-
-XCOMM Allow deletion of Woo-Hoo if window also has property OhBoy with value
-XCOMM ending in "son".  Reads and writes will cause an error.
-property Woo-Hoo	OhBoy = "*son"	ad
-
-.fi
+The syntax of the security policy file is described in 
+\fISecurityPolicy\fP(__filemansuffix__).
 .SH "NETWORK CONNECTIONS"
 The X server supports client connections via a platform-dependent subset of
 the following transport types: TCP\/IP, Unix Domain sockets, DECnet,
@@ -757,6 +544,9 @@ Error log file for display number \fBn\f
 .TP 30
 .I __projectroot__/lib/X11/xdm/xdm-errors
 Default error log file if the server is run from \fIxdm\fP(1)
+.TP 30
+.I __projectroot__/lib/xserver/SecurityPolicy
+Default X server security policy
 .SH "SEE ALSO"
 General information: \fIX\fP(__miscmansuffix__)
 .PP
@@ -771,6 +561,7 @@ Fonts: \fIbdftopcf\fP(1), \fImkfontdir\f
 .PP
 Security: \fIXsecurity\fP(__miscmansuffix__), \fIxauth\fP(1), \fIXau\fP(1), 
 \fIxdm\fP(1), \fIxhost\fP(1), \fIxfwp\fP(1),
+\fISecurityPolicy\fP(__filemansuffix__),
 .I "Security Extension Specification"
 .PP
 Starting the server: \fIxdm\fP(1), \fIxinit\fP(1)
diff-tree b1142cdbce76fed8cb22ba6d7ac027751dd56a76 (from 3344a4eda704edc7dc30037f095de277a60a70bb)
Author: Brice Goglin <brice.goglin at ens-lyon.org>
Date:   Thu Feb 22 12:26:04 2007 -0800

    Bug #10034: 'man Xserver' typos: s/dqoute/dquote/
    
    Bugzilla #10034: <http://bugs.freedesktop.org/show_bug.cgi?id=10034>
    Patch #8780: <http://bugs.freedesktop.org/attachment.cgi?id=8780>

diff --git a/doc/Xserver.man.pre b/doc/Xserver.man.pre
index aa931a8..cca58b1 100644
--- a/doc/Xserver.man.pre
+++ b/doc/Xserver.man.pre
@@ -452,7 +452,7 @@ the text after the /; it is used to dist
 
 <string> ::= <dbl quoted string> | <single quoted string> | <unquoted string>
 
-<dbl quoted string> ::= <space> " <not dqoute>* " <space>
+<dbl quoted string> ::= <space> " <not dquote>* " <space>
 
 <single quoted string> ::= <space> ' <not squote>* ' <space>
 
@@ -463,7 +463,7 @@ the text after the /; it is used to dist
 Character sets:
 
 <not newline> ::= any character except '\en'
-<not dqoute>  ::= any character except "
+<not dquote>  ::= any character except "
 <not squote>  ::= any character except '
 <not space>   ::= any character except those in <space>
 .fi
diff-tree 3344a4eda704edc7dc30037f095de277a60a70bb (from 3c7a27dc77595ad018bb7c4f7cef6bc178268cb6)
Author: Michel Dänzer <michel at tungstengraphics.com>
Date:   Thu Feb 15 16:27:50 2007 +0100

    DRI: Make sure number of DRI windows is accurate in driver ClipNotify hook.
    
    Always call DRI{De,In}creaseNumberVisible (which in turn calls
    DRIDriverClipNotify) after updating pDRIPriv->nrWindows.

diff --git a/hw/xfree86/dri/dri.c b/hw/xfree86/dri/dri.c
index bdef75a..c183e2a 100644
--- a/hw/xfree86/dri/dri.c
+++ b/hw/xfree86/dri/dri.c
@@ -1134,11 +1134,11 @@ DRICreateDrawable(ScreenPtr pScreen, Dra
 	    pWin->devPrivates[DRIWindowPrivIndex].ptr =
 						(pointer)pDRIDrawablePriv;
 
+	    pDRIPriv->nrWindows++;
+
 	    if (pDRIDrawablePriv->nrects)
 		DRIIncreaseNumberVisible(pScreen);
 
-	    pDRIPriv->nrWindows++;
-
 	    /* track this in case this window is destroyed */
 	    AddResource(id, DRIDrawablePrivResType, (pointer)pWin);
 	}
@@ -1210,13 +1210,13 @@ DRIDrawablePrivDelete(pointer pResource,
 	    return FALSE;
 	}
 
-	if (pDRIDrawablePriv->nrects)
-	    DRIDecreaseNumberVisible(pDrawable->pScreen);
-
 	xfree(pDRIDrawablePriv);
 	pWin->devPrivates[DRIWindowPrivIndex].ptr = NULL;
 
 	pDRIPriv->nrWindows--;
+
+	if (REGION_NUM_RECTS(&pWin->clipList))
+	    DRIDecreaseNumberVisible(pDrawable->pScreen);
     }
     else { /* pixmap (or for GLX 1.3, a PBuffer) */
 	/* NOT_DONE */
diff-tree 3c7a27dc77595ad018bb7c4f7cef6bc178268cb6 (from eedf148e5a1273ebbf4dc8dcac9c435712fc00ea)
Author: Michel Dänzer <michel at tungstengraphics.com>
Date:   Wed Feb 14 16:17:18 2007 +0100

    DRI: New ClipNotify driver hook.
    
    The hook is called whenever the clipList of any DRI window changes, be it via
    DRIClipNotify, DRICreateDrawable or DRIDrawablePrivDelete. This allows the
    driver to keep track of which DRI windows are visible where.

diff --git a/hw/xfree86/dri/dri.c b/hw/xfree86/dri/dri.c
index ebfe28b..bdef75a 100644
--- a/hw/xfree86/dri/dri.c
+++ b/hw/xfree86/dri/dri.c
@@ -1007,6 +1007,55 @@ DRITransitionTo2d(ScreenPtr pScreen)
 }
 
 
+static int
+DRIDCNTreeTraversal(WindowPtr pWin, pointer data)
+{
+    DRIDrawablePrivPtr pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin);
+
+    if (pDRIDrawablePriv) {
+	ScreenPtr pScreen = pWin->drawable.pScreen;
+	DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
+
+	if (REGION_NUM_RECTS(&pWin->clipList) > 0) {
+	    WindowPtr *pDRIWindows = (WindowPtr*)data;
+	    int i = 0;
+
+	    while (pDRIWindows[i])
+		i++;
+
+	    pDRIWindows[i] = pWin;
+
+	    pDRIPriv->nrWalked++;
+	}
+
+	if (pDRIPriv->nrWindows == pDRIPriv->nrWalked)
+	    return WT_STOPWALKING;
+    }
+
+    return WT_WALKCHILDREN;
+}
+
+static void
+DRIDriverClipNotify(ScreenPtr pScreen)
+{
+    DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
+
+    if (pDRIPriv->pDriverInfo->ClipNotify) {
+	WindowPtr *pDRIWindows = xcalloc(sizeof(WindowPtr), pDRIPriv->nrWindows);
+	DRIInfoPtr pDRIInfo = pDRIPriv->pDriverInfo;
+
+	if (pDRIPriv->nrWindows > 0) {
+	    pDRIPriv->nrWalked = 0;
+	    TraverseTree(WindowTable[pScreen->myNum], DRIDCNTreeTraversal,
+			 (pointer)pDRIWindows);
+	}
+
+	pDRIInfo->ClipNotify(pScreen, pDRIWindows, pDRIPriv->nrWindows);
+
+	xfree(pDRIWindows);
+    }
+}
+
 static void
 DRIIncreaseNumberVisible(ScreenPtr pScreen)
 {
@@ -1022,6 +1071,8 @@ DRIIncreaseNumberVisible(ScreenPtr pScre
     default:
 	break;
     }
+
+    DRIDriverClipNotify(pScreen);
 }
 
 static void
@@ -1039,6 +1090,8 @@ DRIDecreaseNumberVisible(ScreenPtr pScre
     default:
 	break;
     }
+
+    DRIDriverClipNotify(pScreen);
 }
 
 Bool
@@ -1880,6 +1933,8 @@ DRIClipNotify(WindowPtr pWin, int dx, in
 	    DRIIncreaseNumberVisible(pScreen);
 	else if (!nrects && pDRIDrawablePriv->nrects)
 	    DRIDecreaseNumberVisible(pScreen);
+	else
+	    DRIDriverClipNotify(pScreen);
 
 	pDRIDrawablePriv->nrects = nrects;
 
diff --git a/hw/xfree86/dri/dri.h b/hw/xfree86/dri/dri.h
index dca0edd..f65c571 100644
--- a/hw/xfree86/dri/dri.h
+++ b/hw/xfree86/dri/dri.h
@@ -107,7 +107,7 @@ typedef struct {
  */
 
 #define DRIINFO_MAJOR_VERSION   5
-#define DRIINFO_MINOR_VERSION   0
+#define DRIINFO_MINOR_VERSION   1
 #define DRIINFO_PATCH_VERSION   0
 
 typedef struct {
@@ -173,6 +173,9 @@ typedef struct {
     /* New with DRI version 4.1.0 */
     void        (*TransitionSingleToMulti3D)(ScreenPtr pScreen);
     void        (*TransitionMultiToSingle3D)(ScreenPtr pScreen);
+
+    /* New with DRI version 5.1.0 */
+    void        (*ClipNotify)(ScreenPtr pScreen, WindowPtr *ppWin, int num);
 } DRIInfoRec, *DRIInfoPtr;
 
 
diff --git a/hw/xfree86/dri/dristruct.h b/hw/xfree86/dri/dristruct.h
index 7579806..9c42ff9 100644
--- a/hw/xfree86/dri/dristruct.h
+++ b/hw/xfree86/dri/dristruct.h
@@ -89,6 +89,7 @@ typedef struct _DRIScreenPrivRec
     DRIInfoPtr		pDriverInfo;
     int                 nrWindows;
     int                 nrWindowsVisible;
+    int                 nrWalked;
     drm_clip_rect_t  private_buffer_rect; /* management of private buffers */
     DrawablePtr         fullscreen; /* pointer to fullscreen drawable */
     drm_clip_rect_t  fullscreen_rect; /* fake rect for fullscreen mode */
diff-tree eedf148e5a1273ebbf4dc8dcac9c435712fc00ea (from 8a42af6a935b1cf0e15102e986bb527f4fab31a8)
Author: Michel Dänzer <michel at tungstengraphics.com>
Date:   Fri Feb 2 18:27:40 2007 +0100

    Track number of visible DRI windows separately for transitions.
    
    This allows e.g. doing page flipping with multiple DRI windows as long as
    only one of them is visible.

diff --git a/hw/xfree86/dri/dri.c b/hw/xfree86/dri/dri.c
index 5337f9a..ebfe28b 100644
--- a/hw/xfree86/dri/dri.c
+++ b/hw/xfree86/dri/dri.c
@@ -204,6 +204,7 @@ DRIScreenInit(ScreenPtr pScreen, DRIInfo
     pDRIPriv->directRenderingSupport = TRUE;
     pDRIPriv->pDriverInfo = pDRIInfo;
     pDRIPriv->nrWindows = 0;
+    pDRIPriv->nrWindowsVisible = 0;
     pDRIPriv->fullscreen = NULL;
 
     pDRIPriv->createDummyCtx     = pDRIInfo->createDummyCtx;
@@ -1006,6 +1007,40 @@ DRITransitionTo2d(ScreenPtr pScreen)
 }
 
 
+static void
+DRIIncreaseNumberVisible(ScreenPtr pScreen)
+{
+    DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
+
+    switch (++pDRIPriv->nrWindowsVisible) {
+    case 1:
+	DRITransitionTo3d( pScreen );
+	break;
+    case 2:
+	DRITransitionToSharedBuffers( pScreen );
+	break;
+    default:
+	break;
+    }
+}
+
+static void
+DRIDecreaseNumberVisible(ScreenPtr pScreen)
+{
+    DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
+
+    switch (--pDRIPriv->nrWindowsVisible) {
+    case 0:
+	DRITransitionTo2d( pScreen );
+	break;
+    case 1:
+	DRITransitionToPrivateBuffers( pScreen );
+	break;
+    default:
+	break;
+    }
+}
+
 Bool
 DRICreateDrawable(ScreenPtr pScreen, Drawable id,
                   DrawablePtr pDrawable, drm_drawable_t * hHWDrawable)
@@ -1040,21 +1075,16 @@ DRICreateDrawable(ScreenPtr pScreen, Dra
 	    pDRIDrawablePriv->pScreen = pScreen;
 	    pDRIDrawablePriv->refCount = 1;
 	    pDRIDrawablePriv->drawableIndex = -1;
+	    pDRIDrawablePriv->nrects = REGION_NUM_RECTS(&pWin->clipList);
 
 	    /* save private off of preallocated index */
 	    pWin->devPrivates[DRIWindowPrivIndex].ptr =
 						(pointer)pDRIDrawablePriv;
 
-	    switch (++pDRIPriv->nrWindows) {
-	    case 1:
-	       DRITransitionTo3d( pScreen );
-	       break;
-	    case 2:
-	       DRITransitionToSharedBuffers( pScreen );
-	       break;
-	    default:
-	       break;
-	    }
+	    if (pDRIDrawablePriv->nrects)
+		DRIIncreaseNumberVisible(pScreen);
+
+	    pDRIPriv->nrWindows++;
 
 	    /* track this in case this window is destroyed */
 	    AddResource(id, DRIDrawablePrivResType, (pointer)pWin);
@@ -1126,19 +1156,14 @@ DRIDrawablePrivDelete(pointer pResource,
 			       pDRIDrawablePriv->hwDrawable)) {
 	    return FALSE;
 	}
+
+	if (pDRIDrawablePriv->nrects)
+	    DRIDecreaseNumberVisible(pDrawable->pScreen);
+
 	xfree(pDRIDrawablePriv);
 	pWin->devPrivates[DRIWindowPrivIndex].ptr = NULL;
 
-	switch (--pDRIPriv->nrWindows) {
-	case 0:
-	   DRITransitionTo2d( pDrawable->pScreen );
-	   break;
-	case 1:
-	   DRITransitionToPrivateBuffers( pDrawable->pScreen );
-	   break;
-	default:
-	   break;
-	}
+	pDRIPriv->nrWindows--;
     }
     else { /* pixmap (or for GLX 1.3, a PBuffer) */
 	/* NOT_DONE */
@@ -1276,7 +1301,7 @@ DRIGetDrawableInfo(ScreenPtr pScreen,
 	    *backX = *X;
 	    *backY = *Y;
 
-	    if (pDRIPriv->nrWindows == 1 && *numClipRects) {
+	    if (pDRIPriv->nrWindowsVisible == 1 && *numClipRects) {
 	       /* Use a single cliprect. */
 
 	       int x0 = *X;
@@ -1652,7 +1677,7 @@ DRICopyWindow(WindowPtr pWin, DDXPointRe
 
     if(!pDRIPriv) return;
 
-    if(pDRIPriv->nrWindows > 0) {
+    if(pDRIPriv->nrWindowsVisible > 0) {
        RegionRec reg;
 
        REGION_NULL(pScreen, &reg);
@@ -1844,19 +1869,26 @@ DRIClipNotify(WindowPtr pWin, int dx, in
     if(!pDRIPriv) return;
 
     if ((pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin))) {
+        int nrects = REGION_NUM_RECTS(&pWin->clipList);
 
         if(!pDRIPriv->windowsTouched) {
             DRILockTree(pScreen);
             pDRIPriv->windowsTouched = TRUE;
         }
 
+	if (nrects && !pDRIDrawablePriv->nrects)
+	    DRIIncreaseNumberVisible(pScreen);
+	else if (!nrects && pDRIDrawablePriv->nrects)
+	    DRIDecreaseNumberVisible(pScreen);
+
+	pDRIDrawablePriv->nrects = nrects;
+
 	pDRIPriv->pSAREA->drawableTable[pDRIDrawablePriv->drawableIndex].stamp
 	    = DRIDrawableValidationStamp++;
 
 	drmUpdateDrawableInfo(pDRIPriv->drmFD, pDRIDrawablePriv->hwDrawable,
 			      DRM_DRAWABLE_CLIPRECTS,
-			      REGION_NUM_RECTS(&pWin->clipList),
-			      REGION_RECTS(&pWin->clipList));
+			      nrects, REGION_RECTS(&pWin->clipList));
     }
 
     /* call lower wrapped functions */
diff --git a/hw/xfree86/dri/dristruct.h b/hw/xfree86/dri/dristruct.h
index 340c59a..7579806 100644
--- a/hw/xfree86/dri/dristruct.h
+++ b/hw/xfree86/dri/dristruct.h
@@ -53,6 +53,7 @@ typedef struct _DRIDrawablePrivRec
     int			drawableIndex;
     ScreenPtr		pScreen;
     int 		refCount;
+    int 		nrects;
 } DRIDrawablePrivRec, *DRIDrawablePrivPtr;
 
 struct _DRIContextPrivRec
@@ -87,6 +88,7 @@ typedef struct _DRIScreenPrivRec
     void**		partial3DContextStore; /* parital 3D context        */
     DRIInfoPtr		pDriverInfo;
     int                 nrWindows;
+    int                 nrWindowsVisible;
     drm_clip_rect_t  private_buffer_rect; /* management of private buffers */
     DrawablePtr         fullscreen; /* pointer to fullscreen drawable */
     drm_clip_rect_t  fullscreen_rect; /* fake rect for fullscreen mode */
diff-tree 8a42af6a935b1cf0e15102e986bb527f4fab31a8 (from 4660eaaffb36f526f71d5847ae1309c10ee133c6)
Author: Keith Packard <keithp at neko.keithp.com>
Date:   Mon Feb 19 15:28:37 2007 -0800

    Check for clientGone before sending events from XFixes (bug #1753).
    
    Freeing resources during client closedown can cause cursor changes which
    attempt to send cursor events through the XFixes extension; a client in the
    process of closing down has no file to send events to, causing a crash when
    this path is hit.

diff --git a/xfixes/cursor.c b/xfixes/cursor.c
index 86a512c..3cdacc0 100755
--- a/xfixes/cursor.c
+++ b/xfixes/cursor.c
@@ -143,7 +143,8 @@ CursorDisplayCursor (ScreenPtr pScreen,
 	CursorCurrent = pCursor;
 	for (e = cursorEvents; e; e = e->next)
 	{
-	    if (e->eventMask & XFixesDisplayCursorNotifyMask)
+	    if ((e->eventMask & XFixesDisplayCursorNotifyMask) &&
+		!e->pClient->clientGone)
 	    {
 		xXFixesCursorNotifyEvent	ev;
 		ev.type = XFixesEventBase + XFixesCursorNotify;
diff --git a/xfixes/select.c b/xfixes/select.c
index d1c22c5..f0a9f2f 100755
--- a/xfixes/select.c
+++ b/xfixes/select.c
@@ -78,7 +78,9 @@ XFixesSelectionCallback (CallbackListPtr
     }
     for (e = selectionEvents; e; e = e->next)
     {
-	if (e->selection == selection->selection && (e->eventMask & eventMask))
+	if (e->selection == selection->selection && 
+	    (e->eventMask & eventMask) &&
+	    !e->pClient->clientGone)
 	{
 	    xXFixesSelectionNotifyEvent	ev;
 
diff-tree 4660eaaffb36f526f71d5847ae1309c10ee133c6 (from 5631a67f648f5f151a849a918ee12871c71c32e9)
Author: Ben Byer <bbyer at bbyer.(none)>
Date:   Sun Feb 18 14:09:51 2007 -0800

    configure fixes for darwin

diff --git a/configure.ac b/configure.ac
index 0a3fe45..3260855 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1253,37 +1253,6 @@ if test "x$XORG" = xyes -o "x$XGL" = xye
 	XORG_CFLAGS="$XORGSERVER_CFLAGS -DHAVE_XORG_CONFIG_H"
 	XORG_LIBS="$COMPOSITE_LIB $MI_LIB $FIXES_LIB $XEXTXORG_LIB $GLX_LIBS $RENDER_LIB $RANDR_LIB $DAMAGE_LIB $MIEXT_DAMAGE_LIB $MIEXT_SHADOW_LIB $XI_LIB $XKB_LIB $XPSTUBS_LIB $OS_LIB"
 
-	if test "x$DGA" = xauto; then
-		PKG_CHECK_MODULES(DGA, xf86dgaproto, [DGA=yes], [DGA=no])
-	fi
-	if test "x$DGA" = xyes; then
-		XORG_MODULES="$XORG_MODULES xf86dgaproto"
-		AC_DEFINE(DGA, 1, [Support DGA extension])
-		AC_DEFINE(XFreeXDGA, 1, [Build XDGA support])
-	fi
-
-	if test "x$XF86MISC" = xauto; then
-		PKG_CHECK_MODULES(XF86MISC, xf86miscproto, [XF86MISC=yes], [XF86MISC=no])
-	fi
-	if test "x$XF86MISC" = xyes; then
-		XORG_MODULES="$XORG_MODULES xf86miscproto"
-		AC_DEFINE(XF86MISC, 1, [Support XFree86 miscellaneous extensions])
-	fi
-
-	if test "x$XF86VIDMODE" = xauto; then
-		PKG_CHECK_MODULES(XF86VIDMODE, xf86vidmodeproto, [XF86VIDMODE=yes], [XF86VIDMODE=no])
-	fi
-	if test "x$XF86VIDMODE" = xyes; then
-		XORG_MODULES="$XORG_MODULES xf86vidmodeproto"
-		AC_DEFINE(XF86VIDMODE, 1, [Support XFree86 Video Mode extension])
-	fi
-
-	if test -n "$XORG_MODULES"; then
-	        PKG_CHECK_MODULES(XORG_MODULES, [$XORG_MODULES])
-	        XORG_CFLAGS="$XORG_CFLAGS $XORG_MODULES_CFLAGS"
-	        XORG_LIBS="$XORG_LIBS $XORG_MODULES_LIBS"
-	fi
-
 dnl Check to see if dlopen is in default libraries (like Solaris, which
 dnl has it in libc), or if libdl is needed to get it.
 	AC_CHECK_FUNC([dlopen], [], 
@@ -1312,17 +1281,19 @@ return 0;}
                    XQUARTZ=no
                  fi
                fi
-               AC_CACHE_CHECK([for AGL framework],xorg_cv_AGL_framework,[
-               save_LDFLAGS=$LDFLAGS
-               LDFLAGS="$LDFLAGS -framework AGL"
-               AC_LINK_IFELSE([char aglEnable();
-int main() {
-aglEnable();
-return 0;}
-               ],[xorg_cv_AGL_framework=yes],
-               [xorg_cv_AGL_framework=no])
-               LDFLAGS=$save_LDFLAGS
-               ])
+#	       glxAGL / glxCGL don't work yet
+#               AC_CACHE_CHECK([for AGL framework],xorg_cv_AGL_framework,[
+#               save_LDFLAGS=$LDFLAGS
+#               LDFLAGS="$LDFLAGS -framework AGL"
+#               AC_LINK_IFELSE([char aglEnable();
+#int main() {
+#aglEnable();
+#return 0;}
+#               ],[xorg_cv_AGL_framework=yes],
+#               [xorg_cv_AGL_framework=no])
+#               LDFLAGS=$save_LDFLAGS
+#               ])
+               xorg_cv_AGL_framework=no
                AC_CHECK_LIB([Xplugin],[xp_init],[:])
                AC_SUBST([APPLE_APPLICATIONS_DIR])
                CFLAGS="${CFLAGS} -D__DARWIN__"
@@ -1331,15 +1302,15 @@ return 0;}
                PLIST_VENDOR_WEB=$VENDOR_WEB
                AC_SUBST([PLIST_VENDOR_WEB])
                # Not sure that we should be disabling all these...
-               if test "x$XF86MISC" = xyes; then
+               if test "x$XF86MISC" = xyes || test "x$XF86MISC" = xauto; then
                        AC_MSG_NOTICE([Disabling XF86Misc extension])
                        XF86MISC=no
                fi
-               if test "x$XF86VIDMODE" = xyes; then
+               if test "x$XF86VIDMODE" = xyes || test "x$XF86VIDMODE" = xauto; then
                        AC_MSG_NOTICE([Disabling XF86VidMode extension])
                        XF86VIDMODE=no
                fi
-               if test "x$DGA" = xyes; then
+               if test "x$DGA" = xyes || test "x$DGA" = xauto; then
                        AC_MSG_NOTICE([Disabling DGA extension])
                        DGA=no
                fi
@@ -1499,6 +1470,37 @@ return 0;}
 	if test "x$XORG_OS_PCI" = x ; then
 		XORG_OS_PCI=$XORG_OS
 	fi
+	if test "x$DGA" = xauto; then
+		PKG_CHECK_MODULES(DGA, xf86dgaproto, [DGA=yes], [DGA=no])
+	fi
+	if test "x$DGA" = xyes; then
+		XORG_MODULES="$XORG_MODULES xf86dgaproto"
+		AC_DEFINE(DGA, 1, [Support DGA extension])
+		AC_DEFINE(XFreeXDGA, 1, [Build XDGA support])
+	fi
+
+	if test "x$XF86MISC" = xauto; then
+		PKG_CHECK_MODULES(XF86MISC, xf86miscproto, [XF86MISC=yes], [XF86MISC=no])
+	fi
+	if test "x$XF86MISC" = xyes; then
+		XORG_MODULES="$XORG_MODULES xf86miscproto"
+		AC_DEFINE(XF86MISC, 1, [Support XFree86 miscellaneous extensions])
+	fi
+
+	if test "x$XF86VIDMODE" = xauto; then
+		PKG_CHECK_MODULES(XF86VIDMODE, xf86vidmodeproto, [XF86VIDMODE=yes], [XF86VIDMODE=no])
+	fi
+	if test "x$XF86VIDMODE" = xyes; then
+		XORG_MODULES="$XORG_MODULES xf86vidmodeproto"
+		AC_DEFINE(XF86VIDMODE, 1, [Support XFree86 Video Mode extension])
+	fi
+
+	if test -n "$XORG_MODULES"; then
+	        PKG_CHECK_MODULES(XORG_MODULES, [$XORG_MODULES])
+	        XORG_CFLAGS="$XORG_CFLAGS $XORG_MODULES_CFLAGS"
+	        XORG_LIBS="$XORG_LIBS $XORG_MODULES_LIBS"
+	fi
+
 	AC_SUBST([XORG_LIBS])
 	AC_SUBST([XORG_INCS])
 	AC_SUBST([XORG_OS])
diff-tree 5631a67f648f5f151a849a918ee12871c71c32e9 (from 096965ec9c7514f0c9fc0d17e5166f2d26781f87)
Author: Keith Packard <keithp at neko.keithp.com>
Date:   Fri Feb 16 10:06:22 2007 -0800

    Don't set subpixel order during startup; the screen won't be ready.
    
    in xf86CrtcSetMode, scrn->pScreen will be NULL during server startup time,
    so don't try to set the subpixel order. subpixel order will be set in the
    randr initialization anyways.
    (cherry picked from commit 5f6f8616d862ce4a37f6d3df4bdbc44fd21cc82a)

diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c
index 37a3025..29042a0 100644
--- a/hw/xfree86/modes/xf86Crtc.c
+++ b/hw/xfree86/modes/xf86Crtc.c
@@ -313,7 +313,8 @@ xf86CrtcSetMode (xf86CrtcPtr crtc, Displ
 
     /* XXX free adjustedmode */
     ret = TRUE;
-    xf86CrtcSetScreenSubpixelOrder (scrn->pScreen);
+    if (scrn->pScreen)
+	xf86CrtcSetScreenSubpixelOrder (scrn->pScreen);
 
 done:
     if (!ret) {
diff-tree 096965ec9c7514f0c9fc0d17e5166f2d26781f87 (from 55797dd252382d35ebab5d9e18a5e0e77872d775)
Author: Keith Packard <keithp at guitar.keithp.com>
Date:   Fri Feb 16 02:17:11 2007 -0800

    Ensure drivers can use new modes header files.
    
    New modes header files required a few minor changes to be used by external
    drivers, the most notable of which is the publication of the config file
    parser header files.

diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c
index 74e4c76..37a3025 100644
--- a/hw/xfree86/modes/xf86Crtc.c
+++ b/hw/xfree86/modes/xf86Crtc.c
@@ -41,6 +41,9 @@
 #define DPMS_SERVER
 #include "X11/extensions/dpms.h"
 #include "X11/Xatom.h"
+#ifdef RENDER
+#include "picturestr.h"
+#endif
 
 /*
  * Initialize xf86CrtcConfig structure
diff --git a/hw/xfree86/modes/xf86Crtc.h b/hw/xfree86/modes/xf86Crtc.h
index 9a70be4..756730e 100644
--- a/hw/xfree86/modes/xf86Crtc.h
+++ b/hw/xfree86/modes/xf86Crtc.h
@@ -28,7 +28,6 @@
 #include "xf86Rename.h"
 #endif
 #include "xf86Modes.h"
-#include "xf86Parser.h"
 #include "damage.h"
 
 /* Compat definitions for older X Servers. */
diff --git a/hw/xfree86/modes/xf86DiDGA.c b/hw/xfree86/modes/xf86DiDGA.c
index 551f052..0964cef 100644
--- a/hw/xfree86/modes/xf86DiDGA.c
+++ b/hw/xfree86/modes/xf86DiDGA.c
@@ -35,6 +35,8 @@
 #include "xf86Crtc.h"
 #include "xf86Modes.h"
 #include "gcstruct.h"
+#include "scrnintstr.h"
+#include "windowstr.h"
 
 static Bool
 xf86_dga_get_modes (ScreenPtr pScreen)
diff --git a/hw/xfree86/modes/xf86Modes.c b/hw/xfree86/modes/xf86Modes.c
index 37d0eb6..5b52bd7 100644
--- a/hw/xfree86/modes/xf86Modes.c
+++ b/hw/xfree86/modes/xf86Modes.c
@@ -36,11 +36,6 @@
 #endif
 #endif
 
-#include <stddef.h>
-#include <string.h>
-#include <stdio.h>
-
-#include "xf86.h"
 #include "xf86Modes.h"
 #include "xf86Priv.h"
 
diff --git a/hw/xfree86/modes/xf86Modes.h b/hw/xfree86/modes/xf86Modes.h
index 9494333..2bd4ede 100644
--- a/hw/xfree86/modes/xf86Modes.h
+++ b/hw/xfree86/modes/xf86Modes.h
@@ -25,11 +25,17 @@
  *
  */
 
-#ifndef _I830_XF86MODES_H_
-#define _I830_XF86MODES_H_
+#ifndef _XF86MODES_H_
+#define _XF86MODES_H_
+
+#include <stddef.h>
+#include <string.h>
+#include <stdio.h>
+
+#include "xf86.h"
 #include "xorgVersion.h"
-#include "xf86Parser.h"
 #include "edid.h"
+#include "xf86Parser.h"
 #if XF86_MODES_RENAME
 #include "xf86Rename.h"
 #endif
@@ -89,4 +95,4 @@ xf86GetMonitorModes (ScrnInfoPtr pScrn, 
 DisplayModePtr
 xf86GetDefaultModes (Bool interlaceAllowed, Bool doubleScanAllowed);
 
-#endif /* _I830_XF86MODES_H_ */
+#endif /* _XF86MODES_H_ */
diff --git a/hw/xfree86/modes/xf86RandR12.c b/hw/xfree86/modes/xf86RandR12.c
index c8ea778..abdf92e 100644
--- a/hw/xfree86/modes/xf86RandR12.c
+++ b/hw/xfree86/modes/xf86RandR12.c
@@ -496,19 +496,18 @@ void
 xf86RandR12SetRotations (ScreenPtr pScreen, Rotation rotations)
 {
     XF86RandRInfoPtr	randrp = XF86RANDRINFO(pScreen);
+#if RANDR_12_INTERFACE
     ScrnInfoPtr		pScrn = xf86Screens[pScreen->myNum];
-    xf86CrtcConfigPtr   config = XF86_CRTC_CONFIG_PTR(pScrn);
     int			c;
+    xf86CrtcConfigPtr   config = XF86_CRTC_CONFIG_PTR(pScrn);
 
-    randrp->supported_rotations = rotations;
-
-#if RANDR_12_INTERFACE
     for (c = 0; c < config->num_crtc; c++) {
 	xf86CrtcPtr    crtc = config->crtc[c];
 
 	RRCrtcSetRotations (crtc->randr_crtc, rotations);
     }
 #endif
+    randrp->supported_rotations = rotations;
 }
 
 void
diff --git a/hw/xfree86/parser/Makefile.am b/hw/xfree86/parser/Makefile.am
index 1c1ba3f..849ee8b 100644
--- a/hw/xfree86/parser/Makefile.am
+++ b/hw/xfree86/parser/Makefile.am
@@ -36,4 +36,6 @@ EXTRA_DIST = \
 	cpconfig.c
 
 sdk_HEADERS = \
-	$(LIBHEADERS)
+	$(LIBHEADERS) \
+	xf86Parser.h \
+	xf86Optrec.h
diff-tree 55797dd252382d35ebab5d9e18a5e0e77872d775 (from e4507825bf0328ea59673f2bbe652de3a9105c86)
Author: Keith Packard <keithp at guitar.keithp.com>
Date:   Fri Feb 16 00:56:00 2007 -0800

    Respect rotation in initial screen size computation.

diff --git a/hw/xfree86/modes/xf86RandR12.c b/hw/xfree86/modes/xf86RandR12.c
index 1dacb6f..c8ea778 100644
--- a/hw/xfree86/modes/xf86RandR12.c
+++ b/hw/xfree86/modes/xf86RandR12.c
@@ -394,8 +394,8 @@ xf86RandR12CreateScreenResources (Screen
     for (c = 0; c < config->num_crtc; c++)
     {
 	xf86CrtcPtr crtc = config->crtc[c];
-	int	    crtc_width = crtc->x + crtc->mode.HDisplay;
-	int	    crtc_height = crtc->y + crtc->mode.VDisplay;
+	int	    crtc_width = crtc->x + xf86ModeWidth (&crtc->mode, crtc->rotation);
+	int	    crtc_height = crtc->y + xf86ModeHeight (&crtc->mode, crtc->rotation);
 	
 	if (crtc->enabled && crtc_width > width)
 	    width = crtc_width;
diff-tree e4507825bf0328ea59673f2bbe652de3a9105c86 (from 8606aeb9b2ab2dafc11e64436db4d3a7e67dbcc0)
Author: Keith Packard <keithp at guitar.keithp.com>
Date:   Fri Feb 16 00:41:29 2007 -0800

    Enable startup-time rotation; change rotation pixmap creation API.
    
    Add monitor "Rotate" option taking one of "normal", "left", "inverted" or
    "right". However, because initial mode selection is made before the screen
    is completely initialized, we cannot create the shadow pixmap object at this
    point. Pend the shadow pixmap creation until the block handler.
    
    Note that this code is not completely functional yet.

diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c
index bda8055..74e4c76 100644
--- a/hw/xfree86/modes/xf86Crtc.c
+++ b/hw/xfree86/modes/xf86Crtc.c
@@ -344,6 +344,7 @@ typedef enum {
     OPTION_MIN_CLOCK,
     OPTION_MAX_CLOCK,
     OPTION_IGNORE,
+    OPTION_ROTATE,
 } OutputOpts;
 
 static OptionInfoRec xf86OutputOptions[] = {
@@ -358,6 +359,7 @@ static OptionInfoRec xf86OutputOptions[]
     {OPTION_MIN_CLOCK,	    "MinClock",		OPTV_FREQ,    {0}, FALSE },
     {OPTION_MAX_CLOCK,	    "MaxClock",		OPTV_FREQ,    {0}, FALSE },
     {OPTION_IGNORE,	    "Ignore",		OPTV_BOOLEAN, {0}, FALSE },
+    {OPTION_ROTATE,	    "Rotate",		OPTV_STRING,  {0}, FALSE },
     {-1,		    NULL,		OPTV_NONE,    {0}, FALSE },
 };
 
@@ -413,6 +415,29 @@ xf86OutputIgnored (xf86OutputPtr    outp
     return xf86ReturnOptValBool (output->options, OPTION_IGNORE, FALSE);
 }
 
+static char *direction[4] = {
+    "normal", 
+    "left", 
+    "inverted", 
+    "right"
+};
+
+static Rotation
+xf86OutputInitialRotation (xf86OutputPtr output)
+{
+    char    *rotate_name = xf86GetOptValString (output->options, 
+						OPTION_ROTATE);
+    int	    i;
+
+    if (!rotate_name)
+	return RR_Rotate_0;
+    
+    for (i = 0; i < 4; i++)
+	if (xf86nameCompare (direction[i], rotate_name) == 0)
+	    return (1 << i);
+    return RR_Rotate_0;
+}
+
 xf86OutputPtr
 xf86OutputCreate (ScrnInfoPtr		    scrn,
 		  const xf86OutputFuncsRec *funcs,
@@ -533,8 +558,12 @@ xf86DefaultMode (xf86OutputPtr output, i
 	int	    preferred = (mode->type & M_T_PREFERRED) != 0;
 	int	    diff;
 
-	if (mode->HDisplay > width || mode->VDisplay > height) continue;
-	dpi = (mode->HDisplay * 254) / (mm_height * 10);
+	if (xf86ModeWidth (mode, output->initial_rotation) > width ||
+	    xf86ModeHeight (mode, output->initial_rotation) > height)
+	    continue;
+	
+	/* yes, use VDisplay here, not xf86ModeHeight */
+	dpi = (mode->VDisplay * 254) / (mm_height * 10);
 	diff = dpi - 96;
 	diff = diff < 0 ? -diff : diff;
 	if (target_mode == NULL || (preferred > target_preferred) ||
@@ -549,7 +578,8 @@ xf86DefaultMode (xf86OutputPtr output, i
 }
 
 static DisplayModePtr
-xf86ClosestMode (xf86OutputPtr output, DisplayModePtr match,
+xf86ClosestMode (xf86OutputPtr output, 
+		 DisplayModePtr match, Rotation match_rotation,
 		 int width, int height)
 {
     DisplayModePtr  target_mode = NULL;
@@ -564,14 +594,17 @@ xf86ClosestMode (xf86OutputPtr output, D
 	int	    dx, dy;
 	int	    diff;
 
-	if (mode->HDisplay > width || mode->VDisplay > height) continue;
+	if (xf86ModeWidth (mode, output->initial_rotation) > width ||
+	    xf86ModeHeight (mode, output->initial_rotation) > height)
+	    continue;
 	
 	/* exact matches are preferred */
-	if (xf86ModesEqual (mode, match))
+	if (output->initial_rotation == match_rotation &&
+	    xf86ModesEqual (mode, match))
 	    return mode;
 	
-	dx = match->HDisplay - mode->HDisplay;
-	dy = match->VDisplay - mode->VDisplay;
+	dx = xf86ModeWidth (match, match_rotation) - xf86ModeWidth (mode, output->initial_rotation);
+	dy = xf86ModeHeight (match, match_rotation) - xf86ModeHeight (mode, output->initial_rotation);
 	diff = dx * dx + dy * dy;
 	if (target_mode == NULL || diff < target_diff)
 	{
@@ -589,7 +622,10 @@ xf86OutputHasPreferredMode (xf86OutputPt
 
     for (mode = output->probed_modes; mode; mode = mode->next)
     {
-	if (mode->HDisplay > width || mode->VDisplay > height) continue;
+	if (xf86ModeWidth (mode, output->initial_rotation) > width ||
+	    xf86ModeHeight (mode, output->initial_rotation) > height)
+	    continue;
+
 	if (mode->type & M_T_PREFERRED)
 	    return TRUE;
     }
@@ -605,7 +641,7 @@ xf86PickCrtcs (ScrnInfoPtr	scrn,
 	       int		height)
 {
     xf86CrtcConfigPtr	config = XF86_CRTC_CONFIG_PTR(scrn);
-    int		    c, o, l;
+    int		    c, o;
     xf86OutputPtr   output;
     xf86CrtcPtr	    crtc;
     xf86CrtcPtr	    *crtcs;
@@ -663,13 +699,11 @@ xf86PickCrtcs (ScrnInfoPtr	scrn,
 	     * see if they can be cloned
 	     */
 	    if (xf86ModesEqual (modes[o], modes[n]) &&
+		config->output[0]->initial_rotation == config->output[n]->initial_rotation &&
 		config->output[o]->initial_x == config->output[n]->initial_x &&
 		config->output[o]->initial_y == config->output[n]->initial_y)
 	    {
-		for (l = 0; l < config->num_output; l++)
-		    if (output->possible_clones & (1 << l))
-			break;
-		if (l == config->num_output)
+		if ((output->possible_clones & (1 << o)) == 0)
 		    continue;		/* nope, try next CRTC */
 	    }
 	    else
@@ -712,8 +746,8 @@ xf86DefaultScreenLimits (ScrnInfoPtr scr
 
 	if (crtc->enabled)
 	{
-	    crtc_width = crtc->x + crtc->desiredMode.HDisplay;
-	    crtc_height = crtc->y + crtc->desiredMode.VDisplay;
+	    crtc_width = crtc->x + xf86ModeWidth (&crtc->desiredMode, crtc->desiredRotation);
+	    crtc_height = crtc->y + xf86ModeHeight (&crtc->desiredMode, crtc->desiredRotation);
 	}
 	for (o = 0; o < config->num_output; o++) 
 	{
@@ -727,8 +761,12 @@ xf86DefaultScreenLimits (ScrnInfoPtr scr
 		    {
 			if (mode->HDisplay > crtc_width)
 			    crtc_width = mode->HDisplay;
+			if (mode->VDisplay > crtc_width)
+			    crtc_width = mode->VDisplay;
 			if (mode->VDisplay > crtc_height)
 			    crtc_height = mode->VDisplay;
+			if (mode->HDisplay > crtc_height)
+			    crtc_height = mode->HDisplay;
 		    }
 		}
 	}
@@ -858,16 +896,16 @@ xf86InitialOutputPositions (ScrnInfoPtr 
 		output->initial_y = relative->initial_y;
 		switch (relation) {
 		case OPTION_BELOW:
-		    output->initial_y += modes[or]->VDisplay;
+		    output->initial_y += xf86ModeHeight (modes[or], relative->initial_rotation);
 		    break;
 		case OPTION_RIGHT_OF:
-		    output->initial_x += modes[or]->HDisplay;
+		    output->initial_x += xf86ModeWidth (modes[or], relative->initial_rotation);
 		    break;
 		case OPTION_ABOVE:
-		    output->initial_y -= modes[o]->VDisplay;
+		    output->initial_y -= xf86ModeHeight (modes[or], relative->initial_rotation);
 		    break;
 		case OPTION_LEFT_OF:
-		    output->initial_x -= modes[o]->HDisplay;
+		    output->initial_x -= xf86ModeWidth (modes[or], relative->initial_rotation);
 		    break;
 		default:
 		    break;
@@ -1208,6 +1246,8 @@ xf86ProbeOutputModes (ScrnInfoPtr scrn, 
 	    }
 	}
 	
+	output->initial_rotation = xf86OutputInitialRotation (output);
+
 #ifdef DEBUG_REPROBE
 	if (output->probed_modes != NULL) {
 	    xf86DrvMsg(scrn->scrnIndex, X_INFO,
@@ -1310,6 +1350,7 @@ xf86InitialConfiguration (ScrnInfoPtr	  
     xf86CrtcConfigPtr	config = XF86_CRTC_CONFIG_PTR(scrn);
     int			o, c;
     DisplayModePtr	target_mode = NULL;
+    Rotation		target_rotation = RR_Rotate_0;
     xf86CrtcPtr		*crtcs;
     DisplayModePtr	*modes;
     Bool		*enabled;
@@ -1351,6 +1392,7 @@ xf86InitialConfiguration (ScrnInfoPtr	  
 	    xf86OutputHasPreferredMode (output, width, height))
 	{
 	    target_mode = xf86DefaultMode (output, width, height);
+	    target_rotation = output->initial_rotation;
 	    if (target_mode)
 	    {
 		modes[o] = target_mode;
@@ -1367,6 +1409,7 @@ xf86InitialConfiguration (ScrnInfoPtr	  
 	    if (enabled[o])
 	    {
 		target_mode = xf86DefaultMode (output, width, height);
+		target_rotation = output->initial_rotation;
 		if (target_mode)
 		{
 		    modes[o] = target_mode;
@@ -1381,7 +1424,7 @@ xf86InitialConfiguration (ScrnInfoPtr	  
 	xf86OutputPtr output = config->output[o];
 	
 	if (enabled[o] && !modes[o])
-	    modes[o] = xf86ClosestMode (output, target_mode, width, height);
+	    modes[o] = xf86ClosestMode (output, target_mode, target_rotation, width, height);
     }
 
     /*
@@ -1429,6 +1472,7 @@ xf86InitialConfiguration (ScrnInfoPtr	  
 	if (mode && crtc)
 	{
 	    crtc->desiredMode = *mode;
+	    crtc->desiredRotation = output->initial_rotation;
 	    crtc->enabled = TRUE;
 	    crtc->x = output->initial_x;
 	    crtc->y = output->initial_y;
diff --git a/hw/xfree86/modes/xf86Crtc.h b/hw/xfree86/modes/xf86Crtc.h
index 07f7d49..9a70be4 100644
--- a/hw/xfree86/modes/xf86Crtc.h
+++ b/hw/xfree86/modes/xf86Crtc.h
@@ -112,16 +112,22 @@ typedef struct _xf86CrtcFuncs {
 		 int size);
 
     /**
+     * Allocate the shadow area, delay the pixmap creation until needed
+     */
+    void *
+    (*shadow_allocate) (xf86CrtcPtr crtc, int width, int height);
+    
+    /**
      * Create shadow pixmap for rotation support
      */
     PixmapPtr
-    (*shadow_create) (xf86CrtcPtr crtc, int width, int height);
+    (*shadow_create) (xf86CrtcPtr crtc, void *data, int width, int height);
     
     /**
      * Destroy shadow pixmap
      */
     void
-    (*shadow_destroy) (xf86CrtcPtr crtc, PixmapPtr pPixmap);
+    (*shadow_destroy) (xf86CrtcPtr crtc, PixmapPtr pPixmap, void *data);
 
     /**
      * Clean up driver-specific bits of the crtc
@@ -159,6 +165,8 @@ struct _xf86Crtc {
     DisplayModeRec  mode;
     Rotation	    rotation;
     PixmapPtr	    rotatedPixmap;
+    void	    *rotatedData;
+    
     /**
      * Position on screen
      *
@@ -357,6 +365,11 @@ struct _xf86Output {
     int			initial_x, initial_y;
 
     /**
+     * Desired initial rotation
+     */
+    Rotation		initial_rotation;
+
+    /**
      * Current connection status
      *
      * This indicates whether a monitor is known to be connected
diff --git a/hw/xfree86/modes/xf86Modes.c b/hw/xfree86/modes/xf86Modes.c
index 0706783..37d0eb6 100644
--- a/hw/xfree86/modes/xf86Modes.c
+++ b/hw/xfree86/modes/xf86Modes.c
@@ -94,6 +94,36 @@ xf86ModeVRefresh(DisplayModePtr mode)
     return refresh;
 }
 
+int
+xf86ModeWidth (DisplayModePtr mode, Rotation rotation)
+{
+    switch (rotation & 0xf) {
+    case RR_Rotate_0:
+    case RR_Rotate_180:
+	return mode->HDisplay;
+    case RR_Rotate_90:
+    case RR_Rotate_270:
+	return mode->VDisplay;
+    default:
+	return 0;
+    }
+}
+
+int
+xf86ModeHeight (DisplayModePtr mode, Rotation rotation)
+{
+    switch (rotation & 0xf) {
+    case RR_Rotate_0:
+    case RR_Rotate_180:
+	return mode->VDisplay;
+    case RR_Rotate_90:
+    case RR_Rotate_270:
+	return mode->HDisplay;
+    default:
+	return 0;
+    }
+}
+
 /** Sets a default mode name of <width>x<height> on a mode. */
 void
 xf86SetModeDefaultName(DisplayModePtr mode)
diff --git a/hw/xfree86/modes/xf86Modes.h b/hw/xfree86/modes/xf86Modes.h
index 60e2790..9494333 100644
--- a/hw/xfree86/modes/xf86Modes.h
+++ b/hw/xfree86/modes/xf86Modes.h
@@ -36,6 +36,13 @@
 
 double xf86ModeHSync(DisplayModePtr mode);
 double xf86ModeVRefresh(DisplayModePtr mode);
+
+int
+xf86ModeWidth (DisplayModePtr mode, Rotation rotation);
+    
+int
+xf86ModeHeight (DisplayModePtr mode, Rotation rotation);
+
 DisplayModePtr xf86DuplicateMode(DisplayModePtr pMode);
 DisplayModePtr xf86DuplicateModes(ScrnInfoPtr pScrn,
 				       DisplayModePtr modeList);
diff --git a/hw/xfree86/modes/xf86Rename.h b/hw/xfree86/modes/xf86Rename.h
index ce4d217..6cfa5ca 100644
--- a/hw/xfree86/modes/xf86Rename.h
+++ b/hw/xfree86/modes/xf86Rename.h
@@ -74,5 +74,7 @@
 #define xf86RandR12SetRotations XF86NAME(xf86RandR12SetRotations)
 #define xf86SaveScreen XF86NAME(xf86SaveScreen)
 #define xf86CrtcSetScreenSubpixelOrder XF86NAME(xf86CrtcSetScreenSubpixelOrder)
+#define xf86ModeWidth XF86NAME(xf86ModeWidth)
+#define xf86ModeHeight XF86NAME(xf86ModeHeight)
 
 #endif /* _XF86RENAME_H_ */
diff --git a/hw/xfree86/modes/xf86Rotate.c b/hw/xfree86/modes/xf86Rotate.c
index 1d55a6e..7b20498 100644
--- a/hw/xfree86/modes/xf86Rotate.c
+++ b/hw/xfree86/modes/xf86Rotate.c
@@ -44,36 +44,6 @@
 #include "X11/extensions/dpms.h"
 #include "X11/Xatom.h"
 
-static int
-mode_height (DisplayModePtr mode, Rotation rotation)
-{
-    switch (rotation & 0xf) {
-    case RR_Rotate_0:
-    case RR_Rotate_180:
-	return mode->VDisplay;
-    case RR_Rotate_90:
-    case RR_Rotate_270:
-	return mode->HDisplay;
-    default:
-	return 0;
-    }
-}
-
-static int
-mode_width (DisplayModePtr mode, Rotation rotation)
-{
-    switch (rotation & 0xf) {
-    case RR_Rotate_0:
-    case RR_Rotate_180:
-	return mode->HDisplay;
-    case RR_Rotate_90:
-    case RR_Rotate_270:
-	return mode->VDisplay;
-    default:
-	return 0;
-    }
-}
-
 /* borrowed from composite extension, move to Render and publish? */
 
 static VisualPtr
@@ -238,6 +208,42 @@ xf86RotateCrtcRedisplay (xf86CrtcPtr crt
 }
 
 static void
+xf86RotatePrepare (ScreenPtr pScreen)
+{
+    ScrnInfoPtr		pScrn = xf86Screens[pScreen->myNum];
+    xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
+    int			c;
+
+    for (c = 0; c < xf86_config->num_crtc; c++)
+    {
+	xf86CrtcPtr crtc = xf86_config->crtc[c];
+	
+	if (crtc->rotatedData && !crtc->rotatedPixmap)
+	{
+	    BoxRec	    damage_box;
+	    RegionRec   damage_region;
+
+	    crtc->rotatedPixmap = crtc->funcs->shadow_create (crtc,
+							     crtc->rotatedData,
+							     crtc->mode.HDisplay,
+							     crtc->mode.VDisplay);
+	    /* Hook damage to screen pixmap */
+	    DamageRegister (&(*pScreen->GetScreenPixmap)(pScreen)->drawable,
+			    xf86_config->rotationDamage);
+	    
+	    damage_box.x1 = 0;
+	    damage_box.y1 = 0;
+	    damage_box.x2 = xf86ModeWidth (&crtc->mode, crtc->rotation);
+	    damage_box.y2 = xf86ModeHeight (&crtc->mode, crtc->rotation);
+	    REGION_INIT (pScreen, &damage_region, &damage_box, 1);
+	    DamageDamageRegion (&(*pScreen->GetScreenPixmap)(pScreen)->drawable,
+				&damage_region);
+	    REGION_UNINIT (pScreen, &damage_region);
+	}
+    }
+}
+
+static void
 xf86RotateRedisplay(ScreenPtr pScreen)
 {
     ScrnInfoPtr		pScrn = xf86Screens[pScreen->myNum];
@@ -247,6 +253,7 @@ xf86RotateRedisplay(ScreenPtr pScreen)
 
     if (!damage)
 	return;
+    xf86RotatePrepare (pScreen);
     region = DamageRegion(damage);
     if (REGION_NOTEMPTY(pScreen, region)) 
     {
@@ -263,9 +270,9 @@ xf86RotateRedisplay(ScreenPtr pScreen)
 
 		/* compute portion of damage that overlaps crtc */
 		box.x1 = crtc->x;
-		box.x2 = crtc->x + mode_width (&crtc->mode, crtc->rotation);
+		box.x2 = crtc->x + xf86ModeWidth (&crtc->mode, crtc->rotation);
 		box.y1 = crtc->y;
-		box.y2 = crtc->y + mode_height (&crtc->mode, crtc->rotation);
+		box.y2 = crtc->y + xf86ModeHeight (&crtc->mode, crtc->rotation);
 		REGION_INIT(pScreen, &crtc_damage, &box, 1);
 		REGION_INTERSECT (pScreen, &crtc_damage, &crtc_damage, region);
 		
@@ -303,10 +310,11 @@ xf86CrtcRotate (xf86CrtcPtr crtc, Displa
     if (rotation == RR_Rotate_0)
     {
 	/* Free memory from rotation */
-	if (crtc->rotatedPixmap)
+	if (crtc->rotatedPixmap || crtc->rotatedData)
 	{
-	    crtc->funcs->shadow_destroy (crtc, crtc->rotatedPixmap);
+	    crtc->funcs->shadow_destroy (crtc, crtc->rotatedPixmap, crtc->rotatedData);
 	    crtc->rotatedPixmap = NULL;
+	    crtc->rotatedData = NULL;
 	}
 
 	if (xf86_config->rotationDamage)
@@ -331,24 +339,24 @@ xf86CrtcRotate (xf86CrtcPtr crtc, Displa
 	 */
 	int	    width = mode->HDisplay;
 	int	    height = mode->VDisplay;
+	void	    *shadowData = crtc->rotatedData;
 	PixmapPtr   shadow = crtc->rotatedPixmap;
 	int	    old_width = shadow ? shadow->drawable.width : 0;
 	int	    old_height = shadow ? shadow->drawable.height : 0;
-	BoxRec	    damage_box;
-	RegionRec   damage_region;
 	
 	/* Allocate memory for rotation */
 	if (old_width != width || old_height != height)
 	{
-	    if (shadow)
+	    if (shadow || shadowData)
 	    {
-		crtc->funcs->shadow_destroy (crtc, shadow);
+		crtc->funcs->shadow_destroy (crtc, shadow, shadowData);
 		crtc->rotatedPixmap = NULL;
+		crtc->rotatedData = NULL;
 	    }
-	    shadow = crtc->funcs->shadow_create (crtc, width, height);
-	    if (!shadow)
+	    shadowData = crtc->funcs->shadow_allocate (crtc, width, height);
+	    if (!shadowData)
 		goto bail1;
-	    crtc->rotatedPixmap = shadow;
+	    crtc->rotatedData = shadowData;
 	}
 	
 	if (!xf86_config->rotationDamage)
@@ -360,10 +368,6 @@ xf86CrtcRotate (xf86CrtcPtr crtc, Displa
 	    if (!xf86_config->rotationDamage)
 		goto bail2;
 	    
-	    /* Hook damage to screen pixmap */
-	    DamageRegister (&(*pScreen->GetScreenPixmap)(pScreen)->drawable,
-			    xf86_config->rotationDamage);
-	    
 	    /* Assign block/wakeup handler */
 	    if (!RegisterBlockAndWakeupHandlers (xf86RotateBlockHandler,
 						 xf86RotateWakeupHandler,
@@ -371,14 +375,6 @@ xf86CrtcRotate (xf86CrtcPtr crtc, Displa
 	    {
 		goto bail3;
 	    }
-	    damage_box.x1 = 0;
-	    damage_box.y1 = 0;
-	    damage_box.x2 = mode_width (mode, rotation);
-	    damage_box.y2 = mode_height (mode, rotation);
-	    REGION_INIT (pScreen, &damage_region, &damage_box, 1);
-	    DamageDamageRegion (&(*pScreen->GetScreenPixmap)(pScreen)->drawable,
-				&damage_region);
-	    REGION_UNINIT (pScreen, &damage_region);
 	}
 	if (0)
 	{
@@ -387,14 +383,16 @@ bail3:
 	    xf86_config->rotationDamage = NULL;
 	    
 bail2:
-	    if (shadow)
+	    if (shadow || shadowData)
 	    {
-		crtc->funcs->shadow_destroy (crtc, shadow);
+		crtc->funcs->shadow_destroy (crtc, shadow, shadowData);
 		crtc->rotatedPixmap = NULL;
+		crtc->rotatedData = NULL;
 	    }
 bail1:
 	    if (old_width && old_height)
 		crtc->rotatedPixmap = crtc->funcs->shadow_create (crtc,
+								  NULL,
 								  old_width,
 								  old_height);
 	    return FALSE;
diff --git a/hw/xfree86/modes/xf86cvt.c b/hw/xfree86/modes/xf86cvt.c
index dd6febf..69ccc42 100644
--- a/hw/xfree86/modes/xf86cvt.c
+++ b/hw/xfree86/modes/xf86cvt.c
@@ -40,6 +40,7 @@
 #endif
 
 #include "xf86.h"
+#include "xf86Modes.h"
 
 #include <string.h>
 
diff-tree 8606aeb9b2ab2dafc11e64436db4d3a7e67dbcc0 (from a88844eccb0e423e71d4fcb286866a026308babd)
Author: Keith Packard <keithp at guitar.keithp.com>
Date:   Thu Feb 15 22:23:16 2007 -0800

    RRConfigureOutputProperty is a variable length request.
    
    Replace REQUEST_SIZE_MATCH with REQUEST_AT_LEAST_SIZE

diff --git a/randr/rrproperty.c b/randr/rrproperty.c
index 916caf0..edfed1f 100644
--- a/randr/rrproperty.c
+++ b/randr/rrproperty.c
@@ -410,7 +410,7 @@ ProcRRConfigureOutputProperty (ClientPtr
     RROutputPtr				output;
     int					num_valid;
     
-    REQUEST_SIZE_MATCH(xRRConfigureOutputPropertyReq);
+    REQUEST_AT_LEAST_SIZE(xRRConfigureOutputPropertyReq);
 
     output = LookupOutput (client, stuff->output, DixReadAccess);
     
diff-tree a88844eccb0e423e71d4fcb286866a026308babd (from e9a2cc7d9fcc73e16576be2522522cce675dc3f3)
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Sat Feb 17 20:35:07 2007 +0200

    configure.ac: disable dmx per default
    
    Disable DMX until it gets ported to the new input API.

diff --git a/configure.ac b/configure.ac
index 6841ee4..0a3fe45 100644
--- a/configure.ac
+++ b/configure.ac
@@ -532,7 +532,7 @@ AC_ARG_ENABLE(xfree86-utils,     AS_HELP
 
 dnl DDXes.
 AC_ARG_ENABLE(xorg,    	      AS_HELP_STRING([--enable-xorg], [Build Xorg server (default: auto)]), [XORG=$enableval], [XORG=auto])
-AC_ARG_ENABLE(dmx,    	      AS_HELP_STRING([--enable-dmx], [Build DMX server (default: auto)]), [DMX=$enableval], [DMX=auto])
+AC_ARG_ENABLE(dmx,    	      AS_HELP_STRING([--enable-dmx], [Build DMX server (default: no)]), [DMX=$enableval], [DMX=no])
 AC_ARG_ENABLE(xvfb,    	      AS_HELP_STRING([--enable-xvfb], [Build Xvfb server (default: yes)]), [XVFB=$enableval], [XVFB=yes])
 AC_ARG_ENABLE(xnest,   	      AS_HELP_STRING([--enable-xnest], [Build Xnest server (default: auto)]), [XNEST=$enableval], [XNEST=auto])
 AC_ARG_ENABLE(xwin,    	      AS_HELP_STRING([--enable-xwin], [Build XWin server (default: auto)]), [XWIN=$enableval], [XWIN=auto])
diff-tree e9a2cc7d9fcc73e16576be2522522cce675dc3f3 (from 81876bc5ddc2f3eda5078fe4bd101917fb32e586)
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Sat Feb 17 16:17:48 2007 +0200

    config: error message cleanup
    
    Demote failure to connect from ErrorF to DebugF.

diff --git a/config/config.c b/config/config.c
index 76191ab..6c40143 100644
--- a/config/config.c
+++ b/config/config.c
@@ -303,15 +303,15 @@ configSetup(void)
     if (!configData)
         configData = (struct config_data *) xcalloc(sizeof(struct config_data), 1);
     if (!configData) {
-        ErrorF("[dbus] failed to allocate data struct.\n");
+        ErrorF("[dbus] failed to allocate data struct\n");
         return FALSE;
     }
 
     dbus_error_init(&error);
     configData->connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
     if (!configData->connection || dbus_error_is_set(&error)) {
-        ErrorF("[dbus] some kind of error occurred: %s (%s)\n", error.name,
-                error.message);
+        DebugF("[dbus] some kind of error occurred while connecting: %s (%s)\n",
+               error.name, error.message);
         dbus_error_free(&error);
         xfree(configData);
         configData = NULL;
diff-tree 81876bc5ddc2f3eda5078fe4bd101917fb32e586 (from d287b76471f66c9aea54f969d050b35643cb2501)
Author: Ben Byer <bbyer at apple.com>
Date:   Sat Feb 17 04:07:11 2007 -0800

    oops, missed a spot

diff --git a/hw/darwin/Makefile.am b/hw/darwin/Makefile.am
index 87076df..ebbfb61 100644
--- a/hw/darwin/Makefile.am
+++ b/hw/darwin/Makefile.am
@@ -128,7 +128,7 @@ cr_la_SOURCES = \
 		quartz/cr/crAppleWM.m \
 		quartz/cr/crFrame.m \
 		quartz/cr/crScreen.m \
-		quartz/fullscreen/quartzCursor.m \
+		quartz/fullscreen/quartzCursor.c \
 		quartz/cr/XView.m
 
 cr_la_LIBADD = \
diff-tree d287b76471f66c9aea54f969d050b35643cb2501 (from 81444486be4f182dde778bac6f7edcbfc4368482)
Author: Ben Byer <bbyer at apple.com>
Date:   Sat Feb 17 03:47:42 2007 -0800

    cleaned up some linking ugliness in hw/darwin/quartz

diff --git a/configure.ac b/configure.ac
index 3288c09..6841ee4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2061,9 +2061,6 @@ hw/darwin/bundle/Swedish.lproj/Makefile
 hw/darwin/bundle/ko.lproj/Makefile
 hw/darwin/iokit/Makefile
 hw/darwin/quartz/Makefile
-hw/darwin/quartz/cr/Makefile
-hw/darwin/quartz/fullscreen/Makefile
-hw/darwin/quartz/xpr/Makefile
 hw/darwin/utils/Makefile
 hw/kdrive/Makefile
 hw/kdrive/ati/Makefile
diff --git a/hw/darwin/Makefile.am b/hw/darwin/Makefile.am
index 7efd056..87076df 100644
--- a/hw/darwin/Makefile.am
+++ b/hw/darwin/Makefile.am
@@ -3,7 +3,7 @@ libdarwin_XINPUT_SRCS = darwinXinput.c
 
 AM_CFLAGS = @XORG_CFLAGS@ @DIX_CFLAGS@
 AM_CPPFLAGS = @XORG_CFLAGS@ @DIX_CFLAGS@
-INCLUDES = @XORG_INCS@
+INCLUDES = @XORG_INCS@ -I../../miext/rootless
 
 DEFS = @DEFS@ -DUSE_NEW_CLUT
 
@@ -20,7 +20,6 @@ SUBDIRS = \
 
 darwinappdir = @APPLE_APPLICATIONS_DIR@/XDarwin.app
 
-
 libdarwinShared_a_SOURCES = darwin.c \
 			  darwinEvents.c \
 			  darwinKeyboard.c \
@@ -66,6 +65,7 @@ XDarwin_LDFLAGS =  \
 		 -Wl,-framework,IOKit
 
 XDarwin_CFLAGS = -DINXDARWIN
+
 if XQUARTZ
 macosdir = $(darwinappdir)/Contents/MacOS
 
@@ -74,8 +74,8 @@ DEFS += -DDARWIN_WITH_QUARTZ -DXFree86Se
 macos_PROGRAMS = XDarwinApp
 
 XDarwinApp_SOURCES = \
-               	$(top_srcdir)/fb/fbcmap.c \
-               	$(top_srcdir)/mi/miinitext.c \
+                $(top_srcdir)/fb/fbcmap.c \
+                $(top_srcdir)/mi/miinitext.c \
 		$(top_srcdir)/Xi/stubs.c 
 
 XDarwinApp_LDADD = \
@@ -118,21 +118,24 @@ XDarwinApp_LDFLAGS =  \
 		 -Wl,-framework,CoreAudio \
 		 -Wl,-framework,IOKit
 
+XDarwinApp_CFLAGS = -DINXDARWINAPP
 HOOK_TARGETS = xquartz-install-hook
 
 
 crplugindir = $(darwinappdir)/Contents/Resources/cr.bundle/Contents/MacOS
 crplugin_LTLIBRARIES = cr.la
-cr_la_SOURCES =
+cr_la_SOURCES = \
+		quartz/cr/crAppleWM.m \
+		quartz/cr/crFrame.m \
+		quartz/cr/crScreen.m \
+		quartz/fullscreen/quartzCursor.m \
+		quartz/cr/XView.m
+
 cr_la_LIBADD = \
-		quartz/cr/crAppleWM.o \
-		quartz/cr/crFrame.o \
-		quartz/cr/crScreen.o \
-		quartz/fullscreen/quartzCursor.o \
-		quartz/cr/XView.o \
 		$(top_builddir)/miext/rootless/librootless.la \
 		$(top_builddir)/miext/rootless/safeAlpha/libsafeAlpha.la \
 		$(top_builddir)/miext/rootless/accel/librlAccel.la
+
 cr_la_LDFLAGS = -shrext '' -Wl,-framework,ApplicationServices \
 		-Wl,-framework,Cocoa \
 		-Wl,-framework,Carbon \
@@ -143,10 +146,11 @@ cr_la_DEPENDENCIES = XDarwinApp	
 
 fullscreenplugindir = $(darwinappdir)/Contents/Resources/fullscreen.bundle/Contents/MacOS
 fullscreenplugin_LTLIBRARIES = fullscreen.la
-fullscreen_la_SOURCES =
+fullscreen_la_SOURCES = \
+		quartz/fullscreen/fullscreen.c \
+		quartz/fullscreen/quartzCursor.c
+
 fullscreen_la_LIBADD = \
-		quartz/fullscreen/fullscreen.o \
-		quartz/fullscreen/quartzCursor.o \
 		$(top_builddir)/miext/shadow/libshadow.la
 
 fullscreen_la_LDFLAGS = -shrext '' -Wl,-framework,ApplicationServices \
@@ -175,20 +179,22 @@ if HAVE_X_PLUGIN
 
 xprplugindir = $(darwinappdir)/Contents/Resources/xpr.bundle/Contents/MacOS
 xprplugin_LTLIBRARIES = xpr.la
-xpr_la_SOURCES =
+xpr_la_SOURCES = \
+		quartz/xpr/appledri.c \
+		quartz/xpr/dri.c \
+		quartz/xpr/xprAppleWM.c \
+		quartz/xpr/xprCursor.c \
+		quartz/xpr/xprFrame.c \
+		quartz/xpr/xprScreen.c \
+		quartz/xpr/x-hash.c \
+		quartz/xpr/x-hook.c \
+		quartz/xpr/x-list.c
+
 xpr_la_LIBADD = \
-		quartz/xpr/appledri.o \
-		quartz/xpr/dri.o \
-		quartz/xpr/xprAppleWM.o \
-		quartz/xpr/xprCursor.o \
-		quartz/xpr/xprFrame.o \
-		quartz/xpr/xprScreen.o \
-		quartz/xpr/x-hash.o \
-		quartz/xpr/x-hook.o \
-		quartz/xpr/x-list.o \
 		$(top_builddir)/miext/rootless/librootless.la \
 		$(top_builddir)/miext/rootless/safeAlpha/libsafeAlpha.la \
 		$(top_builddir)/miext/rootless/accel/librlAccel.la
+
 xpr_la_LDFLAGS = -shrext '' -Wl,-framework,ApplicationServices \
 		-lXplugin \
 		-XCClinker -bundle_loader -XCClinker XDarwinApp \
diff --git a/hw/darwin/quartz/Makefile.am b/hw/darwin/quartz/Makefile.am
index 9789330..993cdb0 100644
--- a/hw/darwin/quartz/Makefile.am
+++ b/hw/darwin/quartz/Makefile.am
@@ -7,10 +7,8 @@ INCLUDES = -I$(srcdir) -I$(srcdir)/.. @X
 AM_DEFS = -DHAS_CG_MACH_PORT -DHAS_KL_API
 if HAVE_X_PLUGIN
 AM_DEFS += -DBUILD_XPR
-XPR = xpr
 endif
 DEFS = @DEFS@ $(AM_DEFS) -DXBINDIR=\"${bindir}\"
-SUBDIRS = cr fullscreen $(XPR)
 
 libXQuartz_a_SOURCES = \
 		  Preferences.m \
diff --git a/hw/darwin/quartz/cr/Makefile.am b/hw/darwin/quartz/cr/Makefile.am
deleted file mode 100644
index 52a4771..0000000
--- a/hw/darwin/quartz/cr/Makefile.am
+++ /dev/null
@@ -1,20 +0,0 @@
-noinst_LIBRARIES = libcr.a
-AM_CFLAGS =  @XORG_CFLAGS@ @DIX_CFLAGS@
-AM_OBJCFLAGS =  @XORG_CFLAGS@ @DIX_CFLAGS@
-DEFS = @DEFS@ -DDEFER_NSWINDOW
-INCLUDES = @XORG_INCS@ \
-	   -I../fullscreen \
-	   -I$(srcdir) -I$(srcdir)/.. -I$(srcdir)/../.. \
-	   -I$(top_srcdir)/miext/rootless \
-	   -I$(top_srcdir)/miext/rootless/safeAlpha \
-	   -I$(top_srcdir)/mi
-
-libcr_a_SOURCES = crAppleWM.m \
-	           crFrame.m \
-	           crScreen.m \
-	           ../fullscreen/quartzCursor.c \
-	           XView.m
-
-EXTRA_DIST = \
-	cr.h \
-	XView.h 
diff --git a/hw/darwin/quartz/cr/crAppleWM.m b/hw/darwin/quartz/cr/crAppleWM.m
index 259c2d8..0741d4e 100644
--- a/hw/darwin/quartz/cr/crAppleWM.m
+++ b/hw/darwin/quartz/cr/crAppleWM.m
@@ -30,8 +30,8 @@
 #ifdef HAVE_XORG_CONFIG_H
 #include <xorg-config.h>
 #endif
-#include "quartzCommon.h"
-#include "cr.h"
+#include "quartz/quartzCommon.h"
+#include "quartz/cr/cr.h"
 
 #undef BOOL
 #define BOOL xBOOL
@@ -39,7 +39,7 @@
 #include "X11/X.h"
 #define _APPLEWM_SERVER_
 #include "X11/extensions/applewm.h"
-#include "applewmExt.h"
+#include "quartz/applewmExt.h"
 #undef BOOL
 
 #define StdDocumentStyleMask (NSTitledWindowMask | \
diff --git a/hw/darwin/quartz/cr/crFrame.m b/hw/darwin/quartz/cr/crFrame.m
index 3c282ea..2b8e57d 100644
--- a/hw/darwin/quartz/cr/crFrame.m
+++ b/hw/darwin/quartz/cr/crFrame.m
@@ -32,13 +32,13 @@
 #ifdef HAVE_XORG_CONFIG_H
 #include <xorg-config.h>
 #endif
-#include "quartzCommon.h"
-#include "cr.h"
+#include "quartz/quartzCommon.h"
+#include "quartz/cr/cr.h"
 
 #undef BOOL
 #define BOOL xBOOL
 #include "rootless.h"
-#include "applewmExt.h"
+#include "quartz/applewmExt.h"
 #include "windowstr.h"
 #undef BOOL
 
diff --git a/hw/darwin/quartz/cr/crScreen.m b/hw/darwin/quartz/cr/crScreen.m
index b78d1ea..9dd130e 100644
--- a/hw/darwin/quartz/cr/crScreen.m
+++ b/hw/darwin/quartz/cr/crScreen.m
@@ -32,18 +32,18 @@
 #ifdef HAVE_XORG_CONFIG_H
 #include <xorg-config.h>
 #endif
-#include "quartzCommon.h"
-#include "cr.h"
+#include "quartz/quartzCommon.h"
+#include "quartz/cr/cr.h"
 
 #undef BOOL
 #define BOOL xBOOL
 #include "darwin.h"
-#include "quartz.h"
-#include "quartzCursor.h"
+#include "quartz/quartz.h"
+#include "quartz/quartzCursor.h"
 #include "rootless.h"
-#include "safeAlpha.h"
-#include "pseudoramiX.h"
-#include "applewmExt.h"
+#include "safeAlpha/safeAlpha.h"
+#include "quartz/pseudoramiX.h"
+#include "quartz/applewmExt.h"
 
 #include "regionstr.h"
 #include "scrnintstr.h"
diff --git a/hw/darwin/quartz/fullscreen/Makefile.am b/hw/darwin/quartz/fullscreen/Makefile.am
deleted file mode 100644
index f56ad42..0000000
--- a/hw/darwin/quartz/fullscreen/Makefile.am
+++ /dev/null
@@ -1,9 +0,0 @@
-noinst_LIBRARIES = libfullscreen.a
-AM_CFLAGS = @XORG_CFLAGS@ @DIX_CFLAGS@
-INCLUDES = @XORG_INCS@ -I$(srcdir) -I$(srcdir)/.. -I$(srcdir)/../.. 
-
-libfullscreen_a_SOURCES = fullscreen.c \
-			   quartzCursor.c
-
-EXTRA_DIST = \
-	quartzCursor.h
diff --git a/hw/darwin/quartz/fullscreen/fullscreen.c b/hw/darwin/quartz/fullscreen/fullscreen.c
index 456c364..02f6e89 100644
--- a/hw/darwin/quartz/fullscreen/fullscreen.c
+++ b/hw/darwin/quartz/fullscreen/fullscreen.c
@@ -25,13 +25,13 @@
  * holders shall not be used in advertising or otherwise to promote the sale,
  * use or other dealings in this Software without prior written authorization.
  */
- #ifdef HAVE_XORG_CONFIG_H
- #include <xorg-config.h>
- #endif
-#include "quartzCommon.h"
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+#include "quartz/quartzCommon.h"
 #include "darwin.h"
-#include "quartz.h"
-#include "quartzCursor.h"
+#include "quartz/quartz.h"
+#include "quartz/quartzCursor.h"
 #include "colormapst.h"
 #include "scrnintstr.h"
 #include "micmap.h"
diff --git a/hw/darwin/quartz/fullscreen/quartzCursor.c b/hw/darwin/quartz/fullscreen/quartzCursor.c
index f3e753c..77fa008 100644
--- a/hw/darwin/quartz/fullscreen/quartzCursor.c
+++ b/hw/darwin/quartz/fullscreen/quartzCursor.c
@@ -32,8 +32,8 @@
 #ifdef HAVE_XORG_CONFIG_H
 #include <xorg-config.h>
 #endif
-#include "quartzCommon.h"
-#include "quartzCursor.h"
+#include "quartz/quartzCommon.h"
+#include "quartz/quartzCursor.h"
 #include "darwin.h"
 
 #include <pthread.h>
diff --git a/hw/darwin/quartz/xpr/Makefile.am b/hw/darwin/quartz/xpr/Makefile.am
deleted file mode 100644
index 7f2b008..0000000
--- a/hw/darwin/quartz/xpr/Makefile.am
+++ /dev/null
@@ -1,29 +0,0 @@
-noinst_LIBRARIES = libxpr.a
-AM_CFLAGS =  @XORG_CFLAGS@ @DIX_CFLAGS@
-INCLUDES = @XORG_INCS@ \
-	   -I$(srcdir) -I$(srcdir)/.. -I$(srcdir)/../.. \
-	   -I$(top_srcdir)/miext/rootless/safeAlpha \
-	   -I$(top_srcdir)/miext/rootless \
-	   -I$(top_srcdir)/miext
-
-libxpr_a_SOURCES = \
-	appledri.c \
-        dri.c \
-        xprAppleWM.c \
-        xprCursor.c \
-        xprFrame.c \
-        xprScreen.c \
-        x-hash.c \
-        x-hook.c \
-        x-list.c
-
-xprbundledir = @APPLE_APPLICATIONS_DIR@/Resources/xpr.bundle/Contents/MacOS
-
-EXTRA_DIST = \
-	dri.h \
-	dristruct.h \
-	x-hash.h \
-	x-hook.h \
-	x-list.h \
-	Xplugin.h \
-	xpr.h
diff --git a/hw/darwin/quartz/xpr/xprAppleWM.c b/hw/darwin/quartz/xpr/xprAppleWM.c
index 0c827e2..fdf404c 100644
--- a/hw/darwin/quartz/xpr/xprAppleWM.c
+++ b/hw/darwin/quartz/xpr/xprAppleWM.c
@@ -31,12 +31,11 @@
 #include <xorg-config.h>
 #endif
 #include "xpr.h"
-#include "applewmExt.h"
+#include "quartz/applewmExt.h"
 #include "rootless.h"
 #include "Xplugin.h"
 #include <X11/X.h>
 
-
 static int xprSetWindowLevel(
     WindowPtr pWin,
     int level)
diff --git a/hw/darwin/quartz/xpr/xprCursor.c b/hw/darwin/quartz/xpr/xprCursor.c
index 71a4277..e7f23b7 100644
--- a/hw/darwin/quartz/xpr/xprCursor.c
+++ b/hw/darwin/quartz/xpr/xprCursor.c
@@ -33,7 +33,7 @@
 #ifdef HAVE_XORG_CONFIG_H
 #include <xorg-config.h>
 #endif
-#include "quartzCommon.h"
+#include "quartz/quartzCommon.h"
 #include "xpr.h"
 #include "darwin.h"
 #include "Xplugin.h"
diff --git a/hw/darwin/quartz/xpr/xprFrame.c b/hw/darwin/quartz/xpr/xprFrame.c
index 49f8714..b71b2a6 100644
--- a/hw/darwin/quartz/xpr/xprFrame.c
+++ b/hw/darwin/quartz/xpr/xprFrame.c
@@ -35,7 +35,7 @@
 #include "Xplugin.h"
 #include "x-hash.h"
 #include "x-list.h"
-#include "applewmExt.h"
+#include "quartz/applewmExt.h"
 
 #include "propertyst.h"
 #include "dix.h"
diff --git a/hw/darwin/quartz/xpr/xprScreen.c b/hw/darwin/quartz/xpr/xprScreen.c
index a5bccbf..67a0737 100644
--- a/hw/darwin/quartz/xpr/xprScreen.c
+++ b/hw/darwin/quartz/xpr/xprScreen.c
@@ -30,17 +30,17 @@
 #ifdef HAVE_XORG_CONFIG_H
 #include <xorg-config.h>
 #endif
-#include "quartzCommon.h"
-#include "quartz.h"
+#include "quartz/quartzCommon.h"
+#include "quartz/quartz.h"
 #include "xpr.h"
-#include "pseudoramiX.h"
+#include "quartz/pseudoramiX.h"
 #include "darwin.h"
 #include "rootless.h"
-#include "safeAlpha.h"
+#include "safeAlpha/safeAlpha.h"
 #include "dri.h"
 #include "globals.h"
 #include "Xplugin.h"
-#include "applewmExt.h"
+#include "quartz/applewmExt.h"
 
 #ifdef DAMAGE
 # include "damage.h"
@@ -49,7 +49,6 @@
 // Name of GLX bundle for native OpenGL
 static const char *xprOpenGLBundle = "glxCGL.bundle";
 
-
 /*
  * eventHandler
  *  Callback handler for Xplugin events.
@@ -100,7 +99,6 @@ eventHandler(unsigned int type, const vo
     }
 }
 
-
 /*
  * displayScreenBounds
  *  Return the display ID for a particular display index.
@@ -119,7 +117,6 @@ displayAtIndex(int index)
         return kCGNullDirectDisplay;
 }
 
-
 /*
  * displayScreenBounds
  *  Return the bounds of a particular display.
@@ -142,7 +139,6 @@ displayScreenBounds(CGDirectDisplayID id
     return frame;
 }
 
-
 /*
  * xprAddPseudoramiXScreens
  *  Add a single virtual screen encompassing all the physical screens
@@ -198,7 +194,6 @@ xprAddPseudoramiXScreens(int *x, int *y,
     xfree(displayList);
 }
 
-
 /*
  * xprDisplayInit
  *  Find number of CoreGraphics displays and initialize Xplugin.
@@ -221,9 +216,7 @@ xprDisplayInit(void)
         darwinScreensFound =  1;
 
     if (xp_init(XP_IN_BACKGROUND) != Success)
-    {
         FatalError("Could not initialize the Xplugin library.");
-    }
 
     xp_select_events(XP_EVENT_DISPLAY_CHANGED
                      | XP_EVENT_WINDOW_STATE_CHANGED
@@ -236,7 +229,6 @@ xprDisplayInit(void)
     xprAppleWMInit();
 }
 
-
 /*
  * xprAddScreen
  *  Init the framebuffer and record pixmap parameters for the screen.
@@ -306,7 +298,6 @@ xprAddScreen(int index, ScreenPtr pScree
     return TRUE;
 }
 
-
 /*
  * xprSetupScreen
  *  Setup the screen for rootless access.
@@ -343,7 +334,6 @@ xprSetupScreen(int index, ScreenPtr pScr
     return DRIFinishScreenInit(pScreen);
 }
 
-
 /*
  * xprUpdateScreen
  *  Update screen after configuation change.
@@ -360,7 +350,6 @@ xprUpdateScreen(ScreenPtr pScreen)
     RootlessUpdateScreenPixmap(pScreen);
 }
 
-
 /*
  * xprInitInput
  *  Finalize xpr specific setup.
@@ -377,7 +366,6 @@ xprInitInput(int argc, char **argv)
         AppleWMSetScreenOrigin(WindowTable[i]);
 }
 
-
 /*
  * Quartz display mode function list.
  */
@@ -403,7 +391,6 @@ static QuartzModeProcsRec xprModeProcs =
     DRIDestroySurface
 };
 
-
 /*
  * QuartzModeBundleInit
  *  Initialize the display mode bundle after loading.
diff --git a/mi/miinitext.c b/mi/miinitext.c
index 2c560d5..0fc6d15 100644
--- a/mi/miinitext.c
+++ b/mi/miinitext.c
@@ -338,18 +338,18 @@ extern void XFree86DGAExtensionInit(INIT
 #endif
 #ifdef GLXEXT
 typedef struct __GLXprovider __GLXprovider;
-#ifndef __DARWIN__
-extern __GLXprovider __glXMesaProvider;
-extern void GlxPushProvider(__GLXprovider *impl);
-extern void GlxExtensionInit(INITARGS);
-extern void GlxWrapInitVisuals(miInitVisualsProcPtr *);
-#else
+#ifdef INXDARWINAPP
 extern __GLXprovider* __DarwinglXMesaProvider;
 extern void DarwinGlxPushProvider(__GLXprovider *impl);
 extern void DarwinGlxExtensionInit(INITARGS);
 extern void DarwinGlxWrapInitVisuals(miInitVisualsProcPtr *);
-#endif
-#endif
+#else
+extern __GLXprovider __glXMesaProvider;
+extern void GlxPushProvider(__GLXprovider *impl);
+extern void GlxExtensionInit(INITARGS);
+extern void GlxWrapInitVisuals(miInitVisualsProcPtr *);
+#endif // INXDARWINAPP
+#endif // GLXEXT
 #ifdef XF86DRI
 extern void XFree86DRIExtensionInit(INITARGS);
 #endif
@@ -633,14 +633,14 @@ InitExtensions(argc, argv)
 #endif
 
 #ifdef GLXEXT
-#ifndef __DARWIN__
-    GlxPushProvider(&__glXMesaProvider);
-    if (!noGlxExtension) GlxExtensionInit();
-#else
+#ifdef INXDARWINAPP
+    DarwinGlxPushProvider(__DarwinglXMesaProvider);
     if (!noGlxExtension) DarwinGlxExtensionInit();
+#else
     GlxPushProvider(&__glXMesaProvider);
-#endif
-#endif
+    if (!noGlxExtension) GlxExtensionInit();
+#endif // INXDARWINAPP
+#endif // GLXEXT
 #ifdef XFIXES
     /* must be before Render to layer DisplayCursor correctly */
     if (!noXFixesExtension) XFixesExtensionInit();
diff-tree 81444486be4f182dde778bac6f7edcbfc4368482 (from cf4994b0db2fef4c10ce8804adef766bc5118daf)
Author: Ben Byer <bbyer at apple.com>
Date:   Sat Feb 17 02:23:11 2007 -0800

    autoconf goodness for XDarwin, courtesy of pogma

diff --git a/configure.ac b/configure.ac
index a9f85db..3288c09 100644
--- a/configure.ac
+++ b/configure.ac
@@ -280,6 +280,7 @@ case $host_cpu in
 	use_x86_asm="yes"
 	I386_VIDEO=yes
 	case $host_os in
+	        darwin*)	use_x86_asm="no" ;;
 		*linux*)	DEFAULT_INT10=vm86 ;;
 		*freebsd*)	AC_DEFINE(USE_DEV_IO) ;;
 		*netbsd*)	AC_DEFINE(USE_I386_IOPL)
@@ -305,6 +306,7 @@ case $host_cpu in
   	use_x86_asm="yes"
 	I386_VIDEO=yes
 	case $host_os in
+	        darwin*)	use_x86_asm="no" ;;
 		*freebsd*)	AC_DEFINE(USE_DEV_IO, 1, [BSD /dev/io]) ;;
 		*netbsd*)	AC_DEFINE(USE_I386_IOPL, 1, [BSD i386 iopl])
 				SYS_LIBS=-lx86_64
@@ -473,6 +475,10 @@ AC_ARG_WITH(rgb-path,         AS_HELP_ST
 AC_ARG_WITH(dri-driver-path,  AS_HELP_STRING([--with-dri-driver-path=PATH], [Path to DRI drivers (default: ${libdir}/dri)]),
 				[ DRI_DRIVER_PATH="$withval" ],
 				[ DRI_DRIVER_PATH="${libdir}/dri" ])
+APPLE_APPLICATIONS_DIR="${bindir}/Applications"
+AC_ARG_WITH(apple-applications-dir,AS_HELP_STRING([--with-apple-applications-dir=PATH], [Path to the Applications directory (default: ${bindir}/Applications)]),
+                               [ APPLE_APPLICATIONS_DIR="${withval}" ].
+                               [ APPLE_APPLICATIONS_DIR="${bindir}/Applications" ])
 AC_ARG_ENABLE(builddocs,      AS_HELP_STRING([--enable-builddocs], [Build docs (default: disabled)]),
                                 [BUILDDOCS=$enableval],
                                 [BUILDDOCS=no])
@@ -495,6 +501,7 @@ AC_ARG_ENABLE(xres,           AS_HELP_ST
 AC_ARG_ENABLE(xtrap,          AS_HELP_STRING([--disable-xtrap], [Build XTrap extension (default: enabled)]), [XTRAP=$enableval], [XTRAP=yes])
 AC_ARG_ENABLE(record,         AS_HELP_STRING([--disable-record], [Build Record extension (default: enabled)]), [RECORD=$enableval], [RECORD=yes])
 AC_ARG_ENABLE(xv,             AS_HELP_STRING([--disable-xv], [Build Xv extension (default: enabled)]), [XV=$enableval], [XV=yes])
+AC_ARG_ENABLE(quartz,         AS_HELP_STRING([--enable-quartz], [Build with darwin quartz support (default: auto)]), [XQUARTZ=$enableval], [XQUARTZ=auto])
 AC_ARG_ENABLE(xvmc,           AS_HELP_STRING([--disable-xvmc], [Build XvMC extension (default: enabled)]), [XVMC=$enableval], [XVMC=yes])
 AC_ARG_ENABLE(dga,            AS_HELP_STRING([--disable-dga], [Build DGA extension (default: auto)]), [DGA=$enableval], [DGA=auto])
 AC_ARG_ENABLE(screensaver,    AS_HELP_STRING([--disable-screensaver], [Build ScreenSaver extension (default: enabled)]), [SCREENSAVER=$enableval], [SCREENSAVER=yes])
@@ -1007,6 +1014,9 @@ if test "x$GCC" = "xyes"; then
        LD_EXPORT_SYMBOLS_FLAG="-rdynamic"
 fi
 case $host_os in
+       darwin*)
+       LD_EXPORT_SYMBOLS_FLAG=""
+       ;;
        openbsd*)
        LD_EXPORT_SYMBOLS_FLAG="-Wl,--export-dynamic"
        ;;
@@ -1064,7 +1074,19 @@ AC_DEFINE([SVR4],1,[Define to 1 on syste
 AC_MSG_RESULT([yes])], AC_MSG_RESULT([no]))
 
 XSERVER_CFLAGS="$XSERVER_CFLAGS $CORE_INCS $XEXT_INC $COMPOSITE_INC $DAMAGE_INC $FIXES_INC $XI_INC $MI_INC $MIEXT_SHADOW_INC $MIEXT_LAYER_INC $MIEXT_DAMAGE_INC $RENDER_INC $RANDR_INC $FB_INC"
-AC_DEFINE_UNQUOTED(X_BYTE_ORDER,[$ENDIAN],[Endian order])
+AC_DEFINE_UNQUOTED(_X_BYTE_ORDER,[$ENDIAN],[Endian order])
+AH_VERBATIM([X_BYTE_ORDER],[
+/* Deal with multiple architecture compiles on Mac OS X */
+#ifndef __APPLE_CC__
+#define X_BYTE_ORDER _X_BYTE_ORDER
+#else
+#ifdef __BIG_ENDIAN__
+#define X_BYTE_ORDER X_BIG_ENDIAN
+#else
+#define X_BYTE_ORDER X_LITTLE_ENDIAN
+#endif
+#endif
+])
 
 AC_SUBST([XSERVER_LIBS])
 
@@ -1155,7 +1177,6 @@ if test "x$XORG" = xauto; then
 	XORG="yes"
 	case $host_os in
 		cygwin*) XORG="no" ;;
-		darwin*) XORG="no" ;;
 	esac
 fi
 AC_MSG_RESULT([$XORG])
@@ -1269,6 +1290,60 @@ dnl has it in libc), or if libdl is need
 		AC_CHECK_LIB([dl], [dlopen], XORG_LIBS="$XORG_LIBS -ldl"))
 
 	case $host_os in
+         darwin*)
+               XORG_OS="Darwin"
+               build_darwin=yes
+               if test "X$XQUARTZ" = Xauto; then
+                 AC_CACHE_CHECK([for Carbon framework],xorg_cv_Carbon_framework,[
+                 save_LDFLAGS=$LDFLAGS
+                 LDFLAGS="$LDFLAGS -framework Carbon"
+                 AC_LINK_IFELSE([char FSFindFolder();
+int main() {
+FSFindFolder();
+return 0;}
+                 ],[xorg_cv_Carbon_framework=yes],
+                  [xorg_cv_Carbon_framework=no])
+                  LDFLAGS=$save_LDFLAGS])
+                 if test "X$xorg_cv_Carbon_framework" = Xyes; then
+                   AC_DEFINE([DARWIN_WITH_QUARTZ],[1],
+                         [Have Quartz])
+                   XQUARTZ=yes
+                 else
+                   XQUARTZ=no
+                 fi
+               fi
+               AC_CACHE_CHECK([for AGL framework],xorg_cv_AGL_framework,[
+               save_LDFLAGS=$LDFLAGS
+               LDFLAGS="$LDFLAGS -framework AGL"
+               AC_LINK_IFELSE([char aglEnable();
+int main() {
+aglEnable();
+return 0;}
+               ],[xorg_cv_AGL_framework=yes],
+               [xorg_cv_AGL_framework=no])
+               LDFLAGS=$save_LDFLAGS
+               ])
+               AC_CHECK_LIB([Xplugin],[xp_init],[:])
+               AC_SUBST([APPLE_APPLICATIONS_DIR])
+               CFLAGS="${CFLAGS} -D__DARWIN__"
+               PLIST_VERSION_STRING=$VENDOR_VERSION_STRING
+               AC_SUBST([PLIST_VERSION_STRING])
+               PLIST_VENDOR_WEB=$VENDOR_WEB
+               AC_SUBST([PLIST_VENDOR_WEB])
+               # Not sure that we should be disabling all these...
+               if test "x$XF86MISC" = xyes; then
+                       AC_MSG_NOTICE([Disabling XF86Misc extension])
+                       XF86MISC=no
+               fi
+               if test "x$XF86VIDMODE" = xyes; then
+                       AC_MSG_NOTICE([Disabling XF86VidMode extension])
+                       XF86VIDMODE=no
+               fi
+               if test "x$DGA" = xyes; then
+                       AC_MSG_NOTICE([Disabling DGA extension])
+                       DGA=no
+               fi
+               ;;
 	  linux*)
 		if test "x$LNXAPM" = xyes; then
 			XORG_CFLAGS="$XORG_CFLAGS -DXF86PM"
@@ -1391,11 +1466,14 @@ dnl has it in libc), or if libdl is need
 
 	case $host_cpu in
 	  i*86)
-		xorg_bus_ix86pci=yes
+               case $host_os in
+                 darwin*) ;;
+                 *) xorg_bus_ix86pci=yes ;;
+               esac
 		;;
 	  powerpc*)
 		case $host_os in
-		  linux*|freebsd*|netbsd*|openbsd*|kfreebsd*-gnu)
+		  darwin*|linux*|freebsd*|netbsd*|openbsd*|kfreebsd*-gnu)
 			;;
 		  *)
 			xorg_bus_ppcpci="yes"
@@ -1408,7 +1486,7 @@ dnl has it in libc), or if libdl is need
 		;;
 	  x86_64*|amd64*)
 		case $host_os in
-		  freebsd*|kfreebsd*-gnu)
+		  darwin*|freebsd*|kfreebsd*-gnu)
 			# FreeBSD uses the system pci interface
 			;;
 		  *)
@@ -1484,6 +1562,8 @@ AM_CONDITIONAL([SOLARIS_ASM_INLINE], [te
 AM_CONDITIONAL(MFB, [test "x$XORG" = xyes])
 AM_CONDITIONAL(CFB, [test "x$XORG" = xyes])
 AM_CONDITIONAL(AFB, [test "x$XORG" = xyes])
+AM_CONDITIONAL([BUILD_DARWIN],[test "X$build_darwin" = Xyes])
+AM_CONDITIONAL([XQUARTZ],[test "X$XQUARTZ" = Xyes])
 AM_CONDITIONAL(DGA, [test "x$DGA" = xyes])
 
 dnl Xprint DDX
@@ -1494,7 +1574,7 @@ AC_MSG_RESULT([$XPRINT])
 if test "x$XPRINT" = xyes; then
 	PKG_CHECK_MODULES([XPRINT], [printproto x11 xfont $XDMCP_MODULES xau])
 	XPRINT_EXTENSIONS="$XEXT_LIB $DBE_LIB $XTRAP_LIB $RECORD_LIB $RENDER_LIB $COMPOSITE_LIB $RANDR_LIB $XI_LIB $FIXES_LIB $DAMAGE_LIB $XI_LIB $GLX_LIBS"
-	XPRINT_LIBS="$XPRINT_LIBS $DIX_LIB $CONFIG_LIB $XKB_LIB $XKB_STUB_LIB $XPRINT_EXTENSIONS $MI_LIB $MIEXT_DAMAGE_LIB $CWRAP_LIB $OS_LIB $LIBS"
+	XPRINT_LIBS="$DIX_LIB $CONFIG_LIB $XKB_LIB $XKB_STUB_LIB $XPRINT_EXTENSIONS $MI_LIB $MIEXT_DAMAGE_LIB $CWRAP_LIB $OS_LIB $LIBS $XPRINT_LIBS"
 	AC_SUBST([XPRINT_CFLAGS])
 	AC_SUBST([XPRINT_LIBS])
 
@@ -1608,6 +1688,21 @@ AM_CONDITIONAL(XWIN_PRIMARYFB, [test "x$
 AM_CONDITIONAL(XWIN_RANDR, [test "x$XWIN" = xyes])
 AM_CONDITIONAL(XWIN_XV, [test "x$XWIN" = xyes && test "x$XV" = xyes])
 
+dnl Darwin / OS X DDX
+AM_CONDITIONAL(HAVE_X_PLUGIN, [test "x$ac_cv_lib_Xplugin_xp_init" = xyes])
+AM_CONDITIONAL(HAVE_AGL_FRAMEWORK, [test "x$xorg_cv_AGL_framework" = xyes])
+# Support for objc in autotools is minimal and not
+# documented.
+OBJC='$(CC)'
+OBJCLD='$(CCLD)'
+OBJCLINK='$(LINK)'
+OBJCFLAGS='$(CFLAGS)'
+AC_SUBST([OBJC])
+AC_SUBST([OBJCCLD])
+AC_SUBST([OBJCLINK])
+AC_SUBST([OBJCFLAGS])
+# internal, undocumented automake func follows :(
+_AM_DEPENDENCIES([OBJC])
 
 dnl kdrive DDX
 
@@ -1737,12 +1832,6 @@ AM_CONDITIONAL(XFAKESERVER, [test "x$KDR
 AM_CONDITIONAL(KDRIVEVESA, [test x"$ac_cv_header_sys_vm86_h" = xyes])
 AM_CONDITIONAL(KDRIVEFBDEV, [test x"$ac_cv_header_linux_fb_h" = xyes])
 
-dnl XDarwin DDX (FIXME)
-AM_CONDITIONAL(XQUARTZ, false)
-AM_CONDITIONAL(HAVE_X_PLUGIN, false)
-AM_CONDITIONAL(HAVE_AGL_FRAMEWORK, false)
-AM_CONDITIONAL(BUILD_DARWIN, false)
-
 dnl these only go in xkb-config.h (which is shared by the Xorg and Xnest servers)
 AC_DEFINE(__XKBDEFRULES__, "xorg", [Default XKB rules])
 AC_DEFINE_DIR(XKB_BASE_DIRECTORY, XKBPATH, [Path to XKB data])
@@ -1847,6 +1936,7 @@ XORG_RELEASE_VERSION
 AC_OUTPUT([
 Makefile
 GL/Makefile
+GL/apple/Makefile
 GL/glx/Makefile
 GL/mesa/Makefile
 GL/mesa/glapi/Makefile
@@ -1880,6 +1970,8 @@ miext/damage/Makefile
 miext/shadow/Makefile
 miext/cw/Makefile
 miext/rootless/Makefile
+miext/rootless/safeAlpha/Makefile
+miext/rootless/accel/Makefile
 os/Makefile
 randr/Makefile
 render/Makefile
@@ -1957,6 +2049,22 @@ hw/xgl/glxext/module/Makefile
 hw/xnest/Makefile
 hw/xwin/Makefile
 hw/darwin/Makefile
+hw/darwin/bundle/Makefile
+hw/darwin/bundle/Dutch.lproj/Makefile
+hw/darwin/bundle/English.lproj/Makefile
+hw/darwin/bundle/French.lproj/Makefile
+hw/darwin/bundle/German.lproj/Makefile
+hw/darwin/bundle/Japanese.lproj/Makefile
+hw/darwin/bundle/Portuguese.lproj/Makefile
+hw/darwin/bundle/Spanish.lproj/Makefile
+hw/darwin/bundle/Swedish.lproj/Makefile
+hw/darwin/bundle/ko.lproj/Makefile
+hw/darwin/iokit/Makefile
+hw/darwin/quartz/Makefile
+hw/darwin/quartz/cr/Makefile
+hw/darwin/quartz/fullscreen/Makefile
+hw/darwin/quartz/xpr/Makefile
+hw/darwin/utils/Makefile
 hw/kdrive/Makefile
 hw/kdrive/ati/Makefile
 hw/kdrive/chips/Makefile
diff --git a/dix/devices.c b/dix/devices.c
index 0739de6..9f42184 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -213,11 +213,7 @@ CoreKeyboardBell(int volume, DeviceIntPt
 {
     KeybdCtrl *ctrl = arg;
 
-#ifdef __DARWIN__
-    // not yet implemented :(
-#else
     DDXRingBell(volume, ctrl->bell_pitch, ctrl->bell_duration);
-#endif
 }
 
 static void
diff --git a/hw/darwin/darwin.c b/hw/darwin/darwin.c
index e33c321..7da8626 100644
--- a/hw/darwin/darwin.c
+++ b/hw/darwin/darwin.c
@@ -204,6 +204,12 @@ DarwinPrintBanner()
 }
 
 
+void DDXRingBell(int volume, int pitch, int duration)
+{
+  // FIXME -- make some noise, yo
+}
+
+
 /*
  * DarwinSaveScreen
  *  X screensaver support. Not implemented.
diff --git a/hw/darwin/utils/Makefile.am b/hw/darwin/utils/Makefile.am
new file mode 100644
index 0000000..11a2611
--- /dev/null
+++ b/hw/darwin/utils/Makefile.am
@@ -0,0 +1,11 @@
+bin_PROGRAMS = dumpkeymap
+
+dumpkeymap_SOURCES = dumpkeymap.c
+
+dumpkeymap_LDFLAGS = -Wl,-framework,IOKit
+
+man1_MANS = dumpkeymap.man
+
+EXTRA_DIST = \
+            README.txt \
+            dumpkeymap.man
diff --git a/include/dix-config.h.in b/include/dix-config.h.in
index 458e3a1..62e109b 100644
--- a/include/dix-config.h.in
+++ b/include/dix-config.h.in
@@ -35,6 +35,9 @@
 /* Support Damage extension */
 #undef DAMAGE
 
+/* Build for darwin with Quartz support */
+#undef DARWIN_WITH_QUARTZ
+
 /* Use OsVendorInit */
 #undef DDXOSINIT
 
@@ -420,7 +423,17 @@
 #undef XVENDORNAME
 
 /* Endian order */
-#undef X_BYTE_ORDER
+#undef _X_BYTE_ORDER
+/* Deal with multiple architecture compiles on Mac OS X */
+#ifndef __APPLE_CC__
+#define X_BYTE_ORDER _X_BYTE_ORDER
+#else
+#ifdef __BIG_ENDIAN__
+#define X_BYTE_ORDER X_BIG_ENDIAN
+#else
+#define X_BYTE_ORDER X_LITTLE_ENDIAN
+#endif
+#endif
 
 /* Enable GNU and other extensions to the C environment for GLIBC */
 #undef _GNU_SOURCE
diff --git a/include/xorg-server.h.in b/include/xorg-server.h.in
index 48196d8..7b2a4d1 100644
--- a/include/xorg-server.h.in
+++ b/include/xorg-server.h.in
@@ -191,7 +191,17 @@
 #undef XVENDORNAME
 
 /* Endian order */
-#undef X_BYTE_ORDER
+#undef _X_BYTE_ORDER
+/* Deal with multiple architecture compiles on Mac OS X */
+#ifndef __APPLE_CC__
+#define X_BYTE_ORDER _X_BYTE_ORDER
+#else
+#ifdef __BIG_ENDIAN__
+#define X_BYTE_ORDER X_BIG_ENDIAN
+#else
+#define X_BYTE_ORDER X_LITTLE_ENDIAN
+#endif
+#endif
 
 /* BSD-compliant source */
 #undef _BSD_SOURCE
diff-tree cf4994b0db2fef4c10ce8804adef766bc5118daf (from cece0601571f6304e392a3a40505664544b249f3)
Author: Ben Byer <bbyer at apple.com>
Date:   Sat Feb 17 01:21:43 2007 -0800

    dix mods for Darwin

diff --git a/dix/devices.c b/dix/devices.c
index 9f42184..0739de6 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -213,7 +213,11 @@ CoreKeyboardBell(int volume, DeviceIntPt
 {
     KeybdCtrl *ctrl = arg;
 
+#ifdef __DARWIN__
+    // not yet implemented :(
+#else
     DDXRingBell(volume, ctrl->bell_pitch, ctrl->bell_duration);
+#endif
 }
 
 static void
diff --git a/dix/dixfonts.c b/dix/dixfonts.c
index d5b42dc..5f087a3 100644
--- a/dix/dixfonts.c
+++ b/dix/dixfonts.c
@@ -64,6 +64,7 @@ Equipment Corporation.
 #include "opaque.h"
 #include "dixfontstr.h"
 #include "closestr.h"
+#include "dixfont.h"
 
 #ifdef DEBUG
 #include	<stdio.h>
diff --git a/hw/Makefile.am b/hw/Makefile.am
index d00d6fb..99df8e2 100644
--- a/hw/Makefile.am
+++ b/hw/Makefile.am
@@ -1,10 +1,18 @@
 if DMX
+if BUILD_DARWIN
+# Darwin does not need the dmx subdir
+else
 DMX_SUBDIRS = dmx
 endif
+endif
 
 if XORG
+if BUILD_DARWIN
+# Darwin does not need the xfree86 subdir
+else
 XORG_SUBDIRS = xfree86
 endif
+endif
 
 if XVFB
 XVFB_SUBDIRS = vfb
@@ -30,12 +38,15 @@ if XPRINT
 XPRINT_SUBDIRS = xprint
 endif
 
-# need to add darwin support here
+if BUILD_DARWIN
+DARWIN_SUBDIRS = darwin
+endif
 
 SUBDIRS =			\
 	$(XORG_SUBDIRS)		\
 	$(XGL_SUBDIRS)		\
 	$(XWIN_SUBDIRS)		\
+	$(DARWIN_SUBDIRS)	\
 	$(XVFB_SUBDIRS)		\
 	$(XNEST_SUBDIRS)	\
 	$(DMX_SUBDIRS)          \
diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c
index ff878d5..221ab9a 100644
--- a/hw/xfree86/common/xf86Init.c
+++ b/hw/xfree86/common/xf86Init.c
@@ -36,6 +36,7 @@
 #endif
 
 #include <stdlib.h>
+#include <errno.h>
 
 #undef HAS_UTSNAME
 #if !defined(WIN32) && !defined(__UNIXOS2__)
diff --git a/mi/miinitext.c b/mi/miinitext.c
index cb34473..2c560d5 100644
--- a/mi/miinitext.c
+++ b/mi/miinitext.c
@@ -338,12 +338,14 @@ extern void XFree86DGAExtensionInit(INIT
 #endif
 #ifdef GLXEXT
 typedef struct __GLXprovider __GLXprovider;
+#ifndef __DARWIN__
 extern __GLXprovider __glXMesaProvider;
 extern void GlxPushProvider(__GLXprovider *impl);
-#ifndef __DARWIN__
 extern void GlxExtensionInit(INITARGS);
 extern void GlxWrapInitVisuals(miInitVisualsProcPtr *);
 #else
+extern __GLXprovider* __DarwinglXMesaProvider;
+extern void DarwinGlxPushProvider(__GLXprovider *impl);
 extern void DarwinGlxExtensionInit(INITARGS);
 extern void DarwinGlxWrapInitVisuals(miInitVisualsProcPtr *);
 #endif
@@ -629,13 +631,14 @@ InitExtensions(argc, argv)
     if (!noXFree86DRIExtension) XFree86DRIExtensionInit();
 #endif
 #endif
-#ifdef GLXEXT
 
-    GlxPushProvider(&__glXMesaProvider);
+#ifdef GLXEXT
 #ifndef __DARWIN__
+    GlxPushProvider(&__glXMesaProvider);
     if (!noGlxExtension) GlxExtensionInit();
 #else
     if (!noGlxExtension) DarwinGlxExtensionInit();
+    GlxPushProvider(&__glXMesaProvider);
 #endif
 #endif
 #ifdef XFIXES
diff-tree cece0601571f6304e392a3a40505664544b249f3 (from 00b0657b815b95964401c3e36eed54063afbd003)
Author: Ben Byer <bbyer at apple.com>
Date:   Sat Feb 17 01:00:13 2007 -0800

    build fix for configure.ac / BUILD_DARWIN, oops

diff --git a/configure.ac b/configure.ac
index d2d2c87..a9f85db 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1741,6 +1741,7 @@ dnl XDarwin DDX (FIXME)
 AM_CONDITIONAL(XQUARTZ, false)
 AM_CONDITIONAL(HAVE_X_PLUGIN, false)
 AM_CONDITIONAL(HAVE_AGL_FRAMEWORK, false)
+AM_CONDITIONAL(BUILD_DARWIN, false)
 
 dnl these only go in xkb-config.h (which is shared by the Xorg and Xnest servers)
 AC_DEFINE(__XKBDEFRULES__, "xorg", [Default XKB rules])
diff-tree 00b0657b815b95964401c3e36eed54063afbd003 (from 93777c7b96e560da087963040e372aecbfca7bbc)
Author: Ben Byer <bbyer at bbyer.(none)>
Date:   Sat Feb 17 00:55:32 2007 -0800

    glx fixes for XDarwin

diff --git a/GL/Makefile.am b/GL/Makefile.am
index b9337ba..df9f533 100644
--- a/GL/Makefile.am
+++ b/GL/Makefile.am
@@ -1,16 +1,16 @@
-SUBDIRS = glx mesa
-
 # someone could get really crazy someday and add support for the SI...
 
 # xwin/darwin/xfree86 have their accel support under the DDX
 
-APPLE_EXTRAS = \
-	apple/aglGlx.c \
-	apple/indirect.c
+if BUILD_DARWIN
+DARWIN_SUBDIRS = apple
+endif
+SUBDIRS = glx mesa $(DARWIN_SUBDIRS)
+
 WINDOWS_EXTRAS = \
 	windows/ChangeLog \
 	windows/glwindows.h \
 	windows/glwrap.c \
 	windows/indirect.c
 
-EXTRA_DIST = symlink-mesa.sh $(APPLE_EXTRAS) $(WINDOWS_EXTRAS)
+EXTRA_DIST = symlink-mesa.sh $(WINDOWS_EXTRAS)
diff --git a/GL/apple/Makefile.am b/GL/apple/Makefile.am
new file mode 100644
index 0000000..2b2d10c
--- /dev/null
+++ b/GL/apple/Makefile.am
@@ -0,0 +1,15 @@
+AM_CFLAGS = -I$(top_srcdir) \
+	 -I$(top_srcdir)/hw/darwin/quartz \
+	 -I$(top_srcdir)/GL/glx \
+	 -I$(top_srcdir)/hw/darwin/quartz/cr \
+	 -I$(top_srcdir)/GL/include
+
+if HAVE_AGL_FRAMEWORK
+noinst_LIBRARIES = libAGLcore.a 
+libAGLcore_a_SOURCES = aglGlx.c \
+		       $(top_srcdir)/hw/darwin/quartz/xpr/x-list.c \
+		       $(top_srcdir)/hw/darwin/quartz/xpr/x-list.h \
+		       $(top_srcdir)/hw/darwin/quartz/xpr/x-hash.c \
+		       $(top_srcdir)/hw/darwin/quartz/xpr/x-hash.h \
+		       $(top_srcdir)/hw/dmx/glxProxy/compsize.c
+endif
diff --git a/GL/glx/glxbyteorder.h b/GL/glx/glxbyteorder.h
index b9d738d..cdf6b15 100644
--- a/GL/glx/glxbyteorder.h
+++ b/GL/glx/glxbyteorder.h
@@ -39,6 +39,11 @@
 #include <byteswap.h>
 #elif defined(USE_SYS_ENDIAN_H)
 #include <sys/endian.h>
+#elif defined(__APPLE__)
+#include <libkern/OSByteOrder.h>
+#define bswap_16 OSSwapInt16
+#define bswap_32 OSSwapInt32
+#define bswap_64 OSSwapInt64
 #else
 #define	bswap_16(value)  \
  	((((value) & 0xff) << 8) | ((value) >> 8))
diff-tree 93777c7b96e560da087963040e372aecbfca7bbc (from 612144c811fdf06b7c03cf48a321388fe411acd4)
Author: Ben Byer <bbyer at bbyer.(none)>
Date:   Sat Feb 17 00:22:39 2007 -0800

    more patches to make the Quartz part of XDarwin work again
    (thanks Peter and Torrey!)

diff --git a/hw/darwin/quartz/Makefile.am b/hw/darwin/quartz/Makefile.am
new file mode 100644
index 0000000..9789330
--- /dev/null
+++ b/hw/darwin/quartz/Makefile.am
@@ -0,0 +1,56 @@
+noinst_LIBRARIES = libXQuartz.a
+
+AM_CFLAGS = @XORG_CFLAGS@ @DIX_CFLAGS@
+AM_OBJCFLAGS = @XORG_CFLAGS@ @DIX_CFLAGS@
+
+INCLUDES = -I$(srcdir) -I$(srcdir)/.. @XORG_INCS@
+AM_DEFS = -DHAS_CG_MACH_PORT -DHAS_KL_API
+if HAVE_X_PLUGIN
+AM_DEFS += -DBUILD_XPR
+XPR = xpr
+endif
+DEFS = @DEFS@ $(AM_DEFS) -DXBINDIR=\"${bindir}\"
+SUBDIRS = cr fullscreen $(XPR)
+
+libXQuartz_a_SOURCES = \
+		  Preferences.m \
+	          XApplication.m \
+	          XServer.m \
+	          applewm.c \
+	          keysym2ucs.c \
+	          quartz.c \
+	          quartzAudio.c \
+	          quartzCocoa.m \
+	          quartzPasteboard.c \
+	          quartzKeyboard.c \
+	          quartzStartup.c \
+	          pseudoramiX.c
+
+bin_PROGRAMS = XDarwinStartup
+
+XDarwinStartup_SOURCES = XDarwinStartup.c
+XDarwinStartup_LDFLAGS = -Wl,-framework,CoreFoundation \
+			 -Wl,-framework,ApplicationServices
+XDarwinStartupCFLAGS = -DXBINDIR="${bindir}"
+XDARWINROOT = @APPLE_APPLICATIONS_DIR@
+BINDIR = $(bindir)
+install-exec-local:
+	-(cd $(DESTDIR)$(BINDIR); rm X; $(LN_S) XDarwinStartup X)
+
+man1_MANS = XDarwinStartup.man
+
+EXTRA_DIST = \
+	applewmExt.h \
+	keysym2ucs.h \
+	Preferences.h \
+	pseudoramiX.h \
+	quartzAudio.h \
+	quartzCommon.h \
+	quartzCursor.c \
+	quartzCursor.h \
+	quartz.h \
+	quartzPasteboard.h \
+	XApplication.h \
+	XDarwin.pbproj/project.pbxproj \
+	XServer.h \
+	XDarwinStartup.man
diff --git a/hw/darwin/quartz/Preferences.m b/hw/darwin/quartz/Preferences.m
index 6c14f49..eb78fd3 100644
--- a/hw/darwin/quartz/Preferences.m
+++ b/hw/darwin/quartz/Preferences.m
@@ -31,7 +31,9 @@
  * authorization.
  */
 /* $XFree86: xc/programs/Xserver/hw/darwin/quartz/Preferences.m,v 1.5 2004/06/08 22:58:10 torrey Exp $ */
-
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
 #import "quartzCommon.h"
 
 #define BOOL xBOOL
@@ -44,7 +46,7 @@
 
 // Macros to build the path name
 #ifndef XBINDIR
-#define XBINDIR /usr/X11R6/bin
+#define XBINDIR /usr/X11/bin
 #endif
 #define STR(s) #s
 #define XSTRPATH(s) STR(s)
diff --git a/hw/darwin/quartz/XDarwin.pbproj/project.pbxproj b/hw/darwin/quartz/XDarwin.pbproj/project.pbxproj
index 90002db..0ad8314 100644
--- a/hw/darwin/quartz/XDarwin.pbproj/project.pbxproj
+++ b/hw/darwin/quartz/XDarwin.pbproj/project.pbxproj
@@ -387,7 +387,7 @@
 	<key>CFBundleIconFile</key>
 	<string>XDarwin.icns</string>
 	<key>CFBundleIdentifier</key>
-	<string>org.xfree86.XDarwin</string>
+	<string>org.x.x11</string>
 	<key>CFBundleInfoDictionaryVersion</key>
 	<string>6.0</string>
 	<key>CFBundleName</key>
diff --git a/hw/darwin/quartz/XDarwinStartup.c b/hw/darwin/quartz/XDarwinStartup.c
index 8697776..8041e32 100644
--- a/hw/darwin/quartz/XDarwinStartup.c
+++ b/hw/darwin/quartz/XDarwinStartup.c
@@ -48,7 +48,7 @@
 
 // Macros to build the path name
 #ifndef XBINDIR
-#define XBINDIR /usr/X11R6/bin
+#define XBINDIR /usr/X11/bin
 #endif
 #define STR(s) #s
 #define XSTRPATH(s) STR(s) "/"
@@ -124,7 +124,7 @@ int main(
 
         // Otherwise query LaunchServices for the location of the XDarwin application
         theStatus = LSFindApplicationForInfo(kLSUnknownCreator,
-                                             CFSTR("org.xfree86.XDarwin"),
+                                             CFSTR("org.x.x11"),
                                              NULL, NULL, &appURL);
         if (theStatus) {
             fprintf(stderr, "Could not find the XDarwin application. (Error = 0x%lx)\n", theStatus);
diff --git a/hw/darwin/quartz/XServer.m b/hw/darwin/quartz/XServer.m
index a5a1011..32bfbf5 100644
--- a/hw/darwin/quartz/XServer.m
+++ b/hw/darwin/quartz/XServer.m
@@ -36,18 +36,20 @@
  */
 /* $XdotOrg: xc/programs/Xserver/hw/darwin/quartz/XServer.m,v 1.3 2004/07/30 19:12:17 torrey Exp $ */
 /* $XFree86: xc/programs/Xserver/hw/darwin/quartz/XServer.m,v 1.19 2003/11/24 05:39:01 torrey Exp $ */
-
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
 #include "quartzCommon.h"
 
 #define BOOL xBOOL
-#include "X.h"
-#include "Xproto.h"
+#include "X11/X.h"
+#include "X11/Xproto.h"
 #include "os.h"
 #include "opaque.h"
 #include "darwin.h"
 #include "quartz.h"
 #define _APPLEWM_SERVER_
-#include "applewm.h"
+#include "X11/extensions/applewm.h"
 #include "applewmExt.h"
 #undef BOOL
 
@@ -830,13 +832,13 @@ static io_connect_t root_port;
                     chdir(tem);
 
                 /* Setup environment */
-                snprintf(buf, sizeof(buf), ":%s", display);
-                setenv("DISPLAY", buf, TRUE);
+//              snprintf(buf, sizeof(buf), ":%s", display);
+//              setenv("DISPLAY", buf, TRUE);
                 tem = getenv("PATH");
                 if (tem != NULL && tem[0] != NULL)
-                    snprintf(buf, sizeof(buf), "%s:/usr/X11R6/bin", tem);
+                    snprintf(buf, sizeof(buf), "%s:/usr/X11/bin", tem);
                 else
-                    snprintf(buf, sizeof(buf), "/bin:/usr/bin:/usr/X11R6/bin");
+                    snprintf(buf, sizeof(buf), "/bin:/usr/bin:/usr/X11/bin");
                 setenv("PATH", buf, TRUE);
 
                 execvp(argv[0], (char **const) argv);
diff --git a/hw/darwin/quartz/applewm.c b/hw/darwin/quartz/applewm.c
index 224d6c5..869f7a9 100644
--- a/hw/darwin/quartz/applewm.c
+++ b/hw/darwin/quartz/applewm.c
@@ -24,7 +24,9 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF 
 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 **************************************************************************/
-
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
 #include "quartzCommon.h"
 
 #define NEED_REPLIES
@@ -43,7 +45,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN
 #include <X11/Xatom.h>
 #include "darwin.h"
 #define _APPLEWM_SERVER_
-#include "applewmstr.h"
+#include "X11/extensions/applewmstr.h"
 #include "applewmExt.h"
 
 #define DEFINE_ATOM_HELPER(func,atom_name)                      \
diff --git a/hw/darwin/quartz/pseudoramiX.c b/hw/darwin/quartz/pseudoramiX.c
index a003daf..7ba6d5a 100644
--- a/hw/darwin/quartz/pseudoramiX.c
+++ b/hw/darwin/quartz/pseudoramiX.c
@@ -34,7 +34,9 @@ Equipment Corporation.
 ******************************************************************/
 
 #include "pseudoramiX.h"
-
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
 #include "extnsionst.h"
 #include "dixstruct.h"
 #include "window.h"
diff --git a/hw/darwin/quartz/quartz.c b/hw/darwin/quartz/quartz.c
index 36a8bea..913ea72 100644
--- a/hw/darwin/quartz/quartz.c
+++ b/hw/darwin/quartz/quartz.c
@@ -29,14 +29,16 @@
  * holders shall not be used in advertising or otherwise to promote the sale,
  * use or other dealings in this Software without prior written authorization.
  */
-
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
 #include "quartzCommon.h"
 #include "quartz.h"
 #include "darwin.h"
 #include "quartzAudio.h"
 #include "pseudoramiX.h"
 #define _APPLEWM_SERVER_
-#include "applewm.h"
+#include "X11/extensions/applewm.h"
 #include "applewmExt.h"
 
 // X headers
diff --git a/hw/darwin/quartz/quartzAudio.c b/hw/darwin/quartz/quartzAudio.c
index b477b03..16b9c2b 100644
--- a/hw/darwin/quartz/quartzAudio.c
+++ b/hw/darwin/quartz/quartzAudio.c
@@ -35,7 +35,9 @@
  * holders shall not be used in advertising or otherwise to promote the sale,
  * use or other dealings in this Software without prior written authorization.
  */
-
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
 #include "quartzCommon.h"
 #include "quartzAudio.h"
 
@@ -44,6 +46,7 @@
 
 #include "inputstr.h"
 #include <X11/extensions/XI.h>
+#include <assert.h>
 
 void NSBeep();
 
diff --git a/hw/darwin/quartz/quartzCocoa.m b/hw/darwin/quartz/quartzCocoa.m
index 3cb191f..c54c18a 100644
--- a/hw/darwin/quartz/quartzCocoa.m
+++ b/hw/darwin/quartz/quartzCocoa.m
@@ -35,6 +35,9 @@
  * use or other dealings in this Software without prior written authorization.
  */
 /* $XFree86: xc/programs/Xserver/hw/darwin/quartz/quartzCocoa.m,v 1.5 2004/06/08 22:58:10 torrey Exp $ */
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
 
 #include "quartzCommon.h"
 
diff --git a/hw/darwin/quartz/quartzCursor.c b/hw/darwin/quartz/quartzCursor.c
index e2333e2..1e618e3 100644
--- a/hw/darwin/quartz/quartzCursor.c
+++ b/hw/darwin/quartz/quartzCursor.c
@@ -30,6 +30,9 @@
  * use or other dealings in this Software without prior written authorization.
  */
 
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
 #include "quartzCommon.h"
 #include "quartzCursor.h"
 #include "darwin.h"
diff --git a/hw/darwin/quartz/quartzCursor.h b/hw/darwin/quartz/quartzCursor.h
index 56cc94d..57fac68 100644
--- a/hw/darwin/quartz/quartzCursor.h
+++ b/hw/darwin/quartz/quartzCursor.h
@@ -36,6 +36,7 @@
 #include "screenint.h"
 
 Bool QuartzInitCursor(ScreenPtr pScreen);
+void QuartzReallySetCursor(void);
 void QuartzSuspendXCursor(ScreenPtr pScreen);
 void QuartzResumeXCursor(ScreenPtr pScreen, int x, int y);
 
diff --git a/hw/darwin/quartz/quartzKeyboard.c b/hw/darwin/quartz/quartzKeyboard.c
index fc12522..bd2cc25 100644
--- a/hw/darwin/quartz/quartzKeyboard.c
+++ b/hw/darwin/quartz/quartzKeyboard.c
@@ -33,13 +33,16 @@
    prior written authorization.
 */
 
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
 #include "quartzCommon.h"
 
 #include <CoreServices/CoreServices.h>
 #include <Carbon/Carbon.h>
 
 #include "darwinKeyboard.h"
-#include "keysym.h"
+#include "X11/keysym.h"
 #include "keysym2ucs.h"
 
 #ifdef HAS_KL_API
diff --git a/hw/darwin/quartz/quartzPasteboard.c b/hw/darwin/quartz/quartzPasteboard.c
index e92fe5c..a3536fc 100644
--- a/hw/darwin/quartz/quartzPasteboard.c
+++ b/hw/darwin/quartz/quartzPasteboard.c
@@ -30,6 +30,9 @@
  * use or other dealings in this Software without prior written authorization.
  */
 
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
 #include "quartzPasteboard.h"
 
 #include <X11/Xatom.h>
diff --git a/hw/darwin/quartz/quartzStartup.c b/hw/darwin/quartz/quartzStartup.c
index 277e593..38fde3c 100644
--- a/hw/darwin/quartz/quartzStartup.c
+++ b/hw/darwin/quartz/quartzStartup.c
@@ -37,7 +37,7 @@
 #include "quartz.h"
 #include "opaque.h"
 #include "micmap.h"
-
+#include <assert.h>
 int NSApplicationMain(int argc, char *argv[]);
 
 char **envpGlobal;      // argcGlobal and argvGlobal
@@ -52,6 +52,9 @@ static GlxWrapInitVisualsPtr GlxWrapInit
 
 typedef Bool (*QuartzModeBundleInitPtr)(void);
 
+void * __DarwinglXMesaProvider = NULL;
+typedef void (*GlxPushProviderPtr)(void *);
+GlxPushProviderPtr GlxPushProvider = NULL;
 
 /*
  * DarwinHandleGUI
@@ -186,7 +189,7 @@ static void LoadGlxBundle(void)
 
     // Choose the bundle to load
     ErrorF("Loading GLX bundle ");
-    if (quartzUseAGL) {
+    if (/*quartzUseAGL*/0) {
         bundleName = CFStringCreateWithCStringNoCopy(kCFAllocatorDefault,
                                                      quartzOpenGLBundle,
                                                      kCFStringEncodingASCII,
@@ -213,6 +216,14 @@ static void LoadGlxBundle(void)
     }
 
     // Find the GLX init functions
+
+
+    __DarwinglXMesaProvider = (void *) CFBundleGetDataPointerForName(
+			       glxBundle, CFSTR("__glXMesaProvider"));
+
+    GlxPushProvider = (void *) CFBundleGetFunctionPointerForName(
+                                glxBundle, CFSTR("GlxPushProvider"));
+
     GlxExtensionInit = (void *) CFBundleGetFunctionPointerForName(
                                 glxBundle, CFSTR("GlxExtensionInit"));
 
@@ -233,6 +244,18 @@ static void LoadGlxBundle(void)
  * DarwinGlxExtensionInit
  *  Initialize the GLX extension.
  */
+void DarwinGlxPushProvider(void *impl)
+{
+    if (!GlxExtensionInit)
+        LoadGlxBundle();
+	
+    GlxPushProvider(impl);
+}
+
+/*
+ * DarwinGlxExtensionInit
+ *  Initialize the GLX extension.
+ */
 void DarwinGlxExtensionInit(void)
 {
     if (!GlxExtensionInit)
diff-tree 612144c811fdf06b7c03cf48a321388fe411acd4 (from 68d39d8571d8717d26cedc84015d537549520a14)
Author: Ben Byer <bbyer at bbyer.(none)>
Date:   Sat Feb 17 00:09:58 2007 -0800

    More build fixes / updates for XDarwin:
       quartz/cr: "Cocoa Rootless" support (deprecated in favor of xpr?)
       quartz/fullscreen: Fullscreen support using Xplugin (not yet functional)

diff --git a/hw/darwin/quartz/cr/Makefile.am b/hw/darwin/quartz/cr/Makefile.am
new file mode 100644
index 0000000..52a4771
--- /dev/null
+++ b/hw/darwin/quartz/cr/Makefile.am
@@ -0,0 +1,20 @@
+noinst_LIBRARIES = libcr.a
+AM_CFLAGS =  @XORG_CFLAGS@ @DIX_CFLAGS@
+AM_OBJCFLAGS =  @XORG_CFLAGS@ @DIX_CFLAGS@
+DEFS = @DEFS@ -DDEFER_NSWINDOW
+INCLUDES = @XORG_INCS@ \
+	   -I../fullscreen \
+	   -I$(srcdir) -I$(srcdir)/.. -I$(srcdir)/../.. \
+	   -I$(top_srcdir)/miext/rootless \
+	   -I$(top_srcdir)/miext/rootless/safeAlpha \
+	   -I$(top_srcdir)/mi
+
+libcr_a_SOURCES = crAppleWM.m \
+	           crFrame.m \
+	           crScreen.m \
+	           ../fullscreen/quartzCursor.c \
+	           XView.m
+
+EXTRA_DIST = \
+	cr.h \
+	XView.h 
diff --git a/hw/darwin/quartz/cr/XView.m b/hw/darwin/quartz/cr/XView.m
index 5feac6b..8bcd1a7 100644
--- a/hw/darwin/quartz/cr/XView.m
+++ b/hw/darwin/quartz/cr/XView.m
@@ -30,7 +30,9 @@
  * use or other dealings in this Software without prior written authorization.
  */
 /* $XFree86: xc/programs/Xserver/hw/darwin/quartz/cr/XView.m,v 1.1 2003/06/07 05:49:07 torrey Exp $ */
-
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
 #import "XView.h"
 
 
diff --git a/hw/darwin/quartz/cr/crAppleWM.m b/hw/darwin/quartz/cr/crAppleWM.m
index a2e97ff..259c2d8 100644
--- a/hw/darwin/quartz/cr/crAppleWM.m
+++ b/hw/darwin/quartz/cr/crAppleWM.m
@@ -27,16 +27,18 @@
  * use or other dealings in this Software without prior written authorization.
  */
 /* $XFree86: xc/programs/Xserver/hw/darwin/quartz/xpr/xprFrame.c,v 1.2 2003/06/30 01:45:13 torrey Exp $ */
-
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
 #include "quartzCommon.h"
 #include "cr.h"
 
 #undef BOOL
 #define BOOL xBOOL
 #include "rootless.h"
-#include "X.h"
+#include "X11/X.h"
 #define _APPLEWM_SERVER_
-#include "applewm.h"
+#include "X11/extensions/applewm.h"
 #include "applewmExt.h"
 #undef BOOL
 
diff --git a/hw/darwin/quartz/cr/crFrame.m b/hw/darwin/quartz/cr/crFrame.m
index 79d55a4..3c282ea 100644
--- a/hw/darwin/quartz/cr/crFrame.m
+++ b/hw/darwin/quartz/cr/crFrame.m
@@ -29,7 +29,9 @@
  */
 /* $XdotOrg: xc/programs/Xserver/hw/darwin/quartz/cr/crFrame.m,v 1.2 2004/04/23 19:15:51 eich Exp $ */
 /* $XFree86: xc/programs/Xserver/hw/darwin/quartz/cr/crFrame.m,v 1.9 2004/03/19 02:05:29 torrey Exp $ */
-
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
 #include "quartzCommon.h"
 #include "cr.h"
 
diff --git a/hw/darwin/quartz/cr/crScreen.m b/hw/darwin/quartz/cr/crScreen.m
index 21a79e0..b78d1ea 100644
--- a/hw/darwin/quartz/cr/crScreen.m
+++ b/hw/darwin/quartz/cr/crScreen.m
@@ -29,7 +29,9 @@
  * use or other dealings in this Software without prior written authorization.
  */
 /* $XFree86: xc/programs/Xserver/hw/darwin/quartz/cr/crScreen.m,v 1.5 2003/11/12 20:21:52 torrey Exp $ */
-
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
 #include "quartzCommon.h"
 #include "cr.h"
 
diff --git a/hw/darwin/quartz/fullscreen/Makefile.am b/hw/darwin/quartz/fullscreen/Makefile.am
new file mode 100644
index 0000000..f56ad42
--- /dev/null
+++ b/hw/darwin/quartz/fullscreen/Makefile.am
@@ -0,0 +1,9 @@
+noinst_LIBRARIES = libfullscreen.a
+AM_CFLAGS = @XORG_CFLAGS@ @DIX_CFLAGS@
+INCLUDES = @XORG_INCS@ -I$(srcdir) -I$(srcdir)/.. -I$(srcdir)/../.. 
+
+libfullscreen_a_SOURCES = fullscreen.c \
+			   quartzCursor.c
+
+EXTRA_DIST = \
+	quartzCursor.h
diff --git a/hw/darwin/quartz/fullscreen/fullscreen.c b/hw/darwin/quartz/fullscreen/fullscreen.c
index a4881f9..456c364 100644
--- a/hw/darwin/quartz/fullscreen/fullscreen.c
+++ b/hw/darwin/quartz/fullscreen/fullscreen.c
@@ -25,7 +25,9 @@
  * holders shall not be used in advertising or otherwise to promote the sale,
  * use or other dealings in this Software without prior written authorization.
  */
-
+ #ifdef HAVE_XORG_CONFIG_H
+ #include <xorg-config.h>
+ #endif
 #include "quartzCommon.h"
 #include "darwin.h"
 #include "quartz.h"
diff --git a/hw/darwin/quartz/fullscreen/quartzCursor.c b/hw/darwin/quartz/fullscreen/quartzCursor.c
index e2333e2..f3e753c 100644
--- a/hw/darwin/quartz/fullscreen/quartzCursor.c
+++ b/hw/darwin/quartz/fullscreen/quartzCursor.c
@@ -29,7 +29,9 @@
  * holders shall not be used in advertising or otherwise to promote the sale,
  * use or other dealings in this Software without prior written authorization.
  */
-
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
 #include "quartzCommon.h"
 #include "quartzCursor.h"
 #include "darwin.h"
diff-tree 68d39d8571d8717d26cedc84015d537549520a14 (from 5507cb885d861e974be240120ada2ace2a980a72)
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Fri Feb 16 23:02:13 2007 +0200

    kdrive/ephyr: fix keysym type confusion once and for all
    
    Take keysyms in as an XID in hostx_load_keymap() and explicitly
    convert them to CARD32 for loading into the server.  Fixes Xephyr on
    AMD64, wa-hey.

diff --git a/hw/kdrive/ephyr/hostx.c b/hw/kdrive/ephyr/hostx.c
index 573f774..36d3cbd 100644
--- a/hw/kdrive/ephyr/hostx.c
+++ b/hw/kdrive/ephyr/hostx.c
@@ -656,7 +656,7 @@ hostx_paint_debug_rect(int x,     int y,
 void
 hostx_load_keymap(void)
 {
-  KeySym          *keymap;
+  XID             *keymap;
   int              host_width, min_keycode, max_keycode, width;
   int              i,j;
 
@@ -677,7 +677,7 @@ hostx_load_keymap(void)
    */
   width = (host_width > 4) ? 4 : host_width;
 
-  ephyrKeySyms.map = (KeySym *)calloc(sizeof(KeySym),
+  ephyrKeySyms.map = (CARD32 *)calloc(sizeof(CARD32),
                                       (max_keycode - min_keycode + 1) *
                                       width);
   if (!ephyrKeySyms.map)
@@ -685,7 +685,7 @@ hostx_load_keymap(void)
 
   for (i=0; i<(max_keycode - min_keycode+1); i++)
     for (j=0; j<width; j++)
-      ephyrKeySyms.map[(i*width)+j] = keymap[(i*host_width) + j];
+      ephyrKeySyms.map[(i*width)+j] = (CARD32) keymap[(i*host_width) + j];
 
   EPHYR_DBG("keymap width, host:%d kdrive:%d", host_width, width);
   
diff --git a/hw/kdrive/ephyr/hostx.h b/hw/kdrive/ephyr/hostx.h
index 4e3c6af..4d5f37f 100644
--- a/hw/kdrive/ephyr/hostx.h
+++ b/hw/kdrive/ephyr/hostx.h
@@ -56,7 +56,7 @@ typedef struct {
   int             minKeyCode;
   int             maxKeyCode;
   int             mapWidth;
-  KeySym         *map;
+  CARD32         *map;
 } EphyrKeySyms;
 
 struct EphyrHostXEvent
diff-tree 5507cb885d861e974be240120ada2ace2a980a72 (from 84efe23ae834dd3a4d3f3e08832b69469c7382aa)
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Fri Feb 16 23:01:27 2007 +0200

    kdrive: delete input debugging, yet again ...
    
    I have no idea how this keeps on coming back.

diff --git a/hw/kdrive/src/kinput.c b/hw/kdrive/src/kinput.c
index 83da67f..3bf6bad 100644
--- a/hw/kdrive/src/kinput.c
+++ b/hw/kdrive/src/kinput.c
@@ -1915,11 +1915,6 @@ KdEnqueueKeyboardEvent(KdKeyboardInfo   
     KeybdCtrl *ctrl = NULL;
     int type, nEvents, i;
 
-#ifdef DEBUG
-    ErrorF("enqueuing kb event (scancode %d, %s)\n", scan_code, is_up ? "up" : "down");
-    ErrorF("event is from %s\n", ki->name);
-#endif
-    
     if (!ki || !ki->dixdev || !ki->dixdev->kbdfeed || !ki->dixdev->key)
 	return;
 
@@ -1947,9 +1942,6 @@ KdEnqueueKeyboardEvent(KdKeyboardInfo   
 	}
 	
         nEvents = GetKeyboardEvents(kdEvents, ki->dixdev, type, key_code);
-#ifdef DEBUG
-        ErrorF("KdEnqueueKeyboardEvent: got %d events from GKE\n", nEvents);
-#endif
         for (i = 0; i < nEvents; i++)
             KdQueueEvent(ki->dixdev, kdEvents + i);
     }
@@ -2009,12 +2001,6 @@ KdEnqueuePointerEvent(KdPointerInfo *pi,
     }
     z = rz;
 
-#ifdef DEBUG
-    ErrorF("sending motion notification for (%d, %d, %d)\n", x, y, z);
-    ErrorF("  comes from (%d, %d, %d)\n", rx, ry, rz);
-    ErrorF("  is %s\n", (flags & KD_MOUSE_DELTA) ? "relative" : "absolute");
-#endif
-
     if (flags & KD_MOUSE_DELTA)
         dixflags = POINTER_RELATIVE & POINTER_ACCELERATE;
     else
@@ -2028,9 +2014,6 @@ KdEnqueuePointerEvent(KdPointerInfo *pi,
          button <<= 1, n++) {
         if (((pi->buttonState & button) ^ (buttons & button)) &&
            !(buttons & button)) {
-#ifdef DEBUG
-            ErrorF("  posting button release %d\n", n);
-#endif
             _KdEnqueuePointerEvent(pi, ButtonRelease, x, y, z, n,
                                    dixflags, FALSE);
 	}
@@ -2039,9 +2022,6 @@ KdEnqueuePointerEvent(KdPointerInfo *pi,
          button <<= 1, n++) {
 	if (((pi->buttonState & button) ^ (buttons & button)) &&
 	    (buttons & button)) {
-#ifdef DEBUG
-            ErrorF("  posting button press %d\n", n);
-#endif
             _KdEnqueuePointerEvent(pi, ButtonPress, x, y, z, n,
                                    dixflags, FALSE);
         }
@@ -2057,11 +2037,6 @@ _KdEnqueuePointerEvent (KdPointerInfo *p
     int nEvents = 0, i = 0;
     int valuators[3] = { x, y, z };
 
-#ifdef DEBUG
-    ErrorF("mouse enqueuing event from device %s (%d, %d, %d; %d)\n",
-           pi->name, x, y, z, b);
-#endif
-
     /* TRUE from KdHandlePointerEvent, means 'we swallowed the event'. */
     if (!force && KdHandlePointerEvent(pi, type, x, y, z, b, absrel))
         return;
diff-tree 84efe23ae834dd3a4d3f3e08832b69469c7382aa (from 5e7f7436a755a33e48ab91831cc6af710a8344ef)
Author: Ben Byer <bbyer at bbyer.(none)>
Date:   Fri Feb 16 04:37:38 2007 -0800

    updated darwin/quartz/xpr (libXplugin interface for Mac OS X) support

diff --git a/hw/darwin/quartz/xpr/Makefile.am b/hw/darwin/quartz/xpr/Makefile.am
new file mode 100644
index 0000000..7f2b008
--- /dev/null
+++ b/hw/darwin/quartz/xpr/Makefile.am
@@ -0,0 +1,29 @@
+noinst_LIBRARIES = libxpr.a
+AM_CFLAGS =  @XORG_CFLAGS@ @DIX_CFLAGS@
+INCLUDES = @XORG_INCS@ \
+	   -I$(srcdir) -I$(srcdir)/.. -I$(srcdir)/../.. \
+	   -I$(top_srcdir)/miext/rootless/safeAlpha \
+	   -I$(top_srcdir)/miext/rootless \
+	   -I$(top_srcdir)/miext
+
+libxpr_a_SOURCES = \
+	appledri.c \
+        dri.c \
+        xprAppleWM.c \
+        xprCursor.c \
+        xprFrame.c \
+        xprScreen.c \
+        x-hash.c \
+        x-hook.c \
+        x-list.c
+
+xprbundledir = @APPLE_APPLICATIONS_DIR@/Resources/xpr.bundle/Contents/MacOS
+
+EXTRA_DIST = \
+	dri.h \
+	dristruct.h \
+	x-hash.h \
+	x-hook.h \
+	x-list.h \
+	Xplugin.h \
+	xpr.h
diff --git a/hw/darwin/quartz/xpr/appledri.c b/hw/darwin/quartz/xpr/appledri.c
index dd688ca..ef68c86 100644
--- a/hw/darwin/quartz/xpr/appledri.c
+++ b/hw/darwin/quartz/xpr/appledri.c
@@ -35,6 +35,9 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN
  *
  */
 
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
 #define NEED_REPLIES
 #define NEED_EVENTS
 #include <X11/X.h>
diff --git a/hw/darwin/quartz/xpr/appledri.h b/hw/darwin/quartz/xpr/appledri.h
new file mode 100644
index 0000000..9c63037
--- /dev/null
+++ b/hw/darwin/quartz/xpr/appledri.h
@@ -0,0 +1,107 @@
+/* $XFree86: xc/lib/GL/dri/xf86dri.h,v 1.7 2000/12/07 20:26:02 dawes Exp $ */
+/**************************************************************************
+
+Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
+Copyright 2000 VA Linux Systems, Inc.
+Copyright (c) 2002 Apple Computer, Inc.
+All Rights Reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+/*
+ * Authors:
+ *   Kevin E. Martin <martin at valinux.com>
+ *   Jens Owen <jens at valinux.com>
+ *   Rickard E. (Rik) Faith <faith at valinux.com>
+ *
+ */
+
+#ifndef _APPLEDRI_H_
+#define _APPLEDRI_H_
+
+#include <X11/Xfuncproto.h>
+
+#define X_AppleDRIQueryVersion			0
+#define X_AppleDRIQueryDirectRenderingCapable	1
+#define X_AppleDRICreateSurface			2
+#define X_AppleDRIDestroySurface		3
+#define X_AppleDRIAuthConnection                4
+/* Requests up to and including 18 were used in a previous version */
+
+/* Events */
+#define AppleDRIObsoleteEvent1		0
+#define AppleDRIObsoleteEvent2		1
+#define AppleDRIObsoleteEvent3		2
+#define AppleDRISurfaceNotify		3
+#define AppleDRINumberEvents		4
+
+/* Errors */
+#define AppleDRIClientNotLocal		0
+#define AppleDRIOperationNotSupported	1
+#define AppleDRINumberErrors		(AppleDRIOperationNotSupported + 1)
+
+/* Kinds of SurfaceNotify events: */
+#define AppleDRISurfaceNotifyChanged	0
+#define AppleDRISurfaceNotifyDestroyed	1
+
+#ifndef _APPLEDRI_SERVER_
+
+typedef struct {
+    int	type;		    /* of event */
+    unsigned long serial;   /* # of last request processed by server */
+    Bool send_event;	    /* true if this came frome a SendEvent request */
+    Display *display;	    /* Display the event was read from */
+    Window window;	    /* window of event */
+    Time time;		    /* server timestamp when event happened */
+    int kind;		    /* subtype of event */
+    int arg;
+} XAppleDRINotifyEvent;
+
+_XFUNCPROTOBEGIN
+
+Bool XAppleDRIQueryExtension (Display *dpy, int *event_base, int *error_base);
+
+Bool XAppleDRIQueryVersion (Display *dpy, int *majorVersion,
+			    int *minorVersion, int *patchVersion);
+
+Bool XAppleDRIQueryDirectRenderingCapable (Display *dpy, int screen,
+					   Bool *isCapable);
+
+void *XAppleDRISetSurfaceNotifyHandler (void (*fun) (Display *dpy,
+						     unsigned uid, int kind));
+
+Bool XAppleDRIAuthConnection (Display *dpy, int screen, unsigned int magic);
+
+Bool XAppleDRICreateSurface (Display *dpy, int screen, Drawable drawable,
+			     unsigned int client_id, unsigned int key[2],
+			     unsigned int* uid);
+
+Bool XAppleDRIDestroySurface (Display *dpy, int screen, Drawable drawable);
+
+Bool XAppleDRISynchronizeSurfaces (Display *dpy);
+
+_XFUNCPROTOEND
+
+#endif /* _APPLEDRI_SERVER_ */
+#endif /* _APPLEDRI_H_ */
+
diff --git a/hw/darwin/quartz/xpr/appledristr.h b/hw/darwin/quartz/xpr/appledristr.h
new file mode 100644
index 0000000..36a2e89
--- /dev/null
+++ b/hw/darwin/quartz/xpr/appledristr.h
@@ -0,0 +1,176 @@
+/* $XFree86: xc/lib/GL/dri/xf86dristr.h,v 1.9 2001/03/21 16:01:08 dawes Exp $ */
+/**************************************************************************
+
+Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
+Copyright 2000 VA Linux Systems, Inc.
+Copyright (c) 2002 Apple Computer, Inc.
+All Rights Reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+/*
+ * Authors:
+ *   Kevin E. Martin <martin at valinux.com>
+ *   Jens Owen <jens at valinux.com>
+ *   Rickard E. (Rik) Fiath <faith at valinux.com>
+ *
+ */
+
+#ifndef _APPLEDRISTR_H_
+#define _APPLEDRISTR_H_
+
+#include "appledri.h"
+
+#define APPLEDRINAME "Apple-DRI"
+
+#define APPLE_DRI_MAJOR_VERSION	1	/* current version numbers */
+#define APPLE_DRI_MINOR_VERSION	0
+#define APPLE_DRI_PATCH_VERSION	0
+
+typedef struct _AppleDRIQueryVersion {
+    CARD8	reqType;		/* always DRIReqCode */
+    CARD8	driReqType;		/* always X_DRIQueryVersion */
+    CARD16	length B16;
+} xAppleDRIQueryVersionReq;
+#define sz_xAppleDRIQueryVersionReq	4
+
+typedef struct {
+    BYTE	type;			/* X_Reply */
+    BOOL	pad1;
+    CARD16	sequenceNumber B16;
+    CARD32	length B32;
+    CARD16	majorVersion B16;	/* major version of DRI protocol */
+    CARD16	minorVersion B16;	/* minor version of DRI protocol */
+    CARD32	patchVersion B32;       /* patch version of DRI protocol */
+    CARD32	pad3 B32;
+    CARD32	pad4 B32;
+    CARD32	pad5 B32;
+    CARD32	pad6 B32;
+} xAppleDRIQueryVersionReply;
+#define sz_xAppleDRIQueryVersionReply	32
+
+typedef struct _AppleDRIQueryDirectRenderingCapable {
+    CARD8	reqType;		/* always DRIReqCode */
+    CARD8	driReqType;		/* X_DRIQueryDirectRenderingCapable */
+    CARD16	length B16;
+    CARD32	screen B32;
+} xAppleDRIQueryDirectRenderingCapableReq;
+#define sz_xAppleDRIQueryDirectRenderingCapableReq	8
+
+typedef struct {
+    BYTE	type;			/* X_Reply */
+    BOOL	pad1;
+    CARD16	sequenceNumber B16;
+    CARD32	length B32;
+    BOOL	isCapable;
+    BOOL	pad2;
+    BOOL	pad3;
+    BOOL	pad4;
+    CARD32	pad5 B32;
+    CARD32	pad6 B32;
+    CARD32	pad7 B32;
+    CARD32	pad8 B32;
+    CARD32	pad9 B32;
+} xAppleDRIQueryDirectRenderingCapableReply;
+#define sz_xAppleDRIQueryDirectRenderingCapableReply	32
+
+typedef struct _AppleDRIAuthConnection {
+    CARD8	reqType;		/* always DRIReqCode */
+    CARD8	driReqType;		/* always X_DRICloseConnection */
+    CARD16	length B16;
+    CARD32	screen B32;
+    CARD32      magic B32;
+} xAppleDRIAuthConnectionReq;
+#define sz_xAppleDRIAuthConnectionReq	12
+
+typedef struct {
+    BYTE        type;
+    BOOL        pad1;
+    CARD16      sequenceNumber B16;
+    CARD32      length B32;
+    CARD32      authenticated B32;
+    CARD32      pad2 B32;
+    CARD32      pad3 B32;
+    CARD32      pad4 B32;
+    CARD32      pad5 B32;
+    CARD32      pad6 B32;
+} xAppleDRIAuthConnectionReply;
+#define zx_xAppleDRIAuthConnectionReply  32
+
+typedef struct _AppleDRICreateSurface {
+    CARD8	reqType;		/* always DRIReqCode */
+    CARD8	driReqType;		/* always X_DRICreateSurface */
+    CARD16	length B16;
+    CARD32	screen B32;
+    CARD32	drawable B32;
+    CARD32	client_id B32;
+} xAppleDRICreateSurfaceReq;
+#define sz_xAppleDRICreateSurfaceReq	16
+
+typedef struct {
+    BYTE	type;			/* X_Reply */
+    BOOL	pad1;
+    CARD16	sequenceNumber B16;
+    CARD32	length B32;
+    CARD32	key_0 B32;
+    CARD32	key_1 B32;
+    CARD32	uid B32;
+    CARD32	pad4 B32;
+    CARD32	pad5 B32;
+    CARD32	pad6 B32;
+} xAppleDRICreateSurfaceReply;
+#define sz_xAppleDRICreateSurfaceReply	32
+
+typedef struct _AppleDRIDestroySurface {
+    CARD8	reqType;		/* always DRIReqCode */
+    CARD8	driReqType;		/* always X_DRIDestroySurface */
+    CARD16	length B16;
+    CARD32	screen B32;
+    CARD32	drawable B32;
+} xAppleDRIDestroySurfaceReq;
+#define sz_xAppleDRIDestroySurfaceReq	12
+
+typedef struct _AppleDRINotify {
+	BYTE	type;		/* always eventBase + event type */
+	BYTE	kind;
+	CARD16	sequenceNumber B16;
+	Time	time B32;	/* time of change */
+	CARD16	pad1 B16;
+	CARD32	arg B32;
+	CARD32	pad3 B32;
+} xAppleDRINotifyEvent;
+#define sz_xAppleDRINotifyEvent	20
+
+#ifdef _APPLEDRI_SERVER_
+
+void AppleDRISendEvent (
+#if NeedFunctionPrototypes
+    int			/* type */,
+    unsigned int	/* mask */,
+    int			/* which */,
+    int			/* arg */
+#endif
+);
+
+#endif /* _APPLEDRI_SERVER_ */
+#endif /* _APPLEDRISTR_H_ */
diff --git a/hw/darwin/quartz/xpr/dri.c b/hw/darwin/quartz/xpr/dri.c
index 9aeaaa5..08ee382 100644
--- a/hw/darwin/quartz/xpr/dri.c
+++ b/hw/darwin/quartz/xpr/dri.c
@@ -33,6 +33,9 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN
  *   Rickard E. (Rik) Faith <faith at valinux.com>
  *
  */
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
 
 #include <sys/time.h>
 #include <unistd.h>
diff --git a/hw/darwin/quartz/xpr/x-hash.c b/hw/darwin/quartz/xpr/x-hash.c
index a7024b2..40e530f 100644
--- a/hw/darwin/quartz/xpr/x-hash.c
+++ b/hw/darwin/quartz/xpr/x-hash.c
@@ -27,7 +27,9 @@
    copyright holders shall not be used in advertising or otherwise to
    promote the sale, use or other dealings in this Software without
    prior written authorization. */
-
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
 #include "x-hash.h"
 #include "x-list.h"
 #include <stdlib.h>
diff --git a/hw/darwin/quartz/xpr/x-hook.c b/hw/darwin/quartz/xpr/x-hook.c
index dcd34fd..7a04967 100644
--- a/hw/darwin/quartz/xpr/x-hook.c
+++ b/hw/darwin/quartz/xpr/x-hook.c
@@ -28,7 +28,9 @@
    promote the sale, use or other dealings in this Software without
    prior written authorization. */
 /* $XFree86: $ */
-
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
 #include "x-hook.h"
 #include <stdlib.h>
 #include <assert.h>
diff --git a/hw/darwin/quartz/xpr/x-list.c b/hw/darwin/quartz/xpr/x-list.c
index b9f2392..a973e03 100644
--- a/hw/darwin/quartz/xpr/x-list.c
+++ b/hw/darwin/quartz/xpr/x-list.c
@@ -27,7 +27,9 @@
    copyright holders shall not be used in advertising or otherwise to
    promote the sale, use or other dealings in this Software without
    prior written authorization. */
-
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
 #include "x-list.h"
 #include <stdlib.h>
 #include <assert.h>
diff --git a/hw/darwin/quartz/xpr/xprAppleWM.c b/hw/darwin/quartz/xpr/xprAppleWM.c
index 21746f6..0c827e2 100644
--- a/hw/darwin/quartz/xpr/xprAppleWM.c
+++ b/hw/darwin/quartz/xpr/xprAppleWM.c
@@ -27,7 +27,9 @@
  * holders shall not be used in advertising or otherwise to promote the sale,
  * use or other dealings in this Software without prior written authorization.
  */
-
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
 #include "xpr.h"
 #include "applewmExt.h"
 #include "rootless.h"
diff --git a/hw/darwin/quartz/xpr/xprCursor.c b/hw/darwin/quartz/xpr/xprCursor.c
index cb949da..71a4277 100644
--- a/hw/darwin/quartz/xpr/xprCursor.c
+++ b/hw/darwin/quartz/xpr/xprCursor.c
@@ -30,7 +30,9 @@
  * holders shall not be used in advertising or otherwise to promote the sale,
  * use or other dealings in this Software without prior written authorization.
  */
-
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
 #include "quartzCommon.h"
 #include "xpr.h"
 #include "darwin.h"
diff --git a/hw/darwin/quartz/xpr/xprFrame.c b/hw/darwin/quartz/xpr/xprFrame.c
index ed02d4b..49f8714 100644
--- a/hw/darwin/quartz/xpr/xprFrame.c
+++ b/hw/darwin/quartz/xpr/xprFrame.c
@@ -27,7 +27,9 @@
  * holders shall not be used in advertising or otherwise to promote the sale,
  * use or other dealings in this Software without prior written authorization.
  */
-
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
 #include "xpr.h"
 #include "rootlessCommon.h"
 #include "Xplugin.h"
diff --git a/hw/darwin/quartz/xpr/xprScreen.c b/hw/darwin/quartz/xpr/xprScreen.c
index 1755ca6..a5bccbf 100644
--- a/hw/darwin/quartz/xpr/xprScreen.c
+++ b/hw/darwin/quartz/xpr/xprScreen.c
@@ -27,7 +27,9 @@
  * holders shall not be used in advertising or otherwise to promote the sale,
  * use or other dealings in this Software without prior written authorization.
  */
-
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
 #include "quartzCommon.h"
 #include "quartz.h"
 #include "xpr.h"
diff-tree 5e7f7436a755a33e48ab91831cc6af710a8344ef (from f350909d1696fcfda87e8f12c729254d762313c9)
Author: Ben Byer <bbyer at bbyer.(none)>
Date:   Fri Feb 16 04:12:26 2007 -0800

    merged in miext/rootless changes for XDarwin support

diff --git a/miext/Makefile.am b/miext/Makefile.am
index 4fa584b..f138963 100644
--- a/miext/Makefile.am
+++ b/miext/Makefile.am
@@ -2,4 +2,7 @@ SUBDIRS = damage shadow
 if COMPOSITE
 SUBDIRS += cw
 endif
+if XQUARTZ
+SUBDIRS += rootless
+endif
 DIST_SUBDIRS = damage shadow cw rootless
diff --git a/miext/rootless/Makefile.am b/miext/rootless/Makefile.am
index ecf762a..8dae6d2 100644
--- a/miext/rootless/Makefile.am
+++ b/miext/rootless/Makefile.am
@@ -1,14 +1,13 @@
-EXTRA_DIST = \
-	accel/rlAccel.c \
-	accel/rlAccel.h \
-	accel/rlBlt.c \
-	accel/rlCopy.c \
-	accel/rlFill.c \
-	accel/rlFillRect.c \
-	accel/rlFillSpans.c \
-	accel/rlGlyph.c \
-	accel/rlSolid.c \
-	README.txt \
+AM_CFLAGS =  \
+	    $(DIX_CFLAGS) \
+	    $(XORG_CFLAGS)
+
+INCLUDES = -I$(top_srcdir)/hw/xfree86/os-support
+
+SUBDIRS = safeAlpha accel
+
+noinst_LTLIBRARIES = librootless.la
+librootless_la_SOURCES = \
 	rootlessCommon.c \
 	rootlessCommon.h \
 	rootlessConfig.h \
@@ -17,7 +16,7 @@ EXTRA_DIST = \
 	rootlessScreen.c \
 	rootlessValTree.c \
 	rootlessWindow.c \
-	rootlessWindow.h \
-	safeAlpha/safeAlpha.h \
-	safeAlpha/safeAlphaPicture.c \
-	safeAlpha/safeAlphaWindow.c
+	rootlessWindow.h 
+
+EXTRA_DIST = \
+	README.txt
diff --git a/miext/rootless/accel/Makefile.am b/miext/rootless/accel/Makefile.am
new file mode 100644
index 0000000..c49d5fb
--- /dev/null
+++ b/miext/rootless/accel/Makefile.am
@@ -0,0 +1,18 @@
+AM_CFLAGS =  \
+	    $(DIX_CFLAGS) \
+	    $(XORG_CFLAGS)
+
+INCLUDES = -I$(srcdir)/.. -I$(top_srcdir)/hw/xfree86/os-support
+
+
+noinst_LTLIBRARIES = librlAccel.la
+librlAccel_la_SOURCES = rlAccel.c \
+	             rlBlt.c \
+	             rlCopy.c \
+	             rlFill.c \
+	             rlFillRect.c \
+	             rlFillSpans.c \
+	             rlGlyph.c \
+	             rlSolid.c
+
+EXTRA_DIST = rlAccel.h
diff --git a/miext/rootless/accel/rlBlt.c b/miext/rootless/accel/rlBlt.c
index d1e7658..2cf72eb 100644
--- a/miext/rootless/accel/rlBlt.c
+++ b/miext/rootless/accel/rlBlt.c
@@ -31,6 +31,7 @@
 #include <dix-config.h>
 #endif
 
+#include <stddef.h> /* For NULL */
 #include "fb.h"
 #include "rootlessCommon.h"
 #include "rlAccel.h"
diff --git a/miext/rootless/rootlessCommon.c b/miext/rootless/rootlessCommon.c
index 8fd922d..9cbb7fa 100644
--- a/miext/rootless/rootlessCommon.c
+++ b/miext/rootless/rootlessCommon.c
@@ -33,6 +33,9 @@
 #include <dix-config.h>
 #endif
 
+#include <stddef.h> /* For NULL */
+#include <limits.h> /* For CHAR_BIT */
+
 #include "rootlessCommon.h"
 
 unsigned int rootless_CopyBytes_threshold = 0;
diff --git a/miext/rootless/rootlessGC.c b/miext/rootless/rootlessGC.c
index 5341267..b26f52c 100644
--- a/miext/rootless/rootlessGC.c
+++ b/miext/rootless/rootlessGC.c
@@ -33,6 +33,7 @@
 #include <dix-config.h>
 #endif
 
+#include <stddef.h> /* For NULL */
 #include "mi.h"
 #include "scrnintstr.h"
 #include "gcstruct.h"
diff --git a/miext/rootless/rootlessValTree.c b/miext/rootless/rootlessValTree.c
index 97348f5..4f16530 100644
--- a/miext/rootless/rootlessValTree.c
+++ b/miext/rootless/rootlessValTree.c
@@ -93,6 +93,7 @@ Equipment Corporation.
 #include <dix-config.h>
 #endif
 
+#include <stddef.h> /* For NULL */
 #include    <X11/X.h>
 #include    "scrnintstr.h"
 #include    "validate.h"
diff --git a/miext/rootless/rootlessWindow.c b/miext/rootless/rootlessWindow.c
index e89ebf8..30b7daa 100644
--- a/miext/rootless/rootlessWindow.c
+++ b/miext/rootless/rootlessWindow.c
@@ -33,6 +33,10 @@
 #include <dix-config.h>
 #endif
 
+#include <stddef.h> /* For NULL */
+#include <limits.h> /* For CHAR_BIT */
+#include <assert.h>
+
 #include "rootlessCommon.h"
 #include "rootlessWindow.h"
 
@@ -325,8 +329,8 @@ RootlessEnsureFrame(WindowPtr pWin)
     RootlessWindowRec *winRec;
 #ifdef SHAPE
     RegionRec shape;
-    RegionPtr pShape = NULL;
 #endif
+    RegionPtr pShape = NULL;
 
     if (WINREC(pWin) != NULL)
         return WINREC(pWin);
diff --git a/miext/rootless/safeAlpha/Makefile.am b/miext/rootless/safeAlpha/Makefile.am
new file mode 100644
index 0000000..7592c18
--- /dev/null
+++ b/miext/rootless/safeAlpha/Makefile.am
@@ -0,0 +1,12 @@
+AM_CFLAGS = \
+	    $(DIX_CFLAGS) \
+            $(XORG_CFLAGS)
+
+INCLUDES = -I$(srcdir)/.. -I$(top_srcdir)/hw/xfree86/os-support
+
+
+noinst_LTLIBRARIES = libsafeAlpha.la
+libsafeAlpha_la_SOURCES = safeAlphaPicture.c \
+		       safeAlphaWindow.c
+
+EXTRA_DIST = safeAlpha.h
diff --git a/miext/rootless/safeAlpha/safeAlphaPicture.c b/miext/rootless/safeAlpha/safeAlphaPicture.c
index 8550cc0..6ccc05a 100644
--- a/miext/rootless/safeAlpha/safeAlphaPicture.c
+++ b/miext/rootless/safeAlpha/safeAlphaPicture.c
@@ -33,15 +33,19 @@
  * Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc.
  */
 
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
 #ifdef RENDER
 
+#include <stddef.h> /* For NULL */
 #include "fb.h"
 #include "picturestr.h"
 #include "mipict.h"
 #include "fbpict.h"
 #include "safeAlpha.h"
 #include "rootlessCommon.h"
-
 # define mod(a,b)	((b) == 1 ? 0 : (a) >= 0 ? (a) % (b) : (b) - (-a) % (b))
 
 
diff --git a/miext/rootless/safeAlpha/safeAlphaWindow.c b/miext/rootless/safeAlpha/safeAlphaWindow.c
index 8884c10..5226782 100644
--- a/miext/rootless/safeAlpha/safeAlphaWindow.c
+++ b/miext/rootless/safeAlpha/safeAlphaWindow.c
@@ -32,6 +32,10 @@
  * Copyright © 1998 Keith Packard
  */
 
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
 #include "fb.h"
 #include "safeAlpha.h"
 #include "rootlessCommon.h"
diff --git a/os/utils.c b/os/utils.c
index 7c725e3..612c264 100644
--- a/os/utils.c
+++ b/os/utils.c
@@ -1871,7 +1871,7 @@ Fopen(char *file, char *type)
     pidlist = cur;
 
 #ifdef DEBUG
-    ErrorF("Popen: `%s', fp = %p\n", command, iop);
+    ErrorF("Fopen(%s), fp = %p\n", file, iop);
 #endif
 
     return iop;
diff-tree f350909d1696fcfda87e8f12c729254d762313c9 (from 258beebc77510f84fbea66d6ebf29c5097bd11db)
Author: Keith Packard <keithp at guitar.keithp.com>
Date:   Thu Feb 15 21:50:48 2007 -0800

    Kludge around duplicate code added in hw/xfree86/modes.
    
    Code added in hw/xfree86/modes came from the server-1.3-branch.
    Portions of this code had previously been integrated into xf86Mode.c
    and edid_modes.c.
    
    To preserve hw/xfree86/modes as much as possible, the duplicate code from
    the other files has been disabled; a more careful review would figure out
    where that code actually belonged.

diff --git a/hw/xfree86/common/xf86Mode.c b/hw/xfree86/common/xf86Mode.c
index d5085b5..fc905df 100644
--- a/hw/xfree86/common/xf86Mode.c
+++ b/hw/xfree86/common/xf86Mode.c
@@ -368,6 +368,7 @@ xf86HandleBuiltinMode(ScrnInfoPtr scrp,
     return MODE_OK;
 }
 
+#if 0
 /** Calculates the horizontal sync rate of a mode */
 _X_EXPORT double
 xf86ModeHSync(DisplayModePtr mode)
@@ -411,6 +412,7 @@ xf86SetModeDefaultName(DisplayModePtr mo
 
     mode->name = XNFprintf("%dx%d", mode->HDisplay, mode->VDisplay);
 }
+#endif
 
 /*
  * xf86LookupMode
@@ -680,6 +682,7 @@ xf86LookupMode(ScrnInfoPtr scrp, Display
 }
 
 
+#if 0
 /*
  * xf86SetModeCrtc
  *
@@ -733,7 +736,9 @@ xf86SetModeCrtc(DisplayModePtr p, int ad
     p->CrtcHAdjusted = FALSE;
     p->CrtcVAdjusted = FALSE;
 }
+#endif
 
+#if 0
 /**
  * Allocates and returns a copy of pMode, including pointers within pMode.
  */
@@ -814,6 +819,7 @@ xf86ModesEqual(DisplayModePtr pMode1, Di
 	return FALSE;
      }
 }
+#endif
 
 /*
  * xf86CheckModeForMonitor
@@ -2040,6 +2046,7 @@ add(char **p, char *new)
     strcat(*p, new);
 }
 
+#if 0
 _X_EXPORT void
 xf86PrintModeline(int scrnIndex,DisplayModePtr mode)
 {
@@ -2075,6 +2082,7 @@ xf86PrintModeline(int scrnIndex,DisplayM
 		   mode->VTotal, flags);
     xfree(flags);
 }
+#endif
 
 _X_EXPORT void
 xf86PrintModes(ScrnInfoPtr scrp)
@@ -2145,6 +2153,7 @@ xf86PrintModes(ScrnInfoPtr scrp)
     } while (p != NULL && p != scrp->modes);
 }
 
+#if 0
 /**
  * Adds the new mode into the mode list, and returns the new list
  *
@@ -2168,3 +2177,4 @@ xf86ModesAdd(DisplayModePtr modes, Displ
 
     return modes;
 }
+#endif
diff --git a/hw/xfree86/ddc/Makefile.am b/hw/xfree86/ddc/Makefile.am
index f3ac803..04d3e44 100644
--- a/hw/xfree86/ddc/Makefile.am
+++ b/hw/xfree86/ddc/Makefile.am
@@ -3,8 +3,7 @@ sdk_HEADERS = edid.h vdif.h xf86DDC.h
 noinst_LIBRARIES = libddc.a
 
 libddc_a_SOURCES = xf86DDC.c edid.c interpret_edid.c print_edid.c \
-                   interpret_vdif.c print_vdif.c ddcProperty.c \
-		   edid_modes.c
+                   interpret_vdif.c print_vdif.c ddcProperty.c
 
 INCLUDES = $(XORG_INCS) -I$(srcdir)/../i2c
 
diff --git a/hw/xfree86/modes/Makefile.am b/hw/xfree86/modes/Makefile.am
index 60d2553..e0b6136 100644
--- a/hw/xfree86/modes/Makefile.am
+++ b/hw/xfree86/modes/Makefile.am
@@ -24,4 +24,4 @@ sdk_HEADERS = \
 	xf86RandR12.h \
 	xf86Rename.h
 
-AM_CFLAGS = $(XORG_CFLAGS)
+AM_CFLAGS = $(DIX_CFLAGS) $(XORG_CFLAGS)
diff --git a/hw/xfree86/modes/xf86EdidModes.c b/hw/xfree86/modes/xf86EdidModes.c
index 77c0c87..c4cf687 100644
--- a/hw/xfree86/modes/xf86EdidModes.c
+++ b/hw/xfree86/modes/xf86EdidModes.c
@@ -259,6 +259,50 @@ DDCModeFromDetailedTiming(int scrnIndex,
     return Mode;
 }
 
+/*
+ *
+ */
+static void
+DDCGuessRangesFromModes(int scrnIndex, MonPtr Monitor, DisplayModePtr Modes)
+{
+    DisplayModePtr Mode = Modes;
+
+    if (!Monitor || !Modes)
+        return;
+
+    /* set up the ranges for scanning through the modes */
+    Monitor->nHsync = 1;
+    Monitor->hsync[0].lo = 1024.0;
+    Monitor->hsync[0].hi = 0.0;
+
+    Monitor->nVrefresh = 1;
+    Monitor->vrefresh[0].lo = 1024.0;
+    Monitor->vrefresh[0].hi = 0.0;
+
+    while (Mode) {
+        if (!Mode->HSync)
+            Mode->HSync = ((float) Mode->Clock ) / ((float) Mode->HTotal);
+
+        if (!Mode->VRefresh)
+            Mode->VRefresh = (1000.0 * ((float) Mode->Clock)) / 
+                ((float) (Mode->HTotal * Mode->VTotal));
+
+        if (Mode->HSync < Monitor->hsync[0].lo)
+            Monitor->hsync[0].lo = Mode->HSync;
+
+        if (Mode->HSync > Monitor->hsync[0].hi)
+            Monitor->hsync[0].hi = Mode->HSync;
+
+        if (Mode->VRefresh < Monitor->vrefresh[0].lo)
+            Monitor->vrefresh[0].lo = Mode->VRefresh;
+
+        if (Mode->VRefresh > Monitor->vrefresh[0].hi)
+            Monitor->vrefresh[0].hi = Mode->VRefresh;
+
+        Mode = Mode->next;
+    }
+}
+
 DisplayModePtr
 xf86DDCGetModes(int scrnIndex, xf86MonPtr DDC)
 {
@@ -341,3 +385,106 @@ xf86DDCGetModes(int scrnIndex, xf86MonPt
     }
     return Modes;
 }
+
+/*
+ * Fill out MonPtr with xf86MonPtr information.
+ */
+void
+xf86DDCMonitorSet(int scrnIndex, MonPtr Monitor, xf86MonPtr DDC)
+{
+    DisplayModePtr Modes = NULL, Mode;
+    int i, clock;
+    Bool have_hsync = FALSE, have_vrefresh = FALSE;
+
+    if (!Monitor || !DDC)
+        return;
+
+    Monitor->DDC = DDC;
+
+    Monitor->widthmm = 10 * DDC->features.hsize;
+    Monitor->heightmm = 10 * DDC->features.vsize;
+
+    /* If this is a digital display, then we can use reduced blanking */
+    if (DDC->features.input_type)
+        Monitor->reducedblanking = TRUE;
+    /* Allow the user to also enable this through config */
+
+    Modes = xf86DDCGetModes(scrnIndex, DDC);
+
+    /* Skip EDID ranges if they were specified in the config file */
+    have_hsync = (Monitor->nHsync != 0);
+    have_vrefresh = (Monitor->nVrefresh != 0);
+
+    /* Go through the detailed monitor sections */
+    for (i = 0; i < DET_TIMINGS; i++) {
+        switch (DDC->det_mon[i].type) {
+        case DS_RANGES:
+	    if (!have_hsync) {
+		if (!Monitor->nHsync)
+		    xf86DrvMsg(scrnIndex, X_INFO,
+			    "Using EDID range info for horizontal sync\n");
+		Monitor->hsync[Monitor->nHsync].lo =
+		    DDC->det_mon[i].section.ranges.min_h;
+		Monitor->hsync[Monitor->nHsync].hi =
+		    DDC->det_mon[i].section.ranges.max_h;
+		Monitor->nHsync++;
+	    } else {
+		xf86DrvMsg(scrnIndex, X_INFO,
+			"Using hsync ranges from config file\n");
+	    }
+
+	    if (!have_vrefresh) {
+		if (!Monitor->nVrefresh)
+		    xf86DrvMsg(scrnIndex, X_INFO,
+			    "Using EDID range info for vertical refresh\n");
+		Monitor->vrefresh[Monitor->nVrefresh].lo =
+		    DDC->det_mon[i].section.ranges.min_v;
+		Monitor->vrefresh[Monitor->nVrefresh].hi =
+		    DDC->det_mon[i].section.ranges.max_v;
+		Monitor->nVrefresh++;
+	    } else {
+		xf86DrvMsg(scrnIndex, X_INFO,
+			"Using vrefresh ranges from config file\n");
+	    }
+
+	    clock = DDC->det_mon[i].section.ranges.max_clock * 1000;
+	    if (clock > Monitor->maxPixClock)
+		Monitor->maxPixClock = clock;
+
+            break;
+        default:
+            break;
+        }
+    }
+
+    if (Modes) {
+        /* Print Modes */
+        xf86DrvMsg(scrnIndex, X_INFO, "Printing DDC gathered Modelines:\n");
+
+        Mode = Modes;
+        while (Mode) {
+            xf86PrintModeline(scrnIndex, Mode);
+            Mode = Mode->next;
+        }
+
+        /* Do we still need ranges to be filled in? */
+        if (!Monitor->nHsync || !Monitor->nVrefresh)
+            DDCGuessRangesFromModes(scrnIndex, Monitor, Modes);
+
+        /* look for last Mode */
+        Mode = Modes;
+
+        while (Mode->next)
+            Mode = Mode->next;
+
+        /* add to MonPtr */
+        if (Monitor->Modes) {
+            Monitor->Last->next = Modes;
+            Modes->prev = Monitor->Last;
+            Monitor->Last = Mode;
+        } else {
+            Monitor->Modes = Modes;
+            Monitor->Last = Mode;
+        }
+    }
+}
diff-tree 258beebc77510f84fbea66d6ebf29c5097bd11db (from ef6b1235fd7d6dc422e8a150c089496a8e648067)
Author: Keith Packard <keithp at guitar.keithp.com>
Date:   Thu Feb 15 20:13:15 2007 -0800

    Report correct RandR 1.0 sizeID. Report correct subpixel order.
    
    RandR 1.0 sizeID must be computed the same way every time, so when reporting
    it in the ScreenChangeNotify event, just construct the usual 1.0 data block
    and use that.
    
    subpixel geometry information can be computed by looking at the connected
    outputs and finding any with subpixel geometry and using one of those for
    the global screen subpixel geometry. This might be improved by reporting
    None if more than one screen has information and they conflict.

diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c
index 5e0a0c6..bda8055 100644
--- a/hw/xfree86/modes/xf86Crtc.c
+++ b/hw/xfree86/modes/xf86Crtc.c
@@ -144,6 +144,71 @@ xf86CrtcInUse (xf86CrtcPtr crtc)
     return FALSE;
 }
 
+void
+xf86CrtcSetScreenSubpixelOrder (ScreenPtr pScreen)
+{
+#ifdef RENDER
+    int			subpixel_order = SubPixelUnknown;
+    Bool		has_none = FALSE;
+    ScrnInfoPtr		scrn = xf86Screens[pScreen->myNum];
+    xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+    int			c, o;
+
+    for (c = 0; c < xf86_config->num_crtc; c++)
+    {
+	xf86CrtcPtr crtc = xf86_config->crtc[c];
+	
+	for (o = 0; o < xf86_config->num_output; o++)
+	{
+	    xf86OutputPtr   output = xf86_config->output[o];
+
+	    if (output->crtc == crtc)
+	    {
+		switch (output->subpixel_order) {
+		case SubPixelNone:
+		    has_none = TRUE;
+		    break;
+		case SubPixelUnknown:
+		    break;
+		default:
+		    subpixel_order = output->subpixel_order;
+		    break;
+		}
+	    }
+	    if (subpixel_order != SubPixelUnknown)
+		break;
+	}
+	if (subpixel_order != SubPixelUnknown)
+	{
+	    static const int circle[4] = {
+		SubPixelHorizontalRGB,
+		SubPixelVerticalRGB,
+		SubPixelHorizontalBGR,
+		SubPixelVerticalBGR,
+	    };
+	    int	rotate;
+	    int c;
+	    for (rotate = 0; rotate < 4; rotate++)
+		if (crtc->rotation & (1 << rotate))
+		    break;
+	    for (c = 0; c < 4; c++)
+		if (circle[c] == subpixel_order)
+		    break;
+	    c = (c + rotate) & 0x3;
+	    if ((crtc->rotation & RR_Reflect_X) && !(c & 1))
+		c ^= 2;
+	    if ((crtc->rotation & RR_Reflect_Y) && (c & 1))
+		c ^= 2;
+	    subpixel_order = circle[c];
+	    break;
+	}
+    }
+    if (subpixel_order == SubPixelUnknown && has_none)
+	subpixel_order = SubPixelNone;
+    PictureSetSubpixelOrder (pScreen, subpixel_order);
+#endif
+}
+
 /**
  * Sets the given video mode on the given crtc
  */
@@ -245,6 +310,8 @@ xf86CrtcSetMode (xf86CrtcPtr crtc, Displ
 
     /* XXX free adjustedmode */
     ret = TRUE;
+    xf86CrtcSetScreenSubpixelOrder (scrn->pScreen);
+
 done:
     if (!ret) {
 	crtc->x = saved_x;
diff --git a/hw/xfree86/modes/xf86Crtc.h b/hw/xfree86/modes/xf86Crtc.h
index 49f4965..07f7d49 100644
--- a/hw/xfree86/modes/xf86Crtc.h
+++ b/hw/xfree86/modes/xf86Crtc.h
@@ -552,4 +552,12 @@ xf86DiDGAInit (ScreenPtr pScreen, unsign
 Bool
 xf86DiDGAReInit (ScreenPtr pScreen);
 
+/*
+ * Set the subpixel order reported for the screen using
+ * the information from the outputs
+ */
+
+void
+xf86CrtcSetScreenSubpixelOrder (ScreenPtr pScreen);
+
 #endif /* _XF86CRTC_H_ */
diff --git a/hw/xfree86/modes/xf86RandR12.c b/hw/xfree86/modes/xf86RandR12.c
index 2a5d7ba..1dacb6f 100644
--- a/hw/xfree86/modes/xf86RandR12.c
+++ b/hw/xfree86/modes/xf86RandR12.c
@@ -433,6 +433,7 @@ xf86RandR12CreateScreenResources (Screen
 	randrp->virtualX = pScrn->virtualX;
 	randrp->virtualY = pScrn->virtualY;
     }
+    xf86CrtcSetScreenSubpixelOrder (pScreen);
 #if RANDR_12_INTERFACE
     if (xf86RandR12CreateScreenResources12 (pScreen))
 	return TRUE;
diff --git a/hw/xfree86/modes/xf86Rename.h b/hw/xfree86/modes/xf86Rename.h
index a00253d..ce4d217 100644
--- a/hw/xfree86/modes/xf86Rename.h
+++ b/hw/xfree86/modes/xf86Rename.h
@@ -73,5 +73,6 @@
 #define xf86RandR12SetConfig XF86NAME(xf86RandR12SetConfig)
 #define xf86RandR12SetRotations XF86NAME(xf86RandR12SetRotations)
 #define xf86SaveScreen XF86NAME(xf86SaveScreen)
+#define xf86CrtcSetScreenSubpixelOrder XF86NAME(xf86CrtcSetScreenSubpixelOrder)
 
 #endif /* _XF86RENAME_H_ */
diff --git a/randr/rrscreen.c b/randr/rrscreen.c
index e10aa03..1680003 100644
--- a/randr/rrscreen.c
+++ b/randr/rrscreen.c
@@ -26,6 +26,9 @@ extern char	*ConnectionInfo;
 
 static int padlength[4] = {0, 3, 2, 1};
 
+static CARD16
+RR10CurrentSizeID (ScreenPtr pScreen);
+
 /*
  * Edit connection information block so that new clients
  * see the current screen size on connect
@@ -96,10 +99,7 @@ RRDeliverScreenEvent (ClientPtr client, 
     rrScrPriv (pScreen);
     xRRScreenChangeNotifyEvent	se;
     RRCrtcPtr	crtc = pScrPriv->numCrtcs ? pScrPriv->crtcs[0] : NULL;
-    RROutputPtr	output = pScrPriv->numOutputs ? pScrPriv->outputs[0] : NULL;
-    RRModePtr	mode = crtc ? crtc->mode : NULL;
     WindowPtr	pRoot = WindowTable[pScreen->myNum];
-    int		i;
     
     se.type = RRScreenChangeNotify + RREventBase;
     se.rotation = (CARD8) (crtc ? crtc->rotation : RR_Rotate_0);
@@ -115,32 +115,12 @@ RRDeliverScreenEvent (ClientPtr client, 
 #endif
 
     se.sequenceNumber = client->sequence;
-    if (mode) 
-    {
-	se.sizeID = -1;
-	for (i = 0; i < output->numModes; i++)
-	    if (mode == output->modes[i])
-	    {
-		se.sizeID = i;
-		break;
-	    }
-	se.widthInPixels = mode->mode.width;
-	se.heightInPixels = mode->mode.height;
-	se.widthInMillimeters = pScreen->mmWidth;
-	se.heightInMillimeters = pScreen->mmHeight;
-    }
-    else
-    {
-	/*
-	 * This "shouldn't happen", but a broken DDX can
-	 * forget to set the current configuration on GetInfo
-	 */
-	se.sizeID = 0xffff;
-	se.widthInPixels = 0;
-	se.heightInPixels = 0;
-	se.widthInMillimeters = 0;
-	se.heightInMillimeters = 0;
-    }    
+    se.sizeID = RR10CurrentSizeID (pScreen);
+    
+    se.widthInPixels = pScreen->width;
+    se.heightInPixels = pScreen->height;
+    se.widthInMillimeters = pScreen->mmWidth;
+    se.heightInMillimeters = pScreen->mmHeight;
     WriteEventsToClient (client, 1, (xEvent *) &se);
 }
 
@@ -949,3 +929,27 @@ sendReply:
     return (client->noClientException);
 }
 
+static CARD16
+RR10CurrentSizeID (ScreenPtr pScreen)
+{
+    CARD16	sizeID = 0xffff;
+    RROutputPtr output = RRFirstOutput (pScreen);
+    
+    if (output)
+    {
+	RR10DataPtr data = RR10GetData (pScreen, output);
+	if (data)
+	{
+	    int i;
+	    for (i = 0; i < data->nsize; i++)
+		if (data->sizes[i].width == pScreen->width &&
+		    data->sizes[i].height == pScreen->height)
+		{
+		    sizeID = (CARD16) i;
+		    break;
+		}
+	    xfree (data);
+	}
+    }
+    return sizeID;
+}
diff-tree ef6b1235fd7d6dc422e8a150c089496a8e648067 (from 3dbe8f6b6ea32a9a137ad6e9235f74009b095bd8)
Author: Keith Packard <keithp at guitar.keithp.com>
Date:   Thu Feb 15 11:27:35 2007 -0800

    Allow new modes code to build inside drivers as well as server.
    
    Use config.h for driver builds where xorg-config.h isn't available.

diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c
index ab7070b..5e0a0c6 100644
--- a/hw/xfree86/modes/xf86Crtc.c
+++ b/hw/xfree86/modes/xf86Crtc.c
@@ -22,6 +22,10 @@
 
 #ifdef HAVE_XORG_CONFIG_H
 #include <xorg-config.h>
+#else
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 #endif
 
 #include <stddef.h>
diff --git a/hw/xfree86/modes/xf86DiDGA.c b/hw/xfree86/modes/xf86DiDGA.c
index f4ac4de..551f052 100644
--- a/hw/xfree86/modes/xf86DiDGA.c
+++ b/hw/xfree86/modes/xf86DiDGA.c
@@ -22,6 +22,10 @@
 
 #ifdef HAVE_XORG_CONFIG_H
 #include <xorg-config.h>
+#else
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 #endif
 
 #include "xf86.h"
diff --git a/hw/xfree86/modes/xf86EdidModes.c b/hw/xfree86/modes/xf86EdidModes.c
index 0476a68..77c0c87 100644
--- a/hw/xfree86/modes/xf86EdidModes.c
+++ b/hw/xfree86/modes/xf86EdidModes.c
@@ -27,6 +27,10 @@
  */
 #ifdef HAVE_XORG_CONFIG_H
 #include <xorg-config.h>
+#else
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 #endif
 
 #include "xf86.h"
diff --git a/hw/xfree86/modes/xf86Modes.c b/hw/xfree86/modes/xf86Modes.c
index d126e5e..0706783 100644
--- a/hw/xfree86/modes/xf86Modes.c
+++ b/hw/xfree86/modes/xf86Modes.c
@@ -30,6 +30,10 @@
 
 #ifdef HAVE_XORG_CONFIG_H
 #include <xorg-config.h>
+#else
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 #endif
 
 #include <stddef.h>
diff --git a/hw/xfree86/modes/xf86RandR12.c b/hw/xfree86/modes/xf86RandR12.c
index bafe71f..2a5d7ba 100644
--- a/hw/xfree86/modes/xf86RandR12.c
+++ b/hw/xfree86/modes/xf86RandR12.c
@@ -25,6 +25,10 @@
 
 #ifdef HAVE_XORG_CONFIG_H
 #include <xorg-config.h>
+#else
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 #endif
 
 #include "xf86.h"
diff --git a/hw/xfree86/modes/xf86Rotate.c b/hw/xfree86/modes/xf86Rotate.c
index 1e79063..1d55a6e 100644
--- a/hw/xfree86/modes/xf86Rotate.c
+++ b/hw/xfree86/modes/xf86Rotate.c
@@ -22,6 +22,10 @@
 
 #ifdef HAVE_XORG_CONFIG_H
 #include <xorg-config.h>
+#else
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 #endif
 
 #include <stddef.h>
diff --git a/hw/xfree86/modes/xf86cvt.c b/hw/xfree86/modes/xf86cvt.c
index 4256577..dd6febf 100644
--- a/hw/xfree86/modes/xf86cvt.c
+++ b/hw/xfree86/modes/xf86cvt.c
@@ -33,6 +33,10 @@
 
 #ifdef HAVE_XORG_CONFIG_H
 #include <xorg-config.h>
+#else
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 #endif
 
 #include "xf86.h"
diff-tree 3dbe8f6b6ea32a9a137ad6e9235f74009b095bd8 (from d4eb4d065032112a38444e36f791cb468a5ca8f4)
Author: Tilman Sauerbeck <tilman at code-monkey.de>
Date:   Thu Feb 15 17:51:01 2007 +0100

    Distribute hw/xfree86/modes.

diff --git a/hw/xfree86/Makefile.am b/hw/xfree86/Makefile.am
index 5bed7d9..1a286d6 100644
--- a/hw/xfree86/Makefile.am
+++ b/hw/xfree86/Makefile.am
@@ -17,7 +17,7 @@ SUBDIRS = common ddc dummylib i2c x86emu
 
 DIST_SUBDIRS = common ddc dummylib i2c x86emu int10 fbdevhw os-support \
                parser rac ramdac shadowfb vbe vgahw xaa xf1bpp xf4bpp \
-               xf8_16bpp xf8_32bpp loader scanpci dixmods dri exa \
+               xf8_16bpp xf8_32bpp loader scanpci dixmods dri exa modes \
 	       utils doc
 
 bin_PROGRAMS = Xorg
diff-tree d4eb4d065032112a38444e36f791cb468a5ca8f4 (from 37fe4c49dc3a5faf2d3d56112b6bd78453045f6a)
Author: Keith Packard <keithp at guitar.keithp.com>
Date:   Thu Feb 15 20:36:20 2007 -0800

    Merge crtc/output-based mode selection code.
    
    This code comes from the intel driver, so there's no history in this tree.
    
    As the crtc/output-based mode selection code uses ddc, the ddc and i2c
    modules have been merged into the server. Attempts to load them are safely
    ignored now.

diff --git a/configure.ac b/configure.ac
index afbf980..d2d2c87 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1905,6 +1905,7 @@ hw/xfree86/fbdevhw/Makefile
 hw/xfree86/i2c/Makefile
 hw/xfree86/int10/Makefile
 hw/xfree86/loader/Makefile
+hw/xfree86/modes/Makefile
 hw/xfree86/os-support/Makefile
 hw/xfree86/os-support/bsd/Makefile
 hw/xfree86/os-support/bus/Makefile
diff --git a/hw/xfree86/Makefile.am b/hw/xfree86/Makefile.am
index 0c1306f..5bed7d9 100644
--- a/hw/xfree86/Makefile.am
+++ b/hw/xfree86/Makefile.am
@@ -12,7 +12,7 @@ DOC_SUBDIR = doc
 
 SUBDIRS = common ddc dummylib i2c x86emu int10 fbdevhw os-support parser rac \
           ramdac shadowfb vbe vgahw xaa xf1bpp xf4bpp xf8_16bpp \
-	  xf8_32bpp loader scanpci dixmods exa \
+	  xf8_32bpp loader scanpci dixmods exa modes \
 	  $(DRI_SUBDIR) $(XF86UTILS_SUBDIR) $(DOC_SUBDIR)
 
 DIST_SUBDIRS = common ddc dummylib i2c x86emu int10 fbdevhw os-support \
@@ -47,6 +47,9 @@ XORG_LIBS = \
 	    rac/librac.a \
             parser/libxf86config.a \
 	    dixmods/libdixmods.la \
+	    modes/libxf86modes.a \
+	    ddc/libddc.a \
+	    i2c/libi2c.a \
             @XORG_LIBS@
 
 Xorg_DEPENDENCIES = \
diff --git a/hw/xfree86/ddc/Makefile.am b/hw/xfree86/ddc/Makefile.am
index a04b5e8..f3ac803 100644
--- a/hw/xfree86/ddc/Makefile.am
+++ b/hw/xfree86/ddc/Makefile.am
@@ -1,11 +1,10 @@
 sdk_HEADERS = edid.h vdif.h xf86DDC.h
 
-module_LTLIBRARIES = libddc.la
+noinst_LIBRARIES = libddc.a
 
-libddc_la_LDFLAGS = -avoid-version
-libddc_la_SOURCES = xf86DDC.c edid.c interpret_edid.c print_edid.c \
+libddc_a_SOURCES = xf86DDC.c edid.c interpret_edid.c print_edid.c \
                    interpret_vdif.c print_vdif.c ddcProperty.c \
-		    edid_modes.c
+		   edid_modes.c
 
 INCLUDES = $(XORG_INCS) -I$(srcdir)/../i2c
 
diff --git a/hw/xfree86/ddc/ddcProperty.c b/hw/xfree86/ddc/ddcProperty.c
index 13083dd..37efb5b 100644
--- a/hw/xfree86/ddc/ddcProperty.c
+++ b/hw/xfree86/ddc/ddcProperty.c
@@ -31,6 +31,7 @@
 #include "property.h"
 #include "propertyst.h"
 #include "xf86DDC.h"
+#include "xf86_ansic.h"
 
 #define EDID1_ATOM_NAME         "XFree86_DDC_EDID1_RAWDATA"
 #define EDID2_ATOM_NAME         "XFree86_DDC_EDID2_RAWDATA"
diff --git a/hw/xfree86/ddc/xf86DDC.c b/hw/xfree86/ddc/xf86DDC.c
index dd64bd5..4ce585c 100644
--- a/hw/xfree86/ddc/xf86DDC.c
+++ b/hw/xfree86/ddc/xf86DDC.c
@@ -15,6 +15,8 @@
 
 static const OptionInfoRec *DDCAvailableOptions(void *unused);
 
+#if DDC_MODULE
+
 static MODULESETUPPROTO(ddcSetup);
 
 static XF86ModuleVersionInfo ddcVersRec =
@@ -57,6 +59,8 @@ ddcSetup(pointer module, pointer opts, i
     return (pointer)1;
 }
 
+#endif
+
 #define RETRIES 4
 
 static unsigned char *EDIDRead_DDC1(
diff --git a/hw/xfree86/i2c/Makefile.am b/hw/xfree86/i2c/Makefile.am
index e73fcae..70a9ace 100644
--- a/hw/xfree86/i2c/Makefile.am
+++ b/hw/xfree86/i2c/Makefile.am
@@ -1,4 +1,4 @@
-module_LTLIBRARIES = libi2c.la
+module_LIBRARIES = libi2c.a
 
 multimediadir = $(moduledir)/multimedia
 multimedia_LTLIBRARIES =	\
@@ -10,8 +10,7 @@ multimedia_LTLIBRARIES =	\
 	tda9885_drv.la		\
 	uda1380_drv.la
 
-libi2c_la_LDFLAGS = -avoid-version
-libi2c_la_SOURCES = xf86i2c.c xf86i2cmodule.c
+libi2c_a_SOURCES = xf86i2c.c
 
 INCLUDES = $(XORG_INCS)
 
diff --git a/hw/xfree86/loader/Makefile.am b/hw/xfree86/loader/Makefile.am
index 2066002..ceb66a2 100644
--- a/hw/xfree86/loader/Makefile.am
+++ b/hw/xfree86/loader/Makefile.am
@@ -2,7 +2,7 @@ noinst_LIBRARIES = libloader.a
 
 INCLUDES = $(XORG_INCS) -I$(srcdir)/../parser -I$(srcdir)/../dixmods/extmod \
 	   -I$(srcdir)/../vbe -I$(top_srcdir)/miext/cw -I$(srcdir)/../int10 \
-	   -I$(srcdir)/../ddc -I$(srcdir)/../i2c
+	   -I$(srcdir)/../ddc -I$(srcdir)/../i2c -I$(srcdir)/../modes
 
 #AM_LDFLAGS = -r
 AM_CFLAGS = -DIN_LOADER $(DIX_CFLAGS) $(XORG_CFLAGS)
diff --git a/hw/xfree86/loader/loadmod.c b/hw/xfree86/loader/loadmod.c
index ec0f181..e489212 100644
--- a/hw/xfree86/loader/loadmod.c
+++ b/hw/xfree86/loader/loadmod.c
@@ -768,7 +768,7 @@ LoadSubModule(ModuleDescPtr parent, cons
 
     submod = doLoadModule(module, NULL, subdirlist, patternlist, options,
 			  modreq, errmaj, errmin, LD_FLAG_GLOBAL);
-    if (submod) {
+    if (submod && submod != (ModuleDescPtr) 1) {
 	parent->child = AddSibling(parent->child, submod);
 	submod->parent = parent;
     }
@@ -799,7 +799,7 @@ LoadSubModuleLocal(ModuleDescPtr parent,
 
     submod = doLoadModule(module, NULL, subdirlist, patternlist, options,
 			  modreq, errmaj, errmin, 0);
-    if (submod) {
+    if (submod && submod != (ModuleDescPtr) 1) {
 	parent->child = AddSibling(parent->child, submod);
 	submod->parent = parent;
     }
@@ -838,6 +838,11 @@ DuplicateModule(ModuleDescPtr mod, Modul
     return ret;
 }
 
+static const char *compiled_in_modules[] = {
+    "ddc",
+    "i2c",
+    NULL
+};
 
 static ModuleDescPtr
 doLoadModule(const char *module, const char *path, const char **subdirlist,
@@ -856,9 +861,17 @@ doLoadModule(const char *module, const c
     PatternPtr patterns = NULL;
     int noncanonical = 0;
     char *m = NULL;
+    char **cim;
 
     xf86MsgVerb(X_INFO, 3, "LoadModule: \"%s\"", module);
 
+    for (cim = compiled_in_modules; *cim; cim++)
+	if (!strcmp (module, *cim))
+	{
+	    xf86MsgVerb(X_INFO, 3, "Module alread ybuilt-in");
+	    return (ModuleDescPtr) 1;
+	}
+
     patterns = InitPatterns(patternlist);
     name = LoaderGetCanonicalName(module, patterns);
     noncanonical = (name && strcmp(module, name) != 0);
@@ -1108,6 +1121,9 @@ UnloadDriver(ModuleDescPtr mod)
 static void
 UnloadModuleOrDriver(ModuleDescPtr mod)
 {
+    if (mod == (ModuleDescPtr) 1)
+	return;
+
     if (mod == NULL || mod->name == NULL)
 	return;
 
@@ -1156,6 +1172,8 @@ FreeModuleDesc(ModuleDescPtr head)
 {
     ModuleDescPtr sibs, prev;
 
+    if (head == (ModuleDescPtr) 1)
+	return;
     /*
      * only free it if it's not marked as in use. In use means that it may
      * be unloaded someday, and UnloadModule or UnloadDriver will free it
@@ -1338,7 +1356,7 @@ LoaderGetCanonicalName(const char *modna
 unsigned long
 LoaderGetModuleVersion(ModuleDescPtr mod)
 {
-    if (!mod || !mod->VersionInfo)
+    if (!mod || mod == (ModuleDescPtr) 1 || !mod->VersionInfo)
 	return 0;
 
     return MODULE_VERSION_NUMERIC(mod->VersionInfo->majorversion,
diff --git a/hw/xfree86/loader/xf86sym.c b/hw/xfree86/loader/xf86sym.c
index 1cb7dae..6337265 100644
--- a/hw/xfree86/loader/xf86sym.c
+++ b/hw/xfree86/loader/xf86sym.c
@@ -89,6 +89,13 @@
 #include "xf86sbusBus.h"
 #endif
 #include "compiler.h"
+#include "xf86Crtc.h"
+#include "xf86Modes.h"
+#ifdef RANDR
+#include "xf86RandR12.h"
+#endif
+#include "xf86DDC.h"
+#include "edid.h"
 
 #ifndef HAS_GLIBC_SIGSETJMP
 #if defined(setjmp) && defined(__GNU_LIBRARY__) && \
@@ -1161,4 +1168,85 @@ _X_HIDDEN void *xfree86LookupTab[] = {
 
     /* Pci.c */
     SYMVAR(pciNumBuses)
+
+    /* modes */
+    SYMFUNC(xf86CrtcConfigInit)
+    SYMFUNC(xf86CrtcConfigPrivateIndex)
+    SYMFUNC(xf86CrtcCreate)
+    SYMFUNC(xf86CrtcDestroy)
+    SYMFUNC(xf86CrtcInUse)
+    SYMFUNC(xf86CrtcRotate)
+    SYMFUNC(xf86CrtcSetMode)
+    SYMFUNC(xf86CrtcSetSizeRange)
+    SYMFUNC(xf86CVTMode)
+    SYMFUNC(xf86DisableUnusedFunctions)
+    SYMFUNC(xf86DPMSSet)
+    SYMFUNC(xf86DuplicateMode)
+    SYMFUNC(xf86DuplicateModes)
+    SYMFUNC(xf86GetDefaultModes)
+    SYMFUNC(xf86GetMonitorModes)
+    SYMFUNC(xf86InitialConfiguration)
+    SYMFUNC(xf86ModeHSync)
+    SYMFUNC(xf86ModesAdd)
+    SYMFUNC(xf86ModesEqual)
+    SYMFUNC(xf86ModeVRefresh)
+    SYMFUNC(xf86OutputCreate)
+    SYMFUNC(xf86OutputDestroy)
+    SYMFUNC(xf86OutputGetEDID)
+    SYMFUNC(xf86OutputGetEDIDModes)
+    SYMFUNC(xf86OutputRename)
+    SYMFUNC(xf86OutputSetEDID)
+    SYMFUNC(xf86PrintModeline)
+    SYMFUNC(xf86ProbeOutputModes)
+    SYMFUNC(xf86PruneInvalidModes)
+    SYMFUNC(xf86SetModeCrtc)
+    SYMFUNC(xf86SetModeDefaultName)
+    SYMFUNC(xf86SetScrnInfoModes)
+    SYMFUNC(xf86ValidateModesClocks)
+    SYMFUNC(xf86ValidateModesFlags)
+    SYMFUNC(xf86ValidateModesSize)
+    SYMFUNC(xf86ValidateModesSync)
+    SYMFUNC(xf86ValidateModesUserConfig)
+    SYMFUNC(xf86DiDGAInit)
+    SYMFUNC(xf86DiDGAReInit)
+    SYMFUNC(xf86DDCGetModes)
+    SYMFUNC(xf86SaveScreen)
+#ifdef RANDR
+    SYMFUNC(xf86RandR12CreateScreenResources)
+    SYMFUNC(xf86RandR12GetOriginalVirtualSize)
+    SYMFUNC(xf86RandR12GetRotation)
+    SYMFUNC(xf86RandR12Init)
+    SYMFUNC(xf86RandR12PreInit)
+    SYMFUNC(xf86RandR12SetConfig)
+    SYMFUNC(xf86RandR12SetRotations)
+#endif
+
+    SYMFUNC(xf86DoEDID_DDC1)
+    SYMFUNC(xf86DoEDID_DDC2)
+    SYMFUNC(xf86InterpretEDID)
+    SYMFUNC(xf86PrintEDID)
+    SYMFUNC(xf86InterpretVdif)
+    SYMFUNC(xf86print_vdif)
+    SYMFUNC(xf86DDCMonitorSet)
+    SYMFUNC(xf86SetDDCproperties)
+
+    SYMFUNC(xf86CreateI2CBusRec)
+    SYMFUNC(xf86CreateI2CDevRec)
+    SYMFUNC(xf86DestroyI2CBusRec)
+    SYMFUNC(xf86DestroyI2CDevRec)
+    SYMFUNC(xf86I2CBusInit)
+    SYMFUNC(xf86I2CDevInit)
+    SYMFUNC(xf86I2CFindBus)
+    SYMFUNC(xf86I2CFindDev)
+    SYMFUNC(xf86I2CGetScreenBuses)
+    SYMFUNC(xf86I2CProbeAddress)
+    SYMFUNC(xf86I2CReadByte)
+    SYMFUNC(xf86I2CReadBytes)
+    SYMFUNC(xf86I2CReadStatus)
+    SYMFUNC(xf86I2CReadWord)
+    SYMFUNC(xf86I2CWriteByte)
+    SYMFUNC(xf86I2CWriteBytes)
+    SYMFUNC(xf86I2CWriteRead)
+    SYMFUNC(xf86I2CWriteVec)
+    SYMFUNC(xf86I2CWriteWord)
 };
diff --git a/hw/xfree86/modes/Makefile.am b/hw/xfree86/modes/Makefile.am
new file mode 100644
index 0000000..60d2553
--- /dev/null
+++ b/hw/xfree86/modes/Makefile.am
@@ -0,0 +1,27 @@
+noinst_LIBRARIES = libxf86modes.a
+
+libxf86modes_a_SOURCES = \
+	xf86Crtc.c \
+	xf86Crtc.h \
+	xf86cvt.c \
+	xf86DiDGA.c \
+	xf86EdidModes.c \
+	xf86Modes.c \
+	xf86Modes.h \
+	xf86RandR12.c \
+	xf86RandR12.h \
+	xf86Rename.h \
+	xf86Rotate.c
+
+INCLUDES = $(XORG_INCS) -I$(srcdir)/../ddc -I$(srcdir)/../i2c \
+	   -I$(srcdir)/../loader -I$(srcdir)/../rac -I$(srcdir)/../parser \
+           -I$(srcdir)/../scanpci -I$(srcdir)/../vbe -I$(srcdir)/../int10 \
+	   -I$(srcdir)/../vgahw -I$(srcdir)/../dixmods/extmod
+
+sdk_HEADERS = \
+	xf86Crtc.h \
+	xf86Modes.h \
+	xf86RandR12.h \
+	xf86Rename.h
+
+AM_CFLAGS = $(XORG_CFLAGS)
diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c
new file mode 100644
index 0000000..ab7070b
--- /dev/null
+++ b/hw/xfree86/modes/xf86Crtc.c
@@ -0,0 +1,1587 @@
+/*
+ * Copyright © 2006 Keith Packard
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission.  The copyright holders make no representations
+ * about the suitability of this software for any purpose.  It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <stddef.h>
+#include <string.h>
+#include <stdio.h>
+
+#include "xf86.h"
+#include "xf86DDC.h"
+#include "xf86Crtc.h"
+#include "xf86Modes.h"
+#include "xf86RandR12.h"
+#include "X11/extensions/render.h"
+#define DPMS_SERVER
+#include "X11/extensions/dpms.h"
+#include "X11/Xatom.h"
+
+/*
+ * Initialize xf86CrtcConfig structure
+ */
+
+int xf86CrtcConfigPrivateIndex = -1;
+
+void
+xf86CrtcConfigInit (ScrnInfoPtr scrn)
+{
+    xf86CrtcConfigPtr	config;
+    
+    if (xf86CrtcConfigPrivateIndex == -1)
+	xf86CrtcConfigPrivateIndex = xf86AllocateScrnInfoPrivateIndex();
+    config = xnfcalloc (1, sizeof (xf86CrtcConfigRec));
+    scrn->privates[xf86CrtcConfigPrivateIndex].ptr = config;
+}
+ 
+void
+xf86CrtcSetSizeRange (ScrnInfoPtr scrn,
+		      int minWidth, int minHeight,
+		      int maxWidth, int maxHeight)
+{
+    xf86CrtcConfigPtr	config = XF86_CRTC_CONFIG_PTR(scrn);
+
+    config->minWidth = minWidth;
+    config->minHeight = minHeight;
+    config->maxWidth = maxWidth;
+    config->maxHeight = maxHeight;
+}
+
+/*
+ * Crtc functions
+ */
+xf86CrtcPtr
+xf86CrtcCreate (ScrnInfoPtr		scrn,
+		const xf86CrtcFuncsRec	*funcs)
+{
+    xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+    xf86CrtcPtr		crtc, *crtcs;
+
+    crtc = xcalloc (sizeof (xf86CrtcRec), 1);
+    if (!crtc)
+	return NULL;
+    crtc->scrn = scrn;
+    crtc->funcs = funcs;
+#ifdef RANDR_12_INTERFACE
+    crtc->randr_crtc = NULL;
+#endif
+    crtc->rotation = RR_Rotate_0;
+    crtc->desiredRotation = RR_Rotate_0;
+    if (xf86_config->crtc)
+	crtcs = xrealloc (xf86_config->crtc,
+			  (xf86_config->num_crtc + 1) * sizeof (xf86CrtcPtr));
+    else
+	crtcs = xalloc ((xf86_config->num_crtc + 1) * sizeof (xf86CrtcPtr));
+    if (!crtcs)
+    {
+	xfree (crtc);
+	return NULL;
+    }
+    xf86_config->crtc = crtcs;
+    xf86_config->crtc[xf86_config->num_crtc++] = crtc;
+    return crtc;
+}
+
+void
+xf86CrtcDestroy (xf86CrtcPtr crtc)
+{
+    xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn);
+    int			c;
+    
+    (*crtc->funcs->destroy) (crtc);
+    for (c = 0; c < xf86_config->num_crtc; c++)
+	if (xf86_config->crtc[c] == crtc)
+	{
+	    memmove (&xf86_config->crtc[c],
+		     &xf86_config->crtc[c+1],
+		     xf86_config->num_crtc - (c + 1));
+	    xf86_config->num_crtc--;
+	    break;
+	}
+    xfree (crtc);
+}
+
+
+/**
+ * Return whether any outputs are connected to the specified pipe
+ */
+
+Bool
+xf86CrtcInUse (xf86CrtcPtr crtc)
+{
+    ScrnInfoPtr		pScrn = crtc->scrn;
+    xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
+    int			o;
+    
+    for (o = 0; o < xf86_config->num_output; o++)
+	if (xf86_config->output[o]->crtc == crtc)
+	    return TRUE;
+    return FALSE;
+}
+
+/**
+ * Sets the given video mode on the given crtc
+ */
+Bool
+xf86CrtcSetMode (xf86CrtcPtr crtc, DisplayModePtr mode, Rotation rotation,
+		 int x, int y)
+{
+    ScrnInfoPtr		scrn = crtc->scrn;
+    xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+    int			i;
+    Bool		ret = FALSE;
+    Bool		didLock = FALSE;
+    DisplayModePtr	adjusted_mode;
+    DisplayModeRec	saved_mode;
+    int			saved_x, saved_y;
+    Rotation		saved_rotation;
+
+    adjusted_mode = xf86DuplicateMode(mode);
+
+    crtc->enabled = xf86CrtcInUse (crtc);
+    
+    if (!crtc->enabled)
+    {
+	/* XXX disable crtc? */
+	return TRUE;
+    }
+
+    didLock = crtc->funcs->lock (crtc);
+
+    saved_mode = crtc->mode;
+    saved_x = crtc->x;
+    saved_y = crtc->y;
+    saved_rotation = crtc->rotation;
+    /* Update crtc values up front so the driver can rely on them for mode
+     * setting.
+     */
+    crtc->mode = *mode;
+    crtc->x = x;
+    crtc->y = y;
+    crtc->rotation = rotation;
+
+    /* XXX short-circuit changes to base location only */
+    
+    /* Pass our mode to the outputs and the CRTC to give them a chance to
+     * adjust it according to limitations or output properties, and also
+     * a chance to reject the mode entirely.
+     */
+    for (i = 0; i < xf86_config->num_output; i++) {
+	xf86OutputPtr output = xf86_config->output[i];
+
+	if (output->crtc != crtc)
+	    continue;
+
+	if (!output->funcs->mode_fixup(output, mode, adjusted_mode)) {
+	    goto done;
+	}
+    }
+
+    if (!crtc->funcs->mode_fixup(crtc, mode, adjusted_mode)) {
+	goto done;
+    }
+
+    if (!xf86CrtcRotate (crtc, mode, rotation)) {
+	goto done;
+    }
+
+    /* Disable the outputs and CRTCs before setting the mode. */
+    for (i = 0; i < xf86_config->num_output; i++) {
+	xf86OutputPtr output = xf86_config->output[i];
+
+	if (output->crtc != crtc)
+	    continue;
+
+	/* Disable the output as the first thing we do. */
+	output->funcs->dpms(output, DPMSModeOff);
+    }
+
+    crtc->funcs->dpms(crtc, DPMSModeOff);
+
+    /* Set up the DPLL and any output state that needs to adjust or depend
+     * on the DPLL.
+     */
+    crtc->funcs->mode_set(crtc, mode, adjusted_mode, x, y);
+    for (i = 0; i < xf86_config->num_output; i++) 
+    {
+	xf86OutputPtr output = xf86_config->output[i];
+	if (output->crtc == crtc)
+	    output->funcs->mode_set(output, mode, adjusted_mode);
+    }
+
+    /* Now, enable the clocks, plane, pipe, and outputs that we set up. */
+    crtc->funcs->dpms(crtc, DPMSModeOn);
+    for (i = 0; i < xf86_config->num_output; i++) 
+    {
+	xf86OutputPtr output = xf86_config->output[i];
+	if (output->crtc == crtc)
+	    output->funcs->dpms(output, DPMSModeOn);
+    }
+
+    /* XXX free adjustedmode */
+    ret = TRUE;
+done:
+    if (!ret) {
+	crtc->x = saved_x;
+	crtc->y = saved_y;
+	crtc->rotation = saved_rotation;
+	crtc->mode = saved_mode;
+    }
+
+    if (didLock)
+	crtc->funcs->unlock (crtc);
+
+    return ret;
+}
+
+/*
+ * Output functions
+ */
+
+extern XF86ConfigPtr xf86configptr;
+
+typedef enum {
+    OPTION_PREFERRED_MODE,
+    OPTION_POSITION,
+    OPTION_BELOW,
+    OPTION_RIGHT_OF,
+    OPTION_ABOVE,
+    OPTION_LEFT_OF,
+    OPTION_ENABLE,
+    OPTION_DISABLE,
+    OPTION_MIN_CLOCK,
+    OPTION_MAX_CLOCK,
+    OPTION_IGNORE,
+} OutputOpts;
+
+static OptionInfoRec xf86OutputOptions[] = {
+    {OPTION_PREFERRED_MODE, "PreferredMode",	OPTV_STRING,  {0}, FALSE },
+    {OPTION_POSITION,	    "Position",		OPTV_STRING,  {0}, FALSE },
+    {OPTION_BELOW,	    "Below",		OPTV_STRING,  {0}, FALSE },
+    {OPTION_RIGHT_OF,	    "RightOf",		OPTV_STRING,  {0}, FALSE },
+    {OPTION_ABOVE,	    "Above",		OPTV_STRING,  {0}, FALSE },
+    {OPTION_LEFT_OF,	    "LeftOf",		OPTV_STRING,  {0}, FALSE },
+    {OPTION_ENABLE,	    "Enable",		OPTV_BOOLEAN, {0}, FALSE },
+    {OPTION_DISABLE,	    "Disable",		OPTV_BOOLEAN, {0}, FALSE },
+    {OPTION_MIN_CLOCK,	    "MinClock",		OPTV_FREQ,    {0}, FALSE },
+    {OPTION_MAX_CLOCK,	    "MaxClock",		OPTV_FREQ,    {0}, FALSE },
+    {OPTION_IGNORE,	    "Ignore",		OPTV_BOOLEAN, {0}, FALSE },
+    {-1,		    NULL,		OPTV_NONE,    {0}, FALSE },
+};
+
+static void
+xf86OutputSetMonitor (xf86OutputPtr output)
+{
+    char    *option_name;
+    static const char monitor_prefix[] = "monitor-";
+    char    *monitor;
+
+    if (!output->name)
+	return;
+
+    if (output->options)
+	xfree (output->options);
+
+    output->options = xnfalloc (sizeof (xf86OutputOptions));
+    memcpy (output->options, xf86OutputOptions, sizeof (xf86OutputOptions));
+    
+    option_name = xnfalloc (strlen (monitor_prefix) +
+			    strlen (output->name) + 1);
+    strcpy (option_name, monitor_prefix);
+    strcat (option_name, output->name);
+    monitor = xf86findOptionValue (output->scrn->options, option_name);
+    if (!monitor)
+	monitor = output->name;
+    else
+	xf86MarkOptionUsedByName (output->scrn->options, option_name);
+    xfree (option_name);
+    output->conf_monitor = xf86findMonitor (monitor,
+					    xf86configptr->conf_monitor_lst);
+    if (output->conf_monitor)
+	xf86ProcessOptions (output->scrn->scrnIndex,
+			    output->conf_monitor->mon_option_lst,
+			    output->options);
+}
+
+static Bool
+xf86OutputEnabled (xf86OutputPtr    output)
+{
+    /* Check to see if this output was disabled in the config file */
+    if (xf86ReturnOptValBool (output->options, OPTION_ENABLE, TRUE) == FALSE ||
+	xf86ReturnOptValBool (output->options, OPTION_DISABLE, FALSE) == TRUE)
+    {
+	return FALSE;
+    }
+    return TRUE;
+}
+
+static Bool
+xf86OutputIgnored (xf86OutputPtr    output)
+{
+    return xf86ReturnOptValBool (output->options, OPTION_IGNORE, FALSE);
+}
+
+xf86OutputPtr
+xf86OutputCreate (ScrnInfoPtr		    scrn,
+		  const xf86OutputFuncsRec *funcs,
+		  const char		    *name)
+{
+    xf86OutputPtr	output, *outputs;
+    xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+    int			len;
+
+    if (name)
+	len = strlen (name) + 1;
+    else
+	len = 0;
+
+    output = xcalloc (sizeof (xf86OutputRec) + len, 1);
+    if (!output)
+	return NULL;
+    output->scrn = scrn;
+    output->funcs = funcs;
+    if (name)
+    {
+	output->name = (char *) (output + 1);
+	strcpy (output->name, name);
+    }
+    output->subpixel_order = SubPixelUnknown;
+#ifdef RANDR_12_INTERFACE
+    output->randr_output = NULL;
+#endif
+    if (name)
+    {
+	xf86OutputSetMonitor (output);
+	if (xf86OutputIgnored (output))
+	{
+	    xfree (output);
+	    return FALSE;
+	}
+    }
+    
+    
+    if (xf86_config->output)
+	outputs = xrealloc (xf86_config->output,
+			  (xf86_config->num_output + 1) * sizeof (xf86OutputPtr));
+    else
+	outputs = xalloc ((xf86_config->num_output + 1) * sizeof (xf86OutputPtr));
+    if (!outputs)
+    {
+	xfree (output);
+	return NULL;
+    }
+    
+    xf86_config->output = outputs;
+    xf86_config->output[xf86_config->num_output++] = output;
+    
+    return output;
+}
+
+Bool
+xf86OutputRename (xf86OutputPtr output, const char *name)
+{
+    int	    len = strlen(name) + 1;
+    char    *newname = xalloc (len);
+    
+    if (!newname)
+	return FALSE;	/* so sorry... */
+    
+    strcpy (newname, name);
+    if (output->name && output->name != (char *) (output + 1))
+	xfree (output->name);
+    output->name = newname;
+    xf86OutputSetMonitor (output);
+    if (xf86OutputIgnored (output))
+	return FALSE;
+    return TRUE;
+}
+
+void
+xf86OutputDestroy (xf86OutputPtr output)
+{
+    ScrnInfoPtr		scrn = output->scrn;
+    xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+    int			o;
+    
+    (*output->funcs->destroy) (output);
+    while (output->probed_modes)
+	xf86DeleteMode (&output->probed_modes, output->probed_modes);
+    for (o = 0; o < xf86_config->num_output; o++)
+	if (xf86_config->output[o] == output)
+	{
+	    memmove (&xf86_config->output[o],
+		     &xf86_config->output[o+1],
+		     xf86_config->num_output - (o + 1));
+	    xf86_config->num_output--;
+	    break;
+	}
+    if (output->name && output->name != (char *) (output + 1))
+	xfree (output->name);
+    xfree (output);
+}
+
+static DisplayModePtr
+xf86DefaultMode (xf86OutputPtr output, int width, int height)
+{
+    DisplayModePtr  target_mode = NULL;
+    DisplayModePtr  mode;
+    int		    target_diff = 0;
+    int		    target_preferred = 0;
+    int		    mm_height;
+    
+    mm_height = output->mm_height;
+    if (!mm_height)
+	mm_height = 203;	/* 768 pixels at 96dpi */
+    /*
+     * Pick a mode closest to 96dpi 
+     */
+    for (mode = output->probed_modes; mode; mode = mode->next)
+    {
+	int	    dpi;
+	int	    preferred = (mode->type & M_T_PREFERRED) != 0;
+	int	    diff;
+
+	if (mode->HDisplay > width || mode->VDisplay > height) continue;
+	dpi = (mode->HDisplay * 254) / (mm_height * 10);
+	diff = dpi - 96;
+	diff = diff < 0 ? -diff : diff;
+	if (target_mode == NULL || (preferred > target_preferred) ||
+	    (preferred == target_preferred && diff < target_diff))
+	{
+	    target_mode = mode;
+	    target_diff = diff;
+	    target_preferred = preferred;
+	}
+    }
+    return target_mode;
+}
+
+static DisplayModePtr
+xf86ClosestMode (xf86OutputPtr output, DisplayModePtr match,
+		 int width, int height)
+{
+    DisplayModePtr  target_mode = NULL;
+    DisplayModePtr  mode;
+    int		    target_diff = 0;
+    
+    /*
+     * Pick a mode closest to the specified mode
+     */
+    for (mode = output->probed_modes; mode; mode = mode->next)
+    {
+	int	    dx, dy;
+	int	    diff;
+
+	if (mode->HDisplay > width || mode->VDisplay > height) continue;
+	
+	/* exact matches are preferred */
+	if (xf86ModesEqual (mode, match))
+	    return mode;
+	
+	dx = match->HDisplay - mode->HDisplay;
+	dy = match->VDisplay - mode->VDisplay;
+	diff = dx * dx + dy * dy;
+	if (target_mode == NULL || diff < target_diff)
+	{
+	    target_mode = mode;
+	    target_diff = diff;
+	}
+    }
+    return target_mode;
+}
+
+static Bool
+xf86OutputHasPreferredMode (xf86OutputPtr output, int width, int height)
+{
+    DisplayModePtr  mode;
+
+    for (mode = output->probed_modes; mode; mode = mode->next)
+    {
+	if (mode->HDisplay > width || mode->VDisplay > height) continue;
+	if (mode->type & M_T_PREFERRED)
+	    return TRUE;
+    }
+    return FALSE;
+}
+
+static int
+xf86PickCrtcs (ScrnInfoPtr	scrn,
+	       xf86CrtcPtr	*best_crtcs,
+	       DisplayModePtr	*modes,
+	       int		n,
+	       int		width,
+	       int		height)
+{
+    xf86CrtcConfigPtr	config = XF86_CRTC_CONFIG_PTR(scrn);
+    int		    c, o, l;
+    xf86OutputPtr   output;
+    xf86CrtcPtr	    crtc;
+    xf86CrtcPtr	    *crtcs;
+    xf86CrtcPtr	    best_crtc;
+    int		    best_score;
+    int		    score;
+    int		    my_score;
+    
+    if (n == config->num_output)
+	return 0;
+    output = config->output[n];
+    
+    /*
+     * Compute score with this output disabled
+     */
+    best_crtcs[n] = NULL;
+    best_crtc = NULL;
+    best_score = xf86PickCrtcs (scrn, best_crtcs, modes, n+1, width, height);
+    if (modes[n] == NULL)
+	return best_score;
+    
+    crtcs = xalloc (config->num_output * sizeof (xf86CrtcPtr));
+    if (!crtcs)
+	return best_score;
+
+    my_score = 1;
+    /* Score outputs that are known to be connected higher */
+    if (output->status == XF86OutputStatusConnected)
+	my_score++;
+    /* Score outputs with preferred modes higher */
+    if (xf86OutputHasPreferredMode (output, width, height))
+	my_score++;
+    /*
+     * Select a crtc for this output and
+     * then attempt to configure the remaining
+     * outputs
+     */
+    for (c = 0; c < config->num_crtc; c++)
+    {
+	if ((output->possible_crtcs & (1 << c)) == 0)
+	    continue;
+	
+	crtc = config->crtc[c];
+	/*
+	 * Check to see if some other output is
+	 * using this crtc
+	 */
+	for (o = 0; o < n; o++)
+	    if (best_crtcs[o] == crtc)
+		break;
+	if (o < n)
+	{
+	    /*
+	     * If the two outputs desire the same mode,
+	     * see if they can be cloned
+	     */
+	    if (xf86ModesEqual (modes[o], modes[n]) &&
+		config->output[o]->initial_x == config->output[n]->initial_x &&
+		config->output[o]->initial_y == config->output[n]->initial_y)
+	    {
+		for (l = 0; l < config->num_output; l++)
+		    if (output->possible_clones & (1 << l))
+			break;
+		if (l == config->num_output)
+		    continue;		/* nope, try next CRTC */
+	    }
+	    else
+		continue;		/* different modes, can't clone */
+	}
+	crtcs[n] = crtc;
+	memcpy (crtcs, best_crtcs, n * sizeof (xf86CrtcPtr));
+	score = my_score + xf86PickCrtcs (scrn, crtcs, modes, n+1, width, height);
+	if (score > best_score)
+	{
+	    best_crtc = crtc;
+	    best_score = score;
+	    memcpy (best_crtcs, crtcs, config->num_output * sizeof (xf86CrtcPtr));
+	}
+    }
+    xfree (crtcs);
+    return best_score;
+}
+
+
+/*
+ * Compute the virtual size necessary to place all of the available
+ * crtcs in the specified configuration and also large enough to
+ * resize any crtc to the largest available mode
+ */
+
+static void
+xf86DefaultScreenLimits (ScrnInfoPtr scrn, int *widthp, int *heightp)
+{
+    xf86CrtcConfigPtr	config = XF86_CRTC_CONFIG_PTR(scrn);
+    int	    width = 0, height = 0;
+    int	    o;
+    int	    c;
+    int	    s;
+
+    for (c = 0; c < config->num_crtc; c++)
+    {
+	int	    crtc_width = 0, crtc_height = 0;
+	xf86CrtcPtr crtc = config->crtc[c];
+
+	if (crtc->enabled)
+	{
+	    crtc_width = crtc->x + crtc->desiredMode.HDisplay;
+	    crtc_height = crtc->y + crtc->desiredMode.VDisplay;
+	}
+	for (o = 0; o < config->num_output; o++) 
+	{
+	    xf86OutputPtr   output = config->output[o];
+
+	    for (s = 0; s < config->num_crtc; s++)
+		if (output->possible_crtcs & (1 << s))
+		{
+		    DisplayModePtr  mode;
+		    for (mode = output->probed_modes; mode; mode = mode->next)
+		    {
+			if (mode->HDisplay > crtc_width)
+			    crtc_width = mode->HDisplay;
+			if (mode->VDisplay > crtc_height)
+			    crtc_height = mode->VDisplay;
+		    }
+		}
+	}
+	if (crtc_width > width)
+	    width = crtc_width;
+	if (crtc_height > height)
+	    height = crtc_height;
+    }
+    if (config->maxWidth && width > config->maxWidth) width = config->maxWidth;
+    if (config->maxHeight && height > config->maxHeight) height = config->maxHeight;
+    if (config->minWidth && width < config->minWidth) width = config->minWidth;
+    if (config->minHeight && height < config->minHeight) height = config->minHeight;
+    *widthp = width;
+    *heightp = height;
+}
+
+#define POSITION_UNSET	-100000
+
+static Bool
+xf86InitialOutputPositions (ScrnInfoPtr scrn, DisplayModePtr *modes)
+{
+    xf86CrtcConfigPtr	config = XF86_CRTC_CONFIG_PTR(scrn);
+    int			o;
+    int			min_x, min_y;
+    
+    for (o = 0; o < config->num_output; o++)
+    {
+	xf86OutputPtr	output = config->output[o];
+
+	output->initial_x = output->initial_y = POSITION_UNSET;
+    }
+    
+    /*
+     * Loop until all outputs are set
+     */
+    for (;;)
+    {
+	Bool	any_set = FALSE;
+	Bool	keep_going = FALSE;
+
+	for (o = 0; o < config->num_output; o++)	
+	{
+	    static const OutputOpts	relations[] = {
+		OPTION_BELOW, OPTION_RIGHT_OF, OPTION_ABOVE, OPTION_LEFT_OF
+	    };
+	    xf86OutputPtr   output = config->output[o];
+	    xf86OutputPtr   relative;
+	    char	    *relative_name;
+	    char	    *position;
+	    OutputOpts	    relation;
+	    int		    r;
+
+	    if (output->initial_x != POSITION_UNSET)
+		continue;
+	    position = xf86GetOptValString (output->options,
+					    OPTION_POSITION);
+	    /*
+	     * Absolute position wins
+	     */
+	    if (position)
+	    {
+		int		    x, y;
+		if (sscanf (position, "%d %d", &x, &y) == 2)
+		{
+		    output->initial_x = x;
+		    output->initial_y = y;
+		}
+		else
+		{
+		    xf86DrvMsg (scrn->scrnIndex, X_ERROR,
+				"Output %s position not of form \"x y\"\n",
+				output->name);
+		    output->initial_x = output->initial_y = 0;
+		}
+		any_set = TRUE;
+		continue;
+	    }
+	    /*
+	     * Next comes relative positions
+	     */
+	    relation = 0;
+	    relative_name = NULL;
+	    for (r = 0; r < 4; r++)
+	    {
+		relation = relations[r];
+		relative_name = xf86GetOptValString (output->options,
+						     relation);
+		if (relative_name)
+		    break;
+	    }
+	    if (relative_name)
+	    {
+		int or;
+		relative = NULL;
+		for (or = 0; or < config->num_output; or++)
+		{
+		    xf86OutputPtr	out_rel = config->output[or];
+		    XF86ConfMonitorPtr	rel_mon = out_rel->conf_monitor;
+		    char		*name;
+
+		    if (rel_mon)
+			name = rel_mon->mon_identifier;
+		    else
+			name = out_rel->name;
+		    if (!strcmp (relative_name, name))
+		    {
+			relative = config->output[or];
+			break;
+		    }
+		}
+		if (!relative)
+		{
+		    xf86DrvMsg (scrn->scrnIndex, X_ERROR,
+				"Cannot position output %s relative to unknown output %s\n",
+				output->name, relative_name);
+		    output->initial_x = 0;
+		    output->initial_y = 0;
+		    any_set = TRUE;
+		    continue;
+		}
+		if (relative->initial_x == POSITION_UNSET)
+		{
+		    keep_going = TRUE;
+		    continue;
+		}
+		output->initial_x = relative->initial_x;
+		output->initial_y = relative->initial_y;
+		switch (relation) {
+		case OPTION_BELOW:
+		    output->initial_y += modes[or]->VDisplay;
+		    break;
+		case OPTION_RIGHT_OF:
+		    output->initial_x += modes[or]->HDisplay;
+		    break;
+		case OPTION_ABOVE:
+		    output->initial_y -= modes[o]->VDisplay;
+		    break;
+		case OPTION_LEFT_OF:
+		    output->initial_x -= modes[o]->HDisplay;
+		    break;
+		default:
+		    break;
+		}
+		any_set = TRUE;
+		continue;
+	    }
+	    
+	    /* Nothing set, just stick them at 0,0 */
+	    output->initial_x = 0;
+	    output->initial_y = 0;
+	    any_set = TRUE;
+	}
+	if (!keep_going)
+	    break;
+	if (!any_set) 
+	{
+	    for (o = 0; o < config->num_output; o++)
+	    {
+		xf86OutputPtr   output = config->output[o];
+		if (output->initial_x == POSITION_UNSET)
+		{
+		    xf86DrvMsg (scrn->scrnIndex, X_ERROR,
+				"Output position loop. Moving %s to 0,0\n",
+				output->name);
+		    output->initial_x = output->initial_y = 0;
+		    break;
+		}
+	    }
+	}
+    }
+
+    /*
+     * normalize positions
+     */
+    min_x = 1000000;
+    min_y = 1000000;
+    for (o = 0; o < config->num_output; o++)
+    {
+	xf86OutputPtr	output = config->output[o];
+
+	if (output->initial_x < min_x)
+	    min_x = output->initial_x;
+	if (output->initial_y < min_y)
+	    min_y = output->initial_y;
+    }
+    
+    for (o = 0; o < config->num_output; o++)
+    {
+	xf86OutputPtr	output = config->output[o];
+
+	output->initial_x -= min_x;
+	output->initial_y -= min_y;
+    }
+    return TRUE;
+}
+
+/*
+ * XXX walk the monitor mode list and prune out duplicates that
+ * are inserted by xf86DDCMonitorSet. In an ideal world, that
+ * function would do this work by itself.
+ */
+
+static void
+xf86PruneDuplicateMonitorModes (MonPtr Monitor)
+{
+    DisplayModePtr  master, clone, next;
+
+    for (master = Monitor->Modes; 
+	 master && master != Monitor->Last; 
+	 master = master->next)
+    {
+	for (clone = master->next; clone && clone != Monitor->Modes; clone = next)
+	{
+	    next = clone->next;
+	    if (xf86ModesEqual (master, clone))
+	    {
+		if (Monitor->Last == clone)
+		    Monitor->Last = clone->prev;
+		xf86DeleteMode (&Monitor->Modes, clone);
+	    }
+	}
+    }
+}
+
+/** Return - 0 + if a should be earlier, same or later than b in list
+ */
+static int
+xf86ModeCompare (DisplayModePtr a, DisplayModePtr b)
+{
+    int	diff;
+
+    diff = ((b->type & M_T_PREFERRED) != 0) - ((a->type & M_T_PREFERRED) != 0);
+    if (diff)
+	return diff;
+    diff = b->HDisplay * b->VDisplay - a->HDisplay * a->VDisplay;
+    if (diff)
+	return diff;
+    diff = b->Clock - a->Clock;
+    return diff;
+}
+
+/**
+ * Insertion sort input in-place and return the resulting head
+ */
+static DisplayModePtr
+xf86SortModes (DisplayModePtr input)
+{
+    DisplayModePtr  output = NULL, i, o, n, *op, prev;
+
+    /* sort by preferred status and pixel area */
+    while (input)
+    {
+	i = input;
+	input = input->next;
+	for (op = &output; (o = *op); op = &o->next)
+	    if (xf86ModeCompare (o, i) > 0)
+		break;
+	i->next = *op;
+	*op = i;
+    }
+    /* prune identical modes */
+    for (o = output; o && (n = o->next); o = n)
+    {
+	if (!strcmp (o->name, n->name) && xf86ModesEqual (o, n))
+	{
+	    o->next = n->next;
+	    xfree (n->name);
+	    xfree (n);
+	    n = o;
+	}
+    }
+    /* hook up backward links */
+    prev = NULL;
+    for (o = output; o; o = o->next)
+    {
+	o->prev = prev;
+	prev = o;
+    }
+    return output;
+}
+
+#define DEBUG_REPROBE 1
+
+void
+xf86ProbeOutputModes (ScrnInfoPtr scrn, int maxX, int maxY)
+{
+    xf86CrtcConfigPtr	config = XF86_CRTC_CONFIG_PTR(scrn);
+    int			o;
+
+    if (maxX == 0 || maxY == 0)
+	xf86RandR12GetOriginalVirtualSize (scrn, &maxX, &maxY);
+
+    /* Elide duplicate modes before defaulting code uses them */
+    xf86PruneDuplicateMonitorModes (scrn->monitor);
+    
+    /* Probe the list of modes for each output. */
+    for (o = 0; o < config->num_output; o++) 
+    {
+	xf86OutputPtr	    output = config->output[o];
+	DisplayModePtr	    mode;
+	DisplayModePtr	    config_modes = NULL, output_modes, default_modes;
+	char		    *preferred_mode;
+	xf86MonPtr	    edid_monitor;
+	XF86ConfMonitorPtr  conf_monitor;
+	MonRec		    mon_rec;
+	int		    min_clock = 0;
+	int		    max_clock = 0;
+	double		    clock;
+	enum { sync_config, sync_edid, sync_default } sync_source = sync_default;
+	
+	while (output->probed_modes != NULL)
+	    xf86DeleteMode(&output->probed_modes, output->probed_modes);
+
+	/*
+	 * Check connection status
+	 */
+	output->status = (*output->funcs->detect)(output);
+
+	if (output->status == XF86OutputStatusDisconnected)
+	    continue;
+
+	memset (&mon_rec, '\0', sizeof (mon_rec));
+	
+	conf_monitor = output->conf_monitor;
+	
+	if (conf_monitor)
+	{
+	    int	i;
+	    
+	    for (i = 0; i < conf_monitor->mon_n_hsync; i++)
+	    {
+		mon_rec.hsync[mon_rec.nHsync].lo = conf_monitor->mon_hsync[i].lo;
+		mon_rec.hsync[mon_rec.nHsync].hi = conf_monitor->mon_hsync[i].hi;
+		mon_rec.nHsync++;
+		sync_source = sync_config;
+	    }
+	    for (i = 0; i < conf_monitor->mon_n_vrefresh; i++)
+	    {
+		mon_rec.vrefresh[mon_rec.nVrefresh].lo = conf_monitor->mon_vrefresh[i].lo;
+		mon_rec.vrefresh[mon_rec.nVrefresh].hi = conf_monitor->mon_vrefresh[i].hi;
+		mon_rec.nVrefresh++;
+		sync_source = sync_config;
+	    }
+	    config_modes = xf86GetMonitorModes (scrn, conf_monitor);
+	}
+	
+	output_modes = (*output->funcs->get_modes) (output);
+	
+	edid_monitor = output->MonInfo;
+	
+	if (edid_monitor)
+	{
+	    int			    i;
+	    Bool		    set_hsync = mon_rec.nHsync == 0;
+	    Bool		    set_vrefresh = mon_rec.nVrefresh == 0;
+
+	    for (i = 0; i < sizeof (edid_monitor->det_mon) / sizeof (edid_monitor->det_mon[0]); i++)
+	    {
+		if (edid_monitor->det_mon[i].type == DS_RANGES)
+		{
+		    struct monitor_ranges   *ranges = &edid_monitor->det_mon[i].section.ranges;
+		    if (set_hsync && ranges->max_h)
+		    {
+			mon_rec.hsync[mon_rec.nHsync].lo = ranges->min_h;
+			mon_rec.hsync[mon_rec.nHsync].hi = ranges->max_h;
+			mon_rec.nHsync++;
+			if (sync_source == sync_default)
+			    sync_source = sync_edid;
+		    }
+		    if (set_vrefresh && ranges->max_v)
+		    {
+			mon_rec.vrefresh[mon_rec.nVrefresh].lo = ranges->min_v;
+			mon_rec.vrefresh[mon_rec.nVrefresh].hi = ranges->max_v;
+			mon_rec.nVrefresh++;
+			if (sync_source == sync_default)
+			    sync_source = sync_edid;
+		    }
+		    if (ranges->max_clock > max_clock)
+			max_clock = ranges->max_clock;
+		}
+	    }
+	}
+
+	if (xf86GetOptValFreq (output->options, OPTION_MIN_CLOCK,
+			       OPTUNITS_KHZ, &clock))
+	    min_clock = (int) clock;
+	if (xf86GetOptValFreq (output->options, OPTION_MAX_CLOCK,
+			       OPTUNITS_KHZ, &clock))
+	    max_clock = (int) clock;
+
+	/*
+	 * These limits will end up setting a 1024x768 at 60Hz mode by default,
+	 * which seems like a fairly good mode to use when nothing else is
+	 * specified
+	 */
+	if (mon_rec.nHsync == 0)
+	{
+	    mon_rec.hsync[0].lo = 31.0;
+	    mon_rec.hsync[0].hi = 55.0;
+	    mon_rec.nHsync = 1;
+	}
+	if (mon_rec.nVrefresh == 0)
+	{
+	    mon_rec.vrefresh[0].lo = 58.0;
+	    mon_rec.vrefresh[0].hi = 62.0;
+	    mon_rec.nVrefresh = 1;
+	}
+	default_modes = xf86GetDefaultModes (output->interlaceAllowed,
+					     output->doubleScanAllowed);
+	
+	if (sync_source == sync_config)
+	{
+	    /* 
+	     * Check output and config modes against sync range from config file
+	     */
+	    xf86ValidateModesSync (scrn, output_modes, &mon_rec);
+	    xf86ValidateModesSync (scrn, config_modes, &mon_rec);
+	}
+	/*
+	 * Check default modes against sync range
+	 */
+        xf86ValidateModesSync (scrn, default_modes, &mon_rec);
+	/*
+	 * Check default modes against monitor max clock
+	 */
+	if (max_clock)
+	    xf86ValidateModesClocks(scrn, default_modes,
+				    &min_clock, &max_clock, 1);
+	
+	output->probed_modes = NULL;
+	output->probed_modes = xf86ModesAdd (output->probed_modes, config_modes);
+	output->probed_modes = xf86ModesAdd (output->probed_modes, output_modes);
+	output->probed_modes = xf86ModesAdd (output->probed_modes, default_modes);
+	
+	/*
+	 * Check all modes against max size
+	 */
+	if (maxX && maxY)
+	    xf86ValidateModesSize (scrn, output->probed_modes,
+				       maxX, maxY, 0);
+	 
+	/*
+	 * Check all modes against output
+	 */
+	for (mode = output->probed_modes; mode != NULL; mode = mode->next) 
+	    if (mode->status == MODE_OK)
+		mode->status = (*output->funcs->mode_valid)(output, mode);
+	
+	xf86PruneInvalidModes(scrn, &output->probed_modes, TRUE);
+	
+	output->probed_modes = xf86SortModes (output->probed_modes);
+	
+	/* Check for a configured preference for a particular mode */
+	preferred_mode = xf86GetOptValString (output->options,
+					      OPTION_PREFERRED_MODE);
+
+	if (preferred_mode)
+	{
+	    for (mode = output->probed_modes; mode; mode = mode->next)
+	    {
+		if (!strcmp (preferred_mode, mode->name))
+		{
+		    if (mode != output->probed_modes)
+		    {
+			if (mode->prev)
+			    mode->prev->next = mode->next;
+			if (mode->next)
+			    mode->next->prev = mode->prev;
+			mode->next = output->probed_modes;
+			output->probed_modes->prev = mode;
+			mode->prev = NULL;
+			output->probed_modes = mode;
+		    }
+		    mode->type |= M_T_PREFERRED;
+		    break;
+		}
+	    }
+	}
+	
+#ifdef DEBUG_REPROBE
+	if (output->probed_modes != NULL) {
+	    xf86DrvMsg(scrn->scrnIndex, X_INFO,
+		       "Printing probed modes for output %s\n",
+		       output->name);
+	} else {
+	    xf86DrvMsg(scrn->scrnIndex, X_INFO,
+		       "No remaining probed modes for output %s\n",
+		       output->name);
+	}
+#endif
+	for (mode = output->probed_modes; mode != NULL; mode = mode->next)
+	{
+	    /* The code to choose the best mode per pipe later on will require
+	     * VRefresh to be set.
+	     */
+	    mode->VRefresh = xf86ModeVRefresh(mode);
+	    xf86SetModeCrtc(mode, INTERLACE_HALVE_V);
+
+#ifdef DEBUG_REPROBE
+	    xf86PrintModeline(scrn->scrnIndex, mode);
+#endif
+	}
+    }
+}
+
+
+/**
+ * Copy one of the output mode lists to the ScrnInfo record
+ */
+
+/* XXX where does this function belong? Here? */
+void
+xf86RandR12GetOriginalVirtualSize(ScrnInfoPtr scrn, int *x, int *y);
+
+void
+xf86SetScrnInfoModes (ScrnInfoPtr scrn)
+{
+    xf86CrtcConfigPtr	config = XF86_CRTC_CONFIG_PTR(scrn);
+    xf86OutputPtr	output;
+    xf86CrtcPtr		crtc;
+    DisplayModePtr	last, mode;
+
+    output = config->output[config->compat_output];
+    if (!output->crtc)
+    {
+	int o;
+
+	output = NULL;
+	for (o = 0; o < config->num_output; o++)
+	    if (config->output[o]->crtc)
+	    {
+		config->compat_output = o;
+		output = config->output[o];
+		break;
+	    }
+	/* no outputs are active, punt and leave things as they are */
+	if (!output)
+	    return;
+    }
+    crtc = output->crtc;
+
+    /* Clear any existing modes from scrn->modes */
+    while (scrn->modes != NULL)
+	xf86DeleteMode(&scrn->modes, scrn->modes);
+
+    /* Set scrn->modes to the mode list for the 'compat' output */
+    scrn->modes = xf86DuplicateModes(scrn, output->probed_modes);
+
+    for (mode = scrn->modes; mode; mode = mode->next)
+	if (xf86ModesEqual (mode, &crtc->desiredMode))
+	    break;
+
+    if (scrn->modes != NULL) {
+	/* For some reason, scrn->modes is circular, unlike the other mode
+	 * lists.  How great is that?
+	 */
+	for (last = scrn->modes; last && last->next; last = last->next)
+	    ;
+	last->next = scrn->modes;
+	scrn->modes->prev = last;
+	if (mode) {
+	    while (scrn->modes != mode)
+		scrn->modes = scrn->modes->next;
+	}
+    }
+    scrn->currentMode = scrn->modes;
+}
+
+/**
+ * Construct default screen configuration
+ *
+ * Given auto-detected (and, eventually, configured) values,
+ * construct a usable configuration for the system
+ */
+
+Bool
+xf86InitialConfiguration (ScrnInfoPtr	    scrn)
+{
+    xf86CrtcConfigPtr	config = XF86_CRTC_CONFIG_PTR(scrn);
+    int			o, c;
+    DisplayModePtr	target_mode = NULL;
+    xf86CrtcPtr		*crtcs;
+    DisplayModePtr	*modes;
+    Bool		*enabled;
+    int			width;
+    int			height;
+
+    if (scrn->display->virtualX)
+	width = scrn->display->virtualX;
+    else
+	width = config->maxWidth;
+    if (scrn->display->virtualY)
+	height = scrn->display->virtualY;
+    else
+	height = config->maxHeight;
+
+    xf86ProbeOutputModes (scrn, width, height);
+
+    crtcs = xnfcalloc (config->num_output, sizeof (xf86CrtcPtr));
+    modes = xnfcalloc (config->num_output, sizeof (DisplayModePtr));
+    enabled = xnfcalloc (config->num_output, sizeof (Bool));
+    
+    for (o = 0; o < config->num_output; o++)
+    {
+	xf86OutputPtr output = config->output[o];
+	
+	modes[o] = NULL;
+	enabled[o] = (xf86OutputEnabled (output) &&
+		      output->status != XF86OutputStatusDisconnected);
+    }
+    
+    /*
+     * Let outputs with preferred modes drive screen size
+     */
+    for (o = 0; o < config->num_output; o++)
+    {
+	xf86OutputPtr output = config->output[o];
+
+	if (enabled[o] &&
+	    xf86OutputHasPreferredMode (output, width, height))
+	{
+	    target_mode = xf86DefaultMode (output, width, height);
+	    if (target_mode)
+	    {
+		modes[o] = target_mode;
+		config->compat_output = o;
+		break;
+	    }
+	}
+    }
+    if (!target_mode)
+    {
+	for (o = 0; o < config->num_output; o++)
+	{
+	    xf86OutputPtr output = config->output[o];
+	    if (enabled[o])
+	    {
+		target_mode = xf86DefaultMode (output, width, height);
+		if (target_mode)
+		{
+		    modes[o] = target_mode;
+		    config->compat_output = o;
+		    break;
+		}
+	    }
+	}
+    }
+    for (o = 0; o < config->num_output; o++)
+    {
+	xf86OutputPtr output = config->output[o];
+	
+	if (enabled[o] && !modes[o])
+	    modes[o] = xf86ClosestMode (output, target_mode, width, height);
+    }
+
+    /*
+     * Set the position of each output
+     */
+    if (!xf86InitialOutputPositions (scrn, modes))
+    {
+	xfree (crtcs);
+	xfree (modes);
+	return FALSE;
+    }
+	
+    /*
+     * Assign CRTCs to fit output configuration
+     */
+    if (!xf86PickCrtcs (scrn, crtcs, modes, 0, width, height))
+    {
+	xfree (crtcs);
+	xfree (modes);
+	return FALSE;
+    }
+    
+    /* XXX override xf86 common frame computation code */
+    
+    scrn->display->frameX0 = 0;
+    scrn->display->frameY0 = 0;
+    
+    for (c = 0; c < config->num_crtc; c++)
+    {
+	xf86CrtcPtr	crtc = config->crtc[c];
+
+	crtc->enabled = FALSE;
+	memset (&crtc->desiredMode, '\0', sizeof (crtc->desiredMode));
+    }
+    
+    /*
+     * Set initial configuration
+     */
+    for (o = 0; o < config->num_output; o++)
+    {
+	xf86OutputPtr	output = config->output[o];
+	DisplayModePtr	mode = modes[o];
+        xf86CrtcPtr	crtc = crtcs[o];
+
+	if (mode && crtc)
+	{
+	    crtc->desiredMode = *mode;
+	    crtc->enabled = TRUE;
+	    crtc->x = output->initial_x;
+	    crtc->y = output->initial_y;
+	    output->crtc = crtc;
+	}
+    }
+    
+    if (scrn->display->virtualX == 0)
+    {
+	/*
+	 * Expand virtual size to cover potential mode switches
+	 */
+	xf86DefaultScreenLimits (scrn, &width, &height);
+    
+	scrn->display->virtualX = width;
+	scrn->display->virtualY = height;
+    }
+
+    if (width > scrn->virtualX)
+	scrn->virtualX = width;
+    if (height > scrn->virtualY)
+	scrn->virtualY = height;
+    
+    /* Mirror output modes to scrn mode list */
+    xf86SetScrnInfoModes (scrn);
+    
+    xfree (crtcs);
+    xfree (modes);
+    return TRUE;
+}
+
+/**
+ * Set the DPMS power mode of all outputs and CRTCs.
+ *
+ * If the new mode is off, it will turn off outputs and then CRTCs.
+ * Otherwise, it will affect CRTCs before outputs.
+ */
+void
+xf86DPMSSet(ScrnInfoPtr scrn, int mode, int flags)
+{
+    xf86CrtcConfigPtr	config = XF86_CRTC_CONFIG_PTR(scrn);
+    int			i;
+
+    if (!scrn->vtSema)
+	return;
+
+    if (mode == DPMSModeOff) {
+	for (i = 0; i < config->num_output; i++) {
+	    xf86OutputPtr output = config->output[i];
+	    if (output->crtc != NULL)
+		(*output->funcs->dpms) (output, mode);
+	}
+    }
+
+    for (i = 0; i < config->num_crtc; i++) {
+	xf86CrtcPtr crtc = config->crtc[i];
+	if (crtc->enabled)
+	    (*crtc->funcs->dpms) (crtc, mode);
+    }
+
+    if (mode != DPMSModeOff) {
+	for (i = 0; i < config->num_output; i++) {
+	    xf86OutputPtr output = config->output[i];
+	    if (output->crtc != NULL)
+		(*output->funcs->dpms) (output, mode);
+	}
+    }
+}
+
+/**
+ * Implement the screensaver by just calling down into the driver DPMS hooks.
+ *
+ * Even for monitors with no DPMS support, by the definition of our DPMS hooks,
+ * the outputs will still get disabled (blanked).
+ */
+Bool
+xf86SaveScreen(ScreenPtr pScreen, int mode)
+{
+    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+
+    if (xf86IsUnblank(mode))
+	xf86DPMSSet(pScrn, DPMSModeOn, 0);
+    else
+	xf86DPMSSet(pScrn, DPMSModeOff, 0);
+
+    return TRUE;
+}
+
+/**
+ * Disable all inactive crtcs and outputs
+ */
+void
+xf86DisableUnusedFunctions(ScrnInfoPtr pScrn)
+{
+    xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
+    int			o, c;
+
+    for (o = 0; o < xf86_config->num_output; o++) 
+    {
+	xf86OutputPtr  output = xf86_config->output[o];
+	if (!output->crtc) 
+	    (*output->funcs->dpms)(output, DPMSModeOff);
+    }
+
+    for (c = 0; c < xf86_config->num_crtc; c++) 
+    {
+	xf86CrtcPtr crtc = xf86_config->crtc[c];
+
+	if (!crtc->enabled) 
+	{
+	    crtc->funcs->dpms(crtc, DPMSModeOff);
+	    memset(&crtc->mode, 0, sizeof(crtc->mode));
+	}
+    }
+}
+
+#ifdef RANDR_12_INTERFACE
+
+#define EDID_ATOM_NAME		"EDID_DATA"
+
+/**
+ * Set the RandR EDID property
+ */
+static void
+xf86OutputSetEDIDProperty (xf86OutputPtr output, void *data, int data_len)
+{
+    Atom edid_atom = MakeAtom(EDID_ATOM_NAME, sizeof(EDID_ATOM_NAME), TRUE);
+
+    /* This may get called before the RandR resources have been created */
+    if (output->randr_output == NULL)
+	return;
+
+    if (data_len != 0) {
+	RRChangeOutputProperty(output->randr_output, edid_atom, XA_INTEGER, 8,
+			       PropModeReplace, data_len, data, FALSE);
+    } else {
+	RRDeleteOutputProperty(output->randr_output, edid_atom);
+    }
+}
+
+#endif
+
+/**
+ * Set the EDID information for the specified output
+ */
+void
+xf86OutputSetEDID (xf86OutputPtr output, xf86MonPtr edid_mon)
+{
+    ScrnInfoPtr		scrn = output->scrn;
+    xf86CrtcConfigPtr	config = XF86_CRTC_CONFIG_PTR(scrn);
+    int			i;
+#ifdef RANDR_12_INTERFACE
+    int			size;
+#endif
+    
+    if (output->MonInfo != NULL)
+	xfree(output->MonInfo);
+    
+    output->MonInfo = edid_mon;
+
+    /* Debug info for now, at least */
+    xf86DrvMsg(scrn->scrnIndex, X_INFO, "EDID for output %s\n", output->name);
+    xf86PrintEDID(edid_mon);
+    
+    /* Set the DDC properties for the 'compat' output */
+    if (output == config->output[config->compat_output])
+        xf86SetDDCproperties(scrn, edid_mon);
+
+#ifdef RANDR_12_INTERFACE
+    /* Set the RandR output properties */
+    size = 0;
+    if (edid_mon)
+    {
+	if (edid_mon->ver.version == 1)
+	    size = 128;
+	else if (edid_mon->ver.version == 2)
+	    size = 256;
+    }
+    xf86OutputSetEDIDProperty (output, edid_mon ? edid_mon->rawData : NULL, size);
+#endif
+
+    if (edid_mon)
+    {
+	/* Pull out a phyiscal size from a detailed timing if available. */
+	for (i = 0; i < 4; i++) {
+	    if (edid_mon->det_mon[i].type == DT &&
+		edid_mon->det_mon[i].section.d_timings.h_size != 0 &&
+		edid_mon->det_mon[i].section.d_timings.v_size != 0)
+	    {
+		output->mm_width = edid_mon->det_mon[i].section.d_timings.h_size;
+		output->mm_height = edid_mon->det_mon[i].section.d_timings.v_size;
+		break;
+	    }
+	}
+    
+	/* if no mm size is available from a detailed timing, check the max size field */
+	if ((!output->mm_width || !output->mm_height) &&
+	    (edid_mon->features.hsize && edid_mon->features.vsize))
+	{
+	    output->mm_width = edid_mon->features.hsize * 10;
+	    output->mm_height = edid_mon->features.vsize * 10;
+	}
+    }
+}
+
+/**
+ * Return the list of modes supported by the EDID information
+ * stored in 'output'
+ */
+DisplayModePtr
+xf86OutputGetEDIDModes (xf86OutputPtr output)
+{
+    ScrnInfoPtr	scrn = output->scrn;
+    xf86MonPtr	edid_mon = output->MonInfo;
+
+    if (!edid_mon)
+	return NULL;
+    return xf86DDCGetModes(scrn->scrnIndex, edid_mon);
+}
+
+xf86MonPtr
+xf86OutputGetEDID (xf86OutputPtr output, I2CBusPtr pDDCBus)
+{
+    ScrnInfoPtr	scrn = output->scrn;
+
+    return xf86DoEDID_DDC2 (scrn->scrnIndex, pDDCBus);
+}
diff --git a/hw/xfree86/modes/xf86Crtc.h b/hw/xfree86/modes/xf86Crtc.h
new file mode 100644
index 0000000..49f4965
--- /dev/null
+++ b/hw/xfree86/modes/xf86Crtc.h
@@ -0,0 +1,555 @@
+/*
+ * Copyright © 2006 Keith Packard
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission.  The copyright holders make no representations
+ * about the suitability of this software for any purpose.  It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+#ifndef _XF86CRTC_H_
+#define _XF86CRTC_H_
+
+#include <edid.h>
+#include "randrstr.h"
+#if XF86_MODES_RENAME
+#include "xf86Rename.h"
+#endif
+#include "xf86Modes.h"
+#include "xf86Parser.h"
+#include "damage.h"
+
+/* Compat definitions for older X Servers. */
+#ifndef M_T_PREFERRED
+#define M_T_PREFERRED	0x08
+#endif
+#ifndef M_T_DRIVER
+#define M_T_DRIVER	0x40
+#endif
+
+typedef struct _xf86Crtc xf86CrtcRec, *xf86CrtcPtr;
+typedef struct _xf86Output xf86OutputRec, *xf86OutputPtr;
+
+typedef enum _xf86OutputStatus {
+   XF86OutputStatusConnected,
+   XF86OutputStatusDisconnected,
+   XF86OutputStatusUnknown,
+} xf86OutputStatus;
+
+typedef struct _xf86CrtcFuncs {
+   /**
+    * Turns the crtc on/off, or sets intermediate power levels if available.
+    *
+    * Unsupported intermediate modes drop to the lower power setting.  If the
+    * mode is DPMSModeOff, the crtc must be disabled sufficiently for it to
+    * be safe to call mode_set.
+    */
+   void
+    (*dpms)(xf86CrtcPtr		crtc,
+	    int		    	mode);
+
+   /**
+    * Saves the crtc's state for restoration on VT switch.
+    */
+   void
+    (*save)(xf86CrtcPtr		crtc);
+
+   /**
+    * Restore's the crtc's state at VT switch.
+    */
+   void
+    (*restore)(xf86CrtcPtr	crtc);
+
+    /**
+     * Lock CRTC prior to mode setting, mostly for DRI.
+     * Returns whether unlock is needed
+     */
+    Bool
+    (*lock) (xf86CrtcPtr crtc);
+    
+    /**
+     * Unlock CRTC after mode setting, mostly for DRI
+     */
+    void
+    (*unlock) (xf86CrtcPtr crtc);
+    
+    /**
+     * Callback to adjust the mode to be set in the CRTC.
+     *
+     * This allows a CRTC to adjust the clock or even the entire set of
+     * timings, which is used for panels with fixed timings or for
+     * buses with clock limitations.
+     */
+    Bool
+    (*mode_fixup)(xf86CrtcPtr crtc,
+		  DisplayModePtr mode,
+		  DisplayModePtr adjusted_mode);
+
+    /**
+     * Callback for setting up a video mode after fixups have been made.
+     */
+    void
+    (*mode_set)(xf86CrtcPtr crtc,
+		DisplayModePtr mode,
+		DisplayModePtr adjusted_mode,
+		int x, int y);
+
+    /* Set the color ramps for the CRTC to the given values. */
+    void
+    (*gamma_set)(xf86CrtcPtr crtc, CARD16 *red, CARD16 *green, CARD16 *blue,
+		 int size);
+
+    /**
+     * Create shadow pixmap for rotation support
+     */
+    PixmapPtr
+    (*shadow_create) (xf86CrtcPtr crtc, int width, int height);
+    
+    /**
+     * Destroy shadow pixmap
+     */
+    void
+    (*shadow_destroy) (xf86CrtcPtr crtc, PixmapPtr pPixmap);
+
+    /**
+     * Clean up driver-specific bits of the crtc
+     */
+    void
+    (*destroy) (xf86CrtcPtr	crtc);
+} xf86CrtcFuncsRec, *xf86CrtcFuncsPtr;
+
+struct _xf86Crtc {
+    /**
+     * Associated ScrnInfo
+     */
+    ScrnInfoPtr	    scrn;
+    
+    /**
+     * Active state of this CRTC
+     *
+     * Set when this CRTC is driving one or more outputs 
+     */
+    Bool	    enabled;
+    
+    /** Track whether cursor is within CRTC range  */
+    Bool	    cursorInRange;
+    
+    /** Track state of cursor associated with this CRTC */
+    Bool	    cursorShown;
+    
+    /**
+     * Active mode
+     *
+     * This reflects the mode as set in the CRTC currently
+     * It will be cleared when the VT is not active or
+     * during server startup
+     */
+    DisplayModeRec  mode;
+    Rotation	    rotation;
+    PixmapPtr	    rotatedPixmap;
+    /**
+     * Position on screen
+     *
+     * Locates this CRTC within the frame buffer
+     */
+    int		    x, y;
+    
+    /**
+     * Desired mode
+     *
+     * This is set to the requested mode, independent of
+     * whether the VT is active. In particular, it receives
+     * the startup configured mode and saves the active mode
+     * on VT switch.
+     */
+    DisplayModeRec  desiredMode;
+    Rotation	    desiredRotation;
+    int		    desiredX, desiredY;
+    
+    /** crtc-specific functions */
+    const xf86CrtcFuncsRec *funcs;
+
+    /**
+     * Driver private
+     *
+     * Holds driver-private information
+     */
+    void	    *driver_private;
+
+#ifdef RANDR_12_INTERFACE
+    /**
+     * RandR crtc
+     *
+     * When RandR 1.2 is available, this
+     * points at the associated crtc object
+     */
+    RRCrtcPtr	    randr_crtc;
+#else
+    void	    *randr_crtc;
+#endif
+};
+
+typedef struct _xf86OutputFuncs {
+    /**
+     * Called to allow the output a chance to create properties after the
+     * RandR objects have been created.
+     */
+    void
+    (*create_resources)(xf86OutputPtr output);
+
+    /**
+     * Turns the output on/off, or sets intermediate power levels if available.
+     *
+     * Unsupported intermediate modes drop to the lower power setting.  If the
+     * mode is DPMSModeOff, the output must be disabled, as the DPLL may be
+     * disabled afterwards.
+     */
+    void
+    (*dpms)(xf86OutputPtr	output,
+	    int			mode);
+
+    /**
+     * Saves the output's state for restoration on VT switch.
+     */
+    void
+    (*save)(xf86OutputPtr	output);
+
+    /**
+     * Restore's the output's state at VT switch.
+     */
+    void
+    (*restore)(xf86OutputPtr	output);
+
+    /**
+     * Callback for testing a video mode for a given output.
+     *
+     * This function should only check for cases where a mode can't be supported
+     * on the output specifically, and not represent generic CRTC limitations.
+     *
+     * \return MODE_OK if the mode is valid, or another MODE_* otherwise.
+     */
+    int
+    (*mode_valid)(xf86OutputPtr	    output,
+		  DisplayModePtr    pMode);
+
+    /**
+     * Callback to adjust the mode to be set in the CRTC.
+     *
+     * This allows an output to adjust the clock or even the entire set of
+     * timings, which is used for panels with fixed timings or for
+     * buses with clock limitations.
+     */
+    Bool
+    (*mode_fixup)(xf86OutputPtr output,
+		  DisplayModePtr mode,
+		  DisplayModePtr adjusted_mode);
+
+    /**
+     * Callback for setting up a video mode after fixups have been made.
+     *
+     * This is only called while the output is disabled.  The dpms callback
+     * must be all that's necessary for the output, to turn the output on
+     * after this function is called.
+     */
+    void
+    (*mode_set)(xf86OutputPtr  output,
+		DisplayModePtr mode,
+		DisplayModePtr adjusted_mode);
+
+    /**
+     * Probe for a connected output, and return detect_status.
+     */
+    xf86OutputStatus
+    (*detect)(xf86OutputPtr	    output);
+
+    /**
+     * Query the device for the modes it provides.
+     *
+     * This function may also update MonInfo, mm_width, and mm_height.
+     *
+     * \return singly-linked list of modes or NULL if no modes found.
+     */
+    DisplayModePtr
+    (*get_modes)(xf86OutputPtr	    output);
+
+#ifdef RANDR_12_INTERFACE
+    /**
+     * Callback when an output's property has changed.
+     */
+    Bool
+    (*set_property)(xf86OutputPtr output,
+		    Atom property,
+		    RRPropertyValuePtr value);
+#endif
+    /**
+     * Clean up driver-specific bits of the output
+     */
+    void
+    (*destroy) (xf86OutputPtr	    output);
+} xf86OutputFuncsRec, *xf86OutputFuncsPtr;
+
+struct _xf86Output {
+    /**
+     * Associated ScrnInfo
+     */
+    ScrnInfoPtr		scrn;
+
+    /**
+     * Currently connected crtc (if any)
+     *
+     * If this output is not in use, this field will be NULL.
+     */
+    xf86CrtcPtr		crtc;
+
+    /**
+     * Possible CRTCs for this output as a mask of crtc indices
+     */
+    CARD32		possible_crtcs;
+
+    /**
+     * Possible outputs to share the same CRTC as a mask of output indices
+     */
+    CARD32		possible_clones;
+    
+    /**
+     * Whether this output can support interlaced modes
+     */
+    Bool		interlaceAllowed;
+
+    /**
+     * Whether this output can support double scan modes
+     */
+    Bool		doubleScanAllowed;
+
+    /**
+     * List of available modes on this output.
+     *
+     * This should be the list from get_modes(), plus perhaps additional
+     * compatible modes added later.
+     */
+    DisplayModePtr	probed_modes;
+
+    /**
+     * Options parsed from the related monitor section
+     */
+    OptionInfoPtr	options;
+    
+    /**
+     * Configured monitor section
+     */
+    XF86ConfMonitorPtr  conf_monitor;
+    
+    /**
+     * Desired initial position
+     */
+    int			initial_x, initial_y;
+
+    /**
+     * Current connection status
+     *
+     * This indicates whether a monitor is known to be connected
+     * to this output or not, or whether there is no way to tell
+     */
+    xf86OutputStatus	status;
+
+    /** EDID monitor information */
+    xf86MonPtr		MonInfo;
+
+    /** subpixel order */
+    int			subpixel_order;
+
+    /** Physical size of the currently attached output device. */
+    int			mm_width, mm_height;
+
+    /** Output name */
+    char		*name;
+
+    /** output-specific functions */
+    const xf86OutputFuncsRec *funcs;
+
+    /** driver private information */
+    void		*driver_private;
+    
+#ifdef RANDR_12_INTERFACE
+    /**
+     * RandR 1.2 output structure.
+     *
+     * When RandR 1.2 is available, this points at the associated
+     * RandR output structure and is created when this output is created
+     */
+    RROutputPtr		randr_output;
+#else
+    void		*randr_output;
+#endif
+};
+
+typedef struct _xf86CrtcConfig {
+    int			num_output;
+    xf86OutputPtr	*output;
+    /**
+     * compat_output is used whenever we deal
+     * with legacy code that only understands a single
+     * output. pScrn->modes will be loaded from this output,
+     * adjust frame will whack this output, etc.
+     */
+    int			compat_output;
+
+    int			num_crtc;
+    xf86CrtcPtr		*crtc;
+
+    int			minWidth, minHeight;
+    int			maxWidth, maxHeight;
+    
+    /* For crtc-based rotation */
+    DamagePtr   rotationDamage;
+
+    /* DGA */
+    unsigned int	dga_flags;
+    unsigned long	dga_address;
+    DGAModePtr		dga_modes;
+    int			dga_nmode;
+    int			dga_width, dga_height, dga_stride;
+    DisplayModePtr	dga_save_mode;
+
+} xf86CrtcConfigRec, *xf86CrtcConfigPtr;
+
+extern int xf86CrtcConfigPrivateIndex;
+
+#define XF86_CRTC_CONFIG_PTR(p)	((xf86CrtcConfigPtr) ((p)->privates[xf86CrtcConfigPrivateIndex].ptr))
+
+/*
+ * Initialize xf86CrtcConfig structure
+ */
+
+void
+xf86CrtcConfigInit (ScrnInfoPtr		scrn);
+
+void
+xf86CrtcSetSizeRange (ScrnInfoPtr scrn,
+		      int minWidth, int minHeight,
+		      int maxWidth, int maxHeight);
+
+/*
+ * Crtc functions
+ */
+xf86CrtcPtr
+xf86CrtcCreate (ScrnInfoPtr		scrn,
+		const xf86CrtcFuncsRec	*funcs);
+
+void
+xf86CrtcDestroy (xf86CrtcPtr		crtc);
+
+
+/**
+ * Allocate a crtc for the specified output
+ *
+ * Find a currently unused CRTC which is suitable for
+ * the specified output
+ */
+
+xf86CrtcPtr 
+xf86AllocCrtc (xf86OutputPtr		output);
+
+/**
+ * Free a crtc
+ *
+ * Mark the crtc as unused by any outputs
+ */
+
+void
+xf86FreeCrtc (xf86CrtcPtr		crtc);
+
+/**
+ * Sets the given video mode on the given crtc
+ */
+Bool
+xf86CrtcSetMode (xf86CrtcPtr crtc, DisplayModePtr mode, Rotation rotation,
+		 int x, int y);
+
+/*
+ * Assign crtc rotation during mode set
+ */
+Bool
+xf86CrtcRotate (xf86CrtcPtr crtc, DisplayModePtr mode, Rotation rotation);
+
+/**
+ * Return whether any output is assigned to the crtc
+ */
+Bool
+xf86CrtcInUse (xf86CrtcPtr crtc);
+
+/*
+ * Output functions
+ */
+xf86OutputPtr
+xf86OutputCreate (ScrnInfoPtr		scrn,
+		      const xf86OutputFuncsRec *funcs,
+		      const char	*name);
+
+Bool
+xf86OutputRename (xf86OutputPtr output, const char *name);
+
+void
+xf86OutputDestroy (xf86OutputPtr	output);
+
+void
+xf86ProbeOutputModes (ScrnInfoPtr pScrn, int maxX, int maxY);
+
+void
+xf86SetScrnInfoModes (ScrnInfoPtr pScrn);
+
+Bool
+xf86InitialConfiguration (ScrnInfoPtr pScrn);
+
+void
+xf86DPMSSet(ScrnInfoPtr pScrn, int PowerManagementMode, int flags);
+    
+Bool
+xf86SaveScreen(ScreenPtr pScreen, int mode);
+
+void
+xf86DisableUnusedFunctions(ScrnInfoPtr pScrn);
+
+/**
+ * Set the EDID information for the specified output
+ */
+void
+xf86OutputSetEDID (xf86OutputPtr output, xf86MonPtr edid_mon);
+
+/**
+ * Return the list of modes supported by the EDID information
+ * stored in 'output'
+ */
+DisplayModePtr
+xf86OutputGetEDIDModes (xf86OutputPtr output);
+
+xf86MonPtr
+xf86OutputGetEDID (xf86OutputPtr output, I2CBusPtr pDDCBus);
+
+/**
+ * Initialize dga for this screen
+ */
+
+Bool
+xf86DiDGAInit (ScreenPtr pScreen, unsigned long dga_address);
+
+/**
+ * Re-initialize dga for this screen (as when the set of modes changes)
+ */
+
+Bool
+xf86DiDGAReInit (ScreenPtr pScreen);
+
+#endif /* _XF86CRTC_H_ */
diff --git a/hw/xfree86/modes/xf86DiDGA.c b/hw/xfree86/modes/xf86DiDGA.c
new file mode 100644
index 0000000..f4ac4de
--- /dev/null
+++ b/hw/xfree86/modes/xf86DiDGA.c
@@ -0,0 +1,280 @@
+/*
+ * Copyright © 2006 Keith Packard
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission.  The copyright holders make no representations
+ * about the suitability of this software for any purpose.  It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include "xf86.h"
+#include "xf86DDC.h"
+#include "xf86_OSproc.h"
+#include "dgaproc.h"
+#include "xf86Crtc.h"
+#include "xf86Modes.h"
+#include "gcstruct.h"
+
+static Bool
+xf86_dga_get_modes (ScreenPtr pScreen)
+{
+    ScrnInfoPtr		scrn = xf86Screens[pScreen->myNum];
+    xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+    DGAModePtr		modes, mode;
+    DisplayModePtr	display_mode;
+    int			bpp = scrn->bitsPerPixel >> 3;
+    int			num;
+
+    num = 0;
+    display_mode = scrn->modes;
+    while (display_mode) 
+    {
+	num++;
+	display_mode = display_mode->next;
+	if (display_mode == scrn->modes)
+	    break;
+    }
+    
+    if (!num)
+	return FALSE;
+    
+    modes = xalloc(num * sizeof(DGAModeRec));
+    if (!modes)
+	return FALSE;
+    
+    num = 0;
+    display_mode = scrn->modes;
+    while (display_mode) 
+    {
+	mode = modes + num++;
+
+	mode->mode = display_mode;
+	mode->flags = DGA_CONCURRENT_ACCESS | DGA_PIXMAP_AVAILABLE;
+        mode->flags |= DGA_FILL_RECT | DGA_BLIT_RECT;
+	if (display_mode->Flags & V_DBLSCAN)
+	    mode->flags |= DGA_DOUBLESCAN;
+	if (display_mode->Flags & V_INTERLACE)
+	    mode->flags |= DGA_INTERLACED;
+	mode->byteOrder = scrn->imageByteOrder;
+	mode->depth = scrn->depth;
+	mode->bitsPerPixel = scrn->bitsPerPixel;
+	mode->red_mask = scrn->mask.red;
+	mode->green_mask = scrn->mask.green;
+	mode->blue_mask = scrn->mask.blue;
+	mode->visualClass = (bpp == 1) ? PseudoColor : TrueColor;
+	mode->viewportWidth = display_mode->HDisplay;
+	mode->viewportHeight = display_mode->VDisplay;
+	mode->xViewportStep = (bpp == 3) ? 2 : 1;
+	mode->yViewportStep = 1;
+	mode->viewportFlags = DGA_FLIP_RETRACE;
+	mode->offset = 0;
+	mode->address = (unsigned char *) xf86_config->dga_address;
+	mode->bytesPerScanline = xf86_config->dga_stride;
+	mode->imageWidth = xf86_config->dga_width;
+	mode->imageHeight = xf86_config->dga_height;
+	mode->pixmapWidth = mode->imageWidth;
+	mode->pixmapHeight = mode->imageHeight;
+	mode->maxViewportX = mode->imageWidth -	mode->viewportWidth;
+	mode->maxViewportY = mode->imageHeight - mode->viewportHeight;
+
+	display_mode = display_mode->next;
+	if (display_mode == scrn->modes)
+	    break;
+    }
+    if (xf86_config->dga_modes)
+	xfree (xf86_config->dga_modes);
+    xf86_config->dga_nmode = num;
+    xf86_config->dga_modes = modes;
+    return TRUE;
+}
+
+static Bool
+xf86_dga_set_mode(ScrnInfoPtr scrn, DGAModePtr display_mode)
+{
+    ScreenPtr		pScreen = scrn->pScreen;
+    xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+
+    if (!display_mode) 
+    {
+	if (xf86_config->dga_save_mode)
+	{
+	    xf86SwitchMode(pScreen, xf86_config->dga_save_mode);
+	    xf86_config->dga_save_mode = NULL;
+	}
+    }
+    else
+    {
+	if (!xf86_config->dga_save_mode)
+	{
+	    xf86_config->dga_save_mode = scrn->currentMode;
+	    xf86SwitchMode(pScreen, display_mode->mode);
+	}
+    }
+    return TRUE;
+}
+
+static int
+xf86_dga_get_viewport(ScrnInfoPtr scrn)
+{
+    return 0;
+}
+
+static void
+xf86_dga_set_viewport(ScrnInfoPtr scrn, int x, int y, int flags)
+{
+   scrn->AdjustFrame(scrn->pScreen->myNum, x, y, flags);
+}
+
+static Bool
+xf86_dga_get_drawable_and_gc (ScrnInfoPtr scrn, DrawablePtr *ppDrawable, GCPtr *ppGC)
+{
+    ScreenPtr		pScreen = scrn->pScreen;
+    xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+    PixmapPtr		pPixmap;
+    GCPtr		pGC;
+    
+    pPixmap = GetScratchPixmapHeader (pScreen, xf86_config->dga_width, xf86_config->dga_height,
+				      scrn->depth, scrn->bitsPerPixel, xf86_config->dga_stride, 
+				      (char *) scrn->memPhysBase + scrn->fbOffset);
+    if (!pPixmap)
+	return FALSE;
+    pGC  = GetScratchGC (scrn->depth, pScreen);
+    if (!pGC)
+    {
+	FreeScratchPixmapHeader (pPixmap);
+	return FALSE;
+    }
+    *ppDrawable = &pPixmap->drawable;
+    *ppGC = pGC;
+    return TRUE;
+}
+
+static void
+xf86_dga_release_drawable_and_gc (ScrnInfoPtr scrn, DrawablePtr pDrawable, GCPtr pGC)
+{
+    FreeScratchGC (pGC);
+    FreeScratchPixmapHeader ((PixmapPtr) pDrawable);
+}
+
+static void
+xf86_dga_fill_rect(ScrnInfoPtr scrn, int x, int y, int w, int h, unsigned long color)
+{
+    GCPtr		pGC;
+    DrawablePtr		pDrawable;
+    XID			vals[1];
+    xRectangle		r;
+
+    if (!xf86_dga_get_drawable_and_gc (scrn, &pDrawable, &pGC))
+	return;
+    vals[0] = color;
+    ChangeGC (pGC, GCForeground, vals);
+    ValidateGC (pDrawable, pGC);
+    r.x = x;
+    r.y = y;
+    r.width = w;
+    r.height = h;
+    pGC->ops->PolyFillRect (pDrawable, pGC, 1, &r);
+    xf86_dga_release_drawable_and_gc (scrn, pDrawable, pGC);
+}
+
+static void
+xf86_dga_sync(ScrnInfoPtr scrn)
+{
+    ScreenPtr	pScreen = scrn->pScreen;
+    WindowPtr	pRoot = WindowTable [pScreen->myNum];
+    char	buffer[4];
+
+    pScreen->GetImage (&pRoot->drawable, 0, 0, 1, 1, ZPixmap, ~0L, buffer);
+}
+
+static void
+xf86_dga_blit_rect(ScrnInfoPtr scrn, int srcx, int srcy, int w, int h, int dstx, int dsty)
+{
+    DrawablePtr	pDrawable;
+    GCPtr	pGC;
+
+    if (!xf86_dga_get_drawable_and_gc (scrn, &pDrawable, &pGC))
+	return;
+    ValidateGC (pDrawable, pGC);
+    pGC->ops->CopyArea (pDrawable, pDrawable, pGC, srcx, srcy, w, h, dstx, dsty);
+    xf86_dga_release_drawable_and_gc (scrn, pDrawable, pGC);
+}
+
+static Bool
+xf86_dga_open_framebuffer(ScrnInfoPtr scrn,
+			  char **name,
+			  unsigned char **mem, int *size, int *offset, int *flags)
+{
+    xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+    
+    *size = xf86_config->dga_stride * xf86_config->dga_height;
+    *mem = (unsigned char *) (xf86_config->dga_address);
+    *offset = 0;
+    *flags = DGA_NEED_ROOT;
+
+    return TRUE;
+}
+
+static void
+xf86_dga_close_framebuffer(ScrnInfoPtr scrn)
+{
+}
+
+static DGAFunctionRec xf86_dga_funcs = {
+   xf86_dga_open_framebuffer,
+   xf86_dga_close_framebuffer,
+   xf86_dga_set_mode,
+   xf86_dga_set_viewport,
+   xf86_dga_get_viewport,
+   xf86_dga_sync,
+   xf86_dga_fill_rect,
+   xf86_dga_blit_rect,
+   NULL
+};
+
+Bool
+xf86DiDGAReInit (ScreenPtr pScreen)
+{
+    ScrnInfoPtr		scrn = xf86Screens[pScreen->myNum];
+    xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+    
+    if (!xf86_dga_get_modes (pScreen))
+	return FALSE;
+    
+    return DGAReInitModes (pScreen, xf86_config->dga_modes, xf86_config->dga_nmode);
+}
+
+Bool
+xf86DiDGAInit (ScreenPtr pScreen, unsigned long dga_address)
+{
+    ScrnInfoPtr		scrn = xf86Screens[pScreen->myNum];
+    xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+
+    xf86_config->dga_flags = 0;
+    xf86_config->dga_address = dga_address;
+    xf86_config->dga_width = scrn->virtualX;
+    xf86_config->dga_height = scrn->virtualY;
+    xf86_config->dga_stride = scrn->displayWidth * scrn->bitsPerPixel >> 3;
+    
+    if (!xf86_dga_get_modes (pScreen))
+	return FALSE;
+    
+    return DGAInit(pScreen, &xf86_dga_funcs, xf86_config->dga_modes, xf86_config->dga_nmode);
+}
diff --git a/hw/xfree86/modes/xf86EdidModes.c b/hw/xfree86/modes/xf86EdidModes.c
new file mode 100644
index 0000000..0476a68
--- /dev/null
+++ b/hw/xfree86/modes/xf86EdidModes.c
@@ -0,0 +1,339 @@
+/*
+ * Copyright 2006 Luc Verhaegen.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * @file This is a copy of edid_modes.c from the X Server, for compatibility
+ * with old X Servers.
+ */
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include "xf86.h"
+#include "xf86DDC.h"
+#include <X11/Xatom.h>
+#include "property.h"
+#include "propertyst.h"
+#include "xf86DDC.h"
+#include "xf86Crtc.h"
+#include <string.h>
+#include <math.h>
+
+/*
+ * Quirks to work around broken EDID data from various monitors.
+ */
+
+typedef enum {
+    DDC_QUIRK_NONE = 0,
+    /* Force detailed sync polarity to -h +v */
+    DDC_QUIRK_DT_SYNC_HM_VP = 1 << 0,
+    /* First detailed mode is bogus, prefer largest mode at 60hz */
+    DDC_QUIRK_PREFER_LARGE_60 = 1 << 1,
+    /* 135MHz clock is too high, drop a bit */
+    DDC_QUIRK_135_CLOCK_TOO_HIGH = 1 << 2
+} ddc_quirk_t;
+
+static Bool quirk_dt_sync_hm_vp (int scrnIndex, xf86MonPtr DDC)
+{
+    /* Belinea 1924S1W */
+    if (memcmp (DDC->vendor.name, "MAX", 4) == 0 &&
+	DDC->vendor.prod_id == 1932)
+	return TRUE;
+    /* Belinea 10 20 30W */
+    if (memcmp (DDC->vendor.name, "MAX", 4) == 0 &&
+	DDC->vendor.prod_id == 2007)
+	return TRUE;
+    /* ViewSonic VX2025wm (bug #9941) */
+    if (memcmp (DDC->vendor.name, "VSC", 4) == 0 &&
+	DDC->vendor.prod_id == 58653)
+	return TRUE;
+
+    return FALSE;
+}
+
+static Bool quirk_prefer_large_60 (int scrnIndex, xf86MonPtr DDC)
+{
+    /* Belinea 10 15 55 */
+    if (memcmp (DDC->vendor.name, "MAX", 4) == 0 &&
+	DDC->vendor.prod_id == 1516)
+	return TRUE;
+    
+    return FALSE;
+}
+
+static Bool quirk_135_clock_too_high (int scrnIndex, xf86MonPtr DDC)
+{
+    /* Envision Peripherals, Inc. EN-7100e.  See bug #9550. */
+    if (memcmp (DDC->vendor.name, "EPI", 4) == 0 &&
+	DDC->vendor.prod_id == 59264)
+	return TRUE;
+    
+    return FALSE;
+}
+
+typedef struct {
+    Bool	(*detect) (int scrnIndex, xf86MonPtr DDC);
+    ddc_quirk_t	quirk;
+    char	*description;
+} ddc_quirk_map_t;
+
+static const ddc_quirk_map_t ddc_quirks[] = {
+    { 
+	quirk_dt_sync_hm_vp,	DDC_QUIRK_DT_SYNC_HM_VP,
+	"Set detailed timing sync polarity to -h +v"
+    },
+    {
+	quirk_prefer_large_60,   DDC_QUIRK_PREFER_LARGE_60,
+	"Detailed timing is not preferred, use largest mode at 60Hz"
+    },
+    {
+	quirk_135_clock_too_high,   DDC_QUIRK_135_CLOCK_TOO_HIGH,
+	"Recommended 135MHz pixel clock is too high"
+    },
+    { 
+	NULL,		DDC_QUIRK_NONE,
+	"No known quirks"
+    },
+};
+
+/*
+ * TODO:
+ *  - for those with access to the VESA DMT standard; review please.
+ */
+#define MODEPREFIX(name) NULL, NULL, name, 0,M_T_DRIVER
+#define MODESUFFIX   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,FALSE,FALSE,0,NULL,0,0.0,0.0
+
+static DisplayModeRec DDCEstablishedModes[17] = {
+    { MODEPREFIX("800x600"),    40000,  800,  840,  968, 1056, 0,  600,  601,  605,  628, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX }, /* 800x600 at 60Hz */
+    { MODEPREFIX("800x600"),    36000,  800,  824,  896, 1024, 0,  600,  601,  603,  625, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX }, /* 800x600 at 56Hz */
+    { MODEPREFIX("640x480"),    31500,  640,  656,  720,  840, 0,  480,  481,  484,  500, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX }, /* 640x480 at 75Hz */
+    { MODEPREFIX("640x480"),    31500,  640,  664,  704,  832, 0,  480,  489,  491,  520, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX }, /* 640x480 at 72Hz */
+    { MODEPREFIX("640x480"),    30240,  640,  704,  768,  864, 0,  480,  483,  486,  525, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX }, /* 640x480 at 67Hz */
+    { MODEPREFIX("640x480"),    25200,  640,  656,  752,  800, 0,  480,  490,  492,  525, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX }, /* 640x480 at 60Hz */
+    { MODEPREFIX("720x400"),    35500,  720,  738,  846,  900, 0,  400,  421,  423,  449, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX }, /* 720x400 at 88Hz */
+    { MODEPREFIX("720x400"),    28320,  720,  738,  846,  900, 0,  400,  412,  414,  449, 0, V_NHSYNC | V_PVSYNC, MODESUFFIX }, /* 720x400 at 70Hz */
+    { MODEPREFIX("1280x1024"), 135000, 1280, 1296, 1440, 1688, 0, 1024, 1025, 1028, 1066, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX }, /* 1280x1024 at 75Hz */
+    { MODEPREFIX("1024x768"),   78800, 1024, 1040, 1136, 1312, 0,  768,  769,  772,  800, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX }, /* 1024x768 at 75Hz */
+    { MODEPREFIX("1024x768"),   75000, 1024, 1048, 1184, 1328, 0,  768,  771,  777,  806, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX }, /* 1024x768 at 70Hz */
+    { MODEPREFIX("1024x768"),   65000, 1024, 1048, 1184, 1344, 0,  768,  771,  777,  806, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX }, /* 1024x768 at 60Hz */
+    { MODEPREFIX("1024x768"),   44900, 1024, 1032, 1208, 1264, 0,  768,  768,  776,  817, 0, V_PHSYNC | V_PVSYNC | V_INTERLACE, MODESUFFIX }, /* 1024x768 at 43Hz */
+    { MODEPREFIX("832x624"),    57284,  832,  864,  928, 1152, 0,  624,  625,  628,  667, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX }, /* 832x624 at 75Hz */
+    { MODEPREFIX("800x600"),    49500,  800,  816,  896, 1056, 0,  600,  601,  604,  625, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX }, /* 800x600 at 75Hz */
+    { MODEPREFIX("800x600"),    50000,  800,  856,  976, 1040, 0,  600,  637,  643,  666, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX }, /* 800x600 at 72Hz */
+    { MODEPREFIX("1152x864"),  108000, 1152, 1216, 1344, 1600, 0,  864,  865,  868,  900, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX }, /* 1152x864 at 75Hz */
+};
+
+static DisplayModePtr
+DDCModesFromEstablished(int scrnIndex, struct established_timings *timing,
+			ddc_quirk_t quirks)
+{
+    DisplayModePtr Modes = NULL, Mode = NULL;
+    CARD32 bits = (timing->t1) | (timing->t2 << 8) |
+        ((timing->t_manu & 0x80) << 9);
+    int i;
+
+    for (i = 0; i < 17; i++) {
+        if (bits & (0x01 << i)) {
+            Mode = xf86DuplicateMode(&DDCEstablishedModes[i]);
+            Modes = xf86ModesAdd(Modes, Mode);
+        }
+    }
+
+    return Modes;
+}
+
+/*
+ *
+ */
+static DisplayModePtr
+DDCModesFromStandardTiming(int scrnIndex, struct std_timings *timing,
+			   ddc_quirk_t quirks)
+{
+    DisplayModePtr Modes = NULL, Mode = NULL;
+    int i;
+
+    for (i = 0; i < STD_TIMINGS; i++) {
+        if (timing[i].hsize && timing[i].vsize && timing[i].refresh) {
+            Mode =  xf86CVTMode(timing[i].hsize, timing[i].vsize,
+                                timing[i].refresh, FALSE, FALSE);
+	    Mode->type = M_T_DRIVER;
+            Modes = xf86ModesAdd(Modes, Mode);
+        }
+    }
+
+    return Modes;
+}
+
+/*
+ *
+ */
+static DisplayModePtr
+DDCModeFromDetailedTiming(int scrnIndex, struct detailed_timings *timing,
+			  int preferred, ddc_quirk_t quirks)
+{
+    DisplayModePtr Mode;
+
+    /* We don't do stereo */
+    if (timing->stereo) {
+        xf86DrvMsg(scrnIndex, X_INFO,
+		   "%s: Ignoring: We don't handle stereo.\n", __func__);
+        return NULL;
+    }
+
+    /* We only do seperate sync currently */
+    if (timing->sync != 0x03) {
+         xf86DrvMsg(scrnIndex, X_INFO,
+		    "%s: %dx%d Warning: We only handle seperate"
+                    " sync.\n", __func__, timing->h_active, timing->v_active);
+    }
+
+    Mode = xnfalloc(sizeof(DisplayModeRec));
+    memset(Mode, 0, sizeof(DisplayModeRec));
+
+    Mode->type = M_T_DRIVER;
+    if (preferred)
+	Mode->type |= M_T_PREFERRED;
+
+    if( ( quirks & DDC_QUIRK_135_CLOCK_TOO_HIGH ) &&
+	timing->clock == 135000000 )
+        Mode->Clock = 108880;
+    else
+        Mode->Clock = timing->clock / 1000.0;
+
+    Mode->HDisplay = timing->h_active;
+    Mode->HSyncStart = timing->h_active + timing->h_sync_off;
+    Mode->HSyncEnd = Mode->HSyncStart + timing->h_sync_width;
+    Mode->HTotal = timing->h_active + timing->h_blanking;
+
+    Mode->VDisplay = timing->v_active;
+    Mode->VSyncStart = timing->v_active + timing->v_sync_off;
+    Mode->VSyncEnd = Mode->VSyncStart + timing->v_sync_width;
+    Mode->VTotal = timing->v_active + timing->v_blanking;
+
+    xf86SetModeDefaultName(Mode);
+
+    /* We ignore h/v_size and h/v_border for now. */
+
+    if (timing->interlaced)
+        Mode->Flags |= V_INTERLACE;
+
+    if (quirks & DDC_QUIRK_DT_SYNC_HM_VP)
+	Mode->Flags |= V_NHSYNC | V_PVSYNC;
+    else
+    {
+	if (timing->misc & 0x02)
+	    Mode->Flags |= V_PHSYNC;
+	else
+	    Mode->Flags |= V_NHSYNC;
+    
+	if (timing->misc & 0x01)
+	    Mode->Flags |= V_PVSYNC;
+	else
+	    Mode->Flags |= V_NVSYNC;
+    }
+
+    return Mode;
+}
+
+DisplayModePtr
+xf86DDCGetModes(int scrnIndex, xf86MonPtr DDC)
+{
+    int preferred, i;
+    DisplayModePtr  Modes = NULL, Mode;
+    ddc_quirk_t	    quirks;
+
+    xf86DrvMsg (scrnIndex, X_INFO, "EDID vendor \"%s\", prod id %d\n",
+		DDC->vendor.name, DDC->vendor.prod_id);
+    quirks = DDC_QUIRK_NONE;
+    for (i = 0; ddc_quirks[i].detect; i++)
+	if (ddc_quirks[i].detect (scrnIndex, DDC))
+	{
+	    xf86DrvMsg (scrnIndex, X_INFO, "    EDID quirk: %s\n",
+			ddc_quirks[i].description);
+	    quirks |= ddc_quirks[i].quirk;
+	}
+    
+    preferred = PREFERRED_TIMING_MODE(DDC->features.msc);
+    if (quirks & DDC_QUIRK_PREFER_LARGE_60)
+	preferred = 0;
+
+    for (i = 0; i < DET_TIMINGS; i++) {
+	struct detailed_monitor_section *det_mon = &DDC->det_mon[i];
+
+        switch (det_mon->type) {
+        case DT:
+            Mode = DDCModeFromDetailedTiming(scrnIndex,
+                                             &det_mon->section.d_timings,
+					     preferred,
+					     quirks);
+	    preferred = 0;
+            Modes = xf86ModesAdd(Modes, Mode);
+            break;
+        case DS_STD_TIMINGS:
+            Mode = DDCModesFromStandardTiming(scrnIndex,
+					      det_mon->section.std_t,
+					      quirks);
+            Modes = xf86ModesAdd(Modes, Mode);
+            break;
+        default:
+            break;
+        }
+    }
+
+    /* Add established timings */
+    Mode = DDCModesFromEstablished(scrnIndex, &DDC->timings1, quirks);
+    Modes = xf86ModesAdd(Modes, Mode);
+
+    /* Add standard timings */
+    Mode = DDCModesFromStandardTiming(scrnIndex, DDC->timings2, quirks);
+    Modes = xf86ModesAdd(Modes, Mode);
+
+    if (quirks & DDC_QUIRK_PREFER_LARGE_60)
+    {
+	DisplayModePtr	best = Modes;
+	for (Mode = Modes; Mode; Mode = Mode->next)
+	{
+	    if (Mode == best) continue;
+	    if (Mode->HDisplay * Mode->VDisplay > best->HDisplay * best->VDisplay)
+	    {
+		best = Mode;
+		continue;
+	    }
+	    if (Mode->HDisplay * Mode->VDisplay == best->HDisplay * best->VDisplay)
+	    {
+		double	mode_refresh = xf86ModeVRefresh (Mode);
+		double	best_refresh = xf86ModeVRefresh (best);
+		double	mode_dist = fabs(mode_refresh - 60.0);
+		double	best_dist = fabs(best_refresh - 60.0);
+		if (mode_dist < best_dist)
+		{
+		    best = Mode;
+		    continue;
+		}
+	    }
+	}
+	if (best)
+	    best->type |= M_T_PREFERRED;
+    }
+    return Modes;
+}
diff --git a/hw/xfree86/modes/xf86Modes.c b/hw/xfree86/modes/xf86Modes.c
new file mode 100644
index 0000000..d126e5e
--- /dev/null
+++ b/hw/xfree86/modes/xf86Modes.c
@@ -0,0 +1,635 @@
+/* -*- c-basic-offset: 4 -*- */
+/* $XdotOrg: xserver/xorg/hw/xfree86/common/xf86Mode.c,v 1.10 2006/03/07 16:00:57 libv Exp $ */
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Mode.c,v 1.69 2003/10/08 14:58:28 dawes Exp $ */
+/*
+ * Copyright (c) 1997-2003 by The XFree86 Project, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Except as contained in this notice, the name of the copyright holder(s)
+ * and author(s) shall not be used in advertising or otherwise to promote
+ * the sale, use or other dealings in this Software without prior written
+ * authorization from the copyright holder(s) and author(s).
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <stddef.h>
+#include <string.h>
+#include <stdio.h>
+
+#include "xf86.h"
+#include "xf86Modes.h"
+#include "xf86Priv.h"
+
+extern XF86ConfigPtr xf86configptr;
+
+/**
+ * @file this file contains symbols from xf86Mode.c and friends that are static
+ * there but we still want to use.  We need to come up with better API here.
+ */
+
+#if XORG_VERSION_CURRENT <= XORG_VERSION_NUMERIC(7,2,99,2,0)
+/**
+ * Calculates the horizontal sync rate of a mode.
+ *
+ * Exact copy of xf86Mode.c's.
+ */
+double
+xf86ModeHSync(DisplayModePtr mode)
+{
+    double hsync = 0.0;
+    
+    if (mode->HSync > 0.0)
+	    hsync = mode->HSync;
+    else if (mode->HTotal > 0)
+	    hsync = (float)mode->Clock / (float)mode->HTotal;
+
+    return hsync;
+}
+
+/**
+ * Calculates the vertical refresh rate of a mode.
+ *
+ * Exact copy of xf86Mode.c's.
+ */
+double
+xf86ModeVRefresh(DisplayModePtr mode)
+{
+    double refresh = 0.0;
+
+    if (mode->VRefresh > 0.0)
+	refresh = mode->VRefresh;
+    else if (mode->HTotal > 0 && mode->VTotal > 0) {
+	refresh = mode->Clock * 1000.0 / mode->HTotal / mode->VTotal;
+	if (mode->Flags & V_INTERLACE)
+	    refresh *= 2.0;
+	if (mode->Flags & V_DBLSCAN)
+	    refresh /= 2.0;
+	if (mode->VScan > 1)
+	    refresh /= (float)(mode->VScan);
+    }
+    return refresh;
+}
+
+/** Sets a default mode name of <width>x<height> on a mode. */
+void
+xf86SetModeDefaultName(DisplayModePtr mode)
+{
+    if (mode->name != NULL)
+	xfree(mode->name);
+
+    mode->name = XNFprintf("%dx%d", mode->HDisplay, mode->VDisplay);
+}
+
+/*
+ * xf86SetModeCrtc
+ *
+ * Initialises the Crtc parameters for a mode.  The initialisation includes
+ * adjustments for interlaced and double scan modes.
+ *
+ * Exact copy of xf86Mode.c's.
+ */
+void
+xf86SetModeCrtc(DisplayModePtr p, int adjustFlags)
+{
+    if ((p == NULL) || ((p->type & M_T_CRTC_C) == M_T_BUILTIN))
+	return;
+
+    p->CrtcHDisplay             = p->HDisplay;
+    p->CrtcHSyncStart           = p->HSyncStart;
+    p->CrtcHSyncEnd             = p->HSyncEnd;
+    p->CrtcHTotal               = p->HTotal;
+    p->CrtcHSkew                = p->HSkew;
+    p->CrtcVDisplay             = p->VDisplay;
+    p->CrtcVSyncStart           = p->VSyncStart;
+    p->CrtcVSyncEnd             = p->VSyncEnd;
+    p->CrtcVTotal               = p->VTotal;
+    if (p->Flags & V_INTERLACE) {
+	if (adjustFlags & INTERLACE_HALVE_V) {
+	    p->CrtcVDisplay         /= 2;
+	    p->CrtcVSyncStart       /= 2;
+	    p->CrtcVSyncEnd         /= 2;
+	    p->CrtcVTotal           /= 2;
+	}
+	/* Force interlaced modes to have an odd VTotal */
+	/* maybe we should only do this when INTERLACE_HALVE_V is set? */
+	p->CrtcVTotal |= 1;
+    }
+
+    if (p->Flags & V_DBLSCAN) {
+        p->CrtcVDisplay         *= 2;
+        p->CrtcVSyncStart       *= 2;
+        p->CrtcVSyncEnd         *= 2;
+        p->CrtcVTotal           *= 2;
+    }
+    if (p->VScan > 1) {
+        p->CrtcVDisplay         *= p->VScan;
+        p->CrtcVSyncStart       *= p->VScan;
+        p->CrtcVSyncEnd         *= p->VScan;
+        p->CrtcVTotal           *= p->VScan;
+    }
+    p->CrtcVBlankStart = min(p->CrtcVSyncStart, p->CrtcVDisplay);
+    p->CrtcVBlankEnd = max(p->CrtcVSyncEnd, p->CrtcVTotal);
+    p->CrtcHBlankStart = min(p->CrtcHSyncStart, p->CrtcHDisplay);
+    p->CrtcHBlankEnd = max(p->CrtcHSyncEnd, p->CrtcHTotal);
+
+    p->CrtcHAdjusted = FALSE;
+    p->CrtcVAdjusted = FALSE;
+}
+
+/**
+ * Allocates and returns a copy of pMode, including pointers within pMode.
+ */
+DisplayModePtr
+xf86DuplicateMode(DisplayModePtr pMode)
+{
+    DisplayModePtr pNew;
+
+    pNew = xnfalloc(sizeof(DisplayModeRec));
+    *pNew = *pMode;
+    pNew->next = NULL;
+    pNew->prev = NULL;
+    if (pNew->name == NULL) {
+	xf86SetModeDefaultName(pMode);
+    } else {
+	pNew->name = xnfstrdup(pMode->name);
+    }
+
+    return pNew;
+}
+
+/**
+ * Duplicates every mode in the given list and returns a pointer to the first
+ * mode.
+ *
+ * \param modeList doubly-linked mode list
+ */
+DisplayModePtr
+xf86DuplicateModes(ScrnInfoPtr pScrn, DisplayModePtr modeList)
+{
+    DisplayModePtr first = NULL, last = NULL;
+    DisplayModePtr mode;
+
+    for (mode = modeList; mode != NULL; mode = mode->next) {
+	DisplayModePtr new;
+
+	new = xf86DuplicateMode(mode);
+
+	/* Insert pNew into modeList */
+	if (last) {
+	    last->next = new;
+	    new->prev = last;
+	} else {
+	    first = new;
+	    new->prev = NULL;
+	}
+	new->next = NULL;
+	last = new;
+    }
+
+    return first;
+}
+
+/**
+ * Returns true if the given modes should program to the same timings.
+ *
+ * This doesn't use Crtc values, as it might be used on ModeRecs without the
+ * Crtc values set.  So, it's assumed that the other numbers are enough.
+ *
+ * This isn't in xf86Modes.c, but it might deserve to be there.
+ */
+Bool
+xf86ModesEqual(DisplayModePtr pMode1, DisplayModePtr pMode2)
+{
+     if (pMode1->Clock == pMode2->Clock &&
+	 pMode1->HDisplay == pMode2->HDisplay &&
+	 pMode1->HSyncStart == pMode2->HSyncStart &&
+	 pMode1->HSyncEnd == pMode2->HSyncEnd &&
+	 pMode1->HTotal == pMode2->HTotal &&
+	 pMode1->HSkew == pMode2->HSkew &&
+	 pMode1->VDisplay == pMode2->VDisplay &&
+	 pMode1->VSyncStart == pMode2->VSyncStart &&
+	 pMode1->VSyncEnd == pMode2->VSyncEnd &&
+	 pMode1->VTotal == pMode2->VTotal &&
+	 pMode1->VScan == pMode2->VScan &&
+	 pMode1->Flags == pMode2->Flags)
+     {
+	return TRUE;
+     } else {
+	return FALSE;
+     }
+}
+
+/* exact copy of xf86Mode.c */
+static void
+add(char **p, char *new)
+{
+    *p = xnfrealloc(*p, strlen(*p) + strlen(new) + 2);
+    strcat(*p, " ");
+    strcat(*p, new);
+}
+
+/**
+ * Print out a modeline.
+ *
+ * Convenient VRefresh printing was added, though, compared to xf86Mode.c
+ */
+void
+xf86PrintModeline(int scrnIndex,DisplayModePtr mode)
+{
+    char tmp[256];
+    char *flags = xnfcalloc(1, 1);
+
+    if (mode->HSkew) { 
+	snprintf(tmp, 256, "hskew %i", mode->HSkew); 
+	add(&flags, tmp);
+    }
+    if (mode->VScan) { 
+	snprintf(tmp, 256, "vscan %i", mode->VScan); 
+	add(&flags, tmp);
+    }
+    if (mode->Flags & V_INTERLACE) add(&flags, "interlace");
+    if (mode->Flags & V_CSYNC) add(&flags, "composite");
+    if (mode->Flags & V_DBLSCAN) add(&flags, "doublescan");
+    if (mode->Flags & V_BCAST) add(&flags, "bcast");
+    if (mode->Flags & V_PHSYNC) add(&flags, "+hsync");
+    if (mode->Flags & V_NHSYNC) add(&flags, "-hsync");
+    if (mode->Flags & V_PVSYNC) add(&flags, "+vsync");
+    if (mode->Flags & V_NVSYNC) add(&flags, "-vsync");
+    if (mode->Flags & V_PCSYNC) add(&flags, "+csync");
+    if (mode->Flags & V_NCSYNC) add(&flags, "-csync");
+#if 0
+    if (mode->Flags & V_CLKDIV2) add(&flags, "vclk/2");
+#endif
+    xf86DrvMsg(scrnIndex, X_INFO,
+		   "Modeline \"%s\"x%.01f  %6.2f  %i %i %i %i  %i %i %i %i%s "
+		   "(%.01f kHz)\n",
+		   mode->name, mode->VRefresh, mode->Clock/1000., mode->HDisplay,
+		   mode->HSyncStart, mode->HSyncEnd, mode->HTotal,
+		   mode->VDisplay, mode->VSyncStart, mode->VSyncEnd,
+		   mode->VTotal, flags, xf86ModeHSync(mode));
+    xfree(flags);
+}
+#endif /* XORG_VERSION_CURRENT <= 7.2.99.2 */
+
+/**
+ * Marks as bad any modes with unsupported flags.
+ *
+ * \param modeList doubly-linked or circular list of modes.
+ * \param flags flags supported by the driver.
+ *
+ * \bug only V_INTERLACE and V_DBLSCAN are supported.  Is that enough?
+ *
+ * This is not in xf86Modes.c, but would be part of the proposed new API.
+ */
+void
+xf86ValidateModesFlags(ScrnInfoPtr pScrn, DisplayModePtr modeList,
+			    int flags)
+{
+    DisplayModePtr mode;
+
+    for (mode = modeList; mode != NULL; mode = mode->next) {
+	if (mode->Flags & V_INTERLACE && !(flags & V_INTERLACE))
+	    mode->status = MODE_NO_INTERLACE;
+	if (mode->Flags & V_DBLSCAN && !(flags & V_DBLSCAN))
+	    mode->status = MODE_NO_DBLESCAN;
+    }
+}
+
+/**
+ * Marks as bad any modes extending beyond the given max X, Y, or pitch.
+ *
+ * \param modeList doubly-linked or circular list of modes.
+ *
+ * This is not in xf86Modes.c, but would be part of the proposed new API.
+ */
+void
+xf86ValidateModesSize(ScrnInfoPtr pScrn, DisplayModePtr modeList,
+			  int maxX, int maxY, int maxPitch)
+{
+    DisplayModePtr mode;
+
+    for (mode = modeList; mode != NULL; mode = mode->next) {
+	if (maxPitch > 0 && mode->HDisplay > maxPitch)
+	    mode->status = MODE_BAD_WIDTH;
+
+	if (maxX > 0 && mode->HDisplay > maxX)
+	    mode->status = MODE_VIRTUAL_X;
+
+	if (maxY > 0 && mode->VDisplay > maxY)
+	    mode->status = MODE_VIRTUAL_Y;
+
+	if (mode->next == modeList)
+	    break;
+    }
+}
+
+/**
+ * Marks as bad any modes that aren't supported by the given monitor's
+ * hsync and vrefresh ranges.
+ *
+ * \param modeList doubly-linked or circular list of modes.
+ *
+ * This is not in xf86Modes.c, but would be part of the proposed new API.
+ */
+void
+xf86ValidateModesSync(ScrnInfoPtr pScrn, DisplayModePtr modeList,
+			  MonPtr mon)
+{
+    DisplayModePtr mode;
+
+    for (mode = modeList; mode != NULL; mode = mode->next) {
+	Bool bad;
+	int i;
+
+	bad = TRUE;
+	for (i = 0; i < mon->nHsync; i++) {
+	    if (xf86ModeHSync(mode) >= mon->hsync[i].lo &&
+		xf86ModeHSync(mode) <= mon->hsync[i].hi)
+	    {
+		bad = FALSE;
+	    }
+	}
+	if (bad)
+	    mode->status = MODE_HSYNC;
+
+	bad = TRUE;
+	for (i = 0; i < mon->nVrefresh; i++) {
+	    if (xf86ModeVRefresh(mode) >= mon->vrefresh[i].lo &&
+		xf86ModeVRefresh(mode) <= mon->vrefresh[i].hi)
+	    {
+		bad = FALSE;
+	    }
+	}
+	if (bad)
+	    mode->status = MODE_VSYNC;
+
+	if (mode->next == modeList)
+	    break;
+    }
+}
+
+/**
+ * Marks as bad any modes extending beyond outside of the given clock ranges.
+ *
+ * \param modeList doubly-linked or circular list of modes.
+ * \param min pointer to minimums of clock ranges
+ * \param max pointer to maximums of clock ranges
+ * \param n_ranges number of ranges.
+ *
+ * This is not in xf86Modes.c, but would be part of the proposed new API.
+ */
+void
+xf86ValidateModesClocks(ScrnInfoPtr pScrn, DisplayModePtr modeList,
+			    int *min, int *max, int n_ranges)
+{
+    DisplayModePtr mode;
+    int i;
+
+    for (mode = modeList; mode != NULL; mode = mode->next) {
+	Bool good = FALSE;
+	for (i = 0; i < n_ranges; i++) {
+	    if (mode->Clock >= min[i] && mode->Clock <= max[i]) {
+		good = TRUE;
+		break;
+	    }
+	}
+	if (!good)
+	    mode->status = MODE_CLOCK_RANGE;
+    }
+}
+
+/**
+ * If the user has specified a set of mode names to use, mark as bad any modes
+ * not listed.
+ *
+ * The user mode names specified are prefixes to names of modes, so "1024x768"
+ * will match modes named "1024x768", "1024x768x75", "1024x768-good", but
+ * "1024x768x75" would only match "1024x768x75" from that list.
+ *
+ * MODE_BAD is used as the rejection flag, for lack of a better flag.
+ *
+ * \param modeList doubly-linked or circular list of modes.
+ *
+ * This is not in xf86Modes.c, but would be part of the proposed new API.
+ */
+void
+xf86ValidateModesUserConfig(ScrnInfoPtr pScrn, DisplayModePtr modeList)
+{
+    DisplayModePtr mode;
+
+    if (pScrn->display->modes[0] == NULL)
+	return;
+
+    for (mode = modeList; mode != NULL; mode = mode->next) {
+	int i;
+	Bool good = FALSE;
+
+	for (i = 0; pScrn->display->modes[i] != NULL; i++) {
+	    if (strncmp(pScrn->display->modes[i], mode->name,
+			strlen(pScrn->display->modes[i])) == 0) {
+		good = TRUE;
+		break;
+	    }
+	}
+	if (!good)
+	    mode->status = MODE_BAD;
+    }
+}
+
+
+/**
+ * Frees any modes from the list with a status other than MODE_OK.
+ *
+ * \param modeList pointer to a doubly-linked or circular list of modes.
+ * \param verbose determines whether the reason for mode invalidation is
+ *	  printed.
+ *
+ * This is not in xf86Modes.c, but would be part of the proposed new API.
+ */
+void
+xf86PruneInvalidModes(ScrnInfoPtr pScrn, DisplayModePtr *modeList,
+			  Bool verbose)
+{
+    DisplayModePtr mode;
+
+    for (mode = *modeList; mode != NULL;) {
+	DisplayModePtr next = mode->next, first = *modeList;
+
+	if (mode->status != MODE_OK) {
+	    if (verbose) {
+		char *type = "";
+		if (mode->type & M_T_BUILTIN)
+		    type = "built-in ";
+		else if (mode->type & M_T_DEFAULT)
+		    type = "default ";
+		xf86DrvMsg(pScrn->scrnIndex, X_INFO,
+			   "Not using %smode \"%s\" (%s)\n", type, mode->name,
+			   xf86ModeStatusToString(mode->status));
+	    }
+	    xf86DeleteMode(modeList, mode);
+	}
+
+	if (next == first)
+	    break;
+	mode = next;
+    }
+}
+
+/**
+ * Adds the new mode into the mode list, and returns the new list
+ *
+ * \param modes doubly-linked mode list.
+ */
+DisplayModePtr
+xf86ModesAdd(DisplayModePtr modes, DisplayModePtr new)
+{
+    if (modes == NULL)
+	return new;
+
+    if (new) {
+	DisplayModePtr mode = modes;
+
+	while (mode->next)
+	    mode = mode->next;
+
+	mode->next = new;
+	new->prev = mode;
+    }
+
+    return modes;
+}
+
+/**
+ * Build a mode list from a list of config file modes
+ */
+static DisplayModePtr
+xf86GetConfigModes (XF86ConfModeLinePtr conf_mode)
+{
+    DisplayModePtr  head = NULL, prev = NULL, mode;
+    
+    for (; conf_mode; conf_mode = (XF86ConfModeLinePtr) conf_mode->list.next)
+    {
+        mode = xcalloc(1, sizeof(DisplayModeRec));
+	if (!mode)
+	    continue;
+        mode->name       = xstrdup(conf_mode->ml_identifier);
+	if (!mode->name)
+	{
+	    xfree (mode);
+	    continue;
+	}
+	mode->type       = 0;
+        mode->Clock      = conf_mode->ml_clock;
+        mode->HDisplay   = conf_mode->ml_hdisplay;
+        mode->HSyncStart = conf_mode->ml_hsyncstart;
+        mode->HSyncEnd   = conf_mode->ml_hsyncend;
+        mode->HTotal     = conf_mode->ml_htotal;
+        mode->VDisplay   = conf_mode->ml_vdisplay;
+        mode->VSyncStart = conf_mode->ml_vsyncstart;
+        mode->VSyncEnd   = conf_mode->ml_vsyncend;
+        mode->VTotal     = conf_mode->ml_vtotal;
+        mode->Flags      = conf_mode->ml_flags;
+        mode->HSkew      = conf_mode->ml_hskew;
+        mode->VScan      = conf_mode->ml_vscan;
+
+        mode->prev = prev;
+	mode->next = NULL;
+	if (prev)
+	    prev->next = mode;
+	else
+	    head = mode;
+	prev = mode;
+    }
+    return head;
+}
+
+/**
+ * Build a mode list from a monitor configuration
+ */
+DisplayModePtr
+xf86GetMonitorModes (ScrnInfoPtr pScrn, XF86ConfMonitorPtr conf_monitor)
+{
+    DisplayModePtr	    modes = NULL;
+    XF86ConfModesLinkPtr    modes_link;
+    
+    if (!conf_monitor)
+	return NULL;
+
+    /*
+     * first we collect the mode lines from the UseModes directive
+     */
+    for (modes_link = conf_monitor->mon_modes_sect_lst; 
+	 modes_link; 
+	 modes_link = modes_link->list.next)
+    {
+	/* If this modes link hasn't been resolved, go look it up now */
+	if (!modes_link->ml_modes)
+	    modes_link->ml_modes = xf86findModes (modes_link->ml_modes_str, 
+						  xf86configptr->conf_modes_lst);
+	if (modes_link->ml_modes)
+	    modes = xf86ModesAdd (modes,
+				  xf86GetConfigModes (modes_link->ml_modes->mon_modeline_lst));
+    }
+
+    return xf86ModesAdd (modes,
+			 xf86GetConfigModes (conf_monitor->mon_modeline_lst));
+}
+
+/**
+ * Build a mode list containing all of the default modes
+ */
+DisplayModePtr
+xf86GetDefaultModes (Bool interlaceAllowed, Bool doubleScanAllowed)
+{
+    DisplayModePtr  head = NULL, prev = NULL, mode;
+    int		    i;
+
+    for (i = 0; xf86DefaultModes[i].name != NULL; i++)
+    {
+	DisplayModePtr	defMode = &xf86DefaultModes[i];
+	
+	if (!interlaceAllowed && (defMode->Flags & V_INTERLACE))
+	    continue;
+	if (!doubleScanAllowed && (defMode->Flags & V_DBLSCAN))
+	    continue;
+
+	mode = xalloc(sizeof(DisplayModeRec));
+	if (!mode)
+	    continue;
+        memcpy(mode,&xf86DefaultModes[i],sizeof(DisplayModeRec));
+        mode->name = xstrdup(xf86DefaultModes[i].name);
+        if (!mode->name)
+	{
+	    xfree (mode);
+	    continue;
+	}
+        mode->prev = prev;
+	mode->next = NULL;
+	if (prev)
+	    prev->next = mode;
+	else
+	    head = mode;
+	prev = mode;
+    }
+    return head;
+}
diff --git a/hw/xfree86/modes/xf86Modes.h b/hw/xfree86/modes/xf86Modes.h
new file mode 100644
index 0000000..60e2790
--- /dev/null
+++ b/hw/xfree86/modes/xf86Modes.h
@@ -0,0 +1,85 @@
+/*
+ * Copyright © 2006 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Authors:
+ *    Eric Anholt <eric at anholt.net>
+ *
+ */
+
+#ifndef _I830_XF86MODES_H_
+#define _I830_XF86MODES_H_
+#include "xorgVersion.h"
+#include "xf86Parser.h"
+#include "edid.h"
+#if XF86_MODES_RENAME
+#include "xf86Rename.h"
+#endif
+
+double xf86ModeHSync(DisplayModePtr mode);
+double xf86ModeVRefresh(DisplayModePtr mode);
+DisplayModePtr xf86DuplicateMode(DisplayModePtr pMode);
+DisplayModePtr xf86DuplicateModes(ScrnInfoPtr pScrn,
+				       DisplayModePtr modeList);
+void xf86SetModeDefaultName(DisplayModePtr mode);
+void xf86SetModeCrtc(DisplayModePtr p, int adjustFlags);
+Bool xf86ModesEqual(DisplayModePtr pMode1, DisplayModePtr pMode2);
+void xf86PrintModeline(int scrnIndex,DisplayModePtr mode);
+DisplayModePtr xf86ModesAdd(DisplayModePtr modes, DisplayModePtr new);
+
+DisplayModePtr xf86DDCGetModes(int scrnIndex, xf86MonPtr DDC);
+DisplayModePtr xf86CVTMode(int HDisplay, int VDisplay, float VRefresh,
+			   Bool Reduced, Bool Interlaced);
+
+void
+xf86ValidateModesFlags(ScrnInfoPtr pScrn, DisplayModePtr modeList,
+		       int flags);
+
+void
+xf86ValidateModesClocks(ScrnInfoPtr pScrn, DisplayModePtr modeList,
+			int *min, int *max, int n_ranges);
+
+void
+xf86ValidateModesSize(ScrnInfoPtr pScrn, DisplayModePtr modeList,
+		      int maxX, int maxY, int maxPitch);
+
+void
+xf86ValidateModesSync(ScrnInfoPtr pScrn, DisplayModePtr modeList,
+		      MonPtr mon);
+
+void
+xf86PruneInvalidModes(ScrnInfoPtr pScrn, DisplayModePtr *modeList,
+		      Bool verbose);
+
+void
+xf86ValidateModesFlags(ScrnInfoPtr pScrn, DisplayModePtr modeList,
+		       int flags);
+
+void
+xf86ValidateModesUserConfig(ScrnInfoPtr pScrn, DisplayModePtr modeList);
+
+DisplayModePtr
+xf86GetMonitorModes (ScrnInfoPtr pScrn, XF86ConfMonitorPtr conf_monitor);
+
+DisplayModePtr
+xf86GetDefaultModes (Bool interlaceAllowed, Bool doubleScanAllowed);
+
+#endif /* _I830_XF86MODES_H_ */
diff --git a/hw/xfree86/modes/xf86RandR12.c b/hw/xfree86/modes/xf86RandR12.c
new file mode 100644
index 0000000..bafe71f
--- /dev/null
+++ b/hw/xfree86/modes/xf86RandR12.c
@@ -0,0 +1,950 @@
+/* $XdotOrg: xc/programs/Xserver/hw/xfree86/common/xf86RandR.c,v 1.3 2004/07/30 21:53:09 eich Exp $ */
+/*
+ * $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86RandR.c,v 1.7tsi Exp $
+ *
+ * Copyright © 2002 Keith Packard, member of The XFree86 Project, Inc.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission.  The copyright holders make no representations
+ * about the suitability of this software for any purpose.  It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include "xf86.h"
+#include "os.h"
+#include "mibank.h"
+#include "globals.h"
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86DDC.h"
+#include "mipointer.h"
+#include "windowstr.h"
+#include <randrstr.h>
+#include <X11/extensions/render.h>
+
+#include "xf86Crtc.h"
+#include "xf86RandR12.h"
+
+typedef struct _xf86RandR12Info {
+    int				    virtualX;
+    int				    virtualY;
+    int				    mmWidth;
+    int				    mmHeight;
+    int				    maxX;
+    int				    maxY;
+    Rotation			    rotation; /* current mode */
+    Rotation                        supported_rotations; /* driver supported */
+} XF86RandRInfoRec, *XF86RandRInfoPtr;
+
+#ifdef RANDR_12_INTERFACE
+static Bool xf86RandR12Init12 (ScreenPtr pScreen);
+static Bool xf86RandR12CreateScreenResources12 (ScreenPtr pScreen);
+#endif
+
+static int	    xf86RandR12Index;
+static int	    xf86RandR12Generation;
+
+#define XF86RANDRINFO(p) \
+	((XF86RandRInfoPtr)(p)->devPrivates[xf86RandR12Index].ptr)
+
+static int
+xf86RandR12ModeRefresh (DisplayModePtr mode)
+{
+    if (mode->VRefresh)
+	return (int) (mode->VRefresh + 0.5);
+    else
+	return (int) (mode->Clock * 1000.0 / mode->HTotal / mode->VTotal + 0.5);
+}
+
+static Bool
+xf86RandR12GetInfo (ScreenPtr pScreen, Rotation *rotations)
+{
+    RRScreenSizePtr	    pSize;
+    ScrnInfoPtr		    scrp = XF86SCRNINFO(pScreen);
+    XF86RandRInfoPtr	    randrp = XF86RANDRINFO(pScreen);
+    DisplayModePtr	    mode;
+    int			    refresh0 = 60;
+    int			    maxX = 0, maxY = 0;
+
+    *rotations = randrp->supported_rotations;
+
+    if (randrp->virtualX == -1 || randrp->virtualY == -1)
+    {
+	randrp->virtualX = scrp->virtualX;
+	randrp->virtualY = scrp->virtualY;
+    }
+
+    /* Re-probe the outputs for new monitors or modes */
+    xf86ProbeOutputModes (scrp, 0, 0);
+    xf86SetScrnInfoModes (scrp);
+    xf86DiDGAReInit (pScreen);
+
+    for (mode = scrp->modes; ; mode = mode->next)
+    {
+	int refresh = xf86RandR12ModeRefresh (mode);
+	if (randrp->maxX == 0 || randrp->maxY == 0)
+	{
+		if (maxX < mode->HDisplay)
+			maxX = mode->HDisplay;
+		if (maxY < mode->VDisplay)
+			maxY = mode->VDisplay;
+	}
+	if (mode == scrp->modes)
+	    refresh0 = refresh;
+	pSize = RRRegisterSize (pScreen,
+				mode->HDisplay, mode->VDisplay,
+				randrp->mmWidth, randrp->mmHeight);
+	if (!pSize)
+	    return FALSE;
+	RRRegisterRate (pScreen, pSize, refresh);
+
+	if (xf86ModesEqual(mode, scrp->currentMode) &&
+	    mode->HDisplay == scrp->virtualX &&
+	    mode->VDisplay == scrp->virtualY)
+	{
+	    RRSetCurrentConfig (pScreen, randrp->rotation, refresh, pSize);
+	}
+	if (mode->next == scrp->modes)
+	    break;
+    }
+
+    if (randrp->maxX == 0 || randrp->maxY == 0)
+    {
+	randrp->maxX = maxX;
+	randrp->maxY = maxY;
+    }
+
+    if (scrp->currentMode->HDisplay != randrp->virtualX ||
+	scrp->currentMode->VDisplay != randrp->virtualY)
+    {
+	pSize = RRRegisterSize (pScreen,
+				randrp->virtualX, randrp->virtualY,
+				randrp->mmWidth,
+				randrp->mmHeight);
+	if (!pSize)
+	    return FALSE;
+	RRRegisterRate (pScreen, pSize, refresh0);
+	if (scrp->virtualX == randrp->virtualX &&
+	    scrp->virtualY == randrp->virtualY)
+	{
+	    RRSetCurrentConfig (pScreen, randrp->rotation, refresh0, pSize);
+	}
+    }
+
+    return TRUE;
+}
+
+static Bool
+xf86RandR12SetMode (ScreenPtr	    pScreen,
+		  DisplayModePtr    mode,
+		  Bool		    useVirtual,
+		  int		    mmWidth,
+		  int		    mmHeight)
+{
+    ScrnInfoPtr		scrp = XF86SCRNINFO(pScreen);
+    XF86RandRInfoPtr	randrp = XF86RANDRINFO(pScreen);
+    int			oldWidth = pScreen->width;
+    int			oldHeight = pScreen->height;
+    int			oldmmWidth = pScreen->mmWidth;
+    int			oldmmHeight = pScreen->mmHeight;
+    WindowPtr		pRoot = WindowTable[pScreen->myNum];
+    DisplayModePtr      currentMode = NULL;
+    Bool 		ret = TRUE;
+    PixmapPtr 		pspix = NULL;
+
+    if (pRoot)
+	(*scrp->EnableDisableFBAccess) (pScreen->myNum, FALSE);
+    if (useVirtual)
+    {
+	scrp->virtualX = randrp->virtualX;
+	scrp->virtualY = randrp->virtualY;
+    }
+    else
+    {
+	scrp->virtualX = mode->HDisplay;
+	scrp->virtualY = mode->VDisplay;
+    }
+
+    if(randrp->rotation & (RR_Rotate_90 | RR_Rotate_270))
+    {
+	/* If the screen is rotated 90 or 270 degrees, swap the sizes. */
+	pScreen->width = scrp->virtualY;
+	pScreen->height = scrp->virtualX;
+	pScreen->mmWidth = mmHeight;
+	pScreen->mmHeight = mmWidth;
+    }
+    else
+    {
+	pScreen->width = scrp->virtualX;
+	pScreen->height = scrp->virtualY;
+	pScreen->mmWidth = mmWidth;
+	pScreen->mmHeight = mmHeight;
+    }
+    if (scrp->currentMode == mode) {
+        /* Save current mode */
+        currentMode = scrp->currentMode;
+        /* Reset, just so we ensure the drivers SwitchMode is called */
+        scrp->currentMode = NULL;
+    }
+    /*
+     * We know that if the driver failed to SwitchMode to the rotated
+     * version, then it should revert back to it's prior mode.
+     */
+    if (!xf86SwitchMode (pScreen, mode))
+    {
+        ret = FALSE;
+	scrp->virtualX = pScreen->width = oldWidth;
+	scrp->virtualY = pScreen->height = oldHeight;
+	pScreen->mmWidth = oldmmWidth;
+	pScreen->mmHeight = oldmmHeight;
+        scrp->currentMode = currentMode;
+    }
+    /*
+     * Get the new Screen pixmap ptr as SwitchMode might have called
+     * ModifyPixmapHeader and xf86EnableDisableFBAccess will put it back...
+     * Unfortunately.
+     */
+    pspix = (*pScreen->GetScreenPixmap) (pScreen);
+    if (pspix->devPrivate.ptr)
+       scrp->pixmapPrivate = pspix->devPrivate;
+
+    /*
+     * Make sure the layout is correct
+     */
+    xf86ReconfigureLayout();
+
+    /*
+     * Make sure the whole screen is visible
+     */
+    xf86SetViewport (pScreen, pScreen->width, pScreen->height);
+    xf86SetViewport (pScreen, 0, 0);
+    if (pRoot)
+	(*scrp->EnableDisableFBAccess) (pScreen->myNum, TRUE);
+    return ret;
+}
+
+Bool
+xf86RandR12SetConfig (ScreenPtr		pScreen,
+		    Rotation		rotation,
+		    int			rate,
+		    RRScreenSizePtr	pSize)
+{
+    ScrnInfoPtr		scrp = XF86SCRNINFO(pScreen);
+    XF86RandRInfoPtr	randrp = XF86RANDRINFO(pScreen);
+    DisplayModePtr	mode;
+    int			px, py;
+    Bool		useVirtual = FALSE;
+    int			maxX = 0, maxY = 0;
+    Rotation		oldRotation = randrp->rotation;
+
+    randrp->rotation = rotation;
+
+    if (randrp->virtualX == -1 || randrp->virtualY == -1)
+    {
+	randrp->virtualX = scrp->virtualX;
+	randrp->virtualY = scrp->virtualY;
+    }
+
+    miPointerPosition (&px, &py);
+    for (mode = scrp->modes; ; mode = mode->next)
+    {
+	if (randrp->maxX == 0 || randrp->maxY == 0)
+	{
+		if (maxX < mode->HDisplay)
+			maxX = mode->HDisplay;
+		if (maxY < mode->VDisplay)
+			maxY = mode->VDisplay;
+	}
+	if (mode->HDisplay == pSize->width &&
+	    mode->VDisplay == pSize->height &&
+	    (rate == 0 || xf86RandR12ModeRefresh (mode) == rate))
+	    break;
+	if (mode->next == scrp->modes)
+	{
+	    if (pSize->width == randrp->virtualX &&
+		pSize->height == randrp->virtualY)
+	    {
+		mode = scrp->modes;
+		useVirtual = TRUE;
+		break;
+	    }
+    	    if (randrp->maxX == 0 || randrp->maxY == 0)
+    	    {
+		randrp->maxX = maxX;
+		randrp->maxY = maxY;
+    	    }
+	    return FALSE;
+	}
+    }
+
+    if (randrp->maxX == 0 || randrp->maxY == 0)
+    {
+	randrp->maxX = maxX;
+	randrp->maxY = maxY;
+    }
+
+    if (!xf86RandR12SetMode (pScreen, mode, useVirtual, pSize->mmWidth,
+			   pSize->mmHeight)) {
+        randrp->rotation = oldRotation;
+	return FALSE;
+    }
+
+    /*
+     * Move the cursor back where it belongs; SwitchMode repositions it
+     */
+    if (pScreen == miPointerCurrentScreen ())
+    {
+        px = (px >= pScreen->width ? (pScreen->width - 1) : px);
+        py = (py >= pScreen->height ? (pScreen->height - 1) : py);
+
+	xf86SetViewport(pScreen, px, py);
+
+	(*pScreen->SetCursorPosition) (pScreen, px, py, FALSE);
+    }
+
+    return TRUE;
+}
+
+static Bool
+xf86RandR12ScreenSetSize (ScreenPtr	pScreen,
+			CARD16		width,
+			CARD16		height,
+			CARD32		mmWidth,
+			CARD32		mmHeight)
+{
+    XF86RandRInfoPtr	randrp = XF86RANDRINFO(pScreen);
+    ScrnInfoPtr		pScrn = XF86SCRNINFO(pScreen);
+    WindowPtr		pRoot = WindowTable[pScreen->myNum];
+    Bool 		ret = TRUE;
+
+    if (randrp->virtualX == -1 || randrp->virtualY == -1)
+    {
+	randrp->virtualX = pScrn->virtualX;
+	randrp->virtualY = pScrn->virtualY;
+    }
+    if (pRoot)
+	(*pScrn->EnableDisableFBAccess) (pScreen->myNum, FALSE);
+    pScrn->virtualX = width;
+    pScrn->virtualY = height;
+
+    pScreen->width = pScrn->virtualX;
+    pScreen->height = pScrn->virtualY;
+    pScreen->mmWidth = mmWidth;
+    pScreen->mmHeight = mmHeight;
+
+    xf86SetViewport (pScreen, pScreen->width-1, pScreen->height-1);
+    xf86SetViewport (pScreen, 0, 0);
+    if (pRoot)
+	(*pScrn->EnableDisableFBAccess) (pScreen->myNum, TRUE);
+#if RANDR_12_INTERFACE
+    if (WindowTable[pScreen->myNum])
+	RRScreenSizeNotify (pScreen);
+#endif
+    return ret;
+}
+
+Rotation
+xf86RandR12GetRotation(ScreenPtr pScreen)
+{
+    XF86RandRInfoPtr	    randrp = XF86RANDRINFO(pScreen);
+
+    return randrp->rotation;
+}
+
+Bool
+xf86RandR12CreateScreenResources (ScreenPtr pScreen)
+{
+    ScrnInfoPtr		pScrn = xf86Screens[pScreen->myNum];
+    xf86CrtcConfigPtr   config = XF86_CRTC_CONFIG_PTR(pScrn);
+    XF86RandRInfoPtr	randrp = XF86RANDRINFO(pScreen);
+    int			c;
+    int			width, height;
+    int			mmWidth, mmHeight;
+#ifdef PANORAMIX
+    /* XXX disable RandR when using Xinerama */
+    if (!noPanoramiXExtension)
+	return TRUE;
+#endif
+
+    /*
+     * Compute size of screen
+     */
+    width = 0; height = 0;
+    for (c = 0; c < config->num_crtc; c++)
+    {
+	xf86CrtcPtr crtc = config->crtc[c];
+	int	    crtc_width = crtc->x + crtc->mode.HDisplay;
+	int	    crtc_height = crtc->y + crtc->mode.VDisplay;
+	
+	if (crtc->enabled && crtc_width > width)
+	    width = crtc_width;
+	if (crtc->enabled && crtc_height > height)
+	    height = crtc_height;
+    }
+    
+    if (width && height)
+    {
+	/*
+	 * Compute physical size of screen
+	 */
+	if (monitorResolution) 
+	{
+	    mmWidth = width * 25.4 / monitorResolution;
+	    mmHeight = height * 25.4 / monitorResolution;
+	}
+	else
+	{
+	    mmWidth = pScreen->mmWidth;
+	    mmHeight = pScreen->mmHeight;
+	}
+	xf86DrvMsg(pScrn->scrnIndex, X_INFO,
+		   "Setting screen physical size to %d x %d\n",
+		   mmWidth, mmHeight);
+	xf86RandR12ScreenSetSize (pScreen,
+				  width,
+				  height,
+				  mmWidth,
+				  mmHeight);
+    }
+
+    if (randrp->virtualX == -1 || randrp->virtualY == -1)
+    {
+	randrp->virtualX = pScrn->virtualX;
+	randrp->virtualY = pScrn->virtualY;
+    }
+#if RANDR_12_INTERFACE
+    if (xf86RandR12CreateScreenResources12 (pScreen))
+	return TRUE;
+#endif
+    return TRUE;
+}
+
+
+Bool
+xf86RandR12Init (ScreenPtr pScreen)
+{
+    rrScrPrivPtr	rp;
+    XF86RandRInfoPtr	randrp;
+
+#ifdef PANORAMIX
+    /* XXX disable RandR when using Xinerama */
+    if (!noPanoramiXExtension)
+	return TRUE;
+#endif
+    if (xf86RandR12Generation != serverGeneration)
+    {
+	xf86RandR12Index = AllocateScreenPrivateIndex();
+	xf86RandR12Generation = serverGeneration;
+    }
+
+    randrp = xalloc (sizeof (XF86RandRInfoRec));
+    if (!randrp)
+	return FALSE;
+
+    if (!RRScreenInit(pScreen))
+    {
+	xfree (randrp);
+	return FALSE;
+    }
+    rp = rrGetScrPriv(pScreen);
+    rp->rrGetInfo = xf86RandR12GetInfo;
+    rp->rrSetConfig = xf86RandR12SetConfig;
+
+    randrp->virtualX = -1;
+    randrp->virtualY = -1;
+    randrp->mmWidth = pScreen->mmWidth;
+    randrp->mmHeight = pScreen->mmHeight;
+
+    randrp->rotation = RR_Rotate_0; /* initial rotated mode */
+
+    randrp->supported_rotations = RR_Rotate_0;
+
+    randrp->maxX = randrp->maxY = 0;
+
+    pScreen->devPrivates[xf86RandR12Index].ptr = randrp;
+
+#if RANDR_12_INTERFACE
+    if (!xf86RandR12Init12 (pScreen))
+	return FALSE;
+#endif
+    return TRUE;
+}
+
+void
+xf86RandR12SetRotations (ScreenPtr pScreen, Rotation rotations)
+{
+    XF86RandRInfoPtr	randrp = XF86RANDRINFO(pScreen);
+    ScrnInfoPtr		pScrn = xf86Screens[pScreen->myNum];
+    xf86CrtcConfigPtr   config = XF86_CRTC_CONFIG_PTR(pScrn);
+    int			c;
+
+    randrp->supported_rotations = rotations;
+
+#if RANDR_12_INTERFACE
+    for (c = 0; c < config->num_crtc; c++) {
+	xf86CrtcPtr    crtc = config->crtc[c];
+
+	RRCrtcSetRotations (crtc->randr_crtc, rotations);
+    }
+#endif
+}
+
+void
+xf86RandR12GetOriginalVirtualSize(ScrnInfoPtr pScrn, int *x, int *y)
+{
+    ScreenPtr pScreen = screenInfo.screens[pScrn->scrnIndex];
+
+    if (xf86RandR12Generation != serverGeneration ||
+	XF86RANDRINFO(pScreen)->virtualX == -1)
+    {
+	*x = pScrn->virtualX;
+	*y = pScrn->virtualY;
+    } else {
+	XF86RandRInfoPtr randrp = XF86RANDRINFO(pScreen);
+
+	*x = randrp->virtualX;
+	*y = randrp->virtualY;
+    }
+}
+
+#if RANDR_12_INTERFACE
+static Bool
+xf86RandR12CrtcNotify (RRCrtcPtr	randr_crtc)
+{
+    ScreenPtr		pScreen = randr_crtc->pScreen;
+    ScrnInfoPtr		pScrn = xf86Screens[pScreen->myNum];
+    xf86CrtcConfigPtr   config = XF86_CRTC_CONFIG_PTR(pScrn);
+    RRModePtr		randr_mode = NULL;
+    int			x;
+    int			y;
+    Rotation		rotation;
+    int			numOutputs;
+    RROutputPtr		*randr_outputs;
+    RROutputPtr		randr_output;
+    xf86CrtcPtr		crtc = randr_crtc->devPrivate;
+    xf86OutputPtr	output;
+    int			i, j;
+    DisplayModePtr	mode = &crtc->mode;
+    Bool		ret;
+
+    randr_outputs = ALLOCATE_LOCAL(config->num_output * sizeof (RROutputPtr));
+    if (!randr_outputs)
+	return FALSE;
+    x = crtc->x;
+    y = crtc->y;
+    rotation = crtc->rotation;
+    numOutputs = 0;
+    randr_mode = NULL;
+    for (i = 0; i < config->num_output; i++)
+    {
+	output = config->output[i];
+	if (output->crtc == crtc)
+	{
+	    randr_output = output->randr_output;
+	    randr_outputs[numOutputs++] = randr_output;
+	    /*
+	     * We make copies of modes, so pointer equality 
+	     * isn't sufficient
+	     */
+	    for (j = 0; j < randr_output->numModes; j++)
+	    {
+		DisplayModePtr	outMode = randr_output->modes[j]->devPrivate;
+		if (xf86ModesEqual(mode, outMode))
+		{
+		    randr_mode = randr_output->modes[j];
+		    break;
+		}
+	    }
+	}
+    }
+    ret = RRCrtcNotify (randr_crtc, randr_mode, x, y,
+			rotation, numOutputs, randr_outputs);
+    DEALLOCATE_LOCAL(randr_outputs);
+    return ret;
+}
+
+static Bool
+xf86RandR12CrtcSet (ScreenPtr	pScreen,
+		  RRCrtcPtr	randr_crtc,
+		  RRModePtr	randr_mode,
+		  int		x,
+		  int		y,
+		  Rotation	rotation,
+		  int		num_randr_outputs,
+		  RROutputPtr	*randr_outputs)
+{
+    ScrnInfoPtr		pScrn = xf86Screens[pScreen->myNum];
+    xf86CrtcConfigPtr   config = XF86_CRTC_CONFIG_PTR(pScrn);
+    xf86CrtcPtr		crtc = randr_crtc->devPrivate;
+    DisplayModePtr	mode = randr_mode ? randr_mode->devPrivate : NULL;
+    Bool		changed = FALSE;
+    int			o, ro;
+    xf86CrtcPtr		*save_crtcs;
+    Bool		save_enabled = crtc->enabled;
+
+    save_crtcs = ALLOCATE_LOCAL(config->num_crtc * sizeof (xf86CrtcPtr));
+    if ((mode != NULL) != crtc->enabled)
+	changed = TRUE;
+    else if (mode && !xf86ModesEqual (&crtc->mode, mode))
+	changed = TRUE;
+    
+    if (rotation != crtc->rotation)
+	changed = TRUE;
+
+    if (x != crtc->x || y != crtc->y)
+	changed = TRUE;
+    for (o = 0; o < config->num_output; o++) 
+    {
+	xf86OutputPtr  output = config->output[o];
+	xf86CrtcPtr    new_crtc;
+
+	save_crtcs[o] = output->crtc;
+	
+	if (output->crtc == crtc)
+	    new_crtc = NULL;
+	else
+	    new_crtc = output->crtc;
+	for (ro = 0; ro < num_randr_outputs; ro++) 
+	    if (output->randr_output == randr_outputs[ro])
+	    {
+		new_crtc = crtc;
+		break;
+	    }
+	if (new_crtc != output->crtc)
+	{
+	    changed = TRUE;
+	    output->crtc = new_crtc;
+	}
+    }
+    /* XXX need device-independent mode setting code through an API */
+    if (changed)
+    {
+	crtc->enabled = mode != NULL;
+
+	if (mode)
+	{
+	    if (!xf86CrtcSetMode (crtc, mode, rotation, x, y))
+	    {
+		crtc->enabled = save_enabled;
+		for (o = 0; o < config->num_output; o++)
+		{
+		    xf86OutputPtr	output = config->output[o];
+		    output->crtc = save_crtcs[o];
+		}
+		DEALLOCATE_LOCAL(save_crtcs);
+		return FALSE;
+	    }
+	    /*
+	     * Save the last successful setting for EnterVT
+	     */
+	    crtc->desiredMode = *mode;
+	    crtc->desiredRotation = rotation;
+	    crtc->desiredX = x;
+	    crtc->desiredY = y;
+	}
+	xf86DisableUnusedFunctions (pScrn);
+    }
+    DEALLOCATE_LOCAL(save_crtcs);
+    return xf86RandR12CrtcNotify (randr_crtc);
+}
+
+static Bool
+xf86RandR12CrtcSetGamma (ScreenPtr    pScreen,
+			 RRCrtcPtr    randr_crtc)
+{
+    xf86CrtcPtr		crtc = randr_crtc->devPrivate;
+
+    if (crtc->funcs->gamma_set == NULL)
+	return FALSE;
+
+    crtc->funcs->gamma_set(crtc, randr_crtc->gammaRed, randr_crtc->gammaGreen,
+			   randr_crtc->gammaBlue, randr_crtc->gammaSize);
+
+    return TRUE;
+}
+
+static Bool
+xf86RandR12OutputSetProperty (ScreenPtr pScreen,
+			      RROutputPtr randr_output,
+			      Atom property,
+			      RRPropertyValuePtr value)
+{
+    xf86OutputPtr output = randr_output->devPrivate;
+
+    /* If we don't have any property handler, then we don't care what the
+     * user is setting properties to.
+     */
+    if (output->funcs->set_property == NULL)
+	return TRUE;
+
+    return output->funcs->set_property(output, property, value);
+}
+
+/**
+ * Given a list of xf86 modes and a RandR Output object, construct
+ * RandR modes and assign them to the output
+ */
+static Bool
+xf86RROutputSetModes (RROutputPtr randr_output, DisplayModePtr modes)
+{
+    DisplayModePtr  mode;
+    RRModePtr	    *rrmodes = NULL;
+    int		    nmode = 0;
+    int		    npreferred = 0;
+    Bool	    ret = TRUE;
+    int		    pref;
+
+    for (mode = modes; mode; mode = mode->next)
+	nmode++;
+
+    if (nmode) {
+	rrmodes = xalloc (nmode * sizeof (RRModePtr));
+	
+	if (!rrmodes)
+	    return FALSE;
+	nmode = 0;
+
+	for (pref = 1; pref >= 0; pref--) {
+	    for (mode = modes; mode; mode = mode->next) {
+		if ((pref != 0) == ((mode->type & M_T_PREFERRED) != 0)) {
+		    xRRModeInfo		modeInfo;
+		    RRModePtr		rrmode;
+		    
+		    modeInfo.nameLength = strlen (mode->name);
+		    modeInfo.width = mode->HDisplay;
+		    modeInfo.dotClock = mode->Clock * 1000;
+		    modeInfo.hSyncStart = mode->HSyncStart;
+		    modeInfo.hSyncEnd = mode->HSyncEnd;
+		    modeInfo.hTotal = mode->HTotal;
+		    modeInfo.hSkew = mode->HSkew;
+
+		    modeInfo.height = mode->VDisplay;
+		    modeInfo.vSyncStart = mode->VSyncStart;
+		    modeInfo.vSyncEnd = mode->VSyncEnd;
+		    modeInfo.vTotal = mode->VTotal;
+		    modeInfo.modeFlags = mode->Flags;
+
+		    rrmode = RRModeGet (&modeInfo, mode->name);
+		    if (rrmode) {
+			rrmode->devPrivate = mode;
+			rrmodes[nmode++] = rrmode;
+			npreferred += pref;
+		    }
+		}
+	    }
+	}
+    }
+    
+    ret = RROutputSetModes (randr_output, rrmodes, nmode, npreferred);
+    xfree (rrmodes);
+    return ret;
+}
+
+/*
+ * Mirror the current mode configuration to RandR
+ */
+static Bool
+xf86RandR12SetInfo12 (ScreenPtr pScreen)
+{
+    ScrnInfoPtr		pScrn = xf86Screens[pScreen->myNum];
+    xf86CrtcConfigPtr   config = XF86_CRTC_CONFIG_PTR(pScrn);
+    RROutputPtr		*clones;
+    RRCrtcPtr		*crtcs;
+    int			ncrtc;
+    int			o, c, l;
+    RRCrtcPtr		randr_crtc;
+    int			nclone;
+    
+    clones = ALLOCATE_LOCAL(config->num_output * sizeof (RROutputPtr));
+    crtcs = ALLOCATE_LOCAL (config->num_crtc * sizeof (RRCrtcPtr));
+    for (o = 0; o < config->num_output; o++)
+    {
+	xf86OutputPtr	output = config->output[o];
+	
+	ncrtc = 0;
+	for (c = 0; c < config->num_crtc; c++)
+	    if (output->possible_crtcs & (1 << c))
+		crtcs[ncrtc++] = config->crtc[c]->randr_crtc;
+
+	if (output->crtc)
+	    randr_crtc = output->crtc->randr_crtc;
+	else
+	    randr_crtc = NULL;
+
+	if (!RROutputSetCrtcs (output->randr_output, crtcs, ncrtc))
+	{
+	    DEALLOCATE_LOCAL (crtcs);
+	    DEALLOCATE_LOCAL (clones);
+	    return FALSE;
+	}
+
+	RROutputSetCrtc (output->randr_output, randr_crtc);
+	RROutputSetPhysicalSize(output->randr_output, 
+				output->mm_width,
+				output->mm_height);
+	xf86RROutputSetModes (output->randr_output, output->probed_modes);
+
+	switch (output->status) {
+	case XF86OutputStatusConnected:
+	    RROutputSetConnection (output->randr_output, RR_Connected);
+	    break;
+	case XF86OutputStatusDisconnected:
+	    RROutputSetConnection (output->randr_output, RR_Disconnected);
+	    break;
+	case XF86OutputStatusUnknown:
+	    RROutputSetConnection (output->randr_output, RR_UnknownConnection);
+	    break;
+	}
+
+	RROutputSetSubpixelOrder (output->randr_output, output->subpixel_order);
+
+	/*
+	 * Valid clones
+	 */
+	nclone = 0;
+	for (l = 0; l < config->num_output; l++)
+	{
+	    xf86OutputPtr	    clone = config->output[l];
+	    
+	    if (l != o && (output->possible_clones & (1 << l)))
+		clones[nclone++] = clone->randr_output;
+	}
+	if (!RROutputSetClones (output->randr_output, clones, nclone))
+	{
+	    DEALLOCATE_LOCAL (crtcs);
+	    DEALLOCATE_LOCAL (clones);
+	    return FALSE;
+	}
+    }
+    DEALLOCATE_LOCAL (crtcs);
+    DEALLOCATE_LOCAL (clones);
+    return TRUE;
+}
+
+
+
+/*
+ * Query the hardware for the current state, then mirror
+ * that to RandR
+ */
+static Bool
+xf86RandR12GetInfo12 (ScreenPtr pScreen, Rotation *rotations)
+{
+    ScrnInfoPtr		pScrn = xf86Screens[pScreen->myNum];
+
+    xf86ProbeOutputModes (pScrn, 0, 0);
+    xf86SetScrnInfoModes (pScrn);
+    xf86DiDGAReInit (pScreen);
+    return xf86RandR12SetInfo12 (pScreen);
+}
+
+static Bool
+xf86RandR12CreateObjects12 (ScreenPtr pScreen)
+{
+    ScrnInfoPtr		pScrn = xf86Screens[pScreen->myNum];
+    xf86CrtcConfigPtr   config = XF86_CRTC_CONFIG_PTR(pScrn);
+    int			c;
+    int			o;
+    
+    if (!RRInit ())
+	return FALSE;
+
+    /*
+     * Configure crtcs
+     */
+    for (c = 0; c < config->num_crtc; c++)
+    {
+	xf86CrtcPtr    crtc = config->crtc[c];
+	
+	crtc->randr_crtc = RRCrtcCreate (crtc);
+	RRCrtcAttachScreen (crtc->randr_crtc, pScreen);
+	RRCrtcGammaSetSize (crtc->randr_crtc, 256);
+    }
+    /*
+     * Configure outputs
+     */
+    for (o = 0; o < config->num_output; o++)
+    {
+	xf86OutputPtr	output = config->output[o];
+
+	output->randr_output = RROutputCreate (output->name, 
+					       strlen (output->name),
+					       output);
+	RROutputAttachScreen (output->randr_output, pScreen);
+
+	if (output->funcs->create_resources != NULL)
+	    output->funcs->create_resources(output);
+    }
+    return TRUE;
+}
+
+static Bool
+xf86RandR12CreateScreenResources12 (ScreenPtr pScreen)
+{
+    int			c;
+    ScrnInfoPtr		pScrn = xf86Screens[pScreen->myNum];
+    XF86RandRInfoPtr	randrp = XF86RANDRINFO(pScreen);
+    xf86CrtcConfigPtr   config = XF86_CRTC_CONFIG_PTR(pScrn);
+
+    for (c = 0; c < config->num_crtc; c++)
+	xf86RandR12CrtcNotify (config->crtc[c]->randr_crtc);
+    
+    
+    RRScreenSetSizeRange (pScreen, 320, 240,
+			  randrp->virtualX, randrp->virtualY);
+    return TRUE;
+}
+
+static void
+xf86RandR12PointerMoved (int scrnIndex, int x, int y)
+{
+}
+
+static Bool
+xf86RandR12Init12 (ScreenPtr pScreen)
+{
+    ScrnInfoPtr		pScrn = xf86Screens[pScreen->myNum];
+    rrScrPrivPtr	rp = rrGetScrPriv(pScreen);
+
+    rp->rrGetInfo = xf86RandR12GetInfo12;
+    rp->rrScreenSetSize = xf86RandR12ScreenSetSize;
+    rp->rrCrtcSet = xf86RandR12CrtcSet;
+    rp->rrCrtcSetGamma = xf86RandR12CrtcSetGamma;
+    rp->rrOutputSetProperty = xf86RandR12OutputSetProperty;
+    rp->rrSetConfig = NULL;
+    pScrn->PointerMoved = xf86RandR12PointerMoved;
+    if (!xf86RandR12CreateObjects12 (pScreen))
+	return FALSE;
+
+    /*
+     * Configure output modes
+     */
+    if (!xf86RandR12SetInfo12 (pScreen))
+	return FALSE;
+    return TRUE;
+}
+
+#endif
+
+Bool
+xf86RandR12PreInit (ScrnInfoPtr pScrn)
+{
+    return TRUE;
+}
diff --git a/hw/xfree86/modes/xf86RandR12.h b/hw/xfree86/modes/xf86RandR12.h
new file mode 100644
index 0000000..8a4668b
--- /dev/null
+++ b/hw/xfree86/modes/xf86RandR12.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright © 2006 Keith Packard
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission.  The copyright holders make no representations
+ * about the suitability of this software for any purpose.  It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+
+#ifndef _XF86_RANDR_H_
+#define _XF86_RANDR_H_
+#include <randrstr.h>
+#include <X11/extensions/render.h>
+
+Bool xf86RandR12CreateScreenResources (ScreenPtr pScreen);
+Bool xf86RandR12Init(ScreenPtr pScreen);
+void xf86RandR12SetRotations (ScreenPtr pScreen, Rotation rotation);
+Bool xf86RandR12SetConfig(ScreenPtr pScreen, Rotation rotation, int rate,
+			RRScreenSizePtr pSize);
+Rotation xf86RandR12GetRotation(ScreenPtr pScreen);
+void xf86RandR12GetOriginalVirtualSize(ScrnInfoPtr pScrn, int *x, int *y);
+Bool xf86RandR12PreInit (ScrnInfoPtr pScrn);
+
+#endif /* _XF86_RANDR_H_ */
diff --git a/hw/xfree86/modes/xf86Rename.h b/hw/xfree86/modes/xf86Rename.h
new file mode 100644
index 0000000..a00253d
--- /dev/null
+++ b/hw/xfree86/modes/xf86Rename.h
@@ -0,0 +1,77 @@
+/*
+ * Copyright © 2006 Keith Packard
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission.  The copyright holders make no representations
+ * about the suitability of this software for any purpose.  It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+
+#ifndef _XF86RENAME_H_
+#define _XF86RENAME_H_
+
+#include "local_xf86Rename.h"
+
+#define xf86CrtcConfigInit XF86NAME(xf86CrtcConfigInit)
+#define xf86CrtcConfigPrivateIndex XF86NAME(xf86CrtcConfigPrivateIndex)
+#define xf86CrtcCreate XF86NAME(xf86CrtcCreate)
+#define xf86CrtcDestroy XF86NAME(xf86CrtcDestroy)
+#define xf86CrtcInUse XF86NAME(xf86CrtcInUse)
+#define xf86CrtcRotate XF86NAME(xf86CrtcRotate)
+#define xf86CrtcSetMode XF86NAME(xf86CrtcSetMode)
+#define xf86CrtcSetSizeRange XF86NAME(xf86CrtcSetSizeRange)
+#define xf86CVTMode XF86NAME(xf86CVTMode)
+#define xf86DisableUnusedFunctions XF86NAME(xf86DisableUnusedFunctions)
+#define xf86DPMSSet XF86NAME(xf86DPMSSet)
+#define xf86DuplicateMode XF86NAME(xf86DuplicateMode)
+#define xf86DuplicateModes XF86NAME(xf86DuplicateModes)
+#define xf86GetDefaultModes XF86NAME(xf86GetDefaultModes)
+#define xf86GetMonitorModes XF86NAME(xf86GetMonitorModes)
+#define xf86InitialConfiguration XF86NAME(xf86InitialConfiguration)
+#define xf86ModeHSync XF86NAME(xf86ModeHSync)
+#define xf86ModesAdd XF86NAME(xf86ModesAdd)
+#define xf86ModesEqual XF86NAME(xf86ModesEqual)
+#define xf86ModeVRefresh XF86NAME(xf86ModeVRefresh)
+#define xf86OutputCreate XF86NAME(xf86OutputCreate)
+#define xf86OutputDestroy XF86NAME(xf86OutputDestroy)
+#define xf86OutputGetEDID XF86NAME(xf86OutputGetEDID)
+#define xf86OutputGetEDIDModes XF86NAME(xf86OutputGetEDIDModes)
+#define xf86OutputRename XF86NAME(xf86OutputRename)
+#define xf86OutputSetEDID XF86NAME(xf86OutputSetEDID)
+#define xf86PrintModeline XF86NAME(xf86PrintModeline)
+#define xf86ProbeOutputModes XF86NAME(xf86ProbeOutputModes)
+#define xf86PruneInvalidModes XF86NAME(xf86PruneInvalidModes)
+#define xf86SetModeCrtc XF86NAME(xf86SetModeCrtc)
+#define xf86SetModeDefaultName XF86NAME(xf86SetModeDefaultName)
+#define xf86SetScrnInfoModes XF86NAME(xf86SetScrnInfoModes)
+#define xf86ValidateModesClocks XF86NAME(xf86ValidateModesClocks)
+#define xf86ValidateModesFlags XF86NAME(xf86ValidateModesFlags)
+#define xf86ValidateModesSize XF86NAME(xf86ValidateModesSize)
+#define xf86ValidateModesSync XF86NAME(xf86ValidateModesSync)
+#define xf86ValidateModesUserConfig XF86NAME(xf86ValidateModesUserConfig)
+#define xf86DiDGAInit XF86NAME(xf86DiDGAInit)
+#define xf86DiDGAReInit XF86NAME(xf86DiDGAReInit)
+#define xf86DDCGetModes XF86NAME(xf86DDCGetModes)
+#define xf86RandR12CreateScreenResources XF86NAME(xf86RandR12CreateScreenResources)
+#define xf86RandR12GetOriginalVirtualSize XF86NAME(xf86RandR12GetOriginalVirtualSize)
+#define xf86RandR12GetRotation XF86NAME(xf86RandR12GetRotation)
+#define xf86RandR12Init XF86NAME(xf86RandR12Init)
+#define xf86RandR12PreInit XF86NAME(xf86RandR12PreInit)
+#define xf86RandR12SetConfig XF86NAME(xf86RandR12SetConfig)
+#define xf86RandR12SetRotations XF86NAME(xf86RandR12SetRotations)
+#define xf86SaveScreen XF86NAME(xf86SaveScreen)
+
+#endif /* _XF86RENAME_H_ */
diff --git a/hw/xfree86/modes/xf86Rotate.c b/hw/xfree86/modes/xf86Rotate.c
new file mode 100644
index 0000000..1e79063
--- /dev/null
+++ b/hw/xfree86/modes/xf86Rotate.c
@@ -0,0 +1,402 @@
+/*
+ * Copyright © 2006 Keith Packard
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission.  The copyright holders make no representations
+ * about the suitability of this software for any purpose.  It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <stddef.h>
+#include <string.h>
+#include <stdio.h>
+
+#include "xf86.h"
+#include "xf86DDC.h"
+#include "fb.h"
+#include "windowstr.h"
+#include "xf86Crtc.h"
+#include "xf86Modes.h"
+#include "xf86RandR12.h"
+#include "X11/extensions/render.h"
+#define DPMS_SERVER
+#include "X11/extensions/dpms.h"
+#include "X11/Xatom.h"
+
+static int
+mode_height (DisplayModePtr mode, Rotation rotation)
+{
+    switch (rotation & 0xf) {
+    case RR_Rotate_0:
+    case RR_Rotate_180:
+	return mode->VDisplay;
+    case RR_Rotate_90:
+    case RR_Rotate_270:
+	return mode->HDisplay;
+    default:
+	return 0;
+    }
+}
+
+static int
+mode_width (DisplayModePtr mode, Rotation rotation)
+{
+    switch (rotation & 0xf) {
+    case RR_Rotate_0:
+    case RR_Rotate_180:
+	return mode->HDisplay;
+    case RR_Rotate_90:
+    case RR_Rotate_270:
+	return mode->VDisplay;
+    default:
+	return 0;
+    }
+}
+
+/* borrowed from composite extension, move to Render and publish? */
+
+static VisualPtr
+compGetWindowVisual (WindowPtr pWin)
+{
+    ScreenPtr	    pScreen = pWin->drawable.pScreen;
+    VisualID	    vid = wVisual (pWin);
+    int		    i;
+
+    for (i = 0; i < pScreen->numVisuals; i++)
+	if (pScreen->visuals[i].vid == vid)
+	    return &pScreen->visuals[i];
+    return 0;
+}
+
+static PictFormatPtr
+compWindowFormat (WindowPtr pWin)
+{
+    ScreenPtr	pScreen = pWin->drawable.pScreen;
+    
+    return PictureMatchVisual (pScreen, pWin->drawable.depth,
+			       compGetWindowVisual (pWin));
+}
+
+static void
+xf86RotateBox (BoxPtr dst, BoxPtr src, Rotation rotation,
+	       int dest_width, int dest_height)
+{
+    switch (rotation & 0xf) {
+    default:
+    case RR_Rotate_0:
+	*dst = *src;
+	break;
+    case RR_Rotate_90:
+	dst->x1 = src->y1;
+	dst->y1 = dest_height - src->x2;
+	dst->x2 = src->y2;
+	dst->y2 = dest_height - src->x1;
+	break;
+    case RR_Rotate_180:
+	dst->x1 = dest_width - src->x2;
+	dst->y1 = dest_height - src->y2;
+	dst->x2 = dest_width - src->x1;
+	dst->y2 = dest_height - src->y1;
+	break;
+    case RR_Rotate_270:
+	dst->x1 = dest_width - src->y2;
+	dst->y1 = src->x1;
+	dst->y2 = src->x2;
+	dst->x2 = dest_width - src->y1;
+	break;
+    }
+    if (rotation & RR_Reflect_X) {
+	int x1 = dst->x1;
+	dst->x1 = dest_width - dst->x2;
+	dst->x2 = dest_width - x1;
+    }
+    if (rotation & RR_Reflect_Y) {
+	int y1 = dst->y1;
+	dst->y1 = dest_height - dst->y2;
+	dst->y2 = dest_height - y1;
+    }
+}
+
+static void
+xf86RotateCrtcRedisplay (xf86CrtcPtr crtc, RegionPtr region)
+{
+    ScrnInfoPtr		scrn = crtc->scrn;
+    ScreenPtr		screen = scrn->pScreen;
+    WindowPtr		root = WindowTable[screen->myNum];
+    PixmapPtr		dst_pixmap = crtc->rotatedPixmap;
+    PictFormatPtr	format = compWindowFormat (WindowTable[screen->myNum]);
+    int			error;
+    PicturePtr		src, dst;
+    PictTransform	transform;
+    int			n = REGION_NUM_RECTS(region);
+    BoxPtr		b = REGION_RECTS(region);
+    XID			include_inferiors = IncludeInferiors;
+    
+    src = CreatePicture (None,
+			 &root->drawable,
+			 format,
+			 CPSubwindowMode,
+			 &include_inferiors,
+			 serverClient,
+			 &error);
+    if (!src) {
+	ErrorF("couldn't create src pict\n");
+	return;
+    }
+    dst = CreatePicture (None,
+			 &dst_pixmap->drawable,
+			 format,
+			 0L,
+			 NULL,
+			 serverClient,
+			 &error);
+    if (!dst) {
+	ErrorF("couldn't create src pict\n");
+	return;
+    }
+
+    memset (&transform, '\0', sizeof (transform));
+    transform.matrix[2][2] = IntToxFixed(1);
+    transform.matrix[0][2] = IntToxFixed(crtc->x);
+    transform.matrix[1][2] = IntToxFixed(crtc->y);
+    switch (crtc->rotation & 0xf) {
+    default:
+    case RR_Rotate_0:
+	transform.matrix[0][0] = IntToxFixed(1);
+	transform.matrix[1][1] = IntToxFixed(1);
+	break;
+    case RR_Rotate_90:
+	transform.matrix[0][1] = IntToxFixed(-1);
+	transform.matrix[1][0] = IntToxFixed(1);
+	transform.matrix[0][2] += IntToxFixed(crtc->mode.VDisplay);
+	break;
+    case RR_Rotate_180:
+	transform.matrix[0][0] = IntToxFixed(-1);
+	transform.matrix[1][1] = IntToxFixed(-1);
+	transform.matrix[0][2] += IntToxFixed(crtc->mode.HDisplay);
+	transform.matrix[1][2] += IntToxFixed(crtc->mode.VDisplay);
+	break;
+    case RR_Rotate_270:
+	transform.matrix[0][1] = IntToxFixed(1);
+	transform.matrix[1][0] = IntToxFixed(-1);
+	transform.matrix[1][2] += IntToxFixed(crtc->mode.HDisplay);
+	break;
+    }
+
+    /* handle reflection */
+    if (crtc->rotation & RR_Reflect_X)
+    {
+	/* XXX figure this out */
+    }
+    if (crtc->rotation & RR_Reflect_Y)
+    {
+	/* XXX figure this out too */
+    }
+
+    error = SetPictureTransform (src, &transform);
+    if (error) {
+	ErrorF("Couldn't set transform\n");
+	return;
+    }
+
+    while (n--)
+    {
+	BoxRec	dst_box;
+
+	xf86RotateBox (&dst_box, b, crtc->rotation,
+		       crtc->mode.HDisplay, crtc->mode.VDisplay);
+	CompositePicture (PictOpSrc,
+			  src, NULL, dst,
+			  dst_box.x1, dst_box.y1, 0, 0, dst_box.x1, dst_box.y1,
+			  dst_box.x2 - dst_box.x1,
+			  dst_box.y2 - dst_box.y1);
+	b++;
+    }
+    FreePicture (src, None);
+    FreePicture (dst, None);
+}
+
+static void
+xf86RotateRedisplay(ScreenPtr pScreen)
+{
+    ScrnInfoPtr		pScrn = xf86Screens[pScreen->myNum];
+    xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
+    DamagePtr		damage = xf86_config->rotationDamage;
+    RegionPtr		region;
+
+    if (!damage)
+	return;
+    region = DamageRegion(damage);
+    if (REGION_NOTEMPTY(pScreen, region)) 
+    {
+	int		    c;
+	
+	for (c = 0; c < xf86_config->num_crtc; c++)
+	{
+	    xf86CrtcPtr	    crtc = xf86_config->crtc[c];
+
+	    if (crtc->rotation != RR_Rotate_0)
+	    {
+		BoxRec	    box;
+		RegionRec   crtc_damage;
+
+		/* compute portion of damage that overlaps crtc */
+		box.x1 = crtc->x;
+		box.x2 = crtc->x + mode_width (&crtc->mode, crtc->rotation);
+		box.y1 = crtc->y;
+		box.y2 = crtc->y + mode_height (&crtc->mode, crtc->rotation);
+		REGION_INIT(pScreen, &crtc_damage, &box, 1);
+		REGION_INTERSECT (pScreen, &crtc_damage, &crtc_damage, region);
+		
+		/* update damaged region */
+		if (REGION_NOTEMPTY(pScreen, &crtc_damage))
+    		    xf86RotateCrtcRedisplay (crtc, &crtc_damage);
+		
+		REGION_UNINIT (pScreen, &crtc_damage);
+	    }
+	}
+	DamageEmpty(damage);
+    }
+}
+
+static void
+xf86RotateBlockHandler(pointer data, OSTimePtr pTimeout, pointer pRead)
+{
+    ScreenPtr pScreen = (ScreenPtr) data;
+
+    xf86RotateRedisplay(pScreen);
+}
+
+static void
+xf86RotateWakeupHandler(pointer data, int i, pointer LastSelectMask)
+{
+}
+
+Bool
+xf86CrtcRotate (xf86CrtcPtr crtc, DisplayModePtr mode, Rotation rotation)
+{
+    ScrnInfoPtr		pScrn = crtc->scrn;
+    xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
+    ScreenPtr		pScreen = pScrn->pScreen;
+    
+    if (rotation == RR_Rotate_0)
+    {
+	/* Free memory from rotation */
+	if (crtc->rotatedPixmap)
+	{
+	    crtc->funcs->shadow_destroy (crtc, crtc->rotatedPixmap);
+	    crtc->rotatedPixmap = NULL;
+	}
+
+	if (xf86_config->rotationDamage)
+	{
+	    /* Free damage structure */
+	    DamageUnregister (&(*pScreen->GetScreenPixmap)(pScreen)->drawable,
+			      xf86_config->rotationDamage);
+	    DamageDestroy (xf86_config->rotationDamage);
+	    xf86_config->rotationDamage = NULL;
+	    /* Free block/wakeup handler */
+	    RemoveBlockAndWakeupHandlers (xf86RotateBlockHandler,
+					  xf86RotateWakeupHandler,
+					  (pointer) pScreen);
+	}
+    }
+    else
+    {
+	/* 
+	 * these are the size of the shadow pixmap, which
+	 * matches the mode, not the pre-rotated copy in the
+	 * frame buffer
+	 */
+	int	    width = mode->HDisplay;
+	int	    height = mode->VDisplay;
+	PixmapPtr   shadow = crtc->rotatedPixmap;
+	int	    old_width = shadow ? shadow->drawable.width : 0;
+	int	    old_height = shadow ? shadow->drawable.height : 0;
+	BoxRec	    damage_box;
+	RegionRec   damage_region;
+	
+	/* Allocate memory for rotation */
+	if (old_width != width || old_height != height)
+	{
+	    if (shadow)
+	    {
+		crtc->funcs->shadow_destroy (crtc, shadow);
+		crtc->rotatedPixmap = NULL;
+	    }
+	    shadow = crtc->funcs->shadow_create (crtc, width, height);
+	    if (!shadow)
+		goto bail1;
+	    crtc->rotatedPixmap = shadow;
+	}
+	
+	if (!xf86_config->rotationDamage)
+	{
+	    /* Create damage structure */
+	    xf86_config->rotationDamage = DamageCreate (NULL, NULL,
+						DamageReportNone,
+						TRUE, pScreen, pScreen);
+	    if (!xf86_config->rotationDamage)
+		goto bail2;
+	    
+	    /* Hook damage to screen pixmap */
+	    DamageRegister (&(*pScreen->GetScreenPixmap)(pScreen)->drawable,
+			    xf86_config->rotationDamage);
+	    
+	    /* Assign block/wakeup handler */
+	    if (!RegisterBlockAndWakeupHandlers (xf86RotateBlockHandler,
+						 xf86RotateWakeupHandler,
+						 (pointer) pScreen))
+	    {
+		goto bail3;
+	    }
+	    damage_box.x1 = 0;
+	    damage_box.y1 = 0;
+	    damage_box.x2 = mode_width (mode, rotation);
+	    damage_box.y2 = mode_height (mode, rotation);
+	    REGION_INIT (pScreen, &damage_region, &damage_box, 1);
+	    DamageDamageRegion (&(*pScreen->GetScreenPixmap)(pScreen)->drawable,
+				&damage_region);
+	    REGION_UNINIT (pScreen, &damage_region);
+	}
+	if (0)
+	{
+bail3:
+	    DamageDestroy (xf86_config->rotationDamage);
+	    xf86_config->rotationDamage = NULL;
+	    
+bail2:
+	    if (shadow)
+	    {
+		crtc->funcs->shadow_destroy (crtc, shadow);
+		crtc->rotatedPixmap = NULL;
+	    }
+bail1:
+	    if (old_width && old_height)
+		crtc->rotatedPixmap = crtc->funcs->shadow_create (crtc,
+								  old_width,
+								  old_height);
+	    return FALSE;
+	}
+    }
+    
+    /* All done */
+    return TRUE;
+}
diff --git a/hw/xfree86/modes/xf86cvt.c b/hw/xfree86/modes/xf86cvt.c
new file mode 100644
index 0000000..4256577
--- /dev/null
+++ b/hw/xfree86/modes/xf86cvt.c
@@ -0,0 +1,303 @@
+/*
+ * Copyright 2005-2006 Luc Verhaegen.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * @file This is a copy of xf86cvt.c from the X Server, for compatibility with
+ * old servers (pre-1.2).
+ */
+
+/*
+ * The reason for having this function in a file of its own is
+ * so that ../utils/cvt/cvt can link to it, and that xf86CVTMode
+ * code is shared directly.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include "xf86.h"
+
+#include <string.h>
+
+/*
+ * Generate a CVT standard mode from HDisplay, VDisplay and VRefresh.
+ *
+ * These calculations are stolen from the CVT calculation spreadsheet written
+ * by Graham Loveridge. He seems to be claiming no copyright and there seems to
+ * be no license attached to this. He apparently just wants to see his name
+ * mentioned.
+ *
+ * This file can be found at http://www.vesa.org/Public/CVT/CVTd6r1.xls
+ *
+ * Comments and structure corresponds to the comments and structure of the xls.
+ * This should ease importing of future changes to the standard (not very
+ * likely though).
+ *
+ * About margins; i'm sure that they are to be the bit between HDisplay and
+ * HBlankStart, HBlankEnd and HTotal, VDisplay and VBlankStart, VBlankEnd and 
+ * VTotal, where the overscan colour is shown. FB seems to call _all_ blanking
+ * outside sync "margin" for some reason. Since we prefer seeing proper
+ * blanking instead of the overscan colour, and since the Crtc* values will
+ * probably get altered after us, we will disable margins altogether. With
+ * these calculations, Margins will plainly expand H/VDisplay, and we don't
+ * want that. -- libv
+ *
+ */
+_X_EXPORT DisplayModePtr
+xf86CVTMode(int HDisplay, int VDisplay, float VRefresh, Bool Reduced,
+	    Bool Interlaced)
+{
+    DisplayModeRec  *Mode = xnfalloc(sizeof(DisplayModeRec));
+
+    /* 1) top/bottom margin size (% of height) - default: 1.8 */
+#define CVT_MARGIN_PERCENTAGE 1.8    
+
+    /* 2) character cell horizontal granularity (pixels) - default 8 */
+#define CVT_H_GRANULARITY 8
+
+    /* 4) Minimum vertical porch (lines) - default 3 */
+#define CVT_MIN_V_PORCH 3
+
+    /* 4) Minimum number of vertical back porch lines - default 6 */
+#define CVT_MIN_V_BPORCH 6
+
+    /* Pixel Clock step (kHz) */
+#define CVT_CLOCK_STEP 250
+
+    Bool Margins = FALSE;
+    float  VFieldRate, HPeriod;
+    int  HDisplayRnd, HMargin;
+    int  VDisplayRnd, VMargin, VSync;
+    float  Interlace; /* Please rename this */
+
+    memset(Mode, 0, sizeof(DisplayModeRec));
+
+    /* CVT default is 60.0Hz */
+    if (!VRefresh)
+        VRefresh = 60.0;
+
+    /* 1. Required field rate */
+    if (Interlaced)
+        VFieldRate = VRefresh * 2;
+    else
+        VFieldRate = VRefresh;
+
+    /* 2. Horizontal pixels */
+    HDisplayRnd = HDisplay - (HDisplay % CVT_H_GRANULARITY);
+
+    /* 3. Determine left and right borders */
+    if (Margins) {
+        /* right margin is actually exactly the same as left */
+        HMargin = (((float) HDisplayRnd) * CVT_MARGIN_PERCENTAGE / 100.0);
+        HMargin -= HMargin % CVT_H_GRANULARITY;
+    } else
+        HMargin = 0;
+
+    /* 4. Find total active pixels */
+    Mode->HDisplay = HDisplayRnd + 2*HMargin;
+
+    /* 5. Find number of lines per field */
+    if (Interlaced)
+        VDisplayRnd = VDisplay / 2;
+    else
+        VDisplayRnd = VDisplay;
+
+    /* 6. Find top and bottom margins */
+    /* nope. */
+    if (Margins)
+        /* top and bottom margins are equal again. */
+        VMargin = (((float) VDisplayRnd) * CVT_MARGIN_PERCENTAGE / 100.0);
+    else
+        VMargin = 0;
+
+    Mode->VDisplay = VDisplay + 2*VMargin;
+
+    /* 7. Interlace */
+    if (Interlaced)
+        Interlace = 0.5;
+    else
+        Interlace = 0.0;
+
+    /* Determine VSync Width from aspect ratio */
+    if (!(VDisplay % 3) && ((VDisplay * 4 / 3) == HDisplay))
+        VSync = 4;
+    else if (!(VDisplay % 9) && ((VDisplay * 16 / 9) == HDisplay))
+        VSync = 5;
+    else if (!(VDisplay % 10) && ((VDisplay * 16 / 10) == HDisplay))
+        VSync = 6;
+    else if (!(VDisplay % 4) && ((VDisplay * 5 / 4) == HDisplay))
+        VSync = 7;
+    else if (!(VDisplay % 9) && ((VDisplay * 15 / 9) == HDisplay))
+        VSync = 7;
+    else /* Custom */
+        VSync = 10;
+
+    if (!Reduced) { /* simplified GTF calculation */
+
+        /* 4) Minimum time of vertical sync + back porch interval (µs) 
+         * default 550.0 */
+#define CVT_MIN_VSYNC_BP 550.0
+
+        /* 3) Nominal HSync width (% of line period) - default 8 */
+#define CVT_HSYNC_PERCENTAGE 8
+
+        float  HBlankPercentage;
+        int  VSyncAndBackPorch, VBackPorch;
+        int  HBlank;
+
+        /* 8. Estimated Horizontal period */
+        HPeriod = ((float) (1000000.0 / VFieldRate - CVT_MIN_VSYNC_BP)) / 
+            (VDisplayRnd + 2 * VMargin + CVT_MIN_V_PORCH + Interlace);
+
+        /* 9. Find number of lines in sync + backporch */
+        if (((int)(CVT_MIN_VSYNC_BP / HPeriod) + 1) < (VSync + CVT_MIN_V_PORCH))
+            VSyncAndBackPorch = VSync + CVT_MIN_V_PORCH;
+        else
+            VSyncAndBackPorch = (int)(CVT_MIN_VSYNC_BP / HPeriod) + 1;
+
+        /* 10. Find number of lines in back porch */
+        VBackPorch = VSyncAndBackPorch - VSync;
+
+        /* 11. Find total number of lines in vertical field */
+        Mode->VTotal = VDisplayRnd + 2 * VMargin + VSyncAndBackPorch + Interlace
+            + CVT_MIN_V_PORCH;
+
+        /* 5) Definition of Horizontal blanking time limitation */
+        /* Gradient (%/kHz) - default 600 */
+#define CVT_M_FACTOR 600
+
+        /* Offset (%) - default 40 */
+#define CVT_C_FACTOR 40
+
+        /* Blanking time scaling factor - default 128 */
+#define CVT_K_FACTOR 128
+
+        /* Scaling factor weighting - default 20 */
+#define CVT_J_FACTOR 20
+
+#define CVT_M_PRIME CVT_M_FACTOR * CVT_K_FACTOR / 256
+#define CVT_C_PRIME (CVT_C_FACTOR - CVT_J_FACTOR) * CVT_K_FACTOR / 256 + \
+        CVT_J_FACTOR
+
+        /* 12. Find ideal blanking duty cycle from formula */
+        HBlankPercentage = CVT_C_PRIME - CVT_M_PRIME * HPeriod/1000.0;
+
+        /* 13. Blanking time */
+        if (HBlankPercentage < 20)
+            HBlankPercentage = 20;
+
+        HBlank = Mode->HDisplay * HBlankPercentage/(100.0 - HBlankPercentage);
+        HBlank -= HBlank % (2*CVT_H_GRANULARITY);
+        
+        /* 14. Find total number of pixels in a line. */
+        Mode->HTotal = Mode->HDisplay + HBlank;
+
+        /* Fill in HSync values */
+        Mode->HSyncEnd = Mode->HDisplay + HBlank / 2;
+
+        Mode->HSyncStart = Mode->HSyncEnd - 
+            (Mode->HTotal * CVT_HSYNC_PERCENTAGE) / 100;
+        Mode->HSyncStart += CVT_H_GRANULARITY - 
+            Mode->HSyncStart % CVT_H_GRANULARITY;
+
+        /* Fill in VSync values */
+        Mode->VSyncStart = Mode->VDisplay + CVT_MIN_V_PORCH;
+        Mode->VSyncEnd = Mode->VSyncStart + VSync;
+
+    } else { /* Reduced blanking */
+        /* Minimum vertical blanking interval time (µs) - default 460 */
+#define CVT_RB_MIN_VBLANK 460.0
+
+        /* Fixed number of clocks for horizontal sync */
+#define CVT_RB_H_SYNC 32.0
+
+        /* Fixed number of clocks for horizontal blanking */
+#define CVT_RB_H_BLANK 160.0
+
+        /* Fixed number of lines for vertical front porch - default 3 */
+#define CVT_RB_VFPORCH 3
+
+        int  VBILines;
+
+        /* 8. Estimate Horizontal period. */
+        HPeriod = ((float) (1000000.0 / VFieldRate - CVT_RB_MIN_VBLANK)) / 
+            (VDisplayRnd + 2*VMargin);
+
+        /* 9. Find number of lines in vertical blanking */
+        VBILines = ((float) CVT_RB_MIN_VBLANK) / HPeriod + 1;
+
+        /* 10. Check if vertical blanking is sufficient */
+        if (VBILines < (CVT_RB_VFPORCH + VSync + CVT_MIN_V_BPORCH))
+            VBILines = CVT_RB_VFPORCH + VSync + CVT_MIN_V_BPORCH;
+        
+        /* 11. Find total number of lines in vertical field */
+        Mode->VTotal = VDisplayRnd + 2 * VMargin + Interlace + VBILines;
+
+        /* 12. Find total number of pixels in a line */
+        Mode->HTotal = Mode->HDisplay + CVT_RB_H_BLANK;
+
+        /* Fill in HSync values */
+        Mode->HSyncEnd = Mode->HDisplay + CVT_RB_H_BLANK / 2;
+        Mode->HSyncStart = Mode->HSyncEnd - CVT_RB_H_SYNC;
+
+        /* Fill in VSync values */
+        Mode->VSyncStart = Mode->VDisplay + CVT_RB_VFPORCH;
+        Mode->VSyncEnd = Mode->VSyncStart + VSync;
+    }
+
+    /* 15/13. Find pixel clock frequency (kHz for xf86) */
+    Mode->Clock = Mode->HTotal * 1000.0 / HPeriod;
+    Mode->Clock -= Mode->Clock % CVT_CLOCK_STEP;
+
+    /* 16/14. Find actual Horizontal Frequency (kHz) */
+    Mode->HSync = ((float) Mode->Clock) / ((float) Mode->HTotal);
+
+    /* 17/15. Find actual Field rate */
+    Mode->VRefresh = (1000.0 * ((float) Mode->Clock)) / 
+        ((float) (Mode->HTotal * Mode->VTotal));
+
+    /* 18/16. Find actual vertical frame frequency */
+    /* ignore - just set the mode flag for interlaced */
+    if (Interlaced)
+        Mode->VTotal *= 2;
+
+    {
+        char  Name[256];
+        Name[0] = 0;
+
+        snprintf(Name, 256, "%dx%d", HDisplay, VDisplay);
+
+        Mode->name = xnfalloc(strlen(Name) + 1);
+        memcpy(Mode->name, Name, strlen(Name) + 1);
+    }
+
+    if (Reduced)
+        Mode->Flags |= V_PHSYNC | V_NVSYNC;
+    else
+        Mode->Flags |= V_NHSYNC | V_PVSYNC;
+
+    if (Interlaced)
+        Mode->Flags |= V_INTERLACE;
+
+    return Mode;
+}
diff --git a/hw/xfree86/ramdac/xf86Cursor.c b/hw/xfree86/ramdac/xf86Cursor.c
index a903f7f..4578076 100644
--- a/hw/xfree86/ramdac/xf86Cursor.c
+++ b/hw/xfree86/ramdac/xf86Cursor.c
@@ -199,10 +199,11 @@ xf86CursorEnableDisableFBAccess(
 	pScreen->devPrivates[xf86CursorScreenIndex].ptr;
 
     if (!enable && ScreenPriv->CurrentCursor != NullCursor) {
-	ScreenPriv->SavedCursor = ScreenPriv->CurrentCursor;
+	CursorPtr   currentCursor = ScreenPriv->CurrentCursor;
 	xf86CursorSetCursor(pScreen, NullCursor, ScreenPriv->x, ScreenPriv->y);
 	ScreenPriv->isUp = FALSE;
 	ScreenPriv->SWCursor = TRUE;
+	ScreenPriv->SavedCursor = currentCursor;
     }
 
     if (ScreenPriv->EnableDisableFBAccess)
diff-tree 37fe4c49dc3a5faf2d3d56112b6bd78453045f6a (from c2f3f705f1db8ca78292912544a7e416116175f3)
Author: Peter Hutterer <peter at cs.unisa.edu.au>
Date:   Fri Feb 16 09:57:57 2007 +1030

    mi:     Move WarpPointer event generation to miPointerMove to avoid duplicate
            events, cache event array allocation.

diff --git a/mi/mipointer.c b/mi/mipointer.c
index c28911b..b94feaa 100644
--- a/mi/mipointer.c
+++ b/mi/mipointer.c
@@ -70,6 +70,8 @@ static Bool miPointerSetCursorPosition(S
 static Bool miPointerCloseScreen(int index, ScreenPtr pScreen);
 static void miPointerMove(ScreenPtr pScreen, int x, int y, unsigned long time);
 
+static xEvent* events; /* for WarpPointer MotionNotifies */
+
 _X_EXPORT Bool
 miPointerInitialize (pScreen, spriteFuncs, screenFuncs, waitForUpdate)
     ScreenPtr		    pScreen;
@@ -128,6 +130,9 @@ miPointerInitialize (pScreen, spriteFunc
     miPointer.confined = FALSE;
     miPointer.x = 0;
     miPointer.y = 0;
+
+    events = NULL;
+
     return TRUE;
 }
 
@@ -144,6 +149,8 @@ miPointerCloseScreen (index, pScreen)
 	miPointer.pSpriteScreen = 0;
     pScreen->CloseScreen = pScreenPriv->CloseScreen;
     xfree ((pointer) pScreenPriv);
+    xfree ((pointer) events);
+    events = NULL;
     return (*pScreen->CloseScreen) (index, pScreen);
 }
 
@@ -466,7 +473,31 @@ miPointerGetPosition(DeviceIntPtr pDev, 
 void
 miPointerMove (ScreenPtr pScreen, int x, int y, unsigned long time)
 {
+    int i, nevents;
+    int valuators[2];
+
     miPointerMoved(inputInfo.pointer, pScreen, x, y, time);
+
+    /* generate motion notify */
+    valuators[0] = x;
+    valuators[1] = y;
+
+    if (!events)
+    {
+        events = (xEvent*)xcalloc(sizeof(xEvent), GetMaximumEventsNum());
+
+        if (!events)
+        {
+            FatalError("Could not allocate event store.\n");
+            return;
+        }
+    }
+
+    nevents = GetPointerEvents(events, inputInfo.pointer, MotionNotify, 0,
+                               POINTER_ABSOLUTE, 0, 2, valuators);
+
+    for (i = 0; i < nevents; i++)
+        mieqEnqueue(inputInfo.pointer, &events[i]);
 }
 
 /* Move the pointer on the current screen,  and update the sprite. */
@@ -474,10 +505,6 @@ void
 miPointerMoved (DeviceIntPtr pDev, ScreenPtr pScreen, int x, int y,
                      unsigned long time)
 {
-    xEvent* events;
-    int i, nevents;
-    int valuators[2];
-
     SetupScreen(pScreen);
 
     if (pDev && (pDev->coreEvents || pDev == inputInfo.pointer) &&
@@ -492,23 +519,4 @@ miPointerMoved (DeviceIntPtr pDev, Scree
     miPointer.x = x;
     miPointer.y = y;
     miPointer.pScreen = pScreen;
-
-    /* generate motion notify */
-    valuators[0] = x;
-    valuators[1] = y;
-
-    events = (xEvent*)xcalloc(sizeof(xEvent), GetMaximumEventsNum());
-    if (!events)
-    {
-        FatalError("Could not allocate event store.\n");
-        return;
-    }
-
-    nevents = GetPointerEvents(events, pDev, MotionNotify, 0,
-                               POINTER_ABSOLUTE, 0, 2, valuators);
-
-    for (i = 0; i < nevents; i++)
-        mieqEnqueue(pDev, &events[i]);
-
-    xfree(events);
 }
diff-tree c2f3f705f1db8ca78292912544a7e416116175f3 (from 811675733e97416c990e6dc9c19271b43d96248d)
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Feb 15 14:38:24 2007 -0500

    Bug #6988: Change behavior of Security extension per user feature request.

diff --git a/Xext/security.c b/Xext/security.c
index bd397a9..7202d39 100644
--- a/Xext/security.c
+++ b/Xext/security.c
@@ -1187,6 +1187,7 @@ CALLBACK(SecurityCheckMapAccess)
     if (STATEPTR(rec->client) &&
 	(TRUSTLEVEL(rec->client) != XSecurityClientTrusted) &&
 	(pWin->drawable.class == InputOnly) &&
+	pWin->parent && pWin->parent->parent &&
 	(TRUSTLEVEL(wClient(pWin->parent)) == XSecurityClientTrusted))
 
 	rec->rval = FALSE;
diff-tree 811675733e97416c990e6dc9c19271b43d96248d (from 8f6961d385bda92703f18090cff551409d2710c9)
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Thu Feb 15 19:09:00 2007 +0200

    os: fix client privates leak
    Minor leak here.  Oops.

diff --git a/os/connection.c b/os/connection.c
index ffe911e..d0ffb81 100644
--- a/os/connection.c
+++ b/os/connection.c
@@ -1066,6 +1066,8 @@ CloseDownConnection(ClientPtr client)
     XdmcpCloseDisplay(oc->fd);
 #endif
     CloseDownFileDescriptor(oc);
+    FreeOsBuffers(oc);
+    xfree(client->osPrivate);
     client->osPrivate = (pointer)NULL;
     if (auditTrailLevel > 1)
 	AuditF("client %d disconnected\n", client->index);
diff-tree 8f6961d385bda92703f18090cff551409d2710c9 (from a3b62623b8aac56b219633bdb2c2f6de19b0580b)
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Thu Feb 15 19:08:46 2007 +0200

    configure.ac: add xdarwin stubs
    Add stub AM_CONDITIONALs to at least fix the build.

diff --git a/configure.ac b/configure.ac
index 9611065..afbf980 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1737,6 +1737,11 @@ AM_CONDITIONAL(XFAKESERVER, [test "x$KDR
 AM_CONDITIONAL(KDRIVEVESA, [test x"$ac_cv_header_sys_vm86_h" = xyes])
 AM_CONDITIONAL(KDRIVEFBDEV, [test x"$ac_cv_header_linux_fb_h" = xyes])
 
+dnl XDarwin DDX (FIXME)
+AM_CONDITIONAL(XQUARTZ, false)
+AM_CONDITIONAL(HAVE_X_PLUGIN, false)
+AM_CONDITIONAL(HAVE_AGL_FRAMEWORK, false)
+
 dnl these only go in xkb-config.h (which is shared by the Xorg and Xnest servers)
 AC_DEFINE(__XKBDEFRULES__, "xorg", [Default XKB rules])
 AC_DEFINE_DIR(XKB_BASE_DIRECTORY, XKBPATH, [Path to XKB data])
diff-tree a3b62623b8aac56b219633bdb2c2f6de19b0580b (from 0f6dd4aea6176507dbe1c90c950d332fecbcaacb)
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Thu Feb 15 17:07:42 2007 +0200

    change versioning for new server version scheme
    See:
    http://xorg.freedesktop.org/wiki/XDC2007Notes#head-2719037a1905516c45cf74f0e155c8703221e446

diff --git a/configure.ac b/configure.ac
index 92dc5c9..9611065 100644
--- a/configure.ac
+++ b/configure.ac
@@ -25,7 +25,7 @@ dnl Process this file with autoconf to c
 AC_PREREQ(2.57)
 dnl This is the not the Xorg version number, it's the server version number.
 dnl Yes, that's weird.
-AC_INIT([xorg-server], 1.2.99.0, [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], xorg-server)
+AC_INIT([xorg-server], 1.3.99.0, [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], xorg-server)
 AC_CONFIG_SRCDIR([Makefile.am])
 AM_INIT_AUTOMAKE([dist-bzip2 foreign])
 AM_MAINTAINER_MODE
diff-tree 0f6dd4aea6176507dbe1c90c950d332fecbcaacb (from 9ecf79ca0111dd899ca88dd54156f71013220fcc)
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Thu Feb 15 16:14:57 2007 +0200

    kdrive/ephyr: free screen struct
    Free screen->driver on screenFini, instead of just leaking it.

diff --git a/hw/kdrive/ephyr/ephyr.c b/hw/kdrive/ephyr/ephyr.c
index 2ca51c3..e8001df 100644
--- a/hw/kdrive/ephyr/ephyr.c
+++ b/hw/kdrive/ephyr/ephyr.c
@@ -675,6 +675,8 @@ ephyrRestore (KdCardInfo *card)
 void
 ephyrScreenFini (KdScreenInfo *screen)
 {
+    xfree(screen->driver);
+    screen->driver = NULL;
 }
 
 /*  
diff-tree 9ecf79ca0111dd899ca88dd54156f71013220fcc (from 136bb4874aadf4a731d7eb8671e8bb641f9980a7)
Author: Ben Byer <bbyer at apple.com>
Date:   Thu Feb 15 05:22:21 2007 -0800

    Beginnings of an update Darwin driver

diff --git a/hw/darwin/Makefile.am b/hw/darwin/Makefile.am
index 542bfdb..7efd056 100644
--- a/hw/darwin/Makefile.am
+++ b/hw/darwin/Makefile.am
@@ -1,52 +1,249 @@
+noinst_LIBRARIES = libdarwinShared.a
+libdarwin_XINPUT_SRCS = darwinXinput.c
+
+AM_CFLAGS = @XORG_CFLAGS@ @DIX_CFLAGS@
+AM_CPPFLAGS = @XORG_CFLAGS@ @DIX_CFLAGS@
+INCLUDES = @XORG_INCS@
+
+DEFS = @DEFS@ -DUSE_NEW_CLUT
+
+if XQUARTZ
+XQUARTZ_SUBDIRS = bundle quartz
+endif
+
+SUBDIRS = \
+	  iokit \
+	  $(XQUARTZ_SUBDIRS) \
+	  utils \
+	  .
+
+
+darwinappdir = @APPLE_APPLICATIONS_DIR@/XDarwin.app
+
+
+libdarwinShared_a_SOURCES = darwin.c \
+			  darwinEvents.c \
+			  darwinKeyboard.c \
+			  $(darwin_XINPUT_SRCS) 
+
+bin_PROGRAMS = XDarwin
+XDarwin_SOURCES = \
+                  $(top_srcdir)/fb/fbcmap.c \
+                  $(top_srcdir)/mi/miinitext.c \
+                  $(top_srcdir)/Xi/stubs.c
+XDarwin_LDADD = \
+		$(top_builddir)/dix/dixfonts.lo \
+		$(top_builddir)/dix/libdix.la \
+		$(top_builddir)/config/libconfig.a \
+		$(top_builddir)/os/libos.la \
+		./libdarwinShared.a \
+		./iokit/libiokit.a \
+		$(top_builddir)/dix/libxpstubs.la \
+		$(top_builddir)/miext/shadow/libshadow.la \
+		$(top_builddir)/fb/libfb.la \
+		$(top_builddir)/composite/libcomposite.la \
+		$(top_builddir)/damageext/libdamageext.la \
+		$(top_builddir)/miext/damage/libdamage.la \
+		$(top_builddir)/xfixes/libxfixes.la \
+		$(top_builddir)/miext/cw/libcw.la \
+		$(top_builddir)/Xext/libXext.la \
+		$(top_builddir)/xkb/libxkb.la \
+		$(top_builddir)/xkb/libxkbstubs.la \
+		$(top_builddir)/Xi/libXi.la \
+		$(top_builddir)/dbe/libdbe.la \
+		$(top_builddir)/record/librecord.la \
+		$(top_builddir)/XTrap/libxtrap.la \
+		$(XGLX_LIBS) \
+		$(top_builddir)/miext/rootless/librootless.la \
+		$(top_builddir)/miext/rootless/safeAlpha/libsafeAlpha.la \
+		$(top_builddir)/miext/rootless/accel/librlAccel.la \
+		@XORG_LIBS@ \
+		-lXau -lXdmcp -lXfont -lfreetype
+
+XDarwin_LDFLAGS =  \
+		 -XCClinker -Objc \
+		 -Wl,-u,_miDCInitialize \
+		 -Wl,-framework,IOKit
+
+XDarwin_CFLAGS = -DINXDARWIN
+if XQUARTZ
+macosdir = $(darwinappdir)/Contents/MacOS
+
+DEFS += -DDARWIN_WITH_QUARTZ -DXFree86Server
+
+macos_PROGRAMS = XDarwinApp
+
+XDarwinApp_SOURCES = \
+               	$(top_srcdir)/fb/fbcmap.c \
+               	$(top_srcdir)/mi/miinitext.c \
+		$(top_srcdir)/Xi/stubs.c 
+
+XDarwinApp_LDADD = \
+		$(top_builddir)/dix/dixfonts.lo \
+		$(top_builddir)/dix/libdix.la \
+		$(top_builddir)/config/libconfig.a \
+		$(top_builddir)/os/libos.la \
+		./quartz/XApplication.o \
+		./libdarwinShared.a \
+		./quartz/libXQuartz.a \
+		$(top_builddir)/dix/libxpstubs.la \
+		 $(top_builddir)/miext/shadow/libshadow.la \
+		 $(top_builddir)/fb/libfb.la \
+		 $(top_builddir)/composite/libcomposite.la \
+		 $(top_builddir)/damageext/libdamageext.la \
+		 $(top_builddir)/miext/damage/libdamage.la \
+		 $(top_builddir)/xfixes/libxfixes.la \
+		 $(top_builddir)/miext/cw/libcw.la \
+		 $(top_builddir)/Xext/libXext.la \
+		 $(top_builddir)/xkb/libxkb.la \
+		 $(top_builddir)/xkb/libxkbstubs.la \
+		 $(top_builddir)/Xi/libXi.la \
+		 $(top_builddir)/dbe/libdbe.la \
+		 $(top_builddir)/record/librecord.la \
+		 $(top_builddir)/XTrap/libxtrap.la \
+		 $(XGLX_LIBS) \
+		 $(top_builddir)/miext/rootless/librootless.la \
+		 $(top_builddir)/miext/rootless/safeAlpha/libsafeAlpha.la \
+		 $(top_builddir)/miext/rootless/accel/librlAccel.la \
+		 @XORG_LIBS@ \
+		 -lXau -lXdmcp -lXfont -lfreetype \
+		 $(top_builddir)/fb/libfb.la 
+
+XDarwinApp_LDFLAGS =  \
+		 -XCClinker -Objc \
+		 -Wl,-u,_miDCInitialize \
+		 -Wl,-framework,Carbon \
+		 -Wl,-framework,ApplicationServices \
+		 -Wl,-framework,Cocoa \
+		 -Wl,-framework,CoreAudio \
+		 -Wl,-framework,IOKit
+
+HOOK_TARGETS = xquartz-install-hook
+
+
+crplugindir = $(darwinappdir)/Contents/Resources/cr.bundle/Contents/MacOS
+crplugin_LTLIBRARIES = cr.la
+cr_la_SOURCES =
+cr_la_LIBADD = \
+		quartz/cr/crAppleWM.o \
+		quartz/cr/crFrame.o \
+		quartz/cr/crScreen.o \
+		quartz/fullscreen/quartzCursor.o \
+		quartz/cr/XView.o \
+		$(top_builddir)/miext/rootless/librootless.la \
+		$(top_builddir)/miext/rootless/safeAlpha/libsafeAlpha.la \
+		$(top_builddir)/miext/rootless/accel/librlAccel.la
+cr_la_LDFLAGS = -shrext '' -Wl,-framework,ApplicationServices \
+		-Wl,-framework,Cocoa \
+		-Wl,-framework,Carbon \
+		-XCClinker -ObjC \
+		-XCClinker -bundle_loader -XCClinker XDarwinApp \
+		-module -avoid-version -no-undefined
+cr_la_DEPENDENCIES = XDarwinApp	
+
+fullscreenplugindir = $(darwinappdir)/Contents/Resources/fullscreen.bundle/Contents/MacOS
+fullscreenplugin_LTLIBRARIES = fullscreen.la
+fullscreen_la_SOURCES =
+fullscreen_la_LIBADD = \
+		quartz/fullscreen/fullscreen.o \
+		quartz/fullscreen/quartzCursor.o \
+		$(top_builddir)/miext/shadow/libshadow.la
+
+fullscreen_la_LDFLAGS = -shrext '' -Wl,-framework,ApplicationServices \
+		-XCClinker -bundle_loader -XCClinker XDarwinApp \
+		-module -avoid-version -no-undefined
+fullscreen_la_DEPENDENCIES = XDarwinApp	
+
+if GLX
+glxMesaplugindir = $(darwinappdir)/Contents/Resources/glxMesa.bundle/Contents/MacOS
+glxMesaplugin_LTLIBRARIES = glxMesa.la
+glxMesa_la_SOURCES =
+glxMesa_la_LIBADD = \
+		$(top_builddir)/GL/glx/libglx.la \
+		$(top_builddir)/GL/mesa/libGLcore.la 
+glxMesa_la_LDFLAGS = -shrext '' \
+		-Wl,-framework,AGL \
+		-Wl,-framework,OpenGL \
+		-XCClinker -ObjC \
+		-XCClinker -bundle_loader -XCClinker XDarwinApp \
+		-module -avoid-version -no-undefined
+glxMesa_la_DEPENDENCIES = XDarwinApp	
+endif
+
+endif
+if HAVE_X_PLUGIN
+
+xprplugindir = $(darwinappdir)/Contents/Resources/xpr.bundle/Contents/MacOS
+xprplugin_LTLIBRARIES = xpr.la
+xpr_la_SOURCES =
+xpr_la_LIBADD = \
+		quartz/xpr/appledri.o \
+		quartz/xpr/dri.o \
+		quartz/xpr/xprAppleWM.o \
+		quartz/xpr/xprCursor.o \
+		quartz/xpr/xprFrame.o \
+		quartz/xpr/xprScreen.o \
+		quartz/xpr/x-hash.o \
+		quartz/xpr/x-hook.o \
+		quartz/xpr/x-list.o \
+		$(top_builddir)/miext/rootless/librootless.la \
+		$(top_builddir)/miext/rootless/safeAlpha/libsafeAlpha.la \
+		$(top_builddir)/miext/rootless/accel/librlAccel.la
+xpr_la_LDFLAGS = -shrext '' -Wl,-framework,ApplicationServices \
+		-lXplugin \
+		-XCClinker -bundle_loader -XCClinker XDarwinApp \
+		-module -avoid-version -no-undefined
+xpr_la_DEPENDENCIES = XDarwinApp	
+
+endif
+
+if HAVE_AGL_FRAMEWORK
+glxCGLplugindir = $(darwinappdir)/Contents/Resources/glxCGL.bundle/Contents/MacOS
+glxCGLplugin_LTLIBRARIES = glxCGL.la
+glxCGL_la_SOURCES =
+glxCGL_la_LIBADD = \
+		$(top_builddir)/GL/glx/glxext.o \
+		$(top_builddir)/GL/glx/libglx.a \
+		$(top_builddir)/GL/apple/libAGLcore.a
+glxCGL_la_LDFLAGS = -shrext '' -Wl,-framework,ApplicationServices \
+		-Wl,-framework,AGL \
+		-Wl,-framework,OpenGL \
+		-XCClinker -ObjC \
+		-XCClinker -bundle_loader -XCClinker XDarwinApp \
+		-module -avoid-version -no-undefined
+glxCGL_la_DEPENDENCIES = XDarwinApp	
+
+
+glxAGLplugindir = $(darwinappdir)/Contents/Resources/glxAGL.bundle/Contents/MacOS
+glxAGLplugin_LTLIBRARIES = glxAGL.la
+glxAGL_la_SOURCES =
+glxAGL_la_LIBADD = \
+		$(top_builddir)/GL/glx/glxext.o \
+		$(top_builddir)/GL/glx/libglx.a \
+		$(top_builddir)/GL/apple/libAGLcore.a
+glxAGL_la_LDFLAGS = -shrext '' \
+		-Wl,-framework,AGL \
+		-Wl,-framework,OpenGL \
+		-XCClinker -ObjC \
+		-XCClinker -bundle_loader -XCClinker XDarwinApp \
+		-module -avoid-version -no-undefined
+glxAGL_la_DEPENDENCIES = XDarwinApp	
+
+
+
+endif
+
+man1_MANS = XDarwin.man
+
+uninstall-hook:
+	rm -rf $(DESTDIR)$(macosdir)/XDarwin
+
+install-data-hook: $(HOOK_TARGETS)
+
+xquartz-install-hook:
+	mv $(DESTDIR)$(macosdir)/XDarwinApp $(DESTDIR)$(macosdir)/XDarwin
+
 EXTRA_DIST = \
-	bundle/Dutch.lproj/Credits.rtf \
-	bundle/Dutch.lproj/Localizable.strings \
-	bundle/Dutch.lproj/MainMenu.nib/classes.nib \
-	bundle/Dutch.lproj/MainMenu.nib/objects.nib \
-	bundle/Dutch.lproj/XDarwinHelp.html.cpp \
-	bundle/English.lproj/Credits.rtf \
-	bundle/English.lproj/InfoPlist.strings.cpp \
-	bundle/English.lproj/Localizable.strings \
-	bundle/English.lproj/MainMenu.nib/classes.nib \
-	bundle/English.lproj/MainMenu.nib/objects.nib \
-	bundle/English.lproj/XDarwinHelp.html.cpp \
-	bundle/French.lproj/Credits.rtf \
-	bundle/French.lproj/Localizable.strings \
-	bundle/French.lproj/MainMenu.nib/classes.nib \
-	bundle/French.lproj/MainMenu.nib/objects.nib \
-	bundle/French.lproj/XDarwinHelp.html.cpp \
-	bundle/German.lproj/Credits.rtf \
-	bundle/German.lproj/Localizable.strings \
-	bundle/German.lproj/MainMenu.nib/classes.nib \
-	bundle/German.lproj/MainMenu.nib/objects.nib \
-	bundle/German.lproj/XDarwinHelp.html.cpp \
-	bundle/Japanese.lproj/Credits.rtf \
-	bundle/Japanese.lproj/Localizable.strings \
-	bundle/Japanese.lproj/MainMenu.nib/classes.nib \
-	bundle/Japanese.lproj/MainMenu.nib/objects.nib \
-	bundle/Japanese.lproj/XDarwinHelp.html.cpp \
-	bundle/ko.lproj/Credits.rtf \
-	bundle/ko.lproj/Localizable.strings \
-	bundle/ko.lproj/MainMenu.nib/classes.nib \
-	bundle/ko.lproj/MainMenu.nib/objects.nib \
-	bundle/ko.lproj/XDarwinHelp.html.cpp \
-	bundle/Portuguese.lproj/Credits.rtf \
-	bundle/Portuguese.lproj/Localizable.strings \
-	bundle/Portuguese.lproj/MainMenu.nib/classes.nib \
-	bundle/Portuguese.lproj/MainMenu.nib/objects.nib \
-	bundle/Portuguese.lproj/XDarwinHelp.html.cpp \
-	bundle/Spanish.lproj/Credits.rtf \
-	bundle/Spanish.lproj/Localizable.strings \
-	bundle/Spanish.lproj/MainMenu.nib/classes.nib \
-	bundle/Spanish.lproj/MainMenu.nib/objects.nib \
-	bundle/Spanish.lproj/XDarwinHelp.html.cpp \
-	bundle/startXClients.cpp \
-	bundle/Swedish.lproj/Credits.rtf \
-	bundle/Swedish.lproj/Localizable.strings \
-	bundle/Swedish.lproj/MainMenu.nib/classes.nib \
-	bundle/Swedish.lproj/MainMenu.nib/objects.nib \
-	bundle/Swedish.lproj/XDarwinHelp.html.cpp \
-	bundle/XDarwin.icns \
 	darwin.c \
 	darwinClut8.h \
 	darwinEvents.c \
@@ -54,64 +251,4 @@ EXTRA_DIST = \
 	darwinKeyboard.c \
 	darwinKeyboard.h \
 	darwinXinput.c \
-	iokit/xfIOKit.c \
-	iokit/xfIOKitCursor.c \
-	iokit/xfIOKit.h \
-	iokit/xfIOKitStartup.c \
-	Makefile.am \
-	quartz/applewm.c \
-	quartz/applewmExt.h \
-	quartz/cr/crAppleWM.m \
-	quartz/cr/crFrame.m \
-	quartz/cr/cr.h \
-	quartz/cr/crScreen.m \
-	quartz/cr/XView.h \
-	quartz/cr/XView.m \
-	quartz/fullscreen/fullscreen.c \
-	quartz/fullscreen/quartzCursor.c \
-	quartz/fullscreen/quartzCursor.h \
-	quartz/keysym2ucs.c \
-	quartz/keysym2ucs.h \
-	quartz/Preferences.h \
-	quartz/Preferences.m \
-	quartz/pseudoramiX.c \
-	quartz/pseudoramiX.h \
-	quartz/quartzAudio.c \
-	quartz/quartzAudio.h \
-	quartz/quartz.c \
-	quartz/quartzCocoa.m \
-	quartz/quartzCommon.h \
-	quartz/quartzCursor.c \
-	quartz/quartzCursor.h \
-	quartz/quartz.h \
-	quartz/quartzKeyboard.c \
-	quartz/quartzPasteboard.c \
-	quartz/quartzPasteboard.h \
-	quartz/quartzStartup.c \
-	quartz/XApplication.h \
-	quartz/XApplication.m \
-	quartz/XDarwin.pbproj/project.pbxproj \
-	quartz/XDarwinStartup.c \
-	quartz/XDarwinStartup.man \
-	quartz/xpr/appledri.c \
-	quartz/xpr/dri.c \
-	quartz/xpr/dri.h \
-	quartz/xpr/dristruct.h \
-	quartz/xpr/x-hash.c \
-	quartz/xpr/x-hash.h \
-	quartz/xpr/x-hook.c \
-	quartz/xpr/x-hook.h \
-	quartz/xpr/x-list.c \
-	quartz/xpr/x-list.h \
-	quartz/xpr/Xplugin.h \
-	quartz/xpr/xprAppleWM.c \
-	quartz/xpr/xprCursor.c \
-	quartz/xpr/xprFrame.c \
-	quartz/xpr/xpr.h \
-	quartz/xpr/xprScreen.c \
-	quartz/XServer.h \
-	quartz/XServer.m \
-	utils/dumpkeymap.c \
-	utils/dumpkeymap.man \
-	utils/README.txt \
 	XDarwin.man
diff --git a/hw/darwin/darwin.c b/hw/darwin/darwin.c
index bd99989..e33c321 100644
--- a/hw/darwin/darwin.c
+++ b/hw/darwin/darwin.c
@@ -30,6 +30,10 @@
  * use or other dealings in this Software without prior written authorization.
  */
 
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
 #include <X11/X.h>
 #include <X11/Xproto.h>
 #include "os.h"
@@ -409,9 +413,9 @@ static int DarwinMouseProc(
             InitPointerDeviceStruct( (DevicePtr)pPointer,
                         map,
                         5,   // numbuttons (4 & 5 are scroll wheel)
-                        miPointerGetMotionEvents,
+                        GetMotionHistory,
                         DarwinChangePointerControl,
-                        0 );
+                        GetMotionHistorySize(), 2 );
 #ifdef XINPUT
             InitValuatorAxisStruct( pPointer,
                                     0,     // X axis
diff --git a/hw/darwin/darwin.h b/hw/darwin/darwin.h
index cd57225..48a2224 100644
--- a/hw/darwin/darwin.h
+++ b/hw/darwin/darwin.h
@@ -31,6 +31,7 @@
 #include "inputstr.h"
 #include "scrnintstr.h"
 #include <X11/extensions/XKB.h>
+#include <assert.h>
 
 typedef struct {
     void                *framebuffer;
diff --git a/hw/darwin/darwinKeyboard.c b/hw/darwin/darwinKeyboard.c
index 1cc49fe..4e7a136 100644
--- a/hw/darwin/darwinKeyboard.c
+++ b/hw/darwin/darwinKeyboard.c
@@ -72,7 +72,7 @@
 #include <architecture/byte_order.h>  // For the NXSwap*
 #include "darwin.h"
 #include "darwinKeyboard.h"
-
+#include <assert.h>
 #define AltMask         Mod1Mask
 #define MetaMask        Mod2Mask
 #define FunctionMask    Mod3Mask
diff --git a/hw/darwin/darwinKeyboard.h b/hw/darwin/darwinKeyboard.h
index f4a8611..368aee9 100644
--- a/hw/darwin/darwinKeyboard.h
+++ b/hw/darwin/darwinKeyboard.h
@@ -29,7 +29,7 @@
 
 #define XK_TECHNICAL		// needed to get XK_Escape
 #define XK_PUBLISHING
-#include "keysym.h"
+#include "X11/keysym.h"
 #include "inputstr.h"
 
 // Each key can generate 4 glyphs. They are, in order:
diff-tree 136bb4874aadf4a731d7eb8671e8bb641f9980a7 (from 3ead1afe78d2913f08c8144cb2d3813c6b159488)
Author: Ben Byer <bbyer at apple.com>
Date:   Thu Feb 15 05:14:38 2007 -0800

    iokit support for XDarwin

diff --git a/hw/darwin/iokit/Makefile.am b/hw/darwin/iokit/Makefile.am
new file mode 100644
index 0000000..54464ae
--- /dev/null
+++ b/hw/darwin/iokit/Makefile.am
@@ -0,0 +1,17 @@
+noinst_LIBRARIES = libiokit.a
+
+AM_CFLAGS = @XORG_CFLAGS@ @DIX_CFLAGS@
+INCLUDES = -I. -I.. -I$(srcdir) -I$(srcdir)/.. @XORG_INCS@
+AM_DEFS =
+if XQUARTZ
+AM_DEFS += -DDARWIN_WITH_QUARTZ -DXFree86Server
+XQUARTZ_SUBDIRS = bundle quartz
+endif
+DEFS = @DEFS@ $(AM_DEFS)
+
+libiokit_a_SOURCES = xfIOKit.c \
+	           xfIOKitCursor.c \
+	           xfIOKitStartup.c
+
+EXTRA_DIST = \
+	xfIOKit.h
diff --git a/hw/darwin/iokit/xfIOKit.c b/hw/darwin/iokit/xfIOKit.c
index 95a7fb3..c7ebd1c 100644
--- a/hw/darwin/iokit/xfIOKit.c
+++ b/hw/darwin/iokit/xfIOKit.c
@@ -34,6 +34,10 @@
  * use or other dealings in this Software without prior written authorization.
  */
 
+#if HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
 #include <X11/X.h>
 #include <X11/Xproto.h>
 #include "os.h"
@@ -51,6 +55,7 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <pthread.h>
+#include <assert.h>
 
 #include <mach/mach_interface.h>
 
diff --git a/hw/darwin/iokit/xfIOKitCursor.c b/hw/darwin/iokit/xfIOKitCursor.c
index ef3e254..8388513 100644
--- a/hw/darwin/iokit/xfIOKitCursor.c
+++ b/hw/darwin/iokit/xfIOKitCursor.c
@@ -58,6 +58,9 @@
  * use or other dealings in this Software without prior written authorization.
  */
 
+#if HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
 #include "scrnintstr.h"
 #include "cursorstr.h"
 #include "mipointrst.h"
@@ -67,7 +70,7 @@
 #include <IOKit/hidsystem/IOHIDLib.h>
 #include "darwin.h"
 #include "xfIOKit.h"
-
+#include <assert.h>
 #define DUMP_DARWIN_CURSOR FALSE
 
 #define CURSOR_PRIV(pScreen) \
diff --git a/hw/darwin/iokit/xfIOKitStartup.c b/hw/darwin/iokit/xfIOKitStartup.c
index 512793a..07e8c21 100644
--- a/hw/darwin/iokit/xfIOKitStartup.c
+++ b/hw/darwin/iokit/xfIOKitStartup.c
@@ -29,6 +29,11 @@
  * use or other dealings in this Software without prior written authorization.
  */
 
+
+#if HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
 #include "darwin.h"
 #include "darwinKeyboard.h"
 #include "micmap.h"
@@ -57,7 +62,9 @@ void DarwinHandleGUI(
  */
 void DarwinGlxExtensionInit(void)
 {
-    GlxExtensionInit();
+#ifdef GLXEXT
+    	GlxExtensionInit();
+#endif
 }
 
 
@@ -67,7 +74,9 @@ void DarwinGlxExtensionInit(void)
 void DarwinGlxWrapInitVisuals(
     miInitVisualsProcPtr *procPtr)
 {
+#ifdef GLXEXT
     GlxWrapInitVisuals(procPtr);
+#endif
 }
 
 
diff-tree 3ead1afe78d2913f08c8144cb2d3813c6b159488 (from d570ff7c81858a3174686b46a088f67563b4a2d5)
Author: Ben Byer <bbyer at apple.com>
Date:   Thu Feb 15 05:09:29 2007 -0800

    Beginning of patches to add XDarwin support to the modular tree;
    special thanks to Torrey Lyons and Peter O'Gorman for making this possible.
    
    This is the automake framework for the XDarwin.app interface files.

diff --git a/hw/darwin/bundle/Dutch.lproj/Makefile.am b/hw/darwin/bundle/Dutch.lproj/Makefile.am
new file mode 100644
index 0000000..a480cee
--- /dev/null
+++ b/hw/darwin/bundle/Dutch.lproj/Makefile.am
@@ -0,0 +1,35 @@
+BINDIR = ${bindir}
+include $(top_srcdir)/cpprules.in
+XINITDIR = $(libdir)/X11/xinit
+XDEFS = \
+        -DX_VERSION="$(PLIST_VERSION_STRING)" \
+        -DX_PRE_RELEASE="$(PRE)" \
+        -DX_REL_DATE="$(XORG_DATE)" \
+        -DX_VENDOR_NAME="$(VENDOR_STRING)" \
+        -DX_VENDOR_LINK="$(PLIST_VENDOR_WEB)"
+
+resourcesdir = @APPLE_APPLICATIONS_DIR@/XDarwin.app/Contents/Resources
+
+Dutchlprojdir = $(resourcesdir)/Dutch.lproj
+
+Dutchlproj_DATA = \
+		    XDarwinHelp.html \
+		    InfoPlist.strings \
+		    Credits.rtf Localizable.strings
+
+Dutchlprojnibdir = $(Dutchlprojdir)/MainMenu.nib
+Dutchlprojnib_DATA = MainMenu.nib/classes.nib MainMenu.nib/objects.nib
+
+InfoPlist.strings: $(srcdir)/../English.lproj/InfoPlist.strings.cpp
+	 $(RAWCPP) $(RAWCPPFLAGS) $(XDEFS) $(CPP_FILES_FLAGS) $< | $(CPP_SED_MAGIC) | $(SED) -e's/__quote__/"/g' > $@
+
+XDarwinHelp.html: XDarwinHelp.html.cpp
+	$(RAWCPP) $(RAWCPPFLAGS) $(XDEFS) $(XDEFS) $(CPP_FILES_FLAGS) $< | $(CPP_SED_MAGIC) > $@
+
+CLEANFILES = XDarwinHelp.html InfoPlist.strings 
+
+EXTRA_DIST = \
+	Credits.rtf Localizable.strings \
+	MainMenu.nib/classes.nib \
+	MainMenu.nib/objects.nib \
+	XDarwinHelp.html.cpp
diff --git a/hw/darwin/bundle/English.lproj/Makefile.am b/hw/darwin/bundle/English.lproj/Makefile.am
new file mode 100644
index 0000000..4558708
--- /dev/null
+++ b/hw/darwin/bundle/English.lproj/Makefile.am
@@ -0,0 +1,35 @@
+BINDIR = ${bindir}
+include $(top_srcdir)/cpprules.in
+XINITDIR = $(libdir)/X11/xinit
+XDEFS = \
+        -DX_VERSION="$(PLIST_VERSION_STRING)" \
+        -DX_PRE_RELEASE="$(PRE)" \
+        -DX_REL_DATE="$(XORG_DATE)" \
+        -DX_VENDOR_NAME="$(VENDOR_STRING)" \
+        -DX_VENDOR_LINK="$(PLIST_VENDOR_WEB)"
+
+resourcesdir = @APPLE_APPLICATIONS_DIR@/XDarwin.app/Contents/Resources
+
+Englishlprojdir = $(resourcesdir)/English.lproj
+Englishlproj_DATA = \
+		    XDarwinHelp.html \
+		    InfoPlist.strings \
+		    Credits.rtf Localizable.strings
+
+Englishlprojnibdir = $(Englishlprojdir)/MainMenu.nib
+Englishlprojnib_DATA = MainMenu.nib/classes.nib MainMenu.nib/objects.nib
+
+InfoPlist.strings: InfoPlist.strings.cpp
+	 $(RAWCPP) $(RAWCPPFLAGS) $(XDEFS) $(CPP_FILES_FLAGS) $< | $(CPP_SED_MAGIC) | $(SED) -e's/__quote__/"/g' > $@
+
+XDarwinHelp.html: XDarwinHelp.html.cpp
+	$(RAWCPP) $(RAWCPPFLAGS) $(XDEFS) $(CPP_FILES_FLAGS) $< | $(CPP_SED_MAGIC) > $@
+
+CLEANFILES = XDarwinHelp.html InfoPlist.strings 
+
+EXTRA_DIST = \
+	Credits.rtf Localizable.strings \
+	MainMenu.nib/classes.nib \
+	MainMenu.nib/objects.nib \
+	XDarwinHelp.html.cpp \
+	InfoPlist.strings.cpp
diff --git a/hw/darwin/bundle/French.lproj/Makefile.am b/hw/darwin/bundle/French.lproj/Makefile.am
new file mode 100644
index 0000000..656ba5c
--- /dev/null
+++ b/hw/darwin/bundle/French.lproj/Makefile.am
@@ -0,0 +1,38 @@
+BINDIR = ${bindir}
+include $(top_srcdir)/cpprules.in
+XINITDIR = $(libdir)/X11/xinit
+
+XDEFS = \
+        -DX_VERSION="$(PLIST_VERSION_STRING)" \
+        -DX_PRE_RELEASE="$(PRE)" \
+        -DX_REL_DATE="$(XORG_DATE)" \
+        -DX_VENDOR_NAME="$(VENDOR_STRING)" \
+        -DX_VENDOR_LINK="$(PLIST_VENDOR_WEB)"
+
+
+resourcesdir = @APPLE_APPLICATIONS_DIR@/XDarwin.app/Contents/Resources
+
+Frenchlprojdir = $(resourcesdir)/French.lproj
+
+Frenchlproj_DATA = \
+		    XDarwinHelp.html \
+		    InfoPlist.strings \
+		    Credits.rtf Localizable.strings
+
+Frenchlprojnibdir = $(Frenchlprojdir)/MainMenu.nib
+Frenchlprojnib_DATA = MainMenu.nib/classes.nib MainMenu.nib/objects.nib
+
+InfoPlist.strings: $(srcdir)/../English.lproj/InfoPlist.strings.cpp
+	 $(RAWCPP) $(RAWCPPFLAGS) $(XDEFS) $(CPP_FILES_FLAGS) $< | $(CPP_SED_MAGIC) | $(SED) -e's/__quote__/"/g' > $@
+
+XDarwinHelp.html: XDarwinHelp.html.cpp
+	$(RAWCPP) $(RAWCPPFLAGS) $(XDEFS) $(CPP_FILES_FLAGS) $< | $(CPP_SED_MAGIC) > $@
+
+CLEANFILES = XDarwinHelp.html InfoPlist.strings 
+
+EXTRA_DIST = \
+	Credits.rtf Localizable.strings \
+	Localizable.strings \
+	MainMenu.nib/classes.nib \
+	MainMenu.nib/objects.nib \
+	XDarwinHelp.html.cpp
diff --git a/hw/darwin/bundle/German.lproj/Makefile.am b/hw/darwin/bundle/German.lproj/Makefile.am
new file mode 100644
index 0000000..17af414
--- /dev/null
+++ b/hw/darwin/bundle/German.lproj/Makefile.am
@@ -0,0 +1,36 @@
+BINDIR = ${bindir}
+include $(top_srcdir)/cpprules.in
+XINITDIR = $(libdir)/X11/xinit
+XDEFS = \
+        -DX_VERSION="$(PLIST_VERSION_STRING)" \
+        -DX_PRE_RELEASE="$(PRE)" \
+        -DX_REL_DATE="$(XORG_DATE)" \
+        -DX_VENDOR_NAME="$(VENDOR_STRING)" \
+        -DX_VENDOR_LINK="$(PLIST_VENDOR_WEB)"
+
+resourcesdir = @APPLE_APPLICATIONS_DIR@/XDarwin.app/Contents/Resources
+
+Germanlprojdir = $(resourcesdir)/German.lproj
+
+Germanlproj_DATA = \
+		    XDarwinHelp.html \
+		    InfoPlist.strings \
+		    Credits.rtf Localizable.strings
+
+Germanlprojnibdir = $(Germanlprojdir)/MainMenu.nib
+Germanlprojnib_DATA =  MainMenu.nib/classes.nib MainMenu.nib/objects.nib
+
+InfoPlist.strings: $(srcdir)/../English.lproj/InfoPlist.strings.cpp
+	 $(RAWCPP) $(RAWCPPFLAGS) $(XDEFS) $(CPP_FILES_FLAGS) $< | $(CPP_SED_MAGIC) | $(SED) -e's/__quote__/"/g' > $@
+
+XDarwinHelp.html: XDarwinHelp.html.cpp
+	$(RAWCPP) $(RAWCPPFLAGS) $(XDEFS) $(XDEFS) $(CPP_FILES_FLAGS) $< | $(CPP_SED_MAGIC) > $@
+
+CLEANFILES = XDarwinHelp.html InfoPlist.strings 
+
+EXTRA_DIST = \
+	Credits.rtf Localizable.strings \
+	Localizable.strings \
+	MainMenu.nib/classes.nib \
+	MainMenu.nib/objects.nib \
+	XDarwinHelp.html.cpp
diff --git a/hw/darwin/bundle/Info.plist b/hw/darwin/bundle/Info.plist
new file mode 100644
index 0000000..bfef48d
--- /dev/null
+++ b/hw/darwin/bundle/Info.plist
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+	<key>CFBundleDevelopmentRegion</key>
+	<string>English</string>
+	<key>CFBundleDocumentTypes</key>
+	<array>
+		<dict>
+			<key>CFBundleTypeExtensions</key>
+			<array>
+				<string>x11app</string>
+			</array>
+			<key>CFBundleTypeName</key>
+			<string>X11 Application</string>
+			<key>CFBundleTypeOSTypes</key>
+			<array>
+				<string>****</string>
+			</array>
+			<key>CFBundleTypeRole</key>
+			<string>Viewer</string>
+		</dict>
+		<dict>
+			<key>CFBundleTypeExtensions</key>
+			<array>
+				<string>tool</string>
+				<string>*</string>
+			</array>
+			<key>CFBundleTypeName</key>
+			<string>UNIX Application</string>
+			<key>CFBundleTypeOSTypes</key>
+			<array>
+				<string>****</string>
+			</array>
+			<key>CFBundleTypeRole</key>
+			<string>Viewer</string>
+		</dict>
+	</array>
+	<key>CFBundleExecutable</key>
+	<string>XDarwin</string>
+	<key>CFBundleGetInfoString</key>
+	<string>XDarwin 1.4.0, X.Org Foundation</string>
+	<key>CFBundleIconFile</key>
+	<string>XDarwin.icns</string>
+	<key>CFBundleIdentifier</key>
+	<string>org.x.XDarwin</string>
+	<key>CFBundleInfoDictionaryVersion</key>
+	<string>6.0</string>
+	<key>CFBundleName</key>
+	<string>XDarwin</string>
+	<key>CFBundlePackageType</key>
+	<string>APPL</string>
+	<key>CFBundleShortVersionString</key>
+	<string>XDarwin 1.4.0</string>
+	<key>CFBundleSignature</key>
+	<string>????</string>
+	<key>CFBundleVersion</key>
+	<string></string>
+	<key>NSHelpFile</key>
+	<string>XDarwinHelp.html</string>
+	<key>NSMainNibFile</key>
+	<string>MainMenu</string>
+	<key>NSPrincipalClass</key>
+	<string>XApplication</string>
+</dict>
+</plist>
diff --git a/hw/darwin/bundle/Japanese.lproj/Makefile.am b/hw/darwin/bundle/Japanese.lproj/Makefile.am
new file mode 100644
index 0000000..2cc5248
--- /dev/null
+++ b/hw/darwin/bundle/Japanese.lproj/Makefile.am
@@ -0,0 +1,37 @@
+BINDIR = ${bindir}
+include $(top_srcdir)/cpprules.in
+XINITDIR = $(libdir)/X11/xinit
+XDEFS = \
+        -DX_VERSION="$(PLIST_VERSION_STRING)" \
+        -DX_PRE_RELEASE="$(PRE)" \
+        -DX_REL_DATE="$(XORG_DATE)" \
+        -DX_VENDOR_NAME="$(VENDOR_STRING)" \
+        -DX_VENDOR_LINK="$(PLIST_VENDOR_WEB)"
+
+
+resourcesdir = @APPLE_APPLICATIONS_DIR@/XDarwin.app/Contents/Resources
+
+Japaneselprojdir = $(resourcesdir)/Japanese.lproj
+
+Japaneselproj_DATA = \
+		    XDarwinHelp.html \
+		    InfoPlist.strings \
+		    Credits.rtf Localizable.strings
+
+Japaneselprojnibdir = $(Japaneselprojdir)/MainMenu.nib
+Japaneselprojnib_DATA = MainMenu.nib/classes.nib MainMenu.nib/objects.nib
+
+InfoPlist.strings: $(srcdir)/../English.lproj/InfoPlist.strings.cpp
+	 $(RAWCPP) $(RAWCPPFLAGS) $(XDEFS) $(CPP_FILES_FLAGS) $< | $(CPP_SED_MAGIC) | $(SED) -e's/__quote__/"/g' > $@
+
+XDarwinHelp.html: XDarwinHelp.html.cpp
+	$(RAWCPP) $(RAWCPPFLAGS) $(XDEFS) $(CPP_FILES_FLAGS) $< | $(CPP_SED_MAGIC) > $@
+
+CLEANFILES = XDarwinHelp.html InfoPlist.strings 
+
+EXTRA_DIST = \
+	Credits.rtf Localizable.strings \
+	Localizable.strings \
+	MainMenu.nib/classes.nib \
+	MainMenu.nib/objects.nib \
+	XDarwinHelp.html.cpp
diff --git a/hw/darwin/bundle/Makefile.am b/hw/darwin/bundle/Makefile.am
new file mode 100644
index 0000000..dee34fd
--- /dev/null
+++ b/hw/darwin/bundle/Makefile.am
@@ -0,0 +1,38 @@
+BINDIR = ${bindir}
+include $(top_srcdir)/cpprules.in
+XINITDIR = $(libdir)/X11/xinit
+XDEFS = \
+        -DX_VERSION="$(PLIST_VERSION_STRING)" \
+        -DX_PRE_RELEASE="$(PRE)" \
+        -DX_REL_DATE="$(XORG_DATE)" \
+        -DX_VENDOR_NAME="$(VENDOR_STRING)" \
+        -DX_VENDOR_LINK="$(PLIST_VENDOR_WEB)"
+
+SUBDIRS =  English.lproj Dutch.lproj French.lproj German.lproj Japanese.lproj \
+	ko.lproj Portuguese.lproj Spanish.lproj Swedish.lproj
+
+bin_SCRIPTS = startXClients
+
+startXClients: $(srcdir)/startXClients.cpp
+	$(RAWCPP) $(RAWCPPFLAGS) $(XDEFS) $(CPP_FILES_FLAGS) -DXINITDIR=$(XINITDIR) -DXBINDIR=$(BINDIR)  $< | $(CPP_SED_MAGIC) > $@
+	-chmod 755 startXClients
+
+contentsdir = @APPLE_APPLICATIONS_DIR@/XDarwin.app/Contents
+resourcesdir = $(contentsdir)/Resources
+
+contents_DATA = Info.plist
+resources_DATA = XDarwin.icns startXClients
+
+install-data-hook:
+	chmod 755 $(DESTDIR)$(resourcesdir)/startXClients
+	echo "APPL????" > $(DESTDIR)$(contentsdir)/PkgInfo
+	touch $(DESTDIR)@APPLE_APPLICATIONS_DIR@/XDarwin.app
+
+uninstall-hook:
+	rm -rf $(DESTDIR)$(contentsdir)/PkgInfo
+
+CLEANFILES = startXClients
+
+EXTRA_DIST = \
+	XDarwin.icns \
+	Info.plist
diff --git a/hw/darwin/bundle/Portuguese.lproj/Makefile.am b/hw/darwin/bundle/Portuguese.lproj/Makefile.am
new file mode 100644
index 0000000..81ba2be
--- /dev/null
+++ b/hw/darwin/bundle/Portuguese.lproj/Makefile.am
@@ -0,0 +1,36 @@
+BINDIR = ${bindir}
+include $(top_srcdir)/cpprules.in
+XINITDIR = $(libdir)/X11/xinit
+XDEFS = \
+        -DX_VERSION="$(PLIST_VERSION_STRING)" \
+        -DX_PRE_RELEASE="$(PRE)" \
+        -DX_REL_DATE="$(XORG_DATE)" \
+        -DX_VENDOR_NAME="$(VENDOR_STRING)" \
+        -DX_VENDOR_LINK="$(PLIST_VENDOR_WEB)"
+
+resourcesdir = @APPLE_APPLICATIONS_DIR@/XDarwin.app/Contents/Resources
+
+Portugueselprojdir = $(resourcesdir)/Portuguese.lproj
+
+Portugueselproj_DATA = \
+		    XDarwinHelp.html \
+		    InfoPlist.strings \
+		    Credits.rtf Localizable.strings
+
+Portugueselprojnibdir = $(Portugueselprojdir)/MainMenu.nib
+Portugueselprojnib_DATA = MainMenu.nib/classes.nib MainMenu.nib/objects.nib
+
+InfoPlist.strings: $(srcdir)/../English.lproj/InfoPlist.strings.cpp
+	 $(RAWCPP) $(RAWCPPFLAGS) $(XDEFS) $(CPP_FILES_FLAGS) $< | $(CPP_SED_MAGIC) | $(SED) -e's/__quote__/"/g' > $@
+
+XDarwinHelp.html: XDarwinHelp.html.cpp
+	$(RAWCPP) $(RAWCPPFLAGS) $(XDEFS) $(CPP_FILES_FLAGS) $< | $(CPP_SED_MAGIC) > $@
+
+CLEANFILES = XDarwinHelp.html InfoPlist.strings 
+
+EXTRA_DIST = \
+	Credits.rtf Localizable.strings \
+	Localizable.strings \
+	MainMenu.nib/classes.nib \
+	MainMenu.nib/objects.nib \
+	XDarwinHelp.html.cpp
diff --git a/hw/darwin/bundle/Spanish.lproj/Makefile.am b/hw/darwin/bundle/Spanish.lproj/Makefile.am
new file mode 100644
index 0000000..438d0c2
--- /dev/null
+++ b/hw/darwin/bundle/Spanish.lproj/Makefile.am
@@ -0,0 +1,36 @@
+BINDIR = ${bindir}
+include $(top_srcdir)/cpprules.in
+XINITDIR = $(libdir)/X11/xinit
+XDEFS = \
+        -DX_VERSION="$(PLIST_VERSION_STRING)" \
+        -DX_PRE_RELEASE="$(PRE)" \
+        -DX_REL_DATE="$(XORG_DATE)" \
+        -DX_VENDOR_NAME="$(VENDOR_STRING)" \
+        -DX_VENDOR_LINK="$(PLIST_VENDOR_WEB)"
+
+resourcesdir = @APPLE_APPLICATIONS_DIR@/XDarwin.app/Contents/Resources
+
+Spanishlprojdir = $(resourcesdir)/Spanish.lproj
+
+Spanishlproj_DATA = \
+		    XDarwinHelp.html \
+		    InfoPlist.strings \
+		    Credits.rtf Localizable.strings
+
+Spanishlprojnibdir = $(Spanishlprojdir)/MainMenu.nib
+Spanishlprojnib_DATA = MainMenu.nib/classes.nib MainMenu.nib/objects.nib
+
+InfoPlist.strings: $(srcdir)/../English.lproj/InfoPlist.strings.cpp
+	 $(RAWCPP) $(RAWCPPFLAGS) $(XDEFS) $(CPP_FILES_FLAGS) $< | $(CPP_SED_MAGIC) | $(SED) -e's/__quote__/"/g' > $@
+
+XDarwinHelp.html: XDarwinHelp.html.cpp
+	$(RAWCPP) $(RAWCPPFLAGS) $(XDEFS) $(CPP_FILES_FLAGS) $< | $(CPP_SED_MAGIC) > $@
+
+CLEANFILES = XDarwinHelp.html InfoPlist.strings 
+
+EXTRA_DIST = \
+	Credits.rtf Localizable.strings \
+	Localizable.strings \
+	MainMenu.nib/classes.nib \
+	MainMenu.nib/objects.nib \
+	XDarwinHelp.html.cpp
diff --git a/hw/darwin/bundle/Swedish.lproj/Makefile.am b/hw/darwin/bundle/Swedish.lproj/Makefile.am
new file mode 100644
index 0000000..19f35a6
--- /dev/null
+++ b/hw/darwin/bundle/Swedish.lproj/Makefile.am
@@ -0,0 +1,36 @@
+BINDIR = ${bindir}
+include $(top_srcdir)/cpprules.in
+XINITDIR = $(libdir)/X11/xinit
+XDEFS = \
+        -DX_VERSION="$(PLIST_VERSION_STRING)" \
+        -DX_PRE_RELEASE="$(PRE)" \
+        -DX_REL_DATE="$(XORG_DATE)" \
+        -DX_VENDOR_NAME="$(VENDOR_STRING)" \
+        -DX_VENDOR_LINK="$(PLIST_VENDOR_WEB)"
+
+resourcesdir = @APPLE_APPLICATIONS_DIR@/XDarwin.app/Contents/Resources
+
+Swedishlprojdir = $(resourcesdir)/Swedish.lproj
+
+Swedishlproj_DATA = \
+		    XDarwinHelp.html \
+		    InfoPlist.strings \
+		    Credits.rtf Localizable.strings
+
+Swedishlprojnibdir = $(Swedishlprojdir)/MainMenu.nib
+Swedishlprojnib_DATA = MainMenu.nib/classes.nib MainMenu.nib/objects.nib
+
+InfoPlist.strings: $(srcdir)/../English.lproj/InfoPlist.strings.cpp
+	 $(RAWCPP) $(RAWCPPFLAGS) $(XDEFS) $(CPP_FILES_FLAGS) $< | $(CPP_SED_MAGIC) | $(SED) -e's/__quote__/"/g' > $@
+
+XDarwinHelp.html: XDarwinHelp.html.cpp
+	$(RAWCPP) $(RAWCPPFLAGS) $(XDEFS) $(CPP_FILES_FLAGS) $< | $(CPP_SED_MAGIC) > $@
+
+CLEANFILES = XDarwinHelp.html InfoPlist.strings 
+
+EXTRA_DIST = \
+	Credits.rtf Localizable.strings \
+	Localizable.strings \
+	MainMenu.nib/classes.nib \
+	MainMenu.nib/objects.nib \
+	XDarwinHelp.html.cpp
diff --git a/hw/darwin/bundle/ko.lproj/Makefile.am b/hw/darwin/bundle/ko.lproj/Makefile.am
new file mode 100644
index 0000000..56dd6b3
--- /dev/null
+++ b/hw/darwin/bundle/ko.lproj/Makefile.am
@@ -0,0 +1,37 @@
+BINDIR = ${bindir}
+include $(top_srcdir)/cpprules.in
+XINITDIR = $(libdir)/X11/xinit
+XDEFS = \
+        -DX_VERSION="$(PLIST_VERSION_STRING)" \
+        -DX_PRE_RELEASE="$(PRE)" \
+        -DX_REL_DATE="$(XORG_DATE)" \
+        -DX_VENDOR_NAME="$(VENDOR_STRING)" \
+        -DX_VENDOR_LINK="$(PLIST_VENDOR_WEB)"
+
+
+resourcesdir = @APPLE_APPLICATIONS_DIR@/XDarwin.app/Contents/Resources
+
+kolprojdir = $(resourcesdir)/ko.lproj
+
+kolproj_DATA = \
+		    XDarwinHelp.html \
+		    InfoPlist.strings \
+		    Credits.rtf Localizable.strings
+
+kolprojnibdir = $(kolprojdir)/MainMenu.nib
+kolprojnib_DATA = MainMenu.nib/classes.nib MainMenu.nib/objects.nib
+
+InfoPlist.strings: $(srcdir)/../English.lproj/InfoPlist.strings.cpp
+	 $(RAWCPP) $(RAWCPPFLAGS) $(XDEFS) $(CPP_FILES_FLAGS) $< | $(CPP_SED_MAGIC) | $(SED) -e's/__quote__/"/g' > $@
+
+XDarwinHelp.html: XDarwinHelp.html.cpp
+	$(RAWCPP) $(RAWCPPFLAGS) $(XDEFS) $(CPP_FILES_FLAGS) $< | $(CPP_SED_MAGIC) > $@
+
+CLEANFILES = XDarwinHelp.html InfoPlist.strings 
+
+EXTRA_DIST = \
+	Credits.rtf Localizable.strings \
+	Localizable.strings \
+	MainMenu.nib/classes.nib \
+	MainMenu.nib/objects.nib \
+	XDarwinHelp.html.cpp



More information about the xorg-commit mailing list