Re: Notification of changes in has-focus property



"Padraig O'Briain" <Padraig Obriain Sun COM> writes:

> I am trying to use the notify signal generated when the "has-focus"
> property changes on a GtkWidget to become aware of when a widget
> gains or loses focus. I have not been successful as it seems that
> the calls to g_object_notify (G_OBJECT (widget), "has_focus") are
> not made when the has-focus property changes.

Actually, the simple and reliable way of catching focus changes
is listening to ::focus_in_event, ::focus_out_event.

But, yes, if we have a has-focus property, we should properly
notify on changes to it.
 
> Is the following change reasonable?

> ===================================================================
> RCS file: /cvs/gnome/gtk+/gtk/gtkwidget.c,v
> retrieving revision 1.214
> diff -u -p -r1.214 gtkwidget.c
> --- gtkwidget.c 2001/05/03 20:11:07     1.214
> +++ gtkwidget.c 2001/05/11 12:27:32
> @@ -2511,6 +2511,7 @@ gtk_widget_real_focus_in_event (GtkWidge
>                                  GdkEventFocus *event)
>  {
>    GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_FOCUS);
> +  g_object_notify (G_OBJECT (widget), "has_focus");
>    gtk_widget_queue_draw (widget);
>  
>    return FALSE;
> @@ -2521,6 +2522,7 @@ gtk_widget_real_focus_out_event (GtkWidg
>                                   GdkEventFocus *event)
>  {
>    GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_FOCUS);
> +  g_object_notify (G_OBJECT (widget), "has_focus");
>    gtk_widget_queue_draw (widget);
>  
>    return FALSE;

These are reasonable, but not complete; there was no default handler
for focus_in/focus_out for GTK+-1.2, so many widgets override
these signals and don't chain up.

Rather than adding the notification to all these widgets or requiring
widgets to chain up, it might make sense to move both the flag setting
and the notification gtk_window_real_set_focus().

> @@ -2951,7 +2953,6 @@ gtk_widget_grab_focus (GtkWidget *widget
>  
>    g_object_ref (G_OBJECT (widget));
>    gtk_signal_emit (GTK_OBJECT (widget), widget_signals[GRAB_FOCUS]);
> -  g_object_notify (G_OBJECT (widget), "has_focus");
>    g_object_unref (G_OBJECT (widget));
>  }

Yes, this one is extraneous. grab_focus() is a request, not an action.

Regards,
                                       Owen




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