From 9262cecf21a3a2fcf5f5c0f7dcc872fdc5435ca1 Mon Sep 17 00:00:00 2001 From: Miles Alan Date: Mon, 7 Dec 2020 21:16:37 -0600 Subject: [PATCH] cyclefont: Add keybinding to cycle between multiple different fonts --- config.def.h | 8 +++++++- x.c | 17 +++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/config.def.h b/config.def.h index 6f05dce..5cd506c 100644 --- a/config.def.h +++ b/config.def.h @@ -5,7 +5,12 @@ * * 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", + "tewi:pixelsize=12:antialias=true:autohint=true" +}; +static int fonts_current = 0; + static int borderpx = 2; /* @@ -199,6 +204,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 210f184..88cb8e7 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" @@ -949,6 +950,18 @@ xloadfont(Font *f, FcPattern *pattern) return 0; } +void +cyclefonts(const Arg *dummy) +{ + fonts_current++; + if (fonts_current > (sizeof fonts / sizeof fonts[0]) - 1) { + fonts_current = 0; + } + usedfont = fonts[fonts_current]; + xloadfonts(fonts[fonts_current], 0); + redraw(); +} + void xloadfonts(char *fontstr, double fontsize) { @@ -1113,8 +1126,8 @@ xinit(int cols, int rows) if (!FcInit()) die("could not init fontconfig.\n"); - usedfont = (opt_font == NULL)? font : opt_font; - xloadfonts(usedfont, 0); + usedfont = fonts[fonts_current]; + xloadfonts(fonts[fonts_current], 0); /* colors */ xw.cmap = XDefaultColormap(xw.dpy, xw.scr); -- 2.26.2