Пример #1
0
unsigned int
get_pixel_resource (char *res_name, char *res_class,
		    Display *dpy, Colormap cmap)
{
  XColor color;
  char *s = get_string_resource (res_name, res_class);
  char *s2;
  if (!s) goto DEFAULT;

  for (s2 = s + strlen(s) - 1; s2 > s; s2--)
    if (*s2 == ' ' || *s2 == '\t')
      *s2 = 0;
    else
      break;

  if (! XParseColor (dpy, cmap, s, &color))
    {
      fprintf (stderr, "%s: can't parse color %s\n", progname, s);
      goto DEFAULT;
    }
  if (! XAllocColor (dpy, cmap, &color))
    {
      fprintf (stderr, "%s: couldn't allocate color %s\n", progname, s);
      goto DEFAULT;
    }
  free (s);
  return color.pixel;
 DEFAULT:
  if (s) free (s);
  return ((strlen(res_class) >= 10 &&
	   !strcmp ("Background", res_class + strlen(res_class) - 10))
	  ? BlackPixel (dpy, DefaultScreen (dpy))
	  : WhitePixel (dpy, DefaultScreen (dpy)));
}
/* Callback in xscreensaver_function_table, via xlockmore.c.
 */
Visual *
xlockmore_pick_gl_visual (Screen *screen)
{
    /* pick the "best" visual by interrogating the GL library instead of
       by asking Xlib.  GL knows better.
     */
    Visual *v = 0;
    Display *dpy = DisplayOfScreen (screen);
    char *string = get_string_resource (dpy, "visualID", "VisualID");
    char *s;

    if (string)
        for (s = string; *s; s++)
            if (isupper (*s)) *s = _tolower (*s);

    if (!string || !*string ||
            !strcmp (string, "gl") ||
            !strcmp (string, "best") ||
            !strcmp (string, "color") ||
            !strcmp (string, "default"))
        v = get_gl_visual (screen);		/* from ../utils/visual-gl.c */

    if (string)
        free (string);

    return v;
}
Пример #3
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" );
}
Пример #4
0
/* The first time we grab an image, do it the default way.
   The second and subsequent times, add "-no-desktop" to the command.
   That way we don't have to watch the window un-map 5+ times in a row.
   Also, we end up with the desktop on only one channel, and pictures
   on all the others (or colorbars, if no imageDirectory is set.)
 */
static void
hack_resources (Display *dpy)
{
#ifndef HAVE_JWXYZ
  static int count = -1;
  count++;

  if (count == 0)
    return;
  else if (count == 1)
    {
      XrmDatabase db = XtDatabase (dpy);
      char *res = "desktopGrabber";
      char *val = get_string_resource (dpy, res, "DesktopGrabber");
      char buf1[255];
      char buf2[255];
      XrmValue value;
      sprintf (buf1, "%.100s.%.100s", progname, res);
      sprintf (buf2, "%.200s -no-desktop", val);
      value.addr = buf2;
      value.size = strlen(buf2);
      XrmPutResource (&db, buf1, "String", &value);
    }
#endif /* HAVE_JWXYZ */
}
Пример #5
0
int 
get_integer_resource (char *res_name, char *res_class, int default_value)
{
  int val;
  char c, *s = get_string_resource (res_name, res_class);
  char *ss = s;
  if (!s) return default_value;

  while (*ss && *ss <= ' ') ss++;			/* skip whitespace */

  if (ss[0] == '0' && (ss[1] == 'x' || ss[1] == 'X'))	/* 0x: parse as hex */
    {
      if (1 == sscanf (ss+2, "%x %c", &val, &c))
	{
	  free (s);
	  return val;
	}
    }
  else							/* else parse as dec */
    {
      if (1 == sscanf (ss, "%d %c", &val, &c))
	{
	  free (s);
	  return val;
	}
    }

  fprintf (stderr, "%s: %s must be an integer, not %s.\n",
	   progname, res_name, s);
  free (s);
  return default_value;
}
Пример #6
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;
}
Пример #7
0
unsigned int
get_pixel_resource (char *res_name, char *res_class,
		    Display *dpy, Colormap cmap, unsigned int default_value)
{
  XColor color;
  char *s = get_string_resource (res_name, res_class);
  char *s2;
  if (!s) goto DEFAULT;

  for (s2 = s + strlen(s) - 1; s2 > s; s2--)
    if (*s2 == ' ' || *s2 == '\t')
      *s2 = 0;
    else
      break;

  if (! XParseColor (dpy, cmap, s, &color))
    {
      fprintf (stderr, "%s: can't parse color %s\n", progname, s);
      goto DEFAULT;
    }
  if (! XAllocColor (dpy, cmap, &color))
    {
      fprintf (stderr, "%s: couldn't allocate color %s\n", progname, s);
      goto DEFAULT;
    }
  free (s);
  return color.pixel;
 DEFAULT:
  if (s) free (s);
  return default_value;
}
Пример #8
0
Bool 
get_boolean_resource (char *res_name, char *res_class, Bool default_value)
{
  char *tmp, buf [100];
  char *s = get_string_resource (res_name, res_class);
  char *os = s;
  if (! s) return default_value;
  for (tmp = buf; *s; s++)
    *tmp++ = isupper (*s) ? _tolower (*s) : *s;
  *tmp = 0;
  free (os);

  while (*buf &&
	 (buf[strlen(buf)-1] == ' ' ||
	  buf[strlen(buf)-1] == '\t'))
    buf[strlen(buf)-1] = 0;

  if (!strcmp (buf, "on") || !strcmp (buf, "true") || !strcmp (buf, "yes"))
    return 1;
  if (!strcmp (buf,"off") || !strcmp (buf, "false") || !strcmp (buf,"no"))
    return 0;
  fprintf (stderr, "%s: %s must be boolean, not %s.\n",
	   progname, res_name, buf);
  return default_value;
}
Пример #9
0
static void
launch_text_generator (state *s)
{
  char *oprogram = get_string_resource (s->dpy, "program", "Program");
  char *program = (char *) malloc (strlen (oprogram) + 10);
  strcpy (program, "( ");
  strcat (program, oprogram);
  strcat (program, " ) 2>&1");

  if (s->debug_p)
    fprintf (stderr, "%s: forking: %s\n", progname, program);

  if ((s->pipe = popen (program, "r")))
    {
      s->pipe_id =
        XtAppAddInput (XtDisplayToApplicationContext (s->dpy), 
                       fileno (s->pipe),
                       (XtPointer) (XtInputReadMask | XtInputExceptMask),
                       subproc_cb, (XtPointer) s);
    }
  else
    {
      char buf[255];
      sprintf (buf, "%.100s: %.100s", progname, program);
      perror (buf);
    }

  free(oprogram);
  free(program);
}
Пример #10
0
static void
gl_init (ModeInfo *mi)
{
  sws_configuration *sc = &scs[MI_SCREEN(mi)];

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

  glDisable (GL_LIGHTING);
  glDisable (GL_DEPTH_TEST);

  if (smooth_p)
    {
      glEnable (GL_LINE_SMOOTH);
      glHint (GL_LINE_SMOOTH_HINT, GL_NICEST);
      glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 
      glEnable (GL_BLEND);
    }

  sc->text_list = glGenLists (1);
  glNewList (sc->text_list, GL_COMPILE);
  glEndList ();

  sc->star_list = glGenLists (1);
  glNewList (sc->star_list, GL_COMPILE);
  glEndList ();

  sc->line_thickness = 1.0;
}
Пример #11
0
static unsigned int 
get_time_resource (char *res_name, char *res_class, Bool sec_p)
{
  int val;
  char *s = get_string_resource (res_name, res_class);
  if (!s) return 0;
  val = parse_time (s, sec_p, False);
  free (s);
  return (val < 0 ? 0 : val);
}
Пример #12
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;
}
Пример #13
0
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;
}
unsigned int
get_pixel_resource (Display *dpy, Colormap cmap,
                    char *res_name, char *res_class)
{
  XColor color;
  char *s = get_string_resource (dpy, res_name, res_class);
  char *s2;
  Bool ok = True;
  if (!s) goto DEFAULT;

  for (s2 = s + strlen(s) - 1; s2 > s; s2--)
    if (*s2 == ' ' || *s2 == '\t')
      *s2 = 0;
    else
      break;

  if (! XParseColor (dpy, cmap, s, &color))
    {
      fprintf (stderr, "%s: can't parse color %s", progname, s);
      ok = False;
      goto DEFAULT;
    }
  if (! XAllocColor (dpy, cmap, &color))
    {
      fprintf (stderr, "%s: couldn't allocate color %s", progname, s);
      ok = False;
      goto DEFAULT;
    }
  free (s);
  return (unsigned int) color.pixel;
 DEFAULT:
  if (s) free (s);

  {
    Bool black_p = (strlen(res_class) >= 10 &&
                    !strcasecmp ("Background",
                                 res_class + strlen(res_class) - 10));
    if (!ok)
      fprintf (stderr, ": using %s.\n", (black_p ? "black" : "white"));
    color.flags = DoRed|DoGreen|DoBlue;
    color.red = color.green = color.blue = (black_p ? 0 : 0xFFFF);
    if (XAllocColor (dpy, cmap, &color))
      return (unsigned int) color.pixel;
    else
      {
        fprintf (stderr, "%s: couldn't allocate %s either!\n", progname,
                 (black_p ? "black" : "white"));
        /* We can't use BlackPixel/WhitePixel here, because we don't know
           what screen we're allocating on (only an issue when running inside
           the xscreensaver daemon: for hacks, DefaultScreen is fine.)
         */
        return 0;
      }
  }
}
Пример #15
0
/* Loads an image into the Drawable.
   When grabbing desktop images, the Window will be unmapped first.
   Used only when running "real" X11, not jwxyz.
 */
static void
load_random_image_x11 (Screen *screen, Window window, Drawable drawable,
                       void (*callback) (Screen *, Window, Drawable,
                                         const char *name, XRectangle *geom,
                                         void *closure),
                       void *closure)
{
  Display *dpy = DisplayOfScreen (screen);
  char *grabber = get_string_resource(dpy, "desktopGrabber", "DesktopGrabber");
  char *cmd;
  char id[200];

  if (!grabber || !*grabber)
    {
      fprintf (stderr,
         "%s: resources installed incorrectly: \"desktopGrabber\" is unset!\n",
               progname);
      exit (1);
    }

  sprintf (id, "0x%lx 0x%lx",
           (unsigned long) window,
           (unsigned long) drawable);
  cmd = (char *) malloc (strlen(grabber) + strlen(id) + 1);

  /* Needn't worry about buffer overflows here, because the buffer is
     longer than the length of the format string, and the length of what
     we're putting into it.  So the only way to crash would be if the
     format string itself was corrupted, but that comes from the
     resource database, and if hostile forces have access to that,
     then the game is already over.
   */
  sprintf (cmd, grabber, id);
  free (grabber);
  grabber = 0;

  /* In case "cmd" fails, leave some random image on the screen, not just
     black or white, so that it's more obvious what went wrong. */
  checkerboard (screen, drawable);
  if (window == drawable)
    print_loading_msg (screen, window);

  XSync (dpy, True);
  hack_subproc_environment (dpy);

  /* Start the image loading in another fork and return immediately.
     Invoke the callback function when done. */
  fork_exec_cb (cmd, screen, window, drawable, callback, closure);

  free (cmd);
  XSync (dpy, True);
}
Пример #16
0
char *getStringResourceWithDefault(char *instanceName, char *className,
				   char *defaultText)
{
   char *s = get_string_resource(instanceName, className);
   if (!s) {
      if (!defaultText) {
	 s = strdup("");
      } else {
	 s = strdup(defaultText);
      }
   }
   return(s);
}
Пример #17
0
/* 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);
}
Пример #18
0
XFontStruct *getFontResource(AppInfo *app, char *instanceName, char *className)
{
   char *fallbackFont = "fixed";
   
   XFontStruct *f = NULL;
   char *s = get_string_resource(instanceName, className);
   f = XLoadQueryFont(app->dpy, (s ? s : fallbackFont));
   if (!f) {
      f = XLoadQueryFont(app->dpy, fallbackFont);
   }
   if (s) {
      free(s);
   }
   return(f);
}
Пример #19
0
/* Kludge to add "-v" to invocation of "xscreensaver-getimage" in -debug mode
 */
static void
hack_resources (void)
{
#if 0
  char *res = "desktopGrabber";
  char *val = get_string_resource (res, "DesktopGrabber");
  char buf1[255];
  char buf2[255];
  XrmValue value;
  sprintf (buf1, "%.100s.%.100s", progclass, res);
  sprintf (buf2, "%.200s -v", val);
  value.addr = buf2;
  value.size = strlen(buf2);
  XrmPutResource (&db, buf1, "String", &value);
#endif
}
Пример #20
0
double
get_float_resource (char *res_name, char *res_class)
{
  double val;
  char c, *s = get_string_resource (res_name, res_class);
  if (! s) return 0.0;
  if (1 == sscanf (s, " %lf %c", &val, &c))
    {
      free (s);
      return val;
    }
  fprintf (stderr, "%s: %s must be a float, not %s.\n",
	   progname, res_name, s);
  free (s);
  return 0.0;
}
Пример #21
0
/* Kludge to add "-v" to invocation of "xscreensaver-getimage" in -debug mode
 */
static void
hack_resources (Display *dpy)
{
# ifndef HAVE_COCOA
  char *res = "desktopGrabber";
  char *val = get_string_resource (dpy, res, "DesktopGrabber");
  char buf1[255];
  char buf2[255];
  XrmValue value;
  XrmDatabase db = XtDatabase (dpy);
  sprintf (buf1, "%.100s.%.100s", progname, res);
  sprintf (buf2, "%.200s -v", val);
  value.addr = buf2;
  value.size = strlen(buf2);
  XrmPutResource (&db, buf1, "String", &value);
# endif /* !HAVE_COCOA */
}
Пример #22
0
static void
parse_color (ModeInfo *mi, char *key, GLfloat color[4])
{
  XColor xcolor;
  char *string = get_string_resource (mi->dpy, key, "CameraColor");
  if (!XParseColor (mi->dpy, mi->xgwa.colormap, string, &xcolor))
    {
      fprintf (stderr, "%s: unparsable color in %s: %s\n", progname,
               key, string);
      exit (1);
    }

  color[0] = xcolor.red   / 65536.0;
  color[1] = xcolor.green / 65536.0;
  color[2] = xcolor.blue  / 65536.0;
  color[3] = 1;
}
Пример #23
0
unsigned int getUnsignedIntegerResource(AppInfo *app, char *instanceName,
					char *className,
					unsigned int defaultValue)
{
   int n;
   unsigned int value;
   char c;
   char *s = get_string_resource(instanceName, className);
   char *cp = s;
   
   if (NULL == s) {
      return(defaultValue);
   }
   while ((*cp) && isspace(*cp)) {
      /* Skip whitespace. */
      cp++;
   }
   if (*cp) {
      if (('0' == cp[0]) && cp[1]) {
	 if (('x' == cp[1]) || ('X' == cp[1])) {
	    /* Hex */
	    n = sscanf(cp + 2, "%x %c", &value, &c);
	 } else {
	    /* Octal */
	    n = sscanf(cp + 1, "%o %c", &value, &c);
	 }
	 if (1 == n) {
	    free(s);
	    return(value);
	 }
      } else {
	 /* Unsigned Decimal */
	 n = sscanf(cp, "%u %c", &value, &c);
	 if (1 == n) {
	    free(s);
	    return(value);
	 }
      }
   }
   /* If we get here, no conversion succeeded. */
   fprintf(stderr, "%s[%ld]: invalid value '%s' for %s.\n",
	   app->appName, (long) app->pid, s, instanceName);
   free(s);
   return(defaultValue);
}
Пример #24
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);
    }
}
Пример #25
0
/* xgflux initialization routine */
ENTRYPOINT void init_gflux(ModeInfo * mi)
{
    int screen = MI_SCREEN(mi);
    gfluxstruct *gp;

    if (gfluxes == NULL) {
        if ((gfluxes = (gfluxstruct *) 
                 calloc(MI_NUM_SCREENS(mi), sizeof (gfluxstruct))) == NULL)
            return;
    }
    gp = &gfluxes[screen];

    gp->trackball = gltrackball_init ();

    gp->time = frand(1000.0);  /* don't run two screens in lockstep */

    {
      char *s = get_string_resource (mi->dpy, "mode", "Mode");
      if (!s || !*s)                       _draw = wire;
      else if (!strcasecmp (s, "wire"))    _draw = wire;
      else if (!strcasecmp (s, "solid"))   _draw = solid;
      else if (!strcasecmp (s, "light"))   _draw = light;
      else if (!strcasecmp (s, "checker")) _draw = checker;
      else if (!strcasecmp (s, "grab"))    _draw = grab;
      else
        {
          fprintf (stderr,
                   "%s: mode must be one of: wire, solid, "
                   "light, checker, or grab; not \"%s\"\n",
                   progname, s);
          exit (1);
        }
    }

    gp->modeinfo = mi;
    gp->window = MI_WINDOW(mi);
    if ((gp->glx_context = init_GL(mi)) != NULL) {
        reshape_gflux(mi, MI_WIDTH(mi), MI_HEIGHT(mi));
        initializeGL(mi, MI_WIDTH(mi), MI_HEIGHT(mi));
    } else {
        MI_CLEARWINDOW(mi);
    }
}
Пример #26
0
static void
launch_text_generator (sws_configuration *sc)
{
  XtAppContext app = XtDisplayToApplicationContext (sc->dpy);
  char *oprogram = get_string_resource (sc->dpy, "program", "Program");
  char *program = (char *) malloc (strlen (oprogram) + 10);
  strcpy (program, "( ");
  strcat (program, oprogram);
  strcat (program, " ) 2>&1");

  if ((sc->pipe = popen (program, "r")))
    {
      sc->pipe_id =
        XtAppAddInput (app, fileno (sc->pipe),
                       (XtPointer) (XtInputReadMask | XtInputExceptMask),
                       subproc_cb, (XtPointer) sc);
    }
  else
    {
      perror (program);
    }
}
Пример #27
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);
    }
}
Пример #28
0
static Bool
load_font (ModeInfo *mi, char *res, XFontStruct **fontP, GLuint *dlistP)
{
#ifdef STANDALONE
  const char *font = get_string_resource (res, "Font");
#else
  const char *font = res;
#endif
  XFontStruct *f;
  Font id;
  int first, last;

  if (!font) font = "-*-times-bold-r-normal-*-180-*";

  f = XLoadQueryFont(MI_DISPLAY(mi), font);
  if (!f) f = XLoadQueryFont(MI_DISPLAY(mi), "fixed");

  id = f->fid;
  first = f->min_char_or_byte2;
  last = f->max_char_or_byte2;

  clear_gl_error ();
  *dlistP = glGenLists ((GLuint) last+1);
  if (check_gl_error ("glGenLists"))
	return False;
  /*-
   * PURIFY reports a cumulative memory leak on the next line with Mesa 3.4.1
   * on Solaris 2.X and SunOS 4.1.X. This can be fixed with a patch to Mesa
   * 3.4.1. OpenGL on Solaris does not have the memory leak.
   */
  glXUseXFont(id, first, last-first+1, *dlistP + first);
  if (check_gl_error ("glXUseXFont"))
	return False;

  *fontP = f;
  return True;
}
Пример #29
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;
}
Пример #30
0
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;
}