static void parse_simple_tint( colorset_t *cs, char *args, char **tint, int supplied_color, int *changed, int *percent, char *cmd) { char *rest; static char *name = "parse_colorset (tint)"; *changed = False; rest = get_simple_color(args, tint, cs, supplied_color, 0, NULL); if (!(cs->color_flags & supplied_color)) { /* restore to default */ *percent = 0; *changed = True; cs->color_flags &= ~(supplied_color); } else if (!GetIntegerArguments(rest, NULL, percent, 1)) { fvwm_msg(WARN, name, "%s must have two arguments a color and an integer", cmd); return; } *changed = True; if (*percent > 100) { *percent = 100; } else if (*percent < 0) { *percent = 0; } }
void CMD_EwmhBaseStruts(F_CMD_ARGS) { int val[4]; if (GetIntegerArguments(action, NULL, val, 4) != 4 || val[0] < 0 || val[1] < 0 || val[2] < 0 || val[3] < 0) { fvwm_msg(ERR,"CMD_EwmhBaseStruts", "EwmhBaseStruts needs four positive arguments"); return; } if (ewmhc.BaseStrut.left != val[0] || ewmhc.BaseStrut.right != val[1] || ewmhc.BaseStrut.top != val[2] || ewmhc.BaseStrut.bottom != val[3]) { ewmhc.BaseStrut.left = val[0]; ewmhc.BaseStrut.right = val[1]; ewmhc.BaseStrut.top = val[2]; ewmhc.BaseStrut.bottom = val[3]; ewmh_ComputeAndSetWorkArea(); ewmh_HandleDynamicWorkArea(); } }
/* Intended to be called by modules. Simply pass in the parameter from the * config string sent by fvwm. */ void FScreenConfigureModule(char *args) { int val[6]; int n; char *next; n = GetIntegerArguments(args, &next, val, 4); if (n != 4) { /* ignore broken line */ return; } FScreenSetPrimaryScreen(val[1]); if (val[3]) { /* SLS screen coordinates follow */ n = GetIntegerArguments(next, &next, val + 4, 1); if (n != 1) { /* ignore broken line */ return; } FScreenConfigureSLSScreens(val[4], next); } else { /* simple SLS line */ n = GetIntegerArguments(next, NULL, val + 4, 2); if (n != 2) { /* ignore broken line */ return; } FScreenConfigureSLSSize(val[4], val[5]); } FScreenSLSOnOff(val[2]); FScreenOnOff(val[0]); return; }
void CMD_Colorset(F_CMD_ARGS) { int n; char *token; if (GetIntegerArguments(action, &token, &n, 1) != 1) { return; } if (n < 0) { return; } if (token == NULL) { return; } parse_colorset(n, token); update_fvwm_colorset(n); return; }
void CMD_EwmhNumberOfDesktops(F_CMD_ARGS) { int val[2]; int num; num = GetIntegerArguments(action, NULL, val, 2); if ((num != 1 && num != 2) || val[0] < 1 || (num == 2 && val[1] < val[0] && val[1] != 0)) { fvwm_msg(ERR,"EwmhNumberOfDesktops", "Bad arguments to EwmhNumberOfDesktops"); return; } if (num == 2 && ewmhc.MaxDesktops != val[1]) { ewmhc.MaxDesktops = val[1]; num = 3; } else if (num == 1 && ewmhc.MaxDesktops != 0) { ewmhc.MaxDesktops = 0; num = 3; } if (ewmhc.NumberOfDesktops != val[0]) { ewmhc.NumberOfDesktops = val[0]; num = 3; } if (num == 3) { ewmhc.NeedsToCheckDesk = True; EWMH_SetNumberOfDesktops(); } }
/* translate a colorset spec into a colorset structure */ void parse_colorset(int n, char *line) { int i; int w; int h; int tmp; int percent; colorset_t *cs; char *optstring; char *args; char *option; char *tmp_str; char *fg = NULL; char *bg = NULL; char *hi = NULL; char *sh = NULL; char *fgsh = NULL; char *tint = NULL; char *fg_tint = NULL; char *bg_tint = NULL; char *icon_tint = NULL; Bool have_pixels_changed = False; Bool has_icon_pixels_changed = False; Bool has_fg_changed = False; Bool has_bg_changed = False; Bool has_sh_changed = False; Bool has_hi_changed = False; Bool has_fgsh_changed = False; Bool has_fg_alpha_changed = False; Bool has_tint_changed = False; Bool has_fg_tint_changed = False; Bool has_bg_tint_changed = False; Bool has_icon_tint_changed = False; Bool has_pixmap_changed = False; Bool has_shape_changed = False; Bool has_image_alpha_changed = False; Bool pixmap_is_a_bitmap = False; Bool do_reload_pixmap = False; Bool is_server_grabbed = False; XColor color; XGCValues xgcv; static char *name = "parse_colorset"; Window win = Scr.NoFocusWin; static GC gc = None; /* initialize statics */ if (gc == None) { gc = fvwmlib_XCreateGC(dpy, win, 0, &xgcv); } /* make sure it exists and has sensible contents */ alloc_colorset(n); cs = &Colorset[n]; /*** Parse the options ***/ while (line && *line) { /* Read next option specification delimited by a comma or \0. */ line = GetQuotedString( line, &optstring, ",", NULL, NULL, NULL); if (!optstring) break; args = GetNextToken(optstring, &option); if (!option) { free(optstring); break; } switch((i = GetTokenIndex(option, csetopts, 0, NULL))) { case 0: /* Foreground */ case 1: /* Fore */ case 2: /* fg */ get_simple_color( args, &fg, cs, FG_SUPPLIED, FG_CONTRAST, "contrast"); has_fg_changed = True; break; case 3: /* Background */ case 4: /* Back */ case 5: /* bg */ get_simple_color( args, &bg, cs, BG_SUPPLIED, BG_AVERAGE, "average"); has_bg_changed = True; break; case 6: /* Hilight */ case 7: /* Hilite */ case 8: /* hi */ get_simple_color(args, &hi, cs, HI_SUPPLIED, 0, NULL); has_hi_changed = True; break; case 9: /* Shadow */ case 10: /* Shade */ case 11: /* sh */ get_simple_color(args, &sh, cs, SH_SUPPLIED, 0, NULL); has_sh_changed = True; break; case 12: /* fgsh */ get_simple_color( args, &fgsh, cs, FGSH_SUPPLIED, 0,NULL); has_fgsh_changed = True; break; case 13: /* fg_alpha */ case 14: /* fgAlpha */ if (GetIntegerArguments(args, NULL, &tmp, 1)) { if (tmp > 100) tmp = 100; else if (tmp < 0) tmp = 0; } else { tmp = 100; } if (tmp != cs->fg_alpha_percent) { cs->fg_alpha_percent = tmp; has_fg_alpha_changed = True; } break; case 15: /* TiledPixmap */ case 16: /* Pixmap */ case 17: /* AspectPixmap */ has_pixmap_changed = True; free_colorset_background(cs, True); tmp_str = PeekToken(args, &args); if (tmp_str) { CopyString(&cs->pixmap_args, tmp_str); do_reload_pixmap = True; cs->gradient_type = 0; /* set the flags */ if (csetopts[i][0] == 'T') { cs->pixmap_type = PIXMAP_TILED; } else if (csetopts[i][0] == 'A') { cs->pixmap_type = PIXMAP_STRETCH_ASPECT; } else { cs->pixmap_type = PIXMAP_STRETCH; } } /* the pixmap is build later */ break; case 18: /* Shape */ case 19: /* TiledShape */ case 20: /* AspectShape */ parse_shape(win, cs, i, args, &has_shape_changed); break; case 21: /* Plain */ has_pixmap_changed = True; free_colorset_background(cs, True); break; case 22: /* NoShape */ has_shape_changed = True; if (cs->shape_mask) { add_to_junk(cs->shape_mask); cs->shape_mask = None; } break; case 23: /* Transparent */ /* This is only allowable when the root depth == fvwm * visual depth otherwise bad match errors happen, * it may be even more restrictive but my tests (on * exceed 6.2) show that only == depth is necessary */ if (Pdepth != DefaultDepth(dpy, (DefaultScreen(dpy)))) { fvwm_msg( ERR, name, "can't do Transparent " "when root_depth!=fvwm_depth"); break; } has_pixmap_changed = True; free_colorset_background(cs, True); cs->pixmap = ParentRelative; cs->pixmap_type = PIXMAP_STRETCH; break; case 24: /* RootTransparent */ if (Pdepth != DefaultDepth(dpy, (DefaultScreen(dpy)))) { fvwm_msg( ERR, name, "can't do RootTransparent " "when root_depth!=fvwm_depth"); break; } free_colorset_background(cs, True); has_pixmap_changed = True; cs->pixmap_type = PIXMAP_ROOT_PIXMAP_PURE; do_reload_pixmap = True; tmp_str = PeekToken(args, &args); if (StrEquals(tmp_str, "buffer")) { cs->allows_buffered_transparency = True; } else { cs->allows_buffered_transparency = False; } cs->is_maybe_root_transparent = True; break; case 25: /* Tint */ case 26: /* PixmapTint */ case 27: /* ImageTint */ case 28: /* TintMask */ parse_simple_tint( cs, args, &tint, TINT_SUPPLIED, &has_tint_changed, &percent, "tint"); if (has_tint_changed) { cs->tint_percent = percent; } break; case 29: /* NoTint */ has_tint_changed = True; cs->tint_percent = 0; cs->color_flags &= ~TINT_SUPPLIED; break; case 30: /* fgTint */ parse_simple_tint( cs, args, &fg_tint, FG_TINT_SUPPLIED, &has_fg_tint_changed, &percent, "fgTint"); if (has_fg_tint_changed) { cs->fg_tint_percent = percent; } break; case 31: /* bgTint */ parse_simple_tint( cs, args, &bg_tint, BG_TINT_SUPPLIED, &has_bg_tint_changed, &percent, "bgTint"); if (has_bg_tint_changed) { cs->bg_tint_percent = percent; } break; case 32: /* dither */ if (cs->pixmap_args || cs->gradient_args) { has_pixmap_changed = True; do_reload_pixmap = True; } cs->dither = True; break; case 33: /* nodither */ if (cs->pixmap_args || cs->gradient_args) { has_pixmap_changed = True; do_reload_pixmap = True; } cs->dither = False; break; case 34: /* Alpha */ case 35: /* PixmapAlpha */ case 36: /* ImageAlpha */ if (GetIntegerArguments(args, NULL, &tmp, 1)) { if (tmp > 100) tmp = 100; else if (tmp < 0) tmp = 0; } else { tmp = 100; } if (tmp != cs->image_alpha_percent) { has_image_alpha_changed = True; cs->image_alpha_percent = tmp; } break; /* dither icon is not dynamic (yet) maybe a bad opt: default * to False ? */ case 37: /* ditherIcon */ cs->do_dither_icon = True; break; case 38: /* DoNotDitherIcon */ cs->do_dither_icon = False; break; case 39: /* IconTint */ parse_simple_tint( cs, args, &icon_tint, ICON_TINT_SUPPLIED, &has_icon_tint_changed, &percent, "IconTint"); if (has_icon_tint_changed) { cs->icon_tint_percent = percent; has_icon_pixels_changed = True; } break; case 40: /* NoIconTint */ has_icon_tint_changed = True; if (cs->icon_tint_percent != 0) { has_icon_pixels_changed = True; } cs->icon_tint_percent = 0; break; case 41: /* IconAlpha */ if (GetIntegerArguments(args, NULL, &tmp, 1)) { if (tmp > 100) tmp = 100; else if (tmp < 0) tmp = 0; } else { tmp = 100; } if (tmp != cs->icon_alpha_percent) { has_icon_pixels_changed = True; cs->icon_alpha_percent = tmp; } break; default: /* test for ?Gradient */ if (option[0] && StrEquals(&option[1], "Gradient")) { cs->gradient_type = toupper(option[0]); if (!IsGradientTypeSupported(cs->gradient_type)) break; has_pixmap_changed = True; free_colorset_background(cs, True); CopyString(&cs->gradient_args, args); do_reload_pixmap = True; if (cs->gradient_type == V_GRADIENT) { cs->pixmap_type = PIXMAP_STRETCH_Y; } else if (cs->gradient_type == H_GRADIENT) cs->pixmap_type = PIXMAP_STRETCH_X; else cs->pixmap_type = PIXMAP_STRETCH; } else { fvwm_msg( WARN, name, "bad colorset pixmap " "specifier %s %s", option, line); } break; } /* switch */ if (option) { free(option); option = NULL; } free(optstring); optstring = NULL; } /* while (line && *line) */ /* * ---------- change the "pixmap" tint colour ---------- */ if (has_tint_changed) { /* user specified colour */ if (tint != NULL) { Pixel old_tint = cs->tint; PictureFreeColors(dpy, Pcmap, &cs->tint, 1, 0, True); cs->tint = GetColor(tint); if (old_tint != cs->tint) { have_pixels_changed = True; } } else if (tint == NULL) { /* default */ Pixel old_tint = cs->tint; PictureFreeColors(dpy, Pcmap, &cs->tint, 1, 0, True); cs->tint = GetColor(black); if (old_tint != cs->tint) { have_pixels_changed = True; } } } /* * reload the gradient if the tint or the alpha have changed. * Do this too if we need to recompute the bg average and the * gradient is tinted (perforemence issue). */ if ((has_tint_changed || has_image_alpha_changed || (has_bg_changed && (cs->color_flags & BG_AVERAGE) && cs->tint_percent > 0)) && cs->gradient_args) { do_reload_pixmap = True; } /* * reset the pixmap if the tint or the alpha has changed */ if (!do_reload_pixmap && (has_tint_changed || has_image_alpha_changed || (has_bg_changed && cs->alpha_pixmap != None))) { if (cs->pixmap_type == PIXMAP_ROOT_PIXMAP_PURE || cs->pixmap_type == PIXMAP_ROOT_PIXMAP_TRAN) { do_reload_pixmap = True; } else if (cs->picture != NULL && cs->pixmap) { XSetClipMask(dpy, gc, cs->picture->mask); reset_cs_pixmap(cs, gc); XSetClipMask(dpy, gc, None); has_pixmap_changed = True; } } /* * (re)build the pixmap or the gradient */ if (do_reload_pixmap) { free_colorset_background(cs, False); has_pixmap_changed = True; if (cs->pixmap_type == PIXMAP_ROOT_PIXMAP_PURE || cs->pixmap_type == PIXMAP_ROOT_PIXMAP_TRAN) { cs->pixmap_type = 0; if (root_pic.pixmap) { cs->pixmap = root_pic.pixmap; cs->width = root_pic.width; cs->height = root_pic.height; cs->pixmap_type = PIXMAP_ROOT_PIXMAP_PURE; #if 0 fprintf(stderr,"Cset %i LoadRoot 0x%lx\n", n, cs->pixmap); #endif } } else if (cs->pixmap_args) { parse_pixmap(win, gc, cs, &pixmap_is_a_bitmap); } else if (cs->gradient_args) { cs->pixmap = CreateGradientPixmapFromString( dpy, win, gc, cs->gradient_type, cs->gradient_args, &w, &h, &cs->pixels, &cs->nalloc_pixels, cs->dither); cs->width = w; cs->height = h; } has_pixmap_changed = True; } if (cs->picture != NULL && cs->picture->depth != Pdepth) { pixmap_is_a_bitmap = True; } /* * ---------- change the background colour ---------- */ if (has_bg_changed || (has_pixmap_changed && (cs->color_flags & BG_AVERAGE) && cs->pixmap != None && cs->pixmap != ParentRelative && !pixmap_is_a_bitmap)) { Bool do_set_default_background = False; Pixmap average_pix = None; if (cs->color_flags & BG_AVERAGE) { if (cs->picture != NULL && cs->picture->picture != None) { average_pix = cs->picture->picture; } else if (cs->pixmap != ParentRelative) { average_pix = cs->pixmap; } if (average_pix == root_pic.pixmap) { int w; int h; XID dummy; MyXGrabServer(dpy); is_server_grabbed = True; if (!XGetGeometry( dpy, average_pix, &dummy, (int *)&dummy, (int *)&dummy, (unsigned int *)&w, (unsigned int *)&h, (unsigned int *)&dummy, (unsigned int *)&dummy)) { average_pix = None; } else { if (w != cs->width || h != cs->height) { average_pix = None; } } if (average_pix == None) { MyXUngrabServer(dpy); is_server_grabbed = False; } } } /* note: no average for bitmap */ if ((cs->color_flags & BG_AVERAGE) && average_pix) { /* calculate average background color */ XColor *colors; XImage *image; XImage *mask_image = None; unsigned int i, j, k = 0; unsigned long red = 0, blue = 0, green = 0; unsigned long tred, tblue, tgreen; double dred = 0.0, dblue = 0.0, dgreen = 0.0; has_bg_changed = True; /* create an array to store all the pixmap colors in */ /* Note: this may allocate a lot of memory: * cs->width * cs->height * 12 and then the rest of the * procedure can take a lot of times */ colors = (XColor *)safemalloc( cs->width * cs->height * sizeof(XColor)); /* get the pixmap and mask into an image */ image = XGetImage( dpy, average_pix, 0, 0, cs->width, cs->height, AllPlanes, ZPixmap); if (cs->mask != None) { mask_image = XGetImage( dpy, cs->mask, 0, 0, cs->width, cs->height, AllPlanes, ZPixmap); } if (is_server_grabbed == True) { MyXUngrabServer(dpy); } if (image != None && mask_image != None) { /* only fetch the pixels that are not masked * out */ for (i = 0; i < cs->width; i++) { for (j = 0; j < cs->height; j++) { if ( cs->mask == None || XGetPixel( mask_image, i, j) == 0) { colors[k++].pixel = XGetPixel( image, i, j); } } } } if (image != None) { XDestroyImage(image); } if (mask_image != None) { XDestroyImage(mask_image); } if (k == 0) { do_set_default_background = True; } else { /* look them all up, XQueryColors() can't * handle more than 256 */ for (i = 0; i < k; i += 256) { XQueryColors( dpy, Pcmap, &colors[i], min(k - i, 256)); } /* calculate average, add overflows in a double * .red is short, red is long */ for (i = 0; i < k; i++) { tred = red; red += colors[i].red; if (red < tred) { dred += (double)tred; red = colors[i].red; } tgreen = green; green += colors[i].green; if (green < tgreen) { dgreen += (double)tgreen; green = colors[i].green; } tblue = blue; blue += colors[i].blue; if (blue < tblue) { dblue += (double)tblue; blue = colors[i].blue; } } dred += red; dgreen += green; dblue += blue; /* get it */ color.red = dred / k; color.green = dgreen / k; color.blue = dblue / k; { Pixel old_bg = cs->bg; PictureFreeColors( dpy, Pcmap, &cs->bg, 1, 0, True); PictureAllocColor( dpy, Pcmap, &color, True); cs->bg = color.pixel; if (old_bg != cs->bg) { have_pixels_changed = True; } } } free(colors); } /* average */ else if ((cs->color_flags & BG_SUPPLIED) && bg != NULL) { /* user specified colour */ Pixel old_bg = cs->bg; PictureFreeColors(dpy, Pcmap, &cs->bg, 1, 0, True); cs->bg = GetColor(bg); if (old_bg != cs->bg) { have_pixels_changed = True; } } /* user specified */ else if (bg == NULL && has_bg_changed) { /* default */ do_set_default_background = True; } /* default */ if (do_set_default_background) { Pixel old_bg = cs->bg; PictureFreeColors(dpy, Pcmap, &cs->bg, 1, 0, True); cs->bg = GetColor(white); if (old_bg != cs->bg) { have_pixels_changed = True; } has_bg_changed = True; } if (has_bg_changed) { /* save the bg color for tinting */ cs->bg_saved = cs->bg; } } /* has_bg_changed */ /* * ---------- setup the bg tint colour ---------- */ if (has_bg_tint_changed && cs->bg_tint_percent > 0 && bg_tint != NULL) { PictureFreeColors(dpy, Pcmap, &cs->bg_tint, 1, 0, True); cs->bg_tint = GetColor(bg_tint); } /* * ---------- tint the bg colour ---------- */ if (has_bg_tint_changed || (has_bg_changed && cs->bg_tint_percent > 0)) { if (cs->bg_tint_percent == 0) { Pixel old_bg = cs->bg; PictureFreeColors(dpy, Pcmap, &cs->bg, 1, 0, True); cs->bg = cs->bg_saved; if (old_bg != cs->bg) { have_pixels_changed = True; has_bg_changed = True; } } else { Pixel old_bg = cs->bg; PictureFreeColors(dpy, Pcmap, &cs->bg, 1, 0, True); cs->bg = GetTintedPixel( cs->bg_saved, cs->bg_tint, cs->bg_tint_percent); if (old_bg != cs->bg) { have_pixels_changed = True; has_bg_changed = True; } } } /* * ---------- setup the fg tint colour ---------- */ if (has_fg_tint_changed && cs->fg_tint_percent > 0 && fg_tint != NULL) { PictureFreeColors(dpy, Pcmap, &cs->fg_tint, 1, 0, True); cs->fg_tint = GetColor(fg_tint); } /* * ---------- change the foreground colour ---------- */ if (has_fg_changed || (has_bg_changed && (cs->color_flags & FG_CONTRAST))) { if (cs->color_flags & FG_CONTRAST) { Pixel old_fg = cs->fg; /* calculate contrasting foreground color */ color.pixel = cs->bg; XQueryColor(dpy, Pcmap, &color); color.red = (color.red > 32767) ? 0 : 65535; color.green = (color.green > 32767) ? 0 : 65535; color.blue = (color.blue > 32767) ? 0 : 65535; PictureFreeColors(dpy, Pcmap, &cs->fg, 1, 0, True); PictureAllocColor(dpy, Pcmap, &color, True); cs->fg = color.pixel; if (old_fg != cs->fg) { have_pixels_changed = True; has_fg_changed = 1; } } /* contrast */ else if ((cs->color_flags & FG_SUPPLIED) && fg != NULL) { /* user specified colour */ Pixel old_fg = cs->fg; PictureFreeColors(dpy, Pcmap, &cs->fg, 1, 0, True); cs->fg = GetColor(fg); if (old_fg != cs->fg) { have_pixels_changed = True; has_fg_changed = 1; } } /* user specified */ else if (fg == NULL) { /* default */ Pixel old_fg = cs->fg; PictureFreeColors(dpy, Pcmap, &cs->fg, 1, 0, True); cs->fg = GetColor(black); if (old_fg != cs->fg) { have_pixels_changed = True; has_fg_changed = 1; } } /* save the fg color for tinting */ cs->fg_saved = cs->fg; } /* has_fg_changed */ /* * ---------- tint the foreground colour ---------- */ if (has_fg_tint_changed || (has_fg_changed && cs->fg_tint_percent > 0)) { if (cs->fg_tint_percent == 0) { Pixel old_fg = cs->fg; PictureFreeColors(dpy, Pcmap, &cs->fg, 1, 0, True); cs->fg = cs->fg_saved; if (old_fg != cs->fg) { have_pixels_changed = True; has_fg_changed = 1; } } else { Pixel old_fg = cs->fg; PictureFreeColors(dpy, Pcmap, &cs->fg, 1, 0, True); cs->fg = GetTintedPixel( cs->fg_saved, cs->fg_tint, cs->fg_tint_percent); if (old_fg != cs->fg) { have_pixels_changed = True; has_fg_changed = 1; } } } /* * ---------- change the hilight colour ---------- */ if (has_hi_changed || (has_bg_changed && !(cs->color_flags & HI_SUPPLIED))) { has_hi_changed = 1; if ((cs->color_flags & HI_SUPPLIED) && hi != NULL) { /* user specified colour */ Pixel old_hilite = cs->hilite; PictureFreeColors(dpy, Pcmap, &cs->hilite, 1, 0, True); cs->hilite = GetColor(hi); if (old_hilite != cs->hilite) { have_pixels_changed = True; } } /* user specified */ else if (hi == NULL) { Pixel old_hilite = cs->hilite; PictureFreeColors(dpy, Pcmap, &cs->hilite, 1, 0, True); cs->hilite = GetHilite(cs->bg); if (old_hilite != cs->hilite) { have_pixels_changed = True; } } } /* has_hi_changed */ /* * ---------- change the shadow colour ---------- */ if (has_sh_changed || (has_bg_changed && !(cs->color_flags & SH_SUPPLIED))) { has_sh_changed = 1; if ((cs->color_flags & SH_SUPPLIED) && sh != NULL) { /* user specified colour */ Pixel old_shadow = cs->shadow; PictureFreeColors(dpy, Pcmap, &cs->shadow, 1, 0, True); cs->shadow = GetColor(sh); if (old_shadow != cs->shadow) { have_pixels_changed = True; } } /* user specified */ else if (sh == NULL) { Pixel old_shadow = cs->shadow; PictureFreeColors(dpy, Pcmap, &cs->shadow, 1, 0, True); cs->shadow = GetShadow(cs->bg); if (old_shadow != cs->shadow) { have_pixels_changed = True; } } } /* has_sh_changed */ /* * ---------- change the shadow foreground colour ---------- */ if (has_fgsh_changed || ((has_fg_changed || has_bg_changed) && !(cs->color_flags & FGSH_SUPPLIED))) { has_fgsh_changed = 1; if ((cs->color_flags & FGSH_SUPPLIED) && fgsh != NULL) { /* user specified colour */ Pixel old_fgsh = cs->fgsh; PictureFreeColors(dpy, Pcmap, &cs->fgsh, 1, 0, True); cs->fgsh = GetColor(fgsh); if (old_fgsh != cs->fgsh) { have_pixels_changed = True; } } /* user specified */ else if (fgsh == NULL) { Pixel old_fgsh = cs->fgsh; PictureFreeColors(dpy, Pcmap, &cs->fgsh, 1, 0, True); cs->fgsh = GetForeShadow(cs->fg, cs->bg); if (old_fgsh != cs->fgsh) { have_pixels_changed = True; } } } /* has_fgsh_changed */ /* * ------- the pixmap is a bitmap: create here cs->pixmap ------- */ if (cs->picture != None && pixmap_is_a_bitmap && (has_pixmap_changed || has_bg_changed)) { cs->pixmap = XCreatePixmap( dpy, win, cs->width, cs->height, Pdepth); XSetBackground(dpy, gc, cs->bg); XSetForeground(dpy, gc, cs->fg); reset_cs_pixmap(cs, gc); } /* * ------- change the masked out parts of the background pixmap ------- */ if (cs->pixmap != None && cs->pixmap != ParentRelative && (!CSETS_IS_TRANSPARENT_ROOT(cs)|| cs->allows_buffered_transparency) && (cs->mask != None || cs->alpha_pixmap != None || cs->image_alpha_percent < 100 || cs->tint_percent > 0) && (has_pixmap_changed || has_bg_changed || has_image_alpha_changed || has_tint_changed)) { /* Now that we know the background colour we can update the * pixmap background. */ FvwmRenderAttributes fra; Pixmap temp, mask, alpha; memset(&fra, 0, sizeof(fra)); temp = XCreatePixmap(dpy, win, cs->width, cs->height, Pdepth); if (cs->picture != NULL) { mask = cs->picture->mask; alpha = cs->picture->alpha; } else { mask = None; alpha = None; } XSetForeground(dpy, gc, cs->bg); XFillRectangle( dpy, temp, gc, 0, 0, cs->width, cs->height); fra.mask = FRAM_HAVE_ADDED_ALPHA | FRAM_HAVE_TINT; fra.added_alpha_percent = cs->image_alpha_percent; fra.tint = cs->tint; fra.tint_percent = cs->tint_percent; PGraphicsRenderPixmaps( dpy, win, cs->pixmap, mask, alpha, Pdepth, &fra, temp, gc, Scr.MonoGC, Scr.AlphaGC, 0, 0, cs->width, cs->height, 0, 0, cs->width, cs->height, False); if (cs->pixmap != root_pic.pixmap) { add_to_junk(cs->pixmap); } cs->pixmap = temp; has_pixmap_changed = True; if (CSETS_IS_TRANSPARENT_ROOT(cs)) { cs->pixmap_type = PIXMAP_ROOT_PIXMAP_TRAN; } } /* has_pixmap_changed */ /* * ---------- change the icon tint colour ---------- */ if (has_icon_tint_changed) { /* user specified colour */ if (icon_tint != NULL) { Pixel old_tint = cs->icon_tint; PictureFreeColors( dpy, Pcmap, &cs->icon_tint, 1, 0, True); cs->icon_tint = GetColor(icon_tint); if (old_tint != cs->icon_tint) { has_icon_pixels_changed = True; } } else { /* default */ Pixel old_tint = cs->icon_tint; PictureFreeColors( dpy, Pcmap, &cs->icon_tint, 1, 0, True); cs->icon_tint = GetColor(black); if (old_tint != cs->icon_tint) { has_icon_pixels_changed = True; } } } /* * ---------- send new colorset to fvwm and clean up ---------- */ /* make sure the server has this to avoid races */ XSync(dpy, False); /* inform modules of the change */ if (have_pixels_changed || has_pixmap_changed || has_shape_changed || has_fg_alpha_changed || has_icon_pixels_changed) { BroadcastColorset(n); } if (fg) { free(fg); } if (bg) { free(bg); } if (hi) { free(hi); } if (sh) { free(sh); } if (fgsh) { free(fgsh); } if (tint) { free(tint); } if (fg_tint) { free(fg_tint); } if (bg_tint) { free(bg_tint); } if (icon_tint) { free(icon_tint); } return; }
/***************************************************************************** * * This routine is responsible for reading and parsing the config file * ****************************************************************************/ void ParseOptions(void) { char *tline= NULL; int desk; int dx = 3; int dy = 3; Scr.FvwmRoot = NULL; Scr.Hilite = NULL; Scr.VScale = 32; Scr.MyDisplayWidth = DisplayWidth(dpy, Scr.screen); Scr.MyDisplayHeight = DisplayHeight(dpy, Scr.screen); InitGetConfigLine(fd,CatString3("*",MyName,0)); for (GetConfigLine(fd,&tline); tline != NULL; GetConfigLine(fd,&tline)) { int g_x, g_y, flags; unsigned width,height; char *resource; char *resource_string; char *arg1; char *arg2; char *tline2; char *token; char *next; Bool MoveThresholdSetForModule = False; resource_string = arg1 = arg2 = NULL; token = PeekToken(tline, &next); if (StrEquals(token, "Colorset")) { LoadColorset(next); continue; } else if (StrEquals(token, XINERAMA_CONFIG_STRING)) { FScreenConfigureModule(next); } else if (StrEquals(token, "DesktopSize")) { token = PeekToken(next, &next); if (token) { sscanf(token, "%d", &dx); token = PeekToken(next, &next); if (token) sscanf(token, "%d", &dy); } continue; } else if (StrEquals(token, "ImagePath")) { if (ImagePath != NULL) { free(ImagePath); ImagePath = NULL; } GetNextToken(next, &ImagePath); #ifdef DEBUG fprintf(stderr, "[ParseOptions]: ImagePath = %s\n", ImagePath); #endif continue; } else if (StrEquals(token, "MoveThreshold")) { if (!MoveThresholdSetForModule) { int val; if (GetIntegerArguments(next, NULL, &val, 1) > 0) { if (val >= 0) MoveThreshold = val; else MoveThreshold = DEFAULT_PAGER_MOVE_THRESHOLD; } } continue; } tline2 = GetModuleResource(tline, &resource, MyName); if (!resource) continue; tline2 = GetNextToken(tline2, &arg1); if (!arg1) { arg1 = (char *)safemalloc(1); arg1[0] = 0; } tline2 = GetNextToken(tline2, &arg2); if (!arg2) { arg2 = (char *)safemalloc(1); arg2[0] = 0; } if(StrEquals(resource,"Colorset")) { ParseColorset(arg1, arg2, &(((DeskInfo *)(NULL))->colorset), &(((PagerStringList *)(NULL))->colorset), &globalcolorset); } else if(StrEquals(resource,"BalloonColorset")) { ParseColorset(arg1, arg2, &(((DeskInfo *)(NULL))->ballooncolorset), &(((PagerStringList *)(NULL))->ballooncolorset), &globalballooncolorset); } else if(StrEquals(resource,"HilightColorset")) { ParseColorset(arg1, arg2, &(((DeskInfo *)(NULL))->highcolorset), &(((PagerStringList *)(NULL))->highcolorset), &globalhighcolorset); } else if (StrEquals(resource, "Geometry")) { window_w = 0; window_h = 0; window_x = 0; window_y = 0; xneg = 0; yneg = 0; usposition = 0; flags = FScreenParseGeometry(arg1,&g_x,&g_y,&width,&height); if (flags & WidthValue) { window_w = width; } if (flags & HeightValue) { window_h = height; } if (flags & XValue) { window_x = g_x; usposition = 1; if (flags & XNegative) { xneg = 1; } } if (flags & YValue) { window_y = g_y; usposition = 1; if (flags & YNegative) { yneg = 1; } } } else if (StrEquals(resource, "IconGeometry")) { icon_w = 0; icon_h = 0; icon_x = -10000; icon_y = -10000; icon_xneg = 0; icon_yneg = 0; flags = FScreenParseGeometry(arg1,&g_x,&g_y,&width,&height); if (flags & WidthValue) icon_w = width; if (flags & HeightValue) icon_h = height; if (flags & XValue) { icon_x = g_x; if (flags & XNegative) { icon_xneg = 1; } } if (flags & YValue) { icon_y = g_y; if (flags & YNegative) { icon_yneg = 1; } } } else if (StrEquals(resource, "Label")) { if (StrEquals(arg1, "*")) { desk = Scr.CurrentDesk; } else { desk = desk1; sscanf(arg1,"%d",&desk); } if (fAlwaysCurrentDesk) { PagerStringList *item; item = FindDeskStrings(desk); if (item->next != NULL) { /* replace label */ if (item->next->label != NULL) { free(item->next->label); item->next->label = NULL; } CopyString(&(item->next->label), arg2); } else { /* new Dcolor and desktop */ item = NewPagerStringItem(item, desk); CopyString(&(item->label), arg2); } if (desk == Scr.CurrentDesk) { free(Desks[0].label); CopyString(&Desks[0].label, arg2); } } else if((desk >= desk1)&&(desk <=desk2)) { free(Desks[desk - desk1].label); CopyString(&Desks[desk - desk1].label, arg2); } } else if (StrEquals(resource, "Font")) { if (font_string) free(font_string); if (next && next[0] == '\"') { int l; next++; CopyString(&font_string, next); l = strlen(font_string); if (l > 0 && font_string[l - 1] == '\"') { font_string[l - 1] = 0; } } else { CopyString(&font_string,next); } if(strncasecmp(font_string,"none",4) == 0) uselabel = 0; } else if (StrEquals(resource, "Fore")) { if(Pdepth > 1) { if (PagerFore) free(PagerFore); CopyString(&PagerFore,arg1); } } else if (StrEquals(resource, "Back")) { if(Pdepth > 1) { if (PagerBack) free(PagerBack); CopyString(&PagerBack,arg1); } } else if (StrEquals(resource, "DeskColor")) { if (StrEquals(arg1, "*")) { desk = Scr.CurrentDesk; } else { desk = desk1; sscanf(arg1,"%d",&desk); } if (fAlwaysCurrentDesk) { PagerStringList *item; item = FindDeskStrings(desk); if (item->next != NULL) { /* replace Dcolor */ if (item->next->Dcolor != NULL) { free(item->next->Dcolor); item->next->Dcolor = NULL; } CopyString(&(item->next->Dcolor), arg2); } else { /* new Dcolor and desktop */ item = NewPagerStringItem(item, desk); CopyString(&(item->Dcolor), arg2); } if (desk == Scr.CurrentDesk) { free(Desks[0].Dcolor); CopyString(&Desks[0].Dcolor, arg2); } } else if((desk >= desk1)&&(desk <=desk2)) { free(Desks[desk - desk1].Dcolor); CopyString(&Desks[desk - desk1].Dcolor, arg2); } } else if (StrEquals(resource, "DeskPixmap")) { if (StrEquals(arg1, "*")) { desk = Scr.CurrentDesk; } else { desk = desk1; sscanf(arg1,"%d",&desk); } if (fAlwaysCurrentDesk) { PagerStringList *item; item = FindDeskStrings(desk); if (item->next != NULL) { if (item->next->bgPixmap != NULL) { DestroyPicture(dpy, item->next->bgPixmap); item->next->bgPixmap = NULL; } item->next->bgPixmap = CachePicture (dpy, Scr.Pager_w, ImagePath, arg2, 0); } else { /* new Dcolor and desktop */ item = NewPagerStringItem(item, desk); item->bgPixmap = CachePicture (dpy, Scr.Pager_w, ImagePath, arg2, 0); } if (desk == Scr.CurrentDesk) { if (Desks[0].bgPixmap != NULL) { DestroyPicture(dpy, Desks[0].bgPixmap); Desks[0].bgPixmap = NULL; } Desks[0].bgPixmap = CachePicture (dpy, Scr.Pager_w, ImagePath, arg2, 0); } } else if((desk >= desk1)&&(desk <=desk2)) { int dNr = desk - desk1; if (Desks[dNr].bgPixmap != NULL) { DestroyPicture(dpy, Desks[dNr].bgPixmap); Desks[dNr].bgPixmap = NULL; } Desks[dNr].bgPixmap = CachePicture (dpy, Scr.Pager_w, ImagePath, arg2, 0); } #ifdef DEBUG fprintf(stderr, "[ParseOptions]: Desk %d: bgPixmap = %s\n", desk, arg2); #endif } else if (StrEquals(resource, "Pixmap")) { if(Pdepth > 1) { if (PixmapBack) { DestroyPicture (dpy, PixmapBack); PixmapBack = NULL; } PixmapBack = CachePicture (dpy, Scr.Pager_w, ImagePath, arg1, 0); #ifdef DEBUG fprintf(stderr, "[ParseOptions]: Global: bgPixmap = %s\n", arg1); #endif } } else if (StrEquals(resource, "HilightPixmap")) { if(Pdepth > 1) { if (HilightPixmap) { DestroyPicture (dpy, HilightPixmap); HilightPixmap = NULL; } HilightPixmap = CachePicture (dpy, Scr.Pager_w, ImagePath, arg1, 0); #ifdef DEBUG fprintf(stderr, "[ParseOptions]: HilightPixmap = %s\n", arg1); #endif } } else if (StrEquals(resource, "DeskHilight")) { HilightDesks = 1; } else if (StrEquals(resource, "NoDeskHilight")) { HilightDesks = 0; } else if (StrEquals(resource, "Hilight")) { if(Pdepth > 1) { if (HilightC) free(HilightC); CopyString(&HilightC,arg1); } } else if (StrEquals(resource, "SmallFont")) { if (smallFont) free(smallFont); if (next && next[0] == '\"') { int l; next++; CopyString(&smallFont, next); l = strlen(smallFont); if (l > 0 && smallFont[l - 1] == '\"') { smallFont[l - 1] = 0; } } else { CopyString(&smallFont,next); } if (strncasecmp(smallFont,"none",4) == 0) { free(smallFont); smallFont = NULL; } } else if (StrEquals(resource, "MiniIcons")) { MiniIcons = 1; } else if (StrEquals(resource, "StartIconic")) { StartIconic = 1; } else if (StrEquals(resource, "NoStartIconic")) { StartIconic = 0; } else if (StrEquals(resource, "LabelsBelow")) { LabelsBelow = 1; } else if (StrEquals(resource, "LabelsAbove")) { LabelsBelow = 0; } else if (FHaveShapeExtension && StrEquals(resource, "ShapeLabels")) { ShapeLabels = 1; } else if (FHaveShapeExtension && StrEquals(resource, "NoShapeLabels")) { ShapeLabels = 0; } else if (StrEquals(resource, "Rows")) { sscanf(arg1,"%d",&Rows); } else if (StrEquals(resource, "Columns")) { sscanf(arg1,"%d",&Columns); } else if (StrEquals(resource, "DeskTopScale")) { sscanf(arg1,"%d",&Scr.VScale); } else if (StrEquals(resource, "WindowColors")) { if (Pdepth > 1) { if (WindowFore) free(WindowFore); if (WindowBack) free(WindowBack); if (WindowHiFore) free(WindowHiFore); if (WindowHiBack) free(WindowHiBack); CopyString(&WindowFore, arg1); CopyString(&WindowBack, arg2); tline2 = GetNextToken(tline2, &WindowHiFore); GetNextToken(tline2, &WindowHiBack); } } else if (StrEquals(resource, "WindowBorderWidth")) { sscanf(arg1, "%d", &WindowBorderWidth); MinSize = 2 * WindowBorderWidth + 1; } else if (StrEquals(resource, "Window3dBorders")) { WindowBorders3d = True; } else if (StrEquals(resource,"WindowColorsets")) { sscanf(arg1,"%d",&windowcolorset); AllocColorset(windowcolorset); sscanf(arg2,"%d",&activecolorset); AllocColorset(activecolorset); } else if (StrEquals(resource,"WindowLabelFormat")) { if (WindowLabelFormat) free(WindowLabelFormat); CopyString(&WindowLabelFormat,arg1); } else if (StrEquals(resource, "MoveThreshold")) { int val; if (GetIntegerArguments(next, NULL, &val, 1) > 0 && val >= 0) { MoveThreshold = val; MoveThresholdSetForModule = True; } } else if (StrEquals(resource, "SloppyFocus")) { do_focus_on_enter = True; } else if (StrEquals(resource, "SolidSeparators")) { use_dashed_separators = False; use_no_separators = False; } else if (StrEquals(resource, "NoSeparators")) { use_no_separators = True; } /* ... and get Balloon config options ... -- [email protected] */ else if (StrEquals(resource, "Balloons")) { if (BalloonTypeString) free(BalloonTypeString); CopyString(&BalloonTypeString, arg1); if ( strncasecmp(BalloonTypeString, "Pager", 5) == 0 ) { ShowPagerBalloons = 1; ShowIconBalloons = 0; } else if ( strncasecmp(BalloonTypeString, "Icon", 4) == 0 ) { ShowPagerBalloons = 0; ShowIconBalloons = 1; } else { ShowPagerBalloons = 1; ShowIconBalloons = 1; } /* turn this on initially so balloon window is created; later this variable is changed to match ShowPagerBalloons or ShowIconBalloons whenever we receive iconify or deiconify packets */ ShowBalloons = 1; } else if (StrEquals(resource, "BalloonBack")) { if (Pdepth > 1) { if (BalloonBack) free(BalloonBack); CopyString(&BalloonBack, arg1); } } else if (StrEquals(resource, "BalloonFore")) { if (Pdepth > 1) { if (BalloonFore) free(BalloonFore); CopyString(&BalloonFore, arg1); } } else if (StrEquals(resource, "BalloonFont")) { if (BalloonFont) free(BalloonFont); CopyStringWithQuotes(&BalloonFont, next); } else if (StrEquals(resource, "BalloonBorderColor")) { if (BalloonBorderColor) free(BalloonBorderColor); CopyString(&BalloonBorderColor, arg1); } else if (StrEquals(resource, "BalloonBorderWidth")) { sscanf(arg1, "%d", &BalloonBorderWidth); } else if (StrEquals(resource, "BalloonYOffset")) { sscanf(arg1, "%d", &BalloonYOffset); } else if (StrEquals(resource,"BalloonStringFormat")) { if (BalloonFormatString) free(BalloonFormatString); CopyString(&BalloonFormatString,arg1); } free(resource); free(arg1); free(arg2); } Scr.VxMax = dx * Scr.MyDisplayWidth - Scr.MyDisplayWidth; Scr.VyMax = dy * Scr.MyDisplayHeight - Scr.MyDisplayHeight; if(Scr.VxMax <0) Scr.VxMax = 0; if(Scr.VyMax <0) Scr.VyMax = 0; Scr.VxPages = Scr.VxMax / Scr.MyDisplayWidth; Scr.VyPages = Scr.VyMax / Scr.MyDisplayHeight; Scr.VWidth = Scr.VxMax + Scr.MyDisplayWidth; Scr.VHeight = Scr.VyMax + Scr.MyDisplayHeight; Scr.Vx = 0; Scr.Vy = 0; return; }
Bool FScreenConfigureSLSScreens(int nscreens, char *args) { int sn; char *next; if (nscreens == 0 || args == NULL) { return FScreenConfigureSLSSize(1, 1); } if (nscreens == 1 && screens_sls) { return False; } if (screens_sls) { free(screens_sls); screens_sls = NULL; } screens_sls = (XineramaScreenInfo *) safemalloc(sizeof(XineramaScreenInfo) * (nscreens + 1)); screens_sls[0] = screens_xi[0]; for (sn = 1; sn <= nscreens; sn++, args = next) { char *token; int val[4]; /* read next screen spec */ token = PeekToken(args, &next); if (!token) { break; } if (XParseGeometry(token, &val[0], &val[1], (unsigned int *)&val[2], (unsigned int *)&val[3]) == (XValue|YValue|WidthValue|HeightValue) || GetIntegerArguments(args, &next, val, 4) == 4) { if (val[0] < 0 || val[1] < 0 || val[2] < 1 || val[3] < 1) { /* illegal spec */ break; } screens_sls[sn].screen_number = sn - 1; screens_sls[sn].x_org = val[0]; screens_sls[sn].y_org = val[1]; screens_sls[sn].width = val[2]; screens_sls[sn].height = val[3]; } else { /* illegal spec */ break; } } total_screens_sls = sn - 1; have_sls_screen_list = True; FScreenSLSOnOff(is_sls_enabled); return True; }
/* groks a gradient string and creates arrays of colors and percentages * returns the number of colors asked for (No. allocated may be less due * to the ColorLimit command). A return of 0 indicates an error */ int ParseGradient( char *gradient, char **rest, char ***colors_return, int **perc_return, int *nsegs_return) { char *item; char *orig; int npixels; char **s_colors; int *perc; int nsegs, i, sum; Bool is_syntax_error = False; /* get the number of colors specified */ if (rest) { *rest = gradient; } orig = gradient; if (GetIntegerArguments(gradient, &gradient, (int *)&npixels, 1) != 1 || npixels < 2) { fprintf( stderr, "ParseGradient: illegal number of colors in" " gradient: '%s'\n", orig); return 0; } /* get the starting color or number of segments */ gradient = GetNextToken(gradient, &item); if (gradient) { gradient = SkipSpaces(gradient, NULL, 0); } if (!gradient || !*gradient || !item) { fprintf(stderr, "Incomplete gradient style: '%s'\n", orig); if (item) { free(item); } if (rest) { *rest = gradient; } return 0; } if (GetIntegerArguments(item, NULL, &nsegs, 1) != 1) { /* get the end color of a simple gradient */ s_colors = (char **)safemalloc(sizeof(char *) * 2); perc = (int *)safemalloc(sizeof(int)); nsegs = 1; s_colors[0] = item; gradient = GetNextToken(gradient, &item); s_colors[1] = item; perc[0] = 100; } else { free(item); /* get a list of colors and percentages */ if (nsegs < 1) nsegs = 1; if (nsegs > MAX_GRADIENT_SEGMENTS) nsegs = MAX_GRADIENT_SEGMENTS; s_colors = (char **)safemalloc(sizeof(char *) * (nsegs + 1)); perc = (int *)safemalloc(sizeof(int) * nsegs); for (i = 0; !is_syntax_error && i <= nsegs; i++) { s_colors[i] = 0; gradient = GetNextToken(gradient, &s_colors[i]); if (i < nsegs) { if (GetIntegerArguments( gradient, &gradient, &perc[i], 1) != 1 || perc[i] <= 0) { /* illegal size */ perc[i] = 0; } } } if (s_colors[nsegs] == NULL) { fprintf( stderr, "ParseGradient: too few gradient" " segments: '%s'\n", orig); is_syntax_error = True; } } /* sanity check */ for (i = 0, sum = 0; !is_syntax_error && i < nsegs; ++i) { int old_sum = sum; sum += perc[i]; if (sum < old_sum) { /* integer overflow */ fprintf( stderr, "ParseGradient: multi gradient" " overflow: '%s'", orig); is_syntax_error = 1; break; } } if (is_syntax_error) { for (i = 0; i <= nsegs; ++i) { if (s_colors[i]) { free(s_colors[i]); } } free(s_colors); free(perc); if (rest) { *rest = gradient; } return 0; } /* sensible limits */ if (npixels < 2) npixels = 2; if (npixels > MAX_GRADIENT_COLORS) npixels = MAX_GRADIENT_COLORS; /* send data back */ *colors_return = s_colors; *perc_return = perc; *nsegs_return = nsegs; if (rest) *rest = gradient; return npixels; }