Imlib_Image scrot_grab_shot_multi(void) { int screens; int i; char *dispstr, *subdisp; char newdisp[255]; gib_list *images = NULL; Imlib_Image ret = NULL; screens = ScreenCount(disp); if (screens < 2) return scrot_grab_shot(); dispstr = DisplayString(disp); subdisp = gib_estrdup(DisplayString(disp)); for (i = 0; i < screens; i++) { dispstr = strchr(subdisp, ':'); if (dispstr) { dispstr = strchr(dispstr, '.'); if (NULL != dispstr) *dispstr = '\0'; } snprintf(newdisp, sizeof(newdisp), "%s.%d", subdisp, i); init_x_and_imlib(newdisp, i); ret = gib_imlib_create_image_from_drawable(root, 0, 0, 0, scr->width, scr->height, 1); images = gib_list_add_end(images, ret); } free(subdisp); ret = stalk_image_concat(images); return ret; }
gib_list *feh_wrap_string(char *text, int wrap_width, Imlib_Font fn, gib_style * style) { gib_list *ll, *lines = NULL, *list = NULL, *words; gib_list *l = NULL; char delim[2] = { '\n', '\0' }; int w, line_width; int tw, th; char *p, *pp; char *line = NULL; char *temp; int space_width = 0, m_width = 0, t_width = 0, new_width = 0; lines = gib_string_split(text, delim); if (wrap_width) { gib_imlib_get_text_size(fn, "M M", style, &t_width, NULL, IMLIB_TEXT_TO_RIGHT); gib_imlib_get_text_size(fn, "M", style, &m_width, NULL, IMLIB_TEXT_TO_RIGHT); space_width = t_width - (2 * m_width); w = wrap_width; l = lines; while (l) { line_width = 0; p = (char *) l->data; /* quick check to see if whole line fits okay */ gib_imlib_get_text_size(fn, p, style, &tw, &th, IMLIB_TEXT_TO_RIGHT); if (tw <= w) { list = gib_list_add_end(list, estrdup(p)); } else if (strlen(p) == 0) { list = gib_list_add_end(list, estrdup("")); } else if (!strcmp(p, " ")) { list = gib_list_add_end(list, estrdup(" ")); } else { words = gib_string_split(p, " "); if (words) { ll = words; while (ll) { pp = (char *) ll->data; if (strcmp(pp, " ")) { gib_imlib_get_text_size (fn, pp, style, &tw, &th, IMLIB_TEXT_TO_RIGHT); if (line_width == 0) new_width = tw; else new_width = line_width + space_width + tw; if (new_width <= w) { /* add word to line */ if (line) { int len; len = strlen(line) + strlen(pp) + 2; temp = emalloc(len); snprintf(temp, len, "%s %s", line, pp); free(line); line = temp; } else { line = estrdup(pp); } line_width = new_width; } else if (line_width == 0) { /* can't fit single word in :/ increase width limit to width of word and jam the bastard in anyhow */ w = tw; line = estrdup(pp); line_width = new_width; } else { /* finish this line, start next and add word there */ if (line) { list = gib_list_add_end(list, estrdup(line)); free(line); line = NULL; } line = estrdup(pp); line_width = tw; } } ll = ll->next; } if (line) { /* finish last line */ list = gib_list_add_end(list, estrdup(line)); free(line); line = NULL; line_width = 0; } gib_list_free_and_data(words); } } l = l->next; } gib_list_free_and_data(lines); lines = list; } return lines; }