0001-xkb-fix-XkbSetMap-when-changing-a-keysym-without-cha.patch 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. From 0217cc6e0cf5013366105a90f5f91ccc4bab5425 Mon Sep 17 00:00:00 2001
  2. From: Samuel Thibault <samuel.thibault@ens-lyon.org>
  3. Date: Wed, 26 Jan 2022 00:05:55 +0100
  4. Subject: [PATCH] xkb: fix XkbSetMap when changing a keysym without changing a
  5. keytype
  6. As the comment says:
  7. "symsPerKey/mapWidths must be filled regardless of client-side flags"
  8. so we always have to call CheckKeyTypes which will notably fill mapWidths
  9. and nTypes. That is needed for CheckKeySyms to work since it checks the
  10. width. Without it, any request with XkbKeySymsMask but not
  11. XkbKeyTypesMask will fail because of the missing width information, for
  12. instance this:
  13. XkbDescPtr xkb;
  14. if (!(xkb = XkbGetMap (dpy, XkbKeyTypesMask|XkbKeySymsMask, XkbUseCoreKbd))) {
  15. fprintf (stderr, "ERROR getting map\n");
  16. exit(1);
  17. }
  18. XFlush (dpy);
  19. XSync (dpy, False);
  20. XkbMapChangesRec changes = { .changed = 0 };
  21. int oneGroupType[XkbNumKbdGroups] = { XkbOneLevelIndex };
  22. if (XkbChangeTypesOfKey(xkb, keycode, 1, XkbGroup1Mask, oneGroupType, &changes)) {
  23. fprintf(stderr, "ERROR changing type of key\n");
  24. exit(1);
  25. }
  26. XkbKeySymEntry(xkb,keycode,0,0) = keysym;
  27. if (!XkbChangeMap(dpy,xkb,&changes)) {
  28. fprintf(stderr, "ERROR changing map\n");
  29. exit(1);
  30. }
  31. XkbFreeKeyboard (xkb, 0, TRUE);
  32. XFlush (dpy);
  33. XSync (dpy, False);
  34. This had being going under the radar since about ever until commit
  35. de940e06f8733d87bbb857aef85d830053442cfe ("xkb: fix key type index check
  36. in _XkbSetMapChecks") fixed checking the values of kt_index, which was
  37. previously erroneously ignoring errors and ignoring all other checks, just
  38. because nTypes was not set, precisely because CheckKeyTypes was not called.
  39. Note: yes, CheckKeyTypes is meant to be callable without XkbKeyTypesMask, it
  40. does properly check for that and just fills nTypes and mapWidths in that
  41. case.
  42. Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
  43. Signed-off-by: Laurent Carlier <lordheavym@gmail.com>
  44. ---
  45. xkb/xkb.c | 11 +++++------
  46. 1 file changed, 5 insertions(+), 6 deletions(-)
  47. diff --git a/xkb/xkb.c b/xkb/xkb.c
  48. index bfc21de00..820cd7166 100644
  49. --- a/xkb/xkb.c
  50. +++ b/xkb/xkb.c
  51. @@ -2511,16 +2511,15 @@ _XkbSetMapChecks(ClientPtr client, DeviceIntPtr dev, xkbSetMapReq * req,
  52. }
  53. }
  54. - if (!(req->present & XkbKeyTypesMask)) {
  55. - nTypes = xkb->map->num_types;
  56. - }
  57. - else if (!CheckKeyTypes(client, xkb, req, (xkbKeyTypeWireDesc **) &values,
  58. - &nTypes, mapWidths, doswap)) {
  59. + /* nTypes/mapWidths/symsPerKey must be filled for further tests below,
  60. + * regardless of client-side flags */
  61. +
  62. + if (!CheckKeyTypes(client, xkb, req, (xkbKeyTypeWireDesc **) &values,
  63. + &nTypes, mapWidths, doswap)) {
  64. client->errorValue = nTypes;
  65. return BadValue;
  66. }
  67. - /* symsPerKey/mapWidths must be filled regardless of client-side flags */
  68. map = &xkb->map->key_sym_map[xkb->min_key_code];
  69. for (i = xkb->min_key_code; i < xkb->max_key_code; i++, map++) {
  70. register int g, ng, w;
  71. --
  72. 2.35.1