Re: gtk_grab_add() and key press events



Owen Taylor <otaylor redhat com> writes:

> While working on one of the older GTK+ bugs:
> 
>  (http://bugzilla.gnome.org/show_bug.cgi?id=424)
> 
> It came to my attention that there is a problem with key press
> events and gtk_grab_add() - when the grab is on a non-toplevel
> window, then the keyboard event is sent to the toplevel which
> the grab is in and processed normally, and is in no sense
> "grabbed."
> 
> I don't think this is correct behavior, and causes at least
> bug #424, and probably other problems. So, I've applied
> the following patch to the stable branch. 
> 
> The biggest problem I could see happening is if somebody
> is handling key press events without returning a proper
> return value - in that case, they could conceivably get
> the same key press twice.

>From a cursory glance it looks good.  If people are returning the
wrong value from their event handlers they deserve to lose, anyways.

I have cooked up a patch heavily based on your excellent description
of how GTK+ focusing works and on Jonathan's and Tim's patch.  The
whole patch does this:

	- Applies basically everything that JRB and Tim did.

	- Fixes the nasty hit-Tab-on-the-last-widget-and-everything-
          loses-focus situation.

	- Makes arrow keys do more reasonable things when used in box
          containers.

	- Makes GtkWindow and other bits of the code not ignore the
          return value from gtk_widget_activate().

	- Misc. stuff I can't remember but is in the ChangeLog
          anyways.

The patch is here:

	http://primates.ximian.com/~federico/misc/gtk+-focus.patch

I don't think the ChangeLog is there, so I'll post it at the end of
this mail.

I've been using it and it makes dialog boxes and windows *much* more
pleasant to use.  I would like to think it is a good candidate for
inclusion in both the stable and the development branches, so it would
be great if people could take a look.

Thanks,

  Federico

2001-01-20  Federico Mena Quintero  <federico ximian com>

	* gtk/gtkhbox.c (gtk_hbox_focus): New focus handler for horizontal
	boxes.
	(focus_along_children): Changes the focus for tab/left/right
	directions by walking the children list appropriately.
	(focus_outside): Changes the focus for up/down directions by a)
	giving up the focus in case we already have a (non-container)
	focus child; this makes pressing up/down in hboxes not focus
	another widget in the box; or b) by finding the child that is the
	most horizontally overlapping with the previously focused widget,
	which produces more intuitive results than the old method.

	* gtk/gtkvbox.c: Analogously.

	* gtk/gtkhbbox.c: Analogously.

	* gtk/gtkvbbox.c: Analogously.

2001-01-19  Federico Mena Quintero  <federico ximian com>

	Fixing the basic focus mechanism.

	* gtk/gtkcontainer.c (gtk_container_focus_up_down): Do not
	generate a list with NULL children by removing the invalid ones
	from it.  This means we must take a reference to the pointer to
	the first list element, not just a pointer to the first element.
	(gtk_container_focus_left_right): Likewise.
	(gtk_container_focus_tab): Likewise.
	(gtk_container_focus_move): We do not handle NULL children
	anymore.
	(gtk_container_focus_move): Do not skip containers without
	HAS_FOCUS.
	(gtk_container_focus): Initialize return_val to FALSE for if
	anyone screws up in the focus handler.

	* gtk/gtkwindow.c (gtk_window_key_press_event): Whenever we call
	gtk_widget_activate(), use its return value as the criterion for
	having handled the event.
	(gtk_window_activate_focus): Likewise.
	(gtk_window_activate_default): Likewise.
	(gtk_window_key_press_event): If our initial attempt at cycling
	the focus failed, restart from the beginning.

	* gtk/gtkentry.c (gtk_entry_key_press): Likewise.

	* gtk/gtkplug.c (gtk_plug_key_press_event): Likewise.
	(gtk_plug_key_press_event): When we initially send the event to
	the focus widget, see if it is sensitive and that it is not the
	plug itself.  After that, when handling the spacebar, see if the
	focus widget is sensitive before we activate it.  All of this
	makes the behavior consistent with that of GtkWindow.





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