This is an automated email from the git hooks/post-receive script. f 2 4 0 4 p u s h e d a c o m m i t t o b r a n c h m a s t e r in repository apps/xfce4-terminal.
commit 17dafe40dc89f0e69b774f4af9ef8e121a7acdb1 Author: Igor <[email protected]> Date: Thu Aug 17 09:04:45 2017 -0400 Request confirmation when closing the window while a process is running If any tab has a process (other than shell) running, a confirmation window will be shown. Fixes bug #13781 --- terminal/terminal-screen.c | 33 +++++++++++++++++++++++++++++ terminal/terminal-screen.h | 2 ++ terminal/terminal-window.c | 53 ++++++++++++++++++++++++++++++++++++---------- 3 files changed, 77 insertions(+), 11 deletions(-) diff --git a/terminal/terminal-screen.c b/terminal/terminal-screen.c index 007700a..15b3f44 100644 --- a/terminal/terminal-screen.c +++ b/terminal/terminal-screen.c @@ -2529,3 +2529,36 @@ terminal_screen_save_contents (TerminalScreen *screen, vte_terminal_write_contents_sync (VTE_TERMINAL (screen->terminal), stream, VTE_WRITE_DEFAULT, NULL, &error); } + + + +/** + * terminal_screen_has_foreground_process: + * @screen : A #TerminalScreen. + * + * Return value: %TRUE if there's a foreground process running in @screen. + **/ +gboolean +terminal_screen_has_foreground_process (TerminalScreen *screen) +{ + VtePty *pty; + int fd; + int fgpid; + + if (screen == NULL) + return FALSE; + + pty = vte_terminal_get_pty (VTE_TERMINAL (screen->terminal)); + if (pty == NULL) + return FALSE; + + fd = vte_pty_get_fd (pty); + if (fd == -1) + return FALSE; + + fgpid = tcgetpgrp (fd); + if (fgpid == -1 || fgpid == screen->pid) + return FALSE; + + return TRUE; +} diff --git a/terminal/terminal-screen.h b/terminal/terminal-screen.h index ad151b2..ab273cf 100644 --- a/terminal/terminal-screen.h +++ b/terminal/terminal-screen.h @@ -125,6 +125,8 @@ void terminal_screen_save_contents (TerminalScreen *scree GOutputStream *stream, GError *error); +gboolean terminal_screen_has_foreground_process (TerminalScreen *screen); + G_END_DECLS diff --git a/terminal/terminal-window.c b/terminal/terminal-window.c index 84c6303..a8f2450 100644 --- a/terminal/terminal-window.c +++ b/terminal/terminal-window.c @@ -755,16 +755,27 @@ terminal_window_confirm_close (TerminalWindow *window) gchar *message; gchar *markup; gint response; - gint n_tabs; - - n_tabs = gtk_notebook_get_n_pages (GTK_NOTEBOOK (window->priv->notebook)); - if (G_UNLIKELY (n_tabs < 2)) - return TRUE; + gint i, n_tabs; g_object_get (G_OBJECT (window->priv->preferences), "misc-confirm-close", &confirm_close, NULL); if (!confirm_close) return TRUE; + n_tabs = gtk_notebook_get_n_pages (GTK_NOTEBOOK (window->priv->notebook)); + confirm_close = FALSE; + for (i = 0; i < n_tabs; ++i) + { + TerminalScreen *screen = TERMINAL_SCREEN (gtk_notebook_get_nth_page (GTK_NOTEBOOK (window->priv->notebook), i)); + if (terminal_screen_has_foreground_process (screen)) + { + confirm_close = TRUE; + break; + } + } + + if (n_tabs < 2 && !confirm_close) + return TRUE; + dialog = gtk_dialog_new_with_buttons (_("Warning"), GTK_WINDOW (window), GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL, @@ -772,8 +783,30 @@ terminal_window_confirm_close (TerminalWindow *window) GTK_RESPONSE_CANCEL, NULL); - button = xfce_gtk_button_new_mixed ("window-close", _("Close T_ab")); - gtk_dialog_add_action_widget (GTK_DIALOG (dialog), button, GTK_RESPONSE_CLOSE); + if (n_tabs > 1) + { + /* multiple tabs */ + button = xfce_gtk_button_new_mixed ("window-close", _("Close T_ab")); + gtk_dialog_add_action_widget (GTK_DIALOG (dialog), button, GTK_RESPONSE_CLOSE); + + if (confirm_close) + { + /* and process running */ + message = g_strdup_printf (_("There are still processes running in some tabs.\n" + "Closing this window will kill all of them.")); + } + else + { + message = g_strdup_printf (_("This window has %d tabs open. Closing this window\n" + "will also close all its tabs."), n_tabs); + } + } + else + { + /* single tab, process running */ + message = g_strdup_printf (_("There is still a process running.\n" + "Closing this window will kill it.")); + } button = xfce_gtk_button_new_mixed ("application-exit", _("Close _Window")); gtk_dialog_add_action_widget (GTK_DIALOG (dialog), button, GTK_RESPONSE_YES); @@ -791,10 +824,8 @@ terminal_window_confirm_close (TerminalWindow *window) vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0); - message = g_strdup_printf (_("This window has %d tabs open. Closing this window\n" - "will also close all its tabs."), n_tabs); markup = g_strdup_printf ("<span weight=\"bold\" size=\"larger\">%s</span>\n\n%s", - _("Close all tabs?"), message); + n_tabs > 1 ? _("Close all tabs?") : _("Close window?"), message); g_free (message); label = g_object_new (GTK_TYPE_LABEL, @@ -2076,7 +2107,7 @@ terminal_window_action_set_title (GtkAction *action, G_CALLBACK (title_popover_close), window); } - gtk_widget_show_all (window->priv->title_popover); + gtk_widget_show_all (window->priv->title_popover); } -- To stop receiving notification emails like this one, please contact the administrator of this repository. _______________________________________________ Xfce4-commits mailing list [email protected] https://mail.xfce.org/mailman/listinfo/xfce4-commits
