2007-07-06 09:56:01 -04:00
|
|
|
/* Clutter.
|
|
|
|
* An OpenGL based 'interactive canvas' library.
|
|
|
|
* Authored By Matthew Allum <mallum@openedhand.com>
|
|
|
|
* Copyright (C) 2006-2007 OpenedHand
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "clutter-stage-egl.h"
|
|
|
|
#include "clutter-backend-egl.h"
|
|
|
|
#include "clutter-egl.h"
|
|
|
|
|
|
|
|
#include "../clutter-backend.h"
|
|
|
|
#include "../clutter-event.h"
|
|
|
|
#include "../clutter-private.h"
|
|
|
|
#include "../clutter-debug.h"
|
|
|
|
#include "../clutter-main.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
2007-07-09 18:25:26 -04:00
|
|
|
#ifdef HAVE_TSLIB
|
|
|
|
#include <tslib.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef struct _ClutterEventSource ClutterEventSource;
|
2007-07-06 09:56:01 -04:00
|
|
|
|
|
|
|
struct _ClutterEventSource
|
|
|
|
{
|
|
|
|
GSource source;
|
|
|
|
|
|
|
|
ClutterBackend *backend;
|
2007-07-09 18:25:26 -04:00
|
|
|
GPollFD event_poll_fd;
|
|
|
|
#ifdef HAVE_TSLIB
|
|
|
|
struct tsdev *ts_device;
|
|
|
|
#endif
|
2007-07-06 09:56:01 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
static gboolean clutter_event_prepare (GSource *source,
|
|
|
|
gint *timeout);
|
|
|
|
static gboolean clutter_event_check (GSource *source);
|
|
|
|
static gboolean clutter_event_dispatch (GSource *source,
|
|
|
|
GSourceFunc callback,
|
|
|
|
gpointer user_data);
|
|
|
|
|
|
|
|
static GList *event_sources = NULL;
|
|
|
|
|
|
|
|
static GSourceFuncs event_funcs = {
|
|
|
|
clutter_event_prepare,
|
|
|
|
clutter_event_check,
|
|
|
|
clutter_event_dispatch,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static GSource *
|
|
|
|
clutter_event_source_new (ClutterBackend *backend)
|
|
|
|
{
|
|
|
|
GSource *source = g_source_new (&event_funcs, sizeof (ClutterEventSource));
|
|
|
|
ClutterEventSource *event_source = (ClutterEventSource *) source;
|
|
|
|
|
|
|
|
event_source->backend = backend;
|
|
|
|
|
|
|
|
return source;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_clutter_events_init (ClutterBackend *backend)
|
|
|
|
{
|
2007-07-09 18:25:26 -04:00
|
|
|
ClutterBackendEGL *backend_egl = CLUTTER_BACKEND_EGL (backend);
|
|
|
|
GSource *source;
|
2007-07-06 09:56:01 -04:00
|
|
|
ClutterEventSource *event_source;
|
|
|
|
|
2007-07-09 18:25:26 -04:00
|
|
|
#ifdef HAVE_TSLIB
|
|
|
|
/* FIXME LEAK on error paths */
|
2007-07-06 09:56:01 -04:00
|
|
|
source = backend_egl->event_source = clutter_event_source_new (backend);
|
|
|
|
event_source = (ClutterEventSource *) source;
|
|
|
|
|
2007-07-09 18:25:26 -04:00
|
|
|
event_source->ts_device = ts_open(g_getenv("TSLIB_TSDEVICE"), 0);
|
|
|
|
|
|
|
|
if (event_source->ts_device)
|
|
|
|
{
|
|
|
|
|
|
|
|
CLUTTER_NOTE (EVENT, "Opened '%s'", g_getenv("TSLIB_TSDEVICE"));
|
|
|
|
|
|
|
|
if (ts_config(event_source->ts_device))
|
|
|
|
{
|
|
|
|
g_warning ("ts_config() failed");
|
|
|
|
ts_close (event_source->ts_device);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_source_set_priority (source, CLUTTER_PRIORITY_EVENTS);
|
|
|
|
event_source->event_poll_fd.fd = ts_fd(event_source->ts_device);
|
|
|
|
event_source->event_poll_fd.events = G_IO_IN;
|
2007-07-06 09:56:01 -04:00
|
|
|
|
2007-07-09 18:25:26 -04:00
|
|
|
event_sources = g_list_prepend (event_sources, event_source);
|
2007-07-06 09:56:01 -04:00
|
|
|
|
2007-07-09 18:25:26 -04:00
|
|
|
g_source_add_poll (source, &event_source->event_poll_fd);
|
|
|
|
g_source_set_can_recurse (source, TRUE);
|
|
|
|
g_source_attach (source, NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
g_warning ("ts_open() failed opening %s'",
|
|
|
|
g_getenv("TSLIB_TSDEVICE") ?
|
|
|
|
g_getenv("TSLIB_TSDEVICE") : "None, TSLIB_TSDEVICE not set");
|
2007-07-06 09:56:01 -04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_clutter_events_uninit (ClutterBackend *backend)
|
|
|
|
{
|
|
|
|
ClutterBackendEGL *backend_egl = CLUTTER_BACKEND_EGL (backend);
|
|
|
|
|
|
|
|
if (backend_egl->event_source)
|
|
|
|
{
|
|
|
|
CLUTTER_NOTE (EVENT, "Destroying the event source");
|
|
|
|
|
2007-07-09 18:25:26 -04:00
|
|
|
ClutterEventSource *event_source =
|
|
|
|
(ClutterEventSource *) backend_egl->event_source;
|
|
|
|
|
|
|
|
#ifdef HAVE_TSLIB
|
|
|
|
ts_close (event_source->ts_device);
|
2007-07-06 09:56:01 -04:00
|
|
|
event_sources = g_list_remove (event_sources,
|
|
|
|
backend_egl->event_source);
|
2007-07-09 18:25:26 -04:00
|
|
|
#endif
|
2007-07-06 09:56:01 -04:00
|
|
|
g_source_destroy (backend_egl->event_source);
|
|
|
|
g_source_unref (backend_egl->event_source);
|
|
|
|
backend_egl->event_source = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-09 18:25:26 -04:00
|
|
|
static gboolean
|
|
|
|
clutter_event_prepare (GSource *source,
|
|
|
|
gint *timeout)
|
|
|
|
{
|
|
|
|
ClutterBackend *backend = ((ClutterEventSource *) source)->backend;
|
|
|
|
|
|
|
|
*timeout = -1;
|
|
|
|
|
|
|
|
return clutter_events_pending ();
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
clutter_event_check (GSource *source)
|
|
|
|
{
|
|
|
|
ClutterEventSource *event_source = (ClutterEventSource *) source;
|
|
|
|
ClutterBackend *backend = event_source->backend;
|
|
|
|
|
|
|
|
return ((event_source->event_poll_fd.revents & G_IO_IN)
|
|
|
|
|| clutter_events_pending ());
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
clutter_event_dispatch (GSource *source,
|
|
|
|
GSourceFunc callback,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
ClutterBackend *backend = ((ClutterEventSource *) source)->backend;
|
|
|
|
ClutterEventSource *event_source = (ClutterEventSource *) source;
|
|
|
|
ClutterEvent *event;
|
|
|
|
struct ts_sample tsevent;
|
|
|
|
ClutterMainContext *clutter_context;
|
2007-07-12 07:30:56 -04:00
|
|
|
static gint last_x, last_y;
|
2007-07-09 18:25:26 -04:00
|
|
|
|
|
|
|
clutter_context = clutter_context_get_default ();
|
|
|
|
#ifdef HAVE_TSLIB
|
|
|
|
/* FIXME while would be better here but need to deal with lockups */
|
|
|
|
if ((!clutter_events_pending()) &&
|
|
|
|
(ts_read(event_source->ts_device, &tsevent, 1) == 1))
|
|
|
|
{
|
2007-07-12 07:30:56 -04:00
|
|
|
/* Avoid sending too many events which are just pressure changes.
|
|
|
|
* We dont current handle pressure in events (FIXME) and thus
|
|
|
|
* event_button_generate gets confused generating lots of double
|
|
|
|
* and triple clicks.
|
|
|
|
*/
|
|
|
|
if (tsevent.pressure && last_x == tsevent.x && last_y == tsevent.y)
|
|
|
|
return;
|
|
|
|
|
2007-07-09 18:25:26 -04:00
|
|
|
event = clutter_event_new (CLUTTER_NOTHING);
|
|
|
|
|
2007-07-12 07:30:56 -04:00
|
|
|
last_x = event->button.x = tsevent.x;
|
|
|
|
last_y = event->button.y = tsevent.y;
|
|
|
|
|
2007-07-09 18:25:26 -04:00
|
|
|
event->button.time = 0;
|
|
|
|
event->button.modifier_state = 0;
|
|
|
|
event->button.button = 1;
|
|
|
|
|
|
|
|
if (tsevent.pressure)
|
|
|
|
event->button.type = event->type = CLUTTER_BUTTON_PRESS;
|
|
|
|
else
|
|
|
|
event->button.type = event->type = CLUTTER_BUTTON_RELEASE;
|
|
|
|
|
|
|
|
_clutter_event_button_generate (backend, event);
|
|
|
|
|
|
|
|
g_queue_push_head (clutter_context->events_queue, event);
|
2007-07-12 07:30:56 -04:00
|
|
|
|
2007-07-09 18:25:26 -04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Pop an event off the queue if any */
|
|
|
|
event = clutter_event_get ();
|
|
|
|
|
|
|
|
if (event)
|
|
|
|
{
|
|
|
|
/* forward the event into clutter for emission etc. */
|
|
|
|
clutter_do_event (event);
|
|
|
|
clutter_event_free (event);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|