ptyx.h revision 50027b5b
1/* $XTermId: ptyx.h,v 1.1060 2022/03/08 23:31:40 tom Exp $ */
2
3/*
4 * Copyright 1999-2021,2022 by Thomas E. Dickey
5 *
6 *                         All Rights Reserved
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the
10 * "Software"), to deal in the Software without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sublicense, and/or sell copies of the Software, and to
13 * permit persons to whom the Software is furnished to do so, subject to
14 * the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22 * IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
23 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 *
27 * Except as contained in this notice, the name(s) of the above copyright
28 * holders shall not be used in advertising or otherwise to promote the
29 * sale, use or other dealings in this Software without prior written
30 * authorization.
31 *
32 *
33 * Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
34 *
35 *                         All Rights Reserved
36 *
37 * Permission to use, copy, modify, and distribute this software and its
38 * documentation for any purpose and without fee is hereby granted,
39 * provided that the above copyright notice appear in all copies and that
40 * both that copyright notice and this permission notice appear in
41 * supporting documentation, and that the name of Digital Equipment
42 * Corporation not be used in advertising or publicity pertaining to
43 * distribution of the software without specific, written prior permission.
44 *
45 *
46 * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
47 * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
48 * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
49 * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
50 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
51 * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
52 * SOFTWARE.
53 */
54
55#ifndef included_ptyx_h
56#define included_ptyx_h 1
57
58#ifdef HAVE_CONFIG_H
59#include <xtermcfg.h>
60#endif
61
62/* ptyx.h */
63/* *INDENT-OFF* */
64/* @(#)ptyx.h	X10/6.6	11/10/86 */
65
66#include <X11/IntrinsicP.h>
67#include <X11/Shell.h>		/* for XtNdieCallback, etc. */
68#include <X11/StringDefs.h>	/* for standard resource names */
69#include <X11/Xmu/Misc.h>	/* For Max() and Min(). */
70#include <X11/cursorfont.h>
71
72
73#undef bcopy
74#undef bzero
75#include <X11/Xfuncs.h>
76
77#include <X11/Xosdefs.h>
78#include <X11/Xmu/Converters.h>
79#ifdef XRENDERFONT
80#include <X11/Xft/Xft.h>
81#endif
82
83#include <stdio.h>
84
85#if defined(HAVE_STDINT_H) || !defined(HAVE_CONFIG_H)
86#include <stdint.h>
87#define DECONST(type,s) ((type *)(intptr_t)(const type *)(s))
88#else
89#define DECONST(type,s) ((type *)(s))
90#endif
91
92/* adapted from IntrinsicI.h */
93#define MyStackAlloc(size, stack_cache_array)     \
94    ((size) <= sizeof(stack_cache_array)	  \
95    ?  (XtPointer)(stack_cache_array)		  \
96    :  (XtPointer)malloc((size_t)(size)))
97
98#define MyStackFree(pointer, stack_cache_array) \
99    if ((pointer) != ((char *)(stack_cache_array))) free(pointer)
100
101/* adapted from vile (vi-like-emacs) */
102#define TypeCallocN(type,n)	(type *)calloc((size_t) (n), sizeof(type))
103#define TypeCalloc(type)	TypeCallocN(type, 1)
104
105#define TypeMallocN(type,n)	(type *)malloc(sizeof(type) * (size_t) (n))
106#define TypeMalloc(type)	TypeMallocN(type, 1)
107
108#define TypeRealloc(type,n,p)	(type *)realloc(p, (n) * sizeof(type))
109
110#define TypeXtReallocN(t,p,n)	(t *)(void *)XtRealloc((char *)(p), (Cardinal)(sizeof(t) * (size_t) (n)))
111
112#define TypeXtMallocX(type,n)	(type *)(void *)XtMalloc((Cardinal)(sizeof(type) + (size_t) (n)))
113#define TypeXtMallocN(type,n)	(type *)(void *)XtMalloc((Cardinal)(sizeof(type) * (size_t) (n)))
114#define TypeXtMalloc(type)	TypeXtMallocN(type, 1)
115
116#define CastMalloc(type)	(type *)malloc(sizeof(type))
117
118#define BumpBuffer(type, buffer, size, want) \
119	if (want >= size) { \
120	    size = 1 + (want * 2); \
121	    buffer = TypeRealloc(type, size, buffer); \
122	}
123
124#define BfBuf(type) screen->bf_buf_##type
125#define BfLen(type) screen->bf_len_##type
126
127#define TypedBuffer(type) \
128	type		*bf_buf_##type; \
129	Cardinal	bf_len_##type
130
131#define BumpTypedBuffer(type, want) \
132	BumpBuffer(type, BfBuf(type), BfLen(type), want)
133
134#define FreeTypedBuffer(type) \
135	do { \
136	    FreeAndNull(BfBuf(type)); \
137	    BfLen(type) = 0; \
138	} while (0)
139
140#define FreeAndNull(value) \
141	do { \
142	    free((void *)(value)); \
143	    value = NULL; \
144	} while (0)
145
146/*
147** System V definitions
148*/
149
150#ifdef att
151#define ATT
152#endif
153
154#ifdef SVR4
155#undef  SYSV			/* predefined on Solaris 2.4 */
156#define SYSV			/* SVR4 is (approx) superset of SVR3 */
157#define ATT
158#endif
159
160#ifdef SYSV
161#ifdef X_NOT_POSIX
162#if !defined(CRAY) && !defined(SVR4)
163#define	dup2(fd1,fd2)	((fd1 == fd2) ? fd1 : \
164				(close(fd2), fcntl(fd1, F_DUPFD, fd2)))
165#endif
166#endif
167#endif /* SYSV */
168
169/*
170 * Newer versions of <X11/Xft/Xft.h> have a version number.  We use certain
171 * features from that.
172 */
173#if defined(XRENDERFONT) && defined(XFT_VERSION) && XFT_VERSION >= 20100
174#define HAVE_TYPE_FCCHAR32	1	/* compatible: XftChar16 */
175#define HAVE_TYPE_XFTCHARSPEC	1	/* new type XftCharSpec */
176#endif
177
178/*
179** Definitions to simplify ifdef's for pty's.
180*/
181#define USE_PTY_DEVICE 1
182#define USE_PTY_SEARCH 1
183
184#if defined(__osf__) || (defined(linux) && defined(__GLIBC__) && (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1)) || defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
185#undef USE_PTY_DEVICE
186#undef USE_PTY_SEARCH
187#define USE_PTS_DEVICE 1
188#elif defined(VMS)
189#undef USE_PTY_DEVICE
190#undef USE_PTY_SEARCH
191#elif defined(PUCC_PTYD)
192#undef USE_PTY_SEARCH
193#elif (defined(sun) && defined(SVR4)) || defined(_ALL_SOURCE) || defined(__CYGWIN__)
194#undef USE_PTY_SEARCH
195#elif defined(__OpenBSD__)
196#undef USE_PTY_SEARCH
197#undef USE_PTY_DEVICE
198#endif
199
200#if (defined (__GLIBC__) && ((__GLIBC__ > 2) || (__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 1)))
201#define USE_HANDSHAKE 0	/* "recent" Linux systems do not require handshaking */
202#endif
203
204#if (defined (__GLIBC__) && ((__GLIBC__ > 2) || (__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 1)))
205#define USE_USG_PTYS
206#elif (defined(ATT) && !defined(__sgi)) || defined(__MVS__) || (defined(SYSV) && defined(i386))
207#define USE_USG_PTYS
208#endif
209
210/*
211 * More systems than not require pty-handshaking.
212 */
213#ifndef USE_HANDSHAKE
214#define USE_HANDSHAKE 1
215#endif
216
217/*
218** allow for mobility of the pty master/slave directories
219*/
220#ifndef PTYDEV
221#if defined(__hpux)
222#define	PTYDEV		"/dev/ptym/ptyxx"
223#elif defined(__MVS__)
224#define	PTYDEV		"/dev/ptypxxxx"
225#else
226#define	PTYDEV		"/dev/ptyxx"
227#endif
228#endif	/* !PTYDEV */
229
230#ifndef TTYDEV
231#if defined(__hpux)
232#define TTYDEV		"/dev/pty/ttyxx"
233#elif defined(__MVS__)
234#define TTYDEV		"/dev/ptypxxxx"
235#elif defined(USE_PTS_DEVICE)
236#define TTYDEV		"/dev/pts/0"
237#else
238#define	TTYDEV		"/dev/ttyxx"
239#endif
240#endif	/* !TTYDEV */
241
242#ifndef PTYCHAR1
243#ifdef __hpux
244#define PTYCHAR1	"zyxwvutsrqp"
245#else	/* !__hpux */
246#define	PTYCHAR1	"pqrstuvwxyzPQRSTUVWXYZ"
247#endif	/* !__hpux */
248#endif	/* !PTYCHAR1 */
249
250#ifndef PTYCHAR2
251#ifdef __hpux
252#define	PTYCHAR2	"fedcba9876543210"
253#else	/* !__hpux */
254#if defined(__DragonFly__) || defined(__FreeBSD__)
255#define	PTYCHAR2	"0123456789abcdefghijklmnopqrstuv"
256#else /* !__FreeBSD__ */
257#define	PTYCHAR2	"0123456789abcdef"
258#endif /* !__FreeBSD__ */
259#endif	/* !__hpux */
260#endif	/* !PTYCHAR2 */
261
262#ifndef TTYFORMAT
263#if defined(CRAY)
264#define TTYFORMAT "/dev/ttyp%03d"
265#elif defined(__MVS__)
266#define TTYFORMAT "/dev/ttyp%04d"
267#else
268#define TTYFORMAT "/dev/ttyp%d"
269#endif
270#endif /* TTYFORMAT */
271
272#ifndef PTYFORMAT
273#ifdef CRAY
274#define PTYFORMAT "/dev/pty/%03d"
275#elif defined(__MVS__)
276#define PTYFORMAT "/dev/ptyp%04d"
277#else
278#define PTYFORMAT "/dev/ptyp%d"
279#endif
280#endif /* PTYFORMAT */
281
282#ifndef PTYCHARLEN
283#ifdef CRAY
284#define PTYCHARLEN 3
285#elif defined(__MVS__)
286#define PTYCHARLEN 8     /* OS/390 stores, e.g. ut_id="ttyp1234"  */
287#else
288#define PTYCHARLEN 2
289#endif
290#endif
291
292#ifndef MAXPTTYS
293#ifdef CRAY
294#define MAXPTTYS 256
295#else
296#define MAXPTTYS 2048
297#endif
298#endif
299
300/* Until the translation manager comes along, I have to do my own translation of
301 * mouse events into the proper routines. */
302
303typedef enum {
304    NORMAL = 0
305    , LEFTEXTENSION
306    , RIGHTEXTENSION
307} EventMode;
308
309/*
310 * The origin of a screen is 0, 0.  Therefore, the number of rows
311 * on a screen is screen->max_row + 1, and similarly for columns.
312 */
313#define MaxCols(screen)		((screen)->max_col + 1)
314#define MaxRows(screen)		((screen)->max_row + 1)
315
316typedef unsigned char Char;		/* to support 8 bit chars */
317typedef Char *ScrnPtr;
318typedef ScrnPtr *ScrnBuf;
319
320/*
321 * Declare an X String, but for unsigned chars.
322 */
323#ifdef _CONST_X_STRING
324typedef const Char *UString;
325#else
326typedef Char *UString;
327#endif
328
329#define IsEmpty(s) ((s) == 0 || *(s) == '\0')
330#define IsSpace(c) ((c) == ' ' || (c) == '\t' || (c) == '\r' || (c) == '\n')
331
332/*
333 * Check strtol result, using "FullS2L" when no more data is expected, and
334 * "PartS2L" when more data may follow in the string.
335 */
336#define FullS2L(s,d) (PartS2L(s,d) && (*(d) == '\0'))
337#define PartS2L(s,d) (isdigit(CharOf(*(s))) && (d) != (s) && (d) != 0)
338
339#define CASETYPE(name) case name: result = #name; break
340
341#define CharOf(n) ((Char)(n))
342
343typedef struct {
344    int row;
345    int col;
346} CELL;
347
348typedef struct {
349    Char  *data_buffer;			/* the current selection */
350    size_t data_limit;			/* size of allocated buffer */
351    size_t data_length;			/* number of significant bytes */
352} SelectedCells;
353
354#define isSameRow(a,b)		((a)->row == (b)->row)
355#define isSameCol(a,b)		((a)->col == (b)->col)
356#define isSameCELL(a,b)		(isSameRow(a,b) && isSameCol(a,b))
357
358#define xBIT(n)         (1 << (n))
359
360/*
361 * ANSI emulation, special character codes
362 */
363#define ANSI_EOT	0x04
364#define ANSI_BEL	0x07
365#define ANSI_BS		0x08
366#define ANSI_HT		0x09
367#define ANSI_LF		0x0A
368#define ANSI_VT		0x0B
369#define	ANSI_FF		0x0C		/* C0, C1 control names		*/
370#define ANSI_CR		0x0D
371#define ANSI_SO		0x0E
372#define ANSI_SI		0x0F
373#define	ANSI_XON	0x11		/* DC1 */
374#define	ANSI_XOFF	0x13		/* DC3 */
375#define	ANSI_NAK	0x15
376#define	ANSI_CAN	0x18
377#define	ANSI_ESC	0x1B
378#define	ANSI_SPA	0x20
379#define XTERM_POUND	0x1E		/* internal mapping for '#'	*/
380#define	ANSI_DEL	0x7F
381#define	ANSI_SS2	0x8E
382#define	ANSI_SS3	0x8F
383#define	ANSI_DCS	0x90
384#define	ANSI_SOS	0x98
385#define	ANSI_CSI	0x9B
386#define	ANSI_ST		0x9C
387#define	ANSI_OSC	0x9D
388#define	ANSI_PM		0x9E
389#define	ANSI_APC	0x9F
390
391#define BAD_ASCII	'?'
392#define NonLatin1(c)	(((c) != ANSI_LF) && \
393			 ((c) != ANSI_HT) && \
394			 (((c) < ANSI_SPA) || \
395			  ((c) >= ANSI_DEL && (c) <= ANSI_APC)))
396#define OnlyLatin1(c)	(NonLatin1(c) ? BAD_ASCII : (c))
397
398#define L_CURL		'{'
399#define R_CURL		'}'
400
401#define MIN_DECID  52			/* can emulate VT52 */
402#define MAX_DECID 525			/* ...through VT525 */
403
404#ifndef DFT_DECID
405#define DFT_DECID "420"			/* default VT420 */
406#endif
407
408#ifndef DFT_KBD_DIALECT
409#define DFT_KBD_DIALECT "B"		/* default USASCII */
410#endif
411
412#define MAX_I_PARAM	65535		/* parameters */
413#define MAX_I_DELAY	32767		/* time-delay in ReGIS */
414#define MAX_U_COLOR	65535u		/* colors */
415#define MAX_U_COORD	32767u		/* coordinates */
416#define MAX_U_STRING	65535u		/* string-length */
417
418/* constants used for utf8 mode */
419#define UCS_REPL	0xfffd
420#define UCS_LIMIT	0x80000000U	/* both limit and flag for non-UCS */
421
422#define TERMCAP_SIZE 1500		/* 1023 is standard; 'screen' exceeds */
423
424#define MAX_XLFD_FONTS	1
425#define MAX_XFT_FONTS	1
426#define NMENUFONTS	10		/* font entries in fontMenu */
427
428#define	NBOX	5			/* Number of Points in box	*/
429#define	NPARAM	30			/* Max. parameters		*/
430
431typedef struct {
432	String opt;
433	String desc;
434} OptionHelp;
435
436typedef	struct {
437	int	count;			/* number of values in params[]	*/
438	int	has_subparams;		/* true if there are any sub's	*/
439	int	is_sub[NPARAM];		/* true for subparam		*/
440	int	params[NPARAM];		/* parameter value		*/
441} PARAMS;
442
443typedef short ParmType;
444typedef unsigned short UParm;		/* unparseputn passes ParmType	*/
445
446typedef struct {
447	Char		a_type;		/* CSI, etc., see unparseq()	*/
448	Char		a_pintro;	/* private-mode char, if any	*/
449	const char *	a_delim;	/* between parameters (;)	*/
450	Char		a_inters;	/* special (before final-char)	*/
451	Char		a_final;	/* final-char			*/
452	ParmType	a_nparam;	/* # of parameters		*/
453	ParmType	a_param[NPARAM]; /* Parameters			*/
454	Char		a_radix[NPARAM]; /* Parameters			*/
455} ANSI;
456
457#define TEK_FONT_LARGE 0
458#define TEK_FONT_2 1
459#define TEK_FONT_3 2
460#define TEK_FONT_SMALL 3
461#define	TEKNUMFONTS 4
462
463/* Actually there are 5 types of lines, but four are non-solid lines */
464#define	TEKNUMLINES	4
465
466typedef struct {
467	int	x;
468	int	y;
469	int	fontsize;
470	unsigned linetype;
471} Tmodes;
472
473typedef struct {
474	int Twidth;
475	int Theight;
476} T_fontsize;
477
478typedef struct {
479	short *bits;
480	int x;
481	int y;
482	int width;
483	int height;
484} BitmapBits;
485
486/* bit-assignments for extensions to DECRQCRA */
487typedef enum {
488    csDEC = 0
489    ,csPOSITIVE = xBIT(0)
490    ,csATTRIBS = xBIT(1)
491    ,csNOTRIM = xBIT(2)
492    ,csDRAWN = xBIT(3)
493    ,csBYTE = xBIT(4)
494    ,cs8TH = xBIT(5)
495} CSBITS;
496
497#define EXCHANGE(a,b,tmp) tmp = a; a = b; b = tmp
498
499/***====================================================================***/
500
501#if (XtSpecificationRelease < 6)
502#ifndef NO_ACTIVE_ICON
503#define NO_ACTIVE_ICON 1 /* Note: code relies on an X11R6 function */
504#endif
505#endif
506
507#ifndef OPT_AIX_COLORS
508#define OPT_AIX_COLORS  1 /* true if xterm is configured with AIX (16) colors */
509#endif
510
511#ifndef OPT_ALLOW_XXX_OPS
512#define OPT_ALLOW_XXX_OPS 1 /* true if xterm adds "Allow XXX Ops" submenu */
513#endif
514
515#ifndef OPT_BLINK_CURS
516#define OPT_BLINK_CURS  1 /* true if xterm has blinking cursor capability */
517#endif
518
519#ifndef OPT_BLINK_TEXT
520#define OPT_BLINK_TEXT  OPT_BLINK_CURS /* true if xterm has blinking text capability */
521#endif
522
523#ifndef OPT_BOX_CHARS
524#define OPT_BOX_CHARS	1 /* true if xterm can simulate box-characters */
525#endif
526
527#ifndef OPT_BUILTIN_XPMS
528#define OPT_BUILTIN_XPMS 0 /* true if all xpm data is compiled-in */
529#endif
530
531#ifndef OPT_BROKEN_OSC
532#ifdef linux
533#define OPT_BROKEN_OSC	1 /* man console_codes, 1st paragraph - cf: ECMA-48 */
534#else
535#define OPT_BROKEN_OSC	0 /* true if xterm allows Linux's broken OSC parsing */
536#endif
537#endif
538
539#ifndef OPT_BROKEN_ST
540#define OPT_BROKEN_ST	1 /* true if xterm allows old/broken OSC parsing */
541#endif
542
543#ifndef OPT_C1_PRINT
544#define OPT_C1_PRINT	1 /* true if xterm allows C1 controls to be printable */
545#endif
546
547#ifndef OPT_CLIP_BOLD
548#define OPT_CLIP_BOLD	1 /* true if xterm uses clipping to avoid bold-trash */
549#endif
550
551#ifndef OPT_COLOR_CLASS
552#define OPT_COLOR_CLASS 1 /* true if xterm uses separate color-resource classes */
553#endif
554
555#ifndef OPT_DABBREV
556#define OPT_DABBREV 0	/* dynamic abbreviations */
557#endif
558
559#ifndef OPT_DEC_CHRSET
560#define OPT_DEC_CHRSET  1 /* true if xterm is configured for DEC charset */
561#endif
562
563#ifndef OPT_DEC_LOCATOR
564#define	OPT_DEC_LOCATOR 0 /* true if xterm supports VT220-style mouse events */
565#endif
566
567#ifndef OPT_DEC_RECTOPS
568#define OPT_DEC_RECTOPS 1 /* true if xterm is configured for VT420 rectangles */
569#endif
570
571#ifndef OPT_SIXEL_GRAPHICS
572#define OPT_SIXEL_GRAPHICS 0 /* true if xterm supports VT240-style sixel graphics */
573#endif
574
575#ifndef OPT_PRINT_GRAPHICS
576#define OPT_PRINT_GRAPHICS 0 /* true if xterm supports screen dumps as sixel graphics */
577#endif
578
579#ifndef OPT_SCREEN_DUMPS
580#define OPT_SCREEN_DUMPS 1 /* true if xterm supports screen dumps */
581#endif
582
583#ifndef OPT_REGIS_GRAPHICS
584#define OPT_REGIS_GRAPHICS 0 /* true if xterm supports VT125/VT240/VT330 ReGIS graphics */
585#endif
586
587#ifndef OPT_GRAPHICS
588#define OPT_GRAPHICS 0 /* true if xterm is configured for any type of graphics */
589#endif
590
591#ifndef OPT_DEC_SOFTFONT
592#define OPT_DEC_SOFTFONT 0 /* true if xterm is configured for VT220 softfonts */
593#endif
594
595#ifndef OPT_DOUBLE_BUFFER
596#define OPT_DOUBLE_BUFFER 0 /* true if using double-buffering */
597#endif
598
599#ifndef OPT_EBCDIC
600#ifdef __MVS__
601#define OPT_EBCDIC 1
602#else
603#define OPT_EBCDIC 0
604#endif
605#endif
606
607#ifndef OPT_EXEC_XTERM
608#define OPT_EXEC_XTERM 0 /* true if xterm can fork/exec copies of itself */
609#endif
610
611#ifndef OPT_EXTRA_PASTE
612#define OPT_EXTRA_PASTE 1
613#endif
614
615#ifndef OPT_FOCUS_EVENT
616#define OPT_FOCUS_EVENT	1 /* focus in/out events */
617#endif
618
619#ifndef OPT_HP_FUNC_KEYS
620#define OPT_HP_FUNC_KEYS 0 /* true if xterm supports HP-style function keys */
621#endif
622
623#ifndef OPT_I18N_SUPPORT
624#if (XtSpecificationRelease >= 5)
625#define OPT_I18N_SUPPORT 1 /* true if xterm uses internationalization support */
626#else
627#define OPT_I18N_SUPPORT 0
628#endif
629#endif
630
631#ifndef OPT_INITIAL_ERASE
632#define OPT_INITIAL_ERASE 1 /* use pty's erase character if it's not 128 */
633#endif
634
635#ifndef OPT_INPUT_METHOD
636#if (XtSpecificationRelease >= 6)
637#define OPT_INPUT_METHOD OPT_I18N_SUPPORT /* true if xterm uses input-method support */
638#else
639#define OPT_INPUT_METHOD 0
640#endif
641#endif
642
643#ifndef OPT_ISO_COLORS
644#define OPT_ISO_COLORS  1 /* true if xterm is configured with ISO colors */
645#endif
646
647#ifndef OPT_DIRECT_COLOR
648#define OPT_DIRECT_COLOR  OPT_ISO_COLORS /* true if xterm is configured with direct-colors */
649#endif
650
651#ifndef OPT_256_COLORS
652#define OPT_256_COLORS  1 /* true if xterm is configured with 256 colors */
653#endif
654
655#ifndef OPT_88_COLORS
656#define OPT_88_COLORS	1 /* true if xterm is configured with 88 colors */
657#endif
658
659#ifndef OPT_HIGHLIGHT_COLOR
660#define OPT_HIGHLIGHT_COLOR 1 /* true if xterm supports color highlighting */
661#endif
662
663#ifndef OPT_LOAD_VTFONTS
664#define OPT_LOAD_VTFONTS 0 /* true if xterm has load-vt-fonts() action */
665#endif
666
667#ifndef OPT_LUIT_PROG
668#define OPT_LUIT_PROG   1 /* true if xterm supports luit */
669#endif
670
671#ifndef OPT_MAXIMIZE
672#define OPT_MAXIMIZE	1 /* add actions for iconify ... maximize */
673#endif
674
675#ifndef OPT_MINI_LUIT
676#define OPT_MINI_LUIT   0 /* true if xterm supports built-in mini-luit */
677#endif
678
679#ifndef OPT_MOD_FKEYS
680#define OPT_MOD_FKEYS	1 /* modify cursor- and function-keys in normal mode */
681#endif
682
683#ifndef OPT_NUM_LOCK
684#define OPT_NUM_LOCK	1 /* use NumLock key only for numeric-keypad */
685#endif
686
687#ifndef OPT_PASTE64
688#define OPT_PASTE64	1 /* program control of select/paste via base64 */
689#endif
690
691#ifndef OPT_PC_COLORS
692#define OPT_PC_COLORS   1 /* true if xterm supports PC-style (bold) colors */
693#endif
694
695#ifndef OPT_PRINT_ON_EXIT
696#define OPT_PRINT_ON_EXIT 1 /* true allows xterm to dump screen on X error */
697#endif
698
699#ifndef OPT_PTY_HANDSHAKE
700#define OPT_PTY_HANDSHAKE USE_HANDSHAKE	/* avoid pty races on older systems */
701#endif
702
703#ifndef OPT_PRINT_COLORS
704#define OPT_PRINT_COLORS 1 /* true if we print color information */
705#endif
706
707#ifndef OPT_READLINE
708#define OPT_READLINE	0 /* mouse-click/paste support for readline */
709#endif
710
711#ifndef OPT_RENDERFONT
712#ifdef XRENDERFONT
713#define OPT_RENDERFONT 1
714#else
715#define OPT_RENDERFONT 0
716#endif
717#endif
718
719#ifndef OPT_RENDERWIDE
720#if OPT_RENDERFONT && OPT_WIDE_CHARS && defined(HAVE_TYPE_XFTCHARSPEC)
721#define OPT_RENDERWIDE 1
722#else
723#define OPT_RENDERWIDE 0
724#endif
725#endif
726
727#ifndef OPT_REPORT_CCLASS
728#define OPT_REPORT_CCLASS  1 /* provide "-report-charclass" option */
729#endif
730
731#ifndef OPT_REPORT_COLORS
732#define OPT_REPORT_COLORS  1 /* provide "-report-colors" option */
733#endif
734
735#ifndef OPT_REPORT_FONTS
736#define OPT_REPORT_FONTS   1 /* provide "-report-fonts" option */
737#endif
738
739#ifndef OPT_REPORT_ICONS
740#define OPT_REPORT_ICONS   1 /* provide "-report-icons" option */
741#endif
742
743#ifndef OPT_SAME_NAME
744#define OPT_SAME_NAME   1 /* suppress redundant updates of title, icon, etc. */
745#endif
746
747#ifndef OPT_SCO_FUNC_KEYS
748#define OPT_SCO_FUNC_KEYS 0 /* true if xterm supports SCO-style function keys */
749#endif
750
751#ifndef OPT_SUN_FUNC_KEYS
752#define OPT_SUN_FUNC_KEYS 1 /* true if xterm supports Sun-style function keys */
753#endif
754
755#ifndef OPT_SCROLL_LOCK
756#define OPT_SCROLL_LOCK 1 /* true if xterm interprets fontsize-shifting */
757#endif
758
759#ifndef OPT_SELECT_REGEX
760#define OPT_SELECT_REGEX 1 /* true if xterm supports regular-expression selects */
761#endif
762
763#ifndef OPT_SELECTION_OPS
764#define OPT_SELECTION_OPS 1 /* true if xterm supports operations on selection */
765#endif
766
767#ifndef OPT_SESSION_MGT
768#if defined(XtNdieCallback) && defined(XtNsaveCallback)
769#define OPT_SESSION_MGT 1
770#else
771#define OPT_SESSION_MGT 0
772#endif
773#endif
774
775#ifndef OPT_SHIFT_FONTS
776#define OPT_SHIFT_FONTS 0 /* true if xterm interprets fontsize-shifting */
777#endif
778
779#ifndef OPT_STATUS_LINE
780#define OPT_STATUS_LINE	0 /* true if xterm supports status-line controls */
781#endif
782
783#ifndef OPT_SUNPC_KBD
784#define OPT_SUNPC_KBD	1 /* true if xterm supports Sun/PC keyboard map */
785#endif
786
787#ifndef OPT_TCAP_FKEYS
788#define OPT_TCAP_FKEYS	1 /* true for termcap function-keys */
789#endif
790
791#ifndef OPT_TCAP_QUERY
792#define OPT_TCAP_QUERY	1 /* true for termcap query */
793#endif
794
795#ifndef OPT_TEK4014
796#define OPT_TEK4014     1 /* true if we're using tek4014 emulation */
797#endif
798
799#ifndef OPT_TOOLBAR
800#define OPT_TOOLBAR	0 /* true if xterm supports toolbar menus */
801#endif
802
803#ifndef OPT_TRACE
804#define OPT_TRACE       0 /* true if we're using debugging traces */
805#endif
806
807#ifndef OPT_TRACE_FLAGS
808#define OPT_TRACE_FLAGS 0 /* additional tracing used for SCRN_BUF_FLAGS */
809#endif
810
811#ifndef OPT_TRACE_UNIQUE
812#define OPT_TRACE_UNIQUE 0 /* true if we're using multiple trace files */
813#endif
814
815#ifndef OPT_VT52_MODE
816#define OPT_VT52_MODE   1 /* true if xterm supports VT52 emulation */
817#endif
818
819#ifndef OPT_WIDE_ATTRS
820#define OPT_WIDE_ATTRS  1 /* true if xterm supports 16-bit attributes */
821#endif
822
823#ifndef OPT_WIDE_CHARS
824#define OPT_WIDE_CHARS  1 /* true if xterm supports 16-bit characters */
825#endif
826
827#ifndef OPT_WIDER_ICHAR
828#define OPT_WIDER_ICHAR 1 /* true if xterm uses 32-bits for wide-chars */
829#endif
830
831#ifndef OPT_XMC_GLITCH
832#define OPT_XMC_GLITCH	0 /* true if xterm supports xmc (magic cookie glitch) */
833#endif
834
835#ifndef OPT_XRES_QUERY
836#define OPT_XRES_QUERY	1 /* true for resource query */
837#endif
838
839#ifndef OPT_XTERM_SGR
840#define OPT_XTERM_SGR   1 /* true if xterm supports private SGR controls */
841#endif
842
843#ifndef OPT_ZICONBEEP
844#define OPT_ZICONBEEP   1 /* true if xterm supports "-ziconbeep" option */
845#endif
846
847/***====================================================================***/
848
849#if OPT_AIX_COLORS && !OPT_ISO_COLORS
850/* You must have ANSI/ISO colors to support AIX colors */
851#undef  OPT_AIX_COLORS
852#define OPT_AIX_COLORS 0
853#endif
854
855#if OPT_PC_COLORS && !OPT_ISO_COLORS
856/* You must have ANSI/ISO colors to support PC colors */
857#undef  OPT_PC_COLORS
858#define OPT_PC_COLORS 0
859#endif
860
861#if OPT_PRINT_COLORS && !OPT_ISO_COLORS
862/* You must have ANSI/ISO colors to be able to print them */
863#undef  OPT_PRINT_COLORS
864#define OPT_PRINT_COLORS 0
865#endif
866
867#if OPT_256_COLORS && !OPT_ISO_COLORS
868/* You must have ANSI/ISO colors to support 256 colors */
869#undef  OPT_256_COLORS
870#define OPT_256_COLORS 0
871#endif
872
873#if OPT_88_COLORS && !OPT_ISO_COLORS
874/* You must have ANSI/ISO colors to support 88 colors */
875#undef  OPT_88_COLORS
876#define OPT_88_COLORS 0
877#endif
878
879#if OPT_88_COLORS && OPT_256_COLORS
880/* 256 colors supersedes 88 colors */
881#undef  OPT_88_COLORS
882#define OPT_88_COLORS 0
883#endif
884
885/***====================================================================***/
886
887/*
888 * Indices for menu_font_names[][]
889 */
890typedef enum {
891    fNorm = 0			/* normal font */
892    , fBold			/* bold font */
893#if OPT_WIDE_ATTRS || OPT_RENDERWIDE
894    , fItal			/* italic font */
895    , fBtal			/* bold-italic font */
896#endif
897#if OPT_WIDE_CHARS
898    , fWide			/* double-width font */
899    , fWBold			/* double-width bold font */
900    , fWItal			/* double-width italic font */
901    , fWBtal			/* double-width bold-italic font */
902#endif
903    , fMAX
904} VTFontEnum;
905
906/*
907 * Indices for cachedGCs.c (unrelated to VTFontEnum).
908 */
909typedef enum {
910    gcNorm = 0
911    , gcBold
912    , gcNormReverse
913    , gcBoldReverse
914    , gcFiller
915    , gcBorder
916#if OPT_BOX_CHARS
917    , gcLine
918    , gcDots
919#endif
920#if OPT_DEC_CHRSET
921    , gcCNorm
922    , gcCBold
923#endif
924#if OPT_WIDE_CHARS
925    , gcWide
926    , gcWBold
927    , gcWideReverse
928    , gcWBoldReverse
929#endif
930    , gcVTcursNormal
931    , gcVTcursFilled
932    , gcVTcursReverse
933    , gcVTcursOutline
934#if OPT_TEK4014
935    , gcTKcurs
936#endif
937    , gcMAX
938} CgsEnum;
939
940#define for_each_text_gc(n) for (n = gcNorm; n < gcVTcursNormal; ++n)
941#define for_each_curs_gc(n) for (n = gcVTcursNormal; n <= gcVTcursOutline; ++n)
942#define for_each_gc(n)      for (n = gcNorm; n < gcMAX; ++n)
943
944/*
945 * Indices for the normal terminal colors in screen.Tcolors[].
946 * See also OscTextColors, which has corresponding values.
947 */
948typedef enum {
949    TEXT_FG = 0			/* text foreground */
950    , TEXT_BG			/* text background */
951    , TEXT_CURSOR		/* text cursor */
952    , MOUSE_FG			/* mouse foreground */
953    , MOUSE_BG			/* mouse background */
954#if OPT_TEK4014
955    , TEK_FG = 5		/* tektronix foreground */
956    , TEK_BG			/* tektronix background */
957#endif
958#if OPT_HIGHLIGHT_COLOR
959    , HIGHLIGHT_BG = 7		/* highlight background */
960#endif
961#if OPT_TEK4014
962    , TEK_CURSOR = 8		/* tektronix cursor */
963#endif
964#if OPT_HIGHLIGHT_COLOR
965    , HIGHLIGHT_FG = 9		/* highlight foreground */
966#endif
967    , NCOLORS			/* total number of colors */
968} TermColors;
969
970/*
971 * Definitions for exec-formatted and insert-formatted actions.
972 */
973typedef void (*FormatSelect) (Widget, char *, char *, CELL *, CELL *);
974
975typedef struct {
976    Boolean done;
977    char *format;
978    char *buffer;
979    FormatSelect format_select;
980#if OPT_PASTE64
981    Cardinal base64_paste;
982#endif
983#if OPT_PASTE64 || OPT_READLINE
984    unsigned paste_brackets;
985#endif
986} InternalSelect;
987
988/*
989 * Constants for titleModes resource
990 */
991typedef enum {
992    tmSetBase16 = 1		/* set title using hex-string */
993    , tmGetBase16 = 2		/* get title using hex-string */
994#if OPT_WIDE_CHARS
995    , tmSetUtf8 = 4		/* like utf8Title, but controllable */
996    , tmGetUtf8 = 8		/* retrieve title encoded as UTF-8 */
997#endif
998} TitleModes;
999
1000#define IsTitleMode(xw,mode) (((xw)->screen.title_modes & mode) != 0)
1001
1002#include <xcharmouse.h>
1003
1004/*
1005 * For readability...
1006 */
1007#define nrc_percent   100
1008#define nrc_dquote    200
1009#define nrc_ampersand 300
1010typedef enum {
1011    nrc_ASCII = 0
1012    ,nrc_British		/* vt100 */
1013    ,nrc_British_Latin_1	/* vt3xx */
1014    ,nrc_DEC_Cyrillic		/* vt5xx */
1015    ,nrc_DEC_Spec_Graphic	/* vt100 */
1016    ,nrc_DEC_Alt_Chars		/* vt100 */
1017    ,nrc_DEC_Alt_Graphics	/* vt100 */
1018    ,nrc_DEC_Supp		/* vt2xx */
1019    ,nrc_DEC_Supp_Graphic	/* vt3xx */
1020    ,nrc_DEC_Technical		/* vt3xx */
1021    ,nrc_Dutch			/* vt2xx */
1022    ,nrc_Finnish		/* vt2xx */
1023    ,nrc_Finnish2		/* vt2xx */
1024    ,nrc_French			/* vt2xx */
1025    ,nrc_French2		/* vt2xx */
1026    ,nrc_French_Canadian	/* vt2xx */
1027    ,nrc_French_Canadian2	/* vt3xx */
1028    ,nrc_German			/* vt2xx */
1029    ,nrc_Greek			/* vt5xx */
1030    ,nrc_DEC_Greek_Supp		/* vt5xx */
1031    ,nrc_ISO_Greek_Supp		/* vt5xx */
1032    ,nrc_DEC_Hebrew_Supp	/* vt5xx */
1033    ,nrc_Hebrew			/* vt5xx */
1034    ,nrc_ISO_Hebrew_Supp	/* vt5xx */
1035    ,nrc_Italian		/* vt2xx */
1036    ,nrc_ISO_Latin_1_Supp	/* vt5xx */
1037    ,nrc_ISO_Latin_2_Supp	/* vt5xx */
1038    ,nrc_ISO_Latin_5_Supp	/* vt5xx */
1039    ,nrc_ISO_Latin_Cyrillic	/* vt5xx */
1040    ,nrc_Norwegian_Danish	/* vt3xx */
1041    ,nrc_Norwegian_Danish2	/* vt2xx */
1042    ,nrc_Norwegian_Danish3	/* vt2xx */
1043    ,nrc_Portugese		/* vt3xx */
1044    ,nrc_Russian		/* vt5xx */
1045    ,nrc_SCS_NRCS		/* vt5xx - probably Serbo/Croatian */
1046    ,nrc_Spanish		/* vt2xx */
1047    ,nrc_Swedish		/* vt2xx */
1048    ,nrc_Swedish2		/* vt2xx */
1049    ,nrc_Swiss			/* vt2xx */
1050    ,nrc_DEC_Turkish_Supp	/* vt5xx */
1051    ,nrc_Turkish		/* vt5xx */
1052    ,nrc_Unknown
1053} DECNRCM_codes;
1054
1055/*
1056 * Use this enumerated type to check consistency among dpmodes(), savemodes()
1057 * restoremodes() and do_dec_rqm().
1058 */
1059typedef enum {
1060    srm_DECCKM = 1
1061    ,srm_DECANM = 2
1062    ,srm_DECCOLM = 3
1063    ,srm_DECSCLM = 4
1064    ,srm_DECSCNM = 5
1065    ,srm_DECOM = 6
1066    ,srm_DECAWM = 7
1067    ,srm_DECARM = 8
1068    ,srm_X10_MOUSE = SET_X10_MOUSE
1069#if OPT_TOOLBAR
1070    ,srm_RXVT_TOOLBAR = 10
1071#endif
1072#if OPT_BLINK_CURS
1073    ,srm_ATT610_BLINK = 12
1074    ,srm_CURSOR_BLINK_OPS = 13
1075    ,srm_XOR_CURSOR_BLINKS = 14
1076#endif
1077    ,srm_DECPFF = 18
1078    ,srm_DECPEX = 19
1079    ,srm_DECTCEM = 25
1080    ,srm_RXVT_SCROLLBAR = 30
1081#if OPT_SHIFT_FONTS
1082    ,srm_RXVT_FONTSIZE = 35
1083#endif
1084#if OPT_TEK4014
1085    ,srm_DECTEK = 38
1086#endif
1087    ,srm_132COLS = 40
1088    ,srm_CURSES_HACK = 41
1089    ,srm_DECNRCM = 42
1090#if OPT_PRINT_GRAPHICS
1091    ,srm_DECGEPM = 43		/* Graphics Expanded Print Mode */
1092#endif
1093    ,srm_MARGIN_BELL = 44	/* also DECGPCM (Graphics Print Color Mode) */
1094    ,srm_REVERSEWRAP = 45	/* also DECGPCS (Graphics Print Color Syntax) */
1095#ifdef ALLOWLOGGING
1096    ,srm_ALLOWLOGGING = 46	/* also DECGPBM (Graphics Print Background Mode) */
1097#elif OPT_PRINT_GRAPHICS
1098    ,srm_DECGPBM = 46		/* Graphics Print Background Mode */
1099#endif
1100    ,srm_ALTBUF = 47		/* also DECGRPM (Graphics Rotated Print Mode) */
1101    ,srm_DECNKM = 66
1102    ,srm_DECBKM = 67
1103    ,srm_DECLRMM = 69
1104#if OPT_SIXEL_GRAPHICS
1105    ,srm_DECSDM = 80		/* Sixel Display Mode */
1106#endif
1107    ,srm_DECNCSM = 95
1108    ,srm_VT200_MOUSE = SET_VT200_MOUSE
1109    ,srm_VT200_HIGHLIGHT_MOUSE = SET_VT200_HIGHLIGHT_MOUSE
1110    ,srm_BTN_EVENT_MOUSE = SET_BTN_EVENT_MOUSE
1111    ,srm_ANY_EVENT_MOUSE = SET_ANY_EVENT_MOUSE
1112#if OPT_FOCUS_EVENT
1113    ,srm_FOCUS_EVENT_MOUSE = SET_FOCUS_EVENT_MOUSE
1114#endif
1115    ,srm_EXT_MODE_MOUSE = SET_EXT_MODE_MOUSE
1116    ,srm_SGR_EXT_MODE_MOUSE = SET_SGR_EXT_MODE_MOUSE
1117    ,srm_URXVT_EXT_MODE_MOUSE = SET_URXVT_EXT_MODE_MOUSE
1118    ,srm_PIXEL_POSITION_MOUSE = SET_PIXEL_POSITION_MOUSE
1119    ,srm_ALTERNATE_SCROLL = SET_ALTERNATE_SCROLL
1120    ,srm_RXVT_SCROLL_TTY_OUTPUT = 1010
1121    ,srm_RXVT_SCROLL_TTY_KEYPRESS = 1011
1122    ,srm_EIGHT_BIT_META = 1034
1123#if OPT_NUM_LOCK
1124    ,srm_REAL_NUMLOCK = 1035
1125    ,srm_META_SENDS_ESC = 1036
1126#endif
1127    ,srm_DELETE_IS_DEL = 1037
1128#if OPT_NUM_LOCK
1129    ,srm_ALT_SENDS_ESC = 1039
1130#endif
1131    ,srm_KEEP_SELECTION = 1040
1132    ,srm_SELECT_TO_CLIPBOARD = 1041
1133    ,srm_BELL_IS_URGENT = 1042
1134    ,srm_POP_ON_BELL = 1043
1135    ,srm_KEEP_CLIPBOARD = 1044
1136    ,srm_ALLOW_ALTBUF = 1046
1137    ,srm_OPT_ALTBUF = 1047
1138    ,srm_SAVE_CURSOR = 1048
1139    ,srm_OPT_ALTBUF_CURSOR = 1049
1140#if OPT_TCAP_FKEYS
1141    ,srm_TCAP_FKEYS = 1050
1142#endif
1143#if OPT_SUN_FUNC_KEYS
1144    ,srm_SUN_FKEYS = 1051
1145#endif
1146#if OPT_HP_FUNC_KEYS
1147    ,srm_HP_FKEYS = 1052
1148#endif
1149#if OPT_SCO_FUNC_KEYS
1150    ,srm_SCO_FKEYS = 1053
1151#endif
1152    ,srm_LEGACY_FKEYS = 1060
1153#if OPT_SUNPC_KBD
1154    ,srm_VT220_FKEYS = 1061
1155#endif
1156#if OPT_GRAPHICS
1157    ,srm_PRIVATE_COLOR_REGISTERS = 1070
1158#endif
1159#if OPT_PASTE64 || OPT_READLINE
1160    ,srm_PASTE_IN_BRACKET = SET_PASTE_IN_BRACKET
1161#endif
1162#if OPT_READLINE
1163    ,srm_BUTTON1_MOVE_POINT = SET_BUTTON1_MOVE_POINT
1164    ,srm_BUTTON2_MOVE_POINT = SET_BUTTON2_MOVE_POINT
1165    ,srm_DBUTTON3_DELETE = SET_DBUTTON3_DELETE
1166    ,srm_PASTE_QUOTE = SET_PASTE_QUOTE
1167    ,srm_PASTE_LITERAL_NL = SET_PASTE_LITERAL_NL
1168#endif				/* OPT_READLINE */
1169#if OPT_SIXEL_GRAPHICS
1170    ,srm_SIXEL_SCROLLS_RIGHT = 8452
1171#endif
1172} DECSET_codes;
1173
1174/* internal codes for selection atoms */
1175typedef enum {
1176    PRIMARY_CODE = 0
1177    ,CLIPBOARD_CODE
1178    ,SECONDARY_CODE
1179    ,MAX_SELECTION_CODES
1180} SelectionCodes;
1181
1182/* indices for mapping multiple clicks to selection types */
1183typedef enum {
1184    Select_CHAR=0
1185    ,Select_WORD
1186    ,Select_LINE
1187    ,Select_GROUP
1188    ,Select_PAGE
1189    ,Select_ALL
1190#if OPT_SELECT_REGEX
1191    ,Select_REGEX
1192#endif
1193    ,NSELECTUNITS
1194} SelectUnit;
1195
1196#if OPT_BLINK_CURS
1197typedef enum {
1198    cbFalse = 0
1199    , cbTrue
1200    , cbAlways
1201    , cbNever
1202    , cbLAST
1203} BlinkOps;
1204#endif
1205
1206typedef enum {
1207    ecSetColor = 1
1208    , ecGetColor
1209    , ecGetAnsiColor
1210    , ecLAST
1211} ColorOps;
1212
1213typedef enum {
1214    efSetFont = 1
1215    , efGetFont
1216    , efLAST
1217} FontOps;
1218
1219typedef enum {
1220    esFalse = 0
1221    , esTrue
1222    , esAlways
1223    , esNever
1224    , esLAST
1225} FullscreenOps;
1226
1227#ifndef NO_ACTIVE_ICON
1228typedef enum {
1229    eiFalse = 0
1230    , eiTrue
1231    , eiDefault
1232    , eiLAST
1233} AIconOps;
1234#endif
1235
1236typedef enum {
1237    emX10 = 1
1238    , emLocator
1239    , emVT200Click
1240    , emVT200Hilite
1241    , emAnyButton
1242    , emAnyEvent
1243    , emFocusEvent
1244    , emExtended
1245    , emSGR
1246    , emURXVT
1247    , emAlternateScroll
1248    , emLAST
1249} MouseOps;
1250
1251typedef enum {
1252#define DATA(name) ep##name
1253    DATA(NUL) = 0
1254    , DATA(SOH) =  1
1255    , DATA(STX) =  2
1256    , DATA(ETX) =  3
1257    , DATA(EOT) =  4
1258    , DATA(ENQ) =  5
1259    , DATA(ACK) =  6
1260    , DATA(BEL) =  7
1261    , DATA(BS)  =  8
1262    , DATA(HT)  =  9
1263    , DATA(LF)  = 10
1264    , DATA(VT)  = 11
1265    , DATA(FF)  = 12
1266    , DATA(CR)  = 13
1267    , DATA(SO)  = 14
1268    , DATA(SI)  = 15
1269    , DATA(DLE) = 16
1270    , DATA(DC1) = 17
1271    , DATA(DC2) = 18
1272    , DATA(DC3) = 19
1273    , DATA(DC4) = 20
1274    , DATA(NAK) = 21
1275    , DATA(SYN) = 22
1276    , DATA(ETB) = 23
1277    , DATA(CAN) = 24
1278    , DATA(EM)  = 25
1279    , DATA(SUB) = 26
1280    , DATA(ESC) = 27
1281    , DATA(FS)  = 28
1282    , DATA(GS)  = 29
1283    , DATA(RS)  = 30
1284    , DATA(US)  = 31
1285    /* aliases */
1286    , DATA(C0)
1287    , DATA(DEL)
1288#undef DATA
1289    , epLAST
1290} PasteControls;
1291
1292typedef enum {			/* legal values for keyboard.shift_escape */
1293    ssFalse = 0
1294    , ssTrue = 1
1295    , ssAlways = 2
1296    , ssNever = 3
1297    , ssLAST
1298} ShiftEscapeOps;
1299
1300/*
1301 * xterm uses these codes for the its push-SGR feature.  They match where
1302 * possible the corresponding SGR coding.  The foreground and background colors
1303 * do not fit into that scheme (because they are a set of ranges), so those are
1304 * chosen arbitrarily -TD
1305 */
1306typedef enum {
1307    psBOLD = 1
1308#if OPT_WIDE_ATTRS
1309    , psATR_FAINT = 2
1310    , psATR_ITALIC = 3
1311#endif
1312    , psUNDERLINE = 4
1313    , psBLINK = 5
1314    , psINVERSE = 7
1315    , psINVISIBLE = 8
1316#if OPT_WIDE_ATTRS
1317    , psATR_STRIKEOUT = 9
1318#endif
1319    /* SGR 10-19 correspond to primary/alternate fonts, currently unused */
1320#if OPT_ISO_COLORS
1321    , psFG_COLOR_obs = 10
1322    , psBG_COLOR_obs = 11
1323#endif
1324#if OPT_WIDE_ATTRS
1325    , psATR_DBL_UNDER = 21
1326#endif
1327    /* SGR 22-29 mostly are used to reset SGR 1-9 */
1328#if OPT_ISO_COLORS
1329    , psFG_COLOR = 30	/* stack maps many colors to one state */
1330    , psBG_COLOR = 31
1331#endif
1332    , MAX_PUSH_SGR
1333} PushSGR;
1334
1335typedef enum {
1336    etSetTcap = 1
1337    , etGetTcap
1338    , etLAST
1339} TcapOps;
1340
1341typedef enum {
1342    /* 1-23 are chosen to be the same as the control-sequence coding */
1343    ewRestoreWin = 1
1344    , ewMinimizeWin = 2
1345    , ewSetWinPosition = 3
1346    , ewSetWinSizePixels = 4
1347    , ewRaiseWin = 5
1348    , ewLowerWin = 6
1349    , ewRefreshWin = 7
1350    , ewSetWinSizeChars = 8
1351#if OPT_MAXIMIZE
1352    , ewMaximizeWin = 9
1353    , ewFullscreenWin = 10
1354#endif
1355    , ewGetWinState = 11
1356    , ewGetWinPosition = 13
1357    , ewGetWinSizePixels = 14
1358#if OPT_MAXIMIZE
1359    , ewGetScreenSizePixels = 15
1360    , ewGetCharSizePixels = 16
1361#endif
1362    , ewGetWinSizeChars = 18
1363#if OPT_MAXIMIZE
1364    , ewGetScreenSizeChars = 19
1365#endif
1366    , ewGetIconTitle = 20
1367    , ewGetWinTitle = 21
1368    , ewPushTitle = 22
1369    , ewPopTitle = 23
1370    /* these do not fit into that scheme, which is why we use an array */
1371    , ewSetWinLines
1372    , ewSetXprop
1373    , ewGetSelection
1374    , ewSetSelection
1375    , ewGetChecksum
1376    , ewSetChecksum
1377    /* get the size of the array... */
1378    , ewLAST
1379} WindowOps;
1380
1381/***====================================================================***/
1382
1383#define	COLOR_DEFINED(s,w)	((s)->which & (unsigned) (1<<(w)))
1384#define	COLOR_VALUE(s,w)	((s)->colors[w])
1385#define	SET_COLOR_VALUE(s,w,v)	(((s)->colors[w] = (v)), UIntSet((s)->which, (1<<(w))))
1386
1387#define	COLOR_NAME(s,w)		((s)->names[w])
1388#define	SET_COLOR_NAME(s,w,v)	(((s)->names[w] = (v)), ((s)->which |= (unsigned) (1<<(w))))
1389
1390#define	UNDEFINE_COLOR(s,w)	((s)->which &= (~((w)<<1)))
1391
1392/***====================================================================***/
1393
1394#if OPT_ISO_COLORS
1395#if OPT_WIDE_ATTRS
1396#define COLOR_FLAGS		(FG_COLOR | BG_COLOR | ATR_DIRECT_FG | ATR_DIRECT_BG)
1397#else
1398#define COLOR_FLAGS		(FG_COLOR | BG_COLOR)
1399#endif
1400#define TERM_COLOR_FLAGS(xw)	((xw)->flags & COLOR_FLAGS)
1401#define COLOR_0		0
1402#define COLOR_1		1
1403#define COLOR_2		2
1404#define COLOR_3		3
1405#define COLOR_4		4
1406#define COLOR_5		5
1407#define COLOR_6		6
1408#define COLOR_7		7
1409#define COLOR_8		8
1410#define COLOR_9		9
1411#define COLOR_10	10
1412#define COLOR_11	11
1413#define COLOR_12	12
1414#define COLOR_13	13
1415#define COLOR_14	14
1416#define COLOR_15	15
1417#define MIN_ANSI_COLORS 16
1418
1419#if OPT_256_COLORS
1420# define NUM_ANSI_COLORS 256
1421#elif OPT_88_COLORS
1422# define NUM_ANSI_COLORS 88
1423#else
1424# define NUM_ANSI_COLORS MIN_ANSI_COLORS
1425#endif
1426
1427#define okIndexedColor(n) ((n) >= 0 && (n) < NUM_ANSI_COLORS)
1428
1429#if NUM_ANSI_COLORS > MIN_ANSI_COLORS
1430# define OPT_EXT_COLORS  1
1431#else
1432# define OPT_EXT_COLORS  0
1433#endif
1434
1435#define COLOR_BD	(NUM_ANSI_COLORS)	/* BOLD */
1436#define COLOR_UL	(NUM_ANSI_COLORS+1)	/* UNDERLINE */
1437#define COLOR_BL	(NUM_ANSI_COLORS+2)	/* BLINK */
1438#define COLOR_RV	(NUM_ANSI_COLORS+3)	/* REVERSE */
1439
1440#if OPT_WIDE_ATTRS
1441#define COLOR_IT	(NUM_ANSI_COLORS+4)	/* ITALIC */
1442#define MAXCOLORS	(NUM_ANSI_COLORS+5)
1443#else
1444#define MAXCOLORS	(NUM_ANSI_COLORS+4)
1445#endif
1446
1447#ifndef DFT_COLORMODE
1448#define DFT_COLORMODE True	/* default colorMode resource */
1449#endif
1450
1451#define UseItalicFont(screen) (!(screen)->colorITMode)
1452
1453#define ReverseOrHilite(screen,flags,hilite) \
1454		(( screen->colorRVMode && hilite ) || \
1455		    ( !screen->colorRVMode && \
1456		      (( (flags & INVERSE) && !hilite) || \
1457		       (!(flags & INVERSE) &&  hilite)) ))
1458
1459#else	/* !OPT_ISO_COLORS */
1460
1461#define TERM_COLOR_FLAGS(xw) 0
1462
1463#define UseItalicFont(screen) True
1464#define ReverseOrHilite(screen,flags,hilite) \
1465		      (( (flags & INVERSE) && !hilite) || \
1466		       (!(flags & INVERSE) &&  hilite))
1467
1468#endif	/* OPT_ISO_COLORS */
1469
1470typedef enum {
1471	XK_TCAPNAME = 3
1472	/* Define fake XK codes, we need those for the fake color response in
1473	 * xtermcapKeycode().
1474	 */
1475#if OPT_ISO_COLORS
1476	, XK_COLORS
1477	, XK_RGB
1478#endif
1479} TcapQuery;
1480
1481#if OPT_AIX_COLORS
1482#define if_OPT_AIX_COLORS(screen, code) if(screen->colorMode) code
1483#else
1484#define if_OPT_AIX_COLORS(screen, code) /* nothing */
1485#endif
1486
1487#if OPT_256_COLORS || OPT_88_COLORS || OPT_ISO_COLORS
1488# define if_OPT_ISO_COLORS(screen, code) if (screen->colorMode) code
1489#else
1490# define if_OPT_ISO_COLORS(screen, code) /* nothing */
1491#endif
1492
1493#if OPT_DIRECT_COLOR
1494# define if_OPT_DIRECT_COLOR(screen, code) if (screen->direct_color) code
1495# define if_OPT_DIRECT_COLOR2(screen, test, code) if (screen->direct_color && (test)) code
1496#else
1497# define if_OPT_DIRECT_COLOR(screen, code) /* nothing */
1498# define if_OPT_DIRECT_COLOR2(screen, test, code) /* nothing */
1499#endif
1500
1501#define if_OPT_DIRECT_COLOR2_else(cond, test, stmt) \
1502	if_OPT_DIRECT_COLOR2(cond, test, stmt else)
1503
1504#define COLOR_RES_NAME(root) "color" root
1505
1506#if OPT_COLOR_CLASS
1507#define COLOR_RES_CLASS(root) "Color" root
1508#else
1509#define COLOR_RES_CLASS(root) XtCForeground
1510#endif
1511
1512#define COLOR_RES(root,offset,value) Sres(COLOR_RES_NAME(root), COLOR_RES_CLASS(root), offset.resource, value)
1513#define COLOR_RES2(name,class,offset,value) Sres(name, class, offset.resource, value)
1514
1515#define CLICK_RES_NAME(count)  "on" count "Clicks"
1516#define CLICK_RES_CLASS(count) "On" count "Clicks"
1517#define CLICK_RES(count,offset,value) Sres(CLICK_RES_NAME(count), CLICK_RES_CLASS(count), offset, value)
1518
1519/***====================================================================***/
1520
1521#if OPT_DEC_CHRSET
1522#define if_OPT_DEC_CHRSET(code) code
1523	/* Use 2 bits for encoding the double high/wide sense of characters */
1524#define CSET_SWL        0
1525#define CSET_DHL_TOP    1
1526#define CSET_DHL_BOT    2
1527#define CSET_DWL        3
1528#define NUM_CHRSET      8	/* normal/bold and 4 CSET_xxx values */
1529
1530	/* Use remaining bits for encoding the other character-sets */
1531#define CSET_NORMAL(code)  ((code) == CSET_SWL)
1532#define CSET_DOUBLE(code)  (!CSET_NORMAL(code) && !CSET_EXTEND(code))
1533#define CSET_EXTEND(code)  ((int)(code) > CSET_DWL)
1534
1535#define DBLCS_BITS            4
1536#define DBLCS_MASK            BITS2MASK(DBLCS_BITS)
1537
1538#define GetLineDblCS(ld)      (((ld)->bufHead >> LINEFLAG_BITS) & DBLCS_MASK)
1539#define SetLineDblCS(ld,cs)   (ld)->bufHead = (RowData) ((ld->bufHead & LINEFLAG_MASK) | (cs << LINEFLAG_BITS))
1540
1541#define LineCharSet(screen, ld) \
1542	(unsigned) ((CSET_DOUBLE(GetLineDblCS(ld))) \
1543		    ? GetLineDblCS(ld) \
1544		    : (screen)->cur_chrset)
1545#define LineMaxCol(screen, ld) \
1546	(CSET_DOUBLE(GetLineDblCS(ld)) \
1547	 ? (screen->max_col / 2) \
1548	 : (screen->max_col))
1549#define LineCursorX(screen, ld, col) \
1550	(CSET_DOUBLE(GetLineDblCS(ld)) \
1551	 ? CursorX(screen, 2*(col)) \
1552	 : CursorX(screen, (col)))
1553#define LineFontWidth(screen, ld) \
1554	(CSET_DOUBLE(GetLineDblCS(ld)) \
1555	 ? 2*FontWidth(screen) \
1556	 : FontWidth(screen))
1557#else
1558
1559#define if_OPT_DEC_CHRSET(code) /*nothing*/
1560#define CSET_SWL                        0
1561#define GetLineDblCS(ld)                0U
1562#define LineCharSet(screen, ld)         0U
1563#define LineMaxCol(screen, ld)          screen->max_col
1564#define LineCursorX(screen, ld, col)    CursorX(screen, col)
1565#define LineFontWidth(screen, ld)       FontWidth(screen)
1566
1567#endif
1568
1569#if OPT_LUIT_PROG && !OPT_WIDE_CHARS
1570/* Luit requires the wide-chars configuration */
1571#undef OPT_LUIT_PROG
1572#define OPT_LUIT_PROG 0
1573#endif
1574
1575/***====================================================================***/
1576
1577#if OPT_EBCDIC
1578extern int E2A(int);
1579extern int A2E(int);
1580#else
1581#define E2A(a) (a)
1582#define A2E(a) (a)
1583#endif
1584
1585#define CONTROL(a) (A2E(E2A(a)&037))
1586
1587/***====================================================================***/
1588
1589#if OPT_TEK4014
1590#define TEK4014_ACTIVE(xw)      ((xw)->misc.TekEmu)
1591#define TEK4014_SHOWN(xw)       ((xw)->misc.Tshow)
1592#define CURRENT_EMU_VAL(tek,vt) (TEK4014_ACTIVE(term) ? tek : vt)
1593#define CURRENT_EMU()           CURRENT_EMU_VAL((Widget)tekWidget, (Widget)term)
1594#else
1595#define TEK4014_ACTIVE(screen)  0
1596#define TEK4014_SHOWN(xw)       0
1597#define CURRENT_EMU_VAL(tek,vt) (vt)
1598#define CURRENT_EMU()           ((Widget)term)
1599#endif
1600
1601/***====================================================================***/
1602
1603#if OPT_TOOLBAR
1604#define SHELL_OF(widget) XtParent(XtParent(widget))
1605#else
1606#define SHELL_OF(widget) XtParent(widget)
1607#endif
1608
1609/***====================================================================***/
1610
1611#if OPT_VT52_MODE
1612#define if_OPT_VT52_MODE(screen, code) if(screen->vtXX_level == 0) code
1613#else
1614#define if_OPT_VT52_MODE(screen, code) /* nothing */
1615#endif
1616
1617/***====================================================================***/
1618
1619#if OPT_XMC_GLITCH
1620#define if_OPT_XMC_GLITCH(screen, code) if(screen->xmc_glitch) code
1621#define XMC_GLITCH 1	/* the character we'll show */
1622#define XMC_FLAGS (INVERSE|UNDERLINE|BOLD|BLINK)
1623#else
1624#define if_OPT_XMC_GLITCH(screen, code) /* nothing */
1625#endif
1626
1627/***====================================================================***/
1628
1629typedef unsigned IFlags;	/* at least 32 bits */
1630
1631#if OPT_WIDE_ATTRS
1632typedef unsigned short IAttr;	/* at least 16 bits */
1633#else
1634typedef unsigned char IAttr;	/* at least 8 bits */
1635#endif
1636
1637/***====================================================================***/
1638
1639#define LO_BYTE(ch) CharOf((ch) & 0xff)
1640#define HI_BYTE(ch) CharOf((ch) >> 8)
1641
1642#if OPT_WIDE_CHARS
1643#define if_OPT_WIDE_CHARS(screen, code) if(screen->wide_chars) code
1644#define if_WIDE_OR_NARROW(screen, wide, narrow) if(screen->wide_chars) wide else narrow
1645#define NARROW_ICHAR	0xffff
1646#if OPT_WIDER_ICHAR
1647#define WIDEST_ICHAR	0x1fffff
1648typedef unsigned IChar;		/* for 8-21 bit characters */
1649#else
1650#define WIDEST_ICHAR	NARROW_ICHAR
1651typedef unsigned short IChar;	/* for 8-16 bit characters */
1652#endif
1653#else
1654#define if_OPT_WIDE_CHARS(screen, code) /* nothing */
1655#define if_WIDE_OR_NARROW(screen, wide, narrow) narrow
1656typedef unsigned char IChar;	/* for 8-bit characters */
1657#endif
1658
1659/***====================================================================***/
1660
1661#ifndef RES_OFFSET
1662#define RES_OFFSET(offset) XtOffsetOf(XtermWidgetRec, offset)
1663#endif
1664
1665#define RES_NAME(name) name
1666#define RES_CLASS(name) name
1667
1668#define Bres(name, class, offset, dftvalue) \
1669	{RES_NAME(name), RES_CLASS(class), XtRBoolean, sizeof(Boolean), \
1670	 RES_OFFSET(offset), XtRImmediate, (XtPointer) dftvalue}
1671
1672#define Cres(name, class, offset, dftvalue) \
1673	{RES_NAME(name), RES_CLASS(class), XtRPixel, sizeof(Pixel), \
1674	 RES_OFFSET(offset), XtRString, DECONST(char,dftvalue)}
1675
1676#define Tres(name, class, offset, dftvalue) \
1677	COLOR_RES2(name, class, screen.Tcolors[offset], dftvalue) \
1678
1679#define Fres(name, class, offset, dftvalue) \
1680	{RES_NAME(name), RES_CLASS(class), XtRFontStruct, sizeof(XFontStruct *), \
1681	 RES_OFFSET(offset), XtRString, DECONST(char,dftvalue)}
1682
1683#define Ires(name, class, offset, dftvalue) \
1684	{RES_NAME(name), RES_CLASS(class), XtRInt, sizeof(int), \
1685	 RES_OFFSET(offset), XtRImmediate, (XtPointer) dftvalue}
1686
1687#define Dres(name, class, offset, dftvalue) \
1688	{RES_NAME(name), RES_CLASS(class), XtRFloat, sizeof(float), \
1689	 RES_OFFSET(offset), XtRString, DECONST(char,dftvalue)}
1690
1691#define Sres(name, class, offset, dftvalue) \
1692	{RES_NAME(name), RES_CLASS(class), XtRString, sizeof(char *), \
1693	 RES_OFFSET(offset), XtRString, DECONST(char,dftvalue)}
1694
1695#define Wres(name, class, offset, dftvalue) \
1696	{RES_NAME(name), RES_CLASS(class), XtRWidget, sizeof(Widget), \
1697	 RES_OFFSET(offset), XtRWidget, (XtPointer) dftvalue}
1698
1699/***====================================================================***/
1700
1701#define FRG_SIZE resource.minBufSize
1702#define BUF_SIZE resource.maxBufSize
1703
1704typedef struct {
1705	Char    *next;
1706	Char    *last;
1707	int      update;	/* HandleInterpret */
1708#if OPT_WIDE_CHARS
1709	IChar    utf_data;	/* resulting character */
1710	int      utf_size;	/* ...number of bytes decoded */
1711	Char    *write_buf;
1712	unsigned write_len;
1713#endif
1714	Char     buffer[1];
1715} PtyData;
1716
1717/***====================================================================***/
1718
1719/*
1720 * Pixel (and its components) are declared as unsigned long, but even for RGB
1721 * we need no more than 32-bits.
1722 */
1723typedef uint32_t MyPixel;
1724typedef int32_t MyColor;
1725
1726#if OPT_ISO_COLORS
1727#if OPT_DIRECT_COLOR
1728typedef struct {
1729    MyColor fg;
1730    MyColor bg;
1731} CellColor;
1732
1733#define isSameCColor(p,q) (!memcmp(&(p), &(q), sizeof(CellColor)))
1734
1735#elif OPT_256_COLORS || OPT_88_COLORS
1736
1737#define COLOR_BITS 8
1738typedef unsigned short CellColor;
1739
1740#else
1741
1742#define COLOR_BITS 4
1743typedef Char CellColor;
1744
1745#endif
1746#else
1747typedef unsigned CellColor;
1748#endif
1749
1750#define NO_COLOR		((unsigned)-1)
1751
1752#ifndef isSameCColor
1753#define isSameCColor(p,q)	((p) == (q))
1754#endif
1755
1756#define BITS2MASK(b)		((1 << b) - 1)
1757
1758#define COLOR_MASK		BITS2MASK(COLOR_BITS)
1759
1760#if OPT_DIRECT_COLOR
1761#define clrDirectFG(flags)	UIntClr(flags, ATR_DIRECT_FG)
1762#define clrDirectBG(flags)	UIntClr(flags, ATR_DIRECT_BG)
1763#define GetCellColorFG(data)	((data).fg)
1764#define GetCellColorBG(data)	((data).bg)
1765#define hasDirectFG(flags)	((flags) & ATR_DIRECT_FG)
1766#define hasDirectBG(flags)	((flags) & ATR_DIRECT_BG)
1767#define setDirectFG(flags,test)	if (test) UIntSet(flags, ATR_DIRECT_FG); else UIntClr(flags, ATR_DIRECT_FG)
1768#define setDirectBG(flags,test)	if (test) UIntSet(flags, ATR_DIRECT_BG); else UIntClr(flags, ATR_DIRECT_BG)
1769#elif OPT_ISO_COLORS
1770#define clrDirectFG(flags)	/* nothing */
1771#define clrDirectBG(flags)	/* nothing */
1772#define GetCellColorFG(data)	((data) & COLOR_MASK)
1773#define GetCellColorBG(data)	(((data) >> COLOR_BITS) & COLOR_MASK)
1774#define hasDirectFG(flags)	0
1775#define hasDirectBG(flags)	0
1776#define setDirectFG(flags,test)	(void)(test)
1777#define setDirectBG(flags,test)	(void)(test)
1778#else
1779#define GetCellColorFG(data)	7
1780#define GetCellColorBG(data)	0
1781#endif
1782extern CellColor blank_cell_color;
1783
1784typedef Char RowData;		/* wrap/blink, and DEC single-double chars */
1785
1786#define LINEFLAG_BITS		4
1787#define LINEFLAG_MASK		BITS2MASK(LINEFLAG_BITS)
1788
1789#define GetLineFlags(ld)	((ld)->bufHead & LINEFLAG_MASK)
1790
1791#if OPT_DEC_CHRSET
1792#define SetLineFlags(ld,xx)	(ld)->bufHead = (RowData) ((ld->bufHead & (DBLCS_MASK << LINEFLAG_BITS)) | (xx & LINEFLAG_MASK))
1793#else
1794#define SetLineFlags(ld,xx)	(ld)->bufHead = (RowData) (xx & LINEFLAG_MASK)
1795#endif
1796
1797typedef IChar CharData;
1798
1799/*
1800 * This is the xterm line-data/scrollback structure.
1801 */
1802typedef struct {
1803	Dimension lineSize;	/* number of columns in this row */
1804	RowData bufHead;	/* flag for wrapped lines */
1805#if OPT_WIDE_CHARS
1806	Char combSize;		/* number of items in combData[] */
1807#endif
1808	IAttr *attribs;		/* video attributes */
1809#if OPT_ISO_COLORS
1810	CellColor *color;	/* foreground+background color numbers */
1811#endif
1812	CharData *charData;	/* cell's base character */
1813	CharData *combData[1];	/* first enum past fixed-offsets */
1814} LineData;
1815
1816typedef const LineData CLineData;
1817
1818/*
1819 * We use CellData in a few places, when copying a cell's data to a temporary
1820 * variable.
1821 */
1822typedef struct {
1823	IAttr attribs;
1824#if OPT_WIDE_CHARS
1825	Char combSize;		/* number of items in combData[] */
1826#endif
1827#if OPT_ISO_COLORS
1828	CellColor color;	/* color-array */
1829#endif
1830	CharData charData;	/* cell's base character */
1831	CharData combData[1];	/* array of combining chars */
1832} CellData;
1833
1834#define for_each_combData(off, ld) for (off = 0; off < ld->combSize; ++off)
1835
1836#define Clear1Cell(ld, x) \
1837	do { \
1838	    ld->charData[x] = ' '; \
1839	    do { \
1840	    if_OPT_WIDE_CHARS(screen, { \
1841		size_t z; \
1842		for_each_combData(z, ld) { \
1843		    ld->combData[z][x] = '\0'; \
1844		} \
1845	    }) } while (0); \
1846	} while (0)
1847
1848#define Clear2Cell(dst, src, x) \
1849	do { \
1850	    dst->charData[x] = ' '; \
1851	    dst->attribs[x] = src->attribs[x]; \
1852	    do { \
1853	    if_OPT_ISO_COLORS(screen, { \
1854		dst->color[x] = src->color[x]; \
1855	    }) } while (0); \
1856	    do { \
1857	    if_OPT_WIDE_CHARS(screen, { \
1858		size_t z; \
1859		for_each_combData(z, dst) { \
1860		    dst->combData[z][x] = '\0'; \
1861		} \
1862	    }) } while (0); \
1863	} while (0)
1864
1865/*
1866 * Accommodate older compilers by not using variable-length arrays.
1867 */
1868#define SizeOfLineData  offsetof(LineData, combData)
1869#define SizeOfCellData  offsetof(CellData, combData)
1870
1871	/*
1872	 * A "row" is the index within the visible part of the screen, and an
1873	 * "inx" is the index within the whole set of scrollable lines.
1874	 */
1875#define ROW2INX(screen, row)	((row) + (screen)->topline)
1876#define INX2ROW(screen, inx)	((inx) - (screen)->topline)
1877
1878/* these are unused but could be useful for debugging */
1879#if 0
1880#define ROW2ABS(screen, row)	((row) + (screen)->savedlines)
1881#define INX2ABS(screen, inx)	ROW2ABS(screen, INX2ROW(screen, inx))
1882#endif
1883
1884#define okScrnRow(screen, row) \
1885	((row) <= ((screen)->max_row - (screen)->topline) \
1886      && (row) >= -((screen)->savedlines))
1887
1888	/*
1889	 * Cache data for "proportional" and other fonts containing a mixture
1890	 * of widths.
1891	 */
1892typedef struct {
1893	Bool		mixed;
1894	Dimension	min_width;	/* nominal cell width for 0..255 */
1895	Dimension	max_width;	/* maximum cell width */
1896} FontMap;
1897
1898#define KNOWN_MISSING	256
1899
1900typedef enum {
1901	fwNever = 0,
1902	fwResource,
1903	fwAlways
1904} fontWarningTypes;
1905
1906typedef struct {
1907	unsigned	chrset;
1908	unsigned	flags;
1909	fontWarningTypes warn;
1910	XFontStruct *	fs;
1911	char *		fn;
1912	FontMap		map;
1913	Char		known_missing[KNOWN_MISSING];
1914} XTermFonts;
1915
1916#if OPT_RENDERFONT
1917typedef enum {
1918	erFalse = 0
1919	, erTrue
1920	, erDefault
1921	, erDefaultOff
1922	, erLast
1923} RenderFont;
1924
1925#define DefaultRenderFont(xw) \
1926	if ((xw)->work.render_font == erDefault) \
1927	    (xw)->work.render_font = erFalse
1928
1929typedef enum {
1930    	xcEmpty = 0			/* slot is unused */
1931	, xcBogus			/* ignore this pattern */
1932	, xcOpened			/* slot has open font descriptor */
1933	, xcUnused			/* opened, but unused so far */
1934} XftCache;
1935
1936typedef struct {
1937	XftFont *	font;
1938	XftCache	usage;
1939} XTermXftCache;
1940
1941typedef struct {
1942	XftFont *	font;		/* main font */
1943	XftPattern *	pattern;	/* pattern for main font */
1944	XftFontSet *	fontset;	/* ordered list of fallback patterns */
1945	XTermXftCache * cache;
1946	unsigned	limit;		/* allocated size of cache[] */
1947	unsigned	opened;		/* number of slots with xcOpened */
1948	FontMap		map;
1949} XTermXftFonts;
1950
1951typedef	struct _ListXftFonts {
1952	struct _ListXftFonts *next;
1953	XftFont *	font;
1954} ListXftFonts;
1955#endif
1956
1957typedef struct {
1958	int		top;
1959	int		left;
1960	int		bottom;
1961	int		right;
1962} XTermRect;
1963
1964/***====================================================================***/
1965
1966	/* indices into save_modes[] */
1967typedef enum {
1968	DP_ALLOW_ALTBUF,
1969	DP_ALTERNATE_SCROLL,
1970	DP_ALT_SENDS_ESC,
1971	DP_BELL_IS_URGENT,
1972	DP_CRS_VISIBLE,
1973	DP_DECANM,
1974	DP_DECARM,
1975	DP_DECAWM,
1976	DP_DECBKM,
1977	DP_DECCKM,
1978	DP_DECCOLM,	/* IN132COLUMNS */
1979	DP_DECKPAM,
1980	DP_DECNRCM,
1981	DP_DECOM,
1982	DP_DECPEX,
1983	DP_DECPFF,
1984	DP_DECSCLM,
1985	DP_DECSCNM,
1986	DP_DECTCEM,
1987	DP_DELETE_IS_DEL,
1988	DP_EIGHT_BIT_META,
1989	DP_KEEP_CLIPBOARD,
1990	DP_KEEP_SELECTION,
1991	DP_KEYBOARD_TYPE,
1992	DP_POP_ON_BELL,
1993	DP_PRN_EXTENT,
1994	DP_PRN_FORMFEED,
1995	DP_RXVT_SCROLLBAR,
1996	DP_RXVT_SCROLL_TTY_KEYPRESS,
1997	DP_RXVT_SCROLL_TTY_OUTPUT,
1998	DP_SELECT_TO_CLIPBOARD,
1999	DP_X_ALTBUF,
2000	DP_X_DECCOLM,
2001	DP_X_EXT_MOUSE,
2002	DP_X_LOGGING,
2003	DP_X_LRMM,
2004	DP_X_MARGIN,
2005	DP_X_MORE,
2006	DP_X_MOUSE,
2007	DP_X_NCSM,
2008	DP_X_REVWRAP,
2009	DP_X_X10MSE,
2010#if OPT_BLINK_CURS
2011	DP_CRS_BLINK,
2012#endif
2013#if OPT_FOCUS_EVENT
2014	DP_X_FOCUS,
2015#endif
2016#if OPT_NUM_LOCK
2017	DP_REAL_NUMLOCK,
2018	DP_META_SENDS_ESC,
2019#endif
2020#if OPT_SHIFT_FONTS
2021	DP_RXVT_FONTSIZE,
2022#endif
2023#if OPT_SIXEL_GRAPHICS
2024	DP_DECSDM,
2025#endif
2026#if OPT_TEK4014
2027	DP_DECTEK,
2028#endif
2029#if OPT_TOOLBAR
2030	DP_TOOLBAR,
2031#endif
2032#if OPT_GRAPHICS
2033	DP_X_PRIVATE_COLOR_REGISTERS,
2034#endif
2035#if OPT_SIXEL_GRAPHICS
2036	DP_SIXEL_SCROLLS_RIGHT,
2037#endif
2038#if OPT_PRINT_GRAPHICS
2039	DP_DECGEPM,  /* Graphics Expanded Print Mode */
2040	DP_DECGPCM,  /* Graphics Print Color Mode */
2041	DP_DECGPCS,  /* Graphics Print Color Syntax */
2042	DP_DECGPBM,  /* Graphics Print Background Mode */
2043	DP_DECGRPM,  /* Graphics Rotated Print Mode */
2044#endif
2045	DP_LAST
2046} SaveModes;
2047
2048#define DoSM(code,value)  screen->save_modes[code] = (unsigned) (value)
2049#define DoRM(code,value)  value = (Boolean) screen->save_modes[code]
2050#define DoRM0(code,value) value = screen->save_modes[code]
2051
2052	/* index into vt_shell[] or tek_shell[] */
2053typedef enum {
2054	noMenu = -1
2055	,mainMenu
2056	,vtMenu
2057	,fontMenu
2058#if OPT_TEK4014
2059	,tekMenu
2060#endif
2061} MenuIndex;
2062
2063typedef enum {
2064	bvOff = -1,
2065	bvLow = 0,
2066	bvHigh
2067} BellVolume;
2068
2069#define NUM_POPUP_MENUS 4
2070
2071typedef struct {
2072	String		resource;
2073	Pixel		value;
2074	unsigned short red, green, blue;
2075	int		mode;		/* -1=invalid, 0=unset, 1=set   */
2076} ColorRes;
2077
2078/* these are set in getPrinterFlags */
2079typedef struct {
2080	int	printer_extent;		/* print complete page		*/
2081	int	printer_formfeed;	/* print formfeed per function	*/
2082	int	printer_newline;	/* print newline per function	*/
2083	int	print_attributes;	/* 0=off, 1=normal, 2=color	*/
2084	int	print_everything;	/* 0=all, 1=dft, 2=alt, 3=saved */
2085} PrinterFlags;
2086
2087typedef struct {
2088	FILE *	fp;			/* output file/pipe used	*/
2089	Boolean isOpen;			/* output was opened/tried	*/
2090	Boolean toFile;			/* true when directly to file	*/
2091	Boolean printer_checked;	/* printer_command is checked	*/
2092	String	printer_command;	/* pipe/shell command string	*/
2093	Boolean printer_autoclose;	/* close printer when offline	*/
2094	Boolean printer_extent;		/* print complete page		*/
2095	Boolean printer_formfeed;	/* print formfeed per function	*/
2096	Boolean printer_newline;	/* print newline per function	*/
2097	int	printer_controlmode;	/* 0=off, 1=auto, 2=controller	*/
2098	int	print_attributes;	/* 0=off, 1=normal, 2=color	*/
2099	int	print_everything;	/* 0=all, 1=dft, 2=alt, 3=saved */
2100} PrinterState;
2101
2102typedef struct {
2103	unsigned	which;		/* must have NCOLORS bits */
2104	Pixel		colors[NCOLORS];
2105	char		*names[NCOLORS];
2106} ScrnColors;
2107
2108#define NUM_GSETS 4
2109
2110typedef struct {
2111	Boolean		saved;
2112	int		row;
2113	int		col;
2114	IFlags		flags;		/* VTxxx saves graphics rendition */
2115	Char		curgl;
2116	Char		curgr;
2117	DECNRCM_codes	gsets[NUM_GSETS];
2118	Boolean		wrap_flag;
2119#if OPT_ISO_COLORS
2120	int		cur_foreground;  /* current foreground color	*/
2121	int		cur_background;  /* current background color	*/
2122	int		sgr_foreground;  /* current SGR foreground color */
2123	int		sgr_background;  /* current SGR background color */
2124	Boolean		sgr_38_xcolors;  /* true if ISO 8613 extension	*/
2125#endif
2126} SavedCursor;
2127
2128typedef struct _SaveTitle {
2129	struct _SaveTitle *next;
2130	char		*iconName;
2131	char		*windowName;
2132} SaveTitle;
2133
2134#define SAVED_CURSORS 2
2135
2136typedef struct {
2137	int		width;		/* if > 0, width of scrollbar,	*/
2138					/* and scrollbar is showing	*/
2139	Boolean		rv_cached;	/* see ScrollBarReverseVideo	*/
2140	int		rv_active;	/* ...current reverse-video	*/
2141	Pixel		bg;		/* ...cached background color	*/
2142	Pixel		fg;		/* ...cached foreground color	*/
2143	Pixel		bdr;		/* ...cached border color	*/
2144	Pixmap		bdpix;		/* ...cached border pixmap	*/
2145} SbInfo;
2146
2147#if OPT_TOOLBAR
2148typedef struct {
2149	Widget		menu_bar;	/* toolbar, if initialized	*/
2150	Dimension	menu_height;	/* ...and its height		*/
2151	Dimension	menu_border;	/* ...and its border		*/
2152} TbInfo;
2153#define VT100_TB_INFO(name) screen.fullVwin.tb_info.name
2154#endif
2155
2156typedef struct {
2157	Window		window;		/* X window id			*/
2158	int		width;		/* width of columns in pixels	*/
2159	int		height;		/* height of rows in pixels	*/
2160	Dimension	fullwidth;	/* full width of window		*/
2161	Dimension	fullheight;	/* full height of window	*/
2162	int		f_width;	/* width of fonts in pixels	*/
2163	int		f_height;	/* height of fonts in pixels	*/
2164	int		f_ascent;	/* ascent of font in pixels	*/
2165	int		f_descent;	/* descent of font in pixels	*/
2166	SbInfo		sb_info;
2167	GC		filler_gc;	/* filler's fg/bg		*/
2168	GC		border_gc;	/* inner border's fg/bg		*/
2169	GC		marker_gc[2];	/* wrap-marks			*/
2170#if USE_DOUBLE_BUFFER
2171	Drawable	drawable;	/* X drawable id                */
2172#endif
2173#if OPT_TOOLBAR
2174	Boolean		active;		/* true if toolbars are used	*/
2175	TbInfo		tb_info;	/* toolbar information		*/
2176#endif
2177} VTwin;
2178
2179typedef struct {
2180	Window		window;		/* X window id			*/
2181	int		width;		/* width of columns		*/
2182	int		height;		/* height of rows		*/
2183	Dimension	fullwidth;	/* full width of window		*/
2184	Dimension	fullheight;	/* full height of window	*/
2185	double		tekscale;	/* scale factor Tek -> vs100	*/
2186} TKwin;
2187
2188typedef struct {
2189    char *f_n;			/* the normal font */
2190    char *f_b;			/* the bold font */
2191#if OPT_WIDE_CHARS
2192    char *f_w;			/* the normal wide font */
2193    char *f_wb;			/* the bold wide font */
2194#endif
2195} VTFontNames;
2196
2197typedef struct {
2198    char **list_n;		/* the normal font */
2199    char **list_b;		/* the bold font */
2200#if OPT_WIDE_ATTRS || OPT_RENDERWIDE
2201    char **list_i;		/* italic font (Xft only) */
2202    char **list_bi;		/* bold-italic font (Xft only) */
2203#endif
2204#if OPT_WIDE_CHARS
2205    char **list_w;		/* the normal wide font */
2206    char **list_wb;		/* the bold wide font */
2207    char **list_wi;		/* wide italic font (Xft only) */
2208    char **list_wbi;		/* wide bold-italic font (Xft only) */
2209#endif
2210} VTFontList;
2211
2212typedef struct {
2213    VTFontList x11;
2214#if OPT_RENDERFONT
2215    VTFontList xft;
2216#endif
2217} XtermFontNames;
2218
2219typedef struct {
2220    VTFontNames default_font;
2221    String menu_font_names[NMENUFONTS][fMAX];
2222    XtermFontNames fonts;
2223} SubResourceRec;
2224
2225#if OPT_INPUT_METHOD
2226#define NINPUTWIDGETS	3
2227typedef struct {
2228	Widget		w;
2229	XIM		xim;		/* input method attached to 'w' */
2230	XIC		xic;		/* input context attached to 'xim' */
2231} TInput;
2232#endif
2233
2234typedef enum {
2235	CURSOR_BLOCK = 2
2236	, CURSOR_UNDERLINE = 4
2237	, CURSOR_BAR = 6
2238} XtCursorShape;
2239
2240#define isCursorBlock(s)	((s)->cursor_shape == CURSOR_BLOCK)
2241#define isCursorUnderline(s)	((s)->cursor_shape == CURSOR_UNDERLINE)
2242#define isCursorBar(s)		((s)->cursor_shape == CURSOR_BAR)
2243
2244typedef enum {
2245	DEFAULT_STYLE = 0
2246	, BLINK_BLOCK
2247	, STEADY_BLOCK
2248	, BLINK_UNDERLINE
2249	, STEADY_UNDERLINE
2250	, BLINK_BAR
2251	, STEADY_BAR
2252} XtCursorStyle;
2253
2254#if OPT_GRAPHICS
2255#define GraphicsTermId(screen) (\
2256	(screen)->graphics_termid \
2257	 ? (screen)->graphics_termid \
2258	 : (screen)->terminal_id)
2259#else
2260#define GraphicsTermId(screen) (screen)->terminal_id
2261#endif
2262
2263#if OPT_REGIS_GRAPHICS
2264#define optRegisGraphics(screen) \
2265	(GraphicsTermId(screen) == 125 || \
2266	 GraphicsTermId(screen) == 240 || \
2267	 GraphicsTermId(screen) == 241 || \
2268	 GraphicsTermId(screen) == 330 || \
2269	 GraphicsTermId(screen) == 340)
2270#else
2271#define optRegisGraphics(screen) False
2272#endif
2273
2274#if OPT_SIXEL_GRAPHICS
2275#define optSixelGraphics(screen) \
2276	(GraphicsTermId(screen) == 240 || \
2277	 GraphicsTermId(screen) == 241 || \
2278	 GraphicsTermId(screen) == 330 || \
2279	 GraphicsTermId(screen) == 340 || \
2280	 GraphicsTermId(screen) == 382)
2281#else
2282#define optSixelGraphics(screen) False
2283#endif
2284
2285#if OPT_PRINT_GRAPHICS
2286#define if_PRINT_GRAPHICS2(statement) if (optRegisGraphics(screen)) { statement; } else
2287#else
2288#define if_PRINT_GRAPHICS2(statement) /* nothing */
2289#endif
2290
2291typedef struct {
2292/* These parameters apply to both windows */
2293	Display		*display;	/* X display for screen		*/
2294	int		respond;	/* socket for responses
2295					   (position report, etc.)	*/
2296	int		nextEventDelay;	/* msecs to delay for x-events  */
2297/* These parameters apply to VT100 window */
2298	IChar		*unparse_bfr;
2299	unsigned	unparse_len;
2300	unsigned	unparse_max;	/* limitResponse resource	*/
2301
2302#if OPT_TCAP_QUERY
2303	int		tc_query_code;
2304	Bool		tc_query_fkey;
2305#endif
2306	pid_t		pid;		/* pid of process on far side   */
2307	uid_t		uid;		/* user id of actual person	*/
2308	gid_t		gid;		/* group id of actual person	*/
2309	ColorRes	Tcolors[NCOLORS]; /* terminal colors		*/
2310#if OPT_HIGHLIGHT_COLOR
2311	Boolean		hilite_color;	/* hilite colors override	*/
2312	Boolean		hilite_reverse;	/* hilite overrides reverse	*/
2313#endif
2314#if OPT_ISO_COLORS
2315	XColor *	cmap_data;	/* color table			*/
2316	unsigned	cmap_size;
2317	ColorRes	Acolors[MAXCOLORS]; /* ANSI color emulation	*/
2318	int		veryBoldColors;	/* modifier for boldColors	*/
2319	Boolean		boldColors;	/* can we make bold colors?	*/
2320	Boolean		colorMode;	/* are we using color mode?	*/
2321	Boolean		colorULMode;	/* use color for underline?	*/
2322	Boolean		italicULMode;	/* italic font for underline?	*/
2323	Boolean		colorBDMode;	/* use color for bold?		*/
2324	Boolean		colorBLMode;	/* use color for blink?		*/
2325	Boolean		colorRVMode;	/* use color for reverse?	*/
2326	Boolean		colorAttrMode;	/* prefer colorUL/BD to SGR	*/
2327#if OPT_WIDE_ATTRS
2328	Boolean		colorITMode;	/* use color for italics?	*/
2329#endif
2330#if OPT_DIRECT_COLOR
2331	Boolean		direct_color;	/* direct-color enabled?	*/
2332#endif
2333#endif /* OPT_ISO_COLORS */
2334#if OPT_DEC_CHRSET
2335	Boolean		font_doublesize;/* enable font-scaling		*/
2336	int		cache_doublesize;/* limit of our cache		*/
2337	Char		cur_chrset;	/* character-set index & code	*/
2338	int		fonts_used;	/* count items in double_fonts	*/
2339	XTermFonts	double_fonts[NUM_CHRSET];
2340#if OPT_RENDERFONT
2341	XftFont *	double_xft_fonts[NUM_CHRSET];
2342#endif
2343#endif /* OPT_DEC_CHRSET */
2344#if OPT_DEC_RECTOPS
2345	int		cur_decsace;	/* parameter for DECSACE	*/
2346	int		checksum_ext;	/* extensions for DECRQCRA	*/
2347	int		checksum_ext0;	/* initial checksumExtension	*/
2348#endif
2349#if OPT_WIDE_CHARS
2350	Boolean		wide_chars;	/* true when 16-bit chars	*/
2351	Boolean		vt100_graphics;	/* true to allow vt100-graphics	*/
2352	Boolean		utf8_inparse;	/* true to enable UTF-8 parser	*/
2353	Boolean		normalized_c;	/* true to precompose to Form C */
2354	char *		utf8_mode_s;	/* use UTF-8 decode/encode	*/
2355	char *		utf8_fonts_s;	/* use UTF-8 decode/encode	*/
2356	char *		utf8_title_s;	/* use UTF-8 titles		*/
2357	int		utf8_nrc_mode;	/* saved UTF-8 mode for DECNRCM */
2358	Boolean		utf8_always;	/* special case for wideChars	*/
2359	int		utf8_mode;	/* use UTF-8 decode/encode: 0-2	*/
2360	int		utf8_fonts;	/* use UTF-8 fonts: 0-2		*/
2361	int		utf8_title;	/* use UTF-8 EWHM props: 0-2	*/
2362	int		max_combining;	/* maximum # of combining chars	*/
2363	Boolean		utf8_latin1;	/* use UTF-8 with Latin-1 bias	*/
2364	Boolean		utf8_weblike;	/* use UTF-8 with browser bias	*/
2365	int		latin9_mode;	/* poor man's luit, latin9	*/
2366	int		unicode_font;	/* font uses unicode encoding	*/
2367	int		utf_count;	/* state of utf_char		*/
2368	IChar		utf_char;	/* in-progress character	*/
2369	Boolean		char_was_written;
2370	int		last_written_col;
2371	int		last_written_row;
2372	TypedBuffer(XChar2b);
2373	TypedBuffer(char);
2374#endif
2375#if OPT_BROKEN_OSC
2376	Boolean		brokenLinuxOSC; /* true to ignore Linux palette ctls */
2377#endif
2378#if OPT_BROKEN_ST
2379	Boolean		brokenStringTerm; /* true to match old OSC parse */
2380#endif
2381#if OPT_C1_PRINT || OPT_WIDE_CHARS
2382	Boolean		c1_printable;	/* true if we treat C1 as print	*/
2383#endif
2384	int		border;		/* inner border			*/
2385	int		scrollBarBorder; /* scrollBar border		*/
2386	long		event_mask;
2387	unsigned	send_mouse_pos;	/* user wants mouse transition  */
2388					/* and position information	*/
2389	int		extend_coords;	/* support large terminals	*/
2390#if OPT_FOCUS_EVENT
2391	Boolean		send_focus_pos; /* user wants focus in/out info */
2392#endif
2393	Boolean		quiet_grab;	/* true if no cursor change on focus */
2394#if OPT_PASTE64
2395	Cardinal	base64_paste;	/* set to send paste in base64	*/
2396	int		base64_final;	/* string-terminator for paste	*/
2397	/* _qWriteSelectionData expects these to be initialized to zero.
2398	 * base64_flush() is the last step of the conversion, it clears these
2399	 * variables.
2400	 */
2401	unsigned	base64_accu;
2402	unsigned	base64_count;
2403	unsigned	base64_pad;
2404#endif
2405#if OPT_PASTE64 || OPT_READLINE
2406	unsigned	paste_brackets;
2407	/* not part of bracketed-paste, these are here to simplify ifdefs */
2408	unsigned	dclick3_deletes;
2409	unsigned	paste_literal_nl;
2410#endif
2411#if OPT_READLINE
2412	unsigned	click1_moves;
2413	unsigned	paste_moves;
2414	unsigned	paste_quotes;
2415#endif	/* OPT_READLINE */
2416#if OPT_DEC_LOCATOR
2417	Boolean		locator_reset;	/* turn mouse off after 1 report? */
2418	Boolean		locator_pixels;	/* report in pixels?		*/
2419					/* if false, report in cells	*/
2420	unsigned	locator_events;	/* what events to report	*/
2421	Boolean		loc_filter;	/* is filter rectangle active?	*/
2422	int		loc_filter_top;	/* filter rectangle for DEC Locator */
2423	int		loc_filter_left;
2424	int		loc_filter_bottom;
2425	int		loc_filter_right;
2426#endif	/* OPT_DEC_LOCATOR */
2427	int		mouse_button;	/* current button pressed	*/
2428	int		mouse_row;	/* ...and its row		*/
2429	int		mouse_col;	/* ...and its column		*/
2430	int		select;		/* xterm selected		*/
2431	Boolean		bellOnReset;	/* bellOnReset			*/
2432	Boolean		visualbell;	/* visual bell mode		*/
2433	Boolean		poponbell;	/* pop on bell mode		*/
2434
2435	Boolean		eraseSavedLines; /* eraseSavedLines option	*/
2436	Boolean		eraseSavedLines0; /* initial eraseSavedLines	*/
2437	Boolean		tabCancelsWrap; /* tabCancelsWrap option	*/
2438
2439	Boolean		allowPasteControls; /* PasteControls mode	*/
2440	Boolean		allowColorOps;	/* ColorOps mode		*/
2441	Boolean		allowFontOps;	/* FontOps mode			*/
2442	Boolean		allowMouseOps;	/* MouseOps mode		*/
2443	Boolean		allowSendEvents;/* SendEvent mode		*/
2444	Boolean		allowTcapOps;	/* TcapOps mode			*/
2445	Boolean		allowTitleOps;	/* TitleOps mode		*/
2446	Boolean		allowWindowOps;	/* WindowOps mode		*/
2447
2448	Boolean		allowPasteControl0; /* PasteControls mode	*/
2449	Boolean		allowColorOp0;	/* initial ColorOps mode	*/
2450	Boolean		allowFontOp0;	/* initial FontOps mode		*/
2451	Boolean		allowMouseOp0;	/* initial MouseOps mode	*/
2452	Boolean		allowSendEvent0;/* initial SendEvent mode	*/
2453	Boolean		allowTcapOp0;	/* initial TcapOps mode		*/
2454	Boolean		allowTitleOp0;	/* initial TitleOps mode	*/
2455	Boolean		allowWindowOp0;	/* initial WindowOps mode	*/
2456
2457	String		disallowedColorOps;
2458	char		disallow_color_ops[ecLAST];
2459
2460	String		disallowedFontOps;
2461	char		disallow_font_ops[efLAST];
2462
2463	String		disallowedMouseOps;
2464	char		disallow_mouse_ops[emLAST];
2465
2466	String		disallowedPasteControls;
2467	char		disallow_paste_controls[epLAST];
2468
2469	String		disallowedTcapOps;
2470	char		disallow_tcap_ops[etLAST];
2471
2472	String		disallowedWinOps;
2473	char		disallow_win_ops[ewLAST];
2474
2475	Boolean		awaitInput;	/* select-timeout mode		*/
2476	Boolean		grabbedKbd;	/* keyboard is grabbed		*/
2477#ifdef ALLOWLOGGING
2478	int		logging;	/* logging mode			*/
2479	int		logfd;		/* file descriptor of log	*/
2480	char		*logfile;	/* log file name		*/
2481	Char		*logstart;	/* current start of log buffer	*/
2482#endif
2483	int		inhibit;	/* flags for inhibiting changes	*/
2484
2485/* VT window parameters */
2486	Boolean		Vshow;		/* VT window showing		*/
2487	VTwin		fullVwin;
2488	int		needSwap;
2489#ifndef NO_ACTIVE_ICON
2490	VTwin		iconVwin;
2491	VTwin		*whichVwin;
2492#endif /* NO_ACTIVE_ICON */
2493
2494	int		pointer_mode;	/* when to use hidden_cursor	*/
2495	int		pointer_mode0;	/* ...initial value             */
2496	Boolean 	hide_pointer;	/* true to use "hidden_cursor"  */
2497	String		pointer_shape;	/* name of shape in cursor font */
2498	Cursor		pointer_cursor;	/* current pointer cursor	*/
2499	Cursor		hidden_cursor;	/* hidden cursor in window	*/
2500
2501	String	answer_back;		/* response to ENQ		*/
2502
2503	PrinterState	printer_state;	/* actual printer state		*/
2504	PrinterFlags	printer_flags;	/* working copy of printer flags */
2505#if OPT_PRINT_ON_EXIT
2506	Boolean		write_error;
2507#endif
2508
2509	Boolean		fnt_prop;	/* true if proportional fonts	*/
2510	unsigned	fnt_boxes;	/* 0=no boxes, 1=old, 2=unicode */
2511	Boolean		force_packed;	/* true to override proportional */
2512#if OPT_BOX_CHARS
2513	Boolean		force_box_chars;/* true if we assume no boxchars */
2514	Boolean		broken_box_chars;/* true if broken boxchars	*/
2515	Boolean		force_all_chars;/* true to outline missing chars */
2516	Boolean		assume_all_chars;/* true to allow missing chars */
2517	Boolean		allow_packing;	/* true to allow packed-fonts	*/
2518#endif
2519	Dimension	fnt_wide;
2520	Dimension	fnt_high;
2521	float		scale_height;	/* scaling for font-height	*/
2522	XTermFonts	fnts[fMAX];	/* normal/bold/etc for terminal	*/
2523	Boolean		free_bold_box;	/* same_font_size's austerity	*/
2524	Boolean		allowBoldFonts;	/* do we use bold fonts at all? */
2525#if OPT_WIDE_ATTRS
2526	XTermFonts	ifnts[fMAX];	/* normal/bold/etc italic fonts */
2527	Boolean		ifnts_ok;	/* true if ifnts[] is cached	*/
2528#endif
2529#ifndef NO_ACTIVE_ICON
2530	XTermFonts	fnt_icon;	/* icon font			*/
2531	String		icon_fontname;	/* name of icon font		*/
2532	int		icon_fontnum;	/* number to use for icon font	*/
2533#endif /* NO_ACTIVE_ICON */
2534	int		enbolden;	/* overstrike for bold font	*/
2535	XPoint		*box;		/* draw unselected cursor	*/
2536
2537	int		cursor_state;	/* ON, OFF, or BLINKED_OFF	*/
2538	int		cursor_busy;	/* do not redraw...		*/
2539	Boolean		cursor_underline; /* true if cursor is in underline mode */
2540	XtCursorShape	cursor_shape;
2541#if OPT_BLINK_CURS
2542	BlinkOps	cursor_blink;	/* cursor blink enable		*/
2543	BlinkOps	cursor_blink_i;	/* save cursor blink enable	*/
2544	char *		cursor_blink_s;	/* ...resource cursorBlink	*/
2545	int		cursor_blink_esc; /* cursor blink escape-state	*/
2546	Boolean		cursor_blink_xor; /* how to merge menu/escapes	*/
2547#endif
2548#if OPT_BLINK_TEXT
2549	Boolean		blink_as_bold;	/* text blink disable		*/
2550#endif
2551#if OPT_BLINK_CURS || OPT_BLINK_TEXT
2552	int		blink_state;	/* ON, OFF, or BLINKED_OFF	*/
2553	int		blink_on;	/* cursor on time (msecs)	*/
2554	int		blink_off;	/* cursor off time (msecs)	*/
2555	XtIntervalId	blink_timer;	/* timer-id for cursor-proc	*/
2556#endif
2557#if OPT_ZICONBEEP
2558	Boolean		zIconBeep_flagged; /* True if icon name was changed */
2559#endif /* OPT_ZICONBEEP */
2560	int		cursor_GC;	/* see ShowCursor()		*/
2561	int		cursor_set;	/* requested state		*/
2562	CELL		cursorp;	/* previous cursor row/column	*/
2563	int		cur_col;	/* current cursor column	*/
2564	int		cur_row;	/* current cursor row		*/
2565	int		max_col;	/* rightmost column		*/
2566	int		max_row;	/* bottom row			*/
2567	int		top_marg;	/* top line of scrolling region */
2568	int		bot_marg;	/* bottom line of  "	    "	*/
2569	int		lft_marg;	/* left column of "	    "	*/
2570	int		rgt_marg;	/* right column of "	    "	*/
2571	Widget		scrollWidget;	/* pointer to scrollbar struct	*/
2572#if USE_DOUBLE_BUFFER
2573	int		buffered_sb;	/* nonzero when pending update	*/
2574	struct timeval	buffered_at;	/* reference time, for FPS	*/
2575#define DbeMsecs(xw)	(1000L / (long) resource.buffered_fps)
2576#endif
2577	/*
2578	 * Indices used to keep track of the top of the vt100 window and
2579	 * the saved lines, taking scrolling into account.
2580	 */
2581	int		topline;	/* line number of top, <= 0	*/
2582	long		saved_fifo;     /* number of lines that've ever been saved */
2583	int		savedlines;     /* number of lines that've been saved */
2584	int		savelines;	/* number of lines off top to save */
2585	int		scroll_amt;	/* amount to scroll		*/
2586	int		refresh_amt;	/* amount to refresh		*/
2587	/*
2588	 * Working variables for getLineData().
2589	 */
2590	size_t		lineExtra;	/* extra space for combining chars */
2591	size_t		cellExtra;	/* extra space for combining chars */
2592	/*
2593	 * Pointer to the current visible buffer.
2594	 */
2595	ScrnBuf		visbuf;		/* ptr to visible screen buf (main) */
2596	/*
2597	 * Data for the normal buffer, which may have saved lines to which
2598	 * the user can scroll.
2599	 */
2600	ScrnBuf		saveBuf_index;
2601	Char		*saveBuf_data;
2602	/*
2603	 * Data for visible and alternate buffer.
2604	 */
2605	ScrnBuf		editBuf_index[2];
2606	Char		*editBuf_data[2];
2607	int		whichBuf;	/* 0/1 for normal/alternate buf */
2608	Boolean		is_running;	/* true when buffers are legal	*/
2609	/*
2610	 * Workspace used for screen operations.
2611	 */
2612	Char		**save_ptr;	/* workspace for save-pointers  */
2613	size_t		save_len;	/* ...and its length		*/
2614
2615	int		scrolllines;	/* number of lines to button scroll */
2616	Boolean		alternateScroll; /* scroll-actions become keys */
2617	Boolean		scrollttyoutput; /* scroll to bottom on tty output */
2618	Boolean		scrollkey;	/* scroll to bottom on key	*/
2619	Boolean		cursor_moved;	/* scrolling makes cursor move	*/
2620
2621	Boolean		do_wrap;	/* true if cursor in last column
2622					    and character just output    */
2623
2624	int		incopy;		/* 0 idle; 1 XCopyArea issued;
2625					    -1 first GraphicsExpose seen,
2626					    but last not seen		*/
2627	int		copy_src_x;	/* params from last XCopyArea ... */
2628	int		copy_src_y;
2629	unsigned int	copy_width;
2630	unsigned int	copy_height;
2631	int		copy_dest_x;
2632	int		copy_dest_y;
2633
2634	Dimension	embed_wide;
2635	Dimension	embed_high;
2636
2637	Boolean		c132;		/* allow change to 132 columns	*/
2638	Boolean		curses;		/* kludge line wrap for more	*/
2639	Boolean		hp_ll_bc;	/* kludge HP-style ll for xdb	*/
2640	Boolean		marginbell;	/* true if margin bell on	*/
2641	int		nmarginbell;	/* columns from right margin	*/
2642	int		bellArmed;	/* cursor below bell margin	*/
2643	BellVolume	marginVolume;	/* margin-bell volume           */
2644	BellVolume	warningVolume;	/* warning-bell volume          */
2645	Boolean		multiscroll;	/* true if multi-scroll		*/
2646	int		scrolls;	/* outstanding scroll count,
2647					    used only with multiscroll	*/
2648	SavedCursor	sc[SAVED_CURSORS]; /* data for restore cursor	*/
2649	IFlags		save_modes[DP_LAST]; /* save dec/xterm private modes */
2650
2651	int		title_modes;	/* control set/get of titles	*/
2652	int		title_modes0;	/* ...initial value         	*/
2653	SaveTitle	*save_title;
2654
2655	/* Improved VT100 emulation stuff.				*/
2656	String		keyboard_dialect; /* default keyboard dialect	*/
2657	DECNRCM_codes	gsets[NUM_GSETS]; /* G0 through G3.		*/
2658	Char		curgl;		/* Current GL setting.		*/
2659	Char		curgr;		/* Current GR setting.		*/
2660	Char		curss;		/* Current single shift.	*/
2661	String		term_id;	/* resource for terminal_id	*/
2662	int		terminal_id;	/* 100=vt100, 220=vt220, etc.	*/
2663	int		vtXX_level;	/* 0=vt52, 1,2,3 = vt100 ... vt320 */
2664	int		ansi_level;	/* dpANSI levels 1,2,3		*/
2665	int		protected_mode;	/* 0=off, 1=DEC, 2=ISO		*/
2666	Boolean		always_bold_mode; /* compare normal/bold font	*/
2667	Boolean		always_highlight; /* whether to highlight cursor */
2668	Boolean		bold_mode;	/* use bold font or overstrike	*/
2669	Boolean		delete_is_del;	/* true for compatible Delete key */
2670	Boolean		jumpscroll;	/* whether we should jumpscroll */
2671	Boolean		fastscroll;	/* whether we should fastscroll */
2672	Boolean		old_fkeys;	/* true for compatible fkeys	*/
2673	Boolean		old_fkeys0;	/* ...initial value         	*/
2674	Boolean		underline;	/* whether to underline text	*/
2675
2676#if OPT_MAXIMIZE
2677	Boolean		restore_data;
2678	int		restore_x;
2679	int		restore_y;
2680	unsigned	restore_width;
2681	unsigned	restore_height;
2682#endif
2683
2684#if OPT_REGIS_GRAPHICS
2685	String		graphics_regis_default_font; /* font for "builtin" */
2686
2687	String		graphics_regis_screensize; /* given a size in pixels */
2688	Dimension	graphics_regis_def_wide; /* ...corresponding width   */
2689	Dimension	graphics_regis_def_high; /* ...and height            */
2690#endif
2691
2692#if OPT_GRAPHICS
2693	String		graph_termid;		/* resource for graphics_termid */
2694	int		graphics_termid;	/* based on terminal_id   */
2695	String		graphics_max_size;	/* given a size in pixels */
2696	Dimension	graphics_max_wide;	/* ...corresponding width */
2697	Dimension	graphics_max_high;	/* ...and height          */
2698#endif
2699
2700#if OPT_SCROLL_LOCK
2701	Boolean		allowScrollLock;/* ScrollLock mode		*/
2702	Boolean		allowScrollLock0;/* initial ScrollLock mode	*/
2703	Boolean		autoScrollLock; /* Auto ScrollLock mode		*/
2704	Boolean		scroll_lock;	/* true to keep buffer in view	*/
2705	Boolean		scroll_dirty;	/* scrolling makes screen dirty	*/
2706#endif
2707
2708#if OPT_SIXEL_GRAPHICS
2709	Boolean		sixel_scrolling; /* sixel scrolling             */
2710	Boolean		sixel_scrolls_right; /* sixel scrolling moves cursor to right */
2711#endif
2712
2713#if OPT_GRAPHICS
2714	int		numcolorregisters; /* number of supported color registers */
2715	Boolean		privatecolorregisters; /* private color registers for each graphic */
2716#endif
2717
2718	/* Graphics Printing */
2719#if OPT_PRINT_GRAPHICS
2720	Boolean		graphics_print_to_host;
2721	Boolean		graphics_expanded_print_mode;
2722	Boolean		graphics_print_color_mode;
2723	Boolean		graphics_print_color_syntax;
2724	Boolean		graphics_print_background_mode;
2725	Boolean		graphics_rotated_print_mode;
2726#endif
2727
2728#define StatusLineRows	1		/* number of rows in status-line */
2729
2730#if OPT_STATUS_LINE
2731#define AddStatusLineRows(nrow)         nrow += StatusLineRows
2732#define LastRowNumber(screen) \
2733	( (screen)->max_row \
2734	 + (IsStatusShown(screen) ? StatusLineRows : 0) )
2735#define FirstRowNumber(screen) \
2736	( (screen)->status_active \
2737	   ? LastRowNumber(screen) \
2738	   : 0 )
2739#define IsStatusShown(screen) \
2740	( ( (screen)->status_type == 2) || \
2741	  ( (screen)->status_type == 1) )
2742#define PlusStatusLine(screen,expr) \
2743	( (screen)->status_shown \
2744	  ? (expr) + StatusLineRows \
2745	  : (expr) )
2746#define if_STATUS_LINE(screen,stmt) \
2747	if (IsStatusShown(screen) && (screen)->status_active) stmt
2748
2749	Boolean		status_timeout;	/* status timeout needs service	*/
2750	Boolean		status_active;	/* DECSASD */
2751	int		status_type;	/* DECSSDT */
2752	int		status_shown;	/* last-displayed type */
2753	SavedCursor	status_data[2];
2754	char *		status_fmt;	/* format for indicator-status	*/
2755
2756#else /* !OPT_STATUS_LINE */
2757
2758#define AddStatusLineRows(nrow)         /* nothing */
2759#define LastRowNumber(screen)           (screen)->max_row
2760#define FirstRowNumber(screen)          0
2761#define PlusStatusLine(screen,expr)     (expr)
2762#define if_STATUS_LINE(screen,stmt)	/* nothing */
2763
2764#endif /* OPT_STATUS_LINE */
2765
2766#if OPT_VT52_MODE
2767	IFlags		vt52_save_flags;
2768	Char		vt52_save_curgl;
2769	Char		vt52_save_curgr;
2770	Char		vt52_save_curss;
2771	DECNRCM_codes	vt52_save_gsets[NUM_GSETS];
2772#endif
2773	/* Testing */
2774#if OPT_XMC_GLITCH
2775	unsigned	xmc_glitch;	/* # of spaces to pad on SGR's	*/
2776	IAttr		xmc_attributes;	/* attrs that make a glitch	*/
2777	Boolean		xmc_inline;	/* SGR's propagate only to eol	*/
2778	Boolean		move_sgr_ok;	/* SGR is reset on move		*/
2779#endif
2780
2781	/*
2782	 * Bell
2783	 */
2784	int		visualBellDelay; /* msecs to delay for visibleBell */
2785	int		bellSuppressTime; /* msecs after Bell before another allowed */
2786	Boolean		bellInProgress; /* still ringing/flashing prev bell? */
2787	Boolean		bellIsUrgent;	/* set XUrgency WM hint on bell */
2788	Boolean		flash_line;	/* show visualBell as current line */
2789	/*
2790	 * Select/paste state.
2791	 */
2792	Boolean		selectToClipboard; /* primary vs clipboard */
2793	String		*mappedSelect;	/* mapping for "SELECT" to "PRIMARY" */
2794
2795	Boolean		waitingForTrackInfo;
2796	int		numberOfClicks;
2797	int		maxClicks;
2798	int		multiClickTime;	/* time between multiclick selects */
2799	SelectUnit	selectUnit;
2800	SelectUnit	selectMap[NSELECTUNITS];
2801	String		onClick[NSELECTUNITS + 1];
2802
2803	char		*charClass;	/* for overriding word selection */
2804	Boolean		cutNewline;	/* whether or not line cut has \n */
2805	Boolean		cutToBeginningOfLine;  /* line cuts to BOL? */
2806	Boolean		highlight_selection; /* controls appearance of selection */
2807	Boolean		show_wrap_marks; /* show lines which are wrapped */
2808	Boolean		trim_selection; /* controls trimming of selection */
2809	Boolean		i18nSelections;
2810	Boolean		brokenSelections;
2811	Boolean		keepClipboard;	/* retain data sent to clipboard */
2812	Boolean		keepSelection;	/* do not lose selection on output */
2813	Boolean		replyToEmacs;	/* Send emacs escape code when done selecting or extending? */
2814
2815	SelectedCells	clipboard_data;	/* what we sent to the clipboard */
2816
2817	EventMode	eventMode;
2818	Time		selection_time;	/* latest event timestamp */
2819	Time		lastButtonUpTime;
2820	unsigned	lastButton;
2821
2822#define MAX_CUT_BUFFER  8		/* CUT_BUFFER0 to CUT_BUFFER7 */
2823#define MAX_SELECTIONS	(MAX_SELECTION_CODES + MAX_CUT_BUFFER)
2824	SelectedCells	selected_cells[MAX_SELECTIONS];
2825
2826	CELL		rawPos;		/* raw position for selection start */
2827	CELL		startRaw;	/* area before selectUnit processing */
2828	CELL		endRaw;		/* " " */
2829	CELL		startSel;	/* area after selectUnit processing */
2830	CELL		endSel;		/* " " */
2831	CELL		startH;		/* start highlighted text */
2832	CELL		endH;		/* end highlighted text */
2833	CELL		saveStartW;	/* saved WORD state, for LINE */
2834	CELL		startExt;	/* Start, end of extension */
2835	CELL		endExt;		/* " " */
2836	CELL		saveStartR;	/* Saved values of raw selection for extend to restore to */
2837	CELL		saveEndR;	/* " " */
2838	int		startHCoord, endHCoord;
2839	int		firstValidRow;	/* Valid rows for selection clipping */
2840	int		lastValidRow;	/* " " */
2841
2842	Boolean		selectToBuffer;	/* copy selection to buffer	*/
2843	InternalSelect	internal_select;
2844
2845	String		default_string;
2846	String		eightbit_select_types;
2847	Atom*		selection_targets_8bit;
2848#if OPT_WIDE_CHARS
2849	String		utf8_select_types;
2850	Atom*		selection_targets_utf8;
2851#endif
2852	Atom*		selection_atoms; /* which selections we own */
2853	Cardinal	sel_atoms_size;	 /* how many atoms allocated */
2854	Cardinal	selection_count; /* how many atoms in use */
2855#if OPT_SELECT_REGEX
2856	char *		selectExpr[NSELECTUNITS];
2857#endif
2858	/*
2859	 * Input/output state.
2860	 */
2861	Boolean		input_eight_bits;	/* do not send ESC when meta pressed */
2862	int		eight_bit_meta;		/* use 8th bit when meta pressed */
2863	char *		eight_bit_meta_s;	/* ...resource eightBitMeta */
2864	Boolean		output_eight_bits;	/* honor all bits or strip */
2865	Boolean		control_eight_bits;	/* send CSI as 8-bits */
2866	Boolean		backarrow_key;		/* backspace/delete */
2867	Boolean		alt_is_not_meta;	/* use both Alt- and Meta-key */
2868	Boolean		alt_sends_esc;		/* Alt-key sends ESC prefix */
2869	Boolean		meta_sends_esc;		/* Meta-key sends ESC prefix */
2870	/*
2871	 * Fonts
2872	 */
2873	Pixmap		menu_item_bitmap;	/* mask for checking items */
2874	String		initial_font;
2875	char *		menu_font_names[NMENUFONTS][fMAX];
2876#define MenuFontName(n) menu_font_names[n][fNorm]
2877#define EscapeFontName() MenuFontName(fontMenu_fontescape)
2878#define SelectFontName() MenuFontName(fontMenu_fontsel)
2879	long		menu_font_sizes[NMENUFONTS];
2880	int		menu_font_number;
2881#if OPT_LOAD_VTFONTS || OPT_WIDE_CHARS
2882	Boolean		savedVTFonts;
2883	Boolean		mergedVTFonts;
2884	SubResourceRec	cacheVTFonts;
2885#endif
2886#if OPT_CLIP_BOLD
2887	Boolean		use_border_clipping;
2888	Boolean		use_clipping;
2889#endif
2890	void *		main_cgs_cache;
2891#ifndef NO_ACTIVE_ICON
2892	void *		icon_cgs_cache;
2893#endif
2894#if OPT_RENDERFONT
2895	Boolean		force_xft_height;
2896	ListXftFonts	*list_xft_fonts;
2897	XTermXftFonts	renderFontNorm[NMENUFONTS];
2898	XTermXftFonts	renderFontBold[NMENUFONTS];
2899	XTermXftFonts	renderFontItal[NMENUFONTS];
2900	XTermXftFonts	renderFontBtal[NMENUFONTS];
2901#if OPT_RENDERWIDE
2902	XTermXftFonts	renderWideNorm[NMENUFONTS];
2903	XTermXftFonts	renderWideBold[NMENUFONTS];
2904	XTermXftFonts	renderWideItal[NMENUFONTS];
2905	XTermXftFonts	renderWideBtal[NMENUFONTS];
2906	TypedBuffer(XftCharSpec);
2907#else
2908	TypedBuffer(XftChar8);
2909#endif
2910	XftDraw *	renderDraw;
2911#endif
2912#if OPT_DABBREV
2913	Boolean		dabbrev_working;	/* nonzero during dabbrev process */
2914	unsigned char	dabbrev_erase_char;	/* used for deleting inserted completion */
2915#endif
2916	char		tcapbuf[TERMCAP_SIZE];
2917	char		tcap_area[TERMCAP_SIZE];
2918#if OPT_TCAP_FKEYS
2919	char **		tcap_fkeys;
2920#endif
2921	String		cursor_font_name;	/* alternate cursor font */
2922} TScreen;
2923
2924typedef XTermFonts *(*MyGetFont) (TScreen *, int);
2925
2926typedef struct _TekPart {
2927	XFontStruct *	Tfont[TEKNUMFONTS];
2928	int		tobaseline[TEKNUMFONTS]; /* top-baseline, each font */
2929	char *		initial_font;		/* large, 2, 3, small */
2930	char *		gin_terminator_str;	/* ginTerminator resource */
2931#if OPT_TOOLBAR
2932	TbInfo		tb_info;	/* toolbar information		*/
2933#endif
2934} TekPart;
2935
2936/* Tektronix window parameters */
2937typedef struct _TekScreen {
2938	GC		TnormalGC;	/* normal painting		*/
2939	GC		TcursorGC;	/* normal cursor painting	*/
2940
2941	Boolean		waitrefresh;	/* postpone refresh		*/
2942	TKwin		fullTwin;
2943#ifndef NO_ACTIVE_ICON
2944	TKwin		iconTwin;
2945	TKwin		*whichTwin;
2946#endif /* NO_ACTIVE_ICON */
2947
2948	Cursor		arrow;		/* arrow cursor			*/
2949	GC		linepat[TEKNUMLINES]; /* line patterns		*/
2950	int		cur_X;		/* current x			*/
2951	int		cur_Y;		/* current y			*/
2952	Tmodes		cur;		/* current tek modes		*/
2953	Tmodes		page;		/* starting tek modes on page	*/
2954	int		margin;		/* 0 -> margin 1, 1 -> margin 2	*/
2955	int		pen;		/* current Tektronix pen 0=up, 1=dn */
2956	char		*TekGIN;	/* nonzero if Tektronix GIN mode*/
2957	int		gin_terminator; /* Tek strap option */
2958	char		tcapbuf[TERMCAP_SIZE];
2959} TekScreen;
2960
2961#if OPT_PASTE64 || OPT_READLINE
2962#define SCREEN_FLAG(screenp,f)		(1&(screenp)->f)
2963#define SCREEN_FLAG_set(screenp,f)	((screenp)->f |= 1)
2964#define SCREEN_FLAG_unset(screenp,f)	((screenp)->f &= (unsigned) ~1L)
2965#define SCREEN_FLAG_save(screenp,f)	\
2966	((screenp)->f = (((screenp)->f)<<1) | SCREEN_FLAG(screenp,f))
2967#define SCREEN_FLAG_restore(screenp,f)	((screenp)->f = (((screenp)->f)>>1))
2968#else
2969#define SCREEN_FLAG(screenp,f)		(0)
2970#endif
2971
2972/*
2973 * After screen-updates, reset the flag that tells us we should do wrapping.
2974 * Likewise, reset (in wide-character mode) the flag that tells us where the
2975 * "previous" character was written.
2976 */
2977#if OPT_WIDE_CHARS
2978#define ResetWrap(screen) \
2979    (screen)->do_wrap = \
2980    (screen)->char_was_written = False
2981#else
2982#define ResetWrap(screen) \
2983    (screen)->do_wrap = False
2984#endif
2985
2986/* meaning of bits in screen.select flag */
2987#define	INWINDOW	01	/* the mouse is in one of the windows */
2988#define	FOCUS		02	/* one of the windows is the focus window */
2989
2990#define MULTICLICKTIME 250	/* milliseconds */
2991
2992typedef struct {
2993    const char *name;
2994    int code;
2995} FlagList;
2996
2997typedef enum {
2998    keyboardIsLegacy,		/* bogus vt220 codes for F1-F4, etc. */
2999    keyboardIsDefault,
3000    keyboardIsHP,
3001    keyboardIsSCO,
3002    keyboardIsSun,
3003    keyboardIsTermcap,
3004    keyboardIsVT220
3005} xtermKeyboardType;
3006
3007typedef enum {			/* legal values for screen.pointer_mode */
3008    pNever = 0
3009    , pNoMouse = 1
3010    , pAlways = 2
3011    , pFocused = 3
3012} pointerModeTypes;
3013
3014typedef enum {			/* legal values for screen.utf8_mode */
3015    uFalse = 0
3016    , uTrue = 1
3017    , uAlways = 2
3018    , uDefault = 3
3019    , uLast
3020} utf8ModeTypes;
3021
3022typedef enum {			/* legal values for screen.eight_bit_meta */
3023    ebFalse = 0
3024    , ebTrue = 1
3025    , ebNever = 2
3026    , ebLocale = 3
3027    , ebLast
3028} ebMetaModeTypes;
3029
3030typedef enum {			/* legal values for misc.cdXtraScroll */
3031    edFalse = 0
3032    , edTrue = 1
3033    , edTrim = 2
3034    , edLast
3035} edXtraScrollTypes;
3036
3037#define NAME_OLD_KT " legacy"
3038
3039#if OPT_HP_FUNC_KEYS
3040#define NAME_HP_KT " hp"
3041#else
3042#define NAME_HP_KT /*nothing*/
3043#endif
3044
3045#if OPT_SCO_FUNC_KEYS
3046#define NAME_SCO_KT " sco"
3047#else
3048#define NAME_SCO_KT /*nothing*/
3049#endif
3050
3051#if OPT_SUN_FUNC_KEYS
3052#define NAME_SUN_KT " sun"
3053#else
3054#define NAME_SUN_KT /*nothing*/
3055#endif
3056
3057#if OPT_SUNPC_KBD
3058#define NAME_VT220_KT " vt220"
3059#else
3060#define NAME_VT220_KT /*nothing*/
3061#endif
3062
3063#if OPT_TCAP_FKEYS
3064#define NAME_TCAP_KT " tcap"
3065#else
3066#define NAME_TCAP_KT /*nothing*/
3067#endif
3068
3069#define KEYBOARD_TYPES NAME_TCAP_KT NAME_HP_KT NAME_SCO_KT NAME_SUN_KT NAME_VT220_KT
3070
3071#if OPT_TRACE
3072#define TRACE_RC(code,func) code = func
3073#else
3074#define TRACE_RC(code,func) func
3075#endif
3076
3077extern	const char * visibleKeyboardType(xtermKeyboardType);
3078
3079typedef struct
3080{
3081    int allow_keys;		/* how to handle legacy/vt220 keyboard */
3082    int cursor_keys;		/* how to handle cursor-key modifiers */
3083    int function_keys;		/* how to handle function-key modifiers */
3084    int keypad_keys;		/* how to handle keypad key-modifiers */
3085    int other_keys;		/* how to handle other key-modifiers */
3086    int string_keys;		/* how to handle string() modifiers */
3087} TModify;
3088
3089typedef struct
3090{
3091    xtermKeyboardType type;
3092    IFlags flags;
3093    char *shell_translations;	/* shell's translations, for input check */
3094    char *xterm_translations;	/* xterm's translations, for input check */
3095    char *extra_translations;
3096    char *print_translations;	/* printable translations for buttons */
3097    unsigned shift_buttons;	/* special shift-modifier for mouse-buttons */
3098    int shift_escape;		/* working value of shiftEscape */
3099    char * shift_escape_s;	/* resource for shiftEscape */
3100#if OPT_INITIAL_ERASE
3101    int	reset_DECBKM;		/* reset should set DECBKM */
3102#endif
3103#if OPT_MOD_FKEYS
3104    TModify modify_now;		/* current modifier value */
3105    TModify modify_1st;		/* original modifier value, for resets */
3106    int format_keys;		/* format of modifyOtherKeys */
3107#endif
3108} TKeyboard;
3109
3110#define GravityIsNorthWest(w) ((w)->misc.resizeGravity == NorthWestGravity)
3111#define GravityIsSouthWest(w) ((w)->misc.resizeGravity == SouthWestGravity)
3112
3113typedef struct _Misc {
3114    VTFontNames default_font;
3115    char *geo_metry;
3116    char *T_geometry;
3117#if OPT_WIDE_CHARS
3118    Boolean cjk_width;		/* true for built-in CJK wcwidth() */
3119    Boolean mk_width;		/* true for simpler built-in wcwidth() */
3120    int mk_samplesize;
3121    int mk_samplepass;
3122#endif
3123#if OPT_LUIT_PROG
3124    Boolean callfilter;		/* true to invoke luit */
3125    Boolean use_encoding;	/* true to use -encoding option for luit */
3126    char *locale_str;		/* "locale" resource */
3127    char *localefilter;		/* path for luit */
3128#endif
3129    fontWarningTypes fontWarnings;
3130    int limit_resize;
3131#ifdef ALLOWLOGGING
3132    Boolean log_on;
3133#endif
3134    Boolean color_inner_border;
3135    Boolean login_shell;
3136    Boolean re_verse;
3137    Boolean re_verse0;		/* initial value of "-rv" */
3138    Boolean resizeByPixel;
3139    XtGravity resizeGravity;
3140    Boolean reverseWrap;
3141    Boolean autoWrap;
3142    Boolean logInhibit;
3143    Boolean signalInhibit;
3144#if OPT_TEK4014
3145    Boolean tekInhibit;
3146    Boolean tekSmall;		/* start tek window in small size */
3147    Boolean TekEmu;		/* true if Tektronix emulation	*/
3148    Boolean Tshow;		/* Tek window showing		*/
3149#endif
3150    Boolean scrollbar;
3151#ifdef SCROLLBAR_RIGHT
3152    Boolean useRight;
3153#endif
3154    Boolean titeInhibit;
3155    Boolean appcursorDefault;
3156    Boolean appkeypadDefault;
3157    int cdXtraScroll;		/* scroll on cd (clear-display) */
3158    char *cdXtraScroll_s;
3159    int tiXtraScroll;		/* scroll on ti/te (init/end-cup) */
3160    char *tiXtraScroll_s;
3161#if OPT_INPUT_METHOD
3162    char* f_x;			/* font for XIM */
3163    char* input_method;
3164    char* preedit_type;
3165    Boolean open_im;		/* true if input-method is opened */
3166    int retry_im;
3167#endif
3168    Boolean dynamicColors;
3169#ifndef NO_ACTIVE_ICON
3170    char *active_icon_s;	/* use application icon window  */
3171    unsigned icon_border_width;
3172    Pixel icon_border_pixel;
3173#endif /* NO_ACTIVE_ICON */
3174#if OPT_DEC_SOFTFONT
3175    Boolean font_loadable;
3176#endif
3177#if OPT_SHIFT_FONTS
3178    Boolean shift_fonts;	/* true if we interpret fontsize-shifting */
3179#endif
3180#if OPT_SUNPC_KBD
3181    int ctrl_fkeys;		/* amount to add to XK_F1 for ctrl modifier */
3182#endif
3183#if OPT_NUM_LOCK
3184    Boolean real_NumLock;	/* true if we treat NumLock key specially */
3185    Boolean alwaysUseMods;	/* true if we always want f-key modifiers */
3186#endif
3187#if OPT_RENDERFONT
3188    VTFontNames default_xft;
3189    float face_size[NMENUFONTS];
3190    char *render_font_s;
3191    int limit_fontsets;
3192#endif
3193} Misc;
3194
3195typedef struct _Work {
3196    int dummy;
3197#ifdef SunXK_F36
3198#define MAX_UDK 37
3199#else
3200#define MAX_UDK 35
3201#endif
3202    struct {
3203	char *str;
3204	int len;
3205    } user_keys[MAX_UDK];
3206#define MAX_POINTER (XC_num_glyphs/2)
3207    Cursor pointer_cursors[MAX_POINTER]; /* saved cursors	*/
3208#ifndef NO_ACTIVE_ICON
3209    int active_icon;		/* use application icon window  */
3210    char *wm_name;
3211#endif /* NO_ACTIVE_ICON */
3212#if OPT_INPUT_METHOD
3213    Boolean cannot_im;		/* true if we cannot use input-method */
3214    XFontSet xim_fs;		/* fontset for XIM preedit */
3215    int xim_fs_ascent;		/* ascent of fs */
3216    TInput inputs[NINPUTWIDGETS];
3217#endif
3218    Boolean doing_resize;	/* currently in RequestResize */
3219#if OPT_MAXIMIZE
3220#define MAX_EWMH_MODE 3
3221#define MAX_EWMH_DATA (1 + OPT_TEK4014)
3222    struct {
3223	int mode;		/* fullscreen, etc.		*/
3224	Boolean checked[MAX_EWMH_MODE + 1];
3225	Boolean allowed[MAX_EWMH_MODE + 1];
3226    } ewmh[MAX_EWMH_DATA];
3227#endif
3228#if OPT_NUM_LOCK
3229    unsigned num_lock;		/* modifier for Num_Lock */
3230    unsigned alt_mods;		/* modifier for Alt_L or Alt_R */
3231    unsigned meta_mods;		/* modifier for Meta_L or Meta_R */
3232#endif
3233    XtermFontNames fonts;
3234    Boolean force_wideFont;	/* true to single-step wideFont	*/
3235#if OPT_RENDERFONT
3236    Boolean render_font;
3237    unsigned max_fontsets;
3238#endif
3239#if OPT_DABBREV
3240#define MAX_DABBREV	1024	/* maximum word length as in tcsh */
3241    char dabbrev_data[MAX_DABBREV];
3242#endif
3243    ScrnColors *oldColors;
3244    Boolean palette_changed;
3245    Boolean broken_box_chars;
3246} Work;
3247
3248typedef struct {int foo;} XtermClassPart, TekClassPart;
3249
3250typedef struct _XtermClassRec {
3251    CoreClassPart  core_class;
3252    XtermClassPart xterm_class;
3253} XtermClassRec;
3254
3255extern WidgetClass xtermWidgetClass;
3256
3257#define IsXtermWidget(w) (XtClass(w) == xtermWidgetClass)
3258
3259#if OPT_TEK4014
3260typedef struct _TekClassRec {
3261    CoreClassPart core_class;
3262    TekClassPart tek_class;
3263} TekClassRec;
3264
3265extern WidgetClass tekWidgetClass;
3266
3267#define IsTekWidget(w) (XtClass(w) == tekWidgetClass)
3268
3269#endif
3270
3271/* define masks for keyboard.flags */
3272#define MODE_KAM	xBIT(0)	/* mode 2: keyboard action mode */
3273#define MODE_DECKPAM	xBIT(1)	/* keypad application mode */
3274#define MODE_DECCKM	xBIT(2)	/* private mode 1: cursor keys */
3275#define MODE_SRM	xBIT(3)	/* mode 12: send-receive mode */
3276#define MODE_DECBKM	xBIT(4)	/* private mode 67: backarrow */
3277#define MODE_DECSDM	xBIT(5)	/* private mode 80: sixel scrolling mode */
3278
3279#define N_MARGINBELL	10
3280
3281#define TAB_BITS_SHIFT	5	/* FIXME: 2**5 == 32 (should derive) */
3282#define TAB_BITS_WIDTH	(1 << TAB_BITS_SHIFT)
3283#define TAB_ARRAY_SIZE	(1024 / TAB_BITS_WIDTH)
3284#define MAX_TABS	(TAB_BITS_WIDTH * TAB_ARRAY_SIZE)
3285
3286#define OkTAB(c)	((c) >= 0 && (c) < MAX_TABS)
3287
3288typedef unsigned Tabs [TAB_ARRAY_SIZE];
3289
3290#if OPT_XTERM_SGR
3291#define MAX_SAVED_SGR	10
3292typedef	struct {
3293    int		used;
3294    struct	{
3295	IFlags	mask;
3296	IFlags	flags;
3297#if OPT_ISO_COLORS
3298	int	sgr_foreground;
3299	int	sgr_background;
3300	Boolean	sgr_38_xcolors;
3301#endif
3302    } stack[MAX_SAVED_SGR];
3303} SavedSGR;
3304
3305typedef struct {
3306    ScrnColors base;
3307    ColorRes ansi[1];
3308} ColorSlot;
3309
3310typedef struct {
3311    int		used;		/* currently saved or restored	*/
3312    int		last;		/* maximum number of saved palettes */
3313    ColorSlot	*palettes[MAX_SAVED_SGR];
3314} SavedColors;
3315#endif /* OPT_XTERM_SGR */
3316
3317typedef struct _XtermWidgetRec {
3318    CorePart	core;
3319    XSizeHints	hints;
3320    XVisualInfo *visInfo;
3321    int		numVisuals;
3322    unsigned	rgb_shifts[3];
3323    unsigned	rgb_widths[3];
3324    Bool	has_rgb;
3325    Bool	init_menu;
3326    TKeyboard	keyboard;	/* terminal keyboard		*/
3327    TScreen	screen;		/* terminal screen		*/
3328    IFlags	flags;		/* mode flags			*/
3329    int		cur_foreground; /* current foreground color	*/
3330    int		cur_background; /* current background color	*/
3331    Pixel	dft_foreground; /* default foreground color	*/
3332    Pixel	dft_background; /* default background color	*/
3333    Pixel	old_foreground; /* original foreground color	*/
3334    Pixel	old_background; /* original background color	*/
3335#if OPT_ISO_COLORS
3336    int		sgr_foreground; /* current SGR foreground color */
3337    int		sgr_background; /* current SGR background color */
3338    Boolean	sgr_38_xcolors;	/* true if ISO 8613 extension	*/
3339#endif
3340    IFlags	initflags;	/* initial mode flags		*/
3341    Tabs	tabs;		/* tabstops of the terminal	*/
3342    Misc	misc;		/* miscellaneous parameters	*/
3343    Work	work;		/* workspace (no resources)	*/
3344#if OPT_XTERM_SGR
3345    SavedSGR	saved_sgr;
3346    SavedColors	saved_colors;
3347#endif
3348} XtermWidgetRec, *XtermWidget;
3349
3350#if OPT_TEK4014
3351typedef struct _TekWidgetRec {
3352    CorePart	core;
3353    XtermWidget vt;		/* main widget has border, etc. */
3354    TekPart	tek;		/* contains resources */
3355    TekScreen	screen;		/* contains working data (no resources) */
3356    Bool	init_menu;
3357    XSizeHints	hints;
3358} TekWidgetRec, *TekWidget;
3359#endif /* OPT_TEK4014 */
3360
3361/*
3362 * terminal flags
3363 * There are actually two namespaces mixed together here:
3364 * a) One is the set of flags that can go in screen->visbuf attributes and
3365 *    which must fit in an IAttr (either a char or short, depending on whether
3366 *    wide-attributes are used).
3367 * b) The other is the global setting stored in term->flags and
3368 *    screen->save_modes, which fits in an unsigned (IFlags).
3369 */
3370
3371#define AttrBIT(n)	xBIT(n)		/* text-attributes */
3372#define MiscBIT(n)	xBIT(n + 16)	/* miscellaneous state flags */
3373
3374/* global flags and character flags (visible character attributes) */
3375#define INVERSE		AttrBIT(0)	/* invert the characters to be output */
3376#define UNDERLINE	AttrBIT(1)	/* true if underlining */
3377#define BOLD		AttrBIT(2)
3378#define BLINK		AttrBIT(3)
3379/* global flags (also character attributes) */
3380#define BG_COLOR	AttrBIT(4)	/* true if background set */
3381#define FG_COLOR	AttrBIT(5)	/* true if foreground set */
3382
3383/* character flags (internal attributes) */
3384#define PROTECTED	AttrBIT(6)	/* a character that cannot be erased */
3385#define CHARDRAWN	AttrBIT(7)	/* a character has been drawn here on
3386					   the screen.  Used to distinguish
3387					   blanks from empty parts of the
3388					   screen when selecting */
3389
3390#if OPT_WIDE_ATTRS
3391#define ATR_FAINT	AttrBIT(8)
3392#define ATR_ITALIC	AttrBIT(9)
3393#define ATR_STRIKEOUT	AttrBIT(10)
3394#define ATR_DBL_UNDER	AttrBIT(11)
3395#define ATR_DIRECT_FG	AttrBIT(12)
3396#define ATR_DIRECT_BG	AttrBIT(13)
3397#define SGR_MASK2       (ATR_FAINT | ATR_ITALIC | ATR_STRIKEOUT | ATR_DBL_UNDER | ATR_DIRECT_FG | ATR_DIRECT_BG)
3398#else
3399#define SGR_MASK2       0
3400#endif
3401
3402/*
3403 * Other flags
3404 */
3405#define WRAPAROUND	MiscBIT(0)	/* true if auto wraparound mode */
3406#define	REVERSEWRAP	MiscBIT(1)	/* true if reverse wraparound mode */
3407#define REVERSE_VIDEO	MiscBIT(2)	/* true if screen white on black */
3408#define LINEFEED	MiscBIT(3)	/* true if in auto linefeed mode */
3409#define ORIGIN		MiscBIT(4)	/* true if in origin mode */
3410#define INSERT		MiscBIT(5)	/* true if in insert mode */
3411#define SMOOTHSCROLL	MiscBIT(6)	/* true if in smooth scroll mode */
3412#define IN132COLUMNS	MiscBIT(7)	/* true if in 132 column mode */
3413#define INVISIBLE	MiscBIT(8)	/* true if writing invisible text */
3414#define NATIONAL        MiscBIT(9)	/* true if writing national charset */
3415#define LEFT_RIGHT      MiscBIT(10)	/* true if left/right margin mode */
3416#define NOCLEAR_COLM    MiscBIT(11)	/* true if no clear on DECCOLM change */
3417
3418#define DrawBIT(n)	xBIT(n + 8)	/* XTermDraw.draw_flags */
3419/* The following attributes are used in the argument of drawXtermText()  */
3420#define NOBACKGROUND	DrawBIT(0)	/* Used for overstrike */
3421#define NOTRANSLATION	DrawBIT(1)	/* No scan for chars missing in font */
3422#define DOUBLEWFONT	DrawBIT(2)	/* The actual X-font is double-width */
3423#define DOUBLEHFONT	DrawBIT(3)	/* The actual X-font is double-height */
3424#define CHARBYCHAR	DrawBIT(4)	/* Draw chars one-by-one */
3425
3426/* The following attribute is used in the argument of xtermSpecialFont etc */
3427#define NORESOLUTION	DrawBIT(5)	/* find the font without resolution */
3428
3429/*
3430 * Groups of attributes
3431 */
3432			/* mask for video-attributes only */
3433#define SGR_MASK	(BOLD | BLINK | UNDERLINE | INVERSE)
3434
3435			/* mask: user-visible attributes */
3436#define	ATTRIBUTES	(SGR_MASK | SGR_MASK2 | BG_COLOR | FG_COLOR | INVISIBLE | PROTECTED)
3437
3438/* The toplevel-call to drawXtermText() should have text-attributes guarded: */
3439#define DRAWX_MASK	(ATTRIBUTES | CHARDRAWN)
3440
3441/*
3442 * BOLDATTR is not only nonzero when we will use bold font, but uses the bits
3443 * for BOLD/BLINK to match against the video attributes which were originally
3444 * requested.
3445 */
3446#define USE_BOLD(screen) ((screen)->allowBoldFonts)
3447
3448#if OPT_BLINK_TEXT
3449#define BOLDATTR(screen) (unsigned) (USE_BOLD(screen) ? (BOLD | ((screen)->blink_as_bold ? BLINK : 0)) : 0)
3450#else
3451#define BOLDATTR(screen) (unsigned) (USE_BOLD(screen) ? (BOLD | BLINK) : 0)
3452#endif
3453
3454/*
3455 * Sixel-scrolling is backwards, perhaps from an error in the hardware design.
3456 */
3457#define SixelScrolling(xw) (!((xw)->keyboard.flags & MODE_DECSDM))
3458
3459/*
3460 * Per-line flags
3461 */
3462#define LINEWRAPPED	AttrBIT(0)
3463/* used once per line to indicate that it wraps onto the next line so we can
3464 * tell the difference between lines that have wrapped around and lines that
3465 * have ended naturally with a CR at column max_col.
3466 */
3467#define LINEBLINKED	AttrBIT(1)
3468/* set when the line contains blinking text.
3469 */
3470
3471#if OPT_ZICONBEEP || OPT_TOOLBAR || (USE_DOUBLE_BUFFER && OPT_RENDERFONT)
3472#define HANDLE_STRUCT_NOTIFY 1
3473#else
3474#define HANDLE_STRUCT_NOTIFY 0
3475#endif
3476
3477/*
3478 * If we've set protected attributes with the DEC-style DECSCA, then we'll have
3479 * to use DECSED or DECSEL to erase preserving protected text.  (The normal ED,
3480 * EL won't preserve protected-text).  If we've used SPA, then normal ED and EL
3481 * will preserve protected-text.  To keep things simple, just remember the last
3482 * control that was used to begin protected-text, and use that to determine how
3483 * erases are performed (otherwise we'd need 2 bits per protected character).
3484 */
3485#define OFF_PROTECT 0
3486#define DEC_PROTECT 1
3487#define ISO_PROTECT 2
3488
3489/***====================================================================***/
3490
3491/*
3492 * Reduce parameter-count of drawXtermText by putting less-modified data here.
3493 */
3494typedef struct {
3495	XtermWidget	xw;
3496	unsigned	attr_flags;
3497	unsigned	draw_flags;
3498	unsigned	this_chrset;
3499	unsigned	real_chrset;
3500	int		on_wide;
3501} XTermDraw;
3502
3503/***====================================================================***/
3504
3505#define TScreenOf(xw)	(&(xw)->screen)
3506#define TekScreenOf(tw) (&(tw)->screen)
3507
3508#define PrinterOf(screen) (screen)->printer_state
3509
3510#ifdef SCROLLBAR_RIGHT
3511#define OriginX(screen) (((term->misc.useRight)?0:ScrollbarWidth(screen)) + screen->border)
3512#else
3513#define OriginX(screen) (ScrollbarWidth(screen) + screen->border)
3514#endif
3515
3516#define OriginY(screen) (screen->border)
3517
3518#define CursorMoved(screen) \
3519		((screen)->cursor_moved || \
3520		    ((screen)->cursorp.col != (screen)->cur_col || \
3521		     (screen)->cursorp.row != (screen)->cur_row))
3522
3523#define CursorX2(screen,col,fw) ((col) * (int)(fw) + OriginX(screen))
3524#define CursorX(screen,col)     CursorX2(screen, col, FontWidth(screen))
3525#define CursorY2(screen,row)    (((row) * FontHeight(screen)) + screen->border)
3526#define CursorY(screen,row)     CursorY2(screen, INX2ROW(screen, row))
3527
3528/*
3529 * These definitions depend on whether xterm supports active-icon.
3530 */
3531#ifndef NO_ACTIVE_ICON
3532#define IsIconWin(screen,win)	((win) == &(screen)->iconVwin)
3533#define IsIcon(screen)		(WhichVWin(screen) == &(screen)->iconVwin)
3534#define WhichVWin(screen)	((screen)->whichVwin)
3535#define WhichTWin(screen)	((screen)->whichTwin)
3536
3537#define WhichVFont(screen,name)	(IsIcon(screen) ? getIconicFont(screen) \
3538						: getNormalFont(screen, (int)(name)))->fs
3539#define FontAscent(screen)	(IsIcon(screen) ? getIconicFont(screen)->fs->ascent \
3540						: WhichVWin(screen)->f_ascent)
3541#define FontDescent(screen)	(IsIcon(screen) ? getIconicFont(screen)->fs->descent \
3542						: WhichVWin(screen)->f_descent)
3543#else /* NO_ACTIVE_ICON */
3544
3545#define IsIconWin(screen,win)	(False)
3546#define IsIcon(screen)		(False)
3547#define WhichVWin(screen)	(&((screen)->fullVwin))
3548#define WhichTWin(screen)	(&((screen)->fullTwin))
3549
3550#define WhichVFont(screen,name)	getNormalFont(screen, (int)(name))->fs
3551#define FontAscent(screen)	WhichVWin(screen)->f_ascent
3552#define FontDescent(screen)	WhichVWin(screen)->f_descent
3553
3554#endif /* NO_ACTIVE_ICON */
3555
3556#define okFont(font) ((font) != 0 && (font)->fid != 0)
3557
3558/*
3559 * Macro to check if we are iconified; do not use render for that case.
3560 */
3561#define UsingRenderFont(xw)	(((xw)->work.render_font == True) && !IsIcon(TScreenOf(xw)))
3562
3563/*
3564 * These definitions do not depend on whether xterm supports active-icon.
3565 */
3566#define VWindow(screen)		WhichVWin(screen)->window
3567#define VShellWindow(xw)	XtWindow(SHELL_OF(xw))
3568#define TWindow(screen)		WhichTWin(screen)->window
3569#define TShellWindow		XtWindow(SHELL_OF(tekWidget))
3570
3571#if USE_DOUBLE_BUFFER
3572extern Window VDrawable(TScreen * /* screen */);
3573#else
3574#define VDrawable(screen)	VWindow(screen)
3575#endif
3576
3577#define Width(screen)		WhichVWin(screen)->width
3578#define Height(screen)		WhichVWin(screen)->height
3579#define FullWidth(screen)	WhichVWin(screen)->fullwidth
3580#define FullHeight(screen)	WhichVWin(screen)->fullheight
3581#define FontWidth(screen)	WhichVWin(screen)->f_width
3582#define FontHeight(screen)	WhichVWin(screen)->f_height
3583
3584#define NormalFont(screen)	WhichVFont(screen, fNorm)
3585#define BoldFont(screen)	WhichVFont(screen, fBold)
3586
3587#if OPT_WIDE_CHARS
3588#define NormalWFont(screen)	WhichVFont(screen, fWide)
3589#define BoldWFont(screen)	WhichVFont(screen, fWBold)
3590#endif
3591
3592#define ScrollbarWidth(screen)	WhichVWin(screen)->sb_info.width
3593
3594/* y -> y_shift, to center text versus the cursor */
3595#define ScaleShift(screen) \
3596	    (int) ((IsIcon(screen) || (screen->scale_height <= 1.0f)) \
3597	           ? 0.0f \
3598	           : ((float) WhichVWin(screen)->f_height \
3599		      * ((float) screen->scale_height - 1.0f) / 2.0f))
3600
3601#define BorderGC(w,sp)		WhichVWin(sp)->border_gc
3602#define FillerGC(w,sp)		WhichVWin(sp)->filler_gc
3603#define NormalGC(w,sp)		getCgsGC(w, WhichVWin(sp), gcNorm)
3604#define ReverseGC(w,sp)		getCgsGC(w, WhichVWin(sp), gcNormReverse)
3605#define NormalBoldGC(w,sp)	getCgsGC(w, WhichVWin(sp), gcBold)
3606#define ReverseBoldGC(w,sp)	getCgsGC(w, WhichVWin(sp), gcBoldReverse)
3607
3608#define TWidth(screen)		WhichTWin(screen)->width
3609#define THeight(screen)		WhichTWin(screen)->height
3610#define TFullWidth(screen)	WhichTWin(screen)->fullwidth
3611#define TFullHeight(screen)	WhichTWin(screen)->fullheight
3612#define TekScale(screen)	WhichTWin(screen)->tekscale
3613
3614/* use these before tek4014 is realized, good enough for default "9x15" font */
3615#define TDefaultRows		37
3616#define TDefaultCols		75
3617
3618#define BorderWidth(w)		((w)->core.border_width)
3619#define BorderPixel(w)		((w)->core.border_pixel)
3620
3621#define AllowXtermOps(w,name)	(TScreenOf(w)->name && !TScreenOf(w)->allowSendEvents)
3622
3623#define AllowColorOps(w,name)	(AllowXtermOps(w, allowColorOps) || \
3624				 !TScreenOf(w)->disallow_color_ops[name])
3625
3626#define AllowFontOps(w,name)	(AllowXtermOps(w, allowFontOps) || \
3627				 !TScreenOf(w)->disallow_font_ops[name])
3628
3629#define AllowMouseOps(w,name)	(AllowXtermOps(w, allowMouseOps) || \
3630				 !TScreenOf(w)->disallow_mouse_ops[name])
3631
3632#define AllowTcapOps(w,name)	(AllowXtermOps(w, allowTcapOps) || \
3633				 !TScreenOf(w)->disallow_tcap_ops[name])
3634
3635#define AllowTitleOps(w)	AllowXtermOps(w, allowTitleOps)
3636
3637#define AllowXResOps(w)		True
3638
3639#define SpecialWindowOps(w,name) (!TScreenOf(w)->disallow_win_ops[name])
3640#define AllowWindowOps(w,name)	(AllowXtermOps(w, allowWindowOps) || \
3641				 SpecialWindowOps(w,name))
3642
3643#if OPT_TOOLBAR
3644#define ToolbarHeight(w)	((resource.toolBar) \
3645				 ? ((w)->VT100_TB_INFO(menu_height) \
3646				  + (w)->VT100_TB_INFO(menu_border) * 2) \
3647				 : 0)
3648#else
3649#define ToolbarHeight(w) 0
3650#endif
3651
3652#if OPT_TEK4014
3653#define TEK_LINK_BLOCK_SIZE 1024
3654
3655typedef struct Tek_Link
3656{
3657	struct Tek_Link	*next;	/* pointer to next TekLink in list
3658				   NULL <=> this is last TekLink */
3659	unsigned short fontsize;/* character size, 0-3 */
3660	unsigned short count;	/* number of chars in data */
3661	char *ptr;		/* current pointer into data */
3662	char data [TEK_LINK_BLOCK_SIZE];
3663} TekLink;
3664#endif /* OPT_TEK4014 */
3665
3666/* flags for cursors */
3667#define	OFF		0
3668#define	ON		1
3669#define	BLINKED_OFF	2
3670#define	CLEAR		0
3671#define	TOGGLE		1
3672
3673/* flags for inhibit */
3674#ifdef ALLOWLOGGING
3675#define	I_LOG		0x01
3676#endif
3677#define	I_SIGNAL	0x02
3678#define	I_TEK		0x04
3679
3680/* *INDENT-ON* */
3681
3682#endif /* included_ptyx_h */
3683