summaryrefslogtreecommitdiff
path: root/src/conf.c
diff options
context:
space:
mode:
authorDavid Herrmann <dh.herrmann@googlemail.com>2012-10-01 11:23:21 +0200
committerDavid Herrmann <dh.herrmann@googlemail.com>2012-10-01 11:23:21 +0200
commit79ef4f950575a7e6943dd1a75ccc2e90520cdeee (patch)
tree0fda91f14d050e5972b0b64e1022cbc45eb68800 /src/conf.c
parenta3abdfc5bccd02236a7dc0ed0ffb8ebefeace206 (diff)
Move grab-parsing into conf.c
We really need to clean this up and allow parsing of grabs in conf.c again. xkbcommon is now mandatory so we can fix all the input layers to use it. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
Diffstat (limited to 'src/conf.c')
-rw-r--r--src/conf.c87
1 files changed, 87 insertions, 0 deletions
diff --git a/src/conf.c b/src/conf.c
index c69026a..87cac59 100644
--- a/src/conf.c
+++ b/src/conf.c
@@ -36,8 +36,10 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <xkbcommon/xkbcommon.h>
#include "conf.h"
#include "log.h"
+#include "shl_misc.h"
#define LOG_SUBSYSTEM "config"
@@ -147,6 +149,84 @@ void conf_default_string_list(struct conf_option *opt)
*(void**)opt->mem = opt->def;
}
+int conf_parse_grab(struct conf_option *opt, bool on, const char *arg)
+{
+ char *buf, *tmp, *start;
+ struct conf_grab grab, *gnew;
+
+ memset(&grab, 0, sizeof(grab));
+
+ buf = strdup(arg);
+ if (!buf)
+ return -ENOMEM;
+ tmp = buf;
+
+next_mod:
+ if (*tmp == '<') {
+ start = tmp;
+ while (*tmp && *tmp != '>')
+ ++tmp;
+
+ if (*tmp != '>') {
+ log_error("missing '>' in grab '%s' near '%s'",
+ arg, start);
+ goto err_free;
+ }
+
+ *tmp++ = 0;
+ ++start;
+ if (!strcasecmp(start, "shift")) {
+ grab.mods |= SHL_SHIFT_MASK;
+ } else if (!strcasecmp(start, "lock")) {
+ grab.mods |= SHL_LOCK_MASK;
+ } else if (!strcasecmp(start, "control") ||
+ !strcasecmp(start, "ctrl")) {
+ grab.mods |= SHL_CONTROL_MASK;
+ } else if (!strcasecmp(start, "alt")) {
+ grab.mods |= SHL_ALT_MASK;
+ } else if (!strcasecmp(start, "logo")) {
+ grab.mods |= SHL_LOGO_MASK;
+ } else {
+ log_error("invalid modifier '%s' in grab '%s'",
+ start, arg);
+ goto err_free;
+ }
+
+ goto next_mod;
+ }
+
+ if (!*tmp) {
+ log_error("missing key in grab '%s'", arg);
+ goto err_free;
+ }
+
+ grab.keysym = xkb_keysym_from_name(tmp);
+ if (!grab.keysym) {
+ log_error("invalid key '%s' in grab '%s'", tmp, arg);
+ goto err_free;
+ }
+
+ gnew = malloc(sizeof(*gnew));
+ if (!gnew)
+ goto err_free;
+ memcpy(gnew, &grab, sizeof(*gnew));
+
+ opt->type->free(opt);
+ *(void**)opt->mem = gnew;
+ free(buf);
+
+ return 0;
+
+err_free:
+ free(buf);
+ return -EFAULT;
+}
+
+void conf_default_grab(struct conf_option *opt)
+{
+ *(void**)opt->mem = opt->def;
+}
+
const struct conf_type conf_bool = {
.flags = 0,
.parse = conf_parse_bool,
@@ -182,6 +262,13 @@ const struct conf_type conf_string_list = {
.set_default = conf_default_string_list,
};
+const struct conf_type conf_grab = {
+ .flags = CONF_HAS_ARG,
+ .parse = conf_parse_grab,
+ .free = conf_free_value,
+ .set_default = conf_default_grab,
+};
+
/* free all memory that we allocated and reset to initial state */
void conf_free(struct conf_option *opts, size_t len)
{