Alan Pevec f7f9ca
(*
Alan Pevec f7f9ca
Module: Xorg
Alan Pevec f7f9ca
 Parses /etc/X11/xorg.conf
Alan Pevec f7f9ca
Alan Pevec f7f9ca
Authors: Raphael Pinson <raphink@gmail.com>
Alan Pevec f7f9ca
         Matthew Booth <mbooth@redhat.com>
Alan Pevec f7f9ca
Alan Pevec f7f9ca
About: Reference
Alan Pevec f7f9ca
 This lens tries to keep as close as possible to `man xorg.conf` where
Alan Pevec f7f9ca
 possible.
Alan Pevec f7f9ca
Alan Pevec f7f9ca
The definitions from `man xorg.conf` are put as commentaries for reference
Alan Pevec f7f9ca
throughout the file. More information can be found in the manual.
Alan Pevec f7f9ca
Alan Pevec f7f9ca
About: License
Alan Pevec f7f9ca
  This file is licensed under the GPL.
Alan Pevec f7f9ca
Alan Pevec f7f9ca
About: Lens Usage
Alan Pevec f7f9ca
  Sample usage of this lens in augtool
Alan Pevec f7f9ca
Alan Pevec f7f9ca
    * Get the identifier of the devices with a "Clone" option:
Alan Pevec f7f9ca
      > match "/files/etc/X11/xorg.conf/Device[Option = 'Clone']/Identifier"
Alan Pevec f7f9ca
Alan Pevec f7f9ca
About: Configuration files
Alan Pevec f7f9ca
  This lens applies to /etc/X11/xorg.conf. See <filter>.
Alan Pevec f7f9ca
*)
Alan Pevec f7f9ca
Alan Pevec f7f9ca
module Xorg =
Alan Pevec f7f9ca
  autoload xfm
Alan Pevec f7f9ca
Alan Pevec f7f9ca
(************************************************************************
Alan Pevec f7f9ca
 * Group:                 USEFUL PRIMITIVES
Alan Pevec f7f9ca
 *************************************************************************)
Alan Pevec f7f9ca
Alan Pevec f7f9ca
(* Group: Generic primitives *)
Alan Pevec f7f9ca
Alan Pevec f7f9ca
(* Variable: eol *)
Alan Pevec f7f9ca
let eol     = Util.eol
Alan Pevec f7f9ca
Alan Pevec f7f9ca
(* Variable: to_eol
Alan Pevec f7f9ca
 * Match everything from here to eol, cropping whitespace at both ends
Alan Pevec f7f9ca
 *)
Alan Pevec f7f9ca
let to_eol  = /[^ \t\n](.*[^ \t\n])?/
Alan Pevec f7f9ca
Alan Pevec f7f9ca
(* Variable: indent *)
Alan Pevec f7f9ca
let indent  = Util.indent
Alan Pevec f7f9ca
Alan Pevec f7f9ca
(* Variable: comment *)
Alan Pevec f7f9ca
let comment = Util.comment
Alan Pevec f7f9ca
Alan Pevec f7f9ca
(* Variable: empty *)
Alan Pevec f7f9ca
let empty   = Util.empty
Alan Pevec f7f9ca
Alan Pevec f7f9ca
Alan Pevec f7f9ca
(* Group: Separators *)
Alan Pevec f7f9ca
Alan Pevec f7f9ca
(* Variable: sep_spc *)
Alan Pevec f7f9ca
let sep_spc = Util.del_ws_spc
Alan Pevec f7f9ca
Alan Pevec f7f9ca
(* Variable: sep_dquote *)
Alan Pevec f7f9ca
let sep_dquote  = Util.del_str "\""
Alan Pevec f7f9ca
Alan Pevec f7f9ca
Alan Pevec f7f9ca
(* Group: Fields and values *)
Alan Pevec f7f9ca
Alan Pevec f7f9ca
(* Variable: entries_re
Alan Pevec f7f9ca
 * This is a list of all patterns which have specific handlers, and should
Alan Pevec f7f9ca
 * therefore not be matched by the generic handler
Alan Pevec f7f9ca
 *)
Alan Pevec f7f9ca
let entries_re  = /([oO]ption|[sS]creen|[iI]nput[dD]evice|[dD]river|[sS]ub[sS]ection|[dD]isplay|[iI]dentifier|[vV]ideo[rR]am|[dD]efault[dD]epth|[dD]evice)/
Alan Pevec f7f9ca
Alan Pevec f7f9ca
(* Variable: generic_entry_re *)
Alan Pevec f7f9ca
let generic_entry_re = /[^# \t\n\/]+/ - entries_re
Alan Pevec f7f9ca
Alan Pevec f7f9ca
(* Variable: quoted_string_val *)
Alan Pevec f7f9ca
let quoted_string_val = del "\"" "\"" . store /[^"\n]+/ . del "\"" "\""
Alan Pevec f7f9ca
                                              (* " relax, emacs *)
Alan Pevec f7f9ca
Alan Pevec f7f9ca
(* Variable: int *)
Alan Pevec f7f9ca
let int = /[0-9]+/
Alan Pevec f7f9ca
Alan Pevec f7f9ca
Alan Pevec f7f9ca
(************************************************************************
Alan Pevec f7f9ca
 * Group:                          ENTRIES AND OPTIONS
Alan Pevec f7f9ca
 *************************************************************************)
Alan Pevec f7f9ca
Alan Pevec f7f9ca
Alan Pevec f7f9ca
(* View: entry_int
Alan Pevec f7f9ca
 * This matches an entry which takes a single integer for an argument
Alan Pevec f7f9ca
 *)
Alan Pevec f7f9ca
let entry_int (canon:string) (re:regexp) =
Alan Pevec f7f9ca
        [ indent . del re canon . label canon . sep_spc . store int . eol ]
Alan Pevec f7f9ca
Alan Pevec f7f9ca
(* View: entry_rgb
Alan Pevec f7f9ca
 * This matches an entry which takes 3 integers as arguments representing red,
Alan Pevec f7f9ca
 * green and blue components
Alan Pevec f7f9ca
 *)
Alan Pevec f7f9ca
let entry_rgb (canon:string) (re:regexp) =
Alan Pevec f7f9ca
        [ indent . del re canon . label canon
Alan Pevec f7f9ca
          . [ label "red"   . sep_spc . store int ]
Alan Pevec f7f9ca
          . [ label "green" . sep_spc . store int ]
Alan Pevec f7f9ca
          . [ label "blue"  . sep_spc . store int ]
Alan Pevec f7f9ca
          . eol ]
Alan Pevec f7f9ca
Alan Pevec f7f9ca
(* View: entry_xy
Alan Pevec f7f9ca
 * This matches an entry which takes 2 integers as arguments representing X and
Alan Pevec f7f9ca
 * Y coordinates
Alan Pevec f7f9ca
 *)
Alan Pevec f7f9ca
let entry_xy (canon:string) (re:regexp) =
Alan Pevec f7f9ca
        [ indent . del re canon . label canon
Alan Pevec f7f9ca
          . [ label "x" . sep_spc . store int ]
Alan Pevec f7f9ca
          . [ label "y" . sep_spc . store int ]
Alan Pevec f7f9ca
          . eol ]
Alan Pevec f7f9ca
Alan Pevec f7f9ca
(* View: entry_str
Alan Pevec f7f9ca
 * This matches an entry which takes a single quoted string
Alan Pevec f7f9ca
 *)
Alan Pevec f7f9ca
let entry_str (canon:string) (re:regexp) =
Alan Pevec f7f9ca
        [ indent . del re canon . label canon
Alan Pevec f7f9ca
          . sep_spc . quoted_string_val . eol ]
Alan Pevec f7f9ca
Alan Pevec f7f9ca
(* View: entry_generic
Alan Pevec f7f9ca
 * An entry without a specific handler. Store everything after the keyword,
Alan Pevec f7f9ca
 * cropping whitespace at both ends.
Alan Pevec f7f9ca
 *)
Alan Pevec f7f9ca
let entry_generic  = [ indent . key generic_entry_re
Alan Pevec f7f9ca
                       . sep_spc . store to_eol . eol ]
Alan Pevec f7f9ca
Alan Pevec f7f9ca
(* View: option *)
Alan Pevec f7f9ca
let option = [ indent . del /[oO]ption/ "Option" . label "Option" . sep_spc
Alan Pevec f7f9ca
               . quoted_string_val
Alan Pevec f7f9ca
               . [ label "value" . sep_spc . quoted_string_val ]*
Alan Pevec f7f9ca
               . eol ]
Alan Pevec f7f9ca
Alan Pevec f7f9ca
(* View: screen
Alan Pevec f7f9ca
 * The Screen entry of ServerLayout
Alan Pevec f7f9ca
 *)
Alan Pevec f7f9ca
let screen = [ indent . del /[sS]creen/ "Screen" . label "Screen" . sep_spc
Alan Pevec f7f9ca
               . [ label "num" . store int . sep_spc ]?
Alan Pevec f7f9ca
               . quoted_string_val . sep_spc
Alan Pevec f7f9ca
               . [ label "position" . store to_eol ]
Alan Pevec f7f9ca
               . eol ]
Alan Pevec f7f9ca
Alan Pevec f7f9ca
(* View: input_device *)
Alan Pevec f7f9ca
let input_device = [ indent . del /[iI]nput[dD]evice/ "InputDevice"
Alan Pevec f7f9ca
                     . label "InputDevice" . sep_spc . quoted_string_val
Alan Pevec f7f9ca
                     . [ label "option" . sep_spc . quoted_string_val ]*
Alan Pevec f7f9ca
                     . eol ]
Alan Pevec f7f9ca
Alan Pevec f7f9ca
(* View: driver *)
Alan Pevec f7f9ca
let driver = entry_str "Driver" /[dD]river/
Alan Pevec f7f9ca
Alan Pevec f7f9ca
(* View: identifier *)
Alan Pevec f7f9ca
let identifier = entry_str "Identifier" /[iI]dentifier/
Alan Pevec f7f9ca
Alan Pevec f7f9ca
(* View: videoram *)
Alan Pevec f7f9ca
let videoram = entry_int "VideoRam" /[vV]ideo[rR]am/
Alan Pevec f7f9ca
Alan Pevec f7f9ca
(* View: default_depth *)
Alan Pevec f7f9ca
let default_depth = entry_int "DefaultDepth" /[dD]efault[dD]epth/
Alan Pevec f7f9ca
Alan Pevec f7f9ca
(* View: device *)
Alan Pevec f7f9ca
let device = entry_str "Device" /[dD]evice/
Alan Pevec f7f9ca
Alan Pevec f7f9ca
(************************************************************************
Alan Pevec f7f9ca
 * Group:                          DISPLAY SUBSECTION
Alan Pevec f7f9ca
 *************************************************************************)
Alan Pevec f7f9ca
Alan Pevec f7f9ca
Alan Pevec f7f9ca
(* View: display_modes *)
Alan Pevec f7f9ca
let display_modes = [ indent . del /[mM]odes/ "Modes" . label "Modes"
Alan Pevec f7f9ca
                      . [ label "mode" . sep_spc . quoted_string_val ]+
Alan Pevec f7f9ca
                      . eol ]
Alan Pevec f7f9ca
Alan Pevec f7f9ca
(*************************************************************************
Alan Pevec f7f9ca
 * View: display_entry
Alan Pevec f7f9ca
 *   Known values for entries in the Display subsection
Alan Pevec f7f9ca
 *
Alan Pevec f7f9ca
 *   Definition:
Alan Pevec f7f9ca
 *     > Depth    depth
Alan Pevec f7f9ca
 *     > FbBpp    bpp
Alan Pevec f7f9ca
 *     > Weight   red-weight green-weight blue-weight
Alan Pevec f7f9ca
 *     > Virtual  xdim ydim
Alan Pevec f7f9ca
 *     > ViewPort x0 y0
Alan Pevec f7f9ca
 *     > Modes    "mode-name" ...
Alan Pevec f7f9ca
 *     > Visual   "visual-name"
Alan Pevec f7f9ca
 *     > Black    red green blue
Alan Pevec f7f9ca
 *     > White    red green blue
Alan Pevec f7f9ca
 *     > Options
Alan Pevec f7f9ca
 *)
Alan Pevec f7f9ca
Alan Pevec f7f9ca
let display_entry = entry_int "Depth"    /[dD]epth/ |
Alan Pevec f7f9ca
                    entry_int "FbBpp"    /[fF]b[bB]pp/ |
Alan Pevec f7f9ca
                    entry_rgb "Weight"   /[wW]eight/ |
Alan Pevec f7f9ca
                    entry_xy  "Virtual"  /[vV]irtual/ |
Alan Pevec f7f9ca
                    entry_xy  "ViewPort" /[vV]iew[pP]ort/ |
Alan Pevec f7f9ca
                    display_modes |
Alan Pevec f7f9ca
                    entry_str "Visual"   /[vV]isual/ |
Alan Pevec f7f9ca
                    entry_rgb "Black"    /[bB]lack/ |
Alan Pevec f7f9ca
                    entry_rgb "White"    /[wW]hite/ |
Alan Pevec f7f9ca
                    entry_str "Options"  /[oO]ptions/ |
Alan Pevec f7f9ca
                    empty |
Alan Pevec f7f9ca
                    comment
Alan Pevec f7f9ca
Alan Pevec f7f9ca
(* View: display *)
Alan Pevec f7f9ca
let display = [ indent . del "SubSection" "SubSection" . sep_spc
Alan Pevec f7f9ca
                       . sep_dquote . key "Display" . sep_dquote
Alan Pevec f7f9ca
                       . eol
Alan Pevec f7f9ca
                       . display_entry*
Alan Pevec f7f9ca
                       . indent . del "EndSubSection" "EndSubSection" . eol ]
Alan Pevec f7f9ca
Alan Pevec f7f9ca
Alan Pevec f7f9ca
(************************************************************************
Alan Pevec f7f9ca
 * Group:                       SECTIONS
Alan Pevec f7f9ca
 *************************************************************************)
Alan Pevec f7f9ca
Alan Pevec f7f9ca
Alan Pevec f7f9ca
(************************************************************************
Alan Pevec f7f9ca
 * Variable: section_re
Alan Pevec f7f9ca
 *   Known values for Section names
Alan Pevec f7f9ca
 *
Alan Pevec f7f9ca
 *   Definition:
Alan Pevec f7f9ca
 *     >   The section names are:
Alan Pevec f7f9ca
 *     >
Alan Pevec f7f9ca
 *     >   Files          File pathnames
Alan Pevec f7f9ca
 *     >   ServerFlags    Server flags
Alan Pevec f7f9ca
 *     >   Module         Dynamic module loading
Alan Pevec f7f9ca
 *     >   InputDevice    Input device description
Alan Pevec f7f9ca
 *     >   Device         Graphics device description
Alan Pevec f7f9ca
 *     >   VideoAdaptor   Xv video adaptor description
Alan Pevec f7f9ca
 *     >   Monitor        Monitor description
Alan Pevec f7f9ca
 *     >   Modes          Video modes descriptions
Alan Pevec f7f9ca
 *     >   Screen         Screen configuration
Alan Pevec f7f9ca
 *     >   ServerLayout   Overall layout
Alan Pevec f7f9ca
 *     >   DRI            DRI-specific configuration
Alan Pevec f7f9ca
 *     >   Vendor         Vendor-specific configuration
Alan Pevec f7f9ca
 *************************************************************************)
Alan Pevec f7f9ca
let section_re = /(Files|ServerFlags|Module|InputDevice|Device|VideoAdaptor|Monitor|Modes|Screen|ServerLayout|DRI|Vendor)/
Alan Pevec f7f9ca
Alan Pevec f7f9ca
Alan Pevec f7f9ca
(************************************************************************
Alan Pevec f7f9ca
 * Variable: secton_re_obsolete
Alan Pevec f7f9ca
 *   The  following obsolete section names are still recognised for
Alan Pevec f7f9ca
 *   compatibility purposes.  In new config files, the InputDevice
Alan Pevec f7f9ca
 *   section should be used instead.
Alan Pevec f7f9ca
 *
Alan Pevec f7f9ca
 *   Definition:
Alan Pevec f7f9ca
 *     >  Keyboard       Keyboard configuration
Alan Pevec f7f9ca
 *     >  Pointer        Pointer/mouse configuration
Alan Pevec f7f9ca
 *************************************************************************)
Alan Pevec f7f9ca
let section_re_obsolete = /(Keyboard|Pointer)/
Alan Pevec f7f9ca
Alan Pevec f7f9ca
(* View: section_entry *)
Alan Pevec f7f9ca
let section_entry = option |
Alan Pevec f7f9ca
                    screen |
Alan Pevec f7f9ca
                    display |
Alan Pevec f7f9ca
                    input_device |
Alan Pevec f7f9ca
                    driver |
Alan Pevec f7f9ca
                    identifier |
Alan Pevec f7f9ca
                    videoram |
Alan Pevec f7f9ca
                    default_depth |
Alan Pevec f7f9ca
                    device |
Alan Pevec f7f9ca
                    entry_generic |
Alan Pevec f7f9ca
                    empty | comment
Alan Pevec f7f9ca
Alan Pevec f7f9ca
(************************************************************************
Alan Pevec f7f9ca
 * View: section
Alan Pevec f7f9ca
 *   A section in xorg.conf
Alan Pevec f7f9ca
 *
Alan Pevec f7f9ca
 *   Definition:
Alan Pevec f7f9ca
 *     > Section  "SectionName"
Alan Pevec f7f9ca
 *     >    SectionEntry
Alan Pevec f7f9ca
 *     >    ...
Alan Pevec f7f9ca
 *     > EndSection
Alan Pevec f7f9ca
 *************************************************************************)
Alan Pevec f7f9ca
let section = [ indent . del "Section" "Section"
Alan Pevec f7f9ca
                       . sep_spc . sep_dquote
Alan Pevec f7f9ca
                       . key (section_re|section_re_obsolete) . sep_dquote
Alan Pevec f7f9ca
                       . eol
Alan Pevec f7f9ca
                .  section_entry*
Alan Pevec f7f9ca
                . indent . del "EndSection" "EndSection" . eol ]
Alan Pevec f7f9ca
Alan Pevec f7f9ca
(*
Alan Pevec f7f9ca
 * View: lns
Alan Pevec f7f9ca
 *   The xorg.conf lens
Alan Pevec f7f9ca
 *)
Alan Pevec f7f9ca
let lns = ( empty | comment | section )*
Alan Pevec f7f9ca
Alan Pevec f7f9ca
Alan Pevec f7f9ca
(* Variable: filter *)
Alan Pevec f7f9ca
let filter = (incl "/etc/X11/xorg.conf")
Alan Pevec f7f9ca
Alan Pevec f7f9ca
let xfm = transform lns filter