Subject: borders.c patch

From: Orlando Andico <[email-masked]>
Date: Tue, 18 Mar 1997 16:58:21 +0800 (GMT)

hello!

 here's a patch I made to borders.c which makes title clipping a bit
"neater" when the window is too narrow. It's to fvwm-2.0.45. it's
"feature" is when the window is too narrow, the title is clipped at an
intercharacter space instead of wherever it hits the edge of the title
bar.

-----------------------------------------------------------------------
Orlando Andico                               IRC Lab/EE Dept/UP Diliman
email: [email-masked]          http://gibson.eee.upd.edu.ph

--------------------------BEGIN CODE SEGMENT---------------------------

--- borders.c.orig	Tue Mar 18 16:54:06 1997
+++ borders.c	Tue Mar 18 16:54:04 1997
@@ -706,16 +706,17 @@
  *  Redraws just the title bar
  *
  ****************************************************************************/
 void SetTitleBar (FvwmWindow *t,Bool onoroff, Bool NewTitle)
 {
-  int hor_off, w, i;
+  int hor_off, w, i, nchars;
   enum ButtonState title_state;
   ButtonFaceStyle tb_style;
   int tb_flags;
   GC ReliefGC, ShadowGC, tGC;
   Pixel Forecolor, BackColor;
+   char wtitle[1024];		       /* magic numbers are bad, but..  */
 
   if(!t)
     return;
   if(!(t->flags & TITLE))
     return;
@@ -745,22 +746,28 @@
     tGC = ShadowGC;
     ShadowGC = ReliefGC;
     ReliefGC = tGC;
   }
   flush_expose(t->title_w);
-  
-  if(t->name != (char *)NULL)
-  {
-    w=XTextWidth(GetDecor(t,WindowFont.font),t->name,strlen(t->name));
-    if(w > t->title_width-12)
-      w = t->title_width-4;
-    if(w < 0)
-      w = 0;
-  }
-  else
-    w = 0;
 
+   /* do a "neat" trimming of the title (i.e. trim on a char boundary) */
+   strcpy (wtitle, t->name);
+   nchars = 0;
+   if (w < 0)
+     w = 0;
+              
+   if(wtitle != (char *)NULL)
+     {
+	nchars = strlen (wtitle);
+	while ((w=XTextWidth(GetDecor(t,WindowFont.font),wtitle,nchars)) >=
+	       t->title_width-12 && nchars > 1 && w > 0)
+	  {
+	     nchars--;
+	     wtitle[nchars]='\0';
+	  }
+     }
+                                                           
   title_state = GetButtonState(t->title_w);
   tb_style = GetDecor(t,titlebar.state[title_state].style);
   tb_flags = GetDecor(t,titlebar.flags);
   if (tb_flags & HOffCenter) {
       if (tb_flags & HRight)
@@ -806,14 +813,14 @@
                    (PressedW==t->title_w?ShadowGC:ReliefGC),
                    hor_off - 2, 0, w+4,t->title_height);
       
     XDrawLine(dpy,t->title_w,ShadowGC,hor_off+w+1,0,hor_off+w+1,
               t->title_height);
-    if(t->name != (char *)NULL)
+    if(wtitle != (char *)NULL)
       XDrawString (dpy, t->title_w,Scr.ScratchGC3,hor_off,
                    GetDecor(t,WindowFont.y)+1, 
-                   t->name, strlen(t->name));
+                   wtitle, nchars);
   }
   else
   {
 #ifdef EXTENDED_TITLESTYLE
       ButtonFace *bf = &GetDecor(t,titlebar.state[title_state]);
@@ -843,11 +850,11 @@
       }
       
       if(t->name != (char *)NULL)
         XDrawString (dpy, t->title_w,Scr.ScratchGC3,hor_off,
                      GetDecor(t,WindowFont.y)+1, 
-                     t->name, strlen(t->name));
+                     wtitle, nchars);
   }
   /* now, draw lines in title bar if it's a sticky window */
   if(t->flags & STICKY)
   {
     for(i=0 ;i< t->title_height/2-3;i+=4)

--
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].