summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorPeter Mikkelsen <petermikkelsen10@gmail.com>2024-02-11 16:39:26 +0000
committerPeter Mikkelsen <petermikkelsen10@gmail.com>2024-02-11 16:39:26 +0000
commit0ad54d136ef33d61172658e97b538f7cd6a91c26 (patch)
tree2aa2817fbebca09ef0feffc507cb9b1b0acd654e /main.c
parent7aeae86d36a1a04e93bb4be2216cb735acfab714 (diff)
Add a basic textbox element
Diffstat (limited to 'main.c')
-rw-r--r--main.c46
1 files changed, 40 insertions, 6 deletions
diff --git a/main.c b/main.c
index 59e9d0c..8137fdb 100644
--- a/main.c
+++ b/main.c
@@ -101,13 +101,13 @@ settype(GuiElement *g, int type)
for(int i = 0; i < nbaseprops; i++){
int tag = baseprops[i];
props[i].tag = tag;
- props[i].val = propspecs[tag].def();
+ props[i].val = propspecs[tag].def(type, tag);
props[i].qid = mkpropqid(tag);
}
for(int i = 0; i < spec.nprops; i++){
int tag = spec.proptags[i];
props[i+nbaseprops].tag = tag;
- props[i+nbaseprops].val = propspecs[tag].def();
+ props[i+nbaseprops].val = propspecs[tag].def(type, tag);
props[i+nbaseprops].qid = mkpropqid(tag);
}
@@ -195,9 +195,14 @@ fswalk1(Fid *fid, char *name, Qid *qid)
fid->aux = g->parent;
*qid = g->parent->qid;
}
- }else if(strcmp(name, "clone") == 0)
- *qid = g->qclone;
- else if(strcmp(name, "event") == 0)
+ }else if(strcmp(name, "clone") == 0){
+ rlock(&g->lock);
+ if(guispecs[g->type].leafnode)
+ err = Eexist;
+ else
+ *qid = g->qclone;
+ runlock(&g->lock);
+ }else if(strcmp(name, "event") == 0)
*qid = g->qevent;
else if(strcmp(name, "type") == 0)
*qid = g->qtype;
@@ -304,6 +309,11 @@ dirtreegen(int n, Dir *d, void *aux)
d->gid = estrdup9p(username);
d->muid = estrdup9p(username);
+ rlock(&g->lock);
+ if(guispecs[g->type].leafnode)
+ n++;
+ runlock(&g->lock);
+
if(n < Fmax){
d->length = 0;
@@ -427,7 +437,31 @@ fswrite(Req *r)
switch(QID_TYPE(r->fid->qid)){
case Qtype:
- err = "Can't switch type";
+ {
+ char *buf = emalloc(r->ifcall.count + 1);
+ buf[r->ifcall.count] = 0;
+ memcpy(buf, r->ifcall.data, r->ifcall.count);
+
+ int type;
+ for(type = 0; type < Gmax; type++){
+ char *name = guispecs[type].name;
+ int len = strlen(name);
+ if(strncmp(buf, name, len) == 0 && allspace(buf+len)){
+ rlock(&g->lock);
+ int canswitch = (g->nchildren == 0 || guispecs[type].leafnode == 0);
+ runlock(&g->lock);
+
+ if(canswitch)
+ settype(g, type);
+ else
+ err = "old node has children, and new node type can't";
+ break;
+ }
+ }
+ if(type == Gmax)
+ err = "no such gui element type";
+ free(buf);
+ }
break;
case Qprop:
{