aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/devdraw/mouseswap.c
blob: e6ece33399007e8d27b1013ef23c828e10407623 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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;
}