Guest User

Untitled

a guest
Apr 24th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.44 KB | None | 0 0
  1. diff --git a/config.def.h b/config.def.h
  2. index 82b1b09..cfbdc9f 100644
  3. --- a/config.def.h
  4. +++ b/config.def.h
  5. @@ -82,6 +82,9 @@ char *termname = "st-256color";
  6. */
  7. unsigned int tabspaces = 8;
  8.  
  9. +/* bg opacity */
  10. +unsigned int alpha = 0xcc;
  11. +
  12. /* Terminal colors (16 first used in escape sequence) */
  13. static const char *colorname[] = {
  14. /* 8 normal colors */
  15. @@ -109,6 +112,7 @@ static const char *colorname[] = {
  16. /* more colors can be added after 255 to use with DefaultXX */
  17. "#cccccc",
  18. "#555555",
  19. + "black,
  20. };
  21.  
  22.  
  23. @@ -178,6 +182,8 @@ static Shortcut shortcuts[] = {
  24. { TERMMOD, XK_Y, selpaste, {.i = 0} },
  25. { TERMMOD, XK_Num_Lock, numlock, {.i = 0} },
  26. { TERMMOD, XK_I, iso14755, {.i = 0} },
  27. + { ShiftMask, XK_Page_Up, kscrollup, {.i = -1} },
  28. + { ShiftMask, XK_Page_Down, kscrolldown, {.i = -1} },
  29. };
  30.  
  31. /*
  32. diff --git a/config.mk b/config.mk
  33. index 039c42c..eb2dc01 100644
  34. --- a/config.mk
  35. +++ b/config.mk
  36. @@ -14,7 +14,7 @@ X11LIB = /usr/X11R6/lib
  37. INCS = -I$(X11INC) \
  38. `pkg-config --cflags fontconfig` \
  39. `pkg-config --cflags freetype2`
  40. -LIBS = -L$(X11LIB) -lm -lrt -lX11 -lutil -lXft \
  41. +LIBS = -L$(X11LIB) -lm -lrt -lX11 -lutil -lXft -lXrender \
  42. `pkg-config --libs fontconfig` \
  43. `pkg-config --libs freetype2`
  44.  
  45. diff --git a/st.c b/st.c
  46. index 0628707..2888643 100644
  47. --- a/st.c
  48. +++ b/st.c
  49. @@ -121,6 +121,9 @@ typedef struct {
  50. int col; /* nb col */
  51. Line *line; /* screen */
  52. Line *alt; /* alternate screen */
  53. + Line hist[HISTSIZE]; /* history buffer */
  54. + int histi; /* history index */
  55. + int scr; /* scroll back */
  56. int *dirty; /* dirtyness of lines */
  57. TCursor c; /* cursor */
  58. int ocx; /* old cursor col */
  59. @@ -188,8 +191,8 @@ static void tnewline(int);
  60. static void tputtab(int);
  61. static void tputc(Rune);
  62. static void treset(void);
  63. -static void tscrollup(int, int);
  64. -static void tscrolldown(int, int);
  65. +static void tscrollup(int, int, int);
  66. +static void tscrolldown(int, int, int);
  67. static void tsetattr(int *, int);
  68. static void tsetchar(Rune, Glyph *, int, int);
  69. static void tsetdirt(int, int);
  70. @@ -431,10 +434,10 @@ tlinelen(int y)
  71. {
  72. int i = term.col;
  73.  
  74. - if (term.line[y][i - 1].mode & ATTR_WRAP)
  75. + if (TLINE(y)[i - 1].mode & ATTR_WRAP)
  76. return i;
  77.  
  78. - while (i > 0 && term.line[y][i - 1].u == ' ')
  79. + while (i > 0 && TLINE(y)[i - 1].u == ' ')
  80. --i;
  81.  
  82. return i;
  83. @@ -543,7 +546,7 @@ selsnap(int *x, int *y, int direction)
  84. * Snap around if the word wraps around at the end or
  85. * beginning of a line.
  86. */
  87. - prevgp = &term.line[*y][*x];
  88. + prevgp = &TLINE(*y)[*x];
  89. prevdelim = ISDELIM(prevgp->u);
  90. for (;;) {
  91. newx = *x + direction;
  92. @@ -558,14 +561,14 @@ selsnap(int *x, int *y, int direction)
  93. yt = *y, xt = *x;
  94. else
  95. yt = newy, xt = newx;
  96. - if (!(term.line[yt][xt].mode & ATTR_WRAP))
  97. + if (!(TLINE(yt)[xt].mode & ATTR_WRAP))
  98. break;
  99. }
  100.  
  101. if (newx >= tlinelen(newy))
  102. break;
  103.  
  104. - gp = &term.line[newy][newx];
  105. + gp = &TLINE(newy)[newx];
  106. delim = ISDELIM(gp->u);
  107. if (!(gp->mode & ATTR_WDUMMY) && (delim != prevdelim
  108. || (delim && gp->u != prevgp->u)))
  109. @@ -586,14 +589,14 @@ selsnap(int *x, int *y, int direction)
  110. *x = (direction < 0) ? 0 : term.col - 1;
  111. if (direction < 0) {
  112. for (; *y > 0; *y += direction) {
  113. - if (!(term.line[*y-1][term.col-1].mode
  114. + if (!(TLINE(*y-1)[term.col-1].mode
  115. & ATTR_WRAP)) {
  116. break;
  117. }
  118. }
  119. } else if (direction > 0) {
  120. for (; *y < term.row-1; *y += direction) {
  121. - if (!(term.line[*y][term.col-1].mode
  122. + if (!(TLINE(*y)[term.col-1].mode
  123. & ATTR_WRAP)) {
  124. break;
  125. }
  126. @@ -624,13 +627,13 @@ getsel(void)
  127. }
  128.  
  129. if (sel.type == SEL_RECTANGULAR) {
  130. - gp = &term.line[y][sel.nb.x];
  131. + gp = &TLINE(y)[sel.nb.x];
  132. lastx = sel.ne.x;
  133. } else {
  134. - gp = &term.line[y][sel.nb.y == y ? sel.nb.x : 0];
  135. + gp = &TLINE(y)[sel.nb.y == y ? sel.nb.x : 0];
  136. lastx = (sel.ne.y == y) ? sel.ne.x : term.col-1;
  137. }
  138. - last = &term.line[y][MIN(lastx, linelen-1)];
  139. + last = &TLINE(y)[MIN(lastx, linelen-1)];
  140. while (last >= gp && last->u == ' ')
  141. --last;
  142.  
  143. @@ -836,6 +839,9 @@ ttyread(void)
  144. if (buflen > 0)
  145. memmove(buf, buf + written, buflen);
  146.  
  147. + if (term.scr > 0 && term.scr < HISTSIZE-1)
  148. + term.scr++;
  149. +
  150. return ret;
  151. }
  152.  
  153. @@ -843,6 +849,9 @@ void
  154. ttywrite(const char *s, size_t n, int may_echo)
  155. {
  156. const char *next;
  157. + Arg arg = (Arg) { .i = term.scr };
  158. +
  159. + kscrolldown(&arg);
  160.  
  161. if (may_echo && IS_SET(MODE_ECHO))
  162. twrite(s, n, 1);
  163. @@ -1054,13 +1063,54 @@ tswapscreen(void)
  164. }
  165.  
  166. void
  167. -tscrolldown(int orig, int n)
  168. +kscrolldown(const Arg* a)
  169. +{
  170. + int n = a->i;
  171. +
  172. + if (n < 0)
  173. + n = term.row + n;
  174. +
  175. + if (n > term.scr)
  176. + n = term.scr;
  177. +
  178. + if (term.scr > 0) {
  179. + term.scr -= n;
  180. + selscroll(0, -n);
  181. + tfulldirt();
  182. + }
  183. +}
  184. +
  185. +void
  186. +kscrollup(const Arg* a)
  187. +{
  188. + int n = a->i;
  189. +
  190. + if (n < 0)
  191. + n = term.row + n;
  192. +
  193. + if (term.scr <= HISTSIZE-n) {
  194. + term.scr += n;
  195. + selscroll(0, n);
  196. + tfulldirt();
  197. + }
  198. +}
  199. +
  200. +
  201. +void
  202. +tscrolldown(int orig, int n, int copyhist)
  203. {
  204. int i;
  205. Line temp;
  206.  
  207. LIMIT(n, 0, term.bot-orig+1);
  208.  
  209. + if (copyhist) {
  210. + term.histi = (term.histi - 1 + HISTSIZE) % HISTSIZE;
  211. + temp = term.hist[term.histi];
  212. + term.hist[term.histi] = term.line[term.bot];
  213. + term.line[term.bot] = temp;
  214. + }
  215. +
  216. tsetdirt(orig, term.bot-n);
  217. tclearregion(0, term.bot-n+1, term.col-1, term.bot);
  218.  
  219. @@ -1074,13 +1124,20 @@ tscrolldown(int orig, int n)
  220. }
  221.  
  222. void
  223. -tscrollup(int orig, int n)
  224. +tscrollup(int orig, int n, int copyhist)
  225. {
  226. int i;
  227. Line temp;
  228.  
  229. LIMIT(n, 0, term.bot-orig+1);
  230.  
  231. + if (copyhist) {
  232. + term.histi = (term.histi + 1) % HISTSIZE;
  233. + temp = term.hist[term.histi];
  234. + term.hist[term.histi] = term.line[orig];
  235. + term.line[orig] = temp;
  236. + }
  237. +
  238. tclearregion(0, orig, term.col-1, orig+n-1);
  239. tsetdirt(orig+n, term.bot);
  240.  
  241. @@ -1129,7 +1186,7 @@ tnewline(int first_col)
  242. int y = term.c.y;
  243.  
  244. if (y == term.bot) {
  245. - tscrollup(term.top, 1);
  246. + tscrollup(term.top, 1, 1);
  247. } else {
  248. y++;
  249. }
  250. @@ -1294,14 +1351,14 @@ void
  251. tinsertblankline(int n)
  252. {
  253. if (BETWEEN(term.c.y, term.top, term.bot))
  254. - tscrolldown(term.c.y, n);
  255. + tscrolldown(term.c.y, n, 0);
  256. }
  257.  
  258. void
  259. tdeleteline(int n)
  260. {
  261. if (BETWEEN(term.c.y, term.top, term.bot))
  262. - tscrollup(term.c.y, n);
  263. + tscrollup(term.c.y, n, 0);
  264. }
  265.  
  266. int32_t
  267. @@ -1730,11 +1787,11 @@ csihandle(void)
  268. break;
  269. case 'S': /* SU -- Scroll <n> line up */
  270. DEFAULT(csiescseq.arg[0], 1);
  271. - tscrollup(term.top, csiescseq.arg[0]);
  272. + tscrollup(term.top, csiescseq.arg[0], 0);
  273. break;
  274. case 'T': /* SD -- Scroll <n> line down */
  275. DEFAULT(csiescseq.arg[0], 1);
  276. - tscrolldown(term.top, csiescseq.arg[0]);
  277. + tscrolldown(term.top, csiescseq.arg[0], 0);
  278. break;
  279. case 'L': /* IL -- Insert <n> blank lines */
  280. DEFAULT(csiescseq.arg[0], 1);
  281. @@ -2258,7 +2315,7 @@ eschandle(uchar ascii)
  282. return 0;
  283. case 'D': /* IND -- Linefeed */
  284. if (term.c.y == term.bot) {
  285. - tscrollup(term.top, 1);
  286. + tscrollup(term.top, 1, 1);
  287. } else {
  288. tmoveto(term.c.x, term.c.y+1);
  289. }
  290. @@ -2271,7 +2328,7 @@ eschandle(uchar ascii)
  291. break;
  292. case 'M': /* RI -- Reverse index */
  293. if (term.c.y == term.top) {
  294. - tscrolldown(term.top, 1);
  295. + tscrolldown(term.top, 1, 1);
  296. } else {
  297. tmoveto(term.c.x, term.c.y-1);
  298. }
  299. @@ -2490,7 +2547,7 @@ twrite(const char *buf, int buflen, int show_ctrl)
  300. void
  301. tresize(int col, int row)
  302. {
  303. - int i;
  304. + int i, j;
  305. int minrow = MIN(row, term.row);
  306. int mincol = MIN(col, term.col);
  307. int *bp;
  308. @@ -2527,7 +2584,15 @@ tresize(int col, int row)
  309. term.dirty = xrealloc(term.dirty, row * sizeof(*term.dirty));
  310. term.tabs = xrealloc(term.tabs, col * sizeof(*term.tabs));
  311.  
  312. - /* resize each row to new width, zero-pad if needed */
  313. + for (i = 0; i < HISTSIZE; i++) {
  314. + term.hist[i] = xrealloc(term.hist[i], col * sizeof(Glyph));
  315. + for (j = mincol; j < col; j++) {
  316. + term.hist[i][j] = term.c.attr;
  317. + term.hist[i][j].u = ' ';
  318. + }
  319. + }
  320. +
  321. + /* resize each r w to new width, zero-pad if needed */
  322. for (i = 0; i < minrow; i++) {
  323. term.line[i] = xrealloc(term.line[i], col * sizeof(Glyph));
  324. term.alt[i] = xrealloc(term.alt[i], col * sizeof(Glyph));
  325. @@ -2584,7 +2649,7 @@ drawregion(int x1, int y1, int x2, int y2)
  326. continue;
  327.  
  328. term.dirty[y] = 0;
  329. - xdrawline(term.line[y], x1, y, x2);
  330. + xdrawline(TLINE(y), x1, y, x2);
  331. }
  332. }
  333.  
  334. @@ -2605,8 +2670,10 @@ draw(void)
  335. cx--;
  336.  
  337. drawregion(0, 0, term.col, term.row);
  338. - xdrawcursor(cx, term.c.y, term.line[term.c.y][cx],
  339. - term.ocx, term.ocy, term.line[term.ocy][term.ocx]);
  340. + if (term.scr == 0) {
  341. + xdrawcursor(cx, term.c.y, term.line[term.c.y][cx],
  342. + term.ocx, term.ocy, term.line[term.ocy][term.ocx]);
  343. + }
  344. term.ocx = cx, term.ocy = term.c.y;
  345. xfinishdraw();
  346. }
  347. diff --git a/st.h b/st.h
  348. index dac64d8..a2f8335 100644
  349. --- a/st.h
  350. +++ b/st.h
  351. @@ -3,6 +3,9 @@
  352. #include <stdint.h>
  353. #include <sys/types.h>
  354.  
  355. +/* Arbitrary size */
  356. +#define HISTSIZE 2000
  357. +
  358. /* macros */
  359. #define MIN(a, b) ((a) < (b) ? (a) : (b))
  360. #define MAX(a, b) ((a) < (b) ? (b) : (a))
  361. @@ -19,6 +22,8 @@
  362.  
  363. #define TRUECOLOR(r,g,b) (1 << 24 | (r) << 16 | (g) << 8 | (b))
  364. #define IS_TRUECOL(x) (1 << 24 & (x))
  365. +#define TLINE(y) ((y) < term.scr ? term.hist[((y) + term.histi - term.scr \
  366. + + HISTSIZE + 1) % HISTSIZE] : term.line[(y) - term.scr])
  367.  
  368. enum glyph_attribute {
  369. ATTR_NULL = 0,
  370. @@ -111,6 +116,9 @@ void *xmalloc(size_t);
  371. void *xrealloc(void *, size_t);
  372. char *xstrdup(char *);
  373.  
  374. +void kscrolldown(const Arg *);
  375. +void kscrollup(const Arg *);
  376. +
  377. /* config.h globals */
  378. extern char *utmp;
  379. extern char *stty_args;
  380. @@ -118,6 +126,7 @@ extern char *vtiden;
  381. extern char *worddelimiters;
  382. extern int allowaltscreen;
  383. extern char *termname;
  384. +extern unsigned int alpha;
  385. extern unsigned int tabspaces;
  386. extern unsigned int defaultfg;
  387. extern unsigned int defaultbg;
  388. diff --git a/win.h b/win.h
  389. index 31f327d..d277477 100644
  390. --- a/win.h
  391. +++ b/win.h
  392. @@ -23,6 +23,10 @@ enum win_mode {
  393. |MODE_MOUSEMANY,
  394. };
  395.  
  396. +/* alpha */
  397. +#define OPAQUE 0Xff
  398. +#define USE_ARGB (alpha != OPAQUE && opt_embed == NULL)
  399. +
  400. void xbell(void);
  401. void xclipcopy(void);
  402. void xdrawcursor(int, int, Glyph, int, int, Glyph);
  403. diff --git a/x.c b/x.c
  404. index c0bd890..8ced567 100644
  405. --- a/x.c
  406. +++ b/x.c
  407. @@ -98,6 +98,7 @@ typedef struct {
  408. XSetWindowAttributes attrs;
  409. int scr;
  410. int isfixed; /* is fixed geometry? */
  411. + int depth; /* bit depth */
  412. int l, t; /* left and top offset */
  413. int gm; /* geometry mask */
  414. } XWindow;
  415. @@ -686,7 +687,7 @@ xresize(int col, int row)
  416.  
  417. XFreePixmap(xw.dpy, xw.buf);
  418. xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h,
  419. - DefaultDepth(xw.dpy, xw.scr));
  420. + xw.depth);
  421. XftDrawChange(xw.draw, xw.buf);
  422. xclear(0, 0, win.w, win.h);
  423.  
  424. @@ -746,6 +747,12 @@ xloadcols(void)
  425. else
  426. die("could not allocate color %d\n", i);
  427. }
  428. + /* set alpha value of bg color */
  429. + if (USE_ARGB) {
  430. + dc.col[defaultbg].color.alpha = (0xffff * alpha) / OPAQUE;
  431. + dc.col[defaultbg].pixel &= 0x00111111;
  432. + dc.col[defaultbg].pixel |= alpha << 24;
  433. + }
  434. loaded = 1;
  435. }
  436.  
  437. @@ -767,6 +774,17 @@ xsetcolorname(int x, const char *name)
  438. return 0;
  439. }
  440.  
  441. +void
  442. +xtermclear(int col1, int row1, int col2, int row2)
  443. +{
  444. + XftDrawRect(xw.draw,
  445. + &dc.col[IS_SET(MODE_REVERSE) ? defaultfg : defaultbg],
  446. + borderpx + col1 * win.cw,
  447. + borderpx + row1 * win.ch,
  448. + (col2-col1+1) * win.cw,
  449. + (row2-row1+1) * win.ch);
  450. +}
  451. +
  452. /*
  453. * Absolute coordinates.
  454. */
  455. @@ -1004,7 +1022,40 @@ xinit(int cols, int rows)
  456. if (!(xw.dpy = XOpenDisplay(NULL)))
  457. die("can't open display\n");
  458. xw.scr = XDefaultScreen(xw.dpy);
  459. - xw.vis = XDefaultVisual(xw.dpy, xw.scr);
  460. + xw.depth = (USE_ARGB) ? 32: XDefaultDepth(xw.dpy, xw.scr);
  461. + if (!USE_ARGB)
  462. + xw.vis = XDefaultVisual(xw.dpy, xw.scr);
  463. + else {
  464. + XVisualInfo *vis;
  465. + XRenderPictFormat *fmt;
  466. + int nvi;
  467. + int i;
  468. +
  469. + XVisualInfo tpl = {
  470. + .screen = xw.scr,
  471. + .depth = 32,
  472. + .class = TrueColor
  473. + };
  474. +
  475. + vis = XGetVisualInfo(xw.dpy,
  476. + VisualScreenMask | VisualDepthMask | VisualClassMask,
  477. + &tpl, &nvi);
  478. + xw.vis = NULL;
  479. + for (i = 0; i < nvi; i++) {
  480. + fmt = XRenderFindVisualFormat(xw.dpy, vis[i].visual);
  481. + if (fmt->type == PictTypeDirect && fmt->direct.alphaMask) {
  482. + xw.vis = vis[i].visual;
  483. + break;
  484. + }
  485. + }
  486. +
  487. + XFree(vis);
  488. +
  489. + if (!xw.vis) {
  490. + fprintf(stderr, "Couldn't find ARGB visual.\n");
  491. + exit(1);
  492. + }
  493. + }
  494.  
  495. /* font */
  496. if (!FcInit())
  497. @@ -1014,7 +1065,11 @@ xinit(int cols, int rows)
  498. xloadfonts(usedfont, 0);
  499.  
  500. /* colors */
  501. - xw.cmap = XDefaultColormap(xw.dpy, xw.scr);
  502. + if (!USE_ARGB)
  503. + xw.cmap = XDefaultColormap(xw.dpy, xw.scr);
  504. + else
  505. + xw.cmap = XCreateColormap(xw.dpy, XRootWindow(xw.dpy, xw.scr),
  506. + xw.vis, None);
  507. xloadcols();
  508.  
  509. /* adjust fixed window geometry */
  510. @@ -1037,16 +1092,15 @@ xinit(int cols, int rows)
  511. if (!(opt_embed && (parent = strtol(opt_embed, NULL, 0))))
  512. parent = XRootWindow(xw.dpy, xw.scr);
  513. xw.win = XCreateWindow(xw.dpy, parent, xw.l, xw.t,
  514. - win.w, win.h, 0, XDefaultDepth(xw.dpy, xw.scr), InputOutput,
  515. + win.w, win.h, 0, xw.depth, InputOutput,
  516. xw.vis, CWBackPixel | CWBorderPixel | CWBitGravity
  517. | CWEventMask | CWColormap, &xw.attrs);
  518.  
  519. memset(&gcvalues, 0, sizeof(gcvalues));
  520. gcvalues.graphics_exposures = False;
  521. - dc.gc = XCreateGC(xw.dpy, parent, GCGraphicsExposures,
  522. - &gcvalues);
  523. - xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h,
  524. - DefaultDepth(xw.dpy, xw.scr));
  525. + xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h, xw.depth);
  526. + dc.gc = XCreateGC(xw.dpy, (USE_ARGB) ? xw.buf: parent,
  527. + GCGraphicsExposures, &gcvalues);
  528. XSetForeground(xw.dpy, dc.gc, dc.col[defaultbg].pixel);
  529. XFillRectangle(xw.dpy, xw.buf, dc.gc, 0, 0, win.w, win.h);
Add Comment
Please, Sign In to add comment