diff options
Diffstat (limited to 'src/cmd')
-rw-r--r-- | src/cmd/devdraw/devdraw.h | 1 | ||||
-rw-r--r-- | src/cmd/devdraw/mkfile | 1 | ||||
-rw-r--r-- | src/cmd/devdraw/mouseswap.c | 62 |
3 files changed, 64 insertions, 0 deletions
diff --git a/src/cmd/devdraw/devdraw.h b/src/cmd/devdraw/devdraw.h index 498bd5aa..074cf0d7 100644 --- a/src/cmd/devdraw/devdraw.h +++ b/src/cmd/devdraw/devdraw.h @@ -3,4 +3,5 @@ int _drawmsgwrite(void*, int); void _initdisplaymemimage(Memimage*); int _latin1(Rune*, int); int parsewinsize(char*, Rectangle*, int*); +int mouseswap(int); diff --git a/src/cmd/devdraw/mkfile b/src/cmd/devdraw/mkfile index 66bea897..8e4af443 100644 --- a/src/cmd/devdraw/mkfile +++ b/src/cmd/devdraw/mkfile @@ -5,6 +5,7 @@ TARG=devdraw WSYSOFILES=\ devdraw.$O\ latin1.$O\ + mouseswap.$O\ winsize.$O\ <|sh ./mkwsysrules.sh diff --git a/src/cmd/devdraw/mouseswap.c b/src/cmd/devdraw/mouseswap.c new file mode 100644 index 00000000..e6ece333 --- /dev/null +++ b/src/cmd/devdraw/mouseswap.c @@ -0,0 +1,62 @@ +#include <u.h> +#include <libc.h> +#include <draw.h> +#include <memdraw.h> +#include "devdraw.h" + +enum +{ + Nbutton = 10 +}; + +static int debug; + +static struct +{ + int b[Nbutton]; + int init; +} map; + +static void +initmap(void) +{ + char *p; + int i; + + p = getenv("mousedebug"); + if(p && p[0]) + debug = atoi(p); + + for(i=0; i<Nbutton; i++) + map.b[i] = i; + map.init = 1; + p = getenv("mousebuttonmap"); + if(p) + for(i=0; i<Nbutton && p[i]; i++) + if('0' <= p[i] && p[i] <= '9') + map.b[i] = p[i] - '1'; + if(debug){ + fprint(2, "mousemap: "); + for(i=0; i<Nbutton; i++) + fprint(2, " %d", 1+map.b[i]); + fprint(2, "\n"); + } +} + +int +mouseswap(int but) +{ + int i; + int nbut; + + if(!map.init) + initmap(); + + nbut = 0; + for(i=0; i<Nbutton; i++) + if((but&(1<<i)) && map.b[i] >= 0) + nbut |= 1<<map.b[i]; + if(debug) + fprint(2, "swap %#b -> %#b\n", but, nbut); + return nbut; +} |