コード例 #1
0
ファイル: twang.c プロジェクト: Zygo/xscreensaver
/* set up the system */
static void setup (struct state *st)
{
    XWindowAttributes xgwa;
    XGCValues gcv;

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

    st->screen = xgwa.screen;
    st->windowWidth = xgwa.width;
    st->windowHeight = xgwa.height;

    gcv.line_width = st->borderWidth;
    gcv.foreground = get_pixel_resource (st->dpy, xgwa.colormap,
                                         "borderColor", "BorderColor");
    st->borderPixel = gcv.foreground;
    st->borderGC = XCreateGC (st->dpy, st->window, GCForeground | GCLineWidth, 
			  &gcv);

    gcv.foreground = get_pixel_resource (st->dpy, xgwa.colormap,
                                         "background", "Background");
    st->backgroundPixel = gcv.foreground;
    st->backgroundGC = XCreateGC (st->dpy, st->window, GCForeground, &gcv);

    gcv.foreground = get_pixel_resource (st->dpy, xgwa.colormap,
                                         "foreground", "Foreground");
    st->foregroundGC = XCreateGC (st->dpy, st->window, GCForeground, &gcv);

    grabImage_start (st, &xgwa);
}
コード例 #2
0
ファイル: barcode.c プロジェクト: david-sackmary/distro-mods
/* set up the system */
static void setup (struct state *st)
{
    XWindowAttributes xgwa;
    XGCValues gcv;

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

    st->visual = xgwa.visual;
    st->cmap = xgwa.colormap;
    st->windowWidth = xgwa.width;
    st->windowHeight = xgwa.height;

    gcv.background = get_pixel_resource (st->dpy, xgwa.colormap,
                                         "background", "Background");
    gcv.foreground = get_pixel_resource (st->dpy, xgwa.colormap,
                                         "foreground", "Foreground");
    st->fg_pixel = gcv.foreground;
    st->theGC = XCreateGC (st->dpy, st->window, GCForeground|GCBackground, &gcv);

    st->theBitmap = makeBitmap(BARCODE_WIDTH * MAX_MAG, BARCODE_HEIGHT * MAX_MAG);
    st->theImage = XCreateImage(st->dpy, st->visual, 1, XYBitmap, 0, st->theBitmap->buf,
			    st->theBitmap->width, st->theBitmap->height, 8,
			    st->theBitmap->widthBytes);
    st->theImage->bitmap_bit_order = LSBFirst;
    st->theImage->byte_order       = LSBFirst;
}
コード例 #3
0
ファイル: whirlwindwarp.c プロジェクト: RazZziel/pongclock
static void *
whirlwindwarp_init (Display *dpy, Window window)
{
  struct state *st = (struct state *) calloc (1, sizeof(*st));
  XGCValues gcv;
  Colormap cmap;

  st->dpy = dpy;
  st->window = window;

  st->ps=500;
  st->ts=5;

  XGetWindowAttributes (st->dpy, st->window, &st->xgwa);
  cmap = st->xgwa.colormap;
  gcv.foreground = st->default_fg_pixel = get_pixel_resource (st->dpy, cmap, "foreground", "Foreground");
  st->draw_gc = XCreateGC (st->dpy, st->window, GCForeground, &gcv);
  gcv.foreground = get_pixel_resource (st->dpy, cmap, "background", "Background");
  st->erase_gc = XCreateGC (st->dpy, st->window, GCForeground, &gcv);

  st->ps = get_integer_resource (st->dpy, "points", "Integer");
  st->ts = get_integer_resource (st->dpy, "tails", "Integer");
  st->meters = get_boolean_resource (st->dpy, "meters", "Show meters");
  if (st->ps > maxps) st->ps = maxps;
  if (st->ts > maxts) st->ts = maxts;

  return st;
}
コード例 #4
0
ファイル: helix.c プロジェクト: HorseloverFat/xscreensaver
static void *
helix_init (Display *dpy, Window window)
{
  struct state *st = (struct state *) calloc (1, sizeof(*st));
  int i;
  XGCValues gcv;
  XWindowAttributes xgwa;

  st->sleep_time = get_integer_resource(dpy, "delay", "Integer");
  st->subdelay = get_integer_resource(dpy, "subdelay", "Integer");

  XGetWindowAttributes (dpy, window, &xgwa);
  st->width = xgwa.width;
  st->height = xgwa.height;
  st->cmap = xgwa.colormap;
  gcv.foreground = st->default_fg_pixel =
    get_pixel_resource (dpy, st->cmap, "foreground", "Foreground");
  st->draw_gc = XCreateGC (dpy, window, GCForeground, &gcv);
  gcv.foreground = get_pixel_resource (dpy, st->cmap, "background", "Background");

  for (i = 0; i < 360; i++)
    {
      st->sins [i] = sin ((((double) i) / 180.0) * M_PI);
      st->coss [i] = cos ((((double) i) / 180.0) * M_PI);
    }

  st->dstate = (random() & 1) ? HELIX : TRIG;

  return st;
}
コード例 #5
0
ファイル: starfish.c プロジェクト: MaddTheSane/xscreensaver
static void
run_starfish (struct state *st, struct starfish *s)
{
  throb_starfish (s);
  spin_starfish (s);
  draw_starfish (st, st->window, st->gc, s, False);

  if (mono_p)
    {
      if (!st->initted)
	{
	  st->black = get_pixel_resource (st->dpy, st->cmap, "background", "Background");
	  st->white = get_pixel_resource (st->dpy, st->cmap, "foreground", "Foreground");
	  st->initted = True;
	  st->fg_index = st->white;
	  XSetForeground (st->dpy, st->gc, st->fg_index);
	}
      else if (!s->blob_p)
	{
	  st->fg_index = (st->fg_index == st->black ? st->white : st->black);
	  XSetForeground (st->dpy, st->gc, st->fg_index);
	}
    }
  else
    {
      st->fg_index = (st->fg_index + 1) % st->ncolors;
      XSetForeground (st->dpy, st->gc, st->colors [st->fg_index].pixel);
    }
}
コード例 #6
0
ファイル: pedal.c プロジェクト: BuBuaBu/bang-screensaver
static void *
pedal_init (Display *dpy, Window window)
{
  struct state *st = (struct state *) calloc (1, sizeof(*st));
  XGCValues gcv;
  XWindowAttributes xgwa;

  st->dpy = dpy;
  st->window = window;

  st->delay = get_integer_resource (st->dpy, "delay", "Integer");
  if (st->delay < 0) st->delay = 0;

  st->maxlines = get_integer_resource (st->dpy, "maxlines", "Integer");
  if (st->maxlines < MINLINES) st->maxlines = MINLINES;
  else if (st->maxlines > MAXLINES) st->maxlines = MAXLINES;

  st->points = (XPoint *)malloc(sizeof(XPoint) * st->maxlines);

  XGetWindowAttributes (st->dpy, st->window, &xgwa);
  st->sizex = xgwa.width;
  st->sizey = xgwa.height;

  st->cmap = xgwa.colormap;

  gcv.function = GXcopy;
  gcv.foreground = get_pixel_resource (st->dpy, st->cmap, "foreground", "Foreground");
  gcv.background = get_pixel_resource (st->dpy, st->cmap, "background", "Background");
  st->gc = XCreateGC (st->dpy, st->window, GCForeground | GCBackground |GCFunction, &gcv);

  return st;
}
コード例 #7
0
ファイル: erase.c プロジェクト: RazZziel/pongclock
static eraser_state *
eraser_init (Display *dpy, Window window)
{
  eraser_state *st = (eraser_state *) calloc (1, sizeof(*st));
  XWindowAttributes xgwa;
  XGCValues gcv;
  unsigned long fg, bg;
  double duration;
  int which;
  char *s;

  st->dpy = dpy;
  st->window = window;

  XGetWindowAttributes (dpy, window, &xgwa);
  st->width = xgwa.width;
  st->height = xgwa.height;

  bg = get_pixel_resource (dpy, xgwa.colormap, "background", "Background");
  fg = get_pixel_resource (dpy, xgwa.colormap, "foreground", "Foreground");

  gcv.foreground = fg;
  gcv.background = bg;
  st->fg_gc = XCreateGC (dpy, window, GCForeground|GCBackground, &gcv);
  gcv.foreground = bg;
  gcv.background = fg;
  st->bg_gc = XCreateGC (dpy, window, GCForeground|GCBackground, &gcv);

# ifdef HAVE_COCOA
  /* Pretty much all of these leave turds if AA is on. */
  jwxyz_XSetAntiAliasing (st->dpy, st->fg_gc, False);
  jwxyz_XSetAntiAliasing (st->dpy, st->bg_gc, False);
# endif

  s = get_string_resource (dpy, "eraseMode", "Integer");
  if (!s || !*s)
    which = -1;
  else
    which = get_integer_resource(dpy, "eraseMode", "Integer");

  if (which < 0 || which >= countof(erasers))
    which = random() % countof(erasers);
  st->fn = erasers[which];

  duration = get_float_resource (dpy, "eraseSeconds", "Float");
  if (duration < 0.1 || duration > 10)
    duration = 1;

  st->start_time = double_time();
  st->stop_time = st->start_time + duration;

  XSync (st->dpy, False);

  return st;
}
コード例 #8
0
ファイル: petri.c プロジェクト: MaddTheSane/xscreensaver
static void setup_random_colormap (struct state *st, XWindowAttributes *xgwa)
{
    XGCValues gcv;
    int lose = 0;
    int ncolors = st->count - 1;
    int n;
    XColor *colors = (XColor *) calloc (sizeof(*colors), st->count*2);
    
    colors[0].pixel = get_pixel_resource (st->dpy, xgwa->colormap,
                                          "background", "Background");
    
    make_random_colormap (xgwa->screen, xgwa->visual, xgwa->colormap,
			  colors+1, &ncolors, True, True, 0, True);
    if (ncolors < 1)
      {
        fprintf (stderr, "%s: couldn't allocate any colors\n", progname);
	exit (-1);
      }
    
    ncolors++;
    st->count = ncolors;
    
    memcpy (colors + st->count, colors, st->count * sizeof(*colors));
    colors[st->count].pixel = get_pixel_resource (st->dpy, xgwa->colormap,
                                              "foreground", "Foreground");
    
    for (n = 1; n < st->count; n++)
    {
	int m = n + st->count;
	colors[n].red = colors[m].red / 2;
	colors[n].green = colors[m].green / 2;
	colors[n].blue = colors[m].blue / 2;
	
	if (!XAllocColor (st->dpy, xgwa->colormap, &colors[n]))
	{
	    lose++;
	    colors[n] = colors[m];
	}
    }

    if (lose)
    {
	fprintf (stderr, 
		 "%s: unable to allocate %d half-intensity colors.\n",
		 progname, lose);
    }
    
    for (n = 0; n < st->count*2; n++) 
    {
	gcv.foreground = colors[n].pixel;
	st->coloredGCs[n] = XCreateGC (st->dpy, st->window, GCForeground, &gcv);
    }

    free (colors);
}
コード例 #9
0
ファイル: petri.c プロジェクト: MaddTheSane/xscreensaver
static void setup_original_colormap (struct state *st, XWindowAttributes *xgwa)
{
    XGCValues gcv;
    int lose = 0;
    int n;
    XColor *colors = (XColor *) calloc (sizeof(*colors), st->count*2);
    
    colors[0].pixel = get_pixel_resource (st->dpy, xgwa->colormap,
                                          "background", "Background");

    colors[st->count].pixel = get_pixel_resource (st->dpy, xgwa->colormap,
                                              "foreground", "Foreground");

    for (n = 1; n < st->count; n++)
    {
	int m = n + st->count;
	colors[n].red =   ((n & 0x01) != 0) * 0x8000;
	colors[n].green = ((n & 0x02) != 0) * 0x8000;
	colors[n].blue =  ((n & 0x04) != 0) * 0x8000;

	if (!XAllocColor (st->dpy, xgwa->colormap, &colors[n]))
	{
	    lose++;
	    colors[n] = colors[0];
	}

	colors[m].red   = colors[n].red + 0x4000;
	colors[m].green = colors[n].green + 0x4000;
	colors[m].blue  = colors[n].blue + 0x4000;

	if (!XAllocColor (st->dpy, xgwa->colormap, &colors[m]))
	{
	    lose++;
	    colors[m] = colors[st->count];
	}
    }

    if (lose)
    {
	fprintf (stderr, 
		 "%s: unable to allocate %d colors.\n",
		 progname, lose);
    }
    
    for (n = 0; n < st->count*2; n++) 
    {
	gcv.foreground = colors[n].pixel;
	st->coloredGCs[n] = XCreateGC (st->dpy, st->window, GCForeground, &gcv);
    }

    free (colors);
}
コード例 #10
0
static void
init_tsg (struct state *st)
{
  XGCValues	gcv;
  Colormap	cmap;

  XGetWindowAttributes (st->dpy, st->window, &st->xgwa);
  cmap = st->xgwa.colormap;
  gcv.foreground = st->default_fg_pixel =
    get_pixel_resource (st->dpy, cmap, "foreground", "Foreground");
  st->draw_gc = XCreateGC (st->dpy, st->window, GCForeground, &gcv);
  gcv.foreground = get_pixel_resource (st->dpy, cmap, "background", "Background");
}
コード例 #11
0
ファイル: boxfit.c プロジェクト: mmarseglia/xscreensaver
static void *
boxfit_init (Display *dpy, Window window)
{
  XGCValues gcv;
  state *st = (state *) calloc (1, sizeof (*st));

  st->dpy = dpy;
  st->window = window;
  st->delay = get_integer_resource (dpy, "delay", "Integer");

  XGetWindowAttributes (st->dpy, st->window, &st->xgwa);
/*  XSelectInput (dpy, window, st->xgwa.your_event_mask | ExposureMask);*/

  if (! get_boolean_resource (dpy, "grab", "Boolean"))
    {
      st->ncolors = get_integer_resource (dpy, "colors", "Colors");
      if (st->ncolors < 1) st->ncolors = 1;
      st->colors = (XColor *) malloc (sizeof(XColor) * st->ncolors);
    }

  st->inc = get_integer_resource (dpy, "growBy", "GrowBy");
  st->spacing = get_integer_resource (dpy, "spacing", "Spacing");
  st->border_size = get_integer_resource (dpy, "borderSize", "BorderSize");
  st->fg_color = get_pixel_resource (st->dpy, st->xgwa.colormap, 
                                     "foreground", "Foreground");
  st->bg_color = get_pixel_resource (st->dpy, st->xgwa.colormap,
                                     "background", "Background");
  if (st->inc < 1) st->inc = 1;
  if (st->border_size < 0) st->border_size = 0;

  gcv.line_width = st->border_size;
  gcv.background = st->bg_color;
  st->gc = XCreateGC (st->dpy, st->window, GCBackground|GCLineWidth, &gcv);

  st->box_count = get_integer_resource (dpy, "boxCount", "BoxCount");
  if (st->box_count < 1) st->box_count = 1;

  st->nboxes = 0;
  st->boxes_size = st->box_count * 2;
  st->boxes = (box *) calloc (st->boxes_size, sizeof(*st->boxes));

  reset_boxes (st);

  reshape_boxes (st);
  return st;
}
コード例 #12
0
ファイル: twinkle1.c プロジェクト: 10crimes/code
static Bool init_twinkle(Display *dpy, Window window) {
  XGCValues gcv;
  Colormap cmap;
  XWindowAttributes xgwa;
  XGetWindowAttributes (dpy, window, &xgwa);
  cmap = xgwa.colormap;
  gcv.foreground = default_fg_pixel = get_pixel_resource ("foreground", "Foreground", dpy, cmap);
  draw_gc = XCreateGC (dpy, window, GCForeground, &gcv);
  gcv.foreground = get_pixel_resource ("background", "Background", dpy, cmap);
  erase_gc = XCreateGC (dpy, window, GCForeground, &gcv);

  ps = get_integer_resource ("points", "Integer");
  ts = get_integer_resource ("tails", "Integer");
  meters = get_boolean_resource ("meters", "Show meters");
  if (ps>maxps || ts>maxts)
    return 0;
  return 1;
}
コード例 #13
0
ファイル: cloudlife.c プロジェクト: BuBuaBu/bang-screensaver
static void *
cloudlife_init (Display *dpy, Window window)
{
  struct state *st = (struct state *) calloc (1, sizeof(*st));
    Bool tmp = True;

    st->dpy = dpy;
    st->window = window;
    st->field = init_field(st);

#ifdef TIME_ME
    st->start_time = time(NULL);
#endif

    st->cycle_delay = get_integer_resource(st->dpy, "cycleDelay", "Integer");
    st->cycle_colors = get_integer_resource(st->dpy, "cycleColors", "Integer");
    st->ncolors = get_integer_resource(st->dpy, "ncolors", "Integer");
    st->density = (get_integer_resource(st->dpy, "initialDensity", "Integer") 
                  % 100 * 256)/100;

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

    if (st->cycle_colors) {
        st->colors = (XColor *) xrealloc(st->colors, sizeof(XColor) * (st->ncolors+1));
        make_smooth_colormap (st->xgwa.screen, st->xgwa.visual,
                              st->xgwa.colormap, st->colors, &st->ncolors,
                              True, &tmp, True);
    }

    st->gcv.foreground = get_pixel_resource(st->dpy, st->xgwa.colormap,
                                        "foreground", "Foreground");
    st->fgc = XCreateGC(st->dpy, st->window, GCForeground, &st->gcv);

    st->gcv.foreground = get_pixel_resource(st->dpy, st->xgwa.colormap,
                                        "background", "Background");
    st->bgc = XCreateGC(st->dpy, st->window, GCForeground, &st->gcv);

    return st;
}
コード例 #14
0
ファイル: pyro.c プロジェクト: RazZziel/pongclock
static void *
pyro_init (Display *dpy, Window window)
{
    struct state *st = (struct state *) calloc (1, sizeof(*st));
    int i;
    XGCValues gcv;
    XWindowAttributes xgwa;
    st->dpy = dpy;
    st->window = window;
    XGetWindowAttributes (st->dpy, st->window, &xgwa);
    st->last_pixel = ~0;
    st->cmap = xgwa.colormap;
    st->delay = get_integer_resource (st->dpy, "delay", "Integer");
    st->how_many = get_integer_resource (st->dpy, "count", "Integer");
    st->frequency = get_integer_resource (st->dpy, "frequency", "Integer");
    st->scatter = get_integer_resource (st->dpy, "scatter", "Integer");
    if (st->how_many <= 0) st->how_many = 100;
    if (st->frequency <= 0) st->frequency = 30;
    if (st->scatter <= 0) st->scatter = 20;
    st->projectiles = 0;
    st->free_projectiles = 0;
    st->projectiles = (struct projectile *)
                      calloc (st->how_many, sizeof (*st->projectiles));
    st->sorted_projectiles = (struct projectile **)
                             calloc (st->how_many, sizeof (*st->sorted_projectiles));
    for (i = 0; i < st->how_many; i++)
        free_projectile (st, &st->projectiles [i]);
    for (i = 0; i < st->how_many; i++)
        st->sorted_projectiles[i] = &st->projectiles[i];
    gcv.foreground = st->default_fg_pixel =
                         get_pixel_resource (st->dpy, st->cmap, "foreground", "Foreground");
    st->draw_gc = XCreateGC (st->dpy, st->window, GCForeground, &gcv);
    gcv.foreground = get_pixel_resource (st->dpy, st->cmap, "background", "Background");
    st->erase_gc = XCreateGC (st->dpy, st->window, GCForeground, &gcv);
    XClearWindow (st->dpy, st->window);
    cache(st);

    return st;
}
コード例 #15
0
ファイル: grabclient.c プロジェクト: mmarseglia/xscreensaver
/* Writes the string "Loading..." in the middle of the screen.
   This will presumably get blown away when the image finally loads,
   minutes or hours later...

   This is called by load_image_async_simple() but not by load_image_async(),
   since it is assumed that hacks that are loading more than one image
   *at one time* will be doing something more clever than just blocking
   with a blank screen.
 */
static void
print_loading_msg (Screen *screen, Window window)
{
  Display *dpy = DisplayOfScreen (screen);
  XWindowAttributes xgwa;
  XGCValues gcv;
  XFontStruct *f = 0;
  GC gc;
  char *fn = get_string_resource (dpy, "labelFont", "Font");
  const char *text = "Loading...";
  int w;

  if (!fn) fn = get_string_resource (dpy, "titleFont", "Font");
  if (!fn) fn = get_string_resource (dpy, "font", "Font");
  if (!fn) fn = strdup ("-*-times-bold-r-normal-*-180-*");
  f = XLoadQueryFont (dpy, fn);
  if (!f) f = XLoadQueryFont (dpy, "fixed");
  if (!f) abort();
  free (fn);
  fn = 0;

  XGetWindowAttributes (dpy, window, &xgwa);
  w = XTextWidth (f, text, (int) strlen(text));

  gcv.foreground = get_pixel_resource (dpy, xgwa.colormap,
                                       "foreground", "Foreground");
  gcv.background = get_pixel_resource (dpy, xgwa.colormap,
                                       "background", "Background");
  gcv.font = f->fid;
  gc = XCreateGC (dpy, window, GCFont | GCForeground | GCBackground, &gcv);
  XDrawImageString (dpy, window, gc,
                    (xgwa.width - w) / 2,
                    (xgwa.height - (f->ascent + f->descent)) / 2 + f->ascent,
                    text, (int) strlen(text));
  XFreeFont (dpy, f);
  XFreeGC (dpy, gc);
  XSync (dpy, False);
}
コード例 #16
0
ファイル: rorschach.c プロジェクト: mmarseglia/xscreensaver
static void *
rorschach_init (Display *dpy, Window window)
{
  struct state *st = (struct state *) calloc (1, sizeof(*st));
  XGCValues gcv;
  Colormap cmap;
  XWindowAttributes xgwa;
  XGetWindowAttributes (dpy, window, &xgwa);
  cmap = xgwa.colormap;
  gcv.foreground = st->default_fg_pixel =
    get_pixel_resource (dpy, cmap, "foreground", "Foreground");
  st->draw_gc = XCreateGC (dpy, window, GCForeground, &gcv);
  gcv.foreground = get_pixel_resource (dpy, cmap, "background", "Background");
  st->iterations = get_integer_resource (dpy, "iterations", "Integer");
  st->offset = get_integer_resource (dpy, "offset", "Integer");
  if (st->offset <= 0) st->offset = 3;
  if (st->iterations < 10) st->iterations = 10;
  st->sleep_time = get_integer_resource (dpy, "delay", "Delay");
  st->xsym = get_boolean_resource (dpy, "xsymmetry", "Symmetry");
  st->ysym = get_boolean_resource (dpy, "ysymmetry", "Symmetry");
  st->remaining_iterations = -1;
  st->color.pixel = 0;
  return st;
}
コード例 #17
0
ファイル: nerverot.c プロジェクト: BuBuaBu/bang-screensaver
/* set up the colormap */
static void setupColormap (struct state *st, XWindowAttributes *xgwa)
{
    int n;
    XGCValues gcv;
    XColor *colors = (XColor *) calloc (sizeof (XColor), st->colorCount + 1);

    unsigned short r, g, b;
    int h1, h2;
    double s1, s2, v1, v2;

    r = RAND_FLOAT_01 * 0x10000;
    g = RAND_FLOAT_01 * 0x10000;
    b = RAND_FLOAT_01 * 0x10000;
    rgb_to_hsv (r, g, b, &h1, &s1, &v1);
    v1 = 1.0;
    s1 = 1.0;

    r = RAND_FLOAT_01 * 0x10000;
    g = RAND_FLOAT_01 * 0x10000;
    b = RAND_FLOAT_01 * 0x10000;
    rgb_to_hsv (r, g, b, &h2, &s2, &v2);
    s2 = 0.7;
    v2 = 0.7;
    
    colors[0].pixel = get_pixel_resource (st->dpy, xgwa->colormap,
                                          "background", "Background");
    
    make_color_ramp (xgwa->screen, xgwa->visual, xgwa->colormap,
                     h1, s1, v1, h2, s2, v2,
		     colors + 1, &st->colorCount, False, True, False);

    if (st->colorCount < 1)
    {
        fprintf (stderr, "%s: couldn't allocate any colors\n", progname);
	exit (-1);
    }
    
    st->gcs = (GC *) calloc (sizeof (GC), st->colorCount + 1);

    for (n = 0; n <= st->colorCount; n++) 
    {
	gcv.foreground = colors[n].pixel;
	gcv.line_width = st->lineWidth;
	st->gcs[n] = XCreateGC (st->dpy, st->window, GCForeground | GCLineWidth, &gcv);
    }

    free (colors);
}
コード例 #18
0
ファイル: lock.c プロジェクト: wenhann/chromiumos
static int
new_passwd_window (saver_info *si)
{
  passwd_dialog_data *pw;
  Screen *screen;
  Colormap cmap;
  char *f;  /* temp variable for user with getting strings from config */
  saver_screen_info *ssi = &si->screens [mouse_screen (si)];

  pw = (passwd_dialog_data *) calloc (1, sizeof(*pw));
  if (!pw)
    return -1;

  pw->passwd_cursor = XCreateFontCursor (si->dpy, XC_top_left_arrow);

  pw->prompt_screen = ssi;

  screen = pw->prompt_screen->screen;
  cmap = DefaultColormapOfScreen (screen);

  pw->show_stars_p = get_boolean_resource(si->dpy, "passwd.asterisks",
					  "Boolean");

  pw->passwd_string = strdup("");

  f = get_string_resource(si->dpy, "passwd.passwdFont", "Dialog.Font");
  pw->passwd_font = XLoadQueryFont (si->dpy, (f ? f : "fixed"));
  if (!pw->passwd_font) pw->passwd_font = XLoadQueryFont (si->dpy, "fixed");
  if (f) free (f);

  f = get_string_resource(si->dpy, "passwd.unameFont", "Dialog.Font");
  pw->uname_font = XLoadQueryFont (si->dpy, (f ? f : "fixed"));
  if (!pw->uname_font) pw->uname_font = XLoadQueryFont (si->dpy, "fixed");
  if (f) free (f);

  pw->foreground = get_pixel_resource (si->dpy, cmap,
				       "passwd.foreground",
				       "Dialog.Foreground" );
  pw->background = get_pixel_resource (si->dpy, cmap,
				       "passwd.background",
				       "Dialog.Background" );

  if (pw->foreground == pw->background)
    {
      /* Make sure the error messages show up. */
      pw->foreground = BlackPixelOfScreen (screen);
      pw->background = WhitePixelOfScreen (screen);
    }

  pw->passwd_foreground = get_pixel_resource (si->dpy, cmap,
					      "passwd.text.foreground",
					      "Dialog.Text.Foreground" );
  pw->passwd_background = get_pixel_resource (si->dpy, cmap,
					      "passwd.text.background",
					      "Dialog.Text.Background" );
  /* [email protected] - Get Chrome OS specific options */
  pw->passwd_field_width = get_integer_resource(si->dpy, "chromeos.password.width", "Integer");
  pw->passwd_field_height = get_integer_resource(si->dpy, "chromeos.password.height", "Integer");
  pw->width = get_integer_resource(si->dpy, "chromeos.background.width", "Integer");
  pw->height = get_integer_resource(si->dpy, "chromeos.background.height", "Integer");

  {
    Window pointer_root, pointer_child;
    int root_x, root_y, win_x, win_y;
    unsigned int mask;
    pw->previous_mouse_x = 0;
    pw->previous_mouse_y = 0;
    if (XQueryPointer (si->dpy, RootWindowOfScreen (pw->prompt_screen->screen),
                       &pointer_root, &pointer_child,
                       &root_x, &root_y, &win_x, &win_y, &mask))
      {
        pw->previous_mouse_x = root_x;
        pw->previous_mouse_y = root_y;
        if (si->prefs.verbose_p)
          fprintf (stderr, "%s: %d: mouse is at %d,%d.\n",
                   blurb(), pw->prompt_screen->number,
                   pw->previous_mouse_x, pw->previous_mouse_y);
      }
    else if (si->prefs.verbose_p)
      fprintf (stderr, "%s: %d: unable to determine mouse position?\n",
               blurb(), pw->prompt_screen->number);
  }

  /* Before mapping the window, save a pixmap of the current screen.
     When we lower the window, we
     restore these bits.  This works, because the running screenhack
     has already been sent SIGSTOP, so we know nothing else is drawing
     right now! */
  {
    XGCValues gcv;
    GC gc;
    pw->save_under = XCreatePixmap (si->dpy,
				    pw->prompt_screen->screensaver_window,
				    pw->prompt_screen->width,
				    pw->prompt_screen->height,
				    pw->prompt_screen->current_depth);
    gcv.function = GXcopy;
    gc = XCreateGC (si->dpy, pw->save_under, GCFunction, &gcv);
    XCopyArea (si->dpy, pw->prompt_screen->screensaver_window,
	       pw->save_under, gc,
	       0, 0,
	       pw->prompt_screen->width, pw->prompt_screen->height,
	       0, 0);
    XFreeGC (si->dpy, gc);
  }

  si->pw_data = pw;
  return 0;
}
コード例 #19
0
ファイル: squiral.c プロジェクト: Ro6afF/XScreenSaver
static void *
squiral_init (Display *dpy, Window window)
{
    struct state *st = (struct state *) calloc (1, sizeof(*st));
    XGCValues gcv;
    Colormap cmap;
    XWindowAttributes xgwa;
    Bool writeable = False;

    st->dpy = dpy;
    st->window = window;

    st->delay= get_integer_resource(st->dpy, "delay", "Integer");

    XClearWindow(st->dpy, st->window);
    XGetWindowAttributes(st->dpy, st->window, &xgwa);
    st->width  = xgwa.width;
    st->height = xgwa.height;

    cmap = xgwa.colormap;
    gcv.foreground = get_pixel_resource(st->dpy, cmap, "foreground",
                                        "Foreground");
    st->draw_gc = XCreateGC(st->dpy, st->window, GCForeground, &gcv);
    gcv.foreground = get_pixel_resource (st->dpy, cmap, "background", "Background");
    st->erase_gc = XCreateGC (st->dpy, st->window, GCForeground, &gcv);
    cmap = xgwa.colormap;
    if( st->ncolors ) {
        free_colors(xgwa.screen, cmap, st->colors, st->ncolors);
        st->ncolors = 0;
    }
    if( mono_p ) {
        st->ncolors=1;
        st->colors[0].pixel=get_pixel_resource(st->dpy, cmap, "foreground","Foreground");
    } else {
        st->ncolors = get_integer_resource(st->dpy, "ncolors", "Integer");
        if (st->ncolors < 0 || st->ncolors > NCOLORSMAX)
            st->ncolors = NCOLORSMAX;
        make_uniform_colormap(xgwa.screen, xgwa.visual, cmap,
                              st->colors, &st->ncolors, True,
                              &writeable, False);
        if (st->ncolors <= 0) {
            st->ncolors = 1;
            st->colors[0].pixel=get_pixel_resource(st->dpy, cmap, "foreground","Foreground");
        }
    }
    st->count= get_integer_resource(st->dpy, "count", "Integer");
    st->frac = get_integer_resource(st->dpy, "fill",  "Integer")*0.01;
    st->cycle= get_boolean_resource(st->dpy, "cycle", "Cycle");
    st->disorder=get_float_resource(st->dpy, "disorder", "Float");
    st->handedness=get_float_resource(st->dpy, "handedness", "Float");

    if(st->frac<0.01) st->frac=0.01;
    if(st->frac>0.99) st->frac=0.99;
    if(st->count==0) st->count=st->width/32;
    if(st->count<1) st->count=1;
    if(st->count>1000) st->count=1000;

    if(st->worms) free(st->worms);
    if(st->fill)  free(st->fill);

    squiral_init_1 (st);

    return st;
}
コード例 #20
0
ファイル: deluxe.c プロジェクト: MaddTheSane/xscreensaver
static void *
deluxe_init (Display *dpy, Window window)
{
  struct state *st = (struct state *) calloc (1, sizeof(*st));
  XGCValues gcv;
  int i;
  st->dpy = dpy;
  st->window = window;
  st->count = get_integer_resource (st->dpy, "count", "Integer");
  st->delay = get_integer_resource (st->dpy, "delay", "Integer");
  st->ncolors = get_integer_resource (st->dpy, "ncolors", "Integer");
  st->dbuf = get_boolean_resource (st->dpy, "doubleBuffer", "Boolean");

# ifdef HAVE_DOUBLE_BUFFER_EXTENSION
  st->dbeclear_p = get_boolean_resource (st->dpy, "useDBEClear", "Boolean");
#endif

# ifdef HAVE_JWXYZ	/* Don't second-guess Quartz's double-buffering */
  st->dbuf = False;
# endif

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

  st->transparent_p = get_boolean_resource(st->dpy, "transparent", "Transparent");

  st->colors = (XColor *) calloc (sizeof(*st->colors), st->ncolors);

  if (get_boolean_resource(st->dpy, "mono", "Boolean"))
    {
    MONO:
      st->ncolors = 1;
      st->colors[0].pixel = get_pixel_resource(st->dpy, st->xgwa.colormap,
                                           "foreground", "Foreground");
    }
#ifndef HAVE_JWXYZ
  else if (st->transparent_p)
    {
      st->nplanes = get_integer_resource (st->dpy, "planes", "Planes");
      if (st->nplanes <= 0)
        st->nplanes = (random() % (st->xgwa.depth-2)) + 2;

      allocate_alpha_colors (st->xgwa.screen, st->xgwa.visual, st->xgwa.colormap,
                             &st->nplanes, True, &st->plane_masks,
			     &st->base_pixel);
      if (st->nplanes <= 1)
	{
# if 0
	  fprintf (stderr,
         "%s: couldn't allocate any color planes; turning transparency off.\n",
		   progname);
# endif
          st->transparent_p = False;
	  goto COLOR;
	}
    }
#endif /* !HAVE_JWXYZ */
  else
    {
#ifndef HAVE_JWXYZ
    COLOR:
#endif
      make_random_colormap (st->xgwa.screen, st->xgwa.visual, st->xgwa.colormap,
                            st->colors, &st->ncolors, True, True, 0, True);
      if (st->ncolors < 2)
        goto MONO;
    }

  if (st->dbuf)
    {
#ifdef HAVE_DOUBLE_BUFFER_EXTENSION
      if (st->dbeclear_p)
        st->b = xdbe_get_backbuffer (st->dpy, st->window, XdbeBackground);
      else
        st->b = xdbe_get_backbuffer (st->dpy, st->window, XdbeUndefined);
      st->backb = st->b;
#endif /* HAVE_DOUBLE_BUFFER_EXTENSION */

      if (!st->b)
        {
          st->ba = XCreatePixmap (st->dpy, st->window, st->xgwa.width, st->xgwa.height,st->xgwa.depth);
          st->bb = XCreatePixmap (st->dpy, st->window, st->xgwa.width, st->xgwa.height,st->xgwa.depth);
          st->b = st->ba;
        }
    }
  else
    {
      st->b = st->window;
    }

  st->throbbers = (struct throbber **) calloc (st->count, sizeof(struct throbber *));
  for (i = 0; i < st->count; i++)
    st->throbbers[i] = make_throbber (st, st->b, st->xgwa.width, st->xgwa.height,
                                  st->colors[random() % st->ncolors].pixel);

  gcv.foreground = get_pixel_resource (st->dpy, st->xgwa.colormap,
                                       "background", "Background");
  st->erase_gc = XCreateGC (st->dpy, st->b, GCForeground, &gcv);

  if (st->ba) XFillRectangle (st->dpy, st->ba, st->erase_gc, 0, 0, st->xgwa.width, st->xgwa.height);
  if (st->bb) XFillRectangle (st->dpy, st->bb, st->erase_gc, 0, 0, st->xgwa.width, st->xgwa.height);

  return st;
}
コード例 #21
0
ファイル: popsquares.c プロジェクト: Zygo/xscreensaver
static void *
popsquares_init (Display *dpy, Window window)
{
  struct state *st = (struct state *) calloc (1, sizeof(*st));
  int x, y;
  double s1, v1, s2, v2 = 0;
  int h1, h2 = 0;
  /* Not sure how to use DBEClear */
  /* Bool dbeclear_p = get_boolean_resource(dpy, "useDBEClear", "Boolean"); */
  XColor fg, bg;
  XGCValues gcv;
  
  st->dpy = dpy;
  st->window = window;

  st->delay = get_integer_resource (st->dpy, "delay", "Integer");
  st->subdivisionx = get_integer_resource(st->dpy, "subdivision", "Integer");
  st->subdivisiony = st->subdivisionx;
  st->border = get_integer_resource(st->dpy, "border", "Integer");
  st->ncolors = get_integer_resource(st->dpy, "ncolors", "Integer");
  st->twitch = get_boolean_resource(st->dpy, "twitch", "Boolean");
  st->dbuf = get_boolean_resource(st->dpy, "doubleBuffer", "Boolean");

# ifdef HAVE_JWXYZ	/* Don't second-guess Quartz's double-buffering */
  st->dbuf = False;
# endif

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

  fg.pixel = get_pixel_resource (st->dpy, st->xgwa.colormap, "foreground", "Foreground");
  bg.pixel = get_pixel_resource (st->dpy, st->xgwa.colormap, "background", "Background");

  XQueryColor (st->dpy, st->xgwa.colormap, &fg);
  XQueryColor (st->dpy, st->xgwa.colormap, &bg);

  st->sw = st->xgwa.width / st->subdivisionx;
  st->sh = st->xgwa.height / st->subdivisiony;
  st->gw = st->sw ? st->xgwa.width / st->sw : 0;
  st->gh = st->sh ? st->xgwa.height / st->sh : 0;
  st->nsquares = st->gw * st->gh;
  if (st->nsquares < 1) st->nsquares = 1;
  if (st->ncolors < 1) st->ncolors = 1;

  gcv.foreground = fg.pixel;
  gcv.background = bg.pixel;
  st->gc = XCreateGC (st->dpy, st->window, GCForeground|GCBackground, &gcv);

  st->colors = (XColor *) calloc (st->ncolors, sizeof(XColor));
  st->squares = (square *) calloc (st->nsquares, sizeof(square));

  rgb_to_hsv (fg.red, fg.green, fg.blue, &h1, &s1, &v1);
  rgb_to_hsv (bg.red, bg.green, bg.blue, &h2, &s2, &v2);
  make_color_ramp (st->xgwa.screen, st->xgwa.visual, st->xgwa.colormap,
                   h1, s1, v1,
                   h2, s2, v2,
                   st->colors, &st->ncolors,  /* would this be considered a value-result argument? */
                   True, True, False);
  if (st->ncolors < 2)
    {
      fprintf (stderr, "%s: insufficient colors!\n", progname);
      exit (1);
    }

  for (y = 0; y < st->gh; y++)
    for (x = 0; x < st->gw; x++) 
      {
        square *s = (square *) &st->squares[st->gw * y + x];
        s->w = st->sw;
        s->h = st->sh;
        s->x = x * st->sw;
        s->y = y * st->sh;
      }

  randomize_square_colors(st->squares, st->nsquares, st->ncolors);

  if (st->dbuf)
    {
#ifdef HAVE_DOUBLE_BUFFER_EXTENSION
      st->b = xdbe_get_backbuffer (st->dpy, st->window, XdbeUndefined);
      st->backb = st->b;
#endif /* HAVE_DOUBLE_BUFFER_EXTENSION */
      if (!st->b)                      
        {
          st->ba = XCreatePixmap (st->dpy, st->window, st->xgwa.width, st->xgwa.height, st->xgwa.depth);
          st->bb = XCreatePixmap (st->dpy, st->window, st->xgwa.width, st->xgwa.height, st->xgwa.depth);
          st->b = st->ba;
        }
    }
  else 
    {
      st->b = st->window;
    }

  popsquares_reshape (dpy, window, st, st->xgwa.width, st->xgwa.height);

  return st;
}
コード例 #22
0
ファイル: splash.c プロジェクト: RazZziel/pongclock
void
make_splash_dialog (saver_info *si)
{
  int x, y, bw;
  XSetWindowAttributes attrs;
  unsigned long attrmask = 0;
  splash_dialog_data *sp;
  saver_screen_info *ssi;
  Colormap cmap;
  char *f;

  if (si->sp_data)
    return;
  if (!si->prefs.splash_p ||
      si->prefs.splash_duration <= 0)
    return;

  ssi = &si->screens[mouse_screen (si)];
  cmap = DefaultColormapOfScreen (ssi->screen);

  sp = (splash_dialog_data *) calloc (1, sizeof(*sp));
  sp->prompt_screen = ssi;

  sp->heading_label = get_string_resource (si->dpy,
                                           "splash.heading.label",
					   "Dialog.Label.Label");
  sp->body_label = get_string_resource (si->dpy,
                                        "splash.body.label",
					"Dialog.Label.Label");
  sp->body2_label = get_string_resource (si->dpy,
                                         "splash.body2.label",
					 "Dialog.Label.Label");
  sp->demo_label = get_string_resource (si->dpy,
                                        "splash.demo.label",
					"Dialog.Button.Label");
#ifdef PREFS_BUTTON
  sp->prefs_label = get_string_resource (si->dpy,
                                         "splash.prefs.label",
					"Dialog.Button.Label");
#endif /* PREFS_BUTTON */
  sp->help_label = get_string_resource (si->dpy,
                                        "splash.help.label",
					"Dialog.Button.Label");

  if (!sp->heading_label)
    sp->heading_label = strdup("ERROR: REESOURCES NOT INSTALLED CORRECTLY");
  if (!sp->body_label)
    sp->body_label = strdup("ERROR: REESOURCES NOT INSTALLED CORRECTLY");
  if (!sp->body2_label)
    sp->body2_label = strdup("ERROR: REESOURCES NOT INSTALLED CORRECTLY");
  if (!sp->demo_label) sp->demo_label = strdup("ERROR");
#ifdef PREFS_BUTTON
  if (!sp->prefs_label) sp->prefs_label = strdup("ERROR");
#endif /* PREFS_BUTTON */
  if (!sp->help_label) sp->help_label = strdup("ERROR");

  /* Put the version number in the label. */
  {
    char *s = (char *) malloc (strlen(sp->heading_label) + 20);
    sprintf(s, sp->heading_label, si->version);
    free (sp->heading_label);
    sp->heading_label = s;
  }

  f = get_string_resource (si->dpy, "splash.headingFont", "Dialog.Font");
  sp->heading_font = XLoadQueryFont (si->dpy, (f ? f : "fixed"));
  if (!sp->heading_font) sp->heading_font = XLoadQueryFont (si->dpy, "fixed");
  if (f) free (f);

  f = get_string_resource(si->dpy, "splash.bodyFont", "Dialog.Font");
  sp->body_font = XLoadQueryFont (si->dpy, (f ? f : "fixed"));
  if (!sp->body_font) sp->body_font = XLoadQueryFont (si->dpy, "fixed");
  if (f) free (f);

  f = get_string_resource(si->dpy, "splash.buttonFont", "Dialog.Font");
  sp->button_font = XLoadQueryFont (si->dpy, (f ? f : "fixed"));
  if (!sp->button_font) sp->button_font = XLoadQueryFont (si->dpy, "fixed");
  if (f) free (f);

  sp->foreground = get_pixel_resource (si->dpy, cmap,
                                       "splash.foreground",
				       "Dialog.Foreground");
  sp->background = get_pixel_resource (si->dpy, cmap, 
                                       "splash.background",
				       "Dialog.Background");

  if (sp->foreground == sp->background)
    {
      /* Make sure the error messages show up. */
      sp->foreground = BlackPixelOfScreen (ssi->screen);
      sp->background = WhitePixelOfScreen (ssi->screen);
    }

  sp->button_foreground = get_pixel_resource (si->dpy, cmap,
                                              "splash.Button.foreground",
					      "Dialog.Button.Foreground");
  sp->button_background = get_pixel_resource (si->dpy, cmap,
                                              "splash.Button.background",
					      "Dialog.Button.Background");
  sp->shadow_top = get_pixel_resource (si->dpy, cmap,
                                       "splash.topShadowColor",
				       "Dialog.Foreground");
  sp->shadow_bottom = get_pixel_resource (si->dpy, cmap,
                                          "splash.bottomShadowColor",
					  "Dialog.Background");

  sp->logo_width = get_integer_resource (si->dpy, 
                                         "splash.logo.width",
					 "Dialog.Logo.Width");
  sp->logo_height = get_integer_resource (si->dpy, 
                                          "splash.logo.height",
					  "Dialog.Logo.Height");
  sp->internal_border = get_integer_resource (si->dpy, 
                                              "splash.internalBorderWidth",
					      "Dialog.InternalBorderWidth");
  sp->shadow_width = get_integer_resource (si->dpy, 
                                           "splash.shadowThickness",
					   "Dialog.ShadowThickness");

  if (sp->logo_width == 0)  sp->logo_width = 150;
  if (sp->logo_height == 0) sp->logo_height = 150;
  if (sp->internal_border == 0) sp->internal_border = 15;
  if (sp->shadow_width == 0) sp->shadow_width = 4;

  {
    int direction, ascent, descent;
    XCharStruct overall;

    sp->width = 0;
    sp->height = 0;

    /* Measure the heading_label. */
    XTextExtents (sp->heading_font,
		  sp->heading_label, strlen(sp->heading_label),
		  &direction, &ascent, &descent, &overall);
    if (overall.width > sp->width) sp->width = overall.width;
    sp->height += ascent + descent;

    /* Measure the body_label. */
    XTextExtents (sp->body_font,
		  sp->body_label, strlen(sp->body_label),
		  &direction, &ascent, &descent, &overall);
    if (overall.width > sp->width) sp->width = overall.width;
    sp->height += ascent + descent;

    /* Measure the body2_label. */
    XTextExtents (sp->body_font,
		  sp->body2_label, strlen(sp->body2_label),
		  &direction, &ascent, &descent, &overall);
    if (overall.width > sp->width) sp->width = overall.width;
    sp->height += ascent + descent;

    {
      Dimension w2 = 0, w3 = 0, w4 = 0;
      Dimension h2 = 0, h3 = 0, h4 = 0;

      /* Measure the Demo button. */
      XTextExtents (sp->button_font,
		    sp->demo_label, strlen(sp->demo_label),
		    &direction, &ascent, &descent, &overall);
      w2 = overall.width;
      h2 = ascent + descent;

#ifdef PREFS_BUTTON
      /* Measure the Prefs button. */
      XTextExtents (sp->button_font,
		    sp->prefs_label, strlen(sp->prefs_label),
		    &direction, &ascent, &descent, &overall);
      w3 = overall.width;
      h3 = ascent + descent;
#else  /* !PREFS_BUTTON */
      w3 = 0;
      h3 = 0;
#endif /* !PREFS_BUTTON */

      /* Measure the Help button. */
      XTextExtents (sp->button_font,
		    sp->help_label, strlen(sp->help_label),
		    &direction, &ascent, &descent, &overall);
      w4 = overall.width;
      h4 = ascent + descent;

      w2 = MAX(w2, w3); w2 = MAX(w2, w4);
      h2 = MAX(h2, h3); h2 = MAX(h2, h4);

      /* Add some horizontal padding inside the buttons. */
      w2 += ascent;

      w2 += ((ascent + descent) / 2) + (sp->shadow_width * 2);
      h2 += ((ascent + descent) / 2) + (sp->shadow_width * 2);

      sp->button_width = w2;
      sp->button_height = h2;

#ifdef PREFS_BUTTON
      w2 *= 3;
#else  /* !PREFS_BUTTON */
      w2 *= 2;
#endif /* !PREFS_BUTTON */

      w2 += ((ascent + descent) * 2);  /* for space between buttons */

      if (w2 > sp->width) sp->width = w2;
      sp->height += h2;
    }

    sp->width  += (sp->internal_border * 2);
    sp->height += (sp->internal_border * 3);

    if (sp->logo_height > sp->height)
      sp->height = sp->logo_height;
    else if (sp->height > sp->logo_height)
      sp->logo_height = sp->height;

    sp->logo_width = sp->logo_height;

    sp->width += sp->logo_width;
  }

  attrmask |= CWOverrideRedirect; attrs.override_redirect = True;
  attrmask |= CWEventMask;
  attrs.event_mask = (ExposureMask | ButtonPressMask | ButtonReleaseMask);

  {
    int sx, sy, w, h;
    int mouse_x = 0, mouse_y = 0;

    {
      Window pointer_root, pointer_child;
      int root_x, root_y, win_x, win_y;
      unsigned int mask;
      if (XQueryPointer (si->dpy,
                         RootWindowOfScreen (ssi->screen),
                         &pointer_root, &pointer_child,
                         &root_x, &root_y, &win_x, &win_y, &mask))
        {
          mouse_x = root_x;
          mouse_y = root_y;
        }
    }

    get_screen_viewport (ssi, &sx, &sy, &w, &h, mouse_x, mouse_y, False);
    if (si->prefs.debug_p) w /= 2;
    x = sx + (((w + sp->width)  / 2) - sp->width);
    y = sy + (((h + sp->height) / 2) - sp->height);
    if (x < sx) x = sx;
    if (y < sy) y = sy;
  }

  bw = get_integer_resource (si->dpy, 
                             "splash.borderWidth",
                             "Dialog.BorderWidth");

  si->splash_dialog =
    XCreateWindow (si->dpy,
		   RootWindowOfScreen(ssi->screen),
		   x, y, sp->width, sp->height, bw,
		   DefaultDepthOfScreen (ssi->screen), InputOutput,
		   DefaultVisualOfScreen(ssi->screen),
		   attrmask, &attrs);
  XSetWindowBackground (si->dpy, si->splash_dialog, sp->background);

  sp->logo_pixmap = xscreensaver_logo (ssi->screen, 
                                       /* same visual as si->splash_dialog */
                                       DefaultVisualOfScreen (ssi->screen),
                                       si->splash_dialog, cmap,
                                       sp->background, 
                                       &sp->logo_pixels, &sp->logo_npixels,
                                       &sp->logo_clipmask, True);

  XMapRaised (si->dpy, si->splash_dialog);
  XSync (si->dpy, False);

  si->sp_data = sp;

  sp->timer = XtAppAddTimeOut (si->app, si->prefs.splash_duration,
			       unsplash_timer, (XtPointer) si);

  draw_splash_window (si);
  XSync (si->dpy, False);
}
コード例 #23
0
ファイル: rocks.c プロジェクト: BuBuaBu/bang-screensaver
static void *
rocks_init (Display *d, Window w)
{
  struct state *st = (struct state *) calloc (1, sizeof(*st));
  int i;
  XGCValues gcv;
  Colormap cmap;
  XWindowAttributes xgwa;
  unsigned int bg;
  st->dpy = d;
  st->window = w;
  XGetWindowAttributes (st->dpy, st->window, &xgwa);

  st->width = xgwa.width;
  st->height = xgwa.height;
  st->midx = st->width/2;
  st->midy = st->height/2;

  cmap = xgwa.colormap;
  st->delay = get_integer_resource (st->dpy, "delay", "Integer");
  if (st->delay < 0) st->delay = 0;
  st->speed = get_integer_resource (st->dpy, "speed", "Integer");
  if (st->speed < 1) st->speed = 1;
  if (st->speed > 100) st->speed = 100;
  st->rotate_p = get_boolean_resource (st->dpy, "rotate", "Boolean");
  st->move_p = get_boolean_resource (st->dpy, "move", "Boolean");
  if (mono_p)
    st->ncolors = 2;
  else
    st->ncolors = get_integer_resource (st->dpy, "colors", "Colors");

  if (st->ncolors < 2)
    {
      st->ncolors = 2;
      mono_p = True;
  }

  st->colors = (XColor *) malloc(st->ncolors * sizeof(*st->colors));
  st->draw_gcs = (GC *) malloc(st->ncolors * sizeof(*st->draw_gcs));

  bg = get_pixel_resource (st->dpy, cmap, "background", "Background");
  st->colors[0].pixel = bg;
  st->colors[0].flags = DoRed|DoGreen|DoBlue;
  XQueryColor(st->dpy, cmap, &st->colors[0]);

  st->ncolors--;
  make_random_colormap(xgwa.screen, xgwa.visual, cmap,
                       st->colors+1, &st->ncolors, True,
		       True, 0, True);
  st->ncolors++;

  if (st->ncolors < 2)
    {
      st->ncolors = 2;
      mono_p = True;
  }

  if (mono_p)
    {
      unsigned int fg = get_pixel_resource(st->dpy, cmap, "foreground", "Foreground");
      st->colors[1].pixel = fg;
      st->colors[1].flags = DoRed|DoGreen|DoBlue;
      XQueryColor(st->dpy, cmap, &st->colors[1]);
      gcv.foreground = fg;
      gcv.background = bg;
      st->draw_gcs[0] = XCreateGC (st->dpy, st->window, GCForeground|GCBackground, &gcv);
      st->draw_gcs[1] = st->draw_gcs[0];
    }
  else
    for( i = 0; i < st->ncolors; i++ )
      {
	gcv.foreground = st->colors[i].pixel;
	gcv.background = bg;
	st->draw_gcs[i] = XCreateGC (st->dpy, st->window, GCForeground|GCBackground, &gcv);
      }

  gcv.foreground = bg;
  st->erase_gc = XCreateGC (st->dpy, st->window, GCForeground|GCBackground, &gcv);

  st->max_dep = (st->move_p ? MAX_DEP : 0);

  for (i = 0; i < SIN_RESOLUTION; i++)
    {
      st->sins [i] = sin ((((double) i) / (SIN_RESOLUTION / 2)) * M_PI);
      st->coss [i] = cos ((((double) i) / (SIN_RESOLUTION / 2)) * M_PI);
    }
  /* we actually only need i/speed of these, but wtf */
  for (i = 1; i < (sizeof (st->depths) / sizeof (st->depths[0])); i++)
    st->depths [i] = atan (((double) 0.5) / (((double) i) / DEPTH_SCALE));
  st->depths [0] = M_PI/2; /* avoid division by 0 */

  st->threed = get_boolean_resource(st->dpy, "use3d", "Boolean");
  if (st->threed)
    {
      gcv.background = bg;
      gcv.foreground = get_pixel_resource (st->dpy, cmap, "left3d", "Foreground");
      st->threed_left_gc = XCreateGC (st->dpy, st->window, GCForeground|GCBackground,&gcv);
      gcv.foreground = get_pixel_resource (st->dpy, cmap, "right3d", "Foreground");
      st->threed_right_gc = XCreateGC (st->dpy, st->window,GCForeground|GCBackground,&gcv);
      st->threed_delta = get_float_resource(st->dpy, "delta3d", "Integer");
    }

  /* don't want any exposure events from XCopyPlane */
  for( i = 0; i < st->ncolors; i++)
    XSetGraphicsExposures (st->dpy, st->draw_gcs[i], False);
  XSetGraphicsExposures (st->dpy, st->erase_gc, False);

  st->nrocks = get_integer_resource (st->dpy, "count", "Count");
  if (st->nrocks < 1) st->nrocks = 1;
  st->rocks = (struct rock *) calloc (st->nrocks, sizeof (struct rock));
  init_pixmaps (st);
  XClearWindow (st->dpy, st->window);
  return st;
}
コード例 #24
0
ファイル: xrayswarm.c プロジェクト: Ro6afF/XScreenSaver
static int initGraphics(struct state *st)
{
  XGCValues xgcv;
  XWindowAttributes xgwa;
/*  XSetWindowAttributes xswa;*/
  Colormap cmap;
  XColor color;
  int n, i;
  
  initCMap(st);

  XGetWindowAttributes(st->dpy,st->win,&xgwa);
  cmap=xgwa.colormap;
/*  xswa.backing_store=Always;
  XChangeWindowAttributes(st->dpy,st->win,CWBackingStore,&xswa);*/
  xgcv.function=GXcopy;

  st->delay = get_integer_resource(st->dpy, "delay","Integer");
  
  xgcv.foreground=get_pixel_resource (st->dpy, cmap, "background", "Background");
  st->fgc[0]=XCreateGC(st->dpy, st->win, GCForeground|GCFunction,&xgcv);
#ifdef HAVE_JWXYZ
  jwxyz_XSetAntiAliasing (st->dpy, st->fgc[0], False);
#endif
  
  n=0;
  if (mono_p) {
    xgcv.foreground=get_pixel_resource (st->dpy, cmap, "foreground", "Foreground");
    st->fgc[1]=XCreateGC(st->dpy,st->win,GCForeground|GCFunction,&xgcv);
#ifdef HAVE_JWXYZ
    jwxyz_XSetAntiAliasing (st->dpy, st->fgc[1], False);
#endif
    for (i=0;i<st->numColors;i+=2) st->fgc[i]=st->fgc[0];
    for (i=1;i<st->numColors;i+=2) st->fgc[i]=st->fgc[1];
  } else {
    for (i = 0; i < st->numColors; i++) {
      color.red=st->colors[n++]<<8;
      color.green=st->colors[n++]<<8;
      color.blue=st->colors[n++]<<8;
      color.flags=DoRed|DoGreen|DoBlue;
      XAllocColor(st->dpy,cmap,&color);
      xgcv.foreground=color.pixel;
      st->fgc[i] = XCreateGC(st->dpy, st->win, GCForeground | GCFunction,&xgcv);
#ifdef HAVE_JWXYZ
      jwxyz_XSetAntiAliasing (st->dpy, st->fgc[i], False);
#endif
    }
  }
  st->cgc = XCreateGC(st->dpy,st->win,GCForeground|GCFunction,&xgcv);
  XSetGraphicsExposures(st->dpy,st->cgc,False);
#ifdef HAVE_JWXYZ
  jwxyz_XSetAntiAliasing (st->dpy, st->cgc, False);
#endif

  st->xsize = xgwa.width;
  st->ysize = xgwa.height;
  st->xc = st->xsize >> 1;
  st->yc = st->ysize >> 1;

  st->maxx = 1.0;
  st->maxy = st->ysize/(float)st->xsize;

  if (st->colorScheme < 0) st->colorScheme = random()%NUM_SCHEMES;

  return True;
}
コード例 #25
0
void createDialog(AppInfo *app)
{
   DialogInfo *d;
   char *labelText;
   
   if (app->dialog) {
      return;
   }
   d = malloc(sizeof(*d));
   if (NULL == d) {
      outOfMemory(app, __LINE__);
   }
   memset(d, 0, sizeof(*d));

   app->grabKeyboard = 
      get_boolean_resource("grabKeyboard", "GrabKeyboard", True);
   app->grabPointer =
      get_boolean_resource("grabPointer", "GrabPointer", False);
   app->grabServer =
      get_boolean_resource("grabServer", "GrabServer", False);

   /* inputTimeout resource specified in seconds for easy human interface.
    * Convert to milliseconds here.
    */
   app->inputTimeout = (unsigned long) 1000 *
      getUnsignedIntegerResource(app, "inputTimeout", "InputTimeout", 0);
   
   app->defaultXResolution =
      getResolutionResource(app, "defaultXResolution", "DefaultXResolution",
			    "75/in");
   app->defaultYResolution =
      getResolutionResource(app, "defaultYResolution", "DefaultYResolution",
			    "75/in");
   app->xFuzz =
      getResolutionResource(app, "xResolutionFuzz", "XResolutionFuzz", "20/in");
   app->yFuzz =
      getResolutionResource(app, "yResolutionFuzz", "YResolutionFuzz", "20/in");
   
   d->title =
      getStringResourceWithDefault("dialog.title", "Dialog.Title",
				   "OpenSSH Authentication Passphrase Request");
   d->w3.w.foreground =
      get_pixel_resource("foreground", "Foreground",
			 app->dpy, app->colormap, app->black);
   d->w3.w.background =
      get_pixel_resource("background", "Background",
			 app->dpy, app->colormap, app->white);
   d->w3.topShadowColor =
      get_pixel_resource("topShadowColor", "TopShadowColor",
			 app->dpy, app->colormap, app->white);
   d->w3.bottomShadowColor =
      get_pixel_resource("bottomShadowColor", "BottomShadowColor",
			 app->dpy, app->colormap, app->black);
   d->w3.shadowThickness =
      get_integer_resource("shadowThickness", "ShadowThickness", 3);
   d->w3.borderColor =
      get_pixel_resource("borderColor", "BorderColor",
			 app->dpy, app->colormap, app->black);
   d->w3.borderWidth =
      get_integer_resource("borderWidth", "BorderWidth", 1);
   
   d->w3.horizontalSpacing = scaleXDimension(app,
      get_integer_resource("horizontalSpacing", "Spacing", 5));
   d->w3.verticalSpacing = scaleYDimension(app,
      get_integer_resource("verticalSpacing", "Spacing", 6));
   
   if (2 == app->argc) {
      labelText = strdup(app->argv[1]);
   } else {
      labelText =
	 getStringResourceWithDefault("dialog.label", "Dialog.Label",
				      "Please enter your authentication passphrase:");
   }
   createLabel(app, labelText, &(d->label));
   freeIf(labelText);
   d->label.font = getFontResource(app, "dialog.font", "Dialog.Font");
   calcLabelTextExtents(&(d->label));
   d->label.w.foreground = d->w3.w.foreground;
   d->label.w.background = d->w3.w.background;
   
   d->okButton.w3.w.foreground =
      get_pixel_resource("okButton.foreground", "Button.Foreground",
			 app->dpy, app->colormap, app->black);
   d->okButton.w3.w.background =
      get_pixel_resource("okButton.background", "Button.Background",
			 app->dpy, app->colormap, app->white);
   d->okButton.w3.topShadowColor =
      get_pixel_resource("okButton.topShadowColor", "Button.TopShadowColor",
			 app->dpy, app->colormap, app->white);
   d->okButton.w3.bottomShadowColor =
      get_pixel_resource("okButton.bottomShadowColor",
			 "Button.BottomShadowColor",
			 app->dpy, app->colormap, app->black);
   d->okButton.w3.shadowThickness =
      get_integer_resource("okButton.shadowThickness",
			   "Button.ShadowThickness", 2);
   d->okButton.w3.borderColor =
      get_pixel_resource("okButton.borderColor", "Button.BorderColor",
			 app->dpy, app->colormap, app->black);
   d->okButton.w3.borderWidth =
      get_integer_resource("okButton.borderWidth", "Button.BorderWidth", 1);
   d->okButton.w3.horizontalSpacing = scaleXDimension(app,
      get_integer_resource("okButton.horizontalSpacing", "Button.Spacing", 4));
   d->okButton.w3.verticalSpacing = scaleYDimension(app,
      get_integer_resource("okButton.verticalSpacing", "Button.Spacing", 2));
   labelText =
      getStringResourceWithDefault("okButton.label", "Button.Label", "OK");
   createLabel(app, labelText, &(d->okButton.label));
   freeIf(labelText);
   d->okButton.label.font =
      getFontResource(app, "okButton.font", "Button.Font");
   calcButtonExtents(&(d->okButton));
   d->okButton.label.w.foreground = d->okButton.w3.w.foreground;
   d->okButton.label.w.background = d->okButton.w3.w.background;
   
   d->cancelButton.w3.w.foreground =
      get_pixel_resource("cancelButton.foreground", "Button.Foreground",
			 app->dpy, app->colormap, app->black);
   d->cancelButton.w3.w.background =
      get_pixel_resource("cancelButton.background", "Button.Background",
			 app->dpy, app->colormap, app->white);
   d->cancelButton.w3.topShadowColor =
      get_pixel_resource("cancelButton.topShadowColor",
			 "Button.TopShadowColor",
			 app->dpy, app->colormap, app->white);
   d->cancelButton.w3.bottomShadowColor =
      get_pixel_resource("cancelButton.bottomShadowColor",
			 "Button.BottomShadowColor",
			 app->dpy, app->colormap, app->black);
   d->cancelButton.w3.shadowThickness =
      get_integer_resource("cancelButton.shadowThickness",
			   "Button.ShadowThickness", 2);
   d->cancelButton.w3.borderColor =
      get_pixel_resource("cancelButton.borderColor", "Button.BorderColor",
			 app->dpy, app->colormap, app->black);
   d->cancelButton.w3.borderWidth =
      get_integer_resource("cancelButton.borderWidth", "Button.BorderWidth",
			   1);
   d->cancelButton.w3.horizontalSpacing = scaleXDimension(app,
      get_integer_resource("cancelButton.horizontalSpacing", "Button.Spacing",
			   4));
   d->cancelButton.w3.verticalSpacing = scaleYDimension(app,
      get_integer_resource("cancelButton.verticalSpacing", "Button.Spacing",
			   2));
   labelText =
      getStringResourceWithDefault("cancelButton.label", "Button.Label",
				   "Cancel");
   createLabel(app, labelText, &(d->cancelButton.label));
   freeIf(labelText);
   d->cancelButton.label.font =
      getFontResource(app, "cancelButton.font", "Button.Font");
   calcButtonExtents(&(d->cancelButton));
   d->cancelButton.label.w.foreground = d->cancelButton.w3.w.foreground;
   d->cancelButton.label.w.background = d->cancelButton.w3.w.background;

   balanceButtonExtents(&(d->okButton), &(d->cancelButton));
   
   d->indicator.w3.w.foreground =
      get_pixel_resource("indicator.foreground", "Indicator.Foreground",
			 app->dpy, app->colormap, app->black);
   d->indicator.w3.w.background =
      get_pixel_resource("indicator.background", "Indicator.Background",
			 app->dpy, app->colormap, app->white);
   d->indicator.w3.w.width = scaleXDimension(app,
      get_integer_resource("indicator.width", "Indicator.Width", 15));
   d->indicator.w3.w.height = scaleYDimension(app,
      get_integer_resource("indicator.height", "Indicator.Height", 7));
   d->indicator.w3.topShadowColor =
      get_pixel_resource("indicator.topShadowColor",
			 "Indicator.TopShadowColor",
			 app->dpy, app->colormap, app->white);
   d->indicator.w3.bottomShadowColor =
      get_pixel_resource("indicator.bottomShadowColor",
			 "Indicator.BottomShadowColor",
			 app->dpy, app->colormap, app->black);
   d->indicator.w3.shadowThickness =
      get_integer_resource("indicator.shadowThickness",
			   "Indicator.ShadowThickness", 2);
   d->indicator.w3.borderColor =
      get_pixel_resource("indicator.borderColor", "Indicator.BorderColor",
			 app->dpy, app->colormap, app->black);
   d->indicator.w3.borderWidth =
      get_integer_resource("indicator.borderWidth", "Indicator.BorderWidth",
			   0);
   d->indicator.w3.horizontalSpacing = scaleXDimension(app,
      get_integer_resource("indicator.horizontalSpacing", "Indicator.Spacing",
			   2));
   d->indicator.w3.verticalSpacing =scaleYDimension(app,
      get_integer_resource("indicator.verticalSpacing", "Indicator.Spacing",
			   4));
   d->indicator.minimumCount =
      get_integer_resource("indicator.minimumCount", "Indicator.MinimumCount",
			   8);
   d->indicator.maximumCount =
      get_integer_resource("indicator.maximumCount", "Indicator.MaximumCount",
			   24);
   d->indicator.w3.interiorWidth = d->indicator.w3.w.width;
   d->indicator.w3.interiorHeight = d->indicator.w3.w.height;
   d->indicator.w3.w.width += (2 * d->indicator.w3.shadowThickness);
   d->indicator.w3.w.width += (2 * d->indicator.w3.borderWidth);
   d->indicator.w3.w.height += (2 * d->indicator.w3.shadowThickness);
   d->indicator.w3.w.height += (2 * d->indicator.w3.borderWidth);
   {
      /* Make sure the indicators can all fit on the screen.
       * 80% of the screen width seems fine.
       */
      Dimension maxWidth = (WidthOfScreen(app->screen) * 8 / 10);
      Dimension extraSpace = ((2 * d->w3.horizontalSpacing) +
			      (2 * d->w3.shadowThickness));
      
      if (d->indicator.maximumCount < 8) {
	 d->indicator.maximumCount = 8;
      }
      if (((d->indicator.maximumCount * d->indicator.w3.w.width) +
	   ((d->indicator.maximumCount - 1) *
	    d->indicator.w3.horizontalSpacing) + extraSpace) > maxWidth) {
	 d->indicator.maximumCount =
	    ((maxWidth - extraSpace - d->indicator.w3.w.width) /
	     (d->indicator.w3.w.width + d->indicator.w3.horizontalSpacing))
	    + 1;
      }
      if (d->indicator.minimumCount <= 6) {
	 d->indicator.minimumCount = 6;
      }
      if (d->indicator.minimumCount > d->indicator.maximumCount) {
	 d->indicator.minimumCount = d->indicator.maximumCount;
      }
   }
   
   {
      /* Calculate the width and horizontal position of things. */
      Dimension labelAreaWidth;
      Dimension buttonAreaWidth;
      Dimension indicatorAreaWidth;
      Dimension extraIndicatorSpace;
      Dimension singleIndicatorSpace;
      Dimension interButtonSpace;
      Dimension w;
      Position leftX;
      int i;
      
      labelAreaWidth = d->label.w.width + (2 * d->w3.horizontalSpacing);
      buttonAreaWidth = ((3 * d->w3.horizontalSpacing) +
			 d->okButton.w3.w.width +
			 d->cancelButton.w3.w.width);
      w = MAX(labelAreaWidth, buttonAreaWidth);
      extraIndicatorSpace = ((2 * d->w3.horizontalSpacing) +
			     d->indicator.w3.w.width);
      singleIndicatorSpace = (d->indicator.w3.w.width +
			      d->indicator.w3.horizontalSpacing);
      d->indicator.count = ((w - extraIndicatorSpace) / singleIndicatorSpace);
      d->indicator.current = 0;
      d->indicator.count++; /* For gatepost indicator in extra space. */
      if (((w - extraIndicatorSpace) % singleIndicatorSpace) >
	  (singleIndicatorSpace / 2)) {
	 d->indicator.count++;
      }
      if (d->indicator.count < d->indicator.minimumCount) {
	 d->indicator.count = d->indicator.minimumCount;
      }
      if (d->indicator.count > d->indicator.maximumCount) {
	 d->indicator.count = d->indicator.maximumCount;
      }
      indicatorAreaWidth = ((singleIndicatorSpace * (d->indicator.count - 1)) +
			    extraIndicatorSpace);
      d->w3.interiorWidth = MAX(w, indicatorAreaWidth);
      d->w3.w.width = d->w3.interiorWidth + (2 * d->w3.shadowThickness);

      leftX = (d->w3.w.width - d->label.w.width) / 2;
      d->label.w.x = leftX;
      
      leftX = ((d->w3.w.width -
	       (d->indicator.count * d->indicator.w3.w.width) -
	       ((d->indicator.count - 1) * d->indicator.w3.horizontalSpacing))
	       / 2);
      {
	 int n = d->indicator.count * sizeof(IndicatorElement);
	 d->indicators = malloc(n);
	 if (NULL == d->indicators) {
	    destroyDialog(app);
	    outOfMemory(app, __LINE__);
	 }
	 memset(d->indicators, 0, n);
      }
      d->indicators[0].parent = &(d->indicator);
      d->indicators[0].w.x = d->indicator.w3.w.x = leftX;
      d->indicators[0].w.width = d->indicator.w3.w.width;
      d->indicators[0].isLit = False;
      for (i = 1; i < d->indicator.count; i++) {
	 d->indicators[i].parent = &(d->indicator);
	 d->indicators[i].w.x = (d->indicators[i - 1].w.x +
				 d->indicator.w3.w.width +
				 d->indicator.w3.horizontalSpacing);
	 d->indicators[i].w.width = d->indicator.w3.w.width;
	 d->indicators[i].isLit = False;
      }
      interButtonSpace = ((d->w3.interiorWidth - d->okButton.w3.w.width -
			   d->cancelButton.w3.w.width) / 3);
      d->okButton.w3.w.x = interButtonSpace + d->w3.shadowThickness;
      d->cancelButton.w3.w.x = (d->okButton.w3.w.x + d->okButton.w3.w.width +
				interButtonSpace);
   }
   {
      /* Calculate the height and vertical position of things. */
      int i;
      
      d->w3.interiorHeight = ((4 * d->w3.verticalSpacing) +
			      (2 * d->indicator.w3.verticalSpacing) +
			      d->label.w.height +
			      d->indicator.w3.w.height +
			      d->okButton.w3.w.height);
      d->w3.w.height = d->w3.interiorHeight + (2 * d->w3.shadowThickness);
      d->label.w.y = d->w3.shadowThickness + d->w3.verticalSpacing;
      d->indicator.w3.w.y = (d->label.w.y + d->label.w.height +
			     d->w3.verticalSpacing +
			     d->indicator.w3.verticalSpacing);
      for (i = 0; i < d->indicator.count; i++) {
	 d->indicators[i].w.y = d->indicator.w3.w.y;
	 d->indicators[i].w.height = d->indicator.w3.w.height;
      }
      d->okButton.w3.w.y = d->cancelButton.w3.w.y =
	 (d->indicator.w3.w.y + d->indicator.w3.w.height +
	  d->w3.verticalSpacing + d->indicator.w3.verticalSpacing);
   }
   calcButtonLabelPosition(&(d->okButton));
   calcButtonLabelPosition(&(d->cancelButton));

   d->w3.w.x = (WidthOfScreen(app->screen) - d->w3.w.width) / 2;
   d->w3.w.y = (HeightOfScreen(app->screen) - d->w3.w.height) / 3;
   
   app->dialog = d;
}
コード例 #26
0
ファイル: critical.c プロジェクト: MaddTheSane/xscreensaver
static void *
critical_init (Display *dpy, Window window)
{
  struct state *st = (struct state *) calloc (1, sizeof(*st));
  int			model_w, model_h;
  st->dpy = dpy;
  st->window = window;

  /* Find window attributes */
  XGetWindowAttributes (st->dpy, st->window, &st->wattr);

  st->batchcount = get_integer_resource (st->dpy, "batchcount", "Integer");
  if (st->batchcount < 5)
    st->batchcount = 5;

  st->lines_per_color = 10;

  /* For the moment the model size is just fixed -- making it vary
     with the screen size just makes the hack boring on large
     screens. */
  model_w = 80;
  st->settings.cell_size = st->wattr.width / model_w;
  model_h = st->settings.cell_size ?
    st->wattr.height / st->settings.cell_size : 1;

  /* Construct the initial model state. */

  st->settings.trail = clip(2, get_integer_resource (st->dpy, "trail", "Integer"), 1000);
  
  st->history = calloc (st->settings.trail, sizeof (st->history[0]));
  if (!st->history)
    {
      fprintf (stderr, "critical: "
	       "couldn't allocate trail history of %d cells\n",
	       st->settings.trail);
      abort();
    }

  st->model = model_allocate (model_w, model_h);
  if (!st->model)
    {
      fprintf (stderr, "critical: error preparing the model\n");
      abort();
    }
  
  /* make a black gc for the background */
  st->gcv.foreground = get_pixel_resource (st->dpy, st->wattr.colormap,
                                       "background", "Background");
  st->bgc = XCreateGC (st->dpy, st->window, GCForeground, &st->gcv);

  st->fgc = XCreateGC (st->dpy, st->window, 0, &st->gcv);

#ifdef HAVE_JWXYZ
  jwxyz_XSetAntiAliasing (dpy, st->fgc, False);
  jwxyz_XSetAntiAliasing (dpy, st->bgc, False);
#endif

  st->delay_usecs = get_integer_resource (st->dpy, "delay", "Integer");
  st->n_restart = get_integer_resource (st->dpy, "restart", "Integer");
    
  setup_colormap (st, &st->d_colors, &st->d_n_colors);
  model_initialize (st->model);
  model_step (st->model, &st->history[0]);
  st->d_pos = 1;
  st->d_wrapped = 0;
  st->i_restart = 0;
  st->d_i_batch = st->batchcount;

  return st;
}
コード例 #27
0
ファイル: penetrate.c プロジェクト: RazZziel/pongclock
static void *
penetrate_init (Display *dpy, Window window)
{
  struct state *st = (struct state *) calloc (1, sizeof(*st));
  int i;
  /*char *fontname =   "-*-new century schoolbook-*-r-*-*-*-380-*-*-*-*-*-*"; */
  char *fontname =   "-*-courier-*-r-*-*-*-380-*-*-*-*-*-*";
  XGCValues gcv;
  XWindowAttributes xgwa;

  st->dpy = dpy;
  st->window = window;

  XGetWindowAttributes (st->dpy, st->window, &xgwa);
  st->cmap = xgwa.colormap;

  st->lrate = 80;
  st->nextBonus = kFirstBonus;
  st->aim = 180;

  st->smart = get_boolean_resource(st->dpy, "smart","Boolean");
  st->bgrowth = get_integer_resource (st->dpy, "bgrowth", "Integer");
  st->lrate = get_integer_resource (st->dpy, "lrate", "Integer");
  if (st->bgrowth < 0) st->bgrowth = 2;
  if (st->lrate < 0) st->lrate = 2;
  st->startlrate = st->lrate;

  if (!fontname || !*fontname)
    fprintf (stderr, "%s: no font specified.\n", progname);
  st->font = XLoadQueryFont(st->dpy, fontname);
  if (!st->font)
    fprintf (stderr, "%s: could not load font %s.\n", progname, fontname);

  if (!(st->scoreFont = XLoadQueryFont(st->dpy, "-*-times-*-r-*-*-*-180-*-*-*-*-*-*")))
	 fprintf(stderr, "%s: Can't load Times font.", progname);

  for (i = 0; i < kMaxMissiles; i++)
    st->missile[i].alive = 0;

  for (i = 0; i < kMaxLasers; i++)
    st->laser[i].alive = 0;

  for (i = 0; i < kMaxBooms; i++)
    st->boom[i].alive = 0;

  for (i = 0; i < kNumCities; i++) {
	 City *m = &st->city[i];
    m->alive = 1;
	 m->color.red = m->color.green = m->color.blue = 0xFFFF;
	 m->color.blue = 0x1111; m->color.green = 0x8888;
	 m->color.flags = DoRed | DoGreen | DoBlue;
	 if (!XAllocColor (st->dpy, st->cmap, &m->color)) {
		m->color.pixel = WhitePixel (st->dpy, DefaultScreen (st->dpy));
		m->color.red = m->color.green = m->color.blue = 0xFFFF;
	 }
  }

  gcv.foreground = st->default_fg_pixel =
    get_pixel_resource(st->dpy, st->cmap, "foreground", "Foreground");
  gcv.font = st->scoreFont->fid;
  st->draw_gc = XCreateGC(st->dpy, st->window, GCForeground | GCFont, &gcv);
  gcv.font = st->font->fid;
  st->level_gc = XCreateGC(st->dpy, st->window, GCForeground | GCFont, &gcv);
  XSetForeground (st->dpy, st->level_gc, st->city[0].color.pixel);
  gcv.foreground = get_pixel_resource(st->dpy, st->cmap, "background", "Background");
  st->erase_gc = XCreateGC(st->dpy, st->window, GCForeground, &gcv);

# ifdef HAVE_COCOA
  jwxyz_XSetAntiAliasing (st->dpy, st->erase_gc, False);
  jwxyz_XSetAntiAliasing (st->dpy, st->draw_gc, False);
# endif


  /* make a gray color for score */
  if (!mono_p) {
	 st->scoreColor.red = st->scoreColor.green = st->scoreColor.blue = 0xAAAA;
	 st->scoreColor.flags = DoRed | DoGreen | DoBlue;
	 if (!XAllocColor (st->dpy, st->cmap, &st->scoreColor)) {
		st->scoreColor.pixel = WhitePixel (st->dpy, DefaultScreen (st->dpy));
		st->scoreColor.red = st->scoreColor.green = st->scoreColor.blue = 0xFFFF;
	 }
  }

  XClearWindow(st->dpy, st->window);
  return st;
}
コード例 #28
0
ファイル: decayscreen.c プロジェクト: RazZziel/pongclock
static void *
decayscreen_init (Display *dpy, Window window)
{
  struct state *st = (struct state *) calloc (1, sizeof(*st));
  XGCValues gcv;
  XWindowAttributes xgwa;
  long gcflags;
  unsigned long bg;
  char *s;

  st->dpy = dpy;
  st->window = window;

  s = get_string_resource(st->dpy, "mode", "Mode");
  if      (s && !strcmp(s, "shuffle")) st->mode = SHUFFLE;
  else if (s && !strcmp(s, "up")) st->mode = UP;
  else if (s && !strcmp(s, "left")) st->mode = LEFT;
  else if (s && !strcmp(s, "right")) st->mode = RIGHT;
  else if (s && !strcmp(s, "down")) st->mode = DOWN;
  else if (s && !strcmp(s, "upleft")) st->mode = UPLEFT;
  else if (s && !strcmp(s, "downleft")) st->mode = DOWNLEFT;
  else if (s && !strcmp(s, "upright")) st->mode = UPRIGHT;
  else if (s && !strcmp(s, "downright")) st->mode = DOWNRIGHT;
  else if (s && !strcmp(s, "in")) st->mode = IN;
  else if (s && !strcmp(s, "out")) st->mode = OUT;
  else if (s && !strcmp(s, "melt")) st->mode = MELT;
  else if (s && !strcmp(s, "stretch")) st->mode = STRETCH;
  else if (s && !strcmp(s, "fuzz")) st->mode = FUZZ;
  else {
    if (s && *s && !!strcmp(s, "random"))
      fprintf(stderr, "%s: unknown mode %s\n", progname, s);
    st->mode = random() % (FUZZ+1);
  }

  st->delay = get_integer_resource (st->dpy, "delay", "Integer");

  if (st->delay < 0) st->delay = 0;

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

  gcv.function = GXcopy;
  gcv.subwindow_mode = IncludeInferiors;
  bg = get_pixel_resource (st->dpy, xgwa.colormap, "background", "Background");
  gcv.foreground = bg;

  gcflags = GCForeground | GCFunction;
  if (use_subwindow_mode_p(xgwa.screen, st->window)) /* see grabscreen.c */
    gcflags |= GCSubwindowMode;
  st->gc = XCreateGC (st->dpy, st->window, gcflags, &gcv);

  st->sizex = xgwa.width;
  st->sizey = xgwa.height;

  if (st->mode == MELT || st->mode == STRETCH)
    st->iterations = 1;    /* slow down for smoother melting */

  st->img_loader = load_image_async_simple (0, xgwa.screen, st->window,
                                            st->window, 0, 0);

  return st;
}
コード例 #29
0
ファイル: whirlygig.c プロジェクト: MaddTheSane/xscreensaver
static void *
whirlygig_init (Display *dpy, Window window)
{
  struct state *st = (struct state *) calloc (1, sizeof(*st));
  st->dpy = dpy;
  st->window = window;

  st->ncolors = NCOLORS;

    st->dbuf = get_boolean_resource (st->dpy, "doubleBuffer", "Boolean");

# ifdef HAVE_JWXYZ	/* Don't second-guess Quartz's double-buffering */
    st->dbuf = False;
# endif

    st->start_time = st->current_time;
    st->info = (struct info *)malloc(sizeof(struct info));

    st->screen = DefaultScreen(st->dpy);
    XGetWindowAttributes (st->dpy, st->window, &st->xgwa);
    if (st->dbuf)
      {
#ifdef HAVE_DOUBLE_BUFFER_EXTENSION
        if (get_boolean_resource(st->dpy,"useDBE","Boolean"))
          {
            st->dbeclear_p = get_boolean_resource (st->dpy, "useDBEClear",
                                                   "Boolean");
            if (st->dbeclear_p)
              st->b = xdbe_get_backbuffer (st->dpy, st->window, XdbeBackground);
            else
              st->b = xdbe_get_backbuffer (st->dpy, st->window, XdbeUndefined);
            st->backb = st->b;
          }
#endif /* HAVE_DOUBLE_BUFFER_EXTENSION */

	if (!st->b)
	  {
	    st->ba = XCreatePixmap (st->dpy, st->window, st->xgwa.width, st->xgwa.height,st->xgwa.depth);
	    st->b = st->ba;
	  }
      }
    else
      {
	st->b = st->window;
      }

    st->gcv.foreground = get_pixel_resource(st->dpy, st->xgwa.colormap, "foreground", "Foreground");
    st->fgc = XCreateGC (st->dpy, st->b, GCForeground, &st->gcv);
    st->gcv.foreground = get_pixel_resource(st->dpy, st->xgwa.colormap, "background", "Background");
    st->bgc = XCreateGC (st->dpy, st->b, GCForeground, &st->gcv);

#ifdef HAVE_JWXYZ  /* #### should turn off double-buffering instead */
    jwxyz_XSetAntiAliasing (dpy, st->fgc, False);
    jwxyz_XSetAntiAliasing (dpy, st->bgc, False);
#endif

    {
      Bool writable_p = False;
    make_uniform_colormap (st->xgwa.screen, st->xgwa.visual,
                           st->xgwa.colormap, st->colors, &st->ncolors,
                           True, &writable_p, True);
    }

    if (st->ba) XFillRectangle (st->dpy, st->ba, st->bgc, 0, 0, st->xgwa.width, st->xgwa.height);

        /* info is a structure holding all the random pieces of information I may want to 
           pass to my baby functions -- much of it I may never use, but it is nice to
           have around just in case I want it to make a funky function funkier */
/*    info->writable = get_boolean_resource (dpy, "cycle", "Boolean"); */
    st->info->xspeed = get_float_resource(st->dpy, "xspeed" , "Float");
    st->info->yspeed = get_float_resource(st->dpy, "yspeed" , "Float");
    st->info->xamplitude = get_float_resource(st->dpy, "xamplitude", "Float");
    st->info->yamplitude = get_float_resource(st->dpy, "yamplitude", "Float");
    st->info->offset_period = get_float_resource(st->dpy, "offset_period", "Float");
    st->info->whirlies = get_integer_resource(st->dpy, "whirlies", "Integer");
    st->info->nlines = get_integer_resource(st->dpy, "nlines", "Integer");
    st->info->half_width = st->xgwa.width / 2;
    st->info->half_height = st->xgwa.height / 2;
    st->info->speed = get_integer_resource(st->dpy, "speed" , "Integer");
    st->info->trail = get_boolean_resource(st->dpy, "trail", "Integer");
    st->info->color_modifier = get_integer_resource(st->dpy, "color_modifier", "Integer");
    st->info->xoffset = get_float_resource(st->dpy, "xoffset", "Float");
    st->info->yoffset = get_float_resource(st->dpy, "yoffset", "Float");
    st->xmode_str = get_string_resource(st->dpy, "xmode", "Mode");
    st->ymode_str = get_string_resource(st->dpy, "ymode", "Mode");
    st->wrap = get_boolean_resource(st->dpy, "wrap", "Boolean");
    st->modifier = 3000.0 + frand(1500.0);
    if (! st->xmode_str) st->xmode = spin_mode;
    else if (! strcmp (st->xmode_str, "spin")) st->xmode = spin_mode;
    else if (! strcmp (st->xmode_str, "funky")) st->xmode = funky_mode;
    else if (! strcmp (st->xmode_str, "circle")) st->xmode = circle_mode;
    else if (! strcmp (st->xmode_str, "linear")) st->xmode = linear_mode;
    else if (! strcmp (st->xmode_str, "test")) st->xmode = test_mode;
    else if (! strcmp (st->xmode_str, "fun")) st->xmode = fun_mode;
    else if (! strcmp (st->xmode_str, "innie")) st->xmode = innie_mode;
    else if (! strcmp (st->xmode_str, "lissajous")) st->xmode = lissajous_mode;
    else {
        st->xmode = random() % (int) lissajous_mode;
    }
    if (! st->ymode_str) st->ymode = spin_mode;
    else if (! strcmp (st->ymode_str, "spin")) st->ymode = spin_mode;
    else if (! strcmp (st->ymode_str, "funky")) st->ymode = funky_mode;
    else if (! strcmp (st->ymode_str, "circle")) st->ymode = circle_mode;
    else if (! strcmp (st->ymode_str, "linear")) st->ymode = linear_mode;
    else if (! strcmp (st->ymode_str, "test")) st->ymode = test_mode;
    else if (! strcmp (st->ymode_str, "fun")) st->ymode = fun_mode;
    else if (! strcmp (st->ymode_str, "innie")) st->ymode = innie_mode;
    else if (! strcmp (st->ymode_str, "lissajous")) st->ymode = lissajous_mode;
    else {
        st->ymode = random() % (int) lissajous_mode;
    }

    if (get_integer_resource(st->dpy, "start_time", "Integer") == -1)
        st->current_time = (unsigned long int)(random());
    else
        st->current_time = get_integer_resource(st->dpy, "start_time", "Integer");
    if (st->info->whirlies == -1)
        st->info->whirlies = 1 + (random() % 15);
    if (st->info->nlines == -1)
        st->info->nlines = 1 + (random() % 5);
    if (st->info->color_modifier == -1)
        st->info->color_modifier = 1 + (random() % 25);
    if (get_boolean_resource(st->dpy, "explain", "Integer"))
      st->explaining = 1;
    st->current_color = 1 + (random() % NCOLORS);

  return st;
}
コード例 #30
0
static void *
intermomentary_init (Display *dpy, Window window)
{
  struct state *st = (struct state *) calloc (1, sizeof(*st));

#ifdef TIME_ME
    time_t start_time = time(NULL);
#endif

    int tempx;
    XGCValues gcv;

    st->dpy = dpy;
    st->window = window;

    XGetWindowAttributes(dpy, window, &st->xgwa);
 
    st->ncolors = get_integer_resource (st->dpy, "colors", "Colors");
    st->ncolors++;
    st->colors = (XColor *) malloc(sizeof(*st->colors) * (st->ncolors+1));

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

    {
      XColor fgc, bgc;
      int fgh, bgh;
      double fgs, fgv, bgs, bgv;
      fgc.pixel = gcv.foreground;
      bgc.pixel = gcv.background;
      XQueryColor (st->dpy, st->xgwa.colormap, &fgc);
      XQueryColor (st->dpy, st->xgwa.colormap, &bgc);
      rgb_to_hsv (fgc.red, fgc.green, fgc.blue, &fgh, &fgs, &fgv);
      rgb_to_hsv (bgc.red, bgc.green, bgc.blue, &bgh, &bgs, &bgv);
#if 0
      bgh = fgh;
      bgs = fgs;
      bgv = fgv / 10.0;
#endif
      make_color_ramp (st->dpy, st->xgwa.colormap,
                       bgh, bgs, bgv,
                       fgh, fgs, fgv,
                       st->colors, &st->ncolors,
                       False, /* closed */
                       True, False);
    }

    st->f = init_field();

    st->f->height = st->xgwa.height;
    st->f->width = st->xgwa.width;
    st->f->visdepth = st->xgwa.depth;

    st->draw_delay = (get_integer_resource(dpy, "drawDelay", "Integer"));
    st->f->maxrider = (get_integer_resource(dpy, "maxRiders", "Integer"));
    st->f->maxradius = (get_integer_resource(dpy, "maxRadius", "Integer"));
    st->f->initial_discs = (get_integer_resource(dpy, "numDiscs", "Integer"));

    if (st->f->initial_discs <= 10) {
        fprintf(stderr, "%s: Initial discs must be greater than 10\n", progname);
        exit (1);
    }

    if (st->f->maxradius <= 30) {
        fprintf(stderr, "%s: Max radius must be greater than 30\n", progname);
        exit (1);
    }

    if (st->f->maxrider <= 10) {
        fprintf(stderr, "%s: Max riders must be greater than 10\n", progname);
        exit (1);
    }
    
    st->fgc = XCreateGC(dpy, window, GCForeground, &gcv);
    st->copygc = XCreateGC(dpy, window, GCForeground, &gcv);

    st->f->fgcolor = gcv.foreground;
    st->f->bgcolor = gcv.background;

    /* Initialize stuff */
    build_img(dpy, window, st->f);

    for (tempx = 0; tempx < st->f->initial_discs; tempx++) {
        float fx, fy, x, y, r;
        int bt;

        /* Arrange in anti-collapsing circle */
        fx = 0.4 * st->f->width * cos((2 * M_PI) * tempx / st->f->initial_discs);
        fy = 0.4 * st->f->height * sin((2 * M_PI) * tempx / st->f->initial_discs);
        x = frand(st->f->width / 2) + fx;
        y = frand(st->f->height / 2) + fy;
        r = 5 + frand(st->f->maxradius);
        bt = 1;

        if ((random() % 100) < 50)
            bt = -1;

        make_disc(st->f, x, y, bt * fx / 1000.0, bt * fy / 1000.0, r);
        
    }
    
    return st;
}