added --fn parameter to set font at run time

This commit is contained in:
Maarten van Gompel 2021-08-24 21:08:00 +02:00 committed by John Sullivan
parent fb82daea9c
commit bdfdf559b4
2 changed files with 15 additions and 4 deletions

View File

@ -71,7 +71,7 @@ static enum layout_id layers[] = {
#include "keymap.mobintl.h"
#include "keyboard.h"
static const char *fc_font_pattern = "Monospace 16";
static const char *default_font = "Monospace 15";
static struct key keys_full[], keys_special[], keys_simple[], keys_cyrillic[],
keys_arabic[],

17
main.c
View File

@ -347,7 +347,7 @@ usage(char *argv0)
fprintf(stderr, " -o - Print press keys to standard output\n");
fprintf(stderr, " -l - Comma separated list of layers\n");
fprintf(stderr, " -H [int] - Height in pixels\n");
fprintf(stderr, " -fn [font] - Set font (Xft, e.g: DejaVu Sans:bold:size=20)\n");
fprintf(stderr, " -fn [font] - Set font (e.g: DejaVu Sans 20)\n");
}
int
@ -355,6 +355,7 @@ main(int argc, char **argv) {
/* parse command line arguments */
int i;
char *layer_names_list = NULL;
const char *fc_font_pattern = NULL;
char *tmp;
uint32_t height = KBD_PIXEL_HEIGHT;
@ -365,10 +366,10 @@ main(int argc, char **argv) {
for (i = 1; argv[i]; i++) {
if (!strcmp(argv[i], "-v")) {
if ((!strcmp(argv[i], "-v")) || (!strcmp(argv[i], "--version"))) {
printf("wvkbd-%s", VERSION);
exit(0);
} else if (!strcmp(argv[i], "-h")) {
} else if ((!strcmp(argv[i], "-h")) || (!strcmp(argv[i], "--help"))) {
usage(argv[0]);
exit(0);
} else if (!strcmp(argv[i], "-l")) {
@ -387,6 +388,8 @@ main(int argc, char **argv) {
height = atoi(argv[++i]);
} else if (!strcmp(argv[i], "-D")) {
debug = true;
} else if ((!strcmp(argv[i], "-fn")) || (!strcmp(argv[i], "--fn"))) {
fc_font_pattern = estrdup(argv[++i]);
} else if (!strcmp(argv[i], "-o")) {
keyboard.print = true;
} else {
@ -396,6 +399,10 @@ main(int argc, char **argv) {
}
}
if (!fc_font_pattern) {
fc_font_pattern = default_font;
}
/* connect to compositor */
display = wl_display_connect(NULL);
if (display == NULL) {
@ -452,5 +459,9 @@ main(int argc, char **argv) {
while (wl_display_dispatch(display) != -1 && run_display) {
}
if (fc_font_pattern != default_font) {
free((void*) fc_font_pattern);
}
return 0;
}