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:
11
config.def.h
11
config.def.h
@@ -5,7 +5,15 @@
|
||||
*
|
||||
* 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;
|
||||
|
||||
|
||||
@@ -254,6 +262,7 @@ static Shortcut shortcuts[] = {
|
||||
{ ShiftMask, XK_Insert, selpaste, {.i = 0} },
|
||||
{ TERMMOD, XK_Num_Lock, numlock, {.i = 0} },
|
||||
{ MODKEY, XK_c, normalMode, {.i = 0} },
|
||||
{ TERMMOD, XK_S, cyclefonts, {} },
|
||||
};
|
||||
|
||||
/*
|
||||
|
||||
20
x.c
20
x.c
@@ -61,6 +61,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"
|
||||
@@ -334,12 +335,8 @@ void
|
||||
zoomreset(const Arg *arg)
|
||||
{
|
||||
Arg larg;
|
||||
|
||||
if (defaultfontsize > 0) {
|
||||
larg.f = defaultfontsize;
|
||||
zoomabs(&larg);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ttysend(const Arg *arg)
|
||||
@@ -363,6 +360,15 @@ evrow(XEvent *e)
|
||||
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
|
||||
mousesel(XEvent *e, int done)
|
||||
{
|
||||
@@ -1189,7 +1195,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 */
|
||||
@@ -2194,7 +2200,7 @@ xrdb_load(void)
|
||||
defaultrcs = defaultbg;
|
||||
}
|
||||
|
||||
XRESOURCE_LOAD_STRING("font", font);
|
||||
XRESOURCE_LOAD_STRING("font", fonts[0]);
|
||||
XRESOURCE_LOAD_STRING("termname", termname);
|
||||
|
||||
XRESOURCE_LOAD_INTEGER("blinktimeout", blinktimeout);
|
||||
@@ -2217,7 +2223,7 @@ reload(int sig)
|
||||
/* colors, fonts */
|
||||
xloadcols();
|
||||
xunloadfonts();
|
||||
xloadfonts(font, 0);
|
||||
xloadfonts(fonts[currentfont], 0);
|
||||
|
||||
/* pretend the window just got resized */
|
||||
cresize(win.w, win.h);
|
||||
|
||||
Reference in New Issue
Block a user