Search code examples
cgtkgtk3glib

(GLib) How to create and emit GSignals?


I am trying to create a wm based on XCB.I use GApplication for my base object.I try to create a new GSignal and emit it based on certain xcb events.The program compiles fine, but when I run it and the event happens I get an error : GLib-GObject-WARNING **: 09:45:01.395: ../glib/gobject/gsignal.c:3492: signal name 'pointer-motion' is invalid for instance '0x5597bbb9e890' of type 'GApplication'. Here is how I create the signal:

  g_signal_new ("pointer-motion",
                G_TYPE_FROM_CLASS (class),
                G_SIGNAL_DETAILED |
                G_SIGNAL_ACTION |
                G_SIGNAL_RUN_FIRST,
                0,
                NULL,
                NULL,
                NULL,
                G_TYPE_NONE,
                1,
                G_TYPE_POINTER);

Here is how I emit it:

g_signal_emit_by_name (fairy,
                       "pointer-motion",
                       motion_notify_event);

And this is the full source: https://pastebin.com/TMtQFwAb. Can somebody point me what I am doing wrong.


Solution

  • The signal code looks fine. The issue that the error message "signal is invalid for instance of type GApplication" is hinting at is that you never actually instantiate your object:

    fairy_wm_new (const gchar *id, GApplicationFlags flags)
    {
      return g_object_new (G_TYPE_APPLICATION,"application-id",id,"flags",flags,NULL);
    }
    

    This returns a pointer to a GApplication, not a FairyWM. Use FAIRY_TYPE_WM instead.