st-cyclefonts-20220731-baa9357.diff - sites - public wiki contents of suckless.… | |
git clone git://git.suckless.org/sites | |
Log | |
Files | |
Refs | |
--- | |
st-cyclefonts-20220731-baa9357.diff (2602B) | |
--- | |
1 From 3c83f90504445efb358f18b4ae86193c6baa709c Mon Sep 17 00:00:00 2001 | |
2 From: Justinas Grigas <[email protected]> | |
3 Date: Sun, 31 Jul 2022 10:43:14 +0300 | |
4 Subject: [PATCH] cyclefonts: keybind to cycle fonts | |
5 | |
6 This patch is an update to the 20210604, which fixes zoomreset. | |
7 | |
8 Because the cyclefonts function doesn't change the defaultfontsize | |
9 variable, zoomreset function resets all fonts to the size of the first | |
10 one loaded. | |
11 | |
12 With this patch, zoomreset will reset the font to the specified fontsize | |
13 --- | |
14 config.def.h | 7 ++++++- | |
15 x.c | 20 ++++++++++++++------ | |
16 2 files changed, 20 insertions(+), 7 deletions(-) | |
17 | |
18 diff --git a/config.def.h b/config.def.h | |
19 index 91ab8ca..c213e48 100644 | |
20 --- a/config.def.h | |
21 +++ b/config.def.h | |
22 @@ -5,7 +5,11 @@ | |
23 * | |
24 * font: see http://freedesktop.org/software/fontconfig/fontconfig-user… | |
25 */ | |
26 -static char *font = "Liberation Mono:pixelsize=12:antialias=true:autohi… | |
27 +static char *fonts[] = { | |
28 + "Liberation Mono:pixelsize=12:antialias=true:autohint=true", | |
29 + "Gohu GohuFont:pixelsize=11:antialias=false:autohint=false", | |
30 +}; | |
31 +static size_t currentfont = 0; | |
32 static int borderpx = 2; | |
33 | |
34 /* | |
35 @@ -201,6 +205,7 @@ static Shortcut shortcuts[] = { | |
36 { TERMMOD, XK_Y, selpaste, {.i = … | |
37 { ShiftMask, XK_Insert, selpaste, {.i = … | |
38 { TERMMOD, XK_Num_Lock, numlock, {.i = … | |
39 + { TERMMOD, XK_S, cyclefonts, {} … | |
40 }; | |
41 | |
42 /* | |
43 diff --git a/x.c b/x.c | |
44 index 2a3bd38..08f7275 100644 | |
45 --- a/x.c | |
46 +++ b/x.c | |
47 @@ -59,6 +59,7 @@ static void zoom(const Arg *); | |
48 static void zoomabs(const Arg *); | |
49 static void zoomreset(const Arg *); | |
50 static void ttysend(const Arg *); | |
51 +static void cyclefonts(const Arg *); | |
52 | |
53 /* config.h for applying patches and the configuration. */ | |
54 #include "config.h" | |
55 @@ -315,11 +316,7 @@ void | |
56 zoomreset(const Arg *arg) | |
57 { | |
58 Arg larg; | |
59 - | |
60 - if (defaultfontsize > 0) { | |
61 - larg.f = defaultfontsize; | |
62 - zoomabs(&larg); | |
63 - } | |
64 + zoomabs(&larg); | |
65 } | |
66 | |
67 void | |
68 @@ -328,6 +325,17 @@ ttysend(const Arg *arg) | |
69 ttywrite(arg->s, strlen(arg->s), 1); | |
70 } | |
71 | |
72 +void | |
73 +cyclefonts(const Arg *arg) | |
74 +{ | |
75 + currentfont++; | |
76 + currentfont %= (sizeof fonts / sizeof fonts[0]); | |
77 + usedfont = fonts[currentfont]; | |
78 + Arg larg; | |
79 + larg.f = usedfontsize; | |
80 + zoomabs(&larg); | |
81 +} | |
82 + | |
83 int | |
84 evcol(XEvent *e) | |
85 { | |
86 @@ -1144,7 +1152,7 @@ xinit(int cols, int rows) | |
87 if (!FcInit()) | |
88 die("could not init fontconfig.\n"); | |
89 | |
90 - usedfont = (opt_font == NULL)? font : opt_font; | |
91 + usedfont = (opt_font == NULL)? fonts[currentfont] : opt_font; | |
92 xloadfonts(usedfont, 0); | |
93 | |
94 /* colors */ | |
95 -- | |
96 2.37.1 | |
97 |