Subject: Custom Labels for Pager

From: Andreas Dischinger <[email-masked]>
Date: Wed, 24 Feb 1999 16:40:34 +0100 (CET)

Hi guys,

first of all: Good work, keep it rolling.

The enclosed patch adds formating for the labels in the pager. The
format is the same as in FvwmIconMan (%i for icon, %c for class, %r
for resource and %it for the window title). This change affects
ballons and the labels in the mini-windows.

This patch applies to 2.2. It although has a manpage-update.

The next thing I will try to integrate into the pager is a mechanism for
specifying different colors for different windows. Let's say, all
Gimp-Windows should have a red background inside the pager. I'm not
quiet sure if I should use a style options or specify it with a new
option for the Pager (something like
'*FvwmPagerWindowColor("patter",inactive,active,fore)')

So long,
	Andreas

-8<---------------------------------------------------------
diff -c -r fvwm-2.2.orig/modules/FvwmPager/FvwmPager.1 fvwm-2.2/modules/FvwmPager/FvwmPager.1
*** fvwm-2.2.orig/modules/FvwmPager/FvwmPager.1	Sat Dec 12 02:33:14 1998
--- fvwm-2.2/modules/FvwmPager/FvwmPager.1	Wed Feb 24 16:07:33 1999
***************
*** 170,175 ****
--- 170,181 ----
  Change the normal/highlight colors of the windows. \fIfore\fP and
  \fIhiFore\fP specify the colors as used for the font inside the windows.
  \fIback\fP and \fIhiBack\fP are used to fill the windows with.
+ 
+ .IP "*FvwmPagerWindowLabelFormat \fIformat\fP"
+ This specifies a printf() like format for the labels in the mini window.
+ Possible flags are: %t, %i, %c, and %r for the window's title, icon, class,
+ or resource name, respectively.  The default is "%i".
+ 
  .IP "*FvwmPagerLabel \fIdesk label\fP"
  Assigns the text \fIlabel\fP to desk \fIdesk\fP (or the current desk
  if desk is "*") in the pager window. Useful for assigning symbolic names
***************
*** 236,241 ****
--- 242,250 ----
  loop. Defaults to +2. The offset will change sign automatically, as needed,
  to keep the balloon on the screen.
  
+ .IP "*FvwmPagerBalloonStringFormat \fTformat\fP"
+ The same as \fI*FvwmPagerWindowLabelFormat\fP, it just specifies the string to
+ display in the balloons.
  
  .SH AUTHOR
  Robert Nation 
diff -c -r fvwm-2.2.orig/modules/FvwmPager/FvwmPager.c fvwm-2.2/modules/FvwmPager/FvwmPager.c
*** fvwm-2.2.orig/modules/FvwmPager/FvwmPager.c	Sun Jan 10 22:00:03 1999
--- fvwm-2.2/modules/FvwmPager/FvwmPager.c	Wed Feb 24 16:20:27 1999
***************
*** 70,75 ****
--- 70,76 ----
  char *WindowFore = NULL;
  char *WindowHiBack = NULL;
  char *WindowHiFore = NULL;
+ char *WindowLabelFormat = NULL;
  
  int ShowBalloons = 0, ShowPagerBalloons = 0, ShowIconBalloons = 0;
  char *BalloonTypeString = NULL;
***************
*** 77,82 ****
--- 78,84 ----
  char *BalloonFore = NULL;
  char *BalloonFont = NULL;
  char *BalloonBorderColor = NULL;
+ char *BalloonFormatString = NULL;
  int BalloonBorderWidth = 1;
  int BalloonYOffset = 2;
  
***************
*** 190,199 ****
--- 192,204 ----
  
    PagerFore = strdup("black");
    PagerBack = strdup("white");
+   WindowLabelFormat = strdup("%i");
    font_string = strdup("fixed");
    HilightC = strdup("black");
    BalloonFont = strdup("fixed");
    BalloonBorderColor = strdup("black");
+   BalloonTypeString = strdup("%i");
+   BalloonFormatString = strdup("%i");
    Desks = (DeskInfo *)safemalloc(ndesks*sizeof(DeskInfo));
    for(i=0;i<ndesks;i++)
      {
***************
*** 236,241 ****
--- 241,249 ----
                   M_ICONIFY|
  		 M_ICON_LOCATION|
  		 M_DEICONIFY|
+ 		 M_RES_NAME|
+ 		 M_RES_CLASS|
+ 		 M_WINDOW_NAME|
  		 M_ICON_NAME|
  		 M_CONFIG_INFO|
  		 M_END_CONFIG_INFO|
***************
*** 326,331 ****
--- 334,344 ----
      case M_DEICONIFY:
        list_deiconify(body);
        break;
+     case M_RES_CLASS:
+     case M_RES_NAME:
+     case M_WINDOW_NAME:
+       list_window_name(body,type);
+       break;
      case M_ICON_NAME:
        list_icon_name(body);
        break;
***************
*** 394,399 ****
--- 407,416 ----
    (*prev)->icon_view_width = 0;
    (*prev)->icon_view_height = 0;
    (*prev)->icon_name = NULL;
+   (*prev)->window_name = NULL;
+   (*prev)->res_name = NULL;
+   (*prev)->res_class = NULL;
+   (*prev)->window_label = NULL;
    (*prev)->mini_icon.picture = 0;
    (*prev)->title_height = body[9];
    (*prev)->border_width = body[10];
***************
*** 812,817 ****
--- 829,869 ----
  }

+ void list_window_name(unsigned long *body,unsigned long type)
+ {
+   PagerWindow *t;
+   Window target_w;
+ 
+   target_w = body[0];
+   t = Start;
+   while((t!= NULL)&&(t->w != target_w))
+     {
+       t = t->next;
+     }
+   if(t!= NULL)
+     {
+       switch (type) {
+       case M_RES_CLASS:
+         if(t->res_class != NULL)
+           free(t->res_class);
+         CopyString(&t->res_class,(char *)(&body[3]));
+         break;
+       case M_RES_NAME:
+         if(t->res_name != NULL)
+           free(t->res_name);
+         CopyString(&t->res_name,(char *)(&body[3]));
+         break;
+       case M_WINDOW_NAME:
+         if(t->window_name != NULL)
+           free(t->window_name);
+         CopyString(&t->window_name,(char *)(&body[3]));
+         break;
+       }
+       LabelWindow(t);
+       LabelIconWindow(t);
+     }
+ }
+ 
  /***********************************************************************
   *
   *  Procedure:
***************
*** 1235,1241 ****
  	      GetNextToken(tline2, &WindowHiBack);
  	    }
  	}
! 
  
        /* ... and get Balloon config options ...
           -- [email-masked] */
--- 1287,1298 ----
  	      GetNextToken(tline2, &WindowHiBack);
  	    }
  	}
!        else if (StrEquals(resource,"WindowLabelFormat"))
!          {
!            if (WindowLabelFormat)
!              free(WindowLabelFormat);
!            CopyString(&WindowLabelFormat,arg1);
!          }
  
        /* ... and get Balloon config options ...
           -- [email-masked] */
***************
*** 1307,1312 ****
--- 1364,1375 ----
  	{
  	  sscanf(arg1, "%d", &BalloonYOffset);
  	}
+       else if (StrEquals(resource,"BalloonStringFormat"))
+          {
+            if (BalloonFormatString)
+              free(BalloonFormatString);
+            CopyString(&BalloonFormatString,arg1);
+           }
  
        free(resource);
        free(arg1);
diff -c -r fvwm-2.2.orig/modules/FvwmPager/FvwmPager.h fvwm-2.2/modules/FvwmPager/FvwmPager.h
*** fvwm-2.2.orig/modules/FvwmPager/FvwmPager.h	Wed Dec  9 00:40:57 1998
--- fvwm-2.2/modules/FvwmPager/FvwmPager.h	Wed Feb 24 16:07:33 1999
***************
*** 55,60 ****
--- 55,64 ----
    Window icon_w;
    Window icon_pixmap_w;
    char *icon_name;
+   char *window_name;
+   char *res_name;
+   char *res_class;
+   char *window_label; /* This is displayed inside the mini window */
    Picture mini_icon;
    int pager_view_width;
    int pager_view_height;
***************
*** 73,78 ****
--- 77,83 ----
    Window w;              /* ID of balloon window */
    PagerWindow *pw;       /* pager window it's associated with */
    XFontStruct *font;
+   char *label;           /* the label displayed inside the balloon */
    int height;            /* height of balloon window based on font */
    int border;            /* border width */
    int yoffset;           /* pixels above (<0) or below (>0) pager win */
***************
*** 126,132 ****
  void list_unknown(unsigned long *body);
  void list_iconify(unsigned long *body);
  void list_deiconify(unsigned long *body);
! void list_window_name(unsigned long *body);
  void list_icon_name(unsigned long *body);
  void list_class(unsigned long *body);
  void list_res_name(unsigned long *body);
--- 131,137 ----
  void list_unknown(unsigned long *body);
  void list_iconify(unsigned long *body);
  void list_deiconify(unsigned long *body);
! void list_window_name(unsigned long *body,unsigned long type);
  void list_icon_name(unsigned long *body);
  void list_class(unsigned long *body);
  void list_res_name(unsigned long *body);
diff -c -r fvwm-2.2.orig/modules/FvwmPager/x_pager.c fvwm-2.2/modules/FvwmPager/x_pager.c
*** fvwm-2.2.orig/modules/FvwmPager/x_pager.c	Thu Jan 28 17:24:48 1999
--- fvwm-2.2/modules/FvwmPager/x_pager.c	Wed Feb 24 16:07:33 1999
***************
*** 35,40 ****
--- 35,42 ----
  extern int StartIconic;
  extern int MiniIcons;
  extern int ShowBalloons, ShowPagerBalloons, ShowIconBalloons;
+ extern char *BalloonFormatString;
+ extern char *WindowLabelFormat;
  
  extern int icon_w, icon_h, icon_x, icon_y;
  XFontStruct *font, *windowFont;
***************
*** 80,85 ****
--- 82,89 ----
  Window		icon_win;               /* icon window */
  BalloonWindow balloon;            /* balloon window */
  
+ static char *GetBalloonLabel(const PagerWindow *pw,const char *fmt);
+ 
  /***********************************************************************
   *
   *  Procedure:
***************
*** 1647,1657 ****
        XChangeGC(dpy, StdGC,Globalgcm,&Globalgcv);
  
      }
    if(t->PagerView != None)
      {
        XClearWindow(dpy, t->PagerView);
        XDrawString (dpy, t->PagerView,StdGC,2,windowFont->ascent+2 ,
! 			t->icon_name, strlen(t->icon_name));
      }
  }
  
--- 1651,1666 ----
        XChangeGC(dpy, StdGC,Globalgcm,&Globalgcv);
  
      }
+   { /* Update the window label for this window */
+     if (t->window_label)
+       free(t->window_label);
+     t->window_label = GetBalloonLabel(t,WindowLabelFormat);
+   }
    if(t->PagerView != None)
      {
        XClearWindow(dpy, t->PagerView);
        XDrawString (dpy, t->PagerView,StdGC,2,windowFont->ascent+2 ,
! 		        t->window_label, strlen(t->window_label));
      }
  }
  
***************
*** 1689,1697 ****
        XChangeGC(dpy,StdGC,Globalgcm,&Globalgcv);
  
      }
    XClearWindow(dpy, t->IconView);
    XDrawString (dpy, t->IconView,StdGC,2,windowFont->ascent+2 ,
! 	       t->icon_name, strlen(t->icon_name));
  
  }
  void PictureWindow (PagerWindow *t)
--- 1698,1711 ----
        XChangeGC(dpy,StdGC,Globalgcm,&Globalgcv);
  
      }
+   { /* Update the window label for this window */
+     if (t->window_label)
+       free(t->window_label);
+     t->window_label = GetBalloonLabel(t,WindowLabelFormat);
+   }
    XClearWindow(dpy, t->IconView);
    XDrawString (dpy, t->IconView,StdGC,2,windowFont->ascent+2 ,
! 	       t->window_label, strlen(t->window_label));
  
  }
  void PictureWindow (PagerWindow *t)
***************
*** 1962,1970 ****
    /* associate balloon with its pager window */
    balloon.pw = t;
  
!   /* calculate window width to accommodate string */
!   window_changes.width = 4 + XTextWidth(balloon.font, t->icon_name,
!                                         strlen(t->icon_name));
  
    /* get x and y coords relative to pager window */
    x = (view_width / 2) - (window_changes.width / 2) - balloon.border;
--- 1976,1990 ----
    /* associate balloon with its pager window */
    balloon.pw = t;
  
!   /* get the label for this balloon */
!   if (balloon.label)
!     free(balloon.label);
!   balloon.label = GetBalloonLabel(balloon.pw,BalloonFormatString);
! 
!   { /* calculate window width to accommodate string */
!     window_changes.width = 4 + XTextWidth(balloon.font,balloon.label,
!                                           strlen(balloon.label));
!   }
  
    /* get x and y coords relative to pager window */
    x = (view_width / 2) - (window_changes.width / 2) - balloon.border;
***************
*** 2021,2026 ****
--- 2041,2097 ----
  }

+ /* Generate the BallonLabel from the format string 
+    -- [email-masked] */
+ char *GetBalloonLabel(const PagerWindow *pw,const char *fmt)
+ {
+   char *dest = strdup("");
+   unsigned int allocSize = 0;
+   const unsigned int enlargeSize = 32;
+   const char *pos = fmt;
+   char buffer[2];
+ 
+   buffer[1] = '\0';
+ 
+ #define INSERT(s) while (strlen(s)+strlen(dest)+1>allocSize) { \
+                     dest = realloc(dest,allocSize+enlargeSize); \
+                     allocSize += enlargeSize; \
+                   } \
+                   strcat(dest,s)
+ 
+   while (*pos) {
+     if (*pos=='%' && *(pos+1)!='\0') {
+       pos++;
+       switch (*pos) {
+       case 'i':
+         INSERT(pw->icon_name);
+         break;
+       case 't':
+         INSERT(pw->window_name);
+         break;
+       case 'r':
+         INSERT(pw->res_name);
+         break;
+       case 'c':
+         INSERT(pw->res_class);
+         break;
+       case '%':
+         buffer[0] = '%';
+         INSERT(buffer);
+         break;
+       default:
+       }
+     } else {
+       buffer[0] = *pos;
+       INSERT(buffer);
+     }
+     pos++;
+   }
+ #undef INSERT
+   return dest;
+ }
+ 
+ 
  /* -- [email-masked] */
  void UnmapBalloonWindow (void)
  {
***************
*** 2040,2044 ****
  
    XDrawString(dpy, balloon.w, BalloonGC,
                2, balloon.font->ascent,
!               balloon.pw->icon_name, strlen(balloon.pw->icon_name));
  }
--- 2111,2115 ----
  
    XDrawString(dpy, balloon.w, BalloonGC,
                2, balloon.font->ascent,
!               balloon.label,strlen(balloon.label));
  }
-8<---------------------------------------------------------
-- 
   //|       |\\
  //||       ||\\         http://degnet.de/~awd/
 //=||       ||//         email: [email-masked]
//  ||ndreas |//ischinger PGP-Key by finger.

Sex is one of the nine reasons for reincarnation ... the other eight
are unimportant.
                -- Henry Miller

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