summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRich J Wareham <richwareham@users.sourceforge.net>2001-07-14 23:17:37 +0000
committerRich J Wareham <richwareham@users.sourceforge.net>2001-07-14 23:17:37 +0000
commit8a5824b6c5fb5fc8d072c2ef27f559fd04396381 (patch)
tree9cd13316f3d13da2fdfecea9649605791a389e30 /src
parent07c0477c310bffef3e08ebeb7756ff53b56e6c66 (diff)
downloadxine-lib-8a5824b6c5fb5fc8d072c2ef27f559fd04396381.tar.gz
xine-lib-8a5824b6c5fb5fc8d072c2ef27f559fd04396381.tar.bz2
Added first bit of event mechanism for mouse/keyboard stuff.
CVS patchset: 281 CVS date: 2001/07/14 23:17:37
Diffstat (limited to 'src')
-rw-r--r--src/xine-engine/Makefile.am5
-rw-r--r--src/xine-engine/events.c82
-rw-r--r--src/xine-engine/events.h52
-rw-r--r--src/xine-engine/xine.c40
-rw-r--r--src/xine-engine/xine_internal.h46
5 files changed, 219 insertions, 6 deletions
diff --git a/src/xine-engine/Makefile.am b/src/xine-engine/Makefile.am
index ff5d68d17..a6c1f61ac 100644
--- a/src/xine-engine/Makefile.am
+++ b/src/xine-engine/Makefile.am
@@ -10,7 +10,7 @@ lib_LTLIBRARIES = libxine.la
libxine_la_SOURCES = xine.c metronom.c configfile.c buffer.c monitor.c \
utils.c load_plugins.c video_decoder.c \
- audio_decoder.c video_out.c
+ audio_decoder.c video_out.c events.c
libxine_la_LIBADD = cpu_accel.lo \
$(THREAD_LIBS) \
$(DYNAMIC_LD_LIBS) \
@@ -20,7 +20,8 @@ libxine_la_LDFLAGS = -version-info 5:0:5
include_HEADERS = buffer.h metronom.h configfile.h \
monitor.h cpu_accel.h attributes.h utils.h \
- audio_out.h video_out.h xine_internal.h spu_decoder.h
+ audio_out.h video_out.h xine_internal.h spu_decoder.h \
+ events.h
###
# Hardcoded rule:
diff --git a/src/xine-engine/events.c b/src/xine-engine/events.c
new file mode 100644
index 000000000..f2774168a
--- /dev/null
+++ b/src/xine-engine/events.c
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2000-2001 the xine project
+ *
+ * This file is part of xine, a unix video player.
+ *
+ * xine is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * xine 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ * $Id:
+ *
+ * Event handling functions
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "xine_internal.h"
+
+int xine_register_event_listener(xine_t *this, event_listener_t *listener) {
+ /* Ensure the listener is non-NULL */
+ if(listener == NULL) {
+ return 0;
+ }
+
+ /* Check we hava a slot free */
+ if(this->num_event_listeners < XINE_MAX_EVENT_LISTENERS) {
+ this->event_listeners[this->num_event_listeners++] = listener;
+ return 1;
+ }
+
+ return 0;
+}
+
+void xine_send_event(xine_t *this, event_t *event, void *data) {
+ uint16_t i;
+
+ /* Itterate through all event handlers */
+ for(i=0; i < this->num_event_listeners; i++) {
+ (this->event_listeners[i]) (this, event, data);
+ }
+}
+
+int xine_remove_event_listener(xine_t *this, event_listener_t *listener) {
+ uint16_t i, found;
+
+ found = 1; i = 0;
+
+ /* Attempt to find the listener */
+ while((found == 1) && (i < this->num_event_listeners)) {
+ if(this->event_listeners[i] == listener) {
+ /* Set found flag */
+ found = 0;
+
+ this->event_listeners[i] = NULL;
+
+ /* If possible, move the last listener to the hole thats left */
+ if(this->num_event_listeners > 1) {
+ this->event_listeners[i] = this->event_listeners[this->num_event_listeners - 1];
+ this->event_listeners[this->num_event_listeners - 1] = NULL;
+ }
+
+ this->num_event_listeners --;
+ }
+
+ i++;
+ }
+
+ return found;
+}
diff --git a/src/xine-engine/events.h b/src/xine-engine/events.h
new file mode 100644
index 000000000..eeda3320e
--- /dev/null
+++ b/src/xine-engine/events.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2000-2001 the xine project
+ *
+ * Copyright (C) Rich Wareham <richwareham@users.sourceforge.net> - July 2001
+ *
+ * This file is part of xine, a unix video player.
+ *
+ * xine is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * xine 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ */
+
+#ifndef HAVE_EVENTS_H
+#define HAVE_EVENTS_H
+
+#include <inttypes.h>
+
+/**
+ * This file defines types for many events which can be sent in Xine.
+ */
+
+/**
+ * Generic Event type.
+ */
+typedef struct event_s {
+ uint32_t type; /* The event type (determines remainder of struct) */
+
+ /* Event dependent data goes after this. */
+} event_t;
+
+/**
+ * Mouse event.
+ */
+#define XINE_MOUSE_EVENT 0x0001
+typedef struct mouse_event_s {
+ event_t event;
+ uint8_t button; /* Generally 1 = left, 2 = mid, 3 = right */
+ uint16_t x,y; /* In Image space */
+} mouse_event_t;
+
+#endif /* HAVE_EVENTS_H */
diff --git a/src/xine-engine/xine.c b/src/xine-engine/xine.c
index c13f43a7e..4691bb071 100644
--- a/src/xine-engine/xine.c
+++ b/src/xine-engine/xine.c
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*
- * $Id: xine.c,v 1.34 2001/07/14 13:28:32 guenter Exp $
+ * $Id: xine.c,v 1.35 2001/07/14 23:17:37 richwareham Exp $
*
* top-level xine functions
*
@@ -351,6 +351,36 @@ void xine_pause (xine_t *this) {
pthread_mutex_unlock (&this->xine_lock);
}
+void event_handler(xine_t *xine, event_t *event, void *data) {
+ /* Check Xine handle/current input plugin is not NULL */
+ if((xine == NULL) || (xine->cur_input_plugin == NULL)) {
+ return;
+ }
+
+ switch(event->type) {
+ case XINE_MOUSE_EVENT:
+ {
+ mouse_event_t *mevent = (mouse_event_t*)event;
+
+ /* Send event to imput plugin if appropriate. */
+ if(xine->cur_input_plugin->handle_input_event != NULL) {
+ if(mevent->button != 0) {
+ /* Click event. */
+ xine->cur_input_plugin->handle_input_event(xine->cur_input_plugin,
+ INPUT_EVENT_MOUSEBUTTON,
+ 0, mevent->x, mevent->y);
+ } else {
+ /* Motion event */
+ xine->cur_input_plugin->handle_input_event(xine->cur_input_plugin,
+ INPUT_EVENT_MOUSEMOVE,
+ 0, mevent->x, mevent->y);
+ }
+ }
+ }
+ break;
+ }
+}
+
xine_t *xine_init (vo_driver_t *vo,
ao_functions_t *ao,
config_values_t *config,
@@ -408,6 +438,14 @@ xine_t *xine_init (vo_driver_t *vo,
}
audio_decoder_init (this);
printf("xine_init returning\n");
+
+ /*
+ * init event listeners
+ */
+ this->num_event_listeners = 0; /* Initially there are none */
+
+ xine_register_event_listener(this, event_handler);
+
return this;
}
diff --git a/src/xine-engine/xine_internal.h b/src/xine-engine/xine_internal.h
index 9fa9c2f26..fb70f8cd6 100644
--- a/src/xine-engine/xine_internal.h
+++ b/src/xine-engine/xine_internal.h
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*
- * $Id: xine_internal.h,v 1.29 2001/07/14 13:28:32 guenter Exp $
+ * $Id: xine_internal.h,v 1.30 2001/07/14 23:17:37 richwareham Exp $
*
*/
@@ -32,6 +32,7 @@
#include "metronom.h"
#include "spu_decoder.h"
#include "libspudec/spu_decoder_api.h"
+#include "events.h"
#define INPUT_PLUGIN_MAX 50
#define DEMUXER_PLUGIN_MAX 50
@@ -39,6 +40,7 @@
#define DECODER_PLUGIN_IFACE_VERSION 1
#define AUDIO_OUT_PLUGIN_MAX 50
#define VIDEO_OUT_PLUGIN_MAX 50
+#define XINE_MAX_EVENT_LISTENERS 50
/*
* generic xine video decoder plugin interface
@@ -109,7 +111,10 @@ typedef void (*gui_stream_end_cb_t)(int nStatus);
#define XINE_PAUSE 2
#define XINE_QUIT 3
-typedef struct xine_s {
+typedef struct xine_s xine_t;
+typedef void (*event_listener_t) (xine_t *xine, event_t *event, void *data);
+
+struct xine_s {
/* private : */
@@ -166,7 +171,11 @@ typedef struct xine_s {
/* Lock for xine player functions */
pthread_mutex_t xine_lock;
-} xine_t;
+ /* Array of event handlers. */
+ event_listener_t event_listeners[XINE_MAX_EVENT_LISTENERS];
+ uint16_t num_event_listeners;
+
+};
/*
* read config file and init a config object
@@ -417,4 +426,35 @@ char **xine_list_audio_output_plugins ();
ao_functions_t *xine_load_audio_output_plugin(config_values_t *config, char *id);
+/**
+ * @defgroup eventgroup Sending events
+ * Event dispatcher mechanism
+ * @{
+ */
+
+/**
+ * \fn xine_register_event_listener(event_listener_t *listener)
+ * \brief registers an event listener callback.
+ * \return 0 if the listener was registerd, non-zero if it could not.
+ */
+
+int xine_register_event_listener(xine_t *this, event_listener_t *listener);
+
+/**
+ * \fn xine_remove_event_listener(event_listener_t *listener)
+ * \brief Attempts to remove a registered event listener.
+ * \return 0 if the listener was removes, non-zero if it wasn't (e.g. not found).
+ */
+
+int xine_remove_event_listener(xine_t *this, event_listener_t *listener);
+
+/**
+ * \fn xine_send_event(event_t *event)
+ * \brief sends an event to all listeners.
+ */
+
+void xine_send_event(xine_t *this, event_t *event, void *data);
+
+/** @} end of eventgroup */
+
#endif