My build of the simple terminal from suckless.org.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 

168 lignes
4.3 KiB

  1. From 3307b33b60adb4e1b5db4dd9849c78fce72b6ca4 Mon Sep 17 00:00:00 2001
  2. From: Julius Huelsmann <juliusHuelsmann@gmail.com>
  3. Date: Fri, 31 Jul 2020 10:13:30 +0200
  4. Subject: [PATCH] patch: focus
  5. ---
  6. config.def.h | 5 +++--
  7. st.c | 1 -
  8. st.h | 3 ++-
  9. x.c | 44 ++++++++++++++++++++++++++++++--------------
  10. 4 files changed, 35 insertions(+), 18 deletions(-)
  11. diff --git a/config.def.h b/config.def.h
  12. index b94b23c..577d1f1 100644
  13. --- a/config.def.h
  14. +++ b/config.def.h
  15. @@ -85,7 +85,7 @@ char *termname = "st-256color";
  16. unsigned int tabspaces = 8;
  17. /* bg opacity */
  18. -float alpha = 0.8;
  19. +float alpha = 0.8, alphaUnfocused = 0.6;
  20. /* Terminal colors (16 first used in escape sequence) */
  21. static const char *colorname[] = {
  22. @@ -123,9 +123,10 @@ static const char *colorname[] = {
  23. * foreground, background, cursor, reverse cursor
  24. */
  25. unsigned int defaultfg = 7;
  26. -unsigned int defaultbg = 258;
  27. +unsigned int defaultbg = 0;
  28. static unsigned int defaultcs = 256;
  29. static unsigned int defaultrcs = 257;
  30. +unsigned int bg = 17, bgUnfocused = 16;
  31. /*
  32. * Default shape of cursor
  33. diff --git a/st.c b/st.c
  34. index 0ce6ac2..c7f40c8 100644
  35. --- a/st.c
  36. +++ b/st.c
  37. @@ -194,7 +194,6 @@ static void tsetscroll(int, int);
  38. static void tswapscreen(void);
  39. static void tsetmode(int, int, int *, int);
  40. static int twrite(const char *, int, int);
  41. -static void tfulldirt(void);
  42. static void tcontrolcode(uchar );
  43. static void tdectest(char );
  44. static void tdefutf8(char);
  45. diff --git a/st.h b/st.h
  46. index 2c656af..44cb3fd 100644
  47. --- a/st.h
  48. +++ b/st.h
  49. @@ -79,6 +79,7 @@ typedef union {
  50. void die(const char *, ...);
  51. void redraw(void);
  52. +void tfulldirt(void);
  53. void draw(void);
  54. void printscreen(const Arg *);
  55. @@ -122,4 +123,4 @@ extern char *termname;
  56. extern unsigned int tabspaces;
  57. extern unsigned int defaultfg;
  58. extern unsigned int defaultbg;
  59. -extern float alpha;
  60. +extern float alpha, alphaUnfocused;
  61. diff --git a/x.c b/x.c
  62. index 50da23c..a2e820f 100644
  63. --- a/x.c
  64. +++ b/x.c
  65. @@ -254,6 +254,8 @@ static char *opt_line = NULL;
  66. static char *opt_name = NULL;
  67. static char *opt_title = NULL;
  68. +static int focused = 0;
  69. +
  70. static int oldbutton = 3; /* button event on startup: 3 = release */
  71. void
  72. @@ -774,35 +776,38 @@ xloadcolor(int i, const char *name, Color *ncolor)
  73. return XftColorAllocName(xw.dpy, xw.vis, xw.cmap, name, ncolor);
  74. }
  75. +void
  76. +xloadalpha(void)
  77. +{
  78. + float const usedAlpha = focused ? alpha : alphaUnfocused;
  79. + if (opt_alpha) alpha = strtof(opt_alpha, NULL);
  80. + dc.col[defaultbg].color.alpha = (unsigned short)(0xffff * usedAlpha);
  81. + dc.col[defaultbg].pixel &= 0x00FFFFFF;
  82. + dc.col[defaultbg].pixel |= (unsigned char)(0xff * usedAlpha) << 24;
  83. +}
  84. +
  85. void
  86. xloadcols(void)
  87. {
  88. - int i;
  89. static int loaded;
  90. Color *cp;
  91. - if (loaded) {
  92. - for (cp = dc.col; cp < &dc.col[dc.collen]; ++cp)
  93. - XftColorFree(xw.dpy, xw.vis, xw.cmap, cp);
  94. - } else {
  95. - dc.collen = MAX(LEN(colorname), 256);
  96. - dc.col = xmalloc(dc.collen * sizeof(Color));
  97. + if (!loaded) {
  98. + dc.collen = 1 + (defaultbg = MAX(LEN(colorname), 256));
  99. + dc.col = xmalloc((dc.collen) * sizeof(Color));
  100. }
  101. - for (i = 0; i < dc.collen; i++)
  102. + for (int i = 0; i+1 < dc.collen; ++i)
  103. if (!xloadcolor(i, NULL, &dc.col[i])) {
  104. if (colorname[i])
  105. die("could not allocate color '%s'\n", colorname[i]);
  106. else
  107. die("could not allocate color %d\n", i);
  108. }
  109. + if (dc.collen) // cannot die, as the color is already loaded.
  110. + xloadcolor(focused ?bg :bgUnfocused, NULL, &dc.col[defaultbg]);
  111. - /* set alpha value of bg color */
  112. - if (opt_alpha)
  113. - alpha = strtof(opt_alpha, NULL);
  114. - dc.col[defaultbg].color.alpha = (unsigned short)(0xffff * alpha);
  115. - dc.col[defaultbg].pixel &= 0x00FFFFFF;
  116. - dc.col[defaultbg].pixel |= (unsigned char)(0xff * alpha) << 24;
  117. + xloadalpha();
  118. loaded = 1;
  119. }
  120. @@ -1747,12 +1752,22 @@ focus(XEvent *ev)
  121. xseturgency(0);
  122. if (IS_SET(MODE_FOCUS))
  123. ttywrite("\033[I", 3, 0);
  124. + if (!focused) {
  125. + focused = 1;
  126. + xloadcols();
  127. + tfulldirt();
  128. + }
  129. } else {
  130. if (xw.ime.xic)
  131. XUnsetICFocus(xw.ime.xic);
  132. win.mode &= ~MODE_FOCUSED;
  133. if (IS_SET(MODE_FOCUS))
  134. ttywrite("\033[O", 3, 0);
  135. + if (focused) {
  136. + focused = 0;
  137. + xloadcols();
  138. + tfulldirt();
  139. + }
  140. }
  141. }
  142. @@ -2065,6 +2080,7 @@ run:
  143. XSetLocaleModifiers("");
  144. cols = MAX(cols, 1);
  145. rows = MAX(rows, 1);
  146. + defaultbg = MAX(LEN(colorname), 256);
  147. tnew(cols, rows);
  148. xinit(cols, rows);
  149. xsetenv();
  150. --
  151. 2.28.0