From 71204c2db80348c92b42c5cca08fc8c1166ab40d Mon Sep 17 00:00:00 2001 From: Martin Wimpress Date: Mon, 24 Feb 2014 14:44:24 +0000 Subject: Opening new terminal in a tab now works. The new intended behaviour is desbribed in https://bugzilla.gnome.org/show_bug.cgi?id=83203#c57 Fixes #45. --- src/terminal-window.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'src/terminal-window.c') diff --git a/src/terminal-window.c b/src/terminal-window.c index 43333bf..d15a90c 100644 --- a/src/terminal-window.c +++ b/src/terminal-window.c @@ -97,6 +97,7 @@ struct _TerminalWindowPrivate /* Workaround until gtk+ bug #535557 is fixed */ guint icon_title_set : 1; + time_t focus_time; }; #define PROFILE_DATA_KEY "GT::Profile" @@ -139,6 +140,9 @@ static gboolean terminal_window_state_event (GtkWidget *widget, static gboolean terminal_window_delete_event (GtkWidget *widget, GdkEvent *event, gpointer data); +static gboolean terminal_window_focus_in_event (GtkWidget *widget, + GdkEventFocus *event, + gpointer data); static gboolean notebook_button_press_cb (GtkWidget *notebook, GdkEventButton *event, @@ -2136,6 +2140,10 @@ terminal_window_init (TerminalWindow *window) g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK(terminal_window_delete_event), NULL); + g_signal_connect (G_OBJECT (window), "focus_in_event", + G_CALLBACK(terminal_window_focus_in_event), + NULL); + #ifdef MATE_ENABLE_DEBUG _TERMINAL_DEBUG_IF (TERMINAL_DEBUG_GEOMETRY) { @@ -2383,6 +2391,20 @@ terminal_window_delete_event (GtkWidget *widget, return confirm_close_window_or_tab (TERMINAL_WINDOW (widget), NULL); } +static gboolean +terminal_window_focus_in_event (GtkWidget *widget, + GdkEventFocus *event, + gpointer data) +{ + TerminalWindow *window = TERMINAL_WINDOW (widget); + TerminalWindowPrivate *priv = window->priv; + + if (event->in) + priv->focus_time = time(NULL); + + return FALSE; +} + static void terminal_window_show (GtkWidget *widget) { @@ -4264,3 +4286,26 @@ terminal_window_save_state (TerminalWindow *window, g_key_file_set_string_list (key_file, group, TERMINAL_CONFIG_WINDOW_PROP_TABS, (const char * const *) tab_names, len); g_strfreev (tab_names); } + + +TerminalWindow * +terminal_window_get_latest_focused (TerminalWindow *window1, + TerminalWindow *window2) +{ + TerminalWindowPrivate *priv1 = NULL; + TerminalWindowPrivate *priv2 = NULL; + + if (!window1) + return window2; + + if (!window2) + return window1; + + priv1 = window1->priv; + priv2 = window2->priv; + + if (priv2->focus_time > priv1->focus_time) + return window2; + + return window1; +} -- cgit v1.2.1