Iah7 Actually it's possible to have a text inside the progress bar in gtk3 but with another widget.
This is what I managed to hack today with the GtkEntry widget.
I did not set it to run anything it's just a proof of concept.
Will probably use it on xfce.
gcc -Wall -g timer.c -o timer $(pkg-config --libs --cflags gtk+-3.0)
#include <stdio.h>
#include <string.h>
#include <gtk/gtk.h>
GtkWidget *switch_a;
GtkWidget *switch_b;
/* Determines to continue the timer or not */
static gboolean continue_timer = FALSE;
/* Determines if the timer has started */
static gboolean start_timer = TRUE;
/* Display seconds expired */
static int sec_expired = 30;
static void
_quit_cb (GtkWidget *button, gpointer data)
{
(void)button; (void)data; /* Avoid compiler warnings */
printf("Canceled\n");
gtk_main_quit();
return;
}
static void
_check_switch ()
{
if (gtk_switch_get_active (GTK_SWITCH(switch_a)) == 1)
printf("no_save=on\n");
else
printf("no_save=off\n");
if (gtk_switch_get_active (GTK_SWITCH(switch_b)) == 1)
printf("reboot=on\n");
else
printf("reboot=off\n");
}
static void
_shutdown (GtkWidget *button, gpointer data)
{
(void)button; (void)data; /* Avoid compiler warnings */
_check_switch();
gtk_main_quit();
}
static gboolean
_label_update(gpointer data)
{
GtkEntry *label = (GtkEntry*)data;
char buf[256];
memset(&buf, 0x0, 256);
snprintf(buf, 255, "Turning off computer in %d seconds.", --sec_expired);
if (sec_expired == 0)
{
_check_switch();
gtk_main_quit();
}
gtk_entry_set_text(GTK_ENTRY(label), buf);
gtk_entry_set_progress_fraction(GTK_ENTRY(label), (double)sec_expired / 30.0);
return continue_timer;
}
int main(void)
{
GtkWidget *window;
GtkWidget *box;
GtkWidget *box_a;
GtkWidget *box_b;
GtkWidget *boxl;
GtkWidget *shutdown_button;
GtkWidget *cancel_button;
GtkWidget *label;
GtkWidget *question;
GtkWidget *no_save;
GtkWidget *reboot;
gtk_init(NULL, NULL);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_widget_set_size_request(window, 250, 120);
gtk_window_set_resizable (GTK_WINDOW(window), FALSE);
gtk_window_set_keep_above (GTK_WINDOW (window), TRUE);
gtk_window_stick (GTK_WINDOW (window));
gtk_window_set_skip_taskbar_hint (GTK_WINDOW (window), TRUE);
gtk_window_set_title (GTK_WINDOW (window), "Shutdown");
g_signal_connect (G_OBJECT (window), "destroy",
G_CALLBACK (gtk_main_quit),
NULL);
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
box_a = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
box_b = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
boxl = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2);
gtk_box_set_homogeneous (GTK_BOX (box), TRUE);
gtk_container_add(GTK_CONTAINER(window),boxl);
question = gtk_label_new ("\nAre you sure you want to shutdown?");
label = gtk_entry_new ();
gtk_entry_set_text (GTK_ENTRY(label),
"Turning off computer in 30 seconds.");
gtk_entry_set_progress_fraction(GTK_ENTRY(label), 1.0);
gtk_entry_set_has_frame (GTK_ENTRY(label), FALSE);
gtk_entry_set_activates_default (GTK_ENTRY(label),
FALSE);
gtk_entry_set_overwrite_mode (GTK_ENTRY(label),
FALSE);
gtk_editable_set_editable (GTK_EDITABLE(label), FALSE);
gtk_widget_set_can_focus (GTK_WIDGET(label), FALSE);
gtk_widget_set_state_flags (GTK_WIDGET(label),
GTK_SELECTION_NONE, FALSE);
no_save = gtk_label_new ("No save");
reboot = gtk_label_new ("Reboot ");
switch_a = gtk_switch_new ();
switch_b = gtk_switch_new ();
gtk_box_pack_start (GTK_BOX(box_a), no_save, FALSE, FALSE, 10);
gtk_box_pack_start (GTK_BOX(box_a), switch_a, FALSE, FALSE, 10);
gtk_box_pack_start (GTK_BOX(box_b), reboot, FALSE, FALSE, 10);
gtk_box_pack_start (GTK_BOX(box_b), switch_b, FALSE, FALSE, 10);
shutdown_button = gtk_button_new_with_label("Shutdown");
g_signal_connect(G_OBJECT(shutdown_button), "clicked", G_CALLBACK(_shutdown), shutdown_button);
cancel_button = gtk_button_new_with_label("Cancel");
g_signal_connect(G_OBJECT(cancel_button), "clicked", G_CALLBACK(_quit_cb), NULL);
gtk_box_pack_start (GTK_BOX(boxl), question, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX(boxl), label, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX(boxl), box_a, TRUE, TRUE, 10);
gtk_box_pack_start (GTK_BOX(boxl), box_b, TRUE, TRUE, 10);
gtk_box_pack_start (GTK_BOX (box), cancel_button, TRUE, TRUE, 10);
gtk_box_pack_start (GTK_BOX(box), shutdown_button, TRUE, TRUE, 10);
gtk_box_pack_start (GTK_BOX(boxl), box, TRUE, TRUE, 10);
gtk_widget_show_all(window);
g_timeout_add_seconds(1, _label_update, label);
continue_timer = TRUE;
start_timer = TRUE;
gtk_main();
return 0;
}
Perhaps @vkareh has an idea about how to prevent text selection inside GtkEntry.