garnett@ccwf.cc.utexas.edu (John Garnett) (12/12/90)
Contained below is a simple program to allow one to set the brightness of the NeXT screen from the command line. John Garnett, 12/12/90 --- cut here and feed to sh --- echo x - bright.c sed '1,$s/^X//' <<\!FUNKY!STUFF! > bright.c X/* X bright.c: written for the NeXT computer (using 1.0) X X general usage: bright [0-61] X X example usage: bright 52 X X purpose: dims the screen, waits for a carriage return, and then X resets display to original brightness. X X author: written by John W. Garnett on December 12, 1990 X X email: garnett@cs.utexas.edu X X compile using: cc bright.c -o dim X X relevant manual pages: evs and ioctl X X comments: yes, I know that preferences lets one set the autodim time X so that the screen will automatically dim after a certain period X of time. However, the degree of dimming that occurs is fixed at X 1/4 the current level which I don't think is dim enough. Ideally X there should be some way to control the degree of dimming that X automatically occurs. However, since there doesn't appear to be X any way to do so, I've written this hack. Do with it what you will. X If anyone knows the details of how to duplicate the way the X WindowServer handles the automatic dimming, please let me know X via email (garnett@cs.utexas.edu). X X disclaimer: no claims are made as to the suitability of this software for X any purpose. use at your own risk. X*/ X X#include <stdio.h> X#include <sys/fcntl.h> X#include <sys/ioctl.h> X#include <nextdev/evsio.h> X X#define EVS_DEVICE "/dev/evs0" X X/* open the event status device (see man page for evs) */ X Xint openEvs() X{ X int fd; X X fd = open(EVS_DEVICE,O_RDWR,0660); X if (fd < 0) { X fprintf(stderr,"error: couldn't open %s\n",EVS_DEVICE); X exit(2); X } X return(fd); X} X X/* return brightness level as integer value between 0 and 61 */ X Xunsigned long getBrightness() X{ X unsigned long original; X int fd; X X fd = openEvs(); X ioctl(fd,EVSIOCB,&original); X close(fd); X return(original); X} X X/* set brightness to level and return previous brightness */ X Xint setBrightness(level) Xunsigned long level; X{ X unsigned long original; X int fd; X X fd = openEvs(); X original = getBrightness(); X ioctl(fd,EVSIOSB,&level); X close(fd); X return(original); X} X Xint main(argc,argv) Xint argc; Xchar **argv; X{ X unsigned long request, original; X X if (argc != 2) { X fprintf(stderr,"usage: %s [0-61]\n",argv[0]); X exit(1); X } X sscanf(argv[1],"%lu",&request); X original = setBrightness(request); X getchar(); X setBrightness(original); X return(0); X} !FUNKY!STUFF! echo x - makefile sed '1,$s/^X//' <<\!FUNKY!STUFF! > makefile Xdim: bright.o X cc bright.o -o dim X Xbright.shar: bright.c makefile X shar bright.c makefile > bright.shar X Xall: dim bright.shar !FUNKY!STUFF!