Subject: FVWM: Thanks Rob and Chuck, And how to compress XPM's

From: [email-masked] (Jon Mountjoy)
Date: Mon, 25 Sep 1995 19:12:19 +0100 (MET)

Hello All,

I would first like to thank Robert for all the work that he 
has put in.  We all appreciate it very much.  Secondly, I thank you
Chuck for all the work that you are about to do :-)

Other matters:

Some time ago somebody posted up a pointer to a program that could
supposedly compress the colours used in a number of XPM's.  Since I am
running out of colours, could somebody please point me to it?

Does anybody think that fvwm (.33) has a colour leak?

Thanks again.

Jon
--
To unsubscribe from the list, send "unsubscribe fvwm" in the body of a
message to [email-masked].
To report problems, send mail to [email-masked].

---

From: <[email-masked]> (Charles Hines)
Date: Tue, 26 Sep 1995 09:17:30 -0400

>>>>> "Jon" == Jon Mountjoy <[email-masked]> writes:

Jon> Hello All,
Jon> I would first like to thank Robert for all the work that he
Jon> has put in.  We all appreciate it very much.  Secondly, I thank you
Jon> Chuck for all the work that you are about to do :-)

;^)

Jon> Other matters:

Jon> Some time ago somebody posted up a pointer to a program that could
Jon> supposedly compress the colours used in a number of XPM's.  Since I am
Jon> running out of colours, could somebody please point me to it?

Actually, I'd like to put it in the distribution for the next release.
(Bruce, is that ok with you?)

Jon> Does anybody think that fvwm (.33) has a colour leak?

I don't think so, but I have seen pretty much all of my colours get
eaten from time to time.  I suspected other programs, but it might be
something in fvwm.  I'll keep my eyes open for it...

Chuck

*******************************************************************************
Charles K. Hines
IBM Logic Synthesis developer [BooleDozer (TM)]
and Martial Arts Instructor [Modern Arnis, Presas Style Filipino Martial Arts]

Internet e-mail:     [email-masked]

IBM Internal e-mail: [email-masked]   (preferred from workstation)
                     HINESC at FISHKILL       (preferred from mainframe)
                     HINESC at FSHVMFK1       (discouraged, but I'll get it)

*******************************************************************************
 "dis ting could have possabiwities if I put my twisted widdle mind to it!"
                                                        - Bugs Bunny

 "I have a paper plate in my head because they were all out of the metal ones"
                                                        - Rick Overton
*******************************************************************************
--
To unsubscribe from the list, send "unsubscribe fvwm" in the body of a
message to [email-masked].
To report problems, send mail to [email-masked].

---

From: <[email-masked]> (Charles Hines)
Date: Tue, 26 Sep 1995 09:42:21 -0400

>>>>> "Jon" == Jon Mountjoy <[email-masked]> writes:

Jon> Hello Chuck,
Jon> | Actually, I'd like to put it in the distribution for the next release.
Jon> | (Bruce, is that ok with you?)

Jon> Thanks for the info.  Would it be possible for me to grab it now so
Jon> that I can play?

Sure.  The easiest way to get it would be from the author's home page:

http://supr.scm.liv.ac.uk/~bruce

Jon> | I don't think so, but I have seen pretty much all of my colours get
Jon> | eaten from time to time.  I suspected other programs, but it might be
Jon> | something in fvwm.  I'll keep my eyes open for it...

Jon> Yes.  I just have a niggling feeling because sometimes I can view
Jon> a PS file on my X terminal without a problem.  After some hours
Jon> work, and quitting all applications, I find that the viewer is no
Jon> longer able to allocate the colours.  Well so it seems.  It is
Jon> sporadic and hard to reproduce, though I will try :-) Is there
Jon> any nice way to debug and find out how many colours are allocated
Jon> at any time?

I found this little program 'xcolormap' that shows the colormap, and I
added some code to it that if you click on it w/ button 1, it puts the
number of free colors in the title.  It's pretty handy for this sort
of thing.  I've included it below, and I copied the fvwm list in case
anyone else wants it.

Chuck

--------------->8 'xcolormap.c' cut here 8<---------------
/*
 * Copyright 1991 John L. Cwikla
 *
 * Permission to use, copy, modify, distribute, and sell this software
 * and its documentation for any purpose is hereby granted without fee,
 * provided that the above copyright notice appears in all copies and that
 * both that copyright notice and this permission notice appear in
 * supporting documentation, and that the name of John L. Cwikla or
 * University of Illinois not be used in advertising or publicity
 * pertaining to distribution of the software without specific, written
 * prior permission.  John L. Cwikla and University of Illinois make no
 * representations about the suitability of this software for any
 * purpose.  It is provided "as is" without express or implied warranty.
 *
 * John L. Cwikla and University of Illinois disclaim all warranties with
 * regard to this software, including all implied warranties of
 * merchantability and fitness, in no event shall John L. Cwikla or
 * University of Illinois be liable for any special, indirect or
 * consequential damages or any damages whatsoever resulting from loss of
 * use, data or profits, whether in an action of contract, negligence or
 * other tortious action, arising out of or in connection with the use or
 * performance of this software.
 *
 * Author:
 *      John L. Cwikla
 *      Materials Research Laboratory Center for Computation
 *      University Of Illinois at Urbana-Champaign
 *      104 S. Goodwin
 *      Urbana, IL 61801
 *
 *      [email-masked]
*/

#include <X11/IntrinsicP.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Shell.h>
#include <X11/Core.h>

#include <stdio.h>
#include <math.h>

#define APPNAME "XColormap"

#ifdef ULONG_NEEDED
typedef unsigned long ulong;
#endif

static Display *TheDisplay;
static GC TheGC;

static ulong NumColors;
static ulong Width = 10; /* Of the squares */
static ulong Height = 10; /* Of the squares */
static ulong Margin = 2; /* space between squares */
static ulong Xcolor, Ycolor; /* Number of colors per direction in the matrix */
static int TheScreenNo;

XtAppContext app;

static void DrawSquare(Drawable d, int i)
{
  int row, col, x, y;

  row = i / Xcolor;
  col = i % Xcolor;

  x = (Width + Margin) * col + Margin;
  y = (Height + Margin) * row + Margin;

  XSetForeground(TheDisplay, TheGC, i);
  XFillRectangle(TheDisplay, d, TheGC, x, y,
    Width, Height);
}

static void RedrawWindow(Drawable d)
{
  int i;
  for(i=0;i<NumColors;i++)
    DrawSquare(d, i);
}

static void Redraw(Widget w,XtPointer client_data, XEvent *event,
                   Boolean *continue_to_dispatch)
{
  RedrawWindow(XtWindow(w));
}

static void Resize(Widget wid,XtPointer client_data, XEvent *event,
                   Boolean *continue_to_dispatch)
{
  Width = (wid->core.width - Margin)/Xcolor - Margin;
  Height = (wid->core.height - Margin)/Xcolor - Margin;
  XClearWindow(TheDisplay, XtWindow(wid));
  Redraw(wid,client_data,event,continue_to_dispatch);
}

static void ResetTitle(XtPointer client_data,XtIntervalId *id)
{
  XtVaSetValues(XtParent((Widget)client_data),
                XtNtitle,"XColormap",
                NULL);
  XtRemoveTimeOut(*id);
}

static void ShowFreeColors(Display *disp, Widget w)
{
  int num_colors=256;
  unsigned long plane_mask[1];
  unsigned long colors[256];
  Colormap cmap;
  char title[128];

  cmap = DefaultColormapOfScreen(DefaultScreenOfDisplay(disp));
/*  printf("[xcolormap]: calculating free colors....\n"); */
  while(0==XAllocColorCells(disp,
                            cmap,
                            False,
                            plane_mask,
                            0,
                            colors,
                            num_colors))
  {
    num_colors--;
  }
/*  printf("[xcolormap]: free colors = %d\n",num_colors); */
  XFreeColors(disp,
              cmap,
              colors,
              num_colors,
              0);
  sprintf(title,"XColormap: %d free",num_colors);
  XtVaSetValues(XtParent(w),
                XtNtitle,title,
                NULL);
  XtAppAddTimeOut(app,1000,ResetTitle,w);
}

static void QuitOrShowFree(Widget w,XtPointer client_data, XEvent *event,
                           Boolean *continue_to_dispatch)
{
  if (event->type != ButtonPress)
    return;
  switch(((XButtonPressedEvent *)event)->button)
  {
    case Button1:
      ShowFreeColors(XtDisplay(w),w);
      break;
    default:
      exit(0);
      break;
  }
}

main(int argc, char *argv[])
{
  Widget colorwidget, toplevel;
  Arg warg[2];
  int n;
  ulong xWindowWidth, yWindowHeight;

  XtToolkitInitialize();
  app = XtCreateApplicationContext();

  TheDisplay = XtOpenDisplay (app, NULL, APPNAME, APPNAME,
    NULL, 0, &argc, argv);

  if (!TheDisplay)
  {
#ifdef ORIGINAL
        XtWarning ("%s: can't open display, exiting...", APPNAME);
#else
        XtWarning ("xcolormap: can't open display, exiting...");
#endif
        exit (0);
  }

  TheScreenNo = DefaultScreen(TheDisplay);
  NumColors = XDisplayCells(TheDisplay, TheScreenNo);
  Xcolor = (int)floor(sqrt(NumColors)); /* Best try at a square */
  Ycolor = NumColors/Xcolor;

  if ((argc == 2) && (!strncmp(argv[1], "-root", 5)))
  {
      Drawable TheWindow;
      Pixmap ThePixmap;
      xWindowWidth = DisplayWidth(TheDisplay, TheScreenNo);
      yWindowHeight = DisplayHeight(TheDisplay, TheScreenNo);
      Width = (xWindowWidth - Margin)/Xcolor - Margin;
      Height = (yWindowHeight - Margin)/Xcolor - Margin;
/*      printf("Display is %d x %d.\n", xWindowWidth, yWindowHeight); */
      TheWindow = RootWindow(TheDisplay, TheScreenNo);
      ThePixmap = XCreatePixmap(TheDisplay, TheWindow,
        xWindowWidth, yWindowHeight, DefaultDepth(TheDisplay, TheScreenNo));
      TheGC = XCreateGC(TheDisplay, TheWindow, NULL, 0);
      RedrawWindow(ThePixmap);
      XSetWindowBackgroundPixmap(TheDisplay, TheWindow,
        ThePixmap);
      XClearWindow(TheDisplay, TheWindow);
      while(XtAppPending(app))
      {
        XEvent event;
        XtAppNextEvent(app, &event);
        XtDispatchEvent(&event);
      }
      XFreeGC(TheDisplay, TheGC);
      XFreePixmap(TheDisplay, ThePixmap);
      exit(0);
  }

  colorwidget = XtAppCreateShell (APPNAME, APPNAME,
                applicationShellWidgetClass, TheDisplay, NULL, 0);
  xWindowWidth = Xcolor * (Width + Margin) + Margin; /* Actual window width */
  yWindowHeight = Ycolor * (Height + Margin) + Margin; /* Actual window height */

  n = 0;
  XtSetArg(warg[n], XtNwidth, xWindowWidth); n++;
  XtSetArg(warg[n], XtNheight, yWindowHeight); n++;
  toplevel = XtCreateManagedWidget("TopLevel", widgetClass,
        colorwidget, warg, n);

  XtRealizeWidget(colorwidget);
  XtAddEventHandler(toplevel, ButtonPressMask, FALSE, QuitOrShowFree, NULL);
  XtAddEventHandler(toplevel, ExposureMask, FALSE, Redraw, NULL);
  XtAddEventHandler(toplevel, StructureNotifyMask, FALSE, Resize, NULL);

  TheGC = XCreateGC(TheDisplay, XtWindow(toplevel), NULL, 0);

  XtAppMainLoop(app);
}

---

From: BENJAMIN THOMAS KETTERIDGE <[email-masked]>
Date: Tue, 26 Sep 1995 14:56:34 +0100

>(Bruce, is that ok with you?)
This would be a good idea. Though displays that require this are getting
less common 'round here, they're still there - especially on people's
personal desktop machines. :-(

>something in fvwm.  I'll keep my eyes open for it...
Ah, the joys of 24-bit colour (Sun Sparc 5) workstation displays! ;-)

Ben.

| URL=http://www.dcs.aber.ac.uk/~btk/ | email=[email-masked] | _|--|_   o   |
+-------------------------------------+----------------------+  (\/)  +---+ |
|  Tel: (01970) 622403 [Int: 2403]    |  or: (01970) 627842  |   vv    / \  |
--
To unsubscribe from the list, send "unsubscribe fvwm" in the body of a
message to [email-masked].
To report problems, send mail to [email-masked].

---

From: Eric Ding <[email-masked]>
Date: Tue, 26 Sep 1995 11:08:02 -0700

Hi Jon,

I believe you'll find it at:

> <URL:http://supr.scm.liv.ac.uk/~bruce> and makes an attempt at
> transparent xpms, but may fail.  You need netpbm or equivalent.

Eric
--                                         |
1601 Technology Drive                     -*- [email-masked]
San Jose, CA 95110-1397                    |          PHONE: (408) 437-5068
http://web.mit.edu/ericding/www/home.html  |            FAX: (408) 437-5246
--
To unsubscribe from the list, send "unsubscribe fvwm" in the body of a
message to [email-masked].
To report problems, send mail to [email-masked].

---

From: [email-masked] (Jon Mountjoy)
Date: Tue, 26 Sep 1995 20:10:03 +0100 (MET)

Hi Chuck,

Thanks for the modified xcolormap.  It works like a charm except for when
the colourmap is about full, at which time it dumps with the message:

X Error of failed request:  BadValue (integer parameter out of range for operation)
  Major opcode of failed request:  86 (X_AllocColorCells)
  Value in failed request:  0x0
  Serial number of failed request:  5520
  Current serial number in output stream:  5520

when one pushes the left mouse button.

Using this program, I was able to track down my colour leaks though.
After startup I have about 203 colours free.  Instantiating netscape
I have about 130 free.  Destroying netscape restores my count to 203. The
same happens for various other programs.  Ghostview, xview etc. etc.
I can run a program, and after exit my colourmap is back to 203. 

BUT, this does not happen with the latest release of xdvi.  After I 
run it, and exit, the colourmap program reports about 120 colours free.
And they don't come back.

My question is then this:

[1]  Whose responsibility is it to retrieve those colours? 
 			ie.
[2]  Is it xdvi's fault, or fvwm's fault?

Jon