xkb: only swap once in XkbSetMap

The server swaps part of the request in _XkbSetMapChecks instead of
SProcXkbSetMap (presumably because walking the XkbSetMap request is hard,
and we don't want to maintain another copy of that code).

Swap the first time _XkbSetMapChecks is called, not the second time.

Signed-off-by: Peter Harris <pharris@opentext.com>
This commit is contained in:
Peter Harris 2019-11-14 14:00:31 -05:00
parent d4faab8708
commit 270e439739

View File

@ -1587,7 +1587,7 @@ CheckKeyTypes(ClientPtr client,
XkbDescPtr xkb, XkbDescPtr xkb,
xkbSetMapReq * req, xkbSetMapReq * req,
xkbKeyTypeWireDesc ** wireRtrn, xkbKeyTypeWireDesc ** wireRtrn,
int *nMapsRtrn, CARD8 *mapWidthRtrn) int *nMapsRtrn, CARD8 *mapWidthRtrn, Bool doswap)
{ {
unsigned nMaps; unsigned nMaps;
register unsigned i, n; register unsigned i, n;
@ -1626,7 +1626,7 @@ CheckKeyTypes(ClientPtr client,
for (i = 0; i < req->nTypes; i++) { for (i = 0; i < req->nTypes; i++) {
unsigned width; unsigned width;
if (client->swapped) { if (client->swapped && doswap) {
swaps(&wire->virtualMods); swaps(&wire->virtualMods);
} }
n = i + req->firstType; n = i + req->firstType;
@ -1653,7 +1653,7 @@ CheckKeyTypes(ClientPtr client,
mapWire = (xkbKTSetMapEntryWireDesc *) &wire[1]; mapWire = (xkbKTSetMapEntryWireDesc *) &wire[1];
preWire = (xkbModsWireDesc *) &mapWire[wire->nMapEntries]; preWire = (xkbModsWireDesc *) &mapWire[wire->nMapEntries];
for (n = 0; n < wire->nMapEntries; n++) { for (n = 0; n < wire->nMapEntries; n++) {
if (client->swapped) { if (client->swapped && doswap) {
swaps(&mapWire[n].virtualMods); swaps(&mapWire[n].virtualMods);
} }
if (mapWire[n].realMods & (~wire->realMods)) { if (mapWire[n].realMods & (~wire->realMods)) {
@ -1671,7 +1671,7 @@ CheckKeyTypes(ClientPtr client,
return 0; return 0;
} }
if (wire->preserve) { if (wire->preserve) {
if (client->swapped) { if (client->swapped && doswap) {
swaps(&preWire[n].virtualMods); swaps(&preWire[n].virtualMods);
} }
if (preWire[n].realMods & (~mapWire[n].realMods)) { if (preWire[n].realMods & (~mapWire[n].realMods)) {
@ -1710,7 +1710,7 @@ CheckKeySyms(ClientPtr client,
xkbSetMapReq * req, xkbSetMapReq * req,
int nTypes, int nTypes,
CARD8 *mapWidths, CARD8 *mapWidths,
CARD16 *symsPerKey, xkbSymMapWireDesc ** wireRtrn, int *errorRtrn) CARD16 *symsPerKey, xkbSymMapWireDesc ** wireRtrn, int *errorRtrn, Bool doswap)
{ {
register unsigned i; register unsigned i;
XkbSymMapPtr map; XkbSymMapPtr map;
@ -1724,7 +1724,7 @@ CheckKeySyms(ClientPtr client,
KeySym *pSyms; KeySym *pSyms;
register unsigned nG; register unsigned nG;
if (client->swapped) { if (client->swapped && doswap) {
swaps(&wire->nSyms); swaps(&wire->nSyms);
} }
nG = XkbNumGroups(wire->groupInfo); nG = XkbNumGroups(wire->groupInfo);
@ -2371,11 +2371,11 @@ SetVirtualModMap(XkbSrvInfoPtr xkbi,
/** /**
* Check if the given request can be applied to the given device but don't * Check if the given request can be applied to the given device but don't
* actually do anything.. * actually do anything, except swap values when client->swapped and doswap are both true.
*/ */
static int static int
_XkbSetMapChecks(ClientPtr client, DeviceIntPtr dev, xkbSetMapReq * req, _XkbSetMapChecks(ClientPtr client, DeviceIntPtr dev, xkbSetMapReq * req,
char *values) char *values, Bool doswap)
{ {
XkbSrvInfoPtr xkbi; XkbSrvInfoPtr xkbi;
XkbDescPtr xkb; XkbDescPtr xkb;
@ -2415,7 +2415,7 @@ _XkbSetMapChecks(ClientPtr client, DeviceIntPtr dev, xkbSetMapReq * req,
if ((req->present & XkbKeyTypesMask) && if ((req->present & XkbKeyTypesMask) &&
(!CheckKeyTypes(client, xkb, req, (xkbKeyTypeWireDesc **) &values, (!CheckKeyTypes(client, xkb, req, (xkbKeyTypeWireDesc **) &values,
&nTypes, mapWidths))) { &nTypes, mapWidths, doswap))) {
client->errorValue = nTypes; client->errorValue = nTypes;
return BadValue; return BadValue;
} }
@ -2439,7 +2439,7 @@ _XkbSetMapChecks(ClientPtr client, DeviceIntPtr dev, xkbSetMapReq * req,
if ((req->present & XkbKeySymsMask) && if ((req->present & XkbKeySymsMask) &&
(!CheckKeySyms(client, xkb, req, nTypes, mapWidths, symsPerKey, (!CheckKeySyms(client, xkb, req, nTypes, mapWidths, symsPerKey,
(xkbSymMapWireDesc **) &values, &error))) { (xkbSymMapWireDesc **) &values, &error, doswap))) {
client->errorValue = error; client->errorValue = error;
return BadValue; return BadValue;
} }
@ -2631,7 +2631,7 @@ ProcXkbSetMap(ClientPtr client)
/* Check if we can to the SetMap on the requested device. If this /* Check if we can to the SetMap on the requested device. If this
succeeds, do the same thing for all extension devices (if needed). succeeds, do the same thing for all extension devices (if needed).
If any of them fails, fail. */ If any of them fails, fail. */
rc = _XkbSetMapChecks(client, dev, stuff, tmp); rc = _XkbSetMapChecks(client, dev, stuff, tmp, TRUE);
if (rc != Success) if (rc != Success)
return rc; return rc;
@ -2647,7 +2647,7 @@ ProcXkbSetMap(ClientPtr client)
rc = XaceHook(XACE_DEVICE_ACCESS, client, other, rc = XaceHook(XACE_DEVICE_ACCESS, client, other,
DixManageAccess); DixManageAccess);
if (rc == Success) { if (rc == Success) {
rc = _XkbSetMapChecks(client, other, stuff, tmp); rc = _XkbSetMapChecks(client, other, stuff, tmp, FALSE);
if (rc != Success) if (rc != Success)
return rc; return rc;
} }
@ -2661,7 +2661,7 @@ ProcXkbSetMap(ClientPtr client)
(other != master || dev != master->lastSlave)) (other != master || dev != master->lastSlave))
continue; continue;
rc = _XkbSetMapChecks(client, other, stuff, tmp); rc = _XkbSetMapChecks(client, other, stuff, tmp, FALSE);
if (rc != Success) if (rc != Success)
return rc; return rc;
} }