1 /*--------------------------------*-H-*---------------------------------*
2  * File:    rxvtlib.h
3  *----------------------------------------------------------------------*
4  *
5  * All portions of code are copyright by their respective author/s.
6  * Copyright (c) 1997-2001   Geoff Wing <gcw@pobox.com>
7  * Copyright (c) 2004        Terry Griffin <griffint@pobox.com>
8  * Copyright (c) 2005        Teun Burgers <burgers@ecn.nl>
9  * Copyright (c) 2004-2005   Jingmin Zhou <jimmyzhou@users.sourceforge.net>
10  * Copyright (c) 2005        Gautam Iyer <gi1242@users.sourceforge.net>
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25  *----------------------------------------------------------------------*/
26 
27 #ifndef __RXVTLIB_H__
28 #define __RXVTLIB_H__
29 
30 /*
31  * Boolean variables
32  */
33 #ifdef __GNUC__
34 # define BOOLVAR(x, sz)	x:sz
35 #else
36 # define BOOLVAR(x, sz) x
37 #endif
38 
39 
40 /* type of unicode_t */
41 typedef uint32_t	unicode_t;
42 
43 
44 /*****************************************************************************
45  *                                 SECTION 2                                 *
46  *                      DO NOT TOUCH ANYTHING BELOW HERE                     *
47  *****************************************************************************/
48 
49 struct rxvt_vars;	/* defined later on */
50 struct rxvt_hidden;	/* not defined here */
51 
52 typedef struct {
53     int32_t         row;
54     int32_t         col;
55 } row_col_t;
56 
57 typedef unsigned char text_t;
58 #if defined(TTY_256COLOR) || defined(MULTICHAR_SET)
59 # define rend_t	    uint32_t
60 #else
61 # define rend_t	    uint16_t
62 #endif
63 
64 /* Size of the FIFO buffer */
65 #define FIFO_BUF_SIZE (512)
66 
67 /*
68  * TermWin elements limits
69  *  ncol      : 1 <= ncol       <= MAX(int16_t)
70  *  nrow      : 1 <= nrow       <= MAX(int16_t)
71  *  saveLines : 0 <= saveLines  <= MAX(int16_t)
72  *  nscrolled : 0 <= nscrolled  <= saveLines
73  *  view_start: 0 <= view_start <= nscrolled
74  */
75 
76 typedef struct {
77     uint16_t	    fwidth,	/* font width  [pixels] */
78 		    fheight;	/* font height [pixels] */
79 #ifdef XFT_SUPPORT
80     uint16_t	    pwidth,	/* propotionally spaced font width / height */
81 		    pheight;
82 #endif
83     uint16_t	    propfont;	/* font proportional flags */
84     uint16_t	    ncol;	/* window columns [characters] */
85     uint16_t	    nrow;	/* window rows [characters] */
86     uint16_t	    mapped; 	/* TermWin is mapped? */
87     uint16_t	    int_bwidth; /* internal border width */
88     uint16_t	    ext_bwidth; /* external border width */
89 
90     uint16_t	    maxTabWidth,    /* max width of tab title to display */
91 		    minVisibleTabs; /* Minimum number of tabs to try and keep
92 				       visible */
93 #ifndef NO_LINESPACE
94     uint16_t	    lineSpace;	/* space between rows */
95 #endif
96 
97     char	    BOOLVAR(focus,1);	/* window is focused? */
98     char	    enter;  /* pointer is in window? */
99 
100     Window	    parent; /* parent window */
101     GC		    gc;	    /* GC for drawing text */
102     XFontStruct*    font;   /* main font structure */
103 #ifndef NO_BOLDFONT
104     XFontStruct*    bfont;  /* bold font */
105 #endif
106 #ifdef MULTICHAR_SET
107     XFontStruct*    mfont;  /* Multichar font structure */
108 #endif
109 #ifdef USE_XIM
110     XFontSet	    fontset;
111 #endif
112 #ifdef XFT_SUPPORT
113     XftPattern*	    xftpattern;
114     XftFont	    *xftfont, *xftpfont, *xftPfont;
115 # ifdef MULTICHAR_SET
116     XftPattern*	    xftmpattern;
117     XftFont*	    xftmfont;
118     int		    xftmsize;
119 #  ifdef HAVE_ICONV_H
120     iconv_t	    xfticonv;
121 #  endif
122 # endif
123 # ifndef NO_BOLDFONT
124     XftFont*	    xftbfont;
125 # endif
126     char	    xftfnmono;	/* font is mono? */
127     char	    xftmono;	/* font and mfont are mono? */
128     int		    xftsize, xftpsize;
129 #endif	/* XFT_SUPPORT */
130 
131 # define PARENT_NUMBER	    (6)
132     int		    opacity;	/* transluscent window opaque degree */
133     int		    opacity_degree; /* opaque change degree */
134 
135 #ifdef TRANSPARENT
136     Window	    parenttree[PARENT_NUMBER];
137 #endif
138 
139 #ifdef TINTING_SUPPORT
140     int		    shade;  /* tinting shade percentage */
141 #endif
142 
143     int		    fade;   /* off-focus fading percentage */
144 
145 #ifdef TEXT_SHADOW
146     enum {
147 	SHADOW_NONE = 0,
148 	SHADOW_LEFT,
149 	SHADOW_RIGHT,
150 	SHADOW_TOP,
151 	SHADOW_BOTTOM,
152 	SHADOW_TOPLEFT,
153 	SHADOW_BOTRIGHT,
154 	SHADOW_TOPRIGHT,
155 	SHADOW_BOTLEFT,
156     } shadow_mode;
157     unsigned long   shadow; /* text shadow color */
158 # ifdef XFT_SUPPORT
159     XftColor	    xftshadow;
160 # endif
161 #endif
162 
163 #ifdef HAVE_X11_SM_SMLIB_H
164     SmcConn	    sm_conn;
165     IceConn	    ice_conn;
166     int		    ice_fd;
167     char*	    sm_client_id;
168 #endif
169 
170 #ifndef NO_BELL
171     unsigned long   vBellDuration;
172 #endif
173 } TermWin_t;
174 
175 
176 
177 /*
178  * screen accounting:
179  * screen_t elements
180  *   text:      Contains all text information including the scrollback buffer.
181  *              Each line is length TermWin.ncol
182  *   tlen:      The length of the line or -1 for wrapped lines.
183  *   rend:      Contains rendition information: font, bold, colour, etc.
184  *
185  *   NOTE: Each line for both text and rend are only allocated on demand, and
186  *         text[x] is allocated <=> rend[x] is allocated  for all x.
187  *
188  *   row:       Cursor row position                   : 0 <= row < TermWin.nrow
189  *   col:       Cursor column position                : 0 <= col < TermWin.ncol
190  *   tscroll:   Scrolling region top row inclusive    : 0 <= row < TermWin.nrow
191  *   bscroll:   Scrolling region bottom row inclusive : 0 <= row < TermWin.nrow
192  *
193  * selection_t elements
194  *   clicks:    1, 2 or 3 clicks - 4 indicates a special condition of 1 where
195  *              nothing is selected
196  *   beg:       row/column of beginning of selection  : never past mark
197  *   mark:      row/column of initial click           : never past end
198  *   end:       row/column of one character past end of selection
199  * * Note: -TermWin.nscrolled <= beg.row <= mark.row <= end.row < TermWin.nrow
200  * * Note: col == -1 ==> we're left of screen
201  *
202  * Layout of text/rend information in the screen_t text/rend structures:
203  *   Rows [0] ... [TermWin.saveLines - 1]
204  *     scrollback region : we're only here if TermWin.view_start != 0
205  *   Rows [TermWin.saveLines] ... [TermWin.saveLines + TermWin.nrow - 1]
206  *     normal `unscrolled' screen region
207  */
208 typedef struct {
209     text_t**	    text;	/* _all_ the text */
210     int16_t*	    tlen;	/* length of each text line */
211     rend_t**	    rend;	/* rendition, uses RS_ flags */
212     row_col_t       cur;	/* cursor position on the screen */
213     uint16_t	    tscroll;	/* top of settable scroll region */
214     uint16_t	    bscroll;	/* bottom of settable scroll region */
215     uint16_t	    charset;	/* character set number [0..3] */
216     unsigned int    flags;	/* see below */
217     row_col_t	    s_cur;	/* saved cursor position */
218     uint16_t	    s_charset;	/* saved character set number [0..3] */
219     char	    s_charset_char;
220     rend_t	    s_rstyle;	/* saved rendition style */
221 } screen_t;
222 
223 
224 typedef struct {
225     unsigned char*  text;   /* selected text */
226     uint32_t	    len;    /* length of selected text */
227     enum {
228 	SELECTION_CLEAR = 0,/* nothing selected */
229 	SELECTION_INIT,	    /* marked a point */
230 	SELECTION_BEGIN,    /* started a selection */
231 	SELECTION_CONT,	    /* continued selection */
232 	SELECTION_DONE	    /* selection put in CUT_BUFFER0 */
233     } op;		    /* current operation */
234     short	    vt;	    /* VT that has the selection */
235     short           screen; /* screen being used */
236     short           clicks; /* number of clicks */
237     row_col_t       beg;    /* beginning of selection <= mark */
238     row_col_t       mark;   /* point of initial click <= end */
239     row_col_t       end;    /* one character past end point */
240 } selection_t;
241 
242 typedef enum {
243     OLD_SELECT, OLD_WORD_SELECT, NEW_SELECT
244 } sstyle_t;
245 
246 /* ------------------------------------------------------------------------- */
247 
248 /* screen_t flags */
249 #define Screen_Relative		(1<<0)	/* relative origin mode flag */
250 #define Screen_VisibleCursor	(1<<1)	/* cursor visible? */
251 #define Screen_Autowrap		(1<<2)	/* auto-wrap flag */
252 #define Screen_Insert		(1<<3)	/* insert mode (vs. overstrike) */
253 #define Screen_WrapNext		(1<<4)	/* need to wrap for next char? */
254 #define Screen_DefaultFlags	(Screen_VisibleCursor|Screen_Autowrap)
255 
256 
257 #define IS_OPTION1		    (0x00000000)
258 #define IS_OPTION2		    (0x00000001)
259 #define IS_OPTION3		    (0x00000002)
260 #define IS_OPTION4		    (0x00000003)
261 #define OPTION_MASK		    (0x00000003)
262 #define MAX_OPTION_ARRAY	    (4)
263 
264 /* rxvt_vars.Options */
265 /*
266  * Bits corresponding to 1<<2 through 1<<30 can be used for option flags. 1<<31
267  * is reserved for "reverse" options (which I think is obsolete), and the least
268  * two significant bits are used to get the array index of r->Options.
269  */
270 #define	Opt_console		    ((1LU<<2) | IS_OPTION1)
271 #define Opt_loginShell		    ((1LU<<3) | IS_OPTION1)
272 #define Opt_iconic		    ((1LU<<4) | IS_OPTION1)
273 #define Opt_visualBell		    ((1LU<<5) | IS_OPTION1)
274 #define Opt_currentTabVBell	    ((1LU<<6) | IS_OPTION1)
275 #define Opt_mapAlert		    ((1LU<<7) | IS_OPTION1)
276 #define Opt_reverseVideo	    ((1LU<<8) | IS_OPTION1)
277 #define Opt_utmpInhibit		    ((1LU<<9) | IS_OPTION1)
278 #define Opt_scrollBar		    ((1LU<<10) | IS_OPTION1)
279 #define Opt_scrollBar_right	    ((1LU<<11) | IS_OPTION1)
280 #define Opt_scrollBar_floating	    ((1LU<<12) | IS_OPTION1)
281 #define Opt_meta8		    ((1LU<<13) | IS_OPTION1)
282 #define Opt_scrollTtyOutputInhibit  ((1LU<<14) | IS_OPTION1)
283 #define Opt_scrollTtyKeypress	    ((1LU<<15) | IS_OPTION1)
284 #define Opt_transparent		    ((1LU<<16) | IS_OPTION1)
285 #define Opt_forceTransparent	    ((1LU<<17) | IS_OPTION1)
286 #define Opt_mc_hack		    ((1LU<<18) | IS_OPTION1)
287 #define Opt_tripleclickwords	    ((1LU<<19) | IS_OPTION1)
288 #define Opt_mouseWheelScrollPage    ((1LU<<20) | IS_OPTION1)
289 #define Opt_pointerBlank	    ((1LU<<21) | IS_OPTION1)
290 #define Opt_cursorBlink		    ((1LU<<22) | IS_OPTION1)
291 #ifdef HAVE_SCROLLBARS
292 # define Opt_transparent_scrollbar  ((1LU<<23) | IS_OPTION1)
293 #endif
294 #ifdef HAVE_MENUBAR
295 # define Opt_transparent_menubar    ((1LU<<24) | IS_OPTION1)
296 # define Opt_showMenu		    ((1LU<<25) | IS_OPTION1)
297 #endif
298 #define Opt_transparent_tabbar	    ((1LU<<26) | IS_OPTION1)
299 #define Opt_tabPixmap		    ((1LU<<27) | IS_OPTION1)
300 #ifdef XFT_SUPPORT
301 # define Opt_xft		    ((1LU<<28) | IS_OPTION1)
302 #endif
303 #ifdef USE_FIFO
304 # define Opt_useFifo		    ((1LU<<29) | IS_OPTION1)
305 #endif/*USE_FIFO*/
306 #define DEFAULT_OPTIONS	    \
307     (Opt_scrollBar)
308 
309 /* rxvt_vars.Options2 */
310 #define Opt2_protectSecondary	    ((1LU<<2) | IS_OPTION2)
311 #define Opt2_cmdAllTabs		    ((1LU<<3) | IS_OPTION2)
312 #ifdef XFT_SUPPORT
313 # ifdef MULTICHAR_SET
314 #  define Opt2_xftNomFont	    ((1LU<<4) | IS_OPTION2)
315 #  define Opt2_xftSlowOutput	    ((1LU<<5) | IS_OPTION2)
316 # endif
317 # define Opt2_xftAntialias	    ((1LU<<6) | IS_OPTION2)
318 # define Opt2_xftHinting	    ((1LU<<7) | IS_OPTION2)
319 # define Opt2_xftAutoHint	    ((1LU<<8) | IS_OPTION2)
320 # define Opt2_xftGlobalAdvance	    ((1LU<<9) | IS_OPTION2)
321 #endif
322 #define Opt2_syncTabTitle	    ((1LU<<10) | IS_OPTION2)
323 #define Opt2_syncTabIcon	    ((1LU<<11) | IS_OPTION2)
324 #define Opt2_hideTabbar		    ((1LU<<12) | IS_OPTION2)
325 #define Opt2_bottomTabbar	    ((1LU<<13) | IS_OPTION2)
326 #define Opt2_borderLess		    ((1LU<<14) | IS_OPTION2)
327 #define Opt2_overrideRedirect	    ((1LU<<15) | IS_OPTION2)
328 #define Opt2_broadcast		    ((1LU<<16) | IS_OPTION2)
329 #define Opt2_hideButtons	    ((1LU<<17) | IS_OPTION2)
330 #define Opt2_veryBold		    ((1LU<<18) | IS_OPTION2)
331 #ifndef NO_BRIGHTCOLOR
332 # define Opt2_boldColors	    ((1LU<<19) | IS_OPTION2)
333 # define Opt_veryBright		    ((1LU<<20) | IS_OPTION2)
334 #endif
335 #define Opt2_noSysConfig	    ((1LU<<21) | IS_OPTION2)
336 #define Opt2_disableMacros	    ((1LU<<22) | IS_OPTION2)
337 #ifdef HAVE_X11_SM_SMLIB_H
338 # define Opt2_enableSessionMgt	    ((1LU<<23) | IS_OPTION2)
339 #endif
340 #define Opt2_linuxHomeEndKey	    ((1LU<<24) | IS_OPTION2)
341 #define Opt2_hlTabOnBell	    ((1LU<<25) | IS_OPTION2)
342 #define Opt2_smoothResize	    ((1LU<<26) | IS_OPTION2)
343 #define Opt2_smartResize	    ((1LU<<27) | IS_OPTION2)
344 #define Opt2_autohideTabbar	    ((1LU<<28) | IS_OPTION2)
345 #define Opt2_maximized		    ((1LU<<29) | IS_OPTION2)
346 #define Opt2_fullscreen		    ((1LU<<30) | IS_OPTION2)
347 
348 
349 #ifdef XFT_SUPPORT
350 # define DEFAULT_OPTIONS2   \
351     (Opt2_veryBold | Opt2_smartResize | Opt2_xftAntialias)
352 #else
353 # define DEFAULT_OPTIONS2   \
354     (Opt2_veryBold | Opt2_smartResize)
355 #endif
356 
357 #define DEFAULT_OPTIONS3    \
358     (IS_OPTION3)
359 #define DEFAULT_OPTIONS4    \
360     (IS_OPTION4)
361 
362 /* place holder used for parsing command-line options */
363 #define Opt_Reverse	    (1LU<<31)
364 
365 /* Macros to manipulate options (given an option array) */
366 #define ISSET_ARRAYOPT( array, option )	    \
367     ( (array)[ (option) & OPTION_MASK ] & ( (option) & ~OPTION_MASK ) )
368 
369 #define NOTSET_ARRAYOPT( array, option )    \
370     !ISSET_ARRAYOPT( array, option )
371 
372 #define SET_ARRAYOPT( array, option )	    \
373     ( (array)[ (option) & OPTION_MASK ] |= ( (option) & ~OPTION_MASK ) )
374 
375 #define UNSET_ARRAYOPT( array, option )	    \
376     ( (array)[ (option) & OPTION_MASK ] &= ~( (option) & ~OPTION_MASK ) )
377 
378 #define TOGGLE_ARRAYOPT( array, option )	    \
379     ( (array)[ (option) & OPTION_MASK ] ^= ( (option) & ~OPTION_MASK ) )
380 
381 /* Macros to manipulate standard options */
382 #define ISSET_OPTION(R, OPT)	\
383     ISSET_ARRAYOPT( (R)->Options, (OPT) )
384 
385 #define NOTSET_OPTION(R, OPT)	\
386     !ISSET_OPTION( (R), (OPT) )
387 
388 #define SET_OPTION(R, OPT)  	\
389     SET_ARRAYOPT( (R)->Options, (OPT) )
390 
391 #define UNSET_OPTION(R, OPT)  	\
392     UNSET_ARRAYOPT( (R)->Options, (OPT) )
393 
394 #define TOGGLE_OPTION(R, OPT)	\
395     TOGGLE_ARRAYOPT( (R)->Options, (OPT) )
396 
397 
398 
399 #define PROPFONT_NORMAL		    (1<<0)
400 #define PROPFONT_BOLD		    (1<<1)
401 #define PROPFONT_MULTI		    (1<<2)
402 
403 /*
404  * Weather or not we should use xftPfont / xftpfont while drawing text. This has
405  * ABSOLUTELY NOTHING to do with PROPFONT_* or the propfont junk. This is used
406  * for drawing tab titles / menubar / etc.
407  */
408 #define NO_PFONT		    (0)
409 #define USE_PFONT		    (1)
410 #define USE_BOLD_PFONT		    (2)
411 
412 /* ------------------------------------------------------------------------- */
413 
414 #ifdef HAVE_MENUBAR
415 typedef struct {
416     short           state;
417     Window          win;
418     GC		    gc;
419 # ifdef BACKGROUND_IMAGE
420     Pixmap	    pixmap;
421 # endif
422     unsigned long   fg;
423     unsigned long   bg;
424     unsigned long   topshadow;
425     unsigned long   botshadow;
426 
427 # ifdef XFT_SUPPORT
428     XftDraw	    *xftDraw;
429     XftColor	    xftFore;
430 # endif
431 } menuBar_t;
432 #endif
433 
434 
435 #ifdef HAVE_SCROLLBARS
436 typedef struct {
437     char            state;  /* scrollbar state */
438     char            init;   /* scrollbar has been initialised */
439     short           beg;    /* slider sub-window begin height */
440     short           end;    /* slider sub-window end height */
441     short           top;    /* slider top position */
442     short           bot;    /* slider bottom position */
443     short           style;  /* style: rxvt, xterm, next */
444     short           width;  /* scrollbar width */
445     Window          win;
446     int             (*update)(struct rxvt_vars *, int, int, int, int);
447 
448     GC		    gc;
449 # ifdef BACKGROUND_IMAGE
450     Pixmap	    pixmap;
451 # endif
452 # ifdef RXVT_SCROLLBAR
453     unsigned long   rxvt_fg;
454     unsigned long   rxvt_bg;
455     unsigned long   rxvt_topshadow;
456     unsigned long   rxvt_botshadow;
457 # endif
458 # ifdef XTERM_SCROLLBAR
459     unsigned long   xterm_fg;
460     unsigned long   xterm_bg;
461     unsigned long   xterm_shadow;
462 # endif
463 # ifdef PLAIN_SCROLLBAR
464     unsigned long   plain_fg;
465     unsigned long   plain_bg;
466 # endif
467 # ifdef NEXT_SCROLLBAR
468     unsigned long   next_fg;	/* black */
469     unsigned long   next_bg;	/* gray */
470     unsigned long   next_white;
471     unsigned long   next_dark;
472     GC		    next_stippleGC;
473     Pixmap	    next_dimple,
474 		    next_upArrow,
475 		    next_upArrowHi,
476 		    next_downArrow,
477 		    next_downArrowHi;
478 # endif
479 # ifdef SGI_SCROLLBAR
480     unsigned long   sgi_fg;	/* medium */
481     unsigned long   sgi_bg;	/* light */
482     unsigned long   sgi_black;
483     unsigned long   sgi_white;
484     unsigned long   sgi_lmedium;
485     unsigned long   sgi_dark;
486     unsigned long   sgi_vdark;
487     GC		    sgi_stippleGC;
488     Pixmap	    sgi_dimple,
489 		    sgi_upArrow,
490 		    sgi_upArrowHi,
491 		    sgi_upArrowLow,
492 		    sgi_downArrow,
493 		    sgi_downArrowHi,
494 		    sgi_downArrowLow;
495 # endif
496 } scrollBar_t;
497 #endif	/* HAVE_SCROLLBARS */
498 
499 
500 typedef struct {
501     char	state;	/* tabbar state */
502 
503     short	ltab;	/* last tab */
504     short	atab;	/* active tab */
505     short	ptab;	/* previous active tab */
506     short	fvtab;	/* first visible tab */
507     short	lvtab;	/* last visible tab */
508 
509     Window	win;
510 #ifdef BACKGROUND_IMAGE
511     Bool	    hasPixmap;	/* has a background Pixmap */
512 #endif
513     GC		gc;	/* tab background/foreground, grey25/black */
514     unsigned long   fg;	    /* foreground, black */
515     unsigned long   bg;	    /* background, grey25 */
516     unsigned long   ifg;    /* inactive tab foreground, black */
517     unsigned long   ibg;    /* inactive tab background, grey */
518     char	    rsfg;   /* fg resource has changed */
519     char	    rsbg;   /* bg resource has changed */
520     char	    rsifg;  /* ifg resource has changed */
521     char	    rsibg;  /* ibg resource has changed */
522     unsigned long   frame;	/* tab frame, white */
523     unsigned long   delimit;	/* delimit, dark grey */
524 #ifdef XFT_SUPPORT
525     XftDraw*	    xftwin; /* XFT window */
526     XftColor	    xftfg;  /* foreground */
527     XftColor	    xftifg; /* background */
528 #endif
529 } tabBar_t;
530 
531 
532 #ifdef BACKGROUND_IMAGE
533 typedef struct {
534     short           w, h, x, y;
535     Pixmap          pixmap;
536 } bgPixmap_t;
537 #endif
538 
539 
540 /* To suppress compile warning without xpm library */
541 #ifdef BACKGROUND_IMAGE
542 # ifndef HAVE_LIBXPM
543 #  define XpmCloseness	    (0)
544 #  define XpmColormap	    (0)
545 #  define XpmVisual	    (0)
546 #  define XpmDepth	    (0)
547 #  define XpmSize	    (0)
548 #  define XpmReturnPixels   (0)
549 typedef struct {
550     unsigned long   valuemask;
551     Visual*	    visual;
552     Colormap	    colormap;
553     unsigned int    depth;
554     unsigned int    width;
555     unsigned int    height;
556     unsigned int    closeness;
557 } XpmAttributes;
558 # endif	/* HAVE_LIBXPM */
559 #endif	/* BACKGROUND_IMAGE */
560 
561 
562 typedef enum {
563     TERMENV_XTERM = 0,
564     TERMENV_RXVT,
565     TERMENV_VT102,
566     TERMENV_VT100,
567     TERMENV_ANSI,
568     TERMENV_DUMB,
569 } termenv_t;
570 
571 struct term_t;
572 typedef struct {
573     /*
574      * Index to vts. If it's -1, then this term_t structure is not used.
575      * Otherwise, it is used by pointer vts[vts_idx]. This is to improve destroy
576      * performance so that we only need to do (i = page..ltab) vts[i] = vts[i+1]
577      * instead of vterm[i] = vterm[i+1].
578      */
579     short	    vts_idx;
580 
581     unsigned char   profileNum;	    /* Profile used to init settings */
582     int		    globalTabNum;   /* Number of tabs created before this tab
583 				       during this processes lifetime */
584 
585     /* moved from TermWin_t */
586     uint16_t	    saveLines;	/* number of lines to save */
587     uint16_t	    num_scr;	/* number of lines scrolled */
588     uint16_t	    nscrolled;	/* number of line actually scrolled */
589     uint16_t	    view_start;	/* scrollback view starts here */
590     uint16_t	    mapped;	/* window state mapped? */
591 
592     /* screen structure initialized? */
593     unsigned char   BOOLVAR(init_screen, 1);
594 
595     Window          vt; /* terminal window */
596 #ifdef XFT_SUPPORT
597     XftDraw*	    xftvt;
598 #endif
599 #ifdef BACKGROUND_IMAGE
600     Pixmap	    pixmap;	/* background image, NOT used by */
601     bgPixmap_t	    bg;		/* transparent window!!! */
602     XpmAttributes   xpm_attr;	/* original attr of image */
603 #endif
604 
605     /* Apparently, people like fg/bg colors for individual terminal */
606     unsigned long   p_fg,
607 		    p_bg,
608 		    p_fgfade,
609 		    p_bgfade;
610 #ifdef XFT_SUPPORT
611     XftColor	    p_xftfg,
612 		    p_xftbg,
613 		    p_xftfgfade,
614 		    p_xftbgfade;
615 #endif
616 
617     /* moved from rxvt_t */
618     text_t**	    drawn_text;	/* text drawn on screen (characters) */
619     rend_t**	    drawn_rend;	/* text drawn on screen (rendition) */
620     text_t**	    buf_text;
621     rend_t**	    buf_rend;
622     screen_t        screen;
623 #if NSCREENS
624     screen_t        swap;
625 #endif
626     /* move from hidden */
627     rend_t	    rstyle;
628 
629     uint16_t	    prev_ncol; /* previous columns */
630     uint16_t	    prev_nrow; /* previous rows */
631     /* moved from tab_t */
632     short		tab_width;	/* tab width */
633     char UNTAINTED *	tab_title;  	/* tab title */
634 
635     char	    *title_format;	/* Format to be used to display the tab
636 					   title */
637     char	    *winTitleFormat;	/* Format of the window title (used when
638 					   syncing the tab title */
639 
640     /* moved from rxvt_t */
641     int             cmd_fd; /* pty file descriptor; connected to command */
642     int             tty_fd; /* tty file descriptor; connected to child */
643     /* moved from hidden */
644     unsigned char   BOOLVAR( current_screen, 1);    /* PRIMARY / SECONDARY */
645 #ifdef POINTER_BLANK
646     unsigned char   BOOLVAR( hidden_pointer, 1);    /* pointer is hidden? */
647 #endif
648 
649     pid_t	    cmd_pid;
650     char*	    ttydev;
651 #ifndef RESET_TTY_TO_COMMON_DEFAULTS
652     struct stat     ttyfd_stat; /* original status of our tty */
653 #endif
654 #ifndef NO_SETOWNER_TTYDEV
655     unsigned char   next_tty_action;
656 #endif
657 
658     /* moved from hidden */
659     uint32_t	    PrivateModes;
660     uint32_t	    SavedModes;
661 
662 #ifdef UTMP_SUPPORT
663 #ifndef UTEMPTER_SUPPORT
664 # ifdef HAVE_STRUCT_UTMP
665     struct utmp     ut;
666 # endif
667 # if defined(HAVE_STRUCT_UTMPX) && !defined(HAVE_STRUCT_UTMP)
668     struct utmpx    utx;
669 # endif
670 # if (defined(HAVE_STRUCT_UTMP) && defined(HAVE_UTMP_PID)) || defined(HAVE_STRUCT_UTMPX)
671     char            ut_id[5];
672 # endif
673     int             utmp_pos;
674 #endif	/* UTEMPTER_SUPPORT */
675     unsigned char   next_utmp_action;
676 #endif
677 
678 #if 0
679     char**	    command_argv;
680     int		    command_argc;
681 #endif
682 
683     /* move from rxvt_hidden */
684     ttymode_t	    tio;
685     unsigned int    ttymode;
686     char	    rvideo;
687 #ifdef MULTICHAR_SET
688     char	    chstat,
689     /* set ==> we only got half a glyph */
690 		    lost_multi,
691     /* set ==> currently using 2 bytes per glyph */
692 		    multi_byte;
693 #endif
694     char	    charsets[4];
695 
696     /* need to hold the terminal?
697      *   hold == 0: not hold
698      *   hold == 1: hold
699      *   hold >  1: can destroy the terminal now
700      */
701     unsigned char   BOOLVAR(hold,2),
702 		    BOOLVAR(holdOption,3),  /* Copy of the profile option for
703 					       this tab.*/
704 		    BOOLVAR(gotEIO,1),	    /* Read on this terminal's fd
705 					       got EIO */
706 		    BOOLVAR(dead,1),	    /* the terminal is dead or alive? */
707 		    BOOLVAR(highlight,1);   /* the terminal is highlighted? */
708     int		    status;		    /* Status of child process after it
709 					       exits */
710 
711     /* the terminal TERM type */
712     termenv_t	    termenv;
713 
714     int		    scrolled_lines;	/* If this tab is producing lots of
715 					   data, this is the number of lines
716 					   that have scrolled without a refresh
717 					   request */
718 
719     short	    monitor_tab;	/* monitor tab status value,
720 	                                 * see TAB_MON_* constants for possible values
721 					 */
722 
723     int		    monitor_nbytes_read;    /* number of bytes read since
724                                                monitor-start */
725     struct	    timeval monitor_start;  /* epoch time of monitor starttime
726 					       of the tab */
727 
728     /*
729      * Moved from hidden: want_refresh needs to be local to each tab.
730      * want_full_refresh, refresh_type (except for SMOOTH_REFRESH), and
731      * want_clip_refresh should be window (not tab) variables.
732      */
733     unsigned char   BOOLVAR( want_refresh, 1);		/* Awaiting screen
734 							   refresh */
735 
736     int		    nbytes_last_read;	/* Number of bytes read on the last
737 					   read() call to child's fd */
738 
739     /*
740      * Data we want to write into cmd_fd is buffered in here, before being
741      * written by rxvt_tt_write(). [Child's input buffer]
742      */
743     unsigned char   *v_buffer,		/* pointer to physical buffer */
744 		    *v_bufstr,		/* beginning of area to write */
745 		    *v_bufptr,		/* end of area to write */
746 		    *v_bufend;		/* end of physical buffer */
747 
748     /*
749      * Data read from cmd_fd is buffered in here [Child's output buffer]
750      */
751     unsigned char   *cmdbuf_escstart,	/* Start of an escape sequence */
752 		    *cmdbuf_escfail,	/* Position where processing of an
753 					   escape sequence last failed */
754 		    *cmdbuf_ptr,	/* current char */
755 		    *cmdbuf_endp;	/* End of read child's output */
756     unsigned char   cmdbuf_base[BUFSIZ];
757 } term_t;
758 
759 #define TAB_MON_OFF 0            /* tab monitoring off */
760 #define TAB_MON_ACTIVITY 1       /* monitor for activity */
761 #define TAB_MON_INACTIVITY 2     /* monitor for inactivity */
762 #define TAB_MON_AUTO 3           /* automatic discovery of monitor type */
763 #define TAB_MON_NOTIFICATION 4   /* inactivity/activity detected, notification needed */
764 
765 
766 /* Possible values for macros.modFlags */
767 #define MACRO_CTRL	(1U << 0)
768 #define MACRO_META	(1U << 1)
769 #define MACRO_SHIFT	(1U << 2)
770 #define MACRO_PRIMARY	(1U << 3)
771 
772 /* Number of bits used by modifiers in modFlags */
773 #define MACRO_N_MOD_BITS    (4)
774 #define MACRO_MODMASK	\
775     ( MACRO_CTRL | MACRO_META | MACRO_SHIFT | MACRO_PRIMARY )
776 #define MACRO_MAX_CHAINLEN  (0xf)
777 
778 /* Get / set the macro number from modFlags */
779 #define MACRO_GET_NUMBER(x)	\
780     (( (x) & ~MACRO_MODMASK ) >> MACRO_N_MOD_BITS)
781 
782 
783 /*
784  * Action to take when a macro is called / menu item is selected.
785  */
786 typedef struct {
787     unsigned short  type;   /* must not be changed; first element */
788     unsigned short  len;    /* strlen (str) */
789     unsigned char   *str;   /* action to take */
790 } action_t;
791 
792 /* Values for macro_t.type. Must sync this with macroNames from macros.c */
793 enum {
794     MacroFnDummy=0,
795     MacroFnEsc,
796     MacroFnStr,
797     MacroFnNewTab,
798     MacroFnExec,
799     MacroFnClose,
800     MacroFnGoto,
801     MacroFnMove,
802     MacroFnScroll,
803     MacroFnCopy,
804     MacroFnPaste,
805     MacroFnPasteFile,
806     MacroFnMonitorTab,
807     MacroFnToggleSubwin,
808     MacroFnFont,
809     MacroFnToggleVeryBold,
810     MacroFnToggleBoldColors,
811     MacroFnToggleVeryBright,
812     MacroFnToggleTransp,
813     MacroFnToggleBcst,
814     MacroFnToggleHold,
815     MacroFnToggleFullscreen,
816     MacroFnRaise,
817     MacroFnSetTitle,
818     MacroFnUseFifo,
819     MacroFnPrintScreen,
820     MacroFnSaveConfig,
821     MacroFnToggleMacros,
822     NMACRO_FUNCS
823 } macroFnNames;
824 
825 typedef unsigned char macro_priority_t;
826 typedef struct {
827     KeySym		keysym;
828     unsigned char	modFlags;	/* First 4 bits are the action order
829 					   number. Last four bits are the
830 					   modifiers */
831     macro_priority_t	priority;
832     action_t		action;
833 } macros_t;
834 
835 /*
836  * profile_t structure. Contains information about each profile (formerly the
837  * vt%d.xx resources.
838  */
839 typedef struct _profile_t
840 {
841     unsigned long	fg,
842 			bg;
843 #ifdef XFT_SUPPORT
844     XftColor		xftfg,
845 			xftbg;
846 #endif
847     unsigned long	fg_fade,
848 			bg_fade;
849 # ifdef XFT_SUPPORT
850     XftColor		xftfg_fade,
851 			xftbg_fade;
852 # endif
853 
854     int			saveLines;
855 
856     unsigned char	BOOLVAR( holdOption, 3 );
857 
858     /*
859      * Each profile also has a tab title, and command associated to it. However
860      * since that's already stored in our resource options, we don't need
861      * pointers for it here.
862      */
863 } profile_t;
864 
865 
866 typedef struct rxvt_vars {
867     /*
868      * These ``hidden'' items are not for public consumption and must not be
869      * accessed externally
870      *
871      * 2006-02-19 gi1242: mrxvt was forked from rxvt. In rxvt, they compiled
872      * common rxvt functions into a library "rxvtlib". Thus when loading
873      * multiple versions of rxvt, this common code was linked to, saving some
874      * memory.
875      *
876      * With tabs, we of course won't find this as useful. With grand dreams of
877      * multiple windows, we'll never need it :).
878      */
879     struct rxvt_hidden *h;
880 
881     /*
882      * Exposed items
883      *   Changes to structure here require library version number change
884      */
885     TermWin_t	    TermWin;
886 #ifdef HAVE_SCROLLBARS
887     scrollBar_t	    scrollBar;
888 #endif
889 #ifdef HAVE_MENUBAR
890     menuBar_t	    menuBar;
891 #endif
892     tabBar_t	    tabBar;
893     Display*	    Xdisplay;
894     uint32_t	    Options[MAX_OPTION_ARRAY];
895     XSizeHints      szHint;
896 
897     /* macros */
898     macros_t*	    macros;		    /* array of user defind macros */
899     unsigned short  nmacros,		    /* Number of macros defined */
900 		    maxMacros;		    /* max # of macros that can be
901 					       stored in memory pointed to by
902 					       "macros" */
903 
904     Colormap        Xcmap;
905 
906     unsigned long   *pixColorsFocus,
907 		    *pixColorsUnfocus;	    /* Arrays of size TOTAL_COLORS.
908 					       Pixel colors to be used when
909 					       focused / unfocussed. */
910     unsigned long   *pixColors;		    /* Array of size TOTAL_COLORS */
911 
912     int		    ntabs;		    /* Number of tabs created so far
913 					       during process lifetime */
914     int		    fgbg_tabnum;	    /* (Global) tab number corresponding
915 					       to which Color_fg/bg are set */
916 
917 #ifdef XFT_SUPPORT
918     XftColor*	    xftColors;		    /* Array of size TOTAL_COLORS */
919 
920     XftColor	    *xftColorsFocus,	    /* Same as above, but for Xft */
921 		    *xftColorsUnfocus;
922 # endif
923 
924 
925     profile_t	    profile[MAX_PROFILES];
926 
927     Cursor	    term_pointer;	    /* cursor for vt window */
928     int		    Xdepth;
929     int		    sb_shadow;		    /* scrollbar shadow width */
930     int		    Xfd;		    /* file descriptor of the X
931 					       connection */
932 
933     /*
934      * term_t structures and pointers.
935      *
936      * 2006-08-18 gi1242 TODO: This should be an array that grows dynamically in
937      * size. Plus we should only reserve enough memory for a our currently
938      * displayed term structures.
939      */
940     term_t	    vterm[MAX_PAGES];
941     term_t*	    vts[MAX_PAGES];
942 
943     short	    tabClicked;		    /* Tab clicked by user. Used for
944 					       moving tabs by drag and drop. */
945 
946     unsigned char   BOOLVAR( cleanDeadChilds, 1 ),
947 					    /* True if we have marked some
948 					       children as dead, but not called
949 					       rxvt_clean_cmd_page() to clean
950 					       them out */
951 		    BOOLVAR( gotEIO, 1 );   /* True if some read() got EIO */
952 
953     short	    ndead_childs;	    /* number of children that have
954 					       died */
955     short	    nAsyncChilds;	    /* Number of alive children launched
956 					       via rxvt_async_exec */
957     short	    asyncChilds[MAX_CHILDS];
958 					    /* PIDS of children exec'ed via
959 					     * rxvt_async_exec */
960 
961     int		    num_fds;		    /* number of fd to monitor */
962 
963 
964 #ifdef USE_FIFO
965     int		    fifo_fd;			/* fd to read macros from */
966     char	    fifo_buf[FIFO_BUF_SIZE];	/* Buffer size of data read from
967 						   fifo_fd */
968     char	    *fbuf_ptr;			/* Pointer where data from
969 						   fifo_fd should be read */
970     char	    *fifo_name;			/* Name of the fifo */
971 #endif
972 
973 
974     selection_t     selection;
975     sstyle_t	    selection_style;
976 
977     int		    numlock_state;
978     char*	    tabstop;		    /* per location: 1 == tab-stop */
979     enum enc_label  encoding_method;
980 
981     char**	    global_argv;
982     int		    global_argc;
983 
984 } rxvt_t;
985 
986 
987 typedef enum {
988     HIDE_MENUBAR = 0,
989     SHOW_MENUBAR,
990     HIDE_TABBAR,
991     SHOW_TABBAR,
992     HIDE_SCROLLBAR,
993     SHOW_SCROLLBAR,
994     RESIZE_FONT,
995     X_CONFIGURE,
996 } resize_reason_t;
997 
998 
999 /* MACROS for colors of individual terminals */
1000 #if 0
1001 #define VTFG(R, P)	\
1002     ((R)->pixColors[TOTAL_COLORS + (P)])
1003 #define VTBG(R, P)	\
1004     ((R)->pixColors[TOTAL_COLORS + MAX_PAGES + (P)])
1005 #ifdef XFT_SUPPORT
1006 # define VTXFTFG(R, P)	    \
1007     ((R)->xftColors[TOTAL_COLORS + (P)])
1008 # define VTXFTBG(R, P)	    \
1009     ((R)->xftColors[TOTAL_COLORS + MAX_PAGES + (P)])
1010 #endif	/* XFT_SUPPORT */
1011 #define ISSET_VTFG(R, P)    \
1012     (NULL != ((R)->h->rs[Rs_color + TOTAL_COLORS + (P)]))
1013 #define ISSET_VTBG(R, P)    \
1014     (NULL != ((R)->h->rs[Rs_color + TOTAL_COLORS + MAX_PAGES + (P)]))
1015 #endif
1016 
1017 #define VTFG(R, P)	\
1018     ((R)->profile[(P)].fg)
1019 #define VTBG(R, P)	\
1020     ((R)->profile[(P)].bg)
1021 
1022 #ifdef XFT_SUPPORT
1023 # define VTXFTFG(R, P)	    \
1024     ((R)->profile[(P)].xftfg)
1025 # define VTXFTBG(R, P)	    \
1026     ((R)->profile[(P)].xftbg)
1027 #endif	/* XFT_SUPPORT */
1028 
1029 # define VTFG_FADE(R, P)	    \
1030     ((R)->profile[(P)].fg_fade)
1031 # define VTBG_FADE(R, P)	    \
1032     ((R)->profile[(P)].bg_fade)
1033 
1034 # ifdef XFT_SUPPORT
1035 #  define VTXFTFG_FADE(R, P)	    \
1036     ((R)->profile[(P)].xftfg_fade)
1037 #  define VTXFTBG_FADE(R, P)	    \
1038     ((R)->profile[(P)].xftbg_fade)
1039 # endif /* XFT_SUPPORT */
1040 
1041 #define ISSET_VTFG(R, P)    \
1042     (NULL != ((R)->h->rs[Rs_foreground + (P)] ) )
1043 #define ISSET_VTBG(R, P)    \
1044     (NULL != ((R)->h->rs[Rs_background + (P)] ) )
1045 
1046 
1047 
1048 /* MACROS for tab/page number */
1049 #define ATAB(R)	    ((R)->tabBar.atab)
1050 #define LTAB(R)	    ((R)->tabBar.ltab)
1051 #define FVTAB(R)    ((R)->tabBar.fvtab)
1052 #define LVTAB(R)    ((R)->tabBar.lvtab)
1053 #define PTAB(R)	    ((R)->tabBar.ptab)
1054 
1055 #define APAGE(R)    ((R)->tabBar.atab)
1056 #define LPAGE(R)    ((R)->tabBar.ltab)
1057 #define FVPAGE(R)   ((R)->tabBar.fvtab)
1058 #define LVPAGE(R)   ((R)->tabBar.lvtab)
1059 #define PPAGE(R)    ((R)->tabBar.ptab)
1060 
1061 /* MACROS for vts structure */
1062 #define AVTS(R)	    ((R)->vts[(R)->tabBar.atab])
1063 #define LVTS(R)	    ((R)->vts[(R)->tabBar.ltab])
1064 #define PVTS(R, P)  ((R)->vts[(P)])
1065 
1066 #define SEL(R)	    ((R)->selection)
1067 
1068 #define ASCR(R)	    ((R)->vts[(R)->tabBar.atab]->screen)
1069 #define PSCR(R, P)  ((R)->vts[(P)]->screen)
1070 
1071 
1072 
1073 /* macros for private/saved mode of term_t */
1074 #define ISSET_PMODE(R, P, V)   \
1075     ((R)->vts[(P)]->PrivateModes & (V))
1076 #define SET_PMODE(R, P, V)  \
1077     ((R)->vts[(P)]->PrivateModes |= (V))
1078 #define UNSET_PMODE(R, P, V)  \
1079     ((R)->vts[(P)]->PrivateModes &= ~(V))
1080 #define ISSET_SMODE(R, P, V)   \
1081     ((R)->vts[(P)]->SavedModes & (V))
1082 #define SET_SMODE(R, P, V)  \
1083     ((R)->vts[(P)]->SavedModes |= (V))
1084 #define UNSET_SMODE(R, P, V)  \
1085     ((R)->vts[(P)]->SavedModes &= ~(V))
1086 
1087 
1088 /* Macro to determine weather we should the i-th tab or not */
1089 #define SHOULD_HOLD( r, i )					\
1090     (								\
1091       ( HOLD_ALWAYSBIT & PVTS((r),(i))->holdOption )		\
1092       ||							\
1093       (								\
1094 	( HOLD_NORMALBIT & PVTS((r),(i))->holdOption )		\
1095 	&& !WIFEXITED( PVTS((r),(i))->status )			\
1096       )								\
1097       ||							\
1098       (								\
1099 	( HOLD_STATUSBIT & PVTS((r),(i))->holdOption )		\
1100 	&& WEXITSTATUS( PVTS((r),(i))->status ) != 0		\
1101       )								\
1102     )
1103 
1104 
1105 /*****************************************************************************
1106  *                                PROTOTYPES                                 *
1107  *****************************************************************************/
1108 void	    rxvt_main_loop(rxvt_t *);
1109 rxvt_t*	    rxvt_init (int, const char *const *);
1110 
1111 #endif	    /* __RXVTLIB_H__ */
1112 /*----------------------- end-of-file (H source) -----------------------*/
1113