static void free_mandelbrot(Display *display, mandelstruct *mp) { ModeInfo *mi = mp->mi; if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) { MI_WHITE_PIXEL(mi) = mp->whitepixel; MI_BLACK_PIXEL(mi) = mp->blackpixel; #ifndef STANDALONE MI_FG_PIXEL(mi) = mp->fg; MI_BG_PIXEL(mi) = mp->bg; #endif if (mp->colors != NULL) { if (mp->ncolors && !mp->no_colors) free_colors(display, mp->cmap, mp->colors, mp->ncolors); free(mp->colors); mp->colors = (XColor *) NULL; } if (mp->cmap != None) { XFreeColormap(display, mp->cmap); mp->cmap = None; } } if (mp->gc != None) { XFreeGC(display, mp->gc); mp->gc = None; } }
int ColorModel::command(int argc, const char*const* argv) { Tcl& tcl = Tcl::instance(); if (argc == 2) { if (strcmp(argv[1], "alloc-colors") == 0) { tcl.result(allocate() < 0 ? "0" : "1"); return (TCL_OK); } if (strcmp(argv[1], "free-colors") == 0) { free_colors(); return (TCL_OK); } } else if (argc == 3) { if (strcmp(argv[1], "visual") == 0) { Tk_Window tk = Tk_NameToWindow(tcl.interp(), (char*)argv[2], tcl.tkmain()); setvisual(Tk_Visual(tk), Tk_Colormap(tk), Tk_Depth(tk)); return (TCL_OK); } if (strcmp(argv[1], "gamma") == 0) { double v = atof(argv[2]); if (v < 0) tcl.result("0"); gamma_ = v; tcl.result("1"); return (TCL_OK); } } return (TclObject::command(argc, argv)); }
void cleanup() /* {{{ */ { /* function to run on termination */ keybind *lastbind; /* free memory allocated normally */ check_free(searchstring); free_tasks(head); check_free(cfg.sortmode); free(cfg.version); free(cfg.formats.task); free(cfg.formats.title); free(cfg.formats.view); free(active_filter); while (keybinds!=NULL) { lastbind = keybinds; keybinds = keybinds->next; check_free(lastbind->argstr); free(lastbind); } free_colors(); free_prompts(); free_formats(); /* close open files */ fflush(logfp); fclose(logfp); } /* }}} */
int ColorModel::allocate() { if (alloc_grays() < 0 || alloc_colors() < 0) { free_colors(); return (-1); } return (0); }
/*************************************************************************** ... ***************************************************************************/ void dtor_sprite(struct Sprite *mysprite) { XFreePixmap(display, mysprite->pixmap); if(mysprite->has_mask) XFreePixmap(display, mysprite->mask); free_colors(mysprite->pcolorarray, mysprite->ncols); free(mysprite->pcolorarray); free(mysprite); }
/*************************************************************************** Deletes a sprite. These things can use a lot of memory. ***************************************************************************/ void free_sprite(struct sprite *s) { XFreePixmap(display, s->pixmap); if (s->has_mask) { XFreePixmap(display, s->mask); } if (s->pcolorarray) { free_colors(s->pcolorarray, s->ncols); free(s->pcolorarray); s->pcolorarray = NULL; } free(s); }
static void free_tik_tak(Display *display, tik_takstruct *tiktak) { ModeInfo *mi = tiktak->mi; if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) { MI_WHITE_PIXEL(mi) = tiktak->whitepixel; MI_BLACK_PIXEL(mi) = tiktak->blackpixel; #ifndef STANDALONE MI_FG_PIXEL(mi) = tiktak->fg; MI_BG_PIXEL(mi) = tiktak->bg; #endif if (tiktak->colors != NULL) { if (tiktak->ncolors && !tiktak->no_colors) free_colors(display, tiktak->cmap, tiktak->colors, tiktak->ncolors); free(tiktak->colors); tiktak->colors = (XColor *) NULL; } if (tiktak->cmap != None) { XFreeColormap(display, tiktak->cmap); tiktak->cmap = None; } } if (tiktak->gc != None) { XFreeGC(display, tiktak->gc); tiktak->gc = None; } if (tiktak->object != NULL) { int i; for (i = 0; i < tiktak->num_object; i++) { tik_takobject *object0; object0 = &tiktak->object[i]; if (object0->xy1 != NULL) free(object0->xy1); if (object0->xy != NULL) free(object0->xy); } free(tiktak->object); tiktak->object = (tik_takobject *) NULL; } }
static void hexadrop_free (Display *dpy, Window window, void *closure) { state *st = (state *) closure; if (st->colors) { free_colors (st->xgwa.screen, st->xgwa.colormap, st->colors, st->ncolors); free (st->colors); st->colors = 0; } if (st->cells) { free (st->cells); st->cells = 0; } if (st->gc) { XFreeGC (st->dpy, st->gc); st->gc = 0; } }
static void free_toneclock(Display *display, toneclockstruct *tclock) { ModeInfo *mi = tclock->mi; if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) { MI_WHITE_PIXEL(mi) = tclock->whitepixel; MI_BLACK_PIXEL(mi) = tclock->blackpixel; #ifndef STANDALONE MI_FG_PIXEL(mi) = tclock->fg; MI_BG_PIXEL(mi) = tclock->bg; #endif if (tclock->colors != NULL) { if (tclock->ncolors && !tclock->no_colors) free_colors(display, tclock->cmap, tclock->colors, tclock->ncolors); free(tclock->colors); tclock->colors = (XColor *) NULL; } if (tclock->cmap != None) { XFreeColormap(display, tclock->cmap); tclock->cmap = None; } } if (tclock->gc != None) { XFreeGC(display, tclock->gc); tclock->gc = None; } free_hour(tclock); #ifndef NO_DBUF if (tclock->dbuf != None) { XFreePixmap(display, tclock->dbuf); tclock->dbuf = None; } if (tclock->dbuf_gc != None) { XFreeGC(display, tclock->dbuf_gc); tclock->dbuf_gc = None; } #endif }
static void free_swirl(Display *display, swirlstruct *sp) { ModeInfo *mi = sp->mi; if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) { MI_WHITE_PIXEL(mi) = sp->whitepixel; MI_BLACK_PIXEL(mi) = sp->blackpixel; #ifndef STANDALONE MI_FG_PIXEL(mi) = sp->fg; MI_BG_PIXEL(mi) = sp->bg; #endif if (sp->colors != NULL) { if (sp->ncolors && !sp->no_colors) free_colors(display, sp->cmap, sp->colors, sp->ncolors); free(sp->colors); sp->colors = (XColor *) NULL; } if (sp->cmap != None) { XFreeColormap(display, sp->cmap); sp->cmap = None; } } if (sp->gc != None) { XFreeGC(display, sp->gc); sp->gc = None; } if (sp->ximage != None) { (void) XDestroyImage(sp->ximage); sp->ximage = None; } if (sp->knots != NULL) { free(sp->knots); sp->knots = (KNOT_P) NULL; } }
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; }
void init_mandelbrot(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); mandelstruct *mp; if (mandels == NULL) { if ((mandels = (mandelstruct *) calloc(MI_NUM_SCREENS(mi), sizeof (mandelstruct))) == NULL) return; } mp = &mandels[MI_SCREEN(mi)]; mp->mi = mi; mp->screen_width = MI_WIDTH(mi); mp->screen_height = MI_HEIGHT(mi); mp->backwards = (Bool) (LRAND() & 1); if (mp->backwards) mp->column = mp->screen_width - 1; else mp->column = 0; mp->power = NRAND(3) + MINPOWER; mp->counter = 0; MI_CLEARWINDOW(mi); if (MI_IS_FULLRANDOM(mi)) { mp->binary = (Bool) (LRAND() & 1); mp->dem = (Bool) (LRAND() & 1); mp->interior = NRAND(interior_size); #if 0 /* too slow */ mp->pow = (NRAND(5) == 0); mp->sin = (NRAND(5) == 0); #endif } else { mp->binary = binary_p; mp->dem = dem_p; if (index_p) { mp->interior = INDEX; } else if(alpha_p) { mp->interior = ALPHA; } else if(lyap_p) { mp->interior = LYAPUNOV; } else { mp->interior = NONE; } mp->pow = pow_p; mp->sin = sin_p; } mp->reptop = 300; /* these could be tuned a little closer, but the selection ** process throws out the chaf anyway, it just takes slightly ** longer */ mp->extreme_ul.real = -3.0; mp->extreme_ul.imag = -3.0; mp->extreme_lr.real = 3.0; mp->extreme_lr.imag = 3.0; if (!mp->gc) { if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) { XColor color; #ifndef STANDALONE mp->fg = MI_FG_PIXEL(mi); mp->bg = MI_BG_PIXEL(mi); #endif mp->blackpixel = MI_BLACK_PIXEL(mi); mp->whitepixel = MI_WHITE_PIXEL(mi); if ((mp->cmap = XCreateColormap(display, window, MI_VISUAL(mi), AllocNone)) == None) { free_mandelbrot(display, mp); return; } XSetWindowColormap(display, window, mp->cmap); (void) XParseColor(display, mp->cmap, "black", &color); (void) XAllocColor(display, mp->cmap, &color); MI_BLACK_PIXEL(mi) = color.pixel; (void) XParseColor(display, mp->cmap, "white", &color); (void) XAllocColor(display, mp->cmap, &color); MI_WHITE_PIXEL(mi) = color.pixel; #ifndef STANDALONE (void) XParseColor(display, mp->cmap, background, &color); (void) XAllocColor(display, mp->cmap, &color); MI_BG_PIXEL(mi) = color.pixel; (void) XParseColor(display, mp->cmap, foreground, &color); (void) XAllocColor(display, mp->cmap, &color); MI_FG_PIXEL(mi) = color.pixel; #endif mp->colors = (XColor *) NULL; mp->ncolors = 0; } if ((mp->gc = XCreateGC(display, MI_WINDOW(mi), (unsigned long) 0, (XGCValues *) NULL)) == None) { free_mandelbrot(display, mp); return; } } MI_CLEARWINDOW(mi); /* Set up colour map */ mp->direction = (LRAND() & 1) ? 1 : -1; if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) { if (mp->colors != NULL) { if (mp->ncolors && !mp->no_colors) free_colors(display, mp->cmap, mp->colors, mp->ncolors); free(mp->colors); mp->colors = (XColor *) NULL; } mp->ncolors = MI_NCOLORS(mi); if (mp->ncolors < 2) mp->ncolors = 2; if (mp->ncolors <= 2) mp->mono_p = True; else mp->mono_p = False; if (mp->mono_p) mp->colors = (XColor *) NULL; else if ((mp->colors = (XColor *) malloc(sizeof (*mp->colors) * (mp->ncolors + 1))) == NULL) { free_mandelbrot(display, mp); return; } mp->cycle_p = has_writable_cells(mi); if (mp->cycle_p) { if (MI_IS_FULLRANDOM(mi)) { if (!NRAND(8)) mp->cycle_p = False; else mp->cycle_p = True; } else { mp->cycle_p = cycle_p; } } if (!mp->mono_p) { if (!(LRAND() % 10)) make_random_colormap( #if STANDALONE display, MI_WINDOW(mi), #else mi, #endif mp->cmap, mp->colors, &mp->ncolors, True, True, &mp->cycle_p); else if (!(LRAND() % 2)) make_uniform_colormap( #if STANDALONE display, MI_WINDOW(mi), #else mi, #endif mp->cmap, mp->colors, &mp->ncolors, True, &mp->cycle_p); else make_smooth_colormap( #if STANDALONE display, MI_WINDOW(mi), #else mi, #endif mp->cmap, mp->colors, &mp->ncolors, True, &mp->cycle_p); } XInstallColormap(display, mp->cmap); if (mp->ncolors < 2) { mp->ncolors = 2; mp->no_colors = True; } else mp->no_colors = False; if (mp->ncolors <= 2) mp->mono_p = True; if (mp->mono_p) mp->cycle_p = False; } if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) { if (mp->mono_p) { mp->cur_color = MI_BLACK_PIXEL(mi); } } Select(&mp->extreme_ul,&mp->extreme_lr, mp->screen_width,mp->screen_height, (int) mp->power,mp->reptop, mp->pow, mp->sin, &mp->ul,&mp->lr); }
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 init_map (struct state *st) { XGCValues gcv; XGetWindowAttributes (st->dpy, st->window, &st->xgwa); st->cmap = st->xgwa.colormap; st->flip_x = (random() % 2); st->flip_xy = (random() % 2); if (mono_p) st->flip_xy = 0; else if (st->colors) { free_colors (st->xgwa.screen, st->cmap, st->colors, st->ncolors); free (st->colors); } st->colors = 0; st->ncolors = get_integer_resource (st->dpy, "ncolors", "Integer"); st->delay = get_integer_resource (st->dpy, "delay", "Integer"); st->delay2 = get_integer_resource (st->dpy, "delay2", "Integer"); st->iterations = get_integer_resource (st->dpy, "iterations", "Integer"); if (st->iterations < 0) st->iterations = 0; else if (st->iterations > 7) st->iterations = 7; if (st->ncolors <= 2) st->ncolors = 0; if (st->ncolors == 0) mono_p = True; if (st->ncolors > 255) st->ncolors = 255; /* too many look bad */ if (!st->gc) st->gc = XCreateGC (st->dpy, st->window, 0, &gcv); if (!st->gc2) st->gc2 = XCreateGC (st->dpy, st->window, 0, &gcv); if (mono_p) st->extra_krinkly_p = !(random() % 15); else st->extra_krinkly_p = !(random() % 5); if (!mono_p) { if (st->ncolors < 1) st->ncolors = 1; if (st->colors) free (st->colors); st->colors = (XColor *) malloc (st->ncolors * sizeof(*st->colors)); make_smooth_colormap (st->xgwa.screen, st->xgwa.visual, st->cmap, st->colors, &st->ncolors, True, 0, False); if (st->ncolors <= 2) mono_p = 1; } if (mono_p) { int i; unsigned long fg_pixel = get_pixel_resource (st->dpy, st->xgwa.colormap, "foreground", "Foreground"); unsigned long bg_pixel = get_pixel_resource (st->dpy, st->xgwa.colormap, "background", "Background"); if (!st->colors) { st->ncolors = 50; st->colors = (XColor *) calloc (st->ncolors, sizeof(*st->colors)); } st->colors[0].pixel = fg_pixel; for (i = 1; i < st->ncolors; i++) st->colors[i].pixel = bg_pixel; } XSetForeground (st->dpy, st->gc, st->colors[1].pixel); XFillRectangle (st->dpy, st->window, st->gc, 0, 0, st->xgwa.width, st->xgwa.height); if (st->flip_xy) { st->xmax = st->xgwa.height; st->ymax = st->xgwa.width; } else { st->xmax = st->xgwa.width; st->ymax = st->xgwa.height; } if (st->cell) free (st->cell); st->cell = (signed char *) calloc (st->xmax * st->ymax, 1); CELL (0, 0) = 0; st->xstep = COUNT; st->ystep = COUNT; st->iteration = 0; st->cx = 0; }
/*- * init_swirl * * Initialise things for swirling * * - win is the window to draw in */ void init_swirl(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); swirlstruct *sp; /* does the swirls array exist? */ if (swirls == NULL) { int i; /* allocate an array, one entry for each screen */ if ((swirls = (swirlstruct *) calloc(MI_NUM_SCREENS(mi), sizeof (swirlstruct))) == NULL) return; /* initialise them all */ for (i = 0; i < MI_NUM_SCREENS(mi); i++) initialise_swirl(&swirls[i]); } /* get a pointer to this swirl */ sp = &(swirls[MI_SCREEN(mi)]); sp->mi = mi; /* get window parameters */ sp->width = MI_WIDTH(mi); sp->height = MI_HEIGHT(mi); sp->depth = MI_DEPTH(mi); sp->rdepth = sp->depth; sp->visual = MI_VISUAL(mi); if (sp->depth > 16) sp->depth = 16; /* initialise image for speeding up drawing */ if (!initialise_image(display, sp)) { free_swirl(display, sp); return; } MI_CLEARWINDOW(mi); if (!sp->gc) { if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) { XColor color; #ifndef STANDALONE sp->fg = MI_FG_PIXEL(mi); sp->bg = MI_BG_PIXEL(mi); #endif sp->blackpixel = MI_BLACK_PIXEL(mi); sp->whitepixel = MI_WHITE_PIXEL(mi); if ((sp->cmap = XCreateColormap(display, window, MI_VISUAL(mi), AllocNone)) == None) { free_swirl(display, sp); return; } XSetWindowColormap(display, window, sp->cmap); (void) XParseColor(display, sp->cmap, "black", &color); (void) XAllocColor(display, sp->cmap, &color); MI_BLACK_PIXEL(mi) = color.pixel; (void) XParseColor(display, sp->cmap, "white", &color); (void) XAllocColor(display, sp->cmap, &color); MI_WHITE_PIXEL(mi) = color.pixel; #ifndef STANDALONE (void) XParseColor(display, sp->cmap, background, &color); (void) XAllocColor(display, sp->cmap, &color); MI_BG_PIXEL(mi) = color.pixel; (void) XParseColor(display, sp->cmap, foreground, &color); (void) XAllocColor(display, sp->cmap, &color); MI_FG_PIXEL(mi) = color.pixel; #endif sp->colors = (XColor *) NULL; sp->ncolors = 0; } if ((sp->gc = XCreateGC(display, MI_WINDOW(mi), (unsigned long) 0, (XGCValues *) NULL)) == None) { free_swirl(display, sp); return; } } MI_CLEARWINDOW(mi); /* Set up colour map */ sp->direction = (LRAND() & 1) ? 1 : -1; if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) { if (sp->colors != NULL) { if (sp->ncolors && !sp->no_colors) free_colors(display, sp->cmap, sp->colors, sp->ncolors); free(sp->colors); sp->colors = (XColor *) NULL; } sp->ncolors = MI_NCOLORS(mi); if (sp->ncolors < 2) sp->ncolors = 2; if (sp->ncolors <= 2) sp->mono_p = True; else sp->mono_p = False; if (sp->mono_p) sp->colors = (XColor *) NULL; else if ((sp->colors = (XColor *) malloc(sizeof (*sp->colors) * (sp->ncolors + 1))) == NULL) { free_swirl(display, sp); return; } sp->cycle_p = has_writable_cells(mi); if (sp->cycle_p) { if (MI_IS_FULLRANDOM(mi)) { if (!NRAND(8)) sp->cycle_p = False; else sp->cycle_p = True; } else { sp->cycle_p = cycle_p; } } if (!sp->mono_p) { if (!(LRAND() % 10)) make_random_colormap( #if STANDALONE display, MI_WINDOW(mi), #else mi, #endif sp->cmap, sp->colors, &sp->ncolors, True, True, &sp->cycle_p); else if (!(LRAND() % 2)) make_uniform_colormap( #if STANDALONE display, MI_WINDOW(mi), #else mi, #endif sp->cmap, sp->colors, &sp->ncolors, True, &sp->cycle_p); else make_smooth_colormap( #if STANDALONE display, MI_WINDOW(mi), #else mi, #endif sp->cmap, sp->colors, &sp->ncolors, True, &sp->cycle_p); } XInstallColormap(display, sp->cmap); if (sp->ncolors < 2) { sp->ncolors = 2; sp->no_colors = True; } else sp->no_colors = False; if (sp->ncolors <= 2) sp->mono_p = True; if (sp->mono_p) sp->cycle_p = False; } if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) { if (sp->mono_p) { sp->cur_color = MI_BLACK_PIXEL(mi); } } /* resolution starts off chunky */ sp->resolution = MIN_RES + 1; /* calculate the pixel step for this resulution */ sp->r = (1 << (sp->resolution - 1)); /* how many knots? */ sp->n_knots = random_no((unsigned int) MI_COUNT(mi) / 2) + MI_COUNT(mi) + 1; /* what type of knots? */ sp->knot_type = ALL; /* for now */ /* use two_plane mode occaisionally */ if (random_no(100) <= TWO_PLANE_PCNT) { sp->two_plane = sp->first_plane = True; sp->max_resolution = 2; } else sp->two_plane = False; /* fix the knot values */ if (!create_knots(sp)) { free_swirl(display, sp); return; } /* we are off */ sp->started = True; sp->drawing = False; }
int main(int argc, char **argv) { int opt; int option_index = 0; char *socket_path = getenv("I3SOCK"); char *command = NULL; char *fontname = NULL; char *i3_default_sock_path = "/tmp/i3-ipc.sock"; struct xcb_color_strings_t colors = { NULL, }; /* Definition of the standard-config */ config.hide_on_modifier = 0; config.dockpos = DOCKPOS_NONE; config.disable_ws = 0; static struct option long_opt[] = { { "socket", required_argument, 0, 's' }, { "command", required_argument, 0, 'c' }, { "hide", no_argument, 0, 'm' }, { "dock", optional_argument, 0, 'd' }, { "font", required_argument, 0, 'f' }, { "nows", no_argument, 0, 'w' }, { "help", no_argument, 0, 'h' }, { "version", no_argument, 0, 'v' }, { "verbose", no_argument, 0, 'V' }, { "color-bar-fg", required_argument, 0, 'A' }, { "color-bar-bg", required_argument, 0, 'B' }, { "color-active-ws-fg", required_argument, 0, 'C' }, { "color-active-ws-bg", required_argument, 0, 'D' }, { "color-inactive-ws-fg", required_argument, 0, 'E' }, { "color-inactive-ws-bg", required_argument, 0, 'F' }, { "color-urgent-ws-bg", required_argument, 0, 'G' }, { "color-urgent-ws-fg", required_argument, 0, 'H' }, { "color-focus-ws-bg", required_argument, 0, 'I' }, { "color-focus-ws-fg", required_argument, 0, 'J' }, { NULL, 0, 0, 0} }; while ((opt = getopt_long(argc, argv, "s:c:d::mf:whvVA:B:C:D:E:F:G:H:I:J:", long_opt, &option_index)) != -1) { switch (opt) { case 's': socket_path = expand_path(optarg); break; case 'c': command = strdup(optarg); break; case 'm': config.hide_on_modifier = 1; break; case 'd': config.hide_on_modifier = 0; if (optarg == NULL) { config.dockpos = DOCKPOS_BOT; break; } if (!strcmp(optarg, "top")) { config.dockpos = DOCKPOS_TOP; } else if (!strcmp(optarg, "bottom")) { config.dockpos = DOCKPOS_BOT; } else { print_usage(argv[0]); exit(EXIT_FAILURE); } break; case 'f': fontname = strdup(optarg); break; case 'w': config.disable_ws = 1; break; case 'v': printf("i3bar version " I3_VERSION " © 2010-2011 Axel Wagner and contributors\n"); exit(EXIT_SUCCESS); break; case 'V': config.verbose = 1; break; case 'A': read_color(&colors.bar_fg); break; case 'B': read_color(&colors.bar_bg); break; case 'C': read_color(&colors.active_ws_fg); break; case 'D': read_color(&colors.active_ws_bg); break; case 'E': read_color(&colors.inactive_ws_fg); break; case 'F': read_color(&colors.inactive_ws_bg); break; case 'G': read_color(&colors.urgent_ws_bg); break; case 'H': read_color(&colors.urgent_ws_fg); break; case 'I': read_color(&colors.focus_ws_bg); break; case 'J': read_color(&colors.focus_ws_fg); break; default: print_usage(argv[0]); exit(EXIT_SUCCESS); break; } } if (fontname == NULL) { /* This is a very restrictive default. More sensefull would be something like * "-misc-*-*-*-*--*-*-*-*-*-*-*-*". But since that produces very ugly results * on my machine, let's stick with this until we have a configfile */ fontname = "-misc-fixed-medium-r-semicondensed--12-110-75-75-c-60-iso10646-1"; } if (config.dockpos != DOCKPOS_NONE) { if (config.hide_on_modifier) { ELOG("--dock and --hide are mutually exclusive!\n"); exit(EXIT_FAILURE); } } else { config.hide_on_modifier = 1; } main_loop = ev_default_loop(0); init_colors(&colors); char *atom_sock_path = init_xcb(fontname); if (socket_path == NULL) { socket_path = atom_sock_path; } if (socket_path == NULL) { ELOG("No Socket Path Specified, default to %s\n", i3_default_sock_path); socket_path = expand_path(i3_default_sock_path); } free_colors(&colors); init_outputs(); if (init_connection(socket_path)) { /* We subscribe to the i3-events we need */ subscribe_events(); /* We initiate the main-function by requesting infos about the outputs and * workspaces. Everything else (creating the bars, showing the right workspace- * buttons and more) is taken care of by the event-driveniness of the code */ i3_send_msg(I3_IPC_MESSAGE_TYPE_GET_OUTPUTS, NULL); if (!config.disable_ws) { i3_send_msg(I3_IPC_MESSAGE_TYPE_GET_WORKSPACES, NULL); } } /* The name of this function is actually misleading. Even if no -c is specified, * this function initiates the watchers to listen on stdin and react accordingly */ start_child(command); FREE(command); /* We listen to SIGTERM/QUIT/INT and try to exit cleanly, by stopping the main-loop. * We only need those watchers on the stack, so putting them on the stack saves us * some calls to free() */ ev_signal *sig_term = malloc(sizeof(ev_signal)); ev_signal *sig_int = malloc(sizeof(ev_signal)); ev_signal *sig_hup = malloc(sizeof(ev_signal)); if (sig_term == NULL || sig_int == NULL || sig_hup == NULL) { ELOG("malloc() failed: %s\n", strerror(errno)); exit(EXIT_FAILURE); } ev_signal_init(sig_term, &sig_cb, SIGTERM); ev_signal_init(sig_int, &sig_cb, SIGINT); ev_signal_init(sig_hup, &sig_cb, SIGHUP); ev_signal_start(main_loop, sig_term); ev_signal_start(main_loop, sig_int); ev_signal_start(main_loop, sig_hup); /* From here on everything should run smooth for itself, just start listening for * events. We stop simply stop the event-loop, when we are finished */ ev_loop(main_loop, 0); kill_child(); FREE(statusline_buffer); clean_xcb(); ev_default_destroy(); free_workspaces(); return 0; }
static void make_color_path(Display * dpy, Colormap cmap, int npoints, int *h, double *s, double *v, XColor * colors, int *ncolorsP, Bool allocate_p, Bool writable_p) { int i, k; int total_ncolors = *ncolorsP; int ncolors[MAXPOINTS]; /* number of pixels per edge */ double dh[MAXPOINTS]; /* distance between pixels, per edge (0 - 360.0) */ double ds[MAXPOINTS]; /* distance between pixels, per edge (0 - 1.0) */ double dv[MAXPOINTS]; /* distance between pixels, per edge (0 - 1.0) */ if (npoints == 0) { *ncolorsP = 0; return; } else if (npoints == 2) { /* using make_color_ramp() will be faster */ make_color_ramp(dpy, cmap, h[0], s[0], v[0], h[1], s[1], v[1], colors, ncolorsP, True, /* closed_p */ allocate_p, writable_p); return; } else if (npoints >= MAXPOINTS) { npoints = MAXPOINTS - 1; } AGAIN: { double DH[MAXPOINTS]; /* Distance between H values in the shortest direction around the circle, that is, the distance between 10 and 350 is 20. (Range is 0 - 360.0.) */ double edge[MAXPOINTS]; /* lengths of edges in unit HSV space. */ double ratio[MAXPOINTS]; /* proportions of the edges (total 1.0) */ double circum = 0; double one_point_oh = 0; /* (debug) */ for (i = 0; i < npoints; i++) { int j = (i + 1) % npoints; double d = ((double) (h[i] - h[j])) / 360; if (d < 0) d = -d; if (d > 0.5) d = 0.5 - (d - 0.5); DH[i] = d; } for (i = 0; i < npoints; i++) { int j = (i + 1) % npoints; edge[i] = sqrt((DH[i] * DH[j]) + ((s[j] - s[i]) * (s[j] - s[i])) + ((v[j] - v[i]) * (v[j] - v[i]))); circum += edge[i]; } #ifdef DEBUG (void) fprintf(stderr, "\ncolors:"); for (i = 0; i < npoints; i++) (void) fprintf(stderr, " (%d, %.3f, %.3f)", h[i], s[i], v[i]); (void) fprintf(stderr, "\nlengths:"); for (i = 0; i < npoints; i++) (void) fprintf(stderr, " %.3f", edge[i]); #endif /* DEBUG */ if (circum < 0.0001) goto FAIL; for (i = 0; i < npoints; i++) { ratio[i] = edge[i] / circum; one_point_oh += ratio[i]; } #ifdef DEBUG (void) fprintf(stderr, "\nratios:"); for (i = 0; i < npoints; i++) (void) fprintf(stderr, " %.3f", ratio[i]); #endif /* DEBUG */ if (one_point_oh < 0.99999 || one_point_oh > 1.00001) abort(); /* space the colors evenly along the circumference -- that means that the number of pixels on a edge is proportional to the length of that edge (relative to the lengths of the other edges.) */ for (i = 0; i < npoints; i++) ncolors[i] = (int) (total_ncolors * ratio[i]); #ifdef DEBUG (void) fprintf(stderr, "\npixels:"); for (i = 0; i < npoints; i++) (void) fprintf(stderr, " %d", ncolors[i]); (void) fprintf(stderr, " (%d)\n", total_ncolors); #endif /* DEBUG */ for (i = 0; i < npoints; i++) { int j = (i + 1) % npoints; if (ncolors[i] > 0) { dh[i] = 360 * (DH[i] / ncolors[i]); ds[i] = (s[j] - s[i]) / ncolors[i]; dv[i] = (v[j] - v[i]) / ncolors[i]; } } } (void) memset(colors, 0, (*ncolorsP) * sizeof (*colors)); k = 0; for (i = 0; i < npoints; i++) { int distance, direction, j; distance = h[(i + 1) % npoints] - h[i]; direction = (distance >= 0 ? -1 : 1); if (distance > 180) distance = 180 - (distance - 180); else if (distance < -180) distance = -(180 - ((-distance) - 180)); else direction = -direction; #ifdef DEBUG (void) fprintf(stderr, "point %d: %3d %.2f %.2f\n", i, h[i], s[i], v[i]); (void) fprintf(stderr, " h[i]=%d dh[i]=%.2f ncolors[i]=%d\n", h[i], dh[i], ncolors[i]); #endif /* DEBUG */ for (j = 0; j < ncolors[i]; j++, k++) { double hh = (h[i] + (j * dh[i] * direction)); if (hh < 0) hh += 360; else if (hh > 360) hh -= 0; colors[k].flags = DoRed | DoGreen | DoBlue; hsv_to_rgb((int) hh, (s[i] + (j * ds[i])), (v[i] + (j * dv[i])), &colors[k].red, &colors[k].green, &colors[k].blue); #ifdef DEBUG (void) fprintf(stderr, "point %d+%d: %.2f %.2f %.2f %04X %04X %04X\n", i, j, hh, (s[i] + (j * ds[i])), (v[i] + (j * dv[i])), colors[k].red, colors[k].green, colors[k].blue); #endif /* DEBUG */ } } /* Floating-point round-off can make us decide to use fewer colors. */ if (k < *ncolorsP) { *ncolorsP = k; if (k <= 0) return; } if (!allocate_p) return; if (writable_p) { unsigned long *pixels = (unsigned long *) malloc(sizeof (unsigned long) * ((*ncolorsP) + 1)); /* allocate_writable_colors() won't do here, because we need exactly this number of cells, or the color sequence we've chosen won't fit. */ if (!XAllocColorCells(dpy, cmap, False, 0, 0, pixels, *ncolorsP)) { free(pixels); goto FAIL; } for (i = 0; i < *ncolorsP; i++) colors[i].pixel = pixels[i]; free(pixels); XStoreColors(dpy, cmap, colors, *ncolorsP); } else { for (i = 0; i < *ncolorsP; i++) { XColor color; color = colors[i]; if (XAllocColor(dpy, cmap, &color)) { colors[i].pixel = color.pixel; } else { free_colors(dpy, cmap, colors, i); goto FAIL; } } } return; FAIL: /* we weren't able to allocate all the colors we wanted; decrease the requested number and try again. */ total_ncolors = (total_ncolors > 170 ? total_ncolors - 20 : total_ncolors > 100 ? total_ncolors - 10 : total_ncolors > 75 ? total_ncolors - 5 : total_ncolors > 25 ? total_ncolors - 3 : total_ncolors > 10 ? total_ncolors - 2 : total_ncolors > 2 ? total_ncolors - 1 : 0); *ncolorsP = total_ncolors; if (total_ncolors > 0) goto AGAIN; }
ENTRYPOINT void draw_triangle (ModeInfo * mi) { trianglestruct *tp = &triangles[MI_SCREEN(mi)]; int d, d2, i, j, delta; if (!tp->init_now) { draw_mesh(mi, tp, tp->d / 2, MAX_SIZE / tp->d); /* The init_now flag will pop up when the scene is complete. * Cycles specifies how long to wait, in 1/10 secs. TODO: This is wrong for multi-screens *** */ if (tp->init_now) { #ifndef STANDALONE MI_PAUSE(mi) = 2000000; #else if (tp->stage == -1) { XClearWindow(MI_DISPLAY(mi), MI_WINDOW(mi)); if (!mono_p) { free_colors(mi->xgwa.screen, mi->xgwa.colormap, mi->colors, mi->npixels); mi->npixels = get_integer_resource (mi->dpy, "ncolors", "Integer"); make_smooth_colormap (mi->xgwa.screen, mi->xgwa.visual, mi->xgwa.colormap, mi->colors, &mi->npixels, True, &mi->writable_p, True); } } #endif } return; } if (tp->delta[0] > 0) { if (!(++tp->stage)) { tp->h[0][0] = (short int) MAX(0, DISPLACE(0, tp->delta[0])); tp->h[tp->size][0] = (short int) MAX(0, DISPLACE(0, tp->delta[0])); tp->h[0][tp->size] = (short int) MAX(0, DISPLACE(0, tp->delta[0])); } else { d = 2 << (tp->steps - tp->stage); d2 = d / 2; delta = tp->delta[tp->stage - 1]; for (i = 0; i < tp->size; i += d) { for (j = 0; j < (tp->size - i); j += d) { tp->h[i + d2][j] = (short int) DISPLACE(tp->h[i][j] + tp->h[i + d][j], delta); tp->h[i][j + d2] = (short int) DISPLACE(tp->h[i][j] + tp->h[i][j + d], delta); tp->h[i + d2][j + d2] = (short int) DISPLACE(tp->h[i + d][j] + tp->h[i][j + d], delta); } tp->init_now = 0; tp->i = 0; tp->j = 0; tp->d = d; } } } if (tp->stage == tp->steps) { tp->stage = -1; } }
static struct starfish * reset_starfish (struct state *st) { XGCValues gcv; unsigned int flags = 0; XWindowAttributes xgwa; XGetWindowAttributes (st->dpy, st->window, &xgwa); st->cmap = xgwa.colormap; if (st->done_once) { if (st->colors && st->ncolors) free_colors (xgwa.screen, st->cmap, st->colors, st->ncolors); if (st->colors) free (st->colors); st->colors = 0; XFreeGC (st->dpy, st->gc); st->gc = 0; } 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() % 3) make_smooth_colormap (xgwa.screen, xgwa.visual, st->cmap, st->colors, &st->ncolors, True, 0, True); else make_uniform_colormap (xgwa.screen, xgwa.visual, st->cmap, st->colors, &st->ncolors, True, 0, True); if (st->ncolors < 2) st->ncolors = 2; if (st->ncolors <= 2) mono_p = True; st->fg_index = 0; if (!mono_p && !st->blob_p) { flags |= GCForeground; gcv.foreground = st->colors[st->fg_index].pixel; XSetWindowBackground (st->dpy, st->window, gcv.foreground); } if (!st->done_once) { XClearWindow (st->dpy, st->window); st->done_once = 1; } flags |= GCFillRule; gcv.fill_rule = EvenOddRule; st->gc = XCreateGC (st->dpy, st->window, flags, &gcv); #ifdef HAVE_JWXYZ if (!st->blob_p) jwxyz_XSetAntiAliasing (st->dpy, st->gc, False); #endif return make_window_starfish (st); }
static void reset_boxes (state *st) { st->nboxes = 0; st->growing_p = True; st->color_horiz_p = random() & 1; if (st->done_once && st->colors) free_colors (st->xgwa.screen, st->xgwa.colormap, st->colors, st->ncolors); if (!st->done_once) { char *s = get_string_resource (st->dpy, "mode", "Mode"); if (!s || !*s || !strcasecmp (s, "random")) st->mode = -1; else if (!strcasecmp (s, "squares") || !strcasecmp (s, "square")) st->mode = 0; else if (!strcasecmp (s, "circles") || !strcasecmp (s, "circle")) st->mode = 1; else { fprintf (stderr, "%s: mode must be random, squares, or circles, not '%s'\n", progname, s); exit (1); } } if (st->mode == -1) st->circles_p = random() & 1; else st->circles_p = (st->mode == 1); st->done_once = True; if (st->image || get_boolean_resource (st->dpy, "grab", "Boolean")) { if (st->image) XDestroyImage (st->image); st->image = 0; if (st->loading_pixmap) abort(); if (st->img_loader) abort(); if (!get_boolean_resource (st->dpy, "peek", "Boolean")) st->loading_pixmap = XCreatePixmap (st->dpy, st->window, st->xgwa.width, st->xgwa.height, st->xgwa.depth); XClearWindow (st->dpy, st->window); st->img_loader = load_image_async_simple (0, st->xgwa.screen, st->window, (st->loading_pixmap ? st->loading_pixmap : st->window), 0, 0); } else { st->ncolors = get_integer_resource (st->dpy, "colors", "Colors"); /* re-get */ if (st->ncolors < 1) st->ncolors = 1; make_smooth_colormap (st->xgwa.screen, st->xgwa.visual, st->xgwa.colormap, st->colors, &st->ncolors, True, 0, False); if (st->ncolors < 1) abort(); XClearWindow (st->dpy, st->window); } }
int ColorModel::alloc_color(color& c) { #ifdef MAC_OSX_TK abort(); #else int r = c.r; int g = c.g; int b = c.b; if (gamma_ != 1.) { r = int(256. * pow(r / 256., gamma_)); g = int(256. * pow(g / 256., gamma_)); b = int(256. * pow(b / 256., gamma_)); } #ifndef WIN32 if (r == g && r == b && (r & 7) == 0 && r > 0) { /* * This color is one level away from the gray ramp * used in nv, ghostscript, and the LBL-modified * tk library. Change it so we'll end up sharing * the colormap entry. The error won't be perceptible. */ r -= 1; g -= 1; b -= 1; } #endif XColor xc; xc.red = r << 8; xc.green = g << 8; xc.blue = b << 8; if (XAllocColor(dpy_, colormap_, &xc) == 0) { free_colors(); return (-1); } #ifdef WIN32 /* * The current WinTk returns RGB values in the pixel. X returns * a colormap index. So get the palette index and use that. */ TkWinColormap *cmap = (TkWinColormap *) colormap_; UINT index = GetNearestPaletteIndex(cmap->palette, PALETTERGB(r, g, b)); int pixel = index; pixel_[index] = xc.pixel; color& p = colors_[ncolor_]; if (++ncolor_ >= 256) { fprintf(stderr, "vic: colormap overflow (internal error)\n"); exit(1); } #if defined(WIN32) && (TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION == 0) if (!win32Colors) win32Colors = pixel_; win32NColors = ncolor_; #endif #else int pixel = xc.pixel; pixel_[ncolor_] = pixel; if (++ncolor_ >= 256) { fprintf(stderr, "vic: colormap overflow (internal error)\n"); exit(1); } color& p = colors_[pixel]; #endif p.r = xc.red >> 8; p.g = xc.green >> 8; p.b = xc.blue >> 8; /* XXX ed ditherer needs this */ rgb_to_yuv(p); return (pixel); #endif // MAC_OSX_TK }
ColorModel::~ColorModel() { free_colors(); }
void init_toneclock(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); int i, size_hour, istart; toneclockstruct *tclock; /* initialize */ if (toneclocks == NULL) { if ((toneclocks = (toneclockstruct *) calloc(MI_NUM_SCREENS(mi), sizeof (toneclockstruct))) == NULL) return; } tclock = &toneclocks[MI_SCREEN(mi)]; tclock->mi = mi; if (tclock->gc == None) { if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) { XColor color; #ifndef STANDALONE tclock->fg = MI_FG_PIXEL(mi); tclock->bg = MI_BG_PIXEL(mi); #endif tclock->blackpixel = MI_BLACK_PIXEL(mi); tclock->whitepixel = MI_WHITE_PIXEL(mi); if ((tclock->cmap = XCreateColormap(display, window, MI_VISUAL(mi), AllocNone)) == None) { free_toneclock(display, tclock); return; } XSetWindowColormap(display, window, tclock->cmap); (void) XParseColor(display, tclock->cmap, "black", &color); (void) XAllocColor(display, tclock->cmap, &color); MI_BLACK_PIXEL(mi) = color.pixel; (void) XParseColor(display, tclock->cmap, "white", &color); (void) XAllocColor(display, tclock->cmap, &color); MI_WHITE_PIXEL(mi) = color.pixel; #ifndef STANDALONE (void) XParseColor(display, tclock->cmap, background, &color); (void) XAllocColor(display, tclock->cmap, &color); MI_BG_PIXEL(mi) = color.pixel; (void) XParseColor(display, tclock->cmap, foreground, &color); (void) XAllocColor(display, tclock->cmap, &color); MI_FG_PIXEL(mi) = color.pixel; #endif tclock->colors = (XColor *) NULL; tclock->ncolors = 0; } if ((tclock->gc = XCreateGC(display, MI_WINDOW(mi), (unsigned long) 0, (XGCValues *) NULL)) == None) { free_toneclock(display, tclock); return; } } /* Clear Display */ MI_CLEARWINDOW(mi); tclock->painted = False; XSetFunction(display, tclock->gc, GXxor); /*Set up toneclock data */ if (MI_IS_FULLRANDOM(mi)) { if (NRAND(10)) tclock->original = False; else tclock->original = True; } else { tclock->original = original; } tclock->direction = (LRAND() & 1) ? 1 : -1; tclock->win_width = MI_WIDTH(mi); tclock->win_height = MI_HEIGHT(mi); if (tclock->hour != NULL) free_hour(tclock); if ( tclock->original ) { tclock->num_hour = 12; } else { tclock->num_hour = MI_COUNT(mi); } tclock->x0 = tclock->win_width / 2; tclock->y0 = tclock->win_height / 2; if (tclock->num_hour == 0) { tclock->num_hour = DEF_NUM_hour; } else if (tclock->num_hour < 0) { tclock->num_hour = NRAND(-tclock->num_hour) + 1; } if ( tclock->num_hour < 12 ) istart = NRAND( 12 - tclock->num_hour ); else istart = 0; if ((tclock->hour = (toneclockhour *) calloc(tclock->num_hour, sizeof (toneclockhour))) == NULL) { free_toneclock(display, tclock); return; } if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) { /* Set up colour map */ if (tclock->colors != NULL) { if (tclock->ncolors && !tclock->no_colors) free_colors(display, tclock->cmap, tclock->colors, tclock->ncolors); free(tclock->colors); tclock->colors = (XColor *) NULL; } tclock->ncolors = MI_NCOLORS(mi); if (tclock->ncolors < 2) tclock->ncolors = 2; if (tclock->ncolors <= 2) tclock->mono_p = True; else tclock->mono_p = False; if (tclock->mono_p) tclock->colors = (XColor *) NULL; else if ((tclock->colors = (XColor *) malloc(sizeof (*tclock->colors) * (tclock->ncolors + 1))) == NULL) { free_toneclock(display, tclock); return; } tclock->cycle_p = has_writable_cells(mi); if (tclock->cycle_p) { if (MI_IS_FULLRANDOM(mi)) { if (!NRAND(8)) tclock->cycle_p = False; else tclock->cycle_p = True; } else { tclock->cycle_p = cycle_p; } } if (!tclock->mono_p) { if (!(LRAND() % 10)) make_random_colormap( #ifdef STANDALONE MI_DISPLAY(mi), MI_WINDOW(mi), #else mi, #endif tclock->cmap, tclock->colors, &tclock->ncolors, True, True, &tclock->cycle_p); else if (!(LRAND() % 2)) make_uniform_colormap( #ifdef STANDALONE MI_DISPLAY(mi), MI_WINDOW(mi), #else mi, #endif tclock->cmap, tclock->colors, &tclock->ncolors, True, &tclock->cycle_p); else make_smooth_colormap( #ifdef STANDALONE MI_DISPLAY(mi), MI_WINDOW(mi), #else mi, #endif tclock->cmap, tclock->colors, &tclock->ncolors, True, &tclock->cycle_p); } XInstallColormap(display, tclock->cmap); if (tclock->ncolors < 2) { tclock->ncolors = 2; tclock->no_colors = True; } else tclock->no_colors = False; if (tclock->ncolors <= 2) tclock->mono_p = True; if (tclock->mono_p) tclock->cycle_p = False; } #ifndef NO_DBUF if (tclock->dbuf != None) XFreePixmap(display, tclock->dbuf); tclock->dbuf = XCreatePixmap(display, window, tclock->win_width, tclock->win_height, MI_DEPTH(mi)); /* Allocation checked */ if (tclock->dbuf != None) { XGCValues gcv; gcv.foreground = 0; gcv.background = 0; gcv.graphics_exposures = False; gcv.function = GXcopy; if (tclock->dbuf_gc != None) XFreeGC(display, tclock->dbuf_gc); if ((tclock->dbuf_gc = XCreateGC(display, (Drawable) tclock->dbuf, GCForeground | GCBackground | GCGraphicsExposures | GCFunction, &gcv)) == None) { XFreePixmap(display, tclock->dbuf); tclock->dbuf = None; } else { XFillRectangle(display, (Drawable) tclock->dbuf, tclock->dbuf_gc, 0, 0, tclock->win_width, tclock->win_height); /*XSetBackground(display, MI_GC(mi), MI_BLACK_PIXEL(mi)); XSetFunction(display, MI_GC(mi), GXcopy);*/ } } #endif tclock->angle = NRAND(360) * PI_RAD; tclock->velocity = (NRAND(7) - 3) * PI_RAD; size_hour = MIN( tclock->win_width , tclock->win_height) / 3; tclock->pulsating = False; tclock->moving = False; tclock->anglex = 0.0; tclock->angley = 0.0; tclock->fill = 0; tclock->radius = size_hour; tclock->max_radius =0.0; if ( ( !tclock->original && NRAND( 15 ) == 3 ) || tclock->num_hour > 12 ) tclock->randomhour = True; else tclock->randomhour = False; if ( !tclock->original && tclock->win_width > 20 ) { if ( abs( MI_SIZE(mi) ) > size_hour ) { if ( MI_SIZE( mi ) < 0 ) { size_hour = -size_hour; } } else { size_hour = MI_SIZE(mi); } if ( size_hour < 0 ) { tclock->radius = MIN(NRAND( size_hour - 10) + 10, tclock->radius ); } else { tclock->radius = MIN( size_hour , tclock->radius ); } if ( MI_IS_FULLRANDOM( mi ) ) { if ( NRAND(2) ) tclock->pulsating = True; else tclock->pulsating = False; tclock->fill = NRAND( 101 ); } else { tclock->pulsating = pulsating; tclock->fill = fill; } } tclock->phase = 0.0; if ( tclock->pulsating ) tclock->ph_vel = (NRAND(7) - 3) * PI_RAD; for (i = 0; i < tclock->num_hour; i++) { toneclockhour *hour0; hour0 = &tclock->hour[i]; if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) { if (tclock->ncolors > 2) hour0->colour = NRAND(tclock->ncolors - 2) + 2; else hour0->colour = 1; /* Just in case */ XSetForeground(display, tclock->gc, tclock->colors[hour0->colour].pixel); } else { if (MI_NPIXELS(mi) > 2) hour0->colour = MI_PIXEL(mi, NRAND(MI_NPIXELS(mi))); else hour0->colour = 1; /*Xor'red so WHITE may not be appropriate */ XSetForeground(display, tclock->gc, hour0->colour); } hour0->angle = NRAND(360) * PI_RAD; hour0->velocity = (NRAND(7) - 3) * PI_RAD; hour0->radius = tclock->radius / 5.0; tclock->max_radius = MAX( tclock->max_radius , hour0->radius ); hour0->num_point = 12; hour0->num_point1 = 16; if ( tclock->randomhour ) { int j; hour0->point_numbers = tclock->hexadecimal_clock + i * hour0->num_point1; if ( NRAND( 14 ) == 4 ) { for (j = 0; j < ( hour0->num_point1 / 4 ) - 1 ; j++) { hour0->point_numbers[ j * 4 ] = NRAND( 12 ) + 1; hour0->point_numbers[ j * 4 + 1 ] = NRAND( 12 ) + 1; hour0->point_numbers[ j * 4 + 2 ] = NRAND( 12 ) + 1; hour0->point_numbers[ j * 4 + 3 ] = NRAND( 12 ) + 1; } hour0->point_numbers[ hour0->num_point1 / 4 ] = 1; hour0->point_numbers[ 1 + hour0->num_point1 / 4 ] = 1; hour0->point_numbers[ 2 + hour0->num_point1 / 4 ] = 1; hour0->point_numbers[ 3 + hour0->num_point1 / 4 ] = 1; } else { for (j = 0; j < hour0->num_point1 / 4 ; j++) { hour0->point_numbers[ j * 4 ] = NRAND( 12 ) + 1; hour0->point_numbers[ j * 4 + 1 ] = hour0->point_numbers[ j * 4 ]; hour0->point_numbers[ j * 4 + 2 ] = NRAND( 12 ) + 1; hour0->point_numbers[ j * 4 + 3 ] = NRAND( 12 ) + 1; } } } else hour0->point_numbers = original_clock[i+istart]; if ( NRAND( 100 ) >= tclock->fill ) hour0->draw = True; else hour0->draw = False; #ifdef NO_DBUF { int x0 , y0; x0 = (int) (tclock->radius * sin( -tclock->angle - PI_RAD * i * 360.0 / tclock->num_hour ) * 0.5 * ( 1 + cos( tclock->phase ) ) + tclock->x0 + tclock->a_x * sin( tclock->anglex ) ); y0 = (int) (tclock->radius * cos( -tclock->angle - PI_RAD * i * 360.0 / tclock->num_hour ) * 0.5 * ( 1 + cos( tclock->phase ) ) + tclock->y0 + tclock->a_y * sin( tclock->angley ) ); toneclock_drawhour(mi , hour0 , x0 , y0 ); } #endif } tclock->a_x = 0; tclock->a_y = 0; if ( !tclock->original && tclock->win_width > 20 ) { if ( tclock->radius < MIN( tclock->win_width , tclock->win_height) / 4 ) { if ( MI_IS_FULLRANDOM( mi ) ) { if ( NRAND(2) ) tclock->moving = True; } else { tclock->moving = move_clock; } if ( tclock->moving ) { tclock->a_x = (int) floor( ( tclock->win_width / 2 ) - 1.05 * ( tclock->radius + tclock->max_radius ) ); tclock->a_y = (int) floor( ( tclock->win_height / 2 ) - 1.05 * ( tclock->radius + tclock->max_radius ) ); tclock->vx = (NRAND(15) - 7) * PI_RAD; tclock->vy = (NRAND(15) - 7) * PI_RAD; } } } XFlush(display); XSetFunction(display, tclock->gc, GXcopy); }
void init_tik_tak(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); int i, max_objects, size_object; tik_takstruct *tiktak; /* initialize */ if (tik_taks == NULL) { if ((tik_taks = (tik_takstruct *) calloc(MI_NUM_SCREENS(mi), sizeof (tik_takstruct))) == NULL) return; } tiktak = &tik_taks[MI_SCREEN(mi)]; tiktak->mi = mi; if (tiktak->gc == None) { if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) { XColor color; #ifndef STANDALONE tiktak->fg = MI_FG_PIXEL(mi); tiktak->bg = MI_BG_PIXEL(mi); #endif tiktak->blackpixel = MI_BLACK_PIXEL(mi); tiktak->whitepixel = MI_WHITE_PIXEL(mi); if ((tiktak->cmap = XCreateColormap(display, window, MI_VISUAL(mi), AllocNone)) == None) { free_tik_tak(display, tiktak); return; } XSetWindowColormap(display, window, tiktak->cmap); (void) XParseColor(display, tiktak->cmap, "black", &color); (void) XAllocColor(display, tiktak->cmap, &color); MI_BLACK_PIXEL(mi) = color.pixel; (void) XParseColor(display, tiktak->cmap, "white", &color); (void) XAllocColor(display, tiktak->cmap, &color); MI_WHITE_PIXEL(mi) = color.pixel; #ifndef STANDALONE (void) XParseColor(display, tiktak->cmap, background, &color); (void) XAllocColor(display, tiktak->cmap, &color); MI_BG_PIXEL(mi) = color.pixel; (void) XParseColor(display, tiktak->cmap, foreground, &color); (void) XAllocColor(display, tiktak->cmap, &color); MI_FG_PIXEL(mi) = color.pixel; #endif tiktak->colors = (XColor *) NULL; tiktak->ncolors = 0; } if ((tiktak->gc = XCreateGC(display, MI_WINDOW(mi), (unsigned long) 0, (XGCValues *) NULL)) == None) { free_tik_tak(display, tiktak); return; } } /* Clear Display */ MI_CLEARWINDOW(mi); tiktak->painted = False; XSetFunction(display, tiktak->gc, GXxor); /*Set up tik_tak data */ tiktak->direction = (LRAND() & 1) ? 1 : -1; tiktak->win_width = MI_WIDTH(mi); tiktak->win_height = MI_HEIGHT(mi); tiktak->num_object = MI_COUNT(mi); tiktak->x0 = tiktak->win_width / 2; tiktak->y0 = tiktak->win_height / 2; max_objects = MI_COUNT(mi); if (tiktak->num_object == 0) { tiktak->num_object = DEF_NUM_OBJECT; max_objects = DEF_NUM_OBJECT; } else if (tiktak->num_object < 0) { max_objects = -tiktak->num_object; tiktak->num_object = NRAND(-tiktak->num_object) + 1; } if (tiktak->object == NULL) if ((tiktak->object = (tik_takobject *) calloc(max_objects, sizeof (tik_takobject))) == NULL) { free_tik_tak(display, tiktak); return; } size_object = MIN( tiktak->win_width , tiktak->win_height) / 3; if ( abs( MI_SIZE(mi) ) > size_object) { if ( MI_SIZE( mi ) < 0 ) { size_object = -size_object; } } else { size_object = MI_SIZE(mi); } if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) { /* Set up colour map */ if (tiktak->colors != NULL) { if (tiktak->ncolors && !tiktak->no_colors) free_colors(display, tiktak->cmap, tiktak->colors, tiktak->ncolors); free(tiktak->colors); tiktak->colors = (XColor *) NULL; } tiktak->ncolors = MI_NCOLORS(mi); if (tiktak->ncolors < 2) tiktak->ncolors = 2; if (tiktak->ncolors <= 2) tiktak->mono_p = True; else tiktak->mono_p = False; if (tiktak->mono_p) tiktak->colors = (XColor *) NULL; else if ((tiktak->colors = (XColor *) malloc(sizeof (*tiktak->colors) * (tiktak->ncolors + 1))) == NULL) { free_tik_tak(display, tiktak); return; } tiktak->cycle_p = has_writable_cells(mi); if (tiktak->cycle_p) { if (MI_IS_FULLRANDOM(mi)) { if (!NRAND(8)) tiktak->cycle_p = False; else tiktak->cycle_p = True; } else { tiktak->cycle_p = cycle_p; } } if (!tiktak->mono_p) { if (!(LRAND() % 10)) make_random_colormap( #ifdef STANDALONE MI_DISPLAY(mi), MI_WINDOW(mi), #else mi, #endif tiktak->cmap, tiktak->colors, &tiktak->ncolors, True, True, &tiktak->cycle_p); else if (!(LRAND() % 2)) make_uniform_colormap( #ifdef STANDALONE MI_DISPLAY(mi), MI_WINDOW(mi), #else mi, #endif tiktak->cmap, tiktak->colors, &tiktak->ncolors, True, &tiktak->cycle_p); else make_smooth_colormap( #ifdef STANDALONE MI_DISPLAY(mi), MI_WINDOW(mi), #else mi, #endif tiktak->cmap, tiktak->colors, &tiktak->ncolors, True, &tiktak->cycle_p); } XInstallColormap(display, tiktak->cmap); if (tiktak->ncolors < 2) { tiktak->ncolors = 2; tiktak->no_colors = True; } else tiktak->no_colors = False; if (tiktak->ncolors <= 2) tiktak->mono_p = True; if (tiktak->mono_p) tiktak->cycle_p = False; } for (i = 0; i < tiktak->num_object; i++) { tik_takobject *object0; object0 = &tiktak->object[i]; if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) { if (tiktak->ncolors > 2) object0->colour = NRAND(tiktak->ncolors - 2) + 2; else object0->colour = 1; /* Just in case */ XSetForeground(display, tiktak->gc, tiktak->colors[object0->colour].pixel); } else { if (MI_NPIXELS(mi) > 2) object0->colour = MI_PIXEL(mi, NRAND(MI_NPIXELS(mi))); else object0->colour = 1; /*Xor'red so WHITE may not be appropriate */ XSetForeground(display, tiktak->gc, object0->colour); } object0->angle = NRAND(90) * PI_RAD; object0->angle1 = NRAND(90) * PI_RAD; object0->velocity_a = (NRAND(7) - 3) * PI_RAD; object0->velocity_a1 = (NRAND(7) - 3) * PI_RAD; if (size_object == 0) object0->size_ob = 9; else if (size_object > 0) object0->size_ob = size_object; else object0->size_ob = NRAND(-size_object) + 1; object0->size_ob++; object0->num_point = NRAND(6)+3; if (LRAND() & 1) object0->size_mult = 1.0; else { object0->num_point *= 2; object0->size_mult = 1.0 - ( 1.0 / (float) ((LRAND() & 1) + 2 ) ); } if (object0->xy != NULL) free(object0->xy); if ((object0->xy = (XPoint *) malloc(sizeof( XPoint ) * (2 * object0->num_point + 2))) == NULL) { free_tik_tak(display, tiktak); return; } if ((LRAND() & 1) || object0->size_ob < 10 ) { object0->inner = False; if ( object0->xy1 != NULL ) free( object0->xy1 ); object0->xy1 = (XPoint *) NULL; } else { object0->inner = True; object0->size_ob1 = object0->size_ob - NRAND( object0->size_ob / 5 ) - 1; object0->num_point1 = NRAND(6)+3; if (LRAND() & 1) object0->size_mult1 = 1.0; else { object0->num_point1 *= 2; object0->size_mult1 = 1.0 - ( 1.0 / (float) ((LRAND() & 1) + 2 ) ); } if (object0->xy1 != NULL) free(object0->xy1); if ((object0->xy1 = (XPoint *) malloc(sizeof( XPoint ) * (2 * object0->num_point1 + 2))) == NULL) { free_tik_tak(display, tiktak); return; } object0->size_mult1 = 1.0; } tik_tak_setupobject( mi , object0); tik_tak_reset_object( object0); tik_tak_drawobject(mi, object0 ); } XFlush(display); XSetFunction(display, tiktak->gc, GXcopy); }
/* Free allocated colormap created by setup_colormap. */ static void free_colormap (struct state *st, XColor **colors, int n_colors) { free_colors (st->wattr.screen, st->wattr.colormap, *colors, n_colors); free (*colors); }
void make_color_ramp(Display * dpy, Colormap cmap, int h1, double s1, double v1, /* 0-360, 0-1.0, 0-1.0 */ int h2, double s2, double v2, /* 0-360, 0-1.0, 0-1.0 */ XColor * colors, int *ncolorsP, Bool closed_p, Bool allocate_p, Bool writable_p) { int i; int ncolors = *ncolorsP; double dh, ds, dv; /* deltas */ AGAIN: (void) memset(colors, 0, (*ncolorsP) * sizeof (*colors)); if (closed_p) ncolors = (ncolors / 2) + 1; /* Note: unlike other routines in this module, this function assumes that if h1 and h2 are more than 180 degrees apart, then the desired direction is always from h1 to h2 (rather than the shorter path.) make_uniform depends on this. */ dh = ((double) h2 - (double) h1) / ncolors; ds = (s2 - s1) / ncolors; dv = (v2 - v1) / ncolors; for (i = 0; i < ncolors; i++) { colors[i].flags = DoRed | DoGreen | DoBlue; hsv_to_rgb((int) (h1 + (i * dh)), (s1 + (i * ds)), (v1 + (i * dv)), &colors[i].red, &colors[i].green, &colors[i].blue); } if (closed_p) for (i = ncolors; i < *ncolorsP; i++) colors[i] = colors[(*ncolorsP) - i]; if (!allocate_p) return; if (writable_p) { unsigned long *pixels; if ((pixels = (unsigned long *) malloc(sizeof (unsigned long) * ((*ncolorsP) + 1))) == NULL) { goto FAIL; } /* allocate_writable_colors() won't do here, because we need exactly this number of cells, or the color sequence we've chosen won't fit. */ if (!XAllocColorCells(dpy, cmap, False, 0, 0, pixels, *ncolorsP)) { free(pixels); goto FAIL; } for (i = 0; i < *ncolorsP; i++) colors[i].pixel = pixels[i]; free(pixels); XStoreColors(dpy, cmap, colors, *ncolorsP); } else { for (i = 0; i < *ncolorsP; i++) { XColor color; color = colors[i]; if (XAllocColor(dpy, cmap, &color)) { colors[i].pixel = color.pixel; } else { free_colors(dpy, cmap, colors, i); goto FAIL; } } } return; FAIL: /* we weren't able to allocate all the colors we wanted; decrease the requested number and try again. */ ncolors = (ncolors > 170 ? ncolors - 20 : ncolors > 100 ? ncolors - 10 : ncolors > 75 ? ncolors - 5 : ncolors > 25 ? ncolors - 3 : ncolors > 10 ? ncolors - 2 : ncolors > 2 ? ncolors - 1 : 0); *ncolorsP = ncolors; if (ncolors > 0) goto AGAIN; }