From 5bfe6f02178eeb5f8fab6cf03e3af683e5d6d8db Mon Sep 17 00:00:00 2001 From: mutantturkey Date: Fri, 23 Apr 2010 14:58:34 -0400 Subject: fixed close tab to work correctly. thanks Sakura :) --- mt.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) (limited to 'mt.c') diff --git a/mt.c b/mt.c index 6ef31f9..373f904 100644 --- a/mt.c +++ b/mt.c @@ -9,32 +9,26 @@ static void tab_new(); static void tab_close(); /* part of the code is from sakura. :) i just want a more minimal version, sakura is to code bloat for what i want. so snippets will do*/ +/* i am very thankful for this part, because it really helped me figure out how to close tabs properly (sounds easy, but i am dumb as a doorknob*/ static GQuark term_data_id = 0; -#define get_page_term(page_idx) (struct term*)g_object_get_qdata(G_OBJECT( gtk_notebook_get_nth_page( (GtkNotebook*)mt.notebook, page_idx ) ), term_data_id); +#define get_page_term( sakura, page_idx ) \ + (struct term*)g_object_get_qdata(G_OBJECT( gtk_notebook_get_nth_page( (GtkNotebook*)mt.notebook, page_idx ) ), term_data_id); -#define set_page_term( sakura, page_idx, term ) \ - g_object_set_qdata_full( \ - G_OBJECT( gtk_notebook_get_nth_page( (GtkNotebook*)mt.notebook, page_idx) ), \ - term_data_id, term, (GDestroyNotify)g_free); - static struct { GtkWidget *win; GtkWidget *notebook; gchar *title; } mt; - struct term { GtkWidget *vte; /* Reference to VTE terminal */ GtkWidget *scrollbar; GtkWidget *label; - gchar *label_teoxt; + gchar *label_text; }; - static void quit() { gtk_main_quit(); } - gboolean key_press_cb (GtkWidget *widget, GdkEventKey *event) { if (event->state == GDK_CONTROL_MASK) { @@ -82,14 +76,14 @@ static void tab_close() { gint page = gtk_notebook_get_current_page(GTK_NOTEBOOK(mt.notebook)); - struct term *t = get_page_term(page); + struct term *t; + t = get_page_term(NULL, page); gtk_widget_hide(t->vte); gtk_notebook_remove_page(GTK_NOTEBOOK(mt.notebook), page); g_free(t); - if (gtk_notebook_get_n_pages(GTK_NOTEBOOK(mt.notebook)) == 0) { - quit(); -} + if (gtk_notebook_get_n_pages(GTK_NOTEBOOK(mt.notebook)) == 0) { quit(); } + } @@ -102,6 +96,9 @@ static void tab_new() { vte_terminal_fork_command(VTE_TERMINAL(t->vte), NULL, NULL, NULL, NULL, FALSE, FALSE, FALSE); int index = gtk_notebook_append_page(GTK_NOTEBOOK(mt.notebook), t->vte, t->label); printf("%d \n", index); + //sakura_set_page_term(NULL, index, t); + + g_object_set_qdata_full(G_OBJECT(gtk_notebook_get_nth_page((GtkNotebook*)mt.notebook, index)), term_data_id, t, NULL); g_signal_connect(t->vte, "child-exited", G_CALLBACK(tab_close), NULL); gtk_notebook_set_current_page(GTK_NOTEBOOK(mt.notebook), index); gtk_widget_grab_focus(t->vte); @@ -110,7 +107,7 @@ static void tab_new() { int main (int argc, char* argv[]) { gtk_init (&argc, &argv); - + term_data_id = g_quark_from_static_string("mt"); mt.notebook = gtk_notebook_new(); mt.win = gtk_window_new (GTK_WINDOW_TOPLEVEL); g_signal_connect (G_OBJECT (mt.win), "destroy", G_CALLBACK (quit), NULL); -- cgit v1.2.3