st-anysize-20220718-baa9357.diff 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. From 8dcdc4b21a73268e167d98aa30f24315c7f3b7ff Mon Sep 17 00:00:00 2001
  2. From: Bakkeby <bakkeby@gmail.com>
  3. Date: Mon, 18 Jul 2022 16:52:03 +0200
  4. Subject: [PATCH] Adding anysize patch
  5. ---
  6. x.c | 56 ++++++++++++++++++++++++++++++--------------------------
  7. 1 file changed, 30 insertions(+), 26 deletions(-)
  8. diff --git a/x.c b/x.c
  9. index 2a3bd38..f534347 100644
  10. --- a/x.c
  11. +++ b/x.c
  12. @@ -81,6 +81,7 @@ typedef XftGlyphFontSpec GlyphFontSpec;
  13. typedef struct {
  14. int tw, th; /* tty width and height */
  15. int w, h; /* window width and height */
  16. + int hborderpx, vborderpx;
  17. int ch; /* char height */
  18. int cw; /* char width */
  19. int mode; /* window state/mode flags */
  20. @@ -331,7 +332,7 @@ ttysend(const Arg *arg)
  21. int
  22. evcol(XEvent *e)
  23. {
  24. - int x = e->xbutton.x - borderpx;
  25. + int x = e->xbutton.x - win.hborderpx;
  26. LIMIT(x, 0, win.tw - 1);
  27. return x / win.cw;
  28. }
  29. @@ -339,7 +340,7 @@ evcol(XEvent *e)
  30. int
  31. evrow(XEvent *e)
  32. {
  33. - int y = e->xbutton.y - borderpx;
  34. + int y = e->xbutton.y - win.vborderpx;
  35. LIMIT(y, 0, win.th - 1);
  36. return y / win.ch;
  37. }
  38. @@ -739,6 +740,9 @@ cresize(int width, int height)
  39. col = MAX(1, col);
  40. row = MAX(1, row);
  41. + win.hborderpx = (win.w - col * win.cw) / 2;
  42. + win.vborderpx = (win.h - row * win.ch) / 2;
  43. +
  44. tresize(col, row);
  45. xresize(col, row);
  46. ttyresize(win.tw, win.th);
  47. @@ -869,8 +873,8 @@ xhints(void)
  48. sizeh->flags = PSize | PResizeInc | PBaseSize | PMinSize;
  49. sizeh->height = win.h;
  50. sizeh->width = win.w;
  51. - sizeh->height_inc = win.ch;
  52. - sizeh->width_inc = win.cw;
  53. + sizeh->height_inc = 1;
  54. + sizeh->width_inc = 1;
  55. sizeh->base_height = 2 * borderpx;
  56. sizeh->base_width = 2 * borderpx;
  57. sizeh->min_height = win.ch + 2 * borderpx;
  58. @@ -1152,8 +1156,8 @@ xinit(int cols, int rows)
  59. xloadcols();
  60. /* adjust fixed window geometry */
  61. - win.w = 2 * borderpx + cols * win.cw;
  62. - win.h = 2 * borderpx + rows * win.ch;
  63. + win.w = 2 * win.hborderpx + 2 * borderpx + cols * win.cw;
  64. + win.h = 2 * win.vborderpx + 2 * borderpx + rows * win.ch;
  65. if (xw.gm & XNegative)
  66. xw.l += DisplayWidth(xw.dpy, xw.scr) - win.w - 2;
  67. if (xw.gm & YNegative)
  68. @@ -1242,7 +1246,7 @@ xinit(int cols, int rows)
  69. int
  70. xmakeglyphfontspecs(XftGlyphFontSpec *specs, const Glyph *glyphs, int len, int x, int y)
  71. {
  72. - float winx = borderpx + x * win.cw, winy = borderpx + y * win.ch, xp, yp;
  73. + float winx = win.hborderpx + x * win.cw, winy = win.vborderpx + y * win.ch, xp, yp;
  74. ushort mode, prevmode = USHRT_MAX;
  75. Font *font = &dc.font;
  76. int frcflags = FRC_NORMAL;
  77. @@ -1375,7 +1379,7 @@ void
  78. xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, int y)
  79. {
  80. int charlen = len * ((base.mode & ATTR_WIDE) ? 2 : 1);
  81. - int winx = borderpx + x * win.cw, winy = borderpx + y * win.ch,
  82. + int winx = win.hborderpx + x * win.cw, winy = win.vborderpx + y * win.ch,
  83. width = charlen * win.cw;
  84. Color *fg, *bg, *temp, revfg, revbg, truefg, truebg;
  85. XRenderColor colfg, colbg;
  86. @@ -1465,17 +1469,17 @@ xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, i
  87. /* Intelligent cleaning up of the borders. */
  88. if (x == 0) {
  89. - xclear(0, (y == 0)? 0 : winy, borderpx,
  90. + xclear(0, (y == 0)? 0 : winy, win.hborderpx,
  91. winy + win.ch +
  92. - ((winy + win.ch >= borderpx + win.th)? win.h : 0));
  93. + ((winy + win.ch >= win.vborderpx + win.th)? win.h : 0));
  94. }
  95. - if (winx + width >= borderpx + win.tw) {
  96. + if (winx + width >= win.hborderpx + win.tw) {
  97. xclear(winx + width, (y == 0)? 0 : winy, win.w,
  98. - ((winy + win.ch >= borderpx + win.th)? win.h : (winy + win.ch)));
  99. + ((winy + win.ch >= win.vborderpx + win.th)? win.h : (winy + win.ch)));
  100. }
  101. if (y == 0)
  102. - xclear(winx, 0, winx + width, borderpx);
  103. - if (winy + win.ch >= borderpx + win.th)
  104. + xclear(winx, 0, winx + width, win.vborderpx);
  105. + if (winy + win.ch >= win.vborderpx + win.th)
  106. xclear(winx, winy + win.ch, winx + width, win.h);
  107. /* Clean up the region we want to draw to. */
  108. @@ -1569,35 +1573,35 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og)
  109. case 3: /* Blinking Underline */
  110. case 4: /* Steady Underline */
  111. XftDrawRect(xw.draw, &drawcol,
  112. - borderpx + cx * win.cw,
  113. - borderpx + (cy + 1) * win.ch - \
  114. + win.hborderpx + cx * win.cw,
  115. + win.vborderpx + (cy + 1) * win.ch - \
  116. cursorthickness,
  117. win.cw, cursorthickness);
  118. break;
  119. case 5: /* Blinking bar */
  120. case 6: /* Steady bar */
  121. XftDrawRect(xw.draw, &drawcol,
  122. - borderpx + cx * win.cw,
  123. - borderpx + cy * win.ch,
  124. + win.hborderpx + cx * win.cw,
  125. + win.vborderpx + cy * win.ch,
  126. cursorthickness, win.ch);
  127. break;
  128. }
  129. } else {
  130. XftDrawRect(xw.draw, &drawcol,
  131. - borderpx + cx * win.cw,
  132. - borderpx + cy * win.ch,
  133. + win.hborderpx + cx * win.cw,
  134. + win.vborderpx + cy * win.ch,
  135. win.cw - 1, 1);
  136. XftDrawRect(xw.draw, &drawcol,
  137. - borderpx + cx * win.cw,
  138. - borderpx + cy * win.ch,
  139. + win.hborderpx + cx * win.cw,
  140. + win.vborderpx + cy * win.ch,
  141. 1, win.ch - 1);
  142. XftDrawRect(xw.draw, &drawcol,
  143. - borderpx + (cx + 1) * win.cw - 1,
  144. - borderpx + cy * win.ch,
  145. + win.hborderpx + (cx + 1) * win.cw - 1,
  146. + win.vborderpx + cy * win.ch,
  147. 1, win.ch - 1);
  148. XftDrawRect(xw.draw, &drawcol,
  149. - borderpx + cx * win.cw,
  150. - borderpx + (cy + 1) * win.ch - 1,
  151. + win.hborderpx + cx * win.cw,
  152. + win.vborderpx + (cy + 1) * win.ch - 1,
  153. win.cw, 1);
  154. }
  155. }
  156. --
  157. 2.37.1