XQueryColor(3)
π XQueryColor(3) β bestie, let's talk colors π
okay so this whole page is from the XLIB FUNCTIONS manual, and it is literally about obtaining color values from X. it's giving βI just need to know what RGB this pixel isβ energy, and honestly? iconic. π
π NAME π
XQueryColor, XQueryColors, XLookupColor, and XParseColor β obtain color values. periodt. π
π SYNTAX π
int XQueryColor(Display *display, Colormap colormap, XColor
*def_in_out);
int XQueryColors(Display *display, Colormap colormap, XColor
defs_in_out[], int ncolors);
Status XLookupColor(Display *display, Colormap colormap, _Xconst char
*color_name, XColor *exact_def_return, XColor
*screen_def_return);
Status XParseColor(Display *display, Colormap colormap, _Xconst char
*spec, XColor *exact_def_return);
π«Ά ARGUMENTS π«Ά
colormapβ specifies the colormap. yes bestie, that one. π¨color_nameβ specifies the color name string (for example,red) whose color definition structure you want returned. very βjust tell me the name and Iβll get the structureβ of it all. πdef_in_outβ specifies and returns the RGB values for the pixel specified in the structure. it goes in, it comes out, itβs literally in the name. π«defs_in_outβ specifies and returns an array of color definition structures for the pixel specified in the structure. plural era. β¨displayβ specifies the connection to the X server. the main-character connection, if you will. πexact_def_returnβ returns the exact RGB values. precise queen. πncolorsβ specifies the number ofXColorstructures in the color definition array. count βem. π’screen_def_returnβ returns the closest RGB values provided by the hardware. close enough is still cute. π«Άspecβ specifies the color name string; case is ignored. soRED,red, andReDare all valid, no cap. πexact_def_returnβ yep, itβs listed again: returns the exact color value for later use and sets theDoRed,DoGreen, andDoBlueflags. flags are getting set, bestie. π©
β¨ DESCRIPTION β¨
So XQueryColor returns the current RGB value for the pixel in the XColor structure, and it sets the DoRed, DoGreen, and DoBlue flags. very βhereβs your pixelβs current vibe, and also these three flags are now on.β π
XQueryColors does the same thing for each pixel in each XColor structure and sets the DoRed, DoGreen, and DoBlue flags in each structure. itβs the group-chat version: every structure gets the update. π¬
XQueryColor and XQueryColors can generate BadColor and BadValue errors. so likeβ¦ behave with your colormaps and numeric values, bestie. π
The XLookupColor function looks up the string name of a color with respect to the screen associated with the specified colormap. it returns both the exact color values and the closest values provided by the screen with respect to the visual type of the specified colormap. so you get the exact tea and the hardwareβs best approximation. π«β¨
If the color name is not in the Host Portable Character Encoding, the result is implementation-dependent. use of uppercase or lowercase does not matter. XLookupColor returns nonzero if the name is resolved; otherwise, it returns zero. simple as that. π
The XParseColor function looks up the string name of a color with respect to the screen associated with the specified colormap. it returns the exact color value. again: if the color name is not in the Host Portable Character Encoding, the result is implementation-dependent, and use of uppercase or lowercase does not matter. XParseColor returns nonzero if the name is resolved; otherwise, it returns zero. π―
XLookupColor and XParseColor can generate BadColor error. singular error, still a moment. π
π COLOR NAMES π
An RGB Device specification is identified by the prefix rgb: and conforms to the following syntax:
rgb:<red>/<green>/<blue>
<red>, <green>, <blue> := h | hh | hhh | hhhh
h := single hexadecimal digits (case insignificant)
Note that h indicates the value scaled in 4 bits, hh the value scaled in 8 bits, hhh the value scaled in 12 bits, and hhhh the value scaled in 16 bits, respectively. bit-scaling lore. π§
bestie, for backward compatibility, an older syntax for RGB Device is supported, but its continued use is not encouraged. itβs giving βwe keep it around, but please donβt make it your whole personality.β π
The syntax is an initial sharp sign character followed by a numeric specification, in one of the following formats:
#RGB (4 bits each)
#RRGGBB (8 bits each)
#RRRGGGBBB (12 bits each)
#RRRRGGGGBBBB (16 bits each)
The R, G, and B represent single hexadecimal digits. when fewer than 16 bits each are specified, they represent the most significant bits of the value (unlike the rgb: syntax, in which values are scaled). for example, the string #3a7 is the same as #3000a0007000. math ate. π₯
An RGB intensity specification is identified by the prefix rgbi: and conforms to the following syntax:
rgbi:<red>/<green>/<blue>
Note that red, green, and blue are floating-point values between 0.0 and 1.0, inclusive. the input format for these values is an optional sign, a string of numbers possibly containing a decimal point, and an optional exponent field containing an E or e followed by a possibly signed integer string. floating-point realness. π
The standard device-independent string specifications have the following syntax:
CIEXYZ:<X>/<Y>/<Z>
CIEuvY:<u>/<v>/<Y>
CIExyY:<x>/<y>/<Y>
CIELab:<L>/<a>/<b>
CIELuv:<L>/<u>/<v>
TekHVC:<H>/<V>/<C>
All of the values (C, H, V, X, Y, Z, a, b, u, v, y, x) are floating-point values. the syntax for these values is an optional plus or minus sign, a string of digits possibly containing a decimal point, and an optional exponent field consisting of an E or e followed by an optional plus or minus followed by a string of digits. very βscientific notation but make it color.β π§ͺπ
π DIAGNOSTICS π
BadColorβ a value for aColormapargument does not name a definedColormap. that colormap is not giving what it needs to give. π¬BadValueβ some numeric value falls outside the range of values accepted by the request. unless a specific range is specified for an argument, the full range defined by the argument's type is accepted. any argument defined as a set of alternatives can generate this error. so yeah, check your numbers, bestie. π¨
π¦ SEE ALSO π¦
XAllocColor(3)XCreateColormap(3)XStoreColors(3)Xlib - C Language X Interface
mwah π β this page is from X Version 11, libX11 1.8.14, and thatβs the footer tea. π«Άβ¨
π¦ where this page comes from
- alpine 3.24: libx11-doc 1.8.14-r0 Β· X11
- arch rolling: libx11 1.8.14-1 Β· MIT AND X11
- nixos 26.05: libx11 1.8.14
- nixpkgs unstable: libx11 1.8.14
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms