Question

I got this code that works for the left mouse click on a button but how would I use to get the right mouse click signal:

g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(button-action), NULL);
Was it helpful?

Solution

A simple way to listen for any mouse clicks, be it left or right would be this:

g_signal_connect(
    G_OBJECT(button)
    "button-press-event",
    G_CALLBACK(btn_press_callback),
    NULL
);

Then, for the callback function:

gboolean btn_press_callback(GtkWidget *btn, GdkEventButton *event, gpointer userdata)
{
    if (event->type == GDK_BUTTON_PRESS  &&  event->button == 3)
    {//3 is right mouse btn
        //do stuff
        return true;//or false
    }
    if (event->type == GDK_BUTTON_PRESS  &&  event->button == 1)
    {//1 is left mouse btn
    }
}

And so on... More info here.

some examples, using GTK+-2 but still useful, can be found here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top