diff options
| -rw-r--r-- | st.c | 22 | ||||
| -rw-r--r-- | st.h | 21 | ||||
| -rw-r--r-- | x.c | 35 |
3 files changed, 39 insertions, 39 deletions
| @@ -95,6 +95,26 @@ enum escape_state { | |||
| 95 | ESC_DCS =128, | 95 | ESC_DCS =128, |
| 96 | }; | 96 | }; |
| 97 | 97 | ||
| 98 | /* Internal representation of the screen */ | ||
| 99 | typedef struct { | ||
| 100 | int row; /* nb row */ | ||
| 101 | int col; /* nb col */ | ||
| 102 | Line *line; /* screen */ | ||
| 103 | Line *alt; /* alternate screen */ | ||
| 104 | int *dirty; /* dirtyness of lines */ | ||
| 105 | TCursor c; /* cursor */ | ||
| 106 | int ocx; /* old cursor col */ | ||
| 107 | int ocy; /* old cursor row */ | ||
| 108 | int top; /* top scroll limit */ | ||
| 109 | int bot; /* bottom scroll limit */ | ||
| 110 | int mode; /* terminal mode flags */ | ||
| 111 | int esc; /* escape state flags */ | ||
| 112 | char trantbl[4]; /* charset table translation */ | ||
| 113 | int charset; /* current charset */ | ||
| 114 | int icharset; /* selected charset for sequence */ | ||
| 115 | int *tabs; | ||
| 116 | } Term; | ||
| 117 | |||
| 98 | /* CSI Escape sequence structs */ | 118 | /* CSI Escape sequence structs */ |
| 99 | /* ESC '[' [[ [<priv>] <arg> [;]] <mode> [<mode>]] */ | 119 | /* ESC '[' [[ [<priv>] <arg> [;]] <mode> [<mode>]] */ |
| 100 | typedef struct { | 120 | typedef struct { |
| @@ -181,11 +201,11 @@ static char *base64dec(const char *); | |||
| 181 | static ssize_t xwrite(int, const char *, size_t); | 201 | static ssize_t xwrite(int, const char *, size_t); |
| 182 | 202 | ||
| 183 | /* Globals */ | 203 | /* Globals */ |
| 184 | Term term; | ||
| 185 | int cmdfd; | 204 | int cmdfd; |
| 186 | pid_t pid; | 205 | pid_t pid; |
| 187 | int oldbutton = 3; /* button event on startup: 3 = release */ | 206 | int oldbutton = 3; /* button event on startup: 3 = release */ |
| 188 | 207 | ||
| 208 | static Term term; | ||
| 189 | static Selection sel; | 209 | static Selection sel; |
| 190 | static CSIEscape csiescseq; | 210 | static CSIEscape csiescseq; |
| 191 | static STREscape strescseq; | 211 | static STREscape strescseq; |
| @@ -76,26 +76,6 @@ typedef struct { | |||
| 76 | char state; | 76 | char state; |
| 77 | } TCursor; | 77 | } TCursor; |
| 78 | 78 | ||
| 79 | /* Internal representation of the screen */ | ||
| 80 | typedef struct { | ||
| 81 | int row; /* nb row */ | ||
| 82 | int col; /* nb col */ | ||
| 83 | Line *line; /* screen */ | ||
| 84 | Line *alt; /* alternate screen */ | ||
| 85 | int *dirty; /* dirtyness of lines */ | ||
| 86 | TCursor c; /* cursor */ | ||
| 87 | int ocx; /* old cursor col */ | ||
| 88 | int ocy; /* old cursor row */ | ||
| 89 | int top; /* top scroll limit */ | ||
| 90 | int bot; /* bottom scroll limit */ | ||
| 91 | int mode; /* terminal mode flags */ | ||
| 92 | int esc; /* escape state flags */ | ||
| 93 | char trantbl[4]; /* charset table translation */ | ||
| 94 | int charset; /* current charset */ | ||
| 95 | int icharset; /* selected charset for sequence */ | ||
| 96 | int *tabs; | ||
| 97 | } Term; | ||
| 98 | |||
| 99 | /* Purely graphic info */ | 79 | /* Purely graphic info */ |
| 100 | typedef struct { | 80 | typedef struct { |
| 101 | int tw, th; /* tty width and height */ | 81 | int tw, th; /* tty width and height */ |
| @@ -168,7 +148,6 @@ void *xrealloc(void *, size_t); | |||
| 168 | char *xstrdup(char *); | 148 | char *xstrdup(char *); |
| 169 | 149 | ||
| 170 | /* Globals */ | 150 | /* Globals */ |
| 171 | extern Term term; | ||
| 172 | extern int cmdfd; | 151 | extern int cmdfd; |
| 173 | extern pid_t pid; | 152 | extern pid_t pid; |
| 174 | extern int oldbutton; | 153 | extern int oldbutton; |
| @@ -130,7 +130,7 @@ static void xdrawglyphfontspecs(const XftGlyphFontSpec *, Glyph, int, int, int); | |||
| 130 | static void xdrawglyph(Glyph, int, int); | 130 | static void xdrawglyph(Glyph, int, int); |
| 131 | static void xclear(int, int, int, int); | 131 | static void xclear(int, int, int, int); |
| 132 | static int xgeommasktogravity(int); | 132 | static int xgeommasktogravity(int); |
| 133 | static void xinit(void); | 133 | static void xinit(int, int); |
| 134 | static void cresize(int, int); | 134 | static void cresize(int, int); |
| 135 | static void xresize(int, int); | 135 | static void xresize(int, int); |
| 136 | static int xloadfont(Font *, FcPattern *); | 136 | static int xloadfont(Font *, FcPattern *); |
| @@ -299,18 +299,16 @@ int | |||
| 299 | x2col(int x) | 299 | x2col(int x) |
| 300 | { | 300 | { |
| 301 | x -= borderpx; | 301 | x -= borderpx; |
| 302 | x /= win.cw; | 302 | LIMIT(x, 0, win.tw - 1); |
| 303 | 303 | return x / win.cw; | |
| 304 | return LIMIT(x, 0, term.col-1); | ||
| 305 | } | 304 | } |
| 306 | 305 | ||
| 307 | int | 306 | int |
| 308 | y2row(int y) | 307 | y2row(int y) |
| 309 | { | 308 | { |
| 310 | y -= borderpx; | 309 | y -= borderpx; |
| 311 | y /= win.ch; | 310 | LIMIT(y, 0, win.th - 1); |
| 312 | 311 | return y / win.ch; | |
| 313 | return LIMIT(y, 0, term.row-1); | ||
| 314 | } | 312 | } |
| 315 | 313 | ||
| 316 | void | 314 | void |
| @@ -984,7 +982,7 @@ xunloadfonts(void) | |||
| 984 | } | 982 | } |
| 985 | 983 | ||
| 986 | void | 984 | void |
| 987 | xinit(void) | 985 | xinit(int cols, int rows) |
| 988 | { | 986 | { |
| 989 | XGCValues gcvalues; | 987 | XGCValues gcvalues; |
| 990 | Cursor cursor; | 988 | Cursor cursor; |
| @@ -1009,8 +1007,8 @@ xinit(void) | |||
| 1009 | xloadcols(); | 1007 | xloadcols(); |
| 1010 | 1008 | ||
| 1011 | /* adjust fixed window geometry */ | 1009 | /* adjust fixed window geometry */ |
| 1012 | win.w = 2 * borderpx + term.col * win.cw; | 1010 | win.w = 2 * borderpx + cols * win.cw; |
| 1013 | win.h = 2 * borderpx + term.row * win.ch; | 1011 | win.h = 2 * borderpx + rows * win.ch; |
| 1014 | if (xw.gm & XNegative) | 1012 | if (xw.gm & XNegative) |
| 1015 | xw.l += DisplayWidth(xw.dpy, xw.scr) - win.w - 2; | 1013 | xw.l += DisplayWidth(xw.dpy, xw.scr) - win.w - 2; |
| 1016 | if (xw.gm & YNegative) | 1014 | if (xw.gm & YNegative) |
| @@ -1042,7 +1040,7 @@ xinit(void) | |||
| 1042 | XFillRectangle(xw.dpy, xw.buf, dc.gc, 0, 0, win.w, win.h); | 1040 | XFillRectangle(xw.dpy, xw.buf, dc.gc, 0, 0, win.w, win.h); |
| 1043 | 1041 | ||
| 1044 | /* font spec buffer */ | 1042 | /* font spec buffer */ |
| 1045 | xw.specbuf = xmalloc(term.col * sizeof(GlyphFontSpec)); | 1043 | xw.specbuf = xmalloc(cols * sizeof(GlyphFontSpec)); |
| 1046 | 1044 | ||
| 1047 | /* Xft rendering context */ | 1045 | /* Xft rendering context */ |
| 1048 | xw.draw = XftDrawCreate(xw.dpy, xw.buf, xw.vis, xw.cmap); | 1046 | xw.draw = XftDrawCreate(xw.dpy, xw.buf, xw.vis, xw.cmap); |
| @@ -1337,15 +1335,16 @@ xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, i | |||
| 1337 | /* Intelligent cleaning up of the borders. */ | 1335 | /* Intelligent cleaning up of the borders. */ |
| 1338 | if (x == 0) { | 1336 | if (x == 0) { |
| 1339 | xclear(0, (y == 0)? 0 : winy, borderpx, | 1337 | xclear(0, (y == 0)? 0 : winy, borderpx, |
| 1340 | winy + win.ch + ((y >= term.row-1)? win.h : 0)); | 1338 | winy + win.ch + |
| 1339 | ((winy + win.ch >= borderpx + win.th)? win.h : 0)); | ||
| 1341 | } | 1340 | } |
| 1342 | if (x + charlen >= term.col) { | 1341 | if (winx + width >= borderpx + win.tw) { |
| 1343 | xclear(winx + width, (y == 0)? 0 : winy, win.w, | 1342 | xclear(winx + width, (y == 0)? 0 : winy, win.w, |
| 1344 | ((y >= term.row-1)? win.h : (winy + win.ch))); | 1343 | ((winy + win.ch >= borderpx + win.th)? win.h : (winy + win.ch))); |
| 1345 | } | 1344 | } |
| 1346 | if (y == 0) | 1345 | if (y == 0) |
| 1347 | xclear(winx, 0, winx + width, borderpx); | 1346 | xclear(winx, 0, winx + width, borderpx); |
| 1348 | if (y == term.row-1) | 1347 | if (winy + win.ch >= borderpx + win.th) |
| 1349 | xclear(winx, winy + win.ch, winx + width, win.h); | 1348 | xclear(winx, winy + win.ch, winx + width, win.h); |
| 1350 | 1349 | ||
| 1351 | /* Clean up the region we want to draw to. */ | 1350 | /* Clean up the region we want to draw to. */ |
| @@ -1930,8 +1929,10 @@ run: | |||
| 1930 | } | 1929 | } |
| 1931 | setlocale(LC_CTYPE, ""); | 1930 | setlocale(LC_CTYPE, ""); |
| 1932 | XSetLocaleModifiers(""); | 1931 | XSetLocaleModifiers(""); |
| 1933 | tnew(MAX(cols, 1), MAX(rows, 1)); | 1932 | cols = MAX(cols, 1); |
| 1934 | xinit(); | 1933 | rows = MAX(rows, 1); |
| 1934 | tnew(cols, rows); | ||
| 1935 | xinit(cols, rows); | ||
| 1935 | xsetenv(); | 1936 | xsetenv(); |
| 1936 | selinit(); | 1937 | selinit(); |
| 1937 | run(); | 1938 | run(); |
