Skip to content

Commit

Permalink
main: Allow user to override layers in landscape mode
Browse files Browse the repository at this point in the history
Add a new parameter `--landscape-layers` as well as an environment
variable `WVKBD_LANDSCAPE_LAYERS` that allows the user to override the
default set of layers in landscape mode. This complements the existing
`-l` parameter and `WVKBD_LAYERS` environment variable, which do the
equivalent for non-landscape mode.

Furthermore, add documentation for the new switch. Move the `-l`
parameter to the bottom so we don't have to realign all parameters and
so all layer-related parameters are grouped together.
  • Loading branch information
pks-t authored and proycon committed Oct 7, 2022
1 parent dfae590 commit 9bbc8d4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
19 changes: 16 additions & 3 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,6 @@ usage(char *argv0) {
fprintf(stderr, " -D - Enable debug\n");
fprintf(stderr, " -o - Print pressed keys to standard output\n");
fprintf(stderr, " -O - Print intersected keys to standard output\n");
fprintf(stderr, " -l - Comma separated list of layers\n");
fprintf(stderr, " -H [int] - Height in pixels\n");
fprintf(stderr, " -L [int] - Landscape height in pixels\n");
fprintf(stderr, " --fn [font] - Set font (e.g: DejaVu Sans 20)\n");
Expand All @@ -377,6 +376,8 @@ usage(char *argv0) {
fprintf(stderr, " --text [rrggbb|aa] - Set color of text on keys\n");
fprintf(stderr, " --text-sp [rrggbb|aa] - Set color of text on special keys\n");
fprintf(stderr, " --list-layers - Print the list of available layers\n");
fprintf(stderr, " -l - Comma separated list of layers\n");
fprintf(stderr, " --landscape-layers - Comma separated list of landscape layers\n");
}

void
Expand Down Expand Up @@ -461,14 +462,16 @@ set_kbd_colors(uint8_t * bgra, char * hex) {
int
main(int argc, char **argv) {
/* parse command line arguments */
char *layer_names_list = NULL;
char *layer_names_list = NULL, *landscape_layer_names_list = NULL;
const char *fc_font_pattern = NULL;
height = normal_height = KBD_PIXEL_HEIGHT;
landscape_height = KBD_PIXEL_LANDSCAPE_HEIGHT;

char *tmp;
if ((tmp = getenv("WVKBD_LAYERS")))
layer_names_list = estrdup(tmp);
if ((tmp = getenv("WVKBD_LANDSCAPE_LAYERS")))
landscape_layer_names_list = estrdup(tmp);
if ((tmp = getenv("WVKBD_HEIGHT")))
normal_height = atoi(tmp);
if ((tmp = getenv("WVKBD_LANDSCAPE_HEIGHT")))
Expand Down Expand Up @@ -497,6 +500,15 @@ main(int argc, char **argv) {
if (layer_names_list)
free(layer_names_list);
layer_names_list = estrdup(argv[++i]);
} else if ((!strcmp(argv[i], "-landscape-layers")) ||
(!strcmp(argv[i], "--landscape-layers"))) {
if (i >= argc - 1) {
usage(argv[0]);
exit(1);
}
if (landscape_layer_names_list)
free(landscape_layer_names_list);
landscape_layer_names_list = estrdup(argv[++i]);
} else if ((!strcmp(argv[i], "-bg")) || (!strcmp(argv[i], "--bg"))) {
if (i >= argc - 1) {
usage(argv[0]);
Expand Down Expand Up @@ -624,7 +636,8 @@ main(int argc, char **argv) {
die("failed to init virtual keyboard_manager\n");
}

kbd_init(&keyboard, (struct layout *)&layouts, layer_names_list);
kbd_init(&keyboard, (struct layout *)&layouts,
layer_names_list, landscape_layer_names_list);

draw_ctx.font_description =
pango_font_description_from_string(fc_font_pattern);
Expand Down
5 changes: 5 additions & 0 deletions wvkbd.1
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ print intersected keys to standard output
comma separated list of layers
.P
.RE
\fB--landscape-layers\fR
.RS 4
comma separated list of layers used in landscape mode
.P
.RE
\fB-H\fR \fIPX\fR
.RS 4
height in pixels
Expand Down

0 comments on commit 9bbc8d4

Please sign in to comment.