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