aboutsummaryrefslogtreecommitdiff
blob: 5b0ec9c8c88c7f0f784e0ac82f0bfaad7958b07a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# Copyright (c) 2008 Saleem Abdulrasool <compnerd@compnerd.org>

# Very simple script which converts the InputDevice section for keyboards into a
# FDI rule.  Any time a specific model is present, we ignore it and set it to
# evdev, as that will be the driver used.

import sys
import xf86config
from xf86config import XF86SectionMissing

def xkb_model(value):
   model  = '      <!-- Option "XkbModel" "%s" -->' % (value,) + '\n'
   model += '      <merge key="input.xkb.model" type="string">evdev</merge>'

   return model

def xkb_rules(value):
   return '      <merge key="input.xkb.rules" type="string">%s</merge>' % (value,)

def xkb_layout(value):
   return '      <merge key="input.xkb.layout" type="string">%s</merge>' % (value,)

def xkb_options(values):
   options = '      <merge key="input.xkb.options" type="strlist">%s</merge>' % (values.split(',')[0])
   for value in values.split(',')[1:]:
      options += '\n' + '      <append key="input.xkb.options" type="strlist">%s</append>' % (value,)

   return options

def xkb_variant(value):
   return '      <merge key="input.xkb.variant" type="string">%s</merge>' % (value,)

if __name__ == '__main__':
   OptionHandlers = {
                        'XkbModel' : xkb_model,
                        'XkbRules' : xkb_rules,
                        'XkbLayout' : xkb_layout,
                        'XkbOptions' : xkb_options,
                        'XkbVariant' : xkb_variant,
                    }

   (configuration, path) = xf86config.readConfigFile()

   if not configuration:
      sys.stderr.write("Failed to read xorg.conf\n")
      sys.exit(-1)

   try:
      keyboard = xf86config.getCoreKeyboard(configuration)
   except XF86SectionMissing:
      sys.stderr.write("No CoreKeyboard\n")
      sys.exit(-1)

   rule  = '<?xml version="1.0" encoding="utf-8"?>' + '\n'
   rule += '<deviceinfo version="0.2">' + '\n'
   rule += '   <match key="info.capabilities" contains="input.keys">' + '\n'
   for option in keyboard.options:
      if option.name in OptionHandlers:
         rule += OptionHandlers[option.name](option.val) + '\n'
      else:
         sys.stderr.write('Failed to translate: %s %s\n' % (option.name, option.val))
   rule += '   </match>' + '\n'
   rule += '</deviceinfo>' + '\n'

   print rule

# vim: set ts=3 sw=3 et nowrap: