xref: /original-bsd/usr.bin/window/wwcursor.c (revision c3e32dec)
1 /*
2  * Copyright (c) 1983, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * Edward Wang at The University of California, Berkeley.
7  *
8  * %sccs.include.redist.c%
9  */
10 
11 #ifndef lint
12 static char sccsid[] = "@(#)wwcursor.c	8.1 (Berkeley) 06/06/93";
13 #endif /* not lint */
14 
15 #include "ww.h"
16 
17 wwcursor(w, on)
18 register struct ww *w;
19 {
20 	register char *win;
21 
22 	if (on) {
23 		if (w->ww_hascursor)
24 			return;
25 		w->ww_hascursor = 1;
26 	} else {
27 		if (!w->ww_hascursor)
28 			return;
29 		w->ww_hascursor = 0;
30 	}
31 	if (wwcursormodes != 0) {
32 		win = &w->ww_win[w->ww_cur.r][w->ww_cur.c];
33 		*win ^= wwcursormodes;
34 		if (w->ww_cur.r < w->ww_i.t || w->ww_cur.r >= w->ww_i.b
35 		    || w->ww_cur.c < w->ww_i.l || w->ww_cur.c >= w->ww_i.r)
36 			return;
37 		if (wwsmap[w->ww_cur.r][w->ww_cur.c] == w->ww_index) {
38 			if (*win == 0)
39 				w->ww_nvis[w->ww_cur.r]++;
40 			else if (*win == wwcursormodes)
41 				w->ww_nvis[w->ww_cur.r]--;
42 			wwns[w->ww_cur.r][w->ww_cur.c].c_m ^= wwcursormodes;
43 			wwtouched[w->ww_cur.r] |= WWU_TOUCHED;
44 		}
45 	}
46 }
47 
48 wwsetcursormodes(new)
49 register new;
50 {
51 	register i;
52 	register struct ww *w;
53 	register old = wwcursormodes;
54 
55 	new &= wwavailmodes;
56 	if (new == wwcursormodes)
57 		return;
58 	for (i = 0; i < NWW; i++)
59 		if (wwindex[i] != 0 && (w = wwindex[i])->ww_hascursor) {
60 			wwcursor(w, 0);
61 			wwcursormodes = new;
62 			wwcursor(w, 1);
63 			wwcursormodes = old;
64 		}
65 	wwcursormodes = new;
66 }
67