diff options
author | Martin Pitt <martin.pitt@canonical.com> | 2010-01-12 15:31:23 -0500 |
---|---|---|
committer | Ray Strode <rstrode@redhat.com> | 2010-01-12 15:31:23 -0500 |
commit | 978596dcd5cbca22f6dc94669219b23f1626cf4f (patch) | |
tree | 70b3d46eb24a85b052b534a0f27bcaa5c4e133f5 /daemon | |
parent | a998fc72ac782353fa2378c51221d369ac2686d4 (diff) | |
download | gdm-978596dcd5cbca22f6dc94669219b23f1626cf4f.tar.gz |
Detect default layout with xklavier
Try to read the default layout by connecting to the X server.
https://bugzilla.gnome.org/show_bug.cgi?id=572765
Diffstat (limited to 'daemon')
-rw-r--r-- | daemon/Makefile.am | 3 | ||||
-rw-r--r-- | daemon/gdm-session-direct.c | 39 |
2 files changed, 39 insertions, 3 deletions
diff --git a/daemon/Makefile.am b/daemon/Makefile.am index ab10dc5f..5e04d41e 100644 --- a/daemon/Makefile.am +++ b/daemon/Makefile.am @@ -106,6 +106,7 @@ test_session_LDADD = \ $(EXTRA_DAEMON_LIBS) \ $(DAEMON_LIBS) \ $(PAM_LIBS) \ + $(LIBXKLAVIER_LIBS) \ $(NULL) libexec_PROGRAMS = \ @@ -152,6 +153,7 @@ gdm_simple_slave_LDADD = \ $(XLIB_LIBS) \ $(DAEMON_LIBS) \ $(EXTRA_DAEMON_LIBS) \ + $(LIBXKLAVIER_LIBS) \ $(NULL) gdm_factory_slave_SOURCES = \ @@ -215,6 +217,7 @@ gdm_product_slave_LDADD = \ $(XLIB_LIBS) \ $(DAEMON_LIBS) \ $(EXTRA_DAEMON_LIBS) \ + $(LIBXKLAVIER_LIBS) \ $(NULL) gdm_xdmcp_chooser_slave_SOURCES = \ diff --git a/daemon/gdm-session-direct.c b/daemon/gdm-session-direct.c index 2d711b16..011a919b 100644 --- a/daemon/gdm-session-direct.c +++ b/daemon/gdm-session-direct.c @@ -42,6 +42,9 @@ #include <glib/gstdio.h> #include <glib-object.h> +#include <libxklavier/xklavier.h> +#include <X11/Xlib.h> /* for Display */ + #include <dbus/dbus-glib.h> #include <dbus/dbus-glib-lowlevel.h> @@ -595,14 +598,44 @@ get_default_language_name (GdmSessionDirect *session) return setlocale (LC_MESSAGES, NULL); } +static char * +get_system_default_layout (GdmSessionDirect *session) +{ + char *result; + Display *display; + + result = NULL; + display = XOpenDisplay (session->priv->display_name); + if (display) { + XklConfigRec *config; + XklEngine *engine = xkl_engine_get_instance (display); + if (engine) + { + XklConfigRec *config = xkl_config_rec_new (); + if (xkl_config_rec_get_from_server (config, engine) && config->layouts && config->layouts[0]) { + if (config->variants && config->variants[0] && config->variants[0][0]) + result = g_strdup_printf("%s\t%s", config->layouts[0], config->variants[0]); + else + result = g_strdup (config->layouts[0]); + } + g_object_unref (config); + } + XCloseDisplay (display); + } + + if (!result) + result = g_strdup ("us"); + return result; +} + static const char * get_default_layout_name (GdmSessionDirect *session) { - if (session->priv->saved_layout != NULL) { - return session->priv->saved_layout; + if (!session->priv->saved_layout) { + session->priv->saved_layout = get_system_default_layout (session); } - return "us"; + return session->priv->saved_layout; } static char * |