GTK+ FAQ
<<< Previous | Development with GTK+: general questions | Next >>>

# How do I catch a double click event? [GTK 2.x]

Tim Janik wrote to gtk-list (slightly modified):

Define a signal handler:

    gint
    signal_handler_event(GtkWidget *widget, GdkEventButton *event, gpointer func_data)
    {
      if (GTK_IS_BUTTON(widget) &&
           (event->type==GDK_2BUTTON_PRESS ||
            event->type==GDK_3BUTTON_PRESS) ) {
        printf("I feel %s clicked with button %d\n",
               event->type==GDK_2BUTTON_PRESS ? "double" : "triple",
               event->button);
      }

      return FALSE;
    }

And connect the handler to your object:

    {
      /* button init stuff */

      g_signal_connect(G_OBJECT(button),
                         "button_press_event",
                         G_CALLBACK(signal_handler_event),
                         NULL);

      /* and/or */

      g_signal_connect(G_OBJECT(button),
                         "button_release_event",
                         G_CALLBACK(signal_handler_event),
                         NULL);

      /* something else */
    }

and, Owen Taylor wrote:

"Note that a single button press will be received beforehand, and if you are doing this for a button, you will therefore also get a "clicked" signal for the button. (This is going to be true for any toolkit, since computers aren't good at reading one's mind.)"

<<< Previous | Home | Next >>>
How do I get the Window ID of a GtkWindow? [GTK 2.x] | Up | By the way, what are the differences between signals and events?