>>>>> "Jon" == Jon Mountjoy <jon_at_fwi.uva.nl> 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
*
* cwikla_at_uimrl7.mrl.uiuc.edu
*/
#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);
}
--
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 Sep 26 1995 - 08:39:11 BST