diff --git a/src/main.c b/src/main.c index edf6ebf..d518f11 100644 --- a/src/main.c +++ b/src/main.c @@ -129,9 +129,17 @@ btn_cb (GtkWidget *b, gchar *cmd) static gboolean timeout_cb (gpointer data) { - static guint count = 1; + static guint count = 0; + static gboolean initialized = FALSE; GtkWidget *w = (GtkWidget *) data; + /* Initialize count only once, accounting for elapsed time from previous dialog */ + if (!initialized) + { + count = options.data.timeout_elapsed + 1; + initialized = TRUE; + } + if (options.data.timeout < count) { yad_exit (YAD_RESPONSE_TIMEOUT); @@ -463,8 +471,15 @@ create_dialog (void) if (G_LIKELY (options.data.to_indicator) && strcasecmp (options.data.to_indicator, "none") != 0) { + gdouble initial_fraction = 1.0; + topb = gtk_progress_bar_new (); - gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (topb), 1.0); + + /* Calculate initial fraction accounting for elapsed time */ + if (options.data.timeout_elapsed > 0 && options.data.timeout_elapsed < options.data.timeout) + initial_fraction = (gdouble)(options.data.timeout - options.data.timeout_elapsed) / (gdouble)options.data.timeout; + + gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (topb), initial_fraction); gtk_widget_set_name (topb, "yad-timeout-indicator"); } @@ -508,7 +523,13 @@ create_dialog (void) if (SHOW_REMAIN) #endif { - gchar *lbl = g_strdup_printf (_("%d sec"), options.data.timeout); + guint remaining = options.data.timeout; + + /* Account for elapsed time in initial label */ + if (options.data.timeout_elapsed > 0 && options.data.timeout_elapsed < options.data.timeout) + remaining = options.data.timeout - options.data.timeout_elapsed; + + gchar *lbl = g_strdup_printf (_("%d sec"), remaining); gtk_progress_bar_set_show_text (GTK_PROGRESS_BAR (topb), TRUE); gtk_progress_bar_set_text (GTK_PROGRESS_BAR (topb), lbl); g_free (lbl); diff --git a/src/option.c b/src/option.c index 11e48e5..c4de235 100644 --- a/src/option.c +++ b/src/option.c @@ -111,6 +111,8 @@ static GOptionEntry general_options[] = { N_("Set dialog timeout in seconds"), N_("TIMEOUT") }, { "timeout-indicator", 0, 0, G_OPTION_ARG_STRING, &options.data.to_indicator, N_("Show remaining time indicator (top, bottom, left, right)"), N_("POS") }, + { "timeout-elapsed", 0, 0, G_OPTION_ARG_INT, &options.data.timeout_elapsed, + N_("Set elapsed time for timeout continuation"), N_("SECONDS") }, { "text", 0, G_OPTION_FLAG_NOALIAS, G_OPTION_ARG_STRING, &options.data.dialog_text, N_("Set the dialog text"), N_("TEXT") }, { "text-width", 0, G_OPTION_FLAG_NOALIAS, G_OPTION_ARG_INT, &options.data.text_width, @@ -1667,6 +1669,7 @@ yad_options_init (void) options.data.icon_theme = NULL; options.data.expander = NULL; options.data.timeout = 0; + options.data.timeout_elapsed = 0; options.data.to_indicator = NULL; options.data.hscroll_policy = GTK_POLICY_AUTOMATIC; options.data.vscroll_policy = GTK_POLICY_AUTOMATIC; diff --git a/src/yad.h b/src/yad.h index 649ba4f..565c20f 100644 --- a/src/yad.h +++ b/src/yad.h @@ -238,6 +238,7 @@ typedef struct { gboolean negy; gchar *geometry; guint timeout; + guint timeout_elapsed; /* Time already elapsed from previous dialog */ gchar *to_indicator; gchar *dialog_text; guint text_width;