problem with callback
- From: "Richard Boaz" <riboaz xs4all nl>
- To: ammoises yahoo com mx
- Cc: gtk-list gnome org
- Subject: problem with callback
- Date: Fri, 21 Mar 2008 23:41:22 +0100 (CET)
you have gotten your panties into a serious twist.
start over:
when wanting to receive key press events in a drawing area, you must do
all of the following:
1. set up the drawing area to receive key press and/or release events.
2. set up the drawing area to receive enter and leave notify events.
3. when receiving an enter notify event, you must grab focus of the
drawing area and hold it until you receive the leave notify event, and
then let it go!
so, at creation of the drawing area:
// connect the signals, at least:
g_signal_connect (da, "key_press_event", G_CALLBACK (keyEvent), NULL);
g_signal_connect (da, "key_release_event", G_CALLBACK (keyEvent), NULL);
g_signal_connect (da, "enter_notify_event", G_CALLBACK (grabFocus), NULL);
g_signal_connect (da, "leave_notify_event", G_CALLBACK (grabFocus), NULL);
// set up the events to be received by the drawing area, at least:
gtk_widget_set_events (da, gtk_widget_get_events (da)
| GDK_LEAVE_NOTIFY_MASK
| GDK_ENTER_NOTIFY_MASK
| GDK_KEY_PRESS_MASK
| GDK_KEY_RELEASE_MASK);
// define you grabFocus() callback
gboolean grabFocus(GtkWidget *widget, GdkEvent *event, gpointer nil)
{ // we must grab the focus when mouse enters to receive key events
switch(event->type)
{
case GDK_ENTER_NOTIFY:
gtk_grab_add(GTK_WIDGET (widget));
break;
case GDK_LEAVE_NOTIFY:
gtk_grab_remove(GTK_WIDGET (widget));
break;
default:
break;
}
return TRUE;
}
do it like this and when the mouse is inside the drawing are, the drawing
are will receive all keyboard events. when the mouse is outside the
drawing area, the entry area assigned the current focus will receive the
keyboard events. clicking inside an entry area will always assign focus
to that entry area.
to answer your other question, g_signal_connect() returns the signal
handler id you are looking for. save it when creating the signal callback
and blocking and unblocking is easily done.
richard
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]