sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

st-anysize-20220718-baa9357.diff (5373B)


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