? src/core.25368
? src/core.25427
Index: src/acme.c
===================================================================
RCS file: /cvs/gnome/acme/src/acme.c,v
retrieving revision 1.81
diff -u -r1.81 acme.c
--- src/acme.c	2 Jan 2004 15:20:06 -0000	1.81
+++ src/acme.c	17 Mar 2004 11:29:41 -0000
@@ -376,27 +376,76 @@
 }
 
 static void
-unhookup_keysym (int keycode)
+unhookup_keysym (int keycode, int index)
 {
 	char *command;
 
 	if (keycode <= 0)
 		return;
 
-	command = g_strdup_printf ("xmodmap -e \"keycode %d = \"", keycode);
+	if (keys[index].saved_binding != NULL)
+		command = g_strdup_printf ("xmodmap -e \"%s\"", keys[index].saved_binding);
+	else
+		command = g_strdup_printf ("xmodmap -e \"keycode %d = \"", keycode);
+
+	g_free (keys[index].saved_binding);
+	keys[index].saved_binding = NULL;
 
 	g_spawn_command_line_sync (command, NULL, NULL, NULL, NULL);
 	g_free (command);
 }
 
+static char *
+save_original_modmap_cmd (int keycode)
+{
+	char *argv[3];
+	char *output, **lines, *res;
+	int i;
+
+	argv[0] = "xmodmap";
+	argv[1] = "-pke";
+	argv[2] = NULL;
+
+	res = NULL;
+
+	if (g_spawn_sync (NULL, argv, NULL,
+				G_SPAWN_SEARCH_PATH, 0, 0,
+				&output, NULL, NULL, NULL) == FALSE)
+	{
+		g_message ("xmodmap -pke failed");
+		return NULL;
+	}
+
+	lines = g_strsplit (output, "\n", 0);
+	for (i = 0; lines[i] != NULL; i++)
+	{
+		int tmp;
+
+		if (sscanf (lines[i], "keycode %d = ", &tmp) != 1)
+			continue;
+
+		if (keycode == tmp)
+		{
+			res = g_strdup (lines[i]);
+			break;
+		}
+	}
+
+	g_strfreev (lines);
+
+	return res;
+}
+
 static gboolean
-hookup_keysym (int keycode, const char *keysym)
+hookup_keysym (int keycode, const char *keysym, int index)
 {
 	char *command;
 
 	if (keycode <= 0)
 		return TRUE;
 
+	keys[index].saved_binding = save_original_modmap_cmd (keycode);
+
 	command = g_strdup_printf ("xmodmap -e \"keycode %d = %s\"",
 			keycode, keysym);
 
@@ -431,7 +480,7 @@
 			case PREVIOUS_KEY:
 			case NEXT_KEY:
 			case REFRESH_KEY:
-				unhookup_keysym (keys[i].key_code);
+				unhookup_keysym (keys[i].key_code, i);
 				break;
 			}
 
@@ -443,27 +492,27 @@
 			switch (keys[i].key_type) {
 			case PLAY_KEY:
 				grab = hookup_keysym (key_code,
-						"XF86AudioPlay");
+						"XF86AudioPlay", i);
 				break;
 			case PAUSE_KEY:
 				grab = hookup_keysym (key_code,
-						"XF86AudioPause");
+						"XF86AudioPause", i);
 				break;
 			case STOP_KEY:
 				grab = hookup_keysym (key_code,
-						"XF86AudioStop");
+						"XF86AudioStop", i);
 				break;
 			case PREVIOUS_KEY:
 				grab = hookup_keysym (key_code,
-						"XF86AudioPrev");
+						"XF86AudioPrev", i);
 				break;
 			case NEXT_KEY:
 				grab = hookup_keysym (key_code,
-						"XF86AudioNext");
+						"XF86AudioNext", i);
 				break;
 			case REFRESH_KEY:
 				grab = hookup_keysym (key_code,
-						"XF86Refresh");
+						"XF86Refresh", i);
 				break;
 			}
 
@@ -515,27 +564,27 @@
 		switch (keys[i].key_type) {
 		case PLAY_KEY:
 			grab = hookup_keysym (keys[i].key_code,
-					"XF86AudioPlay");
+					"XF86AudioPlay", i);
 			break;
 		case PAUSE_KEY:
 			grab = hookup_keysym (keys[i].key_code,
-					"XF86AudioPause");
+					"XF86AudioPause", i);
 			break;
 		case STOP_KEY:
 			grab = hookup_keysym (keys[i].key_code,
-					"XF86AudioStop");
+					"XF86AudioStop", i);
 			break;
 		case PREVIOUS_KEY:
 			grab = hookup_keysym (keys[i].key_code,
-					"XF86AudioPrev");
+					"XF86AudioPrev", i);
 			break;
 		case NEXT_KEY:
 			grab = hookup_keysym (keys[i].key_code,
-					"XF86AudioNext");
+					"XF86AudioNext", i);
 			break;
 		case REFRESH_KEY:
 			grab = hookup_keysym (keys[i].key_code,
-					"XF86Refresh");
+					"XF86Refresh", i);
 			break;
 		}
 
Index: src/acme.h
===================================================================
RCS file: /cvs/gnome/acme/src/acme.h,v
retrieving revision 1.16
diff -u -r1.16 acme.h
--- src/acme.h	11 Mar 2003 19:52:30 -0000	1.16
+++ src/acme.h	17 Mar 2004 11:29:41 -0000
@@ -70,62 +70,63 @@
 	const char *key_config;
 	const char *description;
 	int key_code;
+	char *saved_binding;
 } keys[HANDLED_KEYS] = {
 	{ MUTE_KEY, "/apps/acme/mute_key",
-		N_("Mute key"), 166 },
+		N_("Mute key"), 166, NULL },
 	{ VOLUME_DOWN_KEY, "/apps/acme/volume_down_key",
-		N_("Volume down key"), 165 },
+		N_("Volume down key"), 165, NULL },
 	{ VOLUME_UP_KEY, "/apps/acme/volume_up_key",
-		N_("Volume up key"), 158 },
+		N_("Volume up key"), 158, NULL },
 	{ POWER_KEY, "/apps/acme/power_key",
-		N_("Power key"), 222 },
+		N_("Power key"), 222, NULL },
 	{ EJECT_KEY, "/apps/acme/eject_key",
-		N_("Eject key"), 116 },
+		N_("Eject key"), 116, NULL },
 	{ MEDIA_KEY, "/apps/acme/media_key",
-		N_("Media key"), 0 },
+		N_("Media key"), 0, NULL },
 	{ PLAY_KEY, "/apps/acme/play_key",
-		N_("Play key"), -1 },
+		N_("Play key"), -1, NULL },
 	{ PAUSE_KEY, "/apps/acme/pause_key",
-		N_("Pause key"), -1 },
+		N_("Pause key"), -1, NULL },
 	{ STOP_KEY, "/apps/acme/stop_key",
-		N_("Stop (Audio) key"), -1 },
+		N_("Stop (Audio) key"), -1, NULL },
 	{ PREVIOUS_KEY, "/apps/acme/previous_key",
-		N_("Previous (Audio) key"), -1 },
+		N_("Previous (Audio) key"), -1, NULL },
 	{ NEXT_KEY, "/apps/acme/next_key",
-		N_("Next (Audio) key"), -1 },
+		N_("Next (Audio) key"), -1, NULL },
 	{ HOME_KEY, "/apps/acme/home_key",
-		N_("My Home key"), -1 },
+		N_("My Home key"), -1, NULL },
 	{ REFRESH_KEY, "/apps/acme/refresh_key",
-		N_("Refresh key"), -1 },
+		N_("Refresh key"), -1, NULL },
 	{ SEARCH_KEY, "/apps/acme/search_key",
-		N_("Search key"), -1 },
+		N_("Search key"), -1, NULL },
 	{ EMAIL_KEY, "/apps/acme/email_key",
-		N_("E-Mail key"), -1 },
+		N_("E-Mail key"), -1, NULL },
 	{ SLEEP_KEY, "/apps/acme/sleep_key",
-		N_("Sleep key"), -1 },
+		N_("Sleep key"), -1, NULL },
 	{ SCREENSAVER_KEY, "/apps/acme/screensaver_key",
-		N_("Screensaver key"), -1 },
+		N_("Screensaver key"), -1, NULL },
 	{ FINANCE_KEY, "/apps/acme/finance_key",
-		N_("Finance key"), -1 },
+		N_("Finance key"), -1, NULL },
 	{ HELP_KEY, "/apps/acme/help_key",
-		N_("Help key"), -1 },
+		N_("Help key"), -1, NULL },
 	{ WWW_KEY, "/apps/acme/www_key",
-		N_("WWW key"), -1 },
+		N_("WWW key"), -1, NULL },
 	{ GROUPS_KEY, "/apps/acme/groups_key",
-		N_("Groups key"), -1 },
+		N_("Groups key"), -1, NULL },
 	{ CALCULATOR_KEY, "/apps/acme/calculator_key",
-		N_("Calculator key"), -1 },
+		N_("Calculator key"), -1, NULL },
 	{ RECORD_KEY, "/apps/acme/record_key",
-		N_("Record key"), -1 },
+		N_("Record key"), -1, NULL },
 	{ CLOSE_WINDOW_KEY, "/apps/acme/close_window_key",
-		N_("Close Window key"), -1 },
+		N_("Close Window key"), -1, NULL },
 	{ SHADE_WINDOW_KEY, "/apps/acme/shade_window_key",
-		N_("Shade Window key"), -1 },
+		N_("Shade Window key"), -1, NULL },
 #ifdef USE_FBLEVEL
 	{ BRIGHT_DOWN_KEY, "/apps/acme/brightness_down",
-		N_("Brightness down key"), 101 },
+		N_("Brightness down key"), 101, NULL },
 	{ BRIGHT_UP_KEY, "/apps/acme/brightness_up",
-		N_("Brightness up key"), 212 },
+		N_("Brightness up key"), 212, NULL },
 #endif
 };
 
