How to discover screen depth?

Tim Hunt beareq!sun6!hunt at wheaties.ai.mit.edu
Tue Nov 29 21:35:16 AEST 1988


> I have 1-bit and 8-bit monitors hooked up to a Sun.  Is there an easy way
> to find out the screen depth (under Suntools) without creating a new
> window?

I have a small program that I use with shell scripts to determine both
screen size and depth. A shar file follows:

Tim Hunt
Fusion Systems Group, New York   (212)285-8001
sun!gotham!fusion!tim

#-----------------------------------------------------------------------
#!/bin/sh
#
#	This is a shell archive, meaning:
#
#	1. Remove everything above the #!/bin/sh line.
#	2. Save the resulting text in a file.
#	3. Execute the file with /bin/sh (not csh) to create:
#		fbtype.c
#
# This archive created: Wed Nov 16 09:27:14 EST 1988
shar: fbtype.c (1985 characters)
if [ -s fbtype.c ]
then
echo 'shar: fbtype.c already exists - not extracted'
else
echo 'shar: extracting fbtype.c (1985 characters)'
sed -n 's/^XX//p' > fbtype.c <<'*-*-END-of-fbtype.c-*-*'
XX#ifndef lint
XXstatic char *Sccsid="%W% %E% %U% (TIM HUNT)";
XX#endif
XX/***********************************************************************
XX
XX			%F%
XX
XX	Routines:
XX		main
XX
XX	Purpose:
XX		Print out the type and resolution of workstation.
XX
XX		usage:	fbtype [-s] [/dev/device]
XX
XX		-s	Prints out values in a form suitable for using
XX			with shell eval commands.
XX
XX	History:
XX
XX***********************************************************************/
XX#include <stdio.h>
XX
XX#include <fcntl.h>
XX
XX#include <sys/ioctl.h>
XX#include <sun/fbio.h>
XX
XXmain(argc,argv)
XXint	argc;
XXchar	**argv;
XX{
XX	char	*device = "/dev/fb";
XX
XX	char	*type;
XX
XX	/* Output format without the "-s" option */
XX
XX	char	*fmt = "%s %d %d %d %d\n";
XX
XX	int	fd;
XX
XX	struct	fbtype fb, *realfb;
XX	struct	fbgattr fba;
XX
XX	if ( argc > 1 ) {
XX		if ( strcmp(argv[1],"-s") == 0 ) {
XX			argv++;
XX			argc--;
XX
XX			/* Format for Bourne shell and derivatives */
XX
XX			fmt = "FB_TYPE='%s';\nFB_HEIGHT=%d;\nFB_WIDTH=%d;\nFB_DEPTH=%d;\nFB_CMSIZE=%d;\n";
XX
XX			/* Handle C-Shell and derivatives */
XX
XX			if ( strcmp("/bin/csh",getenv("SHELL")) == 0 
XX			  || strcmp("/bin/tcsh",getenv("SHELL")) == 0 )
XX				fmt = "set fb_type='%s';\n@ fb_height=%d;\n@ fb_width=%d;\n@ fb_depth=%d;\n@ fb_cmsize=%d;\n";
XX
XX		}
XX		if ( argc > 1 )
XX			device = argv[1];
XX	}
XX
XX	if ( (fd = open(device,O_WRONLY)) < 0 ) {
XX		perror(device);
XX		exit(1);
XX	}
XX
XX	bzero((char *)(&fb),sizeof fb);
XX	if ( ioctl(fd,FBIOGTYPE,&fb) < 0 ) {
XX		perror(device);
XX		exit(1);
XX	}
XX	bzero((char *)(&fba),sizeof fba);
XX	if ( ioctl(fd,FBIOGATTR,&fba) < 0 ) {
XX		realfb = &fb;
XX	} else {
XX		realfb = &(fba.fbtype);
XX	}
XX
XX	close (fd);
XX
XX	switch ( realfb->fb_type ) {
XX	case FBTYPE_SUN1BW:
XX	case FBTYPE_SUN2BW:
XX	case FBTYPE_SUN3BW:
XX		type = "bw";
XX		break;
XX	case FBTYPE_SUN1COLOR:
XX	case FBTYPE_SUN2COLOR:
XX	case FBTYPE_SUN3COLOR:
XX	case FBTYPE_SUN4COLOR:
XX		type = "color";
XX		break;
XX	case FBTYPE_SUN2GP:
XX		type = "gp";
XX		break;
XX	default:
XX		type = "undef";
XX		break;
XX	}
XX
XX	printf(fmt,type,realfb->fb_height,realfb->fb_width,realfb->fb_depth,realfb->fb_cmsize);
XX}
*-*-END-of-fbtype.c-*-*
if [ ` wc -w < fbtype.c ` != 238 ]
then
echo 'shar: warning possible error in fbtype.c'
fi
fi



More information about the Comp.sys.sun mailing list