|
|
1.1 root 1: /* winx.c - xwindow version of display code */
2:
3: #ifndef lint
4: static char *rcsid = "$Header: /f/osi/others/quipu/photo/RCS/winx.c,v 7.0 89/11/23 22:01:50 mrose Rel $";
5: #endif
6:
7: /*
8: * $Header: /f/osi/others/quipu/photo/RCS/winx.c,v 7.0 89/11/23 22:01:50 mrose Rel $
9: *
10: *
11: * $Log: winx.c,v $
12: * Revision 7.0 89/11/23 22:01:50 mrose
13: * Release 6.0
14: *
15: */
16:
17: /*
18: * NOTICE
19: *
20: * Acquisition, use, and distribution of this module and related
21: * materials are subject to the restrictions of a license agreement.
22: * Consult the Preface in the User's Manual for the full terms of
23: * this agreement.
24: *
25: */
26:
27:
28:
29: #include <stdio.h>
30: #include "quipu/photo.h"
31: #include <X11/Xlib.h>
32: #include <X11/Xatom.h>
33: #include <X11/Xutil.h>
34:
35:
36: /* It appears that window manager writers have problems */
37:
38: #ifndef NEVER_USE_WM
39: #define WM_DISAPPEARED_BUG /* wm screw up & loses the window ! */
40: #define WM_WINGE_BUG /* When wm screws up, it also winges */
41: #endif NEVER_USE_WM
42:
43: #ifndef NEVER_USE_TWM
44: #define TWM_RESIZE_BUG /* twm looses the resize if done too early. */
45: #endif NEVER_USE_TWM
46:
47:
48: extern GC XCreateGC();
49: Pixmap pixmap;
50: Display *dpy;
51: Screen *scr;
52: Window win;
53: int winX, winY, winW, winH;
54: XSetWindowAttributes xswa;
55: GC gc;
56: extern int NUMLINES,PIC_LINESIZE;
57: extern unsigned position;
58: unsigned long XorVal;
59: int buttons_down = 0;
60: int ignore_action = 0;
61:
62: static int passno = 1;
63: static int x, y, maxx;
64:
65: extern int two_passes;
66:
67: photo_start (name)
68: char * name;
69: {
70: x = y = 0;
71: if (passno == 1)
72: maxx = 0, two_passes = 1;
73: return 0;
74: }
75:
76:
77: photo_end (name)
78: char * name;
79: {
80: /* Decoding has finished - display the photo */
81: char buff[128];
82:
83: if (passno == 1) {
84: passno = 2;
85: x = maxx, y--;
86:
87: /* Initialise a window to recieve a photo of 'name' */
88:
89: if (!(dpy= XOpenDisplay((char *) 0))) {
90: (void) printf ("Cannot open X display");
91: return (-1);
92: }
93: scr = DefaultScreenOfDisplay(dpy);
94: winW = x;
95: winH = y;
96: winX = WidthOfScreen(scr) - winW;
97: winY = HeightOfScreen(scr) - winH;
98:
99: /*NB: to get button release you have to ask for button press as well*/
100: xswa.event_mask = ExposureMask | ButtonReleaseMask | ButtonPressMask;
101:
102: xswa.background_pixel = BlackPixelOfScreen(scr);
103: xswa.backing_store = WhenMapped;
104:
105: win = XCreateWindow(dpy, RootWindowOfScreen(scr),
106: winX, winY, winW, winH, 0,
107: DefaultDepthOfScreen(scr), InputOutput,
108: DefaultVisualOfScreen(scr),
109: CWEventMask | CWBackPixel | CWBackingStore, &xswa);
110: pixmap = XCreatePixmap(dpy, win,
111: winW,winH, DefaultDepthOfScreen(scr));
112: if (!pixmap) {
113: (void) fprintf (stderr,"PHOTO: Pixmap failed");
114: return (-1);
115: }
116:
117: /* Set up a graphics context: */
118: gc = XCreateGC(dpy, pixmap, 0, NULL);
119:
120: /* Clear pixmap */
121: XSetForeground(dpy, gc, BlackPixelOfScreen(scr));
122: XFillRectangle(dpy, pixmap, gc, 0, 0, winW,winH);
123:
124: XSetForeground(dpy, gc, WhitePixelOfScreen(scr));
125: XSetBackground(dpy, gc, BlackPixelOfScreen(scr));
126:
127: XorVal = WhitePixelOfScreen(scr) ^ BlackPixelOfScreen(scr);
128:
129: return (0);
130: }
131:
132: if (strcmp (name, "unknown") == 0)
133: name = NULL;
134:
135: if (name == NULL) {
136: (void) printf ("(See X window, pid %d)", getpid());
137: (void) fflush (stdout);
138: }
139: (void) close (1);
140:
141: (void) sprintf(buff, name ? "%s" : "%s (%d)",
142: name ? name : "Photo", getpid());
143: XChangeProperty(dpy, win, XA_WM_NAME, XA_STRING, 8,
144: PropModeReplace, buff, strlen(buff));
145: XMapWindow(dpy, win);
146: XSetForeground(dpy, gc, XorVal);
147: for (;;)
148: { XEvent xev;
149:
150: XNextEvent(dpy, &xev);
151: switch (xev.type)
152: {
153: case ButtonPress:
154: if (buttons_down++)
155: { if (!ignore_action++)
156: { XSetFunction(dpy, gc, GXcopy);
157: XCopyArea(dpy, pixmap, win,
158: gc, 0, 0,
159: PIC_LINESIZE, NUMLINES,
160: 0, 0);
161: }
162: }
163: else
164: { XSetFunction(dpy, gc, GXxor);
165: XFillRectangle(dpy, win, gc,
166: 0, 0, PIC_LINESIZE, NUMLINES);
167: }
168: continue;
169: case ButtonRelease:
170: if (!buttons_down) buttons_down++;
171: if (--buttons_down) continue;
172: if (!ignore_action) break;
173: ignore_action = 0;
174: continue;
175: case Expose:
176: XSetFunction(dpy, gc, GXcopy);
177: XCopyArea(dpy, pixmap, win, gc,
178: xev.xexpose.x, xev.xexpose.y,
179: xev.xexpose.width, xev.xexpose.height,
180: xev.xexpose.x, xev.xexpose.y);
181: default:
182: continue;
183: }
184: break;
185: }
186: return 0;
187: }
188:
189: photo_black (length)
190: int length;
191: {
192: if (passno == 1) {
193: x += length;
194: return 0;
195: }
196: /* draw a black line of 'length' pixels */
197:
198: return 0;
199: }
200:
201: photo_white (length)
202: int length;
203: {
204: if (passno == 1) {
205: x += length;
206: return 0;
207: }
208:
209: /* draw a white line of 'length' pixels */
210: XDrawLine (dpy,pixmap,gc,position,NUMLINES,length+position-1,NUMLINES);
211:
212: return 0;
213: }
214:
215:
216: photo_line_end (line)
217: bit_string * line;
218: {
219: /* the end of a line has been reached */
220: /* A bit string is stored in line->dbuf_top */
221:
222: if (passno == 1 && x > maxx)
223: maxx = x;
224: x = 0, y++;
225:
226: return 0;
227: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.