Hi,
This patch (against tip) introduces an array of font names in the config
instead FONT and allows to cycle through them with Ctrl-PgUp at runtime.
I missed this feature a lot when light conditions and distance to
display change, often so with a notebook, even more when different
displays plugged. Of course, tmux helps -- kill, start new st, attach to
the right session --, but I like this approach more.
Someone might find it useful.
cheers,
--s_
diff -r ba208156a8af config.def.h
--- a/config.def.h Tue Oct 09 19:40:37 2012 +0200
+++ b/config.def.h Tue Oct 09 22:33:55 2012 +0200
@@ -1,5 +1,9 @@
-#define FONT "Liberation Mono:pixelsize=12:antialias=false:autohint=false"
+static char* fonts[] = {
+ "Liberation Mono:pixelsize=12:antialias=false:autohint=false",
+ "Liberation Mono:pixelsize=14:antialias=false:autohint=false",
+ "Liberation Mono:pixelsize=24:antialias=false:autohint=false"
+};
/* Space in pixels around the terminal buffer */
#define BORDER 2
diff -r ba208156a8af st.c
--- a/st.c Tue Oct 09 19:40:37 2012 +0200
+++ b/st.c Tue Oct 09 22:33:55 2012 +0200
@@ -73,6 +73,7 @@
#define Y2ROW(y) (((y) - BORDER)/xw.ch)
#define VT102ID "\033[?6c"
+#define FONT fonts[currfont]
enum glyph_attribute {
ATTR_NULL = 0,
@@ -335,6 +336,8 @@
static void selpaste(void);
static void selscroll(int, int);
+static void togglefont(void);
+
static int utf8decode(char *, long *);
static int utf8encode(long *, char *);
static int utf8size(char *);
@@ -378,6 +381,7 @@
static char *opt_embed = NULL;
static char *opt_class = NULL;
static char *opt_font = NULL;
+static unsigned int currfont = 0;
void *
xmalloc(size_t len) {
@@ -2566,6 +2570,20 @@
}
void
+togglefont(){
+ int col, row;
+
+ currfont = (++currfont) % LEN(fonts);
+ initfonts(FONT);
+ col = (xw.w - 2*BORDER) / xw.cw;
+ row = (xw.h - 2*BORDER) / xw.ch;
+ tresize(col, row);
+ xresize(col, row);
+ ttyresize();
+ draw();
+}
+
+void
kpress(XEvent *ev) {
XKeyEvent *e = &ev->xkey;
KeySym ksym;
@@ -2574,11 +2592,13 @@
int len;
int meta;
int shift;
+ int ctrl;
Status status;
if (IS_SET(MODE_KBDLOCK))
return;
+ ctrl = e->state & ControlMask;
meta = e->state & Mod1Mask;
shift = e->state & ShiftMask;
len = XmbLookupString(xw.xic, e, buf, sizeof(buf), &ksym, &status);
@@ -2589,6 +2609,11 @@
/* 2. hardcoded (overrides X lookup) */
} else {
switch(ksym) {
+ case XK_Prior:
+ case XK_Next:
+ if(ctrl)
+ togglefont();
+ break;
case XK_Up:
case XK_Down:
case XK_Left: