[gdm] Detect default layout with xklavier



commit 978596dcd5cbca22f6dc94669219b23f1626cf4f
Author: Martin Pitt <martin pitt canonical com>
Date:   Tue Jan 12 15:31:23 2010 -0500

    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

 daemon/Makefile.am          |    3 +++
 daemon/gdm-session-direct.c |   39 ++++++++++++++++++++++++++++++++++++---
 2 files changed, 39 insertions(+), 3 deletions(-)
---
diff --git a/daemon/Makefile.am b/daemon/Makefile.am
index ab10dc5..5e04d41 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 2d711b1..011a919 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 *



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]