1 /* Copyright (c) 2008, 2009
2  *      Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
3  *      Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
4  *      Micah Cowan (micah@cowan.name)
5  *      Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
6  * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
7  *      Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
8  *      Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
9  * Copyright (c) 1987 Oliver Laumann
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 3, or (at your option)
14  * any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program (see the file COPYING); if not, see
23  * https://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
25  *
26  ****************************************************************
27  * $Id$ GNU
28  */
29 
30 #ifndef SCREEN_DISPLAY_H
31 #define SCREEN_DISPLAY_H
32 
33 #include "layout.h"
34 #include "canvas.h"
35 #include "viewport.h"
36 
37 #ifdef MAPKEYS
38 
39 #define KMAP_KEYS (T_OCAPS-T_CAPS)
40 #define KMAP_AKEYS (T_OCAPS-T_CURSOR)
41 
42 #define KMAP_NOTIMEOUT 0x4000
43 
44 struct kmap_ext
45 {
46   char *str;
47   int fl;
48   struct action um;
49   struct action dm;
50   struct action mm;
51 };
52 
53 #else
54 
55 #define KMAP_KEYS 0
56 
57 #endif
58 
59 struct win;			/* forward declaration */
60 
61 struct mouse_parse
62 {
63   char sgrmode;                 /* non-zero if parsing an SGR sequence */
64   char state;                   /* current state of parsing */
65   int params[3];                /* parsed params: button, x, y */
66 };
67 
68 struct display
69 {
70   struct display *d_next;	/* linked list */
71   struct acluser *d_user;	/* user who owns that display */
72   struct canvas d_canvas;	/* our canvas slice */
73   struct canvas *d_cvlist;	/* the canvases of this display */
74   struct canvas *d_forecv;	/* current input focus */
75   struct layout *d_layout;	/* layout we're using */
76   void (*d_processinput) __P((char *, int));
77   char *d_processinputdata;	/* data for processinput */
78   int d_vpxmin, d_vpxmax;	/* min/max used position on display */
79   struct win *d_fore;		/* pointer to fore window */
80   struct win *d_other;		/* pointer to other window */
81   int   d_nonblock;		/* -1 don't block if obufmax reached */
82 				/* >0: block after nonblock secs */
83   char  d_termname[MAXTERMLEN + 1];	/* $TERM */
84   char	*d_tentry;		/* buffer for tgetstr */
85   char	d_tcinited;		/* termcap inited flag */
86   int	d_width, d_height;	/* width/height of the screen */
87   int	d_defwidth, d_defheight;	/* default width/height of windows */
88   int	d_top, d_bot;		/* scrollregion start/end */
89   int	d_x, d_y;		/* cursor position */
90   struct mchar d_rend;		/* current rendition */
91   int   d_col16change;		/* the 16col bits changed in attr */
92   char	d_atyp;			/* current attribute types */
93 #ifdef DW_CHARS
94   int   d_mbcs;			/* saved char for multibytes charset */
95 #endif
96 #ifdef ENCODINGS
97   int   d_encoding;		/* what encoding type the display is */
98   int   d_decodestate;		/* state of our decoder */
99   int   d_realfont;		/* real font of terminal */
100 #endif
101   int	d_insert;		/* insert mode flag */
102   int	d_keypad;		/* application keypad flag */
103   int	d_cursorkeys;		/* application cursorkeys flag */
104   int	d_revvid;		/* reverse video */
105   int	d_curvis;		/* cursor visibility */
106   int   d_has_hstatus;		/* display has hardstatus line */
107   int	d_hstatus;		/* hardstatus used */
108   int	d_lp_missing;		/* last character on bot line missing */
109   int   d_mouse;		/* mouse mode */
110   int	d_extmouse;		/* extended mouse mode */
111   struct mouse_parse d_mouse_parse;		/* state of mouse code parsing */
112   int	d_mousetrack;		/* set when user wants to use mouse even when the window
113 				   does not */
114 #ifdef RXVT_OSC
115   int   d_xtermosc[4];		/* osc used */
116 #endif
117   struct mchar d_lpchar;	/* missing char */
118   struct timeval d_status_time;	/* time of status display */
119   int   d_status;		/* is status displayed? */
120   char	d_status_bell;		/* is it only a vbell? */
121   int	d_status_len;		/* length of status line */
122   char *d_status_lastmsg;	/* last displayed message */
123   int   d_status_buflen;	/* last message buffer len */
124   int	d_status_lastx;		/* position of the cursor */
125   int	d_status_lasty;		/*   before status was displayed */
126   int   d_status_obuflen;	/* saved obuflen */
127   int   d_status_obuffree;	/* saved obuffree */
128   int	d_status_obufpos;	/* end of status position in obuf */
129   struct event d_statusev;	/* timeout event */
130   struct event d_hstatusev;	/* hstatus changed event */
131   int	d_kaablamm;		/* display kaablamm msg */
132   struct action *d_ESCseen;	/* Was the last char an ESC (^a) */
133   int	d_userpid;		/* pid of attacher */
134   char	d_usertty[MAXPATHLEN];	/* tty we are attached to */
135   int	d_userfd;		/* fd of the tty */
136   struct event d_readev;	/* userfd read event */
137   struct event d_writeev;	/* userfd write event */
138   struct event d_blockedev;	/* blocked timeout */
139   struct mode d_OldMode;	/* tty mode when screen was started */
140   struct mode d_NewMode;	/* New tty mode */
141   int	d_flow;			/* tty's flow control on/off flag*/
142   int   d_intrc;		/* current intr when flow is on */
143   char *d_obuf;			/* output buffer */
144   int   d_obuflen;		/* len of buffer */
145   int	d_obufmax;		/* len where we are blocking the pty */
146   int	d_obuflenmax;		/* len - max */
147   char *d_obufp;		/* pointer in buffer */
148   int   d_obuffree;		/* free bytes in buffer */
149 #ifdef AUTO_NUKE
150   int	d_auto_nuke;		/* autonuke flag */
151 #endif
152 #ifdef MAPKEYS
153   int	d_nseqs;		/* number of valid mappings */
154   int	d_aseqs;		/* number of allocated mappings */
155   unsigned char  *d_kmaps;	/* keymaps */
156   unsigned char *d_seqp;	/* pointer into keymap array */
157   int	d_seql;			/* number of parsed chars */
158   unsigned char *d_seqh;	/* last hit */
159   struct event d_mapev;		/* timeout event */
160   int	d_dontmap;		/* do not map next */
161   int	d_mapdefault;		/* do map next to default */
162 #endif
163   union	tcu d_tcs[T_N];		/* terminal capabilities */
164   char *d_attrtab[NATTR];	/* attrib emulation table */
165   char  d_attrtyp[NATTR];	/* attrib group table */
166   int   d_hascolor;		/* do we support color */
167   short	d_dospeed;		/* baudrate of tty */
168 #ifdef FONT
169   char	d_c0_tab[256];		/* conversion for C0 */
170   char ***d_xtable;		/* char translation table */
171 #endif
172   int	d_UPcost, d_DOcost, d_LEcost, d_NDcost;
173   int	d_CRcost, d_IMcost, d_EIcost, d_NLcost;
174   int   d_printfd;		/* fd for vt100 print sequence */
175 #ifdef UTMPOK
176   slot_t d_loginslot;		/* offset, where utmp_logintty belongs */
177   struct utmp d_utmp_logintty;	/* here the original utmp structure is stored */
178   int   d_loginttymode;
179 # ifdef _SEQUENT_
180   char	d_loginhost[100+1];
181 # endif /* _SEQUENT_ */
182 #endif
183   int   d_blocked;
184   int   d_blocked_fuzz;
185   struct event d_idleev;	/* screen blanker */
186 #ifdef BLANKER_PRG
187   int   d_blankerpid;
188   struct event d_blankerev;
189 #endif
190 };
191 
192 #ifdef MULTI
193 # define DISPLAY(x) display->x
194 #else
195 extern struct display TheDisplay;
196 # define DISPLAY(x) TheDisplay.x
197 #endif
198 
199 #define D_user		DISPLAY(d_user)
200 #define D_username	(DISPLAY(d_user) ? DISPLAY(d_user)->u_name : 0)
201 #define D_canvas	DISPLAY(d_canvas)
202 #define D_cvlist	DISPLAY(d_cvlist)
203 #define D_layout	DISPLAY(d_layout)
204 #define D_forecv	DISPLAY(d_forecv)
205 #define D_processinput	DISPLAY(d_processinput)
206 #define D_processinputdata	DISPLAY(d_processinputdata)
207 #define D_vpxmin	DISPLAY(d_vpxmin)
208 #define D_vpxmax	DISPLAY(d_vpxmax)
209 #define D_fore		DISPLAY(d_fore)
210 #define D_other		DISPLAY(d_other)
211 #define D_nonblock      DISPLAY(d_nonblock)
212 #define D_termname	DISPLAY(d_termname)
213 #define D_tentry	DISPLAY(d_tentry)
214 #define D_tcinited	DISPLAY(d_tcinited)
215 #define D_width		DISPLAY(d_width)
216 #define D_height	DISPLAY(d_height)
217 #define D_defwidth	DISPLAY(d_defwidth)
218 #define D_defheight	DISPLAY(d_defheight)
219 #define D_top		DISPLAY(d_top)
220 #define D_bot		DISPLAY(d_bot)
221 #define D_x		DISPLAY(d_x)
222 #define D_y		DISPLAY(d_y)
223 #define D_rend		DISPLAY(d_rend)
224 #define D_col16change	DISPLAY(d_col16change)
225 #define D_atyp		DISPLAY(d_atyp)
226 #define D_mbcs		DISPLAY(d_mbcs)
227 #define D_encoding	DISPLAY(d_encoding)
228 #define D_decodestate	DISPLAY(d_decodestate)
229 #define D_realfont	DISPLAY(d_realfont)
230 #define D_insert	DISPLAY(d_insert)
231 #define D_keypad	DISPLAY(d_keypad)
232 #define D_cursorkeys	DISPLAY(d_cursorkeys)
233 #define D_revvid	DISPLAY(d_revvid)
234 #define D_curvis	DISPLAY(d_curvis)
235 #define D_has_hstatus	DISPLAY(d_has_hstatus)
236 #define D_hstatus	DISPLAY(d_hstatus)
237 #define D_lp_missing	DISPLAY(d_lp_missing)
238 #define D_mouse		DISPLAY(d_mouse)
239 #define D_mouse_parse	DISPLAY(d_mouse_parse)
240 #define D_extmouse	DISPLAY(d_extmouse)
241 #define D_mousetrack	DISPLAY(d_mousetrack)
242 #define D_xtermosc	DISPLAY(d_xtermosc)
243 #define D_lpchar	DISPLAY(d_lpchar)
244 #define D_status	DISPLAY(d_status)
245 #define D_status_time	DISPLAY(d_status_time)
246 #define D_status_bell	DISPLAY(d_status_bell)
247 #define D_status_len	DISPLAY(d_status_len)
248 #define D_status_lastmsg	DISPLAY(d_status_lastmsg)
249 #define D_status_buflen	DISPLAY(d_status_buflen)
250 #define D_status_lastx	DISPLAY(d_status_lastx)
251 #define D_status_lasty	DISPLAY(d_status_lasty)
252 #define D_status_obuflen	DISPLAY(d_status_obuflen)
253 #define D_status_obuffree	DISPLAY(d_status_obuffree)
254 #define D_status_obufpos	DISPLAY(d_status_obufpos)
255 #define D_statusev	DISPLAY(d_statusev)
256 #define D_hstatusev	DISPLAY(d_hstatusev)
257 #define D_kaablamm	DISPLAY(d_kaablamm)
258 #define D_ESCseen	DISPLAY(d_ESCseen)
259 #define D_userpid	DISPLAY(d_userpid)
260 #define D_usertty	DISPLAY(d_usertty)
261 #define D_userfd	DISPLAY(d_userfd)
262 #define D_OldMode	DISPLAY(d_OldMode)
263 #define D_NewMode	DISPLAY(d_NewMode)
264 #define D_flow		DISPLAY(d_flow)
265 #define D_intr		DISPLAY(d_intr)
266 #define D_obuf		DISPLAY(d_obuf)
267 #define D_obuflen	DISPLAY(d_obuflen)
268 #define D_obufmax	DISPLAY(d_obufmax)
269 #define D_obuflenmax	DISPLAY(d_obuflenmax)
270 #define D_obufp		DISPLAY(d_obufp)
271 #define D_obuffree	DISPLAY(d_obuffree)
272 #define D_auto_nuke	DISPLAY(d_auto_nuke)
273 #define D_nseqs		DISPLAY(d_nseqs)
274 #define D_aseqs		DISPLAY(d_aseqs)
275 #define D_seqp		DISPLAY(d_seqp)
276 #define D_seql		DISPLAY(d_seql)
277 #define D_seqh		DISPLAY(d_seqh)
278 #define D_dontmap	DISPLAY(d_dontmap)
279 #define D_mapdefault	DISPLAY(d_mapdefault)
280 #define D_kmaps		DISPLAY(d_kmaps)
281 #define D_tcs		DISPLAY(d_tcs)
282 #define D_attrtab	DISPLAY(d_attrtab)
283 #define D_attrtyp	DISPLAY(d_attrtyp)
284 #define D_hascolor	DISPLAY(d_hascolor)
285 #define D_dospeed	DISPLAY(d_dospeed)
286 #define D_c0_tab	DISPLAY(d_c0_tab)
287 #define D_xtable	DISPLAY(d_xtable)
288 #define D_UPcost	DISPLAY(d_UPcost)
289 #define D_DOcost	DISPLAY(d_DOcost)
290 #define D_LEcost	DISPLAY(d_LEcost)
291 #define D_NDcost	DISPLAY(d_NDcost)
292 #define D_CRcost	DISPLAY(d_CRcost)
293 #define D_IMcost	DISPLAY(d_IMcost)
294 #define D_EIcost	DISPLAY(d_EIcost)
295 #define D_NLcost	DISPLAY(d_NLcost)
296 #define D_printfd	DISPLAY(d_printfd)
297 #define D_loginslot	DISPLAY(d_loginslot)
298 #define D_utmp_logintty	DISPLAY(d_utmp_logintty)
299 #define D_loginttymode	DISPLAY(d_loginttymode)
300 #define D_loginhost	DISPLAY(d_loginhost)
301 #define D_readev	DISPLAY(d_readev)
302 #define D_writeev	DISPLAY(d_writeev)
303 #define D_blockedev	DISPLAY(d_blockedev)
304 #define D_mapev		DISPLAY(d_mapev)
305 #define D_blocked	DISPLAY(d_blocked)
306 #define D_blocked_fuzz	DISPLAY(d_blocked_fuzz)
307 #define D_idleev	DISPLAY(d_idleev)
308 #define D_blankerev	DISPLAY(d_blankerev)
309 #define D_blankerpid	DISPLAY(d_blankerpid)
310 
311 
312 #define GRAIN 4096	/* Allocation grain size for output buffer */
313 #define OBUF_MAX 256	/* default for obuflimit */
314 
315 #define OUTPUT_BLOCK_SIZE 256  /* Block size of output to tty */
316 
317 #define AddChar(c)		\
318 do				\
319   {				\
320     if (--D_obuffree <= 0)	\
321       Resize_obuf();		\
322     *D_obufp++ = (c);		\
323   }				\
324 while (0)
325 
326 #define STATUS_OFF	0
327 #define STATUS_ON_WIN	1
328 #define STATUS_ON_HS	2
329 
330 #define HSTATUS_IGNORE		0
331 #define HSTATUS_LASTLINE	1
332 #define HSTATUS_MESSAGE		2
333 #define HSTATUS_HS		3
334 #define HSTATUS_FIRSTLINE	4
335 #define HSTATUS_ALWAYS		(1<<3)
336 
337 #endif /* SCREEN_DISPLAY_H */
338 
339