예제 #1
0
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;
}
예제 #2
0
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;
}
예제 #3
0
static void *
glitchpeg_init (Display *dpy, Window window)
{
  struct state *st = (struct state *) calloc (1, sizeof(*st));
  XGCValues gcv;

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

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

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

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

  st->count = get_integer_resource (st->dpy, "count", "Integer");
  if (st->count < 1) st->count = 1;

  XClearWindow (st->dpy, st->window);

  return st;
}
예제 #4
0
static void *
lcdscrub_init (Display *dpy, Window window)
{
  struct state *st = (struct state *) calloc (1, sizeof(*st));
  XGCValues gcv;
  st->dpy = dpy;
  st->window = window;
  st->delay  = get_integer_resource (st->dpy, "delay",  "Integer");
  st->spread = get_integer_resource (st->dpy, "spread", "Integer");
  st->cycles = get_integer_resource (st->dpy, "cycles", "Integer");

  XGetWindowAttributes (st->dpy, st->window, &st->xgwa);
  gcv.foreground = BlackPixelOfScreen (st->xgwa.screen);
  gcv.background = WhitePixelOfScreen (st->xgwa.screen);
  st->bg = XCreateGC (st->dpy, st->window, GCForeground, &gcv);
  gcv.foreground = WhitePixelOfScreen (st->xgwa.screen);
  gcv.background = BlackPixelOfScreen (st->xgwa.screen);
  st->fg = XCreateGC (st->dpy, st->window, GCForeground, &gcv);

#ifdef HAVE_COCOA
  jwxyz_XSetAntiAliasing (st->dpy, st->fg, False);
  jwxyz_XSetAntiAliasing (st->dpy, st->bg, False);
#endif

  return st;
}
예제 #5
0
static void *
starfish_init (Display *dpy, Window window)
{
  struct state *st = (struct state *) calloc (1, sizeof(*st));
  char *s;
  st->dpy = dpy;
  st->window = window;
  st->delay = get_integer_resource (st->dpy, "delay", "Delay");
  st->delay2 = get_integer_resource (st->dpy, "delay2", "Delay") * 1000000;
/*  st->duration = get_seconds_resource (st->dpy, "duration", "Seconds");*/
  st->duration = get_integer_resource (st->dpy, "duration", "Seconds");
  st->direction = (random() & 1) ? 1 : -1;

  s = get_string_resource (st->dpy, "mode", "Mode");
  if (s && !strcasecmp (s, "blob"))
    st->blob_p = True;
  else if (s && !strcasecmp (s, "zoom"))
    st->blob_p = False;
  else if (!s || !*s || !strcasecmp (s, "random"))
    st->blob_p = !(random() % 3);
  else
    fprintf (stderr, "%s: mode must be blob, zoom, or random", progname);

  if (st->blob_p)
    st->delay *= 3;

  st->starfish = reset_starfish (st);
  return st;
}
예제 #6
0
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
static void *
wormhole_init (Display *dpy, Window window)
{
	struct state *st = (struct state *) calloc (1, sizeof(*st));
  	XGCValues gcv;
	XWindowAttributes attr;

	st->dpy = dpy;
	st->window = window;
#if 1
	st->delay = delay;
	st->make_stars = stars;
	st->z_speed = zspeed;
#else
	st->delay = get_integer_resource(st->dpy,  "delay", "Integer" );
	st->make_stars = get_integer_resource(st->dpy,  "stars", "Integer" );
	st->z_speed = get_integer_resource(st->dpy,  "zspeed", "Integer" );
#endif

	initWormhole( st, &st->worm, st->dpy, st->window );

	st->gc = XCreateGC( st->dpy, st->window, 0, &gcv );
	XGetWindowAttributes( st->dpy, st->window, &attr );
	st->cmap = attr.colormap;

        return st;
}
예제 #8
0
static void *
lcdscrub_init (Display *dpy, Window window)
{
  struct state *st = (struct state *) calloc (1, sizeof(*st));
  XGCValues gcv;
  st->dpy = dpy;
  st->window = window;
  st->delay  = get_integer_resource (st->dpy, "delay",  "Integer");
  st->spread = get_integer_resource (st->dpy, "spread", "Integer");
  st->cycles = get_integer_resource (st->dpy, "cycles", "Integer");

  XGetWindowAttributes (st->dpy, st->window, &st->xgwa);
  gcv.foreground = BlackPixelOfScreen (st->xgwa.screen);
  gcv.background = WhitePixelOfScreen (st->xgwa.screen);
  st->bg  = XCreateGC (st->dpy, st->window, GCForeground, &gcv);
  st->bg2 = XCreateGC (st->dpy, st->window, GCForeground, &gcv);
  gcv.foreground = WhitePixelOfScreen (st->xgwa.screen);
  gcv.background = BlackPixelOfScreen (st->xgwa.screen);
  st->fg = XCreateGC (st->dpy, st->window, GCForeground, &gcv);

#ifdef HAVE_COCOA
  jwxyz_XSetAntiAliasing (st->dpy, st->fg,  False);
  jwxyz_XSetAntiAliasing (st->dpy, st->bg,  False);
  jwxyz_XSetAntiAliasing (st->dpy, st->bg2, False);
#endif

  st->enabled_mask = 0;
# define PREF(R,F) \
   if (get_boolean_resource (st->dpy, R, "Mode")) st->enabled_mask |= (1 << F)
  PREF("modeHW", HORIZ_W);
  PREF("modeHB", HORIZ_B);
  PREF("modeVW", VERT_W);
  PREF("modeVB", VERT_B);
  PREF("modeDW", DIAG_W);
  PREF("modeDB", DIAG_B);
  PREF("modeW",  WHITE);
  PREF("modeB",  BLACK);
  PREF("modeRGB", RGB);
# undef PREF
  if (! st->enabled_mask) 
    {
      fprintf (stderr, "%s: no modes enabled\n", progname);
      exit (1);
    }

  pick_mode (st);

  return st;
}
예제 #9
0
static void Initialize( struct state *st )
{
	XGCValues gcValues;
	XWindowAttributes XWinAttribs;
	/*int iBitsPerPixel;*/

	/* Create the Image for drawing */
	XGetWindowAttributes( st->dpy, st->window, &XWinAttribs );

#if 0
  /* Find the preferred bits-per-pixel. (jwz) */
	{
		int i, pfvc = 0;
		XPixmapFormatValues *pfv = XListPixmapFormats( st->dpy, &pfvc );
		for( i=0; i<pfvc; i++ )
			if( pfv[ i ].depth == XWinAttribs.depth )
			{
				iBitsPerPixel = pfv[ i ].bits_per_pixel;
				break;
			}
		if( pfv )
			XFree (pfv);
	}
#endif

	/*  Create the GC. */
	st->gc = XCreateGC( st->dpy, st->window, 0, &gcValues );

	st->pImage = XCreateImage( st->dpy, XWinAttribs.visual, XWinAttribs.depth, ZPixmap, 0, NULL,
							  XWinAttribs.width, XWinAttribs.height, 8 /*BitmapPad( st->dpy )*/, 0 );
	st->pImage->data = calloc((st->pImage)->bytes_per_line, (st->pImage)->height);

	st->iWinWidth = XWinAttribs.width;
	st->iWinHeight = XWinAttribs.height;

	/*  These are precalculations used in Execute(). */
	st->iBobDiameter = ( ( st->iWinWidth < st->iWinHeight ) ? st->iWinWidth : st->iWinHeight ) / 25;
	st->iBobRadius = st->iBobDiameter / 2;
#ifdef VERBOSE
	printf( "%s: Bob Diameter = %d\n", progname, st->iBobDiameter );
#endif

	st->iWinCenterX = ( XWinAttribs.width / 2 ) - st->iBobRadius;
	st->iWinCenterY = ( XWinAttribs.height / 2 ) - st->iBobRadius;

	st->iVelocity = ( ( st->iWinWidth < st->iWinHeight ) ? st->iWinWidth : st->iWinHeight ) / 150;
	
	/*  Create the Sin and Cosine lookup tables. */
	st->iDegreeCount = get_integer_resource(st->dpy,  "degrees", "Integer" );
	if(      st->iDegreeCount == 0   ) st->iDegreeCount = ( XWinAttribs.width / 6 ) + 400;
	else if( st->iDegreeCount < 90   ) st->iDegreeCount = 90;
	else if( st->iDegreeCount > 5400 ) st->iDegreeCount = 5400;
	CreateTables( st, st->iDegreeCount );
#ifdef VERBOSE
	printf( "%s: Using a %d degree circle.\n", progname, st->iDegreeCount );
#endif /* VERBOSE */
  
	/*  Get the base color. */
	st->sColor = get_string_resource(st->dpy,  "color", "Color" );
}
예제 #10
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;
}
예제 #11
0
static struct field *
init_field(struct state *st)
{
    struct field *f = xrealloc(NULL, sizeof(struct field));
    f->height = 0;
    f->width = 0;
    f->cell_size = get_integer_resource(st->dpy, "cellSize", "Integer");
    f->max_age = get_integer_resource(st->dpy, "maxAge", "Integer");

    if (f->max_age > 255) {
      fprintf (stderr, "%s: max-age must be < 256 (not %d)\n", progname,
               f->max_age);
      exit (1);
    }

    f->cells = NULL;
    f->new_cells = NULL;
    return f;
}
예제 #12
0
static void *
xspirograph_init (Display *dpy, Window window)
{
  struct state *st = (struct state *) calloc (1, sizeof(*st));
  st->dpy = dpy;
  st->window = window;
  st->long_delay = get_integer_resource(st->dpy, "delay", "Integer");
  st->sub_sleep_time = get_integer_resource(st->dpy, "subdelay", "Integer");
  st->num_layers = get_integer_resource(st->dpy, "layers", "Integer");
  st->always_finish_p = get_boolean_resource (st->dpy, "alwaysfinish", "Boolean");
  
  XGetWindowAttributes (st->dpy, st->window, &st->xgwa);

  init_tsg (st);
  st->theta = 1;
  st->drawstate = NEW_LAYER;

  return st;
}
예제 #13
0
text_data *
textclient_open (Display *dpy)
{
  text_data *d = (text_data *) calloc (1, sizeof (*d));

# ifdef DEBUG
  fprintf (stderr, "%s: textclient: init\n", progname);
# endif

  d->dpy = dpy;

  if (get_boolean_resource (dpy, "usePty", "UsePty"))
    {
# ifdef HAVE_FORKPTY
      d->pty_p = True;
# else
      fprintf (stderr,
               "%s: no pty support on this system; using a pipe instead.\n",
               progname);
# endif
    }

  d->subproc_relaunch_delay =
    get_integer_resource (dpy, "relaunchDelay", "Time");
  if (d->subproc_relaunch_delay < 1)
    d->subproc_relaunch_delay = 1;
  d->subproc_relaunch_delay *= 1000;


  d->meta_sends_esc_p = get_boolean_resource (dpy, "metaSendsESC", "Boolean");
  d->swap_bs_del_p    = get_boolean_resource (dpy, "swapBSDEL",    "Boolean");

  d->program = get_string_resource (dpy, "program", "Program");


# ifdef HAVE_FORKPTY
  /* Kludge for MacOS standalone mode: see OSX/SaverRunner.m. */
  {
    const char *s = getenv ("XSCREENSAVER_STANDALONE");
    if (s && *s && strcmp(s, "0"))
      {
        d->pty_p = 1;
        d->program = strdup (getenv ("SHELL"));
#  ifdef DEBUG
        fprintf (stderr, "%s: textclient: standalone: %s\n",
                 progname, d->program);
#  endif
      }
  }
# endif

  start_timer (d);

  return d;
}
예제 #14
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;
}
예제 #15
0
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;
}
예제 #16
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;
}
예제 #17
0
static void *
ccurve_init (Display *dpy, Window window)
{
  struct state *st = (struct state *) calloc (1, sizeof(*st));
    unsigned long int    black           = 0;
    int                  depth           = 0;
    XWindowAttributes    hack_attributes;
    XGCValues            values;
    unsigned long int    white           = 0;

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

    st->delay = get_float_resource (st->dpy, "delay", "Integer");
    st->delay2 = get_float_resource (st->dpy, "pause", "Integer");
    st->maximum_lines = get_integer_resource (st->dpy, "limit", "Integer");
    black = BlackPixel (st->dpy, DefaultScreen (st->dpy));
    white = WhitePixel (st->dpy, DefaultScreen (st->dpy));
    st->background = black;
    XGetWindowAttributes (st->dpy, st->window, &hack_attributes);
    st->width = hack_attributes.width;
    st->height = hack_attributes.height;
    depth = hack_attributes.depth;
    st->color_map = hack_attributes.colormap;
    st->pixmap = XCreatePixmap (st->dpy, st->window, st->width, st->height, depth);
    values.foreground = white;
    values.background = black;
    st->context = XCreateGC (st->dpy, st->window, GCForeground | GCBackground,
			 &values);
    st->color_count = MAXIMUM_COLOR_COUNT;
    make_color_loop (hack_attributes.screen, hack_attributes.visual,
                     st->color_map,
		     0,   1, 1,
		     120, 1, 1,
		     240, 1, 1,
		     st->colors, &st->color_count, True, False);
    if (st->color_count <= 0)
    {
        st->color_count = 1;
        st->colors [0].red = st->colors [0].green = st->colors [0].blue = 0xFFFF;
        XAllocColor (st->dpy, st->color_map, &st->colors [0]);
    }

    st->draw_maximum_x =  1.20;
    st->draw_maximum_y =  0.525;
    st->draw_minimum_x = -0.20;
    st->draw_minimum_y = -0.525;
    st->draw_x2 = 1.0;

    return st;
}
예제 #18
0
static void *
shadebobs_init (Display *dpy, Window window)
{
  struct state *st = (struct state *) calloc (1, sizeof(*st));

#ifdef VERBOSE
	time_t nTime = time( NULL );
	unsigned short iFrame = 0;
#endif  /*  VERBOSE */

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

	st->nShadeBobCount = get_integer_resource(st->dpy,  "count", "Integer" );
	if( st->nShadeBobCount > 64 ) st->nShadeBobCount = 64;
	if( st->nShadeBobCount <  1 ) st->nShadeBobCount = 1;

	if( ( st->aShadeBobs = calloc( st->nShadeBobCount, sizeof(SShadeBob) ) ) == NULL )
	{
		fprintf( stderr, "%s: Could not allocate %d ShadeBobs\n", progname, st->nShadeBobCount );
                abort();
	}
#ifdef VERBOSE 
	printf( "%s: Allocated %d ShadeBobs\n", progname, st->nShadeBobCount );
#endif  /*  VERBOSE */

	Initialize( st );

	for( st->iShadeBob=0; st->iShadeBob<st->nShadeBobCount; st->iShadeBob++ )
		InitShadeBob( st, &st->aShadeBobs[ st->iShadeBob ], st->iShadeBob % 2 );

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

        st->draw_i = 99999999;
        return st;
}
예제 #19
0
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;
}
예제 #20
0
파일: cwaves.c 프로젝트: Zygo/xscreensaver
static void *
cwaves_init (Display *dpy, Window window)
{
  int i;
  XGCValues gcv;
  state *st = (state *) calloc (1, sizeof (*st));

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

  st->debug_p = get_boolean_resource (dpy, "debug", "Boolean");
  st->scale = get_integer_resource (dpy, "scale", "Integer");
  if (st->scale <= 0) st->scale = 1;
  st->ncolors = get_integer_resource (dpy, "ncolors", "Integer");
  if (st->ncolors < 4) st->ncolors = 4;
  st->colors = (XColor *) malloc (sizeof(*st->colors) * (st->ncolors+1));
  make_smooth_colormap (st->xgwa.screen, st->xgwa.visual, st->xgwa.colormap,
                        st->colors, &st->ncolors,
                        True, 0, False);

  st->gc = XCreateGC (st->dpy, st->window, 0, &gcv);
  st->delay = get_integer_resource (dpy, "delay", "Integer");

  st->nwaves  = get_integer_resource (dpy, "nwaves", "Integer");
  st->waves  = (wave *) calloc (st->nwaves,  sizeof(*st->waves));

  for (i = 0; i < st->nwaves; i++)
    {
      st->waves[i].scale  = frand(0.03) + 0.005;
      st->waves[i].offset = frand(M_PI);
      st->waves[i].delta  = (BELLRAND(2)-1) / 15.0;
    }

  return st;
}
예제 #21
0
static void *
petri_init (Display *dpy, Window win)
{
    struct state *st = (struct state *) calloc (1, sizeof(*st));
    st->dpy = dpy;
    st->window = win;

    st->delay = get_integer_resource (st->dpy, "delay", "Delay");
    st->orthlim = 1;

    setup_display (st);
    setup_arr (st);
    randblip (st, 1);
    
    return st;
}
예제 #22
0
/* Construct and return in COLORS and N_COLORS a new set of colors,
   depending on the resource settings.  */
static void
setup_colormap (struct state *st, XColor **colors, int *n_colors)
{
  Bool			writable;
  char const *		color_scheme;

  /* Make a colormap */
  *n_colors = get_integer_resource (st->dpy, "ncolors", "Integer");
  if (*n_colors < 3)
    *n_colors = 3;
  
  *colors = (XColor *) calloc (sizeof(XColor), *n_colors);
  if (!*colors)
    {
      fprintf (stderr, "%s:%d: can't allocate memory for colors\n",
	       __FILE__, __LINE__);
      return;
    }

  writable = False;
  color_scheme = get_string_resource (st->dpy, "colorscheme", "ColorScheme");
  
  if (!strcmp (color_scheme, "random"))
    {
      make_random_colormap (st->wattr.screen, st->wattr.visual,
			    st->wattr.colormap,
			    *colors, n_colors,
			    True, True, &writable, True);
    }
  else if (!strcmp (color_scheme, "smooth"))
    {
      make_smooth_colormap (st->wattr.screen, st->wattr.visual,
			    st->wattr.colormap,
			    *colors, n_colors,
			    True, &writable, True);
    }
  else 
    {
      make_uniform_colormap (st->wattr.screen, st->wattr.visual,
			     st->wattr.colormap,
			     *colors, n_colors, True,
			     &writable, True);
    }
}
예제 #23
0
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;
}
예제 #24
0
/* initialize the user-specifiable params */
static void initParams (struct state *st)
{
    int problems = 0;
    char *s;

    st->delay = get_integer_resource (st->dpy, "delay", "Delay");
    if (st->delay < 0)
    {
	fprintf (stderr, "%s: delay must be at least 0\n", progname);
	problems = 1;
    }

    s = get_string_resource (st->dpy, "mode", "Mode");
    if (!s || !*s || !strcasecmp (s, "scroll"))
      st->mode = BC_SCROLL;
    else if (!strcasecmp (s, "grid"))
      st->mode = BC_GRID;
    else if (!strcasecmp (s, "clock") ||
             !strcasecmp (s, "clock12"))
      st->mode = BC_CLOCK12;
    else if (!strcasecmp (s, "clock24"))
      st->mode = BC_CLOCK24;
    else
      {
	fprintf (stderr, "%s: unknown mode \"%s\"\n", progname, s);
	problems = 1;
      }
    free (s);

    if (st->mode == BC_CLOCK12 || st->mode == BC_CLOCK24)
      st->delay = 10000;  /* only update every 1/10th second */

    if (problems)
    {
	exit (1);
    }
}
예제 #25
0
static unsigned long * SetPalette(struct state *st )
{
	XWindowAttributes XWinAttribs;
	XColor Color, *aColors;
	signed short iColor;
	float nHalfColors;
	
	XGetWindowAttributes( st->dpy, st->window, &XWinAttribs );
	
	Color.red =   RANDOM() % 0xFFFF;
	Color.green = RANDOM() % 0xFFFF;
	Color.blue =  RANDOM() % 0xFFFF;

	if( strcasecmp( st->sColor, "random" ) && !XParseColor( st->dpy, XWinAttribs.colormap, st->sColor, &Color ) )
		fprintf( stderr, "%s: color %s not found in database. Choosing to random...\n", progname, st->sColor );

#ifdef VERBOSE
	printf( "%s: Base color (RGB): <%d, %d, %d>\n", progname, Color.red, Color.green, Color.blue );
#endif  /*  VERBOSE */

	st->iColorCount = get_integer_resource(st->dpy,  "ncolors", "Integer" );
	if( st->iColorCount <   2 )	st->iColorCount = 2;
	if( st->iColorCount > 255 )	st->iColorCount = 255;

	aColors    = calloc( st->iColorCount, sizeof(XColor) );
	st->aiColorVals = calloc( st->iColorCount, sizeof(unsigned long) );
	
	for( iColor=0; iColor<st->iColorCount; iColor++ )
	{
		nHalfColors = st->iColorCount / 2.0F;
		/* Black -> Base Color */
		if( iColor < (st->iColorCount/2) )
		{
			aColors[ iColor ].red   = ( Color.red   / nHalfColors ) * iColor;
			aColors[ iColor ].green = ( Color.green / nHalfColors ) * iColor;
			aColors[ iColor ].blue  = ( Color.blue  / nHalfColors ) * iColor;
		}
		/* Base Color -> White */
		else
		{
			aColors[ iColor ].red   = ( ( ( 0xFFFF - Color.red )   / nHalfColors ) * ( iColor - nHalfColors ) ) + Color.red;
			aColors[ iColor ].green = ( ( ( 0xFFFF - Color.green ) / nHalfColors ) * ( iColor - nHalfColors ) ) + Color.green;
			aColors[ iColor ].blue  = ( ( ( 0xFFFF - Color.blue )  / nHalfColors ) * ( iColor - nHalfColors ) ) + Color.blue;
		}

		if( !XAllocColor( st->dpy, XWinAttribs.colormap, &aColors[ iColor ] ) )
		{
			/* start all over with less colors */	
			XFreeColors( st->dpy, XWinAttribs.colormap, st->aiColorVals, iColor, 0 );
			free( aColors );
			free( st->aiColorVals );
			st->iColorCount--;
			aColors     = calloc( st->iColorCount, sizeof(XColor) );
			st->aiColorVals = calloc( st->iColorCount, sizeof(unsigned long) );
			iColor = -1;
		}
		else
			st->aiColorVals[ iColor ] = aColors[ iColor ].pixel;
	}

	free( aColors );

	XSetWindowBackground( st->dpy, st->window, st->aiColorVals[ 0 ] );

	return st->aiColorVals;
}
예제 #26
0
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;
}
예제 #27
0
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;
}
예제 #28
0
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;
}
예제 #29
0
ENTRYPOINT void
draw_triangle (ModeInfo * mi)
{
    trianglestruct *tp = &triangles[MI_SCREEN(mi)];
    int         d, d2, i, j, delta;

    if (!tp->init_now) {
        draw_mesh(mi, tp, tp->d / 2, MAX_SIZE / tp->d);

        /* The init_now flag will pop up when the scene is complete.
         * Cycles specifies how long to wait, in 1/10 secs.
         TODO: This is wrong for multi-screens ***
         */
        if (tp->init_now) {
#ifndef STANDALONE
            MI_PAUSE(mi) = 2000000;
#else
            if (tp->stage == -1)
            {
                XClearWindow(MI_DISPLAY(mi), MI_WINDOW(mi));
                if (!mono_p)
                {
                    free_colors(mi->xgwa.screen, mi->xgwa.colormap, mi->colors,
                                mi->npixels);
                    mi->npixels =
                        get_integer_resource (mi->dpy, "ncolors", "Integer");
                    make_smooth_colormap (mi->xgwa.screen,
                                          mi->xgwa.visual, mi->xgwa.colormap,
                                          mi->colors, &mi->npixels,
                                          True, &mi->writable_p, True);
                }
            }
#endif
        }
        return;
    }
    if (tp->delta[0] > 0) {
        if (!(++tp->stage)) {
            tp->h[0][0] = (short int) MAX(0, DISPLACE(0, tp->delta[0]));
            tp->h[tp->size][0] = (short int) MAX(0, DISPLACE(0, tp->delta[0]));
            tp->h[0][tp->size] = (short int) MAX(0, DISPLACE(0, tp->delta[0]));
        } else {
            d = 2 << (tp->steps - tp->stage);
            d2 = d / 2;
            delta = tp->delta[tp->stage - 1];

            for (i = 0; i < tp->size; i += d) {
                for (j = 0; j < (tp->size - i); j += d) {
                    tp->h[i + d2][j] = (short int) DISPLACE(tp->h[i][j] +
                                                            tp->h[i + d][j], delta);
                    tp->h[i][j + d2] = (short int) DISPLACE(tp->h[i][j] +
                                                            tp->h[i][j + d], delta);
                    tp->h[i + d2][j + d2] = (short int) DISPLACE(tp->h[i + d][j] +
                                            tp->h[i][j + d], delta);
                }

                tp->init_now = 0;
                tp->i = 0;
                tp->j = 0;
                tp->d = d;
            }
        }
    }
    if (tp->stage == tp->steps) {
        tp->stage = -1;
    }
}
예제 #30
0
파일: lock.c 프로젝트: wenhann/chromiumos
/**
 * info_msg and prompt may be NULL.
 */
static int
make_passwd_window (saver_info *si,
		    const char *info_msg,
		    const char *prompt,
		    Bool echo)
{
  passwd_dialog_data *pw;
  Screen *screen;
  Colormap cmap;
  saver_screen_info *ssi = &si->screens [mouse_screen (si)];
  cleanup_passwd_window (si);

  if (! ssi)
    return -1;

  /* [email protected] - fix for mirroring with external monitor */
  get_current_screen_size(si, ssi);

  if (!si->pw_data)
    if (new_passwd_window (si) < 0)
      return -1;

  if (!(pw = si->pw_data))
    return -1;

  pw->ratio = 1.0;
  pw->prompt_screen = ssi;

  /* [email protected]
   * Figure out where on the desktop to place the window so that it will
   * actually be visible and centered with respect to screen
   */
  pw->x = MAX((ssi->width - pw->width) / 2, 0);
  pw->y = MAX((ssi->height - pw->height) / 2, 0);

  /* [email protected] - Get the rest of the resources from the config file */
  pw->uname_field_x = pw->x + get_integer_resource(si->dpy,
                                "chromeos.username.x", "Integer");
  pw->uname_field_y = pw->y + get_integer_resource(si->dpy,
                                "chromeos.username.y", "Integer");
  pw->passwd_field_x = pw->x + get_integer_resource(si->dpy,
                                 "chromeos.password.x", "Integer");
  pw->passwd_field_y = pw->y + get_integer_resource(si->dpy,
                                 "chromeos.password.y", "Integer");
  if (si->prefs.verbose_p)
    fprintf (stderr, "%s: %d: creating password dialog (\"%s\")\n",
             blurb(), pw->prompt_screen->number,
             info_msg ? info_msg : "");

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

  pw->echo_input = echo;
  pw->draw_password_prompt = (NULL != prompt);

  /* Only create the window the first time around */
  if (!si->passwd_dialog)
    {
      XSetWindowAttributes attrs;
      unsigned long attrmask = CWOverrideRedirect | CWEventMask;

      attrs.override_redirect = True;
      attrs.event_mask = (ExposureMask | KeyPressMask |
                          ButtonPressMask | ButtonReleaseMask);

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

      /* We use the default visual, not ssi->visual, so that the logo pixmap's
	 visual matches that of the si->passwd_dialog window. */
      pw->logo_pixmap = xscreensaver_logo (ssi->screen,
					   DefaultVisualOfScreen(screen),
					   si->passwd_dialog, cmap,
					   pw->background,
					   &pw->logo_pixels, &pw->logo_npixels,
					   &pw->logo_clipmask, True);
    }
  else /* On successive prompts, just resize the window */
    {
      XWindowChanges wc;
      unsigned int mask = CWX | CWY | CWWidth | CWHeight;

      wc.x = ssi->x;
      wc.y = ssi->y;
      wc.width = ssi->width;
      wc.height = ssi->height;

      XConfigureWindow (si->dpy, si->passwd_dialog, mask, &wc);
    }

  restore_background(si);

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

  move_mouse_grab (si, si->passwd_dialog,
                   pw->passwd_cursor,
                   pw->prompt_screen->number);
  undo_vp_motion (si);

  si->pw_data = pw;

  if (cmap)
    XInstallColormap (si->dpy, cmap);
  draw_passwd_window (si);

  return 0;
}