summaryrefslogtreecommitdiff
path: root/cubedbus.c
diff options
context:
space:
mode:
Diffstat (limited to 'cubedbus.c')
-rw-r--r--cubedbus.c510
1 files changed, 510 insertions, 0 deletions
diff --git a/cubedbus.c b/cubedbus.c
new file mode 100644
index 0000000..c9cb93c
--- /dev/null
+++ b/cubedbus.c
@@ -0,0 +1,510 @@
+
+#include <stdbool.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <signal.h>
+#include <unistd.h>
+#include <math.h>
+
+#include <compiz-core.h>
+#include <compiz-cube.h>
+
+#include "cubedbus_options.h"
+#include "cubedbus.h"
+
+#define PI 3.14159
+
+static int displayPrivateIndex;
+
+static int cubeDisplayPrivateIndex;
+
+typedef struct _CubedbusDisplay
+{
+ int screenPrivateIndex;
+
+}
+CubedbusDisplay;
+
+typedef struct _CubedbusScreen
+{
+ DonePaintScreenProc donePaintScreen;
+ PreparePaintScreenProc preparePaintScreen;
+
+ CubeClearTargetOutputProc clearTargetOutput;
+ CubePaintInsideProc paintInside;
+
+ Bool damage;
+
+ CubedbusObject *head;
+
+}
+CubedbusScreen;
+
+#define GET_CUBEDBUS_DISPLAY(d) \
+ ((CubedbusDisplay *) (d)->base.privates[displayPrivateIndex].ptr)
+#define CUBEDBUS_DISPLAY(d) \
+ CubedbusDisplay *gd = GET_CUBEDBUS_DISPLAY(d); /* Macros to get the gd pointer to CubedbusDisplay struct */
+
+#define GET_CUBEDBUS_SCREEN(s, gd) \
+ ((CubedbusScreen *) (s)->base.privates[(gd)->screenPrivateIndex].ptr)
+#define CUBEDBUS_SCREEN(s) \
+ CubedbusScreen *gs = GET_CUBEDBUS_SCREEN(s, GET_CUBEDBUS_DISPLAY(s->display)) /* Macros to get the gs pointer to CubedbusScreen struct */
+
+
+static Bool
+cubedbusAddObject (CompDisplay *d,
+ CompAction *action,
+ CompActionState state,
+ CompOption *option,
+ int nOption)
+{
+ //get gs pointer
+ CompScreen *s;
+ Window xid;
+ xid = getIntOptionNamed (option, nOption, "root", 0);
+ s = findScreenAtDisplay (d, xid);
+ CUBEDBUS_SCREEN(s);
+
+ compLogMessage (NULL, "cubedbus", CompLogLevelWarn, "Adding Object");
+
+ GLint err;
+ while((err=glGetError())){
+ compLogMessage (NULL, "cubedbus", CompLogLevelError, "before %d",err);}
+
+
+ CubedbusObject *objptr;
+ objptr=gs->head;
+
+ if (gs->head == NULL)
+ {
+ gs->head = malloc (sizeof(CubedbusObject));
+ if(gs->head == NULL) return FALSE;
+ objptr=gs->head;
+ objptr->prev = NULL;
+ }
+ else
+ {
+ while(1)
+ {
+ if(objptr->next == NULL )
+ {
+ objptr->next = malloc (sizeof(CubedbusObject));
+ if(objptr->next == NULL) return FALSE;
+ objptr->next->prev=objptr;
+ objptr=objptr->next; /* objptr now points to newly created object */
+ }
+ else objptr=objptr->next;
+ }
+ }
+
+ /* have now created CubedbusObject */
+
+ objptr->next=NULL;
+ objptr->type=getIntOptionNamed (option,nOption, "type", 0);
+ if(objptr->type == 0) return FALSE;
+ objptr->name=getStringOptionNamed (option,nOption,"name", "");
+ if(strcmp(objptr->name,"") == 0) return FALSE;
+
+ switch (objptr->type)
+ {
+ case CUBEDBUS_COLOUR_OBJECT:
+ {
+ compLogMessage (NULL, "cubedbus", CompLogLevelWarn, "Adding ColourObject");
+
+ objptr->func=&cubedbusDrawColourObject;
+ objptr->data= malloc( sizeof(CubedbusColourObject) );
+ if(objptr->data == NULL) return FALSE;
+
+ CubedbusColourObject *colourData=objptr->data;
+
+ colourData->rotate[0]=getFloatOptionNamed (option,nOption, "rotateAngle", 0.0);
+ colourData->rotate[1]=getFloatOptionNamed (option,nOption, "rotateX", 1.0);
+ colourData->rotate[2]=getFloatOptionNamed (option,nOption, "rotateY", 0.0);
+ colourData->rotate[3]=getFloatOptionNamed (option,nOption, "rotateZ", 0.0);
+ colourData->translate[0]=getFloatOptionNamed (option,nOption, "translateX", 0.0);
+ colourData->translate[1]=getFloatOptionNamed (option,nOption, "translateY", 0.0);
+ colourData->translate[2]=getFloatOptionNamed (option,nOption, "translateZ", 0.0);
+ colourData->scale[0]=getFloatOptionNamed (option,nOption, "scaleX", 1.0);
+ colourData->scale[1]=getFloatOptionNamed (option,nOption, "scaleY", 1.0);
+ colourData->scale[2]=getFloatOptionNamed (option,nOption, "scaleZ", 1.0);
+ colourData->order=getBoolOptionNamed (option, nOption, "order", TRUE);
+
+ compLogMessage (NULL, "cubedbus", CompLogLevelWarn, "translate %f", colourData->translate[0]);
+
+ /* Code to make dList */
+
+ colourData->dList=glGenLists (1);
+ glNewList (colourData->dList, GL_COMPILE);
+
+
+ int i;
+ float r,g,b,a;
+ float x,y,z;
+ char string[4];
+
+ glBegin(GL_POLYGON);
+
+ for(i=0;i</*num*/3;i++)
+ {
+ sprintf(string,"r%d",i);
+ r=getFloatOptionNamed (option, nOption, string, 1.0 );
+ sprintf(string,"g%d",i);
+ g=getFloatOptionNamed (option, nOption, string, 0.0 );
+ sprintf(string,"b%d",i);
+ b=getFloatOptionNamed (option, nOption, string, 0.0 );
+ sprintf(string,"a%d",i);
+ a=getFloatOptionNamed (option, nOption, string, 1.0 );
+ sprintf(string,"x%d",i);
+ x=getFloatOptionNamed (option, nOption, string, 0.0);
+ sprintf(string,"y%d",i);
+ y=getFloatOptionNamed (option, nOption, string, 0.0);
+ sprintf(string,"z%d",i);
+ z=getFloatOptionNamed (option, nOption, string, 0.0 );
+
+
+ glColor4f(r,g,b,a);
+ glVertex3f( x, y, z);
+ }
+ glEnd();
+
+ glEndList();
+
+
+ return TRUE;
+ break;
+ }
+ case CUBEDBUS_TEXTURE_OBJECT:
+ {
+ return TRUE;
+ break;
+ }
+ }
+
+ return FALSE;
+}
+
+/* Drawing functions */
+
+static bool
+cubedbusDrawColourObject (CubedbusObject *obj)
+{
+ glShadeModel (GL_SMOOTH);
+
+ CubedbusColourObject *data=obj->data;
+
+ if(data->order) glTranslatef (data->translate[0], data->translate[1], data->translate[2]);
+ glRotatef ( data->rotate[0], data->rotate[1], data->rotate[2], data->rotate[3]);
+ if(!(data->order)) glTranslatef (data->translate[0], data->translate[1], data->translate[2]);
+
+ glScalef( data->scale[0],data->scale[1], data->scale[2]); /* Rotate, translate and scale */
+
+
+
+ glCallList(data->dList);
+
+
+
+
+ return TRUE;
+}
+
+static bool
+cubedbusDrawTextureObject (CubedbusObject *obj)
+{
+ return TRUE;
+}
+
+/* Standard plugin 'stuff' */
+
+static void
+cubedbusClearTargetOutput (CompScreen *s, /* Doesn't do anything except glClear(GL_DEPTH_BUFFER_BIT)? - cube must change it? */
+ float xRotate,
+ float vRotate)
+{
+ CUBEDBUS_SCREEN (s);
+ CUBE_SCREEN (s);
+
+ UNWRAP (gs, cs, clearTargetOutput);
+ (*cs->clearTargetOutput) (s, xRotate, vRotate);
+ WRAP (gs, cs, clearTargetOutput, cubedbusClearTargetOutput);
+
+ glClear (GL_DEPTH_BUFFER_BIT);
+}
+
+static void /* draws the cubedbus, then calls the cube function */
+cubedbusPaintInside (CompScreen *s,
+ const ScreenPaintAttrib *sAttrib,
+ const CompTransform *transform,
+ CompOutput *output,
+ int size)
+{
+ CUBEDBUS_SCREEN (s);
+ CUBE_SCREEN (s);
+
+ Bool enabled;
+
+ ScreenPaintAttrib sA = *sAttrib;
+
+ sA.yRotate += (360.0f / size) * (cs->xRotations - (s->x * cs->nOutput)); /*?*/
+
+ CompTransform mT = *transform;
+
+ (*s->applyScreenTransform) (s, &sA, output, &mT);
+
+ glPushMatrix();
+ glLoadMatrixf (mT.m);
+ glTranslatef (cs->outputXOffset, -cs->outputYOffset, 0.0f); /* OpenGL stuff to set correct transformation due to cube rotation? */
+ glScalef (cs->outputXScale, cs->outputYScale, 1.0f);
+
+ glPushAttrib (GL_COLOR_BUFFER_BIT | GL_TEXTURE_BIT);
+
+ enabled = glIsEnabled (GL_CULL_FACE);
+
+ glDisable(GL_CULL_FACE);
+
+
+ glPushMatrix();
+
+ glDisable (GL_LIGHTING);
+ glDisable (GL_COLOR_MATERIAL);
+ glEnable (GL_DEPTH_TEST);
+
+/*********************************************/
+
+ CubedbusObject *obj=gs->head;
+
+ while(true)
+ {
+ if(obj == NULL) break; /* pull out of loop if finished drawing all objects */
+
+ glPushMatrix();
+
+ if(!( (obj->func) (obj) )) compLogMessage(NULL, "cubedbus", CompLogLevelWarn, "error calling function") ; /* Call function */
+
+ glPopMatrix();
+
+ obj = obj->next;
+ }
+
+/**********************************************/
+
+ glPopMatrix();
+
+ glEnable (GL_COLOR_MATERIAL);
+
+ if (s->lighting)
+ glEnable (GL_LIGHTING);
+
+ glDisable (GL_DEPTH_TEST);
+ glDisable (GL_BLEND);
+
+ if (enabled) glEnable (GL_CULL_FACE);
+ else glDisable (GL_CULL_FACE); /* resets settings to original */
+
+ glPopMatrix();
+ glPopAttrib();
+
+ gs->damage = TRUE;
+
+ UNWRAP (gs, cs, paintInside);
+ (*cs->paintInside) (s, sAttrib, transform, output, size);
+ WRAP (gs, cs, paintInside, cubedbusPaintInside);
+}
+
+static void
+cubedbusPreparePaintScreen (CompScreen *s,
+ int ms)
+{
+ CUBEDBUS_SCREEN (s);
+
+ /* check for messages */
+
+ UNWRAP (gs, s, preparePaintScreen);
+ (*s->preparePaintScreen) (s, ms);
+ WRAP (gs, s, preparePaintScreen, cubedbusPreparePaintScreen);
+}
+
+static void /* Calls damageScreen ? */
+cubedbusDonePaintScreen (CompScreen * s)
+{
+ CUBEDBUS_SCREEN (s);
+
+ if (gs->damage)
+ {
+ damageScreen (s);
+ gs->damage = FALSE;
+ }
+
+ UNWRAP (gs, s, donePaintScreen);
+ (*s->donePaintScreen) (s);
+ WRAP (gs, s, donePaintScreen, cubedbusDonePaintScreen);
+}
+
+/* Inits display */
+
+static Bool
+cubedbusInitDisplay (CompPlugin *p,
+ CompDisplay *d)
+{
+ CubedbusDisplay *gd;
+
+ if (!checkPluginABI ("core", CORE_ABIVERSION) ||
+ !checkPluginABI ("cube", CUBE_ABIVERSION))
+ return FALSE;
+
+ if (!getPluginDisplayIndex (d, "cube", &cubeDisplayPrivateIndex))
+ return FALSE;
+
+ gd = malloc (sizeof (CubedbusDisplay)); /* creates data struct - remainder is error checking */
+
+ if (!gd)
+ return FALSE;
+
+ gd->screenPrivateIndex = allocateScreenPrivateIndex (d);
+
+ if (gd->screenPrivateIndex < 0)
+ {
+ free (gd);
+ return FALSE;
+ }
+
+ d->base.privates[displayPrivateIndex].ptr = gd; /* allows use of CUBEDBUS_DISPLAY macro */
+
+ cubedbusSetAddInitiate (d, cubedbusAddObject);
+
+
+ return TRUE;
+}
+
+static void
+cubedbusFiniDisplay (CompPlugin *p,
+ CompDisplay *d)
+{
+ CUBEDBUS_DISPLAY (d);
+
+ freeScreenPrivateIndex (d, gd->screenPrivateIndex);
+ free (gd);
+}
+
+
+/* Function which is run when screen is initialized */
+
+static Bool
+cubedbusInitScreen (CompPlugin *p,
+ CompScreen *s)
+{
+ CubedbusScreen *gs;
+
+ CUBEDBUS_DISPLAY (s->display); /* sets gd pointer used below */
+
+ CUBE_SCREEN (s);
+
+ gs = malloc (sizeof (CubedbusScreen) ); /* creates gearScreen struct */
+
+ if (!gs)
+ return FALSE;
+
+ s->base.privates[gd->screenPrivateIndex].ptr = gs; /* For the CUBEDBUS_SCREEN macro to work */
+
+ gs->head= NULL;
+
+
+ WRAP (gs, s, donePaintScreen, cubedbusDonePaintScreen); /*Functions version of ... is called instead of cores (which then also calls core function) */
+ WRAP (gs, s, preparePaintScreen, cubedbusPreparePaintScreen);
+ WRAP (gs, cs, clearTargetOutput, cubedbusClearTargetOutput);
+ WRAP (gs, cs, paintInside, cubedbusPaintInside);
+
+ return TRUE;
+
+}
+
+/* Fuction is run when screen is uninitialized */
+
+static void
+cubedbusFiniScreen (CompPlugin *p,
+ CompScreen *s)
+{
+ CUBEDBUS_SCREEN (s); /*Sets the pointers cs gs */
+ CUBE_SCREEN (s);
+
+
+
+
+ UNWRAP (gs, s, donePaintScreen); /* gs is pointer to structure GearScreen, s is pointer to structure screen? - these functions are core functions*/
+ UNWRAP (gs, s, preparePaintScreen);
+
+ UNWRAP (gs, cs, clearTargetOutput); /* ... cs is pointer to structure CubeScreen? - these two functions are part of the Cube plugin*/
+ UNWRAP (gs, cs, paintInside);
+
+
+
+ free (gs);
+}
+
+/* Load and Unload plugin */
+
+static Bool
+cubedbusInit (CompPlugin * p)
+{
+ displayPrivateIndex = allocateDisplayPrivateIndex();
+
+ if (displayPrivateIndex < 0)
+ return FALSE;
+
+ return TRUE;
+}
+
+static void
+cubedbusFini (CompPlugin * p)
+{
+ if (displayPrivateIndex >= 0)
+ freeDisplayPrivateIndex (displayPrivateIndex);
+}
+
+/* Init Object - lists functions for Core, Display and Screen */
+
+static CompBool
+cubedbusInitObject (CompPlugin *p,
+ CompObject *o)
+{
+ static InitPluginObjectProc dispTab[] = {
+ (InitPluginObjectProc) 0, /* InitCore */
+ (InitPluginObjectProc) cubedbusInitDisplay,
+ (InitPluginObjectProc) cubedbusInitScreen
+ };
+
+ RETURN_DISPATCH (o, dispTab, ARRAY_SIZE (dispTab), TRUE, (p, o));
+}
+
+static void
+cubedbusFiniObject (CompPlugin *p,
+ CompObject *o)
+{
+ static FiniPluginObjectProc dispTab[] = {
+ (FiniPluginObjectProc) 0, /* FiniCore */
+ (FiniPluginObjectProc) cubedbusFiniDisplay,
+ (FiniPluginObjectProc) cubedbusFiniScreen
+ };
+
+ DISPATCH (o, dispTab, ARRAY_SIZE (dispTab), (p, o));
+}
+
+/* VTable */
+
+CompPluginVTable cubedbusVTable = {
+ "cubedbus",
+ 0, /* (?) */
+ cubedbusInit,
+ cubedbusFini,
+ cubedbusInitObject,
+ cubedbusFiniObject,
+ 0, /* Get(?) Object Options */
+ 0 /* Set(?) Object Options */
+};
+
+CompPluginVTable *
+getCompPluginInfo (void)
+{
+ return &cubedbusVTable;
+}