conf: add --xkb-XY options

Allow setting XKB options on the command line.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
This commit is contained in:
David Herrmann 2012-03-24 13:02:48 +01:00
parent 4c2ff06f31
commit f8dc74c297
3 changed files with 35 additions and 10 deletions

View File

@ -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 <layout> Set XkbLayout for input devices\n"
"\t --xkb-variant <variant> Set XkbVariant for input devices\n"
"\t --xkb-options <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;

View File

@ -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;

View File

@ -47,7 +47,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#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;