Subject: Relief Patch

From: Remko Troncon <[email-masked]>
Date: Wed, 5 Feb 2003 17:39:25 +0100

Hello FVWM workers,

I wrote a patch for a minor adjustment for the FvwmButtons module. I
added an extra FvwmButtons option 'Relief reliefmode' to specify when
relief of the button should be drawn: only in the up state, only in the down
state, or in both states (default).
The reason i wanted this was so that my buttons can integrate nicely
with my desktop. An example can be seen on 
http://www.cs.kuleuven.ac.be/~remko/fvwm/screenshot2.png, where i only draw 
relief when a button is down (i.e. the panel is open). 
I don't know if you are interested in putting this in the official fvwm 
branch. If so, it might be good to check my patch for bugs ;-)

Finally i have one question: Line 357 of 'draw.c' in FvwmButtons sets
the frame width to the absolute value of the frame; however, the manual
states that a negative value for a frame simply inverts the
relief/shadow. With this line, it does not. Why is that ?

cheers,
Remko

PS: I am not on the fvwm-workers list.

diff -u -r fvwm-2.5.5/modules/FvwmButtons/FvwmButtons.1 fvwm-2.5.5.patched/modules/FvwmButtons/FvwmButtons.1
--- fvwm-2.5.5/modules/FvwmButtons/FvwmButtons.1	Sat Nov  9 16:18:52 2002
+++ fvwm-2.5.5.patched/modules/FvwmButtons/FvwmButtons.1	Wed Feb  5 16:45:45 2003
@@ -169,6 +169,11 @@
 Specifies a background pixmap to use.  Specify "none" (without the
 double quotes) for a transparent background.
 
+.IP "*FvwmButtons: Relief \fImode\fP"
+Specifies when to draw relief around the button. \fImode\fP is either
+\fIUp\fP, \fIDown\fP or \fIBoth\fP for drawing relief only when
+the button is up, down, or in both cases.
+
 .IP "*FvwmButtons: Rows \fIrows\fP"
 Specifies the number of rows of buttons to be created. The default
 is 2 rows.
diff -u -r fvwm-2.5.5/modules/FvwmButtons/FvwmButtons.c fvwm-2.5.5.patched/modules/FvwmButtons/FvwmButtons.c
--- fvwm-2.5.5/modules/FvwmButtons/FvwmButtons.c	Tue Nov  5 13:30:29 2002
+++ fvwm-2.5.5.patched/modules/FvwmButtons/FvwmButtons.c	Wed Feb  5 16:45:46 2003
@@ -779,6 +779,7 @@
 
   UberButton->title   = MyName;
   UberButton->swallow = 1; /* the panel is shown */
+  UberButton->relief  = RELIEF_BOTH; /* By default, show both reliefs */
 
   /* parse module options */
   ParseConfiguration(UberButton);
diff -u -r fvwm-2.5.5/modules/FvwmButtons/FvwmButtons.h fvwm-2.5.5.patched/modules/FvwmButtons/FvwmButtons.h
--- fvwm-2.5.5/modules/FvwmButtons/FvwmButtons.h	Tue Oct  1 09:03:29 2002
+++ fvwm-2.5.5.patched/modules/FvwmButtons/FvwmButtons.h	Wed Feb  5 16:45:46 2003
@@ -89,6 +89,7 @@
 		     0x02000000 /* By default this only done on Popup */
 #define b_Id         0x04000000 /* Has a user defined id for referencing */
 #define b_IconAlpha  0x08000000 /* Icon has an alpha chanel */
+#define b_Relief     0x10000000 /* When to use relief */
 
 /* Flags for b->swallow */
 #define b_Count       0x0003 /* Init counter for swallowing */
@@ -139,6 +140,7 @@
   Pixel bc,hc,sc;          /* b_Back && !b_IconBack */
   FvwmPicture *backicon;   /* b_Back && b_IconBack */
   ushort minx,miny;        /* b_Size */
+  byte relief;             /* b_Relief */
 };
 
 typedef struct
@@ -169,6 +171,10 @@
   char *back;              /* b_Back */
   char *fore;              /* b_Fore */
   int colorset;            /* b_Colorset */
+#define RELIEF_UP 0x1      /* Use relief only in up state */
+#define RELIEF_DOWN 0x2    /* Use relief only in down state */
+#define RELIEF_BOTH 0x3    /* use relief in both states */
+  byte relief;             /* b_Relief */
   byte xpad,ypad;          /* b_Padding */
   signed char framew;      /* b_Frame */
   byte justify;            /* b_Justify */
diff -u -r fvwm-2.5.5/modules/FvwmButtons/button.c fvwm-2.5.5.patched/modules/FvwmButtons/button.c
--- fvwm-2.5.5/modules/FvwmButtons/button.c	Tue Oct  1 09:03:29 2002
+++ fvwm-2.5.5.patched/modules/FvwmButtons/button.c	Wed Feb  5 16:45:46 2003
@@ -309,6 +309,24 @@
   return -1;
 }
 
+byte buttonRelief(button_info *b)
+{
+    button_info *bb = b;
+    if (bb->flags & b_Relief) 
+        return bb->relief;
+    else if (bb->flags & b_Container && bb->c->flags & b_Colorset)
+        return bb->relief;
+    while ((bb = bb->parent))
+    {
+        if (bb->c->flags & b_Relief)
+            return bb->c->relief;
+    }
+#ifdef DEBUG
+    fprintf(stderr,"%s: BUG: No relief definition?\n",MyName);
+#endif
+    return RELIEF_BOTH;
+}
+
 int buttonBackgroundButton(button_info *b, button_info **r_b)
 {
 	button_info *tmpb, *pb;
@@ -515,6 +533,7 @@
     b->c->back=safestrdup("rgb:90/80/90");
     b->c->fore=safestrdup("black");
     b->c->framew=2;
+    b->c->relief=RELIEF_BOTH;
   }
 
 }
diff -u -r fvwm-2.5.5/modules/FvwmButtons/button.h fvwm-2.5.5.patched/modules/FvwmButtons/button.h
--- fvwm-2.5.5/modules/FvwmButtons/button.h	Tue Oct  1 09:03:29 2002
+++ fvwm-2.5.5.patched/modules/FvwmButtons/button.h	Wed Feb  5 16:45:46 2003
@@ -42,6 +42,7 @@
 Pixel buttonHilite(button_info*);
 Pixel buttonShadow(button_info*);
 int buttonColorset(button_info *b);
+byte buttonRelief(button_info *b);
 int buttonBackgroundButton(button_info *b, button_info **r_b);
 byte buttonSwallow(button_info*);
 byte buttonJustify(button_info*);
diff -u -r fvwm-2.5.5/modules/FvwmButtons/draw.c fvwm-2.5.5.patched/modules/FvwmButtons/draw.c
--- fvwm-2.5.5/modules/FvwmButtons/draw.c	Tue Nov  5 13:30:29 2002
+++ fvwm-2.5.5.patched/modules/FvwmButtons/draw.c	Wed Feb  5 16:45:46 2003
@@ -61,30 +61,32 @@
 *** RelieveButton()
 *** Draws the relief pattern around a window.
 **/
-void RelieveButton(Window wn,int width,int x,int y,int w,int h,Pixel relief,
-		   Pixel shadow,int rev)
+void RelieveButton(Window wn,int width,int x,int y,int w,int h,Pixel backgr,
+           Pixel relief, Pixel shadow,int rev,byte relief_flags)
 {
   XGCValues gcv;
-  GC swapGC, reliefGC, shadowGC;
+  GC reliefGC, shadowGC, swapGC;
 
   if(!width)
     return;
 
-  gcv.foreground=relief;
+  if (rev) 
+    gcv.foreground=(relief_flags&0x2 ? shadow : backgr);
+  else 
+    gcv.foreground=(relief_flags&0x1 ? relief : backgr);
   XChangeGC(Dpy,NormalGC,GCForeground,&gcv);
   reliefGC=NormalGC;
 
-  gcv.foreground=shadow;
+  if(rev)
+    gcv.foreground=(relief_flags & 0x2 ? relief : backgr);
+  else
+    gcv.foreground=(relief_flags & 0x1 ? shadow : backgr);
   XChangeGC(Dpy,ShadowGC,GCForeground,&gcv);
   shadowGC=ShadowGC;
-
+  
   if(width<0)
   {
     width=-width;
-    rev = !rev;
-  }
-  if(rev)
-  {
     swapGC=reliefGC;
     reliefGC=shadowGC;
     shadowGC=swapGC;
@@ -618,7 +620,7 @@
 	}
 
 	/* relief */
-	RelieveButton(MyWindow,f,x,y,BW,BH,hc,sc,rev ^ rev_xor);
+	RelieveButton(MyWindow,f,x,y,BW,BH,bc,hc,sc,rev ^ rev_xor,buttonRelief(b));
 }
 
 /**
diff -u -r fvwm-2.5.5/modules/FvwmButtons/draw.h fvwm-2.5.5.patched/modules/FvwmButtons/draw.h
--- fvwm-2.5.5/modules/FvwmButtons/draw.h	Tue Nov  5 13:30:29 2002
+++ fvwm-2.5.5.patched/modules/FvwmButtons/draw.h	Wed Feb  5 16:45:46 2003
@@ -33,7 +33,7 @@
 #define DRAW_FORCE       3
 #define DRAW_DESK_RELIEF 4
 
-void RelieveButton(Window,int,int,int,int,int,Pixel,Pixel,int);
+void RelieveButton(Window,int,int,int,int,int,Pixel,Pixel,Pixel,int,byte);
 void MakeButton(button_info*);
 void RedrawButton(button_info*, int draw, XEvent *pev);
 void DrawTitle(
diff -u -r fvwm-2.5.5/modules/FvwmButtons/output.c fvwm-2.5.5.patched/modules/FvwmButtons/output.c
--- fvwm-2.5.5/modules/FvwmButtons/output.c	Wed Jun 26 15:42:45 2002
+++ fvwm-2.5.5.patched/modules/FvwmButtons/output.c	Wed Feb  5 16:45:46 2003
@@ -66,6 +66,14 @@
     fprintf(stderr,"Title(%s) ",b->title);
   if(b->flags&b_Icon)
     fprintf(stderr,"Icon(%s,%i) ",b->icon_file,(int)b->IconWin);
+  if(b->flags&b_Relief) {
+    switch(b->relief) {
+        case RELIEF_UP: fprintf(stderr,"Relief(Up) "); break;
+        case RELIEF_DOWN: fprintf(stderr,"Relief(Down) "); break;
+        case RELIEF_BOTH: fprintf(stderr,"Relief(Both) "); break;
+        default: fprintf(stderr,"Relief(ILLEGAL) "); /* Should not happen */
+    }
+  }
   if(b->flags&b_Icon)
     fprintf(stderr,"Panelw(%i) ",(int)b->PanelWin);
   if(b->flags&b_Action)
@@ -128,6 +136,13 @@
     fprintf(stderr,"Frame %i ",b->framew);
   if(b->flags&b_Padding)
     fprintf(stderr,"Padding %i %i ",b->xpad,b->ypad);
+  if(b->flags&b_Relief) {
+    switch(b->relief) {
+        case RELIEF_UP: fprintf(stderr,"Relief Up "); break;
+        case RELIEF_DOWN: fprintf(stderr,"Relief Down "); break;
+        case RELIEF_BOTH: fprintf(stderr,"Relief Both "); break;
+    }
+  }
   if(b->flags&b_Title)
   {
     fprintf(stderr,"Title ");
diff -u -r fvwm-2.5.5/modules/FvwmButtons/parse.c fvwm-2.5.5.patched/modules/FvwmButtons/parse.c
--- fvwm-2.5.5/modules/FvwmButtons/parse.c	Tue Oct  1 09:03:29 2002
+++ fvwm-2.5.5.patched/modules/FvwmButtons/parse.c	Wed Feb  5 16:45:46 2003
@@ -242,6 +242,43 @@
   *ss=s;
 }
 
+static void ParseRelief(char **ss, byte *relief, unsigned long *flags)
+{
+    char *opts[] =
+    {
+      "up",
+      "down",
+      "both",
+      NULL
+    };
+    char *t,*s=*ss;
+    
+    s = trimleft(s);
+    switch (GetTokenIndex(s,opts,0,&s)) 
+    {
+        case 0: /* Up */
+            *relief = RELIEF_UP;
+            *flags |= b_Relief;
+            break;
+        case 1: /* Down */
+            *relief = RELIEF_DOWN;
+            *flags |= b_Relief;
+            break;
+        case 2: /* Both */
+            *relief = RELIEF_BOTH;
+            *flags |= b_Relief;
+            break;
+        default:
+            t = seekright(&s);
+            fprintf(stderr,"%s: Illegal relief option \"%s\"\n",
+                                                        MyName,(t)?t:""); 
+            if(t) 
+                free (t);
+    }
+    if (*s) s++;
+    *ss=s;
+}
+
 /**
 *** ParseSwallow()
 *** Parses the options possible to Swallow
@@ -576,6 +613,7 @@
     "size",
     "boxsize",
     "colorset",
+    "relief",
     NULL
   };
   char *t,*o,*s=*ss;
@@ -748,6 +786,10 @@
       }
       break;
 
+    case 13: /* Relief */
+        ParseRelief(&s,&b->c->relief,&b->c->flags);
+        break;
+
     default:
       t=seekright(&s);
       fprintf(stderr,"%s: Illegal container option \"%s\"\n",MyName,
@@ -1344,6 +1386,7 @@
   return;
 }
 
+
 /**
 *** ParseConfigLine
 **/
@@ -1365,6 +1408,7 @@
     "pixmap",
     "boxsize",
     "colorset",
+    "relief",
     NULL
   };
   int i,j,k;
@@ -1488,6 +1532,11 @@
       ub->c->flags &= ~b_Colorset;
     }
     break;
+ 
+  case 13: /* Relief */ 
+    ParseRelief(&s,&ub->c->relief,&ub->c->flags);
+    break;
+  
   default:
     s = trimleft(s);
     ParseButton(ubb,s);
--
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]

---

From: Mikhael Goikhman <[email-masked]>
Date: Mon, 10 Feb 2003 12:16:13 +0000

> branch. If so, it might be good to check my patch for bugs ;-)

I would like to have this patch applied, but I don't have enough time to
do this now.

Probably the option name should be different.
How about having 2 options UpRelief and DownRelief with values
"flat", "none", "raised" and "sunken" ("flat" is different from "none"
in that it consumes Frame space, but I am not sure this is needed).
And in case the negative frame values are fixed these would be boolean
options with values "true" and "false".

> relief/shadow. With this line, it does not. Why is that ?

I don't know. This abs() line seems to be even in 2.2.x.
But negative frame worked in 2.4.x as stated in the man page.
I think this bug (always raised-looking relief) is somewhere else.

Regards,
Mikhael.

---

From: Remko Troncon <[email-masked]>
Date: Mon, 10 Feb 2003 14:10:18 +0100

> I would like to have this patch applied, but I don't have enough time to

Ok, thanks.

> in that it consumes Frame space, but I am not sure this is needed).

These options would make the possibility of negative frame values obsolete, 
right ? This approach allows more control over the relief, although i'm not 
sure if someone would ever need that much possibilities of relief (e.g. 
having both up and down state sunken).

> I think this bug (always raised-looking relief) is somewhere else.

Weird. Because IIRC, removing this line seemed to remove the bug.

cheers,
Remko

---

From: Mikhael Goikhman <[email-masked]>
Date: Mon, 10 Feb 2003 13:31:01 +0000

> Weird. Because IIRC, removing this line seemed to remove the bug.

These were only my thooughst. If you redo the patch (possibly fixing
the negative Frame or, instead, making it absolete by new options),
it is likely that your solution (whichever it will be) is applied.

Regards,
Mikhael.

---

From: Remko Troncon <[email-masked]>
Date: Fri, 14 Feb 2003 09:28:50 +0100

> it is likely that your solution (whichever it will be) is applied.

With the frame bug fixed, are there any preferences for my Relief
option for FvwmButtons (to be able to customize a bit more when to use 
relief) ?
- Either i introduce an option Relief [OnlyUp|OnlyDown|Both] for drawing
  relief in both up,down or both states (this patch is ready)
- Or, as Mikhael proposed, i give more customization power, and insert 
  2 options UpRelief [flat|raised|sunken] and DownRelief
  [flat|raised|sunken] (introducing the possibility of having sunken
  relief for both up and down state)
I'm sorry to bother you with questions on such a small patch, but as i am new 
to this, I would like to get some opinions before adding another option 
to FVWM.

thanks,
Remko