From 0a1c3abb066ac8dade2cbad5936cc2d10ae2284b Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Fri, 5 Mar 2010 19:20:49 +0100 Subject: [PATCH] When MiscAlwaysShowTabs is false, hide tabs after some inactivity --- terminal/terminal-window.c | 47 ++++++++++++++++++++++++++++++++++++++----- 1 files changed, 41 insertions(+), 6 deletions(-) diff --git a/terminal/terminal-window.c b/terminal/terminal-window.c index 6294ef2..68ff4a8 100644 --- a/terminal/terminal-window.c +++ b/terminal/terminal-window.c @@ -105,7 +105,8 @@ static void terminal_window_notebook_page_reordered (GtkNoteboo GtkNotebookPage *page, guint page_num, TerminalWindow *window); -static void terminal_window_notebook_show_tabs (TerminalWindow *window); +static void terminal_window_notebook_show_tabs (TerminalWindow *window, + gboolean show_tabs); static void terminal_window_notebook_page_added (GtkNotebook *notebook, GtkWidget *child, guint page_num, @@ -184,6 +185,7 @@ static void terminal_window_action_report_bug (GtkAction TerminalWindow *window); static void terminal_window_action_about (GtkAction *action, TerminalWindow *window); +static gboolean terminal_window_callback_tabs (gpointer data); @@ -204,6 +206,8 @@ struct _TerminalWindow TerminalScreen *active; + guint hide_bars_counter; + guint inhibit_hide_tabs : 1; /* whether this window has an rgba colormap */ guint is_composited : 1; }; @@ -317,7 +321,8 @@ terminal_window_init (TerminalWindow *window) GtkRcStyle *style; window->preferences = terminal_preferences_get (); - + window->hide_bars_counter = 0; + window->inhibit_hide_tabs = 0; /* The Terminal size needs correction when the font name or the scrollbar * visibility is changed. */ @@ -852,15 +857,30 @@ terminal_window_notebook_page_reordered (GtkNotebook *notebook, terminal_window_rebuild_gomenu (window); } +static gboolean +terminal_window_callback_tabs (gpointer data) +{ + TerminalWindow *window = (TerminalWindow *) data; + + if (window->inhibit_hide_tabs) + return TRUE; + + window->hide_bars_counter--; + + if (! window->hide_bars_counter) + terminal_window_notebook_show_tabs (window, FALSE); + return FALSE; +} static void -terminal_window_notebook_show_tabs (TerminalWindow *window) +terminal_window_notebook_show_tabs (TerminalWindow *window, + gboolean show_tabs) { GtkNotebook *notebook = GTK_NOTEBOOK (window->notebook); - gboolean show_tabs = TRUE; gint npages; gint width_chars, height_chars; + gboolean always_show_tabs; /* set the visibility of the tabs */ npages = gtk_notebook_get_n_pages (notebook); @@ -880,6 +900,13 @@ terminal_window_notebook_show_tabs (TerminalWindow *window) terminal_window_set_size_force_grid (window, window->active, width_chars, height_chars); } + + g_object_get (G_OBJECT (window->preferences), "misc-always-show-tabs", &always_show_tabs, NULL); + if (show_tabs && !always_show_tabs) + { + window->hide_bars_counter++; + g_timeout_add_seconds (3, terminal_window_callback_tabs, window); + } } @@ -915,7 +942,7 @@ terminal_window_notebook_page_added (GtkNotebook *notebook, terminal_screen_set_size (screen, w, h); /* show the tabs when needed */ - terminal_window_notebook_show_tabs (window); + terminal_window_notebook_show_tabs (window, TRUE); } else { @@ -964,7 +991,7 @@ terminal_window_notebook_page_removed (GtkNotebook *notebook, else { /* show the tabs when needed */ - terminal_window_notebook_show_tabs (window); + terminal_window_notebook_show_tabs (window, TRUE); /* regenerate the "Go" menu */ terminal_window_rebuild_gomenu (window); @@ -991,6 +1018,8 @@ terminal_window_notebook_button_press_event (GtkNotebook *notebook, gboolean close_middle_click; gint x, y; + window->inhibit_hide_tabs = 1; + terminal_return_val_if_fail (TERMINAL_IS_WINDOW (window), FALSE); terminal_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), FALSE); @@ -1057,6 +1086,8 @@ terminal_window_notebook_button_release_event (GtkNotebook *notebook, GdkEventButton *event, TerminalWindow *window) { + window->inhibit_hide_tabs = 0; + terminal_return_val_if_fail (TERMINAL_IS_WINDOW (window), FALSE); terminal_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), FALSE); @@ -1481,6 +1512,8 @@ terminal_window_action_prev_tab (GtkAction *action, n_pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (window->notebook)); gtk_notebook_set_current_page (GTK_NOTEBOOK (window->notebook), (page_num - 1) % n_pages); + + terminal_window_notebook_show_tabs (window, TRUE); } @@ -1496,6 +1529,8 @@ terminal_window_action_next_tab (GtkAction *action, n_pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (window->notebook)); gtk_notebook_set_current_page (GTK_NOTEBOOK (window->notebook), (page_num + 1) % n_pages); + + terminal_window_notebook_show_tabs (window, TRUE); } -- 1.7.0