[libgnomekbd] Trying two xmodmap files: .xmodmap and .Xmodmap



commit 76f99c1fc2a4d5943b44d54fa21dacef324688cf
Author: Sergey V. Udaltsov <svu gnome org>
Date:   Wed Jan 5 22:16:04 2011 +0000

    Trying two xmodmap files: .xmodmap and .Xmodmap
    
    http://bugzilla.gnome.org/show_bug.cgi?id=638732

 libgnomekbd/gkbd-keyboard-config.c |   54 ++++++++++++++++++++++-------------
 1 files changed, 34 insertions(+), 20 deletions(-)
---
diff --git a/libgnomekbd/gkbd-keyboard-config.c b/libgnomekbd/gkbd-keyboard-config.c
index 71c5267..51c6ce4 100644
--- a/libgnomekbd/gkbd-keyboard-config.c
+++ b/libgnomekbd/gkbd-keyboard-config.c
@@ -36,7 +36,7 @@
 
 #define GROUP_SWITCHERS_GROUP "grp"
 #define DEFAULT_GROUP_SWITCH "grp:shift_caps_toggle"
-#define XMODMAP_KNOWN_FILE ".xmodmap"
+
 #define XMODMAP_CMD "xmodmap"
 
 const gchar GKBD_KEYBOARD_CONFIG_KEY_MODEL[] = "model";
@@ -49,6 +49,8 @@ const gchar *GKBD_KEYBOARD_CONFIG_ACTIVE[] = {
 	GKBD_KEYBOARD_CONFIG_KEY_OPTIONS
 };
 
+const gchar *XMODMAP_KNOWN_FILES[] = { ".xmodmap", ".Xmodmap" };
+
 /**
  * static common functions
  */
@@ -567,27 +569,39 @@ gkbd_keyboard_config_activate (GkbdKeyboardConfig * kbd_config)
 
 	/* Small bit of extensibility by using xmodmap */
 	if (rv) {
-		gchar *xmodmap_file = g_build_filename (g_get_home_dir (),
-							XMODMAP_KNOWN_FILE,
-							NULL);
-		if (g_file_test (xmodmap_file, G_FILE_TEST_EXISTS)) {
-			GError *error = NULL;
-			xkl_debug (150, "Loading custom xmodmap file %s\n",
-				   xmodmap_file);
-			gchar *command =
-			    g_strconcat (XMODMAP_CMD, " ", xmodmap_file,
-					 NULL);
-			/* Fire and forget - do not care about errors */
-			if (!g_spawn_command_line_async (command, &error)) {
-				xkl_debug (0,
-					   "Error loading custom xmodmap file: [%s]\n",
-					   error->message);
-				g_error_free (error);
+		int i =
+		    sizeof (XMODMAP_KNOWN_FILES) /
+		    sizeof (XMODMAP_KNOWN_FILES[0]);
+		while (--i >= 0) {
+			gchar *xmodmap_file =
+			    g_build_filename (g_get_home_dir (),
+					      XMODMAP_KNOWN_FILES[i],
+					      NULL);
+			if (g_file_test (xmodmap_file, G_FILE_TEST_EXISTS)) {
+				GError *error = NULL;
+				xkl_debug (150,
+					   "Loading custom xmodmap file %s\n",
+					   xmodmap_file);
+				gchar *command =
+				    g_strconcat (XMODMAP_CMD, " ",
+						 xmodmap_file,
+						 NULL);
+				/* Fire and forget - do not care about errors */
+				if (!g_spawn_command_line_async
+				    (command, &error)) {
+					xkl_debug (0,
+						   "Error loading custom xmodmap file: [%s]\n",
+						   error->message);
+					g_error_free (error);
+				}
+				g_free (command);
+
+				/* One file is enough */
+				i = 0;
 			}
-			g_free (command);
-		}
 
-		g_free (xmodmap_file);
+			g_free (xmodmap_file);
+		}
 	}
 
 	return rv;



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