diff options
-rw-r--r-- | compiz-wiimote.h | 21 | ||||
-rw-r--r-- | connect.c | 6 | ||||
-rw-r--r-- | option.c | 228 | ||||
-rw-r--r-- | wiimote.c | 11 |
4 files changed, 157 insertions, 109 deletions
diff --git a/compiz-wiimote.h b/compiz-wiimote.h index 896296f..37b14f4 100644 --- a/compiz-wiimote.h +++ b/compiz-wiimote.h @@ -408,13 +408,28 @@ Bool sendReports(void *vs); /* option.c */ void -reloadWiimoteGestures (CompDisplay *d); +reloadReportersForWiimote (CompDisplay *d, + CompWiimote *wiimote); void -reloadWiimoteReporters(CompDisplay *d); +reloadReportersForWiimoteNumber (CompDisplay *d, + int wiimoteNumber); void -reloadWiimoteOptions (CompDisplay *d); +reloadGesturesForWiimote (CompDisplay *d, + CompWiimote *wiimote); + +void +reloadGesturesForWiimoteNumber (CompDisplay *d, + int wiimoteNumber); + +void +reloadOptionsForWiimote (CompDisplay *d, + CompWiimote *wiimote); + +void +reloadOptionsForWiimoteNumber (CompDisplay *d, + int wiimoteNumber); /* action.c */ @@ -357,7 +357,11 @@ Bool checkConnected (void *vd) /* Set the id */ - cmpwiimote->id = cwiid_get_id (ad->cWiimote[ad->nWiimote].wiimote); + cmpwiimote->id = cwiid_get_id (cmpwiimote->wiimote); + + reloadOptionsForWiimote (d, cmpwiimote); + reloadGesturesForWiimote (d, cmpwiimote); + reloadReportersForWiimote (d, cmpwiimote); /* Increment the Wiimote iter to * allow another CompWiimote to initialise @@ -24,57 +24,8 @@ /* Option Initialisation --------------------------------------------------- */ void -reloadWiimoteGestures (CompDisplay *d) -{ - CompListValue *cWiimoteNumber = wiimoteGetGestureWiimoteNumber (d); - CompListValue *cGestureType = wiimoteGetGestureType (d); - CompListValue *cPluginName = wiimoteGetGesturePluginName (d); - CompListValue *cActionName = wiimoteGetGestureActionName (d); - CompListValue *cGestureSensitivity = wiimoteGetGestureSensitivity (d); - - int nGesture; - int iGesture = 0; - int i = 0; - - if ((cWiimoteNumber->nValue != cGestureType->nValue) || - (cWiimoteNumber->nValue != cPluginName->nValue) || - (cWiimoteNumber->nValue != cGestureSensitivity->nValue) || - (cWiimoteNumber->nValue != cActionName->nValue)) - { - /* Options have not been set correctly */ - return; - } - - WIIMOTE_DISPLAY (d); - - for (i = 0; i < MAX_WIIMOTES; i++) - { - nGesture = cWiimoteNumber->nValue; - iGesture = 0; - int k = 0; - ad->cWiimote[i].nGesture = 0; - - while (nGesture-- && iGesture < MAX_GESTURES) - { - if (cWiimoteNumber->value[iGesture].i == i) - { - ad->cWiimote[i].gesture[iGesture].set = TRUE; - ad->cWiimote[i].gesture[iGesture].pluginName = strdup(cPluginName->value[iGesture].s); - ad->cWiimote[i].gesture[iGesture].actionName = strdup(cActionName->value[iGesture].s); - ad->cWiimote[i].gesture[iGesture].sensitivity = cGestureSensitivity->value[iGesture].i; - - ad->cWiimote[i].gesture[k].type = cGestureType->value[iGesture].i; - k++; - ad->cWiimote[i].nGesture++; - - } - iGesture++; - } - } -} - -void -reloadWiimoteReporters(CompDisplay *d) +reloadReportersForWiimote (CompDisplay *d, + CompWiimote *wiimote) { CompListValue *cWiimoteNumber = wiimoteGetReportWiimoteNumber (d); CompListValue *cReportType = wiimoteGetReportType (d); @@ -90,9 +41,6 @@ reloadWiimoteReporters(CompDisplay *d) int nReport; int iReport = 0; - int i = 0; - - WIIMOTE_DISPLAY (d); if ((cWiimoteNumber->nValue != cReportType->nValue) || (cWiimoteNumber->nValue != cPluginName->nValue) || @@ -108,53 +56,120 @@ reloadWiimoteReporters(CompDisplay *d) return; } - for (i = 0; i < MAX_WIIMOTES; i++) + + nReport = cWiimoteNumber->nValue; + iReport = 0; + wiimote->nReport = 0; + + while (nReport-- && iReport < MAX_REPORTS - 1) + { + if (cWiimoteNumber->value[iReport].i == wiimote->id) + { + /* And set them */ + wiimote->report[wiimote->nReport].set = TRUE; + wiimote->report[wiimote->nReport].pluginName = strdup(cPluginName->value[iReport].s); + wiimote->report[wiimote->nReport].actionName = strdup(cActionName->value[iReport].s); + wiimote->report[wiimote->nReport].sensitivity = cReportSensitivity->value[iReport].i; + + wiimote->report[wiimote->nReport].xarg = strdup(cXArgument->value[iReport].s); + wiimote->report[wiimote->nReport].yarg = strdup(cYArgument->value[iReport].s); + wiimote->report[wiimote->nReport].zarg = strdup(cZArgument->value[iReport].s); + + wiimote->report[wiimote->nReport].type = cReportType->value[iReport].i; + wiimote->report[wiimote->nReport].dataType = cDataType->value[iReport].i; + + wiimote->nReport++; + } + + iReport++; + } +} + +void +reloadReportersForWiimoteNumber (CompDisplay *d, + int wiimoteNumber) +{ + CompWiimote *wiimote; + WIIMOTE_DISPLAY (d); + + for (wiimote = ad->wiimotes; wiimote; wiimote = wiimote->next) + { + if (wiimote->id == wiimoteNumber) + { + reloadReportersForWiimote (d, wiimote); + break; + } + } +} + +void +reloadGesturesForWiimote (CompDisplay *d, + CompWiimote *wiimote) +{ + CompListValue *cWiimoteNumber = wiimoteGetGestureWiimoteNumber (d); + CompListValue *cGestureType = wiimoteGetGestureType (d); + CompListValue *cPluginName = wiimoteGetGesturePluginName (d); + CompListValue *cActionName = wiimoteGetGestureActionName (d); + CompListValue *cGestureSensitivity = wiimoteGetGestureSensitivity (d); + + int nGesture; + int iGesture = 0; + + if ((cWiimoteNumber->nValue != cGestureType->nValue) || + (cWiimoteNumber->nValue != cPluginName->nValue) || + (cWiimoteNumber->nValue != cGestureSensitivity->nValue) || + (cWiimoteNumber->nValue != cActionName->nValue)) { - nReport = cWiimoteNumber->nValue; - iReport = 0; - ad->cWiimote[i].nReport = 0; - int k = 0; + /* Options have not been set correctly */ + return; + } - while (nReport-- && iReport < MAX_REPORTS - 1) + nGesture = cWiimoteNumber->nValue; + iGesture = 0; + wiimote->nGesture = 0; + + while (nGesture-- && iGesture < MAX_GESTURES) + { + if (cWiimoteNumber->value[iGesture].i == wiimote->id) { - if (cWiimoteNumber->value[iReport].i == i) - { - /* And set them */ - ad->cWiimote[i].nReport++; - ad->cWiimote[i].report[k].set = TRUE; - ad->cWiimote[i].report[k].pluginName = strdup(cPluginName->value[iReport].s); - ad->cWiimote[i].report[k].actionName = strdup(cActionName->value[iReport].s); - ad->cWiimote[i].report[k].sensitivity = cReportSensitivity->value[iReport].i; - - ad->cWiimote[i].report[k].xarg = strdup(cXArgument->value[iReport].s); - ad->cWiimote[i].report[k].yarg = strdup(cYArgument->value[iReport].s); - ad->cWiimote[i].report[k].zarg = strdup(cZArgument->value[iReport].s); - - ad->cWiimote[i].report[k].type = cReportType->value[iReport].i; - ad->cWiimote[i].report[k].dataType = cDataType->value[iReport].i; - - k++; /* Set next availiable option */ - } - - iReport++; + wiimote->gesture[wiimote->nGesture].set = TRUE; + wiimote->gesture[wiimote->nGesture].pluginName = strdup(cPluginName->value[iGesture].s); + wiimote->gesture[wiimote->nGesture].actionName = strdup(cActionName->value[iGesture].s); + wiimote->gesture[wiimote->nGesture].sensitivity = cGestureSensitivity->value[iGesture].i; + wiimote->gesture[wiimote->nGesture].type = cGestureType->value[iGesture].i; + wiimote->nGesture++; + } + iGesture++; } } void -reloadWiimoteOptions (CompDisplay *d) +reloadGesturesForWiimoteNumber (CompDisplay *d, + int wiimoteNumber) +{ + CompWiimote *wiimote; + WIIMOTE_DISPLAY (d); + + for (wiimote = ad->wiimotes; wiimote; wiimote = wiimote->next) + { + if (wiimote->id == wiimoteNumber) + { + reloadGesturesForWiimote (d, wiimote); + break; + } + } +} + +void +reloadOptionsForWiimote (CompDisplay *d, + CompWiimote *wiimote) { CompListValue *cXCal = wiimoteGetXCalibrationMul (d); CompListValue *cYCal = wiimoteGetYCalibrationMul (d); CompListValue *cXAdj = wiimoteGetXAdjust (d); CompListValue *cYAdj = wiimoteGetYAdjust (d); - int nWiimote; - int iWiimote = 0; - int i = 0; - - WIIMOTE_DISPLAY (d); - if ((cXCal->nValue != cYCal->nValue) || (cXCal->nValue != cXAdj->nValue) || (cXCal->nValue != cYAdj->nValue)) @@ -163,21 +178,30 @@ reloadWiimoteOptions (CompDisplay *d) return; } - for (i = 0; i < MAX_WIIMOTES; i++) + if (wiimote->id < cXCal->nValue) { - nWiimote = cXCal->nValue; - iWiimote = 0; - while (nWiimote-- && iWiimote < MAX_REPORTS) - { - if (iWiimote == i) - { - ad->cWiimote[i].irMulX = cXCal->value[iWiimote].f; - ad->cWiimote[i].irMulY = cYCal->value[iWiimote].f; - ad->cWiimote[i].irSubX = cXAdj->value[iWiimote].f; - ad->cWiimote[i].irSubY = cYAdj->value[iWiimote].f; - } - - iWiimote++; - } + wiimote->irMulX = cXCal->value[wiimote->id].f; + wiimote->irMulY = cYCal->value[wiimote->id].f; + wiimote->irSubX = cXAdj->value[wiimote->id].f; + wiimote->irSubY = cYAdj->value[wiimote->id].f; } } + +void +reloadOptionsForWiimoteNumber (CompDisplay *d, + int wiimoteNumber) +{ + CompWiimote *wiimote; + WIIMOTE_DISPLAY (d); + + for (wiimote = ad->wiimotes; wiimote; wiimote = wiimote->next) + { + if (wiimote->id == wiimoteNumber) + { + reloadOptionsForWiimote (d, wiimote); + break; + } + } +} + + @@ -31,6 +31,8 @@ wiimoteDisplayOptionChanged (CompDisplay *d, CompOption *opt, WiimoteDisplayOptions num) { + CompWiimote *wiimote; + WIIMOTE_DISPLAY (d); switch (num) { @@ -39,7 +41,8 @@ wiimoteDisplayOptionChanged (CompDisplay *d, case WiimoteDisplayOptionXAdjust: case WiimoteDisplayOptionYAdjust: { - reloadWiimoteOptions (d); + for (wiimote = ad->wiimotes; wiimote; wiimote = wiimote->next) + reloadOptionsForWiimote (d, wiimote); break; } case WiimoteDisplayOptionGestureWiimoteNumber: @@ -48,7 +51,8 @@ wiimoteDisplayOptionChanged (CompDisplay *d, case WiimoteDisplayOptionGestureActionName: case WiimoteDisplayOptionGestureSensitivity: { - reloadWiimoteGestures (d); + for (wiimote = ad->wiimotes; wiimote; wiimote = wiimote->next) + reloadGesturesForWiimote (d, wiimote); break; } case WiimoteDisplayOptionReportWiimoteNumber: @@ -57,7 +61,8 @@ wiimoteDisplayOptionChanged (CompDisplay *d, case WiimoteDisplayOptionReportActionName: case WiimoteDisplayOptionReportSensitivity: { - reloadWiimoteReporters (d); + for (wiimote = ad->wiimotes; wiimote; wiimote = wiimote->next) + reloadReportersForWiimote (d, wiimote); break; } default: |