summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Spillaz <smspillaz@gmail.com>2008-04-26 21:15:02 +0800
committerSam Spillaz <smspillaz@gmail.com>2008-04-26 21:15:02 +0800
commit1555dbd527ed4dae30e61e49042f581527c8877d (patch)
tree94fa6a028e52d9735acb835a9883ed606cc83864
parent416d9a4ad1a0d78edb18153b329851581a3b13c8 (diff)
downloadwiimote-1555dbd527ed4dae30e61e49042f581527c8877d.tar.gz
wiimote-1555dbd527ed4dae30e61e49042f581527c8877d.tar.bz2
* Part 8: Split actions into action.c
-rw-r--r--compiz-wiimote.h21
-rw-r--r--wiimote.c174
2 files changed, 21 insertions, 174 deletions
diff --git a/compiz-wiimote.h b/compiz-wiimote.h
index e5652bc..c79fbde 100644
--- a/compiz-wiimote.h
+++ b/compiz-wiimote.h
@@ -390,6 +390,27 @@ reloadWiimoteReporters(CompDisplay *d);
void
reloadWiimoteOptions (CompDisplay *d);
+Bool
+wiimoteToggle (CompDisplay *d,
+ CompAction *action,
+ CompActionState cstate,
+ CompOption *option,
+ int nOption);
+
+Bool
+wiimoteDisable (CompDisplay *d,
+ CompAction *action,
+ CompActionState cstate,
+ CompOption *option,
+ int nOption);
+
+Bool
+wiimoteSendInfo (CompDisplay *d,
+ CompAction *action,
+ CompActionState cstate,
+ CompOption *option,
+ int nOption);
+
/* Shortcut Macros --------------------------------------------------- */
#define toggle_bit(bf,b) \
diff --git a/wiimote.c b/wiimote.c
index 8d63abf..f8450e4 100644
--- a/wiimote.c
+++ b/wiimote.c
@@ -64,180 +64,6 @@ wiimotePaintOutput (CompScreen *s,
glPopMatrix ();
return status;
-}
-/* Callable Actions --------------------------------------------------- */
-
-static Bool
-wiimoteToggle (CompDisplay *d,
- CompAction *action,
- CompActionState cstate,
- CompOption *option,
- int nOption)
-{
- int rc;
-
- WIIMOTE_DISPLAY (d);
-
- /* Create second thread attributes */
-
- pthread_attr_t secondThreadAttr;
- pthread_attr_init(&secondThreadAttr);
- pthread_attr_setdetachstate(&secondThreadAttr, PTHREAD_CREATE_JOINABLE);
-
- CompWindow *w;
- w = findWindowAtDisplay (d, getIntOptionNamed (option, nOption,
- "window", 0));
- if (!w)
- return TRUE;
-
- CompScreen *s;
- s = findScreenAtDisplay (d, getIntOptionNamed (option, nOption,
- "root", 0));
- if (s)
- {
- ad->firstRoot = s->root;
-
- /* Create Message */
- CompOption arg[4];
- int nArg = 0;
-
- arg[nArg].name = "window";
- arg[nArg].type = CompOptionTypeInt;
- arg[nArg].value.i = d->activeWindow;
- nArg++;
-
- arg[nArg].name = "root";
- arg[nArg].type = CompOptionTypeInt;
- arg[nArg].value.i = s->root;
- nArg++;
-
- arg[nArg].name = "string";
- arg[nArg].type = CompOptionTypeString;
- arg[nArg].value.s = "Put your Wii Remote in a neutral position and \n"\
- "hold down the 1 and 2 Buttons now";
- nArg++;
-
- arg[nArg].name = "timeout";
- arg[nArg].type = CompOptionTypeInt;
- arg[nArg].value.i = 2000;
-
- sendInfoToPlugin (d, arg, nArg,
- "prompt",
- "display_text");
- compLogMessage (d, "wiimote", CompLogLevelInfo,
- "Hold down the 1 and 2 Buttons on your Nintendo Wii Remote now");
- /* Create the second thread. */
- rc = pthread_create(&ad->cWiimote[ad->nWiimote].connectWiimote, &secondThreadAttr, connectWiimote, (void *)d);
-
- /* Clean up second thread's attribute. */
- pthread_attr_destroy(&secondThreadAttr);
- if (!rc)
- {
- /* So the thread succeeded!
- * Start Checking! */
- ad->checkingTimeoutHandle = compAddTimeout (10, checkConnected, d);
- }
- }
- return TRUE;
-}
-
-static Bool
-wiimoteDisable (CompDisplay *d,
- CompAction *action,
- CompActionState cstate,
- CompOption *option,
- int nOption)
-{
-
- int rc;
-
- WIIMOTE_DISPLAY (d);
-
- /* nWiimote -1 because we increment nWiimote
- * so we need to find the most recent (Which is -1)
- */
-
-
- if (ad->nWiimote < 1)
- return FALSE;
-
- ad->cWiimote[ad->nWiimote - 1].initiated = FALSE;
- ad->cWiimote[ad->nWiimote - 1].connected = FALSE;
-
- /* Wait for the second thread to return control to itself */
-
- rc = pthread_join(ad->cWiimote[ad->nWiimote -1].connectWiimote, NULL);
- if (rc)
- compLogMessage (d, "wiimote", CompLogLevelError,
- "Threading error occurred.\n");
-
- /* Remove timeout handles */
-
- if (ad->infoTimeoutHandle)
- compRemoveTimeout (ad->infoTimeoutHandle);
-
- if (ad->gestureTimeoutHandle)
- compRemoveTimeout (ad->gestureTimeoutHandle);
-
- /* Remove the lights timeout handle */
-
- if (ad->cWiimote[ad->nWiimote - 1].lightsTimeoutHandle)
- compRemoveTimeout (ad->cWiimote[ad->nWiimote - 1].lightsTimeoutHandle);
-
- /* Tell the user that we are closing the connection */
-
- compLogMessage (d, "wiimote", CompLogLevelInfo,
- "Closing connection to most recently connected Wii Remote\n");
- if (cwiid_close(ad->cWiimote[ad->nWiimote - 1].wiimote)) {
- compLogMessage (d, "wiimote", CompLogLevelError,
- "Error closing that connection\n");
- return -1;
- }
-
- /* Decrement Wiimote Iter */
-
- ad->nWiimote--;
-
- return TRUE;
-}
-
-static Bool
-wiimoteSendInfo (CompDisplay *d,
- CompAction *action,
- CompActionState cstate,
- CompOption *option,
- int nOption)
-{
- WIIMOTE_DISPLAY (d);
-
- Window root;
- CompScreen *s;
-
- ad->report = !ad->report;
-
- if (!ad->report)
- {
- if (ad->infoTimeoutHandle)
- compRemoveTimeout (ad->infoTimeoutHandle);
- return FALSE;
- }
-
- root = getIntOptionNamed (option, nOption, "root", 0);
- s = findScreenAtDisplay (d, root);
-
- if (s)
- {
- /* Add a timeout to send info to another
- * plugin. The preferable way would be for
- * other plugins to get the values when they
- * need them, but this is just a workaround
- * for plugins that support the action system
- */
-
- ad->infoTimeoutHandle = compAddTimeout(wiimoteGetPollInterval (s->display) , sendReports, s);
- ad->gestureTimeoutHandle = compAddTimeout(wiimoteGetGestureTimeout (s->display) , wiimoteCheckForGestures, s);
- }
- return TRUE;
}
static void