Hello everyone,

First of all, thanks a lot for dwm and st, big fan!

I wrote a patch -- intended for the optional patches section on the site --
that makes st resizable to the pixel, as opposed to the nearest char
width/height. This is to avoid the gaps between and around terminals in
tiling WMs.

The patch uses borderpx from config.h as the minimum border, and
dynamically calculates the actual border sizes in cresize(), based on the
window size given to us. Since this is now dynamic information, I store it
in the Term struct. Contents appear centered in st windows, with
independent horizontal and vertical border sizes.

The patch is based on the 0.5 stable release. I've been using it for a bit
on dwm, and couldn't manage to break it. This is my first time
contributing, so please let me know if this will explode st, goes way
against philosophy, or if the style is horribly off.

Thanks!
Augusto Born de Oliveira
Author: Augusto Born de Oliveira <augustob...@gmail.com>
Makes st respect pixel-resolution hints, makes border dynamic (and independent for x and y), bordepx becomes the minimum border.

--- a/st.c	2014-04-05 14:40:11.000000000 -0400
+++ b/st.c	2014-11-02 15:58:44.651354017 -0500
@@ -221,6 +221,8 @@
 typedef struct {
 	int row;      /* nb row */
 	int col;      /* nb col */
+       int hborderpx;      /* horiz border */
+	int vborderpx;      /* vert border */
 	Line *line;   /* screen */
 	Line *alt;    /* alternate screen */
 	bool *dirty;  /* dirtyness of lines */
@@ -636,7 +638,7 @@
 
 static int
 x2col(int x) {
-	x -= borderpx;
+	x -= term.hborderpx;
 	x /= xw.cw;
 
 	return LIMIT(x, 0, term.col-1);
@@ -644,7 +646,7 @@
 
 static int
 y2row(int y) {
-	y -= borderpx;
+	y -= term.vborderpx;
 	y /= xw.ch;
 
 	return LIMIT(y, 0, term.row-1);
@@ -2799,8 +2801,8 @@
 xtermclear(int col1, int row1, int col2, int row2) {
 	XftDrawRect(xw.draw,
 			&dc.col[IS_SET(MODE_REVERSE) ? defaultfg : defaultbg],
-			borderpx + col1 * xw.cw,
-			borderpx + row1 * xw.ch,
+			term.hborderpx + col1 * xw.cw,
+			term.vborderpx + row1 * xw.ch,
 			(col2-col1+1) * xw.cw,
 			(row2-row1+1) * xw.ch);
 }
@@ -2826,10 +2828,10 @@
 		sizeh->flags = PSize | PResizeInc | PBaseSize;
 		sizeh->height = xw.h;
 		sizeh->width = xw.w;
-		sizeh->height_inc = xw.ch;
-		sizeh->width_inc = xw.cw;
-		sizeh->base_height = 2 * borderpx;
-		sizeh->base_width = 2 * borderpx;
+		sizeh->height_inc = 1;
+		sizeh->width_inc = 1; 
+		sizeh->base_height = 2 * term.vborderpx;
+		sizeh->base_width = 2 * term.hborderpx;
 	} else {
 		sizeh->flags = PMaxSize | PMinSize;
 		sizeh->min_width = sizeh->max_width = xw.fw;
@@ -3018,8 +3020,8 @@
 		xw.w = xw.fw;
 	} else {
 		/* window - default size */
-		xw.h = 2 * borderpx + term.row * xw.ch;
-		xw.w = 2 * borderpx + term.col * xw.cw;
+		xw.h = 2 * term.vborderpx + term.row * xw.ch;
+		xw.w = 2 * term.hborderpx + term.col * xw.cw;
 		xw.fx = 0;
 		xw.fy = 0;
 	}
@@ -3094,7 +3096,7 @@
 
 void
 xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
-	int winx = borderpx + x * xw.cw, winy = borderpx + y * xw.ch,
+	int winx = term.hborderpx + x * xw.cw, winy = term.vborderpx + y * xw.ch,
 	    width = charlen * xw.cw, xp, i;
 	int frcflags;
 	int u8fl, u8fblen, u8cblen, doesexist;
@@ -3207,7 +3209,7 @@
 
 	/* Intelligent cleaning up of the borders. */
 	if(x == 0) {
-		xclear(0, (y == 0)? 0 : winy, borderpx,
+		xclear(0, (y == 0)? 0 : winy, term.vborderpx,
 			winy + xw.ch + ((y >= term.row-1)? xw.h : 0));
 	}
 	if(x + charlen >= term.col) {
@@ -3215,7 +3217,7 @@
 			((y >= term.row-1)? xw.h : (winy + xw.ch)));
 	}
 	if(y == 0)
-		xclear(winx, 0, winx + width, borderpx);
+		xclear(winx, 0, winx + width, term.hborderpx);
 	if(y == term.row-1)
 		xclear(winx, winy + xw.ch, winx + width, xw.h);
 
@@ -3399,20 +3401,20 @@
 			xdraws(g.c, g, term.c.x, term.c.y, width, sl);
 		} else {
 			XftDrawRect(xw.draw, &dc.col[defaultcs],
-					borderpx + curx * xw.cw,
-					borderpx + term.c.y * xw.ch,
+					term.hborderpx + curx * xw.cw,
+					term.vborderpx + term.c.y * xw.ch,
 					xw.cw - 1, 1);
 			XftDrawRect(xw.draw, &dc.col[defaultcs],
-					borderpx + curx * xw.cw,
-					borderpx + term.c.y * xw.ch,
+					term.hborderpx + curx * xw.cw,
+					term.vborderpx + term.c.y * xw.ch,
 					1, xw.ch - 1);
 			XftDrawRect(xw.draw, &dc.col[defaultcs],
-					borderpx + (curx + 1) * xw.cw - 1,
-					borderpx + term.c.y * xw.ch,
+					term.hborderpx + (curx + 1) * xw.cw - 1,
+					term.vborderpx + term.c.y * xw.ch,
 					1, xw.ch - 1);
 			XftDrawRect(xw.draw, &dc.col[defaultcs],
-					borderpx + curx * xw.cw,
-					borderpx + (term.c.y + 1) * xw.ch - 1,
+					term.hborderpx + curx * xw.cw,
+					term.vborderpx + (term.c.y + 1) * xw.ch - 1,
 					xw.cw, 1);
 		}
 		oldx = curx, oldy = term.c.y;
@@ -3699,6 +3701,9 @@
 	col = (xw.w - 2 * borderpx) / xw.cw;
 	row = (xw.h - 2 * borderpx) / xw.ch;
 
+        term.hborderpx = (xw.w - (col * xw.cw)) / 2;
+        term.vborderpx = (xw.h - (row * xw.ch)) / 2;
+
 	tresize(col, row);
 	xresize(col, row);
 	ttyresize();

Reply via email to