blob: d2dea666953793624f0393be0b04f5f3e137b8c8 (
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
63
64
65
66
67
|
#include <u.h>
#include <libc.h>
#include <draw.h>
#include <memdraw.h>
#include <memlayer.h>
#include <mouse.h>
#include <cursor.h>
#include <keyboard.h>
#include <drawfcall.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;
}
|