I have an application in which I have a Log in screen. There is a button for logging in. When pressed, the GtkButton
should be set to insensitive to give the user feedback.
After clicking the button, a login request is done via CURL. Because this is done synchronously, the button is not redrawn (and therefore will not (yet) appear insensitive) before sending the CURL request.
Since this CURL request could take up to 5 seconds, I want the user to get feedback that the button is clicked and cannot be clicked again.
How can I make the button insensitive after clicking without having to wait for it to be redrawn? Or is there an other approach I am not seeing?
static void on_login_pressed(GtkWidget *widget, GdkEvent *event, gpointer data)
{
gtk_widget_set_sensitive(GTK_WIDGET(login_cred_screen->login_button), FALSE);
//gtk_widget_queue_draw(GTK_WIDGET(login_cred_screen->login_button)); //have tried this, does not work right away
//this is where I need the button to be redrawn
g_signal_emit_by_name(login_cred_screen->login_button, "login-button-clicked"); //after this is where the CURL request is done
}
Although @BobMorane's is technically correct, the only proper way to solve this problem is to make the cURL request asynchronous (by running it in a different thread for example). The nature of having a UI thread implicitly requires you to handle blocking work in a different thread since the UI will block as well -unless you jump through hoops with unexpected consequences.