Subject: patch to 2.2.2 for user-defined shadow and highlight colors

From: Eddie Kohler <[email-masked]>
Date: Wed, 30 Jun 1999 12:13:53 -0400

Hi,

Enclosed is a patch to fvwm-2.2.2 that lets the user specify which colors
fvwm should use for shadows and highlights. I've tried this before :) but
this patch is better. It's smaller and requires fewer changes to existing
.fvwm2rc files.

It adds one command to .fvwm2rc: "AddHilightShadowMapping". You say (for
example)

	AddHilightShadowMapping mistyrose plum1 plum4

in .fvwm2rc. Then core fvwm will use `plum1' as the highlight color and
`plum4' as the shadow color when the background is `mistyrose'. (This patch
doesn't affect modules.)

love,
ed

---------------------PATCH STARTS HERE-----------------------------
diff -cr fvwm-2.2.2/fvwm/builtins.c fvwm-2.2.2-p/fvwm/builtins.c
*** fvwm-2.2.2/fvwm/builtins.c	Sun Feb 28 13:49:18 1999
--- fvwm-2.2.2-p/fvwm/builtins.c	Wed Jun 30 11:46:22 1999
***************
*** 1419,1424 ****
--- 1419,1442 ----
  }

+ void HandleHiliteShadowMapping(XEvent *eventp,Window w,FvwmWindow *tmp_win,
+ 		unsigned long context, char *action,int* Module)
+ {
+   char *normal=NULL, *hilite=NULL, *shadow=NULL;
+   
+   action = GetNextToken(action,&normal);
+   action = GetNextToken(action,&hilite);
+   GetNextToken(action,&shadow);
+ 
+   if (normal && hilite && shadow)
+     AddHiliteShadowMapping (normal, hilite, shadow);
+   
+   if (normal) free(normal);
+   if (hilite) free(hilite);
+   if (shadow) free(shadow);
+ }
+ 
+ 
  void SetHiColor(XEvent *eventp,Window w,FvwmWindow *tmp_win,
  		unsigned long context, char *action,int* Module)
  {
diff -cr fvwm-2.2.2/fvwm/functions.c fvwm-2.2.2-p/fvwm/functions.c
*** fvwm-2.2.2/fvwm/functions.c	Mon Feb 15 13:42:29 1999
--- fvwm-2.2.2-p/fvwm/functions.c	Wed Jun 30 12:04:11 1999
***************
*** 57,62 ****
--- 57,63 ----
  #ifdef MULTISTYLE
    {"AddButtonStyle",AddButtonStyle,  F_ADD_BUTTON_STYLE,    FUNC_NO_WINDOW},
  #endif /* MULTISTYLE */
+   {"AddHilightShadowMapping", HandleHiliteShadowMapping, F_ADD_HIGHLIGHT_SHADOW_MAPPING, FUNC_NO_WINDOW},
    {"AddModuleConfig",  AddModConfig, F_ADD_MOD,             FUNC_NO_WINDOW},
  #ifdef MULTISTYLE
  #ifdef EXTENDED_TITLESTYLE
diff -cr fvwm-2.2.2/fvwm/fvwm2.1 fvwm-2.2.2-p/fvwm/fvwm2.1
*** fvwm-2.2.2/fvwm/fvwm2.1	Fri May 28 11:07:21 1999
--- fvwm-2.2.2-p/fvwm/fvwm2.1	Wed Jun 30 12:04:32 1999
***************
*** 412,417 ****
--- 412,423 ----
  states and a Vector button style is drawn on top of all state.

+ .IP "AddHilightShadowMapping \fIbackground highlight shadow\fP"
+ Sets the highlight and shadow colors that will be used with the given
+ background color. This command overrides the automatic highlight and shadow
+ colors \fIfvwm\fP normally uses.
+ 
+ 
  .IP "AddTitleStyle [ \fIstate\fP ] [ \fIstyle\fP ] [ -- \fI[!]flag ...\fP ]"
  Adds a title style to the title bar.  \fIstate\fP should be one of
  "ActiveUp," "ActiveDown," or "Inactive."  If \fIstate\fP is omitted,
Only in fvwm-2.2.2-p/fvwm: fvwm2.1.orig
diff -cr fvwm-2.2.2/fvwm/misc.h fvwm-2.2.2-p/fvwm/misc.h
*** fvwm-2.2.2/fvwm/misc.h	Sun Feb 14 10:48:56 1999
--- fvwm-2.2.2-p/fvwm/misc.h	Wed Jun 30 11:46:22 1999
***************
*** 434,439 ****
--- 434,440 ----
  void setIconPath(F_CMD_ARGS);
  void setPixmapPath(F_CMD_ARGS);
  void ProcessNewStyle(F_CMD_ARGS);
+ void HandleHiliteShadowMapping(F_CMD_ARGS);
  void SetHiColor(F_CMD_ARGS);
  void SetMenuColor(F_CMD_ARGS);
  void ChangeMenuStyle(F_CMD_ARGS);
diff -cr fvwm-2.2.2/fvwm/parse.h fvwm-2.2.2-p/fvwm/parse.h
*** fvwm-2.2.2/fvwm/parse.h	Tue Jan 12 16:07:44 1999
--- fvwm-2.2.2-p/fvwm/parse.h	Wed Jun 30 12:04:16 1999
***************
*** 85,90 ****
--- 85,91 ----
      F_DFLT_FONT,
      F_DFLT_COLORS,
      F_GLOBAL_OPTS,
+     F_ADD_HIGHLIGHT_SHADOW_MAPPING,
      F_EMULATE,
  
      F_RESIZE = 100,
diff -cr fvwm-2.2.2/libs/ColorUtils.c fvwm-2.2.2-p/libs/ColorUtils.c
*** fvwm-2.2.2/libs/ColorUtils.c	Wed Dec  9 05:46:27 1998
--- fvwm-2.2.2-p/libs/ColorUtils.c	Wed Jun 30 11:46:22 1999
***************
*** 208,213 ****
--- 208,214 ----
    }
  }
  
+ 
  /*
   * This  routine  uses PictureSaveDisplay  and PictureCMap  which must be
   * created by InitPictureCMAP in Picture.c.
***************
*** 215,233 ****
   * If you  attempt to use GetShadow  and GetHilit, make  sure your module
   * calls InitPictureCMAP first.
   */
- static Pixel
- adjust_pixel_brightness(Pixel pixel, double factor)
- {
-   extern Colormap PictureCMap;
-   extern Display *PictureSaveDisplay;
-   XColor c;
-   c.pixel = pixel;
-   XQueryColor (PictureSaveDisplay, PictureCMap, &c);
-   color_mult(&c.red, &c.green, &c.blue, factor);
-   XAllocColor (PictureSaveDisplay, PictureCMap, &c);
- 
-   return c.pixel;
- }
  
  /*
   * These  are  the original fvwm2  APIs, one  for highlights  and one for
--- 216,221 ----
***************
*** 250,261 ****
   * library closeness stuff may be the ideal model.
   * (dje 11/15/98)
   */
  #define DARKNESS_FACTOR 0.5
  Pixel GetShadow(Pixel background) {
!   return adjust_pixel_brightness(background, DARKNESS_FACTOR);
  }
  
- #define BRIGHTNESS_FACTOR 1.4
  Pixel GetHilite(Pixel background) {
!   return adjust_pixel_brightness(background, BRIGHTNESS_FACTOR);
  }
--- 238,331 ----
   * library closeness stuff may be the ideal model.
   * (dje 11/15/98)
   */
+ 
+ 
+ /* Allow user to specify particular mappings for hilite/shadow colors */
+  
+ typedef struct ColorHiliteMap {
+   struct ColorHiliteMap *next;
+   XColor normal;
+   XColor hilite;
+   XColor shadow;
+ } ColorHiliteMap;
+  
+ static ColorHiliteMap *hilite_maps;
+ 
+ 
+ void
+ AddHiliteShadowMapping(char *normal, char *hilite, char *shadow)
+ {
+   extern Colormap PictureCMap;
+   extern Display *PictureSaveDisplay;
+   ColorHiliteMap *himap = (ColorHiliteMap *)safemalloc(sizeof(ColorHiliteMap));
+   if (!himap)
+     goto dead;
+   
+   if (!XParseColor (PictureSaveDisplay, PictureCMap, normal, &himap->normal)) {
+     fprintf (stderr, "[AddHiliteMap]: can't parse color `%s'\n", normal);
+     goto dead;
+   }
+   /* Since a color's definition may change when it is allocated, we allocate
+      it here and re-query it to get the REAL red,green,blue components */
+   if (XAllocColor (PictureSaveDisplay, PictureCMap, &himap->normal)) {
+     XQueryColor (PictureSaveDisplay, PictureCMap, &himap->normal);
+   }
+   
+   if (!XParseColor (PictureSaveDisplay, PictureCMap, hilite, &himap->hilite)) {
+     fprintf (stderr, "[AddHiliteMap]: can't parse color `%s'\n", hilite);
+     goto dead;
+   }
+     
+   if (!XParseColor (PictureSaveDisplay, PictureCMap, shadow, &himap->shadow)) {
+     fprintf (stderr, "[AddHiliteMap]: can't parse color `%s'\n", shadow);
+     goto dead;
+   }
+ 
+   himap->next = hilite_maps;
+   hilite_maps = himap;
+   return;
+   
+  dead:
+   if (himap)
+     free(himap);
+ }
+ 
+ 
  #define DARKNESS_FACTOR 0.5
+ #define BRIGHTNESS_FACTOR 1.4
+ 
+ static Pixel
+ get_shadow_or_hilite(Pixel background, int is_hilite)
+ {
+   extern Colormap PictureCMap;
+   extern Display *PictureSaveDisplay;
+   ColorHiliteMap *cbm;
+   XColor c;
+   
+   c.pixel = background;
+   XQueryColor (PictureSaveDisplay, PictureCMap, &c);
+   
+   /* check existing shadow/hilite mappings */
+   for (cbm = hilite_maps; cbm; cbm = cbm->next)
+     if (c.red == cbm->normal.red
+ 	&& c.green == cbm->normal.green
+ 	&& c.blue == cbm->normal.blue) {
+       XColor *answer = (is_hilite ? &cbm->hilite : &cbm->shadow);
+       XAllocColor (PictureSaveDisplay, PictureCMap, answer);
+       return answer->pixel;
+     }
+   
+   /* if not found, use the default color multiplication */
+   color_mult(&c.red, &c.green, &c.blue,
+ 	     (is_hilite ? BRIGHTNESS_FACTOR : DARKNESS_FACTOR));
+   XAllocColor (PictureSaveDisplay, PictureCMap, &c);
+   return c.pixel;
+ }
+ 
  Pixel GetShadow(Pixel background) {
!   return get_shadow_or_hilite(background, 0);
  }
  
  Pixel GetHilite(Pixel background) {
!   return get_shadow_or_hilite(background, 1);
  }
diff -cr fvwm-2.2.2/libs/fvwmlib.h fvwm-2.2.2-p/libs/fvwmlib.h
*** fvwm-2.2.2/libs/fvwmlib.h	Mon Jan 11 00:00:28 1999
--- fvwm-2.2.2-p/libs/fvwmlib.h	Wed Jun 30 11:46:22 1999
***************
*** 136,141 ****
--- 136,142 ----
  void color_reduce_pixmap(XpmImage *, int);
  #endif
  
+ void	 AddHiliteShadowMapping(char *normal, char *hilite, char *shadow);
  Pixel    GetShadow(Pixel);              /* 3d.c */
  Pixel    GetHilite(Pixel);              /* 3d.c */
  
--
Visit the official FVWM web page at <URL:http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm-workers" in the
body of a message to [email-masked].
To report problems, send mail to [email-masked]