from xlib import Display

type
  XkbRF_VarDefsRec* {.bycopy.} = object
    model*: cstring
    layout*: cstring
    variant*: cstring
    options*: cstring
    sz_extra*: cushort
    num_extra*: cushort
    extra_names*: cstring
    extra_values*: cstringArray

  XkbRF_VarDefsPtr* = ptr XkbRF_VarDefsRec
  XkbRF_VarDescRec* {.bycopy.} = object
    name*: cstring
    desc*: cstring

  XkbRF_VarDescPtr* = ptr XkbRF_VarDescRec
  XkbRF_DescribeVarsRec* {.bycopy.} = object
    sz_desc*: cint
    num_desc*: cint
    desc*: XkbRF_VarDescPtr

  XkbRF_DescribeVarsPtr* = ptr XkbRF_DescribeVarsRec
  XkbRF_RuleRec* {.bycopy.} = object
    number*: cint
    layout_num*: cint
    variant_num*: cint
    model*: cstring
    layout*: cstring
    variant*: cstring
    option*: cstring           
    keycodes*: cstring
    symbols*: cstring
    types*: cstring
    compat*: cstring
    geometry*: cstring
    keymap*: cstring
    flags*: cuint

  XkbRF_RulePtr* = ptr XkbRF_RuleRec
  XkbRF_GroupRec* {.bycopy.} = object
    number*: cint
    name*: cstring
    words*: cstring

  XkbRF_GroupPtr* = ptr XkbRF_GroupRec

const
  XkbRF_PendingMatch* = 2
  XkbRF_Option* = 4
  XkbRF_Append* = 8
  XkbRF_Normal* = 16
  XkbRF_Invalid* = 32
  XKB_RF_NAMES_PROP_ATOM* = "_XKB_RULES_NAMES"
  XKB_RF_NAMES_PROP_MAXLEN* = 1024

type
  XkbRF_RulesRec* {.bycopy.} = object
    models*: XkbRF_DescribeVarsRec
    layouts*: XkbRF_DescribeVarsRec
    variants*: XkbRF_DescribeVarsRec
    options*: XkbRF_DescribeVarsRec
    sz_extra*: cushort
    num_extra*: cushort
    extra_names*: cstringArray
    extra*: XkbRF_DescribeVarsPtr
    sz_rules*: cushort
    num_rules*: cushort
    rules*: XkbRF_RulePtr
    sz_groups*: cushort
    num_groups*: cushort
    groups*: XkbRF_GroupPtr

  XkbRF_RulesPtr* = ptr XkbRF_RulesRec

proc XkbRF_GetNamesProp*( a1: ptr Display 
                        , a2: cstringArray
                        , a3: XkbRF_VarDefsPtr): bool {.importc, cdecl.}

proc XkbRF_SetNamesProp*( a1: ptr Display
                        , a2: cstring
                        , a3: XkbRF_VarDefsPtr): bool {.importc, cdecl.}

proc XkbRF_AddRule*(a1: XkbRF_RulesPtr): XkbRF_RulePtr {.importc, cdecl.}

proc XkbRF_AddGroup*(rules: XkbRF_RulesPtr): XkbRF_GroupPtr {.importc, cdecl.}

proc XkbRF_LoadRules*( a1: ptr FILE 
                     , a2: XkbRF_RulesPtr): bool {.importc, cdecl.}

proc XkbRF_LoadRulesByName*(a1: cstring; a2: cstring; a3: XkbRF_RulesPtr): bool {.importc, cdecl.}

proc XkbRF_AddVarDesc*(a1: XkbRF_DescribeVarsPtr): XkbRF_VarDescPtr {.importc, cdecl.}

proc XkbRF_AddVarDescCopy*( a1: XkbRF_DescribeVarsPtr
                          , a2: XkbRF_VarDescPtr
                          ): XkbRF_VarDescPtr {.importc, cdecl.}

proc XkbRF_AddVarToDescribe*( a1: XkbRF_RulesPtr
                            , a2: cstring
                            ): XkbRF_DescribeVarsPtr {.importc, cdecl.}

proc XkbRF_LoadDescriptions*(a1: ptr FILE; 
                             a2: XkbRF_RulesPtr
                            ): bool {.importc, cdecl.}
  
proc XkbRF_LoadDescriptionsByName*(a1: cstring; a2: cstring; a3: XkbRF_RulesPtr): bool {.importc, cdecl.}
  
proc XkbRF_Load*(a1: cstring; a2: cstring; a3: bool; 
                a4: bool): XkbRF_RulesPtr {.importc, cdecl.}
  
proc XkbRF_Create*(a1: cint; a2: cint): XkbRF_RulesPtr {.importc, cdecl.}

proc XkbRF_Free*( a1: XkbRF_RulesPtr
                , a2: bool) {.importc, cdecl.}