libgwater provides several GSources to integrate various events to the GLib main loop.
Each GSource is composed of three parts:
-
An m4 macro for Autoconf:
GW_CHECK_<SOURCE_NAME>
It takes two optional arguments:- Additionnal
pkg-config
packages to check - Additionnal headers to check
- Additionnal
-
A
Makefile.am
snippet for Automake:libgwater/<source-name>.mk
You have to include it in your
Makefile.am
. It defines two variables:GW_<SOURCE_NAME>_CFLAGS
: contains all the neededCFLAGS
(including those from thepkg-config
packages you passed to the m4 macro)GW_<SOURCE_NAME>_LIBS
: contains all the neededLIBS
(including those from thepkg-config
packages you passed to the m4 macro)
This snippet is using Automake 1.14 features and Libtool. If you do not use both in your project, you need to adapt and ship it in your project.
-
A really basic API:
- A
GWater<SourceName>Source
opaque struct - One or more
g_water_<source_name>_source_new()
constructor for said struct - One free function
g_water_<source_name>_source_free()
- Usually a getter, to access the underlaying struct used by the communication library
- A
Non-Autotools setup are not covered upstream but should be easy enough to use.
-
Create your project with Autotools files
-
Add libgwater as a Git submodule
git submodule add https://github.com/sardemff7/libgwater
-
Add the m4 macro call to your
configure.ac
(with an additionnal package,xcb-util
)GW_CHECK_XCB([xcb-util])
-
Make sure aclocal will find the m4 file by adding the directory to
ACLOCAL_AMFLAGS
in yourMakefile.am
ACLOCAL_AMFLAGS = -I libgwater ${ACLOCAL_FLAGS}
-
Include the
Makefile.am
snippetinclude $(top_srcdir)/libgwater/xcb.mk
-
Use the
Makefile.am
variablesxcb_example_client_SOURCES = client.c xcb_example_client_CFLAGS = $(GW_XCB_CFLAGS) xcb_example_client_LDADD = $(GW_XCB_LIBS)
-
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; }
- Common dependencies
- GLib 2.36 (or newer)
- Wayland source
- libwayland 1.1.91 (or newer)
- XCB source
- libxcb
- MPD source
- libmpdclient2
- ALSA Mixer source
- alsa-lib
- Netlink protocol source
- libnl-3.0
- Windows source
Windows.h
libgwater is licenced under the terms of the MIT license
Morgane “Sardem FF7” Glidic (sardemff7+libgwater@sardemff7.net) — My other Free Software projects