*** empty log message ***
[dana/urxvt.git] / src / rxvtlib.h.in
1 #ifndef _RXVTLIB_H_             /* include once only */
2 #define _RXVTLIB_H_
3
4 #include <cstdio>
5 #include <cctype>
6 #include <cerrno>
7 @include_stdarg_h@
8 @include_stdlib_h@
9 @include_stdint_h@
10 #include <sys/types.h>
11 @include_unistd_h@
12 @include_string_h@
13 @include_fcntl_h@
14 @include_util_h@
15 @include_assert_h@
16 @include_sys_ioctl_h@
17 @include_sys_time_h@
18 @include_time_h@
19 @include_sys_select_h@
20 @include_sys_strredir_h@
21
22 #include <sys/wait.h>
23 #include <sys/stat.h>
24
25 #include <cwchar>
26
27 extern "C" {
28 #include <X11/Intrinsic.h>      /* Xlib, Xutil, Xresource, Xfuncproto */
29 }
30
31 /*
32  * If we haven't pulled in typedef's like  int16_t  then do them ourself
33  * type of (normal and unsigned) basic sizes
34  */
35 @rxvt_int16_typedef@
36 @rxvt_uint16_typedef@
37 @rxvt_int32_typedef@
38 @rxvt_uint32_typedef@
39
40 /* whatever normal size corresponds to a integer pointer */
41 @rxvt_intp_define@
42 /* whatever normal size corresponds to a unsigned integer pointer */
43 @rxvt_u_intp_define@
44
45 struct rxvt_fontset;
46 struct rxvt_color;
47 struct rxvt_vars;               /* defined later on */
48 struct rxvt_term;
49 struct rxvt_display;
50 struct rxvt_im;
51 struct rxvt_drawable;
52
53 typedef struct rxvt_term *rxvt_t;
54
55 extern rxvt_t rxvt_current_term;
56
57 # define SET_R(r) rxvt_current_term = (r)
58 # define GET_R rxvt_current_term
59
60 #define scrollbar_visible()    scrollBar.state
61 #define menubar_visible()      menuBar.state
62
63 typedef struct {
64   int32_t         row;
65   int32_t         col;
66 } row_col_t;
67
68 #if UNICODE_3
69 typedef uint32_t text_t;
70 #else
71 typedef uint16_t text_t; // saves lots of memory
72 #endif
73 typedef uint32_t rend_t;
74
75 /*
76  * TermWin elements limits
77  *  width     : 1 <= width
78  *  height    : 1 <= height
79  *  ncol      : 1 <= ncol       <= MAX(int16_t)
80  *  nrow      : 1 <= nrow       <= MAX(int16_t)
81  *  saveLines : 0 <= saveLines  <= MAX(int16_t)
82  *  nscrolled : 0 <= nscrolled  <= saveLines
83  *  view_start: 0 <= view_start <= nscrolled
84  */
85
86 typedef struct {
87   uint16_t       width;         /* window width                    [pixels] */
88   uint16_t       height;        /* window height                   [pixels] */
89   uint16_t       fwidth;        /* font width                      [pixels] */
90   uint16_t       fheight;       /* font height                     [pixels] */
91   uint16_t       fbase;         /* font ascent (baseline)          [pixels] */
92   uint16_t       propfont;      /* font proportional flags                  */
93   uint16_t       ncol;          /* window columns              [characters] */
94   uint16_t       nrow;          /* window rows                 [characters] */
95   uint16_t       focus;         /* window has focus                         */
96   uint16_t       mapped;        /* window state mapped?                     */
97   uint16_t       int_bwidth;    /* internal border width                    */
98   uint16_t       ext_bwidth;    /* external border width                    */
99   uint16_t       lineSpace;     /* number of extra pixels between rows      */
100   uint16_t       saveLines;     /* number of lines that fit in scrollback   */
101   uint16_t       nscrolled;     /* number of line actually scrolled         */
102   uint16_t       view_start;    /* scrollback view starts here              */
103   Window         parent[6];     /* parent identifiers - we're parent[0]     */
104   Window         vt;            /* vt100 window                             */
105   GC             gc;            /* GC for drawing                           */
106   Pixmap         pixmap;
107   rxvt_fontset  *fontset;
108   rxvt_drawable *drawable;
109 } TermWin_t;
110
111 /*
112  * screen accounting:
113  * screen_t elements
114  *   text:      Contains all text information including the scrollback buffer.
115  *              Each line is length TermWin.ncol
116  *   tlen:      The length of the line or -1 for wrapped lines.
117  *   rend:      Contains rendition information: font, bold, colour, etc.
118  * * Note: Each line for both text and rend are only allocated on demand, and
119  *         text[x] is allocated <=> rend[x] is allocated  for all x.
120  *   row:       Cursor row position                   : 0 <= row < TermWin.nrow
121  *   col:       Cursor column position                : 0 <= col < TermWin.ncol
122  *   tscroll:   Scrolling region top row inclusive    : 0 <= row < TermWin.nrow
123  *   bscroll:   Scrolling region bottom row inclusive : 0 <= row < TermWin.nrow
124  *
125  * selection_t elements
126  *   clicks:    1, 2 or 3 clicks - 4 indicates a special condition of 1 where
127  *              nothing is selected
128  *   beg:       row/column of beginning of selection  : never past mark
129  *   mark:      row/column of initial click           : never past end
130  *   end:       row/column of one character past end of selection
131  * * Note: -TermWin.nscrolled <= beg.row <= mark.row <= end.row < TermWin.nrow
132  * * Note: col == -1 ==> we're left of screen
133  *
134  * Layout of text/rend information in the screen_t text/rend structures:
135  *   Rows [0] ... [TermWin.saveLines - 1]
136  *     scrollback region : we're only here if TermWin.view_start != 0
137  *   Rows [TermWin.saveLines] ... [TermWin.saveLines + TermWin.nrow - 1]
138  *     normal `unscrolled' screen region
139  */
140 typedef struct {
141   int16_t        *tlen; /* length of each text line                  */
142   text_t        **text; /* _all_ the text                            */
143   rend_t        **rend; /* rendition, uses RS_ flags                 */
144   row_col_t       cur;  /* cursor position on the screen             */
145   uint16_t        tscroll;      /* top of settable scroll region             */
146   uint16_t        bscroll;      /* bottom of settable scroll region          */
147   uint16_t        charset;      /* character set number [0..3]               */
148   unsigned int    flags;        /* see below                                 */
149   row_col_t       s_cur;        /* saved cursor position                     */
150   uint16_t        s_charset;    /* saved character set number [0..3]         */
151   char            s_charset_char;
152   rend_t          s_rstyle;     /* saved rendition style                     */
153 } screen_t;
154
155 enum selection_op_t {
156   SELECTION_CLEAR = 0,  /* nothing selected                          */
157   SELECTION_INIT,       /* marked a point                            */
158   SELECTION_BEGIN,      /* started a selection                       */
159   SELECTION_CONT,       /* continued selection                       */
160   SELECTION_DONE        /* selection put in CUT_BUFFER0              */
161 };
162
163 typedef struct {
164   wchar_t        *text;       /* selected text                             */
165   uint32_t        len;        /* length of selected text                   */
166   short           screen;     /* screen being used                         */
167   short           clicks;     /* number of clicks                          */
168   selection_op_t  op;         /* current operation                         */
169   row_col_t       beg;        /* beginning of selection   <= mark          */
170   row_col_t       mark;       /* point of initial click   <= end           */
171   row_col_t       end;        /* one character past end point              */
172 } selection_t;
173
174 /* ------------------------------------------------------------------------- */
175
176 /* screen_t flags */
177 #define Screen_Relative         (1<<0)  /* relative origin mode flag         */
178 #define Screen_VisibleCursor    (1<<1)  /* cursor visible?                   */
179 #define Screen_Autowrap         (1<<2)  /* auto-wrap flag                    */
180 #define Screen_Insert           (1<<3)  /* insert mode (vs. overstrike)      */
181 #define Screen_WrapNext         (1<<4)  /* need to wrap for next char?       */
182 #define Screen_DefaultFlags     (Screen_VisibleCursor|Screen_Autowrap)
183
184 /* rxvt_vars.Options */
185 #define Opt_console             (1UL<<0)
186 #define Opt_loginShell          (1UL<<1)
187 #define Opt_iconic              (1UL<<2)
188 #define Opt_visualBell          (1UL<<3)
189 #define Opt_mapAlert            (1UL<<4)
190 #define Opt_reverseVideo        (1UL<<5)
191 #define Opt_utmpInhibit         (1UL<<6)
192 #define Opt_scrollBar           (1UL<<7)
193 #define Opt_scrollBar_right     (1UL<<8)
194 #define Opt_scrollBar_floating  (1UL<<9)
195 #define Opt_meta8               (1UL<<10)
196 #define Opt_scrollTtyOutput     (1UL<<11)
197 #define Opt_scrollTtyKeypress   (1UL<<12)
198 #define Opt_transparent         (1UL<<13)
199 #define Opt_transparent_all     (1UL<<14)
200 #define Opt_15                  (1UL<<15) // UNALLOCATED
201 #define Opt_tripleclickwords    (1UL<<16)
202 #define Opt_scrollWithBuffer    (1UL<<17)
203 #define Opt_jumpScroll          (1UL<<18)
204 #define Opt_mouseWheelScrollPage (1UL<<19)
205 #define Opt_pointerBlank        (1UL<<20)
206 #define Opt_cursorBlink         (1UL<<21)
207 #ifdef NO_FRILLS
208 # define Opt_insecure            0
209 #else
210 # define Opt_insecure            (1UL<<22) // insecure esc sequences
211 #endif
212 #define Opt_secondaryScreen     (1UL<<23)
213 #define Opt_secondaryScroll     (1UL<<24)
214 /* place holder used for parsing command-line options */
215 #define Opt_Reverse             (1UL<<30)
216 #define Opt_Boolean             (1UL<<31)
217
218 #define DEFAULT_OPTIONS         (Opt_scrollBar | Opt_scrollTtyOutput | \
219                                  Opt_jumpScroll | Opt_secondaryScreen)
220
221 /* ------------------------------------------------------------------------- */
222
223 typedef struct {
224   short           state;
225   Window          win;
226   struct rxvt_drawable *drawable;
227 } menuBar_t;
228
229 typedef struct {
230   char            state;        /* scrollbar state                          */
231   char            init;         /* scrollbar has been initialised           */
232   short           beg;          /* slider sub-window begin height           */
233   short           end;          /* slider sub-window end height             */
234   short           top;          /* slider top position                      */
235   short           bot;          /* slider bottom position                   */
236   short           style;        /* style: rxvt, xterm, next                 */
237   short           width;        /* scrollbar width                          */
238   Window          win;
239   int             (rxvt_term::*update)(int, int, int, int);
240
241   void setIdle()   { state =  1 ; }
242   void setMotion() { state = 'm'; }
243   void setUp()     { state = 'U'; }
244   void setDn()     { state = 'D'; }
245 } scrollBar_t;
246
247 struct rxvt_vars {
248   TermWin_t       TermWin;
249   scrollBar_t     scrollBar;
250   menuBar_t       menuBar;
251   unsigned long   Options;
252   XSizeHints      szHint;
253   rxvt_display   *display;
254   rxvt_color     *PixColors;
255   short           numPixColors;
256   Cursor          TermWin_cursor;       /* cursor for vt window */
257   int             sb_shadow;    /* scrollbar shadow width                    */
258   int             cmd_fd;       /* pty file descriptor; connected to command */
259   int             tty_fd;       /* tty file descriptor; connected to child   */
260   int             numlock_state;
261   text_t        **drawn_text;   /* text drawn on screen (characters)         */
262   rend_t        **drawn_rend;   /* text drawn on screen (rendition)          */
263   text_t        **buf_text;
264   rend_t        **buf_rend;
265   char           *tabs;         /* per location: 1 == tab-stop               */
266   screen_t        screen;
267   screen_t        swap;
268   selection_t     selection;
269 };
270
271 void rxvt_init_signals ();
272 rxvt_t rxvt_init (int argc, const char *const *argv);
273
274 #endif                          /* _RXVTLIB_H_ */
275