From 066416f76425a2784ef880826f47ad7b5fac7d43 Mon Sep 17 00:00:00 2001 From: Nikita Langer Date: Sun, 31 May 2026 15:33:29 +0200 Subject: Cycle Fonts --- config.def.h | 8 ++- patches/st-cyclefonts-20220731-baa9357.diff | 97 +++++++++++++++++++++++++++++ x.c | 20 ++++-- 3 files changed, 118 insertions(+), 7 deletions(-) create mode 100644 patches/st-cyclefonts-20220731-baa9357.diff diff --git a/config.def.h b/config.def.h index e0913e4..6547948 100644 --- a/config.def.h +++ b/config.def.h @@ -15,7 +15,12 @@ * * font: see http://freedesktop.org/software/fontconfig/fontconfig-user.html */ -static char *font = "JetBrains Mono Nerd Font Mono:pixelsize=18:antialias=true:autohint=true"; +// static char *font = "JetBrains Mono Nerd Font Mono:pixelsize=18:antialias=true:autohint=true"; +static char *fonts[] = { + "JetBrains Mono Nerd Font Mono:pixelsize=18:antialias=true:autohint=true", + "SF Mono:pixelsize=18:antialias=true:autohint=true", +}; +static size_t currentfont = 0; static int borderpx = 2; /* @@ -262,6 +267,7 @@ static Shortcut shortcuts[] = { { XK_ANY_MOD, XK_Print, printsel, {.i = 0} }, { ControlMask, XK_plus, zoom, {.f = +1} }, { ControlMask, XK_minus, zoom, {.f = -1} }, + { TERMMOD, XK_S, cyclefonts, {} }, komputer({ TERMMOD, XK_Prior, zoom, {.f = +1} },) komputer({ TERMMOD, XK_Next, zoom, {.f = -1} },) { TERMMOD, XK_Home, zoomreset, {.f = 0} }, diff --git a/patches/st-cyclefonts-20220731-baa9357.diff b/patches/st-cyclefonts-20220731-baa9357.diff new file mode 100644 index 0000000..1f0297b --- /dev/null +++ b/patches/st-cyclefonts-20220731-baa9357.diff @@ -0,0 +1,97 @@ +From 3c83f90504445efb358f18b4ae86193c6baa709c Mon Sep 17 00:00:00 2001 +From: Justinas Grigas +Date: Sun, 31 Jul 2022 10:43:14 +0300 +Subject: [PATCH] cyclefonts: keybind to cycle fonts + +This patch is an update to the 20210604, which fixes zoomreset. + +Because the cyclefonts function doesn't change the defaultfontsize +variable, zoomreset function resets all fonts to the size of the first +one loaded. + +With this patch, zoomreset will reset the font to the specified fontsize +--- + config.def.h | 7 ++++++- + x.c | 20 ++++++++++++++------ + 2 files changed, 20 insertions(+), 7 deletions(-) + +diff --git a/config.def.h b/config.def.h +index 91ab8ca..c213e48 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -5,7 +5,11 @@ + * + * font: see http://freedesktop.org/software/fontconfig/fontconfig-user.html + */ +-static char *font = "Liberation Mono:pixelsize=12:antialias=true:autohint=true"; ++static char *fonts[] = { ++ "Liberation Mono:pixelsize=12:antialias=true:autohint=true", ++ "Gohu GohuFont:pixelsize=11:antialias=false:autohint=false", ++}; ++static size_t currentfont = 0; + static int borderpx = 2; + + /* +@@ -201,6 +205,7 @@ static Shortcut shortcuts[] = { + { TERMMOD, XK_Y, selpaste, {.i = 0} }, + { ShiftMask, XK_Insert, selpaste, {.i = 0} }, + { TERMMOD, XK_Num_Lock, numlock, {.i = 0} }, ++ { TERMMOD, XK_S, cyclefonts, {} }, + }; + + /* +diff --git a/x.c b/x.c +index 2a3bd38..08f7275 100644 +--- a/x.c ++++ b/x.c +@@ -59,6 +59,7 @@ static void zoom(const Arg *); + static void zoomabs(const Arg *); + static void zoomreset(const Arg *); + static void ttysend(const Arg *); ++static void cyclefonts(const Arg *); + + /* config.h for applying patches and the configuration. */ + #include "config.h" +@@ -315,11 +316,7 @@ void + zoomreset(const Arg *arg) + { + Arg larg; +- +- if (defaultfontsize > 0) { +- larg.f = defaultfontsize; +- zoomabs(&larg); +- } ++ zoomabs(&larg); + } + + void +@@ -328,6 +325,17 @@ ttysend(const Arg *arg) + ttywrite(arg->s, strlen(arg->s), 1); + } + ++void ++cyclefonts(const Arg *arg) ++{ ++ currentfont++; ++ currentfont %= (sizeof fonts / sizeof fonts[0]); ++ usedfont = fonts[currentfont]; ++ Arg larg; ++ larg.f = usedfontsize; ++ zoomabs(&larg); ++} ++ + int + evcol(XEvent *e) + { +@@ -1144,7 +1152,7 @@ xinit(int cols, int rows) + if (!FcInit()) + die("could not init fontconfig.\n"); + +- usedfont = (opt_font == NULL)? font : opt_font; ++ usedfont = (opt_font == NULL)? fonts[currentfont] : opt_font; + xloadfonts(usedfont, 0); + + /* colors */ +-- +2.37.1 + diff --git a/x.c b/x.c index 57ca715..8ff82cf 100644 --- a/x.c +++ b/x.c @@ -60,6 +60,7 @@ static void zoom(const Arg *); static void zoomabs(const Arg *); static void zoomreset(const Arg *); static void ttysend(const Arg *); +static void cyclefonts(const Arg *); /* config.h for applying patches and the configuration. */ #include "config.h" @@ -337,11 +338,7 @@ void zoomreset(const Arg *arg) { Arg larg; - - if (defaultfontsize > 0) { - larg.f = defaultfontsize; - zoomabs(&larg); - } + zoomabs(&larg); } void @@ -350,6 +347,17 @@ ttysend(const Arg *arg) ttywrite(arg->s, strlen(arg->s), 1); } +void +cyclefonts(const Arg *arg) +{ + currentfont++; + currentfont %= (sizeof fonts / sizeof fonts[0]); + usedfont = fonts[currentfont]; + Arg larg; + larg.f = usedfontsize; + zoomabs(&larg); +} + int evcol(XEvent *e) { @@ -1299,7 +1307,7 @@ xinit(int cols, int rows) if (!FcInit()) die("could not init fontconfig.\n"); - usedfont = (opt_font == NULL)? font : opt_font; + usedfont = (opt_font == NULL)? fonts[currentfont] : opt_font; xloadfonts(usedfont, 0); /* colors */ -- cgit