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; }
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; }
/* Callback for ios_load_random_image(), called after we have loaded an image from the iOS device's Photo Library. See iosgrabimage.m. */ static void ios_load_random_image_cb (void *uiimage, const char *filename, int width, int height, void *closure) { struct pipe_closure *clo2 = (struct pipe_closure *) closure; Display *dpy = DisplayOfScreen (clo2->screen); XRectangle geom; XWindowAttributes xgwa; Window r; int x, y; unsigned int w, h, bbw, d; int rot = 0; XGetWindowAttributes (dpy, clo2->xwindow, &xgwa); XGetGeometry (dpy, clo2->drawable, &r, &x, &y, &w, &h, &bbw, &d); /* If the image is portrait and the window is landscape, or vice versa, rotate the image. The idea is to fill up as many pixels as possible, and assume the user will just rotate their phone until it looks right. This makes "decayscreen", etc. much more easily viewable. */ if (get_boolean_resource (dpy, "rotateImages", "RotateImages")) { if ((width > height) != (w > h)) rot = 5; } if (uiimage) { jwxyz_draw_NSImage_or_CGImage (DisplayOfScreen (clo2->screen), clo2->drawable, True, uiimage, &geom, rot); } else /* Probably means no images in the gallery. */ { draw_colorbars (clo2->screen, xgwa.visual, clo2->drawable, xgwa.colormap, 0, 0, w, h); geom.x = geom.y = 0; geom.width = w; geom.height = h; filename = 0; } clo2->callback (clo2->screen, clo2->xwindow, clo2->drawable, filename, &geom, clo2->closure); clo2->callback = 0; if (clo2->directory) free (clo2->directory); free (clo2); }
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; }
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; }
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; }
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; }
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; }
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; }
static void * wander_init (Display *dpy, Window window) { struct state *st = (struct state *) calloc (1, sizeof(*st)); XGCValues values; XWindowAttributes attributes; 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, &attributes); st->width = attributes.width; st->height = attributes.height; st->depth = attributes.depth; st->color_map = attributes.colormap; if (st->color_count) { free_colors (attributes.screen, st->color_map, st->colors, st->color_count); st->color_count = 0; } st->context = XCreateGC (st->dpy, st->window, 0, &values); st->color_count = MAXIMUM_COLOR_COUNT; make_color_loop (attributes.screen, 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 = 2; st->colors [0].red = st->colors [0].green = st->colors [0].blue = 0; st->colors [1].red = st->colors [1].green = st->colors [1].blue = 0xFFFF; XAllocColor (st->dpy, st->color_map, &st->colors [0]); XAllocColor (st->dpy, st->color_map, &st->colors [1]); } st->color_index = NRAND (st->color_count); st->advance = get_integer_resource (st->dpy, "advance", "Integer"); st->density = get_integer_resource (st->dpy, "density", "Integer"); if (st->density < 1) st->density = 1; st->reset = get_integer_resource (st->dpy, "reset", "Integer"); if (st->reset < 100) st->reset = 100; st->circles = get_boolean_resource (st->dpy, "circles", "Boolean"); st->size = get_integer_resource (st->dpy, "size", "Integer"); if (st->size < 1) st->size = 1; st->width = st->width / st->size; st->height = st->height / st->size; st->length = get_integer_resource (st->dpy, "length", "Integer"); if (st->length < 1) st->length = 1; XSetForeground (st->dpy, st->context, st->colors [st->color_index].pixel); st->x = NRAND (st->width); st->y = NRAND (st->height); st->last_x = st->x; st->last_y = st->y; st->width_1 = st->width - 1; st->height_1 = st->height - 1; st->length_limit = st->length; st->reset_limit = st->reset; st->color_index = NRAND (st->color_count); st->color = st->colors [NRAND (st->color_count)].pixel; st->pixmap = XCreatePixmap (st->dpy, window, st->size, st->size, st->depth); XSetForeground (st->dpy, st->context, BlackPixel (st->dpy, DefaultScreen (st->dpy))); XFillRectangle (st->dpy, st->pixmap, st->context, 0, 0, st->width * st->size, st->height * st->size); XSetForeground (st->dpy, st->context, st->color); XFillArc (st->dpy, st->pixmap, st->context, 0, 0, st->size, st->size, 0, 360*64); return st; }
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; }
static void * fontglide_init (Display *dpy, Window window) { XGCValues gcv; state *s = (state *) calloc (1, sizeof(*s)); s->dpy = dpy; s->window = window; s->frame_delay = get_integer_resource (dpy, "delay", "Integer"); XGetWindowAttributes (s->dpy, s->window, &s->xgwa); s->font_override = get_string_resource (dpy, "font", "Font"); if (s->font_override && (!*s->font_override || *s->font_override == '(')) s->font_override = 0; s->charset = get_string_resource (dpy, "fontCharset", "FontCharset"); s->border_width = get_integer_resource (dpy, "fontBorderWidth", "Integer"); if (s->border_width < 0 || s->border_width > 20) s->border_width = 1; s->speed = get_float_resource (dpy, "speed", "Float"); if (s->speed <= 0 || s->speed > 200) s->speed = 1; s->linger = get_float_resource (dpy, "linger", "Float"); if (s->linger <= 0 || s->linger > 200) s->linger = 1; s->trails_p = get_boolean_resource (dpy, "trails", "Trails"); s->debug_p = get_boolean_resource (dpy, "debug", "Debug"); s->debug_metrics_p = (get_boolean_resource (dpy, "debugMetrics", "Debug") ? 'y' : 0); s->dbuf = get_boolean_resource (dpy, "doubleBuffer", "Boolean"); # ifdef HAVE_COCOA /* Don't second-guess Quartz's double-buffering */ s->dbuf = False; # endif if (s->trails_p) s->dbuf = False; /* don't need it in this case */ { char *ss = get_string_resource (dpy, "mode", "Mode"); if (!ss || !*ss || !strcasecmp (ss, "random")) s->mode = ((random() % 2) ? SCROLL : PAGE); else if (!strcasecmp (ss, "scroll")) s->mode = SCROLL; else if (!strcasecmp (ss, "page")) s->mode = PAGE; else { fprintf (stderr, "%s: `mode' must be `scroll', `page', or `random', not `%s'\n", progname, ss); } } if (s->dbuf) { #ifdef HAVE_DOUBLE_BUFFER_EXTENSION s->dbeclear_p = get_boolean_resource (dpy, "useDBEClear", "Boolean"); if (s->dbeclear_p) s->b = xdbe_get_backbuffer (dpy, window, XdbeBackground); else s->b = xdbe_get_backbuffer (dpy, window, XdbeUndefined); s->backb = s->b; #endif /* HAVE_DOUBLE_BUFFER_EXTENSION */ if (!s->b) { s->ba = XCreatePixmap (s->dpy, s->window, s->xgwa.width, s->xgwa.height, s->xgwa.depth); s->b = s->ba; } } else { s->b = s->window; } gcv.foreground = get_pixel_resource (s->dpy, s->xgwa.colormap, "background", "Background"); s->bg_gc = XCreateGC (s->dpy, s->b, GCForeground, &gcv); s->subproc_relaunch_delay = 2 * 1000; if (! s->debug_metrics_p) launch_text_generator (s); s->nsentences = 5; /* #### */ s->sentences = (sentence **) calloc (s->nsentences, sizeof (sentence *)); s->spawn_p = True; return s; }
static void * zoom_init (Display *dpy, Window window) { struct state *st = (struct state *) calloc (1, sizeof(*st)); XGCValues gcv; XWindowAttributes xgwa; Colormap cmap; unsigned long bg; long gcflags; int nblocksx, nblocksy; st->dpy = dpy; st->window = window; XGetWindowAttributes(st->dpy, st->window, &xgwa); st->screen = xgwa.screen; st->sizex = xgwa.width; st->sizey = xgwa.height; cmap = xgwa.colormap; bg = get_pixel_resource(st->dpy, cmap, "background", "Background"); st->delay = get_integer_resource(st->dpy, "delay", "Integer"); if (st->delay < 1) st->delay = 1; st->duration = get_integer_resource (st->dpy, "duration", "Seconds"); if (st->duration < 1) st->duration = 1; st->pixwidth = get_integer_resource(st->dpy, "pixwidth", "Integer"); if (st->pixwidth < 1) st->pixwidth = 1; st->pixheight = get_integer_resource(st->dpy, "pixheight", "Integer"); if (st->pixheight < 1) st->pixheight = 1; st->pixspacex = get_integer_resource(st->dpy, "pixspacex", "Integer"); if (st->pixspacex < 0) st->pixspacex = 0; st->pixspacey = get_integer_resource(st->dpy, "pixspacey", "Integer"); if (st->pixspacey < 0) st->pixspacey = 0; st->lenses = get_boolean_resource(st->dpy, "lenses", "Boolean"); st->lensoffsetx = get_integer_resource(st->dpy, "lensoffsetx", "Integer"); st->lensoffsetx = MAX(0, MIN(st->pixwidth, st->lensoffsetx)); st->lensoffsety = get_integer_resource(st->dpy, "lensoffsety", "Integer"); st->lensoffsety = MAX(0, MIN(st->pixwidth, st->lensoffsety)); gcv.function = GXcopy; gcv.subwindow_mode = IncludeInferiors; gcflags = GCForeground|GCFunction; gcv.foreground = bg; if (!st->lenses && use_subwindow_mode_p(xgwa.screen, st->window)) /* see grabscreen.c */ gcflags |= GCSubwindowMode; st->window_gc = XCreateGC(st->dpy, st->window, gcflags, &gcv); st->orig_map = NULL; st->pm = XCreatePixmap(st->dpy, st->window, st->sizex, st->sizey, xgwa.depth); XFillRectangle(st->dpy, st->window, st->window_gc, 0, 0, st->sizex, st->sizey); XSetWindowBackground(st->dpy, st->window, bg); st->start_time = time ((time_t) 0); st->img_loader = load_image_async_simple (0, xgwa.screen, st->window, st->pm, 0, 0); /* We might have needed this to grab the image, but if we leave this set to GCSubwindowMode, then we'll *draw* right over subwindows too. */ XSetSubwindowMode (st->dpy, st->window_gc, ClipByChildren); nblocksx = (int)ceil((double)st->sizex / (double)(st->pixwidth + st->pixspacex)); nblocksy = (int)ceil((double)st->sizey / (double)(st->pixheight + st->pixspacey)); if (st->lenses) st->s = MAX((nblocksx - 1) * st->lensoffsetx + st->pixwidth, (nblocksy - 1) * st->lensoffsety + st->pixheight) * 2; else st->s = MAX(nblocksx, nblocksy) * 2; st->sinusoid_offset = random(); return st; }
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; }
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; }
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; }
static void setup_display (struct state *st) { XWindowAttributes xgwa; int cell_size = get_integer_resource (st->dpy, "size", "Integer"); int osize, alloc_size, oalloc; int mem_throttle = 0; char *s; if (cell_size < 1) cell_size = 1; osize = cell_size; s = get_string_resource (st->dpy, "memThrottle", "MemThrottle"); if (s) { int n; char c; if (1 == sscanf (s, " %d M %c", &n, &c) || 1 == sscanf (s, " %d m %c", &n, &c)) mem_throttle = n * (1 << 20); else if (1 == sscanf (s, " %d K %c", &n, &c) || 1 == sscanf (s, " %d k %c", &n, &c)) mem_throttle = n * (1 << 10); else if (1 == sscanf (s, " %d %c", &n, &c)) mem_throttle = n; else { fprintf (stderr, "%s: invalid memThrottle \"%s\" (try \"10M\")\n", progname, s); exit (1); } free (s); } XGetWindowAttributes (st->dpy, st->window, &xgwa); st->originalcolors = get_boolean_resource (st->dpy, "originalcolors", "Boolean"); st->count = get_integer_resource (st->dpy, "count", "Integer"); if (st->count < 2) st->count = 2; /* number of colors can't be greater than the half depth of the screen. */ if (st->count > (unsigned int) (1L << (xgwa.depth-1))) st->count = (unsigned int) (1L << (xgwa.depth-1)); /* Actually, since cell->col is of type char, this has to be small. */ if (st->count >= (unsigned int) (1L << ((sizeof(st->arr[0].col) * 8) - 1))) st->count = (unsigned int) (1L << ((sizeof(st->arr[0].col) * 8) - 1)); if (st->originalcolors && (st->count > 8)) { st->count = 8; } st->coloredGCs = (GC *) calloc (sizeof(GC), st->count * 2); st->diaglim = get_float_resource (st->dpy, "diaglim", "Float"); if (st->diaglim < 1.0) { st->diaglim = 1.0; } else if (st->diaglim > 2.0) { st->diaglim = 2.0; } st->diaglim *= st->orthlim; st->anychan = get_float_resource (st->dpy, "anychan", "Float"); if (st->anychan < 0.0) { st->anychan = 0.0; } else if (st->anychan > 1.0) { st->anychan = 1.0; } st->minorchan = get_float_resource (st->dpy, "minorchan","Float"); if (st->minorchan < 0.0) { st->minorchan = 0.0; } else if (st->minorchan > 1.0) { st->minorchan = 1.0; } st->instantdeathchan = get_float_resource (st->dpy, "instantdeathchan","Float"); if (st->instantdeathchan < 0.0) { st->instantdeathchan = 0.0; } else if (st->instantdeathchan > 1.0) { st->instantdeathchan = 1.0; } st->minlifespan = get_integer_resource (st->dpy, "minlifespan", "Integer"); if (st->minlifespan < 1) { st->minlifespan = 1; } st->maxlifespan = get_integer_resource (st->dpy, "maxlifespan", "Integer"); if (st->maxlifespan < st->minlifespan) { st->maxlifespan = st->minlifespan; } st->minlifespeed = get_float_resource (st->dpy, "minlifespeed", "Float"); if (st->minlifespeed < 0.0) { st->minlifespeed = 0.0; } else if (st->minlifespeed > 1.0) { st->minlifespeed = 1.0; } st->maxlifespeed = get_float_resource (st->dpy, "maxlifespeed", "Float"); if (st->maxlifespeed < st->minlifespeed) { st->maxlifespeed = st->minlifespeed; } else if (st->maxlifespeed > 1.0) { st->maxlifespeed = 1.0; } st->mindeathspeed = get_float_resource (st->dpy, "mindeathspeed", "Float"); if (st->mindeathspeed < 0.0) { st->mindeathspeed = 0.0; } else if (st->mindeathspeed > 1.0) { st->mindeathspeed = 1.0; } st->maxdeathspeed = get_float_resource (st->dpy, "maxdeathspeed", "Float"); if (st->maxdeathspeed < st->mindeathspeed) { st->maxdeathspeed = st->mindeathspeed; } else if (st->maxdeathspeed > 1.0) { st->maxdeathspeed = 1.0; } st->minlifespeed *= st->diaglim; st->maxlifespeed *= st->diaglim; st->mindeathspeed *= st->diaglim; st->maxdeathspeed *= st->diaglim; st->windowWidth = xgwa.width; st->windowHeight = xgwa.height; st->arr_width = st->windowWidth / cell_size; st->arr_height = st->windowHeight / cell_size; alloc_size = sizeof(cell) * st->arr_width * st->arr_height; oalloc = alloc_size; if (mem_throttle > 0) while (cell_size < st->windowWidth/10 && cell_size < st->windowHeight/10 && alloc_size > mem_throttle) { cell_size++; st->arr_width = st->windowWidth / cell_size; st->arr_height = st->windowHeight / cell_size; alloc_size = sizeof(cell) * st->arr_width * st->arr_height; } if (osize != cell_size) { if (!st->warned) { fprintf (stderr, "%s: throttling cell size from %d to %d because of %dM limit.\n", progname, osize, cell_size, mem_throttle / (1 << 20)); fprintf (stderr, "%s: %dx%dx%d = %.1fM, %dx%dx%d = %.1fM.\n", progname, st->windowWidth, st->windowHeight, osize, ((float) oalloc) / (1 << 20), st->windowWidth, st->windowHeight, cell_size, ((float) alloc_size) / (1 << 20)); st->warned = 1; } } st->xSize = st->arr_width ? st->windowWidth / st->arr_width : 0; st->ySize = st->arr_height ? st->windowHeight / st->arr_height : 0; if (st->xSize > st->ySize) { st->xSize = st->ySize; } else { st->ySize = st->xSize; } st->xOffset = (st->windowWidth - (st->arr_width * st->xSize)) / 2; st->yOffset = (st->windowHeight - (st->arr_height * st->ySize)) / 2; if (st->originalcolors) { setup_original_colormap (st, &xgwa); } else { setup_random_colormap (st, &xgwa); } }
static Bool InitializeAll(struct state *st) { XGCValues xgcv; XWindowAttributes xgwa; /* XSetWindowAttributes xswa;*/ Colormap cmap; XColor color; int n,i; double rspeed; st->cosilines = True; XGetWindowAttributes(st->dpy,st->win[0],&xgwa); cmap=xgwa.colormap; /* xswa.backing_store=Always; XChangeWindowAttributes(st->dpy,st->win[0],CWBackingStore,&xswa);*/ xgcv.function=GXcopy; xgcv.foreground=get_pixel_resource (st->dpy, cmap, "background", "Background"); st->fgc[32]=XCreateGC(st->dpy,st->win[0],GCForeground|GCFunction,&xgcv); n=0; if (mono_p) { st->fgc[0]=st->fgc[32]; xgcv.foreground=get_pixel_resource (st->dpy, cmap, "foreground", "Foreground"); st->fgc[1]=XCreateGC(st->dpy,st->win[0],GCForeground|GCFunction,&xgcv); for (i=0;i<32;i+=2) st->fgc[i]=st->fgc[0]; for (i=1;i<32;i+=2) st->fgc[i]=st->fgc[1]; } else for (i=0;i<32;i++) { color.red=colors[n++]<<8; color.green=colors[n++]<<8; color.blue=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[0],GCForeground|GCFunction,&xgcv); } st->cgc=XCreateGC(st->dpy,st->win[0],GCForeground|GCFunction,&xgcv); XSetGraphicsExposures(st->dpy,st->cgc,False); st->cosilines = get_boolean_resource(st->dpy, "random","Boolean"); #ifdef HAVE_DOUBLE_BUFFER_EXTENSION if (get_boolean_resource (st->dpy, "useDBE", "Boolean")) st->usedouble = True; st->win[1] = xdbe_get_backbuffer (st->dpy, st->win[0], XdbeUndefined); if (!st->win[1]) { st->usedouble = False; st->win[1] = st->win[0]; } #endif /* HAVE_DOUBLE_BUFFER_EXTENSION */ st->delay=get_integer_resource(st->dpy, "delay","Integer"); rspeed=get_float_resource(st->dpy, "speed","Float"); if (rspeed<0.0001 || rspeed>0.2) { fprintf(stderr,"Speed not in valid range! (0.0001 - 0.2), using 0.1 \n"); rspeed=0.1; } st->sizx=xgwa.width; st->sizy=xgwa.height; st->midx=st->sizx>>1; st->midy=st->sizy>>1; st->stateX=0; st->stateY=0; if (!make_rots(st,rspeed,rspeed)) { fprintf(stderr,"Not enough memory for tables!\n"); return False; } return True; }
static void * compass_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->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); st->size2 = MIN(st->xgwa.width, st->xgwa.height); if (st->xgwa.width > st->xgwa.height * 5 || /* goofy aspect ratio */ st->xgwa.height > st->xgwa.width * 5) st->size2 = MAX(st->xgwa.width, st->xgwa.height); { int max = 600; if (st->xgwa.width > 2560) max *= 2; /* Retina displays */ if (st->size2 > max) st->size2 = max; } st->size = (st->size2 / 2) * 0.8; st->x = st->xgwa.width/2; st->y = st->xgwa.height/2; if (st->dbuf) { #ifdef HAVE_DOUBLE_BUFFER_EXTENSION st->b = st->backb = xdbe_get_backbuffer (st->dpy, st->window, XdbeUndefined); #endif /* HAVE_DOUBLE_BUFFER_EXTENSION */ if (!st->b) { st->x = st->size2/2; st->y = st->size2/2; st->ba = XCreatePixmap (st->dpy, st->window, st->size2, st->size2, st->xgwa.depth); st->bb = XCreatePixmap (st->dpy, st->window, st->size2, st->size2, st->xgwa.depth); st->b = st->ba; } } else { st->b = st->window; } st->discs[0] = (struct disc *) calloc (1, sizeof (struct disc)); st->discs[1] = (struct disc *) calloc (1, sizeof (struct disc)); st->discs[2] = (struct disc *) calloc (1, sizeof (struct disc)); st->discs[3] = 0; gcv.foreground = get_pixel_resource (st->dpy, st->xgwa.colormap, "foreground", "Foreground"); gcv.line_width = MAX(2, (st->size/60)); gcv.join_style = JoinBevel; st->discs[0]->draw = draw_ticks; st->discs[0]->gc = XCreateGC (st->dpy, st->b, GCForeground|GCLineWidth|GCJoinStyle, &gcv); init_spin (st->discs[0]); gcv.foreground = get_pixel_resource (st->dpy, st->xgwa.colormap, "arrow2Foreground", "Foreground"); gcv.line_width = MAX(4, (st->size / 30)); st->discs[1]->draw = draw_thick_arrow; st->discs[1]->gc = XCreateGC (st->dpy, st->b, GCForeground|GCLineWidth, &gcv); init_spin (st->discs[1]); gcv.foreground = get_pixel_resource (st->dpy, st->xgwa.colormap, "arrow1Foreground", "Foreground"); gcv.line_width = MAX(4, (st->size / 30)); st->discs[2]->draw = draw_thin_arrow; st->discs[2]->gc = XCreateGC (st->dpy, st->b, GCForeground|GCLineWidth, &gcv); init_spin (st->discs[2]); gcv.foreground = get_pixel_resource (st->dpy, st->xgwa.colormap, "pointerForeground", "Foreground"); st->ptr_gc = XCreateGC (st->dpy, st->b, GCForeground|GCLineWidth, &gcv); 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->size2, st->size2); if (st->bb) XFillRectangle (st->dpy, st->bb, st->erase_gc, 0, 0, st->size2, st->size2); return st; }
static void distort_reset (struct state *st) { char *s; int i; st->start_time = 0; XGetWindowAttributes (st->dpy, st->window, &st->xgwa); st->delay = get_integer_resource(st->dpy, "delay", "Integer"); st->duration = get_integer_resource (st->dpy, "duration", "Seconds"); st->radius = get_integer_resource(st->dpy, "radius", "Integer"); st->speed = get_integer_resource(st->dpy, "speed", "Integer"); st->number = get_integer_resource(st->dpy, "number", "Integer"); st->blackhole = get_boolean_resource(st->dpy, "blackhole", "Boolean"); st->vortex = get_boolean_resource(st->dpy, "vortex", "Boolean"); st->magnify = get_boolean_resource(st->dpy, "magnify", "Boolean"); st->reflect = get_boolean_resource(st->dpy, "reflect", "Boolean"); st->slow = get_boolean_resource(st->dpy, "slow", "Boolean"); if (st->delay < 0) st->delay = 0; if (st->duration < 1) st->duration = 1; st->effect = NULL; s = get_string_resource(st->dpy, "effect", "String"); if (s && !strcasecmp(s,"swamp")) st->effect = &swamp_thing; else if (s && !strcasecmp(s,"bounce")) st->effect = &move_lense; else if (s && !strcasecmp(s,"none")) ; else if (s && *s) fprintf(stderr,"%s: bogus effect: %s\n", progname, s); if (st->effect == NULL && st->radius == 0 && st->speed == 0 && st->number == 0 && !st->blackhole && !st->vortex && !st->magnify && !st->reflect) { /* if no cmdline options are given, randomly choose one of: * -radius 125 -number 4 -speed 1 -bounce * -radius 125 -number 4 -speed 1 -blackhole * -radius 125 -number 4 -speed 1 -vortex * -radius 125 -number 4 -speed 1 -vortex -magnify * -radius 125 -number 4 -speed 1 -vortex -magnify -blackhole * -radius 250 -number 1 -speed 2 -bounce * -radius 250 -number 1 -speed 2 -blackhole * -radius 250 -number 1 -speed 2 -vortex * -radius 250 -number 1 -speed 2 -vortex -magnify * -radius 250 -number 1 -speed 2 -vortex -magnify -blackhole * -radius 80 -number 1 -speed 2 -reflect * -radius 125 -number 3 -speed 2 -reflect * jwz: not these * -radius 125 -number 4 -speed 2 -swamp * -radius 125 -number 4 -speed 2 -swamp -blackhole * -radius 125 -number 4 -speed 2 -swamp -vortex * -radius 125 -number 4 -speed 2 -swamp -vortex -magnify * -radius 125 -number 4 -speed 2 -swamp -vortex -magnify -blackhole */ i = (random() % 12 /* 17 */); st->draw = &plain_draw; switch (i) { case 0: st->radius=125;st->number=4;st->speed=1; st->effect=&move_lense;break; case 1: st->radius=125;st->number=4;st->speed=1;st->blackhole=1; st->effect=&move_lense;break; case 2: st->radius=125;st->number=4;st->speed=1;st->vortex=1; st->effect=&move_lense;break; case 3: st->radius=125;st->number=4;st->speed=1;st->vortex=1;st->magnify=1; st->effect=&move_lense;break; case 4: st->radius=125;st->number=4;st->speed=1;st->vortex=1;st->magnify=1;st->blackhole=1; st->effect=&move_lense;break; case 5: st->radius=250;st->number=1;st->speed=2; st->effect=&move_lense;break; case 6: st->radius=250;st->number=1;st->speed=2;st->blackhole=1; st->effect=&move_lense;break; case 7: st->radius=250;st->number=1;st->speed=2;st->vortex=1; st->effect=&move_lense;break; case 8: st->radius=250;st->number=1;st->speed=2;st->vortex=1;st->magnify=1; st->effect=&move_lense;break; case 9: st->radius=250;st->number=1;st->speed=2;st->vortex=1;st->magnify=1;st->blackhole=1; st->effect=&move_lense;break; case 10: st->radius=80;st->number=1;st->speed=2;st->reflect=1; st->draw = &reflect_draw;st->effect = &move_lense;break; case 11: st->radius=125;st->number=4;st->speed=2;st->reflect=1; st->draw = &reflect_draw;st->effect = &move_lense;break; #if 0 /* jwz: not these */ case 12: st->radius=125;st->number=4;st->speed=2; effect=&swamp_thing;break; case 13: st->radius=125;st->number=4;st->speed=2;st->blackhole=1; effect=&swamp_thing;break; case 14: st->radius=125;st->number=4;st->speed=2;st->vortex=1; effect=&swamp_thing;break; case 15: st->radius=125;st->number=4;st->speed=2;st->vortex=1;st->magnify=1; effect=&swamp_thing;break; case 16: st->radius=125;st->number=4;st->speed=2;st->vortex=1;st->magnify=1;st->blackhole=1; effect=&swamp_thing;break; #endif default: abort(); break; } } /* never allow the radius to be too close to the min window dimension */ if (st->radius > st->xgwa.width * 0.3) st->radius = st->xgwa.width * 0.3; if (st->radius > st->xgwa.height * 0.3) st->radius = st->xgwa.height * 0.3; /* -swamp mode consumes vast amounts of memory, proportional to radius -- so throttle radius to a small-ish value (60 => ~30MB.) */ if (st->effect == &swamp_thing && st->radius > 60) st->radius = 60; if (st->delay < 0) st->delay = 0; if (st->radius <= 0) st->radius = 60; if (st->speed <= 0) st->speed = 2; if (st->number <= 0) st->number=1; if (st->number >= 10) st->number=1; if (st->effect == NULL) st->effect = &move_lense; if (st->reflect) { st->draw = &reflect_draw; st->effect = &move_lense; } if (st->draw == NULL) st->draw = &plain_draw; }
static void * halo_init (Display *dpy, Window window) { struct state *st = (struct state *) calloc (1, sizeof(*st)); XGCValues gcv; XWindowAttributes xgwa; char *mode_str = 0; st->dpy = dpy; st->window = window; XGetWindowAttributes (st->dpy, st->window, &xgwa); st->cmap = xgwa.colormap; st->global_count = get_integer_resource (st->dpy, "count", "Integer"); if (st->global_count < 0) st->global_count = 0; st->global_inc = get_integer_resource (st->dpy, "increment", "Integer"); if (st->global_inc < 0) st->global_inc = 0; st->anim_p = get_boolean_resource (st->dpy, "animate", "Boolean"); st->delay = get_integer_resource (st->dpy, "delay", "Integer"); st->delay2 = get_integer_resource (st->dpy, "delay2", "Integer") * 1000000; mode_str = get_string_resource (st->dpy, "colorMode", "ColorMode"); if (! mode_str) cmode = random_mode; else if (!strcmp (mode_str, "seuss")) cmode = seuss_mode; else if (!strcmp (mode_str, "ramp")) cmode = ramp_mode; else if (!strcmp (mode_str, "random")) cmode = random_mode; else { fprintf (stderr, "%s: colorMode must be seuss, ramp, or random, not \"%s\"\n", progname, mode_str); exit (1); } if (mono_p) cmode = seuss_mode; if (cmode == random_mode) cmode = ((random()&3) == 1) ? ramp_mode : seuss_mode; if (cmode == ramp_mode) st->anim_p = False; /* This combo doesn't work right... */ st->ncolors = get_integer_resource (st->dpy, "colors", "Colors"); if (st->ncolors < 2) st->ncolors = 2; if (st->ncolors <= 2) mono_p = True; if (mono_p) st->colors = 0; else st->colors = (XColor *) malloc(sizeof(*st->colors) * (st->ncolors+1)); if (mono_p) ; else if (random() % (cmode == seuss_mode ? 2 : 10)) make_uniform_colormap (xgwa.screen, xgwa.visual, st->cmap, st->colors, &st->ncolors, True, 0, True); else make_smooth_colormap (xgwa.screen, xgwa.visual, st->cmap, st->colors, &st->ncolors, True, 0, True); if (st->ncolors <= 2) mono_p = True; if (mono_p) cmode = seuss_mode; if (mono_p) { st->fg_pixel = get_pixel_resource (st->dpy, st->cmap, "foreground", "Foreground"); st->bg_pixel = get_pixel_resource (st->dpy, st->cmap, "background", "Background"); } else { st->fg_index = 0; st->bg_index = st->ncolors / 4; if (st->fg_index == st->bg_index) st->bg_index++; st->fg_pixel = st->colors[st->fg_index].pixel; st->bg_pixel = st->colors[st->bg_index].pixel; } st->width = max (50, xgwa.width); st->height = max (50, xgwa.height); #ifdef DEBUG st->width/=2; st->height/=2; #endif st->pixmap = XCreatePixmap (st->dpy, st->window, st->width, st->height, 1); if (cmode == seuss_mode) st->buffer = XCreatePixmap (st->dpy, st->window, st->width, st->height, 1); else st->buffer = 0; gcv.foreground = 1; gcv.background = 0; st->draw_gc = XCreateGC (st->dpy, st->pixmap, GCForeground | GCBackground, &gcv); gcv.foreground = 0; st->erase_gc = XCreateGC (st->dpy, st->pixmap, GCForeground, &gcv); gcv.foreground = st->fg_pixel; gcv.background = st->bg_pixel; st->copy_gc = XCreateGC (st->dpy, st->window, GCForeground | GCBackground, &gcv); #ifdef HAVE_COCOA jwxyz_XSetAntiAliasing (dpy, st->draw_gc, False); jwxyz_XSetAntiAliasing (dpy, st->erase_gc, False); jwxyz_XSetAntiAliasing (dpy, st->copy_gc, False); #endif if (cmode == seuss_mode) { gcv.foreground = 1; gcv.background = 0; gcv.function = GXxor; st->merge_gc = XCreateGC (st->dpy, st->pixmap, GCForeground | GCBackground | GCFunction, &gcv); } else { gcv.foreground = st->fg_pixel; gcv.background = st->bg_pixel; gcv.function = GXcopy; st->merge_gc = XCreateGC (st->dpy, st->window, GCForeground | GCBackground | GCFunction, &gcv); } init_circles_1 (st); XClearWindow (st->dpy, st->window); if (st->buffer) XFillRectangle (st->dpy, st->buffer, st->erase_gc, 0, 0, st->width, st->height); return st; }
ENTRYPOINT void init_quasicrystal (ModeInfo *mi) { quasicrystal_configuration *bp; int wire = MI_IS_WIREFRAME(mi); unsigned char *tex_data = 0; int tex_width; int i; if (!bps) { bps = (quasicrystal_configuration *) calloc (MI_NUM_SCREENS(mi), sizeof (quasicrystal_configuration)); if (!bps) { fprintf(stderr, "%s: out of memory\n", progname); exit(1); } } bp = &bps[MI_SCREEN(mi)]; bp->glx_context = init_GL(mi); reshape_quasicrystal (mi, MI_WIDTH(mi), MI_HEIGHT(mi)); glDisable (GL_DEPTH_TEST); glEnable (GL_CULL_FACE); bp->count = MI_COUNT(mi); if (bp->count < 1) bp->count = 1; if (! wire) { unsigned char *o; tex_width = 4096; tex_data = (unsigned char *) calloc (4, tex_width); o = tex_data; for (i = 0; i < tex_width; i++) { unsigned char y = 255 * (1 + sin (i * M_PI * 2 / tex_width)) / 2; *o++ = y; *o++ = y; *o++ = y; *o++ = 255; } } bp->symmetric_p = get_boolean_resource (MI_DISPLAY (mi), "symmetry", "Symmetry"); bp->contrast = get_float_resource (MI_DISPLAY (mi), "contrast", "Contrast"); if (bp->contrast < 0 || bp->contrast > 100) { fprintf (stderr, "%s: contrast must be between 0 and 100%%.\n", progname); bp->contrast = 0; } { Bool spinp = get_boolean_resource (MI_DISPLAY (mi), "spin", "Spin"); Bool wanderp = get_boolean_resource (MI_DISPLAY (mi), "wander", "Wander"); double spin_speed = 0.01; double wander_speed = 0.0001; double spin_accel = 10.0; double scale_speed = 0.005; bp->planes = (plane *) calloc (sizeof (*bp->planes), bp->count); bp->ncolors = 256; /* ncolors affects color-cycling speed */ bp->colors = (XColor *) calloc (bp->ncolors, sizeof(XColor)); make_smooth_colormap (0, 0, 0, bp->colors, &bp->ncolors, False, 0, False); bp->ccolor = 0; for (i = 0; i < bp->count; i++) { plane *p = &bp->planes[i]; p->rot = make_rotator (0, 0, spinp ? spin_speed : 0, spin_accel, wanderp ? wander_speed : 0, True); p->rot2 = make_rotator (0, 0, 0, 0, scale_speed, True); if (! wire) { clear_gl_error(); glGenTextures (1, &p->texid); glBindTexture (GL_TEXTURE_1D, p->texid); glPixelStorei (GL_UNPACK_ALIGNMENT, 1); glTexImage1D (GL_TEXTURE_1D, 0, GL_RGBA, tex_width, 0, GL_RGBA, /* GL_UNSIGNED_BYTE, */ GL_UNSIGNED_INT_8_8_8_8_REV, tex_data); check_gl_error("texture"); glTexParameterf(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameterf(GL_TEXTURE_1D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); } } } if (tex_data) free (tex_data); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); }
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; }
static void moire_init_1 (struct state *st) { int oncolors; int i; int fgh, bgh; double fgs, fgv, bgs, bgv; XWindowAttributes xgwa; XColor fgc, bgc; XGCValues gcv; XGetWindowAttributes (st->dpy, st->window, &xgwa); //st->delay = get_integer_resource (st->dpy, "delay", "Integer"); //st->offset = get_integer_resource (st->dpy, "offset", "Integer"); st->delay = delay; st->offset = offset; if (st->offset < 2) st->offset = 2; #ifdef HAVE_XSHM_EXTENSION st->use_shm = get_boolean_resource(st->dpy, "useSHM", "Boolean"); #endif /* HAVE_XSHM_EXTENSION */ MONO: if (st->colors) { for (i = 0; i < st->ncolors; i++) XFreeColors (st->dpy, xgwa.colormap, &st->colors[i].pixel, 1, 0); free(st->colors); st->colors = 0; } if (mono_p) { st->fg_pixel = WhitePixelOfScreen (DefaultScreenOfDisplay(st->dpy)); st->bg_pixel = BlackPixelOfScreen (DefaultScreenOfDisplay(st->dpy)); } else { #if 1 st->fg_pixel = load_color(st->dpy, xgwa.colormap, foreground); st->bg_pixel = load_color(st->dpy, xgwa.colormap, background); #else st->fg_pixel = get_pixel_resource (st->dpy, xgwa.colormap, "foreground", "Foreground"); st->bg_pixel = get_pixel_resource (st->dpy, xgwa.colormap, "background", "Background"); #endif } if (mono_p) { st->offset *= 20; /* compensate for lack of shading */ gcv.foreground = st->fg_pixel; } else { //st->ncolors = get_integer_resource (st->dpy, "ncolors", "Integer"); st->ncolors = ncolors; if (st->ncolors < 2) st->ncolors = 2; oncolors = st->ncolors; fgc.flags = bgc.flags = DoRed|DoGreen|DoBlue; //if (get_boolean_resource(st->dpy, "random","Boolean")) if (random_) { fgc.red = random() & 0xFFFF; fgc.green = random() & 0xFFFF; fgc.blue = random() & 0xFFFF; bgc.red = random() & 0xFFFF; bgc.green = random() & 0xFFFF; bgc.blue = random() & 0xFFFF; } else { fgc.pixel = st->fg_pixel; bgc.pixel = st->bg_pixel; XQueryColor (st->dpy, xgwa.colormap, &fgc); XQueryColor (st->dpy, 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); st->colors = (XColor *) malloc (sizeof (XColor) * (st->ncolors+2)); memset(st->colors, 0, (sizeof (XColor) * (st->ncolors+2))); make_color_ramp (xgwa.screen, xgwa.visual, xgwa.colormap, fgh, fgs, fgv, bgh, bgs, bgv, st->colors, &st->ncolors, True, True, False); if (st->ncolors != oncolors) fprintf(stderr, "%s: got %d of %d requested colors.\n", progname, st->ncolors, oncolors); if (st->ncolors <= 2) { mono_p = True; goto MONO; } gcv.foreground = st->colors[0].pixel; } st->gc = XCreateGC (st->dpy, st->window, GCForeground, &gcv); }
/* Loads an image into the Drawable, returning once the image is loaded. */ static void load_random_image_1 (Screen *screen, Window window, Drawable drawable, void (*callback) (Screen *, Window, Drawable, const char *name, XRectangle *geom, void *closure), void *closure, char **name_ret, XRectangle *geom_ret) { Display *dpy = DisplayOfScreen (screen); XWindowAttributes xgwa; Bool deskp = get_boolean_resource (dpy, "grabDesktopImages", "Boolean"); Bool filep = get_boolean_resource (dpy, "chooseRandomImages", "Boolean"); const char *dir = 0; Bool done = False; XRectangle geom_ret_2; char *name_ret_2 = 0; if (!drawable) abort(); if (callback) { geom_ret = &geom_ret_2; name_ret = &name_ret_2; } XGetWindowAttributes (dpy, window, &xgwa); { Window r; int x, y; unsigned int w, h, bbw, d; XGetGeometry (dpy, drawable, &r, &x, &y, &w, &h, &bbw, &d); xgwa.width = w; xgwa.height = h; } if (name_ret) *name_ret = 0; if (geom_ret) { geom_ret->x = 0; geom_ret->y = 0; geom_ret->width = xgwa.width; geom_ret->height = xgwa.height; } # ifndef USE_IPHONE if (filep) dir = get_string_resource (dpy, "imageDirectory", "ImageDirectory"); if (!dir || !*dir) filep = False; # endif /* ! USE_IPHONE */ if (deskp && filep) { deskp = !(random() & 5); /* if both, desktop 1/5th of the time */ filep = !deskp; } if (filep && !done) { osx_load_image_file_async (screen, window, drawable, dir, callback, closure); return; } if (deskp && !done) { if (osx_grab_desktop_image (screen, window, drawable, &geom_ret_2)) { if (name_ret) *name_ret = strdup ("desktop"); done = True; } } if (! done) draw_colorbars (screen, xgwa.visual, drawable, xgwa.colormap, 0, 0, xgwa.width, xgwa.height); if (callback) { /* If we got here, we loaded synchronously even though they wanted async. */ callback (screen, window, drawable, name_ret_2, &geom_ret_2, closure); if (name_ret_2) free (name_ret_2); } }
int main(int argc,char* argv[]) { XtAppContext app; int sig_Number; int sig_Signal[] = { SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGTRAP, #if defined(SIGIOT) SIGIOT, #endif SIGABRT, #if defined(SIGEMT) SIGEMT, #endif SIGFPE, SIGBUS, SIGSEGV, #if defined(SIGSYS) SIGSYS, #endif SIGTERM, #if defined(SIGXCPU) SIGXCPU, #endif #if defined(SIGXFSZ) SIGXFSZ, #endif #if defined(SIGDANGER) SIGDANGER, #endif -1 }; Widget app_App; Display* dpy; Window win_Root; XWindowAttributes attr_Win; XGCValues gc_ValFore; XGCValues gc_ValBack; GC gc_GcFore; GC gc_GcBack; XFontStruct* font_Font; char* font_List[] = { "-*-character-*-r-*-*-*-600-*-*-p-*-*-*", "-*-helvetica-*-r-*-*-*-600-*-*-p-*-*-*", "-*-lucida-*-r-*-*-*-600-*-*-p-*-*-*", "-*-*-*-r-*-sans-*-600-*-*-p-*-*-*", "-*-*-*-r-*-*-*-600-*-*-m-*-*-*", "-*-helvetica-*-r-*-*-*-240-*-*-p-*-*-*", "-*-lucida-*-r-*-*-*-240-*-*-p-*-*-*", "-*-*-*-r-*-sans-*-240-*-*-p-*-*-*", "-*-*-*-r-*-*-*-240-*-*-m-*-*-*", "fixed", NULL }; int font_Index; int text_Length; int text_X; int text_Y; int text_Width; int text_Height; char* text_List[XSUBLIM_TEXT_COUNT]; int text_Used[XSUBLIM_TEXT_COUNT]; char text_Text[XSUBLIM_TEXT_LENGTH+1]; char* text_Phrase; char* text_Word; int text_Index; int text_Item; int text_Count; struct { int outline_X; int outline_Y; } text_Outline[] = { { -1,-1 }, { 1,-1 }, { -1, 1 }, { 1, 1 }, { 0, 0 } }; int text_OutlineIndex; XImage* image_Image = NULL; int image_X = 0; int image_Y = 0; int image_Width = 0; int image_Height = 0; int arg_Count; int arg_FlagCenter; int arg_FlagOutline; int arg_FlagScreensaver; int arg_FlagRandom; int arg_DelayShow; int arg_DelayWord; int arg_DelayPhraseMin; int arg_DelayPhraseMax; char* arg_Text; char* arg_Source; /* Set-up ---------------------------------------------------------- */ /* Catch signals */ Xsublim_Sig_Last = -1; for (sig_Number = 0;sig_Signal[sig_Number] != -1;sig_Number++) { signal(sig_Number,xsublim_Sig_Catch); } /* Randomize -- only need to do this here because this program doesn't use the `screenhack.h' or `lockmore.h' APIs. */ # undef ya_rand_init ya_rand_init (0); /* Handle all the X nonsense */ #if defined(__sgi) SgiUseSchemes("none"); #endif for (arg_Count = 0;options[arg_Count].option != NULL;arg_Count++) { ; } app_App = XtAppInitialize(&app,progclass,options,arg_Count,&argc,argv, defaults,0,0); /* jwz */ if (argc > 1) { int x = 18; int end = 78; int i; int count = (sizeof(options)/sizeof(*options))-1; fprintf(stderr, "Unrecognised option: %s\n", argv[1]); fprintf (stderr, "Options include: "); for (i = 0; i < count; i++) { char *sw = options [i].option; Bool argp = (options [i].argKind == XrmoptionSepArg); int size = strlen (sw) + (argp ? 6 : 0) + 2; if (x + size >= end) { fprintf (stderr, "\n\t\t "); x = 18; } x += size; fprintf (stderr, "%s", sw); if (argp) fprintf (stderr, " <arg>"); if (i != count-1) fprintf (stderr, ", "); } fprintf (stderr, ".\n"); exit (-1); } dpy = XtDisplay(app_App); XtGetApplicationNameAndClass(dpy,&progname,&progclass); win_Root = RootWindowOfScreen(XtScreen(app_App)); XtDestroyWidget(app_App); /* Get the arguments */ arg_FlagCenter = get_boolean_resource(dpy, XSUBLIM_ARG_CENTER,"Boolean"); arg_FlagOutline = get_boolean_resource(dpy, XSUBLIM_ARG_OUTLINE,"Boolean"); arg_FlagScreensaver = get_boolean_resource(dpy, XSUBLIM_ARG_SCREENSAVER, "Boolean"); arg_FlagRandom = get_boolean_resource(dpy, XSUBLIM_ARG_RANDOM,"Boolean"); arg_DelayShow = get_integer_resource(dpy, XSUBLIM_ARG_DELAYSHOW,"Integer"); arg_DelayWord = get_integer_resource(dpy, XSUBLIM_ARG_DELAYWORD,"Integer"); arg_DelayPhraseMin = get_integer_resource(dpy, XSUBLIM_ARG_DELAYPHRASEMIN, "Integer"); arg_DelayPhraseMax = get_integer_resource(dpy, XSUBLIM_ARG_DELAYPHRASEMAX, "Integer"); if (arg_DelayPhraseMax < arg_DelayPhraseMin) { arg_DelayPhraseMax = arg_DelayPhraseMin; } /* Get the phrases */ text_Index = 0; text_Item = 0; text_Count = 0; memset(text_Used,0,sizeof(text_Used)); arg_Source = get_string_resource(dpy, XSUBLIM_ARG_FILE,"Filename"); if (arg_Source != NULL) { FILE* file_Fs; struct stat file_Stat; file_Fs = fopen(arg_Source,"rb"); if (file_Fs == NULL) { fprintf(stderr,"%s: Could not open '%s'\n",progname, arg_Source); exit(-1); } if (fstat(fileno(file_Fs),&file_Stat) != 0) { fprintf(stderr,"%s: Could not stat '%s'\n",progname, arg_Source); exit(-1); } arg_Text = calloc(1,file_Stat.st_size+1); if (arg_Text != NULL) { if (fread(arg_Text,file_Stat.st_size,1,file_Fs) != 1) { fprintf(stderr,"%s: Could not read '%s'\n", progname,arg_Source); exit(-1); } } fclose(file_Fs); } else { arg_Source = get_string_resource(dpy, XSUBLIM_ARG_PROGRAM, "Executable"); if (arg_Source != NULL) { char* exe_Command = calloc(1,strlen(arg_Source)+10); FILE* exe_Fs; if (exe_Command == NULL) { fprintf(stderr, "%s: Could not allocate space for '%s'\n", progname,arg_Source); exit(-1); } sprintf(exe_Command,"( %s ) 2>&1",arg_Source); exe_Fs = popen(exe_Command,"r"); if (exe_Fs == NULL) { fprintf(stderr,"%s: Could not run '%s'\n", progname,arg_Source); exit(-1); } arg_Text = calloc(1,XSUBLIM_PROGRAM_SIZE); if (arg_Text != NULL) { if (fread(arg_Text,1,XSUBLIM_PROGRAM_SIZE, exe_Fs) <= 0) { fprintf(stderr, "%s: Could not read output of '%s'\n", progname,arg_Source); exit(-1); } if ( strstr(arg_Text,": not found") || strstr(arg_Text,": Not found") || strstr(arg_Text,": command not found") || strstr(arg_Text,": Command not found")) { fprintf(stderr, "%s: Could not find '%s'\n", progname,arg_Source); exit(-1); } } fclose(exe_Fs); } else { arg_Text = get_string_resource(dpy, XSUBLIM_ARG_PHRASES,"Phrases"); if (arg_Text != NULL) { arg_Text = strdup(arg_Text); } } } if (arg_Text != NULL) { while (((text_Phrase = strtok(arg_Text,"\n")) != NULL) && (text_Count < XSUBLIM_TEXT_COUNT)) { arg_Text = NULL; text_List[text_Count] = text_Phrase; text_Count++; } text_List[text_Count] = NULL; } if (text_Count == 0) { fprintf(stderr,"%s: No text to display\n",progname); exit(-1); } /* Load the font */ font_Font = XLoadQueryFont(dpy, get_string_resource(dpy, XSUBLIM_ARG_FONT,"Font")); font_Index = 0; while ((font_Font == NULL) && (font_List[font_Index] != NULL)) { font_Font = XLoadQueryFont(dpy,font_List[font_Index]); font_Index++; } if (font_Font == NULL) { fprintf(stderr,"%s: Couldn't load a font\n",progname); exit(-1); } /* Create the GCs */ XGetWindowAttributes(dpy,win_Root,&attr_Win); gc_ValFore.font = font_Font->fid; gc_ValFore.foreground = get_pixel_resource(dpy, attr_Win.colormap, "foreground","Foreground"); gc_ValFore.background = get_pixel_resource(dpy, attr_Win.colormap, "background","Background"); gc_ValFore.subwindow_mode = IncludeInferiors; gc_GcFore = XCreateGC(dpy,win_Root, (GCFont|GCForeground|GCBackground|GCSubwindowMode),&gc_ValFore); gc_ValBack.font = font_Font->fid; gc_ValBack.foreground = get_pixel_resource(dpy, attr_Win.colormap, "background","Background"); gc_ValBack.background = get_pixel_resource(dpy, attr_Win.colormap, "foreground","Foreground"); gc_ValBack.subwindow_mode = IncludeInferiors; gc_GcBack = XCreateGC(dpy,win_Root, (GCFont|GCForeground|GCBackground|GCSubwindowMode),&gc_ValBack); /* Loop ------------------------------------------------------------ */ while (Xsublim_Sig_Last == -1) { /* Once-per-phrase stuff ----------------------------------- */ /* If we're waiting for a screensaver... */ if (arg_FlagScreensaver != FALSE) { /* Find the screensaver's window */ win_Root = xsublim_Ss_GetWindow(dpy); if (win_Root == 0) { usleep(30000000); continue; } } /* Pick the next phrase */ if (arg_FlagRandom != FALSE) { text_Item = random()%text_Count; text_Index = 0; } while (text_Used[text_Item] != FALSE) { text_Index++; text_Item++; if (text_Index == text_Count) { text_Index = 0; memset(text_Used,0,sizeof(text_Used)); } if (text_List[text_Item] == NULL) { text_Item = 0; } } text_Used[text_Item] = TRUE; strncpy(text_Text,text_List[text_Item], XSUBLIM_TEXT_LENGTH); text_Phrase = text_Text; /* Run through the phrase */ while (((text_Word = strtok(text_Phrase," \t")) != NULL) && (Xsublim_Sig_Last == -1)) { text_Phrase = NULL; /* Once-per-word stuff ----------------------------- */ /* Find the text's position */ XGetWindowAttributes(dpy,win_Root,&attr_Win); text_Length = strlen(text_Word); text_Width = XTextWidth(font_Font,text_Word, text_Length)+XSUBLIM_TEXT_OUTLINE*2; text_Height = font_Font->ascent+font_Font->descent+1+ XSUBLIM_TEXT_OUTLINE*2; if (arg_FlagCenter == FALSE) { text_X = random()%(attr_Win.width-text_Width); text_Y = random()%(attr_Win.height- text_Height); } else { text_X = (attr_Win.width/2)-(text_Width/2); text_Y = (attr_Win.height/2)-(text_Height/2); } /* Find the image's position (and pad it out slightly, otherwise bits of letter get left behind -- are there boundry issues I don't know about?) */ image_X = text_X-16; image_Y = text_Y; image_Width = text_Width+32; image_Height = text_Height; if (image_X < 0) { image_X = 0; } if (image_Y < 0) { image_Y = 0; } if (image_X+image_Width > attr_Win.width) { image_Width = attr_Win.width-image_X; } if (image_Y+image_Height > attr_Win.height) { image_Height = attr_Win.height-image_Y; } /* Influence people for our own ends --------------- */ /* Grab the server -- we can't let anybody draw over us */ XSync(dpy,FALSE); XGrabServer(dpy); XSync(dpy,FALSE); /* Set up an error handler that ignores BadMatches -- since the screensaver can take its window away at any time, any call that uses it might choke */ Xsublim_Sh_Status = 0; Xsublim_Sh_Handler = XSetErrorHandler(xsublim_Sh_Handler); /* Save the current background */ image_Image = XGetImage(dpy,win_Root,image_X, image_Y,image_Width,image_Height,~0L,ZPixmap); /* If we've successfully saved the background... */ if (image_Image != NULL) { if (Xsublim_Sh_Status == 0) { /* Draw the outline */ if (arg_FlagOutline != FALSE) { for (text_OutlineIndex = 0; text_Outline[ text_OutlineIndex].outline_X != 0;text_OutlineIndex++) { /* Y'know, eight character tabs and descriptive variable names become annoying at some point... */ XDrawString( dpy, win_Root,gc_GcBack, text_X+text_Outline[ text_OutlineIndex]. outline_X* XSUBLIM_TEXT_OUTLINE, text_Y+ (font_Font->ascent)+ text_Outline[ text_OutlineIndex]. outline_Y* XSUBLIM_TEXT_OUTLINE, text_Word, text_Length); } } /* Draw the word */ XDrawString(dpy,win_Root, gc_GcFore,text_X, text_Y+(font_Font->ascent),text_Word, text_Length); } if (Xsublim_Sh_Status == 0) { /* Wait a bit */ XSync(dpy,FALSE); if (Xsublim_Sig_Last == -1) { usleep(arg_DelayShow); } /* Restore the background */ XPutImage(dpy,win_Root, gc_GcFore,image_Image,0,0,image_X, image_Y,image_Width,image_Height); } /* Free the image */ XDestroyImage(image_Image); } /* Restore the error handler, ungrab the server */ XSync(dpy,FALSE); XSetErrorHandler(Xsublim_Sh_Handler); XUngrabServer(dpy); XSync(dpy,FALSE); /* Pause between words */ if (Xsublim_Sig_Last == -1) { usleep(arg_DelayWord); } } /* Pause between phrases */ if (Xsublim_Sig_Last == -1) { usleep(random()%(arg_DelayPhraseMax- arg_DelayPhraseMin+1)+arg_DelayPhraseMin); } } /* Exit ------------------------------------------------------------ */ for (sig_Number = 0;sig_Signal[sig_Number] != -1;sig_Number++) { signal(sig_Number,SIG_DFL); } kill(getpid(),Xsublim_Sig_Last); return 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; }
static void hexadrop_init_1 (Display *dpy, Window window, state *st) { XGCValues gcv; char *s1, *s2; st->dpy = dpy; st->window = window; st->delay = get_integer_resource (st->dpy, "delay", "Integer"); st->ncolors = get_integer_resource (st->dpy, "ncolors", "Integer"); st->speed = get_float_resource (st->dpy, "speed", "Speed"); if (st->speed < 0) st->speed = 0; XGetWindowAttributes (st->dpy, st->window, &st->xgwa); if (st->ncolors < 2) st->ncolors = 2; st->colors = (XColor *) calloc (sizeof(*st->colors), st->ncolors); if (st->ncolors < 10) make_random_colormap (st->xgwa.screen, st->xgwa.visual, st->xgwa.colormap, st->colors, &st->ncolors, False, True, 0, True); else make_smooth_colormap (st->xgwa.screen, st->xgwa.visual, st->xgwa.colormap, st->colors, &st->ncolors, True, 0, True); XSetWindowBackground (dpy, window, st->colors[0].pixel); s1 = get_string_resource (st->dpy, "uniform", "Uniform"); s2 = get_string_resource (st->dpy, "lockstep", "Lockstep"); if ((!s1 || !*s1 || !strcasecmp(s1, "maybe")) && (!s2 || !*s2 || !strcasecmp(s2, "maybe"))) { /* When being random, don't do both. */ st->uniform_p = random() & 1; st->lockstep_p = st->uniform_p ? 0 : random() & 1; } else { if (!s1 || !*s1 || !strcasecmp(s1, "maybe")) st->uniform_p = random() & 1; else st->uniform_p = get_boolean_resource (st->dpy, "uniform", "Uniform"); if (!s2 || !*s2 || !strcasecmp(s2, "maybe")) st->lockstep_p = random() & 1; else st->lockstep_p = get_boolean_resource (st->dpy, "lockstep","Lockstep"); } st->sides = get_integer_resource (st->dpy, "sides", "Sides"); if (! (st->sides == 0 || st->sides == 3 || st->sides == 4 || st->sides == 6 || st->sides == 8)) { printf ("%s: invalid number of sides: %d\n", progname, st->sides); st->sides = 0; } if (! st->sides) { static int defs[] = { 3, 3, 3, 4, 6, 6, 6, 6, 8, 8, 8 }; st->sides = defs[random() % countof(defs)]; } make_cells (st); gcv.foreground = st->colors[0].pixel; st->gc = XCreateGC (dpy, window, GCForeground, &gcv); }
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; }
XImage * create_xshm_image (Display *dpy, Visual *visual, unsigned int depth, int format, XShmSegmentInfo *shm_info, unsigned int width, unsigned int height) { #ifndef HAVE_XSHM_EXTENSION return create_fallback (dpy, visual, depth, format, shm_info, width, height); #else /* HAVE_XSHM_EXTENSION */ Status status; XImage *image = 0; if (!get_boolean_resource(dpy, "useSHM", "Boolean") || !XShmQueryExtension (dpy)) { return create_fallback (dpy, visual, depth, format, shm_info, width, height); } CATCH_X_ERROR(dpy); image = XShmCreateImage(dpy, visual, depth, format, NULL, shm_info, width, height); UNCATCH_X_ERROR(dpy); if (shm_got_x_error) return create_fallback (dpy, visual, depth, format, shm_info, width, height); #ifdef DEBUG fprintf(stderr, "\n%s: XShmCreateImage(... %d, %d)\n", progname, width, height); #endif shm_info->shmid = shmget(IPC_PRIVATE, image->bytes_per_line * image->height, IPC_CREAT | 0777); #ifdef DEBUG fprintf(stderr, "%s: shmget(IPC_PRIVATE, %d, IPC_CREAT | 0777) ==> %d\n", progname, image->bytes_per_line * image->height, shm_info->shmid); #endif if (shm_info->shmid == -1) { char buf[1024]; sprintf (buf, "%s: shmget failed", progname); perror(buf); XDestroyImage (image); image = 0; XSync(dpy, False); } else { shm_info->readOnly = False; image->data = shm_info->shmaddr = shmat(shm_info->shmid, 0, 0); #ifdef DEBUG fprintf(stderr, "%s: shmat(%d, 0, 0) ==> %d\n", progname, shm_info->shmid, (int) image->data); #endif CATCH_X_ERROR(dpy); status = XShmAttach(dpy, shm_info); UNCATCH_X_ERROR(dpy); if (shm_got_x_error) status = False; if (!status) { fprintf (stderr, "%s: XShmAttach failed!\n", progname); XDestroyImage (image); XSync(dpy, False); shmdt (shm_info->shmaddr); image = 0; } #ifdef DEBUG else fprintf(stderr, "%s: XShmAttach(dpy, shm_info) ==> True\n", progname); #endif XSync(dpy, False); /* Delete the shared segment right now; the segment won't actually go away until both the client and server have deleted it. The server will delete it as soon as the client disconnects, so we should delete our side early in case of abnormal termination. (And note that, in the context of xscreensaver, abnormal termination is the rule rather than the exception, so this would leak like a sieve if we didn't do this...) #### Are we leaking anyway? Perhaps because of the window of opportunity between here and the XShmAttach call above, during which we might be killed? Do we need to establish a signal handler for this case? */ shmctl (shm_info->shmid, IPC_RMID, 0); #ifdef DEBUG fprintf(stderr, "%s: shmctl(%d, IPC_RMID, 0)\n\n", progname, shm_info->shmid); #endif } if (!image) { return create_fallback (dpy, visual, depth, format, shm_info, width, height); } return image; #endif /* HAVE_XSHM_EXTENSION */ }