Blob
1 #include <u.h>2 #include <libc.h>3 #include <draw.h>4 #include <memdraw.h>5 #include <memlayer.h>6 #include <mouse.h>7 #include <cursor.h>8 #include <keyboard.h>9 #include <drawfcall.h>10 #include "devdraw.h"12 enum13 {14 Nbutton = 1015 };17 static int debug;19 static struct20 {21 int b[Nbutton];22 int init;23 } map;25 static void26 initmap(void)27 {28 char *p;29 int i;31 p = getenv("mousedebug");32 if(p && p[0])33 debug = atoi(p);35 for(i=0; i<Nbutton; i++)36 map.b[i] = i;37 map.init = 1;38 p = getenv("mousebuttonmap");39 if(p)40 for(i=0; i<Nbutton && p[i]; i++)41 if('0' <= p[i] && p[i] <= '9')42 map.b[i] = p[i] - '1';43 if(debug){44 fprint(2, "mousemap: ");45 for(i=0; i<Nbutton; i++)46 fprint(2, " %d", 1+map.b[i]);47 fprint(2, "\n");48 }49 }51 int52 mouseswap(int but)53 {54 int i;55 int nbut;57 if(!map.init)58 initmap();60 nbut = 0;61 for(i=0; i<Nbutton; i++)62 if((but&(1<<i)) && map.b[i] >= 0)63 nbut |= 1<<map.b[i];64 if(debug)65 fprint(2, "swap %#b -> %#b\n", but, nbut);66 return nbut;67 }