Re: Propagation of key press events



I am trying to figure out how to get Shift+F10 to display an applet's context 
menu even if focus is in a widget within the applet rather the applet itself.

This does not work as the signal handler for the popup_menu signal returns void. 
Is it reasonable to ask that ihe signal handler return a gboolean so that the 
keypress can be propagated up to the applet?

Padraig

> 
> 
> As discussed earlier, here is a patch to propagate key press events up
> the heirarchy ... it's trivial except for some refcounting/reentrancy
> complications.
> 
> I tried using it to implement Ctrl-PageUp/Ctrl-PageDown in the
> notebook, and that worked fine.
> 
> I'm going to commit this tomorrow morning unless I hear strong
> objections and a good, equally simple, alternative suggestion about
> how to do keypress bindings on parent widgets.
> 
> Regards,
>                                         Owen
> 
> Index: gtk/gtkwindow.c
> ===================================================================
> RCS file: /cvs/gnome/gtk+/gtk/gtkwindow.c,v
> retrieving revision 1.164
> diff -u -p -r1.164 gtkwindow.c
> --- gtk/gtkwindow.c	2001/11/13 18:52:25	1.164
> +++ gtk/gtkwindow.c	2001/11/15 19:58:57
> @@ -3485,6 +3485,7 @@ gtk_window_key_press_event (GtkWidget   
>  			    GdkEventKey *event)
>  {
>    GtkWindow *window;
> +  GtkWidget *focus;
>    gboolean handled;
>  
>    g_return_val_if_fail (GTK_IS_WINDOW (widget), FALSE);
> @@ -3493,10 +3494,31 @@ gtk_window_key_press_event (GtkWidget   
>    window = GTK_WINDOW (widget);
>  
>    handled = FALSE;
> -  
> -  if (window->focus_widget && window->focus_widget != widget &&
> -      GTK_WIDGET_IS_SENSITIVE (window->focus_widget))
> -    handled = gtk_widget_event (window->focus_widget, (GdkEvent*) event);
> +
> +  focus = window->focus_widget;
> +  if (focus)
> +    g_object_ref (focus);
> +
> +  while (!handled &&
> +	 focus && focus != widget &&
> +	 gtk_widget_get_toplevel (focus) == widget)
> +    {
> +      GtkWidget *parent;
> +      
> +      if (GTK_WIDGET_IS_SENSITIVE (focus))
> +	handled = gtk_widget_event (focus, (GdkEvent*) event);
> +
> +      parent = focus->parent;
> +      if (parent)
> +	g_object_ref (parent);
> +      
> +      g_object_unref (focus);
> +
> +      focus = parent;
> +    }
> +
> +  if (focus)
> +    g_object_unref (focus);
>  
>    if (!handled)
>      handled = gtk_window_mnemonic_activate (window,
> _______________________________________________
> gtk-devel-list mailing list
> gtk-devel-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtk-devel-list




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