DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T w

⟦8479d3cb4⟧ TextFile

    Length: 5036 (0x13ac)
    Types: TextFile
    Names: »winx.c«

Derivation

└─⟦3d0c2be1b⟧ Bits:30001254 ISODE-5.0 Tape
    └─⟦eba4602b1⟧ »./isode-5.0.tar.Z« 
        └─⟦d3ac74d73⟧ 
            └─⟦this⟧ »isode-5.0/others/quipu/photo/winx.c« 

TextFile

/* winx.c - xwindow version of display code */

#ifndef	lint
static char *rcsid = "$Header: /f/osi/others/quipu/photo/RCS/winx.c,v 6.0 89/03/18 23:34:11 mrose Rel $";
#endif

/* 
 * $Header: /f/osi/others/quipu/photo/RCS/winx.c,v 6.0 89/03/18 23:34:11 mrose Rel $
 *
 *
 * $Log:	winx.c,v $
 * Revision 6.0  89/03/18  23:34:11  mrose
 * Release 5.0
 * 
 */

/*
 *				  NOTICE
 *
 *    Acquisition, use, and distribution of this module and related
 *    materials are subject to the restrictions of a license agreement.
 *    Consult the Preface in the User's Manual for the full terms of
 *    this agreement.
 *
 */



#include <stdio.h>
#include "quipu/photo.h"
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <X11/Xutil.h>


/* It appears that window manager writers have problems */

#ifndef	NEVER_USE_WM
#define	WM_DISAPPEARED_BUG	/* wm screw up & loses the window ! */
#define	WM_WINGE_BUG		/* When wm screws up, it also winges */
#endif	NEVER_USE_WM

#ifndef	NEVER_USE_TWM
#define	TWM_RESIZE_BUG		/* twm looses the resize if done too early. */
#endif	NEVER_USE_TWM

/* Create the window this big & shrink fit it later .... sigh ... */
#define	WIN_MAX_X	256
#define	WIN_MAX_Y	256


char *display_name = NULL;
extern GC XCreateGC();
Pixmap pixmap;
Display *dpy;
Screen *scr;
Window win;
int winX, winY, winW, winH;
XSetWindowAttributes xswa;
GC gc;
extern int NUMLINES,PIC_LINESIZE;
extern unsigned position;
unsigned long XorVal;
int buttons_down	= 0;
int ignore_action	= 0;
int resized		= 0;
int mask		= 0
#ifndef	WM_WINGE_BUG
			| 1
#endif	WM_WINGE_BUG
#ifdef	WM_DISAPPEARED_BUG
			| 2
#endif	WM_DISAPPEARED_BUG
#ifdef	TWM_RESIZE_BUG
			| 4
#endif	TWM_RESIZE_BUG
	;

photo_start (name)
char * name;
{
char * getenv ();
	/* Initialise a window to recieve a photo of 'name' */

	if (!(display_name = getenv ("DISPLAY")))
	{	(void) fprintf (stderr,"Display in X windows only");
		return (-1);
	}

	if (!(dpy= XOpenDisplay(display_name))) {
		(void) fprintf (stderr,"Cannot open X display");
		return (-1);
	}
	scr = DefaultScreenOfDisplay(dpy);
	winW = WIN_MAX_X;
	winH = WIN_MAX_Y;
	winX = (WidthOfScreen(scr) - winW) >> 1;
	winY = (HeightOfScreen(scr) - winH) >> 1;

	/*NB: to get button release you have to ask for button press as well*/
	xswa.event_mask = ExposureMask | ButtonReleaseMask | ButtonPressMask;

	xswa.background_pixel = BlackPixelOfScreen(scr);
	xswa.backing_store	= WhenMapped;

	win = XCreateWindow(dpy, RootWindowOfScreen(scr),
	   winX, winY, winW, winH, 0,
	   DefaultDepthOfScreen(scr), InputOutput,
	   DefaultVisualOfScreen(scr),
	   CWEventMask | CWBackPixel | CWBackingStore, &xswa);
	pixmap = XCreatePixmap(dpy, win,
	   winW,winH, DefaultDepthOfScreen(scr));
	if (!pixmap) {
		(void) fprintf (stderr,"PHOTO: Pixmap failed");
		return (-1);
	}

	/* Set up a graphics context: */
	gc = XCreateGC(dpy, pixmap, 0, NULL);

	/* Clear pixmap */
	XSetForeground(dpy, gc, BlackPixelOfScreen(scr));
	XFillRectangle(dpy, pixmap, gc, 0, 0, winW,winH);

	XSetForeground(dpy, gc, WhitePixelOfScreen(scr));
	XSetBackground(dpy, gc, BlackPixelOfScreen(scr));

	XorVal = WhitePixelOfScreen(scr) ^ BlackPixelOfScreen(scr);

	return (0);
}


photo_end (name)
char * name;
{
	/* Decoding has finished - display the photo */
	char buff[128];

	(void) fprintf (stderr,"(See X window, pid %d)", getpid());
	(void) fflush (stdout);
	(void) close (2); 

	(void) sprintf(buff, "%s (%d)",(name) ? name : "Photo", getpid());
	XChangeProperty(dpy, win, XA_WM_NAME, XA_STRING, 8,
			 PropModeReplace, buff, strlen(buff));
	if (mask & 1)	XResizeWindow(dpy, win, PIC_LINESIZE, NUMLINES);
	XMapWindow(dpy, win);
	XSetForeground(dpy, gc, XorVal);
	if (mask & 2)	XResizeWindow(dpy, win, PIC_LINESIZE, NUMLINES);
	for (;;)
	{       XEvent xev;

		XNextEvent(dpy, &xev);
		if (!resized && (mask & 4 || !(mask & 3)))
		{	XResizeWindow(dpy, win, PIC_LINESIZE, NUMLINES);
			resized++;
		}

		switch (xev.type)
		{
		case ButtonPress:
			if (buttons_down++)
			{	if (!ignore_action++)
				{	XSetFunction(dpy, gc, GXcopy);
					XCopyArea(dpy, pixmap, win,
						gc, 0, 0,
						PIC_LINESIZE, NUMLINES,
						0, 0);
				}
			}
			else
			{	XSetFunction(dpy, gc, GXxor);
				XFillRectangle(dpy, win, gc,
					0, 0, PIC_LINESIZE, NUMLINES);
			}
			continue;
		case ButtonRelease:
			if (!buttons_down)	buttons_down++;
			if (--buttons_down)	continue;
			if (!ignore_action)	break;
			ignore_action = 0;
			continue;
		case Expose:
			XSetFunction(dpy, gc, GXcopy);
			XCopyArea(dpy, pixmap, win, gc,
				xev.xexpose.x, xev.xexpose.y,
				xev.xexpose.width, xev.xexpose.height,
				xev.xexpose.x, xev.xexpose.y); 
		default:
			continue;
		}
		break;
	}
	return 0;
}

photo_black (length)
int length;
{
	/* draw a black line of 'length' pixels */
}

photo_white (length)
int length;
{
	/* draw a white line of 'length' pixels */
	XDrawLine (dpy,pixmap,gc,position,NUMLINES,length+position,NUMLINES); 
}


photo_line_end (line)
bit_string * line;
{
	/* the end of a line has been reached */
	/* A bit string is stored in line->dbuf_top */
}