home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2267 < prev    next >
Internet Message Format  |  1990-12-28  |  3KB

  1. From: garnett@ccwf.cc.utexas.edu (John Garnett)
  2. Newsgroups: alt.sources
  3. Subject: dim: NeXT Screen dimmer (not automatic)
  4. Message-ID: <41238@ut-emx.uucp>
  5. Date: 12 Dec 90 12:23:24 GMT
  6.  
  7. Contained below is a simple program to allow one to set the
  8. brightness of the NeXT screen from the command line.
  9.  
  10. John Garnett, 12/12/90
  11.  
  12. --- cut here and feed to sh ---
  13. echo x - bright.c
  14. sed '1,$s/^X//' <<\!FUNKY!STUFF! > bright.c
  15. X/* 
  16. X   bright.c: written for the NeXT computer (using 1.0)
  17. X
  18. X   general usage: bright [0-61]
  19. X
  20. X   example usage: bright 52
  21. X
  22. X   purpose: dims the screen, waits for a carriage return, and then
  23. X            resets display to original brightness.
  24. X
  25. X   author: written by John W. Garnett on December 12, 1990
  26. X
  27. X   email: garnett@cs.utexas.edu
  28. X
  29. X   compile using: cc bright.c -o dim
  30. X
  31. X   relevant manual pages: evs and ioctl
  32. X
  33. X   comments: yes, I know that preferences lets one set the autodim time
  34. X     so that the screen will automatically dim after a certain period
  35. X     of time.  However, the degree of dimming that occurs is fixed at
  36. X     1/4 the current level which I don't think is dim enough.  Ideally
  37. X     there should be some way to control the degree of dimming that
  38. X     automatically occurs.  However, since there doesn't appear to be
  39. X     any way to do so, I've written this hack.  Do with it what you will.
  40. X     If anyone knows the details of how to duplicate the way the
  41. X     WindowServer handles the automatic dimming, please let me know
  42. X     via email (garnett@cs.utexas.edu).
  43. X
  44. X   disclaimer: no claims are made as to the suitability of this software for
  45. X     any purpose.  use at your own risk.
  46. X*/
  47. X
  48. X#include <stdio.h>
  49. X#include <sys/fcntl.h>
  50. X#include <sys/ioctl.h>
  51. X#include <nextdev/evsio.h>
  52. X
  53. X#define EVS_DEVICE "/dev/evs0"
  54. X
  55. X/* open the event status device (see man page for evs) */
  56. X
  57. Xint openEvs()
  58. X{
  59. X    int fd;
  60. X
  61. X    fd = open(EVS_DEVICE,O_RDWR,0660);
  62. X    if (fd < 0) {
  63. X        fprintf(stderr,"error: couldn't open %s\n",EVS_DEVICE);
  64. X        exit(2);
  65. X    }
  66. X    return(fd);
  67. X}
  68. X
  69. X/* return brightness level as integer value between 0 and 61 */
  70. X
  71. Xunsigned long getBrightness()
  72. X{
  73. X    unsigned long original;
  74. X    int fd;
  75. X
  76. X    fd = openEvs();
  77. X    ioctl(fd,EVSIOCB,&original);
  78. X    close(fd);
  79. X    return(original);
  80. X}
  81. X
  82. X/* set brightness to level and return previous brightness */
  83. X
  84. Xint setBrightness(level)
  85. Xunsigned long level;
  86. X{
  87. X    unsigned long original;
  88. X    int fd;
  89. X
  90. X    fd = openEvs();
  91. X    original = getBrightness();
  92. X    ioctl(fd,EVSIOSB,&level);
  93. X    close(fd);
  94. X    return(original);
  95. X}
  96. X
  97. Xint main(argc,argv)
  98. Xint argc;
  99. Xchar **argv;
  100. X{
  101. X    unsigned long request, original;
  102. X
  103. X    if (argc != 2) {
  104. X        fprintf(stderr,"usage: %s [0-61]\n",argv[0]);
  105. X        exit(1);
  106. X    }
  107. X    sscanf(argv[1],"%lu",&request);
  108. X    original = setBrightness(request);
  109. X    getchar();
  110. X    setBrightness(original);
  111. X    return(0);
  112. X}
  113. !FUNKY!STUFF!
  114. echo x - makefile
  115. sed '1,$s/^X//' <<\!FUNKY!STUFF! > makefile
  116. Xdim: bright.o
  117. X    cc bright.o -o dim
  118. X
  119. Xbright.shar: bright.c makefile
  120. X    shar bright.c makefile > bright.shar
  121. X
  122. Xall: dim bright.shar
  123. !FUNKY!STUFF!
  124.