Last active
August 29, 2015 14:05
-
-
Save sladen/833d4d23d89aa12e9dc8 to your computer and use it in GitHub Desktop.
XLookupColor() -> X11 RGB colour value example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Paul Sladen, 2014-08-13, Public Domain | |
XLookupColor() -> RGB colour value example, per request on | |
http://irclogs.ubuntu.com/2014/08/13/%23ubuntu-devel.html#t19:52 | |
grep MistyRose /usr/share/X11/rgb.txt | awk '{printf("%02x%02x%02x\n",$1,$2,$3);}' | |
http://manpages.ubuntu.com/manpages/man3/XQueryColor.3.html | |
gcc xlookupcolour.c -o xlookupcolour -lX11 && ./xlookupcolour red yellow blue | |
*/ | |
#include <stdio.h> | |
#include <X11/Xlib.h> | |
void main(int argc, char **argv) | |
{ | |
Display *dpy; | |
Colormap map; | |
int scr; | |
XColor rgb, nearest_rgb; | |
const char *fallback_colours[] = {"red", "white", "blue", "pink", NULL}; | |
dpy = XOpenDisplay(NULL); | |
scr = XDefaultScreen(dpy); | |
map = XDefaultColormap(dpy, scr); | |
if (argc < 2) | |
argv = (char**)fallback_colours; | |
for (argv++; *argv; argv++) | |
{ | |
XLookupColor(dpy, map, argv[0], &rgb, &nearest_rgb); | |
printf("%3d %3d %3d %s\n", rgb.red>>8, rgb.green>>8, rgb.blue>>8, argv[0]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment