/usr/share/doc/xviewg/examples/color/color.c is in xview-examples 3.2p1.4-28.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | #include <X11/Xlib.h>
#include <X11/Xutil.h>
main(argc, argv)
char *argv[];
{
Display *display;
int screen;
XSizeHints sizehints;
Window window;
XEvent event;
XButtonEvent *button;
XColormapEvent *colormap;
short i;
int done = 0;
Colormap cmap, orig_cmap;
XVisualInfo vTemplate, *visualList;
int visualsMatched;
Visual *visual;
XSetWindowAttributes atts;
XColor color;
display = XOpenDisplay("");
screen = DefaultScreen ( display );
window = XDefaultRootWindow(display);
vTemplate.screen = screen;
vTemplate.depth = 8;
vTemplate.class = PseudoColor;
visualList = XGetVisualInfo(display,
VisualScreenMask|VisualClassMask|VisualDepthMask,
&vTemplate, &visualsMatched);
if ( visualsMatched == 0 ) {
puts("visual not found, using default");
visual = DefaultVisual( display, screen );
} else {
printf("found %d visuals\n", visualsMatched);
visual = visualList[0].visual;
}
sizehints.x = 200;
sizehints.y = 0;
sizehints.width = sizehints.height = 150;
sizehints.flags = USSize | USPosition;
cmap = XCreateColormap( display,window, visual, AllocAll);
orig_cmap = DefaultColormap(display, DefaultScreen(display));
atts.colormap = cmap;
window = XCreateWindow(display,DefaultRootWindow(display),
sizehints.x, sizehints.y, sizehints.width, sizehints.height,
0, 8, InputOutput, visual, CWColormap, &atts);
XSetStandardProperties(display, window, argv[0],
argv[0], None, argv, 1, &sizehints);
color.flags = DoRed|DoGreen|DoBlue;
srand(time(0));
printf("Allocating %d colors\n", visual->map_entries);
for (color.pixel=0; color.pixel < visual->map_entries; color.pixel++) {
color.red = rand()%65536;
color.green = rand()%65536;
color.blue = rand()%65536;
XStoreColor ( display, cmap, &color );
}
/* while (visualsMatched > 0)
XFree(visualList[--visualsMatched]);
*/
XFree((char *)visualList);
/* Now that the screen is defined, select inputs and get them */
XSelectInput(display, window, ButtonPressMask | ColormapChangeMask);
XMapWindow(display, window);
do {
XNextEvent ( display, &event );
switch (event.type) {
case ButtonPress:
printf ("********* Found ButtonPress event ********\n");
button = (XButtonEvent *) &event;
printf ("button is %d\n", button->button );
if (button->button == 3)
done = -1;
break;
case ColormapNotify:
printf ("********* Found ColormapNotify event ********\n");
colormap = (XColormapEvent *) &event;
if ( colormap->state == ColormapInstalled )
printf ("Colormap has been installed\n");
else
printf ("Colormap has been uninstalled\n");
printf ("Colormap is %d\n", colormap->colormap );
printf ("Associated window is %d\n", colormap->window );
}
} while (!done);
XCloseDisplay(display);
}
|