diff options
author | Sam Spillaz <smspillaz@gmail.com> | 2008-04-26 21:26:42 +0800 |
---|---|---|
committer | Sam Spillaz <smspillaz@gmail.com> | 2008-04-26 21:26:42 +0800 |
commit | e1737e4024c66e066531fd3552abaf5428c1c382 (patch) | |
tree | 9b8fca80b1e6e0db9c2ff4f81f7341d8aab1ad64 /gesture.c | |
parent | ca73db7c91c0e28c3170f9946c168cf4576befa8 (diff) | |
download | wiimote-e1737e4024c66e066531fd3552abaf5428c1c382.tar.gz wiimote-e1737e4024c66e066531fd3552abaf5428c1c382.tar.bz2 |
* Added the new files that I split into (I think I went overboard. Meh)
Diffstat (limited to 'gesture.c')
-rw-r--r-- | gesture.c | 156 |
1 files changed, 156 insertions, 0 deletions
diff --git a/gesture.c b/gesture.c new file mode 100644 index 0000000..cb0abd4 --- /dev/null +++ b/gesture.c @@ -0,0 +1,156 @@ +/** + * + * Compiz Nintendo(R) Wii(TM) Remote Interface Plugin + * + * Copyright : (C) 2008 by Sam Spilsbury + * E-mail : smspillaz@gmail.com + * + * + * This program 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. + * + * This program 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. + * + */ + +#include "compiz-wiimote.h" + +/* 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; \ + } \ + + +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; +} + +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; +} + +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; +} |