After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 446579 - GtkButton widget does not grab focus in a certain situation.
GtkButton widget does not grab focus in a certain situation.
Status: RESOLVED DUPLICATE of bug 56070
Product: gtk+
Classification: Platform
Component: Widget: Other
2.8.x
Other All
: Normal minor
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2007-06-12 01:53 UTC by Georg Grafendorfer
Modified: 2007-06-12 09:40 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Georg Grafendorfer 2007-06-12 01:53:46 UTC
Please describe the problem:
It's very easy and actually i don't know if it's a real bug, but this behaviour does not seem desirable to me:

GtkButton can't grab focus after gtk_widget_set_sensitive (button, TRUE) if you don't leave the button, the best to understand what i want to say is to look at the easy program above.


Steps to reproduce:
Just try it out:
 
// gcc -Wall -lgmp `pkg-config --cflags --libs gtk+-2.0`
#include <stdio.h>
#include <gtk/gtk.h>

GtkWindow *window; 
GtkButton *button;

int delete_event_window (GtkWidget *unused1, GdkEvent *unused2, gpointer unused3)
{
  gtk_main_quit ();
  return TRUE;
}

void computation_on_off (GtkButton *button, gpointer unused)
{
  gtk_widget_set_sensitive (GTK_WIDGET (button), FALSE);
  g_print ("Hallo\n");
  gtk_widget_set_sensitive (GTK_WIDGET (button), TRUE);
}



int main (int argc, char *argv[])
{
  gtk_init(&argc, &argv);

  window = g_object_new(GTK_TYPE_WINDOW,
		        "window-position", GTK_WIN_POS_CENTER,
		        NULL);

  button = g_object_new (GTK_TYPE_BUTTON,
		         "label", "start",
	                 NULL);

  gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (button));

  gtk_widget_show_all (GTK_WIDGET (window));

  g_signal_connect (G_OBJECT (window), "delete_event",
		    G_CALLBACK (delete_event_window), NULL);
  g_signal_connect (G_OBJECT (button), "clicked",
		    G_CALLBACK (computation_on_off), NULL);


  gtk_main();

  return 1;
}



/* void computation_on_off (GtkButton *button, gpointer unused) */
/* { */
/*   g_print ("State: %d\n", GTK_WIDGET_STATE (button)); */
/*   gtk_widget_set_sensitive (GTK_WIDGET (button), FALSE); */
/*   g_print ("State: %d\n", GTK_WIDGET_STATE (button)); */
/*   g_print ("Hallo\n"); */
/*   gtk_widget_set_sensitive (GTK_WIDGET (button), TRUE); */
/*   if (GTK_WIDGET_CAN_FOCUS (button)) g_print ("Ja\n"); */
/*   g_print ("State: %d\n", GTK_WIDGET_STATE (button)); */
/*   gtk_widget_grab_focus (GTK_WIDGET (button)); */
/*   g_print ("State: %d\n", GTK_WIDGET_STATE (button)); */
/* } */



Actual results:
It's all about the signal handler computation_on_off, if you click the button the string "hallo" is printed to stdout as desired, but then if you stay with the mouse pointer on the button and click again, nothing is happening, only when you leave the button and enter again it's working as desired, you can use the outdocumented function at the end for a bit analysing, the button can't grab the focus after gtk_widget_set_sensitive (button, TRUE) unless you leave the button.



Expected results:
I would expect of course that after the command gtk_widget_set_sensitive (button, TRUE) the button is "active" again.

Does this happen every time?
yes

Other information:
This is just an additional explanation why i need this behaviour:

I use the button to start and stop a thread which performs heavy computation, starting the thread is actually a fast operation and therefore no problem, but as i do not know a explicit command to stop a thread i'm setting a global gboolean variable which the thread is checking out from time to time and then stops it self, in the signal handler (actually in an idle function which is not embeeded in an gdk_thread environmenti, invoked by the signal handler) the thread is joined, this can take some time, therefore i wanted to deactivate the button until the thread is stoped (to not get confused with global variables and to not start another thread until this one is over), first i used g_signal_handler_block to perform this task until i found the more elegant way with gtk_widget_set_sensitive, but this does not behave as expected, when i start the thread i have to leave the button and enter it again to stop the thread, otherwise there is no reaction, just the appearence of the button changes a bit (try it out).

I think my expectations are quite naturally, i'm a mathematician and not a software expert, this is for my diploma thesis and my first project bigger than "hello world" at all, so there may be better ways to do this, mainly i'm wondering that there is no command to stop a thread from outside. Or is there?

Thank you very much for reading my report and all the great work on gtk at all!!! I hope i did not waste your time to much and would be happy if you could give me at least a short response if i really discovered undesired behaviour or if i'm just a fool :-)

To my first bug report (to xfce) i got no answer at all, not even a "your report is the worst i have ever seen" or "allready fixed" which was a bit disappointing to me as i'm really  willed to contribute to free and open source software.

Greetings, Georg
Comment 1 Emmanuele Bassi (:ebassi) 2007-06-12 09:40:37 UTC
Thanks for the bug report. This particular bug has already been reported into our bug tracking system, but please feel free to report any further bugs you find.


*** This bug has been marked as a duplicate of 56070 ***