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 |
#if HAVE_CWCHAR |
26 |
# include <cwchar> |
27 |
#elif HAVE_WCHAR_H |
28 |
# include <wchar.h> |
29 |
#else |
30 |
// stdlib.h might provide it |
31 |
#endif |
32 |
|
33 |
#include "ptytty.h" |
34 |
#include "logging.h" |
35 |
|
36 |
extern "C" { |
37 |
#include <X11/Intrinsic.h> /* Xlib, Xutil, Xresource, Xfuncproto */ |
38 |
} |
39 |
|
40 |
/* |
41 |
* If we haven't pulled in typedef's like int16_t then do them ourself |
42 |
* type of (normal and unsigned) basic sizes |
43 |
*/ |
44 |
@rxvt_int16_typedef@ |
45 |
@rxvt_uint16_typedef@ |
46 |
@rxvt_int32_typedef@ |
47 |
@rxvt_uint32_typedef@ |
48 |
|
49 |
/* whatever normal size corresponds to a integer pointer */ |
50 |
@rxvt_intp_define@ |
51 |
/* whatever normal size corresponds to a unsigned integer pointer */ |
52 |
@rxvt_u_intp_define@ |
53 |
|
54 |
struct rxvt_fontset; |
55 |
struct rxvt_color; |
56 |
struct rxvt_vars; /* defined later on */ |
57 |
struct rxvt_term; |
58 |
struct rxvt_display; |
59 |
struct rxvt_im; |
60 |
struct rxvt_drawable; |
61 |
|
62 |
typedef struct rxvt_term *rxvt_t; |
63 |
|
64 |
extern rxvt_t rxvt_current_term; |
65 |
|
66 |
#define SET_R(r) rxvt_current_term = const_cast<rxvt_term *>(r) |
67 |
#define GET_R rxvt_current_term |
68 |
|
69 |
typedef struct { |
70 |
int row; |
71 |
int col; |
72 |
} row_col_t; |
73 |
|
74 |
#if UNICODE_3 |
75 |
typedef uint32_t text_t; |
76 |
#else |
77 |
typedef uint16_t text_t; // saves lots of memory |
78 |
#endif |
79 |
typedef uint32_t rend_t; |
80 |
typedef int32_t tlen_t; // was int16_t, but this results in smaller code and memory use |
81 |
typedef int32_t tlen_t_; // specifically for use in the line_t structure |
82 |
|
83 |
struct line_t; |
84 |
|
85 |
/* |
86 |
* terminal limits: |
87 |
* |
88 |
* width : 1 <= width |
89 |
* height : 1 <= height |
90 |
* ncol : 1 <= ncol <= MAX(tlen_t) |
91 |
* nrow : 1 <= nrow <= MAX(int) |
92 |
* saveLines : 0 <= saveLines <= MAX(int) |
93 |
* term_start : 0 <= term_start < saveLines |
94 |
* total_rows : nrow + saveLines |
95 |
* |
96 |
* top_row : -saveLines <= top_row <= 0 |
97 |
* view_start : top_row <= view_start <= 0 |
98 |
* |
99 |
* | most coordinates are stored relative to term_start, |
100 |
* ROW_BUF | which is the first line of the terminal screen |
101 |
* |························= row_buf[0] |
102 |
* |························= row_buf[1] |
103 |
* |························= row_buf[2] etc. |
104 |
* | |
105 |
* +------------+···········= term_start + top_row |
106 |
* | scrollback | |
107 |
* | scrollback +---------+·= term_start + view_start |
108 |
* | scrollback | display | |
109 |
* | scrollback | display | |
110 |
* +------------+·display·+·= term_start |
111 |
* | terminal | display | |
112 |
* | terminal +---------+ |
113 |
* | terminal | |
114 |
* | terminal | |
115 |
* +------------+···········= term_stat + nrow - 1 |
116 |
* | |
117 |
* | |
118 |
* END······················= total_rows |
119 |
*/ |
120 |
|
121 |
struct TermWin_t { |
122 |
int width; /* window width [pixels] */ |
123 |
int height; /* window height [pixels] */ |
124 |
int fwidth; /* font width [pixels] */ |
125 |
int fheight; /* font height [pixels] */ |
126 |
int fbase; /* font ascent (baseline) [pixels] */ |
127 |
int ncol; /* window columns [characters] */ |
128 |
int nrow; /* window rows [characters] */ |
129 |
int focus; /* window has focus */ |
130 |
int mapped; /* window state mapped? */ |
131 |
int int_bwidth; /* internal border width */ |
132 |
int ext_bwidth; /* external border width */ |
133 |
int lineSpace; /* number of extra pixels between rows */ |
134 |
int saveLines; /* number of lines that fit in scrollback */ |
135 |
int total_rows; /* total number of rows in this terminal */ |
136 |
int term_start; /* term lines start here */ |
137 |
int view_start; /* scrollback view starts here */ |
138 |
int top_row; /* topmost row index of scrollback */ |
139 |
Window parent[6]; /* parent identifiers - we're parent[0] */ |
140 |
Window vt; /* vt100 window */ |
141 |
GC gc; /* GC for drawing */ |
142 |
Pixmap pixmap; |
143 |
rxvt_drawable *drawable; |
144 |
rxvt_fontset *fontset[4]; |
145 |
}; |
146 |
|
147 |
/* |
148 |
* screen accounting: |
149 |
* screen_t elements |
150 |
* row: Cursor row position : 0 <= row < nrow |
151 |
* col: Cursor column position : 0 <= col < ncol |
152 |
* tscroll: Scrolling region top row inclusive : 0 <= row < nrow |
153 |
* bscroll: Scrolling region bottom row inclusive : 0 <= row < nrow |
154 |
* |
155 |
* selection_t elements |
156 |
* clicks: 1, 2 or 3 clicks - 4 indicates a special condition of 1 where |
157 |
* nothing is selected |
158 |
* beg: row/column of beginning of selection : never past mark |
159 |
* mark: row/column of initial click : never past end |
160 |
* end: row/column of one character past end of selection |
161 |
* * Note: -nsaved <= beg.row <= mark.row <= end.row < nrow |
162 |
* * Note: col == -1 ==> we're left of screen |
163 |
* |
164 |
*/ |
165 |
typedef struct { |
166 |
row_col_t cur; /* cursor position on the screen */ |
167 |
int tscroll; /* top of settable scroll region */ |
168 |
int bscroll; /* bottom of settable scroll region */ |
169 |
unsigned int charset; /* character set number [0..3] */ |
170 |
unsigned int flags; /* see below */ |
171 |
row_col_t s_cur; /* saved cursor position */ |
172 |
unsigned int s_charset; /* saved character set number [0..3] */ |
173 |
char s_charset_char; |
174 |
rend_t s_rstyle; /* saved rendition style */ |
175 |
} screen_t; |
176 |
|
177 |
enum selection_op_t { |
178 |
SELECTION_CLEAR = 0, /* nothing selected */ |
179 |
SELECTION_INIT, /* marked a point */ |
180 |
SELECTION_BEGIN, /* started a selection */ |
181 |
SELECTION_CONT, /* continued selection */ |
182 |
SELECTION_DONE /* selection put in CUT_BUFFER0 */ |
183 |
}; |
184 |
|
185 |
typedef struct { |
186 |
wchar_t *text; /* selected text */ |
187 |
unsigned int len; /* length of selected text */ |
188 |
unsigned int screen; /* screen being used */ |
189 |
unsigned int clicks; /* number of clicks */ |
190 |
selection_op_t op; /* current operation */ |
191 |
bool rect; /* rectangluar selection? */ |
192 |
row_col_t beg; /* beginning of selection <= mark */ |
193 |
row_col_t mark; /* point of initial click <= end */ |
194 |
row_col_t end; /* one character past end point */ |
195 |
} selection_t; |
196 |
|
197 |
/* ------------------------------------------------------------------------- */ |
198 |
|
199 |
/* screen_t flags */ |
200 |
#define Screen_Relative (1<<0) /* relative origin mode flag */ |
201 |
#define Screen_VisibleCursor (1<<1) /* cursor visible? */ |
202 |
#define Screen_Autowrap (1<<2) /* auto-wrap flag */ |
203 |
#define Screen_Insert (1<<3) /* insert mode (vs. overstrike) */ |
204 |
#define Screen_WrapNext (1<<4) /* need to wrap for next char? */ |
205 |
#define Screen_DefaultFlags (Screen_VisibleCursor | Screen_Autowrap) |
206 |
|
207 |
/* rxvt_vars.options */ |
208 |
enum { |
209 |
# define def(name,idx) Opt_ ## name = 1UL << (idx), |
210 |
# define nodef(name) Opt_ ## name = 0, |
211 |
# include "optinc.h" |
212 |
# undef nodef |
213 |
# undef def |
214 |
}; |
215 |
|
216 |
/* ------------------------------------------------------------------------- */ |
217 |
|
218 |
typedef struct { |
219 |
char state; /* scrollbar state */ |
220 |
char init; /* scrollbar has been initialised */ |
221 |
unsigned int beg; /* slider sub-window begin height */ |
222 |
unsigned int end; /* slider sub-window end height */ |
223 |
unsigned int top; /* slider top position */ |
224 |
unsigned int bot; /* slider bottom position */ |
225 |
unsigned int style; /* style: rxvt, xterm, next */ |
226 |
unsigned int width; /* scrollbar width */ |
227 |
Window win; |
228 |
int (rxvt_term::*update)(int, int, int, int); |
229 |
|
230 |
void setIdle() { state = 1 ; } |
231 |
void setMotion() { state = 'm'; } |
232 |
void setUp() { state = 'U'; } |
233 |
void setDn() { state = 'D'; } |
234 |
} scrollBar_t; |
235 |
|
236 |
struct rxvt_vars : TermWin_t { |
237 |
scrollBar_t scrollBar; |
238 |
uint32_t options; |
239 |
XSizeHints szHint; |
240 |
rxvt_display *display; |
241 |
rxvt_color *pix_colors; |
242 |
rxvt_color *pix_colors_focused; |
243 |
#ifdef OFF_FOCUS_FADING |
244 |
rxvt_color *pix_colors_unfocused; |
245 |
#endif |
246 |
short numpix_colors; |
247 |
Cursor TermWin_cursor; /* cursor for vt window */ |
248 |
int sb_shadow; /* scrollbar shadow width */ |
249 |
int numlock_state; |
250 |
line_t *row_buf; // all lines, scrollback + terminal, circular, followed by temp_buf |
251 |
line_t *drawn_buf; // text on screen |
252 |
line_t *swap_buf; // lines for swap buffer |
253 |
char *tabs; /* per location: 1 == tab-stop */ |
254 |
screen_t screen; |
255 |
screen_t swap; |
256 |
selection_t selection; |
257 |
}; |
258 |
|
259 |
void rxvt_init (); |
260 |
bool rxvt_tainted (); |
261 |
|
262 |
#endif /* _RXVTLIB_H_ */ |
263 |
|