commit a38844287a53586bd2d799b6ecb3d67e640426f3
parent cbdb1fb9b884d61adbf26c7c1071858c1c88f7cf
Author: Anselm R. Garbe <garbeam@wmii.de>
Date: Thu, 9 Mar 2006 22:43:24 +0100
removed /def/class namespace, instead we got TCR events, though I consider if Uriel provides a nice rule engine in lesser then 100LOC I'm fine with his proposal
Diffstat:
7 files changed, 39 insertions(+), 269 deletions(-)
diff --git a/cmd/wm/Makefile b/cmd/wm/Makefile
@@ -9,7 +9,7 @@ LDFLAGS += -L../../liblitz -llitz -L../../libixp -lixp -L../../libcext -lcext
# Solaris
# LDFLAGS += -lsocket
-SRC = area.c bar.c class.c fs.c frame.c wm.c kb.c client.c event.c mouse.c tag.c
+SRC = area.c bar.c fs.c frame.c wm.c kb.c client.c event.c mouse.c tag.c
OBJ = ${SRC:.c=.o}
all: wmiiwm
diff --git a/cmd/wm/class.c b/cmd/wm/class.c
@@ -1,92 +0,0 @@
-/*
- * (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com>
- * See LICENSE file for license details.
- */
-
-#include <string.h>
-#include <stdlib.h>
-
-#include "wm.h"
-
-static TClass *
-classinst2class(char *sclass, char *sinst)
-{
- unsigned int i;
- for(i = 0; i < nclass; i++) {
- TClass *tc = class[i];
- if((!strncmp(tc->class, sclass, sizeof(tc->class)) ||
- !strncmp(tc->class, "*", sizeof(tc->class)))
- &&
- (!strncmp(tc->instance, sinst, sizeof(tc->instance)) ||
- !strncmp(tc->instance, "*", sizeof(tc->instance))))
- return tc;
- }
- return nil;
-}
-
-TClass *
-get_class(const char *name)
-{
- TClass *tc;
- char buf[256];
- char *p;
- static unsigned int id = 1;
-
- cext_strlcpy(buf, name, sizeof(buf));
- if(!(p = strchr(buf, ':')))
- return nil;
-
- *p = 0;
- p++;
-
- if((tc = classinst2class(buf, p)))
- return tc;
-
- tc = cext_emallocz(sizeof(TClass));
- tc->id = id++;
- cext_strlcpy(tc->class, buf, sizeof(tc->class));
- cext_strlcpy(tc->instance, p, sizeof(tc->instance));
- class = (TClass **)cext_array_attach((void **)class, tc, sizeof(TClass *), &classsz);
- nclass++;
-
- return tc;
-}
-
-void
-destroy_class(TClass *tclass)
-{
- cext_array_detach((void **)class, tclass, &classsz);
- nclass--;
- free(tclass);
-}
-
-int
-classid2index(unsigned short id)
-{
- int i;
- for(i = 0; i < nclass; i++)
- if(class[i]->id == id)
- return i;
- return -1;
-}
-
-TClass *
-name2class(const char *name)
-{
- char buf[256];
- char *p;
-
- cext_strlcpy(buf, name, sizeof(buf));
- if(!(p = strchr(buf, ':')))
- return nil;
-
- *p = 0;
- p++;
- return classinst2class(buf, p);
-}
-
-TClass *
-client2class(Client *c)
-{
- return classinst2class(c->class, c->instance);
-}
diff --git a/cmd/wm/client.c b/cmd/wm/client.c
@@ -16,7 +16,6 @@ alloc_client(Window w, XWindowAttributes *wa)
XTextProperty name;
Client *c = (Client *) cext_emallocz(sizeof(Client));
XSetWindowAttributes fwa;
- XClassHint ch;
long msize;
static unsigned int id = 1;
@@ -38,11 +37,6 @@ alloc_client(Window w, XWindowAttributes *wa)
cext_strlcpy(c->name, (char *)name.value, sizeof(c->name));
free(name.value);
}
- if(XGetClassHint(dpy, c->win, &ch)) {
- cext_strlcpy(c->class, ch.res_class, sizeof(c->class));
- cext_strlcpy(c->instance, ch.res_name, sizeof(c->instance));
- }
-
fwa.override_redirect = 1;
fwa.background_pixmap = ParentRelative;
fwa.event_mask = SubstructureRedirectMask | ExposureMask | ButtonPressMask | PointerMotionMask;
@@ -321,9 +315,23 @@ gravitate(Client *c, Bool invert)
void
manage_client(Client *c)
{
- TClass *tc = client2class(c);
Tag *t;
+ XClassHint ch;
+ char buf[256];
+ unsigned int i;
+ for(i = 0; i < nclient; i++)
+ if(client[i] == c)
+ break;
+
+ /* TCR -> tag client request */
+ XGetClassHint(dpy, c->win, &ch);
+ snprintf(buf, sizeof(buf), "TCR %u 0x%x 0x%x %s:%s\n", i,
+ (unsigned int)c->win, (unsigned int)c->trans, ch.res_class, ch.res_name);
+ XFree(ch.res_class);
+ XFree(ch.res_name);
+ write_event(buf);
+
if(c->trans) {
c->tags[0] = '~';
c->tags[1] = 0;
@@ -332,9 +340,8 @@ manage_client(Client *c)
c->tags[0] = 0;
t = ntag ? tag[sel] : alloc_tag(def.tag);
- cext_strlcat(c->tags, tc && strlen(tc->tags) ? tc->tags : t->name, sizeof(c->tags));
- if(!strncmp(c->tags, "~", 2)) /* allows ~ predefinition to only set specific TClass'es floating */
- cext_strlcat(c->tags, t->name, sizeof(c->tags));
+ cext_strlcat(c->tags, t->name, sizeof(c->tags));
+
update_tags();
/* shorthand proposed by Georg Neis */
@@ -343,7 +350,7 @@ manage_client(Client *c)
char ct[256];
char *p;
- cext_strlcpy(ct, tc && strlen(tc->tags) ? tc->tags : t->name, sizeof(ct));
+ cext_strlcpy(ct, t->name, sizeof(ct));
if((p = strchr(ct, ' ')))
*p = 0;
select_tag(ct);
diff --git a/cmd/wm/fs.c b/cmd/wm/fs.c
@@ -38,7 +38,6 @@ static char Enocommand[] = "command not supported";
* /def/font FsFfont xlib font name
* /def/selcolors FsFselcolors sel color
* /def/normcolors FsFnormcolors normal colors
- * /def/tag FsFtag default tag
* /keys/ FsDkeys
* /keys/foo FsFkey
* /tags/ FsDtags
@@ -48,13 +47,12 @@ static char Enocommand[] = "command not supported";
* /bar/lab/ FsDlabel
* /bar/lab/data FsFdata <arbitrary data which gets displayed>
* /bar/lab/colors FsFcolors <#RRGGBB> <#RRGGBB> <#RRGGBB>
- * /class FsDclass class namespace to define client-specific tags
- * /class/class:inst FsFclasstag
* /clients/ FsDclients
* /clients/1/ FsDGclient see /X/X/X/ namespace below
* /event FsFevent
* /ctl FsFctl command interface (root)
* /ws/ FsDws ws
+ * /ws/tag FsFtag current tag
* /ws/ctl FsFctl command interface (tag)
* /ws/sel/ FsDarea
* /ws/1/ FsDarea
@@ -62,7 +60,6 @@ static char Enocommand[] = "command not supported";
* /ws/1/mode FsFmode col mode
* /ws/1/sel/ FsDclient
* /ws/1/1/name FsFname name of client
- * /ws/1/1/class FsFclass class:instance of client
* /ws/1/1/tags FsFtags tag of client
* /ws/1/1/geom FsFgeom geometry of client
* /ws/1/1/ctl FsFctl command interface (client)
@@ -75,7 +72,7 @@ const char *err;
/**
* Qid->path is calculated related to the index of the associated structure.
- * i1 is associated to tag, key, global client, class or label
+ * i1 is associated to tag, key, global client, or label
* i2 is associated to area
* i3 is associated to client
* ie /ws/sel/ctl is i1id = sel tag id, i2id = sel area id , i3id = 0 (no id)
@@ -125,7 +122,6 @@ decode_qpath(Qid *qid, unsigned char *type, int *i1, int *i2, int *i3)
else {
switch(*type) {
case FsFkey: *i1 = kid2index(i1id); break;
- case FsFclasstag: *i1 = classid2index(i1id); break;
case FsFdata:
case FsFcolors:
case FsDlabel: *i1 = lid2index(i1id); break;
@@ -153,7 +149,6 @@ qid2name(Qid *qid)
case FsDroot: return "/"; break;
case FsDdef: return "def"; break;
case FsDkeys: return "keys"; break;
- case FsDclass: return "class"; break;
case FsDtags: return "tags"; break;
case FsDclients: return "clients"; break;
case FsDbar: return "bar"; break;
@@ -223,13 +218,6 @@ qid2name(Qid *qid)
return nil;
return "geom";
break;
- case FsFclass:
- if((qid->dir_type == FsDclient) && (i1 == -1 || i2 == -1 || i3 == -1))
- return nil;
- else if(i1 == -1)
- return nil;
- return "class";
- break;
case FsFname:
if((qid->dir_type == FsDclient) && (i1 == -1 || i2 == -1 || i3 == -1))
return nil;
@@ -250,12 +238,6 @@ qid2name(Qid *qid)
return "mode";
break;
case FsFevent: return "event"; break;
- case FsFclasstag:
- if(i1 == -1)
- return nil;
- snprintf(buf, sizeof(buf), "%s:%s", class[i1]->class, class[i1]->instance);
- return buf;
- break;
case FsFkey:
if(i1 == -1)
return nil;
@@ -286,12 +268,6 @@ name2type(char *name, unsigned char dir_type)
return FsDbar;
if(!strncmp(name, "def", 4))
return FsDdef;
- if(!strncmp(name, "class", 6)) {
- if(dir_type == FsDdef)
- return FsDclass;
- else
- return FsFclass;
- }
if(!strncmp(name, "keys", 5))
return FsDkeys;
if(!strncmp(name, "ctl", 4))
@@ -322,12 +298,8 @@ name2type(char *name, unsigned char dir_type)
return FsFmode;
if(!strncmp(name, "tag", 4))
return FsFtag;
- if(has_tag(ctag, name, nctag) && (dir_type == FsDtags))
- return FsFtag;
if((dir_type == FsDbar) && name2label(name))
return FsDlabel;
- if((dir_type == FsDclass) && name2class(name))
- return FsFclasstag;
if((dir_type == FsDkeys) && name2key(name))
return FsFkey;
if(!strncmp(name, "sel", 4))
@@ -372,12 +344,6 @@ mkqid(Qid *dir, char *wname, Qid *new)
new->type = IXP_QTDIR;
new->path = mkqpath(type, 0, 0, 0);
break;
- case FsDclass:
- if(dir_type != FsDdef)
- return -1;
- new->type = IXP_QTDIR;
- new->path = mkqpath(type, 0, 0, 0);
- break;
case FsDws:
new->type = IXP_QTDIR;
new->path = mkqpath(FsDws, ntag ? tag[sel]->id : 0, 0, 0);
@@ -438,17 +404,6 @@ mkqid(Qid *dir, char *wname, Qid *new)
new->path = mkqpath(FsDlabel, l->id, 0, 0);
}
break;
- case FsFclasstag:
- if(dir_type != FsDclass)
- return -1;
- {
- TClass *tc;
- if(!(tc = name2class(wname)))
- return -1;
- new->type = IXP_QTFILE;
- new->path = mkqpath(FsFclasstag, tc->id, 0, 0);
- }
- break;
case FsFkey:
if(dir_type != FsDkeys)
return -1;
@@ -474,7 +429,6 @@ mkqid(Qid *dir, char *wname, Qid *new)
new->path = mkqpath(type, qpath_i1id(dir->path), qpath_i2id(dir->path), qpath_i3id(dir->path));
break;
case FsFgeom:
- case FsFclass:
case FsFname:
case FsFtags:
if((dir_type == FsDclient) && ((dir_i1 == -1 || dir_i2 == -1 || dir_i3 == -1)))
@@ -535,9 +489,6 @@ type2stat(Stat *stat, char *wname, Qid *dir)
break;
case FsDbar:
case FsDkeys:
- case FsDclass:
- return mkstat(stat, dir, wname, 0, DMDIR | DMREAD | DMWRITE | DMEXEC);
- break;
case FsFctl:
return mkstat(stat, dir, wname, 0, DMWRITE);
break;
@@ -565,15 +516,6 @@ type2stat(Stat *stat, char *wname, Qid *dir)
snprintf(buf, sizeof(buf), "%d", def.snap);
return mkstat(stat, dir, wname, strlen(buf), DMREAD | DMWRITE);
break;
- case FsFclass:
- if(dir_type == FsDclient) {
- f = tag[dir_i1]->area[dir_i2]->frame[dir_i3];
- snprintf(buf, sizeof(buf), "%s:%s", f->client->class, f->client->instance);
- }
- else
- snprintf(buf, sizeof(buf), "%s:%s", client[dir_i1]->class, client[dir_i1]->instance);
- return mkstat(stat, dir, wname, strlen(buf), DMREAD);
- break;
case FsFname:
if(dir_type == FsDclient) {
f = tag[dir_i1]->area[dir_i2]->frame[dir_i3];
@@ -591,13 +533,10 @@ type2stat(Stat *stat, char *wname, Qid *dir)
return mkstat(stat, dir, wname, strlen(client[dir_i1]->tags), DMREAD | DMWRITE);
break;
case FsFtag:
- if(dir_type == FsDdef)
+ if(dir_type == FsDws)
return mkstat(stat, dir, wname, strlen(def.tag), DMREAD | DMWRITE);
return mkstat(stat, dir, wname, 0, 0);
break;
- case FsFclasstag:
- return mkstat(stat, dir, wname, strlen(class[dir_i1]->tags), DMREAD | DMWRITE);
- break;
case FsFkey:
return mkstat(stat, dir, wname, 0, DMWRITE);
break;
@@ -703,9 +642,6 @@ xcreate(IXPConn *c, Fcall *fcall)
case FsDkeys:
grab_key(get_key(fcall->name));
break;
- case FsDclass:
- get_class(fcall->name);
- break;
case FsDbar:
if(!strncmp(fcall->name, "expand", 7))
return "illegal file name";
@@ -751,7 +687,7 @@ xremove(IXPConn *c, Fcall *fcall)
decode_qpath(&m->qid, &type, &i1, &i2, &i3);
if((i1 == -1) || (i2 == -1) || (i3 == -1))
return Enofile;
- if(type != FsDlabel && type != FsFclasstag && type != FsFkey)
+ if(type != FsDlabel && type != FsFkey)
return Enoperm;
/* clunk */
cext_array_detach((void **)c->map, m, &c->mapsz);
@@ -766,12 +702,6 @@ xremove(IXPConn *c, Fcall *fcall)
draw_bar();
}
break;
- case FsFclasstag:
- {
- TClass *tc = class[i1];
- destroy_class(tc);
- }
- break;
case FsFkey:
{
Key *k = key[i1];
@@ -826,26 +756,6 @@ xread(IXPConn *c, Fcall *fcall)
p = ixp_enc_stat(p, &stat);
}
break;
- case FsDclass:
- /* jump to offset */
- len = 0;
- for(i = 0; i < nclass; i++) {
- snprintf(buf, sizeof(buf), "%s:%s", class[i]->class, class[i]->instance);
- len += type2stat(&stat, buf, &m->qid);
- if(len <= fcall->offset)
- continue;
- break;
- }
- /* offset found, proceeding */
- for(; i < nclass; i++) {
- snprintf(buf, sizeof(buf), "%s:%s", class[i]->class, class[i]->instance);
- len = type2stat(&stat, buf, &m->qid);
- if(fcall->count + len > fcall->iounit)
- break;
- fcall->count += len;
- p = ixp_enc_stat(p, &stat);
- }
- break;
case FsDtags:
/* jump to offset */
len = 0;
@@ -905,6 +815,7 @@ xread(IXPConn *c, Fcall *fcall)
case FsDws:
/* jump to offset */
len = type2stat(&stat, "ctl", &m->qid);
+ len += type2stat(&stat, "tag", &m->qid);
for(i = 0; i < tag[i1]->narea; i++) {
if(i == tag[i1]->sel)
snprintf(buf, sizeof(buf), "%s", "sel");
@@ -994,16 +905,6 @@ xread(IXPConn *c, Fcall *fcall)
p = ixp_enc_stat(p, &stat);
}
break;
- case FsDclass:
- for(i = 0; i < nclass; i++) {
- snprintf(buf, sizeof(buf), "%s:%s", class[i]->class, class[i]->instance);
- len = type2stat(&stat, buf, &m->qid);
- if(fcall->count + len > fcall->iounit)
- break;
- fcall->count += len;
- p = ixp_enc_stat(p, &stat);
- }
- break;
case FsDclients:
for(i = 0; i < nclient; i++) {
snprintf(buf, sizeof(buf), "%u", i);
@@ -1043,9 +944,7 @@ xread(IXPConn *c, Fcall *fcall)
p = ixp_enc_stat(p, &stat);
break;
case FsDdef:
- fcall->count += type2stat(&stat, "border", &m->qid);
- p = ixp_enc_stat(p, &stat);
- fcall->count += type2stat(&stat, "class", &m->qid);
+ fcall->count = type2stat(&stat, "border", &m->qid);
p = ixp_enc_stat(p, &stat);
fcall->count += type2stat(&stat, "snap", &m->qid);
p = ixp_enc_stat(p, &stat);
@@ -1055,12 +954,12 @@ xread(IXPConn *c, Fcall *fcall)
p = ixp_enc_stat(p, &stat);
fcall->count += type2stat(&stat, "font", &m->qid);
p = ixp_enc_stat(p, &stat);
- fcall->count += type2stat(&stat, "tag", &m->qid);
- p = ixp_enc_stat(p, &stat);
break;
case FsDws:
fcall->count = type2stat(&stat, "ctl", &m->qid);
p = ixp_enc_stat(p, &stat);
+ fcall->count += type2stat(&stat, "tag", &m->qid);
+ p = ixp_enc_stat(p, &stat);
for(i = 0; i < tag[i1]->narea; i++) {
if(i == tag[i1]->sel)
snprintf(buf, sizeof(buf), "%s", "sel");
@@ -1093,8 +992,6 @@ xread(IXPConn *c, Fcall *fcall)
break;
case FsDGclient:
case FsDclient:
- fcall->count = type2stat(&stat, "class", &m->qid);
- p = ixp_enc_stat(p, &stat);
fcall->count += type2stat(&stat, "name", &m->qid);
p = ixp_enc_stat(p, &stat);
fcall->count += type2stat(&stat, "tags", &m->qid);
@@ -1136,16 +1033,6 @@ xread(IXPConn *c, Fcall *fcall)
fcall->count = strlen(buf);
memcpy(p, buf, fcall->count);
break;
- case FsFclass:
- if(m->qid.dir_type == FsDclient) {
- f = tag[i1]->area[i2]->frame[i3];
- snprintf(buf, sizeof(buf), "%s:%s", f->client->class, f->client->instance);
- }
- else
- snprintf(buf, sizeof(buf), "%s:%s", client[i1]->class, client[i1]->instance);
- fcall->count = strlen(buf);
- memcpy(p, buf, fcall->count);
- break;
case FsFname:
if(m->qid.dir_type == FsDclient) {
if((fcall->count = strlen(tag[i1]->area[i2]->frame[i3]->client->name)))
@@ -1176,16 +1063,16 @@ xread(IXPConn *c, Fcall *fcall)
if((fcall->count = strlen(label[i1]->data)))
memcpy(p, label[i1]->data, fcall->count);
break;
+ case FsFtag:
+ if((fcall->count = strlen(def.tag)))
+ memcpy(p, def.tag, fcall->count);
+ break;
case FsFcolors:
if(i1 >= nlabel)
return Enofile;
if((fcall->count = strlen(label[i1]->colstr)))
memcpy(p, label[i1]->colstr, fcall->count);
break;
- case FsFtag:
- if((fcall->count = strlen(def.tag)))
- memcpy(p, def.tag, fcall->count);
- break;
case FsFselcolors:
if((fcall->count = strlen(def.selcolor)))
memcpy(p, def.selcolor, fcall->count);
@@ -1198,12 +1085,6 @@ xread(IXPConn *c, Fcall *fcall)
if((fcall->count = strlen(def.font)))
memcpy(p, def.font, fcall->count);
break;
- case FsFclasstag:
- if(i1 >= nclass)
- return Enofile;
- if((fcall->count = strlen(class[i1]->tags)))
- memcpy(p, class[i1]->tags, fcall->count);
- break;
case FsFmode:
if(!i2)
return Enofile;
@@ -1360,6 +1241,10 @@ xwrite(IXPConn *c, Fcall *fcall)
draw_bar();
}
break;
+ case FsFtag:
+ memcpy(def.tag, fcall->data, fcall->count);
+ def.tag[fcall->count] = 0;
+ break;
case FsFcolors:
if((i1 >= nlabel) || (fcall->count != 23)
|| (fcall->data[0] != '#') || (fcall->data[8] != '#')
@@ -1371,10 +1256,6 @@ xwrite(IXPConn *c, Fcall *fcall)
blitz_loadcolor(dpy, screen, label[i1]->colstr, &label[i1]->color);
draw_bar();
break;
- case FsFtag:
- memcpy(def.tag, fcall->data, fcall->count);
- def.tag[fcall->count] = 0;
- break;
case FsFselcolors:
if((fcall->count != 23)
|| (fcall->data[0] != '#') || (fcall->data[8] != '#')
@@ -1423,12 +1304,6 @@ xwrite(IXPConn *c, Fcall *fcall)
tag[i1]->area[i2]->mode = i;
arrange_area(tag[i1]->area[i2]);
break;
- case FsFclasstag:
- if(fcall->count > sizeof(class[i1]->tags))
- return "tags too long";
- memcpy(class[i1]->tags, fcall->data, fcall->count);
- class[i1]->tags[fcall->count] = 0;
- break;
case FsFkey:
break;
default:
diff --git a/cmd/wm/tag.c b/cmd/wm/tag.c
@@ -169,6 +169,7 @@ select_tag(char *arg)
if(!t)
return;
focus_tag(t);
+ cext_strlcpy(def.tag, arg, sizeof(def.tag));
for(i = 0; i < ntag; i++) {
n = 0;
@@ -262,6 +263,9 @@ update_tags()
detach_fromtag(tag[j], client[i]);
}
}
+
+ if(!ntag && nctag)
+ select_tag(ctag[0]);
}
void
diff --git a/cmd/wm/wm.c b/cmd/wm/wm.c
@@ -316,8 +316,6 @@ main(int argc, char *argv[])
keysz = nkey = 0;
label = nil;
nlabel = labelsz = 0;
- class = nil;
- nclass = classsz = 0;
def.font = strdup(BLITZ_FONT);
def.border = DEF_BORDER;
diff --git a/cmd/wm/wm.h b/cmd/wm/wm.h
@@ -49,7 +49,6 @@ enum {
FsDarea,
FsDclients,
FsDclient,
- FsDclass,
FsDGclient,
FsDkeys,
FsDtags,
@@ -69,8 +68,6 @@ enum {
FsFevent,
FsFctl,
FsFname,
- FsFclass,
- FsFclasstag,
FsFtags,
FsFtag,
FsFmode
@@ -119,8 +116,6 @@ struct Client {
unsigned short id;
char name[256];
char tags[256];
- char class[128];
- char instance[128];
int proto;
unsigned int border;
Bool destroyed;
@@ -137,13 +132,6 @@ struct Client {
unsigned int nframe;
};
-typedef struct {
- unsigned short id;
- char class[128];
- char instance[128];
- char tags[256];
-} TClass;
-
typedef struct Key Key;
struct Key {
unsigned short id;
@@ -192,9 +180,6 @@ char expand[256];
char **ctag;
unsigned int nctag;
unsigned int ctagsz;
-TClass **class;
-unsigned int nclass;
-unsigned int classsz;
Display *dpy;
IXPServer *ixps;
@@ -243,13 +228,6 @@ unsigned int bar_height();
Label *name2label(const char *name);
int label2index(Label *l);
-/* class.c */
-TClass *get_class(const char *name);
-void destroy_class(TClass *tclass);
-int classid2index(unsigned short id);
-TClass *name2class(const char *name);
-TClass *client2class(Client *c);
-
/* client.c */
Client *alloc_client(Window w, XWindowAttributes *wa);
void configure_client(Client *c);