2013-07-02 12:06:03 +00:00
|
|
|
/*
|
|
|
|
* GStreamer
|
|
|
|
* Copyright (C) 2012 Matthew Waters <ystreet00@gmail.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "x11_event_source.h"
|
2013-11-27 06:52:46 +00:00
|
|
|
#include "gstgldisplay_x11.h"
|
2013-07-02 12:06:03 +00:00
|
|
|
|
2013-08-16 15:29:12 +00:00
|
|
|
extern gboolean gst_gl_window_x11_handle_event (GstGLWindowX11 * window_x11);
|
2013-07-02 12:06:03 +00:00
|
|
|
|
|
|
|
typedef struct _X11EventSource
|
|
|
|
{
|
|
|
|
GSource source;
|
|
|
|
GPollFD pfd;
|
|
|
|
uint32_t mask;
|
|
|
|
GstGLWindowX11 *window;
|
|
|
|
} X11EventSource;
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
x11_event_source_prepare (GSource * base, gint * timeout)
|
|
|
|
{
|
|
|
|
X11EventSource *source = (X11EventSource *) base;
|
|
|
|
gboolean retval;
|
|
|
|
|
|
|
|
*timeout = -1;
|
|
|
|
|
2013-11-27 06:52:46 +00:00
|
|
|
retval = XPending (source->window->device);
|
2013-07-02 12:06:03 +00:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
x11_event_source_check (GSource * base)
|
|
|
|
{
|
|
|
|
X11EventSource *source = (X11EventSource *) base;
|
|
|
|
gboolean retval;
|
|
|
|
|
2013-11-27 06:52:46 +00:00
|
|
|
retval = source->pfd.revents;
|
2013-07-02 12:06:03 +00:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
x11_event_source_dispatch (GSource * base, GSourceFunc callback, gpointer data)
|
|
|
|
{
|
|
|
|
X11EventSource *source = (X11EventSource *) base;
|
|
|
|
|
2013-08-16 15:29:12 +00:00
|
|
|
gboolean ret = gst_gl_window_x11_handle_event (source->window);
|
2013-07-02 12:06:03 +00:00
|
|
|
|
|
|
|
if (callback)
|
|
|
|
callback (data);
|
|
|
|
|
2013-08-16 15:29:12 +00:00
|
|
|
return ret;
|
2013-07-02 12:06:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GSourceFuncs x11_event_source_funcs = {
|
|
|
|
x11_event_source_prepare,
|
|
|
|
x11_event_source_check,
|
|
|
|
x11_event_source_dispatch,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
GSource *
|
|
|
|
x11_event_source_new (GstGLWindowX11 * window_x11)
|
|
|
|
{
|
|
|
|
X11EventSource *source;
|
|
|
|
|
|
|
|
source = (X11EventSource *)
|
|
|
|
g_source_new (&x11_event_source_funcs, sizeof (X11EventSource));
|
|
|
|
source->window = window_x11;
|
2013-11-27 06:52:46 +00:00
|
|
|
source->pfd.fd = ConnectionNumber (source->window->device);
|
2013-07-02 12:06:03 +00:00
|
|
|
source->pfd.events = G_IO_IN | G_IO_ERR;
|
|
|
|
g_source_add_poll (&source->source, &source->pfd);
|
|
|
|
|
|
|
|
return &source->source;
|
|
|
|
}
|