From: Ingo Bürk Date: Fri, 13 Jan 2017 17:33:29 +0000 (+0100) Subject: Validate that a binding mode is not defined more than once. (#2633) X-Git-Tag: 4.14~70 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=33d6a4e829cf6b67f285541a86499b89d44b8a4d;p=i3%2Fi3 Validate that a binding mode is not defined more than once. (#2633) While defining the same mode usually wouldn't hurt and, in fact, the old behavior allows to split the definition of a binding mode into several blocks, this can lead to user errors where they accidentally define a mode twice and don't understand why the mode behaves a certain way (this has been observed in real life :-)). There's no good usecase for splitting a single binding mode into multiple blocks, thus the new behavior is better. fixes #2615 --- diff --git a/src/bindings.c b/src/bindings.c index c76e7779..bfec27e1 100644 --- a/src/bindings.c +++ b/src/bindings.c @@ -32,8 +32,9 @@ static struct Mode *mode_from_name(const char *name, bool pango_markup) { /* Try to find the mode in the list of modes and return it */ SLIST_FOREACH(mode, &modes, modes) { - if (strcmp(mode->name, name) == 0) + if (strcmp(mode->name, name) == 0) { return mode; + } } /* If the mode was not found, create a new one */ diff --git a/src/config_directives.c b/src/config_directives.c index a260518c..82e1a346 100644 --- a/src/config_directives.c +++ b/src/config_directives.c @@ -126,6 +126,15 @@ CFGFUN(enter_mode, const char *pango_markup, const char *modename) { ELOG("You cannot use the name %s for your mode\n", DEFAULT_BINDING_MODE); exit(1); } + + struct Mode *mode; + SLIST_FOREACH(mode, &modes, modes) { + if (strcmp(mode->name, modename) == 0) { + ELOG("The binding mode with name \"%s\" is defined at least twice.\n", modename); + exit(1); + } + } + DLOG("\t now in mode %s\n", modename); FREE(current_mode); current_mode = sstrdup(modename);