Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

g_signal_connect for right mouse click?

Tags:

c

gtk

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);
like image 862
user3604070 Avatar asked Mar 19 '23 16:03

user3604070


1 Answers

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.

like image 128
Elias Van Ootegem Avatar answered Apr 02 '23 12:04

Elias Van Ootegem