Re: Differences between kinds of events
- From: Gnaural <gnaural users sourceforge net>
- To: gtk-app-devel-list gnome org
- Subject: Re: Differences between kinds of events
- Date: Tue, 11 Apr 2006 19:13:58 -0700 (PDT)
Thanks for the reply. Using gtk_widget_add_events()
was a good tip in general, and the order in which I
call things too. But unfortunately, they didn't help
solve the question I still see.
I'll paste a very short program illustrating what I
mean below, in which I set-up a button-press and a
key-press handler in the same way for drawingarea1,
but only the button-press responds. But if I merely
change "drawingarea1" to "window1" in the key-press
g_signal_connect(), it catches key presses just fine:
<code>
/* Compile with:
gcc main.c -o keytest `pkg-config --cflags --libs
gtk+-2.0`
*/
#include <gtk/gtk.h>
gboolean
on_drawingarea1_button_press_event(GtkWidget
*widget,
GdkEventButton
*event,
gpointer
user_data)
{
printf("button\n");
return FALSE;
}
gboolean
on_drawingarea1_key_press_event(GtkWidget *widget,
GdkEventKey *event,
gpointer user_data)
{
printf("Key\n");
return FALSE;
}
int main (int argc, char *argv[])
{
GtkWidget *window1;
GtkWidget *drawingarea1;
gtk_init (&argc, &argv);
window1 = gtk_window_new (GTK_WINDOW_TOPLEVEL);
drawingarea1 = gtk_drawing_area_new();
gtk_widget_add_events (drawingarea1,
GDK_BUTTON_PRESS_MASK |
GDK_KEY_PRESS_MASK);
gtk_container_add (GTK_CONTAINER (window1),
drawingarea1);
g_signal_connect ((gpointer) drawingarea1,
"button_press_event",
G_CALLBACK
(on_drawingarea1_button_press_event),
NULL);
g_signal_connect ((gpointer) drawingarea1,
"key_press_event",
G_CALLBACK
(on_drawingarea1_key_press_event),
NULL);
gtk_widget_show (drawingarea1);
gtk_widget_show (window1);
gtk_main ();
return 0;
}
</code>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]