Add some window events.
[screen-lua.git] / src / window.h
blobb79adfade4a1fe0ee98b014a4f21dc0cf7987b69
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
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.
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.
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 * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
26 ****************************************************************
27 * $Id$ FAU
31 /* keep this in sync with the initialisations in window.c */
32 struct NewWindow
34 int StartAt; /* where to start the search for the slot */
35 char *aka; /* aka string */
36 char **args; /* argv vector */
37 char *dir; /* directory for chdir */
38 char *term; /* TERM to be set instead of "screen" */
39 int aflag;
40 int flowflag;
41 int lflag;
42 int histheight;
43 int monitor;
44 int wlock; /* default writelock setting */
45 int silence;
46 int wrap;
47 int Lflag; /* logging */
48 int slow; /* inter character milliseconds */
49 int gr;
50 int c1;
51 int bce;
52 int encoding;
53 char *hstatus;
54 char *charset;
57 #ifdef PSEUDOS
59 struct pseudowin
61 int p_fdpat;
62 int p_pid;
63 int p_ptyfd;
64 struct event p_readev;
65 struct event p_writeev;
66 char p_cmd[MAXSTR];
67 char p_tty[MAXSTR];
68 char p_inbuf[IOSIZE]; /* buffered writing to p_ptyfd */
69 int p_inlen;
72 /* bits for fdpat: */
73 #define F_PMASK 0x0003
74 #define F_PSHIFT 2
75 #define F_PFRONT 0x0001 /* . */
76 #define F_PBACK 0x0002 /* ! */
77 #define F_PBOTH (F_PFRONT | F_PBACK) /* : */
79 #define F_UWP 0x1000 /* | */
81 /* The screen process ...)
82 * ... wants to write to pseudo */
83 #define W_WP(w) ((w)->w_pwin && ((w)->w_pwin->p_fdpat & F_PFRONT))
85 /* ... wants to write to window: user writes to window
86 * or stdout/stderr of pseudo are duplicated to window */
87 #define W_WW(w) (!((w)->w_pwin) || \
88 (((w)->w_pwin->p_fdpat & F_PMASK) == F_PBACK) || \
89 ((((w)->w_pwin->p_fdpat >> F_PSHIFT) & F_PMASK) == F_PBOTH) || \
90 ((((w)->w_pwin->p_fdpat >> (F_PSHIFT * 2)) & F_PMASK) == F_PBOTH))
92 /* ... wants to read from pseudowin */
93 #define W_RP(w) ((w)->w_pwin && ((w)->w_pwin->p_fdpat & \
94 ((F_PFRONT << (F_PSHIFT * 2)) | (F_PFRONT << F_PSHIFT)) ))
96 /* ... wants to read from window */
97 #define W_RW(w) (!((w)->w_pwin) || ((w)->w_pwin->p_fdpat & F_PFRONT))
99 /* user input is written to pseudo */
100 #define W_UWP(w) ((w)->w_pwin && ((w)->w_pwin->p_fdpat & F_UWP))
102 /* pseudo output has to be stuffed in window */
103 #define W_PTOW(w) (\
104 ((w)->w_pwin->p_fdpat & F_PMASK << F_PSHIFT) == F_PBOTH << F_PSHIFT || \
105 ((w)->w_pwin->p_fdpat & F_PMASK << F_PSHIFT * 2) == F_PBOTH << F_PSHIFT * 2 )
107 /* window output has to be stuffed in pseudo */
108 #define W_WTOP(w) (((w)->w_pwin->p_fdpat & F_PMASK) == F_PBOTH)
110 #endif /* PSEUDOS */
112 /* definitions for wlocktype */
113 #define WLOCK_OFF 0 /* all in w_userbits can write */
114 #define WLOCK_AUTO 1 /* who selects first, can write */
115 #define WLOCK_ON 2 /* user writes even if deselected */
118 #ifdef COPY_PASTE
119 struct paster
121 char *pa_pastebuf; /* this gets pasted in the window */
122 char *pa_pasteptr; /* pointer in pastebuf */
123 int pa_pastelen; /* bytes left to paste */
124 struct layer *pa_pastelayer; /* layer to paste into */
125 struct event pa_slowev; /* slowpaste event */
127 #else
128 struct paster;
129 #endif
131 struct win
133 struct win *w_next; /* next window */
134 int w_type; /* type of window */
135 void *w_data;
136 struct layer w_layer; /* our layer */
137 struct layer *w_savelayer; /* the layer to keep */
138 int w_blocked; /* block input */
139 #ifdef PSEUDOS
140 struct pseudowin *w_pwin; /* ptr to pseudo */
141 #endif
142 struct display *w_pdisplay; /* display for printer relay */
143 struct display *w_lastdisp; /* where the last input was made */
144 int w_number; /* window number */
145 struct event w_readev;
146 struct event w_writeev;
147 struct event w_silenceev; /* silence event */
148 int w_ptyfd; /* fd of the master pty */
149 char w_inbuf[IOSIZE];
150 int w_inlen;
151 char w_outbuf[IOSIZE];
152 int w_outlen;
153 int w_aflag; /* (-a option) */
154 char *w_title; /* name of the window */
155 char *w_akachange; /* autoaka hack */
156 char w_akabuf[MAXSTR]; /* aka buffer */
157 int w_autoaka; /* autoaka hack */
158 struct win *w_group; /* window group we belong to */
159 int w_intermediate; /* char used while parsing ESC-seq */
160 int w_args[MAXARGS]; /* emulator args */
161 int w_NumArgs;
163 #ifdef MULTIUSER
164 int w_wlock; /* WLOCK_AUTO, WLOCK_OFF, WLOCK_ON */
165 struct acluser *w_wlockuser; /* NULL when unlocked or user who writes */
166 AclBits w_userbits[ACL_BITS_PER_WIN];
167 AclBits w_lio_notify; /* whom to tell when lastio+seconds < time() */
168 AclBits w_mon_notify; /* whom to tell monitor statis */
169 #endif
171 enum state_t w_state; /* parser state */
172 enum string_t w_StringType;
173 struct mline *w_mlines;
174 struct mchar w_rend; /* current rendition */
175 #ifdef FONT
176 char w_FontL; /* character font GL */
177 char w_FontR; /* character font GR */
178 # ifdef ENCODINGS
179 char w_FontE; /* character font GR locked */
180 # endif
181 int w_Charset; /* charset number GL */
182 int w_CharsetR; /* charset number GR */
183 int w_charsets[4]; /* Font = charsets[Charset] */
184 #endif
185 int w_ss;
186 int w_saved;
187 int w_Saved_x, w_Saved_y;
188 struct mchar w_SavedRend;
189 #ifdef FONT
190 int w_SavedCharset;
191 int w_SavedCharsetR;
192 int w_SavedCharsets[4];
193 #endif
194 int w_top, w_bot; /* scrollregion */
195 int w_wrap; /* autowrap */
196 int w_origin; /* origin mode */
197 int w_insert; /* window is in insert mode */
198 int w_keypad; /* keypad mode */
199 int w_cursorkeys; /* appl. cursorkeys mode */
200 int w_revvid; /* reverse video */
201 int w_curinv; /* cursor invisible */
202 int w_curvvis; /* cursor very visible */
203 int w_autolf; /* automatic linefeed */
204 char *w_hstatus; /* hardstatus line */
205 int w_gr; /* enable GR flag */
206 int w_c1; /* enable C1 flag */
207 int w_bce; /* enable backcol erase */
208 #if 0
209 int w_encoding; /* for input and paste */
210 #endif
211 int w_decodestate; /* state of our input decoder */
212 #ifdef DW_CHARS
213 int w_mbcs; /* saved char for multibytes charset */
214 #endif
215 char w_string[MAXSTR];
216 char *w_stringp;
217 char *w_tabs; /* line with tabs */
218 int w_bell; /* bell status of this window */
219 int w_flow; /* flow flags */
220 struct logfile *w_log; /* log to file */
221 int w_logsilence; /* silence in secs */
222 int w_monitor; /* monitor status */
223 int w_silencewait; /* wait for silencewait secs */
224 int w_silence; /* silence status (Lloyd Zusman) */
225 char w_vbwait;
226 char w_norefresh; /* dont redisplay when switching to that win */
227 #ifdef RXVT_OSC
228 char w_xtermosc[4][MAXSTR]; /* special xterm/rxvt escapes */
229 #endif
230 int w_mouse; /* mouse mode 0,9,1000 */
231 #ifdef HAVE_BRAILLE
232 int w_bd_x, w_bd_y; /* Braille cursor position */
233 #endif
235 #ifdef COPY_PASTE
236 int w_slowpaste; /* do careful writes to the window */
237 int w_histheight; /* all histbases are malloced with width * histheight */
238 int w_histidx; /* 0 <= histidx < histheight; where we insert lines */
239 struct mline *w_hlines; /* history buffer */
240 struct paster w_paster; /* paste info */
241 #else
242 int w_histheight; /* always 0 */
243 #endif
244 int w_pid; /* process at the other end of ptyfd */
245 int w_deadpid; /* saved w_pid of a process that closed the ptyfd to us */
247 char *w_cmdargs[MAXARGS]; /* command line argument vector */
248 char *w_dir; /* directory for chdir */
249 char *w_term; /* TERM to be set instead of "screen" */
251 int w_lflag; /* login flag */
252 slot_t w_slot; /* utmp slot */
253 #if defined (UTMPOK)
254 struct utmp w_savut; /* utmp entry of this window */
255 #endif
257 char w_tty[MAXSTR];
259 int w_zauto;
260 #ifdef ZMODEM
261 struct display *w_zdisplay;
262 #endif
263 #ifdef BUILTIN_TELNET
264 struct sockaddr_in w_telsa;
265 char w_telbuf[IOSIZE];
266 int w_telbufl;
267 char w_telmopts[256];
268 char w_telropts[256];
269 int w_telstate;
270 char w_telsubbuf[128];
271 int w_telsubidx;
272 struct event w_telconnev;
273 #endif
274 struct mline *w_alt_mlines;
275 int w_alt_width;
276 int w_alt_height;
277 int w_alt_histheight;
278 int w_alt_x, w_alt_y;
279 #ifdef COPY_PASTE
280 struct mline *w_alt_hlines;
281 int w_alt_histidx;
282 #endif
283 #ifdef SCRIPT
284 struct
286 struct script_event canresize;
287 struct script_event onresize;
288 struct script_event onfocus;
289 struct script_event onleave;
290 struct script_event onhide;
291 struct script_event onshow;
292 } w_sev; /*For Script events. */
293 #endif
297 #define w_encoding w_layer.l_encoding
298 #define w_width w_layer.l_width
299 #define w_height w_layer.l_height
300 #define w_x w_layer.l_x
301 #define w_y w_layer.l_y
303 /* definitions for w_type */
304 #define W_TYPE_PTY 0
305 #define W_TYPE_PLAIN 1
306 #define W_TYPE_TELNET 2
307 #define W_TYPE_GROUP 3
311 * Definitions for flow
312 * 000 -(-) flow off, auto would be off
313 * 001 +(-) flow on , auto would be off
314 * 010 -(+) flow off, auto would be on
315 * 011 +(+) flow on , auto would be on
316 * 100 - flow auto, currently off
317 * 111 + flow auto, currently on
318 * Application controls auto_flow via TIOCPKT, if available,
319 * else via application keypad mode.
321 #define FLOW_NOW (1<<0)
322 #define FLOW_AUTO (1<<1)
323 #define FLOW_AUTOFLAG (1<<2)
327 * WIN gives us a reference to line y of the *whole* image
328 * where line 0 is the oldest line in our history.
329 * y must be in whole image coordinate system, not in display.
332 #define WIN(y) ((y < fore->w_histheight) ? \
333 &fore->w_hlines[(fore->w_histidx + y) % fore->w_histheight] \
334 : &fore->w_mlines[y - fore->w_histheight])
336 #define Layer2Window(l) ((struct win *)(l)->l_bottom->l_data)