FVWM: Patch: balloon help for Pager

From: Richard Lister <ric_at_giccs.georgetown.edu>
Date: Tue, 26 Aug 1997 19:49:02 -0400

Hi folks

The other day I was mucking around with 4Dwm on Irix 6.3, and the
Desks Overview (their pager) had a nice little feature. When you point
at a window in the pager it pops up a little help balloon with the icon
title of the window.

I like this because I keep the pager small and can't use normal labels
or even MiniIcons in such tiny windows.

So I knocked up a little patch to do the same for FvwmPager. I've
included it below.

'patch < file' it in the fvwm-2.0.46 source directory,
read the man page, and add something like this to your config:

    *FvwmPagerBalloons
    *FvwmPagerBalloonBack Yellow
    *FvwmPagerBalloonFore Black
    *FvwmPagerBalloonFont lucidasanstypewriter-12

I've only tested on Linux/X11R6 so far.


If you go to

    http://www.giccs.georgetown.edu/~ric/software/fvwm/pager.html

you can also get a screenshot and the FvwmPager directory as a tarball.

Comments and suggestions welcome.

Ric

Richard J Lister, Georgetown Institute for Cognitive and Computational Sciences
Georgetown University Medical Center, Washington, DC.
Phone: 202-687 2878
Email: ric_at_giccs.georgetown.edu
Web: http://www.giccs.georgetown.edu/


------------------------------cut here for patch--------------------------
diff -u modules/FvwmPager.orig/FvwmPager.c modules/FvwmPager/FvwmPager.c
--- modules/FvwmPager.orig/FvwmPager.c Tue Aug 26 18:46:54 1997
+++ modules/FvwmPager/FvwmPager.c Tue Aug 26 18:50:59 1997
_at_@ -68,6 +68,11 @@
 char *WindowHiBack = NULL;
 char *WindowHiFore = NULL;
 
+int ShowBalloons = 0;
+char *BalloonBack = NULL;
+char *BalloonFore = NULL;
+char *BalloonFont = "fixed";
+
 int window_w=0, window_h=0, window_x=0, window_y=0;
 int icon_x=-10000, icon_y=-10000, icon_w=0, icon_h=0;
 int usposition = 0,uselabel = 1;
_at_@ -1060,6 +1065,36 @@
                         colors = GetNextToken (colors, &WindowHiBack);
                 }
         }
+
+
+ /* ... and get Balloon config options ...
+ -- ric_at_giccs.georgetown.edu */
+ else if ( (strlen(&tline[0]) > 1) &&
+ (strncasecmp (tline, CatString3 ("*", MyName, "Balloons"),
+ Clength + 9) == 0) ) {
+ ShowBalloons = 1;
+ }
+
+ else if ( (strlen(&tline[0]) > 1) &&
+ (strncasecmp (tline, CatString3 ("*", MyName, "BalloonBack"),
+ Clength + 12) == 0) ) {
+ if (Scr.d_depth > 1)
+ CopyString(&BalloonBack, &tline[Clength+12]);
+ }
+
+ else if ( (strlen(&tline[0]) > 1) &&
+ (strncasecmp (tline, CatString3 ("*", MyName, "BalloonFore"),
+ Clength + 12) == 0) ) {
+ if (Scr.d_depth > 1)
+ CopyString(&BalloonFore, &tline[Clength+12]);
+ }
+
+ else if ( (strlen(&tline[0]) > 1) &&
+ (strncasecmp (tline, CatString3 ("*", MyName, "BalloonFont"),
+ Clength + 12) == 0) ) {
+ CopyString(&BalloonFont, &tline[Clength+12]);
+ }
+
       GetConfigLine(fd,&tline);
     }
   return;
diff -u modules/FvwmPager.orig/FvwmPager.h modules/FvwmPager/FvwmPager.h
--- modules/FvwmPager.orig/FvwmPager.h Tue Aug 26 18:46:55 1997
+++ modules/FvwmPager/FvwmPager.h Tue Aug 26 18:50:59 1997
_at_@ -68,6 +68,14 @@
 } PagerWindow;
 
 
+typedef struct balloon_window
+{
+ Window w; /* ID of balloon window */
+ PagerWindow *pw; /* pager window it's associated with */
+ XFontStruct *font;
+} BalloonWindow;
+
+
 typedef struct desk_info
 {
   Window w;
_at_@ -144,6 +152,10 @@
 void IconMoveWindow(XEvent *Event,PagerWindow *t);
 void HandleExpose(XEvent *Event);
 void MoveStickyWindows(void);
+void MapBalloonWindow(XEvent *);
+void UnmapBalloonWindow(void);
+void DrawInBalloonWindow(void);
+
 #ifdef BROKEN_SUN_HEADERS
 #include "../../fvwm/sun_headers.h"
 #endif
diff -u modules/FvwmPager.orig/FvwmPager.man modules/FvwmPager/FvwmPager.man
--- modules/FvwmPager.orig/FvwmPager.man Tue Aug 26 18:46:55 1997
+++ modules/FvwmPager/FvwmPager.man Tue Aug 26 18:50:59 1997
_at_@ -181,10 +181,28 @@
 Allow the pager to display a window's mini icon in the pager, if it has
 one, instead of showing the window's name.
 
+.IP "*FvwmPagerBalloons"
+Show a balloon describing the window when the pointer is moved into
+a window in the pager. Currently only the window's icon name is shown.
+Note that balloons are not shown for the iconified pager.
+
+.IP "*FvwmPagerBalloonFore \fIcolor\fP"
+Specifies the color for text in the balloon window. If omitted it
+defaults to the foreground color for the window being described.
+
+.IP "*FvwmPagerBalloonBack \fIcolor\fP"
+Specifies the background color for the balloon window. If omitted it
+defaults to the background color for the window being described.
+
+.IP "*FvwmPagerBalloonFont \fIfont-name\fP"
+Specifies a font to use for the balloon text.
+
+
 .SH AUTHOR
 Robert Nation
 .br
 DeskColor patch contributed by Alan Wild
 .br
 MiniIcons and WindowColors patch contributed by Rob Whapham
-
+.br
+Balloons patch contributed by Ric Lister <ric_at_giccs.georgetown.edu>
diff -u modules/FvwmPager.orig/Makefile modules/FvwmPager/Makefile
--- modules/FvwmPager.orig/Makefile Tue Aug 26 18:46:55 1997
+++ modules/FvwmPager/Makefile Tue Aug 26 18:50:59 1997
_at_@ -578,6 +578,7 @@
 FvwmPager: $(OBJS) $(DEPLIBS)
         $(RM) $_at_
         $(CC) -o $_at_ $(OBJS) $(LDOPTIONS) $(LOCAL_LIBRARIES) $(LDLIBS) $(EXTRA_LOAD_FLAGS)
+# _at_mv FvwmPager /home/cns/ric/lib/fvwm/modules/.
 
 install:: FvwmPager
         _at_if [ -d $(DESTDIR)$(FVWMDIR) ]; then set +x; \
diff -u modules/FvwmPager.orig/x_pager.c modules/FvwmPager/x_pager.c
--- modules/FvwmPager.orig/x_pager.c Tue Aug 26 18:46:55 1997
+++ modules/FvwmPager/x_pager.c Tue Aug 26 18:50:59 1997
_at_@ -33,12 +33,15 @@
 extern int window_w, window_h,window_x,window_y,usposition,uselabel,xneg,yneg;
 extern int StartIconic;
 extern int MiniIcons;
+extern int ShowBalloons;
+
 extern int icon_w, icon_h, icon_x, icon_y;
 XFontStruct *font, *windowFont;
 
 GC NormalGC,DashedGC,HiliteGC,rvGC;
 GC StdGC;
 GC MiniIconGC;
+GC BalloonGC;
 
 extern PagerWindow *Start;
 extern PagerWindow *FocusWin;
_at_@ -74,6 +77,7 @@
 
 
 Window icon_win; /* icon window */
+BalloonWindow balloon; /* balloon window */
 
 /***********************************************************************
  *
_at_@ -107,6 +111,7 @@
   XSetWindowAttributes attributes;
   extern char *PagerFore, *PagerBack, *HilightC;
   extern char *WindowBack, *WindowFore, *WindowHiBack, *WindowHiFore;
+ extern char *BalloonFore, *BalloonBack, *BalloonFont;
   extern char *font_string, *smallFont;
   int n,m,w,h,i,x,y;
   XGCValues gcv;
_at_@ -402,6 +407,50 @@
   gcv.background = back_pix;
   gcv.line_style = LineOnOffDash;
   DashedGC = XCreateGC(dpy, Scr.Root, gcm, &gcv);
+
+
+ /* create balloon window
+ -- ric_at_giccs.georgetown.edu */
+ if ( ShowBalloons ) {
+
+ /* tell WM to ignore this window */
+ attributes.override_redirect = True;
+
+ attributes.event_mask = ExposureMask;
+
+ /* if given in config set this now, otherwise it'll be set for each
+ pager window when drawn later */
+ attributes.background_pixel =
+ (BalloonBack == NULL) ? 0 : GetColor(BalloonBack);
+
+ /* get font for balloon */
+ if ( (balloon.font = XLoadQueryFont(dpy, BalloonFont)) == NULL ) {
+ if ( (balloon.font = XLoadQueryFont(dpy, "fixed")) == NULL ) {
+ fprintf(stderr,"%s: No fonts available.\n", MyName);
+ exit(1);
+ }
+ fprintf(stderr, "%s: Can't find font '%s', using fixed.\n",
+ MyName, BalloonFont);
+ }
+
+ balloon.w = XCreateWindow(dpy, Scr.Root,
+ 0, 0, /* coords set later */
+ 1, /* width set later */
+ balloon.font->ascent + balloon.font->descent + 1,
+ 1, /* border */
+ CopyFromParent,
+ InputOutput,
+ CopyFromParent,
+ CWOverrideRedirect | CWEventMask | CWBackPixel,
+ &attributes);
+
+ /* make gc for balloon */
+ gcv.font = balloon.font->fid;
+
+ BalloonGC = XCreateGC(dpy, balloon.w,
+ GCFont,
+ &gcv);
+ } /* ShowBalloons */
 }
 
 
_at_@ -449,6 +498,14 @@
 
   switch(Event->xany.type)
     {
+ case EnterNotify:
+ if ( ShowBalloons )
+ MapBalloonWindow(Event);
+ break;
+ case LeaveNotify:
+ if ( ShowBalloons )
+ UnmapBalloonWindow();
+ break;
     case ConfigureNotify:
       ReConfigure();
       break;
_at_@ -556,6 +613,12 @@
   int i;
   PagerWindow *t;
 
+ /* ric_at_giccs.georgetown.edu */
+ if ( Event->xany.window == balloon.w ) {
+ DrawInBalloonWindow();
+ return;
+ }
+
   for(i=0;i<ndesks;i++)
     {
       if((Event->xany.window == Desks[i].w)
_at_@ -953,6 +1016,10 @@
   attributes.border_pixel = fore_pix;
   attributes.event_mask = (ExposureMask);
 
+ /* ric_at_giccs.georgetown.edu -- added Enter and Leave events for
+ popping up balloon window */
+ attributes.event_mask = (ExposureMask | EnterWindowMask | LeaveWindowMask);
+
   if((i >= 0)&& (i <ndesks))
     {
       t->PagerView = XCreateWindow(dpy,Desks[i].w, x, y, w, h,1,
_at_@ -1804,4 +1871,72 @@
         XSetInputFocus (dpy, t->w, RevertToParent, Event->xbutton.time);
     }
 
+}
+
+
+/* Just maps window ... draw stuff in it later after Expose event
+ -- ric_at_giccs.georgetown.edu */
+void MapBalloonWindow (XEvent *event)
+{
+ PagerWindow *t;
+ Window *dummy;
+ XWindowChanges window_changes;
+ extern char *BalloonBack;
+
+ /* is this the best way to match X event window ID to PagerWindow ID? */
+ t = Start;
+
+ while ( (t != NULL) && (t->PagerView != event->xcrossing.window) )
+ t = t->next;
+
+ if (t == NULL)
+ return;
+
+ /* associate balloon with its pager window */
+ balloon.pw = t;
+
+ /* balloon is a top-level window, therefore need to
+ translate pager window coords to root window coords */
+ XTranslateCoordinates(dpy, t->PagerView, Scr.Root,
+ t->pager_view_width / 2,
+ t->pager_view_height + 5,
+ &window_changes.x, &window_changes.y,
+ dummy);
+
+ /* change window width to accomodate string */
+ window_changes.width = 4 + XTextWidth(balloon.font, t->icon_name,
+ strlen(t->icon_name));
+ XConfigureWindow(dpy, balloon.w,
+ CWX | CWY | CWWidth,
+ &window_changes);
+
+ /* if background not set in config make it match pager window */
+ if ( BalloonBack == NULL )
+ XSetWindowBackground(dpy, balloon.w, balloon.pw->back);
+
+
+ XMapRaised(dpy, balloon.w);
+}
+
+
+/* -- ric_at_giccs.georgetown.edu */
+void UnmapBalloonWindow (void)
+{
+ XUnmapWindow(dpy, balloon.w);
+}
+
+
+/* Draws string in balloon window -- call after it's received Expose event
+ -- ric_at_giccs.georgetown.edu */
+void DrawInBalloonWindow (void)
+{
+ extern char *BalloonFore;
+
+ /* if foreground not set in config make it match pager window */
+ if ( BalloonFore == NULL )
+ XSetForeground(dpy, BalloonGC, balloon.pw->text);
+
+ XDrawString(dpy, balloon.w, BalloonGC,
+ 2, balloon.font->ascent,
+ balloon.pw->icon_name, strlen(balloon.pw->icon_name));
 }
--
Visit the official FVWM web page at <URL:http://www.hpc.uh.edu/fvwm/>.
To unsubscribe from the list, send "unsubscribe fvwm" in the body of a
message to majordomo_at_hpc.uh.edu.
To report problems, send mail to fvwm-owner_at_hpc.uh.edu.
Received on Tue Aug 26 1997 - 18:48:17 BST

This archive was generated by hypermail 2.3.0 : Mon Aug 29 2016 - 19:38:00 BST