|
|
1.1 root 1: #ifndef lint
2: static char *sccsid = "%G% hack (aps) %W%";
3: #endif
4:
5: #include "def.h"
6: #include "flying_bee.h"
7:
8: /*
9: * hack -- playing with windows.
10: * This program puts up two windows, each with different
11: * cursors.
12: * This program was actually the beginnings of a window based
13: * talk program.
14: * aps.
15: */
16:
17: #define INCREMENT 1
18: #define DECREMENT 0
19:
20: #define DEBUG 0
21:
22: int debug = DEBUG; /* 10 or greater is painfully detailed */
23: int verbose = NO; /* print some stuff */
24: int myuid; /* my uid */
25: char me[UTMPNAMSIZ]; /* my login name */
26: char mytty[NAMLEN]; /* my dev node name */
27:
28:
29: /*
30: * X and window stuff.
31: */
32: #define XLOC1 40 /* x cordinate for window 1 */
33: #define YLOC1 10 /* y cordinate for window 1 */
34: #define XLOC2 500 /* x cordinate for window 2 */
35: #define YLOC2 10 /* y cordinate for window 2 */
36: #define WIDTH 300 /* width of window */
37: #define HEIGHT 400 /* height of window */
38: #define BDRWDTH 6 /* window border width */
39: #define BORDER WhitePixmap /* border pixmap */
40: #define BCKGRND BlackPixmap /* background pixmap */
41: int xloc;
42: int yloc;
43: Display *mydisp, *herdisp; /* descriptors for the displays */
44: char mydispname[NAMLEN]; /* descriptors for the displays */
45: char herdispname[NAMLEN]; /* descriptors for the displays */
46: Window mywin, herwin; /* descriptors for the windows */
47: Window mywinparent; /* parent window */
48: Window herwinparent; /* parent window */
49:
50:
51: /*
52: * cursor bitmaps for window 1
53: */
54:
55: #define aps_width 24
56: #define aps_height 24
57: static short aps_bits[] = {
58: 0xffff, 0xffff, 0xffff, 0xffff,
59: 0xffff, 0xffe7, 0xffff, 0xffdb,
60: 0xffff, 0xffbd, 0xff87, 0xffbd,
61: 0xff33, 0xffbd, 0xff79, 0xffdb,
62: 0xff7c, 0xffe7, 0x8f7e, 0xfff7,
63: 0xb33e, 0xff31, 0xb93c, 0xffce,
64: 0xb91d, 0xffd2, 0xbc49, 0xffdc,
65: 0x3ce3, 0xffdd, 0x98ff, 0xffe3,
66: 0xe6ff, 0xffff, 0xfe7f, 0xffff,
67: 0xff7f, 0xffff, 0xff3f, 0xffff,
68: 0xffbf, 0xffff, 0xffff, 0xffff,
69: 0xffff, 0xffff, 0xffff, 0xffff};
70:
71: /* Inverse bitmap */
72: #define Iaps_width 24
73: #define Iaps_height 24
74: static short Iaps_bits[] = {
75: 0x0000, 0x0000, 0x0000, 0x0000,
76: 0x0000, 0x0018, 0x0000, 0x0024,
77: 0x0000, 0x0042, 0x0078, 0x0042,
78: 0x00cc, 0x0042, 0x0086, 0x0024,
79: 0x0083, 0x0018, 0x7081, 0x0008,
80: 0x4cc1, 0x00ce, 0x46c3, 0x0031,
81: 0x46e2, 0x002d, 0x43b6, 0x0023,
82: 0xc31c, 0x0022, 0x6700, 0x001c,
83: 0x1900, 0x0000, 0x0180, 0x0000,
84: 0x0080, 0x0000, 0x00c0, 0x0000,
85: 0x0040, 0x0000, 0x0000, 0x0000,
86: 0x0000, 0x0000, 0x0000, 0x0000};
87:
88:
89: /*
90: * array to store bees in flight
91: */
92: #define CUR_COUNT 4 /* number of bee frames */
93: Cursor Bee[CUR_COUNT]; /* cursor table */
94:
95:
96: /*
97: * main() -- What can one say about main...
98: * it is where it's at!
99: *
100: * xhack
101: */
102: main(argc, argv)
103: int argc;
104: char *argv[];
105: {
106: Cursor curcur, hackcur;
107: XEvent herxevent, myxevent;
108: struct _XMouseOrCrossingEvent *mmevp;
109: char *rindex(), *p;
110: int curp;
111: int inc_or_dec;
112:
113: /*
114: * get what few options we allow. (currently none)
115: */
116: while (--argc > 0 && (++argv)[0][0]=='-')
117: {
118: char *cp = argv[0] + 1;
119: if (debug >= 10)
120: printf("argv=%s\n", *argv);
121: while (*cp)
122: switch (*cp++)
123: {
124: case 'v':
125: /* verbose flag */ /* nothing yet */
126: verbose = YES;
127: continue;
128:
129: default:
130: fprintf(stderr, "Unknown flag %s\n",
131: *argv);
132: fprintf(stderr,
133: "hack [-v] \n");
134: exit(-1);
135: }
136: }
137:
138: /*****
139: * Create the windows.
140: *****/
141:
142: /*
143: * Open the display.
144: */
145: if (debug >= 15)
146: printf("About to XOpenDisplay(NULL) my display.\n");
147: mydisp = XOpenDisplay(NULL);
148: if (debug >= 15)
149: printf("XopenDisplay(NULL) returned %x.\n", mydisp);
150: if (mydisp == NULL)
151: {
152: fprintf(stderr, "xhack: can't open my display.\n");
153: exit(-1);
154: }
155:
156: /* creat my window*/
157: xloc = XLOC1;
158: yloc = YLOC1;
159: if (debug >= 15)
160: printf("About to XCreateWindow().\n");
161: mywin = XCreateWindow(mydisp->root, xloc, yloc, WIDTH, HEIGHT,
162: BDRWDTH, BORDER, BCKGRND);
163: if (debug >= 15)
164: printf("XCreatWindow() returned %x.\n", (int) mywin);
165: if (mywin == NULL)
166: {
167: fprintf(stderr, "hack: can't creat window.\n");
168: exit(-1);
169: }
170:
171: XStoreName(mywin, "xhack_window-1"); /* icon name */
172:
173: /* creat (describe) a cursor */
174: curcur = XCreateCursor(aps_width, aps_height, aps_bits,
175: Iaps_bits, 9, 10, BlackPixel, WhitePixel, GXxor);
176: if (curcur == 0)
177: {
178: fprintf(stderr, "xhack: can't creat cursor.\n");
179: exit(-1);
180: }
181:
182: /* define (set) the cursor */
183: XDefineCursor(mywin, curcur);
184: if (debug >= 15)
185: printf("About to XMapWindow().\n");
186:
187: XMapWindow(mywin);
188: /*
189: * Normally, a window is really made on the screen automatically
190: * the next time input is read. Since we don't do any input,
191: * we have to do an explicit flush.
192: */
193: XFlush();
194:
195:
196: /* creat the second window */
197: xloc = XLOC2;
198: yloc = YLOC2;
199:
200: if (debug >= 15)
201: printf("About to XCreateWindow().\n");
202: herwin = XCreateWindow(mydisp->root, xloc, yloc, WIDTH, HEIGHT,
203: BDRWDTH, BORDER, BCKGRND);
204: if (debug >= 15)
205: printf("XCreatWindow() returned %x.\n", (int) herwin);
206: if (herwin == NULL)
207: {
208: fprintf(stderr, "hack: can't creat window.\n");
209: exit(-1);
210: }
211:
212: XStoreName(herwin, "bee_window-2"); /* icon name */
213:
214: /* creat (describe) some cursors */
215:
216: Bee[0] = XCreateCursor(bee_wing1_width, bee_wing1_height,
217: bee_wing1_bits, Ibee_wing1_bits, 46, 16, BlackPixel,
218: WhitePixel, GXxor);
219: Bee[1] = XCreateCursor(bee_wing2_width, bee_wing2_height,
220: bee_wing2_bits, Ibee_wing2_bits, 46, 16, BlackPixel,
221: WhitePixel, GXxor);
222: Bee[2] = XCreateCursor(bee_wing3_width, bee_wing3_height,
223: bee_wing3_bits, Ibee_wing3_bits, 46, 16, BlackPixel,
224: WhitePixel, GXxor);
225: Bee[3] = XCreateCursor(bee_wing4_width, bee_wing4_height,
226: bee_wing4_bits, Ibee_wing4_bits, 46, 16, BlackPixel,
227: WhitePixel, GXxor);
228: if ((Bee[0] == 0) || (Bee[1] == 0) ||
229: (Bee[2] == 0) || (Bee[3] == 0))
230: {
231: fprintf(stderr, "hack: can't creat bee cursors.\n");
232: exit(-1);
233: }
234:
235: /* define (set) the initial cursor */
236: XDefineCursor(herwin, Bee[0]); /* initial cursor define */
237: if (debug >= 15)
238: printf("About to XMapWindow().\n");
239:
240: XMapWindow(herwin);
241: XFlush(); /* necessary because we don't get input */
242:
243: inc_or_dec = INCREMENT; /* set direction to traverse cursor table */
244: curp = 0;
245: XSelectInput(herwin, MouseMoved|LeaveWindow|EnterWindow);
246: for (EVER)
247: {
248: XNextEvent(&herxevent);
249:
250: (XEvent *)mmevp = &herxevent;
251: switch (mmevp->type)
252: {
253: case EnterWindow:
254: if (debug >=10)
255: printf("Mouse entered.\n");
256: continue;
257:
258: case LeaveWindow:
259: if (debug >=10)
260: printf("Mouse left.\n");
261: continue;
262:
263: case MouseMoved:
264: if (debug >=15)
265: printf("rel %d, %d.\n",
266: mmevp->x, mmevp->y);
267: XDefineCursor(herwin, Bee[curp]);
268:
269: /*
270: * This little code allows smoother flight
271: * of the wings by moving forward then
272: * backwards through the different bitmaps
273: * in the table instead of recycling to 0.
274: * There are probably more straight forward
275: * ways to do this.
276: */
277: if (inc_or_dec == INCREMENT)
278: curp++;
279: else
280: curp--;
281: if ((curp >= CUR_COUNT) || (curp <= 0))
282: /* switch directions */
283: if (inc_or_dec == INCREMENT)
284: {
285: inc_or_dec = DECREMENT;
286: curp--;
287: }
288: else
289: {
290: inc_or_dec = INCREMENT;
291: curp++;
292: }
293: continue;
294:
295: default:
296: printf("unknown event.\n");
297: continue;
298:
299: }
300: }
301:
302: /* NOTREACHED */
303: }
304:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.