[134] | 1 | # |
---|
| 2 | # Description: Get default keyboard layout from hal |
---|
| 3 | # Ubuntu: https://bugs.launchpad.net/bugs/395103 |
---|
| 4 | # Fedora: http://cvs.fedoraproject.org/viewvc//devel/gdm/gdm-system-keyboard.patch?view=markup |
---|
| 5 | # |
---|
| 6 | diff -Nur -x '*.orig' -x '*~' gdm-2.28.0/configure.ac gdm-2.28.0.new/configure.ac |
---|
| 7 | --- gdm-2.28.0/configure.ac 2009-09-21 22:06:40.000000000 +0200 |
---|
| 8 | +++ gdm-2.28.0.new/configure.ac 2009-10-01 12:35:50.345762314 +0200 |
---|
| 9 | @@ -70,6 +70,7 @@ |
---|
| 10 | dbus-glib-1 >= $DBUS_GLIB_REQUIRED_VERSION |
---|
| 11 | gobject-2.0 >= $GLIB_REQUIRED_VERSION |
---|
| 12 | gio-2.0 >= $GLIB_REQUIRED_VERSION |
---|
| 13 | + hal |
---|
| 14 | ) |
---|
| 15 | AC_SUBST(DAEMON_CFLAGS) |
---|
| 16 | AC_SUBST(DAEMON_LIBS) |
---|
| 17 | diff -Nur -x '*.orig' -x '*~' gdm-2.28.0/daemon/gdm-session-direct.c gdm-2.28.0.new/daemon/gdm-session-direct.c |
---|
| 18 | --- gdm-2.28.0/daemon/gdm-session-direct.c 2009-09-21 22:05:27.000000000 +0200 |
---|
| 19 | +++ gdm-2.28.0.new/daemon/gdm-session-direct.c 2009-10-01 12:34:43.000000000 +0200 |
---|
| 20 | @@ -45,6 +45,8 @@ |
---|
| 21 | #include <dbus/dbus-glib.h> |
---|
| 22 | #include <dbus/dbus-glib-lowlevel.h> |
---|
| 23 | |
---|
| 24 | +#include <libhal.h> |
---|
| 25 | + |
---|
| 26 | #include "gdm-session-direct.h" |
---|
| 27 | #include "gdm-session.h" |
---|
| 28 | #include "gdm-session-private.h" |
---|
| 29 | @@ -598,14 +600,87 @@ |
---|
| 30 | return setlocale (LC_MESSAGES, NULL); |
---|
| 31 | } |
---|
| 32 | |
---|
| 33 | +static char * |
---|
| 34 | +get_system_default_layout (GdmSessionDirect *session) |
---|
| 35 | +{ |
---|
| 36 | + DBusConnection *connection; |
---|
| 37 | + LibHalContext *ctx; |
---|
| 38 | + char **devices; |
---|
| 39 | + int n_devices; |
---|
| 40 | + char *layout; |
---|
| 41 | + char *variant; |
---|
| 42 | + char *result; |
---|
| 43 | + |
---|
| 44 | + result = NULL; |
---|
| 45 | + |
---|
| 46 | + connection = dbus_g_connection_get_connection (session->priv->connection); |
---|
| 47 | + ctx = libhal_ctx_new (); |
---|
| 48 | + libhal_ctx_set_dbus_connection (ctx, connection); |
---|
| 49 | + |
---|
| 50 | + if (!libhal_ctx_init (ctx, NULL)) { |
---|
| 51 | + goto out; |
---|
| 52 | + } |
---|
| 53 | + |
---|
| 54 | + devices = libhal_find_device_by_capability (ctx, |
---|
| 55 | + "input.keyboard", |
---|
| 56 | + &n_devices, |
---|
| 57 | + NULL); |
---|
| 58 | + if (n_devices > 0) { |
---|
| 59 | + layout = libhal_device_get_property_string (ctx, |
---|
| 60 | + devices[0], |
---|
| 61 | + "input.x11_options.XkbLayout", |
---|
| 62 | + NULL); |
---|
| 63 | + if (!layout) { |
---|
| 64 | + layout = libhal_device_get_property_string (ctx, |
---|
| 65 | + devices[0], |
---|
| 66 | + "input.xkb.layout", |
---|
| 67 | + NULL); |
---|
| 68 | + } |
---|
| 69 | + if (!layout) |
---|
| 70 | + goto out; |
---|
| 71 | + |
---|
| 72 | + variant = libhal_device_get_property_string (ctx, |
---|
| 73 | + devices[0], |
---|
| 74 | + "input.x11_options.XkbVariant", |
---|
| 75 | + NULL); |
---|
| 76 | + if (!variant) { |
---|
| 77 | + variant = libhal_device_get_property_string (ctx, |
---|
| 78 | + devices[0], |
---|
| 79 | + "input.xkb.variant", |
---|
| 80 | + NULL); |
---|
| 81 | + } |
---|
| 82 | + |
---|
| 83 | + if (variant) { |
---|
| 84 | + result = g_strdup_printf("%s\t%s", layout, variant); |
---|
| 85 | + libhal_free_string (variant); |
---|
| 86 | + } else { |
---|
| 87 | + result = g_strdup (layout); |
---|
| 88 | + } |
---|
| 89 | + libhal_free_string (layout); |
---|
| 90 | + } |
---|
| 91 | + |
---|
| 92 | + libhal_free_string_array (devices); |
---|
| 93 | + |
---|
| 94 | + libhal_ctx_shutdown (ctx, NULL); |
---|
| 95 | + libhal_ctx_free (ctx); |
---|
| 96 | + |
---|
| 97 | +out: |
---|
| 98 | + if (!result) { |
---|
| 99 | + result = g_strdup ("us"); |
---|
| 100 | + } |
---|
| 101 | + |
---|
| 102 | + g_debug ("GdmSessionDirect: System default keyboard layout: '%s'", result); |
---|
| 103 | + return result; |
---|
| 104 | +} |
---|
| 105 | + |
---|
| 106 | static const char * |
---|
| 107 | get_default_layout_name (GdmSessionDirect *session) |
---|
| 108 | { |
---|
| 109 | - if (session->priv->saved_layout != NULL) { |
---|
| 110 | - return session->priv->saved_layout; |
---|
| 111 | + if (!session->priv->saved_layout) { |
---|
| 112 | + session->priv->saved_layout = get_system_default_layout (session); |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | - return "us"; |
---|
| 116 | + return session->priv->saved_layout; |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | static char * |
---|