f83aea
--- libxklavier-2.1.0.2006.02.23/libxklavier/xklavier_config_xkb.c.trap-x-error	2006-03-09 15:10:56.000000000 -0500
f83aea
+++ libxklavier-2.1.0.2006.02.23/libxklavier/xklavier_config_xkb.c	2006-03-09 15:35:13.000000000 -0500
f83aea
@@ -158,6 +158,20 @@ void _XklXkbConfigCleanupNative( XkbComp
f83aea
   free(componentNamesPtr->symbols);
f83aea
   free(componentNamesPtr->geometry);
f83aea
 }
f83aea
+static int (* _XklTrapBeforeXkbWriteToServer) (Display *, XErrorEvent *);
f83aea
+
f83aea
+static int _XklXkbWriteToServerTrap (Display     *dpy, 
f83aea
+                                     XErrorEvent *error_event)
f83aea
+{
f83aea
+  if (error_event->error_code != 0 &&
f83aea
+      error_event->error_code != BadValue &&
f83aea
+      _XklTrapBeforeXkbWriteToServer != NULL)
f83aea
+    {
f83aea
+      return _XklTrapBeforeXkbWriteToServer (dpy, error_event);
f83aea
+    }
f83aea
+
f83aea
+  return 0;
f83aea
+}
f83aea
 
f83aea
 static XkbDescPtr _XklConfigGetKeyboard( XkbComponentNamesPtr componentNamesPtr, Bool activate )
f83aea
 {
f83aea
@@ -243,8 +257,17 @@ static XkbDescPtr _XklConfigGetKeyboard(
f83aea
                 XklDebug( 150, "Loaded legal keymap\n" );
f83aea
                 if( activate )
f83aea
                 {
f83aea
+                  Bool config_was_written = False;
f83aea
+
f83aea
                   XklDebug( 150, "Activating it...\n" );
f83aea
-                  if( XkbWriteToServer(&result) )
f83aea
+
f83aea
+                  _XklTrapBeforeXkbWriteToServer = XSetErrorHandler (_XklXkbWriteToServerTrap);
f83aea
+
f83aea
+                  config_was_written = XkbWriteToServer (&result);
f83aea
+
f83aea
+                  XSetErrorHandler (_XklTrapBeforeXkbWriteToServer);
f83aea
+
f83aea
+                  if (config_was_written)
f83aea
                   {
f83aea
                      XklDebug( 150, "Updating the keyboard...\n" );
f83aea
                      xkb = result.xkb;