#![allow(unused_unsafe)]
use base;
use ffi::base::*;
use ffi::xproto::*;
use libc::{self, c_char, c_int, c_uint, c_void};
use std;
use std::iter::Iterator;
pub type Window = xcb_window_t;
pub type Pixmap = xcb_pixmap_t;
pub type Cursor = xcb_cursor_t;
pub type Font = xcb_font_t;
pub type Gcontext = xcb_gcontext_t;
pub type Colormap = xcb_colormap_t;
pub type Atom = xcb_atom_t;
pub type Drawable = xcb_drawable_t;
pub type Fontable = xcb_fontable_t;
pub type Visualid = xcb_visualid_t;
pub type Timestamp = xcb_timestamp_t;
pub type Keysym = xcb_keysym_t;
pub type Keycode = xcb_keycode_t;
pub type Button = xcb_button_t;
pub type VisualClass = u32;
pub const VISUAL_CLASS_STATIC_GRAY : VisualClass = 0x00;
pub const VISUAL_CLASS_GRAY_SCALE  : VisualClass = 0x01;
pub const VISUAL_CLASS_STATIC_COLOR: VisualClass = 0x02;
pub const VISUAL_CLASS_PSEUDO_COLOR: VisualClass = 0x03;
pub const VISUAL_CLASS_TRUE_COLOR  : VisualClass = 0x04;
pub const VISUAL_CLASS_DIRECT_COLOR: VisualClass = 0x05;
pub type EventMask = u32;
pub const EVENT_MASK_NO_EVENT             : EventMask =      0x00;
pub const EVENT_MASK_KEY_PRESS            : EventMask =      0x01;
pub const EVENT_MASK_KEY_RELEASE          : EventMask =      0x02;
pub const EVENT_MASK_BUTTON_PRESS         : EventMask =      0x04;
pub const EVENT_MASK_BUTTON_RELEASE       : EventMask =      0x08;
pub const EVENT_MASK_ENTER_WINDOW         : EventMask =      0x10;
pub const EVENT_MASK_LEAVE_WINDOW         : EventMask =      0x20;
pub const EVENT_MASK_POINTER_MOTION       : EventMask =      0x40;
pub const EVENT_MASK_POINTER_MOTION_HINT  : EventMask =      0x80;
pub const EVENT_MASK_BUTTON_1_MOTION      : EventMask =     0x100;
pub const EVENT_MASK_BUTTON_2_MOTION      : EventMask =     0x200;
pub const EVENT_MASK_BUTTON_3_MOTION      : EventMask =     0x400;
pub const EVENT_MASK_BUTTON_4_MOTION      : EventMask =     0x800;
pub const EVENT_MASK_BUTTON_5_MOTION      : EventMask =    0x1000;
pub const EVENT_MASK_BUTTON_MOTION        : EventMask =    0x2000;
pub const EVENT_MASK_KEYMAP_STATE         : EventMask =    0x4000;
pub const EVENT_MASK_EXPOSURE             : EventMask =    0x8000;
pub const EVENT_MASK_VISIBILITY_CHANGE    : EventMask =   0x10000;
pub const EVENT_MASK_STRUCTURE_NOTIFY     : EventMask =   0x20000;
pub const EVENT_MASK_RESIZE_REDIRECT      : EventMask =   0x40000;
pub const EVENT_MASK_SUBSTRUCTURE_NOTIFY  : EventMask =   0x80000;
pub const EVENT_MASK_SUBSTRUCTURE_REDIRECT: EventMask =  0x100000;
pub const EVENT_MASK_FOCUS_CHANGE         : EventMask =  0x200000;
pub const EVENT_MASK_PROPERTY_CHANGE      : EventMask =  0x400000;
pub const EVENT_MASK_COLOR_MAP_CHANGE     : EventMask =  0x800000;
pub const EVENT_MASK_OWNER_GRAB_BUTTON    : EventMask = 0x1000000;
pub type BackingStore = u32;
pub const BACKING_STORE_NOT_USEFUL : BackingStore = 0x00;
pub const BACKING_STORE_WHEN_MAPPED: BackingStore = 0x01;
pub const BACKING_STORE_ALWAYS     : BackingStore = 0x02;
pub type ImageOrder = u32;
pub const IMAGE_ORDER_LSB_FIRST: ImageOrder = 0x00;
pub const IMAGE_ORDER_MSB_FIRST: ImageOrder = 0x01;
pub type ModMask = u32;
pub const MOD_MASK_SHIFT  : ModMask =   0x01;
pub const MOD_MASK_LOCK   : ModMask =   0x02;
pub const MOD_MASK_CONTROL: ModMask =   0x04;
pub const MOD_MASK_1      : ModMask =   0x08;
pub const MOD_MASK_2      : ModMask =   0x10;
pub const MOD_MASK_3      : ModMask =   0x20;
pub const MOD_MASK_4      : ModMask =   0x40;
pub const MOD_MASK_5      : ModMask =   0x80;
pub const MOD_MASK_ANY    : ModMask = 0x8000;
pub type KeyButMask = u32;
pub const KEY_BUT_MASK_SHIFT   : KeyButMask =   0x01;
pub const KEY_BUT_MASK_LOCK    : KeyButMask =   0x02;
pub const KEY_BUT_MASK_CONTROL : KeyButMask =   0x04;
pub const KEY_BUT_MASK_MOD_1   : KeyButMask =   0x08;
pub const KEY_BUT_MASK_MOD_2   : KeyButMask =   0x10;
pub const KEY_BUT_MASK_MOD_3   : KeyButMask =   0x20;
pub const KEY_BUT_MASK_MOD_4   : KeyButMask =   0x40;
pub const KEY_BUT_MASK_MOD_5   : KeyButMask =   0x80;
pub const KEY_BUT_MASK_BUTTON_1: KeyButMask =  0x100;
pub const KEY_BUT_MASK_BUTTON_2: KeyButMask =  0x200;
pub const KEY_BUT_MASK_BUTTON_3: KeyButMask =  0x400;
pub const KEY_BUT_MASK_BUTTON_4: KeyButMask =  0x800;
pub const KEY_BUT_MASK_BUTTON_5: KeyButMask = 0x1000;
pub type WindowEnum = u32;
pub const WINDOW_NONE: WindowEnum = 0x00;
pub type ButtonMask = u32;
pub const BUTTON_MASK_1  : ButtonMask =  0x100;
pub const BUTTON_MASK_2  : ButtonMask =  0x200;
pub const BUTTON_MASK_3  : ButtonMask =  0x400;
pub const BUTTON_MASK_4  : ButtonMask =  0x800;
pub const BUTTON_MASK_5  : ButtonMask = 0x1000;
pub const BUTTON_MASK_ANY: ButtonMask = 0x8000;
pub type Motion = u32;
pub const MOTION_NORMAL: Motion = 0x00;
pub const MOTION_HINT  : Motion = 0x01;
pub type NotifyDetail = u32;
pub const NOTIFY_DETAIL_ANCESTOR         : NotifyDetail = 0x00;
pub const NOTIFY_DETAIL_VIRTUAL          : NotifyDetail = 0x01;
pub const NOTIFY_DETAIL_INFERIOR         : NotifyDetail = 0x02;
pub const NOTIFY_DETAIL_NONLINEAR        : NotifyDetail = 0x03;
pub const NOTIFY_DETAIL_NONLINEAR_VIRTUAL: NotifyDetail = 0x04;
pub const NOTIFY_DETAIL_POINTER          : NotifyDetail = 0x05;
pub const NOTIFY_DETAIL_POINTER_ROOT     : NotifyDetail = 0x06;
pub const NOTIFY_DETAIL_NONE             : NotifyDetail = 0x07;
pub type NotifyMode = u32;
pub const NOTIFY_MODE_NORMAL       : NotifyMode = 0x00;
pub const NOTIFY_MODE_GRAB         : NotifyMode = 0x01;
pub const NOTIFY_MODE_UNGRAB       : NotifyMode = 0x02;
pub const NOTIFY_MODE_WHILE_GRABBED: NotifyMode = 0x03;
pub type Visibility = u32;
pub const VISIBILITY_UNOBSCURED        : Visibility = 0x00;
pub const VISIBILITY_PARTIALLY_OBSCURED: Visibility = 0x01;
pub const VISIBILITY_FULLY_OBSCURED    : Visibility = 0x02;
pub type Place = u32;
pub const PLACE_ON_TOP   : Place = 0x00;
pub const PLACE_ON_BOTTOM: Place = 0x01;
pub type Property = u32;
pub const PROPERTY_NEW_VALUE: Property = 0x00;
pub const PROPERTY_DELETE   : Property = 0x01;
pub type Time = u32;
pub const TIME_CURRENT_TIME: Time = 0x00;
pub type AtomEnum = u32;
pub const ATOM_NONE               : AtomEnum = 0x00;
pub const ATOM_ANY                : AtomEnum = 0x00;
pub const ATOM_PRIMARY            : AtomEnum = 0x01;
pub const ATOM_SECONDARY          : AtomEnum = 0x02;
pub const ATOM_ARC                : AtomEnum = 0x03;
pub const ATOM_ATOM               : AtomEnum = 0x04;
pub const ATOM_BITMAP             : AtomEnum = 0x05;
pub const ATOM_CARDINAL           : AtomEnum = 0x06;
pub const ATOM_COLORMAP           : AtomEnum = 0x07;
pub const ATOM_CURSOR             : AtomEnum = 0x08;
pub const ATOM_CUT_BUFFER0        : AtomEnum = 0x09;
pub const ATOM_CUT_BUFFER1        : AtomEnum = 0x0a;
pub const ATOM_CUT_BUFFER2        : AtomEnum = 0x0b;
pub const ATOM_CUT_BUFFER3        : AtomEnum = 0x0c;
pub const ATOM_CUT_BUFFER4        : AtomEnum = 0x0d;
pub const ATOM_CUT_BUFFER5        : AtomEnum = 0x0e;
pub const ATOM_CUT_BUFFER6        : AtomEnum = 0x0f;
pub const ATOM_CUT_BUFFER7        : AtomEnum = 0x10;
pub const ATOM_DRAWABLE           : AtomEnum = 0x11;
pub const ATOM_FONT               : AtomEnum = 0x12;
pub const ATOM_INTEGER            : AtomEnum = 0x13;
pub const ATOM_PIXMAP             : AtomEnum = 0x14;
pub const ATOM_POINT              : AtomEnum = 0x15;
pub const ATOM_RECTANGLE          : AtomEnum = 0x16;
pub const ATOM_RESOURCE_MANAGER   : AtomEnum = 0x17;
pub const ATOM_RGB_COLOR_MAP      : AtomEnum = 0x18;
pub const ATOM_RGB_BEST_MAP       : AtomEnum = 0x19;
pub const ATOM_RGB_BLUE_MAP       : AtomEnum = 0x1a;
pub const ATOM_RGB_DEFAULT_MAP    : AtomEnum = 0x1b;
pub const ATOM_RGB_GRAY_MAP       : AtomEnum = 0x1c;
pub const ATOM_RGB_GREEN_MAP      : AtomEnum = 0x1d;
pub const ATOM_RGB_RED_MAP        : AtomEnum = 0x1e;
pub const ATOM_STRING             : AtomEnum = 0x1f;
pub const ATOM_VISUALID           : AtomEnum = 0x20;
pub const ATOM_WINDOW             : AtomEnum = 0x21;
pub const ATOM_WM_COMMAND         : AtomEnum = 0x22;
pub const ATOM_WM_HINTS           : AtomEnum = 0x23;
pub const ATOM_WM_CLIENT_MACHINE  : AtomEnum = 0x24;
pub const ATOM_WM_ICON_NAME       : AtomEnum = 0x25;
pub const ATOM_WM_ICON_SIZE       : AtomEnum = 0x26;
pub const ATOM_WM_NAME            : AtomEnum = 0x27;
pub const ATOM_WM_NORMAL_HINTS    : AtomEnum = 0x28;
pub const ATOM_WM_SIZE_HINTS      : AtomEnum = 0x29;
pub const ATOM_WM_ZOOM_HINTS      : AtomEnum = 0x2a;
pub const ATOM_MIN_SPACE          : AtomEnum = 0x2b;
pub const ATOM_NORM_SPACE         : AtomEnum = 0x2c;
pub const ATOM_MAX_SPACE          : AtomEnum = 0x2d;
pub const ATOM_END_SPACE          : AtomEnum = 0x2e;
pub const ATOM_SUPERSCRIPT_X      : AtomEnum = 0x2f;
pub const ATOM_SUPERSCRIPT_Y      : AtomEnum = 0x30;
pub const ATOM_SUBSCRIPT_X        : AtomEnum = 0x31;
pub const ATOM_SUBSCRIPT_Y        : AtomEnum = 0x32;
pub const ATOM_UNDERLINE_POSITION : AtomEnum = 0x33;
pub const ATOM_UNDERLINE_THICKNESS: AtomEnum = 0x34;
pub const ATOM_STRIKEOUT_ASCENT   : AtomEnum = 0x35;
pub const ATOM_STRIKEOUT_DESCENT  : AtomEnum = 0x36;
pub const ATOM_ITALIC_ANGLE       : AtomEnum = 0x37;
pub const ATOM_X_HEIGHT           : AtomEnum = 0x38;
pub const ATOM_QUAD_WIDTH         : AtomEnum = 0x39;
pub const ATOM_WEIGHT             : AtomEnum = 0x3a;
pub const ATOM_POINT_SIZE         : AtomEnum = 0x3b;
pub const ATOM_RESOLUTION         : AtomEnum = 0x3c;
pub const ATOM_COPYRIGHT          : AtomEnum = 0x3d;
pub const ATOM_NOTICE             : AtomEnum = 0x3e;
pub const ATOM_FONT_NAME          : AtomEnum = 0x3f;
pub const ATOM_FAMILY_NAME        : AtomEnum = 0x40;
pub const ATOM_FULL_NAME          : AtomEnum = 0x41;
pub const ATOM_CAP_HEIGHT         : AtomEnum = 0x42;
pub const ATOM_WM_CLASS           : AtomEnum = 0x43;
pub const ATOM_WM_TRANSIENT_FOR   : AtomEnum = 0x44;
pub type ColormapState = u32;
pub const COLORMAP_STATE_UNINSTALLED: ColormapState = 0x00;
pub const COLORMAP_STATE_INSTALLED  : ColormapState = 0x01;
pub type ColormapEnum = u32;
pub const COLORMAP_NONE: ColormapEnum = 0x00;
pub type Mapping = u32;
pub const MAPPING_MODIFIER: Mapping = 0x00;
pub const MAPPING_KEYBOARD: Mapping = 0x01;
pub const MAPPING_POINTER : Mapping = 0x02;
pub struct RequestError {
    pub base: base::Error<xcb_request_error_t>
}
pub struct ValueError {
    pub base: base::Error<xcb_value_error_t>
}
pub struct WindowError {
    pub base: base::Error<xcb_window_error_t>
}
pub struct PixmapError {
    pub base: base::Error<xcb_pixmap_error_t>
}
pub struct AtomError {
    pub base: base::Error<xcb_atom_error_t>
}
pub struct CursorError {
    pub base: base::Error<xcb_cursor_error_t>
}
pub struct FontError {
    pub base: base::Error<xcb_font_error_t>
}
pub struct MatchError {
    pub base: base::Error<xcb_match_error_t>
}
pub struct DrawableError {
    pub base: base::Error<xcb_drawable_error_t>
}
pub struct AccessError {
    pub base: base::Error<xcb_access_error_t>
}
pub struct AllocError {
    pub base: base::Error<xcb_alloc_error_t>
}
pub struct ColormapError {
    pub base: base::Error<xcb_colormap_error_t>
}
pub struct GContextError {
    pub base: base::Error<xcb_g_context_error_t>
}
pub struct IdChoiceError {
    pub base: base::Error<xcb_id_choice_error_t>
}
pub struct NameError {
    pub base: base::Error<xcb_name_error_t>
}
pub struct LengthError {
    pub base: base::Error<xcb_length_error_t>
}
pub struct ImplementationError {
    pub base: base::Error<xcb_implementation_error_t>
}
pub type WindowClass = u32;
pub const WINDOW_CLASS_COPY_FROM_PARENT: WindowClass = 0x00;
pub const WINDOW_CLASS_INPUT_OUTPUT    : WindowClass = 0x01;
pub const WINDOW_CLASS_INPUT_ONLY      : WindowClass = 0x02;
pub type Cw = u32;
pub const CW_BACK_PIXMAP      : Cw =   0x01;
pub const CW_BACK_PIXEL       : Cw =   0x02;
pub const CW_BORDER_PIXMAP    : Cw =   0x04;
pub const CW_BORDER_PIXEL     : Cw =   0x08;
pub const CW_BIT_GRAVITY      : Cw =   0x10;
pub const CW_WIN_GRAVITY      : Cw =   0x20;
pub const CW_BACKING_STORE    : Cw =   0x40;
pub const CW_BACKING_PLANES   : Cw =   0x80;
pub const CW_BACKING_PIXEL    : Cw =  0x100;
pub const CW_OVERRIDE_REDIRECT: Cw =  0x200;
pub const CW_SAVE_UNDER       : Cw =  0x400;
pub const CW_EVENT_MASK       : Cw =  0x800;
pub const CW_DONT_PROPAGATE   : Cw = 0x1000;
pub const CW_COLORMAP         : Cw = 0x2000;
pub const CW_CURSOR           : Cw = 0x4000;
pub type BackPixmap = u32;
pub const BACK_PIXMAP_NONE           : BackPixmap = 0x00;
pub const BACK_PIXMAP_PARENT_RELATIVE: BackPixmap = 0x01;
pub type Gravity = u32;
pub const GRAVITY_BIT_FORGET: Gravity = 0x00;
pub const GRAVITY_WIN_UNMAP : Gravity = 0x00;
pub const GRAVITY_NORTH_WEST: Gravity = 0x01;
pub const GRAVITY_NORTH     : Gravity = 0x02;
pub const GRAVITY_NORTH_EAST: Gravity = 0x03;
pub const GRAVITY_WEST      : Gravity = 0x04;
pub const GRAVITY_CENTER    : Gravity = 0x05;
pub const GRAVITY_EAST      : Gravity = 0x06;
pub const GRAVITY_SOUTH_WEST: Gravity = 0x07;
pub const GRAVITY_SOUTH     : Gravity = 0x08;
pub const GRAVITY_SOUTH_EAST: Gravity = 0x09;
pub const GRAVITY_STATIC    : Gravity = 0x0a;
pub type MapState = u32;
pub const MAP_STATE_UNMAPPED  : MapState = 0x00;
pub const MAP_STATE_UNVIEWABLE: MapState = 0x01;
pub const MAP_STATE_VIEWABLE  : MapState = 0x02;
pub type SetMode = u32;
pub const SET_MODE_INSERT: SetMode = 0x00;
pub const SET_MODE_DELETE: SetMode = 0x01;
pub type ConfigWindow = u32;
pub const CONFIG_WINDOW_X           : ConfigWindow = 0x01;
pub const CONFIG_WINDOW_Y           : ConfigWindow = 0x02;
pub const CONFIG_WINDOW_WIDTH       : ConfigWindow = 0x04;
pub const CONFIG_WINDOW_HEIGHT      : ConfigWindow = 0x08;
pub const CONFIG_WINDOW_BORDER_WIDTH: ConfigWindow = 0x10;
pub const CONFIG_WINDOW_SIBLING     : ConfigWindow = 0x20;
pub const CONFIG_WINDOW_STACK_MODE  : ConfigWindow = 0x40;
pub type StackMode = u32;
pub const STACK_MODE_ABOVE    : StackMode = 0x00;
pub const STACK_MODE_BELOW    : StackMode = 0x01;
pub const STACK_MODE_TOP_IF   : StackMode = 0x02;
pub const STACK_MODE_BOTTOM_IF: StackMode = 0x03;
pub const STACK_MODE_OPPOSITE : StackMode = 0x04;
pub type Circulate = u32;
pub const CIRCULATE_RAISE_LOWEST : Circulate = 0x00;
pub const CIRCULATE_LOWER_HIGHEST: Circulate = 0x01;
pub type PropMode = u32;
pub const PROP_MODE_REPLACE: PropMode = 0x00;
pub const PROP_MODE_PREPEND: PropMode = 0x01;
pub const PROP_MODE_APPEND : PropMode = 0x02;
pub type GetPropertyType = u32;
pub const GET_PROPERTY_TYPE_ANY: GetPropertyType = 0x00;
pub type SendEventDest = u32;
pub const SEND_EVENT_DEST_POINTER_WINDOW: SendEventDest = 0x00;
pub const SEND_EVENT_DEST_ITEM_FOCUS    : SendEventDest = 0x01;
pub type GrabMode = u32;
pub const GRAB_MODE_SYNC : GrabMode = 0x00;
pub const GRAB_MODE_ASYNC: GrabMode = 0x01;
pub type GrabStatus = u32;
pub const GRAB_STATUS_SUCCESS        : GrabStatus = 0x00;
pub const GRAB_STATUS_ALREADY_GRABBED: GrabStatus = 0x01;
pub const GRAB_STATUS_INVALID_TIME   : GrabStatus = 0x02;
pub const GRAB_STATUS_NOT_VIEWABLE   : GrabStatus = 0x03;
pub const GRAB_STATUS_FROZEN         : GrabStatus = 0x04;
pub type CursorEnum = u32;
pub const CURSOR_NONE: CursorEnum = 0x00;
pub type ButtonIndex = u32;
pub const BUTTON_INDEX_ANY: ButtonIndex = 0x00;
pub const BUTTON_INDEX_1  : ButtonIndex = 0x01;
pub const BUTTON_INDEX_2  : ButtonIndex = 0x02;
pub const BUTTON_INDEX_3  : ButtonIndex = 0x03;
pub const BUTTON_INDEX_4  : ButtonIndex = 0x04;
pub const BUTTON_INDEX_5  : ButtonIndex = 0x05;
pub type Grab = u32;
pub const GRAB_ANY: Grab = 0x00;
pub type Allow = u32;
pub const ALLOW_ASYNC_POINTER  : Allow = 0x00;
pub const ALLOW_SYNC_POINTER   : Allow = 0x01;
pub const ALLOW_REPLAY_POINTER : Allow = 0x02;
pub const ALLOW_ASYNC_KEYBOARD : Allow = 0x03;
pub const ALLOW_SYNC_KEYBOARD  : Allow = 0x04;
pub const ALLOW_REPLAY_KEYBOARD: Allow = 0x05;
pub const ALLOW_ASYNC_BOTH     : Allow = 0x06;
pub const ALLOW_SYNC_BOTH      : Allow = 0x07;
pub type InputFocus = u32;
pub const INPUT_FOCUS_NONE           : InputFocus = 0x00;
pub const INPUT_FOCUS_POINTER_ROOT   : InputFocus = 0x01;
pub const INPUT_FOCUS_PARENT         : InputFocus = 0x02;
pub const INPUT_FOCUS_FOLLOW_KEYBOARD: InputFocus = 0x03;
pub type FontDraw = u32;
pub const FONT_DRAW_LEFT_TO_RIGHT: FontDraw = 0x00;
pub const FONT_DRAW_RIGHT_TO_LEFT: FontDraw = 0x01;
pub type Gc = u32;
pub const GC_FUNCTION             : Gc =     0x01;
pub const GC_PLANE_MASK           : Gc =     0x02;
pub const GC_FOREGROUND           : Gc =     0x04;
pub const GC_BACKGROUND           : Gc =     0x08;
pub const GC_LINE_WIDTH           : Gc =     0x10;
pub const GC_LINE_STYLE           : Gc =     0x20;
pub const GC_CAP_STYLE            : Gc =     0x40;
pub const GC_JOIN_STYLE           : Gc =     0x80;
pub const GC_FILL_STYLE           : Gc =    0x100;
pub const GC_FILL_RULE            : Gc =    0x200;
pub const GC_TILE                 : Gc =    0x400;
pub const GC_STIPPLE              : Gc =    0x800;
pub const GC_TILE_STIPPLE_ORIGIN_X: Gc =   0x1000;
pub const GC_TILE_STIPPLE_ORIGIN_Y: Gc =   0x2000;
pub const GC_FONT                 : Gc =   0x4000;
pub const GC_SUBWINDOW_MODE       : Gc =   0x8000;
pub const GC_GRAPHICS_EXPOSURES   : Gc =  0x10000;
pub const GC_CLIP_ORIGIN_X        : Gc =  0x20000;
pub const GC_CLIP_ORIGIN_Y        : Gc =  0x40000;
pub const GC_CLIP_MASK            : Gc =  0x80000;
pub const GC_DASH_OFFSET          : Gc = 0x100000;
pub const GC_DASH_LIST            : Gc = 0x200000;
pub const GC_ARC_MODE             : Gc = 0x400000;
pub type Gx = u32;
pub const GX_CLEAR        : Gx = 0x00;
pub const GX_AND          : Gx = 0x01;
pub const GX_AND_REVERSE  : Gx = 0x02;
pub const GX_COPY         : Gx = 0x03;
pub const GX_AND_INVERTED : Gx = 0x04;
pub const GX_NOOP         : Gx = 0x05;
pub const GX_XOR          : Gx = 0x06;
pub const GX_OR           : Gx = 0x07;
pub const GX_NOR          : Gx = 0x08;
pub const GX_EQUIV        : Gx = 0x09;
pub const GX_INVERT       : Gx = 0x0a;
pub const GX_OR_REVERSE   : Gx = 0x0b;
pub const GX_COPY_INVERTED: Gx = 0x0c;
pub const GX_OR_INVERTED  : Gx = 0x0d;
pub const GX_NAND         : Gx = 0x0e;
pub const GX_SET          : Gx = 0x0f;
pub type LineStyle = u32;
pub const LINE_STYLE_SOLID      : LineStyle = 0x00;
pub const LINE_STYLE_ON_OFF_DASH: LineStyle = 0x01;
pub const LINE_STYLE_DOUBLE_DASH: LineStyle = 0x02;
pub type CapStyle = u32;
pub const CAP_STYLE_NOT_LAST  : CapStyle = 0x00;
pub const CAP_STYLE_BUTT      : CapStyle = 0x01;
pub const CAP_STYLE_ROUND     : CapStyle = 0x02;
pub const CAP_STYLE_PROJECTING: CapStyle = 0x03;
pub type JoinStyle = u32;
pub const JOIN_STYLE_MITER: JoinStyle = 0x00;
pub const JOIN_STYLE_ROUND: JoinStyle = 0x01;
pub const JOIN_STYLE_BEVEL: JoinStyle = 0x02;
pub type FillStyle = u32;
pub const FILL_STYLE_SOLID          : FillStyle = 0x00;
pub const FILL_STYLE_TILED          : FillStyle = 0x01;
pub const FILL_STYLE_STIPPLED       : FillStyle = 0x02;
pub const FILL_STYLE_OPAQUE_STIPPLED: FillStyle = 0x03;
pub type FillRule = u32;
pub const FILL_RULE_EVEN_ODD: FillRule = 0x00;
pub const FILL_RULE_WINDING : FillRule = 0x01;
pub type SubwindowMode = u32;
pub const SUBWINDOW_MODE_CLIP_BY_CHILDREN : SubwindowMode = 0x00;
pub const SUBWINDOW_MODE_INCLUDE_INFERIORS: SubwindowMode = 0x01;
pub type ArcMode = u32;
pub const ARC_MODE_CHORD    : ArcMode = 0x00;
pub const ARC_MODE_PIE_SLICE: ArcMode = 0x01;
pub type ClipOrdering = u32;
pub const CLIP_ORDERING_UNSORTED : ClipOrdering = 0x00;
pub const CLIP_ORDERING_Y_SORTED : ClipOrdering = 0x01;
pub const CLIP_ORDERING_YX_SORTED: ClipOrdering = 0x02;
pub const CLIP_ORDERING_YX_BANDED: ClipOrdering = 0x03;
pub type CoordMode = u32;
pub const COORD_MODE_ORIGIN  : CoordMode = 0x00;
pub const COORD_MODE_PREVIOUS: CoordMode = 0x01;
pub type PolyShape = u32;
pub const POLY_SHAPE_COMPLEX  : PolyShape = 0x00;
pub const POLY_SHAPE_NONCONVEX: PolyShape = 0x01;
pub const POLY_SHAPE_CONVEX   : PolyShape = 0x02;
pub type ImageFormat = u32;
pub const IMAGE_FORMAT_XY_BITMAP: ImageFormat = 0x00;
pub const IMAGE_FORMAT_XY_PIXMAP: ImageFormat = 0x01;
pub const IMAGE_FORMAT_Z_PIXMAP : ImageFormat = 0x02;
pub type ColormapAlloc = u32;
pub const COLORMAP_ALLOC_NONE: ColormapAlloc = 0x00;
pub const COLORMAP_ALLOC_ALL : ColormapAlloc = 0x01;
pub type ColorFlag = u32;
pub const COLOR_FLAG_RED  : ColorFlag = 0x01;
pub const COLOR_FLAG_GREEN: ColorFlag = 0x02;
pub const COLOR_FLAG_BLUE : ColorFlag = 0x04;
pub type PixmapEnum = u32;
pub const PIXMAP_NONE: PixmapEnum = 0x00;
pub type FontEnum = u32;
pub const FONT_NONE: FontEnum = 0x00;
pub type QueryShapeOf = u32;
pub const QUERY_SHAPE_OF_LARGEST_CURSOR : QueryShapeOf = 0x00;
pub const QUERY_SHAPE_OF_FASTEST_TILE   : QueryShapeOf = 0x01;
pub const QUERY_SHAPE_OF_FASTEST_STIPPLE: QueryShapeOf = 0x02;
pub type Kb = u32;
pub const KB_KEY_CLICK_PERCENT: Kb = 0x01;
pub const KB_BELL_PERCENT     : Kb = 0x02;
pub const KB_BELL_PITCH       : Kb = 0x04;
pub const KB_BELL_DURATION    : Kb = 0x08;
pub const KB_LED              : Kb = 0x10;
pub const KB_LED_MODE         : Kb = 0x20;
pub const KB_KEY              : Kb = 0x40;
pub const KB_AUTO_REPEAT_MODE : Kb = 0x80;
pub type LedMode = u32;
pub const LED_MODE_OFF: LedMode = 0x00;
pub const LED_MODE_ON : LedMode = 0x01;
pub type AutoRepeatMode = u32;
pub const AUTO_REPEAT_MODE_OFF    : AutoRepeatMode = 0x00;
pub const AUTO_REPEAT_MODE_ON     : AutoRepeatMode = 0x01;
pub const AUTO_REPEAT_MODE_DEFAULT: AutoRepeatMode = 0x02;
pub type Blanking = u32;
pub const BLANKING_NOT_PREFERRED: Blanking = 0x00;
pub const BLANKING_PREFERRED    : Blanking = 0x01;
pub const BLANKING_DEFAULT      : Blanking = 0x02;
pub type Exposures = u32;
pub const EXPOSURES_NOT_ALLOWED: Exposures = 0x00;
pub const EXPOSURES_ALLOWED    : Exposures = 0x01;
pub const EXPOSURES_DEFAULT    : Exposures = 0x02;
pub type HostMode = u32;
pub const HOST_MODE_INSERT: HostMode = 0x00;
pub const HOST_MODE_DELETE: HostMode = 0x01;
pub type Family = u32;
pub const FAMILY_INTERNET          : Family = 0x00;
pub const FAMILY_DE_CNET           : Family = 0x01;
pub const FAMILY_CHAOS             : Family = 0x02;
pub const FAMILY_SERVER_INTERPRETED: Family = 0x05;
pub const FAMILY_INTERNET_6        : Family = 0x06;
pub type AccessControl = u32;
pub const ACCESS_CONTROL_DISABLE: AccessControl = 0x00;
pub const ACCESS_CONTROL_ENABLE : AccessControl = 0x01;
pub type CloseDown = u32;
pub const CLOSE_DOWN_DESTROY_ALL     : CloseDown = 0x00;
pub const CLOSE_DOWN_RETAIN_PERMANENT: CloseDown = 0x01;
pub const CLOSE_DOWN_RETAIN_TEMPORARY: CloseDown = 0x02;
pub type Kill = u32;
pub const KILL_ALL_TEMPORARY: Kill = 0x00;
pub type ScreenSaver = u32;
pub const SCREEN_SAVER_RESET : ScreenSaver = 0x00;
pub const SCREEN_SAVER_ACTIVE: ScreenSaver = 0x01;
pub type MappingStatus = u32;
pub const MAPPING_STATUS_SUCCESS: MappingStatus = 0x00;
pub const MAPPING_STATUS_BUSY   : MappingStatus = 0x01;
pub const MAPPING_STATUS_FAILURE: MappingStatus = 0x02;
pub type MapIndex = u32;
pub const MAP_INDEX_SHIFT  : MapIndex = 0x00;
pub const MAP_INDEX_LOCK   : MapIndex = 0x01;
pub const MAP_INDEX_CONTROL: MapIndex = 0x02;
pub const MAP_INDEX_1      : MapIndex = 0x03;
pub const MAP_INDEX_2      : MapIndex = 0x04;
pub const MAP_INDEX_3      : MapIndex = 0x05;
pub const MAP_INDEX_4      : MapIndex = 0x06;
pub const MAP_INDEX_5      : MapIndex = 0x07;
#[derive(Copy, Clone)]
pub struct Char2b {
    pub base: xcb_char2b_t,
}
impl Char2b {
    #[allow(unused_unsafe)]
    pub fn new(byte1: u8,
               byte2: u8)
            -> Char2b {
        unsafe {
            Char2b {
                base: xcb_char2b_t {
                    byte1: byte1,
                    byte2: byte2,
                }
            }
        }
    }
    pub fn byte1(&self) -> u8 {
        unsafe {
            self.base.byte1
        }
    }
    pub fn byte2(&self) -> u8 {
        unsafe {
            self.base.byte2
        }
    }
}
pub type Char2bIterator = xcb_char2b_iterator_t;
impl Iterator for Char2bIterator {
    type Item = Char2b;
    fn next(&mut self) -> std::option::Option<Char2b> {
        if self.rem == 0 { None }
        else {
            unsafe {
                let iter = self as *mut xcb_char2b_iterator_t;
                let data = (*iter).data;
                xcb_char2b_next(iter);
                Some(std::mem::transmute(*data))
            }
        }
    }
}
#[derive(Copy, Clone)]
pub struct Point {
    pub base: xcb_point_t,
}
impl Point {
    #[allow(unused_unsafe)]
    pub fn new(x: i16,
               y: i16)
            -> Point {
        unsafe {
            Point {
                base: xcb_point_t {
                    x: x,
                    y: y,
                }
            }
        }
    }
    pub fn x(&self) -> i16 {
        unsafe {
            self.base.x
        }
    }
    pub fn y(&self) -> i16 {
        unsafe {
            self.base.y
        }
    }
}
pub type PointIterator = xcb_point_iterator_t;
impl Iterator for PointIterator {
    type Item = Point;
    fn next(&mut self) -> std::option::Option<Point> {
        if self.rem == 0 { None }
        else {
            unsafe {
                let iter = self as *mut xcb_point_iterator_t;
                let data = (*iter).data;
                xcb_point_next(iter);
                Some(std::mem::transmute(*data))
            }
        }
    }
}
#[derive(Copy, Clone)]
pub struct Rectangle {
    pub base: xcb_rectangle_t,
}
impl Rectangle {
    #[allow(unused_unsafe)]
    pub fn new(x:      i16,
               y:      i16,
               width:  u16,
               height: u16)
            -> Rectangle {
        unsafe {
            Rectangle {
                base: xcb_rectangle_t {
                    x:      x,
                    y:      y,
                    width:  width,
                    height: height,
                }
            }
        }
    }
    pub fn x(&self) -> i16 {
        unsafe {
            self.base.x
        }
    }
    pub fn y(&self) -> i16 {
        unsafe {
            self.base.y
        }
    }
    pub fn width(&self) -> u16 {
        unsafe {
            self.base.width
        }
    }
    pub fn height(&self) -> u16 {
        unsafe {
            self.base.height
        }
    }
}
pub type RectangleIterator = xcb_rectangle_iterator_t;
impl Iterator for RectangleIterator {
    type Item = Rectangle;
    fn next(&mut self) -> std::option::Option<Rectangle> {
        if self.rem == 0 { None }
        else {
            unsafe {
                let iter = self as *mut xcb_rectangle_iterator_t;
                let data = (*iter).data;
                xcb_rectangle_next(iter);
                Some(std::mem::transmute(*data))
            }
        }
    }
}
#[derive(Copy, Clone)]
pub struct Arc {
    pub base: xcb_arc_t,
}
impl Arc {
    #[allow(unused_unsafe)]
    pub fn new(x:      i16,
               y:      i16,
               width:  u16,
               height: u16,
               angle1: i16,
               angle2: i16)
            -> Arc {
        unsafe {
            Arc {
                base: xcb_arc_t {
                    x:      x,
                    y:      y,
                    width:  width,
                    height: height,
                    angle1: angle1,
                    angle2: angle2,
                }
            }
        }
    }
    pub fn x(&self) -> i16 {
        unsafe {
            self.base.x
        }
    }
    pub fn y(&self) -> i16 {
        unsafe {
            self.base.y
        }
    }
    pub fn width(&self) -> u16 {
        unsafe {
            self.base.width
        }
    }
    pub fn height(&self) -> u16 {
        unsafe {
            self.base.height
        }
    }
    pub fn angle1(&self) -> i16 {
        unsafe {
            self.base.angle1
        }
    }
    pub fn angle2(&self) -> i16 {
        unsafe {
            self.base.angle2
        }
    }
}
pub type ArcIterator = xcb_arc_iterator_t;
impl Iterator for ArcIterator {
    type Item = Arc;
    fn next(&mut self) -> std::option::Option<Arc> {
        if self.rem == 0 { None }
        else {
            unsafe {
                let iter = self as *mut xcb_arc_iterator_t;
                let data = (*iter).data;
                xcb_arc_next(iter);
                Some(std::mem::transmute(*data))
            }
        }
    }
}
#[derive(Copy, Clone)]
pub struct Format {
    pub base: xcb_format_t,
}
impl Format {
    #[allow(unused_unsafe)]
    pub fn new(depth:          u8,
               bits_per_pixel: u8,
               scanline_pad:   u8)
            -> Format {
        unsafe {
            Format {
                base: xcb_format_t {
                    depth:          depth,
                    bits_per_pixel: bits_per_pixel,
                    scanline_pad:   scanline_pad,
                    pad0:           [0; 5],
                }
            }
        }
    }
    pub fn depth(&self) -> u8 {
        unsafe {
            self.base.depth
        }
    }
    pub fn bits_per_pixel(&self) -> u8 {
        unsafe {
            self.base.bits_per_pixel
        }
    }
    pub fn scanline_pad(&self) -> u8 {
        unsafe {
            self.base.scanline_pad
        }
    }
}
pub type FormatIterator = xcb_format_iterator_t;
impl Iterator for FormatIterator {
    type Item = Format;
    fn next(&mut self) -> std::option::Option<Format> {
        if self.rem == 0 { None }
        else {
            unsafe {
                let iter = self as *mut xcb_format_iterator_t;
                let data = (*iter).data;
                xcb_format_next(iter);
                Some(std::mem::transmute(*data))
            }
        }
    }
}
#[derive(Copy, Clone)]
pub struct Visualtype {
    pub base: xcb_visualtype_t,
}
impl Visualtype {
    #[allow(unused_unsafe)]
    pub fn new(visual_id:          Visualid,
               class:              u8,
               bits_per_rgb_value: u8,
               colormap_entries:   u16,
               red_mask:           u32,
               green_mask:         u32,
               blue_mask:          u32)
            -> Visualtype {
        unsafe {
            Visualtype {
                base: xcb_visualtype_t {
                    visual_id:          visual_id,
                    class:              class,
                    bits_per_rgb_value: bits_per_rgb_value,
                    colormap_entries:   colormap_entries,
                    red_mask:           red_mask,
                    green_mask:         green_mask,
                    blue_mask:          blue_mask,
                    pad0:               [0; 4],
                }
            }
        }
    }
    pub fn visual_id(&self) -> Visualid {
        unsafe {
            self.base.visual_id
        }
    }
    pub fn class(&self) -> u8 {
        unsafe {
            self.base.class
        }
    }
    pub fn bits_per_rgb_value(&self) -> u8 {
        unsafe {
            self.base.bits_per_rgb_value
        }
    }
    pub fn colormap_entries(&self) -> u16 {
        unsafe {
            self.base.colormap_entries
        }
    }
    pub fn red_mask(&self) -> u32 {
        unsafe {
            self.base.red_mask
        }
    }
    pub fn green_mask(&self) -> u32 {
        unsafe {
            self.base.green_mask
        }
    }
    pub fn blue_mask(&self) -> u32 {
        unsafe {
            self.base.blue_mask
        }
    }
}
pub type VisualtypeIterator = xcb_visualtype_iterator_t;
impl Iterator for VisualtypeIterator {
    type Item = Visualtype;
    fn next(&mut self) -> std::option::Option<Visualtype> {
        if self.rem == 0 { None }
        else {
            unsafe {
                let iter = self as *mut xcb_visualtype_iterator_t;
                let data = (*iter).data;
                xcb_visualtype_next(iter);
                Some(std::mem::transmute(*data))
            }
        }
    }
}
pub type Depth<'a> = base::StructPtr<'a, xcb_depth_t>;
impl<'a> Depth<'a> {
    pub fn depth(&self) -> u8 {
        unsafe {
            (*self.ptr).depth
        }
    }
    pub fn visuals_len(&self) -> u16 {
        unsafe {
            (*self.ptr).visuals_len
        }
    }
    pub fn visuals(&self) -> VisualtypeIterator {
        unsafe {
            xcb_depth_visuals_iterator(self.ptr)
        }
    }
}
pub type DepthIterator<'a> = xcb_depth_iterator_t<'a>;
impl<'a> Iterator for DepthIterator<'a> {
    type Item = Depth<'a>;
    fn next(&mut self) -> std::option::Option<Depth<'a>> {
        if self.rem == 0 { None }
        else {
            unsafe {
                let iter = self as *mut xcb_depth_iterator_t;
                let data = (*iter).data;
                xcb_depth_next(iter);
                Some(std::mem::transmute(data))
            }
        }
    }
}
pub type Screen<'a> = base::StructPtr<'a, xcb_screen_t>;
impl<'a> Screen<'a> {
    pub fn root(&self) -> Window {
        unsafe {
            (*self.ptr).root
        }
    }
    pub fn default_colormap(&self) -> Colormap {
        unsafe {
            (*self.ptr).default_colormap
        }
    }
    pub fn white_pixel(&self) -> u32 {
        unsafe {
            (*self.ptr).white_pixel
        }
    }
    pub fn black_pixel(&self) -> u32 {
        unsafe {
            (*self.ptr).black_pixel
        }
    }
    pub fn current_input_masks(&self) -> u32 {
        unsafe {
            (*self.ptr).current_input_masks
        }
    }
    pub fn width_in_pixels(&self) -> u16 {
        unsafe {
            (*self.ptr).width_in_pixels
        }
    }
    pub fn height_in_pixels(&self) -> u16 {
        unsafe {
            (*self.ptr).height_in_pixels
        }
    }
    pub fn width_in_millimeters(&self) -> u16 {
        unsafe {
            (*self.ptr).width_in_millimeters
        }
    }
    pub fn height_in_millimeters(&self) -> u16 {
        unsafe {
            (*self.ptr).height_in_millimeters
        }
    }
    pub fn min_installed_maps(&self) -> u16 {
        unsafe {
            (*self.ptr).min_installed_maps
        }
    }
    pub fn max_installed_maps(&self) -> u16 {
        unsafe {
            (*self.ptr).max_installed_maps
        }
    }
    pub fn root_visual(&self) -> Visualid {
        unsafe {
            (*self.ptr).root_visual
        }
    }
    pub fn backing_stores(&self) -> u8 {
        unsafe {
            (*self.ptr).backing_stores
        }
    }
    pub fn save_unders(&self) -> bool {
        unsafe {
            (*self.ptr).save_unders != 0
        }
    }
    pub fn root_depth(&self) -> u8 {
        unsafe {
            (*self.ptr).root_depth
        }
    }
    pub fn allowed_depths_len(&self) -> u8 {
        unsafe {
            (*self.ptr).allowed_depths_len
        }
    }
    pub fn allowed_depths(&self) -> DepthIterator<'a> {
        unsafe {
            xcb_screen_allowed_depths_iterator(self.ptr)
        }
    }
}
pub type ScreenIterator<'a> = xcb_screen_iterator_t<'a>;
impl<'a> Iterator for ScreenIterator<'a> {
    type Item = Screen<'a>;
    fn next(&mut self) -> std::option::Option<Screen<'a>> {
        if self.rem == 0 { None }
        else {
            unsafe {
                let iter = self as *mut xcb_screen_iterator_t;
                let data = (*iter).data;
                xcb_screen_next(iter);
                Some(std::mem::transmute(data))
            }
        }
    }
}
pub type SetupRequest<'a> = base::StructPtr<'a, xcb_setup_request_t>;
impl<'a> SetupRequest<'a> {
    pub fn byte_order(&self) -> u8 {
        unsafe {
            (*self.ptr).byte_order
        }
    }
    pub fn protocol_major_version(&self) -> u16 {
        unsafe {
            (*self.ptr).protocol_major_version
        }
    }
    pub fn protocol_minor_version(&self) -> u16 {
        unsafe {
            (*self.ptr).protocol_minor_version
        }
    }
    pub fn authorization_protocol_name_len(&self) -> u16 {
        unsafe {
            (*self.ptr).authorization_protocol_name_len
        }
    }
    pub fn authorization_protocol_data_len(&self) -> u16 {
        unsafe {
            (*self.ptr).authorization_protocol_data_len
        }
    }
    pub fn authorization_protocol_name(&self) -> &str {
        unsafe {
            let field = self.ptr;
            let len = xcb_setup_request_authorization_protocol_name_length(field) as usize;
            let data = xcb_setup_request_authorization_protocol_name(field);
            let slice = std::slice::from_raw_parts(data as *const u8, len);
            
            std::str::from_utf8_unchecked(&slice)
        }
    }
    pub fn authorization_protocol_data(&self) -> &str {
        unsafe {
            let field = self.ptr;
            let len = xcb_setup_request_authorization_protocol_data_length(field) as usize;
            let data = xcb_setup_request_authorization_protocol_data(field);
            let slice = std::slice::from_raw_parts(data as *const u8, len);
            
            std::str::from_utf8_unchecked(&slice)
        }
    }
}
pub type SetupRequestIterator<'a> = xcb_setup_request_iterator_t<'a>;
impl<'a> Iterator for SetupRequestIterator<'a> {
    type Item = SetupRequest<'a>;
    fn next(&mut self) -> std::option::Option<SetupRequest<'a>> {
        if self.rem == 0 { None }
        else {
            unsafe {
                let iter = self as *mut xcb_setup_request_iterator_t;
                let data = (*iter).data;
                xcb_setup_request_next(iter);
                Some(std::mem::transmute(data))
            }
        }
    }
}
pub type SetupFailed<'a> = base::StructPtr<'a, xcb_setup_failed_t>;
impl<'a> SetupFailed<'a> {
    pub fn status(&self) -> u8 {
        unsafe {
            (*self.ptr).status
        }
    }
    pub fn reason_len(&self) -> u8 {
        unsafe {
            (*self.ptr).reason_len
        }
    }
    pub fn protocol_major_version(&self) -> u16 {
        unsafe {
            (*self.ptr).protocol_major_version
        }
    }
    pub fn protocol_minor_version(&self) -> u16 {
        unsafe {
            (*self.ptr).protocol_minor_version
        }
    }
    pub fn length(&self) -> u16 {
        unsafe {
            (*self.ptr).length
        }
    }
    pub fn reason(&self) -> &str {
        unsafe {
            let field = self.ptr;
            let len = xcb_setup_failed_reason_length(field) as usize;
            let data = xcb_setup_failed_reason(field);
            let slice = std::slice::from_raw_parts(data as *const u8, len);
            
            std::str::from_utf8_unchecked(&slice)
        }
    }
}
pub type SetupFailedIterator<'a> = xcb_setup_failed_iterator_t<'a>;
impl<'a> Iterator for SetupFailedIterator<'a> {
    type Item = SetupFailed<'a>;
    fn next(&mut self) -> std::option::Option<SetupFailed<'a>> {
        if self.rem == 0 { None }
        else {
            unsafe {
                let iter = self as *mut xcb_setup_failed_iterator_t;
                let data = (*iter).data;
                xcb_setup_failed_next(iter);
                Some(std::mem::transmute(data))
            }
        }
    }
}
pub type SetupAuthenticate<'a> = base::StructPtr<'a, xcb_setup_authenticate_t>;
impl<'a> SetupAuthenticate<'a> {
    pub fn status(&self) -> u8 {
        unsafe {
            (*self.ptr).status
        }
    }
    pub fn length(&self) -> u16 {
        unsafe {
            (*self.ptr).length
        }
    }
    pub fn reason(&self) -> &str {
        unsafe {
            let field = self.ptr;
            let len = xcb_setup_authenticate_reason_length(field) as usize;
            let data = xcb_setup_authenticate_reason(field);
            let slice = std::slice::from_raw_parts(data as *const u8, len);
            
            std::str::from_utf8_unchecked(&slice)
        }
    }
}
pub type SetupAuthenticateIterator<'a> = xcb_setup_authenticate_iterator_t<'a>;
impl<'a> Iterator for SetupAuthenticateIterator<'a> {
    type Item = SetupAuthenticate<'a>;
    fn next(&mut self) -> std::option::Option<SetupAuthenticate<'a>> {
        if self.rem == 0 { None }
        else {
            unsafe {
                let iter = self as *mut xcb_setup_authenticate_iterator_t;
                let data = (*iter).data;
                xcb_setup_authenticate_next(iter);
                Some(std::mem::transmute(data))
            }
        }
    }
}
pub type Setup<'a> = base::StructPtr<'a, xcb_setup_t>;
impl<'a> Setup<'a> {
    pub fn status(&self) -> u8 {
        unsafe {
            (*self.ptr).status
        }
    }
    pub fn protocol_major_version(&self) -> u16 {
        unsafe {
            (*self.ptr).protocol_major_version
        }
    }
    pub fn protocol_minor_version(&self) -> u16 {
        unsafe {
            (*self.ptr).protocol_minor_version
        }
    }
    pub fn length(&self) -> u16 {
        unsafe {
            (*self.ptr).length
        }
    }
    pub fn release_number(&self) -> u32 {
        unsafe {
            (*self.ptr).release_number
        }
    }
    pub fn resource_id_base(&self) -> u32 {
        unsafe {
            (*self.ptr).resource_id_base
        }
    }
    pub fn resource_id_mask(&self) -> u32 {
        unsafe {
            (*self.ptr).resource_id_mask
        }
    }
    pub fn motion_buffer_size(&self) -> u32 {
        unsafe {
            (*self.ptr).motion_buffer_size
        }
    }
    pub fn vendor_len(&self) -> u16 {
        unsafe {
            (*self.ptr).vendor_len
        }
    }
    pub fn maximum_request_length(&self) -> u16 {
        unsafe {
            (*self.ptr).maximum_request_length
        }
    }
    pub fn roots_len(&self) -> u8 {
        unsafe {
            (*self.ptr).roots_len
        }
    }
    pub fn pixmap_formats_len(&self) -> u8 {
        unsafe {
            (*self.ptr).pixmap_formats_len
        }
    }
    pub fn image_byte_order(&self) -> u8 {
        unsafe {
            (*self.ptr).image_byte_order
        }
    }
    pub fn bitmap_format_bit_order(&self) -> u8 {
        unsafe {
            (*self.ptr).bitmap_format_bit_order
        }
    }
    pub fn bitmap_format_scanline_unit(&self) -> u8 {
        unsafe {
            (*self.ptr).bitmap_format_scanline_unit
        }
    }
    pub fn bitmap_format_scanline_pad(&self) -> u8 {
        unsafe {
            (*self.ptr).bitmap_format_scanline_pad
        }
    }
    pub fn min_keycode(&self) -> Keycode {
        unsafe {
            (*self.ptr).min_keycode
        }
    }
    pub fn max_keycode(&self) -> Keycode {
        unsafe {
            (*self.ptr).max_keycode
        }
    }
    pub fn vendor(&self) -> &str {
        unsafe {
            let field = self.ptr;
            let len = xcb_setup_vendor_length(field) as usize;
            let data = xcb_setup_vendor(field);
            let slice = std::slice::from_raw_parts(data as *const u8, len);
            
            std::str::from_utf8_unchecked(&slice)
        }
    }
    pub fn pixmap_formats(&self) -> FormatIterator {
        unsafe {
            xcb_setup_pixmap_formats_iterator(self.ptr)
        }
    }
    pub fn roots(&self) -> ScreenIterator<'a> {
        unsafe {
            xcb_setup_roots_iterator(self.ptr)
        }
    }
}
pub type SetupIterator<'a> = xcb_setup_iterator_t<'a>;
impl<'a> Iterator for SetupIterator<'a> {
    type Item = Setup<'a>;
    fn next(&mut self) -> std::option::Option<Setup<'a>> {
        if self.rem == 0 { None }
        else {
            unsafe {
                let iter = self as *mut xcb_setup_iterator_t;
                let data = (*iter).data;
                xcb_setup_next(iter);
                Some(std::mem::transmute(data))
            }
        }
    }
}
pub const KEY_PRESS: u8 = 2;
pub type KeyPressEvent = base::Event<xcb_key_press_event_t>;
impl KeyPressEvent {
    
    
    pub fn detail(&self) -> Keycode {
        unsafe {
            (*self.ptr).detail
        }
    }
    
    pub fn time(&self) -> Timestamp {
        unsafe {
            (*self.ptr).time
        }
    }
    
    pub fn root(&self) -> Window {
        unsafe {
            (*self.ptr).root
        }
    }
    pub fn event(&self) -> Window {
        unsafe {
            (*self.ptr).event
        }
    }
    pub fn child(&self) -> Window {
        unsafe {
            (*self.ptr).child
        }
    }
    
    
    pub fn root_x(&self) -> i16 {
        unsafe {
            (*self.ptr).root_x
        }
    }
    
    
    pub fn root_y(&self) -> i16 {
        unsafe {
            (*self.ptr).root_y
        }
    }
    
    
    pub fn event_x(&self) -> i16 {
        unsafe {
            (*self.ptr).event_x
        }
    }
    
    
    pub fn event_y(&self) -> i16 {
        unsafe {
            (*self.ptr).event_y
        }
    }
    
    
    pub fn state(&self) -> u16 {
        unsafe {
            (*self.ptr).state
        }
    }
    
    pub fn same_screen(&self) -> bool {
        unsafe {
            (*self.ptr).same_screen != 0
        }
    }
    
    
    
    
    pub fn new(response_type: u8,
               detail: Keycode,
               time: Timestamp,
               root: Window,
               event: Window,
               child: Window,
               root_x: i16,
               root_y: i16,
               event_x: i16,
               event_y: i16,
               state: u16,
               same_screen: bool)
            -> KeyPressEvent {
        unsafe {
            let raw = libc::malloc(32 as usize) as *mut xcb_key_press_event_t;
            assert!(response_type == KEY_RELEASE ||
                    response_type == KEY_PRESS,
                    "wrong response_type supplied to KeyPressEvent::new");
            (*raw).response_type = response_type;
            (*raw).detail = detail;
            (*raw).time = time;
            (*raw).root = root;
            (*raw).event = event;
            (*raw).child = child;
            (*raw).root_x = root_x;
            (*raw).root_y = root_y;
            (*raw).event_x = event_x;
            (*raw).event_y = event_y;
            (*raw).state = state;
            (*raw).same_screen = if same_screen { 1 } else { 0 };
            KeyPressEvent {
                ptr: raw
            }
        }
    }
}
pub const KEY_RELEASE: u8 = 3;
pub type KeyReleaseEvent = base::Event<xcb_key_release_event_t>;
pub const BUTTON_PRESS: u8 = 4;
pub type ButtonPressEvent = base::Event<xcb_button_press_event_t>;
impl ButtonPressEvent {
    
    
    pub fn detail(&self) -> Button {
        unsafe {
            (*self.ptr).detail
        }
    }
    
    pub fn time(&self) -> Timestamp {
        unsafe {
            (*self.ptr).time
        }
    }
    
    pub fn root(&self) -> Window {
        unsafe {
            (*self.ptr).root
        }
    }
    pub fn event(&self) -> Window {
        unsafe {
            (*self.ptr).event
        }
    }
    pub fn child(&self) -> Window {
        unsafe {
            (*self.ptr).child
        }
    }
    
    
    pub fn root_x(&self) -> i16 {
        unsafe {
            (*self.ptr).root_x
        }
    }
    
    
    pub fn root_y(&self) -> i16 {
        unsafe {
            (*self.ptr).root_y
        }
    }
    
    
    pub fn event_x(&self) -> i16 {
        unsafe {
            (*self.ptr).event_x
        }
    }
    
    
    pub fn event_y(&self) -> i16 {
        unsafe {
            (*self.ptr).event_y
        }
    }
    
    
    pub fn state(&self) -> u16 {
        unsafe {
            (*self.ptr).state
        }
    }
    
    pub fn same_screen(&self) -> bool {
        unsafe {
            (*self.ptr).same_screen != 0
        }
    }
    
    
    
    
    pub fn new(response_type: u8,
               detail: Button,
               time: Timestamp,
               root: Window,
               event: Window,
               child: Window,
               root_x: i16,
               root_y: i16,
               event_x: i16,
               event_y: i16,
               state: u16,
               same_screen: bool)
            -> ButtonPressEvent {
        unsafe {
            let raw = libc::malloc(32 as usize) as *mut xcb_button_press_event_t;
            assert!(response_type == BUTTON_PRESS ||
                    response_type == BUTTON_RELEASE,
                    "wrong response_type supplied to ButtonPressEvent::new");
            (*raw).response_type = response_type;
            (*raw).detail = detail;
            (*raw).time = time;
            (*raw).root = root;
            (*raw).event = event;
            (*raw).child = child;
            (*raw).root_x = root_x;
            (*raw).root_y = root_y;
            (*raw).event_x = event_x;
            (*raw).event_y = event_y;
            (*raw).state = state;
            (*raw).same_screen = if same_screen { 1 } else { 0 };
            ButtonPressEvent {
                ptr: raw
            }
        }
    }
}
pub const BUTTON_RELEASE: u8 = 5;
pub type ButtonReleaseEvent = base::Event<xcb_button_release_event_t>;
pub const MOTION_NOTIFY: u8 = 6;
pub type MotionNotifyEvent = base::Event<xcb_motion_notify_event_t>;
impl MotionNotifyEvent {
    
    
    pub fn detail(&self) -> u8 {
        unsafe {
            (*self.ptr).detail
        }
    }
    
    pub fn time(&self) -> Timestamp {
        unsafe {
            (*self.ptr).time
        }
    }
    
    pub fn root(&self) -> Window {
        unsafe {
            (*self.ptr).root
        }
    }
    pub fn event(&self) -> Window {
        unsafe {
            (*self.ptr).event
        }
    }
    pub fn child(&self) -> Window {
        unsafe {
            (*self.ptr).child
        }
    }
    
    
    pub fn root_x(&self) -> i16 {
        unsafe {
            (*self.ptr).root_x
        }
    }
    
    
    pub fn root_y(&self) -> i16 {
        unsafe {
            (*self.ptr).root_y
        }
    }
    
    
    pub fn event_x(&self) -> i16 {
        unsafe {
            (*self.ptr).event_x
        }
    }
    
    
    pub fn event_y(&self) -> i16 {
        unsafe {
            (*self.ptr).event_y
        }
    }
    
    
    pub fn state(&self) -> u16 {
        unsafe {
            (*self.ptr).state
        }
    }
    
    pub fn same_screen(&self) -> bool {
        unsafe {
            (*self.ptr).same_screen != 0
        }
    }
    
    
    pub fn new(detail: u8,
               time: Timestamp,
               root: Window,
               event: Window,
               child: Window,
               root_x: i16,
               root_y: i16,
               event_x: i16,
               event_y: i16,
               state: u16,
               same_screen: bool)
            -> MotionNotifyEvent {
        unsafe {
            let raw = libc::malloc(32 as usize) as *mut xcb_motion_notify_event_t;
            (*raw).response_type = MOTION_NOTIFY;
            (*raw).detail = detail;
            (*raw).time = time;
            (*raw).root = root;
            (*raw).event = event;
            (*raw).child = child;
            (*raw).root_x = root_x;
            (*raw).root_y = root_y;
            (*raw).event_x = event_x;
            (*raw).event_y = event_y;
            (*raw).state = state;
            (*raw).same_screen = if same_screen { 1 } else { 0 };
            MotionNotifyEvent {
                ptr: raw
            }
        }
    }
}
pub const ENTER_NOTIFY: u8 = 7;
pub type EnterNotifyEvent = base::Event<xcb_enter_notify_event_t>;
impl EnterNotifyEvent {
    pub fn detail(&self) -> u8 {
        unsafe {
            (*self.ptr).detail
        }
    }
    pub fn time(&self) -> Timestamp {
        unsafe {
            (*self.ptr).time
        }
    }
    
    pub fn root(&self) -> Window {
        unsafe {
            (*self.ptr).root
        }
    }
    
    pub fn event(&self) -> Window {
        unsafe {
            (*self.ptr).event
        }
    }
    
    
    pub fn child(&self) -> Window {
        unsafe {
            (*self.ptr).child
        }
    }
    
    pub fn root_x(&self) -> i16 {
        unsafe {
            (*self.ptr).root_x
        }
    }
    
    pub fn root_y(&self) -> i16 {
        unsafe {
            (*self.ptr).root_y
        }
    }
    
    
    pub fn event_x(&self) -> i16 {
        unsafe {
            (*self.ptr).event_x
        }
    }
    
    
    pub fn event_y(&self) -> i16 {
        unsafe {
            (*self.ptr).event_y
        }
    }
    pub fn state(&self) -> u16 {
        unsafe {
            (*self.ptr).state
        }
    }
    
    pub fn mode(&self) -> u8 {
        unsafe {
            (*self.ptr).mode
        }
    }
    pub fn same_screen_focus(&self) -> u8 {
        unsafe {
            (*self.ptr).same_screen_focus
        }
    }
    
    
    
    
    pub fn new(response_type: u8,
               detail: u8,
               time: Timestamp,
               root: Window,
               event: Window,
               child: Window,
               root_x: i16,
               root_y: i16,
               event_x: i16,
               event_y: i16,
               state: u16,
               mode: u8,
               same_screen_focus: u8)
            -> EnterNotifyEvent {
        unsafe {
            let raw = libc::malloc(32 as usize) as *mut xcb_enter_notify_event_t;
            assert!(response_type == LEAVE_NOTIFY ||
                    response_type == ENTER_NOTIFY,
                    "wrong response_type supplied to EnterNotifyEvent::new");
            (*raw).response_type = response_type;
            (*raw).detail = detail;
            (*raw).time = time;
            (*raw).root = root;
            (*raw).event = event;
            (*raw).child = child;
            (*raw).root_x = root_x;
            (*raw).root_y = root_y;
            (*raw).event_x = event_x;
            (*raw).event_y = event_y;
            (*raw).state = state;
            (*raw).mode = mode;
            (*raw).same_screen_focus = same_screen_focus;
            EnterNotifyEvent {
                ptr: raw
            }
        }
    }
}
pub const LEAVE_NOTIFY: u8 = 8;
pub type LeaveNotifyEvent = base::Event<xcb_leave_notify_event_t>;
pub const FOCUS_IN: u8 = 9;
pub type FocusInEvent = base::Event<xcb_focus_in_event_t>;
impl FocusInEvent {
    
    pub fn detail(&self) -> u8 {
        unsafe {
            (*self.ptr).detail
        }
    }
    
    
    pub fn event(&self) -> Window {
        unsafe {
            (*self.ptr).event
        }
    }
    
    pub fn mode(&self) -> u8 {
        unsafe {
            (*self.ptr).mode
        }
    }
    
    
    
    
    pub fn new(response_type: u8,
               detail: u8,
               event: Window,
               mode: u8)
            -> FocusInEvent {
        unsafe {
            let raw = libc::malloc(32 as usize) as *mut xcb_focus_in_event_t;
            assert!(response_type == FOCUS_IN ||
                    response_type == FOCUS_OUT,
                    "wrong response_type supplied to FocusInEvent::new");
            (*raw).response_type = response_type;
            (*raw).detail = detail;
            (*raw).event = event;
            (*raw).mode = mode;
            FocusInEvent {
                ptr: raw
            }
        }
    }
}
pub const FOCUS_OUT: u8 = 10;
pub type FocusOutEvent = base::Event<xcb_focus_out_event_t>;
pub const KEYMAP_NOTIFY: u8 = 11;
pub type KeymapNotifyEvent = base::Event<xcb_keymap_notify_event_t>;
impl KeymapNotifyEvent {
    pub fn keys(&self) -> &[u8] {
        unsafe {
            &(*self.ptr).keys
        }
    }
    
    
    pub fn new(keys: [u8; 31])
            -> KeymapNotifyEvent {
        unsafe {
            let raw = libc::malloc(32 as usize) as *mut xcb_keymap_notify_event_t;
            (*raw).response_type = KEYMAP_NOTIFY;
            (*raw).keys = keys;
            KeymapNotifyEvent {
                ptr: raw
            }
        }
    }
}
pub const EXPOSE: u8 = 12;
pub type ExposeEvent = base::Event<xcb_expose_event_t>;
impl ExposeEvent {
    
    pub fn window(&self) -> Window {
        unsafe {
            (*self.ptr).window
        }
    }
    
    
    pub fn x(&self) -> u16 {
        unsafe {
            (*self.ptr).x
        }
    }
    
    
    pub fn y(&self) -> u16 {
        unsafe {
            (*self.ptr).y
        }
    }
    
    pub fn width(&self) -> u16 {
        unsafe {
            (*self.ptr).width
        }
    }
    
    pub fn height(&self) -> u16 {
        unsafe {
            (*self.ptr).height
        }
    }
    
    
    
    
    pub fn count(&self) -> u16 {
        unsafe {
            (*self.ptr).count
        }
    }
    
    
    pub fn new(window: Window,
               x: u16,
               y: u16,
               width: u16,
               height: u16,
               count: u16)
            -> ExposeEvent {
        unsafe {
            let raw = libc::malloc(32 as usize) as *mut xcb_expose_event_t;
            (*raw).response_type = EXPOSE;
            (*raw).window = window;
            (*raw).x = x;
            (*raw).y = y;
            (*raw).width = width;
            (*raw).height = height;
            (*raw).count = count;
            ExposeEvent {
                ptr: raw
            }
        }
    }
}
pub const GRAPHICS_EXPOSURE: u8 = 13;
pub type GraphicsExposureEvent = base::Event<xcb_graphics_exposure_event_t>;
impl GraphicsExposureEvent {
    pub fn drawable(&self) -> Drawable {
        unsafe {
            (*self.ptr).drawable
        }
    }
    pub fn x(&self) -> u16 {
        unsafe {
            (*self.ptr).x
        }
    }
    pub fn y(&self) -> u16 {
        unsafe {
            (*self.ptr).y
        }
    }
    pub fn width(&self) -> u16 {
        unsafe {
            (*self.ptr).width
        }
    }
    pub fn height(&self) -> u16 {
        unsafe {
            (*self.ptr).height
        }
    }
    pub fn minor_opcode(&self) -> u16 {
        unsafe {
            (*self.ptr).minor_opcode
        }
    }
    pub fn count(&self) -> u16 {
        unsafe {
            (*self.ptr).count
        }
    }
    pub fn major_opcode(&self) -> u8 {
        unsafe {
            (*self.ptr).major_opcode
        }
    }
    
    
    pub fn new(drawable: Drawable,
               x: u16,
               y: u16,
               width: u16,
               height: u16,
               minor_opcode: u16,
               count: u16,
               major_opcode: u8)
            -> GraphicsExposureEvent {
        unsafe {
            let raw = libc::malloc(32 as usize) as *mut xcb_graphics_exposure_event_t;
            (*raw).response_type = GRAPHICS_EXPOSURE;
            (*raw).drawable = drawable;
            (*raw).x = x;
            (*raw).y = y;
            (*raw).width = width;
            (*raw).height = height;
            (*raw).minor_opcode = minor_opcode;
            (*raw).count = count;
            (*raw).major_opcode = major_opcode;
            GraphicsExposureEvent {
                ptr: raw
            }
        }
    }
}
pub const NO_EXPOSURE: u8 = 14;
pub type NoExposureEvent = base::Event<xcb_no_exposure_event_t>;
impl NoExposureEvent {
    pub fn drawable(&self) -> Drawable {
        unsafe {
            (*self.ptr).drawable
        }
    }
    pub fn minor_opcode(&self) -> u16 {
        unsafe {
            (*self.ptr).minor_opcode
        }
    }
    pub fn major_opcode(&self) -> u8 {
        unsafe {
            (*self.ptr).major_opcode
        }
    }
    
    
    pub fn new(drawable: Drawable,
               minor_opcode: u16,
               major_opcode: u8)
            -> NoExposureEvent {
        unsafe {
            let raw = libc::malloc(32 as usize) as *mut xcb_no_exposure_event_t;
            (*raw).response_type = NO_EXPOSURE;
            (*raw).drawable = drawable;
            (*raw).minor_opcode = minor_opcode;
            (*raw).major_opcode = major_opcode;
            NoExposureEvent {
                ptr: raw
            }
        }
    }
}
pub const VISIBILITY_NOTIFY: u8 = 15;
pub type VisibilityNotifyEvent = base::Event<xcb_visibility_notify_event_t>;
impl VisibilityNotifyEvent {
    pub fn window(&self) -> Window {
        unsafe {
            (*self.ptr).window
        }
    }
    pub fn state(&self) -> u8 {
        unsafe {
            (*self.ptr).state
        }
    }
    
    
    pub fn new(window: Window,
               state: u8)
            -> VisibilityNotifyEvent {
        unsafe {
            let raw = libc::malloc(32 as usize) as *mut xcb_visibility_notify_event_t;
            (*raw).response_type = VISIBILITY_NOTIFY;
            (*raw).window = window;
            (*raw).state = state;
            VisibilityNotifyEvent {
                ptr: raw
            }
        }
    }
}
pub const CREATE_NOTIFY: u8 = 16;
pub type CreateNotifyEvent = base::Event<xcb_create_notify_event_t>;
impl CreateNotifyEvent {
    pub fn parent(&self) -> Window {
        unsafe {
            (*self.ptr).parent
        }
    }
    pub fn window(&self) -> Window {
        unsafe {
            (*self.ptr).window
        }
    }
    pub fn x(&self) -> i16 {
        unsafe {
            (*self.ptr).x
        }
    }
    pub fn y(&self) -> i16 {
        unsafe {
            (*self.ptr).y
        }
    }
    pub fn width(&self) -> u16 {
        unsafe {
            (*self.ptr).width
        }
    }
    pub fn height(&self) -> u16 {
        unsafe {
            (*self.ptr).height
        }
    }
    pub fn border_width(&self) -> u16 {
        unsafe {
            (*self.ptr).border_width
        }
    }
    pub fn override_redirect(&self) -> bool {
        unsafe {
            (*self.ptr).override_redirect != 0
        }
    }
    
    
    pub fn new(parent: Window,
               window: Window,
               x: i16,
               y: i16,
               width: u16,
               height: u16,
               border_width: u16,
               override_redirect: bool)
            -> CreateNotifyEvent {
        unsafe {
            let raw = libc::malloc(32 as usize) as *mut xcb_create_notify_event_t;
            (*raw).response_type = CREATE_NOTIFY;
            (*raw).parent = parent;
            (*raw).window = window;
            (*raw).x = x;
            (*raw).y = y;
            (*raw).width = width;
            (*raw).height = height;
            (*raw).border_width = border_width;
            (*raw).override_redirect = if override_redirect { 1 } else { 0 };
            CreateNotifyEvent {
                ptr: raw
            }
        }
    }
}
pub const DESTROY_NOTIFY: u8 = 17;
pub type DestroyNotifyEvent = base::Event<xcb_destroy_notify_event_t>;
impl DestroyNotifyEvent {
    
    
    pub fn event(&self) -> Window {
        unsafe {
            (*self.ptr).event
        }
    }
    
    pub fn window(&self) -> Window {
        unsafe {
            (*self.ptr).window
        }
    }
    
    
    pub fn new(event: Window,
               window: Window)
            -> DestroyNotifyEvent {
        unsafe {
            let raw = libc::malloc(32 as usize) as *mut xcb_destroy_notify_event_t;
            (*raw).response_type = DESTROY_NOTIFY;
            (*raw).event = event;
            (*raw).window = window;
            DestroyNotifyEvent {
                ptr: raw
            }
        }
    }
}
pub const UNMAP_NOTIFY: u8 = 18;
pub type UnmapNotifyEvent = base::Event<xcb_unmap_notify_event_t>;
impl UnmapNotifyEvent {
    
    
    pub fn event(&self) -> Window {
        unsafe {
            (*self.ptr).event
        }
    }
    
    pub fn window(&self) -> Window {
        unsafe {
            (*self.ptr).window
        }
    }
    
    
    pub fn from_configure(&self) -> bool {
        unsafe {
            (*self.ptr).from_configure != 0
        }
    }
    
    
    pub fn new(event: Window,
               window: Window,
               from_configure: bool)
            -> UnmapNotifyEvent {
        unsafe {
            let raw = libc::malloc(32 as usize) as *mut xcb_unmap_notify_event_t;
            (*raw).response_type = UNMAP_NOTIFY;
            (*raw).event = event;
            (*raw).window = window;
            (*raw).from_configure = if from_configure { 1 } else { 0 };
            UnmapNotifyEvent {
                ptr: raw
            }
        }
    }
}
pub const MAP_NOTIFY: u8 = 19;
pub type MapNotifyEvent = base::Event<xcb_map_notify_event_t>;
impl MapNotifyEvent {
    
    
    pub fn event(&self) -> Window {
        unsafe {
            (*self.ptr).event
        }
    }
    
    pub fn window(&self) -> Window {
        unsafe {
            (*self.ptr).window
        }
    }
    
    pub fn override_redirect(&self) -> bool {
        unsafe {
            (*self.ptr).override_redirect != 0
        }
    }
    
    
    pub fn new(event: Window,
               window: Window,
               override_redirect: bool)
            -> MapNotifyEvent {
        unsafe {
            let raw = libc::malloc(32 as usize) as *mut xcb_map_notify_event_t;
            (*raw).response_type = MAP_NOTIFY;
            (*raw).event = event;
            (*raw).window = window;
            (*raw).override_redirect = if override_redirect { 1 } else { 0 };
            MapNotifyEvent {
                ptr: raw
            }
        }
    }
}
pub const MAP_REQUEST: u8 = 20;
pub type MapRequestEvent = base::Event<xcb_map_request_event_t>;
impl MapRequestEvent {
    
    pub fn parent(&self) -> Window {
        unsafe {
            (*self.ptr).parent
        }
    }
    
    pub fn window(&self) -> Window {
        unsafe {
            (*self.ptr).window
        }
    }
    
    
    pub fn new(parent: Window,
               window: Window)
            -> MapRequestEvent {
        unsafe {
            let raw = libc::malloc(32 as usize) as *mut xcb_map_request_event_t;
            (*raw).response_type = MAP_REQUEST;
            (*raw).parent = parent;
            (*raw).window = window;
            MapRequestEvent {
                ptr: raw
            }
        }
    }
}
pub const REPARENT_NOTIFY: u8 = 21;
pub type ReparentNotifyEvent = base::Event<xcb_reparent_notify_event_t>;
impl ReparentNotifyEvent {
    pub fn event(&self) -> Window {
        unsafe {
            (*self.ptr).event
        }
    }
    pub fn window(&self) -> Window {
        unsafe {
            (*self.ptr).window
        }
    }
    pub fn parent(&self) -> Window {
        unsafe {
            (*self.ptr).parent
        }
    }
    pub fn x(&self) -> i16 {
        unsafe {
            (*self.ptr).x
        }
    }
    pub fn y(&self) -> i16 {
        unsafe {
            (*self.ptr).y
        }
    }
    pub fn override_redirect(&self) -> bool {
        unsafe {
            (*self.ptr).override_redirect != 0
        }
    }
    
    
    pub fn new(event: Window,
               window: Window,
               parent: Window,
               x: i16,
               y: i16,
               override_redirect: bool)
            -> ReparentNotifyEvent {
        unsafe {
            let raw = libc::malloc(32 as usize) as *mut xcb_reparent_notify_event_t;
            (*raw).response_type = REPARENT_NOTIFY;
            (*raw).event = event;
            (*raw).window = window;
            (*raw).parent = parent;
            (*raw).x = x;
            (*raw).y = y;
            (*raw).override_redirect = if override_redirect { 1 } else { 0 };
            ReparentNotifyEvent {
                ptr: raw
            }
        }
    }
}
pub const CONFIGURE_NOTIFY: u8 = 22;
pub type ConfigureNotifyEvent = base::Event<xcb_configure_notify_event_t>;
impl ConfigureNotifyEvent {
    
    
    pub fn event(&self) -> Window {
        unsafe {
            (*self.ptr).event
        }
    }
    
    pub fn window(&self) -> Window {
        unsafe {
            (*self.ptr).window
        }
    }
    
    
    
    pub fn above_sibling(&self) -> Window {
        unsafe {
            (*self.ptr).above_sibling
        }
    }
    
    
    pub fn x(&self) -> i16 {
        unsafe {
            (*self.ptr).x
        }
    }
    
    
    pub fn y(&self) -> i16 {
        unsafe {
            (*self.ptr).y
        }
    }
    
    pub fn width(&self) -> u16 {
        unsafe {
            (*self.ptr).width
        }
    }
    
    pub fn height(&self) -> u16 {
        unsafe {
            (*self.ptr).height
        }
    }
    
    pub fn border_width(&self) -> u16 {
        unsafe {
            (*self.ptr).border_width
        }
    }
    
    pub fn override_redirect(&self) -> bool {
        unsafe {
            (*self.ptr).override_redirect != 0
        }
    }
    
    
    pub fn new(event: Window,
               window: Window,
               above_sibling: Window,
               x: i16,
               y: i16,
               width: u16,
               height: u16,
               border_width: u16,
               override_redirect: bool)
            -> ConfigureNotifyEvent {
        unsafe {
            let raw = libc::malloc(32 as usize) as *mut xcb_configure_notify_event_t;
            (*raw).response_type = CONFIGURE_NOTIFY;
            (*raw).event = event;
            (*raw).window = window;
            (*raw).above_sibling = above_sibling;
            (*raw).x = x;
            (*raw).y = y;
            (*raw).width = width;
            (*raw).height = height;
            (*raw).border_width = border_width;
            (*raw).override_redirect = if override_redirect { 1 } else { 0 };
            ConfigureNotifyEvent {
                ptr: raw
            }
        }
    }
}
pub const CONFIGURE_REQUEST: u8 = 23;
pub type ConfigureRequestEvent = base::Event<xcb_configure_request_event_t>;
impl ConfigureRequestEvent {
    pub fn stack_mode(&self) -> u8 {
        unsafe {
            (*self.ptr).stack_mode
        }
    }
    pub fn parent(&self) -> Window {
        unsafe {
            (*self.ptr).parent
        }
    }
    pub fn window(&self) -> Window {
        unsafe {
            (*self.ptr).window
        }
    }
    pub fn sibling(&self) -> Window {
        unsafe {
            (*self.ptr).sibling
        }
    }
    pub fn x(&self) -> i16 {
        unsafe {
            (*self.ptr).x
        }
    }
    pub fn y(&self) -> i16 {
        unsafe {
            (*self.ptr).y
        }
    }
    pub fn width(&self) -> u16 {
        unsafe {
            (*self.ptr).width
        }
    }
    pub fn height(&self) -> u16 {
        unsafe {
            (*self.ptr).height
        }
    }
    pub fn border_width(&self) -> u16 {
        unsafe {
            (*self.ptr).border_width
        }
    }
    pub fn value_mask(&self) -> u16 {
        unsafe {
            (*self.ptr).value_mask
        }
    }
    
    
    pub fn new(stack_mode: u8,
               parent: Window,
               window: Window,
               sibling: Window,
               x: i16,
               y: i16,
               width: u16,
               height: u16,
               border_width: u16,
               value_mask: u16)
            -> ConfigureRequestEvent {
        unsafe {
            let raw = libc::malloc(32 as usize) as *mut xcb_configure_request_event_t;
            (*raw).response_type = CONFIGURE_REQUEST;
            (*raw).stack_mode = stack_mode;
            (*raw).parent = parent;
            (*raw).window = window;
            (*raw).sibling = sibling;
            (*raw).x = x;
            (*raw).y = y;
            (*raw).width = width;
            (*raw).height = height;
            (*raw).border_width = border_width;
            (*raw).value_mask = value_mask;
            ConfigureRequestEvent {
                ptr: raw
            }
        }
    }
}
pub const GRAVITY_NOTIFY: u8 = 24;
pub type GravityNotifyEvent = base::Event<xcb_gravity_notify_event_t>;
impl GravityNotifyEvent {
    pub fn event(&self) -> Window {
        unsafe {
            (*self.ptr).event
        }
    }
    pub fn window(&self) -> Window {
        unsafe {
            (*self.ptr).window
        }
    }
    pub fn x(&self) -> i16 {
        unsafe {
            (*self.ptr).x
        }
    }
    pub fn y(&self) -> i16 {
        unsafe {
            (*self.ptr).y
        }
    }
    
    
    pub fn new(event: Window,
               window: Window,
               x: i16,
               y: i16)
            -> GravityNotifyEvent {
        unsafe {
            let raw = libc::malloc(32 as usize) as *mut xcb_gravity_notify_event_t;
            (*raw).response_type = GRAVITY_NOTIFY;
            (*raw).event = event;
            (*raw).window = window;
            (*raw).x = x;
            (*raw).y = y;
            GravityNotifyEvent {
                ptr: raw
            }
        }
    }
}
pub const RESIZE_REQUEST: u8 = 25;
pub type ResizeRequestEvent = base::Event<xcb_resize_request_event_t>;
impl ResizeRequestEvent {
    pub fn window(&self) -> Window {
        unsafe {
            (*self.ptr).window
        }
    }
    pub fn width(&self) -> u16 {
        unsafe {
            (*self.ptr).width
        }
    }
    pub fn height(&self) -> u16 {
        unsafe {
            (*self.ptr).height
        }
    }
    
    
    pub fn new(window: Window,
               width: u16,
               height: u16)
            -> ResizeRequestEvent {
        unsafe {
            let raw = libc::malloc(32 as usize) as *mut xcb_resize_request_event_t;
            (*raw).response_type = RESIZE_REQUEST;
            (*raw).window = window;
            (*raw).width = width;
            (*raw).height = height;
            ResizeRequestEvent {
                ptr: raw
            }
        }
    }
}
pub const CIRCULATE_NOTIFY: u8 = 26;
pub type CirculateNotifyEvent = base::Event<xcb_circulate_notify_event_t>;
impl CirculateNotifyEvent {
    
    
    pub fn event(&self) -> Window {
        unsafe {
            (*self.ptr).event
        }
    }
    
    pub fn window(&self) -> Window {
        unsafe {
            (*self.ptr).window
        }
    }
    
    pub fn place(&self) -> u8 {
        unsafe {
            (*self.ptr).place
        }
    }
    
    
    
    
    pub fn new(response_type: u8,
               event: Window,
               window: Window,
               place: u8)
            -> CirculateNotifyEvent {
        unsafe {
            let raw = libc::malloc(32 as usize) as *mut xcb_circulate_notify_event_t;
            assert!(response_type == CIRCULATE_REQUEST ||
                    response_type == CIRCULATE_NOTIFY,
                    "wrong response_type supplied to CirculateNotifyEvent::new");
            (*raw).response_type = response_type;
            (*raw).event = event;
            (*raw).window = window;
            (*raw).place = place;
            CirculateNotifyEvent {
                ptr: raw
            }
        }
    }
}
pub const CIRCULATE_REQUEST: u8 = 27;
pub type CirculateRequestEvent = base::Event<xcb_circulate_request_event_t>;
pub const PROPERTY_NOTIFY: u8 = 28;
pub type PropertyNotifyEvent = base::Event<xcb_property_notify_event_t>;
impl PropertyNotifyEvent {
    
    pub fn window(&self) -> Window {
        unsafe {
            (*self.ptr).window
        }
    }
    
    pub fn atom(&self) -> Atom {
        unsafe {
            (*self.ptr).atom
        }
    }
    
    pub fn time(&self) -> Timestamp {
        unsafe {
            (*self.ptr).time
        }
    }
    
    pub fn state(&self) -> u8 {
        unsafe {
            (*self.ptr).state
        }
    }
    
    
    pub fn new(window: Window,
               atom: Atom,
               time: Timestamp,
               state: u8)
            -> PropertyNotifyEvent {
        unsafe {
            let raw = libc::malloc(32 as usize) as *mut xcb_property_notify_event_t;
            (*raw).response_type = PROPERTY_NOTIFY;
            (*raw).window = window;
            (*raw).atom = atom;
            (*raw).time = time;
            (*raw).state = state;
            PropertyNotifyEvent {
                ptr: raw
            }
        }
    }
}
pub const SELECTION_CLEAR: u8 = 29;
pub type SelectionClearEvent = base::Event<xcb_selection_clear_event_t>;
impl SelectionClearEvent {
    pub fn time(&self) -> Timestamp {
        unsafe {
            (*self.ptr).time
        }
    }
    pub fn owner(&self) -> Window {
        unsafe {
            (*self.ptr).owner
        }
    }
    pub fn selection(&self) -> Atom {
        unsafe {
            (*self.ptr).selection
        }
    }
    
    
    pub fn new(time: Timestamp,
               owner: Window,
               selection: Atom)
            -> SelectionClearEvent {
        unsafe {
            let raw = libc::malloc(32 as usize) as *mut xcb_selection_clear_event_t;
            (*raw).response_type = SELECTION_CLEAR;
            (*raw).time = time;
            (*raw).owner = owner;
            (*raw).selection = selection;
            SelectionClearEvent {
                ptr: raw
            }
        }
    }
}
pub const SELECTION_REQUEST: u8 = 30;
pub type SelectionRequestEvent = base::Event<xcb_selection_request_event_t>;
impl SelectionRequestEvent {
    pub fn time(&self) -> Timestamp {
        unsafe {
            (*self.ptr).time
        }
    }
    pub fn owner(&self) -> Window {
        unsafe {
            (*self.ptr).owner
        }
    }
    pub fn requestor(&self) -> Window {
        unsafe {
            (*self.ptr).requestor
        }
    }
    pub fn selection(&self) -> Atom {
        unsafe {
            (*self.ptr).selection
        }
    }
    pub fn target(&self) -> Atom {
        unsafe {
            (*self.ptr).target
        }
    }
    pub fn property(&self) -> Atom {
        unsafe {
            (*self.ptr).property
        }
    }
    
    
    pub fn new(time: Timestamp,
               owner: Window,
               requestor: Window,
               selection: Atom,
               target: Atom,
               property: Atom)
            -> SelectionRequestEvent {
        unsafe {
            let raw = libc::malloc(32 as usize) as *mut xcb_selection_request_event_t;
            (*raw).response_type = SELECTION_REQUEST;
            (*raw).time = time;
            (*raw).owner = owner;
            (*raw).requestor = requestor;
            (*raw).selection = selection;
            (*raw).target = target;
            (*raw).property = property;
            SelectionRequestEvent {
                ptr: raw
            }
        }
    }
}
pub const SELECTION_NOTIFY: u8 = 31;
pub type SelectionNotifyEvent = base::Event<xcb_selection_notify_event_t>;
impl SelectionNotifyEvent {
    pub fn time(&self) -> Timestamp {
        unsafe {
            (*self.ptr).time
        }
    }
    pub fn requestor(&self) -> Window {
        unsafe {
            (*self.ptr).requestor
        }
    }
    pub fn selection(&self) -> Atom {
        unsafe {
            (*self.ptr).selection
        }
    }
    pub fn target(&self) -> Atom {
        unsafe {
            (*self.ptr).target
        }
    }
    pub fn property(&self) -> Atom {
        unsafe {
            (*self.ptr).property
        }
    }
    
    
    pub fn new(time: Timestamp,
               requestor: Window,
               selection: Atom,
               target: Atom,
               property: Atom)
            -> SelectionNotifyEvent {
        unsafe {
            let raw = libc::malloc(32 as usize) as *mut xcb_selection_notify_event_t;
            (*raw).response_type = SELECTION_NOTIFY;
            (*raw).time = time;
            (*raw).requestor = requestor;
            (*raw).selection = selection;
            (*raw).target = target;
            (*raw).property = property;
            SelectionNotifyEvent {
                ptr: raw
            }
        }
    }
}
pub const COLORMAP_NOTIFY: u8 = 32;
pub type ColormapNotifyEvent = base::Event<xcb_colormap_notify_event_t>;
impl ColormapNotifyEvent {
    
    pub fn window(&self) -> Window {
        unsafe {
            (*self.ptr).window
        }
    }
    
    
    pub fn colormap(&self) -> Colormap {
        unsafe {
            (*self.ptr).colormap
        }
    }
    pub fn new_(&self) -> bool {
        unsafe {
            (*self.ptr).new_ != 0
        }
    }
    
    pub fn state(&self) -> u8 {
        unsafe {
            (*self.ptr).state
        }
    }
    
    
    pub fn new(window: Window,
               colormap: Colormap,
               new_: bool,
               state: u8)
            -> ColormapNotifyEvent {
        unsafe {
            let raw = libc::malloc(32 as usize) as *mut xcb_colormap_notify_event_t;
            (*raw).response_type = COLORMAP_NOTIFY;
            (*raw).window = window;
            (*raw).colormap = colormap;
            (*raw).new_ = if new_ { 1 } else { 0 };
            (*raw).state = state;
            ColormapNotifyEvent {
                ptr: raw
            }
        }
    }
}
pub type ClientMessageData = xcb_client_message_data_t;
impl ClientMessageData {
    pub fn data8(&self) -> &[u8] {
        unsafe {
            let ptr = self.data.as_ptr() as *const u8;
            std::slice::from_raw_parts(ptr, 20)
        }
    }
    pub fn from_data8(data8: [u8; 20]) -> ClientMessageData {
        unsafe {
            ClientMessageData { data: std::mem::transmute(data8) }
        }
    }
    pub fn data16(&self) -> &[u16] {
        unsafe {
            let ptr = self.data.as_ptr() as *const u16;
            std::slice::from_raw_parts(ptr, 10)
        }
    }
    pub fn from_data16(data16: [u16; 10]) -> ClientMessageData {
        unsafe {
            ClientMessageData { data: std::mem::transmute(data16) }
        }
    }
    pub fn data32(&self) -> &[u32] {
        unsafe {
            let ptr = self.data.as_ptr() as *const u32;
            std::slice::from_raw_parts(ptr, 5)
        }
    }
    pub fn from_data32(data32: [u32; 5]) -> ClientMessageData {
        unsafe {
            ClientMessageData { data: std::mem::transmute(data32) }
        }
    }
}
pub type ClientMessageDataIterator = xcb_client_message_data_iterator_t;
impl Iterator for ClientMessageDataIterator {
    type Item = ClientMessageData;
    fn next(&mut self) -> std::option::Option<ClientMessageData> {
        if self.rem == 0 { None }
        else {
            unsafe {
                let iter = self as *mut xcb_client_message_data_iterator_t;
                let data = (*iter).data;
                xcb_client_message_data_next(iter);
                Some(*data)
            }
        }
    }
}
pub const CLIENT_MESSAGE: u8 = 33;
pub type ClientMessageEvent = base::Event<xcb_client_message_event_t>;
impl ClientMessageEvent {
    
    pub fn format(&self) -> u8 {
        unsafe {
            (*self.ptr).format
        }
    }
    pub fn window(&self) -> Window {
        unsafe {
            (*self.ptr).window
        }
    }
    
    
    pub fn type_(&self) -> Atom {
        unsafe {
            (*self.ptr).type_
        }
    }
    
    pub fn data<'a>(&'a self) -> &'a ClientMessageData {
        unsafe {
            &(*self.ptr).data
        }
    }
    
    
    pub fn new(format: u8,
               window: Window,
               type_: Atom,
               data: ClientMessageData)
            -> ClientMessageEvent {
        unsafe {
            let raw = libc::malloc(32 as usize) as *mut xcb_client_message_event_t;
            (*raw).response_type = CLIENT_MESSAGE;
            (*raw).format = format;
            (*raw).window = window;
            (*raw).type_ = type_;
            (*raw).data = data;
            ClientMessageEvent {
                ptr: raw
            }
        }
    }
}
pub const MAPPING_NOTIFY: u8 = 34;
pub type MappingNotifyEvent = base::Event<xcb_mapping_notify_event_t>;
impl MappingNotifyEvent {
    
    pub fn request(&self) -> u8 {
        unsafe {
            (*self.ptr).request
        }
    }
    
    pub fn first_keycode(&self) -> Keycode {
        unsafe {
            (*self.ptr).first_keycode
        }
    }
    
    pub fn count(&self) -> u8 {
        unsafe {
            (*self.ptr).count
        }
    }
    
    
    pub fn new(request: u8,
               first_keycode: Keycode,
               count: u8)
            -> MappingNotifyEvent {
        unsafe {
            let raw = libc::malloc(32 as usize) as *mut xcb_mapping_notify_event_t;
            (*raw).response_type = MAPPING_NOTIFY;
            (*raw).request = request;
            (*raw).first_keycode = first_keycode;
            (*raw).count = count;
            MappingNotifyEvent {
                ptr: raw
            }
        }
    }
}
pub const GE_GENERIC: u8 = 35;
pub type GeGenericEvent = base::Event<xcb_ge_generic_event_t>;
impl GeGenericEvent {
    
    
    pub fn new()
            -> GeGenericEvent {
        unsafe {
            let raw = libc::malloc(32 as usize) as *mut xcb_ge_generic_event_t;
            (*raw).response_type = GE_GENERIC;
            GeGenericEvent {
                ptr: raw
            }
        }
    }
}
pub const REQUEST: u8 = 1;
pub const VALUE: u8 = 2;
pub const WINDOW: u8 = 3;
pub const PIXMAP: u8 = 4;
pub const ATOM: u8 = 5;
pub const CURSOR: u8 = 6;
pub const FONT: u8 = 7;
pub const MATCH: u8 = 8;
pub const DRAWABLE: u8 = 9;
pub const ACCESS: u8 = 10;
pub const ALLOC: u8 = 11;
pub const COLORMAP: u8 = 12;
pub const G_CONTEXT: u8 = 13;
pub const ID_CHOICE: u8 = 14;
pub const NAME: u8 = 15;
pub const LENGTH: u8 = 16;
pub const IMPLEMENTATION: u8 = 17;
pub const CREATE_WINDOW: u8 = 1;
pub fn create_window<'a>(c           : &'a base::Connection,
                         depth       : u8,
                         wid         : Window,
                         parent      : Window,
                         x           : i16,
                         y           : i16,
                         width       : u16,
                         height      : u16,
                         border_width: u16,
                         class       : u16,
                         visual      : Visualid,
                         value_list  : &[(u32, u32)])
        -> base::VoidCookie<'a> {
    unsafe {
        let mut value_list_copy = value_list.to_vec();
        let (value_list_mask, value_list_vec) = base::pack_bitfield(&mut value_list_copy);
        let value_list_ptr = value_list_vec.as_ptr();
        let cookie = xcb_create_window(c.get_raw_conn(),
                                       depth as u8,  
                                       wid as xcb_window_t,  
                                       parent as xcb_window_t,  
                                       x as i16,  
                                       y as i16,  
                                       width as u16,  
                                       height as u16,  
                                       border_width as u16,  
                                       class as u16,  
                                       visual as xcb_visualid_t,  
                                       value_list_mask as u32,  
                                       value_list_ptr as *const u32);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn create_window_checked<'a>(c           : &'a base::Connection,
                                 depth       : u8,
                                 wid         : Window,
                                 parent      : Window,
                                 x           : i16,
                                 y           : i16,
                                 width       : u16,
                                 height      : u16,
                                 border_width: u16,
                                 class       : u16,
                                 visual      : Visualid,
                                 value_list  : &[(u32, u32)])
        -> base::VoidCookie<'a> {
    unsafe {
        let mut value_list_copy = value_list.to_vec();
        let (value_list_mask, value_list_vec) = base::pack_bitfield(&mut value_list_copy);
        let value_list_ptr = value_list_vec.as_ptr();
        let cookie = xcb_create_window_checked(c.get_raw_conn(),
                                               depth as u8,  
                                               wid as xcb_window_t,  
                                               parent as xcb_window_t,  
                                               x as i16,  
                                               y as i16,  
                                               width as u16,  
                                               height as u16,  
                                               border_width as u16,  
                                               class as u16,  
                                               visual as xcb_visualid_t,  
                                               value_list_mask as u32,  
                                               value_list_ptr as *const u32);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const CHANGE_WINDOW_ATTRIBUTES: u8 = 2;
pub fn change_window_attributes<'a>(c         : &'a base::Connection,
                                    window    : Window,
                                    value_list: &[(u32, u32)])
        -> base::VoidCookie<'a> {
    unsafe {
        let mut value_list_copy = value_list.to_vec();
        let (value_list_mask, value_list_vec) = base::pack_bitfield(&mut value_list_copy);
        let value_list_ptr = value_list_vec.as_ptr();
        let cookie = xcb_change_window_attributes(c.get_raw_conn(),
                                                  window as xcb_window_t,  
                                                  value_list_mask as u32,  
                                                  value_list_ptr as *const u32);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn change_window_attributes_checked<'a>(c         : &'a base::Connection,
                                            window    : Window,
                                            value_list: &[(u32, u32)])
        -> base::VoidCookie<'a> {
    unsafe {
        let mut value_list_copy = value_list.to_vec();
        let (value_list_mask, value_list_vec) = base::pack_bitfield(&mut value_list_copy);
        let value_list_ptr = value_list_vec.as_ptr();
        let cookie = xcb_change_window_attributes_checked(c.get_raw_conn(),
                                                          window as xcb_window_t,  
                                                          value_list_mask as u32,  
                                                          value_list_ptr as *const u32);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const GET_WINDOW_ATTRIBUTES: u8 = 3;
pub type GetWindowAttributesCookie<'a> = base::Cookie<'a, xcb_get_window_attributes_cookie_t>;
impl<'a> GetWindowAttributesCookie<'a> {
    pub fn get_reply(&self) -> Result<GetWindowAttributesReply, base::GenericError> {
        unsafe {
            if self.checked {
                let mut err: *mut xcb_generic_error_t = std::ptr::null_mut();
                let reply = GetWindowAttributesReply {
                    ptr: xcb_get_window_attributes_reply (self.conn.get_raw_conn(), self.cookie, &mut err)
                };
                if err.is_null() { Ok (reply) }
                else { Err(base::GenericError { ptr: err }) }
            } else {
                Ok( GetWindowAttributesReply {
                    ptr: xcb_get_window_attributes_reply (self.conn.get_raw_conn(), self.cookie,
                            std::ptr::null_mut())
                })
            }
        }
    }
}
pub type GetWindowAttributesReply = base::Reply<xcb_get_window_attributes_reply_t>;
impl GetWindowAttributesReply {
    pub fn backing_store(&self) -> u8 {
        unsafe {
            (*self.ptr).backing_store
        }
    }
    pub fn visual(&self) -> Visualid {
        unsafe {
            (*self.ptr).visual
        }
    }
    pub fn class(&self) -> u16 {
        unsafe {
            (*self.ptr).class
        }
    }
    pub fn bit_gravity(&self) -> u8 {
        unsafe {
            (*self.ptr).bit_gravity
        }
    }
    pub fn win_gravity(&self) -> u8 {
        unsafe {
            (*self.ptr).win_gravity
        }
    }
    pub fn backing_planes(&self) -> u32 {
        unsafe {
            (*self.ptr).backing_planes
        }
    }
    pub fn backing_pixel(&self) -> u32 {
        unsafe {
            (*self.ptr).backing_pixel
        }
    }
    pub fn save_under(&self) -> bool {
        unsafe {
            (*self.ptr).save_under != 0
        }
    }
    pub fn map_is_installed(&self) -> bool {
        unsafe {
            (*self.ptr).map_is_installed != 0
        }
    }
    pub fn map_state(&self) -> u8 {
        unsafe {
            (*self.ptr).map_state
        }
    }
    pub fn override_redirect(&self) -> bool {
        unsafe {
            (*self.ptr).override_redirect != 0
        }
    }
    pub fn colormap(&self) -> Colormap {
        unsafe {
            (*self.ptr).colormap
        }
    }
    pub fn all_event_masks(&self) -> u32 {
        unsafe {
            (*self.ptr).all_event_masks
        }
    }
    pub fn your_event_mask(&self) -> u32 {
        unsafe {
            (*self.ptr).your_event_mask
        }
    }
    pub fn do_not_propagate_mask(&self) -> u16 {
        unsafe {
            (*self.ptr).do_not_propagate_mask
        }
    }
}
pub fn get_window_attributes<'a>(c     : &'a base::Connection,
                                 window: Window)
        -> GetWindowAttributesCookie<'a> {
    unsafe {
        let cookie = xcb_get_window_attributes(c.get_raw_conn(),
                                               window as xcb_window_t);  
        GetWindowAttributesCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub fn get_window_attributes_unchecked<'a>(c     : &'a base::Connection,
                                           window: Window)
        -> GetWindowAttributesCookie<'a> {
    unsafe {
        let cookie = xcb_get_window_attributes_unchecked(c.get_raw_conn(),
                                                         window as xcb_window_t);  
        GetWindowAttributesCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub const DESTROY_WINDOW: u8 = 4;
pub fn destroy_window<'a>(c     : &'a base::Connection,
                          window: Window)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_destroy_window(c.get_raw_conn(),
                                        window as xcb_window_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn destroy_window_checked<'a>(c     : &'a base::Connection,
                                  window: Window)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_destroy_window_checked(c.get_raw_conn(),
                                                window as xcb_window_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const DESTROY_SUBWINDOWS: u8 = 5;
pub fn destroy_subwindows<'a>(c     : &'a base::Connection,
                              window: Window)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_destroy_subwindows(c.get_raw_conn(),
                                            window as xcb_window_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn destroy_subwindows_checked<'a>(c     : &'a base::Connection,
                                      window: Window)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_destroy_subwindows_checked(c.get_raw_conn(),
                                                    window as xcb_window_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const CHANGE_SAVE_SET: u8 = 6;
pub fn change_save_set<'a>(c     : &'a base::Connection,
                           mode  : u8,
                           window: Window)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_change_save_set(c.get_raw_conn(),
                                         mode as u8,  
                                         window as xcb_window_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn change_save_set_checked<'a>(c     : &'a base::Connection,
                                   mode  : u8,
                                   window: Window)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_change_save_set_checked(c.get_raw_conn(),
                                                 mode as u8,  
                                                 window as xcb_window_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const REPARENT_WINDOW: u8 = 7;
pub fn reparent_window<'a>(c     : &'a base::Connection,
                           window: Window,
                           parent: Window,
                           x     : i16,
                           y     : i16)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_reparent_window(c.get_raw_conn(),
                                         window as xcb_window_t,  
                                         parent as xcb_window_t,  
                                         x as i16,  
                                         y as i16);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn reparent_window_checked<'a>(c     : &'a base::Connection,
                                   window: Window,
                                   parent: Window,
                                   x     : i16,
                                   y     : i16)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_reparent_window_checked(c.get_raw_conn(),
                                                 window as xcb_window_t,  
                                                 parent as xcb_window_t,  
                                                 x as i16,  
                                                 y as i16);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const MAP_WINDOW: u8 = 8;
pub fn map_window<'a>(c     : &'a base::Connection,
                      window: Window)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_map_window(c.get_raw_conn(),
                                    window as xcb_window_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn map_window_checked<'a>(c     : &'a base::Connection,
                              window: Window)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_map_window_checked(c.get_raw_conn(),
                                            window as xcb_window_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const MAP_SUBWINDOWS: u8 = 9;
pub fn map_subwindows<'a>(c     : &'a base::Connection,
                          window: Window)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_map_subwindows(c.get_raw_conn(),
                                        window as xcb_window_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn map_subwindows_checked<'a>(c     : &'a base::Connection,
                                  window: Window)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_map_subwindows_checked(c.get_raw_conn(),
                                                window as xcb_window_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const UNMAP_WINDOW: u8 = 10;
pub fn unmap_window<'a>(c     : &'a base::Connection,
                        window: Window)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_unmap_window(c.get_raw_conn(),
                                      window as xcb_window_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn unmap_window_checked<'a>(c     : &'a base::Connection,
                                window: Window)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_unmap_window_checked(c.get_raw_conn(),
                                              window as xcb_window_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const UNMAP_SUBWINDOWS: u8 = 11;
pub fn unmap_subwindows<'a>(c     : &'a base::Connection,
                            window: Window)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_unmap_subwindows(c.get_raw_conn(),
                                          window as xcb_window_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn unmap_subwindows_checked<'a>(c     : &'a base::Connection,
                                    window: Window)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_unmap_subwindows_checked(c.get_raw_conn(),
                                                  window as xcb_window_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const CONFIGURE_WINDOW: u8 = 12;
pub fn configure_window<'a>(c         : &'a base::Connection,
                            window    : Window,
                            value_list: &[(u16, u32)])
        -> base::VoidCookie<'a> {
    unsafe {
        let mut value_list_copy = value_list.to_vec();
        let (value_list_mask, value_list_vec) = base::pack_bitfield(&mut value_list_copy);
        let value_list_ptr = value_list_vec.as_ptr();
        let cookie = xcb_configure_window(c.get_raw_conn(),
                                          window as xcb_window_t,  
                                          value_list_mask as u16,  
                                          value_list_ptr as *const u32);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn configure_window_checked<'a>(c         : &'a base::Connection,
                                    window    : Window,
                                    value_list: &[(u16, u32)])
        -> base::VoidCookie<'a> {
    unsafe {
        let mut value_list_copy = value_list.to_vec();
        let (value_list_mask, value_list_vec) = base::pack_bitfield(&mut value_list_copy);
        let value_list_ptr = value_list_vec.as_ptr();
        let cookie = xcb_configure_window_checked(c.get_raw_conn(),
                                                  window as xcb_window_t,  
                                                  value_list_mask as u16,  
                                                  value_list_ptr as *const u32);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const CIRCULATE_WINDOW: u8 = 13;
pub fn circulate_window<'a>(c        : &'a base::Connection,
                            direction: u8,
                            window   : Window)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_circulate_window(c.get_raw_conn(),
                                          direction as u8,  
                                          window as xcb_window_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn circulate_window_checked<'a>(c        : &'a base::Connection,
                                    direction: u8,
                                    window   : Window)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_circulate_window_checked(c.get_raw_conn(),
                                                  direction as u8,  
                                                  window as xcb_window_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const GET_GEOMETRY: u8 = 14;
pub type GetGeometryCookie<'a> = base::Cookie<'a, xcb_get_geometry_cookie_t>;
impl<'a> GetGeometryCookie<'a> {
    pub fn get_reply(&self) -> Result<GetGeometryReply, base::GenericError> {
        unsafe {
            if self.checked {
                let mut err: *mut xcb_generic_error_t = std::ptr::null_mut();
                let reply = GetGeometryReply {
                    ptr: xcb_get_geometry_reply (self.conn.get_raw_conn(), self.cookie, &mut err)
                };
                if err.is_null() { Ok (reply) }
                else { Err(base::GenericError { ptr: err }) }
            } else {
                Ok( GetGeometryReply {
                    ptr: xcb_get_geometry_reply (self.conn.get_raw_conn(), self.cookie,
                            std::ptr::null_mut())
                })
            }
        }
    }
}
pub type GetGeometryReply = base::Reply<xcb_get_geometry_reply_t>;
impl GetGeometryReply {
    pub fn depth(&self) -> u8 {
        unsafe {
            (*self.ptr).depth
        }
    }
    pub fn root(&self) -> Window {
        unsafe {
            (*self.ptr).root
        }
    }
    pub fn x(&self) -> i16 {
        unsafe {
            (*self.ptr).x
        }
    }
    pub fn y(&self) -> i16 {
        unsafe {
            (*self.ptr).y
        }
    }
    pub fn width(&self) -> u16 {
        unsafe {
            (*self.ptr).width
        }
    }
    pub fn height(&self) -> u16 {
        unsafe {
            (*self.ptr).height
        }
    }
    pub fn border_width(&self) -> u16 {
        unsafe {
            (*self.ptr).border_width
        }
    }
}
pub fn get_geometry<'a>(c       : &'a base::Connection,
                        drawable: Drawable)
        -> GetGeometryCookie<'a> {
    unsafe {
        let cookie = xcb_get_geometry(c.get_raw_conn(),
                                      drawable as xcb_drawable_t);  
        GetGeometryCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub fn get_geometry_unchecked<'a>(c       : &'a base::Connection,
                                  drawable: Drawable)
        -> GetGeometryCookie<'a> {
    unsafe {
        let cookie = xcb_get_geometry_unchecked(c.get_raw_conn(),
                                                drawable as xcb_drawable_t);  
        GetGeometryCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub const QUERY_TREE: u8 = 15;
pub type QueryTreeCookie<'a> = base::Cookie<'a, xcb_query_tree_cookie_t>;
impl<'a> QueryTreeCookie<'a> {
    pub fn get_reply(&self) -> Result<QueryTreeReply, base::GenericError> {
        unsafe {
            if self.checked {
                let mut err: *mut xcb_generic_error_t = std::ptr::null_mut();
                let reply = QueryTreeReply {
                    ptr: xcb_query_tree_reply (self.conn.get_raw_conn(), self.cookie, &mut err)
                };
                if err.is_null() { Ok (reply) }
                else { Err(base::GenericError { ptr: err }) }
            } else {
                Ok( QueryTreeReply {
                    ptr: xcb_query_tree_reply (self.conn.get_raw_conn(), self.cookie,
                            std::ptr::null_mut())
                })
            }
        }
    }
}
pub type QueryTreeReply = base::Reply<xcb_query_tree_reply_t>;
impl QueryTreeReply {
    pub fn root(&self) -> Window {
        unsafe {
            (*self.ptr).root
        }
    }
    pub fn parent(&self) -> Window {
        unsafe {
            (*self.ptr).parent
        }
    }
    pub fn children_len(&self) -> u16 {
        unsafe {
            (*self.ptr).children_len
        }
    }
    pub fn children(&self) -> &[Window] {
        unsafe {
            let field = self.ptr;
            let len = xcb_query_tree_children_length(field) as usize;
            let data = xcb_query_tree_children(field);
            std::slice::from_raw_parts(data, len)
        }
    }
}
pub fn query_tree<'a>(c     : &'a base::Connection,
                      window: Window)
        -> QueryTreeCookie<'a> {
    unsafe {
        let cookie = xcb_query_tree(c.get_raw_conn(),
                                    window as xcb_window_t);  
        QueryTreeCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub fn query_tree_unchecked<'a>(c     : &'a base::Connection,
                                window: Window)
        -> QueryTreeCookie<'a> {
    unsafe {
        let cookie = xcb_query_tree_unchecked(c.get_raw_conn(),
                                              window as xcb_window_t);  
        QueryTreeCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub const INTERN_ATOM: u8 = 16;
pub type InternAtomCookie<'a> = base::Cookie<'a, xcb_intern_atom_cookie_t>;
impl<'a> InternAtomCookie<'a> {
    pub fn get_reply(&self) -> Result<InternAtomReply, base::GenericError> {
        unsafe {
            if self.checked {
                let mut err: *mut xcb_generic_error_t = std::ptr::null_mut();
                let reply = InternAtomReply {
                    ptr: xcb_intern_atom_reply (self.conn.get_raw_conn(), self.cookie, &mut err)
                };
                if err.is_null() { Ok (reply) }
                else { Err(base::GenericError { ptr: err }) }
            } else {
                Ok( InternAtomReply {
                    ptr: xcb_intern_atom_reply (self.conn.get_raw_conn(), self.cookie,
                            std::ptr::null_mut())
                })
            }
        }
    }
}
pub type InternAtomReply = base::Reply<xcb_intern_atom_reply_t>;
impl InternAtomReply {
    pub fn atom(&self) -> Atom {
        unsafe {
            (*self.ptr).atom
        }
    }
}
pub fn intern_atom<'a>(c             : &'a base::Connection,
                       only_if_exists: bool,
                       name          : &str)
        -> InternAtomCookie<'a> {
    unsafe {
        let name = name.as_bytes();
        let name_len = name.len();
        let name_ptr = name.as_ptr();
        let cookie = xcb_intern_atom(c.get_raw_conn(),
                                     only_if_exists as u8,  
                                     name_len as u16,  
                                     name_ptr as *const c_char);  
        InternAtomCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub fn intern_atom_unchecked<'a>(c             : &'a base::Connection,
                                 only_if_exists: bool,
                                 name          : &str)
        -> InternAtomCookie<'a> {
    unsafe {
        let name = name.as_bytes();
        let name_len = name.len();
        let name_ptr = name.as_ptr();
        let cookie = xcb_intern_atom_unchecked(c.get_raw_conn(),
                                               only_if_exists as u8,  
                                               name_len as u16,  
                                               name_ptr as *const c_char);  
        InternAtomCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub const GET_ATOM_NAME: u8 = 17;
pub type GetAtomNameCookie<'a> = base::Cookie<'a, xcb_get_atom_name_cookie_t>;
impl<'a> GetAtomNameCookie<'a> {
    pub fn get_reply(&self) -> Result<GetAtomNameReply, base::GenericError> {
        unsafe {
            if self.checked {
                let mut err: *mut xcb_generic_error_t = std::ptr::null_mut();
                let reply = GetAtomNameReply {
                    ptr: xcb_get_atom_name_reply (self.conn.get_raw_conn(), self.cookie, &mut err)
                };
                if err.is_null() { Ok (reply) }
                else { Err(base::GenericError { ptr: err }) }
            } else {
                Ok( GetAtomNameReply {
                    ptr: xcb_get_atom_name_reply (self.conn.get_raw_conn(), self.cookie,
                            std::ptr::null_mut())
                })
            }
        }
    }
}
pub type GetAtomNameReply = base::Reply<xcb_get_atom_name_reply_t>;
impl GetAtomNameReply {
    pub fn name_len(&self) -> u16 {
        unsafe {
            (*self.ptr).name_len
        }
    }
    pub fn name(&self) -> &str {
        unsafe {
            let field = self.ptr;
            let len = xcb_get_atom_name_name_length(field) as usize;
            let data = xcb_get_atom_name_name(field);
            let slice = std::slice::from_raw_parts(data as *const u8, len);
            
            std::str::from_utf8_unchecked(&slice)
        }
    }
}
pub fn get_atom_name<'a>(c   : &'a base::Connection,
                         atom: Atom)
        -> GetAtomNameCookie<'a> {
    unsafe {
        let cookie = xcb_get_atom_name(c.get_raw_conn(),
                                       atom as xcb_atom_t);  
        GetAtomNameCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub fn get_atom_name_unchecked<'a>(c   : &'a base::Connection,
                                   atom: Atom)
        -> GetAtomNameCookie<'a> {
    unsafe {
        let cookie = xcb_get_atom_name_unchecked(c.get_raw_conn(),
                                                 atom as xcb_atom_t);  
        GetAtomNameCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub const CHANGE_PROPERTY: u8 = 18;
pub fn change_property<'a, T>(c       : &'a base::Connection,
                              mode    : u8,
                              window  : Window,
                              property: Atom,
                              type_   : Atom,
                              format  : u8,
                              data    : &[T])
        -> base::VoidCookie<'a> {
    unsafe {
        let data_len = data.len();
        let data_ptr = data.as_ptr();
        let cookie = xcb_change_property(c.get_raw_conn(),
                                         mode as u8,  
                                         window as xcb_window_t,  
                                         property as xcb_atom_t,  
                                         type_ as xcb_atom_t,  
                                         format as u8,  
                                         data_len as u32,  
                                         data_ptr as *const c_void);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn change_property_checked<'a, T>(c       : &'a base::Connection,
                                      mode    : u8,
                                      window  : Window,
                                      property: Atom,
                                      type_   : Atom,
                                      format  : u8,
                                      data    : &[T])
        -> base::VoidCookie<'a> {
    unsafe {
        let data_len = data.len();
        let data_ptr = data.as_ptr();
        let cookie = xcb_change_property_checked(c.get_raw_conn(),
                                                 mode as u8,  
                                                 window as xcb_window_t,  
                                                 property as xcb_atom_t,  
                                                 type_ as xcb_atom_t,  
                                                 format as u8,  
                                                 data_len as u32,  
                                                 data_ptr as *const c_void);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const DELETE_PROPERTY: u8 = 19;
pub fn delete_property<'a>(c       : &'a base::Connection,
                           window  : Window,
                           property: Atom)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_delete_property(c.get_raw_conn(),
                                         window as xcb_window_t,  
                                         property as xcb_atom_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn delete_property_checked<'a>(c       : &'a base::Connection,
                                   window  : Window,
                                   property: Atom)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_delete_property_checked(c.get_raw_conn(),
                                                 window as xcb_window_t,  
                                                 property as xcb_atom_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const GET_PROPERTY: u8 = 20;
pub type GetPropertyCookie<'a> = base::Cookie<'a, xcb_get_property_cookie_t>;
impl<'a> GetPropertyCookie<'a> {
    pub fn get_reply(&self) -> Result<GetPropertyReply, base::GenericError> {
        unsafe {
            if self.checked {
                let mut err: *mut xcb_generic_error_t = std::ptr::null_mut();
                let reply = GetPropertyReply {
                    ptr: xcb_get_property_reply (self.conn.get_raw_conn(), self.cookie, &mut err)
                };
                if err.is_null() { Ok (reply) }
                else { Err(base::GenericError { ptr: err }) }
            } else {
                Ok( GetPropertyReply {
                    ptr: xcb_get_property_reply (self.conn.get_raw_conn(), self.cookie,
                            std::ptr::null_mut())
                })
            }
        }
    }
}
pub type GetPropertyReply = base::Reply<xcb_get_property_reply_t>;
impl GetPropertyReply {
    pub fn format(&self) -> u8 {
        unsafe {
            (*self.ptr).format
        }
    }
    pub fn type_(&self) -> Atom {
        unsafe {
            (*self.ptr).type_
        }
    }
    pub fn bytes_after(&self) -> u32 {
        unsafe {
            (*self.ptr).bytes_after
        }
    }
    pub fn value_len(&self) -> u32 {
        unsafe {
            (*self.ptr).value_len
        }
    }
    pub fn value<T>(&self) -> &[T] {
        unsafe {
            let field = self.ptr;
            let len = xcb_get_property_value_length(field) as usize;
            let data = xcb_get_property_value(field);
            debug_assert_eq!(len % std::mem::size_of::<T>(), 0);
            std::slice::from_raw_parts(data as *const T, len / std::mem::size_of::<T>())
        }
    }
}
pub fn get_property<'a>(c          : &'a base::Connection,
                        delete     : bool,
                        window     : Window,
                        property   : Atom,
                        type_      : Atom,
                        long_offset: u32,
                        long_length: u32)
        -> GetPropertyCookie<'a> {
    unsafe {
        let cookie = xcb_get_property(c.get_raw_conn(),
                                      delete as u8,  
                                      window as xcb_window_t,  
                                      property as xcb_atom_t,  
                                      type_ as xcb_atom_t,  
                                      long_offset as u32,  
                                      long_length as u32);  
        GetPropertyCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub fn get_property_unchecked<'a>(c          : &'a base::Connection,
                                  delete     : bool,
                                  window     : Window,
                                  property   : Atom,
                                  type_      : Atom,
                                  long_offset: u32,
                                  long_length: u32)
        -> GetPropertyCookie<'a> {
    unsafe {
        let cookie = xcb_get_property_unchecked(c.get_raw_conn(),
                                                delete as u8,  
                                                window as xcb_window_t,  
                                                property as xcb_atom_t,  
                                                type_ as xcb_atom_t,  
                                                long_offset as u32,  
                                                long_length as u32);  
        GetPropertyCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub const LIST_PROPERTIES: u8 = 21;
pub type ListPropertiesCookie<'a> = base::Cookie<'a, xcb_list_properties_cookie_t>;
impl<'a> ListPropertiesCookie<'a> {
    pub fn get_reply(&self) -> Result<ListPropertiesReply, base::GenericError> {
        unsafe {
            if self.checked {
                let mut err: *mut xcb_generic_error_t = std::ptr::null_mut();
                let reply = ListPropertiesReply {
                    ptr: xcb_list_properties_reply (self.conn.get_raw_conn(), self.cookie, &mut err)
                };
                if err.is_null() { Ok (reply) }
                else { Err(base::GenericError { ptr: err }) }
            } else {
                Ok( ListPropertiesReply {
                    ptr: xcb_list_properties_reply (self.conn.get_raw_conn(), self.cookie,
                            std::ptr::null_mut())
                })
            }
        }
    }
}
pub type ListPropertiesReply = base::Reply<xcb_list_properties_reply_t>;
impl ListPropertiesReply {
    pub fn atoms_len(&self) -> u16 {
        unsafe {
            (*self.ptr).atoms_len
        }
    }
    pub fn atoms(&self) -> &[Atom] {
        unsafe {
            let field = self.ptr;
            let len = xcb_list_properties_atoms_length(field) as usize;
            let data = xcb_list_properties_atoms(field);
            std::slice::from_raw_parts(data, len)
        }
    }
}
pub fn list_properties<'a>(c     : &'a base::Connection,
                           window: Window)
        -> ListPropertiesCookie<'a> {
    unsafe {
        let cookie = xcb_list_properties(c.get_raw_conn(),
                                         window as xcb_window_t);  
        ListPropertiesCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub fn list_properties_unchecked<'a>(c     : &'a base::Connection,
                                     window: Window)
        -> ListPropertiesCookie<'a> {
    unsafe {
        let cookie = xcb_list_properties_unchecked(c.get_raw_conn(),
                                                   window as xcb_window_t);  
        ListPropertiesCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub const SET_SELECTION_OWNER: u8 = 22;
pub fn set_selection_owner<'a>(c        : &'a base::Connection,
                               owner    : Window,
                               selection: Atom,
                               time     : Timestamp)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_set_selection_owner(c.get_raw_conn(),
                                             owner as xcb_window_t,  
                                             selection as xcb_atom_t,  
                                             time as xcb_timestamp_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn set_selection_owner_checked<'a>(c        : &'a base::Connection,
                                       owner    : Window,
                                       selection: Atom,
                                       time     : Timestamp)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_set_selection_owner_checked(c.get_raw_conn(),
                                                     owner as xcb_window_t,  
                                                     selection as xcb_atom_t,  
                                                     time as xcb_timestamp_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const GET_SELECTION_OWNER: u8 = 23;
pub type GetSelectionOwnerCookie<'a> = base::Cookie<'a, xcb_get_selection_owner_cookie_t>;
impl<'a> GetSelectionOwnerCookie<'a> {
    pub fn get_reply(&self) -> Result<GetSelectionOwnerReply, base::GenericError> {
        unsafe {
            if self.checked {
                let mut err: *mut xcb_generic_error_t = std::ptr::null_mut();
                let reply = GetSelectionOwnerReply {
                    ptr: xcb_get_selection_owner_reply (self.conn.get_raw_conn(), self.cookie, &mut err)
                };
                if err.is_null() { Ok (reply) }
                else { Err(base::GenericError { ptr: err }) }
            } else {
                Ok( GetSelectionOwnerReply {
                    ptr: xcb_get_selection_owner_reply (self.conn.get_raw_conn(), self.cookie,
                            std::ptr::null_mut())
                })
            }
        }
    }
}
pub type GetSelectionOwnerReply = base::Reply<xcb_get_selection_owner_reply_t>;
impl GetSelectionOwnerReply {
    pub fn owner(&self) -> Window {
        unsafe {
            (*self.ptr).owner
        }
    }
}
pub fn get_selection_owner<'a>(c        : &'a base::Connection,
                               selection: Atom)
        -> GetSelectionOwnerCookie<'a> {
    unsafe {
        let cookie = xcb_get_selection_owner(c.get_raw_conn(),
                                             selection as xcb_atom_t);  
        GetSelectionOwnerCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub fn get_selection_owner_unchecked<'a>(c        : &'a base::Connection,
                                         selection: Atom)
        -> GetSelectionOwnerCookie<'a> {
    unsafe {
        let cookie = xcb_get_selection_owner_unchecked(c.get_raw_conn(),
                                                       selection as xcb_atom_t);  
        GetSelectionOwnerCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub const CONVERT_SELECTION: u8 = 24;
pub fn convert_selection<'a>(c        : &'a base::Connection,
                             requestor: Window,
                             selection: Atom,
                             target   : Atom,
                             property : Atom,
                             time     : Timestamp)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_convert_selection(c.get_raw_conn(),
                                           requestor as xcb_window_t,  
                                           selection as xcb_atom_t,  
                                           target as xcb_atom_t,  
                                           property as xcb_atom_t,  
                                           time as xcb_timestamp_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn convert_selection_checked<'a>(c        : &'a base::Connection,
                                     requestor: Window,
                                     selection: Atom,
                                     target   : Atom,
                                     property : Atom,
                                     time     : Timestamp)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_convert_selection_checked(c.get_raw_conn(),
                                                   requestor as xcb_window_t,  
                                                   selection as xcb_atom_t,  
                                                   target as xcb_atom_t,  
                                                   property as xcb_atom_t,  
                                                   time as xcb_timestamp_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const SEND_EVENT: u8 = 25;
pub fn send_event<'a, T>(c          : &'a base::Connection,
                         propagate  : bool,
                         destination: Window,
                         event_mask : u32,
                         event      : &base::Event<T>)
        -> base::VoidCookie<'a> {
    unsafe {
        let event_ptr = std::mem::transmute(event.ptr);
        let cookie = xcb_send_event(c.get_raw_conn(),
                                    propagate as u8,  
                                    destination as xcb_window_t,  
                                    event_mask as u32,  
                                    event_ptr);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn send_event_checked<'a, T>(c          : &'a base::Connection,
                                 propagate  : bool,
                                 destination: Window,
                                 event_mask : u32,
                                 event      : &base::Event<T>)
        -> base::VoidCookie<'a> {
    unsafe {
        let event_ptr = std::mem::transmute(event.ptr);
        let cookie = xcb_send_event_checked(c.get_raw_conn(),
                                            propagate as u8,  
                                            destination as xcb_window_t,  
                                            event_mask as u32,  
                                            event_ptr);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const GRAB_POINTER: u8 = 26;
pub type GrabPointerCookie<'a> = base::Cookie<'a, xcb_grab_pointer_cookie_t>;
impl<'a> GrabPointerCookie<'a> {
    pub fn get_reply(&self) -> Result<GrabPointerReply, base::GenericError> {
        unsafe {
            if self.checked {
                let mut err: *mut xcb_generic_error_t = std::ptr::null_mut();
                let reply = GrabPointerReply {
                    ptr: xcb_grab_pointer_reply (self.conn.get_raw_conn(), self.cookie, &mut err)
                };
                if err.is_null() { Ok (reply) }
                else { Err(base::GenericError { ptr: err }) }
            } else {
                Ok( GrabPointerReply {
                    ptr: xcb_grab_pointer_reply (self.conn.get_raw_conn(), self.cookie,
                            std::ptr::null_mut())
                })
            }
        }
    }
}
pub type GrabPointerReply = base::Reply<xcb_grab_pointer_reply_t>;
impl GrabPointerReply {
    pub fn status(&self) -> u8 {
        unsafe {
            (*self.ptr).status
        }
    }
}
pub fn grab_pointer<'a>(c            : &'a base::Connection,
                        owner_events : bool,
                        grab_window  : Window,
                        event_mask   : u16,
                        pointer_mode : u8,
                        keyboard_mode: u8,
                        confine_to   : Window,
                        cursor       : Cursor,
                        time         : Timestamp)
        -> GrabPointerCookie<'a> {
    unsafe {
        let cookie = xcb_grab_pointer(c.get_raw_conn(),
                                      owner_events as u8,  
                                      grab_window as xcb_window_t,  
                                      event_mask as u16,  
                                      pointer_mode as u8,  
                                      keyboard_mode as u8,  
                                      confine_to as xcb_window_t,  
                                      cursor as xcb_cursor_t,  
                                      time as xcb_timestamp_t);  
        GrabPointerCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub fn grab_pointer_unchecked<'a>(c            : &'a base::Connection,
                                  owner_events : bool,
                                  grab_window  : Window,
                                  event_mask   : u16,
                                  pointer_mode : u8,
                                  keyboard_mode: u8,
                                  confine_to   : Window,
                                  cursor       : Cursor,
                                  time         : Timestamp)
        -> GrabPointerCookie<'a> {
    unsafe {
        let cookie = xcb_grab_pointer_unchecked(c.get_raw_conn(),
                                                owner_events as u8,  
                                                grab_window as xcb_window_t,  
                                                event_mask as u16,  
                                                pointer_mode as u8,  
                                                keyboard_mode as u8,  
                                                confine_to as xcb_window_t,  
                                                cursor as xcb_cursor_t,  
                                                time as xcb_timestamp_t);  
        GrabPointerCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub const UNGRAB_POINTER: u8 = 27;
pub fn ungrab_pointer<'a>(c   : &'a base::Connection,
                          time: Timestamp)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_ungrab_pointer(c.get_raw_conn(),
                                        time as xcb_timestamp_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn ungrab_pointer_checked<'a>(c   : &'a base::Connection,
                                  time: Timestamp)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_ungrab_pointer_checked(c.get_raw_conn(),
                                                time as xcb_timestamp_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const GRAB_BUTTON: u8 = 28;
pub fn grab_button<'a>(c            : &'a base::Connection,
                       owner_events : bool,
                       grab_window  : Window,
                       event_mask   : u16,
                       pointer_mode : u8,
                       keyboard_mode: u8,
                       confine_to   : Window,
                       cursor       : Cursor,
                       button       : u8,
                       modifiers    : u16)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_grab_button(c.get_raw_conn(),
                                     owner_events as u8,  
                                     grab_window as xcb_window_t,  
                                     event_mask as u16,  
                                     pointer_mode as u8,  
                                     keyboard_mode as u8,  
                                     confine_to as xcb_window_t,  
                                     cursor as xcb_cursor_t,  
                                     button as u8,  
                                     modifiers as u16);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn grab_button_checked<'a>(c            : &'a base::Connection,
                               owner_events : bool,
                               grab_window  : Window,
                               event_mask   : u16,
                               pointer_mode : u8,
                               keyboard_mode: u8,
                               confine_to   : Window,
                               cursor       : Cursor,
                               button       : u8,
                               modifiers    : u16)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_grab_button_checked(c.get_raw_conn(),
                                             owner_events as u8,  
                                             grab_window as xcb_window_t,  
                                             event_mask as u16,  
                                             pointer_mode as u8,  
                                             keyboard_mode as u8,  
                                             confine_to as xcb_window_t,  
                                             cursor as xcb_cursor_t,  
                                             button as u8,  
                                             modifiers as u16);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const UNGRAB_BUTTON: u8 = 29;
pub fn ungrab_button<'a>(c          : &'a base::Connection,
                         button     : u8,
                         grab_window: Window,
                         modifiers  : u16)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_ungrab_button(c.get_raw_conn(),
                                       button as u8,  
                                       grab_window as xcb_window_t,  
                                       modifiers as u16);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn ungrab_button_checked<'a>(c          : &'a base::Connection,
                                 button     : u8,
                                 grab_window: Window,
                                 modifiers  : u16)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_ungrab_button_checked(c.get_raw_conn(),
                                               button as u8,  
                                               grab_window as xcb_window_t,  
                                               modifiers as u16);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const CHANGE_ACTIVE_POINTER_GRAB: u8 = 30;
pub fn change_active_pointer_grab<'a>(c         : &'a base::Connection,
                                      cursor    : Cursor,
                                      time      : Timestamp,
                                      event_mask: u16)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_change_active_pointer_grab(c.get_raw_conn(),
                                                    cursor as xcb_cursor_t,  
                                                    time as xcb_timestamp_t,  
                                                    event_mask as u16);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn change_active_pointer_grab_checked<'a>(c         : &'a base::Connection,
                                              cursor    : Cursor,
                                              time      : Timestamp,
                                              event_mask: u16)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_change_active_pointer_grab_checked(c.get_raw_conn(),
                                                            cursor as xcb_cursor_t,  
                                                            time as xcb_timestamp_t,  
                                                            event_mask as u16);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const GRAB_KEYBOARD: u8 = 31;
pub type GrabKeyboardCookie<'a> = base::Cookie<'a, xcb_grab_keyboard_cookie_t>;
impl<'a> GrabKeyboardCookie<'a> {
    pub fn get_reply(&self) -> Result<GrabKeyboardReply, base::GenericError> {
        unsafe {
            if self.checked {
                let mut err: *mut xcb_generic_error_t = std::ptr::null_mut();
                let reply = GrabKeyboardReply {
                    ptr: xcb_grab_keyboard_reply (self.conn.get_raw_conn(), self.cookie, &mut err)
                };
                if err.is_null() { Ok (reply) }
                else { Err(base::GenericError { ptr: err }) }
            } else {
                Ok( GrabKeyboardReply {
                    ptr: xcb_grab_keyboard_reply (self.conn.get_raw_conn(), self.cookie,
                            std::ptr::null_mut())
                })
            }
        }
    }
}
pub type GrabKeyboardReply = base::Reply<xcb_grab_keyboard_reply_t>;
impl GrabKeyboardReply {
    pub fn status(&self) -> u8 {
        unsafe {
            (*self.ptr).status
        }
    }
}
pub fn grab_keyboard<'a>(c            : &'a base::Connection,
                         owner_events : bool,
                         grab_window  : Window,
                         time         : Timestamp,
                         pointer_mode : u8,
                         keyboard_mode: u8)
        -> GrabKeyboardCookie<'a> {
    unsafe {
        let cookie = xcb_grab_keyboard(c.get_raw_conn(),
                                       owner_events as u8,  
                                       grab_window as xcb_window_t,  
                                       time as xcb_timestamp_t,  
                                       pointer_mode as u8,  
                                       keyboard_mode as u8);  
        GrabKeyboardCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub fn grab_keyboard_unchecked<'a>(c            : &'a base::Connection,
                                   owner_events : bool,
                                   grab_window  : Window,
                                   time         : Timestamp,
                                   pointer_mode : u8,
                                   keyboard_mode: u8)
        -> GrabKeyboardCookie<'a> {
    unsafe {
        let cookie = xcb_grab_keyboard_unchecked(c.get_raw_conn(),
                                                 owner_events as u8,  
                                                 grab_window as xcb_window_t,  
                                                 time as xcb_timestamp_t,  
                                                 pointer_mode as u8,  
                                                 keyboard_mode as u8);  
        GrabKeyboardCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub const UNGRAB_KEYBOARD: u8 = 32;
pub fn ungrab_keyboard<'a>(c   : &'a base::Connection,
                           time: Timestamp)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_ungrab_keyboard(c.get_raw_conn(),
                                         time as xcb_timestamp_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn ungrab_keyboard_checked<'a>(c   : &'a base::Connection,
                                   time: Timestamp)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_ungrab_keyboard_checked(c.get_raw_conn(),
                                                 time as xcb_timestamp_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const GRAB_KEY: u8 = 33;
pub fn grab_key<'a>(c            : &'a base::Connection,
                    owner_events : bool,
                    grab_window  : Window,
                    modifiers    : u16,
                    key          : Keycode,
                    pointer_mode : u8,
                    keyboard_mode: u8)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_grab_key(c.get_raw_conn(),
                                  owner_events as u8,  
                                  grab_window as xcb_window_t,  
                                  modifiers as u16,  
                                  key as xcb_keycode_t,  
                                  pointer_mode as u8,  
                                  keyboard_mode as u8);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn grab_key_checked<'a>(c            : &'a base::Connection,
                            owner_events : bool,
                            grab_window  : Window,
                            modifiers    : u16,
                            key          : Keycode,
                            pointer_mode : u8,
                            keyboard_mode: u8)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_grab_key_checked(c.get_raw_conn(),
                                          owner_events as u8,  
                                          grab_window as xcb_window_t,  
                                          modifiers as u16,  
                                          key as xcb_keycode_t,  
                                          pointer_mode as u8,  
                                          keyboard_mode as u8);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const UNGRAB_KEY: u8 = 34;
pub fn ungrab_key<'a>(c          : &'a base::Connection,
                      key        : Keycode,
                      grab_window: Window,
                      modifiers  : u16)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_ungrab_key(c.get_raw_conn(),
                                    key as xcb_keycode_t,  
                                    grab_window as xcb_window_t,  
                                    modifiers as u16);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn ungrab_key_checked<'a>(c          : &'a base::Connection,
                              key        : Keycode,
                              grab_window: Window,
                              modifiers  : u16)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_ungrab_key_checked(c.get_raw_conn(),
                                            key as xcb_keycode_t,  
                                            grab_window as xcb_window_t,  
                                            modifiers as u16);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const ALLOW_EVENTS: u8 = 35;
pub fn allow_events<'a>(c   : &'a base::Connection,
                        mode: u8,
                        time: Timestamp)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_allow_events(c.get_raw_conn(),
                                      mode as u8,  
                                      time as xcb_timestamp_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn allow_events_checked<'a>(c   : &'a base::Connection,
                                mode: u8,
                                time: Timestamp)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_allow_events_checked(c.get_raw_conn(),
                                              mode as u8,  
                                              time as xcb_timestamp_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const GRAB_SERVER: u8 = 36;
pub fn grab_server<'a>(c: &'a base::Connection)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_grab_server(c.get_raw_conn());
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn grab_server_checked<'a>(c: &'a base::Connection)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_grab_server_checked(c.get_raw_conn());
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const UNGRAB_SERVER: u8 = 37;
pub fn ungrab_server<'a>(c: &'a base::Connection)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_ungrab_server(c.get_raw_conn());
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn ungrab_server_checked<'a>(c: &'a base::Connection)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_ungrab_server_checked(c.get_raw_conn());
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const QUERY_POINTER: u8 = 38;
pub type QueryPointerCookie<'a> = base::Cookie<'a, xcb_query_pointer_cookie_t>;
impl<'a> QueryPointerCookie<'a> {
    pub fn get_reply(&self) -> Result<QueryPointerReply, base::GenericError> {
        unsafe {
            if self.checked {
                let mut err: *mut xcb_generic_error_t = std::ptr::null_mut();
                let reply = QueryPointerReply {
                    ptr: xcb_query_pointer_reply (self.conn.get_raw_conn(), self.cookie, &mut err)
                };
                if err.is_null() { Ok (reply) }
                else { Err(base::GenericError { ptr: err }) }
            } else {
                Ok( QueryPointerReply {
                    ptr: xcb_query_pointer_reply (self.conn.get_raw_conn(), self.cookie,
                            std::ptr::null_mut())
                })
            }
        }
    }
}
pub type QueryPointerReply = base::Reply<xcb_query_pointer_reply_t>;
impl QueryPointerReply {
    pub fn same_screen(&self) -> bool {
        unsafe {
            (*self.ptr).same_screen != 0
        }
    }
    pub fn root(&self) -> Window {
        unsafe {
            (*self.ptr).root
        }
    }
    pub fn child(&self) -> Window {
        unsafe {
            (*self.ptr).child
        }
    }
    pub fn root_x(&self) -> i16 {
        unsafe {
            (*self.ptr).root_x
        }
    }
    pub fn root_y(&self) -> i16 {
        unsafe {
            (*self.ptr).root_y
        }
    }
    pub fn win_x(&self) -> i16 {
        unsafe {
            (*self.ptr).win_x
        }
    }
    pub fn win_y(&self) -> i16 {
        unsafe {
            (*self.ptr).win_y
        }
    }
    pub fn mask(&self) -> u16 {
        unsafe {
            (*self.ptr).mask
        }
    }
}
pub fn query_pointer<'a>(c     : &'a base::Connection,
                         window: Window)
        -> QueryPointerCookie<'a> {
    unsafe {
        let cookie = xcb_query_pointer(c.get_raw_conn(),
                                       window as xcb_window_t);  
        QueryPointerCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub fn query_pointer_unchecked<'a>(c     : &'a base::Connection,
                                   window: Window)
        -> QueryPointerCookie<'a> {
    unsafe {
        let cookie = xcb_query_pointer_unchecked(c.get_raw_conn(),
                                                 window as xcb_window_t);  
        QueryPointerCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
#[derive(Copy, Clone)]
pub struct Timecoord {
    pub base: xcb_timecoord_t,
}
impl Timecoord {
    #[allow(unused_unsafe)]
    pub fn new(time: Timestamp,
               x:    i16,
               y:    i16)
            -> Timecoord {
        unsafe {
            Timecoord {
                base: xcb_timecoord_t {
                    time: time,
                    x:    x,
                    y:    y,
                }
            }
        }
    }
    pub fn time(&self) -> Timestamp {
        unsafe {
            self.base.time
        }
    }
    pub fn x(&self) -> i16 {
        unsafe {
            self.base.x
        }
    }
    pub fn y(&self) -> i16 {
        unsafe {
            self.base.y
        }
    }
}
pub type TimecoordIterator = xcb_timecoord_iterator_t;
impl Iterator for TimecoordIterator {
    type Item = Timecoord;
    fn next(&mut self) -> std::option::Option<Timecoord> {
        if self.rem == 0 { None }
        else {
            unsafe {
                let iter = self as *mut xcb_timecoord_iterator_t;
                let data = (*iter).data;
                xcb_timecoord_next(iter);
                Some(std::mem::transmute(*data))
            }
        }
    }
}
pub const GET_MOTION_EVENTS: u8 = 39;
pub type GetMotionEventsCookie<'a> = base::Cookie<'a, xcb_get_motion_events_cookie_t>;
impl<'a> GetMotionEventsCookie<'a> {
    pub fn get_reply(&self) -> Result<GetMotionEventsReply, base::GenericError> {
        unsafe {
            if self.checked {
                let mut err: *mut xcb_generic_error_t = std::ptr::null_mut();
                let reply = GetMotionEventsReply {
                    ptr: xcb_get_motion_events_reply (self.conn.get_raw_conn(), self.cookie, &mut err)
                };
                if err.is_null() { Ok (reply) }
                else { Err(base::GenericError { ptr: err }) }
            } else {
                Ok( GetMotionEventsReply {
                    ptr: xcb_get_motion_events_reply (self.conn.get_raw_conn(), self.cookie,
                            std::ptr::null_mut())
                })
            }
        }
    }
}
pub type GetMotionEventsReply = base::Reply<xcb_get_motion_events_reply_t>;
impl GetMotionEventsReply {
    pub fn events_len(&self) -> u32 {
        unsafe {
            (*self.ptr).events_len
        }
    }
    pub fn events(&self) -> TimecoordIterator {
        unsafe {
            xcb_get_motion_events_events_iterator(self.ptr)
        }
    }
}
pub fn get_motion_events<'a>(c     : &'a base::Connection,
                             window: Window,
                             start : Timestamp,
                             stop  : Timestamp)
        -> GetMotionEventsCookie<'a> {
    unsafe {
        let cookie = xcb_get_motion_events(c.get_raw_conn(),
                                           window as xcb_window_t,  
                                           start as xcb_timestamp_t,  
                                           stop as xcb_timestamp_t);  
        GetMotionEventsCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub fn get_motion_events_unchecked<'a>(c     : &'a base::Connection,
                                       window: Window,
                                       start : Timestamp,
                                       stop  : Timestamp)
        -> GetMotionEventsCookie<'a> {
    unsafe {
        let cookie = xcb_get_motion_events_unchecked(c.get_raw_conn(),
                                                     window as xcb_window_t,  
                                                     start as xcb_timestamp_t,  
                                                     stop as xcb_timestamp_t);  
        GetMotionEventsCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub const TRANSLATE_COORDINATES: u8 = 40;
pub type TranslateCoordinatesCookie<'a> = base::Cookie<'a, xcb_translate_coordinates_cookie_t>;
impl<'a> TranslateCoordinatesCookie<'a> {
    pub fn get_reply(&self) -> Result<TranslateCoordinatesReply, base::GenericError> {
        unsafe {
            if self.checked {
                let mut err: *mut xcb_generic_error_t = std::ptr::null_mut();
                let reply = TranslateCoordinatesReply {
                    ptr: xcb_translate_coordinates_reply (self.conn.get_raw_conn(), self.cookie, &mut err)
                };
                if err.is_null() { Ok (reply) }
                else { Err(base::GenericError { ptr: err }) }
            } else {
                Ok( TranslateCoordinatesReply {
                    ptr: xcb_translate_coordinates_reply (self.conn.get_raw_conn(), self.cookie,
                            std::ptr::null_mut())
                })
            }
        }
    }
}
pub type TranslateCoordinatesReply = base::Reply<xcb_translate_coordinates_reply_t>;
impl TranslateCoordinatesReply {
    pub fn same_screen(&self) -> bool {
        unsafe {
            (*self.ptr).same_screen != 0
        }
    }
    pub fn child(&self) -> Window {
        unsafe {
            (*self.ptr).child
        }
    }
    pub fn dst_x(&self) -> i16 {
        unsafe {
            (*self.ptr).dst_x
        }
    }
    pub fn dst_y(&self) -> i16 {
        unsafe {
            (*self.ptr).dst_y
        }
    }
}
pub fn translate_coordinates<'a>(c         : &'a base::Connection,
                                 src_window: Window,
                                 dst_window: Window,
                                 src_x     : i16,
                                 src_y     : i16)
        -> TranslateCoordinatesCookie<'a> {
    unsafe {
        let cookie = xcb_translate_coordinates(c.get_raw_conn(),
                                               src_window as xcb_window_t,  
                                               dst_window as xcb_window_t,  
                                               src_x as i16,  
                                               src_y as i16);  
        TranslateCoordinatesCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub fn translate_coordinates_unchecked<'a>(c         : &'a base::Connection,
                                           src_window: Window,
                                           dst_window: Window,
                                           src_x     : i16,
                                           src_y     : i16)
        -> TranslateCoordinatesCookie<'a> {
    unsafe {
        let cookie = xcb_translate_coordinates_unchecked(c.get_raw_conn(),
                                                         src_window as xcb_window_t,  
                                                         dst_window as xcb_window_t,  
                                                         src_x as i16,  
                                                         src_y as i16);  
        TranslateCoordinatesCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub const WARP_POINTER: u8 = 41;
pub fn warp_pointer<'a>(c         : &'a base::Connection,
                        src_window: Window,
                        dst_window: Window,
                        src_x     : i16,
                        src_y     : i16,
                        src_width : u16,
                        src_height: u16,
                        dst_x     : i16,
                        dst_y     : i16)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_warp_pointer(c.get_raw_conn(),
                                      src_window as xcb_window_t,  
                                      dst_window as xcb_window_t,  
                                      src_x as i16,  
                                      src_y as i16,  
                                      src_width as u16,  
                                      src_height as u16,  
                                      dst_x as i16,  
                                      dst_y as i16);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn warp_pointer_checked<'a>(c         : &'a base::Connection,
                                src_window: Window,
                                dst_window: Window,
                                src_x     : i16,
                                src_y     : i16,
                                src_width : u16,
                                src_height: u16,
                                dst_x     : i16,
                                dst_y     : i16)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_warp_pointer_checked(c.get_raw_conn(),
                                              src_window as xcb_window_t,  
                                              dst_window as xcb_window_t,  
                                              src_x as i16,  
                                              src_y as i16,  
                                              src_width as u16,  
                                              src_height as u16,  
                                              dst_x as i16,  
                                              dst_y as i16);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const SET_INPUT_FOCUS: u8 = 42;
pub fn set_input_focus<'a>(c        : &'a base::Connection,
                           revert_to: u8,
                           focus    : Window,
                           time     : Timestamp)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_set_input_focus(c.get_raw_conn(),
                                         revert_to as u8,  
                                         focus as xcb_window_t,  
                                         time as xcb_timestamp_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn set_input_focus_checked<'a>(c        : &'a base::Connection,
                                   revert_to: u8,
                                   focus    : Window,
                                   time     : Timestamp)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_set_input_focus_checked(c.get_raw_conn(),
                                                 revert_to as u8,  
                                                 focus as xcb_window_t,  
                                                 time as xcb_timestamp_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const GET_INPUT_FOCUS: u8 = 43;
pub type GetInputFocusCookie<'a> = base::Cookie<'a, xcb_get_input_focus_cookie_t>;
impl<'a> GetInputFocusCookie<'a> {
    pub fn get_reply(&self) -> Result<GetInputFocusReply, base::GenericError> {
        unsafe {
            if self.checked {
                let mut err: *mut xcb_generic_error_t = std::ptr::null_mut();
                let reply = GetInputFocusReply {
                    ptr: xcb_get_input_focus_reply (self.conn.get_raw_conn(), self.cookie, &mut err)
                };
                if err.is_null() { Ok (reply) }
                else { Err(base::GenericError { ptr: err }) }
            } else {
                Ok( GetInputFocusReply {
                    ptr: xcb_get_input_focus_reply (self.conn.get_raw_conn(), self.cookie,
                            std::ptr::null_mut())
                })
            }
        }
    }
}
pub type GetInputFocusReply = base::Reply<xcb_get_input_focus_reply_t>;
impl GetInputFocusReply {
    pub fn revert_to(&self) -> u8 {
        unsafe {
            (*self.ptr).revert_to
        }
    }
    pub fn focus(&self) -> Window {
        unsafe {
            (*self.ptr).focus
        }
    }
}
pub fn get_input_focus<'a>(c: &'a base::Connection)
        -> GetInputFocusCookie<'a> {
    unsafe {
        let cookie = xcb_get_input_focus(c.get_raw_conn());
        GetInputFocusCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub fn get_input_focus_unchecked<'a>(c: &'a base::Connection)
        -> GetInputFocusCookie<'a> {
    unsafe {
        let cookie = xcb_get_input_focus_unchecked(c.get_raw_conn());
        GetInputFocusCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub const QUERY_KEYMAP: u8 = 44;
pub type QueryKeymapCookie<'a> = base::Cookie<'a, xcb_query_keymap_cookie_t>;
impl<'a> QueryKeymapCookie<'a> {
    pub fn get_reply(&self) -> Result<QueryKeymapReply, base::GenericError> {
        unsafe {
            if self.checked {
                let mut err: *mut xcb_generic_error_t = std::ptr::null_mut();
                let reply = QueryKeymapReply {
                    ptr: xcb_query_keymap_reply (self.conn.get_raw_conn(), self.cookie, &mut err)
                };
                if err.is_null() { Ok (reply) }
                else { Err(base::GenericError { ptr: err }) }
            } else {
                Ok( QueryKeymapReply {
                    ptr: xcb_query_keymap_reply (self.conn.get_raw_conn(), self.cookie,
                            std::ptr::null_mut())
                })
            }
        }
    }
}
pub type QueryKeymapReply = base::Reply<xcb_query_keymap_reply_t>;
impl QueryKeymapReply {
    pub fn keys(&self) -> &[u8] {
        unsafe {
            &(*self.ptr).keys
        }
    }
}
pub fn query_keymap<'a>(c: &'a base::Connection)
        -> QueryKeymapCookie<'a> {
    unsafe {
        let cookie = xcb_query_keymap(c.get_raw_conn());
        QueryKeymapCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub fn query_keymap_unchecked<'a>(c: &'a base::Connection)
        -> QueryKeymapCookie<'a> {
    unsafe {
        let cookie = xcb_query_keymap_unchecked(c.get_raw_conn());
        QueryKeymapCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub const OPEN_FONT: u8 = 45;
pub fn open_font<'a>(c   : &'a base::Connection,
                     fid : Font,
                     name: &str)
        -> base::VoidCookie<'a> {
    unsafe {
        let name = name.as_bytes();
        let name_len = name.len();
        let name_ptr = name.as_ptr();
        let cookie = xcb_open_font(c.get_raw_conn(),
                                   fid as xcb_font_t,  
                                   name_len as u16,  
                                   name_ptr as *const c_char);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn open_font_checked<'a>(c   : &'a base::Connection,
                             fid : Font,
                             name: &str)
        -> base::VoidCookie<'a> {
    unsafe {
        let name = name.as_bytes();
        let name_len = name.len();
        let name_ptr = name.as_ptr();
        let cookie = xcb_open_font_checked(c.get_raw_conn(),
                                           fid as xcb_font_t,  
                                           name_len as u16,  
                                           name_ptr as *const c_char);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const CLOSE_FONT: u8 = 46;
pub fn close_font<'a>(c   : &'a base::Connection,
                      font: Font)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_close_font(c.get_raw_conn(),
                                    font as xcb_font_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn close_font_checked<'a>(c   : &'a base::Connection,
                              font: Font)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_close_font_checked(c.get_raw_conn(),
                                            font as xcb_font_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
#[derive(Copy, Clone)]
pub struct Fontprop {
    pub base: xcb_fontprop_t,
}
impl Fontprop {
    #[allow(unused_unsafe)]
    pub fn new(name:  Atom,
               value: u32)
            -> Fontprop {
        unsafe {
            Fontprop {
                base: xcb_fontprop_t {
                    name:  name,
                    value: value,
                }
            }
        }
    }
    pub fn name(&self) -> Atom {
        unsafe {
            self.base.name
        }
    }
    pub fn value(&self) -> u32 {
        unsafe {
            self.base.value
        }
    }
}
pub type FontpropIterator = xcb_fontprop_iterator_t;
impl Iterator for FontpropIterator {
    type Item = Fontprop;
    fn next(&mut self) -> std::option::Option<Fontprop> {
        if self.rem == 0 { None }
        else {
            unsafe {
                let iter = self as *mut xcb_fontprop_iterator_t;
                let data = (*iter).data;
                xcb_fontprop_next(iter);
                Some(std::mem::transmute(*data))
            }
        }
    }
}
#[derive(Copy, Clone)]
pub struct Charinfo {
    pub base: xcb_charinfo_t,
}
impl Charinfo {
    #[allow(unused_unsafe)]
    pub fn new(left_side_bearing:  i16,
               right_side_bearing: i16,
               character_width:    i16,
               ascent:             i16,
               descent:            i16,
               attributes:         u16)
            -> Charinfo {
        unsafe {
            Charinfo {
                base: xcb_charinfo_t {
                    left_side_bearing:  left_side_bearing,
                    right_side_bearing: right_side_bearing,
                    character_width:    character_width,
                    ascent:             ascent,
                    descent:            descent,
                    attributes:         attributes,
                }
            }
        }
    }
    pub fn left_side_bearing(&self) -> i16 {
        unsafe {
            self.base.left_side_bearing
        }
    }
    pub fn right_side_bearing(&self) -> i16 {
        unsafe {
            self.base.right_side_bearing
        }
    }
    pub fn character_width(&self) -> i16 {
        unsafe {
            self.base.character_width
        }
    }
    pub fn ascent(&self) -> i16 {
        unsafe {
            self.base.ascent
        }
    }
    pub fn descent(&self) -> i16 {
        unsafe {
            self.base.descent
        }
    }
    pub fn attributes(&self) -> u16 {
        unsafe {
            self.base.attributes
        }
    }
}
pub type CharinfoIterator = xcb_charinfo_iterator_t;
impl Iterator for CharinfoIterator {
    type Item = Charinfo;
    fn next(&mut self) -> std::option::Option<Charinfo> {
        if self.rem == 0 { None }
        else {
            unsafe {
                let iter = self as *mut xcb_charinfo_iterator_t;
                let data = (*iter).data;
                xcb_charinfo_next(iter);
                Some(std::mem::transmute(*data))
            }
        }
    }
}
pub const QUERY_FONT: u8 = 47;
pub type QueryFontCookie<'a> = base::Cookie<'a, xcb_query_font_cookie_t>;
impl<'a> QueryFontCookie<'a> {
    pub fn get_reply(&self) -> Result<QueryFontReply, base::GenericError> {
        unsafe {
            if self.checked {
                let mut err: *mut xcb_generic_error_t = std::ptr::null_mut();
                let reply = QueryFontReply {
                    ptr: xcb_query_font_reply (self.conn.get_raw_conn(), self.cookie, &mut err)
                };
                if err.is_null() { Ok (reply) }
                else { Err(base::GenericError { ptr: err }) }
            } else {
                Ok( QueryFontReply {
                    ptr: xcb_query_font_reply (self.conn.get_raw_conn(), self.cookie,
                            std::ptr::null_mut())
                })
            }
        }
    }
}
pub type QueryFontReply = base::Reply<xcb_query_font_reply_t>;
impl QueryFontReply {
    pub fn min_bounds(&self) -> Charinfo {
        unsafe {
            std::mem::transmute((*self.ptr).min_bounds)
        }
    }
    pub fn max_bounds(&self) -> Charinfo {
        unsafe {
            std::mem::transmute((*self.ptr).max_bounds)
        }
    }
    pub fn min_char_or_byte2(&self) -> u16 {
        unsafe {
            (*self.ptr).min_char_or_byte2
        }
    }
    pub fn max_char_or_byte2(&self) -> u16 {
        unsafe {
            (*self.ptr).max_char_or_byte2
        }
    }
    pub fn default_char(&self) -> u16 {
        unsafe {
            (*self.ptr).default_char
        }
    }
    pub fn properties_len(&self) -> u16 {
        unsafe {
            (*self.ptr).properties_len
        }
    }
    pub fn draw_direction(&self) -> u8 {
        unsafe {
            (*self.ptr).draw_direction
        }
    }
    pub fn min_byte1(&self) -> u8 {
        unsafe {
            (*self.ptr).min_byte1
        }
    }
    pub fn max_byte1(&self) -> u8 {
        unsafe {
            (*self.ptr).max_byte1
        }
    }
    pub fn all_chars_exist(&self) -> bool {
        unsafe {
            (*self.ptr).all_chars_exist != 0
        }
    }
    pub fn font_ascent(&self) -> i16 {
        unsafe {
            (*self.ptr).font_ascent
        }
    }
    pub fn font_descent(&self) -> i16 {
        unsafe {
            (*self.ptr).font_descent
        }
    }
    pub fn char_infos_len(&self) -> u32 {
        unsafe {
            (*self.ptr).char_infos_len
        }
    }
    pub fn properties(&self) -> FontpropIterator {
        unsafe {
            xcb_query_font_properties_iterator(self.ptr)
        }
    }
    pub fn char_infos(&self) -> CharinfoIterator {
        unsafe {
            xcb_query_font_char_infos_iterator(self.ptr)
        }
    }
}
pub fn query_font<'a>(c   : &'a base::Connection,
                      font: Fontable)
        -> QueryFontCookie<'a> {
    unsafe {
        let cookie = xcb_query_font(c.get_raw_conn(),
                                    font as xcb_fontable_t);  
        QueryFontCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub fn query_font_unchecked<'a>(c   : &'a base::Connection,
                                font: Fontable)
        -> QueryFontCookie<'a> {
    unsafe {
        let cookie = xcb_query_font_unchecked(c.get_raw_conn(),
                                              font as xcb_fontable_t);  
        QueryFontCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub const QUERY_TEXT_EXTENTS: u8 = 48;
pub type QueryTextExtentsCookie<'a> = base::Cookie<'a, xcb_query_text_extents_cookie_t>;
impl<'a> QueryTextExtentsCookie<'a> {
    pub fn get_reply(&self) -> Result<QueryTextExtentsReply, base::GenericError> {
        unsafe {
            if self.checked {
                let mut err: *mut xcb_generic_error_t = std::ptr::null_mut();
                let reply = QueryTextExtentsReply {
                    ptr: xcb_query_text_extents_reply (self.conn.get_raw_conn(), self.cookie, &mut err)
                };
                if err.is_null() { Ok (reply) }
                else { Err(base::GenericError { ptr: err }) }
            } else {
                Ok( QueryTextExtentsReply {
                    ptr: xcb_query_text_extents_reply (self.conn.get_raw_conn(), self.cookie,
                            std::ptr::null_mut())
                })
            }
        }
    }
}
pub type QueryTextExtentsReply = base::Reply<xcb_query_text_extents_reply_t>;
impl QueryTextExtentsReply {
    pub fn draw_direction(&self) -> u8 {
        unsafe {
            (*self.ptr).draw_direction
        }
    }
    pub fn font_ascent(&self) -> i16 {
        unsafe {
            (*self.ptr).font_ascent
        }
    }
    pub fn font_descent(&self) -> i16 {
        unsafe {
            (*self.ptr).font_descent
        }
    }
    pub fn overall_ascent(&self) -> i16 {
        unsafe {
            (*self.ptr).overall_ascent
        }
    }
    pub fn overall_descent(&self) -> i16 {
        unsafe {
            (*self.ptr).overall_descent
        }
    }
    pub fn overall_width(&self) -> i32 {
        unsafe {
            (*self.ptr).overall_width
        }
    }
    pub fn overall_left(&self) -> i32 {
        unsafe {
            (*self.ptr).overall_left
        }
    }
    pub fn overall_right(&self) -> i32 {
        unsafe {
            (*self.ptr).overall_right
        }
    }
}
pub fn query_text_extents<'a>(c     : &'a base::Connection,
                              font  : Fontable,
                              string: &[Char2b])
        -> QueryTextExtentsCookie<'a> {
    unsafe {
        let string_len = string.len();
        let string_ptr = string.as_ptr();
        let cookie = xcb_query_text_extents(c.get_raw_conn(),
                                            font as xcb_fontable_t,  
                                            string_len as u32,  
                                            string_ptr as *const xcb_char2b_t);  
        QueryTextExtentsCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub fn query_text_extents_unchecked<'a>(c     : &'a base::Connection,
                                        font  : Fontable,
                                        string: &[Char2b])
        -> QueryTextExtentsCookie<'a> {
    unsafe {
        let string_len = string.len();
        let string_ptr = string.as_ptr();
        let cookie = xcb_query_text_extents_unchecked(c.get_raw_conn(),
                                                      font as xcb_fontable_t,  
                                                      string_len as u32,  
                                                      string_ptr as *const xcb_char2b_t);  
        QueryTextExtentsCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub type Str<'a> = base::StructPtr<'a, xcb_str_t>;
impl<'a> Str<'a> {
    pub fn name_len(&self) -> u8 {
        unsafe {
            (*self.ptr).name_len
        }
    }
    pub fn name(&self) -> &str {
        unsafe {
            let field = self.ptr;
            let len = xcb_str_name_length(field) as usize;
            let data = xcb_str_name(field);
            let slice = std::slice::from_raw_parts(data as *const u8, len);
            
            std::str::from_utf8_unchecked(&slice)
        }
    }
}
pub type StrIterator<'a> = xcb_str_iterator_t<'a>;
impl<'a> Iterator for StrIterator<'a> {
    type Item = Str<'a>;
    fn next(&mut self) -> std::option::Option<Str<'a>> {
        if self.rem == 0 { None }
        else {
            unsafe {
                let iter = self as *mut xcb_str_iterator_t;
                let data = (*iter).data;
                xcb_str_next(iter);
                Some(std::mem::transmute(data))
            }
        }
    }
}
pub const LIST_FONTS: u8 = 49;
pub type ListFontsCookie<'a> = base::Cookie<'a, xcb_list_fonts_cookie_t>;
impl<'a> ListFontsCookie<'a> {
    pub fn get_reply(&self) -> Result<ListFontsReply, base::GenericError> {
        unsafe {
            if self.checked {
                let mut err: *mut xcb_generic_error_t = std::ptr::null_mut();
                let reply = ListFontsReply {
                    ptr: xcb_list_fonts_reply (self.conn.get_raw_conn(), self.cookie, &mut err)
                };
                if err.is_null() { Ok (reply) }
                else { Err(base::GenericError { ptr: err }) }
            } else {
                Ok( ListFontsReply {
                    ptr: xcb_list_fonts_reply (self.conn.get_raw_conn(), self.cookie,
                            std::ptr::null_mut())
                })
            }
        }
    }
}
pub type ListFontsReply = base::Reply<xcb_list_fonts_reply_t>;
impl ListFontsReply {
    pub fn names_len(&self) -> u16 {
        unsafe {
            (*self.ptr).names_len
        }
    }
    pub fn names(&self) -> StrIterator {
        unsafe {
            xcb_list_fonts_names_iterator(self.ptr)
        }
    }
}
pub fn list_fonts<'a>(c        : &'a base::Connection,
                      max_names: u16,
                      pattern  : &str)
        -> ListFontsCookie<'a> {
    unsafe {
        let pattern = pattern.as_bytes();
        let pattern_len = pattern.len();
        let pattern_ptr = pattern.as_ptr();
        let cookie = xcb_list_fonts(c.get_raw_conn(),
                                    max_names as u16,  
                                    pattern_len as u16,  
                                    pattern_ptr as *const c_char);  
        ListFontsCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub fn list_fonts_unchecked<'a>(c        : &'a base::Connection,
                                max_names: u16,
                                pattern  : &str)
        -> ListFontsCookie<'a> {
    unsafe {
        let pattern = pattern.as_bytes();
        let pattern_len = pattern.len();
        let pattern_ptr = pattern.as_ptr();
        let cookie = xcb_list_fonts_unchecked(c.get_raw_conn(),
                                              max_names as u16,  
                                              pattern_len as u16,  
                                              pattern_ptr as *const c_char);  
        ListFontsCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub const LIST_FONTS_WITH_INFO: u8 = 50;
pub type ListFontsWithInfoCookie<'a> = base::Cookie<'a, xcb_list_fonts_with_info_cookie_t>;
impl<'a> ListFontsWithInfoCookie<'a> {
    pub fn get_reply(&self) -> Result<ListFontsWithInfoReply, base::GenericError> {
        unsafe {
            if self.checked {
                let mut err: *mut xcb_generic_error_t = std::ptr::null_mut();
                let reply = ListFontsWithInfoReply {
                    ptr: xcb_list_fonts_with_info_reply (self.conn.get_raw_conn(), self.cookie, &mut err)
                };
                if err.is_null() { Ok (reply) }
                else { Err(base::GenericError { ptr: err }) }
            } else {
                Ok( ListFontsWithInfoReply {
                    ptr: xcb_list_fonts_with_info_reply (self.conn.get_raw_conn(), self.cookie,
                            std::ptr::null_mut())
                })
            }
        }
    }
}
pub type ListFontsWithInfoReply = base::Reply<xcb_list_fonts_with_info_reply_t>;
impl ListFontsWithInfoReply {
    pub fn name_len(&self) -> u8 {
        unsafe {
            (*self.ptr).name_len
        }
    }
    pub fn min_bounds(&self) -> Charinfo {
        unsafe {
            std::mem::transmute((*self.ptr).min_bounds)
        }
    }
    pub fn max_bounds(&self) -> Charinfo {
        unsafe {
            std::mem::transmute((*self.ptr).max_bounds)
        }
    }
    pub fn min_char_or_byte2(&self) -> u16 {
        unsafe {
            (*self.ptr).min_char_or_byte2
        }
    }
    pub fn max_char_or_byte2(&self) -> u16 {
        unsafe {
            (*self.ptr).max_char_or_byte2
        }
    }
    pub fn default_char(&self) -> u16 {
        unsafe {
            (*self.ptr).default_char
        }
    }
    pub fn properties_len(&self) -> u16 {
        unsafe {
            (*self.ptr).properties_len
        }
    }
    pub fn draw_direction(&self) -> u8 {
        unsafe {
            (*self.ptr).draw_direction
        }
    }
    pub fn min_byte1(&self) -> u8 {
        unsafe {
            (*self.ptr).min_byte1
        }
    }
    pub fn max_byte1(&self) -> u8 {
        unsafe {
            (*self.ptr).max_byte1
        }
    }
    pub fn all_chars_exist(&self) -> bool {
        unsafe {
            (*self.ptr).all_chars_exist != 0
        }
    }
    pub fn font_ascent(&self) -> i16 {
        unsafe {
            (*self.ptr).font_ascent
        }
    }
    pub fn font_descent(&self) -> i16 {
        unsafe {
            (*self.ptr).font_descent
        }
    }
    pub fn replies_hint(&self) -> u32 {
        unsafe {
            (*self.ptr).replies_hint
        }
    }
    pub fn properties(&self) -> FontpropIterator {
        unsafe {
            xcb_list_fonts_with_info_properties_iterator(self.ptr)
        }
    }
    pub fn name(&self) -> &str {
        unsafe {
            let field = self.ptr;
            let len = xcb_list_fonts_with_info_name_length(field) as usize;
            let data = xcb_list_fonts_with_info_name(field);
            let slice = std::slice::from_raw_parts(data as *const u8, len);
            
            std::str::from_utf8_unchecked(&slice)
        }
    }
}
pub fn list_fonts_with_info<'a>(c        : &'a base::Connection,
                                max_names: u16,
                                pattern  : &str)
        -> ListFontsWithInfoCookie<'a> {
    unsafe {
        let pattern = pattern.as_bytes();
        let pattern_len = pattern.len();
        let pattern_ptr = pattern.as_ptr();
        let cookie = xcb_list_fonts_with_info(c.get_raw_conn(),
                                              max_names as u16,  
                                              pattern_len as u16,  
                                              pattern_ptr as *const c_char);  
        ListFontsWithInfoCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub fn list_fonts_with_info_unchecked<'a>(c        : &'a base::Connection,
                                          max_names: u16,
                                          pattern  : &str)
        -> ListFontsWithInfoCookie<'a> {
    unsafe {
        let pattern = pattern.as_bytes();
        let pattern_len = pattern.len();
        let pattern_ptr = pattern.as_ptr();
        let cookie = xcb_list_fonts_with_info_unchecked(c.get_raw_conn(),
                                                        max_names as u16,  
                                                        pattern_len as u16,  
                                                        pattern_ptr as *const c_char);  
        ListFontsWithInfoCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub const SET_FONT_PATH: u8 = 51;
pub fn set_font_path<'a>(c   : &'a base::Connection,
                         font: &[Str])
        -> base::VoidCookie<'a> {
    unsafe {
        let font_len = font.len();
        let font_ptr = font.as_ptr();
        let cookie = xcb_set_font_path(c.get_raw_conn(),
                                       font_len as u16,  
                                       font_ptr as *const xcb_str_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn set_font_path_checked<'a>(c   : &'a base::Connection,
                                 font: &[Str])
        -> base::VoidCookie<'a> {
    unsafe {
        let font_len = font.len();
        let font_ptr = font.as_ptr();
        let cookie = xcb_set_font_path_checked(c.get_raw_conn(),
                                               font_len as u16,  
                                               font_ptr as *const xcb_str_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const GET_FONT_PATH: u8 = 52;
pub type GetFontPathCookie<'a> = base::Cookie<'a, xcb_get_font_path_cookie_t>;
impl<'a> GetFontPathCookie<'a> {
    pub fn get_reply(&self) -> Result<GetFontPathReply, base::GenericError> {
        unsafe {
            if self.checked {
                let mut err: *mut xcb_generic_error_t = std::ptr::null_mut();
                let reply = GetFontPathReply {
                    ptr: xcb_get_font_path_reply (self.conn.get_raw_conn(), self.cookie, &mut err)
                };
                if err.is_null() { Ok (reply) }
                else { Err(base::GenericError { ptr: err }) }
            } else {
                Ok( GetFontPathReply {
                    ptr: xcb_get_font_path_reply (self.conn.get_raw_conn(), self.cookie,
                            std::ptr::null_mut())
                })
            }
        }
    }
}
pub type GetFontPathReply = base::Reply<xcb_get_font_path_reply_t>;
impl GetFontPathReply {
    pub fn path_len(&self) -> u16 {
        unsafe {
            (*self.ptr).path_len
        }
    }
    pub fn path(&self) -> StrIterator {
        unsafe {
            xcb_get_font_path_path_iterator(self.ptr)
        }
    }
}
pub fn get_font_path<'a>(c: &'a base::Connection)
        -> GetFontPathCookie<'a> {
    unsafe {
        let cookie = xcb_get_font_path(c.get_raw_conn());
        GetFontPathCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub fn get_font_path_unchecked<'a>(c: &'a base::Connection)
        -> GetFontPathCookie<'a> {
    unsafe {
        let cookie = xcb_get_font_path_unchecked(c.get_raw_conn());
        GetFontPathCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub const CREATE_PIXMAP: u8 = 53;
pub fn create_pixmap<'a>(c       : &'a base::Connection,
                         depth   : u8,
                         pid     : Pixmap,
                         drawable: Drawable,
                         width   : u16,
                         height  : u16)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_create_pixmap(c.get_raw_conn(),
                                       depth as u8,  
                                       pid as xcb_pixmap_t,  
                                       drawable as xcb_drawable_t,  
                                       width as u16,  
                                       height as u16);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn create_pixmap_checked<'a>(c       : &'a base::Connection,
                                 depth   : u8,
                                 pid     : Pixmap,
                                 drawable: Drawable,
                                 width   : u16,
                                 height  : u16)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_create_pixmap_checked(c.get_raw_conn(),
                                               depth as u8,  
                                               pid as xcb_pixmap_t,  
                                               drawable as xcb_drawable_t,  
                                               width as u16,  
                                               height as u16);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const FREE_PIXMAP: u8 = 54;
pub fn free_pixmap<'a>(c     : &'a base::Connection,
                       pixmap: Pixmap)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_free_pixmap(c.get_raw_conn(),
                                     pixmap as xcb_pixmap_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn free_pixmap_checked<'a>(c     : &'a base::Connection,
                               pixmap: Pixmap)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_free_pixmap_checked(c.get_raw_conn(),
                                             pixmap as xcb_pixmap_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const CREATE_GC: u8 = 55;
pub fn create_gc<'a>(c         : &'a base::Connection,
                     cid       : Gcontext,
                     drawable  : Drawable,
                     value_list: &[(u32, u32)])
        -> base::VoidCookie<'a> {
    unsafe {
        let mut value_list_copy = value_list.to_vec();
        let (value_list_mask, value_list_vec) = base::pack_bitfield(&mut value_list_copy);
        let value_list_ptr = value_list_vec.as_ptr();
        let cookie = xcb_create_gc(c.get_raw_conn(),
                                   cid as xcb_gcontext_t,  
                                   drawable as xcb_drawable_t,  
                                   value_list_mask as u32,  
                                   value_list_ptr as *const u32);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn create_gc_checked<'a>(c         : &'a base::Connection,
                             cid       : Gcontext,
                             drawable  : Drawable,
                             value_list: &[(u32, u32)])
        -> base::VoidCookie<'a> {
    unsafe {
        let mut value_list_copy = value_list.to_vec();
        let (value_list_mask, value_list_vec) = base::pack_bitfield(&mut value_list_copy);
        let value_list_ptr = value_list_vec.as_ptr();
        let cookie = xcb_create_gc_checked(c.get_raw_conn(),
                                           cid as xcb_gcontext_t,  
                                           drawable as xcb_drawable_t,  
                                           value_list_mask as u32,  
                                           value_list_ptr as *const u32);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const CHANGE_GC: u8 = 56;
pub fn change_gc<'a>(c         : &'a base::Connection,
                     gc        : Gcontext,
                     value_list: &[(u32, u32)])
        -> base::VoidCookie<'a> {
    unsafe {
        let mut value_list_copy = value_list.to_vec();
        let (value_list_mask, value_list_vec) = base::pack_bitfield(&mut value_list_copy);
        let value_list_ptr = value_list_vec.as_ptr();
        let cookie = xcb_change_gc(c.get_raw_conn(),
                                   gc as xcb_gcontext_t,  
                                   value_list_mask as u32,  
                                   value_list_ptr as *const u32);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn change_gc_checked<'a>(c         : &'a base::Connection,
                             gc        : Gcontext,
                             value_list: &[(u32, u32)])
        -> base::VoidCookie<'a> {
    unsafe {
        let mut value_list_copy = value_list.to_vec();
        let (value_list_mask, value_list_vec) = base::pack_bitfield(&mut value_list_copy);
        let value_list_ptr = value_list_vec.as_ptr();
        let cookie = xcb_change_gc_checked(c.get_raw_conn(),
                                           gc as xcb_gcontext_t,  
                                           value_list_mask as u32,  
                                           value_list_ptr as *const u32);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const COPY_GC: u8 = 57;
pub fn copy_gc<'a>(c         : &'a base::Connection,
                   src_gc    : Gcontext,
                   dst_gc    : Gcontext,
                   value_mask: u32)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_copy_gc(c.get_raw_conn(),
                                 src_gc as xcb_gcontext_t,  
                                 dst_gc as xcb_gcontext_t,  
                                 value_mask as u32);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn copy_gc_checked<'a>(c         : &'a base::Connection,
                           src_gc    : Gcontext,
                           dst_gc    : Gcontext,
                           value_mask: u32)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_copy_gc_checked(c.get_raw_conn(),
                                         src_gc as xcb_gcontext_t,  
                                         dst_gc as xcb_gcontext_t,  
                                         value_mask as u32);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const SET_DASHES: u8 = 58;
pub fn set_dashes<'a>(c          : &'a base::Connection,
                      gc         : Gcontext,
                      dash_offset: u16,
                      dashes     : &[u8])
        -> base::VoidCookie<'a> {
    unsafe {
        let dashes_len = dashes.len();
        let dashes_ptr = dashes.as_ptr();
        let cookie = xcb_set_dashes(c.get_raw_conn(),
                                    gc as xcb_gcontext_t,  
                                    dash_offset as u16,  
                                    dashes_len as u16,  
                                    dashes_ptr as *const u8);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn set_dashes_checked<'a>(c          : &'a base::Connection,
                              gc         : Gcontext,
                              dash_offset: u16,
                              dashes     : &[u8])
        -> base::VoidCookie<'a> {
    unsafe {
        let dashes_len = dashes.len();
        let dashes_ptr = dashes.as_ptr();
        let cookie = xcb_set_dashes_checked(c.get_raw_conn(),
                                            gc as xcb_gcontext_t,  
                                            dash_offset as u16,  
                                            dashes_len as u16,  
                                            dashes_ptr as *const u8);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const SET_CLIP_RECTANGLES: u8 = 59;
pub fn set_clip_rectangles<'a>(c            : &'a base::Connection,
                               ordering     : u8,
                               gc           : Gcontext,
                               clip_x_origin: i16,
                               clip_y_origin: i16,
                               rectangles   : &[Rectangle])
        -> base::VoidCookie<'a> {
    unsafe {
        let rectangles_len = rectangles.len();
        let rectangles_ptr = rectangles.as_ptr();
        let cookie = xcb_set_clip_rectangles(c.get_raw_conn(),
                                             ordering as u8,  
                                             gc as xcb_gcontext_t,  
                                             clip_x_origin as i16,  
                                             clip_y_origin as i16,  
                                             rectangles_len as u32,  
                                             rectangles_ptr as *const xcb_rectangle_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn set_clip_rectangles_checked<'a>(c            : &'a base::Connection,
                                       ordering     : u8,
                                       gc           : Gcontext,
                                       clip_x_origin: i16,
                                       clip_y_origin: i16,
                                       rectangles   : &[Rectangle])
        -> base::VoidCookie<'a> {
    unsafe {
        let rectangles_len = rectangles.len();
        let rectangles_ptr = rectangles.as_ptr();
        let cookie = xcb_set_clip_rectangles_checked(c.get_raw_conn(),
                                                     ordering as u8,  
                                                     gc as xcb_gcontext_t,  
                                                     clip_x_origin as i16,  
                                                     clip_y_origin as i16,  
                                                     rectangles_len as u32,  
                                                     rectangles_ptr as *const xcb_rectangle_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const FREE_GC: u8 = 60;
pub fn free_gc<'a>(c : &'a base::Connection,
                   gc: Gcontext)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_free_gc(c.get_raw_conn(),
                                 gc as xcb_gcontext_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn free_gc_checked<'a>(c : &'a base::Connection,
                           gc: Gcontext)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_free_gc_checked(c.get_raw_conn(),
                                         gc as xcb_gcontext_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const CLEAR_AREA: u8 = 61;
pub fn clear_area<'a>(c        : &'a base::Connection,
                      exposures: bool,
                      window   : Window,
                      x        : i16,
                      y        : i16,
                      width    : u16,
                      height   : u16)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_clear_area(c.get_raw_conn(),
                                    exposures as u8,  
                                    window as xcb_window_t,  
                                    x as i16,  
                                    y as i16,  
                                    width as u16,  
                                    height as u16);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn clear_area_checked<'a>(c        : &'a base::Connection,
                              exposures: bool,
                              window   : Window,
                              x        : i16,
                              y        : i16,
                              width    : u16,
                              height   : u16)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_clear_area_checked(c.get_raw_conn(),
                                            exposures as u8,  
                                            window as xcb_window_t,  
                                            x as i16,  
                                            y as i16,  
                                            width as u16,  
                                            height as u16);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const COPY_AREA: u8 = 62;
pub fn copy_area<'a>(c           : &'a base::Connection,
                     src_drawable: Drawable,
                     dst_drawable: Drawable,
                     gc          : Gcontext,
                     src_x       : i16,
                     src_y       : i16,
                     dst_x       : i16,
                     dst_y       : i16,
                     width       : u16,
                     height      : u16)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_copy_area(c.get_raw_conn(),
                                   src_drawable as xcb_drawable_t,  
                                   dst_drawable as xcb_drawable_t,  
                                   gc as xcb_gcontext_t,  
                                   src_x as i16,  
                                   src_y as i16,  
                                   dst_x as i16,  
                                   dst_y as i16,  
                                   width as u16,  
                                   height as u16);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn copy_area_checked<'a>(c           : &'a base::Connection,
                             src_drawable: Drawable,
                             dst_drawable: Drawable,
                             gc          : Gcontext,
                             src_x       : i16,
                             src_y       : i16,
                             dst_x       : i16,
                             dst_y       : i16,
                             width       : u16,
                             height      : u16)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_copy_area_checked(c.get_raw_conn(),
                                           src_drawable as xcb_drawable_t,  
                                           dst_drawable as xcb_drawable_t,  
                                           gc as xcb_gcontext_t,  
                                           src_x as i16,  
                                           src_y as i16,  
                                           dst_x as i16,  
                                           dst_y as i16,  
                                           width as u16,  
                                           height as u16);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const COPY_PLANE: u8 = 63;
pub fn copy_plane<'a>(c           : &'a base::Connection,
                      src_drawable: Drawable,
                      dst_drawable: Drawable,
                      gc          : Gcontext,
                      src_x       : i16,
                      src_y       : i16,
                      dst_x       : i16,
                      dst_y       : i16,
                      width       : u16,
                      height      : u16,
                      bit_plane   : u32)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_copy_plane(c.get_raw_conn(),
                                    src_drawable as xcb_drawable_t,  
                                    dst_drawable as xcb_drawable_t,  
                                    gc as xcb_gcontext_t,  
                                    src_x as i16,  
                                    src_y as i16,  
                                    dst_x as i16,  
                                    dst_y as i16,  
                                    width as u16,  
                                    height as u16,  
                                    bit_plane as u32);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn copy_plane_checked<'a>(c           : &'a base::Connection,
                              src_drawable: Drawable,
                              dst_drawable: Drawable,
                              gc          : Gcontext,
                              src_x       : i16,
                              src_y       : i16,
                              dst_x       : i16,
                              dst_y       : i16,
                              width       : u16,
                              height      : u16,
                              bit_plane   : u32)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_copy_plane_checked(c.get_raw_conn(),
                                            src_drawable as xcb_drawable_t,  
                                            dst_drawable as xcb_drawable_t,  
                                            gc as xcb_gcontext_t,  
                                            src_x as i16,  
                                            src_y as i16,  
                                            dst_x as i16,  
                                            dst_y as i16,  
                                            width as u16,  
                                            height as u16,  
                                            bit_plane as u32);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const POLY_POINT: u8 = 64;
pub fn poly_point<'a>(c              : &'a base::Connection,
                      coordinate_mode: u8,
                      drawable       : Drawable,
                      gc             : Gcontext,
                      points         : &[Point])
        -> base::VoidCookie<'a> {
    unsafe {
        let points_len = points.len();
        let points_ptr = points.as_ptr();
        let cookie = xcb_poly_point(c.get_raw_conn(),
                                    coordinate_mode as u8,  
                                    drawable as xcb_drawable_t,  
                                    gc as xcb_gcontext_t,  
                                    points_len as u32,  
                                    points_ptr as *const xcb_point_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn poly_point_checked<'a>(c              : &'a base::Connection,
                              coordinate_mode: u8,
                              drawable       : Drawable,
                              gc             : Gcontext,
                              points         : &[Point])
        -> base::VoidCookie<'a> {
    unsafe {
        let points_len = points.len();
        let points_ptr = points.as_ptr();
        let cookie = xcb_poly_point_checked(c.get_raw_conn(),
                                            coordinate_mode as u8,  
                                            drawable as xcb_drawable_t,  
                                            gc as xcb_gcontext_t,  
                                            points_len as u32,  
                                            points_ptr as *const xcb_point_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const POLY_LINE: u8 = 65;
pub fn poly_line<'a>(c              : &'a base::Connection,
                     coordinate_mode: u8,
                     drawable       : Drawable,
                     gc             : Gcontext,
                     points         : &[Point])
        -> base::VoidCookie<'a> {
    unsafe {
        let points_len = points.len();
        let points_ptr = points.as_ptr();
        let cookie = xcb_poly_line(c.get_raw_conn(),
                                   coordinate_mode as u8,  
                                   drawable as xcb_drawable_t,  
                                   gc as xcb_gcontext_t,  
                                   points_len as u32,  
                                   points_ptr as *const xcb_point_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn poly_line_checked<'a>(c              : &'a base::Connection,
                             coordinate_mode: u8,
                             drawable       : Drawable,
                             gc             : Gcontext,
                             points         : &[Point])
        -> base::VoidCookie<'a> {
    unsafe {
        let points_len = points.len();
        let points_ptr = points.as_ptr();
        let cookie = xcb_poly_line_checked(c.get_raw_conn(),
                                           coordinate_mode as u8,  
                                           drawable as xcb_drawable_t,  
                                           gc as xcb_gcontext_t,  
                                           points_len as u32,  
                                           points_ptr as *const xcb_point_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
#[derive(Copy, Clone)]
pub struct Segment {
    pub base: xcb_segment_t,
}
impl Segment {
    #[allow(unused_unsafe)]
    pub fn new(x1: i16,
               y1: i16,
               x2: i16,
               y2: i16)
            -> Segment {
        unsafe {
            Segment {
                base: xcb_segment_t {
                    x1: x1,
                    y1: y1,
                    x2: x2,
                    y2: y2,
                }
            }
        }
    }
    pub fn x1(&self) -> i16 {
        unsafe {
            self.base.x1
        }
    }
    pub fn y1(&self) -> i16 {
        unsafe {
            self.base.y1
        }
    }
    pub fn x2(&self) -> i16 {
        unsafe {
            self.base.x2
        }
    }
    pub fn y2(&self) -> i16 {
        unsafe {
            self.base.y2
        }
    }
}
pub type SegmentIterator = xcb_segment_iterator_t;
impl Iterator for SegmentIterator {
    type Item = Segment;
    fn next(&mut self) -> std::option::Option<Segment> {
        if self.rem == 0 { None }
        else {
            unsafe {
                let iter = self as *mut xcb_segment_iterator_t;
                let data = (*iter).data;
                xcb_segment_next(iter);
                Some(std::mem::transmute(*data))
            }
        }
    }
}
pub const POLY_SEGMENT: u8 = 66;
pub fn poly_segment<'a>(c       : &'a base::Connection,
                        drawable: Drawable,
                        gc      : Gcontext,
                        segments: &[Segment])
        -> base::VoidCookie<'a> {
    unsafe {
        let segments_len = segments.len();
        let segments_ptr = segments.as_ptr();
        let cookie = xcb_poly_segment(c.get_raw_conn(),
                                      drawable as xcb_drawable_t,  
                                      gc as xcb_gcontext_t,  
                                      segments_len as u32,  
                                      segments_ptr as *const xcb_segment_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn poly_segment_checked<'a>(c       : &'a base::Connection,
                                drawable: Drawable,
                                gc      : Gcontext,
                                segments: &[Segment])
        -> base::VoidCookie<'a> {
    unsafe {
        let segments_len = segments.len();
        let segments_ptr = segments.as_ptr();
        let cookie = xcb_poly_segment_checked(c.get_raw_conn(),
                                              drawable as xcb_drawable_t,  
                                              gc as xcb_gcontext_t,  
                                              segments_len as u32,  
                                              segments_ptr as *const xcb_segment_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const POLY_RECTANGLE: u8 = 67;
pub fn poly_rectangle<'a>(c         : &'a base::Connection,
                          drawable  : Drawable,
                          gc        : Gcontext,
                          rectangles: &[Rectangle])
        -> base::VoidCookie<'a> {
    unsafe {
        let rectangles_len = rectangles.len();
        let rectangles_ptr = rectangles.as_ptr();
        let cookie = xcb_poly_rectangle(c.get_raw_conn(),
                                        drawable as xcb_drawable_t,  
                                        gc as xcb_gcontext_t,  
                                        rectangles_len as u32,  
                                        rectangles_ptr as *const xcb_rectangle_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn poly_rectangle_checked<'a>(c         : &'a base::Connection,
                                  drawable  : Drawable,
                                  gc        : Gcontext,
                                  rectangles: &[Rectangle])
        -> base::VoidCookie<'a> {
    unsafe {
        let rectangles_len = rectangles.len();
        let rectangles_ptr = rectangles.as_ptr();
        let cookie = xcb_poly_rectangle_checked(c.get_raw_conn(),
                                                drawable as xcb_drawable_t,  
                                                gc as xcb_gcontext_t,  
                                                rectangles_len as u32,  
                                                rectangles_ptr as *const xcb_rectangle_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const POLY_ARC: u8 = 68;
pub fn poly_arc<'a>(c       : &'a base::Connection,
                    drawable: Drawable,
                    gc      : Gcontext,
                    arcs    : &[Arc])
        -> base::VoidCookie<'a> {
    unsafe {
        let arcs_len = arcs.len();
        let arcs_ptr = arcs.as_ptr();
        let cookie = xcb_poly_arc(c.get_raw_conn(),
                                  drawable as xcb_drawable_t,  
                                  gc as xcb_gcontext_t,  
                                  arcs_len as u32,  
                                  arcs_ptr as *const xcb_arc_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn poly_arc_checked<'a>(c       : &'a base::Connection,
                            drawable: Drawable,
                            gc      : Gcontext,
                            arcs    : &[Arc])
        -> base::VoidCookie<'a> {
    unsafe {
        let arcs_len = arcs.len();
        let arcs_ptr = arcs.as_ptr();
        let cookie = xcb_poly_arc_checked(c.get_raw_conn(),
                                          drawable as xcb_drawable_t,  
                                          gc as xcb_gcontext_t,  
                                          arcs_len as u32,  
                                          arcs_ptr as *const xcb_arc_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const FILL_POLY: u8 = 69;
pub fn fill_poly<'a>(c              : &'a base::Connection,
                     drawable       : Drawable,
                     gc             : Gcontext,
                     shape          : u8,
                     coordinate_mode: u8,
                     points         : &[Point])
        -> base::VoidCookie<'a> {
    unsafe {
        let points_len = points.len();
        let points_ptr = points.as_ptr();
        let cookie = xcb_fill_poly(c.get_raw_conn(),
                                   drawable as xcb_drawable_t,  
                                   gc as xcb_gcontext_t,  
                                   shape as u8,  
                                   coordinate_mode as u8,  
                                   points_len as u32,  
                                   points_ptr as *const xcb_point_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn fill_poly_checked<'a>(c              : &'a base::Connection,
                             drawable       : Drawable,
                             gc             : Gcontext,
                             shape          : u8,
                             coordinate_mode: u8,
                             points         : &[Point])
        -> base::VoidCookie<'a> {
    unsafe {
        let points_len = points.len();
        let points_ptr = points.as_ptr();
        let cookie = xcb_fill_poly_checked(c.get_raw_conn(),
                                           drawable as xcb_drawable_t,  
                                           gc as xcb_gcontext_t,  
                                           shape as u8,  
                                           coordinate_mode as u8,  
                                           points_len as u32,  
                                           points_ptr as *const xcb_point_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const POLY_FILL_RECTANGLE: u8 = 70;
pub fn poly_fill_rectangle<'a>(c         : &'a base::Connection,
                               drawable  : Drawable,
                               gc        : Gcontext,
                               rectangles: &[Rectangle])
        -> base::VoidCookie<'a> {
    unsafe {
        let rectangles_len = rectangles.len();
        let rectangles_ptr = rectangles.as_ptr();
        let cookie = xcb_poly_fill_rectangle(c.get_raw_conn(),
                                             drawable as xcb_drawable_t,  
                                             gc as xcb_gcontext_t,  
                                             rectangles_len as u32,  
                                             rectangles_ptr as *const xcb_rectangle_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn poly_fill_rectangle_checked<'a>(c         : &'a base::Connection,
                                       drawable  : Drawable,
                                       gc        : Gcontext,
                                       rectangles: &[Rectangle])
        -> base::VoidCookie<'a> {
    unsafe {
        let rectangles_len = rectangles.len();
        let rectangles_ptr = rectangles.as_ptr();
        let cookie = xcb_poly_fill_rectangle_checked(c.get_raw_conn(),
                                                     drawable as xcb_drawable_t,  
                                                     gc as xcb_gcontext_t,  
                                                     rectangles_len as u32,  
                                                     rectangles_ptr as *const xcb_rectangle_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const POLY_FILL_ARC: u8 = 71;
pub fn poly_fill_arc<'a>(c       : &'a base::Connection,
                         drawable: Drawable,
                         gc      : Gcontext,
                         arcs    : &[Arc])
        -> base::VoidCookie<'a> {
    unsafe {
        let arcs_len = arcs.len();
        let arcs_ptr = arcs.as_ptr();
        let cookie = xcb_poly_fill_arc(c.get_raw_conn(),
                                       drawable as xcb_drawable_t,  
                                       gc as xcb_gcontext_t,  
                                       arcs_len as u32,  
                                       arcs_ptr as *const xcb_arc_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn poly_fill_arc_checked<'a>(c       : &'a base::Connection,
                                 drawable: Drawable,
                                 gc      : Gcontext,
                                 arcs    : &[Arc])
        -> base::VoidCookie<'a> {
    unsafe {
        let arcs_len = arcs.len();
        let arcs_ptr = arcs.as_ptr();
        let cookie = xcb_poly_fill_arc_checked(c.get_raw_conn(),
                                               drawable as xcb_drawable_t,  
                                               gc as xcb_gcontext_t,  
                                               arcs_len as u32,  
                                               arcs_ptr as *const xcb_arc_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const PUT_IMAGE: u8 = 72;
pub fn put_image<'a>(c       : &'a base::Connection,
                     format  : u8,
                     drawable: Drawable,
                     gc      : Gcontext,
                     width   : u16,
                     height  : u16,
                     dst_x   : i16,
                     dst_y   : i16,
                     left_pad: u8,
                     depth   : u8,
                     data    : &[u8])
        -> base::VoidCookie<'a> {
    unsafe {
        let data_len = data.len();
        let data_ptr = data.as_ptr();
        let cookie = xcb_put_image(c.get_raw_conn(),
                                   format as u8,  
                                   drawable as xcb_drawable_t,  
                                   gc as xcb_gcontext_t,  
                                   width as u16,  
                                   height as u16,  
                                   dst_x as i16,  
                                   dst_y as i16,  
                                   left_pad as u8,  
                                   depth as u8,  
                                   data_len as u32,  
                                   data_ptr as *const u8);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn put_image_checked<'a>(c       : &'a base::Connection,
                             format  : u8,
                             drawable: Drawable,
                             gc      : Gcontext,
                             width   : u16,
                             height  : u16,
                             dst_x   : i16,
                             dst_y   : i16,
                             left_pad: u8,
                             depth   : u8,
                             data    : &[u8])
        -> base::VoidCookie<'a> {
    unsafe {
        let data_len = data.len();
        let data_ptr = data.as_ptr();
        let cookie = xcb_put_image_checked(c.get_raw_conn(),
                                           format as u8,  
                                           drawable as xcb_drawable_t,  
                                           gc as xcb_gcontext_t,  
                                           width as u16,  
                                           height as u16,  
                                           dst_x as i16,  
                                           dst_y as i16,  
                                           left_pad as u8,  
                                           depth as u8,  
                                           data_len as u32,  
                                           data_ptr as *const u8);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const GET_IMAGE: u8 = 73;
pub type GetImageCookie<'a> = base::Cookie<'a, xcb_get_image_cookie_t>;
impl<'a> GetImageCookie<'a> {
    pub fn get_reply(&self) -> Result<GetImageReply, base::GenericError> {
        unsafe {
            if self.checked {
                let mut err: *mut xcb_generic_error_t = std::ptr::null_mut();
                let reply = GetImageReply {
                    ptr: xcb_get_image_reply (self.conn.get_raw_conn(), self.cookie, &mut err)
                };
                if err.is_null() { Ok (reply) }
                else { Err(base::GenericError { ptr: err }) }
            } else {
                Ok( GetImageReply {
                    ptr: xcb_get_image_reply (self.conn.get_raw_conn(), self.cookie,
                            std::ptr::null_mut())
                })
            }
        }
    }
}
pub type GetImageReply = base::Reply<xcb_get_image_reply_t>;
impl GetImageReply {
    pub fn depth(&self) -> u8 {
        unsafe {
            (*self.ptr).depth
        }
    }
    pub fn visual(&self) -> Visualid {
        unsafe {
            (*self.ptr).visual
        }
    }
    pub fn data(&self) -> &[u8] {
        unsafe {
            let field = self.ptr;
            let len = xcb_get_image_data_length(field) as usize;
            let data = xcb_get_image_data(field);
            std::slice::from_raw_parts(data, len)
        }
    }
}
pub fn get_image<'a>(c         : &'a base::Connection,
                     format    : u8,
                     drawable  : Drawable,
                     x         : i16,
                     y         : i16,
                     width     : u16,
                     height    : u16,
                     plane_mask: u32)
        -> GetImageCookie<'a> {
    unsafe {
        let cookie = xcb_get_image(c.get_raw_conn(),
                                   format as u8,  
                                   drawable as xcb_drawable_t,  
                                   x as i16,  
                                   y as i16,  
                                   width as u16,  
                                   height as u16,  
                                   plane_mask as u32);  
        GetImageCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub fn get_image_unchecked<'a>(c         : &'a base::Connection,
                               format    : u8,
                               drawable  : Drawable,
                               x         : i16,
                               y         : i16,
                               width     : u16,
                               height    : u16,
                               plane_mask: u32)
        -> GetImageCookie<'a> {
    unsafe {
        let cookie = xcb_get_image_unchecked(c.get_raw_conn(),
                                             format as u8,  
                                             drawable as xcb_drawable_t,  
                                             x as i16,  
                                             y as i16,  
                                             width as u16,  
                                             height as u16,  
                                             plane_mask as u32);  
        GetImageCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub const POLY_TEXT_8: u8 = 74;
pub fn poly_text_8<'a>(c       : &'a base::Connection,
                       drawable: Drawable,
                       gc      : Gcontext,
                       x       : i16,
                       y       : i16,
                       items   : &[u8])
        -> base::VoidCookie<'a> {
    unsafe {
        let items_len = items.len();
        let items_ptr = items.as_ptr();
        let cookie = xcb_poly_text_8(c.get_raw_conn(),
                                     drawable as xcb_drawable_t,  
                                     gc as xcb_gcontext_t,  
                                     x as i16,  
                                     y as i16,  
                                     items_len as u32,  
                                     items_ptr as *const u8);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn poly_text_8_checked<'a>(c       : &'a base::Connection,
                               drawable: Drawable,
                               gc      : Gcontext,
                               x       : i16,
                               y       : i16,
                               items   : &[u8])
        -> base::VoidCookie<'a> {
    unsafe {
        let items_len = items.len();
        let items_ptr = items.as_ptr();
        let cookie = xcb_poly_text_8_checked(c.get_raw_conn(),
                                             drawable as xcb_drawable_t,  
                                             gc as xcb_gcontext_t,  
                                             x as i16,  
                                             y as i16,  
                                             items_len as u32,  
                                             items_ptr as *const u8);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const POLY_TEXT_16: u8 = 75;
pub fn poly_text_16<'a>(c       : &'a base::Connection,
                        drawable: Drawable,
                        gc      : Gcontext,
                        x       : i16,
                        y       : i16,
                        items   : &[u8])
        -> base::VoidCookie<'a> {
    unsafe {
        let items_len = items.len();
        let items_ptr = items.as_ptr();
        let cookie = xcb_poly_text_16(c.get_raw_conn(),
                                      drawable as xcb_drawable_t,  
                                      gc as xcb_gcontext_t,  
                                      x as i16,  
                                      y as i16,  
                                      items_len as u32,  
                                      items_ptr as *const u8);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn poly_text_16_checked<'a>(c       : &'a base::Connection,
                                drawable: Drawable,
                                gc      : Gcontext,
                                x       : i16,
                                y       : i16,
                                items   : &[u8])
        -> base::VoidCookie<'a> {
    unsafe {
        let items_len = items.len();
        let items_ptr = items.as_ptr();
        let cookie = xcb_poly_text_16_checked(c.get_raw_conn(),
                                              drawable as xcb_drawable_t,  
                                              gc as xcb_gcontext_t,  
                                              x as i16,  
                                              y as i16,  
                                              items_len as u32,  
                                              items_ptr as *const u8);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const IMAGE_TEXT_8: u8 = 76;
pub fn image_text_8<'a>(c       : &'a base::Connection,
                        drawable: Drawable,
                        gc      : Gcontext,
                        x       : i16,
                        y       : i16,
                        string  : &str)
        -> base::VoidCookie<'a> {
    unsafe {
        let string = string.as_bytes();
        let string_len = string.len();
        let string_ptr = string.as_ptr();
        let cookie = xcb_image_text_8(c.get_raw_conn(),
                                      string_len as u8,  
                                      drawable as xcb_drawable_t,  
                                      gc as xcb_gcontext_t,  
                                      x as i16,  
                                      y as i16,  
                                      string_ptr as *const c_char);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn image_text_8_checked<'a>(c       : &'a base::Connection,
                                drawable: Drawable,
                                gc      : Gcontext,
                                x       : i16,
                                y       : i16,
                                string  : &str)
        -> base::VoidCookie<'a> {
    unsafe {
        let string = string.as_bytes();
        let string_len = string.len();
        let string_ptr = string.as_ptr();
        let cookie = xcb_image_text_8_checked(c.get_raw_conn(),
                                              string_len as u8,  
                                              drawable as xcb_drawable_t,  
                                              gc as xcb_gcontext_t,  
                                              x as i16,  
                                              y as i16,  
                                              string_ptr as *const c_char);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const IMAGE_TEXT_16: u8 = 77;
pub fn image_text_16<'a>(c       : &'a base::Connection,
                         drawable: Drawable,
                         gc      : Gcontext,
                         x       : i16,
                         y       : i16,
                         string  : &[Char2b])
        -> base::VoidCookie<'a> {
    unsafe {
        let string_len = string.len();
        let string_ptr = string.as_ptr();
        let cookie = xcb_image_text_16(c.get_raw_conn(),
                                       string_len as u8,  
                                       drawable as xcb_drawable_t,  
                                       gc as xcb_gcontext_t,  
                                       x as i16,  
                                       y as i16,  
                                       string_ptr as *const xcb_char2b_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn image_text_16_checked<'a>(c       : &'a base::Connection,
                                 drawable: Drawable,
                                 gc      : Gcontext,
                                 x       : i16,
                                 y       : i16,
                                 string  : &[Char2b])
        -> base::VoidCookie<'a> {
    unsafe {
        let string_len = string.len();
        let string_ptr = string.as_ptr();
        let cookie = xcb_image_text_16_checked(c.get_raw_conn(),
                                               string_len as u8,  
                                               drawable as xcb_drawable_t,  
                                               gc as xcb_gcontext_t,  
                                               x as i16,  
                                               y as i16,  
                                               string_ptr as *const xcb_char2b_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const CREATE_COLORMAP: u8 = 78;
pub fn create_colormap<'a>(c     : &'a base::Connection,
                           alloc : u8,
                           mid   : Colormap,
                           window: Window,
                           visual: Visualid)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_create_colormap(c.get_raw_conn(),
                                         alloc as u8,  
                                         mid as xcb_colormap_t,  
                                         window as xcb_window_t,  
                                         visual as xcb_visualid_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn create_colormap_checked<'a>(c     : &'a base::Connection,
                                   alloc : u8,
                                   mid   : Colormap,
                                   window: Window,
                                   visual: Visualid)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_create_colormap_checked(c.get_raw_conn(),
                                                 alloc as u8,  
                                                 mid as xcb_colormap_t,  
                                                 window as xcb_window_t,  
                                                 visual as xcb_visualid_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const FREE_COLORMAP: u8 = 79;
pub fn free_colormap<'a>(c   : &'a base::Connection,
                         cmap: Colormap)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_free_colormap(c.get_raw_conn(),
                                       cmap as xcb_colormap_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn free_colormap_checked<'a>(c   : &'a base::Connection,
                                 cmap: Colormap)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_free_colormap_checked(c.get_raw_conn(),
                                               cmap as xcb_colormap_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const COPY_COLORMAP_AND_FREE: u8 = 80;
pub fn copy_colormap_and_free<'a>(c       : &'a base::Connection,
                                  mid     : Colormap,
                                  src_cmap: Colormap)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_copy_colormap_and_free(c.get_raw_conn(),
                                                mid as xcb_colormap_t,  
                                                src_cmap as xcb_colormap_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn copy_colormap_and_free_checked<'a>(c       : &'a base::Connection,
                                          mid     : Colormap,
                                          src_cmap: Colormap)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_copy_colormap_and_free_checked(c.get_raw_conn(),
                                                        mid as xcb_colormap_t,  
                                                        src_cmap as xcb_colormap_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const INSTALL_COLORMAP: u8 = 81;
pub fn install_colormap<'a>(c   : &'a base::Connection,
                            cmap: Colormap)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_install_colormap(c.get_raw_conn(),
                                          cmap as xcb_colormap_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn install_colormap_checked<'a>(c   : &'a base::Connection,
                                    cmap: Colormap)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_install_colormap_checked(c.get_raw_conn(),
                                                  cmap as xcb_colormap_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const UNINSTALL_COLORMAP: u8 = 82;
pub fn uninstall_colormap<'a>(c   : &'a base::Connection,
                              cmap: Colormap)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_uninstall_colormap(c.get_raw_conn(),
                                            cmap as xcb_colormap_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn uninstall_colormap_checked<'a>(c   : &'a base::Connection,
                                      cmap: Colormap)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_uninstall_colormap_checked(c.get_raw_conn(),
                                                    cmap as xcb_colormap_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const LIST_INSTALLED_COLORMAPS: u8 = 83;
pub type ListInstalledColormapsCookie<'a> = base::Cookie<'a, xcb_list_installed_colormaps_cookie_t>;
impl<'a> ListInstalledColormapsCookie<'a> {
    pub fn get_reply(&self) -> Result<ListInstalledColormapsReply, base::GenericError> {
        unsafe {
            if self.checked {
                let mut err: *mut xcb_generic_error_t = std::ptr::null_mut();
                let reply = ListInstalledColormapsReply {
                    ptr: xcb_list_installed_colormaps_reply (self.conn.get_raw_conn(), self.cookie, &mut err)
                };
                if err.is_null() { Ok (reply) }
                else { Err(base::GenericError { ptr: err }) }
            } else {
                Ok( ListInstalledColormapsReply {
                    ptr: xcb_list_installed_colormaps_reply (self.conn.get_raw_conn(), self.cookie,
                            std::ptr::null_mut())
                })
            }
        }
    }
}
pub type ListInstalledColormapsReply = base::Reply<xcb_list_installed_colormaps_reply_t>;
impl ListInstalledColormapsReply {
    pub fn cmaps_len(&self) -> u16 {
        unsafe {
            (*self.ptr).cmaps_len
        }
    }
    pub fn cmaps(&self) -> &[Colormap] {
        unsafe {
            let field = self.ptr;
            let len = xcb_list_installed_colormaps_cmaps_length(field) as usize;
            let data = xcb_list_installed_colormaps_cmaps(field);
            std::slice::from_raw_parts(data, len)
        }
    }
}
pub fn list_installed_colormaps<'a>(c     : &'a base::Connection,
                                    window: Window)
        -> ListInstalledColormapsCookie<'a> {
    unsafe {
        let cookie = xcb_list_installed_colormaps(c.get_raw_conn(),
                                                  window as xcb_window_t);  
        ListInstalledColormapsCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub fn list_installed_colormaps_unchecked<'a>(c     : &'a base::Connection,
                                              window: Window)
        -> ListInstalledColormapsCookie<'a> {
    unsafe {
        let cookie = xcb_list_installed_colormaps_unchecked(c.get_raw_conn(),
                                                            window as xcb_window_t);  
        ListInstalledColormapsCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub const ALLOC_COLOR: u8 = 84;
pub type AllocColorCookie<'a> = base::Cookie<'a, xcb_alloc_color_cookie_t>;
impl<'a> AllocColorCookie<'a> {
    pub fn get_reply(&self) -> Result<AllocColorReply, base::GenericError> {
        unsafe {
            if self.checked {
                let mut err: *mut xcb_generic_error_t = std::ptr::null_mut();
                let reply = AllocColorReply {
                    ptr: xcb_alloc_color_reply (self.conn.get_raw_conn(), self.cookie, &mut err)
                };
                if err.is_null() { Ok (reply) }
                else { Err(base::GenericError { ptr: err }) }
            } else {
                Ok( AllocColorReply {
                    ptr: xcb_alloc_color_reply (self.conn.get_raw_conn(), self.cookie,
                            std::ptr::null_mut())
                })
            }
        }
    }
}
pub type AllocColorReply = base::Reply<xcb_alloc_color_reply_t>;
impl AllocColorReply {
    pub fn red(&self) -> u16 {
        unsafe {
            (*self.ptr).red
        }
    }
    pub fn green(&self) -> u16 {
        unsafe {
            (*self.ptr).green
        }
    }
    pub fn blue(&self) -> u16 {
        unsafe {
            (*self.ptr).blue
        }
    }
    pub fn pixel(&self) -> u32 {
        unsafe {
            (*self.ptr).pixel
        }
    }
}
pub fn alloc_color<'a>(c    : &'a base::Connection,
                       cmap : Colormap,
                       red  : u16,
                       green: u16,
                       blue : u16)
        -> AllocColorCookie<'a> {
    unsafe {
        let cookie = xcb_alloc_color(c.get_raw_conn(),
                                     cmap as xcb_colormap_t,  
                                     red as u16,  
                                     green as u16,  
                                     blue as u16);  
        AllocColorCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub fn alloc_color_unchecked<'a>(c    : &'a base::Connection,
                                 cmap : Colormap,
                                 red  : u16,
                                 green: u16,
                                 blue : u16)
        -> AllocColorCookie<'a> {
    unsafe {
        let cookie = xcb_alloc_color_unchecked(c.get_raw_conn(),
                                               cmap as xcb_colormap_t,  
                                               red as u16,  
                                               green as u16,  
                                               blue as u16);  
        AllocColorCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub const ALLOC_NAMED_COLOR: u8 = 85;
pub type AllocNamedColorCookie<'a> = base::Cookie<'a, xcb_alloc_named_color_cookie_t>;
impl<'a> AllocNamedColorCookie<'a> {
    pub fn get_reply(&self) -> Result<AllocNamedColorReply, base::GenericError> {
        unsafe {
            if self.checked {
                let mut err: *mut xcb_generic_error_t = std::ptr::null_mut();
                let reply = AllocNamedColorReply {
                    ptr: xcb_alloc_named_color_reply (self.conn.get_raw_conn(), self.cookie, &mut err)
                };
                if err.is_null() { Ok (reply) }
                else { Err(base::GenericError { ptr: err }) }
            } else {
                Ok( AllocNamedColorReply {
                    ptr: xcb_alloc_named_color_reply (self.conn.get_raw_conn(), self.cookie,
                            std::ptr::null_mut())
                })
            }
        }
    }
}
pub type AllocNamedColorReply = base::Reply<xcb_alloc_named_color_reply_t>;
impl AllocNamedColorReply {
    pub fn pixel(&self) -> u32 {
        unsafe {
            (*self.ptr).pixel
        }
    }
    pub fn exact_red(&self) -> u16 {
        unsafe {
            (*self.ptr).exact_red
        }
    }
    pub fn exact_green(&self) -> u16 {
        unsafe {
            (*self.ptr).exact_green
        }
    }
    pub fn exact_blue(&self) -> u16 {
        unsafe {
            (*self.ptr).exact_blue
        }
    }
    pub fn visual_red(&self) -> u16 {
        unsafe {
            (*self.ptr).visual_red
        }
    }
    pub fn visual_green(&self) -> u16 {
        unsafe {
            (*self.ptr).visual_green
        }
    }
    pub fn visual_blue(&self) -> u16 {
        unsafe {
            (*self.ptr).visual_blue
        }
    }
}
pub fn alloc_named_color<'a>(c   : &'a base::Connection,
                             cmap: Colormap,
                             name: &str)
        -> AllocNamedColorCookie<'a> {
    unsafe {
        let name = name.as_bytes();
        let name_len = name.len();
        let name_ptr = name.as_ptr();
        let cookie = xcb_alloc_named_color(c.get_raw_conn(),
                                           cmap as xcb_colormap_t,  
                                           name_len as u16,  
                                           name_ptr as *const c_char);  
        AllocNamedColorCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub fn alloc_named_color_unchecked<'a>(c   : &'a base::Connection,
                                       cmap: Colormap,
                                       name: &str)
        -> AllocNamedColorCookie<'a> {
    unsafe {
        let name = name.as_bytes();
        let name_len = name.len();
        let name_ptr = name.as_ptr();
        let cookie = xcb_alloc_named_color_unchecked(c.get_raw_conn(),
                                                     cmap as xcb_colormap_t,  
                                                     name_len as u16,  
                                                     name_ptr as *const c_char);  
        AllocNamedColorCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub const ALLOC_COLOR_CELLS: u8 = 86;
pub type AllocColorCellsCookie<'a> = base::Cookie<'a, xcb_alloc_color_cells_cookie_t>;
impl<'a> AllocColorCellsCookie<'a> {
    pub fn get_reply(&self) -> Result<AllocColorCellsReply, base::GenericError> {
        unsafe {
            if self.checked {
                let mut err: *mut xcb_generic_error_t = std::ptr::null_mut();
                let reply = AllocColorCellsReply {
                    ptr: xcb_alloc_color_cells_reply (self.conn.get_raw_conn(), self.cookie, &mut err)
                };
                if err.is_null() { Ok (reply) }
                else { Err(base::GenericError { ptr: err }) }
            } else {
                Ok( AllocColorCellsReply {
                    ptr: xcb_alloc_color_cells_reply (self.conn.get_raw_conn(), self.cookie,
                            std::ptr::null_mut())
                })
            }
        }
    }
}
pub type AllocColorCellsReply = base::Reply<xcb_alloc_color_cells_reply_t>;
impl AllocColorCellsReply {
    pub fn pixels_len(&self) -> u16 {
        unsafe {
            (*self.ptr).pixels_len
        }
    }
    pub fn masks_len(&self) -> u16 {
        unsafe {
            (*self.ptr).masks_len
        }
    }
    pub fn pixels(&self) -> &[u32] {
        unsafe {
            let field = self.ptr;
            let len = xcb_alloc_color_cells_pixels_length(field) as usize;
            let data = xcb_alloc_color_cells_pixels(field);
            std::slice::from_raw_parts(data, len)
        }
    }
    pub fn masks(&self) -> &[u32] {
        unsafe {
            let field = self.ptr;
            let len = xcb_alloc_color_cells_masks_length(field) as usize;
            let data = xcb_alloc_color_cells_masks(field);
            std::slice::from_raw_parts(data, len)
        }
    }
}
pub fn alloc_color_cells<'a>(c         : &'a base::Connection,
                             contiguous: bool,
                             cmap      : Colormap,
                             colors    : u16,
                             planes    : u16)
        -> AllocColorCellsCookie<'a> {
    unsafe {
        let cookie = xcb_alloc_color_cells(c.get_raw_conn(),
                                           contiguous as u8,  
                                           cmap as xcb_colormap_t,  
                                           colors as u16,  
                                           planes as u16);  
        AllocColorCellsCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub fn alloc_color_cells_unchecked<'a>(c         : &'a base::Connection,
                                       contiguous: bool,
                                       cmap      : Colormap,
                                       colors    : u16,
                                       planes    : u16)
        -> AllocColorCellsCookie<'a> {
    unsafe {
        let cookie = xcb_alloc_color_cells_unchecked(c.get_raw_conn(),
                                                     contiguous as u8,  
                                                     cmap as xcb_colormap_t,  
                                                     colors as u16,  
                                                     planes as u16);  
        AllocColorCellsCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub const ALLOC_COLOR_PLANES: u8 = 87;
pub type AllocColorPlanesCookie<'a> = base::Cookie<'a, xcb_alloc_color_planes_cookie_t>;
impl<'a> AllocColorPlanesCookie<'a> {
    pub fn get_reply(&self) -> Result<AllocColorPlanesReply, base::GenericError> {
        unsafe {
            if self.checked {
                let mut err: *mut xcb_generic_error_t = std::ptr::null_mut();
                let reply = AllocColorPlanesReply {
                    ptr: xcb_alloc_color_planes_reply (self.conn.get_raw_conn(), self.cookie, &mut err)
                };
                if err.is_null() { Ok (reply) }
                else { Err(base::GenericError { ptr: err }) }
            } else {
                Ok( AllocColorPlanesReply {
                    ptr: xcb_alloc_color_planes_reply (self.conn.get_raw_conn(), self.cookie,
                            std::ptr::null_mut())
                })
            }
        }
    }
}
pub type AllocColorPlanesReply = base::Reply<xcb_alloc_color_planes_reply_t>;
impl AllocColorPlanesReply {
    pub fn pixels_len(&self) -> u16 {
        unsafe {
            (*self.ptr).pixels_len
        }
    }
    pub fn red_mask(&self) -> u32 {
        unsafe {
            (*self.ptr).red_mask
        }
    }
    pub fn green_mask(&self) -> u32 {
        unsafe {
            (*self.ptr).green_mask
        }
    }
    pub fn blue_mask(&self) -> u32 {
        unsafe {
            (*self.ptr).blue_mask
        }
    }
    pub fn pixels(&self) -> &[u32] {
        unsafe {
            let field = self.ptr;
            let len = xcb_alloc_color_planes_pixels_length(field) as usize;
            let data = xcb_alloc_color_planes_pixels(field);
            std::slice::from_raw_parts(data, len)
        }
    }
}
pub fn alloc_color_planes<'a>(c         : &'a base::Connection,
                              contiguous: bool,
                              cmap      : Colormap,
                              colors    : u16,
                              reds      : u16,
                              greens    : u16,
                              blues     : u16)
        -> AllocColorPlanesCookie<'a> {
    unsafe {
        let cookie = xcb_alloc_color_planes(c.get_raw_conn(),
                                            contiguous as u8,  
                                            cmap as xcb_colormap_t,  
                                            colors as u16,  
                                            reds as u16,  
                                            greens as u16,  
                                            blues as u16);  
        AllocColorPlanesCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub fn alloc_color_planes_unchecked<'a>(c         : &'a base::Connection,
                                        contiguous: bool,
                                        cmap      : Colormap,
                                        colors    : u16,
                                        reds      : u16,
                                        greens    : u16,
                                        blues     : u16)
        -> AllocColorPlanesCookie<'a> {
    unsafe {
        let cookie = xcb_alloc_color_planes_unchecked(c.get_raw_conn(),
                                                      contiguous as u8,  
                                                      cmap as xcb_colormap_t,  
                                                      colors as u16,  
                                                      reds as u16,  
                                                      greens as u16,  
                                                      blues as u16);  
        AllocColorPlanesCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub const FREE_COLORS: u8 = 88;
pub fn free_colors<'a>(c         : &'a base::Connection,
                       cmap      : Colormap,
                       plane_mask: u32,
                       pixels    : &[u32])
        -> base::VoidCookie<'a> {
    unsafe {
        let pixels_len = pixels.len();
        let pixels_ptr = pixels.as_ptr();
        let cookie = xcb_free_colors(c.get_raw_conn(),
                                     cmap as xcb_colormap_t,  
                                     plane_mask as u32,  
                                     pixels_len as u32,  
                                     pixels_ptr as *const u32);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn free_colors_checked<'a>(c         : &'a base::Connection,
                               cmap      : Colormap,
                               plane_mask: u32,
                               pixels    : &[u32])
        -> base::VoidCookie<'a> {
    unsafe {
        let pixels_len = pixels.len();
        let pixels_ptr = pixels.as_ptr();
        let cookie = xcb_free_colors_checked(c.get_raw_conn(),
                                             cmap as xcb_colormap_t,  
                                             plane_mask as u32,  
                                             pixels_len as u32,  
                                             pixels_ptr as *const u32);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
#[derive(Copy, Clone)]
pub struct Coloritem {
    pub base: xcb_coloritem_t,
}
impl Coloritem {
    #[allow(unused_unsafe)]
    pub fn new(pixel: u32,
               red:   u16,
               green: u16,
               blue:  u16,
               flags: u8)
            -> Coloritem {
        unsafe {
            Coloritem {
                base: xcb_coloritem_t {
                    pixel: pixel,
                    red:   red,
                    green: green,
                    blue:  blue,
                    flags: flags,
                    pad0:  0,
                }
            }
        }
    }
    pub fn pixel(&self) -> u32 {
        unsafe {
            self.base.pixel
        }
    }
    pub fn red(&self) -> u16 {
        unsafe {
            self.base.red
        }
    }
    pub fn green(&self) -> u16 {
        unsafe {
            self.base.green
        }
    }
    pub fn blue(&self) -> u16 {
        unsafe {
            self.base.blue
        }
    }
    pub fn flags(&self) -> u8 {
        unsafe {
            self.base.flags
        }
    }
}
pub type ColoritemIterator = xcb_coloritem_iterator_t;
impl Iterator for ColoritemIterator {
    type Item = Coloritem;
    fn next(&mut self) -> std::option::Option<Coloritem> {
        if self.rem == 0 { None }
        else {
            unsafe {
                let iter = self as *mut xcb_coloritem_iterator_t;
                let data = (*iter).data;
                xcb_coloritem_next(iter);
                Some(std::mem::transmute(*data))
            }
        }
    }
}
pub const STORE_COLORS: u8 = 89;
pub fn store_colors<'a>(c    : &'a base::Connection,
                        cmap : Colormap,
                        items: &[Coloritem])
        -> base::VoidCookie<'a> {
    unsafe {
        let items_len = items.len();
        let items_ptr = items.as_ptr();
        let cookie = xcb_store_colors(c.get_raw_conn(),
                                      cmap as xcb_colormap_t,  
                                      items_len as u32,  
                                      items_ptr as *const xcb_coloritem_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn store_colors_checked<'a>(c    : &'a base::Connection,
                                cmap : Colormap,
                                items: &[Coloritem])
        -> base::VoidCookie<'a> {
    unsafe {
        let items_len = items.len();
        let items_ptr = items.as_ptr();
        let cookie = xcb_store_colors_checked(c.get_raw_conn(),
                                              cmap as xcb_colormap_t,  
                                              items_len as u32,  
                                              items_ptr as *const xcb_coloritem_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const STORE_NAMED_COLOR: u8 = 90;
pub fn store_named_color<'a>(c    : &'a base::Connection,
                             flags: u8,
                             cmap : Colormap,
                             pixel: u32,
                             name : &str)
        -> base::VoidCookie<'a> {
    unsafe {
        let name = name.as_bytes();
        let name_len = name.len();
        let name_ptr = name.as_ptr();
        let cookie = xcb_store_named_color(c.get_raw_conn(),
                                           flags as u8,  
                                           cmap as xcb_colormap_t,  
                                           pixel as u32,  
                                           name_len as u16,  
                                           name_ptr as *const c_char);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn store_named_color_checked<'a>(c    : &'a base::Connection,
                                     flags: u8,
                                     cmap : Colormap,
                                     pixel: u32,
                                     name : &str)
        -> base::VoidCookie<'a> {
    unsafe {
        let name = name.as_bytes();
        let name_len = name.len();
        let name_ptr = name.as_ptr();
        let cookie = xcb_store_named_color_checked(c.get_raw_conn(),
                                                   flags as u8,  
                                                   cmap as xcb_colormap_t,  
                                                   pixel as u32,  
                                                   name_len as u16,  
                                                   name_ptr as *const c_char);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
#[derive(Copy, Clone)]
pub struct Rgb {
    pub base: xcb_rgb_t,
}
impl Rgb {
    #[allow(unused_unsafe)]
    pub fn new(red:   u16,
               green: u16,
               blue:  u16)
            -> Rgb {
        unsafe {
            Rgb {
                base: xcb_rgb_t {
                    red:   red,
                    green: green,
                    blue:  blue,
                    pad0:  [0; 2],
                }
            }
        }
    }
    pub fn red(&self) -> u16 {
        unsafe {
            self.base.red
        }
    }
    pub fn green(&self) -> u16 {
        unsafe {
            self.base.green
        }
    }
    pub fn blue(&self) -> u16 {
        unsafe {
            self.base.blue
        }
    }
}
pub type RgbIterator = xcb_rgb_iterator_t;
impl Iterator for RgbIterator {
    type Item = Rgb;
    fn next(&mut self) -> std::option::Option<Rgb> {
        if self.rem == 0 { None }
        else {
            unsafe {
                let iter = self as *mut xcb_rgb_iterator_t;
                let data = (*iter).data;
                xcb_rgb_next(iter);
                Some(std::mem::transmute(*data))
            }
        }
    }
}
pub const QUERY_COLORS: u8 = 91;
pub type QueryColorsCookie<'a> = base::Cookie<'a, xcb_query_colors_cookie_t>;
impl<'a> QueryColorsCookie<'a> {
    pub fn get_reply(&self) -> Result<QueryColorsReply, base::GenericError> {
        unsafe {
            if self.checked {
                let mut err: *mut xcb_generic_error_t = std::ptr::null_mut();
                let reply = QueryColorsReply {
                    ptr: xcb_query_colors_reply (self.conn.get_raw_conn(), self.cookie, &mut err)
                };
                if err.is_null() { Ok (reply) }
                else { Err(base::GenericError { ptr: err }) }
            } else {
                Ok( QueryColorsReply {
                    ptr: xcb_query_colors_reply (self.conn.get_raw_conn(), self.cookie,
                            std::ptr::null_mut())
                })
            }
        }
    }
}
pub type QueryColorsReply = base::Reply<xcb_query_colors_reply_t>;
impl QueryColorsReply {
    pub fn colors_len(&self) -> u16 {
        unsafe {
            (*self.ptr).colors_len
        }
    }
    pub fn colors(&self) -> RgbIterator {
        unsafe {
            xcb_query_colors_colors_iterator(self.ptr)
        }
    }
}
pub fn query_colors<'a>(c     : &'a base::Connection,
                        cmap  : Colormap,
                        pixels: &[u32])
        -> QueryColorsCookie<'a> {
    unsafe {
        let pixels_len = pixels.len();
        let pixels_ptr = pixels.as_ptr();
        let cookie = xcb_query_colors(c.get_raw_conn(),
                                      cmap as xcb_colormap_t,  
                                      pixels_len as u32,  
                                      pixels_ptr as *const u32);  
        QueryColorsCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub fn query_colors_unchecked<'a>(c     : &'a base::Connection,
                                  cmap  : Colormap,
                                  pixels: &[u32])
        -> QueryColorsCookie<'a> {
    unsafe {
        let pixels_len = pixels.len();
        let pixels_ptr = pixels.as_ptr();
        let cookie = xcb_query_colors_unchecked(c.get_raw_conn(),
                                                cmap as xcb_colormap_t,  
                                                pixels_len as u32,  
                                                pixels_ptr as *const u32);  
        QueryColorsCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub const LOOKUP_COLOR: u8 = 92;
pub type LookupColorCookie<'a> = base::Cookie<'a, xcb_lookup_color_cookie_t>;
impl<'a> LookupColorCookie<'a> {
    pub fn get_reply(&self) -> Result<LookupColorReply, base::GenericError> {
        unsafe {
            if self.checked {
                let mut err: *mut xcb_generic_error_t = std::ptr::null_mut();
                let reply = LookupColorReply {
                    ptr: xcb_lookup_color_reply (self.conn.get_raw_conn(), self.cookie, &mut err)
                };
                if err.is_null() { Ok (reply) }
                else { Err(base::GenericError { ptr: err }) }
            } else {
                Ok( LookupColorReply {
                    ptr: xcb_lookup_color_reply (self.conn.get_raw_conn(), self.cookie,
                            std::ptr::null_mut())
                })
            }
        }
    }
}
pub type LookupColorReply = base::Reply<xcb_lookup_color_reply_t>;
impl LookupColorReply {
    pub fn exact_red(&self) -> u16 {
        unsafe {
            (*self.ptr).exact_red
        }
    }
    pub fn exact_green(&self) -> u16 {
        unsafe {
            (*self.ptr).exact_green
        }
    }
    pub fn exact_blue(&self) -> u16 {
        unsafe {
            (*self.ptr).exact_blue
        }
    }
    pub fn visual_red(&self) -> u16 {
        unsafe {
            (*self.ptr).visual_red
        }
    }
    pub fn visual_green(&self) -> u16 {
        unsafe {
            (*self.ptr).visual_green
        }
    }
    pub fn visual_blue(&self) -> u16 {
        unsafe {
            (*self.ptr).visual_blue
        }
    }
}
pub fn lookup_color<'a>(c   : &'a base::Connection,
                        cmap: Colormap,
                        name: &str)
        -> LookupColorCookie<'a> {
    unsafe {
        let name = name.as_bytes();
        let name_len = name.len();
        let name_ptr = name.as_ptr();
        let cookie = xcb_lookup_color(c.get_raw_conn(),
                                      cmap as xcb_colormap_t,  
                                      name_len as u16,  
                                      name_ptr as *const c_char);  
        LookupColorCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub fn lookup_color_unchecked<'a>(c   : &'a base::Connection,
                                  cmap: Colormap,
                                  name: &str)
        -> LookupColorCookie<'a> {
    unsafe {
        let name = name.as_bytes();
        let name_len = name.len();
        let name_ptr = name.as_ptr();
        let cookie = xcb_lookup_color_unchecked(c.get_raw_conn(),
                                                cmap as xcb_colormap_t,  
                                                name_len as u16,  
                                                name_ptr as *const c_char);  
        LookupColorCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub const CREATE_CURSOR: u8 = 93;
pub fn create_cursor<'a>(c         : &'a base::Connection,
                         cid       : Cursor,
                         source    : Pixmap,
                         mask      : Pixmap,
                         fore_red  : u16,
                         fore_green: u16,
                         fore_blue : u16,
                         back_red  : u16,
                         back_green: u16,
                         back_blue : u16,
                         x         : u16,
                         y         : u16)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_create_cursor(c.get_raw_conn(),
                                       cid as xcb_cursor_t,  
                                       source as xcb_pixmap_t,  
                                       mask as xcb_pixmap_t,  
                                       fore_red as u16,  
                                       fore_green as u16,  
                                       fore_blue as u16,  
                                       back_red as u16,  
                                       back_green as u16,  
                                       back_blue as u16,  
                                       x as u16,  
                                       y as u16);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn create_cursor_checked<'a>(c         : &'a base::Connection,
                                 cid       : Cursor,
                                 source    : Pixmap,
                                 mask      : Pixmap,
                                 fore_red  : u16,
                                 fore_green: u16,
                                 fore_blue : u16,
                                 back_red  : u16,
                                 back_green: u16,
                                 back_blue : u16,
                                 x         : u16,
                                 y         : u16)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_create_cursor_checked(c.get_raw_conn(),
                                               cid as xcb_cursor_t,  
                                               source as xcb_pixmap_t,  
                                               mask as xcb_pixmap_t,  
                                               fore_red as u16,  
                                               fore_green as u16,  
                                               fore_blue as u16,  
                                               back_red as u16,  
                                               back_green as u16,  
                                               back_blue as u16,  
                                               x as u16,  
                                               y as u16);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const CREATE_GLYPH_CURSOR: u8 = 94;
pub fn create_glyph_cursor<'a>(c          : &'a base::Connection,
                               cid        : Cursor,
                               source_font: Font,
                               mask_font  : Font,
                               source_char: u16,
                               mask_char  : u16,
                               fore_red   : u16,
                               fore_green : u16,
                               fore_blue  : u16,
                               back_red   : u16,
                               back_green : u16,
                               back_blue  : u16)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_create_glyph_cursor(c.get_raw_conn(),
                                             cid as xcb_cursor_t,  
                                             source_font as xcb_font_t,  
                                             mask_font as xcb_font_t,  
                                             source_char as u16,  
                                             mask_char as u16,  
                                             fore_red as u16,  
                                             fore_green as u16,  
                                             fore_blue as u16,  
                                             back_red as u16,  
                                             back_green as u16,  
                                             back_blue as u16);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn create_glyph_cursor_checked<'a>(c          : &'a base::Connection,
                                       cid        : Cursor,
                                       source_font: Font,
                                       mask_font  : Font,
                                       source_char: u16,
                                       mask_char  : u16,
                                       fore_red   : u16,
                                       fore_green : u16,
                                       fore_blue  : u16,
                                       back_red   : u16,
                                       back_green : u16,
                                       back_blue  : u16)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_create_glyph_cursor_checked(c.get_raw_conn(),
                                                     cid as xcb_cursor_t,  
                                                     source_font as xcb_font_t,  
                                                     mask_font as xcb_font_t,  
                                                     source_char as u16,  
                                                     mask_char as u16,  
                                                     fore_red as u16,  
                                                     fore_green as u16,  
                                                     fore_blue as u16,  
                                                     back_red as u16,  
                                                     back_green as u16,  
                                                     back_blue as u16);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const FREE_CURSOR: u8 = 95;
pub fn free_cursor<'a>(c     : &'a base::Connection,
                       cursor: Cursor)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_free_cursor(c.get_raw_conn(),
                                     cursor as xcb_cursor_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn free_cursor_checked<'a>(c     : &'a base::Connection,
                               cursor: Cursor)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_free_cursor_checked(c.get_raw_conn(),
                                             cursor as xcb_cursor_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const RECOLOR_CURSOR: u8 = 96;
pub fn recolor_cursor<'a>(c         : &'a base::Connection,
                          cursor    : Cursor,
                          fore_red  : u16,
                          fore_green: u16,
                          fore_blue : u16,
                          back_red  : u16,
                          back_green: u16,
                          back_blue : u16)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_recolor_cursor(c.get_raw_conn(),
                                        cursor as xcb_cursor_t,  
                                        fore_red as u16,  
                                        fore_green as u16,  
                                        fore_blue as u16,  
                                        back_red as u16,  
                                        back_green as u16,  
                                        back_blue as u16);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn recolor_cursor_checked<'a>(c         : &'a base::Connection,
                                  cursor    : Cursor,
                                  fore_red  : u16,
                                  fore_green: u16,
                                  fore_blue : u16,
                                  back_red  : u16,
                                  back_green: u16,
                                  back_blue : u16)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_recolor_cursor_checked(c.get_raw_conn(),
                                                cursor as xcb_cursor_t,  
                                                fore_red as u16,  
                                                fore_green as u16,  
                                                fore_blue as u16,  
                                                back_red as u16,  
                                                back_green as u16,  
                                                back_blue as u16);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const QUERY_BEST_SIZE: u8 = 97;
pub type QueryBestSizeCookie<'a> = base::Cookie<'a, xcb_query_best_size_cookie_t>;
impl<'a> QueryBestSizeCookie<'a> {
    pub fn get_reply(&self) -> Result<QueryBestSizeReply, base::GenericError> {
        unsafe {
            if self.checked {
                let mut err: *mut xcb_generic_error_t = std::ptr::null_mut();
                let reply = QueryBestSizeReply {
                    ptr: xcb_query_best_size_reply (self.conn.get_raw_conn(), self.cookie, &mut err)
                };
                if err.is_null() { Ok (reply) }
                else { Err(base::GenericError { ptr: err }) }
            } else {
                Ok( QueryBestSizeReply {
                    ptr: xcb_query_best_size_reply (self.conn.get_raw_conn(), self.cookie,
                            std::ptr::null_mut())
                })
            }
        }
    }
}
pub type QueryBestSizeReply = base::Reply<xcb_query_best_size_reply_t>;
impl QueryBestSizeReply {
    pub fn width(&self) -> u16 {
        unsafe {
            (*self.ptr).width
        }
    }
    pub fn height(&self) -> u16 {
        unsafe {
            (*self.ptr).height
        }
    }
}
pub fn query_best_size<'a>(c       : &'a base::Connection,
                           class   : u8,
                           drawable: Drawable,
                           width   : u16,
                           height  : u16)
        -> QueryBestSizeCookie<'a> {
    unsafe {
        let cookie = xcb_query_best_size(c.get_raw_conn(),
                                         class as u8,  
                                         drawable as xcb_drawable_t,  
                                         width as u16,  
                                         height as u16);  
        QueryBestSizeCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub fn query_best_size_unchecked<'a>(c       : &'a base::Connection,
                                     class   : u8,
                                     drawable: Drawable,
                                     width   : u16,
                                     height  : u16)
        -> QueryBestSizeCookie<'a> {
    unsafe {
        let cookie = xcb_query_best_size_unchecked(c.get_raw_conn(),
                                                   class as u8,  
                                                   drawable as xcb_drawable_t,  
                                                   width as u16,  
                                                   height as u16);  
        QueryBestSizeCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub const QUERY_EXTENSION: u8 = 98;
pub type QueryExtensionCookie<'a> = base::Cookie<'a, xcb_query_extension_cookie_t>;
impl<'a> QueryExtensionCookie<'a> {
    pub fn get_reply(&self) -> Result<QueryExtensionReply, base::GenericError> {
        unsafe {
            if self.checked {
                let mut err: *mut xcb_generic_error_t = std::ptr::null_mut();
                let reply = QueryExtensionReply {
                    ptr: xcb_query_extension_reply (self.conn.get_raw_conn(), self.cookie, &mut err)
                };
                if err.is_null() { Ok (reply) }
                else { Err(base::GenericError { ptr: err }) }
            } else {
                Ok( QueryExtensionReply {
                    ptr: xcb_query_extension_reply (self.conn.get_raw_conn(), self.cookie,
                            std::ptr::null_mut())
                })
            }
        }
    }
}
pub type QueryExtensionReply = base::Reply<xcb_query_extension_reply_t>;
impl QueryExtensionReply {
    pub fn present(&self) -> bool {
        unsafe {
            (*self.ptr).present != 0
        }
    }
    pub fn major_opcode(&self) -> u8 {
        unsafe {
            (*self.ptr).major_opcode
        }
    }
    pub fn first_event(&self) -> u8 {
        unsafe {
            (*self.ptr).first_event
        }
    }
    pub fn first_error(&self) -> u8 {
        unsafe {
            (*self.ptr).first_error
        }
    }
}
pub fn query_extension<'a>(c   : &'a base::Connection,
                           name: &str)
        -> QueryExtensionCookie<'a> {
    unsafe {
        let name = name.as_bytes();
        let name_len = name.len();
        let name_ptr = name.as_ptr();
        let cookie = xcb_query_extension(c.get_raw_conn(),
                                         name_len as u16,  
                                         name_ptr as *const c_char);  
        QueryExtensionCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub fn query_extension_unchecked<'a>(c   : &'a base::Connection,
                                     name: &str)
        -> QueryExtensionCookie<'a> {
    unsafe {
        let name = name.as_bytes();
        let name_len = name.len();
        let name_ptr = name.as_ptr();
        let cookie = xcb_query_extension_unchecked(c.get_raw_conn(),
                                                   name_len as u16,  
                                                   name_ptr as *const c_char);  
        QueryExtensionCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub const LIST_EXTENSIONS: u8 = 99;
pub type ListExtensionsCookie<'a> = base::Cookie<'a, xcb_list_extensions_cookie_t>;
impl<'a> ListExtensionsCookie<'a> {
    pub fn get_reply(&self) -> Result<ListExtensionsReply, base::GenericError> {
        unsafe {
            if self.checked {
                let mut err: *mut xcb_generic_error_t = std::ptr::null_mut();
                let reply = ListExtensionsReply {
                    ptr: xcb_list_extensions_reply (self.conn.get_raw_conn(), self.cookie, &mut err)
                };
                if err.is_null() { Ok (reply) }
                else { Err(base::GenericError { ptr: err }) }
            } else {
                Ok( ListExtensionsReply {
                    ptr: xcb_list_extensions_reply (self.conn.get_raw_conn(), self.cookie,
                            std::ptr::null_mut())
                })
            }
        }
    }
}
pub type ListExtensionsReply = base::Reply<xcb_list_extensions_reply_t>;
impl ListExtensionsReply {
    pub fn names_len(&self) -> u8 {
        unsafe {
            (*self.ptr).names_len
        }
    }
    pub fn names(&self) -> StrIterator {
        unsafe {
            xcb_list_extensions_names_iterator(self.ptr)
        }
    }
}
pub fn list_extensions<'a>(c: &'a base::Connection)
        -> ListExtensionsCookie<'a> {
    unsafe {
        let cookie = xcb_list_extensions(c.get_raw_conn());
        ListExtensionsCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub fn list_extensions_unchecked<'a>(c: &'a base::Connection)
        -> ListExtensionsCookie<'a> {
    unsafe {
        let cookie = xcb_list_extensions_unchecked(c.get_raw_conn());
        ListExtensionsCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub const CHANGE_KEYBOARD_MAPPING: u8 = 100;
pub fn change_keyboard_mapping<'a>(c                  : &'a base::Connection,
                                   first_keycode      : Keycode,
                                   keysyms_per_keycode: u8,
                                   keysyms            : &[Keysym])
        -> base::VoidCookie<'a> {
    unsafe {
        let keysyms_len = keysyms.len();
        let keysyms_ptr = keysyms.as_ptr();
        let cookie = xcb_change_keyboard_mapping(c.get_raw_conn(),
                                                 keysyms_len as u8,  
                                                 first_keycode as xcb_keycode_t,  
                                                 keysyms_per_keycode as u8,  
                                                 keysyms_ptr as *const xcb_keysym_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn change_keyboard_mapping_checked<'a>(c                  : &'a base::Connection,
                                           first_keycode      : Keycode,
                                           keysyms_per_keycode: u8,
                                           keysyms            : &[Keysym])
        -> base::VoidCookie<'a> {
    unsafe {
        let keysyms_len = keysyms.len();
        let keysyms_ptr = keysyms.as_ptr();
        let cookie = xcb_change_keyboard_mapping_checked(c.get_raw_conn(),
                                                         keysyms_len as u8,  
                                                         first_keycode as xcb_keycode_t,  
                                                         keysyms_per_keycode as u8,  
                                                         keysyms_ptr as *const xcb_keysym_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const GET_KEYBOARD_MAPPING: u8 = 101;
pub type GetKeyboardMappingCookie<'a> = base::Cookie<'a, xcb_get_keyboard_mapping_cookie_t>;
impl<'a> GetKeyboardMappingCookie<'a> {
    pub fn get_reply(&self) -> Result<GetKeyboardMappingReply, base::GenericError> {
        unsafe {
            if self.checked {
                let mut err: *mut xcb_generic_error_t = std::ptr::null_mut();
                let reply = GetKeyboardMappingReply {
                    ptr: xcb_get_keyboard_mapping_reply (self.conn.get_raw_conn(), self.cookie, &mut err)
                };
                if err.is_null() { Ok (reply) }
                else { Err(base::GenericError { ptr: err }) }
            } else {
                Ok( GetKeyboardMappingReply {
                    ptr: xcb_get_keyboard_mapping_reply (self.conn.get_raw_conn(), self.cookie,
                            std::ptr::null_mut())
                })
            }
        }
    }
}
pub type GetKeyboardMappingReply = base::Reply<xcb_get_keyboard_mapping_reply_t>;
impl GetKeyboardMappingReply {
    pub fn keysyms_per_keycode(&self) -> u8 {
        unsafe {
            (*self.ptr).keysyms_per_keycode
        }
    }
    pub fn keysyms(&self) -> &[Keysym] {
        unsafe {
            let field = self.ptr;
            let len = xcb_get_keyboard_mapping_keysyms_length(field) as usize;
            let data = xcb_get_keyboard_mapping_keysyms(field);
            std::slice::from_raw_parts(data, len)
        }
    }
}
pub fn get_keyboard_mapping<'a>(c            : &'a base::Connection,
                                first_keycode: Keycode,
                                count        : u8)
        -> GetKeyboardMappingCookie<'a> {
    unsafe {
        let cookie = xcb_get_keyboard_mapping(c.get_raw_conn(),
                                              first_keycode as xcb_keycode_t,  
                                              count as u8);  
        GetKeyboardMappingCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub fn get_keyboard_mapping_unchecked<'a>(c            : &'a base::Connection,
                                          first_keycode: Keycode,
                                          count        : u8)
        -> GetKeyboardMappingCookie<'a> {
    unsafe {
        let cookie = xcb_get_keyboard_mapping_unchecked(c.get_raw_conn(),
                                                        first_keycode as xcb_keycode_t,  
                                                        count as u8);  
        GetKeyboardMappingCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub const CHANGE_KEYBOARD_CONTROL: u8 = 102;
pub fn change_keyboard_control<'a>(c         : &'a base::Connection,
                                   value_list: &[(u32, u32)])
        -> base::VoidCookie<'a> {
    unsafe {
        let mut value_list_copy = value_list.to_vec();
        let (value_list_mask, value_list_vec) = base::pack_bitfield(&mut value_list_copy);
        let value_list_ptr = value_list_vec.as_ptr();
        let cookie = xcb_change_keyboard_control(c.get_raw_conn(),
                                                 value_list_mask as u32,  
                                                 value_list_ptr as *const u32);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn change_keyboard_control_checked<'a>(c         : &'a base::Connection,
                                           value_list: &[(u32, u32)])
        -> base::VoidCookie<'a> {
    unsafe {
        let mut value_list_copy = value_list.to_vec();
        let (value_list_mask, value_list_vec) = base::pack_bitfield(&mut value_list_copy);
        let value_list_ptr = value_list_vec.as_ptr();
        let cookie = xcb_change_keyboard_control_checked(c.get_raw_conn(),
                                                         value_list_mask as u32,  
                                                         value_list_ptr as *const u32);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const GET_KEYBOARD_CONTROL: u8 = 103;
pub type GetKeyboardControlCookie<'a> = base::Cookie<'a, xcb_get_keyboard_control_cookie_t>;
impl<'a> GetKeyboardControlCookie<'a> {
    pub fn get_reply(&self) -> Result<GetKeyboardControlReply, base::GenericError> {
        unsafe {
            if self.checked {
                let mut err: *mut xcb_generic_error_t = std::ptr::null_mut();
                let reply = GetKeyboardControlReply {
                    ptr: xcb_get_keyboard_control_reply (self.conn.get_raw_conn(), self.cookie, &mut err)
                };
                if err.is_null() { Ok (reply) }
                else { Err(base::GenericError { ptr: err }) }
            } else {
                Ok( GetKeyboardControlReply {
                    ptr: xcb_get_keyboard_control_reply (self.conn.get_raw_conn(), self.cookie,
                            std::ptr::null_mut())
                })
            }
        }
    }
}
pub type GetKeyboardControlReply = base::Reply<xcb_get_keyboard_control_reply_t>;
impl GetKeyboardControlReply {
    pub fn global_auto_repeat(&self) -> u8 {
        unsafe {
            (*self.ptr).global_auto_repeat
        }
    }
    pub fn led_mask(&self) -> u32 {
        unsafe {
            (*self.ptr).led_mask
        }
    }
    pub fn key_click_percent(&self) -> u8 {
        unsafe {
            (*self.ptr).key_click_percent
        }
    }
    pub fn bell_percent(&self) -> u8 {
        unsafe {
            (*self.ptr).bell_percent
        }
    }
    pub fn bell_pitch(&self) -> u16 {
        unsafe {
            (*self.ptr).bell_pitch
        }
    }
    pub fn bell_duration(&self) -> u16 {
        unsafe {
            (*self.ptr).bell_duration
        }
    }
    pub fn auto_repeats(&self) -> &[u8] {
        unsafe {
            &(*self.ptr).auto_repeats
        }
    }
}
pub fn get_keyboard_control<'a>(c: &'a base::Connection)
        -> GetKeyboardControlCookie<'a> {
    unsafe {
        let cookie = xcb_get_keyboard_control(c.get_raw_conn());
        GetKeyboardControlCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub fn get_keyboard_control_unchecked<'a>(c: &'a base::Connection)
        -> GetKeyboardControlCookie<'a> {
    unsafe {
        let cookie = xcb_get_keyboard_control_unchecked(c.get_raw_conn());
        GetKeyboardControlCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub const BELL: u8 = 104;
pub fn bell<'a>(c      : &'a base::Connection,
                percent: i8)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_bell(c.get_raw_conn(),
                              percent as i8);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn bell_checked<'a>(c      : &'a base::Connection,
                        percent: i8)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_bell_checked(c.get_raw_conn(),
                                      percent as i8);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const CHANGE_POINTER_CONTROL: u8 = 105;
pub fn change_pointer_control<'a>(c                       : &'a base::Connection,
                                  acceleration_numerator  : i16,
                                  acceleration_denominator: i16,
                                  threshold               : i16,
                                  do_acceleration         : bool,
                                  do_threshold            : bool)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_change_pointer_control(c.get_raw_conn(),
                                                acceleration_numerator as i16,  
                                                acceleration_denominator as i16,  
                                                threshold as i16,  
                                                do_acceleration as u8,  
                                                do_threshold as u8);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn change_pointer_control_checked<'a>(c                       : &'a base::Connection,
                                          acceleration_numerator  : i16,
                                          acceleration_denominator: i16,
                                          threshold               : i16,
                                          do_acceleration         : bool,
                                          do_threshold            : bool)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_change_pointer_control_checked(c.get_raw_conn(),
                                                        acceleration_numerator as i16,  
                                                        acceleration_denominator as i16,  
                                                        threshold as i16,  
                                                        do_acceleration as u8,  
                                                        do_threshold as u8);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const GET_POINTER_CONTROL: u8 = 106;
pub type GetPointerControlCookie<'a> = base::Cookie<'a, xcb_get_pointer_control_cookie_t>;
impl<'a> GetPointerControlCookie<'a> {
    pub fn get_reply(&self) -> Result<GetPointerControlReply, base::GenericError> {
        unsafe {
            if self.checked {
                let mut err: *mut xcb_generic_error_t = std::ptr::null_mut();
                let reply = GetPointerControlReply {
                    ptr: xcb_get_pointer_control_reply (self.conn.get_raw_conn(), self.cookie, &mut err)
                };
                if err.is_null() { Ok (reply) }
                else { Err(base::GenericError { ptr: err }) }
            } else {
                Ok( GetPointerControlReply {
                    ptr: xcb_get_pointer_control_reply (self.conn.get_raw_conn(), self.cookie,
                            std::ptr::null_mut())
                })
            }
        }
    }
}
pub type GetPointerControlReply = base::Reply<xcb_get_pointer_control_reply_t>;
impl GetPointerControlReply {
    pub fn acceleration_numerator(&self) -> u16 {
        unsafe {
            (*self.ptr).acceleration_numerator
        }
    }
    pub fn acceleration_denominator(&self) -> u16 {
        unsafe {
            (*self.ptr).acceleration_denominator
        }
    }
    pub fn threshold(&self) -> u16 {
        unsafe {
            (*self.ptr).threshold
        }
    }
}
pub fn get_pointer_control<'a>(c: &'a base::Connection)
        -> GetPointerControlCookie<'a> {
    unsafe {
        let cookie = xcb_get_pointer_control(c.get_raw_conn());
        GetPointerControlCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub fn get_pointer_control_unchecked<'a>(c: &'a base::Connection)
        -> GetPointerControlCookie<'a> {
    unsafe {
        let cookie = xcb_get_pointer_control_unchecked(c.get_raw_conn());
        GetPointerControlCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub const SET_SCREEN_SAVER: u8 = 107;
pub fn set_screen_saver<'a>(c              : &'a base::Connection,
                            timeout        : i16,
                            interval       : i16,
                            prefer_blanking: u8,
                            allow_exposures: u8)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_set_screen_saver(c.get_raw_conn(),
                                          timeout as i16,  
                                          interval as i16,  
                                          prefer_blanking as u8,  
                                          allow_exposures as u8);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn set_screen_saver_checked<'a>(c              : &'a base::Connection,
                                    timeout        : i16,
                                    interval       : i16,
                                    prefer_blanking: u8,
                                    allow_exposures: u8)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_set_screen_saver_checked(c.get_raw_conn(),
                                                  timeout as i16,  
                                                  interval as i16,  
                                                  prefer_blanking as u8,  
                                                  allow_exposures as u8);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const GET_SCREEN_SAVER: u8 = 108;
pub type GetScreenSaverCookie<'a> = base::Cookie<'a, xcb_get_screen_saver_cookie_t>;
impl<'a> GetScreenSaverCookie<'a> {
    pub fn get_reply(&self) -> Result<GetScreenSaverReply, base::GenericError> {
        unsafe {
            if self.checked {
                let mut err: *mut xcb_generic_error_t = std::ptr::null_mut();
                let reply = GetScreenSaverReply {
                    ptr: xcb_get_screen_saver_reply (self.conn.get_raw_conn(), self.cookie, &mut err)
                };
                if err.is_null() { Ok (reply) }
                else { Err(base::GenericError { ptr: err }) }
            } else {
                Ok( GetScreenSaverReply {
                    ptr: xcb_get_screen_saver_reply (self.conn.get_raw_conn(), self.cookie,
                            std::ptr::null_mut())
                })
            }
        }
    }
}
pub type GetScreenSaverReply = base::Reply<xcb_get_screen_saver_reply_t>;
impl GetScreenSaverReply {
    pub fn timeout(&self) -> u16 {
        unsafe {
            (*self.ptr).timeout
        }
    }
    pub fn interval(&self) -> u16 {
        unsafe {
            (*self.ptr).interval
        }
    }
    pub fn prefer_blanking(&self) -> u8 {
        unsafe {
            (*self.ptr).prefer_blanking
        }
    }
    pub fn allow_exposures(&self) -> u8 {
        unsafe {
            (*self.ptr).allow_exposures
        }
    }
}
pub fn get_screen_saver<'a>(c: &'a base::Connection)
        -> GetScreenSaverCookie<'a> {
    unsafe {
        let cookie = xcb_get_screen_saver(c.get_raw_conn());
        GetScreenSaverCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub fn get_screen_saver_unchecked<'a>(c: &'a base::Connection)
        -> GetScreenSaverCookie<'a> {
    unsafe {
        let cookie = xcb_get_screen_saver_unchecked(c.get_raw_conn());
        GetScreenSaverCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub const CHANGE_HOSTS: u8 = 109;
pub fn change_hosts<'a>(c      : &'a base::Connection,
                        mode   : u8,
                        family : u8,
                        address: &[u8])
        -> base::VoidCookie<'a> {
    unsafe {
        let address_len = address.len();
        let address_ptr = address.as_ptr();
        let cookie = xcb_change_hosts(c.get_raw_conn(),
                                      mode as u8,  
                                      family as u8,  
                                      address_len as u16,  
                                      address_ptr as *const u8);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn change_hosts_checked<'a>(c      : &'a base::Connection,
                                mode   : u8,
                                family : u8,
                                address: &[u8])
        -> base::VoidCookie<'a> {
    unsafe {
        let address_len = address.len();
        let address_ptr = address.as_ptr();
        let cookie = xcb_change_hosts_checked(c.get_raw_conn(),
                                              mode as u8,  
                                              family as u8,  
                                              address_len as u16,  
                                              address_ptr as *const u8);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub type Host<'a> = base::StructPtr<'a, xcb_host_t>;
impl<'a> Host<'a> {
    pub fn family(&self) -> u8 {
        unsafe {
            (*self.ptr).family
        }
    }
    pub fn address_len(&self) -> u16 {
        unsafe {
            (*self.ptr).address_len
        }
    }
    pub fn address(&self) -> &[u8] {
        unsafe {
            let field = self.ptr;
            let len = xcb_host_address_length(field) as usize;
            let data = xcb_host_address(field);
            std::slice::from_raw_parts(data, len)
        }
    }
}
pub type HostIterator<'a> = xcb_host_iterator_t<'a>;
impl<'a> Iterator for HostIterator<'a> {
    type Item = Host<'a>;
    fn next(&mut self) -> std::option::Option<Host<'a>> {
        if self.rem == 0 { None }
        else {
            unsafe {
                let iter = self as *mut xcb_host_iterator_t;
                let data = (*iter).data;
                xcb_host_next(iter);
                Some(std::mem::transmute(data))
            }
        }
    }
}
pub const LIST_HOSTS: u8 = 110;
pub type ListHostsCookie<'a> = base::Cookie<'a, xcb_list_hosts_cookie_t>;
impl<'a> ListHostsCookie<'a> {
    pub fn get_reply(&self) -> Result<ListHostsReply, base::GenericError> {
        unsafe {
            if self.checked {
                let mut err: *mut xcb_generic_error_t = std::ptr::null_mut();
                let reply = ListHostsReply {
                    ptr: xcb_list_hosts_reply (self.conn.get_raw_conn(), self.cookie, &mut err)
                };
                if err.is_null() { Ok (reply) }
                else { Err(base::GenericError { ptr: err }) }
            } else {
                Ok( ListHostsReply {
                    ptr: xcb_list_hosts_reply (self.conn.get_raw_conn(), self.cookie,
                            std::ptr::null_mut())
                })
            }
        }
    }
}
pub type ListHostsReply = base::Reply<xcb_list_hosts_reply_t>;
impl ListHostsReply {
    pub fn mode(&self) -> u8 {
        unsafe {
            (*self.ptr).mode
        }
    }
    pub fn hosts_len(&self) -> u16 {
        unsafe {
            (*self.ptr).hosts_len
        }
    }
    pub fn hosts(&self) -> HostIterator {
        unsafe {
            xcb_list_hosts_hosts_iterator(self.ptr)
        }
    }
}
pub fn list_hosts<'a>(c: &'a base::Connection)
        -> ListHostsCookie<'a> {
    unsafe {
        let cookie = xcb_list_hosts(c.get_raw_conn());
        ListHostsCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub fn list_hosts_unchecked<'a>(c: &'a base::Connection)
        -> ListHostsCookie<'a> {
    unsafe {
        let cookie = xcb_list_hosts_unchecked(c.get_raw_conn());
        ListHostsCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub const SET_ACCESS_CONTROL: u8 = 111;
pub fn set_access_control<'a>(c   : &'a base::Connection,
                              mode: u8)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_set_access_control(c.get_raw_conn(),
                                            mode as u8);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn set_access_control_checked<'a>(c   : &'a base::Connection,
                                      mode: u8)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_set_access_control_checked(c.get_raw_conn(),
                                                    mode as u8);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const SET_CLOSE_DOWN_MODE: u8 = 112;
pub fn set_close_down_mode<'a>(c   : &'a base::Connection,
                               mode: u8)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_set_close_down_mode(c.get_raw_conn(),
                                             mode as u8);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn set_close_down_mode_checked<'a>(c   : &'a base::Connection,
                                       mode: u8)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_set_close_down_mode_checked(c.get_raw_conn(),
                                                     mode as u8);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const KILL_CLIENT: u8 = 113;
pub fn kill_client<'a>(c       : &'a base::Connection,
                       resource: u32)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_kill_client(c.get_raw_conn(),
                                     resource as u32);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn kill_client_checked<'a>(c       : &'a base::Connection,
                               resource: u32)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_kill_client_checked(c.get_raw_conn(),
                                             resource as u32);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const ROTATE_PROPERTIES: u8 = 114;
pub fn rotate_properties<'a>(c     : &'a base::Connection,
                             window: Window,
                             delta : i16,
                             atoms : &[Atom])
        -> base::VoidCookie<'a> {
    unsafe {
        let atoms_len = atoms.len();
        let atoms_ptr = atoms.as_ptr();
        let cookie = xcb_rotate_properties(c.get_raw_conn(),
                                           window as xcb_window_t,  
                                           atoms_len as u16,  
                                           delta as i16,  
                                           atoms_ptr as *const xcb_atom_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn rotate_properties_checked<'a>(c     : &'a base::Connection,
                                     window: Window,
                                     delta : i16,
                                     atoms : &[Atom])
        -> base::VoidCookie<'a> {
    unsafe {
        let atoms_len = atoms.len();
        let atoms_ptr = atoms.as_ptr();
        let cookie = xcb_rotate_properties_checked(c.get_raw_conn(),
                                                   window as xcb_window_t,  
                                                   atoms_len as u16,  
                                                   delta as i16,  
                                                   atoms_ptr as *const xcb_atom_t);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const FORCE_SCREEN_SAVER: u8 = 115;
pub fn force_screen_saver<'a>(c   : &'a base::Connection,
                              mode: u8)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_force_screen_saver(c.get_raw_conn(),
                                            mode as u8);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn force_screen_saver_checked<'a>(c   : &'a base::Connection,
                                      mode: u8)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_force_screen_saver_checked(c.get_raw_conn(),
                                                    mode as u8);  
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub const SET_POINTER_MAPPING: u8 = 116;
pub type SetPointerMappingCookie<'a> = base::Cookie<'a, xcb_set_pointer_mapping_cookie_t>;
impl<'a> SetPointerMappingCookie<'a> {
    pub fn get_reply(&self) -> Result<SetPointerMappingReply, base::GenericError> {
        unsafe {
            if self.checked {
                let mut err: *mut xcb_generic_error_t = std::ptr::null_mut();
                let reply = SetPointerMappingReply {
                    ptr: xcb_set_pointer_mapping_reply (self.conn.get_raw_conn(), self.cookie, &mut err)
                };
                if err.is_null() { Ok (reply) }
                else { Err(base::GenericError { ptr: err }) }
            } else {
                Ok( SetPointerMappingReply {
                    ptr: xcb_set_pointer_mapping_reply (self.conn.get_raw_conn(), self.cookie,
                            std::ptr::null_mut())
                })
            }
        }
    }
}
pub type SetPointerMappingReply = base::Reply<xcb_set_pointer_mapping_reply_t>;
impl SetPointerMappingReply {
    pub fn status(&self) -> u8 {
        unsafe {
            (*self.ptr).status
        }
    }
}
pub fn set_pointer_mapping<'a>(c  : &'a base::Connection,
                               map: &[u8])
        -> SetPointerMappingCookie<'a> {
    unsafe {
        let map_len = map.len();
        let map_ptr = map.as_ptr();
        let cookie = xcb_set_pointer_mapping(c.get_raw_conn(),
                                             map_len as u8,  
                                             map_ptr as *const u8);  
        SetPointerMappingCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub fn set_pointer_mapping_unchecked<'a>(c  : &'a base::Connection,
                                         map: &[u8])
        -> SetPointerMappingCookie<'a> {
    unsafe {
        let map_len = map.len();
        let map_ptr = map.as_ptr();
        let cookie = xcb_set_pointer_mapping_unchecked(c.get_raw_conn(),
                                                       map_len as u8,  
                                                       map_ptr as *const u8);  
        SetPointerMappingCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub const GET_POINTER_MAPPING: u8 = 117;
pub type GetPointerMappingCookie<'a> = base::Cookie<'a, xcb_get_pointer_mapping_cookie_t>;
impl<'a> GetPointerMappingCookie<'a> {
    pub fn get_reply(&self) -> Result<GetPointerMappingReply, base::GenericError> {
        unsafe {
            if self.checked {
                let mut err: *mut xcb_generic_error_t = std::ptr::null_mut();
                let reply = GetPointerMappingReply {
                    ptr: xcb_get_pointer_mapping_reply (self.conn.get_raw_conn(), self.cookie, &mut err)
                };
                if err.is_null() { Ok (reply) }
                else { Err(base::GenericError { ptr: err }) }
            } else {
                Ok( GetPointerMappingReply {
                    ptr: xcb_get_pointer_mapping_reply (self.conn.get_raw_conn(), self.cookie,
                            std::ptr::null_mut())
                })
            }
        }
    }
}
pub type GetPointerMappingReply = base::Reply<xcb_get_pointer_mapping_reply_t>;
impl GetPointerMappingReply {
    pub fn map_len(&self) -> u8 {
        unsafe {
            (*self.ptr).map_len
        }
    }
    pub fn map(&self) -> &[u8] {
        unsafe {
            let field = self.ptr;
            let len = xcb_get_pointer_mapping_map_length(field) as usize;
            let data = xcb_get_pointer_mapping_map(field);
            std::slice::from_raw_parts(data, len)
        }
    }
}
pub fn get_pointer_mapping<'a>(c: &'a base::Connection)
        -> GetPointerMappingCookie<'a> {
    unsafe {
        let cookie = xcb_get_pointer_mapping(c.get_raw_conn());
        GetPointerMappingCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub fn get_pointer_mapping_unchecked<'a>(c: &'a base::Connection)
        -> GetPointerMappingCookie<'a> {
    unsafe {
        let cookie = xcb_get_pointer_mapping_unchecked(c.get_raw_conn());
        GetPointerMappingCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub const SET_MODIFIER_MAPPING: u8 = 118;
pub type SetModifierMappingCookie<'a> = base::Cookie<'a, xcb_set_modifier_mapping_cookie_t>;
impl<'a> SetModifierMappingCookie<'a> {
    pub fn get_reply(&self) -> Result<SetModifierMappingReply, base::GenericError> {
        unsafe {
            if self.checked {
                let mut err: *mut xcb_generic_error_t = std::ptr::null_mut();
                let reply = SetModifierMappingReply {
                    ptr: xcb_set_modifier_mapping_reply (self.conn.get_raw_conn(), self.cookie, &mut err)
                };
                if err.is_null() { Ok (reply) }
                else { Err(base::GenericError { ptr: err }) }
            } else {
                Ok( SetModifierMappingReply {
                    ptr: xcb_set_modifier_mapping_reply (self.conn.get_raw_conn(), self.cookie,
                            std::ptr::null_mut())
                })
            }
        }
    }
}
pub type SetModifierMappingReply = base::Reply<xcb_set_modifier_mapping_reply_t>;
impl SetModifierMappingReply {
    pub fn status(&self) -> u8 {
        unsafe {
            (*self.ptr).status
        }
    }
}
pub fn set_modifier_mapping<'a>(c       : &'a base::Connection,
                                keycodes: &[Keycode])
        -> SetModifierMappingCookie<'a> {
    unsafe {
        let keycodes_len = keycodes.len();
        let keycodes_ptr = keycodes.as_ptr();
        let cookie = xcb_set_modifier_mapping(c.get_raw_conn(),
                                              keycodes_len as u8,  
                                              keycodes_ptr as *const xcb_keycode_t);  
        SetModifierMappingCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub fn set_modifier_mapping_unchecked<'a>(c       : &'a base::Connection,
                                          keycodes: &[Keycode])
        -> SetModifierMappingCookie<'a> {
    unsafe {
        let keycodes_len = keycodes.len();
        let keycodes_ptr = keycodes.as_ptr();
        let cookie = xcb_set_modifier_mapping_unchecked(c.get_raw_conn(),
                                                        keycodes_len as u8,  
                                                        keycodes_ptr as *const xcb_keycode_t);  
        SetModifierMappingCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub const GET_MODIFIER_MAPPING: u8 = 119;
pub type GetModifierMappingCookie<'a> = base::Cookie<'a, xcb_get_modifier_mapping_cookie_t>;
impl<'a> GetModifierMappingCookie<'a> {
    pub fn get_reply(&self) -> Result<GetModifierMappingReply, base::GenericError> {
        unsafe {
            if self.checked {
                let mut err: *mut xcb_generic_error_t = std::ptr::null_mut();
                let reply = GetModifierMappingReply {
                    ptr: xcb_get_modifier_mapping_reply (self.conn.get_raw_conn(), self.cookie, &mut err)
                };
                if err.is_null() { Ok (reply) }
                else { Err(base::GenericError { ptr: err }) }
            } else {
                Ok( GetModifierMappingReply {
                    ptr: xcb_get_modifier_mapping_reply (self.conn.get_raw_conn(), self.cookie,
                            std::ptr::null_mut())
                })
            }
        }
    }
}
pub type GetModifierMappingReply = base::Reply<xcb_get_modifier_mapping_reply_t>;
impl GetModifierMappingReply {
    pub fn keycodes_per_modifier(&self) -> u8 {
        unsafe {
            (*self.ptr).keycodes_per_modifier
        }
    }
    pub fn keycodes(&self) -> &[Keycode] {
        unsafe {
            let field = self.ptr;
            let len = xcb_get_modifier_mapping_keycodes_length(field) as usize;
            let data = xcb_get_modifier_mapping_keycodes(field);
            std::slice::from_raw_parts(data, len)
        }
    }
}
pub fn get_modifier_mapping<'a>(c: &'a base::Connection)
        -> GetModifierMappingCookie<'a> {
    unsafe {
        let cookie = xcb_get_modifier_mapping(c.get_raw_conn());
        GetModifierMappingCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}
pub fn get_modifier_mapping_unchecked<'a>(c: &'a base::Connection)
        -> GetModifierMappingCookie<'a> {
    unsafe {
        let cookie = xcb_get_modifier_mapping_unchecked(c.get_raw_conn());
        GetModifierMappingCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub const NO_OPERATION: u8 = 127;
pub fn no_operation<'a>(c: &'a base::Connection)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_no_operation(c.get_raw_conn());
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: false
        }
    }
}
pub fn no_operation_checked<'a>(c: &'a base::Connection)
        -> base::VoidCookie<'a> {
    unsafe {
        let cookie = xcb_no_operation_checked(c.get_raw_conn());
        base::VoidCookie {
            cookie:  cookie,
            conn:    c,
            checked: true
        }
    }
}