mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-11-25 14:57:20 +00:00
[client] config: enhance input:escapeKey to accept a KEY_* string value
This makes it possible to define the escape key by name rather then just it's integer code, while still allowing fallback to using an integer value for codes that may not be defined. Example: `input:escapeKey=KEY_F1` An invalid string value will also print a list of all valid string values.
This commit is contained in:
parent
0a768a5a7f
commit
0a9a9ed57e
@ -42,6 +42,8 @@ static char * optPosToString (struct Option * opt);
|
|||||||
static bool optSizeParse (struct Option * opt, const char * str);
|
static bool optSizeParse (struct Option * opt, const char * str);
|
||||||
static StringList optSizeValues (struct Option * opt);
|
static StringList optSizeValues (struct Option * opt);
|
||||||
static char * optSizeToString (struct Option * opt);
|
static char * optSizeToString (struct Option * opt);
|
||||||
|
static bool optScancodeParse (struct Option * opt, const char * str);
|
||||||
|
static StringList optScancodeValues (struct Option * opt);
|
||||||
static bool optScancodeValidate(struct Option * opt, const char ** error);
|
static bool optScancodeValidate(struct Option * opt, const char ** error);
|
||||||
static char * optScancodeToString(struct Option * opt);
|
static char * optScancodeToString(struct Option * opt);
|
||||||
static bool optRotateValidate (struct Option * opt, const char ** error);
|
static bool optRotateValidate (struct Option * opt, const char ** error);
|
||||||
@ -310,10 +312,12 @@ static struct Option options[] =
|
|||||||
{
|
{
|
||||||
.module = "input",
|
.module = "input",
|
||||||
.name = "escapeKey",
|
.name = "escapeKey",
|
||||||
.description = "Specify the escape key, see <linux/input-event-codes.h> for valid values",
|
.description = "Specify the escape/menu key to use (use \"help\" to see valid values)",
|
||||||
.shortopt = 'm',
|
.shortopt = 'm',
|
||||||
.type = OPTION_TYPE_INT,
|
.type = OPTION_TYPE_INT,
|
||||||
.value.x_int = KEY_SCROLLLOCK,
|
.value.x_int = KEY_SCROLLLOCK,
|
||||||
|
.parser = optScancodeParse,
|
||||||
|
.getValues = optScancodeValues,
|
||||||
.validator = optScancodeValidate,
|
.validator = optScancodeValidate,
|
||||||
.toString = optScancodeToString,
|
.toString = optScancodeToString,
|
||||||
},
|
},
|
||||||
@ -862,6 +866,20 @@ static char * optSizeToString(struct Option * opt)
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static StringList optScancodeValues(struct Option * opt)
|
||||||
|
{
|
||||||
|
StringList sl = stringlist_new(false);
|
||||||
|
if (!sl)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
// this typecast is safe as the stringlist doesn't own the values
|
||||||
|
for(unsigned int i = 0; i < KEY_MAX; ++i)
|
||||||
|
if (linux_to_str[i])
|
||||||
|
stringlist_push(sl, (char *)linux_to_str[i]);
|
||||||
|
|
||||||
|
return sl;
|
||||||
|
}
|
||||||
|
|
||||||
static bool optScancodeValidate(struct Option * opt, const char ** error)
|
static bool optScancodeValidate(struct Option * opt, const char ** error)
|
||||||
{
|
{
|
||||||
if (opt->value.x_int >= 0 && opt->value.x_int < KEY_MAX)
|
if (opt->value.x_int >= 0 && opt->value.x_int < KEY_MAX)
|
||||||
@ -871,6 +889,29 @@ static bool optScancodeValidate(struct Option * opt, const char ** error)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool optScancodeParse(struct Option * opt, const char * str)
|
||||||
|
{
|
||||||
|
for(unsigned int i = 0; i < KEY_MAX; ++i)
|
||||||
|
{
|
||||||
|
if (!linux_to_str[i])
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (strcasecmp(linux_to_str[i], str) == 0)
|
||||||
|
{
|
||||||
|
opt->value.x_int = i;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// fallback for pre-keycode name support
|
||||||
|
char * end;
|
||||||
|
opt->value.x_int = strtol(str, &end, 10);
|
||||||
|
if (*end)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static char * optScancodeToString(struct Option * opt)
|
static char * optScancodeToString(struct Option * opt)
|
||||||
{
|
{
|
||||||
char * str;
|
char * str;
|
||||||
|
Loading…
Reference in New Issue
Block a user