Re: [gtk-list] Mouse buttons in callbacks



Robert S. Mallozzi writes:
 > 
 > Hello,
 > 
 > I would like to use the different mouse buttons within
 > a gtk button callback to do different tasks.  How do I
 > discriminate among the different mouse buttons in the
 > callback function? 

In your event handler do something like the following (basically
stolen from test-gnome/canvas-primatives.c):

gint my_event_handler( ... , GdkEvent *event, ...) 
{
	...
	switch (event->type) {
	case GDK_BUTTON_PRESS:
		switch (event->button.button) {
		case 1:
			g_print("button 1 pressed\n");
			break;
		case 2:
			g_print("button 2 pressed\n");
			break;
		...
		}
	case GDK_BUTTON_RELEASE:
		switch (event->button.button) {
		case 1:
			g_print("button 1 released\n");
			break;
		case 2:
			g_print("button 2 released\n");
			break;
		...
	...
	}
}

 > Currently, I have button_press_events,
 > and button_release_events registered with the button, and
 > this works OK, execpt I must also trap 
 > enter_notify_events, and leave_notify_events to ensure that
 > mouse button 1 executes its command only upon button release.
 > This involves a static variable in the callback to keep 
 > track of whether the cursor is on the button when it is
 > released.  Surely there is a simple way to find which
 > button was pressed when in a "regular" callback function?

Isn't it true that the widget will only get an event if the pointer is 
over that widget?  May have to check this....

HTH,
-Brett.



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