Exemplo n.º 1
0
Bool
fixedColors(ModeInfo * mi)
{
	Bool        temp;

#ifdef FORCEFIXEDCOLORS
	/* pretending a fixed colourmap */
	return TRUE;
#else
	/* get information about the default visual */
	temp = (!((MI_NPIXELS(mi) > 2) &&
		  (MI_VISUALCLASS(mi) != StaticGray) &&
		  (MI_VISUALCLASS(mi) != StaticColor) &&
		  (MI_VISUALCLASS(mi) != TrueColor) &&
#if 0
/*-
 * This may fix wrong colors (possibly unreadable text) in password window
 */
		  !MI_IS_ICONIC(mi) &&
#endif
		  !MI_IS_INROOT(mi) &&
		  MI_IS_INSTALL(mi)));
#endif
	if (debug) {
		(void) printf("%s colors on screen %d\n", (temp) ? "fixed" : "writeable",
			      MI_SCREEN(mi));
	}
	return temp;
}
Exemplo n.º 2
0
/* has_writeable was hacked out of xscreensaver and modified for xlockmore
 * by Jouk Jansen <*****@*****.**>
 *
 * xscreensaver, Copyright (c) 1993, 1994, 1995, 1996, 1997, 1998
 *  by Jamie Zawinski <*****@*****.**>
 *
 * Permission to use, copy, modify, distribute, and sell this software and its
 * documentation for any purpose is hereby granted without fee, provided that
 * the above copyright notice appear in all copies and that both that
 * copyright notice and this permission notice appear in supporting
 * documentation.  No representations are made about the suitability of this
 * software for any purpose.  It is provided "as is" without express or
 * implied warranty.
 */
Bool
has_writable_cells(ModeInfo * mi)
{
	switch (MI_VISUALCLASS(mi)) {
		case GrayScale:	/* Mappable grays. */
		case PseudoColor:	/* Mappable colors. */
		case DirectColor:	/* DirectColor visuals are like TrueColor, but have
					   three colormaps - one for each component of RGB. */
			return True;
		case StaticGray:	/* Fixed grays. */
		case TrueColor:	/* Fixed colors. */
		case StaticColor:	/* (What's the difference again?) */
			return False;
		default:
			abort();
	}
	return False;
}
Exemplo n.º 3
0
Bool
setupColormap(ModeInfo * mi, int *colors, Bool * truecolor,
unsigned long *red_mask, unsigned long *blue_mask, unsigned long *green_mask)
{
	/* how many colours are there altogether? */
	*colors = MI_NPIXELS(mi);
	if (*colors > MI_COLORMAP_SIZE(mi)) {
		*colors = MI_COLORMAP_SIZE(mi);
	}
	if (*colors < 2)
		*colors = 2;

	*truecolor = (MI_VISUALCLASS(mi) == TrueColor);

	*red_mask = MI_RED_MASK(mi);
	*green_mask = MI_GREEN_MASK(mi);
	*blue_mask = MI_BLUE_MASK(mi);

	return !fixedColors(mi);
}
Exemplo n.º 4
0
void
fixColormap(ModeInfo * mi, int ncolors, float saturation,
	    Bool mono, Bool install, Bool inroot, Bool inwindow, Bool verbose)
{
	Display    *display = MI_DISPLAY(mi);
	Window     window = MI_WINDOW(mi);
	Screen     *scr = MI_SCREENPTR(mi);
	Colormap    cmap = MI_COLORMAP(mi);
	Colormap    dcmap = DefaultColormapOfScreen(scr);
	XColor      xcolor;
	unsigned char *red = (unsigned char *) NULL,
		*green = (unsigned char *) NULL,
		*blue = (unsigned char *) NULL;
	int         colorcount, i, fixed, visualclass;

#ifndef COMPLIANT_COLORMAP
	Bool        retry = False;

#endif

	if (mono || CellsOfScreen(scr) <= 2) {
		if (MI_PIXELS(mi))
			return;
		if ((MI_PIXELS(mi) = (unsigned long *) calloc(2,
				sizeof (unsigned long))) == NULL) {
			(void) fprintf(stderr, "could not get the 2 colors for mono\n");
		}

		monoColormap(scr, MI_SCREENINFO(mi), foreground, background);
		return;
	}
	colorcount = ncolors;
	if (((  red = (unsigned char *) calloc(ncolors,
			sizeof (unsigned char))) == NULL) ||
	    ((green = (unsigned char *) calloc(ncolors,
			sizeof (unsigned char))) == NULL) ||
	    (( blue = (unsigned char *) calloc(ncolors,
			sizeof (unsigned char))) == NULL)) {
		(void) fprintf(stderr, "could not get the %d colors\n", ncolors);
		if (red != NULL)
			free(red);
		if (green != NULL)
			free(green);
		return;
	}

	visualclass = MI_VISUALCLASS(mi);
	fixed = (visualclass == StaticGray) || (visualclass == StaticColor) ||
		(visualclass == TrueColor);
	if (
#ifdef USE_DTSAVER
		   dtsaver ||	/* needs to be in focus without mouse */

#endif
		   inroot || (!install && !fixed) || cmap == None) {
		cmap = dcmap;
	}
	if (cmap != dcmap && MI_PIXELS(mi)) {
		XFreeColors(display, cmap, MI_PIXELS(mi), MI_NPIXELS(mi), 0);
#ifndef COMPLIANT_COLORMAP
		XFreeColors(display, cmap, &(MI_BLACK_PIXEL(mi)), 1, 0);
		XFreeColors(display, cmap, &(MI_WHITE_PIXEL(mi)), 1, 0);
#endif
		XFreeColors(display, cmap, &(MI_BG_PIXEL(mi)), 1, 0);
		XFreeColors(display, cmap, &(MI_FG_PIXEL(mi)), 1, 0);
	}
	/* else if (cmap) { (void) printf("cmap: this case is possible?\n");  } */
	if (MI_PIXELS(mi))
		free(MI_PIXELS(mi));
	if ((MI_PIXELS(mi) = (unsigned long *) calloc(ncolors,
			sizeof (unsigned long))) == NULL) {
		(void) fprintf(stderr, "could not get the %d colors\n", ncolors);
	}
	/* "allocate" the black and white pixels, so that they
	   will be included by XCopyColormapAndFree() if it gets called */
#ifdef COMPLIANT_COLORMAP
	MI_BLACK_PIXEL(mi) = BlackPixelOfScreen(scr);
	MI_WHITE_PIXEL(mi) = WhitePixelOfScreen(scr);
#else
	MI_BLACK_PIXEL(mi) = allocPixel(display, cmap, "Black", "Black");
	MI_WHITE_PIXEL(mi) = allocPixel(display, cmap, "White", "White");
#endif
	MI_BG_PIXEL(mi) = allocPixel(display, cmap, background, "White");
	MI_FG_PIXEL(mi) = allocPixel(display, cmap, foreground, "Black");
	hsbramp(0.0, saturation, 1.0, 1.0, saturation, 1.0, colorcount,
		red, green, blue);

	MI_NPIXELS(mi) = 0;
	for (i = 0; i < colorcount; i++) {
		xcolor.red = red[i] << 8;
		xcolor.green = green[i] << 8;
		xcolor.blue = blue[i] << 8;
		xcolor.flags = DoRed | DoGreen | DoBlue;

		if (!XAllocColor(display, cmap, &xcolor)) {
#ifdef COMPLIANT_COLORMAP
			if (!install || cmap != dcmap)
				break;
			if ((cmap = XCopyColormapAndFree(display, cmap)) == dcmap)
				break;
			if (verbose)
				(void) fprintf(stderr, "using private colormap\n");
			if (!XAllocColor(display, cmap, &xcolor))
				break;
#else
			if (verbose)
				(void) fprintf(stderr, "ran out of colors on colormap\n");
			if ((saturation != 1.0 || ncolors != 64) && MI_NPIXELS(mi) < 2) {
				if (verbose)
					(void) fprintf(stderr,
						       "retrying with saturation = 1.0 and ncolors = 64\n");
				retry = True;
			}
			break;
#endif
		}
		MI_PIXELS(mi)[i] = xcolor.pixel;
		MI_NPIXELS(mi)++;
	}
	free(red);
	free(green);
	free(blue);
	if (verbose)
		(void) fprintf(stderr, "%d pixel%s allocated\n", MI_NPIXELS(mi),
			       (MI_NPIXELS(mi) == 1) ? "" : "s");
	if (MI_NPIXELS(mi) <= 4) {
		XFreeColors(display, cmap, MI_PIXELS(mi), MI_NPIXELS(mi), 0);
#ifndef COMPLIANT_COLORMAP
		XFreeColors(display, cmap, &(MI_BLACK_PIXEL(mi)), 1, 0);
		XFreeColors(display, cmap, &(MI_WHITE_PIXEL(mi) ), 1, 0);
#endif
		XFreeColors(display, cmap, &(MI_BG_PIXEL(mi)), 1, 0);
		XFreeColors(display, cmap, &(MI_FG_PIXEL(mi)), 1, 0);
#ifndef COMPLIANT_COLORMAP
		if (retry) {
			fixColormap(mi, 64, 1.0,
				    mono, install, inroot, inwindow, verbose);
			return;
		}
#endif
		monoColormap(scr, MI_SCREENINFO(mi), foreground, background);
		MI_COLORMAP(mi) = cmap = DefaultColormapOfScreen(scr);
		return;
	}
	MI_COLORMAP(mi) = cmap;
	if ((install || fixed) && !inroot && MI_NPIXELS(mi) > 2) {
#if 0
		(void) XGetWindowAttributes(display, window, &xgwa);
		if (cmap != xgwa.colormap)
#endif
#if 1				/* Turn off to simulate fvwm and tvwm */
			setColormap(display, window, cmap, inwindow);
#endif
	}
#if 0
	else {
		/* white and black colors may not be right for GL modes so lets set them */
		MI_BLACK_PIXEL(mi) = BlackPixelOfScreen(scr);
		MI_WHITE_PIXEL(mi) = WhitePixelOfScreen(scr);
		/* foreground and background colors may not be right.... */
		BlackPixelOfScreen(scr) = MI_BLACK_PIXEL(mi);
		WhitePixelOfScreen(scr) = MI_WHITE_PIXEL(mi);
	}
#endif
}