| 1 |
pcg |
1.3 |
#ifndef _RXVTLIB_H_ /* include once only */ |
| 2 |
pcg |
1.1 |
#define _RXVTLIB_H_ |
| 3 |
|
|
|
| 4 |
pcg |
1.16 |
#include <cstdio> |
| 5 |
|
|
#include <cctype> |
| 6 |
|
|
#include <cerrno> |
| 7 |
ayin |
1.81 |
#include <cstdarg> |
| 8 |
|
|
#include <cstdlib> |
| 9 |
pcg |
1.1 |
@include_stdint_h@ |
| 10 |
|
|
#include <sys/types.h> |
| 11 |
ayin |
1.81 |
#include <unistd.h> |
| 12 |
|
|
#include <cstring> |
| 13 |
|
|
#include <assert.h> |
| 14 |
pcg |
1.1 |
@include_sys_ioctl_h@ |
| 15 |
|
|
@include_sys_strredir_h@ |
| 16 |
|
|
|
| 17 |
root |
1.44 |
#if HAVE_CWCHAR |
| 18 |
|
|
# include <cwchar> |
| 19 |
root |
1.45 |
#elif HAVE_WCHAR_H |
| 20 |
root |
1.44 |
# include <wchar.h> |
| 21 |
|
|
#else |
| 22 |
|
|
// stdlib.h might provide it |
| 23 |
|
|
#endif |
| 24 |
pcg |
1.16 |
|
| 25 |
root |
1.74 |
using namespace std; |
| 26 |
|
|
|
| 27 |
pcg |
1.1 |
extern "C" { |
| 28 |
root |
1.73 |
#include <X11/Xlib.h> |
| 29 |
|
|
#include <X11/Xutil.h> |
| 30 |
|
|
#include <X11/Xresource.h> |
| 31 |
pcg |
1.1 |
} |
| 32 |
|
|
|
| 33 |
|
|
struct rxvt_fontset; |
| 34 |
|
|
struct rxvt_color; |
| 35 |
pcg |
1.3 |
struct rxvt_term; |
| 36 |
pcg |
1.12 |
struct rxvt_drawable; |
| 37 |
pcg |
1.1 |
|
| 38 |
pcg |
1.3 |
typedef struct rxvt_term *rxvt_t; |
| 39 |
|
|
|
| 40 |
|
|
extern rxvt_t rxvt_current_term; |
| 41 |
|
|
|
| 42 |
root |
1.66 |
#define SET_R(r) rxvt_current_term = const_cast<rxvt_term *>(r) |
| 43 |
root |
1.43 |
#define GET_R rxvt_current_term |
| 44 |
pcg |
1.1 |
|
| 45 |
|
|
typedef struct { |
| 46 |
root |
1.41 |
int row; |
| 47 |
|
|
int col; |
| 48 |
pcg |
1.1 |
} row_col_t; |
| 49 |
|
|
|
| 50 |
pcg |
1.16 |
#if UNICODE_3 |
| 51 |
pcg |
1.1 |
typedef uint32_t text_t; |
| 52 |
|
|
#else |
| 53 |
|
|
typedef uint16_t text_t; // saves lots of memory |
| 54 |
|
|
#endif |
| 55 |
|
|
typedef uint32_t rend_t; |
| 56 |
root |
1.59 |
typedef int32_t tlen_t; // was int16_t, but this results in smaller code and memory use |
| 57 |
|
|
typedef int32_t tlen_t_; // specifically for use in the line_t structure |
| 58 |
root |
1.49 |
|
| 59 |
root |
1.59 |
struct line_t; |
| 60 |
pcg |
1.1 |
|
| 61 |
|
|
/* |
| 62 |
root |
1.52 |
* terminal limits: |
| 63 |
|
|
* |
| 64 |
|
|
* width : 1 <= width |
| 65 |
|
|
* height : 1 <= height |
| 66 |
root |
1.53 |
* ncol : 1 <= ncol <= MAX(tlen_t) |
| 67 |
|
|
* nrow : 1 <= nrow <= MAX(int) |
| 68 |
|
|
* saveLines : 0 <= saveLines <= MAX(int) |
| 69 |
root |
1.65 |
* term_start : 0 <= term_start < saveLines |
| 70 |
root |
1.52 |
* total_rows : nrow + saveLines |
| 71 |
root |
1.65 |
* |
| 72 |
|
|
* top_row : -saveLines <= top_row <= 0 |
| 73 |
|
|
* view_start : top_row <= view_start <= 0 |
| 74 |
root |
1.52 |
* |
| 75 |
|
|
* | most coordinates are stored relative to term_start, |
| 76 |
|
|
* ROW_BUF | which is the first line of the terminal screen |
| 77 |
|
|
* |························= row_buf[0] |
| 78 |
|
|
* |························= row_buf[1] |
| 79 |
|
|
* |························= row_buf[2] etc. |
| 80 |
|
|
* | |
| 81 |
root |
1.65 |
* +------------+···········= term_start + top_row |
| 82 |
ayin |
1.78 |
* | scrollback | |
| 83 |
root |
1.65 |
* | scrollback +---------+·= term_start + view_start |
| 84 |
root |
1.52 |
* | scrollback | display | |
| 85 |
|
|
* | scrollback | display | |
| 86 |
|
|
* +------------+·display·+·= term_start |
| 87 |
|
|
* | terminal | display | |
| 88 |
|
|
* | terminal +---------+ |
| 89 |
|
|
* | terminal | |
| 90 |
|
|
* | terminal | |
| 91 |
|
|
* +------------+···········= term_stat + nrow - 1 |
| 92 |
|
|
* | |
| 93 |
|
|
* | |
| 94 |
|
|
* END······················= total_rows |
| 95 |
pcg |
1.1 |
*/ |
| 96 |
|
|
|
| 97 |
root |
1.49 |
struct TermWin_t { |
| 98 |
root |
1.41 |
int width; /* window width [pixels] */ |
| 99 |
|
|
int height; /* window height [pixels] */ |
| 100 |
|
|
int fwidth; /* font width [pixels] */ |
| 101 |
|
|
int fheight; /* font height [pixels] */ |
| 102 |
|
|
int fbase; /* font ascent (baseline) [pixels] */ |
| 103 |
|
|
int ncol; /* window columns [characters] */ |
| 104 |
|
|
int nrow; /* window rows [characters] */ |
| 105 |
|
|
int focus; /* window has focus */ |
| 106 |
|
|
int mapped; /* window state mapped? */ |
| 107 |
|
|
int int_bwidth; /* internal border width */ |
| 108 |
|
|
int ext_bwidth; /* external border width */ |
| 109 |
|
|
int lineSpace; /* number of extra pixels between rows */ |
| 110 |
|
|
int saveLines; /* number of lines that fit in scrollback */ |
| 111 |
root |
1.51 |
int total_rows; /* total number of rows in this terminal */ |
| 112 |
root |
1.49 |
int term_start; /* term lines start here */ |
| 113 |
root |
1.41 |
int view_start; /* scrollback view starts here */ |
| 114 |
root |
1.65 |
int top_row; /* topmost row index of scrollback */ |
| 115 |
pcg |
1.3 |
Window parent[6]; /* parent identifiers - we're parent[0] */ |
| 116 |
|
|
Window vt; /* vt100 window */ |
| 117 |
|
|
GC gc; /* GC for drawing */ |
| 118 |
|
|
Pixmap pixmap; |
| 119 |
pcg |
1.12 |
rxvt_drawable *drawable; |
| 120 |
root |
1.38 |
rxvt_fontset *fontset[4]; |
| 121 |
root |
1.49 |
}; |
| 122 |
pcg |
1.1 |
|
| 123 |
|
|
/* |
| 124 |
|
|
* screen accounting: |
| 125 |
|
|
* screen_t elements |
| 126 |
root |
1.49 |
* row: Cursor row position : 0 <= row < nrow |
| 127 |
|
|
* col: Cursor column position : 0 <= col < ncol |
| 128 |
|
|
* tscroll: Scrolling region top row inclusive : 0 <= row < nrow |
| 129 |
|
|
* bscroll: Scrolling region bottom row inclusive : 0 <= row < nrow |
| 130 |
pcg |
1.1 |
* |
| 131 |
|
|
* selection_t elements |
| 132 |
|
|
* clicks: 1, 2 or 3 clicks - 4 indicates a special condition of 1 where |
| 133 |
|
|
* nothing is selected |
| 134 |
|
|
* beg: row/column of beginning of selection : never past mark |
| 135 |
|
|
* mark: row/column of initial click : never past end |
| 136 |
|
|
* end: row/column of one character past end of selection |
| 137 |
root |
1.51 |
* * Note: -nsaved <= beg.row <= mark.row <= end.row < nrow |
| 138 |
pcg |
1.1 |
* * Note: col == -1 ==> we're left of screen |
| 139 |
|
|
* |
| 140 |
|
|
*/ |
| 141 |
|
|
typedef struct { |
| 142 |
root |
1.52 |
row_col_t cur; /* cursor position on the screen */ |
| 143 |
|
|
int tscroll; /* top of settable scroll region */ |
| 144 |
|
|
int bscroll; /* bottom of settable scroll region */ |
| 145 |
root |
1.38 |
unsigned int charset; /* character set number [0..3] */ |
| 146 |
pcg |
1.3 |
unsigned int flags; /* see below */ |
| 147 |
|
|
row_col_t s_cur; /* saved cursor position */ |
| 148 |
root |
1.38 |
unsigned int s_charset; /* saved character set number [0..3] */ |
| 149 |
pcg |
1.3 |
char s_charset_char; |
| 150 |
|
|
rend_t s_rstyle; /* saved rendition style */ |
| 151 |
pcg |
1.1 |
} screen_t; |
| 152 |
|
|
|
| 153 |
|
|
enum selection_op_t { |
| 154 |
pcg |
1.3 |
SELECTION_CLEAR = 0, /* nothing selected */ |
| 155 |
|
|
SELECTION_INIT, /* marked a point */ |
| 156 |
|
|
SELECTION_BEGIN, /* started a selection */ |
| 157 |
|
|
SELECTION_CONT, /* continued selection */ |
| 158 |
|
|
SELECTION_DONE /* selection put in CUT_BUFFER0 */ |
| 159 |
pcg |
1.1 |
}; |
| 160 |
|
|
|
| 161 |
|
|
typedef struct { |
| 162 |
root |
1.41 |
wchar_t *text; /* selected text */ |
| 163 |
|
|
unsigned int len; /* length of selected text */ |
| 164 |
|
|
unsigned int screen; /* screen being used */ |
| 165 |
|
|
unsigned int clicks; /* number of clicks */ |
| 166 |
|
|
selection_op_t op; /* current operation */ |
| 167 |
ayin |
1.77 |
bool rect; /* rectangular selection? */ |
| 168 |
root |
1.41 |
row_col_t beg; /* beginning of selection <= mark */ |
| 169 |
|
|
row_col_t mark; /* point of initial click <= end */ |
| 170 |
|
|
row_col_t end; /* one character past end point */ |
| 171 |
pcg |
1.1 |
} selection_t; |
| 172 |
|
|
|
| 173 |
|
|
/* ------------------------------------------------------------------------- */ |
| 174 |
|
|
|
| 175 |
|
|
/* screen_t flags */ |
| 176 |
root |
1.47 |
#define Screen_Relative (1<<0) /* relative origin mode flag */ |
| 177 |
|
|
#define Screen_VisibleCursor (1<<1) /* cursor visible? */ |
| 178 |
|
|
#define Screen_Autowrap (1<<2) /* auto-wrap flag */ |
| 179 |
|
|
#define Screen_Insert (1<<3) /* insert mode (vs. overstrike) */ |
| 180 |
|
|
#define Screen_WrapNext (1<<4) /* need to wrap for next char? */ |
| 181 |
root |
1.48 |
#define Screen_DefaultFlags (Screen_VisibleCursor | Screen_Autowrap) |
| 182 |
pcg |
1.1 |
|
| 183 |
root |
1.32 |
/* rxvt_vars.options */ |
| 184 |
root |
1.61 |
enum { |
| 185 |
ayin |
1.76 |
# define def(name,idx) Opt_ ## name = idx, |
| 186 |
|
|
# define nodef(name) Opt_ ## name = 0, |
| 187 |
root |
1.61 |
# include "optinc.h" |
| 188 |
|
|
# undef nodef |
| 189 |
|
|
# undef def |
| 190 |
ayin |
1.76 |
Opt_count |
| 191 |
root |
1.61 |
}; |
| 192 |
pcg |
1.1 |
|
| 193 |
|
|
/* ------------------------------------------------------------------------- */ |
| 194 |
|
|
|
| 195 |
|
|
typedef struct { |
| 196 |
pcg |
1.3 |
char state; /* scrollbar state */ |
| 197 |
|
|
char init; /* scrollbar has been initialised */ |
| 198 |
root |
1.38 |
unsigned int beg; /* slider sub-window begin height */ |
| 199 |
|
|
unsigned int end; /* slider sub-window end height */ |
| 200 |
|
|
unsigned int top; /* slider top position */ |
| 201 |
|
|
unsigned int bot; /* slider bottom position */ |
| 202 |
|
|
unsigned int style; /* style: rxvt, xterm, next */ |
| 203 |
|
|
unsigned int width; /* scrollbar width */ |
| 204 |
pcg |
1.3 |
Window win; |
| 205 |
pcg |
1.10 |
int (rxvt_term::*update)(int, int, int, int); |
| 206 |
pcg |
1.7 |
|
| 207 |
|
|
void setIdle() { state = 1 ; } |
| 208 |
|
|
void setMotion() { state = 'm'; } |
| 209 |
|
|
void setUp() { state = 'U'; } |
| 210 |
|
|
void setDn() { state = 'D'; } |
| 211 |
pcg |
1.1 |
} scrollBar_t; |
| 212 |
|
|
|
| 213 |
root |
1.49 |
struct rxvt_vars : TermWin_t { |
| 214 |
pcg |
1.3 |
scrollBar_t scrollBar; |
| 215 |
ayin |
1.76 |
uint8_t options[(Opt_count + 7) >> 3]; |
| 216 |
pcg |
1.3 |
XSizeHints szHint; |
| 217 |
root |
1.32 |
rxvt_color *pix_colors; |
| 218 |
|
|
rxvt_color *pix_colors_focused; |
| 219 |
root |
1.24 |
#ifdef OFF_FOCUS_FADING |
| 220 |
root |
1.32 |
rxvt_color *pix_colors_unfocused; |
| 221 |
root |
1.24 |
#endif |
| 222 |
pcg |
1.3 |
Cursor TermWin_cursor; /* cursor for vt window */ |
| 223 |
|
|
int sb_shadow; /* scrollbar shadow width */ |
| 224 |
|
|
int numlock_state; |
| 225 |
root |
1.64 |
line_t *row_buf; // all lines, scrollback + terminal, circular, followed by temp_buf |
| 226 |
root |
1.52 |
line_t *drawn_buf; // text on screen |
| 227 |
|
|
line_t *swap_buf; // lines for swap buffer |
| 228 |
pcg |
1.3 |
char *tabs; /* per location: 1 == tab-stop */ |
| 229 |
|
|
screen_t screen; |
| 230 |
|
|
screen_t swap; |
| 231 |
|
|
selection_t selection; |
| 232 |
|
|
}; |
| 233 |
pcg |
1.1 |
|
| 234 |
root |
1.32 |
void rxvt_init (); |
| 235 |
pcg |
1.1 |
|
| 236 |
pcg |
1.3 |
#endif /* _RXVTLIB_H_ */ |
| 237 |
pcg |
1.1 |
|