aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Edgar <medgar123@gmail.com>2013-08-26 00:10:47 +0200
committerRoberto E. Vargas Caballero <k0ga@shike2.com>2013-09-04 18:33:02 +0200
commit4245ba0d12a330b3e54c6498e88024d90956ae34 (patch)
tree843d42fca2260a2e2426715a15c9928f85ce6f93
parentf3d438b1015a031bc543bb2d65c81cc2329787d4 (diff)
downloadst-4245ba0d12a330b3e54c6498e88024d90956ae34.tar.gz
st-4245ba0d12a330b3e54c6498e88024d90956ae34.zip
Correctly initialize altscreen when defaultbg is not 0.
The alternate screen is not properly initialized when st starts. To see this, set defaultbg in config.h to anything other than 0 (for example, swap defaultfg and defaultbg), and run: ./st -e sh -c 'tput smcup; read' You should see that the top-left 80x24 rectangle is black (or whatever colorname[0] is), while the rest of the screen (if any) has the desired colorname[defaultbg] color. The attached patch fixes this by initializing term.c.attr in tnew() before calling tresize(). It also removes the unnecessary xcalloc() calls, which misled me on this bug hunt since it is really tclearregion() which initializes term.lines and term.alt in tresize().
-rw-r--r--config.def.h6
-rw-r--r--st.c17
2 files changed, 6 insertions, 17 deletions
diff --git a/config.def.h b/config.def.h
index 8cb8804..24aeb19 100644
--- a/config.def.h
+++ b/config.def.h
@@ -129,13 +129,13 @@ static Shortcut shortcuts[] = {
129 * * < 0: crlf mode is disabled 129 * * < 0: crlf mode is disabled
130 * 130 *
131 * Be careful with the order of the definitons because st searchs in 131 * Be careful with the order of the definitons because st searchs in
132 * this table sequencially, so any XK_ANY_MOD must be in the last 132 * this table sequentially, so any XK_ANY_MOD must be in the last
133 * position for a key. 133 * position for a key.
134 */ 134 */
135 135
136/* 136/*
137 * If you want something else but the function keys of X11 (0xFF00 - 0xFFFF) 137 * If you want keys other than the X11 function keys (0xFD00 - 0xFFFF)
138 * mapped below, add them to this array. 138 * to be mapped below, add them to this array.
139 */ 139 */
140static KeySym mappedkeys[] = { -1 }; 140static KeySym mappedkeys[] = { -1 };
141 141
diff --git a/st.c b/st.c
index c751aa1..0fa0c86 100644
--- a/st.c
+++ b/st.c
@@ -420,7 +420,6 @@ static int isfullutf8(char *, int);
420static ssize_t xwrite(int, char *, size_t); 420static ssize_t xwrite(int, char *, size_t);
421static void *xmalloc(size_t); 421static void *xmalloc(size_t);
422static void *xrealloc(void *, size_t); 422static void *xrealloc(void *, size_t);
423static void *xcalloc(size_t, size_t);
424 423
425static void (*handler[LASTEvent])(XEvent *) = { 424static void (*handler[LASTEvent])(XEvent *) = {
426 [KeyPress] = kpress, 425 [KeyPress] = kpress,
@@ -509,16 +508,6 @@ xrealloc(void *p, size_t len) {
509 return p; 508 return p;
510} 509}
511 510
512void *
513xcalloc(size_t nmemb, size_t size) {
514 void *p = calloc(nmemb, size);
515
516 if(!p)
517 die("Out of memory\n");
518
519 return p;
520}
521
522int 511int
523utf8decode(char *s, long *u) { 512utf8decode(char *s, long *u) {
524 uchar c; 513 uchar c;
@@ -1370,7 +1359,7 @@ treset(void) {
1370 1359
1371void 1360void
1372tnew(int col, int row) { 1361tnew(int col, int row) {
1373 memset(&term, 0, sizeof(Term)); 1362 term = (Term){ .c = { .attr = { .fg = defaultfg, .bg = defaultbg } } };
1374 tresize(col, row); 1363 tresize(col, row);
1375 term.numlock = 1; 1364 term.numlock = 1;
1376 1365
@@ -2536,8 +2525,8 @@ tresize(int col, int row) {
2536 /* allocate any new rows */ 2525 /* allocate any new rows */
2537 for(/* i == minrow */; i < row; i++) { 2526 for(/* i == minrow */; i < row; i++) {
2538 term.dirty[i] = 1; 2527 term.dirty[i] = 1;
2539 term.line[i] = xcalloc(col, sizeof(Glyph)); 2528 term.line[i] = xmalloc(col * sizeof(Glyph));
2540 term.alt [i] = xcalloc(col, sizeof(Glyph)); 2529 term.alt[i] = xmalloc(col * sizeof(Glyph));
2541 } 2530 }
2542 if(col > term.col) { 2531 if(col > term.col) {
2543 bp = term.tabs + term.col; 2532 bp = term.tabs + term.col;