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
|
2010-03-01 07:56:10 -05:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*
|
2007-07-06 09:56:01 -04:00
|
|
|
*/
|
|
|
|
|
2007-10-12 04:17:00 -04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2007-07-06 09:56:01 -04:00
|
|
|
#include "config.h"
|
2007-10-12 04:17:00 -04:00
|
|
|
#endif
|
2007-07-06 09:56:01 -04:00
|
|
|
|
|
|
|
#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;
|
|
|
|
|
2010-02-27 04:42:42 -05:00
|
|
|
ClutterBackendEGL *backend;
|
|
|
|
GPollFD event_poll_fd;
|
|
|
|
|
2007-07-09 18:25:26 -04:00
|
|
|
#ifdef HAVE_TSLIB
|
|
|
|
struct tsdev *ts_device;
|
|
|
|
#endif
|
2007-07-06 09:56:01 -04:00
|
|
|
};
|
|
|
|
|
2010-06-17 19:18:02 -04:00
|
|
|
#ifdef HAVE_TSLIB
|
|
|
|
|
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 *
|
2010-02-27 04:42:42 -05:00
|
|
|
clutter_event_source_new (ClutterBackendEGL *backend)
|
2007-07-06 09:56:01 -04:00
|
|
|
{
|
|
|
|
GSource *source = g_source_new (&event_funcs, sizeof (ClutterEventSource));
|
|
|
|
ClutterEventSource *event_source = (ClutterEventSource *) source;
|
|
|
|
|
|
|
|
event_source->backend = backend;
|
|
|
|
|
|
|
|
return source;
|
|
|
|
}
|
|
|
|
|
2008-05-15 10:31:43 -04:00
|
|
|
static guint32
|
|
|
|
get_backend_time (void)
|
|
|
|
{
|
|
|
|
ClutterBackendEGL *backend_egl;
|
|
|
|
|
|
|
|
backend_egl = CLUTTER_BACKEND_EGL (clutter_get_default_backend ());
|
|
|
|
|
2008-06-06 10:21:22 -04:00
|
|
|
return g_timer_elapsed (backend_egl->event_timer, NULL) * 1000;
|
2008-05-15 10:31:43 -04:00
|
|
|
}
|
2010-06-17 19:18:02 -04:00
|
|
|
#endif
|
2008-05-15 10:31:43 -04:00
|
|
|
|
2007-07-06 09:56:01 -04:00
|
|
|
void
|
2010-02-27 04:42:42 -05:00
|
|
|
_clutter_events_egl_init (ClutterBackendEGL *backend_egl)
|
2007-07-06 09:56:01 -04:00
|
|
|
{
|
2010-06-17 19:18:02 -04:00
|
|
|
#ifdef HAVE_TSLIB
|
2007-07-06 09:56:01 -04:00
|
|
|
ClutterEventSource *event_source;
|
2010-02-27 04:42:42 -05:00
|
|
|
const char *device_name;
|
|
|
|
GSource *source;
|
2007-07-06 09:56:01 -04:00
|
|
|
|
2008-05-15 10:31:43 -04:00
|
|
|
CLUTTER_NOTE (EVENT, "Starting timer");
|
|
|
|
g_assert (backend_egl->event_timer != NULL);
|
|
|
|
g_timer_start (backend_egl->event_timer);
|
|
|
|
|
2010-02-27 04:42:42 -05:00
|
|
|
source = backend_egl->event_source = clutter_event_source_new (backend_egl);
|
2007-07-06 09:56:01 -04:00
|
|
|
event_source = (ClutterEventSource *) source;
|
|
|
|
|
2010-02-27 04:42:42 -05:00
|
|
|
device_name = g_getenv ("TSLIB_TSDEVICE");
|
|
|
|
if (device_name == NULL || device_name[0] == '\0')
|
|
|
|
{
|
|
|
|
g_warning ("No device for TSLib has been defined; please set the "
|
|
|
|
"TSLIB_TSDEVICE environment variable to define a touch "
|
|
|
|
"screen device to be used with Clutter.");
|
|
|
|
g_source_unref (source);
|
|
|
|
return;
|
|
|
|
}
|
2007-07-09 18:25:26 -04:00
|
|
|
|
2010-02-27 04:42:42 -05:00
|
|
|
event_source->ts_device = ts_open (device_name, 0);
|
2007-07-09 18:25:26 -04:00
|
|
|
if (event_source->ts_device)
|
|
|
|
{
|
2010-02-27 04:42:42 -05:00
|
|
|
CLUTTER_NOTE (EVENT, "Opened '%s'", device_name);
|
2007-07-09 18:25:26 -04:00
|
|
|
|
2008-05-15 10:31:43 -04:00
|
|
|
if (ts_config (event_source->ts_device))
|
2007-07-09 18:25:26 -04:00
|
|
|
{
|
2010-02-27 04:42:42 -05:00
|
|
|
g_warning ("Closing device '%s': ts_config() failed", device_name);
|
2007-07-09 18:25:26 -04:00
|
|
|
ts_close (event_source->ts_device);
|
2010-02-27 04:42:42 -05:00
|
|
|
g_source_unref (source);
|
2007-07-09 18:25:26 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_source_set_priority (source, CLUTTER_PRIORITY_EVENTS);
|
2010-02-27 04:42:42 -05:00
|
|
|
event_source->event_poll_fd.fd = ts_fd (event_source->ts_device);
|
2007-07-09 18:25:26 -04:00
|
|
|
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
|
2010-02-27 04:42:42 -05:00
|
|
|
{
|
|
|
|
g_warning ("Unable to open '%s'", device_name);
|
|
|
|
g_source_unref (source);
|
|
|
|
}
|
|
|
|
#endif /* HAVE_TSLIB */
|
2007-07-06 09:56:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-03-03 10:31:01 -05:00
|
|
|
_clutter_events_egl_uninit (ClutterBackendEGL *backend_egl)
|
2007-07-06 09:56:01 -04:00
|
|
|
{
|
2010-06-17 19:18:02 -04:00
|
|
|
#ifdef HAVE_TSLIB
|
2010-02-27 04:42:42 -05:00
|
|
|
if (backend_egl->event_timer != NULL)
|
2008-05-15 10:31:43 -04:00
|
|
|
{
|
|
|
|
CLUTTER_NOTE (EVENT, "Stopping the timer");
|
|
|
|
g_timer_stop (backend_egl->event_timer);
|
|
|
|
}
|
|
|
|
|
2010-02-27 04:42:42 -05:00
|
|
|
if (backend_egl->event_source != NULL)
|
2007-07-06 09:56:01 -04:00
|
|
|
{
|
|
|
|
CLUTTER_NOTE (EVENT, "Destroying the event source");
|
|
|
|
|
2007-10-12 04:17:00 -04:00
|
|
|
ClutterEventSource *event_source =
|
2007-07-09 18:25:26 -04:00
|
|
|
(ClutterEventSource *) backend_egl->event_source;
|
|
|
|
|
|
|
|
ts_close (event_source->ts_device);
|
2010-02-27 04:42:42 -05:00
|
|
|
event_sources = g_list_remove (event_sources, backend_egl->event_source);
|
|
|
|
|
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;
|
|
|
|
}
|
2010-06-17 19:18:02 -04:00
|
|
|
#endif /* HAVE_TSLIB */
|
2007-07-06 09:56:01 -04:00
|
|
|
}
|
|
|
|
|
2010-06-17 19:18:02 -04:00
|
|
|
#ifdef HAVE_TSLIB
|
|
|
|
|
2007-07-09 18:25:26 -04:00
|
|
|
static gboolean
|
|
|
|
clutter_event_prepare (GSource *source,
|
|
|
|
gint *timeout)
|
|
|
|
{
|
2007-08-08 06:20:14 -04:00
|
|
|
gboolean retval;
|
|
|
|
|
|
|
|
clutter_threads_enter ();
|
2007-07-09 18:25:26 -04:00
|
|
|
|
|
|
|
*timeout = -1;
|
2007-08-08 06:20:14 -04:00
|
|
|
retval = clutter_events_pending ();
|
|
|
|
|
|
|
|
clutter_threads_leave ();
|
2007-07-09 18:25:26 -04:00
|
|
|
|
2007-08-08 06:20:14 -04:00
|
|
|
return retval;
|
2007-07-09 18:25:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
clutter_event_check (GSource *source)
|
|
|
|
{
|
|
|
|
ClutterEventSource *event_source = (ClutterEventSource *) source;
|
2007-08-08 06:20:14 -04:00
|
|
|
gboolean retval;
|
|
|
|
|
|
|
|
clutter_threads_enter ();
|
|
|
|
|
|
|
|
retval = ((event_source->event_poll_fd.revents & G_IO_IN) ||
|
|
|
|
clutter_events_pending ());
|
2007-07-09 18:25:26 -04:00
|
|
|
|
2007-08-08 06:20:14 -04:00
|
|
|
clutter_threads_leave ();
|
|
|
|
|
|
|
|
return retval;
|
2007-07-09 18:25:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
clutter_event_dispatch (GSource *source,
|
|
|
|
GSourceFunc callback,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2010-03-03 10:31:01 -05:00
|
|
|
ClutterEvent *event;
|
2010-06-17 19:18:02 -04:00
|
|
|
ClutterEventSource *event_source = (ClutterEventSource *) source;
|
2007-07-09 18:25:26 -04:00
|
|
|
struct ts_sample tsevent;
|
|
|
|
ClutterMainContext *clutter_context;
|
|
|
|
|
2007-08-08 06:20:14 -04:00
|
|
|
clutter_threads_enter ();
|
|
|
|
|
2009-06-17 12:59:54 -04:00
|
|
|
clutter_context = _clutter_context_get_default ();
|
2007-09-17 07:34:03 -04:00
|
|
|
|
2007-07-09 18:25:26 -04:00
|
|
|
/* FIXME while would be better here but need to deal with lockups */
|
2007-10-12 04:17:00 -04:00
|
|
|
if ((!clutter_events_pending()) &&
|
2010-03-03 10:31:01 -05:00
|
|
|
(ts_read(event_source->ts_device, &tsevent, 1) == 1))
|
2007-07-09 18:25:26 -04:00
|
|
|
{
|
2010-06-17 19:18:02 -04:00
|
|
|
static gint last_x = 0, last_y = 0;
|
|
|
|
static gboolean clicked = FALSE;
|
|
|
|
|
2007-10-12 04:17:00 -04:00
|
|
|
/* Avoid sending too many events which are just pressure changes.
|
2010-02-27 04:42:42 -05:00
|
|
|
*
|
|
|
|
* FIXME - We don't current handle pressure in events and thus
|
2007-07-12 07:30:56 -04:00
|
|
|
* event_button_generate gets confused generating lots of double
|
2007-10-12 04:17:00 -04:00
|
|
|
* and triple clicks.
|
2007-07-12 07:30:56 -04:00
|
|
|
*/
|
2007-08-08 06:20:14 -04:00
|
|
|
if (tsevent.pressure && last_x == tsevent.x && last_y == tsevent.y)
|
|
|
|
goto out;
|
2007-07-12 07:30:56 -04:00
|
|
|
|
2007-07-09 18:25:26 -04:00
|
|
|
event = clutter_event_new (CLUTTER_NOTHING);
|
|
|
|
|
2008-04-23 13:20:59 -04:00
|
|
|
event->any.stage = clutter_stage_get_default ();
|
|
|
|
|
2007-07-12 07:30:56 -04:00
|
|
|
last_x = event->button.x = tsevent.x;
|
|
|
|
last_y = event->button.y = tsevent.y;
|
|
|
|
|
2007-09-17 07:34:03 -04:00
|
|
|
if (tsevent.pressure && !clicked)
|
|
|
|
{
|
|
|
|
event->button.type = event->type = CLUTTER_BUTTON_PRESS;
|
2008-05-15 10:31:43 -04:00
|
|
|
event->button.time = get_backend_time ();
|
|
|
|
event->button.modifier_state = 0;
|
|
|
|
event->button.button = 1;
|
|
|
|
|
2007-09-17 07:34:03 -04:00
|
|
|
clicked = TRUE;
|
|
|
|
}
|
|
|
|
else if (tsevent.pressure && clicked)
|
|
|
|
{
|
|
|
|
event->motion.type = event->type = CLUTTER_MOTION;
|
2008-05-15 10:31:43 -04:00
|
|
|
event->motion.time = get_backend_time ();
|
|
|
|
event->motion.modifier_state = 0;
|
2007-09-17 07:34:03 -04:00
|
|
|
}
|
2007-07-09 18:25:26 -04:00
|
|
|
else
|
2007-09-17 07:34:03 -04:00
|
|
|
{
|
|
|
|
event->button.type = event->type = CLUTTER_BUTTON_RELEASE;
|
2008-05-15 10:31:43 -04:00
|
|
|
event->button.time = get_backend_time ();
|
|
|
|
event->button.modifier_state = 0;
|
|
|
|
event->button.button = 1;
|
|
|
|
|
2007-09-17 07:34:03 -04:00
|
|
|
clicked = FALSE;
|
|
|
|
}
|
2007-07-09 18:25:26 -04:00
|
|
|
|
2011-01-19 11:34:49 -05:00
|
|
|
_clutter_event_push (event, FALSE);
|
2007-07-09 18:25:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
}
|
|
|
|
|
2007-08-08 06:20:14 -04:00
|
|
|
out:
|
2010-06-17 19:18:02 -04:00
|
|
|
|
2007-08-08 06:20:14 -04:00
|
|
|
clutter_threads_leave ();
|
|
|
|
|
2007-07-09 18:25:26 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
2010-06-17 19:18:02 -04:00
|
|
|
|
|
|
|
#endif
|