summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Spillaz <smspillaz@gmail.com>2008-04-26 21:06:32 +0800
committerSam Spillaz <smspillaz@gmail.com>2008-04-26 21:06:32 +0800
commite47f50efa8c903c44d621d8a1f988bb74c8c7edb (patch)
tree5509101190dce44966af375f17c949a6167d416d
parentafb4797d9de335a313adc8c5d61abf8142c9c460 (diff)
downloadwiimote-e47f50efa8c903c44d621d8a1f988bb74c8c7edb.tar.gz
wiimote-e47f50efa8c903c44d621d8a1f988bb74c8c7edb.tar.bz2
* Part 5: Split gesture handling into gesture.c
-rw-r--r--compiz-wiimote.h1
-rw-r--r--wiimote.c135
2 files changed, 1 insertions, 135 deletions
diff --git a/compiz-wiimote.h b/compiz-wiimote.h
index 998678b..3fe275c 100644
--- a/compiz-wiimote.h
+++ b/compiz-wiimote.h
@@ -378,6 +378,7 @@ void wiimoteProcessNunchuckButtons (CompDisplay *, int, struct cwiid_nunchuk_mes
Bool find_wiimote(bdaddr_t *bdaddr, int timeout);
void* connectWiimote (void *vd);
Bool checkConnected (void *vd);
+Bool wiimoteCheckForGestures (void *vs);
/* Shortcut Macros --------------------------------------------------- */
diff --git a/wiimote.c b/wiimote.c
index 136186b..0642d48 100644
--- a/wiimote.c
+++ b/wiimote.c
@@ -66,40 +66,6 @@ wiimotePaintOutput (CompScreen *s,
return status;
}
-static Bool sendGesture(CompDisplay *d, int wiimoteNumber, int type)
-{
- CompOption argument[2];
- int nArgument = 0;
- int i;
-
- WIIMOTE_DISPLAY (d);
-
- if (ad->cWiimote[wiimoteNumber].connected)
- {
- for (i = 0; i < ad->cWiimote[wiimoteNumber].nGesture; i++)
- {
- if (ad->cWiimote[wiimoteNumber].gesture[i].type == type)
- {
- argument[nArgument].name = "window";
- argument[nArgument].type = CompOptionTypeInt;
- argument[nArgument].value.i = d->activeWindow;
- nArgument++;
-
- argument[nArgument].name = "root";
- argument[nArgument].type = CompOptionTypeInt;
- argument[nArgument].value.i = ad->firstRoot;
- nArgument++;
-
- sendInfoToPlugin (d, argument, nArgument,
- ad->cWiimote[wiimoteNumber].gesture[i].pluginName,
- ad->cWiimote[wiimoteNumber].gesture[i].actionName);
- }
- }
- }
-
- return TRUE;
-}
-
/* Value Reporting --------------------------------------------------- */
static Bool sendReports(void *vs)
@@ -226,107 +192,6 @@ static Bool sendReports(void *vs)
}
-/* Gesturing and gesture checking --------------------------------------------- */
-
-#define CHECK_BUTTON(a,b,c,e) \
- if (mesg->buttons & a) \
- { \
- if (!b) \
- sendGesture(d, wiimoteNumber, c); \
- b = TRUE; \
- } \
- else \
- { \
- if (b) \
- sendGesture(d, wiimoteNumber, e); \
- b = FALSE; \
- } \
-
-void
-wiimoteProcessButtons(CompDisplay *d, int wiimoteNumber, struct cwiid_btn_mesg *mesg)
-{
- WIIMOTE_DISPLAY (d);
-
- CHECK_BUTTON( CWIID_BTN_A, ad->cWiimote[wiimoteNumber].buttons.A, 1, 2);
- CHECK_BUTTON( CWIID_BTN_B, ad->cWiimote[wiimoteNumber].buttons.B, 3, 4);
- CHECK_BUTTON( CWIID_BTN_UP, ad->cWiimote[wiimoteNumber].buttons.Up, 5, 6);
- CHECK_BUTTON( CWIID_BTN_DOWN, ad->cWiimote[wiimoteNumber].buttons.Down, 7, 8);
- CHECK_BUTTON( CWIID_BTN_LEFT, ad->cWiimote[wiimoteNumber].buttons.Left, 9, 10);
- CHECK_BUTTON( CWIID_BTN_RIGHT, ad->cWiimote[wiimoteNumber].buttons.Right, 11, 12);
- CHECK_BUTTON( CWIID_BTN_PLUS, ad->cWiimote[wiimoteNumber].buttons.Plus, 13, 14);
- CHECK_BUTTON( CWIID_BTN_MINUS, ad->cWiimote[wiimoteNumber].buttons.Minus, 15, 16);
- CHECK_BUTTON( CWIID_BTN_HOME, ad->cWiimote[wiimoteNumber].buttons.Home, 17, 18);
- CHECK_BUTTON( CWIID_BTN_1, ad->cWiimote[wiimoteNumber].buttons.One, 19, 20);
- CHECK_BUTTON( CWIID_BTN_2, ad->cWiimote[wiimoteNumber].buttons.Two, 21, 22);
-
-}
-
-void
-wiimoteProcessNunchuckButtons (CompDisplay *d, int wiimoteNumber, struct cwiid_nunchuk_mesg *mesg)
-{
- WIIMOTE_DISPLAY (d);
-
- CHECK_BUTTON ( CWIID_NUNCHUK_BTN_C, ad->cWiimote[wiimoteNumber].nunchuck.buttons.C, 23, 24);
- CHECK_BUTTON ( CWIID_NUNCHUK_BTN_Z, ad->cWiimote[wiimoteNumber].nunchuck.buttons.Z, 25, 26);
-}
-
-/* I would rather use #define, but it's bugged up, so I have to compromise */
-
-static void
-wiimoteCheckGesture (CompScreen *s, int wiimoteNumber, float diff, float init, float *old, float value, int posGest, int negGest)
-{
-
- if (*old <= value - diff && value <= init)
- sendGesture (s->display, wiimoteNumber, negGest);
- if (*old >= value + diff && value >= init)
- sendGesture (s->display, wiimoteNumber, posGest);
-
- *old = value;
-}
-
-static Bool
-wiimoteCheckForGestures (void *vs)
-{
- CompScreen *s = (CompScreen *) vs;
- int i;
- float sens = wiimoteGetGestureSens (s->display);
-
- WIIMOTE_DISPLAY (s->display);
-
- for (i = 0; i < MAX_WIIMOTES; i++)
- {
- if (ad->cWiimote[i].connected)
- {
- /* Check Accellerometer */
-
- wiimoteCheckGesture (s, i, sens, ad->cWiimote[i].acc.initAccY,
- &ad->cWiimote[i].acc.oldAccY,
- ad->cWiimote[i].acc.accY, 27, 28);
- wiimoteCheckGesture (s, i, sens, ad->cWiimote[i].acc.initAccX,
- &ad->cWiimote[i].acc.oldAccX,
- ad->cWiimote[i].acc.accX, 29, 30);
-
- /* Check Nunchuk */
- if (ad->cWiimote[i].nunchuck.connected)
- {
- wiimoteCheckGesture ( s, i, sens, ad->cWiimote[i].nunchuck.initAccY,
- &ad->cWiimote[i].nunchuck.oldAccY,
- ad->cWiimote[i].nunchuck.accY, 31, 32 );
- wiimoteCheckGesture ( s, i, sens, ad->cWiimote[i].nunchuck.initAccX,
- &ad->cWiimote[i].nunchuck.oldAccX,
- ad->cWiimote[i].nunchuck.accX, 33, 34 );
- wiimoteCheckGesture ( s, i, sens, ad->cWiimote[i].nunchuck.initStickY,
- &ad->cWiimote[i].nunchuck.oldStickY,
- ad->cWiimote[i].nunchuck.stickY, 35, 36 );
- wiimoteCheckGesture ( s, i, sens, ad->cWiimote[i].nunchuck.initStickX,
- &ad->cWiimote[i].nunchuck.oldStickX,
- ad->cWiimote[i].nunchuck.stickX, 37, 38 );
- }
- }
- }
- return TRUE;
-}
-
/* Callable Actions --------------------------------------------------- */
static Bool