st-alpha-20220206-0.8.5.diff 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. diff --git a/config.def.h b/config.def.h
  2. index 91ab8ca..6af616e 100644
  3. --- a/config.def.h
  4. +++ b/config.def.h
  5. @@ -93,6 +93,9 @@ char *termname = "st-256color";
  6. */
  7. unsigned int tabspaces = 8;
  8. +/* bg opacity */
  9. +float alpha = 0.8;
  10. +
  11. /* Terminal colors (16 first used in escape sequence) */
  12. static const char *colorname[] = {
  13. /* 8 normal colors */
  14. diff --git a/config.mk b/config.mk
  15. index 4c4c5d5..0114bad 100644
  16. --- a/config.mk
  17. +++ b/config.mk
  18. @@ -16,7 +16,7 @@ PKG_CONFIG = pkg-config
  19. INCS = -I$(X11INC) \
  20. `$(PKG_CONFIG) --cflags fontconfig` \
  21. `$(PKG_CONFIG) --cflags freetype2`
  22. -LIBS = -L$(X11LIB) -lm -lrt -lX11 -lutil -lXft \
  23. +LIBS = -L$(X11LIB) -lm -lrt -lX11 -lutil -lXft -lXrender\
  24. `$(PKG_CONFIG) --libs fontconfig` \
  25. `$(PKG_CONFIG) --libs freetype2`
  26. diff --git a/st.h b/st.h
  27. index 519b9bd..8bb533d 100644
  28. --- a/st.h
  29. +++ b/st.h
  30. @@ -126,3 +126,4 @@ extern unsigned int tabspaces;
  31. extern unsigned int defaultfg;
  32. extern unsigned int defaultbg;
  33. extern unsigned int defaultcs;
  34. +extern float alpha;
  35. diff --git a/x.c b/x.c
  36. index 8a16faa..ddf4178 100644
  37. --- a/x.c
  38. +++ b/x.c
  39. @@ -105,6 +105,7 @@ typedef struct {
  40. XSetWindowAttributes attrs;
  41. int scr;
  42. int isfixed; /* is fixed geometry? */
  43. + int depth; /* bit depth */
  44. int l, t; /* left and top offset */
  45. int gm; /* geometry mask */
  46. } XWindow;
  47. @@ -243,6 +244,7 @@ static char *usedfont = NULL;
  48. static double usedfontsize = 0;
  49. static double defaultfontsize = 0;
  50. +static char *opt_alpha = NULL;
  51. static char *opt_class = NULL;
  52. static char **opt_cmd = NULL;
  53. static char *opt_embed = NULL;
  54. @@ -736,7 +738,7 @@ xresize(int col, int row)
  55. XFreePixmap(xw.dpy, xw.buf);
  56. xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h,
  57. - DefaultDepth(xw.dpy, xw.scr));
  58. + xw.depth);
  59. XftDrawChange(xw.draw, xw.buf);
  60. xclear(0, 0, win.w, win.h);
  61. @@ -796,6 +798,13 @@ xloadcols(void)
  62. else
  63. die("could not allocate color %d\n", i);
  64. }
  65. +
  66. + /* set alpha value of bg color */
  67. + if (opt_alpha)
  68. + alpha = strtof(opt_alpha, NULL);
  69. + dc.col[defaultbg].color.alpha = (unsigned short)(0xffff * alpha);
  70. + dc.col[defaultbg].pixel &= 0x00FFFFFF;
  71. + dc.col[defaultbg].pixel |= (unsigned char)(0xff * alpha) << 24;
  72. loaded = 1;
  73. }
  74. @@ -1118,11 +1127,23 @@ xinit(int cols, int rows)
  75. Window parent;
  76. pid_t thispid = getpid();
  77. XColor xmousefg, xmousebg;
  78. + XWindowAttributes attr;
  79. + XVisualInfo vis;
  80. if (!(xw.dpy = XOpenDisplay(NULL)))
  81. die("can't open display\n");
  82. xw.scr = XDefaultScreen(xw.dpy);
  83. - xw.vis = XDefaultVisual(xw.dpy, xw.scr);
  84. +
  85. + if (!(opt_embed && (parent = strtol(opt_embed, NULL, 0)))) {
  86. + parent = XRootWindow(xw.dpy, xw.scr);
  87. + xw.depth = 32;
  88. + } else {
  89. + XGetWindowAttributes(xw.dpy, parent, &attr);
  90. + xw.depth = attr.depth;
  91. + }
  92. +
  93. + XMatchVisualInfo(xw.dpy, xw.scr, xw.depth, TrueColor, &vis);
  94. + xw.vis = vis.visual;
  95. /* font */
  96. if (!FcInit())
  97. @@ -1132,7 +1153,7 @@ xinit(int cols, int rows)
  98. xloadfonts(usedfont, 0);
  99. /* colors */
  100. - xw.cmap = XDefaultColormap(xw.dpy, xw.scr);
  101. + xw.cmap = XCreateColormap(xw.dpy, parent, xw.vis, None);
  102. xloadcols();
  103. /* adjust fixed window geometry */
  104. @@ -1152,19 +1173,15 @@ xinit(int cols, int rows)
  105. | ButtonMotionMask | ButtonPressMask | ButtonReleaseMask;
  106. xw.attrs.colormap = xw.cmap;
  107. - if (!(opt_embed && (parent = strtol(opt_embed, NULL, 0))))
  108. - parent = XRootWindow(xw.dpy, xw.scr);
  109. xw.win = XCreateWindow(xw.dpy, parent, xw.l, xw.t,
  110. - win.w, win.h, 0, XDefaultDepth(xw.dpy, xw.scr), InputOutput,
  111. + win.w, win.h, 0, xw.depth, InputOutput,
  112. xw.vis, CWBackPixel | CWBorderPixel | CWBitGravity
  113. | CWEventMask | CWColormap, &xw.attrs);
  114. memset(&gcvalues, 0, sizeof(gcvalues));
  115. gcvalues.graphics_exposures = False;
  116. - dc.gc = XCreateGC(xw.dpy, parent, GCGraphicsExposures,
  117. - &gcvalues);
  118. - xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h,
  119. - DefaultDepth(xw.dpy, xw.scr));
  120. + xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h, xw.depth);
  121. + dc.gc = XCreateGC(xw.dpy, xw.buf, GCGraphicsExposures, &gcvalues);
  122. XSetForeground(xw.dpy, dc.gc, dc.col[defaultbg].pixel);
  123. XFillRectangle(xw.dpy, xw.buf, dc.gc, 0, 0, win.w, win.h);
  124. @@ -2019,6 +2036,9 @@ main(int argc, char *argv[])
  125. case 'a':
  126. allowaltscreen = 0;
  127. break;
  128. + case 'A':
  129. + opt_alpha = EARGF(usage());
  130. + break;
  131. case 'c':
  132. opt_class = EARGF(usage());
  133. break;