sardemff7 / libgwater

A collection of GSources
16 stars 4 forks source link

libgwater

libgwater provides several GSources to integrate various events to the GLib main loop.

Composition of a GSource

Each GSource is composed of three parts:

Non-Autotools setup are not covered upstream but should be easy enough to use.

Example usage of XCB GSource

  1. Create your project with Autotools files

  2. Add libgwater as a Git submodule

    git submodule add https://github.com/sardemff7/libgwater
  3. Add the m4 macro call to your configure.ac (with an additionnal package, xcb-util)

    GW_CHECK_XCB([xcb-util])
  4. Make sure aclocal will find the m4 file by adding the directory to ACLOCAL_AMFLAGS in your Makefile.am

    ACLOCAL_AMFLAGS = -I libgwater ${ACLOCAL_FLAGS}
  5. Include the Makefile.am snippet

    include $(top_srcdir)/libgwater/xcb.mk
  6. Use the Makefile.am variables

    xcb_example_client_SOURCES = client.c
    xcb_example_client_CFLAGS = $(GW_XCB_CFLAGS)
    xcb_example_client_LDADD = $(GW_XCB_LIBS)
  7. Use the GSource in your client.c

    #include <glib.h>
    #include <libgwater-xcb.h>
    
    gboolean
    callback(xcb_generic_event_t *event, gpointer user_data)
    {
        if ( event == NULL )
        {
            /* Error occured */
            return FALSE;
        }
        return TRUE;
    }
    
    int
    main()
    {
        GWaterXcbSource *source;
        GMainLoop *loop;
    
        loop = g_main_loop_new(NULL, FALSE);
        source = g_water_xcb_source_new(NULL, NULL, NULL, callback, NULL, NULL);
    
        g_main_loop_run(loop);
        g_main_loop_unref(loop);
    
        g_xcb_source_free(source);
    
        return 0;
    }

Dependencies

Licence

libgwater is licenced under the terms of the MIT license

Author / Contact

Morgane “Sardem FF7” Glidic (sardemff7+libgwater@sardemff7.net) — My other Free Software projects