changeset: 77:bcfce8d32548
tag: tip
user: Aur?lien Aptel <aurelien.aptel_AT_gmail.com>
date: Mon Mar 15 23:56:38 2010 +0100
files: config.h st.c
description:
double-buffering added using pixmap (finally).
results in a lot of simplification :
- no more dirty flags (perf are good enough).
- no more ugly gfx call in emulation functions.
LINESPACE removed from config.h.
BORDER is now handled correctly.
diff -r 23e61afc4989 -r bcfce8d32548 config.h
--- a/config.h Thu Mar 11 23:50:50 2010 +0100
+++ b/config.h Mon Mar 15 23:56:38 2010 +0100
@@ -3,8 +3,7 @@
#define FONT "6x13"
#define BOLDFONT FONT"bold"
-#define BORDER 3
-#define LINESPACE 0 /* additional pixel between each line */
+#define BORDER 2
/* Terminal colors */
static const char *colorname[] = {
diff -r 23e61afc4989 -r bcfce8d32548 st.c
--- a/st.c Thu Mar 11 23:50:50 2010 +0100
+++ b/st.c Mon Mar 15 23:56:38 2010 +0100
@@ -91,6 +91,7 @@
typedef struct {
Display* dis;
Window win;
+ Pixmap buf;
int scr;
int w; /* window width */
int h; /* window height */
@@ -154,7 +155,6 @@
static void xclear(int, int, int, int);
static void xcursor(int);
static void xinit(void);
-static void xscroll(void);
static void expose(XEvent *);
static char* kmap(KeySym);
@@ -215,7 +215,7 @@
void
xbell(void) { /* visual bell */
- XRectangle r = { 0, 0, xw.w, xw.h };
+ XRectangle r = { BORDER, BORDER, xw.w, xw.h };
XSetForeground(xw.dis, dc.gc, dc.col[BellCol]);
XFillRectangles(xw.dis, xw.win, dc.gc, &r, 1);
/* usleep(30000); */
@@ -350,9 +350,7 @@
tscroll(void) {
Line temp = term.line[term.top];
int i;
- /* No dirty flag to set because of xscroll */
- /* X stuff _before_ the line swapping (results in wrong line index) */
- xscroll();
+
for(i = term.top; i < term.bot; i++)
term.line[i] = term.line[i+1];
memset(temp, 0, sizeof(Glyph) * term.col);
@@ -364,7 +362,6 @@
int i;
Line temp;
- /* TODO: set dirty flag or scroll with some X func */
LIMIT(n, 0, term.bot-term.top+1);
for(i = 0; i < n; i++)
@@ -383,7 +380,6 @@
Line temp;
LIMIT(n, 0, term.bot-term.top+1);
- /* TODO: set dirty flag or scroll with some X func */
for(i = 0; i < n; i++)
memset(term.line[term.top+i], 0, term.col*sizeof(Glyph));
@@ -467,7 +463,7 @@
tsetchar(char c) {
term.line[term.c.y][term.c.x] = term.c.attr;
term.line[term.c.y][term.c.x].c = c;
- term.line[term.c.y][term.c.x].state |= GLYPH_SET | GLYPH_DIRTY;
+ term.line[term.c.y][term.c.x].state |= GLYPH_SET;
}
void
@@ -486,8 +482,6 @@
for(y = y1; y <= y2; y++)
memset(&term.line[y][x1], 0, sizeof(Glyph)*(x2-x1+1));
-
- xclear(x1, y1, x2, y2);
}
void
@@ -519,13 +513,6 @@
}
void
-tsetlinestate(int n, int state) {
- int i;
- for(i = 0; i < term.col; i++)
- term.line[n][i].state |= state;
-}
-
-void
tinsertblankline(int n) {
int i;
Line blank;
@@ -546,8 +533,6 @@
term.line[i-n] = blank;
/* blank it */
memset(blank, 0, term.col * sizeof(Glyph));
- tsetlinestate(i, GLYPH_DIRTY);
- tsetlinestate(i-n, GLYPH_DIRTY);
}
}
@@ -572,8 +557,6 @@
term.line[i+n] = blank;
/* blank it */
memset(blank, 0, term.col * sizeof(Glyph));
- tsetlinestate(i, GLYPH_DIRTY);
- tsetlinestate(i-n, GLYPH_DIRTY);
}
}
@@ -1037,21 +1020,10 @@
void
xclear(int x1, int y1, int x2, int y2) {
- XClearArea(xw.dis, xw.win,
- x1 * xw.cw, y1 * xw.ch,
- (x2-x1+1) * xw.cw, (y2-y1+1) * xw.ch,
- False);
-}
-
-void
-xscroll(void) {
- int srcy = (term.top+1) * xw.ch;
- int dsty = term.top * xw.ch;
- int height = (term.bot-term.top) * xw.ch;
-
- xcursor(CURSOR_HIDE);
- XCopyArea(xw.dis, xw.win, xw.win, dc.gc, 0, srcy, xw.w, height, 0, dsty);
- xclear(0, term.bot, term.col-1, term.bot);
+ XSetForeground(xw.dis, dc.gc, dc.col[DefaultBG]);
+ XFillRectangle(xw.dis, xw.buf, dc.gc,
+ x1 * xw.cw, y1 * xw.ch,
+ (x2-x1+1) * xw.cw, (y2-y1+1) * xw.ch);
}
void
@@ -1073,7 +1045,7 @@
/* XXX: Assuming same size for bold font */
xw.cw = dc.font->max_bounds.rbearing - dc.font->min_bounds.lbearing;
- xw.ch = dc.font->ascent + dc.font->descent + LINESPACE;
+ xw.ch = dc.font->ascent + dc.font->descent;
/* colors */
for(i = 0; i < LEN(colorname); i++)
@@ -1085,11 +1057,11 @@
/* windows */
xw.h = term.row * xw.ch;
xw.w = term.col * xw.cw;
- /* XXX: this BORDER is useless after the first resize, handle it in xdraws() */
xw.win = XCreateSimpleWindow(xw.dis, XRootWindow(xw.dis, xw.scr), 0, 0,
- xw.w, xw.h, BORDER,
+ xw.w + 2*BORDER, xw.h + 2*BORDER, 0,
dc.col[DefaultBG],
dc.col[DefaultBG]);
+ xw.buf = XCreatePixmap(xw.dis, xw.win, xw.w, xw.h, XDefaultDepth(xw.dis, xw.scr));
/* gc */
dc.gc = XCreateGC(xw.dis, xw.win, 0, NULL);
XMapWindow(xw.dis, xw.win);
@@ -1097,11 +1069,13 @@
chint.res_name = TNAME, chint.res_class = TNAME;
wmhint.input = 1, wmhint.flags = InputHint;
shint.height_inc = xw.ch, shint.width_inc = xw.cw;
- shint.height = xw.h, shint.width = xw.w;
+ shint.height = xw.h + 2*BORDER, shint.width = xw.w + 2*BORDER;
shint.flags = PSize | PResizeInc;
XSetWMProperties(xw.dis, xw.win, NULL, NULL, &args[0], 0, &shint, &wmhint, &chint);
XStoreName(xw.dis, xw.win, TNAME);
+ XFillRectangle(xw.dis, xw.buf, dc.gc, 0, 0, xw.w, xw.h);
XSync(xw.dis, 0);
+
}
void
@@ -1123,10 +1097,10 @@
s[i] = gfx[s[i]];
XSetFont(xw.dis, dc.gc, base.mode & ATTR_BOLD ? dc.bfont->fid : dc.font->fid);
- XDrawImageString(xw.dis, xw.win, dc.gc, winx, winy, s, len);
+ XDrawImageString(xw.dis, xw.buf, dc.gc, winx, winy, s, len);
if(base.mode & ATTR_UNDERLINE)
- XDrawLine(xw.dis, xw.win, dc.gc, winx, winy+1, winx+width-1, winy+1);
+ XDrawLine(xw.dis, xw.buf, dc.gc, winx, winy+1, winx+width-1, winy+1);
}
void
@@ -1163,7 +1137,7 @@
XSetBackground(xw.dis, dc.gc, dc.col[g.bg]);
XSetForeground(xw.dis, dc.gc, dc.col[g.fg]);
XSetFont(xw.dis, dc.gc, g.mode & ATTR_BOLD ? dc.bfont->fid : dc.font->fid);
- XDrawImageString(xw.dis, xw.win, dc.gc, r.x, r.y+dc.font->ascent, &g.c, 1);
+ XDrawImageString(xw.dis, xw.buf, dc.gc, r.x, r.y+dc.font->ascent, &g.c, 1);
}
void
@@ -1178,6 +1152,8 @@
if(!term.hidec)
xcursor(CURSOR_DRAW);
+ XCopyArea(xw.dis, xw.buf, xw.win, dc.gc, 0, 0, xw.w, xw.h, BORDER, BORDER);
+ XFlush(xw.dis);
}
#endif
@@ -1187,7 +1163,6 @@
Glyph base, new;
char buf[DRAW_BUF_SIZ];
- /* XXX: optimize with GLYPH_DIRTY hint */
for(y = 0; y < term.row; y++) {
base = term.line[y][0];
i = ox = 0;
@@ -1206,6 +1181,8 @@
xdraws(buf, base, ox, y, i);
}
xcursor(term.hidec ? CURSOR_HIDE : CURSOR_DRAW);
+ XCopyArea(xw.dis, xw.buf, xw.win, dc.gc, 0, 0, xw.w, xw.h, BORDER, BORDER);
+ XFlush(xw.dis);
}
void
@@ -1273,6 +1250,8 @@
ttyresize(col, row);
xw.w = e->xconfigure.width;
xw.h = e->xconfigure.height;
+ XFreePixmap(xw.dis, xw.buf);
+ xw.buf = XCreatePixmap(xw.dis, xw.win, xw.w, xw.h, XDefaultDepth(xw.dis, xw.scr));
draw(SCREEN_REDRAW);
}
}
@@ -1285,7 +1264,7 @@
running = 1;
XSelectInput(xw.dis, xw.win, ExposureMask | KeyPressMask | StructureNotifyMask);
- XResizeWindow(xw.dis, xw.win, xw.w , xw.h); /* fix resize bug in wmii (?) */
+ XResizeWindow(xw.dis, xw.win, xw.w+2*BORDER, xw.h+2*BORDER); /* fix resize bug in wmii (?) */
while(running) {
FD_ZERO(&rfd);
Received on Mon Mar 15 2010 - 22:56:58 UTC
This archive was generated by hypermail 2.2.0 : Mon Mar 15 2010 - 23:00:09 UTC