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