Commit Graph

856 Commits

Author SHA1 Message Date
sesankm
0e43e8c2aa xkb: xkb.c: refactor to use c99 style declarations
Signed-off-by: sesankm <26676400+sesankm@users.noreply.github.com>
2025-09-03 13:33:40 +02:00
Enrico Weigelt, metux IT consult
7dcd9c7b1e xkb: xkbEvents: use static struct initialization
Instead of memset()ing all the structs and then assigning (overwriting)
invidual fields one by one, use static init and let the compiler find out
on its own how to do it the best way.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-09-02 12:51:43 +02:00
Enrico Weigelt, metux IT consult
f8ad69698a treewide return code of X_SEND_REPLY_WITH_RPCBUF()
The macro will automatically return BadAlloc if the buffer is broken,
otherwise Success. Thus, we don't need extra prior rpcbuf check.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-09-02 12:48:50 +02:00
Enrico Weigelt, metux IT consult
c4b492b36d xkb: ProcXkbGetDeviceInfo(): use x_rpcbuf_t for reply payload assembly
At this point just use it as allocator, so we can use the
X_SEND_REPLY_WITH_RPCBUF() macro for final sending.

Follow-up commits will change the whole call stack to operate on
x_rpcbuf_t directly, so it's also doing the byte-swap for us.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-31 10:00:40 +02:00
Enrico Weigelt, metux IT consult
64d465fdaf xkb: send simple replies via X_SEND_REPLY_SIMPLE()
Use the X_SEND_REPLY_SIMPLE() macro for sending simple replies.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-29 11:42:53 +02:00
Enrico Weigelt, metux IT consult
a9fce3b3c2 xkb: XkbAssembleGeometry(): use x_rpcbuf_t
Use x_rpcbuf_t for assembling / byte-swapping reply payload.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-26 11:03:17 +02:00
Enrico Weigelt, metux IT consult
84dd2a5039 xkb: ProcXkbGetKbdByName(): extra payload size sanity check
Add extra check for comparing the actually written sub-payload sizes
with their previously computed ones. This is meant for troubeshooting
while still stabelizing the previous, not entirely trivial commits.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-26 11:02:44 +02:00
Enrico Weigelt, metux IT consult
79792e10ae xkb: XkbWriteGeomKeyAliases(): use x_rpcbuf_t
Use x_rpcbuf_t for assembling the reply payload chunk.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-24 12:42:02 +02:00
Enrico Weigelt, metux IT consult
dbf9f932eb xkb: FillDeviceLedInfo(): use x_rpcbuf_t 2025-08-24 12:09:25 +02:00
Enrico Weigelt, metux IT consult
7f7b909abe xkb: XkbWriteGeomProperties(): use x_rpcbuf_t
Use x_rpcbuf_t for assembling reply payload chunk.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-24 12:08:47 +02:00
Enrico Weigelt, metux IT consult
82677b237b xkb: XkbWriteGeomSections(): use x_rpcbuf_t
Use x_rpcbuf_t for payload chunk assembly / byte-swapping.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-22 14:44:05 +02:00
Enrico Weigelt, metux IT consult
fd96c2950e xkb: XkbWriteGeomColors(): use x_rpcbuf_t
Use x_rpcbuf_t for assembling reply payload chunk.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-22 14:33:10 +02:00
Enrico Weigelt, metux IT consult
d6089c52c3 treewide: macro for computing extra units needed for reply header
Add and use macro X_REPLY_HEADER_UNITS() for computing how many
extra protocol units are needed for a reply header (for .length field)

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-22 14:14:32 +02:00
Enrico Weigelt, metux IT consult
16997296d3 xkb: use x_rpcbuf_t in XkbWriteGeomShapes()
Use x_rpcbuf_t for assembling and byte-swapping the reply payload chunk.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-21 13:12:16 +02:00
Enrico Weigelt, metux IT consult
a2211393df xkb: XkbWriteGeomDoodads(): use x_rpcbuf_t
Use x_rpcbuf_t for reply payload chunk assembly and byte-swapping.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-21 13:03:25 +02:00
Enrico Weigelt, metux IT consult
ca27ebbd7d xkb: XkbAssembleNames(): use x_rpcbuf_t for payload assembly
Use rpcbuf for assembling and byte-swapping xkb names payload.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-21 13:03:12 +02:00
Enrico Weigelt, metux IT consult
b0149c0183 xkb: XkbAssembleIndicatorMap(): use x_rpcbuf_t
Use x_rpbuf_t instead of raw buffer for assembling and byte-swapping
indicator map payload.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-21 13:02:53 +02:00
Enrico Weigelt, metux IT consult
d3f9dc4973 xkb: use x_rpcbuf_t in XkbWriteGeomOverlay()
Use x_rpcbuf_t for assembling and byte-swapping the payload chunk.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-21 12:54:35 +02:00
Enrico Weigelt, metux IT consult
c621506c9e xkb: ProcXkbGetKbdByName(): drop obsolete x_rpcbuf_makeroom() call
Since no consumer of this rpcbuf is writing directly to the underlying
buffer space anymore, there's no need to explicitly make room.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-21 12:54:12 +02:00
Enrico Weigelt, metux IT consult
31b6e41c56 xkb: ProcXkbGetMap(): clean up local variables
declare them where needed.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-20 18:35:21 +02:00
Enrico Weigelt, metux IT consult
bec3b45c02 xkb: ProcXkbGetMap(): rename local variable
Give the variable `n` a better name: `numKeys`.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-20 18:35:21 +02:00
Enrico Weigelt, metux IT consult
b8a30d7347 xkb: ProcXkbGetMap(): use X_SEND_REPLY_WITH_RPCBUF()
Use generic macro for sending out final reply.
Also dropping our own unnecessary size payload computation - rpcbuf
already giving us this value.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-20 18:35:21 +02:00
Enrico Weigelt, metux IT consult
e197043099 xkb: ProcXkbGetCompatMap(): clean up variable declarations
Declara only what's really needed, where it's needed.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-20 11:32:32 +02:00
Enrico Weigelt, metux IT consult
743838456d xkb: ProcXkbGetCompatMap(): use X_SEND_REPLY_WITH_RPCBUF()
Now that we're entirely operating on x_rpcbuf_t, we can use generic
macro for the whole final write out, including setting standard
reply header fields.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-20 11:32:32 +02:00
Enrico Weigelt, metux IT consult
eda4dcabf7 xkb: use x_rpcbuf_t in XkbAssembleCompatMap()
Instead of operating on a raw buffer, use x_rpcbuf_t to assemble the
compat map payload.

ProcXkbGetCompatMap() now can directly operate on generic x_rpcbuf_t
and doesn't need it's own private buffer management.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-20 11:32:32 +02:00
Enrico Weigelt, metux IT consult
eea90293fb xkb: simplify XkbAssembleGeometry()
Preparation for further refactoring.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-20 11:32:05 +02:00
Enrico Weigelt, metux IT consult
7b0e5d9ac5 xkb: ProcXkbGetKbdByName(): drop unneeded payload size computation
The amount of data written by XkbAssembleMap() is already known rpcbuf,
so no need for additionally computing this our own anymore.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-20 11:31:08 +02:00
Enrico Weigelt, metux IT consult
8ea70e9e78 treewide: use use x_rpcbuf_wsize_units() instead of rpcbuf.wpos
In the request handlers, use x_rpcbuf_wsize_units() for payload length
computation.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-19 15:50:54 +02:00
Enrico Weigelt, metux IT consult
96129e44bd xkb: ProcXkbGetMap(): use WriteRpcbufToClient()
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-18 17:26:42 +02:00
Enrico Weigelt, metux IT consult
723f6a55a8 xkb: fix swapping bug in ProcXkbGetKbdByName()
We've been adding the individual sub-packet's payload bytes *after*
the swapping, which is leading to totally wrong sizes.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-18 17:26:18 +02:00
Enrico Weigelt, metux IT consult
e62e88fd8b xkb: fix padding in XkbWriteModifierMap()
Fixes: 18fe21fe0e
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-14 12:44:26 +02:00
Enrico Weigelt, metux IT consult
34c3a9c7e2 treewide: fix serverGeneration int type mismatch
The global (exported) serverGeneration field is `unsigned long`, while
many other places copy it and compare it two other integer types, eg.
plain `int` (which is signed). Even if it's unlikely ever reaching such
high number of generations that it will ever make trouble, it's still
a good idea to clean this up and use the same type everywhere.

For clearity, introducing a typedef `x_server_generation_t` which is
used everywhere, instead of raw `unsigned long`.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-13 11:52:03 +02:00
Enrico Weigelt, metux IT consult
7d8d609121 xkb: ProcXkbGetMap(): add payload_len sanity check
Print out a warning when actually written payload length doesn't mactch
the previously computed one.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-11 20:26:14 +02:00
Enrico Weigelt, metux IT consult
c3052dbc39 xkb: use x_rpcbuf_t in XkbWriteVirtualModMap()
As it's caller now has x_rpcbuf, we can use it here, instead of
meddling with pre-allocated buffer space directly via raw pointer.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-11 20:26:14 +02:00
Enrico Weigelt, metux IT consult
18fe21fe0e xkb: use x_rpcbuf_t in XkbWriteModifierMap()
As it's caller now has x_rpcbuf, we can use it here, instead of
meddling with pre-allocated buffer space directly via raw pointer.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-11 20:26:14 +02:00
Enrico Weigelt, metux IT consult
e5d91b49e5 xkb: use x_rpcbuf_t in XkbWriteExplicit()
As it's caller now has x_rpcbuf, we can use it here, instead of
meddling with pre-allocated buffer space directly via raw pointer.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-11 20:26:14 +02:00
Enrico Weigelt, metux IT consult
15a13ef93e xkb: XkbAssembleMap(): use x_rpcbuf_t for writing the virtual mods
As we now have x_rpcbuf, we can use it here, instead of meddling
with pre-allocated buffer space directly via raw pointer.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-11 20:26:14 +02:00
Enrico Weigelt, metux IT consult
316e5e431a xkb: use x_rpcbuf_t in XkbWriteKeyBehaviors()
As it's caller now has x_rpcbuf, we can use it here, instead of
meddling with pre-allocated buffer space directly via raw pointer.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-11 20:26:14 +02:00
Enrico Weigelt, metux IT consult
bee50daeca xkb: use x_rpcbuf_t in XkbWriteKeyActions()
As it's caller now has x_rpcbuf, we can use it here, instead of
meddling with pre-allocated buffer space directly via raw pointer.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-11 20:26:14 +02:00
Enrico Weigelt, metux IT consult
264ecee69b xkb: use x_rpcbuf_t in XkbWriteKeySyms()
As it's caller now has x_rpcbuf_t, we can use it here, instead of
meddling with pre-allocated buffer space directly via raw pointer.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-11 20:26:14 +02:00
Enrico Weigelt, metux IT consult
742443ea73 xkb: pass x_rpcbuf_t into XkbAssembleMap()
The keymap assembly machinery is a horribly complicated machinery,
because often whole replies with variable sized payloads can be nested
into each other. It's time to use x_rpcbuf_t for that, but's is not an
easy thing to do and really a huge change - therefore doing this in small
and easy to digest step.

At first, let XkbAssembleMap() operate on a x_rpcbuf_t. But for now just
let it use the x_rpcbuf_t's raw buffer directly (because it's callees cant
work on this yet) - thus XkbAssembleMap() yet need to make enough room
in the buffer before calling in.

For the time being we're allocating far too much (because calculating
the actually need amount would be too complicated here) and having an
extra memcpy(). But it's just an intermediate step anyways - subsequent
commits will convert everything down the whole call chain into using
x_rpcbuf_t operations, so that extra overhead can be dropped again later.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-11 20:26:14 +02:00
Enrico Weigelt, metux IT consult
f03042a2b7 dix: fix int mismatches related to MakeAtom()
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-11 20:05:57 +02:00
Enrico Weigelt, metux IT consult
3d0df13d78 xkb: xkbDflts.h: drop not needed include of <dix-config.h>
All source files need to include it anyways, so no need to include it here,
and neither having an extra check for HAVE_DIX_CONFIG_H

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-06 13:04:58 +02:00
Collin
398b4ed1e7 XKBMAlloc: Solve CodeQL Alert Potential use after double free 2025-07-23 14:40:42 +02:00
Enrico Weigelt, metux IT consult
48f8aad89b xkb: use dixAddAtom()
Use the new helper for creating atoms on demand.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-07-23 12:24:27 +02:00
Enrico Weigelt, metux IT consult
030745a0e7 dix: move inpututils.h and rename it to inpututil_privs.h
it's a private header, thus should not be in public include directory.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-07-18 04:51:30 +02:00
dasha_uwu
7c64a06ba4 treewide: remove "lib" prefix in static_library names (meson)
this was producing static libraries named "liblibsomething.a"

Signed-off-by: dasha_uwu <dasha@linuxping.win>
2025-07-03 12:01:52 +02:00
dec05eba
5342d0c380 xkb: fix XkbGetKbdByName returning incorrect data
This is a regression first caused by 182404fde6
that sends back the old xkb data instead of the new one.
This causes a mismatch in the data and size calculations between the
XkbComputeGetMapReplySize that is called above that calculates the size
of the reply and XkbAssembleMap that sets the data for the reply.

Without this fix this error is seen when running setxkbmap fr:
"Error loading new keyboard description".

Fixes setxkbmap error described in #180

Signed-off-by: dec05eba <dec05eba@protonmail.com>
2025-06-20 10:17:10 +02:00
dec05eba
f397039d65 xres/xkb/xvmc/modesetting: Fix incorrect pointer data size usage
* xled change tested with `xset led named "Scroll Lock"`
* modesetting change tested with `xrandr --output DP-1 --gamma 0.5:0.5:0.5`.
  Without this fix that command does nothing
* xvmc change tested with `mpv --vo=xv video.mp4`

Of the currently reported issues this fixes #104

Signed-off-by: dec05eba <dec05eba@protonmail.com>
2025-06-13 13:01:24 +02:00
Felipe Contreras
36db4b129d xkb: fix regression in GetDeviceInfo
This fixes a regression in 5499a2999 (xkb: let SendDeviceLedFBs() fill buffer instead of writing directly, 2024-07-16).

We need to write the whole buffer, and the updated length has to take
into consideration that `sz` now contains `led_len` so we need to
subtract that or properly calculate the remaining size.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
2025-06-12 17:21:48 +02:00