summaryrefslogtreecommitdiff
path: root/driver/xf86-input-ws/src
diff options
context:
space:
mode:
authorAlexandr Shadchin <shadchin@cvs.openbsd.org>2012-06-12 17:12:51 +0000
committerAlexandr Shadchin <shadchin@cvs.openbsd.org>2012-06-12 17:12:51 +0000
commitf287f9cf290f74148d376cd44f558de9b5e18698 (patch)
treed5ffd360f2cbaeb3d244f8104644ebc91f24b2af /driver/xf86-input-ws/src
parent94ca25456fd27942a546d75551d9a0ef553ed9ba (diff)
Add support ButtonMapping
ok matthieu@
Diffstat (limited to 'driver/xf86-input-ws/src')
-rw-r--r--driver/xf86-input-ws/src/ws.c40
-rw-r--r--driver/xf86-input-ws/src/ws.h13
2 files changed, 38 insertions, 15 deletions
diff --git a/driver/xf86-input-ws/src/ws.c b/driver/xf86-input-ws/src/ws.c
index fded40f38..5e94a4bba 100644
--- a/driver/xf86-input-ws/src/ws.c
+++ b/driver/xf86-input-ws/src/ws.c
@@ -13,7 +13,7 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-/* $OpenBSD: ws.c,v 1.53 2012/06/12 17:10:03 shadchin Exp $ */
+/* $OpenBSD: ws.c,v 1.54 2012/06/12 17:12:50 shadchin Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -120,7 +120,7 @@ wsPreInit(InputDriverPtr drv, InputInfoPtr pInfo, int flags)
WSDevicePtr priv;
MessageType buttons_from = X_CONFIG;
char *s;
- int rc = BadValue;
+ int i, phy_btn = 1, rc = BadValue;
priv = (WSDevicePtr)calloc(1, sizeof(WSDeviceRec));
if (priv == NULL) {
@@ -145,6 +145,31 @@ wsPreInit(InputDriverPtr drv, InputInfoPtr pInfo, int flags)
buttons_from = X_DEFAULT;
}
+ /* Check for user-defined button mapping */
+ s = xf86SetStrOption(pInfo->options, "ButtonMapping", NULL);
+ if (s) {
+ char *map = s, *end;
+ int btn;
+
+ do {
+ btn = strtol(map, &end, 10);
+
+ if (end == map || btn < 0 || btn > NBUTTONS) {
+ xf86IDrvMsg(pInfo, X_ERROR,
+ "Invalid button mapping. Using defaults\n");
+ phy_btn = 1; /* ensure defaults start at 1 */
+ break;
+ }
+
+ priv->btnmap[phy_btn++] = btn;
+ map = end;
+ } while (end && *end != '\0' && phy_btn <= NBUTTONS);
+ free(s);
+ }
+
+ for (i = phy_btn; i <= NBUTTONS; i++)
+ priv->btnmap[i] = i;
+
wsWheelHandleButtonMap(pInfo, &(priv->Z), "ZAxisMapping", "4 5");
wsWheelHandleButtonMap(pInfo, &(priv->W), "WAxisMapping", "6 7");
@@ -295,8 +320,7 @@ wsDeviceInit(DeviceIntPtr pWS)
{
InputInfoPtr pInfo = (InputInfoPtr)pWS->public.devicePrivate;
WSDevicePtr priv = (WSDevicePtr)pInfo->private;
- unsigned char map[NBUTTONS + 1];
- int i, xmin, xmax, ymin, ymax;
+ int xmin, xmax, ymin, ymax;
Atom btn_labels[NBUTTONS] = {0};
Atom axes_labels[NAXES] = {0};
@@ -305,12 +329,8 @@ wsDeviceInit(DeviceIntPtr pWS)
btn_labels[0] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_LEFT);
btn_labels[1] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_MIDDLE);
btn_labels[2] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_RIGHT);
- for (i = 0; i < NBUTTONS; i++)
- map[i + 1] = i + 1;
- if (!InitButtonClassDeviceStruct(pWS,
- min(priv->buttons, NBUTTONS),
- btn_labels,
- map))
+ if (!InitButtonClassDeviceStruct(pWS, min(priv->buttons, NBUTTONS),
+ btn_labels, priv->btnmap))
return !Success;
if (priv->type == WSMOUSE_TYPE_TPANEL) {
diff --git a/driver/xf86-input-ws/src/ws.h b/driver/xf86-input-ws/src/ws.h
index fd84b633d..83029547b 100644
--- a/driver/xf86-input-ws/src/ws.h
+++ b/driver/xf86-input-ws/src/ws.h
@@ -43,7 +43,6 @@ typedef struct {
typedef struct WSDevice {
char *devName; /* device name */
int type; /* ws device type */
- unsigned int buttons; /* # of buttons */
unsigned int lastButtons; /* last state of buttons */
int old_ax, old_ay;
int min_x, max_x, min_y, max_y; /* coord space */
@@ -56,13 +55,17 @@ typedef struct WSDevice {
WheelAxis W;
struct wsmouse_calibcoords coords; /* mirror of the kernel values */
+ /* # of buttons and config-file specified button mapping */
+ unsigned int buttons;
+ unsigned char btnmap[NBUTTONS + 1];
+
/* Middle mouse button emulation */
struct {
BOOL enabled;
- BOOL pending; /* timer waiting? */
- int buttonstate; /* phys. button state */
- int state; /* state machine (see emumb.c) */
- Time expires; /* time of expiry */
+ BOOL pending; /* timer waiting? */
+ int buttonstate; /* phys. button state */
+ int state; /* state machine (see emumb.c) */
+ Time expires; /* time of expiry */
Time timeout;
} emulateMB;