hlfw.ca

x9dev

Download patch

ref: 6f45786b64aff35f59eaaa2a1a2c739ecce8be2f
author: halfwit <michaelmisch1985@gmail.com>
date: Sat Sep 5 10:16:57 PDT 2020

Stashing changes for now

--- /dev/null
+++ b/README.md
@@ -1,0 +1,29 @@
+# x9dev
+
+x9dev is an x11 server which interacts with plan9's /dev filesystem.
+
+## Usage
+
+`x9dev [-w] [-x cmd] dir`
+
+- `-w` uses the /dev's wsys for window creation and control
+- `-x` will run the cmd on connection, usually an x11 program in a full screen
+
+Example:
+
+```rc
+# Import a remote /dev
+9pfuse -a dev 192.168.0.10 /tmp/9/dev
+x9dev /tmp/9/dev
+```
+
+## Building
+
+Requires plan9port
+
+```rc
+git clone https://github.com/halfwit/x9dev
+mv x9dev /path/to/xorg-server-source/hw/
+cd /path/to/xorg-server-source/hw/x9dev
+mk build; mk install
+```
--- /dev/null
+++ b/config.h
@@ -1,0 +1,32 @@
+#define PACKAGE	"x9dev"
+
+/* libX11 */
+#define TCPCONN 1
+#define UNIXCONN 1
+#define NO_XLOCALEDIR 1
+#define USE_XCB 0
+#define X11_DATADIR "/usr/local/lib/X11"
+#define X11_LIBDIR "/usr/local/lib/X11"
+#define XCMS 1
+#define XERRORDB "/usr/local/lib/X11/XErrorDB"
+#define XF86BIGFONT 1
+#define XKB 1
+#define XKEYSYMDB "/usr/local/lib/X11/XKeysymDB"
+#define XLOCALEDATADIR "/usr/local/lib/X11/locale"
+#define XLOCALEDIR "/usr/local/lib/X11/locale"
+#define XLOCALELIBDIR "/usr/local/lib/X11/locale"
+
+/* libXfont */
+#define FONTCACHE 1
+#define LOADABLEFONTS 1
+#define XFONT_BDFFORMAT 1
+#define XFONT_BITMAP 1
+#define XFONT_BUILTINS 1
+#define XFONT_FC 1
+#define XFONT_FONTFILE 1
+#define XFONT_FREETYPE 1
+#define XFONT_PCFFORMAT 1
+#define XFONT_SNFFORMAT 1
+#define XFONT_SPEEDO 1
+#define XFONT_TYPE1 1
+#define X_GZIP_FONT_COMPRESSION 1
--- /dev/null
+++ b/dix-config.h
@@ -1,0 +1,133 @@
+/*
+ * Copyright (c) 2020 Michael Misch michaelmisch1985@gmail.com>
+ * 
+ * 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 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.
+ */
+
+#ifndef _DIX_CONFIG_H_
+#define _DIX_CONFIG_H_
+
+#define ABORTONFATALERROR  1
+#define BUILDERADDR "michaelmisch1985@gmail.com"
+#define PACKAGE "x9dev"
+#define VENDOR_NAME "The X.Org Foundation"
+
+/* Revisit this, possibly generate this file and allow a path to be passed in for those that want to use APE fonts from plan9 */
+#define COMPILEDDEFAULTFONTPATH "/usr/local/lib/X11/fonts/misc/,/usr/local/lib/X11/fonts/TTF/,/usr/local/lib/X11/fonts/OTF,/usr/local/lib/X11/fonts/Type1/,/usr/local/lib/X11/fonts/100dpi/,/usr/local/lib/X11/fonts/75dpi/"
+
+/* connection types */
+/* #define LOCALCONN 1 */
+#define TCPCONN 1
+#define UNIXCONN 1
+
+/* fb needs these */
+#undef GLYPHPADBYTES
+#define GLYPHPADBYTES 4
+#define GETLEFTBITS_ALIGNMENT 1
+
+#define HAS_FFS 1
+#define HAVE_DIRENT_H 1
+#define HAVE_FCNTL_H 1
+#define HAVE_GETEUID 1
+#define HAVE_GETOPT 1
+#define HAVE_GETUID 1
+#define HAVE_INTTYPES_H 1
+#define HAVE_LIBM 1
+#define HAVE_LINK 1
+#define HAVE_MEMMOVE 1
+#define HAVE_MEMSET 1
+#define HAVE_STDLIB_H 1
+#define HAVE_STRLCPY 1
+#define HAVE_STRLCAT 1
+#define HAVE_STRCHR 1
+#define HAVE_STRING_H 1
+#define HAVE_STRRCHR 1
+#define HAVE_STRTOL 1
+#define HAVE_SYS_STAT_H 1
+#define HAVE_SYS_TYPES_H 1
+#define HAVE_UNISTD_H 1
+#define HAVE_VPRINTF 1
+#define STDC_HEADERS 1
+
+#define SHADOWFB 1
+#define RENDER 1
+#define RES 1
+#define SHAPE 1
+#define XINPUT 1
+#define XResExtension 1
+
+#define NO_LIBCWRAPPER 1
+#define NULL_ROOT_CURSOR 1
+#define USE_RGB_BUILTIN 1
+#define XKB_DFLT_DISABLED  0
+
+#undef BIGREQS /*1*/
+#undef BUILTIN_FONTS
+#undef COMPOSITE /*1*/
+#undef DAMAGE /*1*/
+#undef DBE
+#undef DDXBEFORERESET
+#undef DDXOSFATALERROR
+#define DDXOSINIT 1
+#undef DDXOSVERRORF
+#undef DDXTIME
+#undef DPMSExtension
+#undef EVI
+#undef HASXDMAUTH
+#undef MITSHM
+#undef MULTIBUFFER
+#undef NOFONTSERVERACCESS
+#undef PANORAMIX
+#undef PIXPRIV /*1*/
+#undef PROJECTROOT /* "/sys/lib/ape/X11" */
+/* Try to get randr, etc */
+#undef RANDR /*1*/
+#undef ROOTLESS
+#undef SCREENSAVER
+#undef SERVER_LOCK /*1*/
+#undef SMART_SCHEDULE /*1*/
+#undef TOGCUP
+#undef XACE
+#undef XAPPGROUP
+#undef XCMISC /*1*/
+#undef XCSECURITY
+#undef XDMCP
+#undef XEVIE
+#undef XF86BIGFONT
+/* Try to get DRI*/
+#undef XF86DRI
+#undef XF86MISC
+#undef XF86VIDMODE
+#undef XFIXES /*1*/
+#undef XFreeXDGA
+#undef XINERAMA
+#undef XKB /*1*/
+#undef XKB_IN_SERVER /*1*/
+#undef XRECORD
+#undef XSYNC
+#undef XTEST /*1*/
+#undef XTRAP
+#undef XV
+#undef XvMCExtension
+
+extern int fsync(int);
+extern double hypot(double, double);
+
+#endif /* _DIX_CONFIG_H_ */
--- /dev/null
+++ b/keymap.h
@@ -1,0 +1,560 @@
+/* the key names define come from xwin/winkeynames.h, hence the NOTICE */
+
+/*
+ * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
+ *
+ * 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 Thomas Roell not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission.  Thomas Roell makes no representations
+ * about the suitability of this software for any purpose.  It is provided
+ * "as is" without express or implied warranty.
+ *
+ * THOMAS ROELL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THOMAS ROELL 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.
+ *
+ */
+
+#define MAP_WIDTH   4
+#define NUM_KEYCODES    248
+#define MIN_KEYCODE     8
+#define MAX_KEYCODE     (NUM_KEYCODES + MIN_KEYCODE-1)
+
+/*
+ * definition of the AT84/MF101/MF102 Keyboard:
+ * ============================================================
+ *       Defined             Key Cap Glyphs       Pressed value
+ *      Key Name            Main       Also       (hex)    (dec)
+ *      ----------------   ---------- -------    ------    ------
+ */
+
+#define KEY_Escape       /* Escape                0x01  */    1  
+#define KEY_1            /* 1           !         0x02  */    2 
+#define KEY_2            /* 2           @         0x03  */    3 
+#define KEY_3            /* 3           #         0x04  */    4 
+#define KEY_4            /* 4           $         0x05  */    5 
+#define KEY_5            /* 5           %         0x06  */    6 
+#define KEY_6            /* 6           ^         0x07  */    7 
+#define KEY_7            /* 7           &         0x08  */    8 
+#define KEY_8            /* 8           *         0x09  */    9 
+#define KEY_9            /* 9           (         0x0a  */   10 
+#define KEY_0            /* 0           )         0x0b  */   11 
+#define KEY_Minus        /* - (Minus)   _ (Under) 0x0c  */   12
+#define KEY_Equal        /* = (Equal)   +         0x0d  */   13 
+#define KEY_BackSpace    /* Back Space            0x0e  */   14 
+#define KEY_Tab          /* Tab                   0x0f  */   15
+#define KEY_Q            /* Q                     0x10  */   16
+#define KEY_W            /* W                     0x11  */   17
+#define KEY_E            /* E                     0x12  */   18
+#define KEY_R            /* R                     0x13  */   19
+#define KEY_T            /* T                     0x14  */   20
+#define KEY_Y            /* Y                     0x15  */   21
+#define KEY_U            /* U                     0x16  */   22
+#define KEY_I            /* I                     0x17  */   23
+#define KEY_O            /* O                     0x18  */   24
+#define KEY_P            /* P                     0x19  */   25
+#define KEY_LBrace       /* [           {         0x1a  */   26
+#define KEY_RBrace       /* ]           }         0x1b  */   27 
+#define KEY_Enter        /* Enter                 0x1c  */   28
+#define KEY_LCtrl        /* Ctrl(left)            0x1d  */   29
+#define KEY_A            /* A                     0x1e  */   30
+#define KEY_S            /* S                     0x1f  */   31
+#define KEY_D            /* D                     0x20  */   32 
+#define KEY_F            /* F                     0x21  */   33
+#define KEY_G            /* G                     0x22  */   34
+#define KEY_H            /* H                     0x23  */   35
+#define KEY_J            /* J                     0x24  */   36
+#define KEY_K            /* K                     0x25  */   37
+#define KEY_L            /* L                     0x26  */   38
+#define KEY_SemiColon    /* ;(SemiColon) :(Colon) 0x27  */   39
+#define KEY_Quote        /* ' (Apostr)  " (Quote) 0x28  */   40
+#define KEY_Tilde        /* ` (Accent)  ~ (Tilde) 0x29  */   41
+#define KEY_ShiftL       /* Shift(left)           0x2a  */   42
+#define KEY_BSlash       /* \(BckSlash) |(VertBar)0x2b  */   43
+#define KEY_Z            /* Z                     0x2c  */   44
+#define KEY_X            /* X                     0x2d  */   45
+#define KEY_C            /* C                     0x2e  */   46
+#define KEY_V            /* V                     0x2f  */   47
+#define KEY_B            /* B                     0x30  */   48
+#define KEY_N            /* N                     0x31  */   49
+#define KEY_M            /* M                     0x32  */   50
+#define KEY_Comma        /* , (Comma)   < (Less)  0x33  */   51
+#define KEY_Period       /* . (Period)  >(Greater)0x34  */   52
+#define KEY_Slash        /* / (Slash)   ?         0x35  */   53
+#define KEY_ShiftR       /* Shift(right)          0x36  */   54
+#define KEY_KP_Multiply  /* *                     0x37  */   55
+#define KEY_Alt          /* Alt(left)             0x38  */   56
+#define KEY_Space        /*   (SpaceBar)          0x39  */   57
+#define KEY_CapsLock     /* CapsLock              0x3a  */   58
+#define KEY_F1           /* F1                    0x3b  */   59
+#define KEY_F2           /* F2                    0x3c  */   60
+#define KEY_F3           /* F3                    0x3d  */   61
+#define KEY_F4           /* F4                    0x3e  */   62
+#define KEY_F5           /* F5                    0x3f  */   63
+#define KEY_F6           /* F6                    0x40  */   64
+#define KEY_F7           /* F7                    0x41  */   65
+#define KEY_F8           /* F8                    0x42  */   66
+#define KEY_F9           /* F9                    0x43  */   67
+#define KEY_F10          /* F10                   0x44  */   68
+#define KEY_NumLock      /* NumLock               0x45  */   69
+#define KEY_ScrollLock   /* ScrollLock            0x46  */   70
+#define KEY_KP_7         /* 7           Home      0x47  */   71 
+#define KEY_KP_8         /* 8           Up        0x48  */   72 
+#define KEY_KP_9         /* 9           PgUp      0x49  */   73 
+#define KEY_KP_Minus     /* - (Minus)             0x4a  */   74
+#define KEY_KP_4         /* 4           Left      0x4b  */   75
+#define KEY_KP_5         /* 5                     0x4c  */   76
+#define KEY_KP_6         /* 6           Right     0x4d  */   77
+#define KEY_KP_Plus      /* + (Plus)              0x4e  */   78
+#define KEY_KP_1         /* 1           End       0x4f  */   79
+#define KEY_KP_2         /* 2           Down      0x50  */   80
+#define KEY_KP_3         /* 3           PgDown    0x51  */   81
+#define KEY_KP_0         /* 0           Insert    0x52  */   82
+#define KEY_KP_Decimal   /* . (Decimal) Delete    0x53  */   83 
+#define KEY_SysReqest    /* SysReqest             0x54  */   84
+                         /* NOTUSED               0x55  */
+#define KEY_Less         /* < (Less)   >(Greater) 0x56  */   86
+#define KEY_F11          /* F11                   0x57  */   87
+#define KEY_F12          /* F12                   0x58  */   88
+
+#define KEY_Prefix0      /* special               0x60  */   96
+#define KEY_Prefix1      /* specail               0x61  */   97
+
+/*
+ * The 'scancodes' below are generated by the server, because the MF101/102
+ * keyboard sends them as sequence of other scancodes
+ */
+#define KEY_Home         /* Home                  0x59  */   89
+#define KEY_Up           /* Up                    0x5a  */   90
+#define KEY_PgUp         /* PgUp                  0x5b  */   91
+#define KEY_Left         /* Left                  0x5c  */   92
+#define KEY_Begin        /* Begin                 0x5d  */   93
+#define KEY_Right        /* Right                 0x5e  */   94
+#define KEY_End          /* End                   0x5f  */   95
+#define KEY_Down         /* Down                  0x60  */   96
+#define KEY_PgDown       /* PgDown                0x61  */   97
+#define KEY_Insert       /* Insert                0x62  */   98
+#define KEY_Delete       /* Delete                0x63  */   99
+#define KEY_KP_Enter     /* Enter                 0x64  */  100
+#define KEY_RCtrl        /* Ctrl(right)           0x65  */  101
+#define KEY_Pause        /* Pause                 0x66  */  102
+#define KEY_Print        /* Print                 0x67  */  103
+#define KEY_KP_Divide    /* Divide                0x68  */  104
+#define KEY_AltLang      /* AtlLang(right)        0x69  */  105
+#define KEY_Break        /* Break                 0x6a  */  106
+#define KEY_LMeta        /* Left Meta             0x6b  */  107
+#define KEY_RMeta        /* Right Meta            0x6c  */  108
+#define KEY_Menu         /* Menu                  0x6d  */  109
+#define KEY_F13          /* F13                   0x6e  */  110
+#define KEY_F14          /* F14                   0x6f  */  111
+#define KEY_F15          /* F15                   0x70  */  112
+#define KEY_F16          /* F16                   0x71  */  113
+#define KEY_F17          /* F17                   0x72  */  114
+#define KEY_KP_DEC       /* KP_DEC                0x73  */  115
+#define KEY_KP_Equal     /* Equal (Keypad)        0x76  */  118
+#define KEY_XFER         /* Kanji Transfer        0x79  */  121
+#define KEY_NFER         /* No Kanji Transfer     0x7b  */  123
+#define KEY_Yen          /* Yen                   0x7d  */  125
+#define KEY_HKTG         /* Hirugana/Katakana tog 0xc8  */  200
+#define KEY_BSlash2      /* \           _         0xcb  */  203
+
+struct{
+    unsigned char key, mod;
+}rune2keycode[] = {
+    KEY_Delete, KEY_ShiftL, /* 0x000 */
+    KEY_A,  KEY_LCtrl,  /* 0x001 */
+    KEY_B,  KEY_LCtrl,  /* 0x002 */
+    KEY_C,  KEY_LCtrl,  /* 0x003 */
+    KEY_D,  KEY_LCtrl,  /* 0x004 */
+    KEY_E,  KEY_LCtrl,  /* 0x005 */
+    KEY_F,  KEY_LCtrl,  /* 0x006 */
+    KEY_G,  KEY_LCtrl,  /* 0x007 */
+    KEY_BackSpace,  0,  /* 0x008 */
+    KEY_Tab,    0,  /* 0x009 */
+    KEY_Enter,  0,  /* 0x00a */
+    KEY_K,  KEY_LCtrl,  /* 0x00b */
+    KEY_L,  KEY_LCtrl,  /* 0x00c */
+    KEY_M,    KEY_LCtrl,  /* 0x00d */
+    KEY_N,  KEY_LCtrl,  /* 0x00e */
+    KEY_O,  KEY_LCtrl,  /* 0x00f */
+    KEY_P,  KEY_LCtrl,  /* 0x010 */
+    KEY_Q,  KEY_LCtrl,  /* 0x011 */
+    KEY_R,  KEY_LCtrl,  /* 0x012 */
+    KEY_S,  KEY_LCtrl,  /* 0x013 */
+    KEY_T,  KEY_LCtrl,  /* 0x014 */
+    KEY_U,  KEY_LCtrl,  /* 0x015 */
+    KEY_V,  KEY_LCtrl,  /* 0x016 */
+    KEY_W,  KEY_LCtrl,  /* 0x017 */
+    KEY_X,  KEY_LCtrl,  /* 0x018 */
+    KEY_Y,  KEY_LCtrl,  /* 0x019 */
+    KEY_Z,  KEY_LCtrl,  /* 0x01a */
+    KEY_Escape, 0,  /* 0x01b */
+    KEY_BSlash, KEY_LCtrl,  /* 0x01c */
+    KEY_RBrace, KEY_LCtrl,  /* 0x01d */
+    KEY_Period, KEY_LCtrl,  /* 0x01e */
+    KEY_Slash,  KEY_LCtrl,  /* 0x01f */
+    KEY_Space,  0,  /* 0x020 */
+    KEY_1,  KEY_ShiftL, /* 0x021 */
+    KEY_Quote,  KEY_ShiftL, /* 0x022 */
+    KEY_3,  KEY_ShiftL, /* 0x023 */
+    KEY_4,  KEY_ShiftL, /* 0x024 */
+    KEY_5,  KEY_ShiftL, /* 0x025 */
+    KEY_7,  KEY_ShiftL, /* 0x026 */
+    KEY_Quote,  0,  /* 0x027 */
+    KEY_9,  KEY_ShiftL, /* 0x028 */
+    KEY_0,  KEY_ShiftL, /* 0x029 */
+    KEY_8,  KEY_ShiftL, /* 0x02a */
+    KEY_Equal,  KEY_ShiftL, /* 0x02b */
+    KEY_Comma,  0,  /* 0x02c */
+    KEY_KP_Minus,   0,  /* 0x02d */
+    KEY_Period,0,   /* 0x02e */
+    KEY_Slash,  0,  /* 0x02f */
+    KEY_0,  0,  /* 0x030 */
+    KEY_1,  0,  /* 0x031 */
+    KEY_2,  0,  /* 0x032 */
+    KEY_3,  0,  /* 0x033 */
+    KEY_4,  0,  /* 0x034 */
+    KEY_5,  0,  /* 0x035 */
+    KEY_6,  0,  /* 0x036 */
+    KEY_7,  0,  /* 0x037 */
+    KEY_8,  0,  /* 0x038 */
+    KEY_9,  0,  /* 0x039 */
+    KEY_SemiColon,  KEY_ShiftL, /* 0x03a */
+    KEY_SemiColon,  0,  /* 0x03b */
+    KEY_Comma,  KEY_ShiftL, /* 0x03c */
+    KEY_Equal,  0,  /* 0x03d */
+    KEY_Period, KEY_ShiftL, /* 0x03e */
+    KEY_Slash,  KEY_ShiftL, /* 0x03f */
+    KEY_2,  KEY_ShiftL, /* 0x040 */
+    KEY_A,  KEY_ShiftL, /* 0x041 */
+    KEY_B,  KEY_ShiftL, /* 0x042 */
+    KEY_C,  KEY_ShiftL, /* 0x043 */
+    KEY_D,  KEY_ShiftL, /* 0x044 */
+    KEY_E,  KEY_ShiftL, /* 0x045 */
+    KEY_F,  KEY_ShiftL, /* 0x046 */
+    KEY_G,  KEY_ShiftL, /* 0x047 */
+    KEY_H,  KEY_ShiftL, /* 0x048 */
+    KEY_I,  KEY_ShiftL, /* 0x049 */
+    KEY_J,  KEY_ShiftL, /* 0x04a */
+    KEY_K,  KEY_ShiftL, /* 0x04b */
+    KEY_L,  KEY_ShiftL, /* 0x04c */
+    KEY_M,  KEY_ShiftL, /* 0x04d */
+    KEY_N,  KEY_ShiftL, /* 0x04e */
+    KEY_O,  KEY_ShiftL, /* 0x04f */
+    KEY_P,  KEY_ShiftL, /* 0x050 */
+    KEY_Q,  KEY_ShiftL, /* 0x051 */
+    KEY_R,  KEY_ShiftL, /* 0x052 */
+    KEY_S,  KEY_ShiftL, /* 0x053 */
+    KEY_T,  KEY_ShiftL, /* 0x054 */
+    KEY_U,  KEY_ShiftL, /* 0x055 */
+    KEY_V,  KEY_ShiftL, /* 0x056 */
+    KEY_W,  KEY_ShiftL, /* 0x057 */
+    KEY_X,  KEY_ShiftL, /* 0x058 */
+    KEY_Y,  KEY_ShiftL, /* 0x059 */
+    KEY_Z,  KEY_ShiftL, /* 0x05a */
+    KEY_LBrace, 0,  /* 0x05b */
+    KEY_BSlash, 0,  /* 0x05c */
+    KEY_RBrace, 0,  /* 0x05d */
+    KEY_6,  KEY_ShiftL, /* 0x05e */
+    KEY_Minus,  KEY_ShiftL, /* 0x05f */
+    KEY_Tilde,0,    /* 0x060 */
+    KEY_A,  0,  /* 0x061 */
+    KEY_B,  0,  /* 0x062 */
+    KEY_C,  0,  /* 0x063 */
+    KEY_D,  0,  /* 0x064 */
+    KEY_E,  0,  /* 0x065 */
+    KEY_F,  0,  /* 0x066 */
+    KEY_G,  0,  /* 0x067 */
+    KEY_H,  0,  /* 0x068 */
+    KEY_I,  0,  /* 0x069 */
+    KEY_J,  0,  /* 0x06a */
+    KEY_K,  0,  /* 0x06b */
+    KEY_L,  0,  /* 0x06c */
+    KEY_M,  0,  /* 0x06d */
+    KEY_N,  0,  /* 0x06e */
+    KEY_O,  0,  /* 0x06f */
+    KEY_P,  0,  /* 0x070 */
+    KEY_Q,  0,  /* 0x071 */
+    KEY_R,  0,  /* 0x072 */
+    KEY_S,  0,  /* 0x073 */
+    KEY_T,  0,  /* 0x074 */
+    KEY_U,  0,  /* 0x075 */
+    KEY_V,  0,  /* 0x076 */
+    KEY_W,  0,  /* 0x077 */
+    KEY_X,  0,  /* 0x078 */
+    KEY_Y,  0,  /* 0x079 */
+    KEY_Z,  0,  /* 0x07a */
+    KEY_LBrace, KEY_ShiftL, /* 0x07b */
+    KEY_BSlash, KEY_ShiftL, /* 0x07c */
+    KEY_RBrace, KEY_ShiftL, /* 0x07d */
+    KEY_Tilde,  KEY_ShiftL, /* 0x07e */
+    KEY_Delete, 0,  /* 0x07f */
+    0,   0,  /* 0x080 */
+    KEY_F1,  0,  /* 0x081 */
+    KEY_F2,  0,  /* 0x082 */
+    KEY_F3,  0,  /* 0x083 */
+    KEY_F4,  0,  /* 0x084 */
+    KEY_F5,  0,  /* 0x085 */
+    KEY_F6,  0,  /* 0x086 */
+    KEY_F7,  0,  /* 0x087 */
+    KEY_F8,  0,  /* 0x088 */
+    KEY_F9,  0,  /* 0x089 */
+    KEY_F10,  0,  /* 0x08a */
+    KEY_F11,  0,  /* 0x08b */
+    KEY_F12,  0,  /* 0x08c */
+    KEY_Home,  0,  /* 0x08d */
+    KEY_Up,  0,  /* 0x08e */
+    KEY_PgUp,  0,  /* 0x08f */
+    KEY_Print,  0,  /* 0x090 */
+    KEY_Left,  0,  /* 0x091 */
+    KEY_Right,  0,  /* 0x092 */
+    KEY_PgDown,  0,  /* 0x093 */
+    KEY_Insert,  0,  /* 0x094 */
+    0,  0,  /* 0x095 */
+    0,  0,  /* 0x096 */
+    0,  0,  /* 0x097 */
+    KEY_End,  0,  /* 0x098 */
+    KEY_Down,  0,  /* 0x099 */
+    0,  0,  /* 0x09a */
+    0,  0,  /* 0x09b */
+    0,  0,  /* 0x09c */
+    0,  0,  /* 0x09d */
+    0,  0,  /* 0x09e */
+    0,  0,  /* 0x09f */
+    0,  0,  /* 0x0a0 */
+    0,  0,  /* 0x0a1 */
+    0,  0,  /* 0x0a2 */
+    0,  0,  /* 0x0a3 */
+    0,  0,  /* 0x0a4 */
+    0,  0,  /* 0x0a5 */
+    0,  0,  /* 0x0a6 */
+    0,  0,  /* 0x0a7 */
+    0,  0,  /* 0x0a8 */
+    0,  0,  /* 0x0a9 */
+    0,  0,  /* 0x0aa */
+    0,  0,  /* 0x0ab */
+    0,  0,  /* 0x0ac */
+    0,  0,  /* 0x0ad */
+    0,  0,  /* 0x0ae */
+    0,  0,  /* 0x0af */
+    0,  0,  /* 0x0b0 */
+    0,  0,  /* 0x0b1 */
+    0,  0,  /* 0x0b2 */
+    0,  0,  /* 0x0b3 */
+    0,  0,  /* 0x0b4 */
+    0,  0,  /* 0x0b5 */
+    0,  0,  /* 0x0b6 */
+    0,  0,  /* 0x0b7 */
+    0,  0,  /* 0x0b8 */
+    0,  0,  /* 0x0b9 */
+    0,  0,  /* 0x0ba */
+    0,  0,  /* 0x0bb */
+    0,  0,  /* 0x0bc */
+    0,  0,  /* 0x0bd */
+    0,  0,  /* 0x0be */
+    0,  0,  /* 0x0bf */
+    0,  0,  /* 0x0c0 */
+    0,  0,  /* 0x0c1 */
+    0,  0,  /* 0x0c2 */
+    0,  0,  /* 0x0c3 */
+    0,  0,  /* 0x0c4 */
+    0,  0,  /* 0x0c5 */
+    0,  0,  /* 0x0c6 */
+    0,  0,  /* 0x0c7 */
+    0,  0,  /* 0x0c8 */
+    0,  0,  /* 0x0c9 */
+    0,  0,  /* 0x0ca */
+    0,  0,  /* 0x0cb */
+    0,  0,  /* 0x0cc */
+    0,  0,  /* 0x0cd */
+    0,  0,  /* 0x0ce */
+    0,  0,  /* 0x0cf */
+    0,  0,  /* 0x0d0 */
+    0,  0,  /* 0x0d1 */
+    0,  0,  /* 0x0d2 */
+    0,  0,  /* 0x0d3 */
+    0,  0,  /* 0x0d4 */
+    0,  0,  /* 0x0d5 */
+    0,  0,  /* 0x0d6 */
+    0,  0,  /* 0x0d7 */
+    0,  0,  /* 0x0d8 */
+    0,  0,  /* 0x0d9 */
+    0,  0,  /* 0x0da */
+    0,  0,  /* 0x0db */
+    0,  0,  /* 0x0dc */
+    0,  0,  /* 0x0dd */
+    0,  0,  /* 0x0de */
+    0,  0,  /* 0x0df */
+    0,  0,  /* 0x0e0 */
+    0,  0,  /* 0x0e1 */
+    0,  0,  /* 0x0e2 */
+    0,  0,  /* 0x0e3 */
+    0,  0,  /* 0x0e4 */
+    0,  0,  /* 0x0e5 */
+    0,  0,  /* 0x0e6 */
+    0,  0,  /* 0x0e7 */
+    0,  0,  /* 0x0e8 */
+    0,  0,  /* 0x0e9 */
+    0,  0,  /* 0x0ea */
+    0,  0,  /* 0x0eb */
+    0,  0,  /* 0x0ec */
+    0,  0,  /* 0x0ed */
+    0,  0,  /* 0x0ee */
+    0,  0,  /* 0x0ef */
+    0,  0,  /* 0x0f0 */
+    0,  0,  /* 0x0f1 */
+    0,  0,  /* 0x0f2 */
+    0,  0,  /* 0x0f3 */
+    0,  0,  /* 0x0f4 */
+    0,  0,  /* 0x0f5 */
+    0,  0,  /* 0x0f6 */
+    0,  0,  /* 0x0f7 */
+    0,  0,  /* 0x0f8 */
+    0,  0,  /* 0x0f9 */
+    0,  0,  /* 0x0fa */
+    0,  0,  /* 0x0fb */
+    0,  0,  /* 0x0fc */
+    0,  0,  /* 0x0fd */
+    0,  0,  /* 0x0fe */
+    0,  0,  /* 0x0ff */
+};
+
+/* from xwin/winkeymap.h */
+static KeySym map[NUM_KEYCODES*MAP_WIDTH]={
+    /* 0x00 */  NoSymbol,       NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x01 */  XK_Escape,      NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x02 */  XK_1,           XK_exclam,  NoSymbol,   NoSymbol,
+    /* 0x03 */  XK_2,           XK_at,      NoSymbol,   NoSymbol,
+    /* 0x04 */  XK_3,           XK_numbersign,  NoSymbol,   NoSymbol,
+    /* 0x05 */  XK_4,           XK_dollar,  NoSymbol,   NoSymbol,
+    /* 0x06 */  XK_5,           XK_percent, NoSymbol,   NoSymbol,
+    /* 0x07 */  XK_6,           XK_asciicircum, NoSymbol,   NoSymbol,
+    /* 0x08 */  XK_7,           XK_ampersand,   NoSymbol,   NoSymbol,
+    /* 0x09 */  XK_8,           XK_asterisk,    NoSymbol,   NoSymbol,
+    /* 0x0a */  XK_9,           XK_parenleft,   NoSymbol,   NoSymbol,
+    /* 0x0b */  XK_0,           XK_parenright,  NoSymbol,   NoSymbol,
+    /* 0x0c */  XK_minus,       XK_underscore,  NoSymbol,   NoSymbol,
+    /* 0x0d */  XK_equal,       XK_plus,    NoSymbol,   NoSymbol,
+    /* 0x0e */  XK_BackSpace,   NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x0f */  XK_Tab,         XK_ISO_Left_Tab,NoSymbol,   NoSymbol,
+    /* 0x10 */  XK_Q,           NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x11 */  XK_W,           NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x12 */  XK_E,           NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x13 */  XK_R,           NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x14 */  XK_T,           NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x15 */  XK_Y,           NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x16 */  XK_U,           NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x17 */  XK_I,           NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x18 */  XK_O,           NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x19 */  XK_P,           NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x1a */  XK_bracketleft, XK_braceleft,   NoSymbol,   NoSymbol,
+    /* 0x1b */  XK_bracketright,XK_braceright,  NoSymbol,   NoSymbol,
+    /* 0x1c */  XK_Return,      NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x1d */  XK_Control_L,   NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x1e */  XK_A,           NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x1f */  XK_S,           NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x20 */  XK_D,           NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x21 */  XK_F,           NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x22 */  XK_G,           NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x23 */  XK_H,           NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x24 */  XK_J,           NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x25 */  XK_K,           NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x26 */  XK_L,           NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x27 */  XK_semicolon,   XK_colon,   NoSymbol,   NoSymbol,
+    /* 0x28 */  XK_quoteright,  XK_quotedbl,    NoSymbol,   NoSymbol,
+    /* 0x29 */  XK_quoteleft,   XK_asciitilde,  NoSymbol,   NoSymbol,
+    /* 0x2a */  XK_Shift_L,     NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x2b */  XK_backslash,   XK_bar,     NoSymbol,   NoSymbol,
+    /* 0x2c */  XK_Z,           NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x2d */  XK_X,           NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x2e */  XK_C,           NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x2f */  XK_V,           NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x30 */  XK_B,           NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x31 */  XK_N,           NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x32 */  XK_M,           NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x33 */  XK_comma,       XK_less,    NoSymbol,   NoSymbol,
+    /* 0x34 */  XK_period,      XK_greater, NoSymbol,   NoSymbol,
+    /* 0x35 */  XK_slash,       XK_question,    NoSymbol,   NoSymbol,
+    /* 0x36 */  XK_Shift_R,     NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x37 */  XK_KP_Multiply, NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x38 */  XK_Alt_L,   XK_Meta_L,  NoSymbol,   NoSymbol,
+    /* 0x39 */  XK_space,       NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x3a */  XK_Caps_Lock,   NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x3b */  XK_F1,          NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x3c */  XK_F2,          NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x3d */  XK_F3,          NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x3e */  XK_F4,          NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x3f */  XK_F5,          NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x40 */  XK_F6,          NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x41 */  XK_F7,          NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x42 */  XK_F8,          NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x43 */  XK_F9,          NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x44 */  XK_F10,         NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x45 */  XK_Num_Lock,    NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x46 */  XK_Scroll_Lock, NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x47 */  XK_KP_Home, XK_KP_7,    NoSymbol,   NoSymbol,
+    /* 0x48 */  XK_KP_Up,   XK_KP_8,    NoSymbol,   NoSymbol,
+    /* 0x49 */  XK_KP_Prior,    XK_KP_9,    NoSymbol,   NoSymbol,
+    /* 0x4a */  XK_KP_Subtract, NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x4b */  XK_KP_Left, XK_KP_4,    NoSymbol,   NoSymbol,
+    /* 0x4c */  XK_KP_Begin,    XK_KP_5,    NoSymbol,   NoSymbol,
+    /* 0x4d */  XK_KP_Right,    XK_KP_6,    NoSymbol,   NoSymbol,
+    /* 0x4e */  XK_KP_Add,      NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x4f */  XK_KP_End,  XK_KP_1,    NoSymbol,   NoSymbol,
+    /* 0x50 */  XK_KP_Down, XK_KP_2,    NoSymbol,   NoSymbol,
+    /* 0x51 */  XK_KP_Next, XK_KP_3,    NoSymbol,   NoSymbol,
+    /* 0x52 */  XK_KP_Insert,   XK_KP_0,    NoSymbol,   NoSymbol,
+    /* 0x53 */  XK_KP_Delete,   XK_KP_Decimal,  NoSymbol,   NoSymbol,
+    /* 0x54 */  XK_Sys_Req, NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x55 */  NoSymbol,   NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x56 */  XK_less,    XK_greater, NoSymbol,   NoSymbol,
+    /* 0x57 */  XK_F11,     NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x58 */  XK_F12,     NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x59 */  XK_Home,    NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x5a */  XK_Up,      NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x5b */  XK_Prior,   NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x5c */  XK_Left,    NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x5d */  XK_Begin,   NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x5e */  XK_Right,   NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x5f */  XK_End,     NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x60 */  XK_Down,    NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x61 */  XK_Next,    NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x62 */  XK_Insert,  NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x63 */  XK_Delete,  NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x64 */  XK_KP_Enter,    NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x65 */  XK_Control_R,   NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x66 */  XK_Pause,   NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x67 */  XK_Print,   NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x68 */  XK_KP_Divide,   NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x69 */  XK_Alt_R,   XK_Meta_R,  NoSymbol,   NoSymbol,
+    /* 0x6a */  XK_Break,   NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x6b */  XK_Meta_L,  NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x6c */  XK_Meta_R,  NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x6d */  XK_Menu,    NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x6e */  XK_F13,     NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x6f */  XK_F14,     NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x70 */  XK_F15,     NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x71 */  XK_F16,     NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x72 */  XK_F17,     NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x73 */  XK_backslash,   XK_underscore,  NoSymbol,   NoSymbol,
+    /* 0x74 */  NoSymbol,   NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x75 */  NoSymbol,   NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x76 */  NoSymbol,   NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x77 */  NoSymbol,   NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x78 */  NoSymbol,   NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x79 */  XK_Henkan,  XK_Mode_switch, NoSymbol,   NoSymbol,
+    /* 0x7a */  NoSymbol,   NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x7b */  XK_Muhenkan,    NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x7c */  NoSymbol,   NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x7d */  XK_backslash,   XK_bar,     NoSymbol,   NoSymbol,
+    /* 0x7e */  NoSymbol,   NoSymbol,   NoSymbol,   NoSymbol,
+    /* 0x7f */  NoSymbol,   NoSymbol,   NoSymbol,   NoSymbol,
+};
--- /dev/null
+++ b/mkfile
@@ -1,0 +1,223 @@
+<$PLAN9/src/mkhdr
+
+BIN=/usr/local/bin
+
+TARG=x9dev
+CC=cc
+OFILES=\
+	x9dev.$O\
+	plan9port.$O\
+	shadowfb.$O\
+# Xext \
+	shape.$O\
+	xres.$O\
+# Xi \
+	allowev.$O\
+	chgdctl.$O\
+	chgfctl.$O\
+	chgkbd.$O\
+	chgkmap.$O\
+	chgprop.$O\
+	chgptr.$O\
+	closedev.$O\
+	devbell.$O\
+	exevents.$O\
+	extinit.$O\
+	getbmap.$O\
+	getdctl.$O\
+	getfctl.$O\
+	getfocus.$O\
+	getkmap.$O\
+	getmmap.$O\
+	getprop.$O\
+	getselev.$O\
+	getvers.$O\
+	grabdev.$O\
+	grabdevb.$O\
+	grabdevk.$O\
+	gtmotion.$O\
+	listdev.$O\
+	opendev.$O\
+	queryst.$O\
+	selectev.$O\
+	sendexev.$O\
+	setbmap.$O\
+	setdval.$O\
+	setfocus.$O\
+	setmmap.$O\
+	setmode.$O\
+	stubs.$O\
+	ungrdev.$O\
+	ungrdevb.$O\
+	ungrdevk.$O\
+# config \
+	config.$O\
+# dix \
+	atom.$O\
+	colormap.$O\
+	cursor.$O\
+	devices.$O\
+	dispatch.$O\
+	dixfonts.$O\
+	dixutils.$O\
+	enterleave.$O\
+	eventconvert.$O\
+	events.$O\
+	extension.$O\
+	gc.$O\
+	getevents.$O\
+	globals.$O\
+	glyphcurs.$O\
+	grabs.$O\
+	initatoms.$O\
+	inpututils.$O\
+	main.$O\
+	pixmap.$O\
+	privates.$O\
+	ptrveloc.$O\
+	property.$O\
+	region.$O\
+	registry.$O\
+	resource.$O\
+	selection.$O\
+	stubmain.$O\
+	swaprep.$O\
+	swapreq.$O\
+	tables.$O\
+	touch.$O\
+	window.$O\
+# fb \
+	fballpriv.$O\
+	fbarc.$O\
+	fbbits.$O\
+	fbblt.$O\
+	fbbltone.$O\
+	fbcmap_mi.$O\
+	fbcopy.$O\
+	fbfill.$O\
+	fbfillrect.$O\
+	fbfillsp.$O\
+	fbgc.$O\
+	fbgetsp.$O\
+	fbglyph.$O\
+	fbimage.$O\
+	fbline.$O\
+	fboverlay.$O\
+	fbpict.$O\
+	fbpixmap.$O\
+	fbpoint.$O\
+	fbpush.$O\
+	fbscreen.$O\
+	fbseg.$O\
+	fbsetsp.$O\
+	fbsolid.$O\
+	fbtrap.$O\
+	fbutil.$O\
+	fbwindow.$O\
+# mi \
+	miarc.$O\
+	mibitblt.$O\
+	micmap.$O\
+	micopy.$O\
+	midash.$O\
+	midispcur.$O\
+	mieq.$O\
+	miexpose.$O\
+	mifillarc.$O\
+	mifillrct.$O\
+	migc.$O\
+	miglblt.$O\
+	miinitext.$O\
+	mioverlay.$O\
+	mipointer.$O\
+	mipoly.$O\
+	mipolypnt.$O\
+	mipolyrect.$O\
+	mipolyseg.$O\
+	mipolytext.$O\
+	mipushpxl.$O\
+	miscrinit.$O\
+	misprite.$O\
+	mivaltree.$O\
+	miwideline.$O\
+	miwindow.$O\
+	mizerarc.$O\
+	mizerclip.$O\
+	mizerline.$O\
+# miext/damage \
+	damage.$O\
+# miext/shadow \
+	shadow.$O\
+# os \
+	WaitFor.$O\
+	access.$O\
+	auth.$O\
+	connection.$O\
+	io.$O\
+	log.$O\
+	mitauth.$O\
+	oscolor.$O\
+	osinit.$O\
+	utils.$O\
+	xprintf.$O\
+	xstrans.$O\
+# render \
+	animcur.$O\
+	filter.$O\
+	glyph.$O\
+	matrix.$O\
+	miindex.$O\
+	mipict.$O\
+	mirect.$O\
+	mitrap.$O\
+	mitri.$O\
+	picture.$O\
+	render.$O\
+
+HFILES=\
+	dix-config.h
+
+<$PLAN9/src/mkone
+
+CFLAGS=-c -D_POSIX_SOURCE -D_BSD_EXTENSION -D_SUSV2_SOURCE -DSHADOWFB \
+	-DHAVE_DIX_CONFIG_H -DPLAN9 -DT$objtype -I. -I../../include \
+	-I../../fb -I../../mi -I../../miext/damage -I../../miext/shadow -I../../randr \
+	-I../../render -I../../Xext -I../../Xi \
+	-I/opt/X11/include -I/opt/X11/include/pixman-1  \
+	-I/opt/X11/include/xorg \
+	-I/Users/halfwit/Library/Plan9/include #-DDEBUG
+
+x9dev.$O: x9dev.c keymap.h x9dev.h
+plan9port.$O: plan9port.c x9dev.h
+shadowfb.$O: sfbmodule.c shadowfb.h
+
+%.$O: ../../Xext/%.c
+	$CC  $CFLAGS -I../xfree86/dixmods/extmod ../../Xext/$stem.c
+
+%.$O: ../../Xi/%.c
+	$CC  $CFLAGS ../../Xi/$stem.c
+
+%.$O: ../../config/%.c
+	$CC  $CFLAGS ../../config/$stem.c
+
+%.$O: ../../dix/%.c
+	$CC  $CFLAGS ../../dix/$stem.c
+
+%.$O: ../../fb/%.c
+	$CC  $CFLAGS ../../fb/$stem.c
+
+%.$O: ../../mi/%.c
+	$CC  $CFLAGS ../../mi/$stem.c
+
+%.$O: ../../miext/damage/%.c
+	$CC  $CFLAGS -I../../miext/cw ../../miext/damage/$stem.c
+
+%.$O: ../../miext/shadow/%.c
+	$CC  $CFLAGS ../../miext/shadow/$stem.c
+
+%.$O: ../../os/%.c
+	$CC  $CFLAGS ../../os/$stem.c
+
+%.$O: ../../render/%.c
+	$CC $CFLAGS ../../render/$stem.c
+
--- /dev/null
+++ b/plan9port.c
@@ -1,0 +1,144 @@
+#include <u.h>
+
+/* Unix headers, then libc.h */
+
+#include <libc.h>
+#include <draw.h>
+
+#include <keyboard.h>
+#include "x9dev.h"
+
+extern void ErrorF(char *, ...);
+extern void FatalError(char *, ...);
+
+x9devInfo x9di;
+
+void
+x9devInfoInit(void)
+{
+    Rectangle r;
+    char    buf[256];
+
+    if(initdraw(NULL, 0, "x9dev") < 0)
+        FatalError("can't open display");
+
+    x9di.depth = screen->depth;
+    x9di.width = Dx(screen->r);
+    x9di.width -= x9di.width&(screen->depth/8);
+    /* TODO: Allow tunable */
+    x9di.dpi = 100;
+    x9di.bpl = bytesperline(Rect(0, 0, x9di.width, x9di.height), x9di.depth);
+    x9di.fb = malloc(x9di.bpl * x9di.height);
+    if (x9di.fb == nil)
+        FatalError("couldn't allocate framebuffer");
+
+    snprint(buf, sizeof buf, "%s/mouse", display->devdir);
+    x9di.mouseFd = open(buf, O_RDWR | O_NONBLOCK);
+    if(x9di.mouseFd < 0)
+        FatalError("can't open mouse");
+
+    snprint(buf, sizeof buf, "%s/cons", display->devdir);
+    x9di.keybdFd = open(buf, O_RDONLY | O_NONBLOCK);
+    if(x9di.keybdFd < 0)
+        FatalError("can't open keyboard");
+
+    snprint(buf, sizeof buf, "%s/consctl", display->devdir);
+    x9di.consctlFd = open(buf, O_WRONLY);
+    if(x9di.consctlFd < 0)
+        FatalError("can't open consctl");
+    if(write(x9di.consctlFd, "rawon", 5) != 5)
+        FatalError("can't set rawon");
+}
+
+void
+x9devRefreshScreen(int x1, int y1, int x2, int y2)
+{
+    Rectangle r;
+    uchar *p;
+    int n;
+
+    p = (uchar *)x9di.fb+(y1*x9di.width+x1)*(x9di.depth/8);
+    r = rectaddpt(Rect(x1, y1, x2, y2), screen->r.min);
+    if (Dx(r) == x9di.width) {
+        if (loadimage(screen, r, p, x9di.bpl * Dy(r)) < 0)
+            FatalError("can't load image");
+        goto End;
+    }
+    n = Dx(r)*(x9di.depth/8);
+    y2 += screen->r.min.y;
+       while(r.min.y < y2) {
+        r.max.y = r.min.y+1;
+        if (loadimage(screen, r, p, n) < 0)
+            FatalError("can't load image");
+        p += x9di.bpl;
+        r.min.y++;
+    }
+
+End:
+    flushimage(display, 1);
+}
+
+static void
+x9devResize(void)
+{
+    if (getwindow(display, Refnone) < 0)
+        FatalError("can't reattach to window");
+
+    draw(screen, screen->r, display->white, nil, ZP);
+    x9devRefreshScreen(0, 0, x9di.width, x9di.height);
+}
+
+int
+x9devMouseRead(int *x, int *y, int *b)
+{
+    char    buf[1+4*12];
+    int n;
+
+    if ((n = read(x9di.mouseFd, buf, sizeof buf)) <= 0)
+        return 0;
+
+    if (n != 1 + 4 * 12)
+        FatalError("Bad mouse event");
+
+    if (buf[0] == 'r') {
+        x9devResize();
+        return 0;
+    }
+    *x = atoi(buf + 1 + 0 * 12) - screen->r.min.x;
+    *y = atoi(buf + 1 + 1 * 12) - screen->r.min.y;
+    *b = atoi(buf + 1 + 2 * 12);
+
+    return 1;
+}
+
+wchar_t
+x9devKeybdRead(void)
+{
+    static char s[3];
+    static int  n = 0;
+    wchar_t rune;
+
+    if (read(x9di.keybdFd, s + n, 1) != 1)
+        return 0;
+
+    rune = s[0];
+    if (n > 0 || (rune & 0x80) != 0x00) {
+        if (mbtowc(&rune, s, n + 1) == -1) {
+            /* incomplete rune; wait until next char */
+            if (++n == 3)
+                n = 0;
+            return 0;
+        }
+        n = 0;
+    }
+    if (rune == Kdel) {
+        ErrorF("delete\n");
+        raise(SIGINT);
+    }
+    if (rune == Kdown)
+        rune = 0x99;
+    else if (rune & KF)
+        rune = (rune&~KF) + 0x80;
+
+    return rune;
+}
\ No newline at end of file
--- /dev/null
+++ b/shadowfb.c
@@ -1,0 +1,171 @@
+/*
+   Copyright (C) 1999.  The XFree86 Project Inc.
+   Copyright 2014 Red Hat, Inc.
+
+   Written by Mark Vojkovich (mvojkovi@ucsd.edu)
+   Pre-fb-write callbacks and RENDER support - Nolan Leake (nolan@vmware.com)
+*/
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include <X11/Xproto.h>
+//#include "misc.h"
+#include "pixmapstr.h"
+#include "input.h"
+#include <X11/fonts/font.h>
+#include "mi.h"
+#include "scrnintstr.h"
+#include "windowstr.h"
+#include "gcstruct.h"
+#include "dixfontstr.h"
+#include <X11/fonts/fontstruct.h>
+#include "xf86.h"
+#include "xf86str.h"
+#include "shadowfb.h"
+
+#include "picturestr.h"
+
+static Bool ShadowCloseScreen(ScreenPtr pScreen);
+static Bool ShadowCreateRootWindow(WindowPtr pWin);
+
+typedef struct {
+    ScrnInfoPtr pScrn;
+    RefreshAreaFuncPtr preRefresh;
+    RefreshAreaFuncPtr postRefresh;
+    CloseScreenProcPtr CloseScreen;
+    CreateWindowProcPtr CreateWindow;
+} ShadowScreenRec, *ShadowScreenPtr;
+
+static DevPrivateKeyRec ShadowScreenKeyRec;
+
+static ShadowScreenPtr
+shadowfbGetScreenPrivate(ScreenPtr pScreen)
+{
+    return dixLookupPrivate(&(pScreen)->devPrivates, &ShadowScreenKeyRec);
+}
+
+Bool
+ShadowFBInit2(ScreenPtr pScreen,
+              RefreshAreaFuncPtr preRefreshArea,
+              RefreshAreaFuncPtr postRefreshArea)
+{
+    ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
+    ShadowScreenPtr pPriv;
+
+    if (!preRefreshArea && !postRefreshArea)
+        return FALSE;
+
+    if (!dixRegisterPrivateKey(&ShadowScreenKeyRec, PRIVATE_SCREEN, 0))
+        return FALSE;
+
+    if (!(pPriv = (ShadowScreenPtr) malloc(sizeof(ShadowScreenRec))))
+        return FALSE;
+
+    dixSetPrivate(&pScreen->devPrivates, &ShadowScreenKeyRec, pPriv);
+
+    pPriv->pScrn = pScrn;
+    pPriv->preRefresh = preRefreshArea;
+    pPriv->postRefresh = postRefreshArea;
+
+    pPriv->CloseScreen = pScreen->CloseScreen;
+    pPriv->CreateWindow = pScreen->CreateWindow;
+
+    pScreen->CloseScreen = ShadowCloseScreen;
+    pScreen->CreateWindow = ShadowCreateRootWindow;
+
+    return TRUE;
+}
+
+Bool
+ShadowFBInit(ScreenPtr pScreen, RefreshAreaFuncPtr refreshArea)
+{
+    return ShadowFBInit2(pScreen, NULL, refreshArea);
+}
+
+/*
+ * Note that we don't do DamageEmpty, or indeed look at the region inside the
+ * DamagePtr at all.  This is an optimization, believe it or not.  The
+ * incoming RegionPtr is the new damage, and if we were to empty the region
+ * miext/damage would just have to waste time reallocating and re-unioning
+ * it every time, whereas if we leave it around the union gets fast-pathed
+ * away.
+ */
+
+static void
+shadowfbReportPre(DamagePtr damage, RegionPtr reg, void *closure)
+{
+    ShadowScreenPtr pPriv = closure;
+
+    if (!pPriv->pScrn->vtSema)
+        return;
+
+    pPriv->preRefresh(pPriv->pScrn, RegionNumRects(reg), RegionRects(reg));
+}
+
+static void
+shadowfbReportPost(DamagePtr damage, RegionPtr reg, void *closure)
+{
+    ShadowScreenPtr pPriv = closure;
+
+    if (!pPriv->pScrn->vtSema)
+        return;
+
+    pPriv->postRefresh(pPriv->pScrn, RegionNumRects(reg), RegionRects(reg));
+}
+
+static Bool
+ShadowCreateRootWindow(WindowPtr pWin)
+{
+    Bool ret;
+    ScreenPtr pScreen = pWin->drawable.pScreen;
+    ShadowScreenPtr pPriv = shadowfbGetScreenPrivate(pScreen);
+
+    /* paranoia */
+    if (pWin != pScreen->root)
+        ErrorF("ShadowCreateRootWindow called unexpectedly\n");
+
+    /* call down, but don't hook ourselves back in; we know the first time
+     * we're called it's for the root window.
+     */
+    pScreen->CreateWindow = pPriv->CreateWindow;
+    ret = pScreen->CreateWindow(pWin);
+
+    /* this might look like it leaks, but the damage code reaps listeners
+     * when their drawable disappears.
+     */
+    if (ret) {
+        DamagePtr damage;
+
+        if (pPriv->preRefresh) {
+            damage = DamageCreate(shadowfbReportPre, NULL,
+                                  DamageReportRawRegion,
+                                  TRUE, pScreen, pPriv);
+            DamageRegister(&pWin->drawable, damage);
+        }
+
+        if (pPriv->postRefresh) {
+            damage = DamageCreate(shadowfbReportPost, NULL,
+                                  DamageReportRawRegion,
+                                  TRUE, pScreen, pPriv);
+            DamageSetReportAfterOp(damage, TRUE);
+            DamageRegister(&pWin->drawable, damage);
+        }
+    }
+
+    return ret;
+}
+
+static Bool
+ShadowCloseScreen(ScreenPtr pScreen)
+{
+    ShadowScreenPtr pPriv = shadowfbGetScreenPrivate(pScreen);
+
+    pScreen->CloseScreen = pPriv->CloseScreen;
+
+    free(pPriv);
+
+    return (*pScreen->CloseScreen) (pScreen);
+}
--- /dev/null
+++ b/shadowfb.h
@@ -1,0 +1,39 @@
+
+#ifndef _SHADOWFB_H
+#define _SHADOWFB_H
+
+#include "xf86str.h"
+
+/*
+ * User defined callback function.  Passed a pointer to the ScrnInfo struct,
+ * the number of dirty rectangles, and a pointer to the first dirty rectangle
+ * in the array.
+ */
+typedef void (*RefreshAreaFuncPtr) (ScrnInfoPtr, int, BoxPtr);
+
+/*
+ * ShadowFBInit initializes the shadowfb subsystem.  refreshArea is a pointer
+ * to a user supplied callback function.  This function will be called after
+ * any operation that modifies the framebuffer.  The newly dirtied rectangles
+ * are passed to the callback.
+ *
+ * Returns FALSE in the event of an error.
+ */
+extern _X_EXPORT Bool
+ ShadowFBInit(ScreenPtr pScreen, RefreshAreaFuncPtr refreshArea);
+
+/*
+ * ShadowFBInit2 is a more featureful refinement of the original shadowfb.
+ * ShadowFBInit2 allows you to specify two callbacks, one to be called
+ * immediately before an operation that modifies the framebuffer, and another
+ * to be called immediately after.
+ *
+ * Returns FALSE in the event of an error
+ */
+extern _X_EXPORT Bool
+
+ShadowFBInit2(ScreenPtr pScreen,
+              RefreshAreaFuncPtr preRefreshArea,
+              RefreshAreaFuncPtr postRefreshArea);
+
+#endif                          /* _SHADOWFB_H */
--- /dev/null
+++ b/x9dev.c
@@ -1,0 +1,540 @@
+/*
+ * Copyright (c) 2008 Federico G. Benavento <benavento@gmail.com>
+ * 
+ * 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 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.
+ */
+
+#include <dix-config.h>
+#include <X11/X.h>
+#define NEED_EVENTS
+#include <X11/Xproto.h>
+#include <X11/Xos.h>
+#include <X11/Xpoll.h>
+#define XK_TECHNICA
+#define XK_PUBLISHING
+#include <X11/keysym.h>
+#include <X11/keysymdef.h>
+#include "scrnintstr.h"
+#include "servermd.h"
+#define PSZ 8
+#include "fb.h"
+#include "colormapst.h"
+#include "gcstruct.h"
+#include "input.h"
+#include "mipointer.h"
+#include "micmap.h"
+#include "dix.h"
+#include "miline.h"
+#include "shadow.h"
+#include "shadowfb.h"
+#include "x9dev.h"
+#include "keymap.h"
+#include "xkbsrv.h"
+#include "xserver-properties.h"
+
+static DeviceIntPtr x9devMouse;
+static DeviceIntPtr x9devKeybd;
+static int  oldx, oldy, oldbut;
+
+static KeySymsRec keysyms = {
+    map,    MIN_KEYCODE,    MAX_KEYCODE,    MAP_WIDTH
+};
+
+
+static CARD8 modmap[MAP_LENGTH];
+
+static PixmapFormatRec formats[] = {
+    { 1,    1,  BITMAP_SCANLINE_PAD },
+    { 8,    8,  BITMAP_SCANLINE_PAD },
+    { 16,   16,     BITMAP_SCANLINE_PAD },
+    { 24,   24,     BITMAP_SCANLINE_PAD },
+    { 32,   32,     BITMAP_SCANLINE_PAD }
+};
+#define NUMFORMATS (sizeof(formats)/sizeof((formats)[0]))
+
+#define x9devSaveScreen (void *) NoopDDA
+#define x9devConstrainCursor    (void *) NoopDDA
+#define x9devDisplayCursor  (void *) NoopDDA
+#define x9devRealizeCursor  (void *) NoopDDA
+#define x9devUnrealizeCursor    (void *) NoopDDA
+#define x9devRecolorCursor  (void *) NoopDDA
+#define x9devSetCursorPosition  (void *) NoopDDA
+
+void
+OsVendorInit(void)
+{
+    char temp[] = "/tmp/x9dev.XXXXXX";
+    LogInit(mktemp(temp), NULL);
+}
+
+void
+ddxGiveUp(enum ExitCode error)
+{
+}
+
+
+void
+AbortDDX(enum ExitCode error)
+{
+    ;
+}
+
+
+/* we may need to do some weird stuff here in the future */
+#if defined(DDXBEFORERESET)
+void
+ddxBeforeReset(void)
+{
+}
+#endif
+
+
+void
+ddxUseMsg(void)
+{
+}
+
+
+void
+ddxInitGlobals(void)
+{
+    whiteRoot = TRUE;
+    dispatchExceptionAtReset = FALSE;
+}
+
+
+void
+DDXRingBell(int volume, int pitch, int duration)
+{
+}
+
+
+int
+ddxProcessArgument(int argc, char *argv[], int i)
+{
+    return 0;
+}
+
+
+Bool
+LegalModifier(unsigned int k, DeviceIntPtr pDev)
+{
+    return modmap[k] != 0;
+}
+
+
+void
+ProcessInputEvents(void)
+{
+    mieqProcessInputEvents();
+}
+
+
+#define e    ev.u.u
+#define ek    ev.u.keyButtonPointer
+static void
+x9devSendKeybdEvent(int k, int t)
+{
+    xEvent ev;
+
+    memset(&ev, 0, sizeof(xEvent));
+    e.type = t;
+    e.detail = k + MIN_KEYCODE;
+    ek.time = GetTimeInMillis();
+    mieqEnqueue(x9devKeybd, (InternalEvent *)&ev);
+}
+
+static void
+x9devSendMouseEvent(int x, int y, int b, int t)
+{
+    xEvent ev;
+
+    memset(&ev, 0, sizeof(xEvent));
+    e.type = t;
+    e.detail = b;
+    ek.rootX = x;
+    ek.rootY = y;
+    ek.time = GetTimeInMillis();
+    mieqEnqueue(x9devMouse, (InternalEvent *)&ev);
+}
+#undef ek
+#undef e
+
+
+static int  
+x9devKeybdHandle(void)
+{
+    unsigned char   k, m;
+    int c;
+
+    c = x9devKeybdRead();
+    if (c == 0 || c > sizeof(rune2keycode))
+        return 0;
+
+    k = rune2keycode[c].key;
+    if (k == 0)
+        return 0;
+
+    m = rune2keycode[c].mod;
+    if (m) 
+        x9devSendKeybdEvent(m, KeyPress);
+
+    x9devSendKeybdEvent(k, KeyPress);
+    x9devSendKeybdEvent(k, KeyRelease);
+    if (m) 
+        x9devSendKeybdEvent(m, KeyRelease);
+
+    return 1;
+}
+
+
+static int  
+x9devMouseHandle(void)
+{
+    int x, y, b, but, t;
+
+    if (!x9devMouseRead(&x, &y, &but))
+        return 0;
+
+    t = b = 0;
+    if (x != oldx || y != oldy) {
+        t = MotionNotify;
+        oldx = x, oldy = y;
+    }
+    if (but != oldbut) {
+        b = oldbut ^ but;
+        t = ButtonPress;
+        if (oldbut & b)
+            t = ButtonRelease;
+        if (b == 4)
+            b = 3;
+        if (but & (8 | 16)) {
+            if (b & 8)
+                b = 4;
+            else
+                b = 5;
+            x9devSendMouseEvent(x, y, b, ButtonPress);
+            x9devSendMouseEvent(x, y, b, ButtonRelease);
+            return 1;
+        }
+    }
+    x9devSendMouseEvent(x, y, b, t);
+    oldbut = but;
+
+    return 1;
+}
+
+
+extern fd_set EnabledDevices, LastSelectMask;
+
+static void
+x9devWakeupHandler(int index, pointer blockData, unsigned long result, pointer pReadmask)
+{
+
+    fd_set fs;
+
+    if (result <= 0)
+        return;
+
+    XFD_ANDSET(&fs, &LastSelectMask, &EnabledDevices);
+    if (!XFD_ANYSET(&fs))
+        return;
+
+    while (x9devMouseHandle())
+        ;
+    while (x9devKeybdHandle())
+        ;
+}
+
+
+static void
+x9devInitModmap(void)
+{
+    KeySym * ks;
+    int i;
+
+    for (i = 0; i < MAP_LENGTH; i++)
+        modmap[i] = NoSymbol;
+
+    for (i = MIN_KEYCODE, ks = map; i < (MIN_KEYCODE + NUM_KEYCODES); i++, ks += MAP_WIDTH)
+        switch (*ks) {
+        case XK_Shift_L:
+        case XK_Shift_R:
+            modmap[i] = ShiftMask;
+            break;
+        case XK_Control_L:
+        case XK_Control_R:
+            modmap[i] = ControlMask;
+            break;
+        case XK_Alt_L:
+        case XK_Alt_R:
+            modmap[i] = Mod1Mask;
+            break;
+        }
+}
+
+
+static int  
+x9devKeybdProc(DeviceIntPtr pDevice, int what)
+{
+    DevicePtr pDev = (DevicePtr)pDevice;
+
+    switch (what) {
+    case DEVICE_INIT:
+        x9devInitModmap();
+        /* The middle two need to go away to an Xkb call */
+        //if (!InitKeyboardDeviceStruct(pDev, &keysyms, modmap, 
+        if(!InitKeyboardDeviceStruct(pDev, NULL,
+            (BellProcPtr)NoopDDA, (KbdCtrlProcPtr)NoopDDA))
+            FatalError("can't init keyboard");
+        break;
+
+    case DEVICE_ON:
+        pDev->on = TRUE;
+        AddEnabledDevice(x9di.keybdFd);
+        break;
+
+    case DEVICE_CLOSE:
+    case DEVICE_OFF:
+        pDev->on = FALSE;
+        RemoveEnabledDevice(x9di.keybdFd);
+        break;
+    }
+    return Success;
+}
+
+
+static int  
+x9devMouseProc(DeviceIntPtr pDevice, int what)
+{
+    static unsigned char    map[] = {0, 1, 2, 3, 4, 5};
+    DevicePtr pDev = (DevicePtr)pDevice;
+    Atom btn_labels[3] = {0};
+    Atom axes_labels[2] = {0};
+
+    btn_labels[0] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_LEFT);
+    btn_labels[1] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_MIDDLE);
+    btn_labels[2] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_RIGHT);
+
+    axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_X);
+    axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_Y);
+
+    switch (what) {
+    case DEVICE_INIT:
+        InitPointerDeviceStruct(pDev, map, 3, btn_labels,
+            (PtrCtrlProcPtr)NoopDDA, GetMotionHistorySize(), 2, axes_labels);
+        break;
+
+    case DEVICE_ON:
+        pDev->on = TRUE;
+        AddEnabledDevice(x9di.mouseFd);
+        break;
+
+    case DEVICE_CLOSE:
+    case DEVICE_OFF:
+        pDev->on = FALSE;
+        RemoveEnabledDevice(x9di.mouseFd);
+        break;
+    }
+    return Success;
+}
+
+
+void
+InitInput(int argc, char *argv[])
+{
+    x9devMouse = AddInputDevice(serverClient, x9devMouseProc, TRUE);
+    RegisterPointerDevice(x9devMouse);
+    x9devKeybd = AddInputDevice(serverClient, x9devKeybdProc, TRUE);
+    RegisterKeyboardDevice(x9devKeybd);
+    mieqInit();
+}
+
+
+static void
+x9devCursorLimits(ScreenPtr spr, CursorPtr cpr, BoxPtr hot, BoxPtr topleft)
+{
+    *topleft = *hot;
+}
+
+
+#ifdef SHADOWFB
+static void
+x9devRefreshArea(ScrnInfoPtr ptr, int nbox, BoxPtr pbox)
+{
+    int x1, y1, x2, y2;
+
+    if(nbox <= 0)
+        return;
+
+    x1 = y1 = 100000;
+    x2 = y2 = -100000;
+    while(nbox--) {
+        if(x1 > pbox->x1)
+            x1 = pbox->x1;
+        if(y1 > pbox->y1)
+            y1 = pbox->y1;
+        if(x2 < pbox->x2)
+            x2 = pbox->x2;
+        if(y2 < pbox->y2)
+            y2 = pbox->y2;
+        pbox++;
+    }
+    x9devRefreshScreen(x1, y1, x2, y2);
+}
+
+
+#else
+
+
+static void
+x9devShadowUpdate(ScreenPtr pScreen, shadowBufPtr pBuf)
+{
+    BoxPtr pbox;
+
+    pbox = REGION_EXTENTS(pScreen, &pBuf->damage);
+    x9devRefreshScreen(pbox->x1, pbox->y1, pbox->x2, pbox->y2);
+}
+
+
+/* callback dance... */
+static CreateScreenResourcesProcPtr x9devCreateResourcesPtr;
+
+static Bool
+x9devCreateResources(ScreenPtr pScreen)
+{
+    Bool ret;
+
+    pScreen->CreateScreenResources = x9devCreateResourcesPtr;
+    if (pScreen->CreateScreenResources)
+        ret = pScreen->CreateScreenResources(pScreen);
+
+    x9devCreateResourcesPtr = pScreen->CreateScreenResources;
+    pScreen->CreateScreenResources = x9devCreateResourcesPtr;
+    if (ret == FALSE)
+        return FALSE;
+
+    shadowRemove(pScreen, pScreen->GetScreenPixmap(pScreen));
+    if (!shadowAdd(pScreen, pScreen->GetScreenPixmap(pScreen), x9devShadowUpdate, NULL, SHADOW_ROTATE_0, 0))
+        return FALSE;
+
+    return ret;
+}
+
+
+#endif
+
+
+
+static Bool
+x9devScreenInit(int index, ScreenPtr pScreen, int argc, char *argv[])
+{
+    int v, i;
+    unsigned long   r, g, b;
+    static int  first = 1;
+
+    assert(index == 0);
+    if (first) {
+        x9devInfoInit();
+        first = 0;
+    }
+
+    for (i = 0; i < NUMFORMATS; i++)
+        fbSetVisualTypes(formats[i].depth, 0, 8);
+
+    switch (x9di.depth) {
+    case 16:
+        r = 0xF800, g = 0x07E0, b = 0x001F;
+        v = 1 << TrueColor;
+        break;
+    case 24:
+    case 32:
+        r = 0xFF0000, g = 0x00FF00, b = 0x0000FF;
+        v = 1 << TrueColor;
+        break;
+    default:
+        r = g = b = 0;
+        v = 1 << PseudoColor;
+    }
+    if (!fbSetVisualTypesAndMasks(x9di.depth, v, 8, r, g, b))
+        return FALSE;
+
+    if (monitorResolution)
+        x9di.dpi = monitorResolution;
+    if (!fbScreenInit(pScreen, x9di.fb, x9di.width, x9di.height,
+        x9di.dpi, x9di.dpi, x9di.width, x9di.depth))
+        return FALSE;
+
+    pScreen->mmWidth = x9di.width * 25.4 / x9di.dpi;
+    pScreen->mmHeight = x9di.height * 25.4 / x9di.dpi;
+
+    /* cursor */
+    pScreen->ConstrainCursor = x9devConstrainCursor;
+    pScreen->CursorLimits = x9devCursorLimits;
+    pScreen->DisplayCursor = x9devDisplayCursor;
+    pScreen->RealizeCursor = x9devRealizeCursor;
+    pScreen->UnrealizeCursor = x9devUnrealizeCursor;
+    pScreen->RecolorCursor = x9devRecolorCursor;
+    pScreen->SetCursorPosition = x9devSetCursorPosition;
+
+    pScreen->SaveScreen = x9devSaveScreen;
+    pScreen->WakeupHandler = x9devWakeupHandler;
+
+#ifdef RENDER
+    if (!fbPictureInit(pScreen, 0, 0))
+        return FALSE;
+#endif
+
+    miInitializeBackingStore(pScreen);
+
+#ifdef SHADOWFB
+   if (!ShadowFBInit(pScreen, x9devRefreshArea))
+        return FALSE;
+#else
+   if (!shadowSetup(pScreen))
+        return FALSE;
+
+    x9devCreateResourcesPtr = pScreen->CreateScreenResources;
+    pScreen->CreateScreenResources = x9devCreateResources;
+#endif
+
+    if (!fbCreateDefColormap(pScreen))
+        return FALSE;
+
+    return TRUE;
+}
+
+
+void
+InitOutput(ScreenInfo *screenInfo, int argc, char *argv[])
+{
+    int i;
+
+    screenInfo->imageByteOrder = IMAGE_BYTE_ORDER;
+    screenInfo->bitmapScanlineUnit = BITMAP_SCANLINE_UNIT;
+    screenInfo->bitmapScanlinePad = BITMAP_SCANLINE_PAD;
+    screenInfo->bitmapBitOrder = BITMAP_BIT_ORDER;
+    screenInfo->numPixmapFormats = NUMFORMATS;
+    for (i = 0; i < NUMFORMATS; i++)
+        screenInfo->formats[i] = formats[i];
+    if (AddScreen(x9devScreenInit, argc, argv) < 0)
+        FatalError("InitOutput: can't addscreen");
+}
+
--- /dev/null
+++ b/x9dev.h
@@ -1,0 +1,45 @@
+/*
+ * Copyright (c) 2008 Federico G. Benavento <benavento@gmail.com>
+ * 
+ * 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 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.
+ */
+
+typedef struct x9devInfo x9devInfo;
+
+struct x9devInfo
+{
+    char    *fb;
+    int depth;
+    int width;
+    int height;
+    int dpi;
+    int bpl;
+    int mouseFd;
+    int keybdFd;
+    int consctlFd;
+};
+
+extern x9devInfo x9di;
+
+void    x9devInfoInit(void);
+void    x9devRefreshScreen(int, int, int, int);
+int x9devMouseRead(int *, int *, int *);
+wchar_t x9devKeybdRead(void);
+