dix: write out X_GetKeyboardControl reply directly

No need for using a complex callback machinery, if we just move the
little pieces of byte-swapping directly into the request handler.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
Enrico Weigelt, metux IT consult 2025-04-03 16:26:23 +02:00
parent 5829703de2
commit 46abb82984
4 changed files with 28 additions and 30 deletions

View File

@ -1973,27 +1973,36 @@ ProcGetKeyboardMapping(ClientPtr client)
if (!syms) if (!syms)
return BadAlloc; return BadAlloc;
const int count = syms->mapWidth * stuff->count;
const int size = count * sizeof(KeySym);
void *payload = calloc(count, sizeof(KeySym));
if (!payload)
return BadAlloc;
memcpy(payload,
&syms->map[syms->mapWidth * (stuff->firstKeyCode - syms->minKeyCode)],
size);
xGetKeyboardMappingReply rep = { xGetKeyboardMappingReply rep = {
.type = X_Reply, .type = X_Reply,
.keySymsPerKeyCode = syms->mapWidth, .keySymsPerKeyCode = syms->mapWidth,
.sequenceNumber = client->sequence, .sequenceNumber = client->sequence,
/* length is a count of 4 byte quantities and KeySyms are 4 bytes */ /* length is a count of 4 byte quantities and KeySyms are 4 bytes */
.length = syms->mapWidth * stuff->count .length = count
}; };
if (client->swapped) { if (client->swapped) {
swaps(&rep.sequenceNumber); swaps(&rep.sequenceNumber);
swapl(&rep.length); swapl(&rep.length);
SwapLongs(payload, count);
} }
WriteToClient(client, sizeof(rep), &rep); WriteToClient(client, sizeof(rep), &rep);
client->pSwapReplyFunc = (ReplySwapPtr) CopySwap32Write; WriteToClient(client, size, payload);
WriteSwappedDataToClient(client,
syms->mapWidth * stuff->count * sizeof(KeySym),
&syms->map[syms->mapWidth * (stuff->firstKeyCode -
syms->minKeyCode)]);
free(syms->map); free(syms->map);
free(syms); free(syms);
free(payload);
return Success; return Success;
} }
@ -2255,18 +2264,16 @@ ProcChangeKeyboardControl(ClientPtr client)
int int
ProcGetKeyboardControl(ClientPtr client) ProcGetKeyboardControl(ClientPtr client)
{ {
int rc, i;
DeviceIntPtr kbd = PickKeyboard(client); DeviceIntPtr kbd = PickKeyboard(client);
KeybdCtrl *ctrl = &kbd->kbdfeed->ctrl; KeybdCtrl *ctrl = &kbd->kbdfeed->ctrl;
xGetKeyboardControlReply rep;
REQUEST_SIZE_MATCH(xReq); REQUEST_SIZE_MATCH(xReq);
rc = XaceHookDeviceAccess(client, kbd, DixGetAttrAccess); int rc = XaceHookDeviceAccess(client, kbd, DixGetAttrAccess);
if (rc != Success) if (rc != Success)
return rc; return rc;
rep = (xGetKeyboardControlReply) { xGetKeyboardControlReply rep = {
.type = X_Reply, .type = X_Reply,
.globalAutoRepeat = ctrl->autoRepeat, .globalAutoRepeat = ctrl->autoRepeat,
.sequenceNumber = client->sequence, .sequenceNumber = client->sequence,
@ -2277,9 +2284,17 @@ ProcGetKeyboardControl(ClientPtr client)
.bellPitch = ctrl->bell_pitch, .bellPitch = ctrl->bell_pitch,
.bellDuration = ctrl->bell_duration .bellDuration = ctrl->bell_duration
}; };
for (i = 0; i < 32; i++) for (int i = 0; i < 32; i++)
rep.map[i] = ctrl->autoRepeats[i]; rep.map[i] = ctrl->autoRepeats[i];
WriteReplyToClient(client, sizeof(xGetKeyboardControlReply), &rep);
if (client->swapped) {
swaps(&rep.sequenceNumber);
swapl(&rep.length);
swapl(&rep.ledMask);
swaps(&rep.bellPitch);
swaps(&rep.bellDuration);
}
WriteToClient(client, sizeof(rep), &rep);
return Success; return Success;
} }

View File

@ -535,18 +535,6 @@ SListExtensionsReply(ClientPtr pClient, int size, xListExtensionsReply * pRep)
WriteToClient(pClient, size, pRep); WriteToClient(pClient, size, pRep);
} }
void _X_COLD
SGetKeyboardControlReply(ClientPtr pClient, int size,
xGetKeyboardControlReply * pRep)
{
swaps(&pRep->sequenceNumber);
swapl(&pRep->length);
swapl(&pRep->ledMask);
swaps(&pRep->bellPitch);
swaps(&pRep->bellDuration);
WriteToClient(pClient, size, pRep);
}
void _X_COLD void _X_COLD
SGetPointerControlReply(ClientPtr pClient, int size, SGetPointerControlReply(ClientPtr pClient, int size,
xGetPointerControlReply * pRep) xGetPointerControlReply * pRep)

View File

@ -818,7 +818,7 @@ ReplySwapPtr ReplySwapVector[256] = {
ReplyNotSwappd, /* 100 */ ReplyNotSwappd, /* 100 */
ReplyNotSwappd, ReplyNotSwappd,
ReplyNotSwappd, ReplyNotSwappd,
(ReplySwapPtr) SGetKeyboardControlReply, ReplyNotSwappd,
ReplyNotSwappd, ReplyNotSwappd,
ReplyNotSwappd, /* 105 */ ReplyNotSwappd, /* 105 */
(ReplySwapPtr) SGetPointerControlReply, (ReplySwapPtr) SGetPointerControlReply,

View File

@ -154,11 +154,6 @@ extern void SListExtensionsReply(ClientPtr /* pClient */ ,
int /* size */ , int /* size */ ,
xListExtensionsReply * /* pRep */ ); xListExtensionsReply * /* pRep */ );
extern void SGetKeyboardControlReply(ClientPtr /* pClient */ ,
int /* size */ ,
xGetKeyboardControlReply *
/* pRep */ );
extern void SGetPointerControlReply(ClientPtr /* pClient */ , extern void SGetPointerControlReply(ClientPtr /* pClient */ ,
int /* size */ , int /* size */ ,
xGetPointerControlReply * xGetPointerControlReply *