Change the behavior of the option merging.

1. Later matches in .conf files take precedence.
2. All .conf matches override NewInputDeviceRequest options

diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c
index e0c7830..736bf89 100644
--- a/hw/xfree86/common/xf86Xinput.c
+++ b/hw/xfree86/common/xf86Xinput.c
@@ -516,15 +516,16 @@ InputClassMatches(XF86ConfInputClassPtr iclass, InputAttributes *attrs)
 }
 
 /*
- * Merge in any InputClass configurations. Each InputClass section can
- * add to the original device configuration as well as any previous
- * InputClass sections.
+ * Merge in any InputClass configurations. Each matching InputClass section
+ * can override settings from an earlier section. All InputClass section
+ * settings take precedence to the current IDevPtr settings.
  */
 static int
 MergeInputClasses(IDevPtr idev, InputAttributes *attrs)
 {
     XF86ConfInputClassPtr cl;
-    XF86OptionPtr classopts;
+    char *classdriver = NULL;
+    XF86OptionPtr classopts, mergedopts = NULL;
 
     for (cl = xf86configptr->conf_inputclass_lst; cl; cl = cl->list.next) {
         if (!InputClassMatches(cl, attrs))
@@ -532,22 +533,23 @@ MergeInputClasses(IDevPtr idev, InputAttributes *attrs)
 
         xf86Msg(X_CONFIG, "%s: Applying InputClass \"%s\"\n",
                 idev->identifier, cl->identifier);
-        if (cl->driver && !idev->driver) {
-            idev->driver = xstrdup(cl->driver);
-            if (!idev->driver) {
-                xf86Msg(X_ERROR, "Could not allocate memory while merging "
-                        "InputClass configuration");
-                return BadAlloc;
-            }
-        }
-
+        if (cl->driver)
+            classdriver = cl->driver;
         classopts = xf86optionListDup(cl->option_lst);
-        if (idev->commonOptions)
-            idev->commonOptions = xf86optionListMerge(classopts,
-                                                      idev->commonOptions);
-        else
-            idev->commonOptions = classopts;
+        mergedopts = xf86optionListMerge(mergedopts, classopts);
+    }
+
+    /* Apply options to device with InputClass settings preferred. */
+    if (classdriver) {
+        xfree(idev->driver);
+        idev->driver = xstrdup(classdriver);
+        if (!idev->driver) {
+            xf86Msg(X_ERROR, "Could not allocate memory while merging "
+                    "InputClass configuration");
+            return BadAlloc;
+        }
     }
+    idev->commonOptions = xf86optionListMerge(idev->commonOptions, mergedopts);
 
     return Success;
 }
