diff --git a/config.h b/config.h index 047d735..7ee25e0 100644 --- a/config.h +++ b/config.h @@ -7,6 +7,7 @@ */ static char font[] = "xos4 Terminus:pixelsize=13:antialias=true:autohint=true"; static int borderpx = 2; +#define histsize 2000 /* * What program is execed by st depends of these precedence rules: @@ -161,17 +162,18 @@ static Axiskey ashortcuts[] = { #define MODKEY MOD_MASK_ALT static Shortcut shortcuts[] = { - /* modifier key function argument */ - { MOD_MASK_ANY, XKB_KEY_Break, sendbreak, {.i = 0} }, - { MOD_MASK_CTRL, XKB_KEY_Print, toggleprinter, {.i = 0} }, - { MOD_MASK_SHIFT, XKB_KEY_Print, printscreen, {.i = 0} }, - { MOD_MASK_ANY, XKB_KEY_Print, printsel, {.i = 0} }, - { MODKEY|MOD_MASK_SHIFT, XKB_KEY_Prior, wlzoom, {.f = +1} }, - { MODKEY|MOD_MASK_SHIFT, XKB_KEY_Next, wlzoom, {.f = -1} }, - { MODKEY|MOD_MASK_SHIFT, XKB_KEY_Home, wlzoomreset, {.f = 0} }, - { MOD_MASK_SHIFT, XKB_KEY_Insert, selpaste, {.i = 0} }, - { MODKEY, XKB_KEY_Num_Lock, numlock, {.i = 0} }, - { MODKEY, XKB_KEY_Control_L, iso14755, {.i = 0} }, + /* modifier key function argument */ + { MOD_MASK_ANY, XKB_KEY_Break, sendbreak, {.i = 0} }, + { MOD_MASK_CTRL, XKB_KEY_Print, toggleprinter, {.i = 0} }, + { MOD_MASK_SHIFT, XKB_KEY_Print, printscreen, {.i = 0} }, + { MOD_MASK_ANY, XKB_KEY_Print, printsel, {.i = 0} }, + { MODKEY|MOD_MASK_SHIFT, XKB_KEY_Prior, wlzoom, {.f = +1} }, + { MODKEY|MOD_MASK_SHIFT, XKB_KEY_Next, wlzoom, {.f = -1} }, + { MODKEY|MOD_MASK_SHIFT, XKB_KEY_Home, wlzoomreset, {.f = 0} }, + { MOD_MASK_SHIFT, XKB_KEY_Insert, selpaste, {.i = 0} }, + { MODKEY, XKB_KEY_Num_Lock, numlock, {.i = 0} }, + { MOD_MASK_SHIFT, XKB_KEY_Page_Up, kscrollup, {.i = -1} }, + { MOD_MASK_SHIFT, XKB_KEY_Page_Down, kscrolldown, {.i = -1} }, }; /* diff --git a/st.c b/st.c index d905620..12cd91c 100644 --- a/st.c +++ b/st.c @@ -93,6 +93,9 @@ char *argv0; #define TRUEGREEN(x) (((x) & 0xff00)) #define TRUEBLUE(x) (((x) & 0xff) << 8) +#define TLINE(y) ((y) < term.scr ? term.hist[((y) + term.histi - term.scr \ + + histsize + 1) % histsize] : term.line[(y) - term.scr]) + /* constants */ #define ISO14755CMD "dmenu -p codepoint: 0 && term.line[y][i - 1].u == ' ') + while (i > 0 && TLINE(y)[i - 1].u == ' ') --i; return i; @@ -865,7 +875,7 @@ selsnap(int *x, int *y, int direction) * Snap around if the word wraps around at the end or * beginning of a line. */ - prevgp = &term.line[*y][*x]; + prevgp = &TLINE(*y)[*x]; prevdelim = ISDELIM(prevgp->u); for (;;) { newx = *x + direction; @@ -880,14 +890,14 @@ selsnap(int *x, int *y, int direction) yt = *y, xt = *x; else yt = newy, xt = newx; - if (!(term.line[yt][xt].mode & ATTR_WRAP)) + if (!(TLINE(yt)[xt].mode & ATTR_WRAP)) break; } if (newx >= tlinelen(newy)) break; - gp = &term.line[newy][newx]; + gp = &TLINE(newy)[newx]; delim = ISDELIM(gp->u); if (!(gp->mode & ATTR_WDUMMY) && (delim != prevdelim || (delim && gp->u != prevgp->u))) @@ -908,14 +918,14 @@ selsnap(int *x, int *y, int direction) *x = (direction < 0) ? 0 : term.col - 1; if (direction < 0) { for (; *y > 0; *y += direction) { - if (!(term.line[*y-1][term.col-1].mode + if (!(TLINE(*y-1)[term.col-1].mode & ATTR_WRAP)) { break; } } } else if (direction > 0) { for (; *y < term.row-1; *y += direction) { - if (!(term.line[*y][term.col-1].mode + if (!(TLINE(*y)[term.col-1].mode & ATTR_WRAP)) { break; } @@ -1048,13 +1058,13 @@ getsel(void) } if (sel.type == SEL_RECTANGULAR) { - gp = &term.line[y][sel.nb.x]; + gp = &TLINE(y)[sel.nb.x]; lastx = sel.ne.x; } else { - gp = &term.line[y][sel.nb.y == y ? sel.nb.x : 0]; + gp = &TLINE(y)[sel.nb.y == y ? sel.nb.x : 0]; lastx = (sel.ne.y == y) ? sel.ne.x : term.col-1; } - last = &term.line[y][MIN(lastx, linelen-1)]; + last = &TLINE(y)[MIN(lastx, linelen-1)]; while (last >= gp && last->u == ' ') --last; @@ -1355,6 +1365,10 @@ ttyread(void) if (buflen > 0) memmove(buf, ptr, buflen); + if (term.scr > 0 && term.scr < histsize-1) + term.scr++; + + needdraw = true; return ret; } @@ -1365,6 +1379,9 @@ ttywrite(const char *s, size_t n) fd_set wfd, rfd; ssize_t r; size_t lim = 256; + Arg arg = (Arg){ .i = term.scr }; + + kscrolldown(&arg); /* * Remember that we are using a pty, which might be a modem line. @@ -1569,13 +1586,53 @@ tswapscreen(void) } void -tscrolldown(int orig, int n) +kscrolldown(const Arg* a) +{ + int n = a->i; + + if (n < 0) + n = term.row + n; + + if (n > term.scr) + n = term.scr; + + if (term.scr > 0) { + term.scr -= n; + selscroll(0, -n); + tfulldirt(); + } +} + +void +kscrollup(const Arg* a) +{ + int n = a->i; + + if (n < 0) + n = term.row + n; + + if (term.scr <= histsize - n) { + term.scr += n; + selscroll(0, n); + tfulldirt(); + } +} + +void +tscrolldown(int orig, int n, int copyhist) { int i; Line temp; LIMIT(n, 0, term.bot-orig+1); + if (copyhist) { + term.histi = (term.histi - 1 + histsize) % histsize; + temp = term.hist[term.histi]; + term.hist[term.histi] = term.line[term.bot]; + term.line[term.bot] = temp; + } + tsetdirt(orig, term.bot-n); tclearregion(0, term.bot-n+1, term.col-1, term.bot); @@ -1589,13 +1646,20 @@ tscrolldown(int orig, int n) } void -tscrollup(int orig, int n) +tscrollup(int orig, int n, int copyhist) { int i; Line temp; LIMIT(n, 0, term.bot-orig+1); + if (copyhist) { + term.histi = (term.histi + 1) % histsize; + temp = term.hist[term.histi]; + term.hist[term.histi] = term.line[orig]; + term.line[orig] = temp; + } + tclearregion(0, orig, term.col-1, orig+n-1); tsetdirt(orig+n, term.bot); @@ -1644,7 +1708,7 @@ tnewline(int first_col) int y = term.c.y; if (y == term.bot) { - tscrollup(term.top, 1); + tscrollup(term.top, 1, 1); } else { y++; } @@ -1809,14 +1873,14 @@ void tinsertblankline(int n) { if (BETWEEN(term.c.y, term.top, term.bot)) - tscrolldown(term.c.y, n); + tscrolldown(term.c.y, n, 0); } void tdeleteline(int n) { if (BETWEEN(term.c.y, term.top, term.bot)) - tscrollup(term.c.y, n); + tscrollup(term.c.y, n, 0); } int32_t @@ -2246,11 +2310,11 @@ csihandle(void) break; case 'S': /* SU -- Scroll line up */ DEFAULT(csiescseq.arg[0], 1); - tscrollup(term.top, csiescseq.arg[0]); + tscrollup(term.top, csiescseq.arg[0], 0); break; case 'T': /* SD -- Scroll line down */ DEFAULT(csiescseq.arg[0], 1); - tscrolldown(term.top, csiescseq.arg[0]); + tscrolldown(term.top, csiescseq.arg[0], 0); break; case 'L': /* IL -- Insert blank lines */ DEFAULT(csiescseq.arg[0], 1); @@ -2787,7 +2851,7 @@ eschandle(uchar ascii) return 0; case 'D': /* IND -- Linefeed */ if (term.c.y == term.bot) { - tscrollup(term.top, 1); + tscrollup(term.top, 1, 1); } else { tmoveto(term.c.x, term.c.y+1); } @@ -2800,7 +2864,7 @@ eschandle(uchar ascii) break; case 'M': /* RI -- Reverse index */ if (term.c.y == term.top) { - tscrolldown(term.top, 1); + tscrolldown(term.top, 1, 1); } else { tmoveto(term.c.x, term.c.y-1); } @@ -2987,7 +3051,7 @@ check_control_code: void tresize(int col, int row) { - int i; + int i, j; int minrow = MIN(row, term.row); int mincol = MIN(col, term.col); int *bp; @@ -3024,6 +3088,14 @@ tresize(int col, int row) term.dirty = xrealloc(term.dirty, row * sizeof(*term.dirty)); term.tabs = xrealloc(term.tabs, col * sizeof(*term.tabs)); + for (i = 0; i < histsize; i++) { + term.hist[i] = xrealloc(term.hist[i], col * sizeof(Glyph)); + for (j = mincol; j < col; j++) { + term.hist[i][j] = term.c.attr; + term.hist[i][j].u = ' '; + } + } + /* resize each row to new width, zero-pad if needed */ for (i = 0; i < minrow; i++) { term.line[i] = xrealloc(term.line[i], col * sizeof(Glyph)); @@ -3413,11 +3485,22 @@ wlinit(void) wl.surface = wl_compositor_create_surface(wl.cmp); wl_surface_add_listener(wl.surface, &surflistener, NULL); + if (wl.shell == NULL) + die("wl.shell is not initialized.\n"); + wl.xdgsurface = zxdg_shell_v6_get_xdg_surface(wl.shell, wl.surface); + if (wl.xdgsurface == NULL) + die("wl.xdgsurface is not initialized.\n"); + zxdg_surface_v6_add_listener(wl.xdgsurface, &xdgsurflistener, NULL); + wl.xdgtoplevel = zxdg_surface_v6_get_toplevel(wl.xdgsurface); + if (wl.xdgtoplevel == NULL) + die("wl.xdgtoplevel is not initialized.\n"); + zxdg_toplevel_v6_set_app_id(wl.xdgtoplevel, opt_class ? opt_class : termname); + zxdg_toplevel_v6_add_listener(wl.xdgtoplevel, &xdgtoplevellistener, NULL); @@ -3845,10 +3928,10 @@ drawregion(int x1, int y1, int x2, int y2) continue; term.dirty[y] = 0; - base = term.line[y][0]; + base = TLINE(y)[0]; ic = ib = ox = 0; for (x = x1; x < x2; x++) { - new = term.line[y][x]; + new = TLINE(y)[x]; if (new.mode == ATTR_WDUMMY) continue; if (ena_sel && selected(x, y)) @@ -3869,7 +3952,8 @@ drawregion(int x1, int y1, int x2, int y2) if (ib > 0) wldraws(buf, base, ox, y, ic, ib); } - wldrawcursor(); + if(term.scr == 0) + wldrawcursor(); } void @@ -3957,6 +4041,8 @@ regglobal(void *data, struct wl_registry *registry, uint32_t name, } else if (strcmp(interface, "zxdg_shell_v6") == 0) { wl.shell = wl_registry_bind(registry, name, &zxdg_shell_v6_interface, 1); + if(wl.shell == NULL) + die("wl.shell is null.\n"); zxdg_shell_v6_add_listener(wl.shell, &xdgshelllistener, NULL); } else if (strcmp(interface, "wl_shm") == 0) { wl.shm = wl_registry_bind(registry, name, &wl_shm_interface, 1);