summaryrefslogtreecommitdiff
path: root/cubedbus.c
diff options
context:
space:
mode:
authorJoel Bosveld <joel@JOEL-UBUNTU.(none)>2007-11-14 20:27:34 +0900
committerJoel Bosveld <joel@JOEL-UBUNTU.(none)>2007-11-14 20:27:34 +0900
commit719ffa8e7140d00ba9f063860238b74c7daccf75 (patch)
tree08ea48c7b166b099c7e8a53e209e733a67768fda /cubedbus.c
parentbbf78644d2fb9972d60fd22399fa7760d25428f9 (diff)
downloadcubedbus-719ffa8e7140d00ba9f063860238b74c7daccf75.tar.gz
cubedbus-719ffa8e7140d00ba9f063860238b74c7daccf75.tar.bz2
Added function to delete objects, and some docs
Diffstat (limited to 'cubedbus.c')
-rw-r--r--cubedbus.c104
1 files changed, 99 insertions, 5 deletions
diff --git a/cubedbus.c b/cubedbus.c
index ae8a484..dd950ed 100644
--- a/cubedbus.c
+++ b/cubedbus.c
@@ -1,4 +1,20 @@
-
+/*
+ *
+ * Copyright : (C) 2007 by Joel Bosveld
+ * E-mail : Joel.Bosveld@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 <stdbool.h>
#include <stdlib.h>
#include <string.h>
@@ -96,7 +112,6 @@ cubedbusAddObject (CompDisplay *d,
objptr->next->prev=objptr;
objptr=objptr->next; /* objptr now points to newly created object */
- compLogMessage (NULL, "cubedbus", CompLogLevelWarn, "created obj");
break;
}
else objptr=objptr->next;
@@ -108,8 +123,15 @@ cubedbusAddObject (CompDisplay *d,
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;
+
+ char *tempName=getStringOptionNamed (option,nOption,"name", "");
+ if(strcmp(tempName,"") == 0 || strlen(tempName) >= 16)
+ {
+ compLogMessage (NULL,"cubedbus",CompLogLevelError, "error with name");
+ return FALSE;
+ }
+
+ strcpy(objptr->name,tempName);
switch (objptr->type)
{
@@ -151,7 +173,7 @@ cubedbusAddObject (CompDisplay *d,
for(i=0;i</*num*/3;i++)
{
sprintf(string,"r%d",i);
- r=getFloatOptionNamed (option, nOption, string, 0.0 );
+ r=getFloatOptionNamed (option, nOption, string, 1.0 );
sprintf(string,"g%d",i);
g=getFloatOptionNamed (option, nOption, string, 0.0 );
sprintf(string,"b%d",i);
@@ -187,6 +209,77 @@ cubedbusAddObject (CompDisplay *d,
return FALSE;
}
+static Bool
+cubedbusDeleteObject (CompDisplay *d,
+ CompAction *action,
+ CompActionState state,
+ CompOption *option,
+ int nOption)
+{
+ CompScreen *s;
+ Window xid;
+ xid = getIntOptionNamed (option, nOption, "root", 0);
+ s = findScreenAtDisplay (d, xid);
+ CUBEDBUS_SCREEN(s);
+
+
+ CubedbusObject *objptr;
+ objptr=gs->head;
+ char name[16];
+
+ char *tempName=getStringOptionNamed (option,nOption,"name", "");
+
+ if(strlen(tempName) >= 16)
+ {
+ compLogMessage (NULL,"cubedbus",CompLogLevelError, "name is too long");
+ return FALSE;
+ }
+ strcpy(name,tempName);
+
+ /* Not IDEAL - also, may need a diff function to deal with different types */
+ if (objptr == NULL)
+ {
+ return FALSE;
+ }
+ else
+ {
+ while(1)
+ {
+ if(!strcmp(objptr->name,name))
+ {
+ /*
+
+
+ if(objptr->prev == NULL)
+ {
+ gs->head=objptr->next; // if first in list, or only element in list
+ }
+ else if (objptr->next == NULL)
+ {
+ objptr->prev->next == NULL // = objptr->next if last in list
+ }
+ else
+ {
+ objptr->prev->next=objptr->next;
+ objptr->next->prev=objptr->prev;
+ }
+ */
+
+ if(objptr->prev != NULL) objptr->prev->next=objptr->next;
+ else gs->head=objptr->next;
+
+ if(objptr->next != NULL) objptr->next->prev=objptr->prev;
+
+ compLogMessage(NULL, "cubedbus", CompLogLevelWarn, "w00t - object deleted %s", objptr->name);
+ //DELETE EVERYTHING
+ return TRUE;
+ }
+ objptr=objptr->next;
+ if(objptr==NULL)return FALSE;
+ }
+ }
+}
+
/* Drawing functions */
static bool
@@ -375,6 +468,7 @@ cubedbusInitDisplay (CompPlugin *p,
d->base.privates[displayPrivateIndex].ptr = gd; /* allows use of CUBEDBUS_DISPLAY macro */
cubedbusSetAddInitiate (d, cubedbusAddObject);
+ cubedbusSetDeleteInitiate (d, cubedbusDeleteObject);
return TRUE;