[MPlayer-dev-eng] [PATCH] Allow joystick to be used with libmenu
Andrew Calkin
andrew.calkin at gmail.com
Mon Dec 10 10:30:06 CET 2007
Hi,
The following patch does $subj, and has been well tested with the
GeeXboX project. Please review. Issues that had been raised with an earlier
version that was submitted a long time ago have been resolved as a result of
reworking of libmenu by Ulion in recent weeks, and now the hard-coded
joystick mappings are now configurable as are keys, via the menu.conf file.
//Andrew
-------------- next part --------------
diff -r e9742d85360a input/joystick.c
--- a/input/joystick.c Sun Apr 30 16:54:31 2006 +0200
+++ b/input/joystick.c Sun Apr 30 16:54:32 2006 +0200
@@ -30,6 +30,9 @@
int axis[256];
int btns = 0;
+
+// Callback to allow the menu filter to grab the incoming joystick event
+void (*mp_input_joy_cb)(int code) = NULL;
int mp_input_joystick_init(char* dev) {
int fd,l=0;
@@ -122,7 +125,14 @@ int mp_input_joystick_read(int fd) {
btns &= ~(1 << ev.number);
btns |= (ev.value << ev.number);
if(ev.value == 1)
- return ((JOY_BTN0+ev.number) | MP_KEY_DOWN);
+ {
+ if (mp_input_joy_cb)
+ {
+ mp_input_joy_cb (JOY_BTN0+ev.number);
+ return MP_INPUT_NOTHING;
+ }
+ return ((JOY_BTN0+ev.number) | MP_KEY_DOWN);
+ }
else
return (JOY_BTN0+ev.number);
} else if(ev.type & JS_EVENT_AXIS) {
@@ -135,6 +139,11 @@ int mp_input_joystick_read(int fd) {
} else if(ev.value <= JOY_AXIS_DELTA && ev.value >= -JOY_AXIS_DELTA && axis[ev.number] != 0) {
int r = axis[ev.number] == 1 ? JOY_AXIS0_PLUS+(2*ev.number) : JOY_AXIS0_MINUS+(2*ev.number);
axis[ev.number] = 0;
+ if (mp_input_joy_cb)
+ {
+ mp_input_joy_cb (r);
+ return MP_INPUT_NOTHING;
+ }
return r;
} else
return MP_INPUT_NOTHING;
diff -r e9742d85360a input/joystick.h
--- a/input/joystick.h Sun Apr 30 16:54:31 2006 +0200
+++ b/input/joystick.h Sun Apr 30 16:54:32 2006 +0200
@@ -37,3 +37,5 @@ int mp_input_joystick_init(char* dev);
int mp_input_joystick_read(int fd);
+// Set this to grab all incoming key codes
+extern void (*mp_input_joy_cb)(int code);
diff -r e9742d85360a libmenu/menu.c
--- a/libmenu/menu.c Sun Apr 30 16:54:31 2006 +0200
+++ b/libmenu/menu.c Sun Apr 30 16:54:32 2006 +0200
@@ -22,6 +22,9 @@
#include "m_option.h"
#include "m_struct.h"
#include "menu.h"
+#ifdef HAVE_JOYSTICK
+#include "input/joystick.h"
+#endif
extern menu_info_t menu_info_cmdlist;
extern menu_info_t menu_info_pt;
diff -r e9742d85360a libmenu/vf_menu.c
--- a/libmenu/vf_menu.c Sun Apr 30 16:54:31 2006 +0200
+++ b/libmenu/vf_menu.c Sun Apr 30 16:54:32 2006 +0200
@@ -23,6 +23,9 @@
#include "libvo/font_load.h"
#include "libvo/sub.h"
#include "input/input.h"
+#ifdef HAVE_JOYSTICK
+#include "input/joystick.h"
+#endif
#include "m_struct.h"
#include "menu.h"
#include "access_mpcontext.h"
@@ -157,6 +157,14 @@ static int put_image(struct vf_instance_
if (!mp_input_key_cb)
mp_input_key_cb = key_cb;
+#ifdef HAVE_JOYSTICK
+ // Grab // Ungrab the joy inputs
+ if(!mp_input_joy_cb && vf->priv->current->show)
+ mp_input_joy_cb = key_cb;
+ if(mp_input_joy_cb && !vf->priv->current->show)
+ mp_input_joy_cb = NULL;
+#endif
+
if(mpi->flags&MP_IMGFLAG_DIRECT)
dmpi = mpi->priv;
else {
@@ -170,6 +170,10 @@ static int put_image(struct vf_instance_
} else {
if(mp_input_key_cb)
mp_input_key_cb = NULL;
+#ifdef HAVE_JOYSTICK
+ if(mp_input_joy_cb)
+ mp_input_joy_cb = NULL;
+#endif
if(mpi->flags&MP_IMGFLAG_DIRECT)
dmpi = mpi->priv;
More information about the MPlayer-dev-eng
mailing list