cyclefonts: keybind to cycle fonts (agree with st-xresources-signal-reloading)

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
This commit is contained in:
Justinas Grigas
2022-07-31 10:43:14 +03:00
committed by Łukasz Pankowski
parent f37ea1f018
commit 02739346a8
2 changed files with 24 additions and 9 deletions

View File

@@ -5,7 +5,15 @@
* *
* font: see http://freedesktop.org/software/fontconfig/fontconfig-user.html * font: see http://freedesktop.org/software/fontconfig/fontconfig-user.html
*/ */
static char *font = "Liberation Mono:pixelsize=12:antialias=true:autohint=true"; static char *fonts[] = {
"FiraCode Nerd Font:size=10",
"Monaspace Neon:size=10",
"Monaspace Argon:size=10",
"Monaspace Xenon:size=10",
"Monaspace Radon:size=10",
"Monaspace Krypton:size=10",
};
static size_t currentfont = 0;
static int borderpx = 2; static int borderpx = 2;
@@ -254,6 +262,7 @@ static Shortcut shortcuts[] = {
{ ShiftMask, XK_Insert, selpaste, {.i = 0} }, { ShiftMask, XK_Insert, selpaste, {.i = 0} },
{ TERMMOD, XK_Num_Lock, numlock, {.i = 0} }, { TERMMOD, XK_Num_Lock, numlock, {.i = 0} },
{ MODKEY, XK_c, normalMode, {.i = 0} }, { MODKEY, XK_c, normalMode, {.i = 0} },
{ TERMMOD, XK_S, cyclefonts, {} },
}; };
/* /*

20
x.c
View File

@@ -61,6 +61,7 @@ static void zoom(const Arg *);
static void zoomabs(const Arg *); static void zoomabs(const Arg *);
static void zoomreset(const Arg *); static void zoomreset(const Arg *);
static void ttysend(const Arg *); static void ttysend(const Arg *);
static void cyclefonts(const Arg *);
/* config.h for applying patches and the configuration. */ /* config.h for applying patches and the configuration. */
#include "config.h" #include "config.h"
@@ -334,12 +335,8 @@ void
zoomreset(const Arg *arg) zoomreset(const Arg *arg)
{ {
Arg larg; Arg larg;
if (defaultfontsize > 0) {
larg.f = defaultfontsize;
zoomabs(&larg); zoomabs(&larg);
} }
}
void void
ttysend(const Arg *arg) ttysend(const Arg *arg)
@@ -363,6 +360,15 @@ evrow(XEvent *e)
return y / win.ch; return y / win.ch;
} }
void cyclefonts(const Arg *arg) {
currentfont++;
currentfont %= (sizeof fonts / sizeof fonts[0]);
usedfont = fonts[currentfont];
Arg larg;
larg.f = usedfontsize;
zoomabs(&larg);
}
void void
mousesel(XEvent *e, int done) mousesel(XEvent *e, int done)
{ {
@@ -1189,7 +1195,7 @@ xinit(int cols, int rows)
if (!FcInit()) if (!FcInit())
die("could not init fontconfig.\n"); die("could not init fontconfig.\n");
usedfont = (opt_font == NULL)? font : opt_font; usedfont = (opt_font == NULL) ? fonts[currentfont] : opt_font;
xloadfonts(usedfont, 0); xloadfonts(usedfont, 0);
/* colors */ /* colors */
@@ -2194,7 +2200,7 @@ xrdb_load(void)
defaultrcs = defaultbg; defaultrcs = defaultbg;
} }
XRESOURCE_LOAD_STRING("font", font); XRESOURCE_LOAD_STRING("font", fonts[0]);
XRESOURCE_LOAD_STRING("termname", termname); XRESOURCE_LOAD_STRING("termname", termname);
XRESOURCE_LOAD_INTEGER("blinktimeout", blinktimeout); XRESOURCE_LOAD_INTEGER("blinktimeout", blinktimeout);
@@ -2217,7 +2223,7 @@ reload(int sig)
/* colors, fonts */ /* colors, fonts */
xloadcols(); xloadcols();
xunloadfonts(); xunloadfonts();
xloadfonts(font, 0); xloadfonts(fonts[currentfont], 0);
/* pretend the window just got resized */ /* pretend the window just got resized */
cresize(win.w, win.h); cresize(win.w, win.h);