Lines 33-56
Link Here
|
33 |
gint n_buttons, |
33 |
gint n_buttons, |
34 |
gboolean left_handed) |
34 |
gboolean left_handed) |
35 |
{ |
35 |
{ |
36 |
const gint left_button = 0; |
36 |
const gint left_button = 1; |
37 |
gint right_button; |
37 |
gint right_button; |
|
|
38 |
gint i; |
38 |
|
39 |
|
39 |
/* if the button is higher than 2 (3rd button) then it's |
40 |
/* if the button is higher than 2 (3rd button) then it's |
40 |
* probably one direction of a scroll wheel or something else |
41 |
* probably one direction of a scroll wheel or something else |
41 |
* uninteresting |
42 |
* uninteresting |
42 |
*/ |
43 |
*/ |
43 |
right_button = MIN (n_buttons - 1, 2); |
44 |
right_button = MIN (n_buttons, 3); |
44 |
|
45 |
|
45 |
if (left_handed) |
46 |
/* If we change things we need to make sure we only swap buttons. |
46 |
{ |
47 |
* If we end up with multiple physical buttons assigned to the same |
47 |
buttons[left_button] = right_button + 1; |
48 |
* logical button the server will complain. This code assumes physical |
48 |
buttons[right_button] = left_button + 1; |
49 |
* button 0 is the physical left mouse button, and that the physical |
49 |
} |
50 |
* button other than 0 currently assigned left_button or right_button |
50 |
else |
51 |
* is the physical right mouse button. |
51 |
{ |
52 |
*/ |
52 |
buttons[left_button] = left_button + 1; |
53 |
|
53 |
buttons[right_button] = right_button + 1; |
54 |
/* check if the current mapping satisfies the above assumptions */ |
|
|
55 |
if (buttons[left_button] != left_button && |
56 |
buttons[left_button] != right_button) |
57 |
/* The current mapping is weird. Swapping buttons is probably not a |
58 |
* good idea. |
59 |
*/ |
60 |
return; |
61 |
|
62 |
/* check if we are left_handed and currently not swapped */ |
63 |
if (left_handed && buttons[left_button - 1] == left_button) |
64 |
{ |
65 |
/* find the right button */ |
66 |
for (i = 0; i < n_buttons; i++) |
67 |
{ |
68 |
if (buttons[i] == right_button) |
69 |
break; |
70 |
} |
71 |
/* swap the buttons */ |
72 |
buttons[left_button - 1] = right_button; |
73 |
buttons[i] = left_button; |
74 |
} |
75 |
/* check if we are not left_handed but are swapped */ |
76 |
else if (!left_handed && buttons[left_button - 1] == right_button) |
77 |
{ |
78 |
/* find the right button */ |
79 |
for (i = 0; i < n_buttons; i++) |
80 |
{ |
81 |
if (buttons[i] == left_button) |
82 |
break; |
83 |
} |
84 |
/* swap the buttons */ |
85 |
buttons[i] = right_button; |
86 |
buttons[left_button - 1] = left_button; |
54 |
} |
87 |
} |
55 |
} |
88 |
} |