Compare commits

...

28 Commits

Author SHA1 Message Date
Enrico Weigelt, metux IT consult 4d134256b4 xkb: ProcXkbGetKbdByName(): collect sub-replies in buffer and write at once
Instead of dozens of little WriteToClient() calls, collect the sub-replies in
a buffer and send the whole reply out at once. This also allows more upcoming
simplifications in the send path.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-02-19 15:13:01 +00:00
Enrico Weigelt, metux IT consult e75ac0114b xkb: split XkbSendGeometry()
This function is a funny beast: it assembles and writes out an xkbGetGeometryReply,
called in two different cases, ProcXkbGetGeometry() as well as ProcXkbGetKbdByName().
In the latter case the whole reply is contained in another one. That's the reason
why it's payload size is computed separately - the caller must know that in order
to set up the container's reply size correctly.

As preparation for upcoming simplifications of the reply send path, splitting off
this function into pieces: XkbAssembleGeometry() just assembles the reply payload,
while it's callers now responsible for preparing the request header and writing
out both pieces.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-02-19 15:13:01 +00:00
Enrico Weigelt, metux IT consult dcefd2156f xkb: split XkbSendIndicatorMap()
This function is a funny beast: it assembles and writes out an xkbGetIndicatorMapReply,
called in two different cases, ProcXkbGetIndicatorMap() as well as ProcXkbGetKbdByName().
In the latter case the whole reply is contained in another one. That's the reason
why it's payload size is computed separately - the caller must know that in order
to set up the container's reply size correctly.

As preparation for upcoming simplifications of the reply send path, splitting off
this function into pieces: XkbAssembleIndicatorMap() just assembles the reply payload,
while it's callers now responsible for preparing the request header and writing
out both pieces.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-02-19 15:13:01 +00:00
Enrico Weigelt, metux IT consult 5f667c59b4 xkb: split XkbSendCompatMap()
This function is a funny beast: it assembles and writes out an xkbGetCompatMapReply,
called in two different cases, ProcXkbGetCompatMap() as well as ProcXkbGetKbdByName().
In the latter case the whole reply is contained in another one. That's the reason
why it's payload size is computed separately - the caller must know that in order
to set up the container's reply size correctly.

As preparation for upcoming simplifications of the reply send path, splitting off
this function into pieces: XkbAssembleCompatMap() just assembles the reply payload,
while it's callers now responsible for preparing the request header and writing
out both pieces.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-02-19 15:13:01 +00:00
Enrico Weigelt, metux IT consult 228fade03c xkb: split XkbSendMap()
This function is a funny beast: it assembles and writes out an xkbGetMapReply,
called in two different cases, ProcXkbGetMap() as well as ProcXkbGetKbdByName().
In the latter case the whole reply is contained in another one. That's the reason
why it's payload size is computed separately - the caller must know that in order
to set up the container's reply size correctly.

As preparation for upcoming simplifications of the reply send path, splitting off
this function into pieces: XkbAssembleMap() just assembles the reply payload,
while it's callers now responsible for preparing the request header and writing
out both pieces.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-02-19 15:13:01 +00:00
Enrico Weigelt, metux IT consult bfd5ca197b xkb: ProcXkbGetKbdByName(): static initialization of sub-reply structs
For easier reading, move th sub-reply structs down to where they're used
first and use static initialization for the common fields.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-02-19 15:13:01 +00:00
Enrico Weigelt, metux IT consult 8a21666344 xkb: ProcXkbGetKbdByName() simplify reply struct initialization
Move down the declaration of the reply struct, right before swapping and sending
and use static initialization.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-02-19 15:13:01 +00:00
Enrico Weigelt, metux IT consult bfd2a84e17 xkb: XkbSendGeometry(): pass in struct as value instead of pointer
The function doesn't need to pass anything back via this pointer, it's
the last consumer of this struct. Make understanding the code a bit easier
and clear the road for further simplifications by passing the struct as
value instead of pointer.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-02-19 15:13:01 +00:00
Enrico Weigelt, metux IT consult 669019513b xkb: XkbSendNames(): move common code into a helper macro
A little bit of simplification by putting repeated statements into macro.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-02-19 15:13:01 +00:00
Enrico Weigelt, metux IT consult c2c09f15dc xkb: XkbSendNames(): pass in struct as value instead of pointer
The function doesn't need to pass anything back via this pointer, it's
the last consumer of this struct. Make understanding the code a bit easier
and clear the road for further simplifications by passing the struct as
value instead of pointer.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-02-19 15:13:01 +00:00
Enrico Weigelt, metux IT consult 5d2679f41a xkb: let SendDeviceLedFBs() fill buffer instead of writing directly
Make the code flow a bit easier to understand and allow further simplification
by now just having to write out one additional payload as one block.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-02-19 15:13:01 +00:00
Enrico Weigelt, metux IT consult b3a47dcbc4 xkb: ProcXkbGetDeviceInfo(): consolidate buffers to reduce writes
Putting both payload pieces into one buffer, so it can be written out
with only one call.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-02-19 15:13:01 +00:00
Enrico Weigelt, metux IT consult dff3e38a67 xkb: CheckDeviceLedFBs(): untwist parameters
It's hard to see which fields of the xkbGetDeviceInfoReply struct it's
reading or writing, and that complicates further simplifications of the
caller. So instead let the caller pass in the relevant fields and do the
modifications on the reply structs on its own.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-02-19 15:13:01 +00:00
Enrico Weigelt, metux IT consult d9d03c6241 xkb: XkbSendIndicatorMap(): little simplification
A bit simplification in code flow.
The extra length check (did we write as much as intended?) isn't necessary,
since the buffer size is computed by the very same data before this
function is called.

Hint: the size computation must be done before calling this one, because
the reply might be encapsulated in another one (xkbGetKbdByName).

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-02-19 15:13:01 +00:00
Enrico Weigelt, metux IT consult 9c5ae33f0d xkb: XkbSendIndicatorMap() pass in reply struct as value instead of pointer
It's not passing back any data via that pointer and actually the last
consumer of it. Changing it to value instead of pointer clears the
road for further simplifications by subsequent patches.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-02-19 15:13:01 +00:00
Enrico Weigelt, metux IT consult 702e5a19db xkb: XkbSendCompatMap(): little cleanup and simplification
Make it a bit simpler and easier to read.

calloc() and WriteToClient() can handle zero lengths very well.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-02-19 15:13:01 +00:00
Enrico Weigelt, metux IT consult 84a91a4cd3 xkb: XkbSendCompatMap(): pass xkbGetCompatMapReply as value instead of pointer
It's not passing back any data via that pointer and actually the last
consumer of it. Changing it to value instead of pointer clears the
road for further simplifications by subsequent patches.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-02-19 15:13:01 +00:00
Enrico Weigelt, metux IT consult 8b9beb6e5f xkb: XkbSendMap(): some little variable decl cleanups
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-02-19 15:13:01 +00:00
Enrico Weigelt, metux IT consult 5980d96ee0 xkb: XkbSendMap() pass in reply struct as value instead of pointer
It's not passing back any data via that pointer and actually the last
consumer of it. Changing it to value instead of pointer clears the
road for further simplifications by subsequent patches.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-02-19 15:13:01 +00:00
Enrico Weigelt, metux IT consult 4140099d0f xkb: XkbWriteVirtualModMap(): only pass in the needed data
We don't need the whole struct here, especially do we not wanna change it.
Therefore only pass in what's really needed, so it gets easier to understand.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-02-19 15:13:01 +00:00
Enrico Weigelt, metux IT consult 155d8314a8 xkb: XkbWriteModifierMap(): only pass in the needed data
We don't need the whole struct here, especially do we not wanna change it.
Therefore only pass in what's really needed, so it gets easier to understand.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-02-19 15:13:01 +00:00
Enrico Weigelt, metux IT consult f80c061f98 xkb: XkbWriteExplicit(): only pass in the needed data
We don't need the whole struct here, especially do we not wanna change it.
Therefore only pass in what's really needed, so it gets easier to understand.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-02-19 15:13:01 +00:00
Enrico Weigelt, metux IT consult a3f5706242 xkb: XkbWriteKeyBehaviors(): only pass in the needed data
We don't need the whole struct here, especially do we not wanna change it.
Therefore only pass in what's really needed, so it gets easier to understand.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-02-19 15:13:01 +00:00
Enrico Weigelt, metux IT consult 3e3c514f23 xkb: XkbWriteKeyActions(): only pass in the needed data
We don't need the whole struct here, especially do we not wanna change it.
Therefore only pass in what's really needed, so it gets easier to understand.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-02-19 15:13:01 +00:00
Enrico Weigelt, metux IT consult 1faf2b182e xkb: XkbWriteKeyTypes(): only pass in the needed data
We don't need the whole struct here, especially do we not wanna change it.
Therefore only pass in what's really needed, so it gets easier to understand.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-02-19 15:13:01 +00:00
Enrico Weigelt, metux IT consult 270d340d2a xkb: XkbWriteKeySyms(): only pass in the needed data
We don't need the whole struct here, especially do we not wanna change it.
Therefore only pass in what's really needed, so it gets easier to understand.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-02-19 15:13:01 +00:00
Enrico Weigelt, metux IT consult e1bad7ee58 xkb: SProcXkbSelectEvents(): simplify swapping
The swapping logic isn't entirely trivial to understand and can be
simplified.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-02-19 15:13:01 +00:00
Enrico Weigelt, metux IT consult d422be4161 xkb: simplify reply struct initialization
Use static initializaton as much as possible and drop unnecessary
or duplicate zero assignments.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-02-19 15:13:01 +00:00
2 changed files with 598 additions and 681 deletions

1238
xkb/xkb.c

File diff suppressed because it is too large Load Diff

View File

@ -67,10 +67,10 @@ SProcXkbSelectEvents(ClientPtr client)
CARD16 *c16;
CARD32 *c32;
} from;
register unsigned bit, ndx, maskLeft, dataLeft, size;
register unsigned bit, ndx, maskLeft, dataLeft;
from.c8 = (CARD8 *) &stuff[1];
dataLeft = (client->req_len * 4) - SIZEOF(xkbSelectEventsReq);
dataLeft = (client->req_len * 4) - sizeof(xkbSelectEventsReq);
maskLeft = (stuff->affectWhich & (~XkbMapNotifyMask));
for (ndx = 0, bit = 1; (maskLeft != 0); ndx++, bit <<= 1) {
if (((bit & maskLeft) == 0) || (ndx == XkbMapNotify))
@ -79,42 +79,43 @@ SProcXkbSelectEvents(ClientPtr client)
if ((stuff->selectAll & bit) || (stuff->clear & bit))
continue;
switch (ndx) {
// CARD16
case XkbNewKeyboardNotify:
case XkbStateNotify:
case XkbNamesNotify:
case XkbAccessXNotify:
case XkbExtensionDeviceNotify:
size = 2;
if (dataLeft < sizeof(CARD16)*2)
return BadLength;
swaps(&from.c16[0]);
swaps(&from.c16[1]);
from.c8 += sizeof(CARD16)*2;
dataLeft -= sizeof(CARD16)*2;
break;
// CARD32
case XkbControlsNotify:
case XkbIndicatorStateNotify:
case XkbIndicatorMapNotify:
size = 4;
if (dataLeft < sizeof(CARD32)*2)
return BadLength;
swapl(&from.c32[0]);
swapl(&from.c32[1]);
from.c8 += sizeof(CARD32)*2;
dataLeft -= sizeof(CARD32)*2;
break;
// CARD8
case XkbBellNotify:
case XkbActionMessage:
case XkbCompatMapNotify:
size = 1;
if (dataLeft < 2)
return BadLength;
from.c8 += 4;
dataLeft -= 4;
break;
default:
client->errorValue = _XkbErrCode2(0x1, bit);
return BadValue;
}
if (dataLeft < (size * 2))
return BadLength;
if (size == 2) {
swaps(&from.c16[0]);
swaps(&from.c16[1]);
}
else if (size == 4) {
swapl(&from.c32[0]);
swapl(&from.c32[1]);
}
else {
size = 2;
}
from.c8 += (size * 2);
dataLeft -= (size * 2);
}
if (dataLeft > 2) {
ErrorF("[xkb] Extra data (%d bytes) after SelectEvents\n",