Example #1
0
static Key*
getkey(const char *name) {
	Key *k, *r;
	char buf[128];
	char *seq[8];
	char *kstr;
	int mask;
	uint i, toks;
	static ushort id = 1;

	r = nil;

	if((k = name2key(name))) {
		ungrabkey(k);
		return k;
	}
	utflcpy(buf, name, sizeof buf);
	toks = tokenize(seq, 8, buf, ',');
	for(i = 0; i < toks; i++) {
		if(!k)
			r = k = emallocz(sizeof *k);
		else {
			k->next = emallocz(sizeof *k);
			k = k->next;
		}
		utflcpy(k->name, name, sizeof k->name);
		if(parsekey(seq[i], &mask, &kstr)) {
			k->key = keycode(kstr);
			k->mod = mask;
		}
		if(k->key == 0) {
			freekey(r);
			return nil;
		}
	}
	if(r) {
		r->id = id++;
		r->lnext = key;
		key = r;
	}

	return r;
}
Example #2
0
Bar*
bar_create(Bar **bp, const char *name) {
	static uint id = 1;
	WMScreen *s, **sp;
	Bar *b;
	uint i;

	b = bar_find(*bp, name);;
	if(b)
		return b;

	b = emallocz(sizeof *b);
	b->id = id++;
	utflcpy(b->name, name, sizeof b->name);
	b->col = def.normcolor;

	strlcat(b->buf, b->col.colstr, sizeof(b->buf));
	strlcat(b->buf, " ", sizeof(b->buf));
	strlcat(b->buf, b->text, sizeof(b->buf));
	
	SET(i);
	for(sp=screens; (s = *sp); sp++) {
		i = bp - s->bar;
		if(i < nelem(s->bar))
			break;
	}
	b->bar = i;
	b->screen = s;

	for(; *bp; bp = &bp[0]->next)
		if(strcmp(bp[0]->name, name) >= 0)
			break;
	b->next = *bp;
	*bp = b;

	return b;
}
Example #3
0
char *
message_root(void *p, IxpMsg *m) {
	Font *fn;
	char *s, *ret;
	ulong n;

	USED(p);
	ret = nil;
	s = getword(m);

	switch(getsym(s)) {
	case LQUIT:
		srv.running = 0;
		break;
	case LEXEC:
		execstr = smprint("exec %s", (char*)m->pos);
		srv.running = 0;
		break;
	case LVIEW:
		select_view((char*)m->pos);
		break;
	case LSELCOLORS:
		fprint(2, "%s: warning: selcolors have been removed\n", argv0);
		return Ebadcmd;
	case LFOCUSCOLORS:
		ret = parse_colors(m, &def.focuscolor);
		focus_view(screen, screen->sel);
		break;
	case LNORMCOLORS:
		ret = parse_colors(m, &def.normcolor);
		focus_view(screen, screen->sel);
		break;
	case LFONT:
		fn = loadfont((char*)m->pos);
		if(fn) {
			freefont(def.font);
			def.font = fn;
			resize_bar(screen);
		}else
			ret = "can't load font";
		focus_view(screen, screen->sel);
		break;
	case LBORDER:
		if(!getulong(getword(m), &n))
			return Ebadvalue;
		def.border = n;
		focus_view(screen, screen->sel);
		break;
	case LGRABMOD:
		s = getword(m);
		n = str2modmask(s);

		if((n & (Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask)) == 0)
			return Ebadvalue;

		utflcpy(def.grabmod, s, sizeof(def.grabmod));
		def.mod = n;
		break;
	default:
		return Ebadcmd;
	}
	return ret;
}