Adding the anygeometry patch ref. #137

This commit is contained in:
Bakkeby 2024-05-31 22:47:52 +02:00
parent aa5957495d
commit 8aee31444a
4 changed files with 75 additions and 2 deletions

View File

@ -15,6 +15,8 @@ Refer to [https://st.suckless.org/](https://st.suckless.org/) for details on the
### Changelog:
2024-05-31 - Added the anygeometry patch
2024-03-13 - Added the reflow patch and upgraded the netwmicon patch
2024-03-07 - Improved sixel support, removed VIM browse patch
@ -102,6 +104,10 @@ Refer to [https://st.suckless.org/](https://st.suckless.org/) for details on the
- allows the user to specify two distinct opacity values or background colors in order to
easily differentiate between focused and unfocused terminal windows
- [anygeometry](https://st.suckless.org/patches/anygeometry/)
- allows st to start at any pixel size using the \-G command line option (if floating)
- can be combined with the anysize patch to resize to any pixel size
- [anysize](https://st.suckless.org/patches/anysize/)
- allows st to reize to any pixel size rather than snapping to character width / height

View File

@ -267,6 +267,16 @@ static unsigned int cursorshape = 2;
static unsigned int cols = 80;
static unsigned int rows = 24;
#if ANYGEOMETRY_PATCH
/*
* Whether to use pixel geometry or cell geometry
*/
static Geometry geometry = CellGeometry; // or PixelGeometry to use the below size
static unsigned int width = 564;
static unsigned int height = 364;
#endif // ANYGEOMETRY_PATCH
#if THEMED_CURSOR_PATCH
/*
* Default shape of the mouse cursor

View File

@ -29,6 +29,13 @@
*/
#define ALPHA_GRADIENT_PATCH 0
/* Allows for the initial size of the terminal to be specified as pixel width and height
* using the -G command line option. Can be combined with the anysize patch to also allow
* the window to be resized to any pixel size.
* https://st.suckless.org/patches/anygeometry/
*/
#define ANYGEOMETRY_PATCH 0
/* This patch allows st to resize to any pixel size rather than snapping to character width/height.
* https://st.suckless.org/patches/anysize/
*/

52
x.c
View File

@ -42,6 +42,13 @@ enum undercurl_slope_type {
};
#endif // UNDERCURL_PATCH
#if ANYGEOMETRY_PATCH
typedef enum {
PixelGeometry,
CellGeometry
} Geometry;
#endif // ANYGEOMETRY_PATCH
/* X modifiers */
#define XK_ANY_MOD UINT_MAX
#define XK_NO_MOD 0
@ -1468,13 +1475,31 @@ xinit(int cols, int rows)
xloadcols();
/* adjust fixed window geometry */
#if ANYGEOMETRY_PATCH
switch (geometry) {
case CellGeometry:
#if ANYSIZE_PATCH
win.w = 2 * win.hborderpx + cols * win.cw;
win.h = 2 * win.vborderpx + rows * win.ch;
#else
win.w = 2 * borderpx + cols * win.cw;
win.h = 2 * borderpx + rows * win.ch;
#endif // ANYSIZE_PATCH
#endif // ANYGEOMETRY_PATCH | ANYSIZE_PATCH
break;
case PixelGeometry:
win.w = cols;
win.h = rows;
cols = (win.w - 2 * borderpx) / win.cw;
rows = (win.h - 2 * borderpx) / win.ch;
break;
}
#elif ANYSIZE_PATCH
win.w = 2 * win.hborderpx + cols * win.cw;
win.h = 2 * win.vborderpx + rows * win.ch;
#else
win.w = 2 * borderpx + cols * win.cw;
win.h = 2 * borderpx + rows * win.ch;
#endif // ANYGEOMETRY_PATCH | ANYSIZE_PATCH
if (xw.gm & XNegative)
xw.l += DisplayWidth(xw.dpy, xw.scr) - win.w - 2;
if (xw.gm & YNegative)
@ -3863,7 +3888,17 @@ main(int argc, char *argv[])
case 'g':
xw.gm = XParseGeometry(EARGF(usage()),
&xw.l, &xw.t, &cols, &rows);
#if ANYGEOMETRY_PATCH
geometry = CellGeometry;
#endif // ANYGEOMETRY_PATCH
break;
#if ANYGEOMETRY_PATCH
case 'G':
xw.gm = XParseGeometry(EARGF(usage()),
&xw.l, &xw.t, &width, &height);
geometry = PixelGeometry;
break;
#endif // ANYGEOMETRY_PATCH
case 'i':
xw.isfixed = 1;
break;
@ -3912,13 +3947,28 @@ run:
hbcreatebuffer();
#endif // LIGATURES_PATCH
#if ANYGEOMETRY_PATCH
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;
}
#endif // ANYGEOMETRY_PATCH
cols = MAX(cols, 1);
rows = MAX(rows, 1);
#if ALPHA_PATCH && ALPHA_FOCUS_HIGHLIGHT_PATCH
defaultbg = MAX(LEN(colorname), 256);
#endif // ALPHA_FOCUS_HIGHLIGHT_PATCH
tnew(cols, rows);
#if !ANYGEOMETRY_PATCH
xinit(cols, rows);
#endif // ANYGEOMETRY_PATCH
#if BACKGROUND_IMAGE_PATCH
bginit();
#endif // BACKGROUND_IMAGE_PATCH