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

# I need to add a new signal to a GTK+ widget. Any idea?

If the signal you want to add may be beneficial for other GTK+ users, you may want to submit a patch that presents your changes. Check the tutorial for more information about adding signals to a widget class.

If you don't think it is the case or if your patch is not applied you'll have to use the `gtk_object_class_user_signal_new` function. `gtk_object_class_user_signal_new` allows you to add a new signal to a predefined GTK+ widget without any modification of the GTK+ source code. The new signal can be emited with `gtk_signal_emit` and can be handled in the same way as other signals.

Tim Janik posted this code snippet:

    static guint signal_user_action = 0;

    signal_user_action =
      gtk_object_class_user_signal_new (gtk_type_class (GTK_TYPE_WIDGET),
                        "user_action",
                        GTK_RUN_LAST | GTK_RUN_ACTION,
                        gtk_marshal_NONE__POINTER,
                        GTK_TYPE_NONE, 1,
                        GTK_TYPE_POINTER);

    void
    gtk_widget_user_action (GtkWidget *widget,
                            gpointer   act_data)
    {
      g_return_if_fail (GTK_IS_WIDGET (widget));

      gtk_signal_emit (GTK_OBJECT (widget), signal_user_action, act_data);
    }

If you want your new signal to have more than the classical gpointer parameter, you'll have to play with GTK+ marshallers.

<<< Previous | Home | Next >>>
I have my signal connected to the the (whatever) event, but it seems I don't catch it. What's wrong? | Up | Is it possible to get some text displayed which is truncated to fit inside its allocation?