From http://www.jwz.org/xscreensaver/xscreensaver-5.37.tar.gz
[xscreensaver] / hacks / xanalogtv.c
index 589d475cd26942edeceead53bd2e05f6972c135a..d1f3e1b707c5cb583de6704763d0c872c6efbd10 100644 (file)
@@ -34,7 +34,7 @@
 # include <unistd.h>
 #endif
 
-#ifndef HAVE_COCOA
+#ifndef HAVE_JWXYZ
 # include <X11/Intrinsic.h> /* for XtDatabase in hack_resources() */
 #endif
 
@@ -82,7 +82,7 @@ struct state {
   chansetting *cs;
 
   int change_now;
-
+  int colorbars_only_p;
 };
 
 
@@ -155,6 +155,7 @@ update_smpte_colorbars(analogtv_input *input)
   ypos=ANALOGTV_V/5;
   xpos=ANALOGTV_VIS_START + ANALOGTV_VIS_LEN/2;
 
+  if (! st->colorbars_only_p)
   {
     char localname[256];
     if (gethostname (localname, sizeof (localname))==0) {
@@ -169,8 +170,9 @@ update_smpte_colorbars(analogtv_input *input)
   }
   ypos += st->ugly_font.char_h*5/2;
 
-  analogtv_draw_xpm(st->tv, input,
-                    logo_50_xpm, xpos - 100, ypos);
+  if (! st->colorbars_only_p)
+    analogtv_draw_xpm(st->tv, input,
+                      logo_50_xpm, xpos - 100, ypos);
 
   ypos += 58;
 
@@ -180,6 +182,7 @@ update_smpte_colorbars(analogtv_input *input)
   ypos += st->ugly_font.char_h*4;
 #endif
 
+  if (! st->colorbars_only_p)
   {
     char timestamp[256];
     time_t t = time ((time_t *) 0);
@@ -238,14 +241,15 @@ static const char *xanalogtv_defaults [] = {
   ".background:                black",
   ".foreground:                white",
   "*delay:             5",
-  "*grabDesktopImages:  False",   /* HAVE_COCOA */
-  "*chooseRandomImages: True",    /* HAVE_COCOA */
+  "*grabDesktopImages:  False",   /* HAVE_JWXYZ */
+  "*chooseRandomImages: True",    /* HAVE_JWXYZ */
   ANALOGTV_DEFAULTS
   0,
 };
 
 static XrmOptionDescRec xanalogtv_options [] = {
   { "-delay",          ".delay",               XrmoptionSepArg, 0 },
+  { "-colorbars-only", ".colorbarsOnly",       XrmoptionNoArg, "True" },
   ANALOGTV_OPTIONS
   { 0, 0, 0, 0 }
 };
@@ -281,7 +285,7 @@ getticks(struct state *st)
 static void
 hack_resources (Display *dpy)
 {
-#ifndef HAVE_COCOA
+#ifndef HAVE_JWXYZ
   static int count = -1;
   count++;
 
@@ -301,7 +305,7 @@ hack_resources (Display *dpy)
       value.size = strlen(buf2);
       XrmPutResource (&db, buf1, "String", &value);
     }
-#endif /* HAVE_COCOA */
+#endif /* HAVE_JWXYZ */
 }
 
 
@@ -421,7 +425,8 @@ static void load_station_images(struct state *st)
     analogtv_input *input = st->stations[i];
 
     st->chansettings[i].image_loaded_p = True;
-    if (i == 0) {   /* station 0 is always colorbars */
+    if (i == 0 ||   /* station 0 is always colorbars */
+        st->colorbars_only_p) {
       input->updater = update_smpte_colorbars;
       input->do_teletext=1;
     }
@@ -457,6 +462,9 @@ xanalogtv_init (Display *dpy, Window window)
   st->window = window;
   st->tv=analogtv_allocate(dpy, window);
 
+  st->colorbars_only_p =
+    get_boolean_resource(dpy, "colorbarsOnly", "ColorbarsOnly");
+
   add_stations(st);
 
   analogtv_set_defaults(st->tv, "");
@@ -531,10 +539,14 @@ xanalogtv_draw (Display *dpy, Window window, void *closure)
   int curticks=getticks(st);
   double curtime=curticks*0.001;
 
-  if (st->change_now || 
-      (curticks >= st->change_ticks && st->tv->powerup > 10.0)) {
+  const analogtv_reception *recs[MAX_MULTICHAN];
+  unsigned rec_count = 0;
+
+  int auto_change = curticks >= st->change_ticks && st->tv->powerup > 10.0 ? 1 : 0;
+
+  if (st->change_now || auto_change) {
+    st->curinputi=(st->curinputi+st->change_now+auto_change+N_CHANNELS)%N_CHANNELS;
     st->change_now = 0;
-    st->curinputi=(st->curinputi+1)%N_CHANNELS;
     st->cs = &st->chansettings[st->curinputi];
 #if 0
     fprintf (stderr, "%s: channel %d, %s\n", progname, st->curinputi,
@@ -559,17 +571,21 @@ xanalogtv_draw (Display *dpy, Window window, void *closure)
 
   st->tv->powerup=curtime;
 
-  analogtv_init_signal(st->tv, st->cs->noise_level);
   for (i=0; i<MAX_MULTICHAN; i++) {
     analogtv_reception *rec = &st->cs->recs[i];
-    analogtv_input *inp=rec->input;
-    if (!inp) continue;
-
-    analogtv_reception_update(rec);
-    analogtv_add_signal(st->tv, rec);
+    if (rec->input) {
+      analogtv_reception_update(rec);
+      recs[rec_count] = rec;
+      ++rec_count;
+    }
   }
-  analogtv_draw(st->tv);
-  return 10000;
+  analogtv_draw(st->tv, st->cs->noise_level, recs, rec_count);
+
+#ifdef HAVE_MOBILE
+  return 0;
+#else
+  return 5000;
+#endif
 }
 
 static void
@@ -587,7 +603,8 @@ xanalogtv_event (Display *dpy, Window window, void *closure, XEvent *event)
 
   if (event->type == ButtonPress)
     {
-      st->change_now = 1;
+      unsigned button = event->xbutton.button;
+      st->change_now = button == 2 || button == 3 || button == 5 ? -1 : 1;
       return True;
     }
   else if (event->type == KeyPress)
@@ -595,11 +612,26 @@ xanalogtv_event (Display *dpy, Window window, void *closure, XEvent *event)
       KeySym keysym;
       char c = 0;
       XLookupString (&event->xkey, &c, 1, &keysym, 0);
-      if (c == ' ' || c == '\t' || c == '\r' || c == '\n')
+      if (c == ' ' || c == '\t' || c == '\r' || c == '\n' ||
+          keysym == XK_Up || keysym == XK_Right || keysym == XK_Prior)
         {
           st->change_now = 1;
           return True;
         }
+      else if (c == '\b' ||
+               keysym == XK_Down || keysym == XK_Left || keysym == XK_Next)
+        {
+          st->change_now = -1;
+          return True;
+        }
+      else if (screenhack_event_helper (dpy, window, event))
+        goto DEF;
+    }
+  else if (screenhack_event_helper (dpy, window, event))
+    {
+    DEF:
+      st->change_now = ((random() & 1) ? 1 : -1);
+      return True;
     }
 
   return False;