Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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");
}

Expand Down Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/option.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/yad.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down