From f8dc74c2972106ed2c4dbbf495db500b6cbfae88 Mon Sep 17 00:00:00 2001 From: David Herrmann Date: Sat, 24 Mar 2012 13:02:48 +0100 Subject: [PATCH] conf: add --xkb-XY options Allow setting XKB options on the command line. Signed-off-by: David Herrmann --- src/conf.c | 27 +++++++++++++++++++++++++-- src/conf.h | 5 +++++ src/input.c | 13 +++++-------- 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/src/conf.c b/src/conf.c index cf19436..7899ffe 100644 --- a/src/conf.c +++ b/src/conf.c @@ -52,20 +52,27 @@ static void print_help() "\t-v, --verbose Print verbose messages\n" "\t --debug Enable debug mode\n" "\t --silent Suppress notices and warnings\n" - "\t-s, --switchvt Automatically switch to VT\n", + "\t-s, --switchvt Automatically switch to VT\n" + "Input Device Options:\n" + "\t-l, --xkb-layout Set XkbLayout for input devices\n" + "\t --xkb-variant Set XkbVariant for input devices\n" + "\t --xkb-options Set XkbOptions for input devices\n", "kmscon"); } int conf_parse_argv(int argc, char **argv) { int show_help = 0; - char short_options[] = ":hvs"; + char short_options[] = ":hvsl:"; struct option long_options[] = { { "help", no_argument, NULL, 'h' }, { "verbose", no_argument, NULL, 'v' }, { "debug", no_argument, &conf_global.debug, 1 }, { "silent", no_argument, &conf_global.silent, 1 }, { "switchvt", no_argument, NULL, 's' }, + { "xkb-layout", required_argument, NULL, 'l' }, + { "xkb-variant", required_argument, NULL, -1 }, + { "xkb-options", required_argument, NULL, -2 }, { NULL, 0, NULL, 0 }, }; int idx; @@ -92,6 +99,15 @@ int conf_parse_argv(int argc, char **argv) case 's': conf_global.switchvt = 1; break; + case 'l': + conf_global.xkb_layout = optarg; + break; + case -1: + conf_global.xkb_variant = optarg; + break; + case -2: + conf_global.xkb_options = optarg; + break; case ':': fprintf(stderr, "Missing argument for option -%c\n", optopt); @@ -113,6 +129,13 @@ int conf_parse_argv(int argc, char **argv) if (conf_global.debug) conf_global.verbose = 1; + if (!conf_global.xkb_layout) + conf_global.xkb_layout = "us"; + if (!conf_global.xkb_variant) + conf_global.xkb_variant = ""; + if (!conf_global.xkb_options) + conf_global.xkb_options = ""; + if (show_help) { print_help(); conf_global.exit = 1; diff --git a/src/conf.h b/src/conf.h index e92c329..9e71894 100644 --- a/src/conf.h +++ b/src/conf.h @@ -53,6 +53,11 @@ struct conf_obj { int silent; /* enter new VT directly */ int switchvt; + + /* input KBD layout */ + const char *xkb_layout; + const char *xkb_variant; + const char *xkb_options; }; extern struct conf_obj conf_global; diff --git a/src/input.c b/src/input.c index aa32d4c..e6c94f9 100644 --- a/src/input.c +++ b/src/input.c @@ -47,7 +47,7 @@ #include #include #include - +#include "conf.h" #include "eloop.h" #include "input.h" #include "kbd.h" @@ -278,7 +278,6 @@ int kmscon_input_new(struct kmscon_input **out) { int ret; struct kmscon_input *input; - static const char *layout, *variant, *options; if (!out) return -EINVAL; @@ -293,12 +292,10 @@ int kmscon_input_new(struct kmscon_input **out) input->ref = 1; input->state = INPUT_ASLEEP; - /* TODO: Make properly configurable */ - layout = getenv("KMSCON_XKB_LAYOUT") ?: "us"; - variant = getenv("KMSCON_XKB_VARIANT") ?: ""; - options = getenv("KMSCON_XKB_OPTIONS") ?: ""; - - ret = kmscon_kbd_desc_new(&input->desc, layout, variant, options); + ret = kmscon_kbd_desc_new(&input->desc, + conf_global.xkb_layout, + conf_global.xkb_variant, + conf_global.xkb_options); if (ret) { log_warn("input: cannot create xkb description\n"); goto err_free;