Skip to content

Commit

Permalink
Add Windows source
Browse files Browse the repository at this point in the history
Signed-off-by: Quentin Glidic <sardemff7+git@sardemff7.net>
  • Loading branch information
sardemff7 committed Oct 29, 2015
1 parent 58bd71a commit 50a0f8a
Show file tree
Hide file tree
Showing 4 changed files with 194 additions and 0 deletions.
4 changes: 4 additions & 0 deletions libgwater.m4
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,7 @@ AC_DEFUN([GW_CHECK_ALSA_MIXER], [
AC_DEFUN([GW_CHECK_NL], [
_GW_CHECK([nl], [libnl-3.0 $1], [linux/netlink.h $2])
])

AC_DEFUN([GW_CHECK_WIN], [
_GW_CHECK([win], [$1], [Windows.h $2])
])
23 changes: 23 additions & 0 deletions win.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
noinst_LTLIBRARIES += \
%D%/libgwater-win.la

%C%_libgwater_win_la_SOURCES = \
%D%/win/libgwater-win.c \
%D%/win/libgwater-win.h

%C%_libgwater_win_la_CFLAGS = \
$(AM_CFLAGS) \
$(GW_WIN_INTERNAL_CFLAGS)


%C%_libgwater_win_la_LIBADD = \
$(GW_WIN_INTERNAL_LIBS)

GW_WIN_CFLAGS = \
-I$(srcdir)/%D%/win \
$(GW_WIN_INTERNAL_CFLAGS)

GW_WIN_LIBS = \
%D%/libgwater-win.la \
$(GW_WIN_INTERNAL_LIBS)

128 changes: 128 additions & 0 deletions win/libgwater-win.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*
* libgwater-win - Windows GSource
*
* Copyright © 2012-2015 Quentin "Sardem FF7" Glidic
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */

#ifdef G_LOG_DOMAIN
#undef G_LOG_DOMAIN
#endif /* G_LOG_DOMAIN */
#define G_LOG_DOMAIN "GWaterWin"

#include <glib.h>

#include <Windows.h>

#include "libgwater-win.h"

struct _GWaterWinSource {
GSource source;
GPollFD fd;
guint events;
};

static gboolean
_g_water_win_source_prepare(GSource *source, gint *timeout)
{
GWaterWinSource *self = (GWaterWinSource *)source;
*timeout = -1;
return GetQueueStatus(self->events);
}

static gboolean
_g_water_win_source_check(GSource *source)
{
GWaterWinSource *self = (GWaterWinSource *)source;

gboolean ret = FALSE;
if ( self->fd.revents & G_IO_IN )
{
MSG msg;
ret = PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
}

return ret;
}

static gboolean
_g_water_win_source_dispatch(GSource *source, GSourceFunc callback, gpointer user_data)
{
MSG msg;
while ( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) )
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

return TRUE;
}

static void
_g_water_win_source_finalize(GSource *source)
{
}

static GSourceFuncs _g_water_win_source_funcs = {
_g_water_win_source_prepare,
_g_water_win_source_check,
_g_water_win_source_dispatch,
_g_water_win_source_finalize
};

GWaterWinSource *
g_water_win_source_new(GMainContext *context, guint events)
{
GSource *source;
GWaterWinSource *self;

source = g_source_new(&_g_water_win_source_funcs, sizeof(GWaterWinSource));
self = (GWaterWinSource *)source;
self->events = events;

self->fd.fd = G_WIN32_MSG_HANDLE;
self->fd.events = G_IO_IN|G_IO_HUP;
g_source_add_poll(source, &self->fd);

g_source_attach(source, context);

return self;
}

void
g_water_win_source_ref(GWaterWinSource *self)
{
g_return_if_fail(self != NULL);

g_source_ref((GSource *)self);
}

void
g_water_win_source_unref(GWaterWinSource *self)
{
g_return_if_fail(self != NULL);

g_source_unref((GSource *)self);
}
39 changes: 39 additions & 0 deletions win/libgwater-win.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* libgwater-win - Windows GSource
*
* Copyright © 2012-2015 Quentin "Sardem FF7" Glidic
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/

#ifndef __G_WATER_WIN_H__
#define __G_WATER_WIN_H__

G_BEGIN_DECLS

typedef struct _GWaterWinSource GWaterWinSource;

GWaterWinSource *g_water_win_source_new(GMainContext *context, guint events);
void g_water_win_source_ref(GWaterWinSource *self);
void g_water_win_source_unref(GWaterWinSource *self);

G_END_DECLS

#endif /* __G_WATER_WIN_H__ */

0 comments on commit 50a0f8a

Please sign in to comment.