summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--compiz-wiimote.h9
-rw-r--r--wiimote.c392
2 files changed, 83 insertions, 318 deletions
diff --git a/compiz-wiimote.h b/compiz-wiimote.h
index 9c7674d..0c722d5 100644
--- a/compiz-wiimote.h
+++ b/compiz-wiimote.h
@@ -355,15 +355,6 @@ typedef struct _WiimoteDisplay
typedef struct _WiimoteScreen
{
PaintOutputProc paintOutput;
- int windowPrivateIndex;
- /* text display support */
- CompTexture textTexture;
- Pixmap textPixmap;
- int textWidth;
- int textHeight;
-
- Bool title;
-
} WiimoteScreen;
cwiid_mesg_callback_t cwiid_callback;
diff --git a/wiimote.c b/wiimote.c
index 2d60411..be7598a 100644
--- a/wiimote.c
+++ b/wiimote.c
@@ -149,193 +149,6 @@ static Bool wiimoteChangeLights(void *Wiimote)
/* Text Prompting Interface */
-static void
-wiimoteFreeWindowTitle (CompScreen *s)
-{
- WIIMOTE_SCREEN(s);
-
- if (!as->textPixmap)
- return;
-
- releasePixmapFromTexture (s, &as->textTexture);
- initTexture (s, &as->textTexture);
- XFreePixmap (s->display->display, as->textPixmap);
- as->textPixmap = None;
-}
-
-static void
-wiimoteRenderWindowTitle (CompScreen *s, char *stringData)
-{
- CompTextAttrib tA;
- int stride;
- void *data;
- char *string;
-
- string = stringData;
-
-
- WIIMOTE_SCREEN (s);
-
- //ringFreeWindowTitle (s);
-
- int ox1, ox2, oy1, oy2;
- getCurrentOutputExtents (s, &ox1, &oy1, &ox2, &oy2);
-
- /* 75% of the output device as maximum width */
- tA.maxWidth = (ox2 - ox1) * 3 / 4;
- tA.maxHeight = 100;
- tA.screen = s;
- tA.size = wiimoteGetTitleFontSize (s);
- tA.color[0] = wiimoteGetTitleFontColorRed (s);
- tA.color[1] = wiimoteGetTitleFontColorGreen (s);
- tA.color[2] = wiimoteGetTitleFontColorBlue (s);
- tA.color[3] = wiimoteGetTitleFontColorAlpha (s);
- tA.style = TEXT_STYLE_NORMAL;
- tA.family = "Sans";
- tA.ellipsize = FALSE;
-
- tA.renderMode = TextRenderNormal;
-
- tA.data = (void*)string;
-
- initTexture (s, &as->textTexture);
-
- if ((*s->display->fileToImage) (s->display, TEXT_ID, (char *)&tA,
- &as->textWidth, &as->textHeight,
- &stride, &data))
- {
- as->textPixmap = (Pixmap)data;
- bindPixmapToTexture (s, &as->textTexture, as->textPixmap,
- as->textWidth, as->textHeight, 32);
- }
- else
- {
- as->textPixmap = None;
- as->textWidth = 0;
- as->textHeight = 0;
- }
-}
-
-/* Stolen from ring.c */
-
-static void
-wiimoteDrawTitle (CompScreen *s)
-{
- WIIMOTE_SCREEN(s);
- GLboolean wasBlend;
- GLint oldBlendSrc, oldBlendDst;
-
- float width = as->textWidth;
- float height = as->textHeight;
- float border = 10.0f;
-
- int ox1, ox2, oy1, oy2;
- getCurrentOutputExtents (s, &ox1, &oy1, &ox2, &oy2);
-
- float x = ox1 + ((ox2 - ox1) / 2) - (as->textWidth / 2);
- float y = oy1 + ((oy2 - oy1) / 2) + (height / 2);;
-
- x = floor (x);
- y = floor (y);
-
- glGetIntegerv (GL_BLEND_SRC, &oldBlendSrc);
- glGetIntegerv (GL_BLEND_DST, &oldBlendDst);
- wasBlend = glIsEnabled (GL_BLEND);
-
- if (!wasBlend)
- glEnable (GL_BLEND);
- glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
-
- glColor4f(0.0f, 0.0f, 0.0f, 0.7f);
-
- glPushMatrix ();
-
- glTranslatef (x, y - height, 0.0f);
- glRectf (0.0f, height, width, 0.0f);
- glRectf (0.0f, 0.0f, width, -border);
- glRectf (0.0f, height + border, width, height);
- glRectf (-border, height, 0.0f, 0.0f);
- glRectf (width, height, width + border, 0.0f);
- glTranslatef (-border, -border, 0.0f);
-
-#define CORNER(a,b) \
- for (k = a; k < b; k++) \
- {\
- float rad = k * (PI / 180.0f);\
- glVertex2f (0.0f, 0.0f);\
- glVertex2f (cos (rad) * border, sin (rad) * border);\
- glVertex2f (cos ((k - 1) * (PI / 180.0f)) * border, \
- sin ((k - 1) * (PI / 180.0f)) * border);\
- }
-
- /* Rounded corners */
- int k;
-
- glTranslatef (border, border, 0.0f);
- glBegin (GL_TRIANGLES);
- CORNER (180, 270) glEnd ();
- glTranslatef (-border, -border, 0.0f);
-
- glTranslatef (width + border, border, 0.0f);
- glBegin (GL_TRIANGLES);
- CORNER (270, 360) glEnd ();
- glTranslatef (-(width + border), -border, 0.0f);
-
- glTranslatef (border, height + border, 0.0f);
- glBegin (GL_TRIANGLES);
- CORNER (90, 180) glEnd ();
- glTranslatef (-border, -(height + border), 0.0f);
-
- glTranslatef (width + border, height + border, 0.0f);
- glBegin (GL_TRIANGLES);
- CORNER (0, 90) glEnd ();
- glTranslatef (-(width + border), -(height + border), 0.0f);
-
- glPopMatrix ();
-
-#undef CORNER
-
- glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
- glColor4f (1.0, 1.0, 1.0, 1.0);
-
- enableTexture (s, &as->textTexture,COMP_TEXTURE_FILTER_GOOD);
-
- CompMatrix *m = &as->textTexture.matrix;
-
- glBegin (GL_QUADS);
-
- glTexCoord2f (COMP_TEX_COORD_X (m, 0), COMP_TEX_COORD_Y (m ,0));
- glVertex2f (x, y - height);
- glTexCoord2f (COMP_TEX_COORD_X (m, 0), COMP_TEX_COORD_Y (m, height));
- glVertex2f (x, y);
- glTexCoord2f (COMP_TEX_COORD_X (m, width), COMP_TEX_COORD_Y (m, height));
- glVertex2f (x + width, y);
- glTexCoord2f (COMP_TEX_COORD_X (m, width), COMP_TEX_COORD_Y (m, 0));
- glVertex2f (x + width, y - height);
-
- glEnd ();
-
- disableTexture (s, &as->textTexture);
- glColor4usv (defaultColor);
-
- if (!wasBlend)
- glDisable (GL_BLEND);
- glBlendFunc (oldBlendSrc, oldBlendDst);
-}
-
-static Bool
-removeTitle (void *vs)
-{
- CompScreen *s = (CompScreen *) vs;
-
- WIIMOTE_SCREEN (s);
-
- as->title = FALSE;
-
- wiimoteFreeWindowTitle (s);
- return FALSE;
-}
-
static Bool
allocateCallbackFunction (cwiid_wiimote_t *wiimote, int nWiimote)
{
@@ -400,7 +213,6 @@ static void* connectWiimote (void *vd)
CompDisplay *d = (CompDisplay *) vd;
bdaddr = *BDADDR_ANY;
CompScreen *s;
- char *stringData;
cwiid_wiimote_t *wiimote;
WIIMOTE_DISPLAY (d);
@@ -707,30 +519,24 @@ wiimotePaintOutput (CompScreen *s,
CompOutput *output,
unsigned int mask)
{
- Bool status;
+ Bool status;
- WIIMOTE_SCREEN (s);
- CompTransform sTransform = *transform;
-
- mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS_MASK;
-
- UNWRAP (as, s, paintOutput);
- status = (*s->paintOutput) (s, sAttrib, transform, region, output, mask);
- WRAP (as, s, paintOutput, wiimotePaintOutput);
+ WIIMOTE_SCREEN (s);
+ CompTransform sTransform = *transform;
+
+ mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS_MASK;
+
+ UNWRAP (as, s, paintOutput);
+ status = (*s->paintOutput) (s, sAttrib, transform, region, output, mask);
+ WRAP (as, s, paintOutput, wiimotePaintOutput);
transformToScreenSpace (s, output, -DEFAULT_Z_CAMERA, &sTransform);
-
+
glPushMatrix ();
glLoadMatrixf (sTransform.m);
- //glPopMatrix ();
- if (as->title)
- {
- wiimoteDrawTitle (s);
-
- }
- glPopMatrix ();
+ glPopMatrix ();
- return status;
+ return status;
}
/* Report Creation */
@@ -1279,7 +1085,6 @@ wiimoteToggle (CompDisplay *d,
int nOption)
{
int rc;
- char *stringData;
WIIMOTE_DISPLAY (d);
@@ -1298,49 +1103,48 @@ wiimoteToggle (CompDisplay *d,
s = findScreenAtDisplay (d, getIntOptionNamed (option, nOption,
"root", 0));
if (s) {
- ad->firstRoot = s->root;
-
- WIIMOTE_SCREEN (w->screen);
- /* 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);
+ 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);
- }
+ // 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;
}
@@ -1655,23 +1459,14 @@ static Bool
wiimoteInitCore (CompPlugin *p,
CompCore *c)
{
- WiimoteCore *wc;
-
if (!checkPluginABI ("core", CORE_ABIVERSION))
return FALSE;
- wc = malloc (sizeof (WiimoteCore));
- if (!wc)
- return FALSE;
-
wiimoteDisplayPrivateIndex = allocateDisplayPrivateIndex ();
if (wiimoteDisplayPrivateIndex < 0)
{
- free (wc);
return FALSE;
}
-
- c->base.privates[corePrivateIndex].ptr = wc;
firstDisplay = c->displays;
@@ -1682,58 +1477,7 @@ static void
wiimoteFiniCore (CompPlugin *p,
CompCore *c)
{
- WIIMOTE_CORE (c);
-
freeDisplayPrivateIndex (wiimoteDisplayPrivateIndex);
-
- free (wc);
-}
-
-
-static Bool
-wiimoteInitScreen (CompPlugin *p,
- CompScreen *s)
-{
- WiimoteScreen *as;
-
- WIIMOTE_DISPLAY (s->display);
-
- as = malloc (sizeof (WiimoteScreen));
- if (!as)
- return FALSE;
-
- as->windowPrivateIndex = allocateWindowPrivateIndex (s);
- if (as->windowPrivateIndex < 0)
- {
- free (as);
- return FALSE;
- }
-
- s->base.privates[ad->screenPrivateIndex].ptr = as;
-
- initTexture (s, &as->textTexture);
-
- as->textWidth = 0;
- as->textHeight = 0;
-
- as->textPixmap = None;
-
- as->title = FALSE;
-
- WRAP (as, s, paintOutput, wiimotePaintOutput);
-
- return TRUE;
-}
-
-static void
-wiimoteFiniScreen (CompPlugin *p,
- CompScreen *s)
-{
- WIIMOTE_SCREEN (s);
-
- UNWRAP (as, s, paintOutput);
-
- free (as);
}
static Bool
@@ -1813,6 +1557,36 @@ wiimoteFiniDisplay (CompPlugin *p,
free (ad);
}
+static Bool
+wiimoteInitScreen (CompPlugin *p,
+ CompScreen *s)
+{
+ WiimoteScreen *as;
+
+ WIIMOTE_DISPLAY (s->display);
+
+ as = malloc (sizeof (WiimoteScreen));
+ if (!as)
+ return FALSE;
+
+ s->base.privates[ad->screenPrivateIndex].ptr = as;
+
+ WRAP (as, s, paintOutput, wiimotePaintOutput);
+
+ return TRUE;
+}
+
+static void
+wiimoteFiniScreen (CompPlugin *p,
+ CompScreen *s)
+{
+ WIIMOTE_SCREEN (s);
+
+ UNWRAP (as, s, paintOutput);
+
+ free (as);
+}
+
static CompBool
wiimoteInitObject (CompPlugin *p,
CompObject *o)