How to discover screen depth

Mike Khaw mkhaw at teknowledge-vaxc.arpa
Sun Dec 4 15:05:30 AEST 1988


>>>  Is there an easy way to find out the screen depth?
...
> There should be a better way to handle color 3/60's or other machines with
> two framebuffers correctly.   It currently reports monochrome.  Perhaps
> someone knows how to do it?

You can go through a lot of gyrations to open the root window's "screen"
and look at the bits for 8bit_color_only, or overlay_only, etc.  Or, if
you assume you are in suntools when you want to find out, it looks like a
simple program like this will do it:

<--- cut here --->
/*
 * fbdepth - works for cgfours under suntools.
 * compile with -lsuntool -lsunwindow -lpixrect
 */
#include <suntool/sunview.h>

main()
{
	Frame	base;
	Pixwin	*pw;

	if ((base = window_create(0, FRAME, WIN_SHOW, FALSE, 0)) == NULL)
	  {
		fprintf(stderr, "suntools not running!?\n");
		exit(1);
	  }
	pw = (Pixwin *) window_get(base, WIN_PIXWIN);
	printf("desktop bitplane depth = %d\n", pw->pw_pixrect->pr_depth);
	exit(0);
}
<--- cut here --->

This will return "1" if your have a monochrome frame buffer or are running
on the b&w desktop of a cgfour; otherwise it should return "8".

Now the more elaborate program that will work even if you're not running
under suntools.  This one returns "monochrome" or "color" if it can figure
it out, or "prism" if you have a cgfour and it can't tell which planes are
in use:

<--- cut here --->
/*
 * fbtype - compile with -lsunwindow -lpixrect
 */
#include <stdio.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/file.h>
#include <sun/fbio.h>
#include <sunwindow/window_hs.h>

main()
{
	int     fd;
	char	windevname[12];

	struct fbgattr	attr_buff;

	errno = 0;
	if ((fd = open("/dev/fb", O_RDONLY)) < 0)
		exit(errno);

	errno = 0;
	if (ioctl(fd, FBIOGATTR, &attr_buff) < 0)
		if (ioctl(fd, FBIOGTYPE, &attr_buff.fbtype) < 0)
			exit(errno);
	(void) close(fd);

	if (attr_buff.fbtype.fb_type != FBTYPE_SUN4COLOR)
		switch (attr_buff.fbtype.fb_depth)
		  {
		  case 1:
			printf("monochrome\n");
			break;

		  case 8:
			printf("color\n");
			break;

		  default:
			printf("unknown\n");
			break;
		  }
	else if (we_getparentwindow(windevname))
		printf("prism\n");	/* not in suntools? */
	else
	  {
		struct screen	screen;

		errno = 0;
		if ((fd = open(windevname)) < 0)
			exit(errno);

		win_screenget(fd, &screen);
		(void) close(fd);

		if (screen.scr_flags & SCR_8BITCOLORONLY)
			printf("color\n");
		else if (strncmp("/dev/bw", screen.scr_fbname, 7) == 0 ||
		  screen.scr_flags & SCR_OVERLAYONLY)
			printf("monochrome\n");
		else
			printf("prism\n");
	  }
	exit(0);
}
<--- cut here --->

Mike Khaw
-- 
internet: mkhaw at teknowledge.arpa
uucp:	  {uunet|sun|ucbvax|decwrl|ames|hplabs}!mkhaw%teknowledge.arpa
hardcopy: Teknowledge Inc, 1850 Embarcadero Rd, POB 10119, Palo Alto, CA 94303



More information about the Comp.sys.sun mailing list