Support correct geometric placement, independent of the font size

This commit is contained in:
c0dev0id 2026-03-23 19:43:58 +01:00
parent 64358a4a80
commit 980fa44c50
7 changed files with 169 additions and 1 deletions

View File

@ -3,7 +3,7 @@ COMMENT= simple X terminal (personalized)
V= 0.9.2
DISTNAME= st-${V}
PKGNAME= st-sdk-${V}
REVISION= 34
REVISION= 36
DIST_SUBDIR= st
SUPDISTFILES.p= scrollback/st-scrollback-0.9.2.diff \

View File

@ -372,6 +372,7 @@ static Key key[] = {
{ XK_Right, XK_ANY_MOD, "\033OC", 0, +1},
{ XK_ISO_Left_Tab, ShiftMask, "\033[Z", 0, 0},
{ XK_Return, Mod1Mask, "\033\r", 0, 0},
{ XK_Return, ShiftMask, "\033[13;2u", 0, 0},
{ XK_Return, XK_ANY_MOD, "\r", 0, 0},
{ XK_Insert, ShiftMask, "\033[4l", -1, 0},
{ XK_Insert, ShiftMask, "\033[2;2~", +1, 0},

View File

@ -0,0 +1,69 @@
--- x.c.orig Fri Mar 13 08:07:14 2026
+++ x.c Fri Mar 13 08:10:58 2026
@@ -251,6 +251,7 @@
static char *opt_line = NULL;
static char *opt_name = NULL;
static char *opt_title = NULL;
+static int opt_pixelgeom = 0;
static uint buttons; /* bit field of pressed buttons */
@@ -1147,6 +1148,15 @@
usedfont = (opt_font == NULL)? font : opt_font;
xloadfonts(usedfont, 0);
+ /* -p: convert stashed pixel dimensions to cols/rows */
+ if (opt_pixelgeom && win.w > 0 && win.h > 0) {
+ cols = MAX(1, (win.w - 2 * borderpx) / win.cw);
+ rows = MAX(1, (win.h - 2 * borderpx) / win.ch);
+ tresize(cols, rows);
+ win.w = 2 * borderpx + cols * win.cw;
+ win.h = 2 * borderpx + rows * win.ch;
+ }
+
/* colors */
xw.cmap = XDefaultColormap(xw.dpy, xw.scr);
xloadcols();
@@ -2026,11 +2036,11 @@
void
usage(void)
{
- die("usage: %s [-aiv] [-c class] [-f font] [-g geometry]"
+ die("usage: %s [-aipv] [-c class] [-f font] [-g geometry]"
" [-n name] [-o file]\n"
" [-T title] [-t title] [-w windowid]"
" [[-e] command [args ...]]\n"
- " %s [-aiv] [-c class] [-f font] [-g geometry]"
+ " %s [-aipv] [-c class] [-f font] [-g geometry]"
" [-n name] [-o file]\n"
" [-T title] [-t title] [-w windowid] -l line"
" [stty_args ...]\n", argv0, argv0);
@@ -2061,6 +2071,9 @@
xw.gm = XParseGeometry(EARGF(usage()),
&xw.l, &xw.t, &cols, &rows);
break;
+ case 'p':
+ opt_pixelgeom = 1;
+ break;
case 'i':
xw.isfixed = 1;
break;
@@ -2096,6 +2109,18 @@
setlocale(LC_CTYPE, "");
XSetLocaleModifiers("");
+ if (opt_pixelgeom && cols > 0 && rows > 0) {
+ /*
+ * -p: cols/rows from -g are pixel dimensions.
+ * Stash them in win.w/win.h; use default 80x24
+ * for the initial tnew() allocation. xinit() will
+ * compute the real cols/rows after font loading.
+ */
+ win.w = cols;
+ win.h = rows;
+ cols = 80;
+ rows = 24;
+ }
cols = MAX(cols, 1);
rows = MAX(rows, 1);
tnew(cols, rows);

View File

@ -10,3 +10,11 @@ Index: config.def.h
/* 8 bright colors */
"gray50",
@@ -341,6 +341,7 @@ static Key key[] = {
{ XK_ISO_Left_Tab, ShiftMask, "\033[Z", 0, 0},
{ XK_Return, Mod1Mask, "\033\r", 0, 0},
{ XK_Return, XK_ANY_MOD, "\r", 0, 0},
+ { XK_Return, ShiftMask, "\033[13;2u", 0, 0, 0},
{ XK_Insert, ShiftMask, "\033[4l", -1, 0},
{ XK_Insert, ShiftMask, "\033[2;2~", +1, 0},
{ XK_Insert, ControlMask, "\033[L", -1, 0},

View File

@ -0,0 +1,20 @@
Index: config.def.h
--- config.def.h.orig
+++ config.def.h
@@ -106,7 +106,7 @@ static const char *colorname[] = {
"blue2",
"magenta3",
"cyan3",
- "gray90",
+ "gray",
/* 8 bright colors */
"gray50",
@@ -341,6 +341,7 @@ static Key key[] = {
{ XK_ISO_Left_Tab, ShiftMask, "\033[Z", 0, 0},
{ XK_Return, Mod1Mask, "\033\r", 0, 0},
{ XK_Return, XK_ANY_MOD, "\r", 0, 0},
+ { XK_Return, ShiftMask, "\033[13;2u", 0, 0},
{ XK_Insert, ShiftMask, "\033[4l", -1, 0},
{ XK_Insert, ShiftMask, "\033[2;2~", +1, 0},
{ XK_Insert, ControlMask, "\033[L", -1, 0},

View File

@ -0,0 +1,36 @@
Index: config.mk
--- config.mk.orig
+++ config.mk
@@ -15,10 +15,12 @@ PKG_CONFIG = pkg-config
# includes and libs
INCS = -I$(X11INC) \
`$(PKG_CONFIG) --cflags fontconfig` \
- `$(PKG_CONFIG) --cflags freetype2`
+ `$(PKG_CONFIG) --cflags freetype2` \
+ `$(PKG_CONFIG) --libs harfbuzz`
LIBS = -L$(X11LIB) -lm -lrt -lX11 -lutil -lXft -lXrender\
`$(PKG_CONFIG) --libs fontconfig` \
- `$(PKG_CONFIG) --libs freetype2`
+ `$(PKG_CONFIG) --libs freetype2` \
+ `$(PKG_CONFIG) --libs harfbuzz`
# flags
STCPPFLAGS = -DVERSION=\"$(VERSION)\" -D_XOPEN_SOURCE=600
@@ -26,11 +28,12 @@ STCFLAGS = $(INCS) $(STCPPFLAGS) $(CPPFLAGS) $(CFLAGS)
STLDFLAGS = $(LIBS) $(LDFLAGS)
# OpenBSD:
-#CPPFLAGS = -DVERSION=\"$(VERSION)\" -D_XOPEN_SOURCE=600 -D_BSD_SOURCE
-#LIBS = -L$(X11LIB) -lm -lX11 -lutil -lXft \
-# `$(PKG_CONFIG) --libs fontconfig` \
-# `$(PKG_CONFIG) --libs freetype2`
-#MANPREFIX = ${PREFIX}/man
+CPPFLAGS = -DVERSION=\"$(VERSION)\" -D_XOPEN_SOURCE=600 -D_BSD_SOURCE
+LIBS = -L$(X11LIB) -lm -lX11 -lutil -lXft \
+ `$(PKG_CONFIG) --libs fontconfig` \
+ `$(PKG_CONFIG) --libs freetype2` \
+ `$(PKG_CONFIG) --libs harfbuzz`
+MANPREFIX = ${PREFIX}/man
# compiler and linker
# CC = c99

View File

@ -0,0 +1,34 @@
Index: st.c
--- st.c.orig
+++ st.c
@@ -35,6 +35,7 @@
#define ESC_ARG_SIZ 16
#define STR_BUF_SIZ ESC_BUF_SIZ
#define STR_ARG_SIZ ESC_ARG_SIZ
+#define STR_BUF_MAX (256*1024)
#define HISTSIZE 2000
#define RESIZEBUFFER 1000
@@ -2025,7 +2026,8 @@ csihandle(void)
case 6: /* Report Cursor Position (CPR) "<row>;<column>R" */
n = snprintf(buf, sizeof(buf), "\033[%i;%iR",
term.c.y+1, term.c.x+1);
- ttywrite(buf, n, 0);
+ if (n > 0)
+ ttywrite(buf, n, 0);
break;
default:
goto unknown;
@@ -2645,8 +2647,11 @@ tputc(Rune u)
* term.esc = 0;
* strhandle();
*/
- if (strescseq.siz > (SIZE_MAX - UTF_SIZ) / 2)
+ if (strescseq.siz > (SIZE_MAX - UTF_SIZ) / 2 ||
+ strescseq.siz >= STR_BUF_MAX) {
+ strreset();
return;
+ }
strescseq.siz *= 2;
strescseq.buf = xrealloc(strescseq.buf, strescseq.siz);
}