st

Personal fork of the suckless terminal.
git clone git://git.zepp.club/st.git
Log | Files | Refs | README | LICENSE

commit 6094adda79a5fe6aec059cec1fce2159c419b96e
parent c8ae1a1143ce0321bf2a1dc78d3dec8e79aa311e
Author: Anjeel <xein@zepp.club>
Date:   Sun,  7 Jul 2024 05:04:44 -0300

patch: anygeometry

Diffstat:
Mconfig.def.h | 13+++++++++++++
Mx.c | 36++++++++++++++++++++++++++++++++----
2 files changed, 45 insertions(+), 4 deletions(-)

diff --git a/config.def.h b/config.def.h @@ -142,6 +142,12 @@ static unsigned int defaultrcs = 256; static unsigned int cursorshape = 2; /* + * Whether to use pixel geometry or cell geometry + */ + +static Geometry geometry = CellGeometry; + +/* * Default columns and rows numbers */ @@ -149,6 +155,13 @@ static unsigned int cols = 80; static unsigned int rows = 24; /* + * Default width and height (including borders!) + */ + +static unsigned int width = 564; +static unsigned int height = 364; + +/* * Default colour and shape of the mouse cursor */ static unsigned int mouseshape = XC_xterm; diff --git a/x.c b/x.c @@ -45,6 +45,11 @@ typedef struct { signed char appcursor; /* application cursor */ } Key; +typedef enum { + PixelGeometry, + CellGeometry +} Geometry; + /* X modifiers */ #define XK_ANY_MOD UINT_MAX #define XK_NO_MOD 0 @@ -1137,7 +1142,7 @@ xicdestroy(XIC xim, XPointer client, XPointer call) } void -xinit(int cols, int rows) +xinit(int w, int h) { XGCValues gcvalues; Cursor cursor; @@ -1162,8 +1167,16 @@ xinit(int cols, int rows) xloadcols(); /* adjust fixed window geometry */ - win.w = 2 * borderpx + cols * win.cw; - win.h = 2 * borderpx + rows * win.ch; + switch (geometry) { + case CellGeometry: + win.w = 2 * borderpx + w * win.cw; + win.h = 2 * borderpx + h * win.ch; + break; + case PixelGeometry: + win.w = w; + win.h = h; + break; + } if (xw.gm & XNegative) xw.l += DisplayWidth(xw.dpy, xw.scr) - win.w - 2; if (xw.gm & YNegative) @@ -2078,6 +2091,12 @@ main(int argc, char *argv[]) case 'g': xw.gm = XParseGeometry(EARGF(usage()), &xw.l, &xw.t, &cols, &rows); + geometry = CellGeometry; + break; + case 'G': + xw.gm = XParseGeometry(EARGF(usage()), + &xw.l, &xw.t, &width, &height); + geometry = PixelGeometry; break; case 'i': xw.isfixed = 1; @@ -2114,10 +2133,19 @@ run: setlocale(LC_CTYPE, ""); XSetLocaleModifiers(""); + switch (geometry) { + case CellGeometry: + xinit(cols, rows); + break; + case PixelGeometry: + xinit(width, height); + cols = (win.w - 2 * borderpx) / win.cw; + rows = (win.h - 2 * borderpx) / win.ch; + break; + } cols = MAX(cols, 1); rows = MAX(rows, 1); tnew(cols, rows); - xinit(cols, rows); xsetenv(); selinit(); run();