lxterminal (0.1.8-2) alt-number-key.patch

Summary

 src/lxterminal.c  |   43 ++++++++++++++++++++++++++++++++++---------
 src/lxterminal.h  |    1 +
 src/preferences.c |   12 ++++++++++++
 src/setting.c     |    2 ++
 src/setting.h     |    1 +
 5 files changed, 50 insertions(+), 9 deletions(-)

    
download this patch

Patch contents

commit 27ff36eb03d7698158f93f8b8e095b79b565b18a
Author: Marty Jack <martyj@linux.local>
Date:   Mon Jul 19 14:54:15 2010 -0400

    Add option to conditionalize Alt-n behavior (Bug3006779; Patch3020003, Ideal Shang)

--- a/src/lxterminal.c
+++ b/src/lxterminal.c
@@ -68,6 +68,7 @@
 
 /* Menu and accelerator event handlers. */
 static void terminal_initialize_switch_tab_accelerator(Term * term);
+static void terminal_set_disable_alt(Term *term, gboolean disable_alt);
 static void terminal_switch_tab_accelerator(Term * term);
 static void terminal_new_window_activate_event(GtkAction * action, LXTerminal * terminal);
 static void terminal_new_window_accelerator(LXTerminal * terminal, guint action, GtkWidget * item);
@@ -300,7 +301,23 @@
 
         /* Define the accelerator. */
         term->closure = g_cclosure_new_swap(G_CALLBACK(terminal_switch_tab_accelerator), term, NULL);
-        gtk_accel_group_connect(term->parent->accel_group, key, mods, GTK_ACCEL_LOCKED, term->closure);
+        if (gtk_accel_group_from_accel_closure(term->closure) == NULL)
+            gtk_accel_group_connect(term->parent->accel_group, key, mods, GTK_ACCEL_LOCKED, term->closure);
+    }
+}
+
+/* whether disable alt-n to switch tabs or not. */
+void terminal_set_disable_alt(Term * term, gboolean disable_alt)
+{
+    if (GTK_IS_ACCEL_GROUP(term->parent->accel_group))
+    {
+        if (disable_alt)
+        {
+            if (term->closure != NULL)
+                gtk_accel_group_disconnect(term->parent->accel_group, term->closure);
+        }
+        else
+            terminal_initialize_switch_tab_accelerator(term);
     }
 }
 
@@ -378,7 +395,9 @@
         terminal_window_set_fixed_size(terminal);
         gtk_notebook_set_show_tabs(GTK_NOTEBOOK(term->parent->notebook), TRUE);
     }
-    terminal_initialize_switch_tab_accelerator(term);
+
+    /* Disable Alt-n switch tabs or not. */
+    terminal_set_disable_alt(term, terminal->setting->disable_alt);
 }
 
 /* Handler for accelerator <SHIFT><CTRL> T.  Open a new tab. */
@@ -718,6 +737,9 @@
         {
             Term * t = g_ptr_array_index(terminal->terms, i);
             t->index -= 1;
+            if ((GTK_IS_ACCEL_GROUP(t->parent->accel_group)) && (t->closure != NULL))
+                gtk_accel_group_disconnect(t->parent->accel_group, t->closure);
+            terminal_set_disable_alt(t, t->parent->setting->disable_alt);
         }
 
         /* Delete the tab and free the Term structure. */
@@ -936,7 +958,8 @@
 /* Deallocate a Term structure. */
 static void terminal_free(Term * term)
 {
-    gtk_accel_group_disconnect(term->parent->accel_group, term->closure);
+    if ((GTK_IS_ACCEL_GROUP(term->parent->accel_group)) && (term->closure != NULL))
+        gtk_accel_group_disconnect(term->parent->accel_group, term->closure);
     g_free(term);
 }
 
@@ -945,11 +968,11 @@
 {
     /* Initialize UI manager. */
     GtkUIManager * manager = gtk_ui_manager_new();
-    GtkActionGroup * action_group = gtk_action_group_new("MenuBar");
-    gtk_action_group_set_translation_domain(action_group, GETTEXT_PACKAGE);
-    gtk_action_group_add_actions(action_group, menus, MENUBAR_MENU_COUNT, terminal);
-    gtk_action_group_add_actions(action_group, menu_items, MENUBAR_MENUITEM_COUNT, terminal);
-    gtk_ui_manager_insert_action_group(manager, action_group, 0);
+    terminal->action_group = gtk_action_group_new("MenuBar");
+    gtk_action_group_set_translation_domain(terminal->action_group, GETTEXT_PACKAGE);
+    gtk_action_group_add_actions(terminal->action_group, menus, MENUBAR_MENU_COUNT, terminal);
+    gtk_action_group_add_actions(terminal->action_group, menu_items, MENUBAR_MENUITEM_COUNT, terminal);
+    gtk_ui_manager_insert_action_group(manager, terminal->action_group, 0);
 
     guint merge_id = gtk_ui_manager_new_merge_id(manager);
     gtk_ui_manager_add_ui(manager, merge_id, "/", "MenuBar", NULL, GTK_UI_MANAGER_MENUBAR, FALSE);
@@ -1223,7 +1246,6 @@
 
     /* Initialize accelerators. */
     terminal_accelerator_initialize(terminal);
-    terminal_initialize_switch_tab_accelerator(term);
 
     /* Update terminal settings. */
     terminal_settings_apply(terminal);
@@ -1248,7 +1270,10 @@
     /* Apply settings to all windows. */
     int i;
     for (i = 0; i < terminal->terms->len; i += 1)
+    {
         terminal_settings_apply_to_term(terminal, g_ptr_array_index(terminal->terms, i));
+        terminal_set_disable_alt(g_ptr_array_index(terminal->terms, i), terminal->setting->disable_alt);
+    }
 
     /* Update tab position. */
     terminal->tab_position = terminal_tab_get_position_id(terminal->setting->tab_position);
--- a/src/lxterminal.h
+++ b/src/lxterminal.h
@@ -52,6 +52,7 @@
     GtkWidget * window;				/* Toplevel window */
     GtkWidget * box;				/* Vertical box, child of toplevel window */
     GtkWidget * menu;				/* Menu bar, child of vertical box */
+    GtkActionGroup *action_group;   /* Action group on this window */
     GtkAccelGroup * accel_group;		/* Accelerator group for accelerators on this window */
     GtkWidget * notebook;			/* Notebook, child of vertical box */
     GPtrArray * terms;				/* Array of pointers to Term structures */
--- a/src/preferences.c
+++ b/src/preferences.c
@@ -41,6 +41,7 @@
 static void preferences_dialog_hide_close_button_toggled_event(GtkToggleButton * widget, LXTerminal * terminal);
 static gboolean preferences_dialog_selection_focus_out_event(GtkWidget * widget, GdkEventFocus * event, LXTerminal * terminal);
 static void preferences_dialog_disable_f10_toggled_event(GtkToggleButton * widget, LXTerminal * terminal);
+static void preferences_dialog_disable_alt_toggled_event(GtkToggleButton * widget, LXTerminal * terminal);
 
 /* Handler for "response" signal on preferences dialog. */
 static void preferences_dialog_response_event(GtkWidget * dialog, gint response, LXTerminal * terminal)
@@ -170,6 +171,13 @@
     terminal_settings_apply_to_all(terminal);
 }
 
+/* Handler for "toggled" signal on Disable Alt toggle button. */
+static void preferences_dialog_disable_alt_toggled_event(GtkToggleButton * widget, LXTerminal * terminal)
+{
+    terminal->setting->disable_alt = gtk_toggle_button_get_active(widget);
+    terminal_settings_apply_to_all(terminal);
+}
+
 /* Convert the user preference on tab position, expressed as a string, to the internal representation.
  * These have to match the order in the .glade file. */
 gint terminal_tab_get_position_id(gchar * position)
@@ -261,6 +269,10 @@
     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), setting->disable_f10);
     g_signal_connect(G_OBJECT(w), "toggled", G_CALLBACK(preferences_dialog_disable_f10_toggled_event), terminal);
 
+    w = GTK_WIDGET(gtk_builder_get_object(builder, "disable_alt"));
+    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), setting->disable_alt);
+    g_signal_connect(G_OBJECT(w), "toggled", G_CALLBACK(preferences_dialog_disable_alt_toggled_event), terminal);
+
     gtk_widget_show_all(dialog);
     g_object_unref(builder);
 }
--- a/src/setting.c
+++ b/src/setting.c
@@ -55,6 +55,7 @@
     g_key_file_set_boolean(setting->keyfile, "general", "hideclosebutton", setting->hide_close_button);
     g_key_file_set_string(setting->keyfile, "general", "selchars", setting->word_selection_characters);
     g_key_file_set_boolean(setting->keyfile, "general", "disablef10", setting->disable_f10);
+    g_key_file_set_boolean(setting->keyfile, "general", "disablealt", setting->disable_alt);
 
     /* Convert GKeyFile to text and build path to configuration file. */
     gchar * file_data = g_key_file_to_data(setting->keyfile, NULL, NULL);
@@ -113,6 +114,7 @@
         setting->hide_close_button = g_key_file_get_boolean(setting->keyfile, "general", "hideclosebutton", NULL);
         setting->word_selection_characters = g_key_file_get_string(setting->keyfile, "general", "selchars", NULL);
         setting->disable_f10 = g_key_file_get_boolean(setting->keyfile, "general", "disablef10", NULL);
+        setting->disable_alt = g_key_file_get_boolean(setting->keyfile, "general", "disablealt", NULL);
     }
 
     /* Default configuration strings. */
--- a/src/setting.h
+++ b/src/setting.h
@@ -42,6 +42,7 @@
     gboolean hide_close_button;		/* True if close buttons are NOT visible */
     char * word_selection_characters;	/* Characters that act as word breaks during selection by word */
     gboolean disable_f10;		/* True if F10 will be passed to program; false if it brings up File menu */
+    gboolean disable_alt;		/* True if Alt-n is passed to shell; false if it is used to switch between tabs */
 
     gboolean geometry_change;		/* True if there is a geometry change, until it has been acted on */