diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2008-07-21 17:05:04 +0930 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2008-07-21 17:26:33 +0930 |
commit | 69de40ee45a6e046be79b735cd1540f63b87aee9 (patch) | |
tree | 9edab4f6dfd81ab1754bf17b109c726f9130f13f /dix | |
parent | 0dbfe0ebc69c307c0626ba824de15d03de1251d4 (diff) |
dix: shift the duplicate button mapping check to ProcSetPointerMapping.
XI 2 allows two buttons to have the same button code.
Diffstat (limited to 'dix')
-rw-r--r-- | dix/devices.c | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/dix/devices.c b/dix/devices.c index a7325a60f..1cde5c09a 100644 --- a/dix/devices.c +++ b/dix/devices.c @@ -1584,13 +1584,15 @@ SendMappingNotify(DeviceIntPtr pDev, unsigned request, unsigned firstKeyCode, } /* - * n-squared algorithm. n < 255 and don't want to copy the whole thing and - * sort it to do the checking. How often is it called? Just being lazy? + * Check if the given buffer contains elements between low (inclusive) and + * high (inclusive) only. + * + * @return TRUE if the device map is invalid, FALSE otherwise. */ Bool BadDeviceMap(BYTE *buff, int length, unsigned low, unsigned high, XID *errval) { - int i, j; + int i; for (i = 0; i < length; i++) if (buff[i]) /* only check non-zero elements */ @@ -1600,12 +1602,6 @@ BadDeviceMap(BYTE *buff, int length, unsigned low, unsigned high, XID *errval) *errval = buff[i]; return TRUE; } - for (j = i + 1; j < length; j++) - if (buff[i] == buff[j]) - { - *errval = buff[i]; - return TRUE; - } } return FALSE; } @@ -1861,6 +1857,7 @@ ProcSetPointerMapping(ClientPtr client) { BYTE *map; int ret; + int i, j; DeviceIntPtr ptr = PickPointer(client); xSetPointerMappingReply rep; REQUEST(xSetPointerMappingReq); @@ -1887,6 +1884,19 @@ ProcSetPointerMapping(ClientPtr client) if (BadDeviceMap(&map[0], (int)stuff->nElts, 1, 255, &client->errorValue)) return BadValue; + /* core protocol specs don't allow for duplicate mappings. */ + for (i = 0; i < stuff->nElts; i++) + { + for (j = i + 1; j < stuff->nElts; j++) + { + if (map[i] && map[i] == map[j]) + { + client->errorValue = map[i]; + return BadValue; + } + } + } + ret = DoSetPointerMapping(client, ptr, map, stuff->nElts); if (ret != Success) { rep.success = ret; |