XkbSetMap(3)

πŸ’… XkbSetMap(3) β€” XKB FUNCTIONS πŸ’…

okay bestie, welcome to the XkbSetMap(3) page from the XKB FUNCTIONS manual. this one is lowkey a big deal: it’s all about sending a whole fresh set of map values to the server. no cap, we’re keeping every detail. πŸ’–


✨ NAME ✨

XkbSetMap β€” Send a complete new set of values for entire components to the server.

🌈 SYNOPSIS 🌈

Bool XkbSetMap (Display *dpy, unsigned int which, XkbDescPtr xkb);

πŸŽ€ ARGUMENTS πŸŽ€

  • dpy β€” connection to X server
  • which β€” mask selecting subcomponents to update
  • xkb β€” description from which new values are taken

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so there are literally two ways to make changes to map components: either change a local copy of the keyboard map and call XkbSetMap to send the modified map to the server, or β€” to reduce network traffic β€” use an XkbMapChangesRec structure and call XkbChangeMap. both iconic, different vibes. ✨

Use XkbSetMap to send a complete new set of values for entire components (for example, all symbols, all actions, and so on) to the server. The which parameter specifies the components to be sent to the server, and is a bitwise inclusive OR of the masks listed in Table 1. The xkb parameter is a pointer to an XkbDescRec structure and contains the information to be copied to the server. For each bit set in the which parameter, XkbSetMap takes the corresponding structure values from the xkb parameter and sends it to the server specified by dpy.

If any components specified by which are not present in the xkb parameter, XkbSetMap returns False. Otherwise, it sends the update request to the server and returns True. XkbSetMap can generate BadAlloc, BadLength, and BadValue protocol errors.

⚠️ heads up bestie: those protocol errors are real β€” BadAlloc, BadLength, and BadValue. do not ignore the vibe check. πŸ’€

Key types, symbol maps, and actions are all interrelated; changes in one require changes in the others. Xkb provides functions to make it easier to edit these components and handle the interdependencies. Table 1 lists these helper functions and provides a pointer to where they are defined.

πŸ“‹ Table 1 Xkb Mapping Component Masks and Convenience Functions πŸ“‹

  • XkbKeyTypesMask β€” Value: (1<<0); Map: client; Fields: types, size_types, num_types; Convenience Functions: XkbGetKeyTypes, XkbResizeKeyType, XkbCopyKeyType, XkbCopyKeyTypes
  • XkbKeySymsMask β€” Value: (1<<1); Map: client; Fields: syms, size_syms, num_syms, key_sym_map; Convenience Functions: XkbGetKeySyms, XkbResizeKeySyms, XkbChangeTypesOfKey
  • XkbModifierMapMask β€” Value: (1<<2); Map: client; Fields: modmap; Convenience Functions: XkbGetKeyModifierMap
  • XkbExplicitComponentsMask β€” Value: (1<<3); Map: server; Fields: explicit; Convenience Functions: XkbGetKeyExplicitComponents
  • XkbKeyActionsMask β€” Value: (1<<4); Map: server; Fields: key_acts, acts, num_acts, size_acts; Convenience Functions: XkbGetKeyActions, XkbResizeKeyActions
  • XkbKeyBehaviorsMask β€” Value: (1<<5); Map: server; Fields: behaviors; Convenience Functions: XkbGetKeyBehaviors
  • XkbVirtualModsMask β€” Value: (1<<6); Map: server; Fields: vmods; Convenience Functions: XkbGetVirtualMods
  • XkbVirtualModMapMask β€” Value: (1<<7); Map: server; Fields: vmodmap; Convenience Functions: XkbGetVirtualModMap

The changed field identifies the map components that have changed in an XkbDescRec structure and may contain any of the bits in Table 1, which are also shown in Table 2. Every 1 bit in changed also identifies which other fields in the XkbMapChangesRec structure contain valid values, as indicated in Table 2. The min_key_code and max_key_code fields are for reference only; they are ignored on any requests sent to the server and are always updated by the server whenever it returns the data for an XkbMapChangesRec.

πŸ“‹ Table 2 XkbMapChangesRec Masks πŸ“‹

  • XkbKeyTypesMask β€” Valid XkbMapChangesRec fields: first_type, num_types; XkbDescRec field containing changed data: map->type[first_type] .. map->type[first_type + num_types - 1]
  • XkbKeySymsMask β€” Valid XkbMapChangesRec fields: first_key_sym, num_key_syms; XkbDescRec field containing changed data: map->key_sym_map[first_key_sym] .. map->key_sym_map[first_key_sym + num_key_syms - 1]
  • XkbModifierMapMask β€” Valid XkbMapChangesRec fields: first_modmap_key, num_modmap_keys; XkbDescRec field containing changed data: map->modmap[first_modmap_key] .. map->modmap[first_modmap_key + num_modmap_keys - 1]
  • XkbExplicitComponentsMask β€” Valid XkbMapChangesRec fields: first_key_explicit, num_key_explicit; XkbDescRec field containing changed data: server->explicit[first_key_explicit] .. server->explicit[first_key_explicit + num_key_explicit - 1]
  • XkbKeyActionsMask β€” Valid XkbMapChangesRec fields: first_key_act, num_key_acts; XkbDescRec field containing changed data: server->key_acts[first_key_act] .. server->key_acts[first_key_act + num_key_acts - 1]
  • XkbKeyBehaviorsMask β€” Valid XkbMapChangesRec fields: first_key_behavior, num_key_behaviors; XkbDescRec field containing changed data: server->behaviors[first_key_behavior] .. server->behaviors[first_key_behavior + num_key_behaviors - 1]
  • XkbVirtualModsMask β€” Valid XkbMapChangesRec fields: vmods; XkbDescRec field containing changed data: server->vmods[*]
  • XkbVirtualModMapMask β€” Valid XkbMapChangesRec fields: first_vmodmap_key, num_vmodmap_keys; XkbDescRec field containing changed data: server->vmodmap[first_vmodmap_key] .. server->vmodmap[first_vmodmap_key + num_vmodmap_keys - 1]

πŸ’– RETURN VALUES πŸ’–

  • True β€” The XkbSetMap function returns True all components specified by which are present in the xkb parameter.
  • False β€” The XkbSetMap function returns False if any component specified by which is not present in the xkb parameter.

✨ STRUCTURES ✨

Okay so, bestie, use the XkbMapChangesRec structure to identify and track partial modifications to the mapping components β€” and to reduce the amount of traffic between the server and clients. It’s giving β€œlet’s not ship the whole keyboard over the wire every time” energy πŸ’…

typedef struct _XkbMapChanges {
    unsigned short   changed;            /* identifies valid components in structure */
    KeyCode          min_key_code;       /* lowest numbered keycode for device */
    KeyCode          max_key_code;       /* highest numbered keycode for device */
    unsigned char    first_type;         /* index of first key type modified */
    unsigned char    num_types;          /* # types modified */
    KeyCode          first_key_sym;      /* first key whose key_sym_map changed */
    unsigned char    num_key_syms;       /* # key_sym_map entries changed */
    KeyCode          first_key_act;      /* first key whose key_acts entry changed */
    unsigned char    num_key_acts;       /* # key_acts entries changed */
    KeyCode          first_key_behavior; /* first key whose behaviors changed */
    unsigned char    num_key_behaviors;  /* # behaviors entries changed */
    KeyCode          first_key_explicit; /* first key whose explicit entry changed */
    unsigned char    num_key_explicit;   /* # explicit entries changed */
    KeyCode          first_modmap_key;   /* first key whose modmap entry changed */
    unsigned char    num_modmap_keys;    /* # modmap entries changed */
    KeyCode          first_vmodmap_key;  /* first key whose vmodmap changed */
    unsigned char    num_vmodmap_keys;   /* # vmodmap entries changed */
    unsigned char    pad1;               /* reserved */
    unsigned short   vmods;              /* mask indicating which vmods changed */
} XkbMapChangesRec,*XkbMapChangesPtr;

The complete description of an Xkb keyboard is given by an XkbDescRec. The component structures in the XkbDescRec represent the major Xkb components. Iconic, honestly πŸ”₯

typedef struct {
   struct _XDisplay * display;      /* connection to X server */
   unsigned short     flags;        /* private to Xkb, do not modify */
   unsigned short     device_spec;  /* device of interest */
   KeyCode            min_key_code; /* minimum keycode for device */
   KeyCode            max_key_code; /* maximum keycode for device */
   XkbControlsPtr     ctrls;        /* controls */
   XkbServerMapPtr    server;       /* server keymap */
   XkbClientMapPtr    map;          /* client keymap */
   XkbIndicatorPtr    indicators;   /* indicator map */
   XkbNamesPtr        names;        /* names for all components */
   XkbCompatMapPtr    compat;       /* compatibility map */
   XkbGeometryPtr     geom;         /* physical geometry of keyboard */
} XkbDescRec, *XkbDescPtr;

The display field points to an X display structure. The flags field is private to the library: modifying flags may yield unpredictable results β€” so do not touch it, bestie, I am so serious 😭

The device_spec field specifies the device identifier of the keyboard input device, or XkbUseCoreKeyboard, which specifies the core keyboard device. The min_key_code and max_key_code fields specify the least and greatest keycode that can be returned by the keyboard. Slay.

Each structure component has a corresponding mask bit that is used in function calls to indicate that the structure should be manipulated in some manner, such as allocating it or freeing it. These masks and their relationships to the fields in the XkbDescRec are shown in Table 3.

πŸŽ€ Table 3 Mask Bits for XkbDescRec

  • XkbControlsMask β€” XkbDescRec field: ctrls, value: (1L<<0)
  • XkbServerMapMask β€” XkbDescRec field: server, value: (1L<<1)
  • XkbIClientMapMask β€” XkbDescRec field: map, value: (1L<<2)
  • XkbIndicatorMapMask β€” XkbDescRec field: indicators, value: (1L<<3)
  • XkbNamesMask β€” XkbDescRec field: names, value: (1L<<4)
  • XkbCompatMapMask β€” XkbDescRec field: compat, value: (1L<<5)
  • XkbGeometryMask β€” XkbDescRec field: geom, value: (1L<<6)
  • XkbAllComponentsMask β€” XkbDescRec field: All Fields, value: (0x7f)

πŸ’€ DIAGNOSTICS πŸ’€

  • BadAlloc β€” unable to allocate storage. The allocation said β€œnot today” πŸ™ˆ
  • BadLength β€” the length of a request is shorter or longer than that required to minimally contain the arguments. Bestie, the request length is doing too much or not enough 😭
  • BadValue β€” an argument is out of range. It’s giving β€œgirl, that value is not welcome here” πŸ’…

πŸ¦‹ SEE ALSO πŸ¦‹


Okay bestie, that’s the whole page πŸ’– The source/version is X Version 11, libX11 1.8.14, and the page is XkbSetMap(3). The footer didn’t show a date, so I’m not gonna invent one β€” no cap βœ¨πŸŽ€

πŸ“¦ where this page comes from