diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2020-08-14 05:38:05 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2020-08-14 05:38:05 +0000 |
| commit | d940815f6dce1b1fe75d93783a66fcc00dd22dcc (patch) | |
| tree | ac02bbfe33435c3d923ab5f796dc1ab11b3227eb /config.c | |
| parent | Merge branch 'modifiers-in-mouse-bindings' into master (diff) | |
| parent | changelog: click count in mouse bindings (diff) | |
Merge branch 'click-count-in-mouse-bindings' into master
Closes #78
Diffstat (limited to 'config.c')
| -rw-r--r-- | config.c | 80 |
1 files changed, 51 insertions, 29 deletions
@@ -97,45 +97,43 @@ static const char *const search_binding_action_map[] = { static_assert(ALEN(search_binding_action_map) == BIND_ACTION_SEARCH_COUNT, "search binding action map size mismatch"); -#define LOG_AND_NOTIFY_ERR(fmt, ...) \ - LOG_ERR(fmt, ## __VA_ARGS__); \ - { \ - char *text = xasprintf(fmt, ## __VA_ARGS__); \ - struct user_notification notif = { \ - .kind = USER_NOTIFICATION_ERROR, \ - .text = text, \ - }; \ - tll_push_back(conf->notifications, notif); \ - } +#define LOG_AND_NOTIFY_ERR(fmt, ...) \ + do { \ + LOG_ERR(fmt, ## __VA_ARGS__); \ + char *text = xasprintf(fmt, ## __VA_ARGS__); \ + struct user_notification notif = { \ + .kind = USER_NOTIFICATION_ERROR, \ + .text = text, \ + }; \ + tll_push_back(conf->notifications, notif); \ + } while (0) #define LOG_AND_NOTIFY_WARN(fmt, ...) \ - LOG_WARN(fmt, ## __VA_ARGS__); \ - { \ + do { \ + LOG_WARN(fmt, ## __VA_ARGS__); \ char *text = xasprintf(fmt, ## __VA_ARGS__); \ struct user_notification notif = { \ .kind = USER_NOTIFICATION_WARNING, \ .text = text, \ }; \ tll_push_back(conf->notifications, notif); \ - } + } while (0) #define LOG_AND_NOTIFY_ERRNO(fmt, ...) \ - { \ + do { \ int _errno = errno; \ LOG_ERRNO(fmt, ## __VA_ARGS__); \ - { \ - int len = snprintf(NULL, 0, fmt, ## __VA_ARGS__); \ - int errno_len = snprintf(NULL, 0, ": %s", strerror(_errno)); \ - char *text = xmalloc(len + errno_len + 1); \ - snprintf(text, len + errno_len + 1, fmt, ## __VA_ARGS__); \ - snprintf(&text[len], errno_len + 1, ": %s", strerror(_errno)); \ - struct user_notification notif = { \ - .kind = USER_NOTIFICATION_ERROR, \ - .text = text, \ - }; \ - tll_push_back(conf->notifications, notif); \ - } \ - } + int len = snprintf(NULL, 0, fmt, ## __VA_ARGS__); \ + int errno_len = snprintf(NULL, 0, ": %s", strerror(_errno)); \ + char *text = xmalloc(len + errno_len + 1); \ + snprintf(text, len + errno_len + 1, fmt, ## __VA_ARGS__); \ + snprintf(&text[len], errno_len + 1, ": %s", strerror(_errno)); \ + struct user_notification notif = { \ + .kind = USER_NOTIFICATION_ERROR, \ + .text = text, \ + }; \ + tll_push_back(conf->notifications, notif); \ + } while(0) static char * get_shell(void) @@ -1009,17 +1007,41 @@ parse_mouse_combos(struct config *conf, const char *combos, key_combo_list_t *ke combo = strtok_r(NULL, " ", &tok_ctx)) { struct config_key_modifiers modifiers = {}; - const char *key = strrchr(combo, '+'); + char *key = strrchr(combo, '+'); if (key == NULL) { /* No modifiers */ key = combo; } else { + *key = '\0'; if (!parse_modifiers(conf, combo, key - combo, &modifiers, path, lineno)) goto err; key++; /* Skip past the '+' */ } + size_t count = 0; + { + char *_count = strrchr(key, '-'); + if (_count != NULL) { + *_count = '\0'; + _count++; + + errno = 0; + char *end; + unsigned long value = strtoul(_count, &end, 10); + if (_count[0] == '\0' || *end != '\0' || errno != 0) { + if (errno != 0) + LOG_AND_NOTIFY_ERRNO( + "%s:%d: %s: invalid click count", path, lineno, _count); + else + LOG_AND_NOTIFY_ERR( + "%s:%d: %s: invalid click count", path, lineno, _count); + goto err; + } + count = value; + } + } + static const struct { const char *name; int code; @@ -1052,7 +1074,7 @@ parse_mouse_combos(struct config *conf, const char *combos, key_combo_list_t *ke .modifiers = modifiers, .m = { .button = button, - .count = 1, + .count = count, }, }; tll_push_back(*key_combos, new); |
