XColormapEvent(3)

πŸ’– XColormapEvent(3) β€” bestie's guide to the ColormapNotify event πŸ’–

okay so this is a page straight out of the XLIB FUNCTIONS section of the Xlib manual, and it's lowkey one of the cutest little event structs. it's giving "small but knows everything about your colormap" energy. let's get into it 🫢


✨ NAME ✨

XColormapEvent β€” the ColormapNotify event structure. that's it, that's the whole vibe πŸ’…


πŸŽ€ STRUCTURES πŸŽ€

so the structure for ColormapNotify events contains this, and yes you're gonna want to screenshot it bestie:

typedef struct {
        int type;       /* ColormapNotify */
        unsigned long serial;   /* # of last request processed by server */
        Bool send_event;        /* true if this came from a SendEvent request */
        Display *display;       /* Display the event was read from */
        Window window;
        Colormap colormap;      /* colormap or None */
        Bool new;
        int state;      /* ColormapInstalled, ColormapUninstalled */
} XColormapEvent;

when you receive this event, the structure members get set like this. buckle up, we're going field by field 🌸


🌈 the members, one at a time

the type member is set to the event type constant name that uniquely identifies it. like, for example, when the X server reports a GraphicsExpose event to a client application, it sends an XGraphicsExposeEvent structure with the type member set to GraphicsExpose. see how that works? iconic behavior honestly ✨

the display member is set to a pointer to the display the event was read on. where you at, bb πŸ¦‹

the send_event member is set to True if the event came from a SendEvent protocol request. so if it's True, somebody synthesised it, no cap.

the serial member is set from the serial number reported in the protocol β€” but it gets expanded from the 16-bit least-significant bits to a full 32-bit value. glow-up of the century honestly 😭

the window member is set to the window that is most useful to toolkit dispatchers. teamwork makes the dream work πŸ’œ


🧚 the window / colormap lore (yes there's more)

the window member is set to the window whose associated colormap is changed, installed, or uninstalled. all three, she does it all πŸ‘‘

for a colormap that is changed, installed, or uninstalled, the colormap member is set to the colormap associated with the window. but β€” and this is the plot twist β€” for a colormap that is changed by a call to XFreeColormap, the colormap member is set to None. gone, reduced to atoms πŸ’€

the new member is set to indicate whether the colormap for the specified window was changed or installed or uninstalled, and it can be True or False:

  • True β€” the colormap was changed ✨
  • False β€” the colormap was installed or uninstalled πŸŽ€
ngl, read that True/False thing twice, because False covers both install and uninstall β€” it's not just "not changed", bestie. the state member is what actually tells you which one.

the state member is always set to indicate whether the colormap is installed or uninstalled, and it can be ColormapInstalled or ColormapUninstalled. always. no exceptions. periodt πŸ’…


πŸ’« SEE ALSO πŸ’«

the whole friend group, fr fr β€” go read these too or you're missing out:

and of course, the mothership herself: Xlib - C Language X Interface πŸ“šπŸ’–


πŸ’€ one more vibe check: colormap can literally be None, so pls don't go dereferencing it without checking, bestie. i'm looking out for you.

okay that's the whole page!! this cutie is from X Version 11, specifically libX11 1.8.14 β€” go forth and handle your colormap events with main character energy, i'm obsessed with you, mwah πŸŽ€πŸ’–πŸ¦‹

πŸ“¦ where this page comes from