wmii

git clone git://oldgit.suckless.org/wmii/
Log | Files | Refs | README | LICENSE

sethandler.c (1268B)


      1 /* Copyright ©2007-2010 Kris Maglione <maglione.k at Gmail>
      2  * See LICENSE file for license details.
      3  */
      4 #include "../x11.h"
      5 
      6 static void
      7 updatemap(Window *w) {
      8 	void **e;
      9 
     10 	assert(w->type == WWindow);
     11 	assert((w->prev != nil && w->next != nil) || w->next == w->prev);
     12 
     13 	if(w->handler == nil && w->handler_link == nil)
     14 		map_rm(&windowmap, (ulong)w->xid);
     15 	else {
     16 		e = map_get(&windowmap, (ulong)w->xid, true);
     17 		*e = w;
     18 	}
     19 }
     20 
     21 Handlers*
     22 sethandler(Window *w, Handlers *new) {
     23 	Handlers *old;
     24 
     25 	old = w->handler;
     26 	w->handler = new;
     27 
     28 	updatemap(w);
     29 	return old;
     30 }
     31 
     32 static HandlersLink*	free_link;
     33 
     34 void
     35 pushhandler(Window *w, Handlers *new, void *aux) {
     36 	HandlersLink *l;
     37 	int i;
     38 
     39 	if(free_link == nil) {
     40 		l = emalloc(16 * sizeof *l);
     41 		for(i=0; i < 16; i++) {
     42 			l[i].next = free_link;
     43 			free_link = l;
     44 		}
     45 	}
     46 	l = free_link;
     47 	free_link = l->next;
     48 
     49 	/* TODO: Maybe: pophandler(w, new); */
     50 
     51 	l->next = w->handler_link;
     52 	l->handler = new;
     53 	l->aux = aux;
     54 	w->handler_link = l;
     55 
     56 	updatemap(w);
     57 }
     58 
     59 bool
     60 pophandler(Window *w, Handlers *old) {
     61 	HandlersLink **lp;
     62 	HandlersLink *l;
     63 
     64 	for(lp=&w->handler_link; (l=*lp); lp=&l->next)
     65 		if(l->handler == old) {
     66 			*lp = l->next;
     67 			l->next = free_link;
     68 			free_link = l;
     69 			updatemap(w);
     70 			return true;
     71 		}
     72 	return false;
     73 }
     74