MvwmPicture *PCacheMvwmPicture( Display *dpy, Window win, char *ImagePath, const char *name, MvwmPictureAttributes fpa) { char *path; char *real_path; MvwmPicture *p = MvwmPictureList; /* First find the full pathname */ if ((path = PictureFindImageFile(name, ImagePath, R_OK)) == NULL) { return NULL; } real_path = path; /* See if the picture is already cached */ while (p) { register char *p1, *p2; for (p1 = path, p2 = p->name; *p1 && *p2; ++p1, ++p2) { if (*p1 != *p2) { break; } } /* If we have found a picture with the wanted name and stamp */ if (!*p1 && !*p2 && !isFileStampChanged(&p->stamp, real_path) && PICTURE_FPA_AGREE(p,fpa)) { p->count++; /* Put another weight on the picture */ free(path); return p; } p=p->next; } /* Not previously cached, have to load it ourself. Put it first in list */ p = PImageLoadMvwmPictureFromFile(dpy, win, path, fpa); if(p) { p->next=MvwmPictureList; MvwmPictureList=p; } else { free(path); } return p; }
Bool GetBackPixmap(void) { Pixmap maskPixmap; char *path = NULL; Pixmap tmp_pixmap; int w=0, h=0; int icon_depth = 0; FvwmPictureAttributes fpa; fpa.mask = FPAM_NO_ALLOC_PIXELS | FPAM_NO_ALPHA; if (Pdepth <= 8) { fpa.mask |= FPAM_DITHER; } if (IconwinPixmapFile == NULL) return False; path = PictureFindImageFile(IconwinPixmapFile, imagePath, R_OK); if (path == NULL) { return False; } if (!PImageLoadPixmapFromFile( dpy, main_win, path, &tmp_pixmap, &maskPixmap, NULL, &w, &h, &icon_depth, 0, NULL, 0, fpa)) { w = 0; h = 0; fprintf(stderr, "[FvwmIconBox] Problem creating pixmap from " "file: %s\n", path); free(path); return False; } if (icon_depth == 1) { IconwinPixmap = XCreatePixmap(dpy, main_win, w, h, Pdepth); XCopyPlane(dpy, tmp_pixmap, IconwinPixmap, NormalGC, 0, 0, w, h, 0, 0, 1); XFreePixmap(dpy, tmp_pixmap); } else { IconwinPixmap = tmp_pixmap; } free(path); if (w != 0 && h != 0) return True; return False; }
FvwmPicture *PGetFvwmPicture( Display *dpy, Window win, char *ImagePath, const char *name, FvwmPictureAttributes fpa) { char *path = PictureFindImageFile(name, ImagePath, R_OK); FvwmPicture *p; if (path == NULL) { return NULL; } p = PImageLoadFvwmPictureFromFile(dpy, win, path, fpa); if (p == NULL) { free(path); } return p; }
/* * * Looks for icon from a file * */ void GetIconFromFile(struct icon_info *item) { char *path = PictureFindImageFile(item->icon_file, imagePath, R_OK); FvwmPictureAttributes fpa; if (NULL == path) { fprintf(stderr, "[FvwmIconBox] cannot find %s on ImagePath %s\n", item->icon_file, imagePath); return; } fpa.mask = 0; if (Iconcolorset >= 0 && Colorset[Iconcolorset].do_dither_icon) { fpa.mask |= FPAM_DITHER; } item->icon_w = 0; item->icon_h = 0; if (!PImageLoadPixmapFromFile( dpy, main_win, path, &item->iconPixmap, &item->icon_maskPixmap, &item->icon_alphaPixmap, &item->icon_w, &item->icon_h, &item->icon_depth, &item->icon_nalloc_pixels, &item->icon_alloc_pixels, &item->icon_no_limit, fpa)) { fprintf(stderr, "[FvwmIconBox] cannot load pixmap from " "file '%s'\n",path); item->icon_w = 0; item->icon_h = 0; return; } item->icon_w = min(max_icon_width, item->icon_w); item->icon_h = min(max_icon_height, item->icon_h); SET_ICON_OURS(item, True); SET_PIXMAP_OURS(item, True); free(path); return; }
int SetRootWindow(char *tline) { Pixmap shapeMask = None, temp_pix = None, alpha = None; int w, h; int depth; int nalloc_pixels = 0; Pixel *alloc_pixels = NULL; char *file_path; FvwmPictureAttributes fpa; if (use_our_color_limit) { PictureColorLimitOption colorLimitop = {-1, -1, -1, -1, -1}; colorLimitop.color_limit = opt_color_limit; PictureInitCMapRoot( dpy, !NoColorLimit, &colorLimitop, True, True); } else { /* this use the default visual (not the fvwm one) as * getenv("FVWM_VISUALID") is NULL in any case. But this use * the same color limit than fvwm. * This is "broken" when fvwm use depth <= 8 and a private * color map (i.e., fvwm is started with the -visual{ID} * option), because when fvwm use a private color map the * default color limit is 244. There is no way to know here if * getenv("FVWM_VISUALID") !=NULL. * So, in this unfortunate case the user should use the * --color-limit option */ PictureInitCMap(dpy); } flib_init_graphics(dpy); /* try built-in image path first, but not before pwd */ PictureSetImagePath(".:+"); file_path = PictureFindImageFile(tline, NULL, R_OK); if (file_path == NULL) { file_path = tline; } fpa.mask = FPAM_NO_ALLOC_PIXELS | FPAM_NO_ALPHA; if (Pdepth <= 8 && !NoDither) { fpa.mask |= FPAM_DITHER; } else if (Pdepth <= 16 && Dither) { fpa.mask |= FPAM_DITHER; } if (NoColorLimit) { fpa.mask |= FPAM_NO_COLOR_LIMIT; } if (!PImageLoadPixmapFromFile( dpy, root, file_path, &temp_pix, &shapeMask, &alpha, &w, &h, &depth, &nalloc_pixels, &alloc_pixels, 0, fpa)) { fprintf( stderr, "[fvwm-root] failed to load image file '%s'\n", tline); return -1; } if (depth == Pdepth) { rootImage = temp_pix; } else { XGCValues gcv; GC gc; gcv.background= WhitePixel(dpy, screen); gcv.foreground= BlackPixel(dpy, screen); gc = fvwmlib_XCreateGC( dpy, root, GCForeground | GCBackground, &gcv); rootImage = XCreatePixmap(dpy, root, w, h, Pdepth); XCopyPlane(dpy, temp_pix, rootImage, gc, 0, 0, w, h, 0, 0, 1); XFreePixmap(dpy, temp_pix); XFreeGC(dpy, gc); } XSetWindowBackgroundPixmap(dpy, root, rootImage); save_colors = 1; XClearWindow(dpy, root); return 0; }
static signed int expand_vars_extended( char *var_name, char *output, cond_rc_t *cond_rc, const exec_context_t *exc) { char *rest; char dummy[64] = "\0"; char *target = (output) ? output : dummy; int cs = -1; int n; int i; int l; int x; int y; Pixel pixel = 0; int val = -12345678; const char *string = NULL; char *allocated_string = NULL; char *quoted_string = NULL; Bool should_quote = False; Bool is_numeric = False; Bool is_target = False; Bool is_x; Window context_w = Scr.Root; FvwmWindow *fw = exc->w.fw; signed int len = -1; /* allow partial matches for *.cs, gt, ... etc. variables */ switch ((i = GetTokenIndex(var_name, partial_function_vars, -1, &rest))) { case VAR_FG_CS: case VAR_BG_CS: case VAR_HILIGHT_CS: case VAR_SHADOW_CS: case VAR_FGSH_CS: if (!isdigit(*rest) || (*rest == '0' && *(rest + 1) != 0)) { /* not a non-negative integer without leading zeros */ return -1; } if (sscanf(rest, "%d%n", &cs, &n) < 1) { return -1; } if (*(rest + n) != 0) { /* trailing characters */ return -1; } if (cs < 0) { return -1; } alloc_colorset(cs); switch (i) { case VAR_FG_CS: pixel = Colorset[cs].fg; break; case VAR_BG_CS: pixel = Colorset[cs].bg; break; case VAR_HILIGHT_CS: pixel = Colorset[cs].hilite; break; case VAR_SHADOW_CS: pixel = Colorset[cs].shadow; break; case VAR_FGSH_CS: pixel = Colorset[cs].fgsh; break; } is_target = True; len = pixel_to_color_string(dpy, Pcmap, pixel, target, False); goto GOT_STRING; case VAR_GT_: if (rest == NULL) { return -1; } string = _(rest); goto GOT_STRING; case VAR_INFOSTORE_: if (rest == NULL) return -1; if ((string = get_metainfo_value(rest)) == NULL) return -1; goto GOT_STRING; case VAR_DESK_NAME: if (sscanf(rest, "%d%n", &cs, &n) < 1) { return -1; } if (*(rest + n) != 0) { /* trailing characters */ return -1; } string = GetDesktopName(cs); if (string == NULL) { const char *ddn = _("Desk"); allocated_string = (char *)safemalloc(19 + strlen(ddn)); sprintf(allocated_string, "%s %i", ddn, cs); string = allocated_string; } goto GOT_STRING; default: break; } /* only exact matches for all other variables */ switch ((i = GetTokenIndex(var_name, function_vars, 0, &rest))) { case VAR_DESK_N: is_numeric = True; val = Scr.CurrentDesk; break; case VAR_DESK_WIDTH: is_numeric = True; val = Scr.VxMax + Scr.MyDisplayWidth; break; case VAR_DESK_HEIGHT: is_numeric = True; val = Scr.VyMax + Scr.MyDisplayHeight; break; case VAR_DESK_PAGESX: is_numeric = True; val = (int)(Scr.VxMax / Scr.MyDisplayWidth) + 1; break; case VAR_DESK_PAGESY: is_numeric = True; val = (int)(Scr.VyMax / Scr.MyDisplayHeight) + 1; break; case VAR_VP_X: is_numeric = True; val = Scr.Vx; break; case VAR_VP_Y: is_numeric = True; val = Scr.Vy; break; case VAR_VP_WIDTH: is_numeric = True; val = Scr.MyDisplayWidth; break; case VAR_VP_HEIGHT: is_numeric = True; val = Scr.MyDisplayHeight; break; case VAR_WA_HEIGHT: is_numeric = True; val = Scr.Desktops->ewmh_working_area.height; break; case VAR_WA_WIDTH: is_numeric = True; val = Scr.Desktops->ewmh_working_area.width; break; case VAR_WA_X: is_numeric = True; val = Scr.Desktops->ewmh_working_area.x; break; case VAR_WA_Y: is_numeric = True; val = Scr.Desktops->ewmh_working_area.y; break; case VAR_DWA_HEIGHT: is_numeric = True; val = Scr.Desktops->ewmh_dyn_working_area.height; break; case VAR_DWA_WIDTH: is_numeric = True; val = Scr.Desktops->ewmh_dyn_working_area.width; break; case VAR_DWA_X: is_numeric = True; val = Scr.Desktops->ewmh_dyn_working_area.x; break; case VAR_DWA_Y: is_numeric = True; val = Scr.Desktops->ewmh_dyn_working_area.y; break; case VAR_PAGE_NX: is_numeric = True; val = (int)(Scr.Vx / Scr.MyDisplayWidth); break; case VAR_PAGE_NY: is_numeric = True; val = (int)(Scr.Vy / Scr.MyDisplayHeight); break; case VAR_W_ID: if (fw && !IS_EWMH_DESKTOP(FW_W(fw))) { is_target = True; sprintf(target, "0x%x", (int)FW_W(fw)); } break; case VAR_W_NAME: if (fw && !IS_EWMH_DESKTOP(FW_W(fw))) { string = fw->name.name; should_quote = True; } break; case VAR_W_ICONNAME: if (fw && !IS_EWMH_DESKTOP(FW_W(fw))) { string = fw->icon_name.name; should_quote = True; } break; case VAR_W_ICONFILE: case VAR_W_MINIICONFILE: if (fw && !IS_EWMH_DESKTOP(FW_W(fw))) { char *t; t = (i == VAR_W_ICONFILE) ? fw->icon_bitmap_file : fw->mini_pixmap_file; /* expand the path if possible */ allocated_string = PictureFindImageFile(t, NULL, R_OK); if (allocated_string == NULL) { string = t; } else if (USE_SVG && *allocated_string == ':' && (string = strchr(allocated_string + 1, ':'))) { string++; } else { string = allocated_string; } } break; case VAR_W_ICONFILE_SVGOPTS: case VAR_W_MINIICONFILE_SVGOPTS: if (fw && !IS_EWMH_DESKTOP(FW_W(fw))) { char *t; if (!USE_SVG) { return -1; } t = (i == VAR_W_ICONFILE_SVGOPTS) ? fw->icon_bitmap_file : fw->mini_pixmap_file; /* expand the path if possible */ allocated_string = PictureFindImageFile(t, NULL, R_OK); string = allocated_string; if (string && *string == ':' && (t = strchr(string + 1, ':'))) { *t = 0; } else { string = ""; } } break; case VAR_W_CLASS: if (fw && !IS_EWMH_DESKTOP(FW_W(fw))) { string = fw->class.res_class; should_quote = True; } break; case VAR_W_RESOURCE: if (fw && !IS_EWMH_DESKTOP(FW_W(fw))) { string = fw->class.res_name; should_quote = True; }