[hackers] [st] Correctly initialize altscreen when defaultbg is not 0. || Mark Edgar
commit 4245ba0d12a330b3e54c6498e88024d90956ae34
Author: Mark Edgar <medgar123_AT_gmail.com>
Date: Mon Aug 26 00:10:47 2013 +0200
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().
diff --git a/config.def.h b/config.def.h
index 8cb8804..24aeb19 100644
--- a/config.def.h
+++ b/config.def.h
_AT_@ -129,13 +129,13 @@ static Shortcut shortcuts[] = {
* * < 0: crlf mode is disabled
*
* Be careful with the order of the definitons because st searchs in
- * this table sequencially, so any XK_ANY_MOD must be in the last
+ * this table sequentially, so any XK_ANY_MOD must be in the last
* position for a key.
*/
/*
- * If you want something else but the function keys of X11 (0xFF00 - 0xFFFF)
- * mapped below, add them to this array.
+ * If you want keys other than the X11 function keys (0xFD00 - 0xFFFF)
+ * to be mapped below, add them to this array.
*/
static KeySym mappedkeys[] = { -1 };
diff --git a/st.c b/st.c
index c751aa1..0fa0c86 100644
--- a/st.c
+++ b/st.c
_AT_@ -420,7 +420,6 @@ static int isfullutf8(char *, int);
static ssize_t xwrite(int, char *, size_t);
static void *xmalloc(size_t);
static void *xrealloc(void *, size_t);
-static void *xcalloc(size_t, size_t);
static void (*handler[LASTEvent])(XEvent *) = {
[KeyPress] = kpress,
_AT_@ -509,16 +508,6 @@ xrealloc(void *p, size_t len) {
return p;
}
-void *
-xcalloc(size_t nmemb, size_t size) {
- void *p = calloc(nmemb, size);
-
- if(!p)
- die("Out of memory
");
-
- return p;
-}
-
int
utf8decode(char *s, long *u) {
uchar c;
_AT_@ -1370,7 +1359,7 @@ treset(void) {
void
tnew(int col, int row) {
- memset(&term, 0, sizeof(Term));
+ term = (Term){ .c = { .attr = { .fg = defaultfg, .bg = defaultbg } } };
tresize(col, row);
term.numlock = 1;
_AT_@ -2536,8 +2525,8 @@ tresize(int col, int row) {
/* allocate any new rows */
for(/* i == minrow */; i < row; i++) {
term.dirty[i] = 1;
- term.line[i] = xcalloc(col, sizeof(Glyph));
- term.alt [i] = xcalloc(col, sizeof(Glyph));
+ term.line[i] = xmalloc(col * sizeof(Glyph));
+ term.alt[i] = xmalloc(col * sizeof(Glyph));
}
if(col > term.col) {
bp = term.tabs + term.col;
Received on Wed Sep 04 2013 - 20:29:36 CEST
This archive was generated by hypermail 2.3.0
: Wed Sep 04 2013 - 20:36:13 CEST