aboutsummaryrefslogtreecommitdiffstats
path: root/conf.c
diff options
context:
space:
mode:
authorokan2013-07-08 16:10:55 +0000
committerokan2013-07-08 16:10:55 +0000
commitbd27b5d013dad7414aec04abfb864a2581ac1e3e (patch)
treee2d2c52e28ed8cd9657240e2bde306ed2e19be89 /conf.c
parenta56db3439f26c4bda09fe7fdd665641680a6dad7 (diff)
downloadcwm-bd27b5d013dad7414aec04abfb864a2581ac1e3e.tar.gz
move duplicate kbd and mouse modifier parsing to a generic function;
from Tiago Cunha
Diffstat (limited to 'conf.c')
-rw-r--r--conf.c66
1 files changed, 31 insertions, 35 deletions
diff --git a/conf.c b/conf.c
index 1773033..dd78575 100644
--- a/conf.c
+++ b/conf.c
@@ -15,7 +15,7 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
- * $OpenBSD: conf.c,v 1.137 2013/06/23 17:57:50 okan Exp $
+ * $OpenBSD: conf.c,v 1.138 2013/07/08 16:10:55 okan Exp $
*/
#include <sys/param.h>
@@ -31,8 +31,9 @@
#include "calmwm.h"
-static void conf_mouseunbind(struct conf *, struct mousebinding *);
-static void conf_unbind(struct conf *, struct keybinding *);
+static const char *conf_bind_getmask(const char *, u_int *);
+static void conf_mouseunbind(struct conf *, struct mousebinding *);
+static void conf_unbind(struct conf *, struct keybinding *);
/* Add an command menu entry to the end of the menu */
void
@@ -442,27 +443,35 @@ static struct {
{ 'S', ShiftMask },
};
+static const char *
+conf_bind_getmask(const char *name, u_int *mask)
+{
+ char *dash;
+ const char *ch;
+ u_int i;
+
+ *mask = 0;
+ if ((dash = strchr(name, '-')) == NULL)
+ return (name);
+ for (i = 0; i < nitems(bind_mods); i++) {
+ if ((ch = strchr(name, bind_mods[i].chr)) != NULL && ch < dash)
+ *mask |= bind_mods[i].mask;
+ }
+
+ /* Skip past modifiers. */
+ return (dash + 1);
+}
+
void
conf_bindname(struct conf *c, char *name, char *binding)
{
struct keybinding *current_binding;
- char *substring, *tmp;
- u_int i;
+ const char *substring;
+ u_int i, mask;
current_binding = xcalloc(1, sizeof(*current_binding));
-
- if ((substring = strchr(name, '-')) != NULL) {
- for (i = 0; i < nitems(bind_mods); i++) {
- if ((tmp = strchr(name, bind_mods[i].chr)) !=
- NULL && tmp < substring) {
- current_binding->modmask |= bind_mods[i].mask;
- }
- }
-
- /* skip past the modifiers */
- substring++;
- } else
- substring = name;
+ substring = conf_bind_getmask(name, &mask);
+ current_binding->modmask |= mask;
if (substring[0] == '[' &&
substring[strlen(substring)-1] == ']') {
@@ -551,25 +560,12 @@ int
conf_mousebind(struct conf *c, char *name, char *binding)
{
struct mousebinding *current_binding;
- char *substring, *tmp;
- u_int button;
- const char *errstr;
- u_int i;
+ const char *errstr, *substring;
+ u_int button, i, mask;
current_binding = xcalloc(1, sizeof(*current_binding));
-
- if ((substring = strchr(name, '-')) != NULL) {
- for (i = 0; i < nitems(bind_mods); i++) {
- if ((tmp = strchr(name, bind_mods[i].chr)) !=
- NULL && tmp < substring) {
- current_binding->modmask |= bind_mods[i].mask;
- }
- }
-
- /* skip past the modifiers */
- substring++;
- } else
- substring = name;
+ substring = conf_bind_getmask(name, &mask);
+ current_binding->modmask |= mask;
button = strtonum(substring, 1, 5, &errstr);
if (errstr)