diff options
-rw-r--r-- | config.h | 3 | ||||
-rwxr-xr-x[-rw-r--r--] | st.c | 69 |
2 files changed, 25 insertions, 47 deletions
@@ -3,8 +3,7 @@ | |||
3 | 3 | ||
4 | #define FONT "6x13" | 4 | #define FONT "6x13" |
5 | #define BOLDFONT FONT"bold" | 5 | #define BOLDFONT FONT"bold" |
6 | #define BORDER 3 | 6 | #define BORDER 2 |
7 | #define LINESPACE 0 /* additional pixel between each line */ | ||
8 | 7 | ||
9 | /* Terminal colors */ | 8 | /* Terminal colors */ |
10 | static const char *colorname[] = { | 9 | static const char *colorname[] = { |
@@ -91,6 +91,7 @@ typedef struct { | |||
91 | typedef struct { | 91 | typedef struct { |
92 | Display* dis; | 92 | Display* dis; |
93 | Window win; | 93 | Window win; |
94 | Pixmap buf; | ||
94 | int scr; | 95 | int scr; |
95 | int w; /* window width */ | 96 | int w; /* window width */ |
96 | int h; /* window height */ | 97 | int h; /* window height */ |
@@ -154,7 +155,6 @@ static unsigned long xgetcol(const char *); | |||
154 | static void xclear(int, int, int, int); | 155 | static void xclear(int, int, int, int); |
155 | static void xcursor(int); | 156 | static void xcursor(int); |
156 | static void xinit(void); | 157 | static void xinit(void); |
157 | static void xscroll(void); | ||
158 | 158 | ||
159 | static void expose(XEvent *); | 159 | static void expose(XEvent *); |
160 | static char* kmap(KeySym); | 160 | static char* kmap(KeySym); |
@@ -215,7 +215,7 @@ execsh(void) { | |||
215 | 215 | ||
216 | void | 216 | void |
217 | xbell(void) { /* visual bell */ | 217 | xbell(void) { /* visual bell */ |
218 | XRectangle r = { 0, 0, xw.w, xw.h }; | 218 | XRectangle r = { BORDER, BORDER, xw.w, xw.h }; |
219 | XSetForeground(xw.dis, dc.gc, dc.col[BellCol]); | 219 | XSetForeground(xw.dis, dc.gc, dc.col[BellCol]); |
220 | XFillRectangles(xw.dis, xw.win, dc.gc, &r, 1); | 220 | XFillRectangles(xw.dis, xw.win, dc.gc, &r, 1); |
221 | /* usleep(30000); */ | 221 | /* usleep(30000); */ |
@@ -350,9 +350,7 @@ void | |||
350 | tscroll(void) { | 350 | tscroll(void) { |
351 | Line temp = term.line[term.top]; | 351 | Line temp = term.line[term.top]; |
352 | int i; | 352 | int i; |
353 | /* No dirty flag to set because of xscroll */ | 353 | |
354 | /* X stuff _before_ the line swapping (results in wrong line index) */ | ||
355 | xscroll(); | ||
356 | for(i = term.top; i < term.bot; i++) | 354 | for(i = term.top; i < term.bot; i++) |
357 | term.line[i] = term.line[i+1]; | 355 | term.line[i] = term.line[i+1]; |
358 | memset(temp, 0, sizeof(Glyph) * term.col); | 356 | memset(temp, 0, sizeof(Glyph) * term.col); |
@@ -364,7 +362,6 @@ tscrolldown (int n) { | |||
364 | int i; | 362 | int i; |
365 | Line temp; | 363 | Line temp; |
366 | 364 | ||
367 | /* TODO: set dirty flag or scroll with some X func */ | ||
368 | LIMIT(n, 0, term.bot-term.top+1); | 365 | LIMIT(n, 0, term.bot-term.top+1); |
369 | 366 | ||
370 | for(i = 0; i < n; i++) | 367 | for(i = 0; i < n; i++) |
@@ -383,7 +380,6 @@ tscrollup (int n) { | |||
383 | Line temp; | 380 | Line temp; |
384 | LIMIT(n, 0, term.bot-term.top+1); | 381 | LIMIT(n, 0, term.bot-term.top+1); |
385 | 382 | ||
386 | /* TODO: set dirty flag or scroll with some X func */ | ||
387 | for(i = 0; i < n; i++) | 383 | for(i = 0; i < n; i++) |
388 | memset(term.line[term.top+i], 0, term.col*sizeof(Glyph)); | 384 | memset(term.line[term.top+i], 0, term.col*sizeof(Glyph)); |
389 | 385 | ||
@@ -467,7 +463,7 @@ void | |||
467 | tsetchar(char c) { | 463 | tsetchar(char c) { |
468 | term.line[term.c.y][term.c.x] = term.c.attr; | 464 | term.line[term.c.y][term.c.x] = term.c.attr; |
469 | term.line[term.c.y][term.c.x].c = c; | 465 | term.line[term.c.y][term.c.x].c = c; |
470 | term.line[term.c.y][term.c.x].state |= GLYPH_SET | GLYPH_DIRTY; | 466 | term.line[term.c.y][term.c.x].state |= GLYPH_SET; |
471 | } | 467 | } |
472 | 468 | ||
473 | void | 469 | void |
@@ -486,8 +482,6 @@ tclearregion(int x1, int y1, int x2, int y2) { | |||
486 | 482 | ||
487 | for(y = y1; y <= y2; y++) | 483 | for(y = y1; y <= y2; y++) |
488 | memset(&term.line[y][x1], 0, sizeof(Glyph)*(x2-x1+1)); | 484 | memset(&term.line[y][x1], 0, sizeof(Glyph)*(x2-x1+1)); |
489 | |||
490 | xclear(x1, y1, x2, y2); | ||
491 | } | 485 | } |
492 | 486 | ||
493 | void | 487 | void |
@@ -519,13 +513,6 @@ tinsertblank(int n) { | |||
519 | } | 513 | } |
520 | 514 | ||
521 | void | 515 | void |
522 | tsetlinestate(int n, int state) { | ||
523 | int i; | ||
524 | for(i = 0; i < term.col; i++) | ||
525 | term.line[n][i].state |= state; | ||
526 | } | ||
527 | |||
528 | void | ||
529 | tinsertblankline(int n) { | 516 | tinsertblankline(int n) { |
530 | int i; | 517 | int i; |
531 | Line blank; | 518 | Line blank; |
@@ -546,8 +533,6 @@ tinsertblankline(int n) { | |||
546 | term.line[i-n] = blank; | 533 | term.line[i-n] = blank; |
547 | /* blank it */ | 534 | /* blank it */ |
548 | memset(blank, 0, term.col * sizeof(Glyph)); | 535 | memset(blank, 0, term.col * sizeof(Glyph)); |
549 | tsetlinestate(i, GLYPH_DIRTY); | ||
550 | tsetlinestate(i-n, GLYPH_DIRTY); | ||
551 | } | 536 | } |
552 | } | 537 | } |
553 | 538 | ||
@@ -572,8 +557,6 @@ tdeleteline(int n) { | |||
572 | term.line[i+n] = blank; | 557 | term.line[i+n] = blank; |
573 | /* blank it */ | 558 | /* blank it */ |
574 | memset(blank, 0, term.col * sizeof(Glyph)); | 559 | memset(blank, 0, term.col * sizeof(Glyph)); |
575 | tsetlinestate(i, GLYPH_DIRTY); | ||
576 | tsetlinestate(i-n, GLYPH_DIRTY); | ||
577 | } | 560 | } |
578 | } | 561 | } |
579 | 562 | ||
@@ -1037,21 +1020,10 @@ xgetcol(const char *s) { | |||
1037 | 1020 | ||
1038 | void | 1021 | void |
1039 | xclear(int x1, int y1, int x2, int y2) { | 1022 | xclear(int x1, int y1, int x2, int y2) { |
1040 | XClearArea(xw.dis, xw.win, | 1023 | XSetForeground(xw.dis, dc.gc, dc.col[DefaultBG]); |
1041 | x1 * xw.cw, y1 * xw.ch, | 1024 | XFillRectangle(xw.dis, xw.buf, dc.gc, |
1042 | (x2-x1+1) * xw.cw, (y2-y1+1) * xw.ch, | 1025 | x1 * xw.cw, y1 * xw.ch, |
1043 | False); | 1026 | (x2-x1+1) * xw.cw, (y2-y1+1) * xw.ch); |
1044 | } | ||
1045 | |||
1046 | void | ||
1047 | xscroll(void) { | ||
1048 | int srcy = (term.top+1) * xw.ch; | ||
1049 | int dsty = term.top * xw.ch; | ||
1050 | int height = (term.bot-term.top) * xw.ch; | ||
1051 | |||
1052 | xcursor(CURSOR_HIDE); | ||
1053 | XCopyArea(xw.dis, xw.win, xw.win, dc.gc, 0, srcy, xw.w, height, 0, dsty); | ||
1054 | xclear(0, term.bot, term.col-1, term.bot); | ||
1055 | } | 1027 | } |
1056 | 1028 | ||
1057 | void | 1029 | void |
@@ -1073,7 +1045,7 @@ xinit(void) { | |||
1073 | 1045 | ||
1074 | /* XXX: Assuming same size for bold font */ | 1046 | /* XXX: Assuming same size for bold font */ |
1075 | xw.cw = dc.font->max_bounds.rbearing - dc.font->min_bounds.lbearing; | 1047 | xw.cw = dc.font->max_bounds.rbearing - dc.font->min_bounds.lbearing; |
1076 | xw.ch = dc.font->ascent + dc.font->descent + LINESPACE; | 1048 | xw.ch = dc.font->ascent + dc.font->descent; |
1077 | 1049 | ||
1078 | /* colors */ | 1050 | /* colors */ |
1079 | for(i = 0; i < LEN(colorname); i++) | 1051 | for(i = 0; i < LEN(colorname); i++) |
@@ -1085,11 +1057,11 @@ xinit(void) { | |||
1085 | /* windows */ | 1057 | /* windows */ |
1086 | xw.h = term.row * xw.ch; | 1058 | xw.h = term.row * xw.ch; |
1087 | xw.w = term.col * xw.cw; | 1059 | xw.w = term.col * xw.cw; |
1088 | /* XXX: this BORDER is useless after the first resize, handle it in xdraws() */ | ||
1089 | xw.win = XCreateSimpleWindow(xw.dis, XRootWindow(xw.dis, xw.scr), 0, 0, | 1060 | xw.win = XCreateSimpleWindow(xw.dis, XRootWindow(xw.dis, xw.scr), 0, 0, |
1090 | xw.w, xw.h, BORDER, | 1061 | xw.w + 2*BORDER, xw.h + 2*BORDER, 0, |
1091 | dc.col[DefaultBG], | 1062 | dc.col[DefaultBG], |
1092 | dc.col[DefaultBG]); | 1063 | dc.col[DefaultBG]); |
1064 | xw.buf = XCreatePixmap(xw.dis, xw.win, xw.w, xw.h, XDefaultDepth(xw.dis, xw.scr)); | ||
1093 | /* gc */ | 1065 | /* gc */ |
1094 | dc.gc = XCreateGC(xw.dis, xw.win, 0, NULL); | 1066 | dc.gc = XCreateGC(xw.dis, xw.win, 0, NULL); |
1095 | XMapWindow(xw.dis, xw.win); | 1067 | XMapWindow(xw.dis, xw.win); |
@@ -1097,11 +1069,13 @@ xinit(void) { | |||
1097 | chint.res_name = TNAME, chint.res_class = TNAME; | 1069 | chint.res_name = TNAME, chint.res_class = TNAME; |
1098 | wmhint.input = 1, wmhint.flags = InputHint; | 1070 | wmhint.input = 1, wmhint.flags = InputHint; |
1099 | shint.height_inc = xw.ch, shint.width_inc = xw.cw; | 1071 | shint.height_inc = xw.ch, shint.width_inc = xw.cw; |
1100 | shint.height = xw.h, shint.width = xw.w; | 1072 | shint.height = xw.h + 2*BORDER, shint.width = xw.w + 2*BORDER; |
1101 | shint.flags = PSize | PResizeInc; | 1073 | shint.flags = PSize | PResizeInc; |
1102 | XSetWMProperties(xw.dis, xw.win, NULL, NULL, &args[0], 0, &shint, &wmhint, &chint); | 1074 | XSetWMProperties(xw.dis, xw.win, NULL, NULL, &args[0], 0, &shint, &wmhint, &chint); |
1103 | XStoreName(xw.dis, xw.win, TNAME); | 1075 | XStoreName(xw.dis, xw.win, TNAME); |
1076 | XFillRectangle(xw.dis, xw.buf, dc.gc, 0, 0, xw.w, xw.h); | ||
1104 | XSync(xw.dis, 0); | 1077 | XSync(xw.dis, 0); |
1078 | |||
1105 | } | 1079 | } |
1106 | 1080 | ||
1107 | void | 1081 | void |
@@ -1123,10 +1097,10 @@ xdraws(char *s, Glyph base, int x, int y, int len) { | |||
1123 | s[i] = gfx[s[i]]; | 1097 | s[i] = gfx[s[i]]; |
1124 | 1098 | ||
1125 | XSetFont(xw.dis, dc.gc, base.mode & ATTR_BOLD ? dc.bfont->fid : dc.font->fid); | 1099 | XSetFont(xw.dis, dc.gc, base.mode & ATTR_BOLD ? dc.bfont->fid : dc.font->fid); |
1126 | XDrawImageString(xw.dis, xw.win, dc.gc, winx, winy, s, len); | 1100 | XDrawImageString(xw.dis, xw.buf, dc.gc, winx, winy, s, len); |
1127 | 1101 | ||
1128 | if(base.mode & ATTR_UNDERLINE) | 1102 | if(base.mode & ATTR_UNDERLINE) |
1129 | XDrawLine(xw.dis, xw.win, dc.gc, winx, winy+1, winx+width-1, winy+1); | 1103 | XDrawLine(xw.dis, xw.buf, dc.gc, winx, winy+1, winx+width-1, winy+1); |
1130 | } | 1104 | } |
1131 | 1105 | ||
1132 | void | 1106 | void |
@@ -1163,7 +1137,7 @@ xdrawc(int x, int y, Glyph g) { | |||
1163 | XSetBackground(xw.dis, dc.gc, dc.col[g.bg]); | 1137 | XSetBackground(xw.dis, dc.gc, dc.col[g.bg]); |
1164 | XSetForeground(xw.dis, dc.gc, dc.col[g.fg]); | 1138 | XSetForeground(xw.dis, dc.gc, dc.col[g.fg]); |
1165 | XSetFont(xw.dis, dc.gc, g.mode & ATTR_BOLD ? dc.bfont->fid : dc.font->fid); | 1139 | XSetFont(xw.dis, dc.gc, g.mode & ATTR_BOLD ? dc.bfont->fid : dc.font->fid); |
1166 | XDrawImageString(xw.dis, xw.win, dc.gc, r.x, r.y+dc.font->ascent, &g.c, 1); | 1140 | XDrawImageString(xw.dis, xw.buf, dc.gc, r.x, r.y+dc.font->ascent, &g.c, 1); |
1167 | } | 1141 | } |
1168 | 1142 | ||
1169 | void | 1143 | void |
@@ -1178,6 +1152,8 @@ draw_(int dummy) { | |||
1178 | 1152 | ||
1179 | if(!term.hidec) | 1153 | if(!term.hidec) |
1180 | xcursor(CURSOR_DRAW); | 1154 | xcursor(CURSOR_DRAW); |
1155 | XCopyArea(xw.dis, xw.buf, xw.win, dc.gc, 0, 0, xw.w, xw.h, BORDER, BORDER); | ||
1156 | XFlush(xw.dis); | ||
1181 | } | 1157 | } |
1182 | #endif | 1158 | #endif |
1183 | 1159 | ||
@@ -1187,7 +1163,6 @@ draw(int redraw_all) { | |||
1187 | Glyph base, new; | 1163 | Glyph base, new; |
1188 | char buf[DRAW_BUF_SIZ]; | 1164 | char buf[DRAW_BUF_SIZ]; |
1189 | 1165 | ||
1190 | /* XXX: optimize with GLYPH_DIRTY hint */ | ||
1191 | for(y = 0; y < term.row; y++) { | 1166 | for(y = 0; y < term.row; y++) { |
1192 | base = term.line[y][0]; | 1167 | base = term.line[y][0]; |
1193 | i = ox = 0; | 1168 | i = ox = 0; |
@@ -1206,6 +1181,8 @@ draw(int redraw_all) { | |||
1206 | xdraws(buf, base, ox, y, i); | 1181 | xdraws(buf, base, ox, y, i); |
1207 | } | 1182 | } |
1208 | xcursor(term.hidec ? CURSOR_HIDE : CURSOR_DRAW); | 1183 | xcursor(term.hidec ? CURSOR_HIDE : CURSOR_DRAW); |
1184 | XCopyArea(xw.dis, xw.buf, xw.win, dc.gc, 0, 0, xw.w, xw.h, BORDER, BORDER); | ||
1185 | XFlush(xw.dis); | ||
1209 | } | 1186 | } |
1210 | 1187 | ||
1211 | void | 1188 | void |
@@ -1273,6 +1250,8 @@ resize(XEvent *e) { | |||
1273 | ttyresize(col, row); | 1250 | ttyresize(col, row); |
1274 | xw.w = e->xconfigure.width; | 1251 | xw.w = e->xconfigure.width; |
1275 | xw.h = e->xconfigure.height; | 1252 | xw.h = e->xconfigure.height; |
1253 | XFreePixmap(xw.dis, xw.buf); | ||
1254 | xw.buf = XCreatePixmap(xw.dis, xw.win, xw.w, xw.h, XDefaultDepth(xw.dis, xw.scr)); | ||
1276 | draw(SCREEN_REDRAW); | 1255 | draw(SCREEN_REDRAW); |
1277 | } | 1256 | } |
1278 | } | 1257 | } |
@@ -1285,7 +1264,7 @@ run(void) { | |||
1285 | 1264 | ||
1286 | running = 1; | 1265 | running = 1; |
1287 | XSelectInput(xw.dis, xw.win, ExposureMask | KeyPressMask | StructureNotifyMask); | 1266 | XSelectInput(xw.dis, xw.win, ExposureMask | KeyPressMask | StructureNotifyMask); |
1288 | XResizeWindow(xw.dis, xw.win, xw.w , xw.h); /* fix resize bug in wmii (?) */ | 1267 | XResizeWindow(xw.dis, xw.win, xw.w+2*BORDER, xw.h+2*BORDER); /* fix resize bug in wmii (?) */ |
1289 | 1268 | ||
1290 | while(running) { | 1269 | while(running) { |
1291 | FD_ZERO(&rfd); | 1270 | FD_ZERO(&rfd); |