From bab82948507dacfff804e11e376b00d7a5e12f04 Mon Sep 17 00:00:00 2001 From: Logan Rathbone Date: Sat, 4 Feb 2023 07:51:04 -0500 Subject: Prevent ZENITY_TIMEOUT from clashing with custom response IDs Redefine ZENITY_TIMEOUT response ID as INT_MAX Also, add and use ZENITY_TIMEOUT_DEFAULT exit status (hardcoded to 5 to keep consistent with what it has happened to be for the entire 3.x release cycle; POLA and all). See #48 --- src/util.c | 12 ++++++++++-- src/zenity.h | 9 ++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/util.c b/src/util.c index 2887fd96..a242526a 100644 --- a/src/util.c +++ b/src/util.c @@ -49,6 +49,14 @@ #define ZENITY_ERROR_DEFAULT -1 #define ZENITY_EXTRA_DEFAULT 127 +/* This exit code number is arbitrary, but since for the entire 3.x release + * cycle, zenity would essentially exit(ZENITY_TIMEOUT), which happened to be + * defined as 5 based on where it was placed in the enum sequence. So + * hardcoding it as 5 now in case any pre-existing scripts relied upon that + * being the exit status for timeouts. + */ +#define ZENITY_TIMEOUT_DEFAULT 5 + GtkBuilder * zenity_util_load_ui_file (const gchar *root_widget, ...) { va_list args; @@ -298,7 +306,7 @@ zenity_util_return_exit_code (ZenityExitCode value) { if (!env_var) env_var = g_getenv ("DIALOG_TIMEOUT"); if (!env_var) - retval = ZENITY_TIMEOUT; + retval = ZENITY_TIMEOUT_DEFAULT; break; default: @@ -412,7 +420,7 @@ zenity_util_timeout_handle (gpointer data) { gtk_dialog_response (dialog, ZENITY_TIMEOUT); else { gtk_main_quit (); - exit (ZENITY_TIMEOUT); + exit (ZENITY_TIMEOUT_DEFAULT); } return FALSE; } diff --git a/src/zenity.h b/src/zenity.h index 404eec77..c50a76bd 100644 --- a/src/zenity.h +++ b/src/zenity.h @@ -33,7 +33,14 @@ typedef enum { ZENITY_ESC, ZENITY_ERROR, ZENITY_EXTRA, - ZENITY_TIMEOUT + /* Previously, this was not specified to any value, which could cause it to + * clash with the custom response ID that happened to match it. We could set + * this to a negative value tha doesn't clash with one of GtkDialog's + * predefined response ID's as it's doubtful GTK will ever extend the GtkDialog + * API at this stage -- but technically negative values are reserved for the + * library and positive values for applications, according to gtkdialog.c + */ + ZENITY_TIMEOUT = INT_MAX } ZenityExitCode; typedef struct { -- cgit From 47b1a40e88e8b4b5ad4ae4b10dd42606145eb110 Mon Sep 17 00:00:00 2001 From: Logan Rathbone Date: Sat, 4 Feb 2023 10:38:36 -0500 Subject: msg: Set max-width-chars to relatively small value if --width specified This should fix a small regression caused by 25a92fff, in which dialog texts can be stretched out too long if --width *is* specified. See also #42 --- src/msg.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/msg.c b/src/msg.c index 92651525..641dad6c 100644 --- a/src/msg.c +++ b/src/msg.c @@ -199,8 +199,24 @@ zenity_msg (ZenityData *data, ZenityMsgData *msg_data) { gtk_window_set_default_size ( GTK_WINDOW (dialog), data->width, data->height); - if (data->width > -1) + if (data->width > -1) { gtk_widget_set_size_request (GTK_WIDGET (text), data->width, -1); + + if (!msg_data->no_wrap) { + /* Minimum width */ + gtk_label_set_width_chars (GTK_LABEL(text), 10); + + /* If we don't set max-width-chars, gtk may set the natural width + * of the label to be wider than what we want for the window. So we + * want to set it to something relatively small, because, + * according to TFM, even if max_width_chars is set to anything + * other than -1, for wrapping labels the label will still be + * rewrapped to use all of the available width. So we'll just set + * it to the same value as width-chars for posterity. + */ + gtk_label_set_max_width_chars (GTK_LABEL(text), 10); + } + } else if (!msg_data->ellipsize && !msg_data->no_wrap) { /* The magic number 60 is taken from gtk+/gtk/ui/gtkmessagedialog.ui with 10 as a minimum width. */ -- cgit From 0de4da6691c526f761a7dcdfb50bac053f03b8ee Mon Sep 17 00:00:00 2001 From: Logan Rathbone Date: Thu, 10 Aug 2023 11:29:13 -0400 Subject: tree: Set search column to 1 for check/radiolists We expand 91a6c185 to apply to check/radiolists as the first column (ie, true/false) gets selected as the search column by default unless it is explicitly set. nb: Although acc. to the GtkTreeView docs, the default property for 'search-column' is -1 (ie, disable search) it seems that gtktreeview.c will auotmatically select the first available column as being searchable (ie, 0) so it is not necessary to explicitly set this property to 0 in other non-image/radio/checklist cases. Fixes #49 --- src/tree.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/tree.c b/src/tree.c index 7d98ad2d..d3efe573 100644 --- a/src/tree.c +++ b/src/tree.c @@ -642,10 +642,10 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) { tree_data->editable); } - /* GTK will automatically pick the image column as the search column - * despite it not containing any user readable text. - * Set it to second column instead if it exists. */ - if (tree_data->imagebox && n_columns > 1) { + /* GTK will automatically pick the image/checkbox/radiobox column as the + * search column despite it not containing any user readable text. + * Set it to second column instead if any of the above exists. */ + if ((tree_data->imagebox || tree_data->radiobox || tree_data->checkbox) && n_columns > 1) { gtk_tree_view_set_search_column (GTK_TREE_VIEW (tree_view), 1); } -- cgit