|
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); |
|
|
45 |
|
| 46 |
/* If we change things we need to make sure we only swap buttons. |
| 47 |
* If we end up with multiple physical buttons assigned to the same |
| 48 |
* logical button the server will complain. This code assumes physical |
| 49 |
* button 0 is the physical left mouse button, and that the physical |
| 50 |
* button other than 0 currently assigned left_button or right_button |
| 51 |
* is the physical right mouse button. |
| 52 |
*/ |
| 53 |
|
| 54 |
/* check if the current mapping satisfies the above assumptions */ |
| 55 |
if (buttons[left_button - 1] != left_button && |
| 56 |
buttons[left_button - 1] != right_button) |
| 57 |
/* The current mapping is weird. Swapping buttons is probably not a |
| 58 |
* good idea. |
| 59 |
*/ |
| 60 |
return; |
| 44 |
|
61 |
|
| 45 |
if (left_handed) |
62 |
/* check if we are left_handed and currently not swapped */ |
|
|
63 |
if (left_handed && buttons[left_button - 1] == left_button) |
| 46 |
{ |
64 |
{ |
| 47 |
buttons[left_button] = right_button + 1; |
65 |
/* find the right button */ |
| 48 |
buttons[right_button] = left_button + 1; |
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; |
| 49 |
} |
74 |
} |
| 50 |
else |
75 |
/* check if we are not left_handed but are swapped */ |
|
|
76 |
else if (!left_handed && buttons[left_button - 1] == right_button) |
| 51 |
{ |
77 |
{ |
| 52 |
buttons[left_button] = left_button + 1; |
78 |
/* find the right button */ |
| 53 |
buttons[right_button] = right_button + 1; |
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 |
} |
| 56 |
|
89 |
|