home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / alt / sources / 2880 < prev    next >
Encoding:
Text File  |  1992-12-23  |  3.3 KB  |  91 lines

  1. Newsgroups: alt.sources
  2. Path: sparky!uunet!stanford.edu!nntp.Stanford.EDU!eillihca@grizzle.Stanford.EDU
  3. From: eillihca@drizzle.StanFord.EDU ( Achille Hui, the Day Dreamer )
  4. Subject: Re: Binary clock for X Windows.
  5. Message-ID: <eillihca.92122318162010574@grizzle.Stanford.EDU>
  6. Sender: ?@leland.Stanford.EDU
  7. X-Transfer-Agent: nntp.stanford.edu (NNTP)
  8. Organization: Dept. of Physics, Stanford University.
  9. Date: 24 Dec 92 02:16:20 GMT
  10. Lines: 79
  11.  
  12. markus@octavia.anu.edu.au (Markus Buchhorn) writes: 
  13.  
  14. >
  15. >doug@jhunix.hcf.jhu.edu (Douglas W O'Neal) and norm@bnr.ca and 
  16. >bret@muppet.bt.co.uk (Bret Giddings) all wrote
  17. >>
  18. >> ->|> What! another clock for wimps. I use a real clock, one that displa...
  19. >> ->|> of seconds since Jan 1st 1970.
  20. >> ->This is starting to sound like the "We were *so* poor..." skit from M...
  21. >> ->Python.  BTW, (let's see what I can come up with), *I* use the number...
  22. >> ->since Jan 1, 1970 but in Greenwich Mean Time :-)
  23. >> 
  24. >> *I* use the number of seconds since Nov 17, 1858.  (I can't help it, I ...
  25. >> raised on VMS and UN*X time doesn't come naturally to me.)
  26. >> 
  27. >
  28. >
  29. >Ye gods - it must be the silly season, otherwise I would NEVER followup :-)
  30. >
  31. Yup, it is a silly season and I can't stand people bragging about
  32. their vapourware. Here is the ObSource of my clock with milli-second
  33. resolution. What? you don't know how to interpret the time? It works
  34. fine for me ;-)
  35. ------------------------------------achille (eillihca@drizzle.stanford.edu)
  36. #include <X11/Intrinsic.h>
  37. #include <X11/StringDefs.h>
  38. #include <X11/Xmu/Drawing.h>
  39. #include <sys/time.h>
  40. unsigned long pixels[2];
  41. XColor          colors[2];
  42. int          delay = 666;
  43. int
  44. updateit(Widget widget,XtIntervalId *id){
  45.     struct    timeval               tv;
  46.     struct    timezone    tz;
  47.     int        tmp, r0, g0, b0, r1, g1, b1;
  48.     gettimeofday(&tv,&tz);
  49.     tmp    =  tv.tv_usec / 250;
  50.     r0    =  (tmp & (0x3<<10))>>4;    r1  = (tmp & (0x3<<4))<<2;
  51.     g0    =  (tmp & (0x3<<8))>>2;        g1  = (tmp & (0x3<<2))<<4;
  52.     b0    =  (tmp & (0x3<<6));        b1  = (tmp & (0x3))<<6;
  53.     tmp    =  tv.tv_sec;
  54.     r0 |=  (tmp & (0x1f<<25))>>24;    r1 |= (tmp & (0x1f<<10))>>9;
  55.     g0 |=  (tmp & (0x1f<<20))>>19;    g1 |= (tmp & (0x1f<<5))>>4;
  56.     b0 |=  (tmp & (0x1f<<15))>>14;    b1 |= (tmp & (0x1f))<<1;
  57.     colors[0].red   = (r0<<8)|r0;       colors[1].red   = (r1<<8)|r1;
  58.     colors[0].green = (g0<<8)|g0;       colors[1].green = (g1<<8)|g1;
  59.     colors[0].blue  = (b0<<8)|b0;       colors[1].blue  = (b1<<8)|b1;
  60.     XStoreColors(XtDisplay(widget),DefaultColormapOfScreen(XtScreen(widget)),
  61.          colors,2);
  62.     XtAddTimeOut(delay,updateit,widget);
  63. }
  64. main(int argc,char *argv[]){
  65.     Widget   stupid = XtInitialize(NULL,"Stupid",NULL,0,&argc,argv);
  66.     argc--; argv++;
  67.     if((argc-- > 0) && (((delay = atoi(*argv++))<= 4)||(delay > 10000)))
  68.     delay = 666;
  69.     XAllocColorCells(XtDisplay(stupid),
  70.              DefaultColormapOfScreen(XtScreen(stupid)),
  71.              False,0,0,pixels,2);
  72.     colors[0].flags = colors[1].flags = DoRed|DoGreen|DoBlue;
  73.     colors[0].pixel = pixels[0]; colors[1].pixel = pixels[1];
  74.     XSetWindowBackgroundPixmap(
  75.         XtDisplay(stupid),RootWindowOfScreen(XtScreen(stupid)),
  76.     XmuCreateStippledPixmap(XtScreen(stupid),pixels[0],pixels[1],
  77.                    DefaultDepthOfScreen(XtScreen(stupid))));
  78.     XClearWindow(XtDisplay(stupid),
  79.          RootWindowOfScreen(XtScreen(stupid)));
  80.     updateit(stupid,(XtIntervalId *)0);
  81.     XtMainLoop();
  82. }
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.