Blob
1 #include <u.h>2 #include <libc.h>3 #include <draw.h>4 #include <memdraw.h>5 #include "devdraw.h"7 enum8 {9 Nbutton = 1010 };12 static int debug;14 static struct15 {16 int b[Nbutton];17 int init;18 } map;20 static void21 initmap(void)22 {23 char *p;24 int i;26 p = getenv("mousedebug");27 if(p && p[0])28 debug = atoi(p);30 for(i=0; i<Nbutton; i++)31 map.b[i] = i;32 map.init = 1;33 p = getenv("mousebuttonmap");34 if(p)35 for(i=0; i<Nbutton && p[i]; i++)36 if('0' <= p[i] && p[i] <= '9')37 map.b[i] = p[i] - '1';38 if(debug){39 fprint(2, "mousemap: ");40 for(i=0; i<Nbutton; i++)41 fprint(2, " %d", 1+map.b[i]);42 fprint(2, "\n");43 }44 }46 int47 mouseswap(int but)48 {49 int i;50 int nbut;52 if(!map.init)53 initmap();55 nbut = 0;56 for(i=0; i<Nbutton; i++)57 if((but&(1<<i)) && map.b[i] >= 0)58 nbut |= 1<<map.b[i];59 if(debug)60 fprint(2, "swap %#b -> %#b\n", but, nbut);61 return nbut;62 }