Subject: Re: Color for (Bitmap) Icon ?

From: "Peter J. Weyers" <[email-masked]>
Date: Wed, 5 Mar 1997 15:09:57 +0100 (MET)

On Tue, 25 Feb 1997, Peter J. Weyers wrote:

> If I am right, I would like to implement new (style? decorate ?) commands
> IconColor <fore>/<back>, HiIconColor <fore>/<back> to set the icon colors
> seperatly. In advance I would like to now of course, if anybody is already
> working on something like that. And wether this had a chance to become
> part of the official fvwm2.

In the meantime, I read the TO-DO list carefully enought to see, that
special icon treatment there.

By now I have a patch for 2.0.45 for giving Icons specific colors on a
Decor basis.  Unfortunalty it does not default to the corresponding window
colors, but to a set of pre-defined default colors. To change this it
would be a help if the (inactive) window colors would become a Decor too.
It is basically a copy off the 'HiColor' source code.

The syntax for the .fvwm2rc is "IconColor <fore> <back> <hifore> <hiback>"
by now. Maybe it should become "IconStyle Color <fore> <back>" and 
"IconStyle HiColor <hifore> <hiback>"?

Anyway, I append my patch to be applied in the 'fvwm' directory of the
distributed version.  To make use of it you have to add the compiler flag
-DICONCOLOR.

Of course I'd like to hear your opinion.

Peter _______________
 ----| Info, PGP-Key | -->  http://sugra.desy.de/user/weyers/home.html <--
      ---------------

diff -c /tmp/fvwm-2.0.45/fvwm/builtins.c ./builtins.c
*** /tmp/fvwm-2.0.45/fvwm/builtins.c	Wed Jan 22 14:37:28 1997
--- ./builtins.c	Sat Mar  1 23:28:12 1997
***************
*** 1392,1398 ****
    free(tmp);
  }
  
- 
  void SetHiColor(XEvent *eventp,Window w,FvwmWindow *tmp_win,
  		unsigned long context, char *action,int* Module)
  {
--- 1392,1397 ----
***************
*** 1462,1467 ****
--- 1461,1590 ----
    }
  }
  
+ #ifdef ICONCOLOR
+ 
+ void SetIconColor(XEvent *eventp,Window w,FvwmWindow *tmp_win,
+ 		unsigned long context, char *action,int* Module)
+ {
+   XGCValues gcv;
+   unsigned long gcm;
+   char *fore=NULL, *back=NULL, *hifore=NULL, *hiback=NULL;
+   extern char *white,*black;
+   FvwmWindow *hilight;
+ #ifdef USEDECOR
+   FvwmDecor *fl = cur_decor ? cur_decor : &Scr.DefaultDecor;
+ #else
+   FvwmDecor *fl = &Scr.DefaultDecor;
+ #endif
+   
+   if( action && action[0])
+     action = GetNextToken(action,&fore);
+   if( action && action[0])
+     action = GetNextToken(action,&back);
+   if( action && action[0])
+     action = GetNextToken(action,&hifore);
+   if( action && action[0])
+     GetNextToken(action,&hiback);
+ 
+   if(Scr.d_depth > 2)
+   {
+     if(fore != NULL)
+     {
+ 	fl->IconColors.fore = GetColor(fore);
+     }
+     if(back != NULL)
+     {
+ 	fl->IconColors.back = GetColor(back);
+     }
+     if(hifore != NULL)
+     {
+ 	fl->IconHiColors.fore = GetColor(hifore);
+     }
+     if(hiback != NULL)
+     {
+ 	fl->IconHiColors.back = GetColor(hiback);
+     }
+     fl->IconRelief.back    = GetShadow(fl->IconColors.back);
+     fl->IconRelief.fore    = GetHilite(fl->IconColors.back);
+     fl->IconHiRelief.back  = GetShadow(fl->IconHiColors.back);
+     fl->IconHiRelief.fore  = GetHilite(fl->IconHiColors.back);
+   }
+   else
+   {
+     fl->IconColors.back  = GetColor(white);
+     fl->IconColors.fore  = GetColor(black); 
+     fl->IconRelief.back  = GetColor(black);
+     fl->IconRelief.fore  = GetColor(white);
+     fl->IconHiColors.back  = GetColor(white);
+     fl->IconHiColors.fore  = GetColor(black); 
+     fl->IconHiRelief.back  = GetColor(black);
+     fl->IconHiRelief.fore  = GetColor(white);
+   }
+   if (fore) free(fore); 
+   if (back) free(back);
+   if (hifore) free(hifore); 
+   if (hiback) free(hiback);
+   /*-----norm colors--------*/
+   gcm = GCFunction|GCPlaneMask|GCGraphicsExposures|GCLineWidth|GCForeground|
+     GCBackground;
+   gcv.foreground = fl->IconRelief.fore;
+   gcv.background = fl->IconRelief.back;
+   gcv.fill_style = FillSolid;
+   gcv.plane_mask = AllPlanes;
+   gcv.function = GXcopy;
+   gcv.graphics_exposures = False;
+   gcv.line_width = 0;
+ 
+   if(fl->IconReliefGC != NULL)
+   {
+     XFreeGC(dpy,fl->IconReliefGC);
+   }
+   fl->IconReliefGC = XCreateGC(dpy, Scr.Root, gcm, &gcv);  
+ 
+   gcv.foreground = fl->IconRelief.back;
+   gcv.background = fl->IconRelief.fore;
+   if(fl->IconShadowGC != NULL)
+   {
+     XFreeGC(dpy,fl->IconShadowGC);
+   }
+   fl->IconShadowGC = XCreateGC(dpy, Scr.Root, gcm, &gcv);  
+   /*-----hi colors--------*/
+   gcm = GCFunction|GCPlaneMask|GCGraphicsExposures|GCLineWidth|GCForeground|
+     GCBackground;
+   gcv.foreground = fl->IconHiRelief.fore;
+   gcv.background = fl->IconHiRelief.back;
+   gcv.fill_style = FillSolid;
+   gcv.plane_mask = AllPlanes;
+   gcv.function = GXcopy;
+   gcv.graphics_exposures = False;
+   gcv.line_width = 0;
+ 
+   if(fl->IconHiReliefGC != NULL)
+   {
+     XFreeGC(dpy,fl->IconHiReliefGC);
+   }
+   fl->IconHiReliefGC = XCreateGC(dpy, Scr.Root, gcm, &gcv);  
+ 
+   gcv.foreground = fl->IconHiRelief.back;
+   gcv.background = fl->IconHiRelief.fore;
+   if(fl->IconHiShadowGC != NULL)
+   {
+     XFreeGC(dpy,fl->IconHiShadowGC);
+   }
+   fl->IconHiShadowGC = XCreateGC(dpy, Scr.Root, gcm, &gcv);  
+ 
+ /*-------------*/
+ #if 0
+   if((Scr.flags & WindowsCaptured)&&(Scr.Hilite != NULL))
+   {
+     hilight = Scr.Hilite;
+     SetBorder(Scr.Hilite,False,True,True,None);
+     SetBorder(hilight,True,True,True,None);
+   }
+ #endif
+ }
+ 
+ #endif /* ICONCOLOR */
  
  void SetMenuStyle(XEvent *eventp,Window w,FvwmWindow *tmp_win,
                    unsigned long context, char *action,int* Module)
diff -c /tmp/fvwm-2.0.45/fvwm/functions.c ./functions.c
*** /tmp/fvwm-2.0.45/fvwm/functions.c	Tue Jan 14 15:06:33 1997
--- ./functions.c	Sat Mar  1 17:51:01 1997
***************
*** 80,85 ****
--- 80,88 ----
    {"GlobalOpts",   SetGlobalOptions, F_GLOBAL_OPTS,         FUNC_NO_WINDOW},
    {"GotoPage",     goto_page_func,   F_GOTO_PAGE,           FUNC_NO_WINDOW},
    {"HilightColor", SetHiColor,       F_HICOLOR,             FUNC_NO_WINDOW},
+ #ifdef ICONCOLOR  
+   {"IconColor",    SetIconColor,     F_ICONCOLOR,           FUNC_NO_WINDOW},
+ #endif
    {"Iconify",      iconify_function, F_ICONIFY,             FUNC_NEEDS_WINDOW},
    {"IconFont",     LoadIconFont,     F_ICONFONT,            FUNC_NO_WINDOW},
    {"IconPath",     setIconPath,      F_ICON_PATH,           FUNC_NO_WINDOW},
diff -c /tmp/fvwm-2.0.45/fvwm/fvwm.c ./fvwm.c
*** /tmp/fvwm-2.0.45/fvwm/fvwm.c	Wed Jan 22 14:37:44 1997
--- ./fvwm.c	Sat Mar  1 21:26:12 1997
***************
*** 629,634 ****
--- 629,637 ----
    /* set up default colors, fonts, etc */
    char *defaults[] = {
      "HilightColor black grey",
+ #ifdef ICONCOLOR
+     "IconColor lightgrey dimgrey black grey",
+ #endif
      "XORValue 1",
      "MenuStyle black grey slategrey fixed fvwm",
      "TitleStyle Centered -- Raised",
***************
*** 1092,1098 ****
      
      fl->HiReliefGC = NULL;
      fl->HiShadowGC = NULL;
! 
  #ifdef USEDECOR
      fl->tag = NULL;
      fl->next = NULL;
--- 1095,1107 ----
      
      fl->HiReliefGC = NULL;
      fl->HiShadowGC = NULL;
! #ifdef ICONCOLOR
!     fl->IconReliefGC = NULL;
!     fl->IconShadowGC = NULL;
!     fl->IconHiReliefGC = NULL;
!     fl->IconHiShadowGC = NULL;
! #endif
!     
  #ifdef USEDECOR
      fl->tag = NULL;
      fl->next = NULL;
***************
*** 1101,1106 ****
--- 1110,1118 ----
  	extern void AddToDecor(FvwmDecor *, char *);
  	AddToDecor(fl, "HilightColor black grey");
  	AddToDecor(fl, "WindowFont fixed");
+ #ifdef ICONCOLOR
+     	AddToDecor(fl, "IconColor lightgrey dimgrey black grey");
+ #endif
      }
  #endif
  
diff -c /tmp/fvwm-2.0.45/fvwm/icons.c ./icons.c
*** /tmp/fvwm-2.0.45/fvwm/icons.c	Mon Dec 23 23:07:47 1996
--- ./icons.c	Sat Mar  1 21:04:59 1997
***************
*** 215,224 ****
  	  TextColor = Scr.DefaultDecor.HiColors.fore;
  	  BackColor = Scr.DefaultDecor.HiColors.back;
        } else {
! 	Relief = GetDecor(Tmp_win,HiReliefGC);
! 	Shadow = GetDecor(Tmp_win,HiShadowGC);
! 	TextColor = GetDecor(Tmp_win,HiColors.fore);
! 	BackColor = GetDecor(Tmp_win,HiColors.back);
        }
        /* resize the icon name window */
        if(Tmp_win->icon_w != None)
--- 215,231 ----
  	  TextColor = Scr.DefaultDecor.HiColors.fore;
  	  BackColor = Scr.DefaultDecor.HiColors.back;
        } else {
! #ifdef ICONCOLOR
! 	Relief = GetDecor(Tmp_win,IconHiReliefGC);
! 	Shadow = GetDecor(Tmp_win,IconHiShadowGC);
! 	TextColor = GetDecor(Tmp_win,IconHiColors.fore);
! 	BackColor = GetDecor(Tmp_win,IconHiColors.back);
! #else
!         Relief = GetDecor(Tmp_win,HiReliefGC);
!         Shadow = GetDecor(Tmp_win,HiShadowGC);
!         TextColor = GetDecor(Tmp_win,HiColors.fore);
!         BackColor = GetDecor(Tmp_win,HiColors.back);
! #endif
        }
        /* resize the icon name window */
        if(Tmp_win->icon_w != None)
***************
*** 236,252 ****
  	{
  	  Relief = Scr.MenuGC;
  	  Shadow = Scr.MenuGC;
  	}
        else
  	{
! 	  Globalgcv.foreground = Tmp_win->ReliefPixel;
! 	  Globalgcm = GCForeground;
! 	  XChangeGC(dpy,Scr.ScratchGC1,Globalgcm,&Globalgcv); 
! 	  Relief = Scr.ScratchGC1;
! 	  
! 	  Globalgcv.foreground = Tmp_win->ShadowPixel;
! 	  XChangeGC(dpy,Scr.ScratchGC2,Globalgcm,&Globalgcv); 
! 	  Shadow = Scr.ScratchGC2;
  	}
        /* resize the icon name window */
        if(Tmp_win->icon_w != None)
--- 243,267 ----
  	{
  	  Relief = Scr.MenuGC;
  	  Shadow = Scr.MenuGC;
+ #ifdef ICONCOLOR
+ 	  TextColor = Tmp_win->TextPixel;
+           BackColor = Tmp_win->BackPixel;
+ #endif
  	}
        else
  	{
! #ifdef ICONCOLOR
!           Relief = GetDecor(Tmp_win,IconReliefGC);
!           Shadow = GetDecor(Tmp_win,IconShadowGC);
! #else
!           Globalgcv.foreground = Tmp_win->ReliefPixel;
!           Globalgcm = GCForeground;
!           XChangeGC(dpy,Scr.ScratchGC1,Globalgcm,&Globalgcv); 
!           Relief = Scr.ScratchGC1;
!           Globalgcv.foreground = Tmp_win->ShadowPixel;
!           XChangeGC(dpy,Scr.ScratchGC2,Globalgcm,&Globalgcv); 
!           Shadow = Scr.ScratchGC2;
! #endif
  	}
        /* resize the icon name window */
        if(Tmp_win->icon_w != None)
***************
*** 254,263 ****
            Tmp_win->icon_w_width = Tmp_win->icon_p_width;
            Tmp_win->icon_xl_loc = Tmp_win->icon_x_loc;
          }
        TextColor = Tmp_win->TextPixel;
        BackColor = Tmp_win->BackPixel;
! 	  
      }
    if((Tmp_win->flags & ICON_OURS)&&(Tmp_win->icon_pixmap_w != None))
      XSetWindowBackground(dpy,Tmp_win->icon_pixmap_w,
  			 BackColor);
--- 269,285 ----
            Tmp_win->icon_w_width = Tmp_win->icon_p_width;
            Tmp_win->icon_xl_loc = Tmp_win->icon_x_loc;
          }
+ 
+ #ifdef ICONCOLOR
+       TextColor = GetDecor(Tmp_win,IconColors.fore);
+       BackColor = GetDecor(Tmp_win,IconColors.back);
+ #else	  
        TextColor = Tmp_win->TextPixel;
        BackColor = Tmp_win->BackPixel;
! #endif
! 
      }
+     
    if((Tmp_win->flags & ICON_OURS)&&(Tmp_win->icon_pixmap_w != None))
      XSetWindowBackground(dpy,Tmp_win->icon_pixmap_w,
  			 BackColor);
diff -c /tmp/fvwm-2.0.45/fvwm/misc.h ./misc.h
*** /tmp/fvwm-2.0.45/fvwm/misc.h	Mon Dec 23 23:07:47 1996
--- ./misc.h	Sat Mar  1 19:02:57 1997
***************
*** 490,495 ****
--- 490,499 ----
  	  char *action, int *Module);
  void SetHiColor(XEvent *eventp,Window w,FvwmWindow *tmp_win,
  		unsigned long context, char *action,int* Module);
+ #ifdef ICONCOLOR
+ void SetIconColor(XEvent *eventp,Window w,FvwmWindow *tmp_win,
+ 	    	  unsigned long context, char *action,int* Module);
+ #endif
  void SetMenuColor(XEvent *eventp,Window w,FvwmWindow *tmp_win,
  		unsigned long context, char *action,int* Module);
  void LoadIconFont(XEvent *eventp,Window w,FvwmWindow *tmp_win,
diff -c /tmp/fvwm-2.0.45/fvwm/parse.h ./parse.h
*** /tmp/fvwm-2.0.45/fvwm/parse.h	Mon Dec 23 23:07:47 1996
--- ./parse.h	Sat Mar  1 17:49:07 1997
***************
*** 73,78 ****
--- 73,81 ----
  #define F_COLORMAP_FOCUS        55
  #define F_TITLESTYLE            56
  #define F_EXEC_SETUP            57
+ #ifdef ICONCOLOR
+ #define F_ICONCOLOR             58
+ #endif
  /* Functions which require a target window */
  #define F_RESIZE		100
  #define F_RAISE			101
diff -c /tmp/fvwm-2.0.45/fvwm/screen.h ./screen.h
*** /tmp/fvwm-2.0.45/fvwm/screen.h	Wed Jan 22 14:37:49 1997
--- ./screen.h	Sat Mar  1 17:50:36 1997
***************
*** 193,199 ****
      ColorPair HiRelief;
      GC HiReliefGC;		/* GC for highlighted window relief */
      GC HiShadowGC;		/* GC for highlighted window shadow */
! 
      int TitleHeight;            /* height of the title bar window */
      MyFont WindowFont;          /* font structure for window titles */
  
--- 193,208 ----
      ColorPair HiRelief;
      GC HiReliefGC;		/* GC for highlighted window relief */
      GC HiShadowGC;		/* GC for highlighted window shadow */
! #ifdef ICONCOLOR
!     ColorPair IconColors;       /* icon inactive fore/back colors */
!     ColorPair IconRelief;
!     GC IconReliefGC;            /* GC for inactive icon relief */
!     GC IconShadowGC;            /* GC for inactive icon shadow */
!     ColorPair IconHiColors;	/* icon highlight fore/back colors */
!     ColorPair IconHiRelief;
!     GC IconHiReliefGC;		/* GC for highlighted icon relief */
!     GC IconHiShadowGC;		/* GC for highlighted icon shadow */
! #endif
      int TitleHeight;            /* height of the title bar window */
      MyFont WindowFont;          /* font structure for window titles */

--
Visit the official FVWM web page at <URL:http://www.hpc.uh.edu/fvwm/>.
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].