gtk_widget_set_sensitive and mouse pointer



Hi All,

I had a small problem that was bugging me for a while, and I figured I'd share the results of my findings.

The problem was this:
You have several widgets inside of a container and you call gtk_widget_set_sensitive with false to gray out the container + all children. If you leave your mouse positioned over a button inside that container, and call gtk_widget_set_sensitive with true, you will no longer be able to click on that button.

The explanation is simple, the button widget has not received an enter signal after becoming sensitive.

To fix this, do the following after making the widget sensitive:
gint x,y;
GdkWindow *windowUnderMouse=gdk_window_at_pointer(&x,&y);
if(windowUnderMouse){
   GdkEventCrossing e;
   e.type=GDK_ENTER_NOTIFY;
   e.window=windowUnderMouse;
   e.send_event=1;
   e.subwindow=0;
   e.time=GDK_CURRENT_TIME;
   e.x=0;
   e.y=0;
   e.x_root=0;
   e.y_root=0;
   e.mode=GDK_CROSSING_NORMAL;
   e.detail=GDK_NOTIFY_UNKNOWN;
   e.focus=true;
   e.state=0;
   gdk_event_put((GdkEvent *)&e);
}

I'm actually somewhat surprised that something to handle something like this isn't built right into gtk_widget_set_sensitive.

Eric



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]