From Newsgroup: comp.windows.x
First of all, a fair warning: the license for xbattle is confusing:
README> COPYRIGHT
README> Copied from the GNU Emacs 'copyleft' policy. Basically, you
README> are free to copy, modify and distribute this program as long
README> as you do not sell it or use it in a product that you sell.
The "do not sell" restriction would make this software fail the
FSF free software criteria, but at the same time, the license
text itself mentions no such restrictions. It goes on to state:
README> c) You may charge a distribution fee for the physical act of
README> transferring a copy, and you may at your option offer warranty
README> protection in exchange for a fee.
Now, unlike many free software enthusiasts, I do not consider
the /use/ of (possibly, in this case) non-free software to be
an ethical issue per se, but endorsing it is clearly questionable
in that department.
So there.
Now, there're two issues with xbattle 4.0 as shipped (e. g.,
http://ftp.gwdg.de/pub/x11/x.org/R5contrib/xbattle-4.0.tar.Z ):
a. main.c seems to misuse XSetIOErrorHandler and FD_SET in main,
and also XLookupString and XDrawImageString in process_event;
I have a straightforward patch from 2002 (below) fixing that;
b. it checks if the display supports a 8 bits per pixel PseudoColor
visual, and uses monochrome if that's not the case; this is where
I had to get creative.
What I've used for b. is: a. add new bw_p field to xwindow_type
in extern.h; b. make it used consistently in the code in place
of xwindow->depth tests; c. replaced the initial tests like:
- if(xwindow->depth != 8)
- {
- if (XMatchVisualInfo(xwindow->display, xwindow->screen, 8, PseudoColor, &vinfo))
- {
- visual = vinfo.visual;
- xwindow->depth = 8;
- }
+ if (xwindow->depth == 8) {
+ xwindow->bw_p = 0;
+ } else if (XMatchVisualInfo (xwindow->display, xwindow->screen,
+ 8, PseudoColor, &vinfo)
+ || XMatchVisualInfo (xwindow->display, xwindow->screen,
+ 15, TrueColor, &vinfo)
+ || /* ... and so on... */
So far I'm testing for PseudoColor at depth 8, and TrueColor
visuals at depths 15, 16, 24, 32.
And the question is: what's an easy way to check for a TrueColor
(PseudoColor) visual having /at least/ a given depth?
TIA. The diffs follow.
--- xbattle-4.0/main.c 1992-09-27 16:52:19 +0000
+++ xbattle-4.0/main.c 2002-03-26 09:06:18 +0000
@@ -155,7 +155,7 @@ main(argc,argv)
/************* main event loop *************/
#if UNIX
- XSetIOErrorHandler(1);
+ /* XSetIOErrorHandler(1); */
gettimeofday (&tp_old, &tzp);
oldtime = (tp_old.tv_sec%10000)*1000000 + tp_old.tv_usec;
targettime = oldtime + (delay/10000)*1000000 + (delay%10000)*100;
@@ -207,7 +207,8 @@ main(argc,argv)
{
if (winopen[i])
{
- if (FD_SET(fd = ConnectionNumber(xwindow[i]->display), &rfds))
+ fd = ConnectionNumber(xwindow[i]->display);
+ if (FD_ISSET(fd, &rfds))
{
while (winopen[i] &&
XEventsQueued(xwindow[i]->display, QueuedAfterReading) > 0)
@@ -543,7 +544,7 @@ process_event(event,board,colorarray,pla
/**** process key press events ****/
case KeyPress:
- textcount = XLookupString(&event, text, 10, &key, NULL);
+ textcount = XLookupString(&(event.xkey), text, 10, &key, NULL);
if (textcount != 0)
{
if ((enable_hex && (event.xbutton.y < boardsizey*2*hex_vert + hex_vert)) ||
@@ -1208,7 +1209,7 @@ replaygame(squaresize,board)
for (l=0; l<nsides; l++)
XDrawImageString(xwindow[k]->display,xwindow[k]->window,
xwindow[k]->hue[light],
- TEXTX,textyh[l],
+ TEXTX,*(textyh[l]),
messagestr,strlen(messagestr));
#else
XDrawImageString(xwindow[k]->display,xwindow[k]->window,
--- xbattle-4.0-build/draw.c.~1~ 1992-09-27 16:52:24 +0000
+++ xbattle-4.0-build/draw.c 2026-01-24 19:28:30 +0000
@@ -342,8 +342,8 @@ drawsquare(xwindow,square,windowcolor,sq
else
{
onhue = xwindow->hue[square->color];
- if ((xwindow->depth==1 && color2bw[sidemap[square->color]]<=GRAY3) ||
- (xwindow->depth==8 && sidemap[square->color]==BLACK))
+ if (xwindow->bw_p ? color2bw[sidemap[square->color]]<=GRAY3
+ : sidemap[square->color]==BLACK)
offhue = xwindow->hue[light];
else
offhue = xwindow->hue[dark];
--- xbattle-4.0-build/extern.h.~1~ 1992-09-27 16:52:24 +0000
+++ xbattle-5.0-build/extern.h 2026-01-24 19:17:38 +0000
@@ -103,7 +103,7 @@ typedef struct{
int xsize,ysize;
XSizeHints hint;
XWMHints xwmh;
- int depth,screen;
+ int bw_p,depth,screen;
GC hue[MAXSIDES+3], flip, gc_clear, gc_or;
Pixmap terrain[NHILLTONES];
XFontStruct *font_struct;
--- xbattle-4.0-build/utils.c.~1~ 1992-09-27 16:52:33 +0000
+++ xbattle-4.0-build/utils.c 2026-01-25 11:13:16 +0000
@@ -1,4 +1,6 @@
#include <stdio.h>
+#include <string.h>
+#include <time.h>
/**** x include files ****/
#include <X11/Xlib.h>
@@ -74,20 +76,27 @@ open_xwindow(xwindow,displayname,xpos,yp
visual = DefaultVisual(xwindow->display,xwindow->screen);
- if(xwindow->depth != 8)
- {
- if (XMatchVisualInfo(xwindow->display, xwindow->screen, 8, PseudoColor, &vinfo))
- {
- visual = vinfo.visual;
- xwindow->depth = 8;
- }
+ /** FIXME: add a command line option for black and white rendering */
+ if (xwindow->depth == 8) {
+ xwindow->bw_p = 0;
+ } else if (XMatchVisualInfo (xwindow->display, xwindow->screen,
+ 8, PseudoColor, &vinfo)
+ /** FIXME: is this still a sensible approach? */
+ || XMatchVisualInfo (xwindow->display, xwindow->screen,
+ 15, TrueColor, &vinfo)
+ || XMatchVisualInfo (xwindow->display, xwindow->screen,
+ 16, TrueColor, &vinfo)
+ || XMatchVisualInfo (xwindow->display, xwindow->screen,
+ 24, TrueColor, &vinfo)
+ || XMatchVisualInfo (xwindow->display, xwindow->screen,
+ 32, TrueColor, &vinfo)) {
+ visual = vinfo.visual;
+ xwindow->bw_p = 0;
+ } else {
+ xwindow->bw_p = 1;
}
- if (xwindow->depth != 8)
- xwindow->depth = 1;
-
- if(xwindow->depth == 8)
- {
+ if (! xwindow->bw_p) {
/**** create color map using visual ****/
#if NEWCOLORMAP
xwindow->cmap = XCreateColormap(xwindow->display,
@@ -123,11 +132,10 @@ open_xwindow(xwindow,displayname,xpos,yp
}
/**** get standard properties for window manager ****/
- if (xwindow->depth == 8)
+ if (! xwindow->bw_p)
XSetStandardProperties(xwindow->display, xwindow->window, htitle, htitle,
None, NULL, None, &xwindow->hint);
- else if (xwindow->depth == 1)
- {
+ else {
XSetStandardProperties(xwindow->display, xwindow->window, gtitle, gtitle,
None, NULL, None, &xwindow->hint);
}
@@ -142,8 +150,7 @@ open_xwindow(xwindow,displayname,xpos,yp
XSelectInput(xwindow->display, xwindow->window, eventmask);
/**** load color map ****/
- if(xwindow->depth == 8)
- {
+ if(! xwindow->bw_p) {
for (i=0 ; i<MAXCOLORS ; i++)
{
xwindow->xcolor[i].flags = 0;
@@ -307,8 +314,7 @@ open_xwindow(xwindow,displayname,xpos,yp
XSetFunction(xwindow->display, xwindow->flip, GXinvert);
/**** set drawing colors ****/
- if (xwindow->depth == 1)
- {
+ if (xwindow->bw_p) {
for (j=0; j<nsides; j++) {
if (color2bw[sidemap[j]] == WHITE)
@@ -350,7 +356,7 @@ open_xwindow(xwindow,displayname,xpos,yp
}
/**** set colors (link GC to color) ****/
- if (xwindow->depth == 8)
+ if (! xwindow->bw_p)
{
#if NEWCOLORMAP
for (j=0; j<nsides; j++)
@@ -387,8 +393,7 @@ open_xwindow(xwindow,displayname,xpos,yp
}
}
- if (xwindow->depth == 1)
- {
+ if (xwindow->bw_p) {
/**** set grey stipple color ****/
init_stipple (xwindow->display, xwindow->window, stipple);
@@ -426,7 +431,7 @@ open_xwindow(xwindow,displayname,xpos,yp
squaresize, squaresize, xwindow->depth);
}
- if (xwindow->depth == 8)
+ if (! xwindow->bw_p)
{
for (i=0; i<limit; i++)
{
@@ -438,7 +443,7 @@ open_xwindow(xwindow,displayname,xpos,yp
terrainhue[i], 0, 0, squaresize, squaresize);
}
}
- else if (xwindow->depth == 1)
+ else if (xwindow->bw_p)
{
if (enable_hex)
init_terrain_pixmaps (xwindow, limit, 2*hex_side);
@@ -544,7 +549,7 @@ open_xwindow(xwindow,displayname,xpos,yp
XSetFont(xwindow->display, xwindow->flip, xwindow->font_struct->fid);
}
- if (xwindow->depth == 1)
+ if (xwindow->bw_p)
{
for (i=0; i<nsides; i++)
{
@@ -567,8 +572,8 @@ open_xwindow(xwindow,displayname,xpos,yp
xwindow->drawletter[none] = FALSE;
/**** map window to make it visible ****/
- if (xwindow->depth == 8)
- XMapWindow(xwindow->display, xwindow->window);
+ /* FIXME: ? if (! xwindow->bw_p) */
+ XMapWindow(xwindow->display, xwindow->window);
}
--- Synchronet 3.21b-Linux NewsLink 1.2