af8f6a7
#
af8f6a7
# Description: Get default keyboard layout from hal
af8f6a7
# Ubuntu: https://bugs.launchpad.net/bugs/395103
af8f6a7
# Fedora: http://cvs.fedoraproject.org/viewvc//devel/gdm/gdm-system-keyboard.patch?view=markup
af8f6a7
#
af8f6a7
diff -Nur -x '*.orig' -x '*~' gdm-2.28.0/configure.ac gdm-2.28.0.new/configure.ac
af8f6a7
--- gdm-2.28.0/configure.ac	2009-09-21 22:06:40.000000000 +0200
af8f6a7
+++ gdm-2.28.0.new/configure.ac	2009-10-01 12:35:50.345762314 +0200
af8f6a7
@@ -70,6 +70,7 @@
2197279
         dbus-glib-1 >= $DBUS_GLIB_REQUIRED_VERSION
2197279
         gobject-2.0 >= $GLIB_REQUIRED_VERSION
af8f6a7
         gio-2.0 >= $GLIB_REQUIRED_VERSION
af8f6a7
+        hal
2197279
 )
2197279
 AC_SUBST(DAEMON_CFLAGS)
2197279
 AC_SUBST(DAEMON_LIBS)
af8f6a7
diff -Nur -x '*.orig' -x '*~' gdm-2.28.0/daemon/gdm-session-direct.c gdm-2.28.0.new/daemon/gdm-session-direct.c
af8f6a7
--- gdm-2.28.0/daemon/gdm-session-direct.c	2009-09-21 22:05:27.000000000 +0200
af8f6a7
+++ gdm-2.28.0.new/daemon/gdm-session-direct.c	2009-10-01 12:34:43.000000000 +0200
2197279
@@ -45,6 +45,8 @@
2197279
 #include <dbus/dbus-glib.h>
2197279
 #include <dbus/dbus-glib-lowlevel.h>
2197279
 
2197279
+#include <libhal.h>
2197279
+
2197279
 #include "gdm-session-direct.h"
2197279
 #include "gdm-session.h"
2197279
 #include "gdm-session-private.h"
af8f6a7
@@ -598,14 +600,87 @@
82bbd34
     return setlocale (LC_MESSAGES, NULL);
82bbd34
 }
82bbd34
 
82bbd34
+static char *
2197279
+get_system_default_layout (GdmSessionDirect *session)
82bbd34
+{
2197279
+    DBusConnection *connection;
2197279
+    LibHalContext *ctx;
2197279
+    char **devices;
2197279
+    int n_devices;
2197279
+    char *layout;
af8f6a7
+    char *variant;
82bbd34
+    char *result;
82bbd34
+
82bbd34
+    result = NULL;
2197279
+
2197279
+    connection = dbus_g_connection_get_connection (session->priv->connection);
2197279
+    ctx = libhal_ctx_new ();
2197279
+    libhal_ctx_set_dbus_connection (ctx, connection);
2197279
+
2197279
+    if (!libhal_ctx_init (ctx, NULL)) {
2197279
+        goto out;
82bbd34
+    }
82bbd34
+
2197279
+    devices = libhal_find_device_by_capability (ctx,
2197279
+                                                "input.keyboard",
2197279
+                                                &n_devices,
2197279
+                                                NULL);
2197279
+    if (n_devices > 0) {
2197279
+        layout = libhal_device_get_property_string (ctx,
2197279
+                                                    devices[0],
fc5e13e
+                                                    "input.x11_options.XkbLayout",
2197279
+                                                    NULL);
fc5e13e
+        if (!layout) {
fc5e13e
+            layout = libhal_device_get_property_string (ctx,
fc5e13e
+                                                        devices[0],
fc5e13e
+                                                        "input.xkb.layout",
fc5e13e
+                                                        NULL);
fc5e13e
+        }
af8f6a7
+	if (!layout)
af8f6a7
+	    goto out;
af8f6a7
+
af8f6a7
+        variant = libhal_device_get_property_string (ctx,
af8f6a7
+                                                    devices[0],
af8f6a7
+                                                    "input.x11_options.XkbVariant",
af8f6a7
+                                                    NULL);
af8f6a7
+        if (!variant) {
af8f6a7
+            variant = libhal_device_get_property_string (ctx,
af8f6a7
+                                                        devices[0],
af8f6a7
+                                                        "input.xkb.variant",
af8f6a7
+                                                        NULL);
af8f6a7
+        }
af8f6a7
+
1aa2a61
+	if (variant != NULL && variant[0] != '\0') {
af8f6a7
+	    result = g_strdup_printf("%s\t%s", layout, variant);
af8f6a7
+	    libhal_free_string (variant);
af8f6a7
+	} else {
af8f6a7
+	    result = g_strdup (layout);
af8f6a7
+	}
af8f6a7
+	libhal_free_string (layout);
2197279
+    }
2197279
+
2197279
+    libhal_free_string_array (devices);
2197279
+
2197279
+    libhal_ctx_shutdown (ctx, NULL);
2197279
+    libhal_ctx_free (ctx);
2197279
+
2197279
+out:
82bbd34
+    if (!result) {
82bbd34
+        result = g_strdup ("us");
82bbd34
+    }
82bbd34
+
af8f6a7
+    g_debug ("GdmSessionDirect: System default keyboard layout: '%s'", result);
82bbd34
+    return result;
82bbd34
+}
82bbd34
+
82bbd34
 static const char *
82bbd34
 get_default_layout_name (GdmSessionDirect *session)
82bbd34
 {
82bbd34
-    if (session->priv->saved_layout != NULL) {
82bbd34
-                return session->priv->saved_layout;
af8f6a7
+    if (!session->priv->saved_layout) {
2197279
+        session->priv->saved_layout = get_system_default_layout (session);
82bbd34
     }
82bbd34
 
82bbd34
-    return "us";
82bbd34
+    return session->priv->saved_layout;
82bbd34
 }
82bbd34
 
82bbd34
 static char *