#! /bin/sh -e

# DP: Modified

if [ $# -ne 1 ]; then
    echo >&2 "$0: script expects -patch|-unpatch as argument"
    exit 1
fi
case "$1" in
    -patch) patch -f -p0 < $0;;
    -unpatch) patch -f -R -p0 < $0;;
    *)
        echo >&2 "$0: script expects -patch|-unpatch as argument"
        exit 1
esac
exit 0

--- gnome-terminal/gnome-terminal.c.orig	Thu Dec 27 00:44:11 2001
+++ gnome-terminal/gnome-terminal.c	Thu Dec 27 00:54:19 2001
@@ -51,7 +51,7 @@
 
 char **env;
 
-#define DEFAULT_FONT "-misc-fixed-medium-r-normal--20-200-75-75-c-100-iso8859-1"
+#define DEFAULT_FONT "fixed"
 #define EXTRA 6
 
 /* is there pixmap compiled into zvt */
@@ -109,6 +109,12 @@
 #ifdef HAVE_ZVT_DEL_IS_DEL
 	int del_is_del       :1; 		/* Generates Delete DEL/^H? */
 #endif
+#ifdef HAVE_ZVT_META_USE_HIGH_BIT
+	int meta_use_high_bit:1;                /* generate meta/ESC */
+#endif
+#ifdef HAVE_ZVT_META_MODIFIERS
+	guint meta_modifiers;                   /* which modifiers are meta */
+#endif
 	enum palette_enum color_type; 			/* The color mode */
 	enum color_set_enum color_set;
 	char *font; 				/* Font used by the terminals */
@@ -163,6 +169,17 @@
 #ifdef HAVE_ZVT_DEL_IS_DEL
 	GtkWidget *del_is_del_checkbox;
 #endif
+#ifdef HAVE_ZVT_META_USE_HIGH_BIT
+	GtkWidget *meta_use_high_bit_checkbox;
+#endif
+#ifdef HAVE_ZVT_META_MODIFIERS
+	GtkWidget *meta_modifiers_mod1_checkbox;
+	GtkWidget *meta_modifiers_mod2_checkbox;
+	GtkWidget *meta_modifiers_mod3_checkbox;
+	GtkWidget *meta_modifiers_mod4_checkbox;
+	GtkWidget *meta_modifiers_mod5_checkbox;
+#endif
+
 	GtkWidget *login_by_default_checkbox;
 	GtkWidget *use_bold_checkbox;
 	GtkWidget *wordclass_entry;
@@ -517,7 +534,7 @@
 	else
 		cfg->color_type = PALETTE_LINUX;
 	
-	cfg->keyboard_secured  = FALSE;
+	cfg->keyboard_secured  = gnome_config_get_bool ("keyboard_secured=false");
 	
 	cfg->bell              = gnome_config_get_bool ("bell_silenced=0");
 	cfg->blink             = gnome_config_get_bool ("blinking=0");
@@ -525,6 +542,17 @@
 #ifdef HAVE_ZVT_DEL_IS_DEL
 	cfg->del_is_del        = gnome_config_get_bool ("del_is_del=0");
 #endif
+#ifdef HAVE_ZVT_META_USE_HIGH_BIT
+	cfg->meta_use_high_bit = gnome_config_get_bool ("meta_use_high_bit=0");
+#endif
+#ifdef HAVE_ZVT_META_MODIFIERS
+	cfg->meta_modifiers    = 0;
+	cfg->meta_modifiers   |= gnome_config_get_bool  ("meta_modifiers_mod1=1") ? GDK_MOD1_MASK : 0;
+	cfg->meta_modifiers   |= gnome_config_get_bool  ("meta_modifiers_mod2=0") ? GDK_MOD2_MASK : 0;
+	cfg->meta_modifiers   |= gnome_config_get_bool  ("meta_modifiers_mod3=0") ? GDK_MOD3_MASK : 0;
+	cfg->meta_modifiers   |= gnome_config_get_bool  ("meta_modifiers_mod4=1") ? GDK_MOD4_MASK : 0;
+	cfg->meta_modifiers   |= gnome_config_get_bool  ("meta_modifiers_mod5=0") ? GDK_MOD5_MASK : 0;
+#endif
 
 	cfg->login_by_default  = gnome_config_get_bool ("login_by_default=0");
 	cfg->use_bold          = gnome_config_get_bool ("use_bold=true");
@@ -596,6 +624,23 @@
 #ifdef HAVE_ZVT_DEL_IS_DEL
 	newcfg->del_is_del     = GTK_TOGGLE_BUTTON (prefs->del_is_del_checkbox)->active;
 #endif
+#ifdef HAVE_ZVT_META_USE_HIGH_BIT
+	newcfg->meta_use_high_bit = GTK_TOGGLE_BUTTON(prefs->meta_use_high_bit_checkbox)->active;
+#endif
+#ifdef HAVE_ZVT_META_MODIFIERS
+	newcfg->meta_modifiers    = 0;
+	if (GTK_TOGGLE_BUTTON(prefs->meta_modifiers_mod1_checkbox)->active)
+		newcfg->meta_modifiers |= GDK_MOD1_MASK;
+	if (GTK_TOGGLE_BUTTON(prefs->meta_modifiers_mod2_checkbox)->active)
+		newcfg->meta_modifiers |= GDK_MOD2_MASK;
+	if (GTK_TOGGLE_BUTTON(prefs->meta_modifiers_mod3_checkbox)->active)
+		newcfg->meta_modifiers |= GDK_MOD3_MASK;
+	if (GTK_TOGGLE_BUTTON(prefs->meta_modifiers_mod4_checkbox)->active)
+		newcfg->meta_modifiers |= GDK_MOD4_MASK;
+	if (GTK_TOGGLE_BUTTON(prefs->meta_modifiers_mod5_checkbox)->active)
+		newcfg->meta_modifiers |= GDK_MOD5_MASK;
+#endif
+
 	newcfg->menubar_hidden = GTK_TOGGLE_BUTTON (prefs->menubar_checkbox)->active;
 	newcfg->scroll_out     = GTK_TOGGLE_BUTTON (prefs->scroll_out_checkbox)->active;
 	newcfg->scroll_key     = GTK_TOGGLE_BUTTON (prefs->scroll_kbd_checkbox)->active;
@@ -689,6 +734,12 @@
 #ifdef HAVE_ZVT_DEL_IS_DEL
 	zvt_term_set_del_is_del (term, cfg->del_is_del);
 #endif
+#ifdef HAVE_ZVT_META_USE_HIGH_BIT
+	zvt_term_set_meta_use_high_bit(term, cfg->meta_use_high_bit);
+#endif
+#ifdef HAVE_ZVT_META_MODIFIERS
+	zvt_term_set_meta_modifiers(term, cfg->meta_modifiers);
+#endif
 
 	if (zvt_pixmap_support && cfg->background_pixmap) {
 		int flags;
@@ -1028,6 +1079,22 @@
 #ifdef HAVE_ZVT_DEL_IS_DEL
 	gnome_config_set_bool   ("del_is_del", cfg->del_is_del);
 #endif
+#ifdef HAVE_ZVT_META_USE_HIGH_BIT
+	gnome_config_set_bool   ("meta_use_high_bit", cfg->meta_use_high_bit);
+#endif
+#ifdef HAVE_ZVT_META_MODIFIERS
+	gnome_config_set_bool   ("meta_modifiers_mod1",
+				 ((cfg->meta_modifiers)&GDK_MOD1_MASK) ? 1 :0);
+	gnome_config_set_bool   ("meta_modifiers_mod2",
+				 ((cfg->meta_modifiers)&GDK_MOD2_MASK) ? 1 :0);
+	gnome_config_set_bool   ("meta_modifiers_mod3",
+				 ((cfg->meta_modifiers)&GDK_MOD3_MASK) ? 1 :0);
+	gnome_config_set_bool   ("meta_modifiers_mod4",
+				 ((cfg->meta_modifiers)&GDK_MOD4_MASK) ? 1 :0);
+	gnome_config_set_bool   ("meta_modifiers_mod5",
+				 ((cfg->meta_modifiers)&GDK_MOD5_MASK) ? 1 :0);
+#endif
+
 	gnome_config_set_bool   ("login_by_default", cfg->login_by_default);
 	gnome_config_set_bool   ("use_bold", cfg->use_bold);
 	gnome_config_set_int    ("scrollbacklines", cfg->scrollback);
@@ -1045,6 +1112,7 @@
 #endif
 	gnome_config_set_bool   ("background_pixmap", cfg->background_pixmap);
 	gnome_config_set_string ("pixmap_file", cfg->pixmap_file);
+	gnome_config_set_bool   ("keyboard_secured", cfg->keyboard_secured);
 
 	for (i=0;i<18;i++)
 		colours[i] = g_strdup_printf ("rgb:%04x/%04x/%04x", cfg->palette[i].red,
@@ -1233,6 +1301,125 @@
 	gtk_signal_connect (GTK_OBJECT (prefs->del_is_del_checkbox), "toggled",
 			    GTK_SIGNAL_FUNC (prop_changed), prefs);
 #endif
+#ifdef HAVE_ZVT_META_USE_HIGH_BIT
+	prefs->meta_use_high_bit_checkbox = glade_xml_get_widget (gui, "meta-sets-high-bit-checkbox");
+	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (prefs->meta_use_high_bit_checkbox),
+				      cfg->meta_use_high_bit ? 1 : 0);
+	gtk_signal_connect (GTK_OBJECT (prefs->meta_use_high_bit_checkbox),
+					"toggled",
+					GTK_SIGNAL_FUNC (prop_changed), prefs);
+#else
+	gtk_widget_hide( glade_xml_get_widget( gui, "meta-sets-high-bit-checkbox"));
+#endif
+
+#ifdef HAVE_ZVT_META_MODIFIERS
+	prefs->meta_modifiers_mod1_checkbox = glade_xml_get_widget (gui, "meta-modifiers-mod1-checkbox");
+	prefs->meta_modifiers_mod2_checkbox = glade_xml_get_widget (gui, "meta-modifiers-mod2-checkbox");
+	prefs->meta_modifiers_mod3_checkbox = glade_xml_get_widget (gui, "meta-modifiers-mod3-checkbox");
+	prefs->meta_modifiers_mod4_checkbox = glade_xml_get_widget (gui, "meta-modifiers-mod4-checkbox");
+	prefs->meta_modifiers_mod5_checkbox = glade_xml_get_widget (gui, "meta-modifiers-mod5-checkbox");
+	// Optional part: print the modifiers's association
+	// and disable modifiers which do not make sense
+	{
+		XModifierKeymap *modkm;
+		modkm = XGetModifierMapping(GDK_DISPLAY());
+		if (modkm && modkm->max_keypermod > 0) {
+			GtkWidget *modwidgets[5];
+			int modifier;
+
+			modwidgets[0] = prefs->meta_modifiers_mod1_checkbox;
+			modwidgets[1] = prefs->meta_modifiers_mod2_checkbox;
+			modwidgets[2] = prefs->meta_modifiers_mod3_checkbox;
+			modwidgets[3] = prefs->meta_modifiers_mod4_checkbox;
+			modwidgets[4] = prefs->meta_modifiers_mod5_checkbox;
+			
+			/* Modifiers are Shift, Lock, Control, Mod1, Mod2,
+			   Mod3, Mod4, and Mod5. We start at mod1 */
+			for (modifier = 0; modifier <5; modifier++) {
+				KeySym ksym;
+				char widgetName[32];
+				char *modDescr = NULL;
+				int modifiermask = 0;
+				ksym = XKeycodeToKeysym(GDK_DISPLAY(),
+							modkm->modifiermap[(modifier+3)*modkm->max_keypermod], 0);
+				if (ksym != NoSymbol) {
+					int modDescrLen;
+					modDescr = g_strdup(XKeysymToString(ksym));
+					modDescrLen = strlen(modDescr);
+					if ( modDescrLen > 2
+					     && (strcmp(modDescr+modDescrLen-2,
+							"_L")==0 ||
+						 strcmp(modDescr+modDescrLen-2,
+							"_R")==0))
+						modDescr[modDescrLen-2] = '\0';
+					if (modDescrLen > 5
+					    && strcmp(modDescr+modDescrLen-5,
+						      "_Lock")==0) {
+						g_free(modDescr);
+						modDescr = NULL;
+					}
+				}
+				if (modDescr != NULL) {
+					gtk_widget_set_state(modwidgets[modifier],
+							     GTK_STATE_NORMAL);
+					g_snprintf(widgetName, 
+						   sizeof(widgetName),
+						   "Mod%d (%s)",
+						   modifier+1, modDescr);
+					g_free(modDescr);
+				} else {
+					gtk_widget_set_state(modwidgets[modifier],
+							     GTK_STATE_INSENSITIVE);
+					g_snprintf(widgetName, 
+						   sizeof(widgetName),
+						   "Mod%d",
+						   modifier+1);
+					// We also want to clear this modifier
+					// since it ahs been deemed unsuitable
+					// for meta purposes
+					switch (modifier) {
+					case 0: modifiermask = GDK_MOD1_MASK; break;
+					case 1: modifiermask = GDK_MOD2_MASK; break;
+					case 2: modifiermask = GDK_MOD3_MASK; break;
+					case 3: modifiermask = GDK_MOD4_MASK; break;
+					case 4: modifiermask = GDK_MOD5_MASK; break;
+					}
+					cfg->meta_modifiers &= ~modifiermask;
+				}
+				gtk_label_set_text(GTK_LABEL(GTK_BIN(modwidgets[modifier])->child),
+						   widgetName);
+			}
+			XFreeModifiermap(modkm);
+		}
+	}
+	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (prefs->meta_modifiers_mod1_checkbox),
+				      cfg->meta_modifiers & GDK_MOD1_MASK ? 1 : 0);
+	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (prefs->meta_modifiers_mod2_checkbox),
+				      cfg->meta_modifiers & GDK_MOD2_MASK ? 1 : 0);
+	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (prefs->meta_modifiers_mod3_checkbox),
+				      cfg->meta_modifiers & GDK_MOD3_MASK ? 1 : 0);
+	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (prefs->meta_modifiers_mod4_checkbox),
+				      cfg->meta_modifiers & GDK_MOD4_MASK ? 1 : 0);
+	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (prefs->meta_modifiers_mod5_checkbox),
+				      cfg->meta_modifiers & GDK_MOD5_MASK ? 1 : 0);
+	gtk_signal_connect (GTK_OBJECT (prefs->meta_modifiers_mod1_checkbox),
+					"toggled",
+					GTK_SIGNAL_FUNC (prop_changed), prefs);
+	gtk_signal_connect (GTK_OBJECT (prefs->meta_modifiers_mod2_checkbox),
+					"toggled",
+					GTK_SIGNAL_FUNC (prop_changed), prefs);
+	gtk_signal_connect (GTK_OBJECT (prefs->meta_modifiers_mod3_checkbox),
+					"toggled",
+					GTK_SIGNAL_FUNC (prop_changed), prefs);
+	gtk_signal_connect (GTK_OBJECT (prefs->meta_modifiers_mod4_checkbox),
+					"toggled",
+					GTK_SIGNAL_FUNC (prop_changed), prefs);
+	gtk_signal_connect (GTK_OBJECT (prefs->meta_modifiers_mod5_checkbox),
+					"toggled",
+					GTK_SIGNAL_FUNC (prop_changed), prefs);
+#else
+	gtk_widget_hide (glade_xml_get_widget (gui, "meta-modifiers-frame"));
+#endif
 	
 	/* --login by default */
 	prefs->login_by_default_checkbox = glade_xml_get_widget (gui, "login-by-default-checkbox");
@@ -1503,6 +1690,9 @@
 		gdk_keyboard_grab (term->term_window, TRUE, GDK_CURRENT_TIME);
 	else
 		gdk_keyboard_ungrab (GDK_CURRENT_TIME);
+
+	save_preferences_cmd (w, term);
+
 }
 
 #ifdef ZVT_TERM_MATCH_SUPPORT
@@ -2192,6 +2382,12 @@
 	zvt_term_set_del_key_swap (term, cfg->swap_keys);
 #ifdef HAVE_ZVT_DEL_IS_DEL
 	zvt_term_set_del_is_del (term, cfg->del_is_del);
+#endif
+#ifdef HAVE_ZVT_META_USE_HIGH_BIT
+	zvt_term_set_meta_use_high_bit (term, cfg->meta_use_high_bit);
+#endif
+#ifdef HAVE_ZVT_META_MODIFIERS
+	zvt_term_set_meta_modifiers (term, cfg->meta_modifiers);
 #endif
 
 	gtk_signal_connect (GTK_OBJECT (term), "child_died",
