Beispiel #1
0
static struct throbber *
make_throbber (struct state *st, Drawable d, int w, int h, unsigned long pixel)
{
  XGCValues gcv;
  unsigned long flags;
  struct throbber *t = (struct throbber *) malloc (sizeof (*t));
  t->x = w / 2;
  t->y = h / 2;
  t->max_size = (w > h ? w : h);
  t->speed = get_integer_resource (st->dpy, "speed", "Speed");
  t->fuse = 1 + (random() % 4);
  t->thickness = get_integer_resource (st->dpy, "thickness", "Thickness");

  if (st->xgwa.width > 2560) t->thickness *= 3;  /* Retina displays */

  if (t->speed < 0) t->speed = -t->speed;
  t->speed += (((random() % t->speed) / 2) - (t->speed / 2));
  if (t->speed > 0) t->speed = -t->speed;

  flags = GCForeground;
# ifndef HAVE_JWXYZ
  if (st->transparent_p)
    {
      gcv.foreground = ~0L;
      gcv.plane_mask = st->base_pixel | st->plane_masks[random() % st->nplanes];
      flags |= GCPlaneMask;
    }
  else
# endif /* !HAVE_JWXYZ */
    {
      gcv.foreground = pixel;
    }

  gcv.line_width = t->thickness;
  gcv.cap_style = CapProjecting;
  gcv.join_style = JoinMiter;

  flags |= (GCLineWidth | GCCapStyle | GCJoinStyle);
  t->gc = XCreateGC (st->dpy, d, flags, &gcv);

# ifdef HAVE_JWXYZ
  if (st->transparent_p)
    {
      /* give a non-opaque alpha to the color */
      unsigned long pixel = gcv.foreground;
      unsigned long amask = BlackPixelOfScreen (st->xgwa.screen);
      unsigned long a = (0xCCCCCCCC & amask);
      pixel = (pixel & (~amask)) | a;

      jwxyz_XSetAlphaAllowed (st->dpy, t->gc, True);
      XSetForeground (st->dpy, t->gc, pixel);
    }
# endif /* HAVE_JWXYZ */

  switch (random() % 11) {
  case 0: case 1: case 2: case 3: t->draw = draw_star; break;
  case 4: case 5: case 6: case 7: t->draw = draw_circle; break;
  case 8: t->draw = draw_hlines; break;
  case 9: t->draw = draw_vlines; break;
  case 10: t->draw = draw_corners; break;
  default: abort(); break;
  }

  if (t->draw == draw_circle) 
    t->max_size *= 1.5;

  if (random() % 4)
    t->size = t->max_size;
  else
    t->size = t->thickness, t->speed = -t->speed;

  return t;
}
Beispiel #2
0
static void *
cynosure_init (Display *d, Window w)
{
  struct state *st = (struct state *) calloc (1, sizeof(*st));
  XGCValues gcv;

  st->dpy = d;
  st->window = w;

  st->curColor    = 0;
  st->curBase     = st->curColor;
  st->shadowWidth = get_integer_resource (st->dpy, "shadowWidth", "Integer");
  st->elevation   = get_integer_resource (st->dpy, "elevation", "Integer");
  st->sway        = get_integer_resource (st->dpy, "sway", "Integer");
  st->tweak       = get_integer_resource (st->dpy, "tweak", "Integer");
  st->gridSize    = get_integer_resource (st->dpy, "gridSize", "Integer");
  st->timeLeft    = 0;

  XGetWindowAttributes (st->dpy, st->window, &st->xgwa);

  st->ncolors = get_integer_resource (st->dpy, "colors", "Colors");
  if (st->ncolors < 2) st->ncolors = 2;
  if (st->ncolors <= 2) mono_p = True;

  if (mono_p)
    st->colors = 0;
  else
    st->colors = (XColor *) malloc(sizeof(*st->colors) * (st->ncolors+1));

  if (mono_p)
    ;
  else {
    make_smooth_colormap (st->xgwa.screen, st->xgwa.visual, st->xgwa.colormap,
                          st->colors, &st->ncolors,
			  True, 0, True);
    if (st->ncolors <= 2) {
      mono_p = True;
      st->ncolors = 2;
      if (st->colors) free(st->colors);
      st->colors = 0;
    }
  }

  st->bg_pixel = get_pixel_resource(st->dpy,
				st->xgwa.colormap, "background", "Background");
  st->fg_pixel = get_pixel_resource(st->dpy,
				st->xgwa.colormap, "foreground", "Foreground");

  gcv.foreground = st->fg_pixel;
  st->fg_gc = XCreateGC(st->dpy, st->window, GCForeground, &gcv);
  gcv.foreground = st->bg_pixel;
  st->bg_gc = XCreateGC(st->dpy, st->window, GCForeground, &gcv);

#ifdef DO_STIPPLE
  gcv.fill_style = FillStippled;
  gcv.stipple = XCreateBitmapFromData(st->dpy, st->window, "\125\252", 8, 2);
  st->shadow_gc = XCreateGC(st->dpy, st->window, GCForeground|GCFillStyle|GCStipple, &gcv);
  XFreePixmap(st->dpy, gcv.stipple);

#else /* !DO_STIPPLE */
  st->shadow_gc = XCreateGC(st->dpy, st->window, GCForeground, &gcv);

#  ifdef HAVE_COCOA /* allow non-opaque alpha components in pixel values */
  jwxyz_XSetAlphaAllowed (st->dpy, st->shadow_gc, True);
#  endif

  if (st->colors)
    {
      int i;
      st->ncolors2 = st->ncolors;
      st->colors2 = (XColor *) malloc(sizeof(*st->colors2) * (st->ncolors2+1));

      for (i = 0; i < st->ncolors2; i++)
        {
#  ifdef HAVE_COCOA
          /* give a non-opaque alpha to the shadow colors */
          unsigned long pixel = st->colors[i].pixel;
          unsigned long amask = BlackPixelOfScreen (st->xgwa.screen);
          unsigned long a = (0x77777777 & amask);
          pixel = (pixel & (~amask)) | a;
          st->colors2[i].pixel = pixel;
#  else /* !HAVE_COCOA */
          int h;
          double s, v;
          rgb_to_hsv (st->colors[i].red,
                      st->colors[i].green,
                      st->colors[i].blue,
                      &h, &s, &v);
          v *= 0.4;
          hsv_to_rgb (h, s, v,
                      &st->colors2[i].red,
                      &st->colors2[i].green,
                      &st->colors2[i].blue);
          st->colors2[i].pixel = st->colors[i].pixel;
          XAllocColor (st->dpy, st->xgwa.colormap, &st->colors2[i]);
#  endif /* !HAVE_COCOA */
        }
    }
# endif /* !DO_STIPPLE */

  st->delay = get_integer_resource (st->dpy, "delay", "Delay");
  st->iterations = get_integer_resource (st->dpy, "iterations", "Iterations");

  return st;
}