diff options
author | Alexander Sedov <alex0player@gmail.com> | 2013-04-15 17:13:19 +0400 |
---|---|---|
committer | Christoph Lohmann <20h@r-36.net> | 2013-04-18 06:48:06 +0200 |
commit | b7e6a5c825a8d786a0cc4dbacc82df1c90ad7020 (patch) | |
tree | 1b46dc1d69a91880a82e9d3b3aada8edd99c8d85 | |
parent | 3ae02990648447ec3252b42f5b64e18818c19fd8 (diff) | |
download | st-patched-b7e6a5c825a8d786a0cc4dbacc82df1c90ad7020.tar.bz2 st-patched-b7e6a5c825a8d786a0cc4dbacc82df1c90ad7020.tar.xz st-patched-b7e6a5c825a8d786a0cc4dbacc82df1c90ad7020.zip |
Got rid of redundant Glyph state.
Now, newly allocated Glyphs are set to spaces and current cursor colors
with tclearregion() routine.
Signed-off-by: Christoph Lohmann <20h@r-36.net>
-rw-r--r-- | st.c | 79 |
1 files changed, 34 insertions, 45 deletions
@@ -98,11 +98,6 @@ enum cursor_state { | |||
98 | CURSOR_ORIGIN = 2 | 98 | CURSOR_ORIGIN = 2 |
99 | }; | 99 | }; |
100 | 100 | ||
101 | enum glyph_state { | ||
102 | GLYPH_SET = 1, | ||
103 | GLYPH_DIRTY = 2 | ||
104 | }; | ||
105 | |||
106 | enum term_mode { | 101 | enum term_mode { |
107 | MODE_WRAP = 1, | 102 | MODE_WRAP = 1, |
108 | MODE_INSERT = 2, | 103 | MODE_INSERT = 2, |
@@ -154,7 +149,6 @@ typedef struct { | |||
154 | uchar mode; /* attribute flags */ | 149 | uchar mode; /* attribute flags */ |
155 | ushort fg; /* foreground */ | 150 | ushort fg; /* foreground */ |
156 | ushort bg; /* background */ | 151 | ushort bg; /* background */ |
157 | uchar state; /* state flags */ | ||
158 | } Glyph; | 152 | } Glyph; |
159 | 153 | ||
160 | typedef Glyph *Line; | 154 | typedef Glyph *Line; |
@@ -757,7 +751,7 @@ bpress(XEvent *e) { | |||
757 | 751 | ||
758 | void | 752 | void |
759 | selcopy(void) { | 753 | selcopy(void) { |
760 | char *str, *ptr, *p; | 754 | char *str, *ptr; |
761 | int x, y, bufsize, isselected = 0, size; | 755 | int x, y, bufsize, isselected = 0, size; |
762 | Glyph *gp, *last; | 756 | Glyph *gp, *last; |
763 | 757 | ||
@@ -773,8 +767,8 @@ selcopy(void) { | |||
773 | gp = &term.line[y][0]; | 767 | gp = &term.line[y][0]; |
774 | last = gp + term.col; | 768 | last = gp + term.col; |
775 | 769 | ||
776 | while(--last >= gp && !((last->state & GLYPH_SET) && \ | 770 | while(--last >= gp && !(selected(last - gp, y) && \ |
777 | selected(last - gp, y) && strcmp(last->c, " ") != 0)) | 771 | strcmp(last->c, " ") != 0)) |
778 | /* nothing */; | 772 | /* nothing */; |
779 | 773 | ||
780 | for(x = 0; gp <= last; x++, ++gp) { | 774 | for(x = 0; gp <= last; x++, ++gp) { |
@@ -784,9 +778,8 @@ selcopy(void) { | |||
784 | isselected = 1; | 778 | isselected = 1; |
785 | } | 779 | } |
786 | 780 | ||
787 | p = (gp->state & GLYPH_SET) ? gp->c : " "; | 781 | size = utf8size(gp->c); |
788 | size = utf8size(p); | 782 | memcpy(ptr, gp->c, size); |
789 | memcpy(ptr, p, size); | ||
790 | ptr += size; | 783 | ptr += size; |
791 | } | 784 | } |
792 | 785 | ||
@@ -943,13 +936,11 @@ brelease(XEvent *e) { | |||
943 | } else if(TIMEDIFF(now, sel.tclick1) <= doubleclicktimeout) { | 936 | } else if(TIMEDIFF(now, sel.tclick1) <= doubleclicktimeout) { |
944 | /* double click to select word */ | 937 | /* double click to select word */ |
945 | sel.bx = sel.ex; | 938 | sel.bx = sel.ex; |
946 | while(sel.bx > 0 && term.line[sel.ey][sel.bx-1].state & GLYPH_SET && | 939 | while(sel.bx > 0 && term.line[sel.ey][sel.bx-1].c[0] != ' ') { |
947 | term.line[sel.ey][sel.bx-1].c[0] != ' ') { | ||
948 | sel.bx--; | 940 | sel.bx--; |
949 | } | 941 | } |
950 | sel.b.x = sel.bx; | 942 | sel.b.x = sel.bx; |
951 | while(sel.ex < term.col-1 && term.line[sel.ey][sel.ex+1].state & GLYPH_SET && | 943 | while(sel.ex < term.col-1 && term.line[sel.ey][sel.ex+1].c[0] != ' ') { |
952 | term.line[sel.ey][sel.ex+1].c[0] != ' ') { | ||
953 | sel.ex++; | 944 | sel.ex++; |
954 | } | 945 | } |
955 | sel.e.x = sel.ex; | 946 | sel.e.x = sel.ex; |
@@ -1373,7 +1364,6 @@ tsetchar(char *c, Glyph *attr, int x, int y) { | |||
1373 | term.dirty[y] = 1; | 1364 | term.dirty[y] = 1; |
1374 | term.line[y][x] = *attr; | 1365 | term.line[y][x] = *attr; |
1375 | memcpy(term.line[y][x].c, c, UTF_SIZ); | 1366 | memcpy(term.line[y][x].c, c, UTF_SIZ); |
1376 | term.line[y][x].state |= GLYPH_SET; | ||
1377 | } | 1367 | } |
1378 | 1368 | ||
1379 | void | 1369 | void |
@@ -1395,7 +1385,6 @@ tclearregion(int x1, int y1, int x2, int y2) { | |||
1395 | for(x = x1; x <= x2; x++) { | 1385 | for(x = x1; x <= x2; x++) { |
1396 | term.line[y][x] = term.c.attr; | 1386 | term.line[y][x] = term.c.attr; |
1397 | memcpy(term.line[y][x].c, " ", 2); | 1387 | memcpy(term.line[y][x].c, " ", 2); |
1398 | term.line[y][x].state |= GLYPH_SET; | ||
1399 | } | 1388 | } |
1400 | } | 1389 | } |
1401 | } | 1390 | } |
@@ -2263,11 +2252,12 @@ tputc(char *c, int len) { | |||
2263 | 2252 | ||
2264 | int | 2253 | int |
2265 | tresize(int col, int row) { | 2254 | tresize(int col, int row) { |
2266 | int i, x; | 2255 | int i; |
2267 | int minrow = MIN(row, term.row); | 2256 | int minrow = MIN(row, term.row); |
2268 | int mincol = MIN(col, term.col); | 2257 | int mincol = MIN(col, term.col); |
2269 | int slide = term.c.y - row + 1; | 2258 | int slide = term.c.y - row + 1; |
2270 | bool *bp; | 2259 | bool *bp; |
2260 | Line *orig; | ||
2271 | 2261 | ||
2272 | if(col < 1 || row < 1) | 2262 | if(col < 1 || row < 1) |
2273 | return 0; | 2263 | return 0; |
@@ -2303,10 +2293,6 @@ tresize(int col, int row) { | |||
2303 | term.dirty[i] = 1; | 2293 | term.dirty[i] = 1; |
2304 | term.line[i] = xrealloc(term.line[i], col * sizeof(Glyph)); | 2294 | term.line[i] = xrealloc(term.line[i], col * sizeof(Glyph)); |
2305 | term.alt[i] = xrealloc(term.alt[i], col * sizeof(Glyph)); | 2295 | term.alt[i] = xrealloc(term.alt[i], col * sizeof(Glyph)); |
2306 | for(x = mincol; x < col; x++) { | ||
2307 | term.line[i][x].state = 0; | ||
2308 | term.alt[i][x].state = 0; | ||
2309 | } | ||
2310 | } | 2296 | } |
2311 | 2297 | ||
2312 | /* allocate any new rows */ | 2298 | /* allocate any new rows */ |
@@ -2331,6 +2317,17 @@ tresize(int col, int row) { | |||
2331 | tsetscroll(0, row-1); | 2317 | tsetscroll(0, row-1); |
2332 | /* make use of the LIMIT in tmoveto */ | 2318 | /* make use of the LIMIT in tmoveto */ |
2333 | tmoveto(term.c.x, term.c.y); | 2319 | tmoveto(term.c.x, term.c.y); |
2320 | /* Clearing both screens */ | ||
2321 | orig = term.line; | ||
2322 | do { | ||
2323 | if(mincol < col && 0 < minrow) { | ||
2324 | tclearregion(mincol, 0, col - 1, minrow - 1); | ||
2325 | } | ||
2326 | if(0 < col && minrow < row) { | ||
2327 | tclearregion(0, minrow, col - 1, row - 1); | ||
2328 | } | ||
2329 | tswapscreen(); | ||
2330 | } while(orig != term.line); | ||
2334 | 2331 | ||
2335 | return (slide > 0); | 2332 | return (slide > 0); |
2336 | } | 2333 | } |
@@ -2932,22 +2929,17 @@ void | |||
2932 | xdrawcursor(void) { | 2929 | xdrawcursor(void) { |
2933 | static int oldx = 0, oldy = 0; | 2930 | static int oldx = 0, oldy = 0; |
2934 | int sl; | 2931 | int sl; |
2935 | Glyph g = {{' '}, ATTR_NULL, defaultbg, defaultcs, 0}; | 2932 | Glyph g = {{' '}, ATTR_NULL, defaultbg, defaultcs}; |
2936 | 2933 | ||
2937 | LIMIT(oldx, 0, term.col-1); | 2934 | LIMIT(oldx, 0, term.col-1); |
2938 | LIMIT(oldy, 0, term.row-1); | 2935 | LIMIT(oldy, 0, term.row-1); |
2939 | 2936 | ||
2940 | if(term.line[term.c.y][term.c.x].state & GLYPH_SET) | 2937 | memcpy(g.c, term.line[term.c.y][term.c.x].c, UTF_SIZ); |
2941 | memcpy(g.c, term.line[term.c.y][term.c.x].c, UTF_SIZ); | ||
2942 | 2938 | ||
2943 | /* remove the old cursor */ | 2939 | /* remove the old cursor */ |
2944 | if(term.line[oldy][oldx].state & GLYPH_SET) { | 2940 | sl = utf8size(term.line[oldy][oldx].c); |
2945 | sl = utf8size(term.line[oldy][oldx].c); | 2941 | xdraws(term.line[oldy][oldx].c, term.line[oldy][oldx], oldx, |
2946 | xdraws(term.line[oldy][oldx].c, term.line[oldy][oldx], oldx, | 2942 | oldy, 1, sl); |
2947 | oldy, 1, sl); | ||
2948 | } else { | ||
2949 | xtermclear(oldx, oldy, oldx, oldy); | ||
2950 | } | ||
2951 | 2943 | ||
2952 | /* draw the new one */ | 2944 | /* draw the new one */ |
2953 | if(!(IS_SET(MODE_HIDE))) { | 2945 | if(!(IS_SET(MODE_HIDE))) { |
@@ -3045,23 +3037,20 @@ drawregion(int x1, int y1, int x2, int y2) { | |||
3045 | new = term.line[y][x]; | 3037 | new = term.line[y][x]; |
3046 | if(ena_sel && *(new.c) && selected(x, y)) | 3038 | if(ena_sel && *(new.c) && selected(x, y)) |
3047 | new.mode ^= ATTR_REVERSE; | 3039 | new.mode ^= ATTR_REVERSE; |
3048 | if(ib > 0 && (!(new.state & GLYPH_SET) | 3040 | if(ib > 0 && (ATTRCMP(base, new) |
3049 | || ATTRCMP(base, new) | ||
3050 | || ib >= DRAW_BUF_SIZ-UTF_SIZ)) { | 3041 | || ib >= DRAW_BUF_SIZ-UTF_SIZ)) { |
3051 | xdraws(buf, base, ox, y, ic, ib); | 3042 | xdraws(buf, base, ox, y, ic, ib); |
3052 | ic = ib = 0; | 3043 | ic = ib = 0; |
3053 | } | 3044 | } |
3054 | if(new.state & GLYPH_SET) { | 3045 | if(ib == 0) { |
3055 | if(ib == 0) { | 3046 | ox = x; |
3056 | ox = x; | 3047 | base = new; |
3057 | base = new; | ||
3058 | } | ||
3059 | |||
3060 | sl = utf8size(new.c); | ||
3061 | memcpy(buf+ib, new.c, sl); | ||
3062 | ib += sl; | ||
3063 | ++ic; | ||
3064 | } | 3048 | } |
3049 | |||
3050 | sl = utf8size(new.c); | ||
3051 | memcpy(buf+ib, new.c, sl); | ||
3052 | ib += sl; | ||
3053 | ++ic; | ||
3065 | } | 3054 | } |
3066 | if(ib > 0) | 3055 | if(ib > 0) |
3067 | xdraws(buf, base, ox, y, ic, ib); | 3056 | xdraws(buf, base, ox, y, ic, ib); |